common.c 21 KB

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