exynos.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 <linux/irqchip.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/hardware/cache-l2x0.h>
  24. #include <asm/mach/arch.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/memory.h>
  27. #include <mach/map.h>
  28. #include "common.h"
  29. #include "mfc.h"
  30. #include "regs-pmu.h"
  31. void __iomem *pmu_base_addr;
  32. static struct map_desc exynos4_iodesc[] __initdata = {
  33. {
  34. .virtual = (unsigned long)S5P_VA_SROMC,
  35. .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
  36. .length = SZ_4K,
  37. .type = MT_DEVICE,
  38. }, {
  39. .virtual = (unsigned long)S5P_VA_CMU,
  40. .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
  41. .length = SZ_128K,
  42. .type = MT_DEVICE,
  43. }, {
  44. .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
  45. .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
  46. .length = SZ_8K,
  47. .type = MT_DEVICE,
  48. }, {
  49. .virtual = (unsigned long)S5P_VA_DMC0,
  50. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
  51. .length = SZ_64K,
  52. .type = MT_DEVICE,
  53. }, {
  54. .virtual = (unsigned long)S5P_VA_DMC1,
  55. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
  56. .length = SZ_64K,
  57. .type = MT_DEVICE,
  58. },
  59. };
  60. static struct map_desc exynos5_iodesc[] __initdata = {
  61. {
  62. .virtual = (unsigned long)S5P_VA_SROMC,
  63. .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
  64. .length = SZ_4K,
  65. .type = MT_DEVICE,
  66. }, {
  67. .virtual = (unsigned long)S5P_VA_CMU,
  68. .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
  69. .length = 144 * SZ_1K,
  70. .type = MT_DEVICE,
  71. },
  72. };
  73. static struct platform_device exynos_cpuidle = {
  74. .name = "exynos_cpuidle",
  75. #ifdef CONFIG_ARM_EXYNOS_CPUIDLE
  76. .dev.platform_data = exynos_enter_aftr,
  77. #endif
  78. .id = -1,
  79. };
  80. void __iomem *sysram_base_addr;
  81. void __iomem *sysram_ns_base_addr;
  82. void __init exynos_sysram_init(void)
  83. {
  84. struct device_node *node;
  85. for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram") {
  86. if (!of_device_is_available(node))
  87. continue;
  88. sysram_base_addr = of_iomap(node, 0);
  89. break;
  90. }
  91. for_each_compatible_node(node, NULL, "samsung,exynos4210-sysram-ns") {
  92. if (!of_device_is_available(node))
  93. continue;
  94. sysram_ns_base_addr = of_iomap(node, 0);
  95. break;
  96. }
  97. }
  98. static void __init exynos_init_late(void)
  99. {
  100. if (of_machine_is_compatible("samsung,exynos5440"))
  101. /* to be supported later */
  102. return;
  103. exynos_pm_init();
  104. }
  105. static int __init exynos_fdt_map_chipid(unsigned long node, const char *uname,
  106. int depth, void *data)
  107. {
  108. struct map_desc iodesc;
  109. const __be32 *reg;
  110. int len;
  111. if (!of_flat_dt_is_compatible(node, "samsung,exynos4210-chipid") &&
  112. !of_flat_dt_is_compatible(node, "samsung,exynos5440-clock"))
  113. return 0;
  114. reg = of_get_flat_dt_prop(node, "reg", &len);
  115. if (reg == NULL || len != (sizeof(unsigned long) * 2))
  116. return 0;
  117. iodesc.pfn = __phys_to_pfn(be32_to_cpu(reg[0]));
  118. iodesc.length = be32_to_cpu(reg[1]) - 1;
  119. iodesc.virtual = (unsigned long)S5P_VA_CHIPID;
  120. iodesc.type = MT_DEVICE;
  121. iotable_init(&iodesc, 1);
  122. return 1;
  123. }
  124. /*
  125. * exynos_map_io
  126. *
  127. * register the standard cpu IO areas
  128. */
  129. static void __init exynos_map_io(void)
  130. {
  131. if (soc_is_exynos4())
  132. iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
  133. if (soc_is_exynos5())
  134. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  135. }
  136. static void __init exynos_init_io(void)
  137. {
  138. debug_ll_io_init();
  139. of_scan_flat_dt(exynos_fdt_map_chipid, NULL);
  140. /* detect cpu id and rev. */
  141. s5p_init_cpu(S5P_VA_CHIPID);
  142. exynos_map_io();
  143. }
  144. /*
  145. * Set or clear the USE_DELAYED_RESET_ASSERTION option. Used by smp code
  146. * and suspend.
  147. *
  148. * This is necessary only on Exynos4 SoCs. When system is running
  149. * USE_DELAYED_RESET_ASSERTION should be set so the ARM CLK clock down
  150. * feature could properly detect global idle state when secondary CPU is
  151. * powered down.
  152. *
  153. * However this should not be set when such system is going into suspend.
  154. */
  155. void exynos_set_delayed_reset_assertion(bool enable)
  156. {
  157. if (of_machine_is_compatible("samsung,exynos4")) {
  158. unsigned int tmp, core_id;
  159. for (core_id = 0; core_id < num_possible_cpus(); core_id++) {
  160. tmp = pmu_raw_readl(EXYNOS_ARM_CORE_OPTION(core_id));
  161. if (enable)
  162. tmp |= S5P_USE_DELAYED_RESET_ASSERTION;
  163. else
  164. tmp &= ~(S5P_USE_DELAYED_RESET_ASSERTION);
  165. pmu_raw_writel(tmp, EXYNOS_ARM_CORE_OPTION(core_id));
  166. }
  167. }
  168. }
  169. /*
  170. * Apparently, these SoCs are not able to wake-up from suspend using
  171. * the PMU. Too bad. Should they suddenly become capable of such a
  172. * feat, the matches below should be moved to suspend.c.
  173. */
  174. static const struct of_device_id exynos_dt_pmu_match[] = {
  175. { .compatible = "samsung,exynos5260-pmu" },
  176. { .compatible = "samsung,exynos5410-pmu" },
  177. { /*sentinel*/ },
  178. };
  179. static void exynos_map_pmu(void)
  180. {
  181. struct device_node *np;
  182. np = of_find_matching_node(NULL, exynos_dt_pmu_match);
  183. if (np)
  184. pmu_base_addr = of_iomap(np, 0);
  185. }
  186. static void __init exynos_init_irq(void)
  187. {
  188. irqchip_init();
  189. /*
  190. * Since platsmp.c needs pmu base address by the time
  191. * DT is not unflatten so we can't use DT APIs before
  192. * init_irq
  193. */
  194. exynos_map_pmu();
  195. }
  196. static const struct of_device_id exynos_cpufreq_matches[] = {
  197. { .compatible = "samsung,exynos3250", .data = "cpufreq-dt" },
  198. { .compatible = "samsung,exynos4210", .data = "cpufreq-dt" },
  199. { .compatible = "samsung,exynos4212", .data = "cpufreq-dt" },
  200. { .compatible = "samsung,exynos4412", .data = "cpufreq-dt" },
  201. { .compatible = "samsung,exynos5250", .data = "cpufreq-dt" },
  202. { /* sentinel */ }
  203. };
  204. static void __init exynos_cpufreq_init(void)
  205. {
  206. struct device_node *root = of_find_node_by_path("/");
  207. const struct of_device_id *match;
  208. match = of_match_node(exynos_cpufreq_matches, root);
  209. if (!match) {
  210. platform_device_register_simple("exynos-cpufreq", -1, NULL, 0);
  211. return;
  212. }
  213. platform_device_register_simple(match->data, -1, NULL, 0);
  214. }
  215. static void __init exynos_dt_machine_init(void)
  216. {
  217. /*
  218. * This is called from smp_prepare_cpus if we've built for SMP, but
  219. * we still need to set it up for PM and firmware ops if not.
  220. */
  221. if (!IS_ENABLED(CONFIG_SMP))
  222. exynos_sysram_init();
  223. #if defined(CONFIG_SMP) && defined(CONFIG_ARM_EXYNOS_CPUIDLE)
  224. if (of_machine_is_compatible("samsung,exynos4210") ||
  225. of_machine_is_compatible("samsung,exynos3250"))
  226. exynos_cpuidle.dev.platform_data = &cpuidle_coupled_exynos_data;
  227. #endif
  228. if (of_machine_is_compatible("samsung,exynos4210") ||
  229. of_machine_is_compatible("samsung,exynos4212") ||
  230. (of_machine_is_compatible("samsung,exynos4412") &&
  231. of_machine_is_compatible("samsung,trats2")) ||
  232. of_machine_is_compatible("samsung,exynos3250") ||
  233. of_machine_is_compatible("samsung,exynos5250"))
  234. platform_device_register(&exynos_cpuidle);
  235. exynos_cpufreq_init();
  236. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  237. }
  238. static char const *const exynos_dt_compat[] __initconst = {
  239. "samsung,exynos3",
  240. "samsung,exynos3250",
  241. "samsung,exynos4",
  242. "samsung,exynos4210",
  243. "samsung,exynos4212",
  244. "samsung,exynos4412",
  245. "samsung,exynos4415",
  246. "samsung,exynos5",
  247. "samsung,exynos5250",
  248. "samsung,exynos5260",
  249. "samsung,exynos5420",
  250. "samsung,exynos5440",
  251. NULL
  252. };
  253. static void __init exynos_reserve(void)
  254. {
  255. #ifdef CONFIG_S5P_DEV_MFC
  256. int i;
  257. char *mfc_mem[] = {
  258. "samsung,mfc-v5",
  259. "samsung,mfc-v6",
  260. "samsung,mfc-v7",
  261. "samsung,mfc-v8",
  262. };
  263. for (i = 0; i < ARRAY_SIZE(mfc_mem); i++)
  264. if (of_scan_flat_dt(s5p_fdt_alloc_mfc_mem, mfc_mem[i]))
  265. break;
  266. #endif
  267. }
  268. static void __init exynos_dt_fixup(void)
  269. {
  270. /*
  271. * Some versions of uboot pass garbage entries in the memory node,
  272. * use the old CONFIG_ARM_NR_BANKS
  273. */
  274. of_fdt_limit_memory(8);
  275. }
  276. DT_MACHINE_START(EXYNOS_DT, "SAMSUNG EXYNOS (Flattened Device Tree)")
  277. /* Maintainer: Thomas Abraham <thomas.abraham@linaro.org> */
  278. /* Maintainer: Kukjin Kim <kgene.kim@samsung.com> */
  279. .l2c_aux_val = 0x3c400001,
  280. .l2c_aux_mask = 0xc20fffff,
  281. .smp = smp_ops(exynos_smp_ops),
  282. .map_io = exynos_init_io,
  283. .init_early = exynos_firmware_init,
  284. .init_irq = exynos_init_irq,
  285. .init_machine = exynos_dt_machine_init,
  286. .init_late = exynos_init_late,
  287. .dt_compat = exynos_dt_compat,
  288. .reserve = exynos_reserve,
  289. .dt_fixup = exynos_dt_fixup,
  290. MACHINE_END