common.c 22 KB

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