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