common.c 23 KB

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