blob: 61d2906ccefb3660b3061bb1782576bd0a3ec78e [file] [log] [blame]
Kukjin Kimcc511b82011-12-27 08:18:36 +01001/*
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
12#include <linux/kernel.h>
Tomasz Figa68a433f2013-05-25 06:27:29 +090013#include <linux/bitops.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010014#include <linux/interrupt.h>
15#include <linux/irq.h>
Rob Herringa900e5d2013-02-12 16:04:52 -060016#include <linux/irqchip.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010017#include <linux/io.h>
Linus Torvalds7affca32012-01-07 12:03:30 -080018#include <linux/device.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010019#include <linux/gpio.h>
Tomasz Figa68a433f2013-05-25 06:27:29 +090020#include <clocksource/samsung_pwm.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010021#include <linux/sched.h>
22#include <linux/serial_core.h>
Arnd Bergmann237c78b2012-01-07 12:30:20 +000023#include <linux/of.h>
Doug Anderson5b7897d2012-11-27 11:53:14 -080024#include <linux/of_fdt.h>
Arnd Bergmann237c78b2012-01-07 12:30:20 +000025#include <linux/of_irq.h>
Thomas Abraham1e60bc02012-05-15 16:18:35 +090026#include <linux/export.h>
27#include <linux/irqdomain.h>
Thomas Abrahame873a472012-05-15 16:25:23 +090028#include <linux/of_address.h>
Rob Herring520f7bd2012-12-27 13:10:24 -060029#include <linux/irqchip/arm-gic.h>
Catalin Marinasde88cbb2013-01-18 15:31:37 +000030#include <linux/irqchip/chained_irq.h>
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020031#include <linux/platform_device.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010032
33#include <asm/proc-fns.h>
Arnd Bergmann40ba95f2012-01-07 11:51:28 +000034#include <asm/exception.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010035#include <asm/hardware/cache-l2x0.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010036#include <asm/mach/map.h>
37#include <asm/mach/irq.h>
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -080038#include <asm/cacheflush.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010039
40#include <mach/regs-irq.h>
41#include <mach/regs-pmu.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010042
43#include <plat/cpu.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010044#include <plat/pm.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010045#include <plat/regs-serial.h>
46
47#include "common.h"
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -080048#define L2_AUX_VAL 0x7C470001
49#define L2_AUX_MASK 0xC200ffff
Kukjin Kimcc511b82011-12-27 08:18:36 +010050
Kukjin Kimcc511b82011-12-27 08:18:36 +010051static const char name_exynos4210[] = "EXYNOS4210";
52static const char name_exynos4212[] = "EXYNOS4212";
53static const char name_exynos4412[] = "EXYNOS4412";
Kukjin Kim94c7ca72012-02-11 22:15:45 +090054static const char name_exynos5250[] = "EXYNOS5250";
Chander Kashyap191d7542013-06-19 00:29:34 +090055static const char name_exynos5420[] = "EXYNOS5420";
Kukjin Kim2edb36c2012-11-15 15:48:56 +090056static const char name_exynos5440[] = "EXYNOS5440";
Kukjin Kimcc511b82011-12-27 08:18:36 +010057
Kukjin Kim906c7892012-02-11 21:27:08 +090058static void exynos4_map_io(void);
Kukjin Kim94c7ca72012-02-11 22:15:45 +090059static void exynos5_map_io(void);
Kukjin Kim906c7892012-02-11 21:27:08 +090060static int exynos_init(void);
Kukjin Kimcc511b82011-12-27 08:18:36 +010061
62static struct cpu_table cpu_ids[] __initdata = {
63 {
64 .idcode = EXYNOS4210_CPU_ID,
65 .idmask = EXYNOS4_CPU_MASK,
66 .map_io = exynos4_map_io,
Kukjin Kimcc511b82011-12-27 08:18:36 +010067 .init = exynos_init,
68 .name = name_exynos4210,
69 }, {
70 .idcode = EXYNOS4212_CPU_ID,
71 .idmask = EXYNOS4_CPU_MASK,
72 .map_io = exynos4_map_io,
Kukjin Kimcc511b82011-12-27 08:18:36 +010073 .init = exynos_init,
74 .name = name_exynos4212,
75 }, {
76 .idcode = EXYNOS4412_CPU_ID,
77 .idmask = EXYNOS4_CPU_MASK,
78 .map_io = exynos4_map_io,
Kukjin Kimcc511b82011-12-27 08:18:36 +010079 .init = exynos_init,
80 .name = name_exynos4412,
Kukjin Kim94c7ca72012-02-11 22:15:45 +090081 }, {
82 .idcode = EXYNOS5250_SOC_ID,
83 .idmask = EXYNOS5_SOC_MASK,
84 .map_io = exynos5_map_io,
Kukjin Kim94c7ca72012-02-11 22:15:45 +090085 .init = exynos_init,
86 .name = name_exynos5250,
Kukjin Kim2edb36c2012-11-15 15:48:56 +090087 }, {
Chander Kashyap191d7542013-06-19 00:29:34 +090088 .idcode = EXYNOS5420_SOC_ID,
89 .idmask = EXYNOS5_SOC_MASK,
90 .map_io = exynos5_map_io,
91 .init = exynos_init,
92 .name = name_exynos5420,
93 }, {
Kukjin Kim2edb36c2012-11-15 15:48:56 +090094 .idcode = EXYNOS5440_SOC_ID,
95 .idmask = EXYNOS5_SOC_MASK,
Kukjin Kim2edb36c2012-11-15 15:48:56 +090096 .init = exynos_init,
97 .name = name_exynos5440,
Kukjin Kimcc511b82011-12-27 08:18:36 +010098 },
99};
100
101/* Initial IO mappings */
102
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900103static struct map_desc exynos4_iodesc[] __initdata = {
104 {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100105 .virtual = (unsigned long)S3C_VA_SYS,
106 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
107 .length = SZ_64K,
108 .type = MT_DEVICE,
109 }, {
110 .virtual = (unsigned long)S3C_VA_TIMER,
111 .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
112 .length = SZ_16K,
113 .type = MT_DEVICE,
114 }, {
115 .virtual = (unsigned long)S3C_VA_WATCHDOG,
116 .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
117 .length = SZ_4K,
118 .type = MT_DEVICE,
119 }, {
120 .virtual = (unsigned long)S5P_VA_SROMC,
121 .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
122 .length = SZ_4K,
123 .type = MT_DEVICE,
124 }, {
125 .virtual = (unsigned long)S5P_VA_SYSTIMER,
126 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
127 .length = SZ_4K,
128 .type = MT_DEVICE,
129 }, {
130 .virtual = (unsigned long)S5P_VA_PMU,
131 .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
132 .length = SZ_64K,
133 .type = MT_DEVICE,
134 }, {
135 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
136 .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
137 .length = SZ_4K,
138 .type = MT_DEVICE,
139 }, {
140 .virtual = (unsigned long)S5P_VA_GIC_CPU,
141 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
142 .length = SZ_64K,
143 .type = MT_DEVICE,
144 }, {
145 .virtual = (unsigned long)S5P_VA_GIC_DIST,
146 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
147 .length = SZ_64K,
148 .type = MT_DEVICE,
149 }, {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100150 .virtual = (unsigned long)S5P_VA_CMU,
151 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
152 .length = SZ_128K,
153 .type = MT_DEVICE,
154 }, {
155 .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
156 .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
157 .length = SZ_8K,
158 .type = MT_DEVICE,
159 }, {
160 .virtual = (unsigned long)S5P_VA_L2CC,
161 .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
162 .length = SZ_4K,
163 .type = MT_DEVICE,
164 }, {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100165 .virtual = (unsigned long)S5P_VA_DMC0,
166 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
MyungJoo Ham2bde0b02011-12-01 15:12:30 +0900167 .length = SZ_64K,
168 .type = MT_DEVICE,
169 }, {
170 .virtual = (unsigned long)S5P_VA_DMC1,
171 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
172 .length = SZ_64K,
Kukjin Kimcc511b82011-12-27 08:18:36 +0100173 .type = MT_DEVICE,
174 }, {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100175 .virtual = (unsigned long)S3C_VA_USB_HSPHY,
176 .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
177 .length = SZ_4K,
178 .type = MT_DEVICE,
179 },
180};
181
182static struct map_desc exynos4_iodesc0[] __initdata = {
183 {
184 .virtual = (unsigned long)S5P_VA_SYSRAM,
185 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
186 .length = SZ_4K,
187 .type = MT_DEVICE,
188 },
189};
190
191static struct map_desc exynos4_iodesc1[] __initdata = {
192 {
193 .virtual = (unsigned long)S5P_VA_SYSRAM,
194 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
195 .length = SZ_4K,
196 .type = MT_DEVICE,
197 },
198};
199
Tomasz Figa41de8982012-12-11 13:58:43 +0900200static struct map_desc exynos4210_iodesc[] __initdata = {
201 {
202 .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
203 .pfn = __phys_to_pfn(EXYNOS4210_PA_SYSRAM_NS),
204 .length = SZ_4K,
205 .type = MT_DEVICE,
206 },
207};
208
209static struct map_desc exynos4x12_iodesc[] __initdata = {
210 {
211 .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
212 .pfn = __phys_to_pfn(EXYNOS4x12_PA_SYSRAM_NS),
213 .length = SZ_4K,
214 .type = MT_DEVICE,
215 },
216};
217
218static struct map_desc exynos5250_iodesc[] __initdata = {
219 {
220 .virtual = (unsigned long)S5P_VA_SYSRAM_NS,
221 .pfn = __phys_to_pfn(EXYNOS5250_PA_SYSRAM_NS),
222 .length = SZ_4K,
223 .type = MT_DEVICE,
224 },
225};
226
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900227static struct map_desc exynos5_iodesc[] __initdata = {
228 {
229 .virtual = (unsigned long)S3C_VA_SYS,
230 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
231 .length = SZ_64K,
232 .type = MT_DEVICE,
233 }, {
234 .virtual = (unsigned long)S3C_VA_TIMER,
235 .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
236 .length = SZ_16K,
237 .type = MT_DEVICE,
238 }, {
239 .virtual = (unsigned long)S3C_VA_WATCHDOG,
240 .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
241 .length = SZ_4K,
242 .type = MT_DEVICE,
243 }, {
244 .virtual = (unsigned long)S5P_VA_SROMC,
245 .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
246 .length = SZ_4K,
247 .type = MT_DEVICE,
248 }, {
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900249 .virtual = (unsigned long)S5P_VA_SYSRAM,
250 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
251 .length = SZ_4K,
252 .type = MT_DEVICE,
253 }, {
254 .virtual = (unsigned long)S5P_VA_CMU,
255 .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
256 .length = 144 * SZ_1K,
257 .type = MT_DEVICE,
258 }, {
259 .virtual = (unsigned long)S5P_VA_PMU,
260 .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
261 .length = SZ_64K,
262 .type = MT_DEVICE,
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900263 },
264};
265
Robin Holt7b6d8642013-07-08 16:01:40 -0700266void exynos4_restart(enum reboot_mode mode, const char *cmd)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100267{
268 __raw_writel(0x1, S5P_SWRESET);
269}
270
Robin Holt7b6d8642013-07-08 16:01:40 -0700271void exynos5_restart(enum reboot_mode mode, const char *cmd)
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900272{
Thomas Abraham60db7e52013-01-24 10:09:13 -0800273 struct device_node *np;
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900274 u32 val;
275 void __iomem *addr;
276
Chander Kashyapeff4e7c2013-06-19 00:29:35 +0900277 val = 0x1;
278 addr = EXYNOS_SWRESET;
279
280 if (of_machine_is_compatible("samsung,exynos5440")) {
Jungseok Lee1ba830c2013-05-25 06:33:03 +0900281 u32 status;
Thomas Abraham60db7e52013-01-24 10:09:13 -0800282 np = of_find_compatible_node(NULL, NULL, "samsung,exynos5440-clock");
Jungseok Lee1ba830c2013-05-25 06:33:03 +0900283
284 addr = of_iomap(np, 0) + 0xbc;
285 status = __raw_readl(addr);
286
Thomas Abraham60db7e52013-01-24 10:09:13 -0800287 addr = of_iomap(np, 0) + 0xcc;
Jungseok Lee1ba830c2013-05-25 06:33:03 +0900288 val = __raw_readl(addr);
289
290 val = (val & 0xffff0000) | (status & 0xffff);
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900291 }
292
293 __raw_writel(val, addr);
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900294}
295
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +0200296static struct platform_device exynos_cpuidle = {
297 .name = "exynos_cpuidle",
298 .id = -1,
299};
300
301void __init exynos_cpuidle_init(void)
302{
303 platform_device_register(&exynos_cpuidle);
304}
305
Shawn Guobb13fab2012-04-26 10:35:40 +0800306void __init exynos_init_late(void)
307{
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900308 if (of_machine_is_compatible("samsung,exynos5440"))
309 /* to be supported later */
310 return;
311
Shawn Guobb13fab2012-04-26 10:35:40 +0800312 exynos_pm_late_initcall();
313}
314
Arnd Bergmann564d06b2013-06-19 01:36:56 +0900315static int __init exynos_fdt_map_chipid(unsigned long node, const char *uname,
Thomas Abrahamf5f83c72013-04-23 22:46:53 +0900316 int depth, void *data)
317{
318 struct map_desc iodesc;
319 __be32 *reg;
320 unsigned long len;
321
322 if (!of_flat_dt_is_compatible(node, "samsung,exynos4210-chipid") &&
323 !of_flat_dt_is_compatible(node, "samsung,exynos5440-clock"))
324 return 0;
325
326 reg = of_get_flat_dt_prop(node, "reg", &len);
327 if (reg == NULL || len != (sizeof(unsigned long) * 2))
328 return 0;
329
330 iodesc.pfn = __phys_to_pfn(be32_to_cpu(reg[0]));
331 iodesc.length = be32_to_cpu(reg[1]) - 1;
332 iodesc.virtual = (unsigned long)S5P_VA_CHIPID;
333 iodesc.type = MT_DEVICE;
334 iotable_init(&iodesc, 1);
335 return 1;
336}
Thomas Abrahamf5f83c72013-04-23 22:46:53 +0900337
Kukjin Kimcc511b82011-12-27 08:18:36 +0100338/*
339 * exynos_map_io
340 *
341 * register the standard cpu IO areas
342 */
343
Arnd Bergmann0e2238e2013-06-19 01:36:47 +0900344void __init exynos_init_io(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100345{
Doug Anderson9c1fcdc2013-06-05 13:56:33 -0700346 debug_ll_io_init();
347
Tomasz Figa04fae592013-06-15 09:13:25 +0900348 of_scan_flat_dt(exynos_fdt_map_chipid, NULL);
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900349
Kukjin Kimcc511b82011-12-27 08:18:36 +0100350 /* detect cpu id and rev. */
351 s5p_init_cpu(S5P_VA_CHIPID);
352
353 s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
354}
355
Kukjin Kim906c7892012-02-11 21:27:08 +0900356static void __init exynos4_map_io(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100357{
358 iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
359
360 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
361 iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
362 else
363 iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
364
Tomasz Figa41de8982012-12-11 13:58:43 +0900365 if (soc_is_exynos4210())
366 iotable_init(exynos4210_iodesc, ARRAY_SIZE(exynos4210_iodesc));
367 if (soc_is_exynos4212() || soc_is_exynos4412())
368 iotable_init(exynos4x12_iodesc, ARRAY_SIZE(exynos4x12_iodesc));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100369}
370
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900371static void __init exynos5_map_io(void)
372{
373 iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
Tomasz Figa41de8982012-12-11 13:58:43 +0900374
375 if (soc_is_exynos5250())
376 iotable_init(exynos5250_iodesc, ARRAY_SIZE(exynos5250_iodesc));
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900377}
378
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900379struct bus_type exynos_subsys = {
380 .name = "exynos-core",
381 .dev_name = "exynos-core",
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900382};
383
Linus Torvalds7affca32012-01-07 12:03:30 -0800384static struct device exynos4_dev = {
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900385 .bus = &exynos_subsys,
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900386};
387
388static int __init exynos_core_init(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100389{
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900390 return subsys_system_register(&exynos_subsys, NULL);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100391}
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900392core_initcall(exynos_core_init);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100393
Kukjin Kimcc511b82011-12-27 08:18:36 +0100394static int __init exynos4_l2x0_cache_init(void)
395{
Il Hane1b19942012-04-05 07:59:36 -0700396 int ret;
397
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -0800398 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
Arnd Bergmann87107d82013-06-19 01:36:52 +0900399 if (ret)
400 return ret;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100401
Arnd Bergmann87107d82013-06-19 01:36:52 +0900402 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
403 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100404 return 0;
405}
Kukjin Kimcc511b82011-12-27 08:18:36 +0100406early_initcall(exynos4_l2x0_cache_init);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100407
Kukjin Kim906c7892012-02-11 21:27:08 +0900408static int __init exynos_init(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100409{
410 printk(KERN_INFO "EXYNOS: Initializing architecture\n");
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900411
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900412 return device_register(&exynos4_dev);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100413}