cpu.c 5.3 KB

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