common.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. * Common code for S3C24XX machines
  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 <linux/delay.h>
  30. #include <linux/io.h>
  31. #include <mach/hardware.h>
  32. #include <mach/regs-clock.h>
  33. #include <asm/irq.h>
  34. #include <asm/cacheflush.h>
  35. #include <asm/system_info.h>
  36. #include <asm/system_misc.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/map.h>
  39. #include <mach/regs-gpio.h>
  40. #include <plat/regs-serial.h>
  41. #include <plat/cpu.h>
  42. #include <plat/devs.h>
  43. #include <plat/clock.h>
  44. #include <plat/s3c2410.h>
  45. #include <plat/s3c2412.h>
  46. #include <plat/s3c2416.h>
  47. #include <plat/s3c244x.h>
  48. #include <plat/s3c2443.h>
  49. #include <plat/cpu-freq.h>
  50. #include <plat/pll.h>
  51. /* table of supported CPUs */
  52. static const char name_s3c2410[] = "S3C2410";
  53. static const char name_s3c2412[] = "S3C2412";
  54. static const char name_s3c2416[] = "S3C2416/S3C2450";
  55. static const char name_s3c2440[] = "S3C2440";
  56. static const char name_s3c2442[] = "S3C2442";
  57. static const char name_s3c2442b[] = "S3C2442B";
  58. static const char name_s3c2443[] = "S3C2443";
  59. static const char name_s3c2410a[] = "S3C2410A";
  60. static const char name_s3c2440a[] = "S3C2440A";
  61. static struct cpu_table cpu_ids[] __initdata = {
  62. {
  63. .idcode = 0x32410000,
  64. .idmask = 0xffffffff,
  65. .map_io = s3c2410_map_io,
  66. .init_clocks = s3c2410_init_clocks,
  67. .init_uarts = s3c2410_init_uarts,
  68. .init = s3c2410_init,
  69. .name = name_s3c2410
  70. },
  71. {
  72. .idcode = 0x32410002,
  73. .idmask = 0xffffffff,
  74. .map_io = s3c2410_map_io,
  75. .init_clocks = s3c2410_init_clocks,
  76. .init_uarts = s3c2410_init_uarts,
  77. .init = s3c2410a_init,
  78. .name = name_s3c2410a
  79. },
  80. {
  81. .idcode = 0x32440000,
  82. .idmask = 0xffffffff,
  83. .map_io = s3c2440_map_io,
  84. .init_clocks = s3c244x_init_clocks,
  85. .init_uarts = s3c244x_init_uarts,
  86. .init = s3c2440_init,
  87. .name = name_s3c2440
  88. },
  89. {
  90. .idcode = 0x32440001,
  91. .idmask = 0xffffffff,
  92. .map_io = s3c2440_map_io,
  93. .init_clocks = s3c244x_init_clocks,
  94. .init_uarts = s3c244x_init_uarts,
  95. .init = s3c2440_init,
  96. .name = name_s3c2440a
  97. },
  98. {
  99. .idcode = 0x32440aaa,
  100. .idmask = 0xffffffff,
  101. .map_io = s3c2442_map_io,
  102. .init_clocks = s3c244x_init_clocks,
  103. .init_uarts = s3c244x_init_uarts,
  104. .init = s3c2442_init,
  105. .name = name_s3c2442
  106. },
  107. {
  108. .idcode = 0x32440aab,
  109. .idmask = 0xffffffff,
  110. .map_io = s3c2442_map_io,
  111. .init_clocks = s3c244x_init_clocks,
  112. .init_uarts = s3c244x_init_uarts,
  113. .init = s3c2442_init,
  114. .name = name_s3c2442b
  115. },
  116. {
  117. .idcode = 0x32412001,
  118. .idmask = 0xffffffff,
  119. .map_io = s3c2412_map_io,
  120. .init_clocks = s3c2412_init_clocks,
  121. .init_uarts = s3c2412_init_uarts,
  122. .init = s3c2412_init,
  123. .name = name_s3c2412,
  124. },
  125. { /* a newer version of the s3c2412 */
  126. .idcode = 0x32412003,
  127. .idmask = 0xffffffff,
  128. .map_io = s3c2412_map_io,
  129. .init_clocks = s3c2412_init_clocks,
  130. .init_uarts = s3c2412_init_uarts,
  131. .init = s3c2412_init,
  132. .name = name_s3c2412,
  133. },
  134. { /* a strange version of the s3c2416 */
  135. .idcode = 0x32450003,
  136. .idmask = 0xffffffff,
  137. .map_io = s3c2416_map_io,
  138. .init_clocks = s3c2416_init_clocks,
  139. .init_uarts = s3c2416_init_uarts,
  140. .init = s3c2416_init,
  141. .name = name_s3c2416,
  142. },
  143. {
  144. .idcode = 0x32443001,
  145. .idmask = 0xffffffff,
  146. .map_io = s3c2443_map_io,
  147. .init_clocks = s3c2443_init_clocks,
  148. .init_uarts = s3c2443_init_uarts,
  149. .init = s3c2443_init,
  150. .name = name_s3c2443,
  151. },
  152. };
  153. /* minimal IO mapping */
  154. static struct map_desc s3c_iodesc[] __initdata = {
  155. IODESC_ENT(GPIO),
  156. IODESC_ENT(IRQ),
  157. IODESC_ENT(MEMCTRL),
  158. IODESC_ENT(UART)
  159. };
  160. /* read cpu identificaiton code */
  161. static unsigned long s3c24xx_read_idcode_v5(void)
  162. {
  163. #if defined(CONFIG_CPU_S3C2416)
  164. /* s3c2416 is v5, with S3C24XX_GSTATUS1 instead of S3C2412_GSTATUS1 */
  165. u32 gs = __raw_readl(S3C24XX_GSTATUS1);
  166. /* test for s3c2416 or similar device */
  167. if ((gs >> 16) == 0x3245)
  168. return gs;
  169. #endif
  170. #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
  171. return __raw_readl(S3C2412_GSTATUS1);
  172. #else
  173. return 1UL; /* don't look like an 2400 */
  174. #endif
  175. }
  176. static unsigned long s3c24xx_read_idcode_v4(void)
  177. {
  178. return __raw_readl(S3C2410_GSTATUS1);
  179. }
  180. static void s3c24xx_default_idle(void)
  181. {
  182. unsigned long tmp;
  183. int i;
  184. /* idle the system by using the idle mode which will wait for an
  185. * interrupt to happen before restarting the system.
  186. */
  187. /* Warning: going into idle state upsets jtag scanning */
  188. __raw_writel(__raw_readl(S3C2410_CLKCON) | S3C2410_CLKCON_IDLE,
  189. S3C2410_CLKCON);
  190. /* the samsung port seems to do a loop and then unset idle.. */
  191. for (i = 0; i < 50; i++)
  192. tmp += __raw_readl(S3C2410_CLKCON); /* ensure loop not optimised out */
  193. /* this bit is not cleared on re-start... */
  194. __raw_writel(__raw_readl(S3C2410_CLKCON) & ~S3C2410_CLKCON_IDLE,
  195. S3C2410_CLKCON);
  196. }
  197. void __init s3c24xx_init_io(struct map_desc *mach_desc, int size)
  198. {
  199. arm_pm_idle = s3c24xx_default_idle;
  200. /* initialise the io descriptors we need for initialisation */
  201. iotable_init(mach_desc, size);
  202. iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc));
  203. if (cpu_architecture() >= CPU_ARCH_ARMv5) {
  204. samsung_cpu_id = s3c24xx_read_idcode_v5();
  205. } else {
  206. samsung_cpu_id = s3c24xx_read_idcode_v4();
  207. }
  208. s3c24xx_init_cpu();
  209. s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
  210. }
  211. /* Serial port registrations */
  212. static struct resource s3c2410_uart0_resource[] = {
  213. [0] = DEFINE_RES_MEM(S3C2410_PA_UART0, SZ_16K),
  214. [1] = DEFINE_RES_NAMED(IRQ_S3CUART_RX0, \
  215. IRQ_S3CUART_ERR0 - IRQ_S3CUART_RX0 + 1, \
  216. NULL, IORESOURCE_IRQ)
  217. };
  218. static struct resource s3c2410_uart1_resource[] = {
  219. [0] = DEFINE_RES_MEM(S3C2410_PA_UART1, SZ_16K),
  220. [1] = DEFINE_RES_NAMED(IRQ_S3CUART_RX1, \
  221. IRQ_S3CUART_ERR1 - IRQ_S3CUART_RX1 + 1, \
  222. NULL, IORESOURCE_IRQ)
  223. };
  224. static struct resource s3c2410_uart2_resource[] = {
  225. [0] = DEFINE_RES_MEM(S3C2410_PA_UART2, SZ_16K),
  226. [1] = DEFINE_RES_NAMED(IRQ_S3CUART_RX2, \
  227. IRQ_S3CUART_ERR2 - IRQ_S3CUART_RX2 + 1, \
  228. NULL, IORESOURCE_IRQ)
  229. };
  230. static struct resource s3c2410_uart3_resource[] = {
  231. [0] = DEFINE_RES_MEM(S3C2443_PA_UART3, SZ_16K),
  232. [1] = DEFINE_RES_NAMED(IRQ_S3CUART_RX3, \
  233. IRQ_S3CUART_ERR3 - IRQ_S3CUART_RX3 + 1, \
  234. NULL, IORESOURCE_IRQ)
  235. };
  236. struct s3c24xx_uart_resources s3c2410_uart_resources[] __initdata = {
  237. [0] = {
  238. .resources = s3c2410_uart0_resource,
  239. .nr_resources = ARRAY_SIZE(s3c2410_uart0_resource),
  240. },
  241. [1] = {
  242. .resources = s3c2410_uart1_resource,
  243. .nr_resources = ARRAY_SIZE(s3c2410_uart1_resource),
  244. },
  245. [2] = {
  246. .resources = s3c2410_uart2_resource,
  247. .nr_resources = ARRAY_SIZE(s3c2410_uart2_resource),
  248. },
  249. [3] = {
  250. .resources = s3c2410_uart3_resource,
  251. .nr_resources = ARRAY_SIZE(s3c2410_uart3_resource),
  252. },
  253. };
  254. /* initialise all the clocks */
  255. void __init_or_cpufreq s3c24xx_setup_clocks(unsigned long fclk,
  256. unsigned long hclk,
  257. unsigned long pclk)
  258. {
  259. clk_upll.rate = s3c24xx_get_pll(__raw_readl(S3C2410_UPLLCON),
  260. clk_xtal.rate);
  261. clk_mpll.rate = fclk;
  262. clk_h.rate = hclk;
  263. clk_p.rate = pclk;
  264. clk_f.rate = fclk;
  265. }