common.c 24 KB

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