common.c 9.6 KB

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