cpu.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* linux/arch/arm/plat-s3c24xx/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. #include <linux/init.h>
  24. #include <linux/module.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/ioport.h>
  27. #include <linux/serial_core.h>
  28. #include <linux/platform_device.h>
  29. #include <asm/hardware.h>
  30. #include <asm/irq.h>
  31. #include <asm/io.h>
  32. #include <asm/delay.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/map.h>
  35. #include <asm/arch/regs-gpio.h>
  36. #include <asm/arch/regs-serial.h>
  37. #include <asm/plat-s3c24xx/cpu.h>
  38. #include <asm/plat-s3c24xx/devs.h>
  39. #include <asm/plat-s3c24xx/clock.h>
  40. #include <asm/plat-s3c24xx/s3c2400.h>
  41. #include <asm/plat-s3c24xx/s3c2410.h>
  42. #include <asm/plat-s3c24xx/s3c2412.h>
  43. #include "s3c244x.h"
  44. #include <asm/plat-s3c24xx/s3c2440.h>
  45. #include <asm/plat-s3c24xx/s3c2442.h>
  46. #include <asm/plat-s3c24xx/s3c2443.h>
  47. struct cpu_table {
  48. unsigned long idcode;
  49. unsigned long idmask;
  50. void (*map_io)(struct map_desc *mach_desc, int size);
  51. void (*init_uarts)(struct s3c2410_uartcfg *cfg, int no);
  52. void (*init_clocks)(int xtal);
  53. int (*init)(void);
  54. const char *name;
  55. };
  56. /* table of supported CPUs */
  57. static const char name_s3c2400[] = "S3C2400";
  58. static const char name_s3c2410[] = "S3C2410";
  59. static const char name_s3c2412[] = "S3C2412";
  60. static const char name_s3c2440[] = "S3C2440";
  61. static const char name_s3c2442[] = "S3C2442";
  62. static const char name_s3c2443[] = "S3C2443";
  63. static const char name_s3c2410a[] = "S3C2410A";
  64. static const char name_s3c2440a[] = "S3C2440A";
  65. static struct cpu_table cpu_ids[] __initdata = {
  66. {
  67. .idcode = 0x32410000,
  68. .idmask = 0xffffffff,
  69. .map_io = s3c2410_map_io,
  70. .init_clocks = s3c2410_init_clocks,
  71. .init_uarts = s3c2410_init_uarts,
  72. .init = s3c2410_init,
  73. .name = name_s3c2410
  74. },
  75. {
  76. .idcode = 0x32410002,
  77. .idmask = 0xffffffff,
  78. .map_io = s3c2410_map_io,
  79. .init_clocks = s3c2410_init_clocks,
  80. .init_uarts = s3c2410_init_uarts,
  81. .init = s3c2410_init,
  82. .name = name_s3c2410a
  83. },
  84. {
  85. .idcode = 0x32440000,
  86. .idmask = 0xffffffff,
  87. .map_io = s3c244x_map_io,
  88. .init_clocks = s3c244x_init_clocks,
  89. .init_uarts = s3c244x_init_uarts,
  90. .init = s3c2440_init,
  91. .name = name_s3c2440
  92. },
  93. {
  94. .idcode = 0x32440001,
  95. .idmask = 0xffffffff,
  96. .map_io = s3c244x_map_io,
  97. .init_clocks = s3c244x_init_clocks,
  98. .init_uarts = s3c244x_init_uarts,
  99. .init = s3c2440_init,
  100. .name = name_s3c2440a
  101. },
  102. {
  103. .idcode = 0x32440aaa,
  104. .idmask = 0xffffffff,
  105. .map_io = s3c244x_map_io,
  106. .init_clocks = s3c244x_init_clocks,
  107. .init_uarts = s3c244x_init_uarts,
  108. .init = s3c2442_init,
  109. .name = name_s3c2442
  110. },
  111. {
  112. .idcode = 0x32412001,
  113. .idmask = 0xffffffff,
  114. .map_io = s3c2412_map_io,
  115. .init_clocks = s3c2412_init_clocks,
  116. .init_uarts = s3c2412_init_uarts,
  117. .init = s3c2412_init,
  118. .name = name_s3c2412,
  119. },
  120. { /* a newer version of the s3c2412 */
  121. .idcode = 0x32412003,
  122. .idmask = 0xffffffff,
  123. .map_io = s3c2412_map_io,
  124. .init_clocks = s3c2412_init_clocks,
  125. .init_uarts = s3c2412_init_uarts,
  126. .init = s3c2412_init,
  127. .name = name_s3c2412,
  128. },
  129. {
  130. .idcode = 0x32443001,
  131. .idmask = 0xffffffff,
  132. .map_io = s3c2443_map_io,
  133. .init_clocks = s3c2443_init_clocks,
  134. .init_uarts = s3c2443_init_uarts,
  135. .init = s3c2443_init,
  136. .name = name_s3c2443,
  137. },
  138. {
  139. .idcode = 0x0, /* S3C2400 doesn't have an idcode */
  140. .idmask = 0xffffffff,
  141. .map_io = s3c2400_map_io,
  142. .init_clocks = s3c2400_init_clocks,
  143. .init_uarts = s3c2400_init_uarts,
  144. .init = s3c2400_init,
  145. .name = name_s3c2400
  146. },
  147. };
  148. /* minimal IO mapping */
  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. static struct cpu_table *
  156. s3c_lookup_cpu(unsigned long idcode)
  157. {
  158. struct cpu_table *tab;
  159. int count;
  160. tab = cpu_ids;
  161. for (count = 0; count < ARRAY_SIZE(cpu_ids); count++, tab++) {
  162. if ((idcode & tab->idmask) == tab->idcode)
  163. return tab;
  164. }
  165. return NULL;
  166. }
  167. /* board information */
  168. static struct s3c24xx_board *board;
  169. void s3c24xx_set_board(struct s3c24xx_board *b)
  170. {
  171. int i;
  172. board = b;
  173. if (b->clocks_count != 0) {
  174. struct clk **ptr = b->clocks;
  175. for (i = b->clocks_count; i > 0; i--, ptr++)
  176. s3c24xx_register_clock(*ptr);
  177. }
  178. }
  179. /* cpu information */
  180. static struct cpu_table *cpu;
  181. static unsigned long s3c24xx_read_idcode_v5(void)
  182. {
  183. #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
  184. return __raw_readl(S3C2412_GSTATUS1);
  185. #else
  186. return 1UL; /* don't look like an 2400 */
  187. #endif
  188. }
  189. static unsigned long s3c24xx_read_idcode_v4(void)
  190. {
  191. #ifndef CONFIG_CPU_S3C2400
  192. return __raw_readl(S3C2410_GSTATUS1);
  193. #else
  194. return 0UL;
  195. #endif
  196. }
  197. void __init s3c24xx_init_io(struct map_desc *mach_desc, int size)
  198. {
  199. unsigned long idcode = 0x0;
  200. /* initialise the io descriptors we need for initialisation */
  201. iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc));
  202. if (cpu_architecture() >= CPU_ARCH_ARMv5) {
  203. idcode = s3c24xx_read_idcode_v5();
  204. } else {
  205. idcode = s3c24xx_read_idcode_v4();
  206. }
  207. cpu = s3c_lookup_cpu(idcode);
  208. if (cpu == NULL) {
  209. printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
  210. panic("Unknown S3C24XX CPU");
  211. }
  212. printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
  213. if (cpu->map_io == NULL || cpu->init == NULL) {
  214. printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
  215. panic("Unsupported S3C24XX CPU");
  216. }
  217. (cpu->map_io)(mach_desc, size);
  218. }
  219. /* s3c24xx_init_clocks
  220. *
  221. * Initialise the clock subsystem and associated information from the
  222. * given master crystal value.
  223. *
  224. * xtal = 0 -> use default PLL crystal value (normally 12MHz)
  225. * != 0 -> PLL crystal value in Hz
  226. */
  227. void __init s3c24xx_init_clocks(int xtal)
  228. {
  229. if (xtal == 0)
  230. xtal = 12*1000*1000;
  231. if (cpu == NULL)
  232. panic("s3c24xx_init_clocks: no cpu setup?\n");
  233. if (cpu->init_clocks == NULL)
  234. panic("s3c24xx_init_clocks: cpu has no clock init\n");
  235. else
  236. (cpu->init_clocks)(xtal);
  237. }
  238. /* uart management */
  239. static int nr_uarts __initdata = 0;
  240. static struct s3c2410_uartcfg uart_cfgs[3];
  241. /* s3c24xx_init_uartdevs
  242. *
  243. * copy the specified platform data and configuration into our central
  244. * set of devices, before the data is thrown away after the init process.
  245. *
  246. * This also fills in the array passed to the serial driver for the
  247. * early initialisation of the console.
  248. */
  249. void __init s3c24xx_init_uartdevs(char *name,
  250. struct s3c24xx_uart_resources *res,
  251. struct s3c2410_uartcfg *cfg, int no)
  252. {
  253. struct platform_device *platdev;
  254. struct s3c2410_uartcfg *cfgptr = uart_cfgs;
  255. struct s3c24xx_uart_resources *resp;
  256. int uart;
  257. memcpy(cfgptr, cfg, sizeof(struct s3c2410_uartcfg) * no);
  258. for (uart = 0; uart < no; uart++, cfg++, cfgptr++) {
  259. platdev = s3c24xx_uart_src[cfgptr->hwport];
  260. resp = res + cfgptr->hwport;
  261. s3c24xx_uart_devs[uart] = platdev;
  262. platdev->name = name;
  263. platdev->resource = resp->resources;
  264. platdev->num_resources = resp->nr_resources;
  265. platdev->dev.platform_data = cfgptr;
  266. }
  267. nr_uarts = no;
  268. }
  269. void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  270. {
  271. if (cpu == NULL)
  272. return;
  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. static int __init s3c_arch_init(void)
  279. {
  280. int ret;
  281. // do the correct init for cpu
  282. if (cpu == NULL)
  283. panic("s3c_arch_init: NULL cpu\n");
  284. ret = (cpu->init)();
  285. if (ret != 0)
  286. return ret;
  287. ret = platform_add_devices(s3c24xx_uart_devs, nr_uarts);
  288. if (ret != 0)
  289. return ret;
  290. if (board != NULL) {
  291. struct platform_device **ptr = board->devices;
  292. int i;
  293. for (i = 0; i < board->devices_count; i++, ptr++) {
  294. ret = platform_device_register(*ptr);
  295. if (ret) {
  296. printk(KERN_ERR "s3c24xx: failed to add board device %s (%d) @%p\n", (*ptr)->name, ret, *ptr);
  297. }
  298. }
  299. /* mask any error, we may not need all these board
  300. * devices */
  301. ret = 0;
  302. }
  303. return ret;
  304. }
  305. arch_initcall(s3c_arch_init);