common.c 9.8 KB

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