common.c 22 KB

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