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