common.c 23 KB

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