common.c 10 KB

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