cpu.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 "cpu.h"
  36. #include "clock.h"
  37. #include "s3c2400.h"
  38. #include "s3c2410.h"
  39. #include "s3c2440.h"
  40. struct cpu_table {
  41. unsigned long idcode;
  42. unsigned long idmask;
  43. void (*map_io)(struct map_desc *mach_desc, int size);
  44. void (*init_uarts)(struct s3c2410_uartcfg *cfg, int no);
  45. void (*init_clocks)(int xtal);
  46. int (*init)(void);
  47. const char *name;
  48. };
  49. /* table of supported CPUs */
  50. static const char name_s3c2400[] = "S3C2400";
  51. static const char name_s3c2410[] = "S3C2410";
  52. static const char name_s3c2440[] = "S3C2440";
  53. static const char name_s3c2410a[] = "S3C2410A";
  54. static const char name_s3c2440a[] = "S3C2440A";
  55. static struct cpu_table cpu_ids[] __initdata = {
  56. {
  57. .idcode = 0x32410000,
  58. .idmask = 0xffffffff,
  59. .map_io = s3c2410_map_io,
  60. .init_clocks = s3c2410_init_clocks,
  61. .init_uarts = s3c2410_init_uarts,
  62. .init = s3c2410_init,
  63. .name = name_s3c2410
  64. },
  65. {
  66. .idcode = 0x32410002,
  67. .idmask = 0xffffffff,
  68. .map_io = s3c2410_map_io,
  69. .init_clocks = s3c2410_init_clocks,
  70. .init_uarts = s3c2410_init_uarts,
  71. .init = s3c2410_init,
  72. .name = name_s3c2410a
  73. },
  74. {
  75. .idcode = 0x32440000,
  76. .idmask = 0xffffffff,
  77. .map_io = s3c2440_map_io,
  78. .init_clocks = s3c2440_init_clocks,
  79. .init_uarts = s3c2440_init_uarts,
  80. .init = s3c2440_init,
  81. .name = name_s3c2440
  82. },
  83. {
  84. .idcode = 0x32440001,
  85. .idmask = 0xffffffff,
  86. .map_io = s3c2440_map_io,
  87. .init_clocks = s3c2440_init_clocks,
  88. .init_uarts = s3c2440_init_uarts,
  89. .init = s3c2440_init,
  90. .name = name_s3c2440a
  91. },
  92. {
  93. .idcode = 0x0, /* S3C2400 doesn't have an idcode */
  94. .idmask = 0xffffffff,
  95. .map_io = s3c2400_map_io,
  96. .init_clocks = s3c2400_init_clocks,
  97. .init_uarts = s3c2400_init_uarts,
  98. .init = s3c2400_init,
  99. .name = name_s3c2400
  100. },
  101. };
  102. /* minimal IO mapping */
  103. static struct map_desc s3c_iodesc[] __initdata = {
  104. IODESC_ENT(GPIO),
  105. IODESC_ENT(IRQ),
  106. IODESC_ENT(MEMCTRL),
  107. IODESC_ENT(UART)
  108. };
  109. static struct cpu_table *
  110. s3c_lookup_cpu(unsigned long idcode)
  111. {
  112. struct cpu_table *tab;
  113. int count;
  114. tab = cpu_ids;
  115. for (count = 0; count < ARRAY_SIZE(cpu_ids); count++, tab++) {
  116. if ((idcode & tab->idmask) == tab->idcode)
  117. return tab;
  118. }
  119. return NULL;
  120. }
  121. /* board information */
  122. static struct s3c24xx_board *board;
  123. void s3c24xx_set_board(struct s3c24xx_board *b)
  124. {
  125. int i;
  126. board = b;
  127. if (b->clocks_count != 0) {
  128. struct clk **ptr = b->clocks;
  129. for (i = b->clocks_count; i > 0; i--, ptr++)
  130. s3c24xx_register_clock(*ptr);
  131. }
  132. }
  133. /* cpu information */
  134. static struct cpu_table *cpu;
  135. void __init s3c24xx_init_io(struct map_desc *mach_desc, int size)
  136. {
  137. unsigned long idcode = 0x0;
  138. /* initialise the io descriptors we need for initialisation */
  139. iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc));
  140. #ifndef CONFIG_CPU_S3C2400
  141. idcode = __raw_readl(S3C2410_GSTATUS1);
  142. #endif
  143. cpu = s3c_lookup_cpu(idcode);
  144. if (cpu == NULL) {
  145. printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
  146. panic("Unknown S3C24XX CPU");
  147. }
  148. if (cpu->map_io == NULL || cpu->init == NULL) {
  149. printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
  150. panic("Unsupported S3C24XX CPU");
  151. }
  152. printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
  153. (cpu->map_io)(mach_desc, size);
  154. }
  155. /* s3c24xx_init_clocks
  156. *
  157. * Initialise the clock subsystem and associated information from the
  158. * given master crystal value.
  159. *
  160. * xtal = 0 -> use default PLL crystal value (normally 12MHz)
  161. * != 0 -> PLL crystal value in Hz
  162. */
  163. void __init s3c24xx_init_clocks(int xtal)
  164. {
  165. if (xtal == 0)
  166. xtal = 12*1000*1000;
  167. if (cpu == NULL)
  168. panic("s3c24xx_init_clocks: no cpu setup?\n");
  169. if (cpu->init_clocks == NULL)
  170. panic("s3c24xx_init_clocks: cpu has no clock init\n");
  171. else
  172. (cpu->init_clocks)(xtal);
  173. }
  174. void __init s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  175. {
  176. if (cpu == NULL)
  177. return;
  178. if (cpu->init_uarts == NULL) {
  179. printk(KERN_ERR "s3c24xx_init_uarts: cpu has no uart init\n");
  180. } else
  181. (cpu->init_uarts)(cfg, no);
  182. }
  183. static int __init s3c_arch_init(void)
  184. {
  185. int ret;
  186. // do the correct init for cpu
  187. if (cpu == NULL)
  188. panic("s3c_arch_init: NULL cpu\n");
  189. ret = (cpu->init)();
  190. if (ret != 0)
  191. return ret;
  192. if (board != NULL) {
  193. struct platform_device **ptr = board->devices;
  194. int i;
  195. for (i = 0; i < board->devices_count; i++, ptr++) {
  196. ret = platform_device_register(*ptr);
  197. if (ret) {
  198. printk(KERN_ERR "s3c24xx: failed to add board device %s (%d) @%p\n", (*ptr)->name, ret, *ptr);
  199. }
  200. }
  201. /* mask any error, we may not need all these board
  202. * devices */
  203. ret = 0;
  204. }
  205. return ret;
  206. }
  207. arch_initcall(s3c_arch_init);