common.c 22 KB

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