common.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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 <plat/cpu.h>
  42. #include <plat/devs.h>
  43. #include <plat/pm.h>
  44. #include <plat/sdhci.h>
  45. #include <plat/gpio-cfg.h>
  46. #include <plat/adc-core.h>
  47. #include <plat/fb-core.h>
  48. #include <plat/fimc-core.h>
  49. #include <plat/iic-core.h>
  50. #include <plat/tv-core.h>
  51. #include <plat/spi-core.h>
  52. #include <plat/regs-serial.h>
  53. #include "common.h"
  54. #define L2_AUX_VAL 0x7C470001
  55. #define L2_AUX_MASK 0xC200ffff
  56. static const char name_exynos4210[] = "EXYNOS4210";
  57. static const char name_exynos4212[] = "EXYNOS4212";
  58. static const char name_exynos4412[] = "EXYNOS4412";
  59. static const char name_exynos5250[] = "EXYNOS5250";
  60. static const char name_exynos5440[] = "EXYNOS5440";
  61. static void exynos4_map_io(void);
  62. static void exynos5_map_io(void);
  63. static void exynos5440_map_io(void);
  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 = exynos_init,
  72. .name = name_exynos4210,
  73. }, {
  74. .idcode = EXYNOS4212_CPU_ID,
  75. .idmask = EXYNOS4_CPU_MASK,
  76. .map_io = exynos4_map_io,
  77. .init = exynos_init,
  78. .name = name_exynos4212,
  79. }, {
  80. .idcode = EXYNOS4412_CPU_ID,
  81. .idmask = EXYNOS4_CPU_MASK,
  82. .map_io = exynos4_map_io,
  83. .init = exynos_init,
  84. .name = name_exynos4412,
  85. }, {
  86. .idcode = EXYNOS5250_SOC_ID,
  87. .idmask = EXYNOS5_SOC_MASK,
  88. .map_io = exynos5_map_io,
  89. .init = exynos_init,
  90. .name = name_exynos5250,
  91. }, {
  92. .idcode = EXYNOS5440_SOC_ID,
  93. .idmask = EXYNOS5_SOC_MASK,
  94. .map_io = exynos5440_map_io,
  95. .init = exynos_init,
  96. .name = name_exynos5440,
  97. },
  98. };
  99. /* Initial IO mappings */
  100. static struct map_desc exynos_iodesc[] __initdata = {
  101. {
  102. .virtual = (unsigned long)S5P_VA_CHIPID,
  103. .pfn = __phys_to_pfn(EXYNOS_PA_CHIPID),
  104. .length = SZ_4K,
  105. .type = MT_DEVICE,
  106. },
  107. };
  108. static struct map_desc exynos4_iodesc[] __initdata = {
  109. {
  110. .virtual = (unsigned long)S3C_VA_SYS,
  111. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
  112. .length = SZ_64K,
  113. .type = MT_DEVICE,
  114. }, {
  115. .virtual = (unsigned long)S3C_VA_TIMER,
  116. .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
  117. .length = SZ_16K,
  118. .type = MT_DEVICE,
  119. }, {
  120. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  121. .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
  122. .length = SZ_4K,
  123. .type = MT_DEVICE,
  124. }, {
  125. .virtual = (unsigned long)S5P_VA_SROMC,
  126. .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
  127. .length = SZ_4K,
  128. .type = MT_DEVICE,
  129. }, {
  130. .virtual = (unsigned long)S5P_VA_SYSTIMER,
  131. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
  132. .length = SZ_4K,
  133. .type = MT_DEVICE,
  134. }, {
  135. .virtual = (unsigned long)S5P_VA_PMU,
  136. .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
  137. .length = SZ_64K,
  138. .type = MT_DEVICE,
  139. }, {
  140. .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
  141. .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
  142. .length = SZ_4K,
  143. .type = MT_DEVICE,
  144. }, {
  145. .virtual = (unsigned long)S5P_VA_GIC_CPU,
  146. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
  147. .length = SZ_64K,
  148. .type = MT_DEVICE,
  149. }, {
  150. .virtual = (unsigned long)S5P_VA_GIC_DIST,
  151. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
  152. .length = SZ_64K,
  153. .type = MT_DEVICE,
  154. }, {
  155. .virtual = (unsigned long)S3C_VA_UART,
  156. .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
  157. .length = SZ_512K,
  158. .type = MT_DEVICE,
  159. }, {
  160. .virtual = (unsigned long)S5P_VA_CMU,
  161. .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
  162. .length = SZ_128K,
  163. .type = MT_DEVICE,
  164. }, {
  165. .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
  166. .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
  167. .length = SZ_8K,
  168. .type = MT_DEVICE,
  169. }, {
  170. .virtual = (unsigned long)S5P_VA_L2CC,
  171. .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
  172. .length = SZ_4K,
  173. .type = MT_DEVICE,
  174. }, {
  175. .virtual = (unsigned long)S5P_VA_DMC0,
  176. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
  177. .length = SZ_64K,
  178. .type = MT_DEVICE,
  179. }, {
  180. .virtual = (unsigned long)S5P_VA_DMC1,
  181. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
  182. .length = SZ_64K,
  183. .type = MT_DEVICE,
  184. }, {
  185. .virtual = (unsigned long)S3C_VA_USB_HSPHY,
  186. .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
  187. .length = SZ_4K,
  188. .type = MT_DEVICE,
  189. },
  190. };
  191. static struct map_desc exynos4_iodesc0[] __initdata = {
  192. {
  193. .virtual = (unsigned long)S5P_VA_SYSRAM,
  194. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
  195. .length = SZ_4K,
  196. .type = MT_DEVICE,
  197. },
  198. };
  199. static struct map_desc exynos4_iodesc1[] __initdata = {
  200. {
  201. .virtual = (unsigned long)S5P_VA_SYSRAM,
  202. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
  203. .length = SZ_4K,
  204. .type = MT_DEVICE,
  205. },
  206. };
  207. static struct map_desc exynos4210_iodesc[] __initdata = {
  208. {
  209. .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
  210. .pfn = __phys_to_pfn(EXYNOS4210_PA_SYSRAM_NS),
  211. .length = SZ_4K,
  212. .type = MT_DEVICE,
  213. },
  214. };
  215. static struct map_desc exynos4x12_iodesc[] __initdata = {
  216. {
  217. .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
  218. .pfn = __phys_to_pfn(EXYNOS4x12_PA_SYSRAM_NS),
  219. .length = SZ_4K,
  220. .type = MT_DEVICE,
  221. },
  222. };
  223. static struct map_desc exynos5250_iodesc[] __initdata = {
  224. {
  225. .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
  226. .pfn = __phys_to_pfn(EXYNOS5250_PA_SYSRAM_NS),
  227. .length = SZ_4K,
  228. .type = MT_DEVICE,
  229. },
  230. };
  231. static struct map_desc exynos5_iodesc[] __initdata = {
  232. {
  233. .virtual = (unsigned long)S3C_VA_SYS,
  234. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
  235. .length = SZ_64K,
  236. .type = MT_DEVICE,
  237. }, {
  238. .virtual = (unsigned long)S3C_VA_TIMER,
  239. .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
  240. .length = SZ_16K,
  241. .type = MT_DEVICE,
  242. }, {
  243. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  244. .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
  245. .length = SZ_4K,
  246. .type = MT_DEVICE,
  247. }, {
  248. .virtual = (unsigned long)S5P_VA_SROMC,
  249. .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
  250. .length = SZ_4K,
  251. .type = MT_DEVICE,
  252. }, {
  253. .virtual = (unsigned long)S5P_VA_SYSRAM,
  254. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
  255. .length = SZ_4K,
  256. .type = MT_DEVICE,
  257. }, {
  258. .virtual = (unsigned long)S5P_VA_CMU,
  259. .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
  260. .length = 144 * SZ_1K,
  261. .type = MT_DEVICE,
  262. }, {
  263. .virtual = (unsigned long)S5P_VA_PMU,
  264. .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
  265. .length = SZ_64K,
  266. .type = MT_DEVICE,
  267. }, {
  268. .virtual = (unsigned long)S3C_VA_UART,
  269. .pfn = __phys_to_pfn(EXYNOS5_PA_UART),
  270. .length = SZ_512K,
  271. .type = MT_DEVICE,
  272. },
  273. };
  274. static struct map_desc exynos5440_iodesc0[] __initdata = {
  275. {
  276. .virtual = (unsigned long)S3C_VA_UART,
  277. .pfn = __phys_to_pfn(EXYNOS5440_PA_UART0),
  278. .length = SZ_512K,
  279. .type = MT_DEVICE,
  280. },
  281. };
  282. void exynos4_restart(char mode, const char *cmd)
  283. {
  284. __raw_writel(0x1, S5P_SWRESET);
  285. }
  286. void exynos5_restart(char mode, const char *cmd)
  287. {
  288. struct device_node *np;
  289. u32 val;
  290. void __iomem *addr;
  291. if (of_machine_is_compatible("samsung,exynos5250")) {
  292. val = 0x1;
  293. addr = EXYNOS_SWRESET;
  294. } else if (of_machine_is_compatible("samsung,exynos5440")) {
  295. u32 status;
  296. np = of_find_compatible_node(NULL, NULL, "samsung,exynos5440-clock");
  297. addr = of_iomap(np, 0) + 0xbc;
  298. status = __raw_readl(addr);
  299. addr = of_iomap(np, 0) + 0xcc;
  300. val = __raw_readl(addr);
  301. val = (val & 0xffff0000) | (status & 0xffff);
  302. } else {
  303. pr_err("%s: cannot support non-DT\n", __func__);
  304. return;
  305. }
  306. __raw_writel(val, addr);
  307. }
  308. void __init exynos_init_late(void)
  309. {
  310. if (of_machine_is_compatible("samsung,exynos5440"))
  311. /* to be supported later */
  312. return;
  313. exynos_pm_late_initcall();
  314. }
  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. /*
  335. * exynos_map_io
  336. *
  337. * register the standard cpu IO areas
  338. */
  339. void __init exynos_init_io(struct map_desc *mach_desc, int size)
  340. {
  341. debug_ll_io_init();
  342. if (initial_boot_params)
  343. of_scan_flat_dt(exynos_fdt_map_chipid, NULL);
  344. else
  345. iotable_init(exynos_iodesc, ARRAY_SIZE(exynos_iodesc));
  346. if (mach_desc)
  347. iotable_init(mach_desc, size);
  348. /* detect cpu id and rev. */
  349. s5p_init_cpu(S5P_VA_CHIPID);
  350. s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
  351. }
  352. static void __init exynos4_map_io(void)
  353. {
  354. iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
  355. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
  356. iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
  357. else
  358. iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
  359. if (soc_is_exynos4210())
  360. iotable_init(exynos4210_iodesc, ARRAY_SIZE(exynos4210_iodesc));
  361. if (soc_is_exynos4212() || soc_is_exynos4412())
  362. iotable_init(exynos4x12_iodesc, ARRAY_SIZE(exynos4x12_iodesc));
  363. /* initialize device information early */
  364. exynos4_default_sdhci0();
  365. exynos4_default_sdhci1();
  366. exynos4_default_sdhci2();
  367. exynos4_default_sdhci3();
  368. s3c_adc_setname("samsung-adc-v3");
  369. s3c_fimc_setname(0, "exynos4-fimc");
  370. s3c_fimc_setname(1, "exynos4-fimc");
  371. s3c_fimc_setname(2, "exynos4-fimc");
  372. s3c_fimc_setname(3, "exynos4-fimc");
  373. s3c_sdhci_setname(0, "exynos4-sdhci");
  374. s3c_sdhci_setname(1, "exynos4-sdhci");
  375. s3c_sdhci_setname(2, "exynos4-sdhci");
  376. s3c_sdhci_setname(3, "exynos4-sdhci");
  377. /* The I2C bus controllers are directly compatible with s3c2440 */
  378. s3c_i2c0_setname("s3c2440-i2c");
  379. s3c_i2c1_setname("s3c2440-i2c");
  380. s3c_i2c2_setname("s3c2440-i2c");
  381. s5p_fb_setname(0, "exynos4-fb");
  382. s5p_hdmi_setname("exynos4-hdmi");
  383. s3c64xx_spi_setname("exynos4210-spi");
  384. }
  385. static void __init exynos5_map_io(void)
  386. {
  387. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  388. if (soc_is_exynos5250())
  389. iotable_init(exynos5250_iodesc, ARRAY_SIZE(exynos5250_iodesc));
  390. }
  391. static void __init exynos5440_map_io(void)
  392. {
  393. iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
  394. }
  395. void __init exynos_init_time(void)
  396. {
  397. of_clk_init(NULL);
  398. clocksource_of_init();
  399. }
  400. void __init exynos4_init_irq(void)
  401. {
  402. irqchip_init();
  403. }
  404. void __init exynos5_init_irq(void)
  405. {
  406. irqchip_init();
  407. }
  408. struct bus_type exynos_subsys = {
  409. .name = "exynos-core",
  410. .dev_name = "exynos-core",
  411. };
  412. static struct device exynos4_dev = {
  413. .bus = &exynos_subsys,
  414. };
  415. static int __init exynos_core_init(void)
  416. {
  417. return subsys_system_register(&exynos_subsys, NULL);
  418. }
  419. core_initcall(exynos_core_init);
  420. #ifdef CONFIG_CACHE_L2X0
  421. static int __init exynos4_l2x0_cache_init(void)
  422. {
  423. int ret;
  424. if (soc_is_exynos5250() || soc_is_exynos5440())
  425. return 0;
  426. ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
  427. if (!ret) {
  428. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  429. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  430. return 0;
  431. }
  432. if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
  433. l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
  434. /* TAG, Data Latency Control: 2 cycles */
  435. l2x0_saved_regs.tag_latency = 0x110;
  436. if (soc_is_exynos4212() || soc_is_exynos4412())
  437. l2x0_saved_regs.data_latency = 0x120;
  438. else
  439. l2x0_saved_regs.data_latency = 0x110;
  440. l2x0_saved_regs.prefetch_ctrl = 0x30000007;
  441. l2x0_saved_regs.pwr_ctrl =
  442. (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
  443. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  444. __raw_writel(l2x0_saved_regs.tag_latency,
  445. S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
  446. __raw_writel(l2x0_saved_regs.data_latency,
  447. S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
  448. /* L2X0 Prefetch Control */
  449. __raw_writel(l2x0_saved_regs.prefetch_ctrl,
  450. S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
  451. /* L2X0 Power Control */
  452. __raw_writel(l2x0_saved_regs.pwr_ctrl,
  453. S5P_VA_L2CC + L2X0_POWER_CTRL);
  454. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  455. clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
  456. }
  457. l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
  458. return 0;
  459. }
  460. early_initcall(exynos4_l2x0_cache_init);
  461. #endif
  462. static int __init exynos_init(void)
  463. {
  464. printk(KERN_INFO "EXYNOS: Initializing architecture\n");
  465. return device_register(&exynos4_dev);
  466. }