blob: acc58adfbd216197ef57877391289eb544c201a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/cpu.c
2 *
3 * Copyright (c) 2004-2005 Simtec Electronics
4 * http://www.simtec.co.uk/products/SWLINUX/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * S3C24XX CPU Support
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*/
23
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/interrupt.h>
28#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010029#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <asm/hardware.h>
32#include <asm/irq.h>
33#include <asm/io.h>
34#include <asm/delay.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38
39#include <asm/arch/regs-gpio.h>
Ben Dooks66a9b492006-06-18 23:04:05 +010040#include <asm/arch/regs-serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include "cpu.h"
Ben Dooks66a9b492006-06-18 23:04:05 +010043#include "devs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include "clock.h"
Lucas Correia Villa Real83f755f2006-02-01 21:24:24 +000045#include "s3c2400.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "s3c2410.h"
47#include "s3c2440.h"
48
49struct cpu_table {
50 unsigned long idcode;
51 unsigned long idmask;
52 void (*map_io)(struct map_desc *mach_desc, int size);
53 void (*init_uarts)(struct s3c2410_uartcfg *cfg, int no);
54 void (*init_clocks)(int xtal);
55 int (*init)(void);
56 const char *name;
57};
58
59/* table of supported CPUs */
60
Lucas Correia Villa Real83f755f2006-02-01 21:24:24 +000061static const char name_s3c2400[] = "S3C2400";
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static const char name_s3c2410[] = "S3C2410";
63static const char name_s3c2440[] = "S3C2440";
64static const char name_s3c2410a[] = "S3C2410A";
65static const char name_s3c2440a[] = "S3C2440A";
66
67static struct cpu_table cpu_ids[] __initdata = {
68 {
69 .idcode = 0x32410000,
70 .idmask = 0xffffffff,
71 .map_io = s3c2410_map_io,
72 .init_clocks = s3c2410_init_clocks,
73 .init_uarts = s3c2410_init_uarts,
74 .init = s3c2410_init,
75 .name = name_s3c2410
76 },
77 {
78 .idcode = 0x32410002,
79 .idmask = 0xffffffff,
80 .map_io = s3c2410_map_io,
81 .init_clocks = s3c2410_init_clocks,
82 .init_uarts = s3c2410_init_uarts,
83 .init = s3c2410_init,
84 .name = name_s3c2410a
85 },
86 {
87 .idcode = 0x32440000,
88 .idmask = 0xffffffff,
89 .map_io = s3c2440_map_io,
90 .init_clocks = s3c2440_init_clocks,
91 .init_uarts = s3c2440_init_uarts,
92 .init = s3c2440_init,
93 .name = name_s3c2440
94 },
95 {
96 .idcode = 0x32440001,
97 .idmask = 0xffffffff,
98 .map_io = s3c2440_map_io,
99 .init_clocks = s3c2440_init_clocks,
100 .init_uarts = s3c2440_init_uarts,
101 .init = s3c2440_init,
102 .name = name_s3c2440a
Lucas Correia Villa Real83f755f2006-02-01 21:24:24 +0000103 },
104 {
105 .idcode = 0x0, /* S3C2400 doesn't have an idcode */
106 .idmask = 0xffffffff,
107 .map_io = s3c2400_map_io,
108 .init_clocks = s3c2400_init_clocks,
109 .init_uarts = s3c2400_init_uarts,
110 .init = s3c2400_init,
111 .name = name_s3c2400
112 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113};
114
115/* minimal IO mapping */
116
117static struct map_desc s3c_iodesc[] __initdata = {
118 IODESC_ENT(GPIO),
119 IODESC_ENT(IRQ),
120 IODESC_ENT(MEMCTRL),
121 IODESC_ENT(UART)
122};
123
124
125static struct cpu_table *
126s3c_lookup_cpu(unsigned long idcode)
127{
128 struct cpu_table *tab;
129 int count;
130
131 tab = cpu_ids;
132 for (count = 0; count < ARRAY_SIZE(cpu_ids); count++, tab++) {
133 if ((idcode & tab->idmask) == tab->idcode)
134 return tab;
135 }
136
137 return NULL;
138}
139
140/* board information */
141
142static struct s3c24xx_board *board;
143
144void s3c24xx_set_board(struct s3c24xx_board *b)
145{
146 int i;
147
148 board = b;
149
150 if (b->clocks_count != 0) {
Alexey Dobriyan53b35312006-03-24 03:16:13 -0800151 struct clk **ptr = b->clocks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 for (i = b->clocks_count; i > 0; i--, ptr++)
154 s3c24xx_register_clock(*ptr);
155 }
156}
157
158/* cpu information */
159
160static struct cpu_table *cpu;
161
162void __init s3c24xx_init_io(struct map_desc *mach_desc, int size)
163{
Lucas Correia Villa Real83f755f2006-02-01 21:24:24 +0000164 unsigned long idcode = 0x0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 /* initialise the io descriptors we need for initialisation */
167 iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc));
168
Lucas Correia Villa Real83f755f2006-02-01 21:24:24 +0000169#ifndef CONFIG_CPU_S3C2400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 idcode = __raw_readl(S3C2410_GSTATUS1);
Lucas Correia Villa Real83f755f2006-02-01 21:24:24 +0000171#endif
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 cpu = s3c_lookup_cpu(idcode);
174
175 if (cpu == NULL) {
176 printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
177 panic("Unknown S3C24XX CPU");
178 }
179
Ben Dooks36fe6a82006-06-18 16:21:53 +0100180 printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 if (cpu->map_io == NULL || cpu->init == NULL) {
183 printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
184 panic("Unsupported S3C24XX CPU");
185 }
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 (cpu->map_io)(mach_desc, size);
188}
189
190/* s3c24xx_init_clocks
191 *
192 * Initialise the clock subsystem and associated information from the
193 * given master crystal value.
194 *
195 * xtal = 0 -> use default PLL crystal value (normally 12MHz)
196 * != 0 -> PLL crystal value in Hz
197*/
198
199void __init s3c24xx_init_clocks(int xtal)
200{
201 if (xtal == 0)
202 xtal = 12*1000*1000;
203
204 if (cpu == NULL)
205 panic("s3c24xx_init_clocks: no cpu setup?\n");
206
207 if (cpu->init_clocks == NULL)
208 panic("s3c24xx_init_clocks: cpu has no clock init\n");
209 else
210 (cpu->init_clocks)(xtal);
211}
212
Ben Dooks66a9b492006-06-18 23:04:05 +0100213/* uart management */
214
215static int nr_uarts __initdata = 0;
216
217static struct s3c2410_uartcfg uart_cfgs[3];
218
219/* s3c24xx_init_uartdevs
220 *
221 * copy the specified platform data and configuration into our central
222 * set of devices, before the data is thrown away after the init process.
223 *
224 * This also fills in the array passed to the serial driver for the
225 * early initialisation of the console.
226*/
227
228void __init s3c24xx_init_uartdevs(char *name,
229 struct s3c24xx_uart_resources *res,
230 struct s3c2410_uartcfg *cfg, int no)
231{
232 struct platform_device *platdev;
233 struct s3c2410_uartcfg *cfgptr = uart_cfgs;
234 struct s3c24xx_uart_resources *resp;
235 int uart;
236
237 memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
238
239 for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
240 platdev = s3c24xx_uart_src[cfgptr->hwport];
241
242 resp = res + cfgptr->hwport;
243
244 s3c24xx_uart_devs[uart] = platdev;
245
246 platdev->name = name;
247 platdev->resource = resp->resources;
248 platdev->num_resources = resp->nr_resources;
249
250 platdev->dev.platform_data = cfgptr;
251 }
252
253 nr_uarts = no;
254}
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
257{
258 if (cpu == NULL)
259 return;
260
261 if (cpu->init_uarts == NULL) {
262 printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
263 } else
264 (cpu->init_uarts)(cfg, no);
265}
266
267static int __init s3c_arch_init(void)
268{
269 int ret;
270
271 // do the correct init for cpu
272
273 if (cpu == NULL)
274 panic("s3c_arch_init: NULL cpu\n");
275
276 ret = (cpu->init)();
277 if (ret != 0)
278 return ret;
279
Ben Dooks66a9b492006-06-18 23:04:05 +0100280 ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
281 if (ret != 0)
282 return ret;
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (board != NULL) {
285 struct platform_device **ptr = board->devices;
286 int i;
287
288 for (i = 0; i < board->devices_count; i++, ptr++) {
289 ret = platform_device_register(*ptr);
290
291 if (ret) {
292 printk(KERN_ERR "s3c24xx: failed to add board device %s (%d) @%p\n", (*ptr)->name, ret, *ptr);
293 }
294 }
295
296 /* mask any error, we may not need all these board
297 * devices */
298 ret = 0;
299 }
300
301 return ret;
302}
303
304arch_initcall(s3c_arch_init);