common.c 11 KB

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