common.c 21 KB

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