common.c 25 KB

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