common.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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/io.h>
  15. #include <linux/device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/sched.h>
  18. #include <linux/serial_core.h>
  19. #include <linux/of.h>
  20. #include <linux/of_fdt.h>
  21. #include <linux/of_irq.h>
  22. #include <linux/export.h>
  23. #include <linux/irqdomain.h>
  24. #include <linux/irqchip.h>
  25. #include <linux/of_address.h>
  26. #include <asm/proc-fns.h>
  27. #include <asm/exception.h>
  28. #include <asm/hardware/cache-l2x0.h>
  29. #include <asm/hardware/gic.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 <mach/pmu.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. 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. val = (0x10 << 20) | (0x1 << 16);
  292. addr = EXYNOS5440_SWRESET;
  293. } else {
  294. pr_err("%s: cannot support non-DT\n", __func__);
  295. return;
  296. }
  297. __raw_writel(val, addr);
  298. }
  299. void __init exynos_init_late(void)
  300. {
  301. if (of_machine_is_compatible("samsung,exynos5440"))
  302. /* to be supported later */
  303. return;
  304. exynos_pm_late_initcall();
  305. }
  306. /*
  307. * exynos_map_io
  308. *
  309. * register the standard cpu IO areas
  310. */
  311. void __init exynos_init_io(struct map_desc *mach_desc, int size)
  312. {
  313. struct map_desc *iodesc = exynos_iodesc;
  314. int iodesc_sz = ARRAY_SIZE(exynos_iodesc);
  315. #if defined(CONFIG_OF) && defined(CONFIG_ARCH_EXYNOS5)
  316. unsigned long root = of_get_flat_dt_root();
  317. /* initialize the io descriptors we need for initialization */
  318. if (of_flat_dt_is_compatible(root, "samsung,exynos5440")) {
  319. iodesc = exynos5440_iodesc;
  320. iodesc_sz = ARRAY_SIZE(exynos5440_iodesc);
  321. }
  322. #endif
  323. iotable_init(iodesc, iodesc_sz);
  324. if (mach_desc)
  325. iotable_init(mach_desc, size);
  326. /* detect cpu id and rev. */
  327. s5p_init_cpu(S5P_VA_CHIPID);
  328. s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
  329. }
  330. static void __init exynos4_map_io(void)
  331. {
  332. iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
  333. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
  334. iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
  335. else
  336. iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
  337. /* initialize device information early */
  338. exynos4_default_sdhci0();
  339. exynos4_default_sdhci1();
  340. exynos4_default_sdhci2();
  341. exynos4_default_sdhci3();
  342. s3c_adc_setname("samsung-adc-v3");
  343. s3c_fimc_setname(0, "exynos4-fimc");
  344. s3c_fimc_setname(1, "exynos4-fimc");
  345. s3c_fimc_setname(2, "exynos4-fimc");
  346. s3c_fimc_setname(3, "exynos4-fimc");
  347. s3c_sdhci_setname(0, "exynos4-sdhci");
  348. s3c_sdhci_setname(1, "exynos4-sdhci");
  349. s3c_sdhci_setname(2, "exynos4-sdhci");
  350. s3c_sdhci_setname(3, "exynos4-sdhci");
  351. /* The I2C bus controllers are directly compatible with s3c2440 */
  352. s3c_i2c0_setname("s3c2440-i2c");
  353. s3c_i2c1_setname("s3c2440-i2c");
  354. s3c_i2c2_setname("s3c2440-i2c");
  355. s5p_fb_setname(0, "exynos4-fb");
  356. s5p_hdmi_setname("exynos4-hdmi");
  357. s3c64xx_spi_setname("exynos4210-spi");
  358. }
  359. static void __init exynos5_map_io(void)
  360. {
  361. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  362. }
  363. static void __init exynos4_init_clocks(int xtal)
  364. {
  365. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  366. s3c24xx_register_baseclocks(xtal);
  367. s5p_register_clocks(xtal);
  368. if (soc_is_exynos4210())
  369. exynos4210_register_clocks();
  370. else if (soc_is_exynos4212() || soc_is_exynos4412())
  371. exynos4212_register_clocks();
  372. exynos4_register_clocks();
  373. exynos4_setup_clocks();
  374. }
  375. static void __init exynos5440_map_io(void)
  376. {
  377. iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
  378. }
  379. static void __init exynos5_init_clocks(int xtal)
  380. {
  381. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  382. /* EXYNOS5440 can support only common clock framework */
  383. if (soc_is_exynos5440())
  384. return;
  385. #ifdef CONFIG_SOC_EXYNOS5250
  386. s3c24xx_register_baseclocks(xtal);
  387. s5p_register_clocks(xtal);
  388. exynos5_register_clocks();
  389. exynos5_setup_clocks();
  390. #endif
  391. }
  392. #define COMBINER_ENABLE_SET 0x0
  393. #define COMBINER_ENABLE_CLEAR 0x4
  394. #define COMBINER_INT_STATUS 0xC
  395. static DEFINE_SPINLOCK(irq_controller_lock);
  396. struct combiner_chip_data {
  397. unsigned int irq_offset;
  398. unsigned int irq_mask;
  399. void __iomem *base;
  400. };
  401. static struct irq_domain *combiner_irq_domain;
  402. static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
  403. static inline void __iomem *combiner_base(struct irq_data *data)
  404. {
  405. struct combiner_chip_data *combiner_data =
  406. irq_data_get_irq_chip_data(data);
  407. return combiner_data->base;
  408. }
  409. static void combiner_mask_irq(struct irq_data *data)
  410. {
  411. u32 mask = 1 << (data->hwirq % 32);
  412. __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
  413. }
  414. static void combiner_unmask_irq(struct irq_data *data)
  415. {
  416. u32 mask = 1 << (data->hwirq % 32);
  417. __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
  418. }
  419. static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
  420. {
  421. struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
  422. struct irq_chip *chip = irq_get_chip(irq);
  423. unsigned int cascade_irq, combiner_irq;
  424. unsigned long status;
  425. chained_irq_enter(chip, desc);
  426. spin_lock(&irq_controller_lock);
  427. status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
  428. spin_unlock(&irq_controller_lock);
  429. status &= chip_data->irq_mask;
  430. if (status == 0)
  431. goto out;
  432. combiner_irq = __ffs(status);
  433. cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
  434. if (unlikely(cascade_irq >= NR_IRQS))
  435. do_bad_IRQ(cascade_irq, desc);
  436. else
  437. generic_handle_irq(cascade_irq);
  438. out:
  439. chained_irq_exit(chip, desc);
  440. }
  441. static struct irq_chip combiner_chip = {
  442. .name = "COMBINER",
  443. .irq_mask = combiner_mask_irq,
  444. .irq_unmask = combiner_unmask_irq,
  445. };
  446. static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
  447. {
  448. unsigned int max_nr;
  449. if (soc_is_exynos5250())
  450. max_nr = EXYNOS5_MAX_COMBINER_NR;
  451. else
  452. max_nr = EXYNOS4_MAX_COMBINER_NR;
  453. if (combiner_nr >= max_nr)
  454. BUG();
  455. if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
  456. BUG();
  457. irq_set_chained_handler(irq, combiner_handle_cascade_irq);
  458. }
  459. static void __init combiner_init_one(unsigned int combiner_nr,
  460. void __iomem *base)
  461. {
  462. combiner_data[combiner_nr].base = base;
  463. combiner_data[combiner_nr].irq_offset = irq_find_mapping(
  464. combiner_irq_domain, combiner_nr * MAX_IRQ_IN_COMBINER);
  465. combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3);
  466. /* Disable all interrupts */
  467. __raw_writel(combiner_data[combiner_nr].irq_mask,
  468. base + COMBINER_ENABLE_CLEAR);
  469. }
  470. #ifdef CONFIG_OF
  471. static int combiner_irq_domain_xlate(struct irq_domain *d,
  472. struct device_node *controller,
  473. const u32 *intspec, unsigned int intsize,
  474. unsigned long *out_hwirq,
  475. unsigned int *out_type)
  476. {
  477. if (d->of_node != controller)
  478. return -EINVAL;
  479. if (intsize < 2)
  480. return -EINVAL;
  481. *out_hwirq = intspec[0] * MAX_IRQ_IN_COMBINER + intspec[1];
  482. *out_type = 0;
  483. return 0;
  484. }
  485. #else
  486. static int combiner_irq_domain_xlate(struct irq_domain *d,
  487. struct device_node *controller,
  488. const u32 *intspec, unsigned int intsize,
  489. unsigned long *out_hwirq,
  490. unsigned int *out_type)
  491. {
  492. return -EINVAL;
  493. }
  494. #endif
  495. static int combiner_irq_domain_map(struct irq_domain *d, unsigned int irq,
  496. irq_hw_number_t hw)
  497. {
  498. irq_set_chip_and_handler(irq, &combiner_chip, handle_level_irq);
  499. irq_set_chip_data(irq, &combiner_data[hw >> 3]);
  500. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  501. return 0;
  502. }
  503. static struct irq_domain_ops combiner_irq_domain_ops = {
  504. .xlate = combiner_irq_domain_xlate,
  505. .map = combiner_irq_domain_map,
  506. };
  507. static void __init combiner_init(void __iomem *combiner_base,
  508. struct device_node *np)
  509. {
  510. int i, irq, irq_base;
  511. unsigned int max_nr, nr_irq;
  512. if (np) {
  513. if (of_property_read_u32(np, "samsung,combiner-nr", &max_nr)) {
  514. pr_warning("%s: number of combiners not specified, "
  515. "setting default as %d.\n",
  516. __func__, EXYNOS4_MAX_COMBINER_NR);
  517. max_nr = EXYNOS4_MAX_COMBINER_NR;
  518. }
  519. } else {
  520. max_nr = soc_is_exynos5250() ? EXYNOS5_MAX_COMBINER_NR :
  521. EXYNOS4_MAX_COMBINER_NR;
  522. }
  523. nr_irq = max_nr * MAX_IRQ_IN_COMBINER;
  524. irq_base = irq_alloc_descs(COMBINER_IRQ(0, 0), 1, nr_irq, 0);
  525. if (IS_ERR_VALUE(irq_base)) {
  526. irq_base = COMBINER_IRQ(0, 0);
  527. pr_warning("%s: irq desc alloc failed. Continuing with %d as linux irq base\n", __func__, irq_base);
  528. }
  529. combiner_irq_domain = irq_domain_add_legacy(np, nr_irq, irq_base, 0,
  530. &combiner_irq_domain_ops, &combiner_data);
  531. if (WARN_ON(!combiner_irq_domain)) {
  532. pr_warning("%s: irq domain init failed\n", __func__);
  533. return;
  534. }
  535. for (i = 0; i < max_nr; i++) {
  536. combiner_init_one(i, combiner_base + (i >> 2) * 0x10);
  537. irq = IRQ_SPI(i);
  538. #ifdef CONFIG_OF
  539. if (np)
  540. irq = irq_of_parse_and_map(np, i);
  541. #endif
  542. combiner_cascade_irq(i, irq);
  543. }
  544. }
  545. #ifdef CONFIG_OF
  546. static int __init combiner_of_init(struct device_node *np,
  547. struct device_node *parent)
  548. {
  549. void __iomem *combiner_base;
  550. combiner_base = of_iomap(np, 0);
  551. if (!combiner_base) {
  552. pr_err("%s: failed to map combiner registers\n", __func__);
  553. return -ENXIO;
  554. }
  555. combiner_init(combiner_base, np);
  556. return 0;
  557. }
  558. static const struct of_device_id exynos_dt_irq_match[] = {
  559. { .compatible = "samsung,exynos4210-combiner",
  560. .data = combiner_of_init, },
  561. {},
  562. };
  563. #endif
  564. void __init exynos4_init_irq(void)
  565. {
  566. unsigned int gic_bank_offset;
  567. gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
  568. if (!of_have_populated_dt())
  569. gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
  570. #ifdef CONFIG_OF
  571. else {
  572. irqchip_init();
  573. of_irq_init(exynos_dt_irq_match);
  574. }
  575. #endif
  576. if (!of_have_populated_dt())
  577. combiner_init(S5P_VA_COMBINER_BASE, NULL);
  578. /*
  579. * The parameters of s5p_init_irq() are for VIC init.
  580. * Theses parameters should be NULL and 0 because EXYNOS4
  581. * uses GIC instead of VIC.
  582. */
  583. s5p_init_irq(NULL, 0);
  584. }
  585. void __init exynos5_init_irq(void)
  586. {
  587. #ifdef CONFIG_OF
  588. irqchip_init();
  589. of_irq_init(exynos_dt_irq_match);
  590. #endif
  591. /*
  592. * The parameters of s5p_init_irq() are for VIC init.
  593. * Theses parameters should be NULL and 0 because EXYNOS4
  594. * uses GIC instead of VIC.
  595. */
  596. if (!of_machine_is_compatible("samsung,exynos5440"))
  597. s5p_init_irq(NULL, 0);
  598. gic_arch_extn.irq_set_wake = s3c_irq_wake;
  599. }
  600. struct bus_type exynos_subsys = {
  601. .name = "exynos-core",
  602. .dev_name = "exynos-core",
  603. };
  604. static struct device exynos4_dev = {
  605. .bus = &exynos_subsys,
  606. };
  607. static int __init exynos_core_init(void)
  608. {
  609. return subsys_system_register(&exynos_subsys, NULL);
  610. }
  611. core_initcall(exynos_core_init);
  612. #ifdef CONFIG_CACHE_L2X0
  613. static int __init exynos4_l2x0_cache_init(void)
  614. {
  615. int ret;
  616. if (soc_is_exynos5250() || soc_is_exynos5440())
  617. return 0;
  618. ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
  619. if (!ret) {
  620. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  621. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  622. return 0;
  623. }
  624. if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
  625. l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
  626. /* TAG, Data Latency Control: 2 cycles */
  627. l2x0_saved_regs.tag_latency = 0x110;
  628. if (soc_is_exynos4212() || soc_is_exynos4412())
  629. l2x0_saved_regs.data_latency = 0x120;
  630. else
  631. l2x0_saved_regs.data_latency = 0x110;
  632. l2x0_saved_regs.prefetch_ctrl = 0x30000007;
  633. l2x0_saved_regs.pwr_ctrl =
  634. (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
  635. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  636. __raw_writel(l2x0_saved_regs.tag_latency,
  637. S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
  638. __raw_writel(l2x0_saved_regs.data_latency,
  639. S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
  640. /* L2X0 Prefetch Control */
  641. __raw_writel(l2x0_saved_regs.prefetch_ctrl,
  642. S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
  643. /* L2X0 Power Control */
  644. __raw_writel(l2x0_saved_regs.pwr_ctrl,
  645. S5P_VA_L2CC + L2X0_POWER_CTRL);
  646. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  647. clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
  648. }
  649. l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
  650. return 0;
  651. }
  652. early_initcall(exynos4_l2x0_cache_init);
  653. #endif
  654. static int __init exynos_init(void)
  655. {
  656. printk(KERN_INFO "EXYNOS: Initializing architecture\n");
  657. return device_register(&exynos4_dev);
  658. }
  659. /* uart registration process */
  660. static void __init exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  661. {
  662. struct s3c2410_uartcfg *tcfg = cfg;
  663. u32 ucnt;
  664. for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
  665. tcfg->has_fracval = 1;
  666. s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no);
  667. }
  668. static void __iomem *exynos_eint_base;
  669. static DEFINE_SPINLOCK(eint_lock);
  670. static unsigned int eint0_15_data[16];
  671. static inline int exynos4_irq_to_gpio(unsigned int irq)
  672. {
  673. if (irq < IRQ_EINT(0))
  674. return -EINVAL;
  675. irq -= IRQ_EINT(0);
  676. if (irq < 8)
  677. return EXYNOS4_GPX0(irq);
  678. irq -= 8;
  679. if (irq < 8)
  680. return EXYNOS4_GPX1(irq);
  681. irq -= 8;
  682. if (irq < 8)
  683. return EXYNOS4_GPX2(irq);
  684. irq -= 8;
  685. if (irq < 8)
  686. return EXYNOS4_GPX3(irq);
  687. return -EINVAL;
  688. }
  689. static inline int exynos5_irq_to_gpio(unsigned int irq)
  690. {
  691. if (irq < IRQ_EINT(0))
  692. return -EINVAL;
  693. irq -= IRQ_EINT(0);
  694. if (irq < 8)
  695. return EXYNOS5_GPX0(irq);
  696. irq -= 8;
  697. if (irq < 8)
  698. return EXYNOS5_GPX1(irq);
  699. irq -= 8;
  700. if (irq < 8)
  701. return EXYNOS5_GPX2(irq);
  702. irq -= 8;
  703. if (irq < 8)
  704. return EXYNOS5_GPX3(irq);
  705. return -EINVAL;
  706. }
  707. static unsigned int exynos4_eint0_15_src_int[16] = {
  708. EXYNOS4_IRQ_EINT0,
  709. EXYNOS4_IRQ_EINT1,
  710. EXYNOS4_IRQ_EINT2,
  711. EXYNOS4_IRQ_EINT3,
  712. EXYNOS4_IRQ_EINT4,
  713. EXYNOS4_IRQ_EINT5,
  714. EXYNOS4_IRQ_EINT6,
  715. EXYNOS4_IRQ_EINT7,
  716. EXYNOS4_IRQ_EINT8,
  717. EXYNOS4_IRQ_EINT9,
  718. EXYNOS4_IRQ_EINT10,
  719. EXYNOS4_IRQ_EINT11,
  720. EXYNOS4_IRQ_EINT12,
  721. EXYNOS4_IRQ_EINT13,
  722. EXYNOS4_IRQ_EINT14,
  723. EXYNOS4_IRQ_EINT15,
  724. };
  725. static unsigned int exynos5_eint0_15_src_int[16] = {
  726. EXYNOS5_IRQ_EINT0,
  727. EXYNOS5_IRQ_EINT1,
  728. EXYNOS5_IRQ_EINT2,
  729. EXYNOS5_IRQ_EINT3,
  730. EXYNOS5_IRQ_EINT4,
  731. EXYNOS5_IRQ_EINT5,
  732. EXYNOS5_IRQ_EINT6,
  733. EXYNOS5_IRQ_EINT7,
  734. EXYNOS5_IRQ_EINT8,
  735. EXYNOS5_IRQ_EINT9,
  736. EXYNOS5_IRQ_EINT10,
  737. EXYNOS5_IRQ_EINT11,
  738. EXYNOS5_IRQ_EINT12,
  739. EXYNOS5_IRQ_EINT13,
  740. EXYNOS5_IRQ_EINT14,
  741. EXYNOS5_IRQ_EINT15,
  742. };
  743. static inline void exynos_irq_eint_mask(struct irq_data *data)
  744. {
  745. u32 mask;
  746. spin_lock(&eint_lock);
  747. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  748. mask |= EINT_OFFSET_BIT(data->irq);
  749. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  750. spin_unlock(&eint_lock);
  751. }
  752. static void exynos_irq_eint_unmask(struct irq_data *data)
  753. {
  754. u32 mask;
  755. spin_lock(&eint_lock);
  756. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  757. mask &= ~(EINT_OFFSET_BIT(data->irq));
  758. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  759. spin_unlock(&eint_lock);
  760. }
  761. static inline void exynos_irq_eint_ack(struct irq_data *data)
  762. {
  763. __raw_writel(EINT_OFFSET_BIT(data->irq),
  764. EINT_PEND(exynos_eint_base, data->irq));
  765. }
  766. static void exynos_irq_eint_maskack(struct irq_data *data)
  767. {
  768. exynos_irq_eint_mask(data);
  769. exynos_irq_eint_ack(data);
  770. }
  771. static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
  772. {
  773. int offs = EINT_OFFSET(data->irq);
  774. int shift;
  775. u32 ctrl, mask;
  776. u32 newvalue = 0;
  777. switch (type) {
  778. case IRQ_TYPE_EDGE_RISING:
  779. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  780. break;
  781. case IRQ_TYPE_EDGE_FALLING:
  782. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  783. break;
  784. case IRQ_TYPE_EDGE_BOTH:
  785. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  786. break;
  787. case IRQ_TYPE_LEVEL_LOW:
  788. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  789. break;
  790. case IRQ_TYPE_LEVEL_HIGH:
  791. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  792. break;
  793. default:
  794. printk(KERN_ERR "No such irq type %d", type);
  795. return -EINVAL;
  796. }
  797. shift = (offs & 0x7) * 4;
  798. mask = 0x7 << shift;
  799. spin_lock(&eint_lock);
  800. ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
  801. ctrl &= ~mask;
  802. ctrl |= newvalue << shift;
  803. __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
  804. spin_unlock(&eint_lock);
  805. if (soc_is_exynos5250())
  806. s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  807. else
  808. s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  809. return 0;
  810. }
  811. static struct irq_chip exynos_irq_eint = {
  812. .name = "exynos-eint",
  813. .irq_mask = exynos_irq_eint_mask,
  814. .irq_unmask = exynos_irq_eint_unmask,
  815. .irq_mask_ack = exynos_irq_eint_maskack,
  816. .irq_ack = exynos_irq_eint_ack,
  817. .irq_set_type = exynos_irq_eint_set_type,
  818. #ifdef CONFIG_PM
  819. .irq_set_wake = s3c_irqext_wake,
  820. #endif
  821. };
  822. /*
  823. * exynos4_irq_demux_eint
  824. *
  825. * This function demuxes the IRQ from from EINTs 16 to 31.
  826. * It is designed to be inlined into the specific handler
  827. * s5p_irq_demux_eintX_Y.
  828. *
  829. * Each EINT pend/mask registers handle eight of them.
  830. */
  831. static inline void exynos_irq_demux_eint(unsigned int start)
  832. {
  833. unsigned int irq;
  834. u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
  835. u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
  836. status &= ~mask;
  837. status &= 0xff;
  838. while (status) {
  839. irq = fls(status) - 1;
  840. generic_handle_irq(irq + start);
  841. status &= ~(1 << irq);
  842. }
  843. }
  844. static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  845. {
  846. struct irq_chip *chip = irq_get_chip(irq);
  847. chained_irq_enter(chip, desc);
  848. exynos_irq_demux_eint(IRQ_EINT(16));
  849. exynos_irq_demux_eint(IRQ_EINT(24));
  850. chained_irq_exit(chip, desc);
  851. }
  852. static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
  853. {
  854. u32 *irq_data = irq_get_handler_data(irq);
  855. struct irq_chip *chip = irq_get_chip(irq);
  856. chained_irq_enter(chip, desc);
  857. generic_handle_irq(*irq_data);
  858. chained_irq_exit(chip, desc);
  859. }
  860. static int __init exynos_init_irq_eint(void)
  861. {
  862. int irq;
  863. #ifdef CONFIG_PINCTRL_SAMSUNG
  864. /*
  865. * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
  866. * functionality along with support for external gpio and wakeup
  867. * interrupts. If the samsung pinctrl driver is enabled and includes
  868. * the wakeup interrupt support, then the setting up external wakeup
  869. * interrupts here can be skipped. This check here is temporary to
  870. * allow exynos4 platforms that do not use Samsung pinctrl driver to
  871. * co-exist with platforms that do. When all of the Samsung Exynos4
  872. * platforms switch over to using the pinctrl driver, the wakeup
  873. * interrupt support code here can be completely removed.
  874. */
  875. static const struct of_device_id exynos_pinctrl_ids[] = {
  876. { .compatible = "samsung,pinctrl-exynos4210", },
  877. { .compatible = "samsung,pinctrl-exynos4x12", },
  878. };
  879. struct device_node *pctrl_np, *wkup_np;
  880. const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
  881. for_each_matching_node(pctrl_np, exynos_pinctrl_ids) {
  882. if (of_device_is_available(pctrl_np)) {
  883. wkup_np = of_find_compatible_node(pctrl_np, NULL,
  884. wkup_compat);
  885. if (wkup_np)
  886. return -ENODEV;
  887. }
  888. }
  889. #endif
  890. if (soc_is_exynos5440())
  891. return 0;
  892. if (soc_is_exynos5250())
  893. exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  894. else
  895. exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  896. if (exynos_eint_base == NULL) {
  897. pr_err("unable to ioremap for EINT base address\n");
  898. return -ENOMEM;
  899. }
  900. for (irq = 0 ; irq <= 31 ; irq++) {
  901. irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
  902. handle_level_irq);
  903. set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
  904. }
  905. irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
  906. for (irq = 0 ; irq <= 15 ; irq++) {
  907. eint0_15_data[irq] = IRQ_EINT(irq);
  908. if (soc_is_exynos5250()) {
  909. irq_set_handler_data(exynos5_eint0_15_src_int[irq],
  910. &eint0_15_data[irq]);
  911. irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
  912. exynos_irq_eint0_15);
  913. } else {
  914. irq_set_handler_data(exynos4_eint0_15_src_int[irq],
  915. &eint0_15_data[irq]);
  916. irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
  917. exynos_irq_eint0_15);
  918. }
  919. }
  920. return 0;
  921. }
  922. arch_initcall(exynos_init_irq_eint);