cpu.c 7.1 KB

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