common.c 23 KB

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