common.c 26 KB

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