common.c 26 KB

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