common.c 20 KB

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