common.c 22 KB

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