common.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  2. * Copyright (c) 2009-2011 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * Common Codes for S5P64X0 machines
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/list.h>
  15. #include <linux/timer.h>
  16. #include <linux/init.h>
  17. #include <linux/clk.h>
  18. #include <linux/io.h>
  19. #include <linux/device.h>
  20. #include <linux/serial_core.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/sched.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/gpio.h>
  25. #include <linux/irq.h>
  26. #include <asm/irq.h>
  27. #include <asm/proc-fns.h>
  28. #include <asm/system_misc.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/mach/map.h>
  31. #include <asm/mach/irq.h>
  32. #include <mach/map.h>
  33. #include <mach/hardware.h>
  34. #include <mach/regs-clock.h>
  35. #include <mach/regs-gpio.h>
  36. #include <plat/cpu.h>
  37. #include <plat/clock.h>
  38. #include <plat/devs.h>
  39. #include <plat/pm.h>
  40. #include <plat/sdhci.h>
  41. #include <plat/adc-core.h>
  42. #include <plat/fb-core.h>
  43. #include <plat/spi-core.h>
  44. #include <plat/gpio-cfg.h>
  45. #include <plat/regs-irqtype.h>
  46. #include <plat/regs-serial.h>
  47. #include <plat/watchdog-reset.h>
  48. #include "common.h"
  49. static const char name_s5p6440[] = "S5P6440";
  50. static const char name_s5p6450[] = "S5P6450";
  51. static struct cpu_table cpu_ids[] __initdata = {
  52. {
  53. .idcode = S5P6440_CPU_ID,
  54. .idmask = S5P64XX_CPU_MASK,
  55. .map_io = s5p6440_map_io,
  56. .init_clocks = s5p6440_init_clocks,
  57. .init_uarts = s5p6440_init_uarts,
  58. .init = s5p64x0_init,
  59. .name = name_s5p6440,
  60. }, {
  61. .idcode = S5P6450_CPU_ID,
  62. .idmask = S5P64XX_CPU_MASK,
  63. .map_io = s5p6450_map_io,
  64. .init_clocks = s5p6450_init_clocks,
  65. .init_uarts = s5p6450_init_uarts,
  66. .init = s5p64x0_init,
  67. .name = name_s5p6450,
  68. },
  69. };
  70. /* Initial IO mappings */
  71. static struct map_desc s5p64x0_iodesc[] __initdata = {
  72. {
  73. .virtual = (unsigned long)S5P_VA_CHIPID,
  74. .pfn = __phys_to_pfn(S5P64X0_PA_CHIPID),
  75. .length = SZ_4K,
  76. .type = MT_DEVICE,
  77. }, {
  78. .virtual = (unsigned long)S3C_VA_SYS,
  79. .pfn = __phys_to_pfn(S5P64X0_PA_SYSCON),
  80. .length = SZ_64K,
  81. .type = MT_DEVICE,
  82. }, {
  83. .virtual = (unsigned long)S3C_VA_TIMER,
  84. .pfn = __phys_to_pfn(S5P64X0_PA_TIMER),
  85. .length = SZ_16K,
  86. .type = MT_DEVICE,
  87. }, {
  88. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  89. .pfn = __phys_to_pfn(S5P64X0_PA_WDT),
  90. .length = SZ_4K,
  91. .type = MT_DEVICE,
  92. }, {
  93. .virtual = (unsigned long)S5P_VA_SROMC,
  94. .pfn = __phys_to_pfn(S5P64X0_PA_SROMC),
  95. .length = SZ_4K,
  96. .type = MT_DEVICE,
  97. }, {
  98. .virtual = (unsigned long)S5P_VA_GPIO,
  99. .pfn = __phys_to_pfn(S5P64X0_PA_GPIO),
  100. .length = SZ_4K,
  101. .type = MT_DEVICE,
  102. }, {
  103. .virtual = (unsigned long)VA_VIC0,
  104. .pfn = __phys_to_pfn(S5P64X0_PA_VIC0),
  105. .length = SZ_16K,
  106. .type = MT_DEVICE,
  107. }, {
  108. .virtual = (unsigned long)VA_VIC1,
  109. .pfn = __phys_to_pfn(S5P64X0_PA_VIC1),
  110. .length = SZ_16K,
  111. .type = MT_DEVICE,
  112. },
  113. };
  114. static struct map_desc s5p6440_iodesc[] __initdata = {
  115. {
  116. .virtual = (unsigned long)S3C_VA_UART,
  117. .pfn = __phys_to_pfn(S5P6440_PA_UART(0)),
  118. .length = SZ_4K,
  119. .type = MT_DEVICE,
  120. },
  121. };
  122. static struct map_desc s5p6450_iodesc[] __initdata = {
  123. {
  124. .virtual = (unsigned long)S3C_VA_UART,
  125. .pfn = __phys_to_pfn(S5P6450_PA_UART(0)),
  126. .length = SZ_512K,
  127. .type = MT_DEVICE,
  128. }, {
  129. .virtual = (unsigned long)S3C_VA_UART + SZ_512K,
  130. .pfn = __phys_to_pfn(S5P6450_PA_UART(5)),
  131. .length = SZ_4K,
  132. .type = MT_DEVICE,
  133. },
  134. };
  135. static void s5p64x0_idle(void)
  136. {
  137. unsigned long val;
  138. val = __raw_readl(S5P64X0_PWR_CFG);
  139. val &= ~(0x3 << 5);
  140. val |= (0x1 << 5);
  141. __raw_writel(val, S5P64X0_PWR_CFG);
  142. cpu_do_idle();
  143. }
  144. /*
  145. * s5p64x0_map_io
  146. *
  147. * register the standard CPU IO areas
  148. */
  149. void __init s5p64x0_init_io(struct map_desc *mach_desc, int size)
  150. {
  151. /* initialize the io descriptors we need for initialization */
  152. iotable_init(s5p64x0_iodesc, ARRAY_SIZE(s5p64x0_iodesc));
  153. if (mach_desc)
  154. iotable_init(mach_desc, size);
  155. /* detect cpu id and rev. */
  156. s5p_init_cpu(S5P64X0_SYS_ID);
  157. s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
  158. }
  159. void __init s5p6440_map_io(void)
  160. {
  161. /* initialize any device information early */
  162. s3c_adc_setname("s3c64xx-adc");
  163. s3c_fb_setname("s5p64x0-fb");
  164. s3c64xx_spi_setname("s5p64x0-spi");
  165. s5p64x0_default_sdhci0();
  166. s5p64x0_default_sdhci1();
  167. s5p6440_default_sdhci2();
  168. iotable_init(s5p6440_iodesc, ARRAY_SIZE(s5p6440_iodesc));
  169. }
  170. void __init s5p6450_map_io(void)
  171. {
  172. /* initialize any device information early */
  173. s3c_adc_setname("s3c64xx-adc");
  174. s3c_fb_setname("s5p64x0-fb");
  175. s3c64xx_spi_setname("s5p64x0-spi");
  176. s5p64x0_default_sdhci0();
  177. s5p64x0_default_sdhci1();
  178. s5p6450_default_sdhci2();
  179. iotable_init(s5p6450_iodesc, ARRAY_SIZE(s5p6450_iodesc));
  180. }
  181. /*
  182. * s5p64x0_init_clocks
  183. *
  184. * register and setup the CPU clocks
  185. */
  186. void __init s5p6440_init_clocks(int xtal)
  187. {
  188. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  189. s3c24xx_register_baseclocks(xtal);
  190. s5p_register_clocks(xtal);
  191. s5p6440_register_clocks();
  192. s5p6440_setup_clocks();
  193. }
  194. void __init s5p6450_init_clocks(int xtal)
  195. {
  196. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  197. s3c24xx_register_baseclocks(xtal);
  198. s5p_register_clocks(xtal);
  199. s5p6450_register_clocks();
  200. s5p6450_setup_clocks();
  201. }
  202. /*
  203. * s5p64x0_init_irq
  204. *
  205. * register the CPU interrupts
  206. */
  207. void __init s5p6440_init_irq(void)
  208. {
  209. /* S5P6440 supports 2 VIC */
  210. u32 vic[2];
  211. /*
  212. * VIC0 is missing IRQ_VIC0[3, 4, 8, 10, (12-22)]
  213. * VIC1 is missing IRQ VIC1[1, 3, 4, 10, 11, 12, 14, 15, 22]
  214. */
  215. vic[0] = 0xff800ae7;
  216. vic[1] = 0xffbf23e5;
  217. s5p_init_irq(vic, ARRAY_SIZE(vic));
  218. }
  219. void __init s5p6450_init_irq(void)
  220. {
  221. /* S5P6450 supports only 2 VIC */
  222. u32 vic[2];
  223. /*
  224. * VIC0 is missing IRQ_VIC0[(13-15), (21-22)]
  225. * VIC1 is missing IRQ VIC1[12, 14, 23]
  226. */
  227. vic[0] = 0xff9f1fff;
  228. vic[1] = 0xff7fafff;
  229. s5p_init_irq(vic, ARRAY_SIZE(vic));
  230. }
  231. struct bus_type s5p64x0_subsys = {
  232. .name = "s5p64x0-core",
  233. .dev_name = "s5p64x0-core",
  234. };
  235. static struct device s5p64x0_dev = {
  236. .bus = &s5p64x0_subsys,
  237. };
  238. static int __init s5p64x0_core_init(void)
  239. {
  240. return subsys_system_register(&s5p64x0_subsys, NULL);
  241. }
  242. core_initcall(s5p64x0_core_init);
  243. int __init s5p64x0_init(void)
  244. {
  245. printk(KERN_INFO "S5P64X0(S5P6440/S5P6450): Initializing architecture\n");
  246. /* set idle function */
  247. arm_pm_idle = s5p64x0_idle;
  248. return device_register(&s5p64x0_dev);
  249. }
  250. /* uart registration process */
  251. void __init s5p6440_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  252. {
  253. int uart;
  254. for (uart = 0; uart < no; uart++) {
  255. s5p_uart_resources[uart].resources->start = S5P6440_PA_UART(uart);
  256. s5p_uart_resources[uart].resources->end = S5P6440_PA_UART(uart) + S5P_SZ_UART;
  257. }
  258. s3c24xx_init_uartdevs("s3c6400-uart", s5p_uart_resources, cfg, no);
  259. }
  260. void __init s5p6450_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  261. {
  262. s3c24xx_init_uartdevs("s3c6400-uart", s5p_uart_resources, cfg, no);
  263. }
  264. #define eint_offset(irq) ((irq) - IRQ_EINT(0))
  265. static int s5p64x0_irq_eint_set_type(struct irq_data *data, unsigned int type)
  266. {
  267. int offs = eint_offset(data->irq);
  268. int shift;
  269. u32 ctrl, mask;
  270. u32 newvalue = 0;
  271. if (offs > 15)
  272. return -EINVAL;
  273. switch (type) {
  274. case IRQ_TYPE_NONE:
  275. printk(KERN_WARNING "No edge setting!\n");
  276. break;
  277. case IRQ_TYPE_EDGE_RISING:
  278. newvalue = S3C2410_EXTINT_RISEEDGE;
  279. break;
  280. case IRQ_TYPE_EDGE_FALLING:
  281. newvalue = S3C2410_EXTINT_FALLEDGE;
  282. break;
  283. case IRQ_TYPE_EDGE_BOTH:
  284. newvalue = S3C2410_EXTINT_BOTHEDGE;
  285. break;
  286. case IRQ_TYPE_LEVEL_LOW:
  287. newvalue = S3C2410_EXTINT_LOWLEV;
  288. break;
  289. case IRQ_TYPE_LEVEL_HIGH:
  290. newvalue = S3C2410_EXTINT_HILEV;
  291. break;
  292. default:
  293. printk(KERN_ERR "No such irq type %d", type);
  294. return -EINVAL;
  295. }
  296. shift = (offs / 2) * 4;
  297. mask = 0x7 << shift;
  298. ctrl = __raw_readl(S5P64X0_EINT0CON0) & ~mask;
  299. ctrl |= newvalue << shift;
  300. __raw_writel(ctrl, S5P64X0_EINT0CON0);
  301. /* Configure the GPIO pin for 6450 or 6440 based on CPU ID */
  302. if (soc_is_s5p6450())
  303. s3c_gpio_cfgpin(S5P6450_GPN(offs), S3C_GPIO_SFN(2));
  304. else
  305. s3c_gpio_cfgpin(S5P6440_GPN(offs), S3C_GPIO_SFN(2));
  306. return 0;
  307. }
  308. /*
  309. * s5p64x0_irq_demux_eint
  310. *
  311. * This function demuxes the IRQ from the group0 external interrupts,
  312. * from IRQ_EINT(0) to IRQ_EINT(15). It is designed to be inlined into
  313. * the specific handlers s5p64x0_irq_demux_eintX_Y.
  314. */
  315. static inline void s5p64x0_irq_demux_eint(unsigned int start, unsigned int end)
  316. {
  317. u32 status = __raw_readl(S5P64X0_EINT0PEND);
  318. u32 mask = __raw_readl(S5P64X0_EINT0MASK);
  319. unsigned int irq;
  320. status &= ~mask;
  321. status >>= start;
  322. status &= (1 << (end - start + 1)) - 1;
  323. for (irq = IRQ_EINT(start); irq <= IRQ_EINT(end); irq++) {
  324. if (status & 1)
  325. generic_handle_irq(irq);
  326. status >>= 1;
  327. }
  328. }
  329. static void s5p64x0_irq_demux_eint0_3(unsigned int irq, struct irq_desc *desc)
  330. {
  331. s5p64x0_irq_demux_eint(0, 3);
  332. }
  333. static void s5p64x0_irq_demux_eint4_11(unsigned int irq, struct irq_desc *desc)
  334. {
  335. s5p64x0_irq_demux_eint(4, 11);
  336. }
  337. static void s5p64x0_irq_demux_eint12_15(unsigned int irq,
  338. struct irq_desc *desc)
  339. {
  340. s5p64x0_irq_demux_eint(12, 15);
  341. }
  342. static int s5p64x0_alloc_gc(void)
  343. {
  344. struct irq_chip_generic *gc;
  345. struct irq_chip_type *ct;
  346. gc = irq_alloc_generic_chip("s5p64x0-eint", 1, S5P_IRQ_EINT_BASE,
  347. S5P_VA_GPIO, handle_level_irq);
  348. if (!gc) {
  349. printk(KERN_ERR "%s: irq_alloc_generic_chip for group 0"
  350. "external interrupts failed\n", __func__);
  351. return -EINVAL;
  352. }
  353. ct = gc->chip_types;
  354. ct->chip.irq_ack = irq_gc_ack_set_bit;
  355. ct->chip.irq_mask = irq_gc_mask_set_bit;
  356. ct->chip.irq_unmask = irq_gc_mask_clr_bit;
  357. ct->chip.irq_set_type = s5p64x0_irq_eint_set_type;
  358. ct->chip.irq_set_wake = s3c_irqext_wake;
  359. ct->regs.ack = EINT0PEND_OFFSET;
  360. ct->regs.mask = EINT0MASK_OFFSET;
  361. irq_setup_generic_chip(gc, IRQ_MSK(16), IRQ_GC_INIT_MASK_CACHE,
  362. IRQ_NOREQUEST | IRQ_NOPROBE, 0);
  363. return 0;
  364. }
  365. static int __init s5p64x0_init_irq_eint(void)
  366. {
  367. int ret = s5p64x0_alloc_gc();
  368. irq_set_chained_handler(IRQ_EINT0_3, s5p64x0_irq_demux_eint0_3);
  369. irq_set_chained_handler(IRQ_EINT4_11, s5p64x0_irq_demux_eint4_11);
  370. irq_set_chained_handler(IRQ_EINT12_15, s5p64x0_irq_demux_eint12_15);
  371. return ret;
  372. }
  373. arch_initcall(s5p64x0_init_irq_eint);
  374. void s5p64x0_restart(char mode, const char *cmd)
  375. {
  376. if (mode != 's')
  377. arch_wdt_reset();
  378. soft_restart(0);
  379. }