common.c 26 KB

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