kernel.org linux-2.6.10
[linux-2.6.git] / arch / arm / mach-s3c2410 / cpu.c
1 /* linux/arch/arm/mach-s3c2410/cpu.c
2  *
3  * Copyright (c) 2004 Simtec Electronics
4  * Ben Dooks <ben@simtec.co.uk>
5  *
6  * S3C24XX CPU Support
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/interrupt.h>
27 #include <linux/ioport.h>
28 #include <linux/device.h>
29
30 #include <asm/hardware.h>
31 #include <asm/irq.h>
32 #include <asm/io.h>
33 #include <asm/delay.h>
34
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37
38 #include <asm/arch/regs-gpio.h>
39
40 #include "cpu.h"
41 #include "clock.h"
42 #include "s3c2410.h"
43 #include "s3c2440.h"
44
45 struct cpu_table {
46         unsigned long   idcode;
47         unsigned long   idmask;
48         void            (*map_io)(struct map_desc *mach_desc, int size);
49         int             (*init)(void);
50         const char      *name;
51 };
52
53 /* table of supported CPUs */
54
55 static const char name_s3c2410[]  = "S3C2410";
56 static const char name_s3c2440[]  = "S3C2440";
57 static const char name_s3c2410a[] = "S3C2410A";
58 static const char name_s3c2440a[] = "S3C2440A";
59
60 static struct cpu_table cpu_ids[] __initdata = {
61         {
62                 .idcode = 0x32410000,
63                 .idmask = 0xffffffff,
64                 .map_io = s3c2410_map_io,
65                 .init   = s3c2410_init,
66                 .name   = name_s3c2410
67         },
68         {
69                 .idcode = 0x32410002,
70                 .idmask = 0xffffffff,
71                 .map_io = s3c2410_map_io,
72                 .init   = s3c2410_init,
73                 .name   = name_s3c2410a
74         },
75         {
76                 .idcode = 0x32440000,
77                 .idmask = 0xffffffff,
78                 .map_io = s3c2440_map_io,
79                 .init   = s3c2440_init,
80                 .name   = name_s3c2440
81         },
82         {
83                 .idcode = 0x32440001,
84                 .idmask = 0xffffffff,
85                 .map_io = s3c2440_map_io,
86                 .init   = s3c2440_init,
87                 .name   = name_s3c2440a
88         }
89 };
90
91 /* minimal IO mapping */
92
93 static struct map_desc s3c_iodesc[] __initdata = {
94         IODESC_ENT(GPIO),
95         IODESC_ENT(IRQ),
96         IODESC_ENT(MEMCTRL),
97         IODESC_ENT(UART)
98 };
99
100
101 static struct cpu_table *
102 s3c_lookup_cpu(unsigned long idcode)
103 {
104         struct cpu_table *tab;
105         int count;
106
107         tab = cpu_ids;
108         for (count = 0; count < ARRAY_SIZE(cpu_ids); count++, tab++) {
109                 if ((idcode & tab->idmask) == tab->idcode)
110                         return tab;
111         }
112
113         return NULL;
114 }
115
116 /* board information */
117
118 static struct s3c24xx_board *board;
119
120 void s3c24xx_set_board(struct s3c24xx_board *b)
121 {
122         int i;
123
124         board = b;
125
126         if (b->clocks_count != 0) {
127                 struct clk **ptr = b->clocks;;
128
129                 for (i = b->clocks_count; i > 0; i--, ptr++)
130                         s3c2410_register_clock(*ptr);
131         }
132 }
133
134 /* cpu information */
135
136 static struct cpu_table *cpu;
137
138 void __init s3c24xx_init_io(struct map_desc *mach_desc, int size)
139 {
140         unsigned long idcode;
141
142         /* initialise the io descriptors we need for initialisation */
143         iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc));
144
145         idcode = __raw_readl(S3C2410_GSTATUS1);
146         cpu = s3c_lookup_cpu(idcode);
147
148         if (cpu == NULL) {
149                 printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
150                 panic("Unknown S3C24XX CPU");
151         }
152
153         if (cpu->map_io == NULL || cpu->init == NULL) {
154                 printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
155                 panic("Unsupported S3C24XX CPU");
156         }
157
158         printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
159
160         (cpu->map_io)(mach_desc, size);
161 }
162
163 static int __init s3c_arch_init(void)
164 {
165         int ret;
166
167         // do the correct init for cpu
168
169         if (cpu == NULL)
170                 panic("s3c_arch_init: NULL cpu\n");
171
172         ret = (cpu->init)();
173         if (ret != 0)
174                 return ret;
175
176         if (board != NULL) {
177                 struct platform_device **ptr = board->devices;
178                 int i;
179
180                 for (i = 0; i < board->devices_count; i++, ptr++) {
181                         ret = platform_device_register(*ptr);
182
183                         if (ret) {
184                                 printk(KERN_ERR "s3c24xx: failed to add board device %s (%d) @%p\n", (*ptr)->name, ret, *ptr);
185                         }
186                 }
187
188                 /* mask any error, we may not need all these board
189                  * devices */
190                 ret = 0;
191         }
192
193         return ret;
194 }
195
196 arch_initcall(s3c_arch_init);