common.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. exynos4_clk_init(NULL);
  370. exynos4_clk_register_fixed_ext(xxti_f, xusbxti_f);
  371. mct_init();
  372. }
  373. }
  374. void __init exynos4_init_irq(void)
  375. {
  376. unsigned int gic_bank_offset;
  377. gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
  378. if (!of_have_populated_dt())
  379. gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
  380. #ifdef CONFIG_OF
  381. else
  382. irqchip_init();
  383. #endif
  384. if (!of_have_populated_dt())
  385. combiner_init(S5P_VA_COMBINER_BASE, NULL);
  386. /*
  387. * The parameters of s5p_init_irq() are for VIC init.
  388. * Theses parameters should be NULL and 0 because EXYNOS4
  389. * uses GIC instead of VIC.
  390. */
  391. s5p_init_irq(NULL, 0);
  392. }
  393. void __init exynos5_init_irq(void)
  394. {
  395. #ifdef CONFIG_OF
  396. irqchip_init();
  397. #endif
  398. /*
  399. * The parameters of s5p_init_irq() are for VIC init.
  400. * Theses parameters should be NULL and 0 because EXYNOS4
  401. * uses GIC instead of VIC.
  402. */
  403. if (!of_machine_is_compatible("samsung,exynos5440"))
  404. s5p_init_irq(NULL, 0);
  405. gic_arch_extn.irq_set_wake = s3c_irq_wake;
  406. }
  407. struct bus_type exynos_subsys = {
  408. .name = "exynos-core",
  409. .dev_name = "exynos-core",
  410. };
  411. static struct device exynos4_dev = {
  412. .bus = &exynos_subsys,
  413. };
  414. static int __init exynos_core_init(void)
  415. {
  416. return subsys_system_register(&exynos_subsys, NULL);
  417. }
  418. core_initcall(exynos_core_init);
  419. #ifdef CONFIG_CACHE_L2X0
  420. static int __init exynos4_l2x0_cache_init(void)
  421. {
  422. int ret;
  423. if (soc_is_exynos5250() || soc_is_exynos5440())
  424. return 0;
  425. ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
  426. if (!ret) {
  427. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  428. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  429. return 0;
  430. }
  431. if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
  432. l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
  433. /* TAG, Data Latency Control: 2 cycles */
  434. l2x0_saved_regs.tag_latency = 0x110;
  435. if (soc_is_exynos4212() || soc_is_exynos4412())
  436. l2x0_saved_regs.data_latency = 0x120;
  437. else
  438. l2x0_saved_regs.data_latency = 0x110;
  439. l2x0_saved_regs.prefetch_ctrl = 0x30000007;
  440. l2x0_saved_regs.pwr_ctrl =
  441. (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
  442. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  443. __raw_writel(l2x0_saved_regs.tag_latency,
  444. S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
  445. __raw_writel(l2x0_saved_regs.data_latency,
  446. S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
  447. /* L2X0 Prefetch Control */
  448. __raw_writel(l2x0_saved_regs.prefetch_ctrl,
  449. S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
  450. /* L2X0 Power Control */
  451. __raw_writel(l2x0_saved_regs.pwr_ctrl,
  452. S5P_VA_L2CC + L2X0_POWER_CTRL);
  453. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  454. clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
  455. }
  456. l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
  457. return 0;
  458. }
  459. early_initcall(exynos4_l2x0_cache_init);
  460. #endif
  461. static int __init exynos_init(void)
  462. {
  463. printk(KERN_INFO "EXYNOS: Initializing architecture\n");
  464. return device_register(&exynos4_dev);
  465. }
  466. /* uart registration process */
  467. static void __init exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  468. {
  469. struct s3c2410_uartcfg *tcfg = cfg;
  470. u32 ucnt;
  471. for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
  472. tcfg->has_fracval = 1;
  473. s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no);
  474. }
  475. static void __iomem *exynos_eint_base;
  476. static DEFINE_SPINLOCK(eint_lock);
  477. static unsigned int eint0_15_data[16];
  478. static inline int exynos4_irq_to_gpio(unsigned int irq)
  479. {
  480. if (irq < IRQ_EINT(0))
  481. return -EINVAL;
  482. irq -= IRQ_EINT(0);
  483. if (irq < 8)
  484. return EXYNOS4_GPX0(irq);
  485. irq -= 8;
  486. if (irq < 8)
  487. return EXYNOS4_GPX1(irq);
  488. irq -= 8;
  489. if (irq < 8)
  490. return EXYNOS4_GPX2(irq);
  491. irq -= 8;
  492. if (irq < 8)
  493. return EXYNOS4_GPX3(irq);
  494. return -EINVAL;
  495. }
  496. static inline int exynos5_irq_to_gpio(unsigned int irq)
  497. {
  498. if (irq < IRQ_EINT(0))
  499. return -EINVAL;
  500. irq -= IRQ_EINT(0);
  501. if (irq < 8)
  502. return EXYNOS5_GPX0(irq);
  503. irq -= 8;
  504. if (irq < 8)
  505. return EXYNOS5_GPX1(irq);
  506. irq -= 8;
  507. if (irq < 8)
  508. return EXYNOS5_GPX2(irq);
  509. irq -= 8;
  510. if (irq < 8)
  511. return EXYNOS5_GPX3(irq);
  512. return -EINVAL;
  513. }
  514. static unsigned int exynos4_eint0_15_src_int[16] = {
  515. EXYNOS4_IRQ_EINT0,
  516. EXYNOS4_IRQ_EINT1,
  517. EXYNOS4_IRQ_EINT2,
  518. EXYNOS4_IRQ_EINT3,
  519. EXYNOS4_IRQ_EINT4,
  520. EXYNOS4_IRQ_EINT5,
  521. EXYNOS4_IRQ_EINT6,
  522. EXYNOS4_IRQ_EINT7,
  523. EXYNOS4_IRQ_EINT8,
  524. EXYNOS4_IRQ_EINT9,
  525. EXYNOS4_IRQ_EINT10,
  526. EXYNOS4_IRQ_EINT11,
  527. EXYNOS4_IRQ_EINT12,
  528. EXYNOS4_IRQ_EINT13,
  529. EXYNOS4_IRQ_EINT14,
  530. EXYNOS4_IRQ_EINT15,
  531. };
  532. static unsigned int exynos5_eint0_15_src_int[16] = {
  533. EXYNOS5_IRQ_EINT0,
  534. EXYNOS5_IRQ_EINT1,
  535. EXYNOS5_IRQ_EINT2,
  536. EXYNOS5_IRQ_EINT3,
  537. EXYNOS5_IRQ_EINT4,
  538. EXYNOS5_IRQ_EINT5,
  539. EXYNOS5_IRQ_EINT6,
  540. EXYNOS5_IRQ_EINT7,
  541. EXYNOS5_IRQ_EINT8,
  542. EXYNOS5_IRQ_EINT9,
  543. EXYNOS5_IRQ_EINT10,
  544. EXYNOS5_IRQ_EINT11,
  545. EXYNOS5_IRQ_EINT12,
  546. EXYNOS5_IRQ_EINT13,
  547. EXYNOS5_IRQ_EINT14,
  548. EXYNOS5_IRQ_EINT15,
  549. };
  550. static inline void exynos_irq_eint_mask(struct irq_data *data)
  551. {
  552. u32 mask;
  553. spin_lock(&eint_lock);
  554. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  555. mask |= EINT_OFFSET_BIT(data->irq);
  556. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  557. spin_unlock(&eint_lock);
  558. }
  559. static void exynos_irq_eint_unmask(struct irq_data *data)
  560. {
  561. u32 mask;
  562. spin_lock(&eint_lock);
  563. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  564. mask &= ~(EINT_OFFSET_BIT(data->irq));
  565. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  566. spin_unlock(&eint_lock);
  567. }
  568. static inline void exynos_irq_eint_ack(struct irq_data *data)
  569. {
  570. __raw_writel(EINT_OFFSET_BIT(data->irq),
  571. EINT_PEND(exynos_eint_base, data->irq));
  572. }
  573. static void exynos_irq_eint_maskack(struct irq_data *data)
  574. {
  575. exynos_irq_eint_mask(data);
  576. exynos_irq_eint_ack(data);
  577. }
  578. static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
  579. {
  580. int offs = EINT_OFFSET(data->irq);
  581. int shift;
  582. u32 ctrl, mask;
  583. u32 newvalue = 0;
  584. switch (type) {
  585. case IRQ_TYPE_EDGE_RISING:
  586. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  587. break;
  588. case IRQ_TYPE_EDGE_FALLING:
  589. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  590. break;
  591. case IRQ_TYPE_EDGE_BOTH:
  592. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  593. break;
  594. case IRQ_TYPE_LEVEL_LOW:
  595. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  596. break;
  597. case IRQ_TYPE_LEVEL_HIGH:
  598. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  599. break;
  600. default:
  601. printk(KERN_ERR "No such irq type %d", type);
  602. return -EINVAL;
  603. }
  604. shift = (offs & 0x7) * 4;
  605. mask = 0x7 << shift;
  606. spin_lock(&eint_lock);
  607. ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
  608. ctrl &= ~mask;
  609. ctrl |= newvalue << shift;
  610. __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
  611. spin_unlock(&eint_lock);
  612. if (soc_is_exynos5250())
  613. s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  614. else
  615. s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  616. return 0;
  617. }
  618. static struct irq_chip exynos_irq_eint = {
  619. .name = "exynos-eint",
  620. .irq_mask = exynos_irq_eint_mask,
  621. .irq_unmask = exynos_irq_eint_unmask,
  622. .irq_mask_ack = exynos_irq_eint_maskack,
  623. .irq_ack = exynos_irq_eint_ack,
  624. .irq_set_type = exynos_irq_eint_set_type,
  625. #ifdef CONFIG_PM
  626. .irq_set_wake = s3c_irqext_wake,
  627. #endif
  628. };
  629. /*
  630. * exynos4_irq_demux_eint
  631. *
  632. * This function demuxes the IRQ from from EINTs 16 to 31.
  633. * It is designed to be inlined into the specific handler
  634. * s5p_irq_demux_eintX_Y.
  635. *
  636. * Each EINT pend/mask registers handle eight of them.
  637. */
  638. static inline void exynos_irq_demux_eint(unsigned int start)
  639. {
  640. unsigned int irq;
  641. u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
  642. u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
  643. status &= ~mask;
  644. status &= 0xff;
  645. while (status) {
  646. irq = fls(status) - 1;
  647. generic_handle_irq(irq + start);
  648. status &= ~(1 << irq);
  649. }
  650. }
  651. static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  652. {
  653. struct irq_chip *chip = irq_get_chip(irq);
  654. chained_irq_enter(chip, desc);
  655. exynos_irq_demux_eint(IRQ_EINT(16));
  656. exynos_irq_demux_eint(IRQ_EINT(24));
  657. chained_irq_exit(chip, desc);
  658. }
  659. static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
  660. {
  661. u32 *irq_data = irq_get_handler_data(irq);
  662. struct irq_chip *chip = irq_get_chip(irq);
  663. chained_irq_enter(chip, desc);
  664. generic_handle_irq(*irq_data);
  665. chained_irq_exit(chip, desc);
  666. }
  667. static int __init exynos_init_irq_eint(void)
  668. {
  669. int irq;
  670. #ifdef CONFIG_PINCTRL_SAMSUNG
  671. /*
  672. * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
  673. * functionality along with support for external gpio and wakeup
  674. * interrupts. If the samsung pinctrl driver is enabled and includes
  675. * the wakeup interrupt support, then the setting up external wakeup
  676. * interrupts here can be skipped. This check here is temporary to
  677. * allow exynos4 platforms that do not use Samsung pinctrl driver to
  678. * co-exist with platforms that do. When all of the Samsung Exynos4
  679. * platforms switch over to using the pinctrl driver, the wakeup
  680. * interrupt support code here can be completely removed.
  681. */
  682. static const struct of_device_id exynos_pinctrl_ids[] = {
  683. { .compatible = "samsung,exynos4210-pinctrl", },
  684. { .compatible = "samsung,exynos4x12-pinctrl", },
  685. };
  686. struct device_node *pctrl_np, *wkup_np;
  687. const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
  688. for_each_matching_node(pctrl_np, exynos_pinctrl_ids) {
  689. if (of_device_is_available(pctrl_np)) {
  690. wkup_np = of_find_compatible_node(pctrl_np, NULL,
  691. wkup_compat);
  692. if (wkup_np)
  693. return -ENODEV;
  694. }
  695. }
  696. #endif
  697. if (soc_is_exynos5440())
  698. return 0;
  699. if (soc_is_exynos5250())
  700. exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  701. else
  702. exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  703. if (exynos_eint_base == NULL) {
  704. pr_err("unable to ioremap for EINT base address\n");
  705. return -ENOMEM;
  706. }
  707. for (irq = 0 ; irq <= 31 ; irq++) {
  708. irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
  709. handle_level_irq);
  710. set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
  711. }
  712. irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
  713. for (irq = 0 ; irq <= 15 ; irq++) {
  714. eint0_15_data[irq] = IRQ_EINT(irq);
  715. if (soc_is_exynos5250()) {
  716. irq_set_handler_data(exynos5_eint0_15_src_int[irq],
  717. &eint0_15_data[irq]);
  718. irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
  719. exynos_irq_eint0_15);
  720. } else {
  721. irq_set_handler_data(exynos4_eint0_15_src_int[irq],
  722. &eint0_15_data[irq]);
  723. irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
  724. exynos_irq_eint0_15);
  725. }
  726. }
  727. return 0;
  728. }
  729. arch_initcall(exynos_init_irq_eint);