common.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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. if (!IS_ENABLED(CONFIG_EXYNOS_ATAGS))
  340. return
  341. /* initialize device information early */
  342. exynos4_default_sdhci0();
  343. exynos4_default_sdhci1();
  344. exynos4_default_sdhci2();
  345. exynos4_default_sdhci3();
  346. s3c_adc_setname("samsung-adc-v3");
  347. s3c_fimc_setname(0, "exynos4-fimc");
  348. s3c_fimc_setname(1, "exynos4-fimc");
  349. s3c_fimc_setname(2, "exynos4-fimc");
  350. s3c_fimc_setname(3, "exynos4-fimc");
  351. s3c_sdhci_setname(0, "exynos4-sdhci");
  352. s3c_sdhci_setname(1, "exynos4-sdhci");
  353. s3c_sdhci_setname(2, "exynos4-sdhci");
  354. s3c_sdhci_setname(3, "exynos4-sdhci");
  355. /* The I2C bus controllers are directly compatible with s3c2440 */
  356. s3c_i2c0_setname("s3c2440-i2c");
  357. s3c_i2c1_setname("s3c2440-i2c");
  358. s3c_i2c2_setname("s3c2440-i2c");
  359. s5p_fb_setname(0, "exynos4-fb");
  360. s5p_hdmi_setname("exynos4-hdmi");
  361. s3c64xx_spi_setname("exynos4210-spi");
  362. }
  363. static void __init exynos5_map_io(void)
  364. {
  365. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  366. }
  367. static void __init exynos4_init_clocks(int xtal)
  368. {
  369. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  370. s3c24xx_register_baseclocks(xtal);
  371. s5p_register_clocks(xtal);
  372. if (soc_is_exynos4210())
  373. exynos4210_register_clocks();
  374. else if (soc_is_exynos4212() || soc_is_exynos4412())
  375. exynos4212_register_clocks();
  376. exynos4_register_clocks();
  377. exynos4_setup_clocks();
  378. }
  379. static void __init exynos5440_map_io(void)
  380. {
  381. iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
  382. }
  383. static void __init exynos5_init_clocks(int xtal)
  384. {
  385. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  386. /* EXYNOS5440 can support only common clock framework */
  387. if (soc_is_exynos5440())
  388. return;
  389. #ifdef CONFIG_SOC_EXYNOS5250
  390. s3c24xx_register_baseclocks(xtal);
  391. s5p_register_clocks(xtal);
  392. exynos5_register_clocks();
  393. exynos5_setup_clocks();
  394. #endif
  395. }
  396. void __init exynos4_init_irq(void)
  397. {
  398. unsigned int gic_bank_offset;
  399. gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
  400. if (!of_have_populated_dt())
  401. gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
  402. #ifdef CONFIG_OF
  403. else
  404. irqchip_init();
  405. #endif
  406. if (!of_have_populated_dt())
  407. combiner_init(S5P_VA_COMBINER_BASE, NULL);
  408. /*
  409. * The parameters of s5p_init_irq() are for VIC init.
  410. * Theses parameters should be NULL and 0 because EXYNOS4
  411. * uses GIC instead of VIC.
  412. */
  413. s5p_init_irq(NULL, 0);
  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. #ifdef CONFIG_EXYNOS_ATAGS
  498. static void __iomem *exynos_eint_base;
  499. static DEFINE_SPINLOCK(eint_lock);
  500. static unsigned int eint0_15_data[16];
  501. static inline int exynos4_irq_to_gpio(unsigned int irq)
  502. {
  503. if (irq < IRQ_EINT(0))
  504. return -EINVAL;
  505. irq -= IRQ_EINT(0);
  506. if (irq < 8)
  507. return EXYNOS4_GPX0(irq);
  508. irq -= 8;
  509. if (irq < 8)
  510. return EXYNOS4_GPX1(irq);
  511. irq -= 8;
  512. if (irq < 8)
  513. return EXYNOS4_GPX2(irq);
  514. irq -= 8;
  515. if (irq < 8)
  516. return EXYNOS4_GPX3(irq);
  517. return -EINVAL;
  518. }
  519. static inline int exynos5_irq_to_gpio(unsigned int irq)
  520. {
  521. if (irq < IRQ_EINT(0))
  522. return -EINVAL;
  523. irq -= IRQ_EINT(0);
  524. if (irq < 8)
  525. return EXYNOS5_GPX0(irq);
  526. irq -= 8;
  527. if (irq < 8)
  528. return EXYNOS5_GPX1(irq);
  529. irq -= 8;
  530. if (irq < 8)
  531. return EXYNOS5_GPX2(irq);
  532. irq -= 8;
  533. if (irq < 8)
  534. return EXYNOS5_GPX3(irq);
  535. return -EINVAL;
  536. }
  537. static unsigned int exynos4_eint0_15_src_int[16] = {
  538. EXYNOS4_IRQ_EINT0,
  539. EXYNOS4_IRQ_EINT1,
  540. EXYNOS4_IRQ_EINT2,
  541. EXYNOS4_IRQ_EINT3,
  542. EXYNOS4_IRQ_EINT4,
  543. EXYNOS4_IRQ_EINT5,
  544. EXYNOS4_IRQ_EINT6,
  545. EXYNOS4_IRQ_EINT7,
  546. EXYNOS4_IRQ_EINT8,
  547. EXYNOS4_IRQ_EINT9,
  548. EXYNOS4_IRQ_EINT10,
  549. EXYNOS4_IRQ_EINT11,
  550. EXYNOS4_IRQ_EINT12,
  551. EXYNOS4_IRQ_EINT13,
  552. EXYNOS4_IRQ_EINT14,
  553. EXYNOS4_IRQ_EINT15,
  554. };
  555. static unsigned int exynos5_eint0_15_src_int[16] = {
  556. EXYNOS5_IRQ_EINT0,
  557. EXYNOS5_IRQ_EINT1,
  558. EXYNOS5_IRQ_EINT2,
  559. EXYNOS5_IRQ_EINT3,
  560. EXYNOS5_IRQ_EINT4,
  561. EXYNOS5_IRQ_EINT5,
  562. EXYNOS5_IRQ_EINT6,
  563. EXYNOS5_IRQ_EINT7,
  564. EXYNOS5_IRQ_EINT8,
  565. EXYNOS5_IRQ_EINT9,
  566. EXYNOS5_IRQ_EINT10,
  567. EXYNOS5_IRQ_EINT11,
  568. EXYNOS5_IRQ_EINT12,
  569. EXYNOS5_IRQ_EINT13,
  570. EXYNOS5_IRQ_EINT14,
  571. EXYNOS5_IRQ_EINT15,
  572. };
  573. static inline void exynos_irq_eint_mask(struct irq_data *data)
  574. {
  575. u32 mask;
  576. spin_lock(&eint_lock);
  577. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  578. mask |= EINT_OFFSET_BIT(data->irq);
  579. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  580. spin_unlock(&eint_lock);
  581. }
  582. static void exynos_irq_eint_unmask(struct irq_data *data)
  583. {
  584. u32 mask;
  585. spin_lock(&eint_lock);
  586. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  587. mask &= ~(EINT_OFFSET_BIT(data->irq));
  588. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  589. spin_unlock(&eint_lock);
  590. }
  591. static inline void exynos_irq_eint_ack(struct irq_data *data)
  592. {
  593. __raw_writel(EINT_OFFSET_BIT(data->irq),
  594. EINT_PEND(exynos_eint_base, data->irq));
  595. }
  596. static void exynos_irq_eint_maskack(struct irq_data *data)
  597. {
  598. exynos_irq_eint_mask(data);
  599. exynos_irq_eint_ack(data);
  600. }
  601. static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
  602. {
  603. int offs = EINT_OFFSET(data->irq);
  604. int shift;
  605. u32 ctrl, mask;
  606. u32 newvalue = 0;
  607. switch (type) {
  608. case IRQ_TYPE_EDGE_RISING:
  609. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  610. break;
  611. case IRQ_TYPE_EDGE_FALLING:
  612. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  613. break;
  614. case IRQ_TYPE_EDGE_BOTH:
  615. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  616. break;
  617. case IRQ_TYPE_LEVEL_LOW:
  618. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  619. break;
  620. case IRQ_TYPE_LEVEL_HIGH:
  621. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  622. break;
  623. default:
  624. printk(KERN_ERR "No such irq type %d", type);
  625. return -EINVAL;
  626. }
  627. shift = (offs & 0x7) * 4;
  628. mask = 0x7 << shift;
  629. spin_lock(&eint_lock);
  630. ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
  631. ctrl &= ~mask;
  632. ctrl |= newvalue << shift;
  633. __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
  634. spin_unlock(&eint_lock);
  635. if (soc_is_exynos5250())
  636. s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  637. else
  638. s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  639. return 0;
  640. }
  641. static struct irq_chip exynos_irq_eint = {
  642. .name = "exynos-eint",
  643. .irq_mask = exynos_irq_eint_mask,
  644. .irq_unmask = exynos_irq_eint_unmask,
  645. .irq_mask_ack = exynos_irq_eint_maskack,
  646. .irq_ack = exynos_irq_eint_ack,
  647. .irq_set_type = exynos_irq_eint_set_type,
  648. #ifdef CONFIG_PM
  649. .irq_set_wake = s3c_irqext_wake,
  650. #endif
  651. };
  652. /*
  653. * exynos4_irq_demux_eint
  654. *
  655. * This function demuxes the IRQ from from EINTs 16 to 31.
  656. * It is designed to be inlined into the specific handler
  657. * s5p_irq_demux_eintX_Y.
  658. *
  659. * Each EINT pend/mask registers handle eight of them.
  660. */
  661. static inline void exynos_irq_demux_eint(unsigned int start)
  662. {
  663. unsigned int irq;
  664. u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
  665. u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
  666. status &= ~mask;
  667. status &= 0xff;
  668. while (status) {
  669. irq = fls(status) - 1;
  670. generic_handle_irq(irq + start);
  671. status &= ~(1 << irq);
  672. }
  673. }
  674. static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  675. {
  676. struct irq_chip *chip = irq_get_chip(irq);
  677. chained_irq_enter(chip, desc);
  678. exynos_irq_demux_eint(IRQ_EINT(16));
  679. exynos_irq_demux_eint(IRQ_EINT(24));
  680. chained_irq_exit(chip, desc);
  681. }
  682. static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
  683. {
  684. u32 *irq_data = irq_get_handler_data(irq);
  685. struct irq_chip *chip = irq_get_chip(irq);
  686. chained_irq_enter(chip, desc);
  687. generic_handle_irq(*irq_data);
  688. chained_irq_exit(chip, desc);
  689. }
  690. static int __init exynos_init_irq_eint(void)
  691. {
  692. int irq;
  693. #ifdef CONFIG_PINCTRL_SAMSUNG
  694. /*
  695. * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
  696. * functionality along with support for external gpio and wakeup
  697. * interrupts. If the samsung pinctrl driver is enabled and includes
  698. * the wakeup interrupt support, then the setting up external wakeup
  699. * interrupts here can be skipped. This check here is temporary to
  700. * allow exynos4 platforms that do not use Samsung pinctrl driver to
  701. * co-exist with platforms that do. When all of the Samsung Exynos4
  702. * platforms switch over to using the pinctrl driver, the wakeup
  703. * interrupt support code here can be completely removed.
  704. */
  705. static const struct of_device_id exynos_pinctrl_ids[] = {
  706. { .compatible = "samsung,exynos4210-pinctrl", },
  707. { .compatible = "samsung,exynos4x12-pinctrl", },
  708. };
  709. struct device_node *pctrl_np, *wkup_np;
  710. const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
  711. for_each_matching_node(pctrl_np, exynos_pinctrl_ids) {
  712. if (of_device_is_available(pctrl_np)) {
  713. wkup_np = of_find_compatible_node(pctrl_np, NULL,
  714. wkup_compat);
  715. if (wkup_np)
  716. return -ENODEV;
  717. }
  718. }
  719. #endif
  720. if (soc_is_exynos5440())
  721. return 0;
  722. if (soc_is_exynos5250())
  723. exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  724. else
  725. exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  726. if (exynos_eint_base == NULL) {
  727. pr_err("unable to ioremap for EINT base address\n");
  728. return -ENOMEM;
  729. }
  730. for (irq = 0 ; irq <= 31 ; irq++) {
  731. irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
  732. handle_level_irq);
  733. set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
  734. }
  735. irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
  736. for (irq = 0 ; irq <= 15 ; irq++) {
  737. eint0_15_data[irq] = IRQ_EINT(irq);
  738. if (soc_is_exynos5250()) {
  739. irq_set_handler_data(exynos5_eint0_15_src_int[irq],
  740. &eint0_15_data[irq]);
  741. irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
  742. exynos_irq_eint0_15);
  743. } else {
  744. irq_set_handler_data(exynos4_eint0_15_src_int[irq],
  745. &eint0_15_data[irq]);
  746. irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
  747. exynos_irq_eint0_15);
  748. }
  749. }
  750. return 0;
  751. }
  752. arch_initcall(exynos_init_irq_eint);
  753. #endif