Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* 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 King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 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 Dooks | 66a9b49 | 2006-06-18 23:04:05 +0100 | [diff] [blame] | 40 | #include <asm/arch/regs-serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #include "cpu.h" |
Ben Dooks | 66a9b49 | 2006-06-18 23:04:05 +0100 | [diff] [blame] | 43 | #include "devs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include "clock.h" |
Lucas Correia Villa Real | 83f755f | 2006-02-01 21:24:24 +0000 | [diff] [blame] | 45 | #include "s3c2400.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include "s3c2410.h" |
Ben Dooks | 96ce238 | 2006-06-18 23:06:41 +0100 | [diff] [blame^] | 47 | #include "s3c244x.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include "s3c2440.h" |
Ben Dooks | 96ce238 | 2006-06-18 23:06:41 +0100 | [diff] [blame^] | 49 | #include "s3c2442.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | struct cpu_table { |
| 52 | unsigned long idcode; |
| 53 | unsigned long idmask; |
| 54 | void (*map_io)(struct map_desc *mach_desc, int size); |
| 55 | void (*init_uarts)(struct s3c2410_uartcfg *cfg, int no); |
| 56 | void (*init_clocks)(int xtal); |
| 57 | int (*init)(void); |
| 58 | const char *name; |
| 59 | }; |
| 60 | |
| 61 | /* table of supported CPUs */ |
| 62 | |
Lucas Correia Villa Real | 83f755f | 2006-02-01 21:24:24 +0000 | [diff] [blame] | 63 | static const char name_s3c2400[] = "S3C2400"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static const char name_s3c2410[] = "S3C2410"; |
| 65 | static const char name_s3c2440[] = "S3C2440"; |
Ben Dooks | 96ce238 | 2006-06-18 23:06:41 +0100 | [diff] [blame^] | 66 | static const char name_s3c2442[] = "S3C2442"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static const char name_s3c2410a[] = "S3C2410A"; |
| 68 | static const char name_s3c2440a[] = "S3C2440A"; |
| 69 | |
| 70 | static struct cpu_table cpu_ids[] __initdata = { |
| 71 | { |
| 72 | .idcode = 0x32410000, |
| 73 | .idmask = 0xffffffff, |
| 74 | .map_io = s3c2410_map_io, |
| 75 | .init_clocks = s3c2410_init_clocks, |
| 76 | .init_uarts = s3c2410_init_uarts, |
| 77 | .init = s3c2410_init, |
| 78 | .name = name_s3c2410 |
| 79 | }, |
| 80 | { |
| 81 | .idcode = 0x32410002, |
| 82 | .idmask = 0xffffffff, |
| 83 | .map_io = s3c2410_map_io, |
| 84 | .init_clocks = s3c2410_init_clocks, |
| 85 | .init_uarts = s3c2410_init_uarts, |
| 86 | .init = s3c2410_init, |
| 87 | .name = name_s3c2410a |
| 88 | }, |
| 89 | { |
| 90 | .idcode = 0x32440000, |
| 91 | .idmask = 0xffffffff, |
Ben Dooks | 96ce238 | 2006-06-18 23:06:41 +0100 | [diff] [blame^] | 92 | .map_io = s3c244x_map_io, |
| 93 | .init_clocks = s3c244x_init_clocks, |
| 94 | .init_uarts = s3c244x_init_uarts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | .init = s3c2440_init, |
| 96 | .name = name_s3c2440 |
| 97 | }, |
| 98 | { |
| 99 | .idcode = 0x32440001, |
| 100 | .idmask = 0xffffffff, |
Ben Dooks | 96ce238 | 2006-06-18 23:06:41 +0100 | [diff] [blame^] | 101 | .map_io = s3c244x_map_io, |
| 102 | .init_clocks = s3c244x_init_clocks, |
| 103 | .init_uarts = s3c244x_init_uarts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | .init = s3c2440_init, |
| 105 | .name = name_s3c2440a |
Lucas Correia Villa Real | 83f755f | 2006-02-01 21:24:24 +0000 | [diff] [blame] | 106 | }, |
| 107 | { |
Ben Dooks | 96ce238 | 2006-06-18 23:06:41 +0100 | [diff] [blame^] | 108 | .idcode = 0x32440aaa, |
| 109 | .idmask = 0xffffffff, |
| 110 | .map_io = s3c244x_map_io, |
| 111 | .init_clocks = s3c244x_init_clocks, |
| 112 | .init_uarts = s3c244x_init_uarts, |
| 113 | .init = s3c2442_init, |
| 114 | .name = name_s3c2442 |
| 115 | }, |
| 116 | { |
Lucas Correia Villa Real | 83f755f | 2006-02-01 21:24:24 +0000 | [diff] [blame] | 117 | .idcode = 0x0, /* S3C2400 doesn't have an idcode */ |
| 118 | .idmask = 0xffffffff, |
| 119 | .map_io = s3c2400_map_io, |
| 120 | .init_clocks = s3c2400_init_clocks, |
| 121 | .init_uarts = s3c2400_init_uarts, |
| 122 | .init = s3c2400_init, |
| 123 | .name = name_s3c2400 |
| 124 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | /* minimal IO mapping */ |
| 128 | |
| 129 | static struct map_desc s3c_iodesc[] __initdata = { |
| 130 | IODESC_ENT(GPIO), |
| 131 | IODESC_ENT(IRQ), |
| 132 | IODESC_ENT(MEMCTRL), |
| 133 | IODESC_ENT(UART) |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | static struct cpu_table * |
| 138 | s3c_lookup_cpu(unsigned long idcode) |
| 139 | { |
| 140 | struct cpu_table *tab; |
| 141 | int count; |
| 142 | |
| 143 | tab = cpu_ids; |
| 144 | for (count = 0; count < ARRAY_SIZE(cpu_ids); count++, tab++) { |
| 145 | if ((idcode & tab->idmask) == tab->idcode) |
| 146 | return tab; |
| 147 | } |
| 148 | |
| 149 | return NULL; |
| 150 | } |
| 151 | |
| 152 | /* board information */ |
| 153 | |
| 154 | static struct s3c24xx_board *board; |
| 155 | |
| 156 | void s3c24xx_set_board(struct s3c24xx_board *b) |
| 157 | { |
| 158 | int i; |
| 159 | |
| 160 | board = b; |
| 161 | |
| 162 | if (b->clocks_count != 0) { |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 163 | struct clk **ptr = b->clocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | for (i = b->clocks_count; i > 0; i--, ptr++) |
| 166 | s3c24xx_register_clock(*ptr); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /* cpu information */ |
| 171 | |
| 172 | static struct cpu_table *cpu; |
| 173 | |
| 174 | void __init s3c24xx_init_io(struct map_desc *mach_desc, int size) |
| 175 | { |
Lucas Correia Villa Real | 83f755f | 2006-02-01 21:24:24 +0000 | [diff] [blame] | 176 | unsigned long idcode = 0x0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | /* initialise the io descriptors we need for initialisation */ |
| 179 | iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc)); |
| 180 | |
Lucas Correia Villa Real | 83f755f | 2006-02-01 21:24:24 +0000 | [diff] [blame] | 181 | #ifndef CONFIG_CPU_S3C2400 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | idcode = __raw_readl(S3C2410_GSTATUS1); |
Lucas Correia Villa Real | 83f755f | 2006-02-01 21:24:24 +0000 | [diff] [blame] | 183 | #endif |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | cpu = s3c_lookup_cpu(idcode); |
| 186 | |
| 187 | if (cpu == NULL) { |
| 188 | printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode); |
| 189 | panic("Unknown S3C24XX CPU"); |
| 190 | } |
| 191 | |
Ben Dooks | 36fe6a8 | 2006-06-18 16:21:53 +0100 | [diff] [blame] | 192 | printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode); |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | if (cpu->map_io == NULL || cpu->init == NULL) { |
| 195 | printk(KERN_ERR "CPU %s support not enabled\n", cpu->name); |
| 196 | panic("Unsupported S3C24XX CPU"); |
| 197 | } |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | (cpu->map_io)(mach_desc, size); |
| 200 | } |
| 201 | |
| 202 | /* s3c24xx_init_clocks |
| 203 | * |
| 204 | * Initialise the clock subsystem and associated information from the |
| 205 | * given master crystal value. |
| 206 | * |
| 207 | * xtal = 0 -> use default PLL crystal value (normally 12MHz) |
| 208 | * != 0 -> PLL crystal value in Hz |
| 209 | */ |
| 210 | |
| 211 | void __init s3c24xx_init_clocks(int xtal) |
| 212 | { |
| 213 | if (xtal == 0) |
| 214 | xtal = 12*1000*1000; |
| 215 | |
| 216 | if (cpu == NULL) |
| 217 | panic("s3c24xx_init_clocks: no cpu setup?\n"); |
| 218 | |
| 219 | if (cpu->init_clocks == NULL) |
| 220 | panic("s3c24xx_init_clocks: cpu has no clock init\n"); |
| 221 | else |
| 222 | (cpu->init_clocks)(xtal); |
| 223 | } |
| 224 | |
Ben Dooks | 66a9b49 | 2006-06-18 23:04:05 +0100 | [diff] [blame] | 225 | /* uart management */ |
| 226 | |
| 227 | static int nr_uarts __initdata = 0; |
| 228 | |
| 229 | static struct s3c2410_uartcfg uart_cfgs[3]; |
| 230 | |
| 231 | /* s3c24xx_init_uartdevs |
| 232 | * |
| 233 | * copy the specified platform data and configuration into our central |
| 234 | * set of devices, before the data is thrown away after the init process. |
| 235 | * |
| 236 | * This also fills in the array passed to the serial driver for the |
| 237 | * early initialisation of the console. |
| 238 | */ |
| 239 | |
| 240 | void __init s3c24xx_init_uartdevs(char *name, |
| 241 | struct s3c24xx_uart_resources *res, |
| 242 | struct s3c2410_uartcfg *cfg, int no) |
| 243 | { |
| 244 | struct platform_device *platdev; |
| 245 | struct s3c2410_uartcfg *cfgptr = uart_cfgs; |
| 246 | struct s3c24xx_uart_resources *resp; |
| 247 | int uart; |
| 248 | |
| 249 | memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no); |
| 250 | |
| 251 | for (uart = 0; uart < no; uart++, cfg++, cfgptr++) { |
| 252 | platdev = s3c24xx_uart_src[cfgptr->hwport]; |
| 253 | |
| 254 | resp = res + cfgptr->hwport; |
| 255 | |
| 256 | s3c24xx_uart_devs[uart] = platdev; |
| 257 | |
| 258 | platdev->name = name; |
| 259 | platdev->resource = resp->resources; |
| 260 | platdev->num_resources = resp->nr_resources; |
| 261 | |
| 262 | platdev->dev.platform_data = cfgptr; |
| 263 | } |
| 264 | |
| 265 | nr_uarts = no; |
| 266 | } |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no) |
| 269 | { |
| 270 | if (cpu == NULL) |
| 271 | return; |
| 272 | |
| 273 | if (cpu->init_uarts == NULL) { |
| 274 | printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n"); |
| 275 | } else |
| 276 | (cpu->init_uarts)(cfg, no); |
| 277 | } |
| 278 | |
| 279 | static int __init s3c_arch_init(void) |
| 280 | { |
| 281 | int ret; |
| 282 | |
| 283 | // do the correct init for cpu |
| 284 | |
| 285 | if (cpu == NULL) |
| 286 | panic("s3c_arch_init: NULL cpu\n"); |
| 287 | |
| 288 | ret = (cpu->init)(); |
| 289 | if (ret != 0) |
| 290 | return ret; |
| 291 | |
Ben Dooks | 66a9b49 | 2006-06-18 23:04:05 +0100 | [diff] [blame] | 292 | ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts); |
| 293 | if (ret != 0) |
| 294 | return ret; |
| 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | if (board != NULL) { |
| 297 | struct platform_device **ptr = board->devices; |
| 298 | int i; |
| 299 | |
| 300 | for (i = 0; i < board->devices_count; i++, ptr++) { |
| 301 | ret = platform_device_register(*ptr); |
| 302 | |
| 303 | if (ret) { |
| 304 | printk(KERN_ERR "s3c24xx: failed to add board device %s (%d) @%p\n", (*ptr)->name, ret, *ptr); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /* mask any error, we may not need all these board |
| 309 | * devices */ |
| 310 | ret = 0; |
| 311 | } |
| 312 | |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | arch_initcall(s3c_arch_init); |