common.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /*
  2. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * Common Codes for EXYNOS
  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/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqchip.h>
  15. #include <linux/io.h>
  16. #include <linux/device.h>
  17. #include <linux/gpio.h>
  18. #include <linux/sched.h>
  19. #include <linux/serial_core.h>
  20. #include <linux/of.h>
  21. #include <linux/of_fdt.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/export.h>
  24. #include <linux/irqdomain.h>
  25. #include <linux/irqchip.h>
  26. #include <linux/of_address.h>
  27. #include <linux/irqchip/arm-gic.h>
  28. #include <linux/irqchip/chained_irq.h>
  29. #include <asm/proc-fns.h>
  30. #include <asm/exception.h>
  31. #include <asm/hardware/cache-l2x0.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/mach/irq.h>
  34. #include <asm/cacheflush.h>
  35. #include <mach/regs-irq.h>
  36. #include <mach/regs-pmu.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/gpio-cfg.h>
  44. #include <plat/adc-core.h>
  45. #include <plat/fb-core.h>
  46. #include <plat/fimc-core.h>
  47. #include <plat/iic-core.h>
  48. #include <plat/tv-core.h>
  49. #include <plat/spi-core.h>
  50. #include <plat/regs-serial.h>
  51. #include "common.h"
  52. #define L2_AUX_VAL 0x7C470001
  53. #define L2_AUX_MASK 0xC200ffff
  54. static const char name_exynos4210[] = "EXYNOS4210";
  55. static const char name_exynos4212[] = "EXYNOS4212";
  56. static const char name_exynos4412[] = "EXYNOS4412";
  57. static const char name_exynos5250[] = "EXYNOS5250";
  58. static const char name_exynos5440[] = "EXYNOS5440";
  59. static void exynos4_map_io(void);
  60. static void exynos5_map_io(void);
  61. static void exynos5440_map_io(void);
  62. static void exynos4_init_clocks(int xtal);
  63. static void exynos5_init_clocks(int xtal);
  64. static void exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no);
  65. static int exynos_init(void);
  66. static struct cpu_table cpu_ids[] __initdata = {
  67. {
  68. .idcode = EXYNOS4210_CPU_ID,
  69. .idmask = EXYNOS4_CPU_MASK,
  70. .map_io = exynos4_map_io,
  71. .init_clocks = exynos4_init_clocks,
  72. .init_uarts = exynos4_init_uarts,
  73. .init = exynos_init,
  74. .name = name_exynos4210,
  75. }, {
  76. .idcode = EXYNOS4212_CPU_ID,
  77. .idmask = EXYNOS4_CPU_MASK,
  78. .map_io = exynos4_map_io,
  79. .init_clocks = exynos4_init_clocks,
  80. .init_uarts = exynos4_init_uarts,
  81. .init = exynos_init,
  82. .name = name_exynos4212,
  83. }, {
  84. .idcode = EXYNOS4412_CPU_ID,
  85. .idmask = EXYNOS4_CPU_MASK,
  86. .map_io = exynos4_map_io,
  87. .init_clocks = exynos4_init_clocks,
  88. .init_uarts = exynos4_init_uarts,
  89. .init = exynos_init,
  90. .name = name_exynos4412,
  91. }, {
  92. .idcode = EXYNOS5250_SOC_ID,
  93. .idmask = EXYNOS5_SOC_MASK,
  94. .map_io = exynos5_map_io,
  95. .init_clocks = exynos5_init_clocks,
  96. .init = exynos_init,
  97. .name = name_exynos5250,
  98. }, {
  99. .idcode = EXYNOS5440_SOC_ID,
  100. .idmask = EXYNOS5_SOC_MASK,
  101. .map_io = exynos5440_map_io,
  102. .init = exynos_init,
  103. .name = name_exynos5440,
  104. },
  105. };
  106. /* Initial IO mappings */
  107. static struct map_desc exynos_iodesc[] __initdata = {
  108. {
  109. .virtual = (unsigned long)S5P_VA_CHIPID,
  110. .pfn = __phys_to_pfn(EXYNOS_PA_CHIPID),
  111. .length = SZ_4K,
  112. .type = MT_DEVICE,
  113. },
  114. };
  115. #ifdef CONFIG_ARCH_EXYNOS5
  116. static struct map_desc exynos5440_iodesc[] __initdata = {
  117. {
  118. .virtual = (unsigned long)S5P_VA_CHIPID,
  119. .pfn = __phys_to_pfn(EXYNOS5440_PA_CHIPID),
  120. .length = SZ_4K,
  121. .type = MT_DEVICE,
  122. },
  123. };
  124. #endif
  125. static struct map_desc exynos4_iodesc[] __initdata = {
  126. {
  127. .virtual = (unsigned long)S3C_VA_SYS,
  128. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
  129. .length = SZ_64K,
  130. .type = MT_DEVICE,
  131. }, {
  132. .virtual = (unsigned long)S3C_VA_TIMER,
  133. .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
  134. .length = SZ_16K,
  135. .type = MT_DEVICE,
  136. }, {
  137. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  138. .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
  139. .length = SZ_4K,
  140. .type = MT_DEVICE,
  141. }, {
  142. .virtual = (unsigned long)S5P_VA_SROMC,
  143. .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
  144. .length = SZ_4K,
  145. .type = MT_DEVICE,
  146. }, {
  147. .virtual = (unsigned long)S5P_VA_SYSTIMER,
  148. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
  149. .length = SZ_4K,
  150. .type = MT_DEVICE,
  151. }, {
  152. .virtual = (unsigned long)S5P_VA_PMU,
  153. .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
  154. .length = SZ_64K,
  155. .type = MT_DEVICE,
  156. }, {
  157. .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
  158. .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
  159. .length = SZ_4K,
  160. .type = MT_DEVICE,
  161. }, {
  162. .virtual = (unsigned long)S5P_VA_GIC_CPU,
  163. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
  164. .length = SZ_64K,
  165. .type = MT_DEVICE,
  166. }, {
  167. .virtual = (unsigned long)S5P_VA_GIC_DIST,
  168. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
  169. .length = SZ_64K,
  170. .type = MT_DEVICE,
  171. }, {
  172. .virtual = (unsigned long)S3C_VA_UART,
  173. .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
  174. .length = SZ_512K,
  175. .type = MT_DEVICE,
  176. }, {
  177. .virtual = (unsigned long)S5P_VA_CMU,
  178. .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
  179. .length = SZ_128K,
  180. .type = MT_DEVICE,
  181. }, {
  182. .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
  183. .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
  184. .length = SZ_8K,
  185. .type = MT_DEVICE,
  186. }, {
  187. .virtual = (unsigned long)S5P_VA_L2CC,
  188. .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
  189. .length = SZ_4K,
  190. .type = MT_DEVICE,
  191. }, {
  192. .virtual = (unsigned long)S5P_VA_DMC0,
  193. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
  194. .length = SZ_64K,
  195. .type = MT_DEVICE,
  196. }, {
  197. .virtual = (unsigned long)S5P_VA_DMC1,
  198. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
  199. .length = SZ_64K,
  200. .type = MT_DEVICE,
  201. }, {
  202. .virtual = (unsigned long)S3C_VA_USB_HSPHY,
  203. .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
  204. .length = SZ_4K,
  205. .type = MT_DEVICE,
  206. },
  207. };
  208. static struct map_desc exynos4_iodesc0[] __initdata = {
  209. {
  210. .virtual = (unsigned long)S5P_VA_SYSRAM,
  211. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
  212. .length = SZ_4K,
  213. .type = MT_DEVICE,
  214. },
  215. };
  216. static struct map_desc exynos4_iodesc1[] __initdata = {
  217. {
  218. .virtual = (unsigned long)S5P_VA_SYSRAM,
  219. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
  220. .length = SZ_4K,
  221. .type = MT_DEVICE,
  222. },
  223. };
  224. static struct map_desc exynos5_iodesc[] __initdata = {
  225. {
  226. .virtual = (unsigned long)S3C_VA_SYS,
  227. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
  228. .length = SZ_64K,
  229. .type = MT_DEVICE,
  230. }, {
  231. .virtual = (unsigned long)S3C_VA_TIMER,
  232. .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
  233. .length = SZ_16K,
  234. .type = MT_DEVICE,
  235. }, {
  236. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  237. .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
  238. .length = SZ_4K,
  239. .type = MT_DEVICE,
  240. }, {
  241. .virtual = (unsigned long)S5P_VA_SROMC,
  242. .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
  243. .length = SZ_4K,
  244. .type = MT_DEVICE,
  245. }, {
  246. .virtual = (unsigned long)S5P_VA_SYSTIMER,
  247. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSTIMER),
  248. .length = SZ_4K,
  249. .type = MT_DEVICE,
  250. }, {
  251. .virtual = (unsigned long)S5P_VA_SYSRAM,
  252. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
  253. .length = SZ_4K,
  254. .type = MT_DEVICE,
  255. }, {
  256. .virtual = (unsigned long)S5P_VA_CMU,
  257. .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
  258. .length = 144 * SZ_1K,
  259. .type = MT_DEVICE,
  260. }, {
  261. .virtual = (unsigned long)S5P_VA_PMU,
  262. .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
  263. .length = SZ_64K,
  264. .type = MT_DEVICE,
  265. }, {
  266. .virtual = (unsigned long)S3C_VA_UART,
  267. .pfn = __phys_to_pfn(EXYNOS5_PA_UART),
  268. .length = SZ_512K,
  269. .type = MT_DEVICE,
  270. },
  271. };
  272. static struct map_desc exynos5440_iodesc0[] __initdata = {
  273. {
  274. .virtual = (unsigned long)S3C_VA_UART,
  275. .pfn = __phys_to_pfn(EXYNOS5440_PA_UART0),
  276. .length = SZ_512K,
  277. .type = MT_DEVICE,
  278. },
  279. };
  280. void exynos4_restart(char mode, const char *cmd)
  281. {
  282. __raw_writel(0x1, S5P_SWRESET);
  283. }
  284. void exynos5_restart(char mode, const char *cmd)
  285. {
  286. struct device_node *np;
  287. u32 val;
  288. void __iomem *addr;
  289. if (of_machine_is_compatible("samsung,exynos5250")) {
  290. val = 0x1;
  291. addr = EXYNOS_SWRESET;
  292. } else if (of_machine_is_compatible("samsung,exynos5440")) {
  293. np = of_find_compatible_node(NULL, NULL, "samsung,exynos5440-clock");
  294. addr = of_iomap(np, 0) + 0xcc;
  295. val = (0xfff << 20) | (0x1 << 16);
  296. } else {
  297. pr_err("%s: cannot support non-DT\n", __func__);
  298. return;
  299. }
  300. __raw_writel(val, addr);
  301. }
  302. void __init exynos_init_late(void)
  303. {
  304. if (of_machine_is_compatible("samsung,exynos5440"))
  305. /* to be supported later */
  306. return;
  307. exynos_pm_late_initcall();
  308. }
  309. /*
  310. * exynos_map_io
  311. *
  312. * register the standard cpu IO areas
  313. */
  314. void __init exynos_init_io(struct map_desc *mach_desc, int size)
  315. {
  316. struct map_desc *iodesc = exynos_iodesc;
  317. int iodesc_sz = ARRAY_SIZE(exynos_iodesc);
  318. #if defined(CONFIG_OF) && defined(CONFIG_ARCH_EXYNOS5)
  319. unsigned long root = of_get_flat_dt_root();
  320. /* initialize the io descriptors we need for initialization */
  321. if (of_flat_dt_is_compatible(root, "samsung,exynos5440")) {
  322. iodesc = exynos5440_iodesc;
  323. iodesc_sz = ARRAY_SIZE(exynos5440_iodesc);
  324. }
  325. #endif
  326. iotable_init(iodesc, iodesc_sz);
  327. if (mach_desc)
  328. iotable_init(mach_desc, size);
  329. /* detect cpu id and rev. */
  330. s5p_init_cpu(S5P_VA_CHIPID);
  331. s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
  332. }
  333. static void __init exynos4_map_io(void)
  334. {
  335. iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
  336. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
  337. iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
  338. else
  339. iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
  340. /* initialize device information early */
  341. exynos4_default_sdhci0();
  342. exynos4_default_sdhci1();
  343. exynos4_default_sdhci2();
  344. exynos4_default_sdhci3();
  345. s3c_adc_setname("samsung-adc-v3");
  346. s3c_fimc_setname(0, "exynos4-fimc");
  347. s3c_fimc_setname(1, "exynos4-fimc");
  348. s3c_fimc_setname(2, "exynos4-fimc");
  349. s3c_fimc_setname(3, "exynos4-fimc");
  350. s3c_sdhci_setname(0, "exynos4-sdhci");
  351. s3c_sdhci_setname(1, "exynos4-sdhci");
  352. s3c_sdhci_setname(2, "exynos4-sdhci");
  353. s3c_sdhci_setname(3, "exynos4-sdhci");
  354. /* The I2C bus controllers are directly compatible with s3c2440 */
  355. s3c_i2c0_setname("s3c2440-i2c");
  356. s3c_i2c1_setname("s3c2440-i2c");
  357. s3c_i2c2_setname("s3c2440-i2c");
  358. s5p_fb_setname(0, "exynos4-fb");
  359. s5p_hdmi_setname("exynos4-hdmi");
  360. s3c64xx_spi_setname("exynos4210-spi");
  361. }
  362. static void __init exynos5_map_io(void)
  363. {
  364. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  365. }
  366. static void __init exynos4_init_clocks(int xtal)
  367. {
  368. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  369. s3c24xx_register_baseclocks(xtal);
  370. s5p_register_clocks(xtal);
  371. if (soc_is_exynos4210())
  372. exynos4210_register_clocks();
  373. else if (soc_is_exynos4212() || soc_is_exynos4412())
  374. exynos4212_register_clocks();
  375. exynos4_register_clocks();
  376. exynos4_setup_clocks();
  377. }
  378. static void __init exynos5440_map_io(void)
  379. {
  380. iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
  381. }
  382. static void __init exynos5_init_clocks(int xtal)
  383. {
  384. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  385. /* EXYNOS5440 can support only common clock framework */
  386. if (soc_is_exynos5440())
  387. return;
  388. #ifdef CONFIG_SOC_EXYNOS5250
  389. s3c24xx_register_baseclocks(xtal);
  390. s5p_register_clocks(xtal);
  391. exynos5_register_clocks();
  392. exynos5_setup_clocks();
  393. #endif
  394. }
  395. void __init exynos4_init_irq(void)
  396. {
  397. unsigned int gic_bank_offset;
  398. gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
  399. if (!of_have_populated_dt())
  400. gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
  401. #ifdef CONFIG_OF
  402. else
  403. irqchip_init();
  404. #endif
  405. if (!of_have_populated_dt())
  406. combiner_init(S5P_VA_COMBINER_BASE, NULL);
  407. /*
  408. * The parameters of s5p_init_irq() are for VIC init.
  409. * Theses parameters should be NULL and 0 because EXYNOS4
  410. * uses GIC instead of VIC.
  411. */
  412. s5p_init_irq(NULL, 0);
  413. }
  414. void __init exynos5_init_irq(void)
  415. {
  416. #ifdef CONFIG_OF
  417. irqchip_init();
  418. #endif
  419. /*
  420. * The parameters of s5p_init_irq() are for VIC init.
  421. * Theses parameters should be NULL and 0 because EXYNOS4
  422. * uses GIC instead of VIC.
  423. */
  424. if (!of_machine_is_compatible("samsung,exynos5440"))
  425. s5p_init_irq(NULL, 0);
  426. gic_arch_extn.irq_set_wake = s3c_irq_wake;
  427. }
  428. struct bus_type exynos_subsys = {
  429. .name = "exynos-core",
  430. .dev_name = "exynos-core",
  431. };
  432. static struct device exynos4_dev = {
  433. .bus = &exynos_subsys,
  434. };
  435. static int __init exynos_core_init(void)
  436. {
  437. return subsys_system_register(&exynos_subsys, NULL);
  438. }
  439. core_initcall(exynos_core_init);
  440. #ifdef CONFIG_CACHE_L2X0
  441. static int __init exynos4_l2x0_cache_init(void)
  442. {
  443. int ret;
  444. if (soc_is_exynos5250() || soc_is_exynos5440())
  445. return 0;
  446. ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
  447. if (!ret) {
  448. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  449. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  450. return 0;
  451. }
  452. if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
  453. l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
  454. /* TAG, Data Latency Control: 2 cycles */
  455. l2x0_saved_regs.tag_latency = 0x110;
  456. if (soc_is_exynos4212() || soc_is_exynos4412())
  457. l2x0_saved_regs.data_latency = 0x120;
  458. else
  459. l2x0_saved_regs.data_latency = 0x110;
  460. l2x0_saved_regs.prefetch_ctrl = 0x30000007;
  461. l2x0_saved_regs.pwr_ctrl =
  462. (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
  463. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  464. __raw_writel(l2x0_saved_regs.tag_latency,
  465. S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
  466. __raw_writel(l2x0_saved_regs.data_latency,
  467. S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
  468. /* L2X0 Prefetch Control */
  469. __raw_writel(l2x0_saved_regs.prefetch_ctrl,
  470. S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
  471. /* L2X0 Power Control */
  472. __raw_writel(l2x0_saved_regs.pwr_ctrl,
  473. S5P_VA_L2CC + L2X0_POWER_CTRL);
  474. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  475. clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
  476. }
  477. l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
  478. return 0;
  479. }
  480. early_initcall(exynos4_l2x0_cache_init);
  481. #endif
  482. static int __init exynos_init(void)
  483. {
  484. printk(KERN_INFO "EXYNOS: Initializing architecture\n");
  485. return device_register(&exynos4_dev);
  486. }
  487. /* uart registration process */
  488. static void __init exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  489. {
  490. struct s3c2410_uartcfg *tcfg = cfg;
  491. u32 ucnt;
  492. for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
  493. tcfg->has_fracval = 1;
  494. s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no);
  495. }
  496. static void __iomem *exynos_eint_base;
  497. static DEFINE_SPINLOCK(eint_lock);
  498. static unsigned int eint0_15_data[16];
  499. static inline int exynos4_irq_to_gpio(unsigned int irq)
  500. {
  501. if (irq < IRQ_EINT(0))
  502. return -EINVAL;
  503. irq -= IRQ_EINT(0);
  504. if (irq < 8)
  505. return EXYNOS4_GPX0(irq);
  506. irq -= 8;
  507. if (irq < 8)
  508. return EXYNOS4_GPX1(irq);
  509. irq -= 8;
  510. if (irq < 8)
  511. return EXYNOS4_GPX2(irq);
  512. irq -= 8;
  513. if (irq < 8)
  514. return EXYNOS4_GPX3(irq);
  515. return -EINVAL;
  516. }
  517. static inline int exynos5_irq_to_gpio(unsigned int irq)
  518. {
  519. if (irq < IRQ_EINT(0))
  520. return -EINVAL;
  521. irq -= IRQ_EINT(0);
  522. if (irq < 8)
  523. return EXYNOS5_GPX0(irq);
  524. irq -= 8;
  525. if (irq < 8)
  526. return EXYNOS5_GPX1(irq);
  527. irq -= 8;
  528. if (irq < 8)
  529. return EXYNOS5_GPX2(irq);
  530. irq -= 8;
  531. if (irq < 8)
  532. return EXYNOS5_GPX3(irq);
  533. return -EINVAL;
  534. }
  535. static unsigned int exynos4_eint0_15_src_int[16] = {
  536. EXYNOS4_IRQ_EINT0,
  537. EXYNOS4_IRQ_EINT1,
  538. EXYNOS4_IRQ_EINT2,
  539. EXYNOS4_IRQ_EINT3,
  540. EXYNOS4_IRQ_EINT4,
  541. EXYNOS4_IRQ_EINT5,
  542. EXYNOS4_IRQ_EINT6,
  543. EXYNOS4_IRQ_EINT7,
  544. EXYNOS4_IRQ_EINT8,
  545. EXYNOS4_IRQ_EINT9,
  546. EXYNOS4_IRQ_EINT10,
  547. EXYNOS4_IRQ_EINT11,
  548. EXYNOS4_IRQ_EINT12,
  549. EXYNOS4_IRQ_EINT13,
  550. EXYNOS4_IRQ_EINT14,
  551. EXYNOS4_IRQ_EINT15,
  552. };
  553. static unsigned int exynos5_eint0_15_src_int[16] = {
  554. EXYNOS5_IRQ_EINT0,
  555. EXYNOS5_IRQ_EINT1,
  556. EXYNOS5_IRQ_EINT2,
  557. EXYNOS5_IRQ_EINT3,
  558. EXYNOS5_IRQ_EINT4,
  559. EXYNOS5_IRQ_EINT5,
  560. EXYNOS5_IRQ_EINT6,
  561. EXYNOS5_IRQ_EINT7,
  562. EXYNOS5_IRQ_EINT8,
  563. EXYNOS5_IRQ_EINT9,
  564. EXYNOS5_IRQ_EINT10,
  565. EXYNOS5_IRQ_EINT11,
  566. EXYNOS5_IRQ_EINT12,
  567. EXYNOS5_IRQ_EINT13,
  568. EXYNOS5_IRQ_EINT14,
  569. EXYNOS5_IRQ_EINT15,
  570. };
  571. static inline void exynos_irq_eint_mask(struct irq_data *data)
  572. {
  573. u32 mask;
  574. spin_lock(&eint_lock);
  575. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  576. mask |= EINT_OFFSET_BIT(data->irq);
  577. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  578. spin_unlock(&eint_lock);
  579. }
  580. static void exynos_irq_eint_unmask(struct irq_data *data)
  581. {
  582. u32 mask;
  583. spin_lock(&eint_lock);
  584. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  585. mask &= ~(EINT_OFFSET_BIT(data->irq));
  586. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  587. spin_unlock(&eint_lock);
  588. }
  589. static inline void exynos_irq_eint_ack(struct irq_data *data)
  590. {
  591. __raw_writel(EINT_OFFSET_BIT(data->irq),
  592. EINT_PEND(exynos_eint_base, data->irq));
  593. }
  594. static void exynos_irq_eint_maskack(struct irq_data *data)
  595. {
  596. exynos_irq_eint_mask(data);
  597. exynos_irq_eint_ack(data);
  598. }
  599. static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
  600. {
  601. int offs = EINT_OFFSET(data->irq);
  602. int shift;
  603. u32 ctrl, mask;
  604. u32 newvalue = 0;
  605. switch (type) {
  606. case IRQ_TYPE_EDGE_RISING:
  607. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  608. break;
  609. case IRQ_TYPE_EDGE_FALLING:
  610. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  611. break;
  612. case IRQ_TYPE_EDGE_BOTH:
  613. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  614. break;
  615. case IRQ_TYPE_LEVEL_LOW:
  616. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  617. break;
  618. case IRQ_TYPE_LEVEL_HIGH:
  619. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  620. break;
  621. default:
  622. printk(KERN_ERR "No such irq type %d", type);
  623. return -EINVAL;
  624. }
  625. shift = (offs & 0x7) * 4;
  626. mask = 0x7 << shift;
  627. spin_lock(&eint_lock);
  628. ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
  629. ctrl &= ~mask;
  630. ctrl |= newvalue << shift;
  631. __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
  632. spin_unlock(&eint_lock);
  633. if (soc_is_exynos5250())
  634. s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  635. else
  636. s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  637. return 0;
  638. }
  639. static struct irq_chip exynos_irq_eint = {
  640. .name = "exynos-eint",
  641. .irq_mask = exynos_irq_eint_mask,
  642. .irq_unmask = exynos_irq_eint_unmask,
  643. .irq_mask_ack = exynos_irq_eint_maskack,
  644. .irq_ack = exynos_irq_eint_ack,
  645. .irq_set_type = exynos_irq_eint_set_type,
  646. #ifdef CONFIG_PM
  647. .irq_set_wake = s3c_irqext_wake,
  648. #endif
  649. };
  650. /*
  651. * exynos4_irq_demux_eint
  652. *
  653. * This function demuxes the IRQ from from EINTs 16 to 31.
  654. * It is designed to be inlined into the specific handler
  655. * s5p_irq_demux_eintX_Y.
  656. *
  657. * Each EINT pend/mask registers handle eight of them.
  658. */
  659. static inline void exynos_irq_demux_eint(unsigned int start)
  660. {
  661. unsigned int irq;
  662. u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
  663. u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
  664. status &= ~mask;
  665. status &= 0xff;
  666. while (status) {
  667. irq = fls(status) - 1;
  668. generic_handle_irq(irq + start);
  669. status &= ~(1 << irq);
  670. }
  671. }
  672. static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  673. {
  674. struct irq_chip *chip = irq_get_chip(irq);
  675. chained_irq_enter(chip, desc);
  676. exynos_irq_demux_eint(IRQ_EINT(16));
  677. exynos_irq_demux_eint(IRQ_EINT(24));
  678. chained_irq_exit(chip, desc);
  679. }
  680. static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
  681. {
  682. u32 *irq_data = irq_get_handler_data(irq);
  683. struct irq_chip *chip = irq_get_chip(irq);
  684. chained_irq_enter(chip, desc);
  685. generic_handle_irq(*irq_data);
  686. chained_irq_exit(chip, desc);
  687. }
  688. static int __init exynos_init_irq_eint(void)
  689. {
  690. int irq;
  691. #ifdef CONFIG_PINCTRL_SAMSUNG
  692. /*
  693. * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
  694. * functionality along with support for external gpio and wakeup
  695. * interrupts. If the samsung pinctrl driver is enabled and includes
  696. * the wakeup interrupt support, then the setting up external wakeup
  697. * interrupts here can be skipped. This check here is temporary to
  698. * allow exynos4 platforms that do not use Samsung pinctrl driver to
  699. * co-exist with platforms that do. When all of the Samsung Exynos4
  700. * platforms switch over to using the pinctrl driver, the wakeup
  701. * interrupt support code here can be completely removed.
  702. */
  703. static const struct of_device_id exynos_pinctrl_ids[] = {
  704. { .compatible = "samsung,exynos4210-pinctrl", },
  705. { .compatible = "samsung,exynos4x12-pinctrl", },
  706. };
  707. struct device_node *pctrl_np, *wkup_np;
  708. const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
  709. for_each_matching_node(pctrl_np, exynos_pinctrl_ids) {
  710. if (of_device_is_available(pctrl_np)) {
  711. wkup_np = of_find_compatible_node(pctrl_np, NULL,
  712. wkup_compat);
  713. if (wkup_np)
  714. return -ENODEV;
  715. }
  716. }
  717. #endif
  718. if (soc_is_exynos5440())
  719. return 0;
  720. if (soc_is_exynos5250())
  721. exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  722. else
  723. exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  724. if (exynos_eint_base == NULL) {
  725. pr_err("unable to ioremap for EINT base address\n");
  726. return -ENOMEM;
  727. }
  728. for (irq = 0 ; irq <= 31 ; irq++) {
  729. irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
  730. handle_level_irq);
  731. set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
  732. }
  733. irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
  734. for (irq = 0 ; irq <= 15 ; irq++) {
  735. eint0_15_data[irq] = IRQ_EINT(irq);
  736. if (soc_is_exynos5250()) {
  737. irq_set_handler_data(exynos5_eint0_15_src_int[irq],
  738. &eint0_15_data[irq]);
  739. irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
  740. exynos_irq_eint0_15);
  741. } else {
  742. irq_set_handler_data(exynos4_eint0_15_src_int[irq],
  743. &eint0_15_data[irq]);
  744. irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
  745. exynos_irq_eint0_15);
  746. }
  747. }
  748. return 0;
  749. }
  750. arch_initcall(exynos_init_irq_eint);