exynos.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. * SAMSUNG EXYNOS Flattened Device Tree enabled machine
  3. *
  4. * Copyright (c) 2010-2014 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  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/init.h>
  12. #include <linux/io.h>
  13. #include <linux/kernel.h>
  14. #include <linux/serial_s3c.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_fdt.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/pm_domain.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/hardware/cache-l2x0.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/memory.h>
  26. #include "common.h"
  27. #include "mfc.h"
  28. #include "regs-pmu.h"
  29. static struct map_desc exynos4_iodesc[] __initdata = {
  30. {
  31. .virtual = (unsigned long)S3C_VA_SYS,
  32. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
  33. .length = SZ_64K,
  34. .type = MT_DEVICE,
  35. }, {
  36. .virtual = (unsigned long)S3C_VA_TIMER,
  37. .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
  38. .length = SZ_16K,
  39. .type = MT_DEVICE,
  40. }, {
  41. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  42. .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
  43. .length = SZ_4K,
  44. .type = MT_DEVICE,
  45. }, {
  46. .virtual = (unsigned long)S5P_VA_SROMC,
  47. .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
  48. .length = SZ_4K,
  49. .type = MT_DEVICE,
  50. }, {
  51. .virtual = (unsigned long)S5P_VA_SYSTIMER,
  52. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
  53. .length = SZ_4K,
  54. .type = MT_DEVICE,
  55. }, {
  56. .virtual = (unsigned long)S5P_VA_PMU,
  57. .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
  58. .length = SZ_64K,
  59. .type = MT_DEVICE,
  60. }, {
  61. .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
  62. .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
  63. .length = SZ_4K,
  64. .type = MT_DEVICE,
  65. }, {
  66. .virtual = (unsigned long)S5P_VA_GIC_CPU,
  67. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
  68. .length = SZ_64K,
  69. .type = MT_DEVICE,
  70. }, {
  71. .virtual = (unsigned long)S5P_VA_GIC_DIST,
  72. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
  73. .length = SZ_64K,
  74. .type = MT_DEVICE,
  75. }, {
  76. .virtual = (unsigned long)S5P_VA_CMU,
  77. .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
  78. .length = SZ_128K,
  79. .type = MT_DEVICE,
  80. }, {
  81. .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
  82. .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
  83. .length = SZ_8K,
  84. .type = MT_DEVICE,
  85. }, {
  86. .virtual = (unsigned long)S5P_VA_L2CC,
  87. .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
  88. .length = SZ_4K,
  89. .type = MT_DEVICE,
  90. }, {
  91. .virtual = (unsigned long)S5P_VA_DMC0,
  92. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
  93. .length = SZ_64K,
  94. .type = MT_DEVICE,
  95. }, {
  96. .virtual = (unsigned long)S5P_VA_DMC1,
  97. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
  98. .length = SZ_64K,
  99. .type = MT_DEVICE,
  100. }, {
  101. .virtual = (unsigned long)S3C_VA_USB_HSPHY,
  102. .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
  103. .length = SZ_4K,
  104. .type = MT_DEVICE,
  105. },
  106. };
  107. static struct map_desc exynos5_iodesc[] __initdata = {
  108. {
  109. .virtual = (unsigned long)S3C_VA_SYS,
  110. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
  111. .length = SZ_64K,
  112. .type = MT_DEVICE,
  113. }, {
  114. .virtual = (unsigned long)S3C_VA_TIMER,
  115. .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
  116. .length = SZ_16K,
  117. .type = MT_DEVICE,
  118. }, {
  119. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  120. .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
  121. .length = SZ_4K,
  122. .type = MT_DEVICE,
  123. }, {
  124. .virtual = (unsigned long)S5P_VA_SROMC,
  125. .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
  126. .length = SZ_4K,
  127. .type = MT_DEVICE,
  128. }, {
  129. .virtual = (unsigned long)S5P_VA_CMU,
  130. .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
  131. .length = 144 * SZ_1K,
  132. .type = MT_DEVICE,
  133. }, {
  134. .virtual = (unsigned long)S5P_VA_PMU,
  135. .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
  136. .length = SZ_64K,
  137. .type = MT_DEVICE,
  138. },
  139. };
  140. void exynos_restart(enum reboot_mode mode, const char *cmd)
  141. {
  142. struct device_node *np;
  143. u32 val = 0x1;
  144. void __iomem *addr = EXYNOS_SWRESET;
  145. if (of_machine_is_compatible("samsung,exynos5440")) {
  146. u32 status;
  147. np = of_find_compatible_node(NULL, NULL, "samsung,exynos5440-clock");
  148. addr = of_iomap(np, 0) + 0xbc;
  149. status = __raw_readl(addr);
  150. addr = of_iomap(np, 0) + 0xcc;
  151. val = __raw_readl(addr);
  152. val = (val & 0xffff0000) | (status & 0xffff);
  153. }
  154. __raw_writel(val, addr);
  155. }
  156. static struct platform_device exynos_cpuidle = {
  157. .name = "exynos_cpuidle",
  158. .dev.platform_data = exynos_enter_aftr,
  159. .id = -1,
  160. };
  161. void __init exynos_cpuidle_init(void)
  162. {
  163. if (soc_is_exynos4210() || soc_is_exynos5250())
  164. platform_device_register(&exynos_cpuidle);
  165. }
  166. void __init exynos_cpufreq_init(void)
  167. {
  168. platform_device_register_simple("exynos-cpufreq", -1, NULL, 0);
  169. }
  170. void __iomem *sysram_base_addr;
  171. void __iomem *sysram_ns_base_addr;
  172. void __init exynos_sysram_init(void)
  173. {
  174. struct device_node *node;
  175. for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram") {
  176. if (!of_device_is_available(node))
  177. continue;
  178. sysram_base_addr = of_iomap(node, 0);
  179. break;
  180. }
  181. for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram-ns") {
  182. if (!of_device_is_available(node))
  183. continue;
  184. sysram_ns_base_addr = of_iomap(node, 0);
  185. break;
  186. }
  187. }
  188. void __init exynos_init_late(void)
  189. {
  190. if (of_machine_is_compatible("samsung,exynos5440"))
  191. /* to be supported later */
  192. return;
  193. pm_genpd_poweroff_unused();
  194. exynos_pm_init();
  195. }
  196. static int __init exynos_fdt_map_chipid(unsigned long node, const char *uname,
  197. int depth, void *data)
  198. {
  199. struct map_desc iodesc;
  200. const __be32 *reg;
  201. int len;
  202. if (!of_flat_dt_is_compatible(node, "samsung,exynos4210-chipid") &&
  203. !of_flat_dt_is_compatible(node, "samsung,exynos5440-clock"))
  204. return 0;
  205. reg = of_get_flat_dt_prop(node, "reg", &len);
  206. if (reg == NULL || len != (sizeof(unsigned long) * 2))
  207. return 0;
  208. iodesc.pfn = __phys_to_pfn(be32_to_cpu(reg[0]));
  209. iodesc.length = be32_to_cpu(reg[1]) - 1;
  210. iodesc.virtual = (unsigned long)S5P_VA_CHIPID;
  211. iodesc.type = MT_DEVICE;
  212. iotable_init(&iodesc, 1);
  213. return 1;
  214. }
  215. /*
  216. * exynos_map_io
  217. *
  218. * register the standard cpu IO areas
  219. */
  220. static void __init exynos_map_io(void)
  221. {
  222. if (soc_is_exynos4())
  223. iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
  224. if (soc_is_exynos5())
  225. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  226. }
  227. void __init exynos_init_io(void)
  228. {
  229. debug_ll_io_init();
  230. of_scan_flat_dt(exynos_fdt_map_chipid, NULL);
  231. /* detect cpu id and rev. */
  232. s5p_init_cpu(S5P_VA_CHIPID);
  233. exynos_map_io();
  234. }
  235. static void __init exynos_dt_machine_init(void)
  236. {
  237. struct device_node *i2c_np;
  238. const char *i2c_compat = "samsung,s3c2440-i2c";
  239. unsigned int tmp;
  240. int id;
  241. /*
  242. * Exynos5's legacy i2c controller and new high speed i2c
  243. * controller have muxed interrupt sources. By default the
  244. * interrupts for 4-channel HS-I2C controller are enabled.
  245. * If node for first four channels of legacy i2c controller
  246. * are available then re-configure the interrupts via the
  247. * system register.
  248. */
  249. if (soc_is_exynos5()) {
  250. for_each_compatible_node(i2c_np, NULL, i2c_compat) {
  251. if (of_device_is_available(i2c_np)) {
  252. id = of_alias_get_id(i2c_np, "i2c");
  253. if (id < 4) {
  254. tmp = readl(EXYNOS5_SYS_I2C_CFG);
  255. writel(tmp & ~(0x1 << id),
  256. EXYNOS5_SYS_I2C_CFG);
  257. }
  258. }
  259. }
  260. }
  261. /*
  262. * This is called from smp_prepare_cpus if we've built for SMP, but
  263. * we still need to set it up for PM and firmware ops if not.
  264. */
  265. if (!IS_ENABLED(CONFIG_SMP))
  266. exynos_sysram_init();
  267. exynos_cpuidle_init();
  268. exynos_cpufreq_init();
  269. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  270. }
  271. static char const *exynos_dt_compat[] __initconst = {
  272. "samsung,exynos3",
  273. "samsung,exynos3250",
  274. "samsung,exynos4",
  275. "samsung,exynos4210",
  276. "samsung,exynos4212",
  277. "samsung,exynos4412",
  278. "samsung,exynos5",
  279. "samsung,exynos5250",
  280. "samsung,exynos5260",
  281. "samsung,exynos5420",
  282. "samsung,exynos5440",
  283. NULL
  284. };
  285. static void __init exynos_reserve(void)
  286. {
  287. #ifdef CONFIG_S5P_DEV_MFC
  288. int i;
  289. char *mfc_mem[] = {
  290. "samsung,mfc-v5",
  291. "samsung,mfc-v6",
  292. "samsung,mfc-v7",
  293. };
  294. for (i = 0; i < ARRAY_SIZE(mfc_mem); i++)
  295. if (of_scan_flat_dt(s5p_fdt_alloc_mfc_mem, mfc_mem[i]))
  296. break;
  297. #endif
  298. }
  299. static void __init exynos_dt_fixup(void)
  300. {
  301. /*
  302. * Some versions of uboot pass garbage entries in the memory node,
  303. * use the old CONFIG_ARM_NR_BANKS
  304. */
  305. of_fdt_limit_memory(8);
  306. }
  307. DT_MACHINE_START(EXYNOS_DT, "SAMSUNG EXYNOS (Flattened Device Tree)")
  308. /* Maintainer: Thomas Abraham <thomas.abraham@linaro.org> */
  309. /* Maintainer: Kukjin Kim <kgene.kim@samsung.com> */
  310. .l2c_aux_val = 0x3c400001,
  311. .l2c_aux_mask = 0xc20fffff,
  312. .smp = smp_ops(exynos_smp_ops),
  313. .map_io = exynos_init_io,
  314. .init_early = exynos_firmware_init,
  315. .init_machine = exynos_dt_machine_init,
  316. .init_late = exynos_init_late,
  317. .dt_compat = exynos_dt_compat,
  318. .restart = exynos_restart,
  319. .reserve = exynos_reserve,
  320. .dt_fixup = exynos_dt_fixup,
  321. MACHINE_END