common.c 21 KB

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