common.c 20 KB

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