common.c 23 KB

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