common.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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 <linux/platform_device.h>
  33. #include <asm/proc-fns.h>
  34. #include <asm/exception.h>
  35. #include <asm/hardware/cache-l2x0.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/irq.h>
  38. #include <asm/cacheflush.h>
  39. #include <mach/regs-irq.h>
  40. #include <mach/regs-pmu.h>
  41. #include <plat/cpu.h>
  42. #include <plat/pm.h>
  43. #include <plat/regs-serial.h>
  44. #include "common.h"
  45. #define L2_AUX_VAL 0x7C470001
  46. #define L2_AUX_MASK 0xC200ffff
  47. static const char name_exynos4210[] = "EXYNOS4210";
  48. static const char name_exynos4212[] = "EXYNOS4212";
  49. static const char name_exynos4412[] = "EXYNOS4412";
  50. static const char name_exynos5250[] = "EXYNOS5250";
  51. static const char name_exynos5420[] = "EXYNOS5420";
  52. static const char name_exynos5440[] = "EXYNOS5440";
  53. static void exynos4_map_io(void);
  54. static void exynos5_map_io(void);
  55. static int exynos_init(void);
  56. static struct cpu_table cpu_ids[] __initdata = {
  57. {
  58. .idcode = EXYNOS4210_CPU_ID,
  59. .idmask = EXYNOS4_CPU_MASK,
  60. .map_io = exynos4_map_io,
  61. .init = exynos_init,
  62. .name = name_exynos4210,
  63. }, {
  64. .idcode = EXYNOS4212_CPU_ID,
  65. .idmask = EXYNOS4_CPU_MASK,
  66. .map_io = exynos4_map_io,
  67. .init = exynos_init,
  68. .name = name_exynos4212,
  69. }, {
  70. .idcode = EXYNOS4412_CPU_ID,
  71. .idmask = EXYNOS4_CPU_MASK,
  72. .map_io = exynos4_map_io,
  73. .init = exynos_init,
  74. .name = name_exynos4412,
  75. }, {
  76. .idcode = EXYNOS5250_SOC_ID,
  77. .idmask = EXYNOS5_SOC_MASK,
  78. .map_io = exynos5_map_io,
  79. .init = exynos_init,
  80. .name = name_exynos5250,
  81. }, {
  82. .idcode = EXYNOS5420_SOC_ID,
  83. .idmask = EXYNOS5_SOC_MASK,
  84. .map_io = exynos5_map_io,
  85. .init = exynos_init,
  86. .name = name_exynos5420,
  87. }, {
  88. .idcode = EXYNOS5440_SOC_ID,
  89. .idmask = EXYNOS5_SOC_MASK,
  90. .init = exynos_init,
  91. .name = name_exynos5440,
  92. },
  93. };
  94. /* Initial IO mappings */
  95. static struct map_desc exynos4_iodesc[] __initdata = {
  96. {
  97. .virtual = (unsigned long)S3C_VA_SYS,
  98. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
  99. .length = SZ_64K,
  100. .type = MT_DEVICE,
  101. }, {
  102. .virtual = (unsigned long)S3C_VA_TIMER,
  103. .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
  104. .length = SZ_16K,
  105. .type = MT_DEVICE,
  106. }, {
  107. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  108. .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
  109. .length = SZ_4K,
  110. .type = MT_DEVICE,
  111. }, {
  112. .virtual = (unsigned long)S5P_VA_SROMC,
  113. .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
  114. .length = SZ_4K,
  115. .type = MT_DEVICE,
  116. }, {
  117. .virtual = (unsigned long)S5P_VA_SYSTIMER,
  118. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
  119. .length = SZ_4K,
  120. .type = MT_DEVICE,
  121. }, {
  122. .virtual = (unsigned long)S5P_VA_PMU,
  123. .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
  124. .length = SZ_64K,
  125. .type = MT_DEVICE,
  126. }, {
  127. .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
  128. .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
  129. .length = SZ_4K,
  130. .type = MT_DEVICE,
  131. }, {
  132. .virtual = (unsigned long)S5P_VA_GIC_CPU,
  133. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
  134. .length = SZ_64K,
  135. .type = MT_DEVICE,
  136. }, {
  137. .virtual = (unsigned long)S5P_VA_GIC_DIST,
  138. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
  139. .length = SZ_64K,
  140. .type = MT_DEVICE,
  141. }, {
  142. .virtual = (unsigned long)S5P_VA_CMU,
  143. .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
  144. .length = SZ_128K,
  145. .type = MT_DEVICE,
  146. }, {
  147. .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
  148. .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
  149. .length = SZ_8K,
  150. .type = MT_DEVICE,
  151. }, {
  152. .virtual = (unsigned long)S5P_VA_L2CC,
  153. .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
  154. .length = SZ_4K,
  155. .type = MT_DEVICE,
  156. }, {
  157. .virtual = (unsigned long)S5P_VA_DMC0,
  158. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
  159. .length = SZ_64K,
  160. .type = MT_DEVICE,
  161. }, {
  162. .virtual = (unsigned long)S5P_VA_DMC1,
  163. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
  164. .length = SZ_64K,
  165. .type = MT_DEVICE,
  166. }, {
  167. .virtual = (unsigned long)S3C_VA_USB_HSPHY,
  168. .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
  169. .length = SZ_4K,
  170. .type = MT_DEVICE,
  171. },
  172. };
  173. static struct map_desc exynos4_iodesc0[] __initdata = {
  174. {
  175. .virtual = (unsigned long)S5P_VA_SYSRAM,
  176. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
  177. .length = SZ_4K,
  178. .type = MT_DEVICE,
  179. },
  180. };
  181. static struct map_desc exynos4_iodesc1[] __initdata = {
  182. {
  183. .virtual = (unsigned long)S5P_VA_SYSRAM,
  184. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
  185. .length = SZ_4K,
  186. .type = MT_DEVICE,
  187. },
  188. };
  189. static struct map_desc exynos4210_iodesc[] __initdata = {
  190. {
  191. .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
  192. .pfn = __phys_to_pfn(EXYNOS4210_PA_SYSRAM_NS),
  193. .length = SZ_4K,
  194. .type = MT_DEVICE,
  195. },
  196. };
  197. static struct map_desc exynos4x12_iodesc[] __initdata = {
  198. {
  199. .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
  200. .pfn = __phys_to_pfn(EXYNOS4x12_PA_SYSRAM_NS),
  201. .length = SZ_4K,
  202. .type = MT_DEVICE,
  203. },
  204. };
  205. static struct map_desc exynos5250_iodesc[] __initdata = {
  206. {
  207. .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
  208. .pfn = __phys_to_pfn(EXYNOS5250_PA_SYSRAM_NS),
  209. .length = SZ_4K,
  210. .type = MT_DEVICE,
  211. },
  212. };
  213. static struct map_desc exynos5_iodesc[] __initdata = {
  214. {
  215. .virtual = (unsigned long)S3C_VA_SYS,
  216. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
  217. .length = SZ_64K,
  218. .type = MT_DEVICE,
  219. }, {
  220. .virtual = (unsigned long)S3C_VA_TIMER,
  221. .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
  222. .length = SZ_16K,
  223. .type = MT_DEVICE,
  224. }, {
  225. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  226. .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
  227. .length = SZ_4K,
  228. .type = MT_DEVICE,
  229. }, {
  230. .virtual = (unsigned long)S5P_VA_SROMC,
  231. .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
  232. .length = SZ_4K,
  233. .type = MT_DEVICE,
  234. }, {
  235. .virtual = (unsigned long)S5P_VA_SYSRAM,
  236. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
  237. .length = SZ_4K,
  238. .type = MT_DEVICE,
  239. }, {
  240. .virtual = (unsigned long)S5P_VA_CMU,
  241. .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
  242. .length = 144 * SZ_1K,
  243. .type = MT_DEVICE,
  244. }, {
  245. .virtual = (unsigned long)S5P_VA_PMU,
  246. .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
  247. .length = SZ_64K,
  248. .type = MT_DEVICE,
  249. },
  250. };
  251. void exynos4_restart(enum reboot_mode mode, const char *cmd)
  252. {
  253. __raw_writel(0x1, S5P_SWRESET);
  254. }
  255. void exynos5_restart(enum reboot_mode mode, const char *cmd)
  256. {
  257. struct device_node *np;
  258. u32 val;
  259. void __iomem *addr;
  260. val = 0x1;
  261. addr = EXYNOS_SWRESET;
  262. if (of_machine_is_compatible("samsung,exynos5440")) {
  263. u32 status;
  264. np = of_find_compatible_node(NULL, NULL, "samsung,exynos5440-clock");
  265. addr = of_iomap(np, 0) + 0xbc;
  266. status = __raw_readl(addr);
  267. addr = of_iomap(np, 0) + 0xcc;
  268. val = __raw_readl(addr);
  269. val = (val & 0xffff0000) | (status & 0xffff);
  270. }
  271. __raw_writel(val, addr);
  272. }
  273. static struct platform_device exynos_cpuidle = {
  274. .name = "exynos_cpuidle",
  275. .id = -1,
  276. };
  277. void __init exynos_cpuidle_init(void)
  278. {
  279. platform_device_register(&exynos_cpuidle);
  280. }
  281. void __init exynos_init_late(void)
  282. {
  283. if (of_machine_is_compatible("samsung,exynos5440"))
  284. /* to be supported later */
  285. return;
  286. exynos_pm_late_initcall();
  287. }
  288. static int __init exynos_fdt_map_chipid(unsigned long node, const char *uname,
  289. int depth, void *data)
  290. {
  291. struct map_desc iodesc;
  292. __be32 *reg;
  293. unsigned long len;
  294. if (!of_flat_dt_is_compatible(node, "samsung,exynos4210-chipid") &&
  295. !of_flat_dt_is_compatible(node, "samsung,exynos5440-clock"))
  296. return 0;
  297. reg = of_get_flat_dt_prop(node, "reg", &len);
  298. if (reg == NULL || len != (sizeof(unsigned long) * 2))
  299. return 0;
  300. iodesc.pfn = __phys_to_pfn(be32_to_cpu(reg[0]));
  301. iodesc.length = be32_to_cpu(reg[1]) - 1;
  302. iodesc.virtual = (unsigned long)S5P_VA_CHIPID;
  303. iodesc.type = MT_DEVICE;
  304. iotable_init(&iodesc, 1);
  305. return 1;
  306. }
  307. /*
  308. * exynos_map_io
  309. *
  310. * register the standard cpu IO areas
  311. */
  312. void __init exynos_init_io(void)
  313. {
  314. debug_ll_io_init();
  315. of_scan_flat_dt(exynos_fdt_map_chipid, NULL);
  316. /* detect cpu id and rev. */
  317. s5p_init_cpu(S5P_VA_CHIPID);
  318. s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
  319. }
  320. static void __init exynos4_map_io(void)
  321. {
  322. iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
  323. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
  324. iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
  325. else
  326. iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
  327. if (soc_is_exynos4210())
  328. iotable_init(exynos4210_iodesc, ARRAY_SIZE(exynos4210_iodesc));
  329. if (soc_is_exynos4212() || soc_is_exynos4412())
  330. iotable_init(exynos4x12_iodesc, ARRAY_SIZE(exynos4x12_iodesc));
  331. }
  332. static void __init exynos5_map_io(void)
  333. {
  334. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  335. if (soc_is_exynos5250())
  336. iotable_init(exynos5250_iodesc, ARRAY_SIZE(exynos5250_iodesc));
  337. }
  338. void __init exynos_init_time(void)
  339. {
  340. of_clk_init(NULL);
  341. clocksource_of_init();
  342. }
  343. struct bus_type exynos_subsys = {
  344. .name = "exynos-core",
  345. .dev_name = "exynos-core",
  346. };
  347. static struct device exynos4_dev = {
  348. .bus = &exynos_subsys,
  349. };
  350. static int __init exynos_core_init(void)
  351. {
  352. return subsys_system_register(&exynos_subsys, NULL);
  353. }
  354. core_initcall(exynos_core_init);
  355. static int __init exynos4_l2x0_cache_init(void)
  356. {
  357. int ret;
  358. ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
  359. if (ret)
  360. return ret;
  361. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  362. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  363. return 0;
  364. }
  365. early_initcall(exynos4_l2x0_cache_init);
  366. static int __init exynos_init(void)
  367. {
  368. printk(KERN_INFO "EXYNOS: Initializing architecture\n");
  369. return device_register(&exynos4_dev);
  370. }