blob: 68b4b8eb63dc65ecb74759b8730c0855e6c9fbff [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>
13#include <linux/interrupt.h>
14#include <linux/irq.h>
15#include <linux/io.h>
Linus Torvalds7affca32012-01-07 12:03:30 -080016#include <linux/device.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010017#include <linux/gpio.h>
18#include <linux/sched.h>
19#include <linux/serial_core.h>
Arnd Bergmann237c78b2012-01-07 12:30:20 +000020#include <linux/of.h>
Doug Anderson5b7897d2012-11-27 11:53:14 -080021#include <linux/of_fdt.h>
Arnd Bergmann237c78b2012-01-07 12:30:20 +000022#include <linux/of_irq.h>
Thomas Abraham1e60bc02012-05-15 16:18:35 +090023#include <linux/export.h>
24#include <linux/irqdomain.h>
Thomas Abrahame873a472012-05-15 16:25:23 +090025#include <linux/of_address.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010026
27#include <asm/proc-fns.h>
Arnd Bergmann40ba95f2012-01-07 11:51:28 +000028#include <asm/exception.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010029#include <asm/hardware/cache-l2x0.h>
30#include <asm/hardware/gic.h>
31#include <asm/mach/map.h>
32#include <asm/mach/irq.h>
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -080033#include <asm/cacheflush.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010034
35#include <mach/regs-irq.h>
36#include <mach/regs-pmu.h>
37#include <mach/regs-gpio.h>
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -080038#include <mach/pmu.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010039
40#include <plat/cpu.h>
41#include <plat/clock.h>
42#include <plat/devs.h>
43#include <plat/pm.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010044#include <plat/sdhci.h>
45#include <plat/gpio-cfg.h>
46#include <plat/adc-core.h>
47#include <plat/fb-core.h>
48#include <plat/fimc-core.h>
49#include <plat/iic-core.h>
50#include <plat/tv-core.h>
Heiko Stuebner308b3af2012-10-17 16:47:11 +090051#include <plat/spi-core.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010052#include <plat/regs-serial.h>
53
54#include "common.h"
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -080055#define L2_AUX_VAL 0x7C470001
56#define L2_AUX_MASK 0xC200ffff
Kukjin Kimcc511b82011-12-27 08:18:36 +010057
Kukjin Kimcc511b82011-12-27 08:18:36 +010058static const char name_exynos4210[] = "EXYNOS4210";
59static const char name_exynos4212[] = "EXYNOS4212";
60static const char name_exynos4412[] = "EXYNOS4412";
Kukjin Kim94c7ca72012-02-11 22:15:45 +090061static const char name_exynos5250[] = "EXYNOS5250";
Kukjin Kim2edb36c2012-11-15 15:48:56 +090062static const char name_exynos5440[] = "EXYNOS5440";
Kukjin Kimcc511b82011-12-27 08:18:36 +010063
Kukjin Kim906c7892012-02-11 21:27:08 +090064static void exynos4_map_io(void);
Kukjin Kim94c7ca72012-02-11 22:15:45 +090065static void exynos5_map_io(void);
Kukjin Kim2edb36c2012-11-15 15:48:56 +090066static void exynos5440_map_io(void);
Kukjin Kim906c7892012-02-11 21:27:08 +090067static void exynos4_init_clocks(int xtal);
Kukjin Kim94c7ca72012-02-11 22:15:45 +090068static void exynos5_init_clocks(int xtal);
Kukjin Kim920f4882012-01-24 20:52:52 +090069static void exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no);
Kukjin Kim906c7892012-02-11 21:27:08 +090070static int exynos_init(void);
Kukjin Kimcc511b82011-12-27 08:18:36 +010071
72static struct cpu_table cpu_ids[] __initdata = {
73 {
74 .idcode = EXYNOS4210_CPU_ID,
75 .idmask = EXYNOS4_CPU_MASK,
76 .map_io = exynos4_map_io,
77 .init_clocks = exynos4_init_clocks,
Kukjin Kim920f4882012-01-24 20:52:52 +090078 .init_uarts = exynos_init_uarts,
Kukjin Kimcc511b82011-12-27 08:18:36 +010079 .init = exynos_init,
80 .name = name_exynos4210,
81 }, {
82 .idcode = EXYNOS4212_CPU_ID,
83 .idmask = EXYNOS4_CPU_MASK,
84 .map_io = exynos4_map_io,
85 .init_clocks = exynos4_init_clocks,
Kukjin Kim920f4882012-01-24 20:52:52 +090086 .init_uarts = exynos_init_uarts,
Kukjin Kimcc511b82011-12-27 08:18:36 +010087 .init = exynos_init,
88 .name = name_exynos4212,
89 }, {
90 .idcode = EXYNOS4412_CPU_ID,
91 .idmask = EXYNOS4_CPU_MASK,
92 .map_io = exynos4_map_io,
93 .init_clocks = exynos4_init_clocks,
Kukjin Kim920f4882012-01-24 20:52:52 +090094 .init_uarts = exynos_init_uarts,
Kukjin Kimcc511b82011-12-27 08:18:36 +010095 .init = exynos_init,
96 .name = name_exynos4412,
Kukjin Kim94c7ca72012-02-11 22:15:45 +090097 }, {
98 .idcode = EXYNOS5250_SOC_ID,
99 .idmask = EXYNOS5_SOC_MASK,
100 .map_io = exynos5_map_io,
101 .init_clocks = exynos5_init_clocks,
102 .init_uarts = exynos_init_uarts,
103 .init = exynos_init,
104 .name = name_exynos5250,
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900105 }, {
106 .idcode = EXYNOS5440_SOC_ID,
107 .idmask = EXYNOS5_SOC_MASK,
108 .map_io = exynos5440_map_io,
109 .init = exynos_init,
110 .name = name_exynos5440,
Kukjin Kimcc511b82011-12-27 08:18:36 +0100111 },
112};
113
114/* Initial IO mappings */
115
116static struct map_desc exynos_iodesc[] __initdata = {
117 {
118 .virtual = (unsigned long)S5P_VA_CHIPID,
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900119 .pfn = __phys_to_pfn(EXYNOS_PA_CHIPID),
Kukjin Kimcc511b82011-12-27 08:18:36 +0100120 .length = SZ_4K,
121 .type = MT_DEVICE,
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900122 },
123};
124
Doug Anderson5b7897d2012-11-27 11:53:14 -0800125#ifdef CONFIG_ARCH_EXYNOS5
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900126static struct map_desc exynos5440_iodesc[] __initdata = {
127 {
128 .virtual = (unsigned long)S5P_VA_CHIPID,
129 .pfn = __phys_to_pfn(EXYNOS5440_PA_CHIPID),
130 .length = SZ_4K,
131 .type = MT_DEVICE,
132 },
133};
Doug Anderson5b7897d2012-11-27 11:53:14 -0800134#endif
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900135
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900136static struct map_desc exynos4_iodesc[] __initdata = {
137 {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100138 .virtual = (unsigned long)S3C_VA_SYS,
139 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
140 .length = SZ_64K,
141 .type = MT_DEVICE,
142 }, {
143 .virtual = (unsigned long)S3C_VA_TIMER,
144 .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
145 .length = SZ_16K,
146 .type = MT_DEVICE,
147 }, {
148 .virtual = (unsigned long)S3C_VA_WATCHDOG,
149 .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
150 .length = SZ_4K,
151 .type = MT_DEVICE,
152 }, {
153 .virtual = (unsigned long)S5P_VA_SROMC,
154 .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
155 .length = SZ_4K,
156 .type = MT_DEVICE,
157 }, {
158 .virtual = (unsigned long)S5P_VA_SYSTIMER,
159 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
160 .length = SZ_4K,
161 .type = MT_DEVICE,
162 }, {
163 .virtual = (unsigned long)S5P_VA_PMU,
164 .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
165 .length = SZ_64K,
166 .type = MT_DEVICE,
167 }, {
168 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
169 .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
170 .length = SZ_4K,
171 .type = MT_DEVICE,
172 }, {
173 .virtual = (unsigned long)S5P_VA_GIC_CPU,
174 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
175 .length = SZ_64K,
176 .type = MT_DEVICE,
177 }, {
178 .virtual = (unsigned long)S5P_VA_GIC_DIST,
179 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
180 .length = SZ_64K,
181 .type = MT_DEVICE,
182 }, {
183 .virtual = (unsigned long)S3C_VA_UART,
184 .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
185 .length = SZ_512K,
186 .type = MT_DEVICE,
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900187 }, {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100188 .virtual = (unsigned long)S5P_VA_CMU,
189 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
190 .length = SZ_128K,
191 .type = MT_DEVICE,
192 }, {
193 .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
194 .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
195 .length = SZ_8K,
196 .type = MT_DEVICE,
197 }, {
198 .virtual = (unsigned long)S5P_VA_L2CC,
199 .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
200 .length = SZ_4K,
201 .type = MT_DEVICE,
202 }, {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100203 .virtual = (unsigned long)S5P_VA_DMC0,
204 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
MyungJoo Ham2bde0b02011-12-01 15:12:30 +0900205 .length = SZ_64K,
206 .type = MT_DEVICE,
207 }, {
208 .virtual = (unsigned long)S5P_VA_DMC1,
209 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
210 .length = SZ_64K,
Kukjin Kimcc511b82011-12-27 08:18:36 +0100211 .type = MT_DEVICE,
212 }, {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100213 .virtual = (unsigned long)S3C_VA_USB_HSPHY,
214 .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
215 .length = SZ_4K,
216 .type = MT_DEVICE,
217 },
218};
219
220static struct map_desc exynos4_iodesc0[] __initdata = {
221 {
222 .virtual = (unsigned long)S5P_VA_SYSRAM,
223 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
224 .length = SZ_4K,
225 .type = MT_DEVICE,
226 },
227};
228
229static struct map_desc exynos4_iodesc1[] __initdata = {
230 {
231 .virtual = (unsigned long)S5P_VA_SYSRAM,
232 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
233 .length = SZ_4K,
234 .type = MT_DEVICE,
235 },
236};
237
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900238static struct map_desc exynos5_iodesc[] __initdata = {
239 {
240 .virtual = (unsigned long)S3C_VA_SYS,
241 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
242 .length = SZ_64K,
243 .type = MT_DEVICE,
244 }, {
245 .virtual = (unsigned long)S3C_VA_TIMER,
246 .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
247 .length = SZ_16K,
248 .type = MT_DEVICE,
249 }, {
250 .virtual = (unsigned long)S3C_VA_WATCHDOG,
251 .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
252 .length = SZ_4K,
253 .type = MT_DEVICE,
254 }, {
255 .virtual = (unsigned long)S5P_VA_SROMC,
256 .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
257 .length = SZ_4K,
258 .type = MT_DEVICE,
259 }, {
260 .virtual = (unsigned long)S5P_VA_SYSTIMER,
261 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSTIMER),
262 .length = SZ_4K,
263 .type = MT_DEVICE,
264 }, {
265 .virtual = (unsigned long)S5P_VA_SYSRAM,
266 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
267 .length = SZ_4K,
268 .type = MT_DEVICE,
269 }, {
270 .virtual = (unsigned long)S5P_VA_CMU,
271 .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
272 .length = 144 * SZ_1K,
273 .type = MT_DEVICE,
274 }, {
275 .virtual = (unsigned long)S5P_VA_PMU,
276 .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
277 .length = SZ_64K,
278 .type = MT_DEVICE,
279 }, {
280 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
281 .pfn = __phys_to_pfn(EXYNOS5_PA_COMBINER),
282 .length = SZ_4K,
283 .type = MT_DEVICE,
284 }, {
285 .virtual = (unsigned long)S3C_VA_UART,
286 .pfn = __phys_to_pfn(EXYNOS5_PA_UART),
287 .length = SZ_512K,
288 .type = MT_DEVICE,
289 }, {
290 .virtual = (unsigned long)S5P_VA_GIC_CPU,
291 .pfn = __phys_to_pfn(EXYNOS5_PA_GIC_CPU),
Changhwan Younc9ce7db2012-04-24 14:31:11 -0700292 .length = SZ_8K,
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900293 .type = MT_DEVICE,
294 }, {
295 .virtual = (unsigned long)S5P_VA_GIC_DIST,
296 .pfn = __phys_to_pfn(EXYNOS5_PA_GIC_DIST),
Changhwan Younc9ce7db2012-04-24 14:31:11 -0700297 .length = SZ_4K,
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900298 .type = MT_DEVICE,
299 },
300};
301
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900302static struct map_desc exynos5440_iodesc0[] __initdata = {
303 {
304 .virtual = (unsigned long)S3C_VA_UART,
305 .pfn = __phys_to_pfn(EXYNOS5440_PA_UART0),
306 .length = SZ_512K,
307 .type = MT_DEVICE,
308 },
309};
310
Russell King9eb48592012-01-03 11:56:53 +0100311void exynos4_restart(char mode, const char *cmd)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100312{
313 __raw_writel(0x1, S5P_SWRESET);
314}
315
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900316void exynos5_restart(char mode, const char *cmd)
317{
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900318 u32 val;
319 void __iomem *addr;
320
321 if (of_machine_is_compatible("samsung,exynos5250")) {
322 val = 0x1;
323 addr = EXYNOS_SWRESET;
324 } else if (of_machine_is_compatible("samsung,exynos5440")) {
325 val = (0x10 << 20) | (0x1 << 16);
326 addr = EXYNOS5440_SWRESET;
327 } else {
328 pr_err("%s: cannot support non-DT\n", __func__);
329 return;
330 }
331
332 __raw_writel(val, addr);
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900333}
334
Shawn Guobb13fab2012-04-26 10:35:40 +0800335void __init exynos_init_late(void)
336{
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900337 if (of_machine_is_compatible("samsung,exynos5440"))
338 /* to be supported later */
339 return;
340
Shawn Guobb13fab2012-04-26 10:35:40 +0800341 exynos_pm_late_initcall();
342}
343
Kukjin Kimcc511b82011-12-27 08:18:36 +0100344/*
345 * exynos_map_io
346 *
347 * register the standard cpu IO areas
348 */
349
350void __init exynos_init_io(struct map_desc *mach_desc, int size)
351{
Doug Anderson5b7897d2012-11-27 11:53:14 -0800352 struct map_desc *iodesc = exynos_iodesc;
353 int iodesc_sz = ARRAY_SIZE(exynos_iodesc);
354#if defined(CONFIG_OF) && defined(CONFIG_ARCH_EXYNOS5)
355 unsigned long root = of_get_flat_dt_root();
356
Kukjin Kimcc511b82011-12-27 08:18:36 +0100357 /* initialize the io descriptors we need for initialization */
Doug Anderson5b7897d2012-11-27 11:53:14 -0800358 if (of_flat_dt_is_compatible(root, "samsung,exynos5440")) {
359 iodesc = exynos5440_iodesc;
360 iodesc_sz = ARRAY_SIZE(exynos5440_iodesc);
361 }
362#endif
363
364 iotable_init(iodesc, iodesc_sz);
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900365
Kukjin Kimcc511b82011-12-27 08:18:36 +0100366 if (mach_desc)
367 iotable_init(mach_desc, size);
368
369 /* detect cpu id and rev. */
370 s5p_init_cpu(S5P_VA_CHIPID);
371
372 s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
373}
374
Kukjin Kim906c7892012-02-11 21:27:08 +0900375static void __init exynos4_map_io(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100376{
377 iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
378
379 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
380 iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
381 else
382 iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
383
384 /* initialize device information early */
385 exynos4_default_sdhci0();
386 exynos4_default_sdhci1();
387 exynos4_default_sdhci2();
388 exynos4_default_sdhci3();
389
390 s3c_adc_setname("samsung-adc-v3");
391
392 s3c_fimc_setname(0, "exynos4-fimc");
393 s3c_fimc_setname(1, "exynos4-fimc");
394 s3c_fimc_setname(2, "exynos4-fimc");
395 s3c_fimc_setname(3, "exynos4-fimc");
396
Thomas Abraham8482c812012-04-14 08:04:46 -0700397 s3c_sdhci_setname(0, "exynos4-sdhci");
398 s3c_sdhci_setname(1, "exynos4-sdhci");
399 s3c_sdhci_setname(2, "exynos4-sdhci");
400 s3c_sdhci_setname(3, "exynos4-sdhci");
401
Kukjin Kimcc511b82011-12-27 08:18:36 +0100402 /* The I2C bus controllers are directly compatible with s3c2440 */
403 s3c_i2c0_setname("s3c2440-i2c");
404 s3c_i2c1_setname("s3c2440-i2c");
405 s3c_i2c2_setname("s3c2440-i2c");
406
407 s5p_fb_setname(0, "exynos4-fb");
408 s5p_hdmi_setname("exynos4-hdmi");
Heiko Stuebner308b3af2012-10-17 16:47:11 +0900409
410 s3c64xx_spi_setname("exynos4210-spi");
Kukjin Kimcc511b82011-12-27 08:18:36 +0100411}
412
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900413static void __init exynos5_map_io(void)
414{
415 iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
416
Kukjin Kimbb19a752012-01-25 13:48:11 +0900417 s3c_device_i2c0.resource[0].start = EXYNOS5_PA_IIC(0);
418 s3c_device_i2c0.resource[0].end = EXYNOS5_PA_IIC(0) + SZ_4K - 1;
419 s3c_device_i2c0.resource[1].start = EXYNOS5_IRQ_IIC;
420 s3c_device_i2c0.resource[1].end = EXYNOS5_IRQ_IIC;
421
Thomas Abraham8482c812012-04-14 08:04:46 -0700422 s3c_sdhci_setname(0, "exynos4-sdhci");
423 s3c_sdhci_setname(1, "exynos4-sdhci");
424 s3c_sdhci_setname(2, "exynos4-sdhci");
425 s3c_sdhci_setname(3, "exynos4-sdhci");
426
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900427 /* The I2C bus controllers are directly compatible with s3c2440 */
428 s3c_i2c0_setname("s3c2440-i2c");
429 s3c_i2c1_setname("s3c2440-i2c");
430 s3c_i2c2_setname("s3c2440-i2c");
Heiko Stuebner308b3af2012-10-17 16:47:11 +0900431
432 s3c64xx_spi_setname("exynos4210-spi");
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900433}
434
Kukjin Kim906c7892012-02-11 21:27:08 +0900435static void __init exynos4_init_clocks(int xtal)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100436{
437 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
438
439 s3c24xx_register_baseclocks(xtal);
440 s5p_register_clocks(xtal);
441
442 if (soc_is_exynos4210())
443 exynos4210_register_clocks();
444 else if (soc_is_exynos4212() || soc_is_exynos4412())
445 exynos4212_register_clocks();
446
447 exynos4_register_clocks();
448 exynos4_setup_clocks();
449}
450
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900451static void __init exynos5440_map_io(void)
452{
453 iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
454}
455
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900456static void __init exynos5_init_clocks(int xtal)
457{
458 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
459
460 s3c24xx_register_baseclocks(xtal);
461 s5p_register_clocks(xtal);
462
463 exynos5_register_clocks();
464 exynos5_setup_clocks();
465}
466
Kukjin Kimcc511b82011-12-27 08:18:36 +0100467#define COMBINER_ENABLE_SET 0x0
468#define COMBINER_ENABLE_CLEAR 0x4
469#define COMBINER_INT_STATUS 0xC
470
471static DEFINE_SPINLOCK(irq_controller_lock);
472
473struct combiner_chip_data {
474 unsigned int irq_offset;
475 unsigned int irq_mask;
476 void __iomem *base;
477};
478
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900479static struct irq_domain *combiner_irq_domain;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100480static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
481
482static inline void __iomem *combiner_base(struct irq_data *data)
483{
484 struct combiner_chip_data *combiner_data =
485 irq_data_get_irq_chip_data(data);
486
487 return combiner_data->base;
488}
489
490static void combiner_mask_irq(struct irq_data *data)
491{
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900492 u32 mask = 1 << (data->hwirq % 32);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100493
494 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
495}
496
497static void combiner_unmask_irq(struct irq_data *data)
498{
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900499 u32 mask = 1 << (data->hwirq % 32);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100500
501 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
502}
503
504static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
505{
506 struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
507 struct irq_chip *chip = irq_get_chip(irq);
508 unsigned int cascade_irq, combiner_irq;
509 unsigned long status;
510
511 chained_irq_enter(chip, desc);
512
513 spin_lock(&irq_controller_lock);
514 status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
515 spin_unlock(&irq_controller_lock);
516 status &= chip_data->irq_mask;
517
518 if (status == 0)
519 goto out;
520
521 combiner_irq = __ffs(status);
522
523 cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
524 if (unlikely(cascade_irq >= NR_IRQS))
525 do_bad_IRQ(cascade_irq, desc);
526 else
527 generic_handle_irq(cascade_irq);
528
529 out:
530 chained_irq_exit(chip, desc);
531}
532
533static struct irq_chip combiner_chip = {
534 .name = "COMBINER",
535 .irq_mask = combiner_mask_irq,
536 .irq_unmask = combiner_unmask_irq,
537};
538
539static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
540{
Kukjin Kimbb19a752012-01-25 13:48:11 +0900541 unsigned int max_nr;
542
543 if (soc_is_exynos5250())
544 max_nr = EXYNOS5_MAX_COMBINER_NR;
545 else
546 max_nr = EXYNOS4_MAX_COMBINER_NR;
547
548 if (combiner_nr >= max_nr)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100549 BUG();
550 if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
551 BUG();
552 irq_set_chained_handler(irq, combiner_handle_cascade_irq);
553}
554
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900555static void __init combiner_init_one(unsigned int combiner_nr,
556 void __iomem *base)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100557{
Kukjin Kimcc511b82011-12-27 08:18:36 +0100558 combiner_data[combiner_nr].base = base;
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900559 combiner_data[combiner_nr].irq_offset = irq_find_mapping(
560 combiner_irq_domain, combiner_nr * MAX_IRQ_IN_COMBINER);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100561 combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3);
562
563 /* Disable all interrupts */
Kukjin Kimcc511b82011-12-27 08:18:36 +0100564 __raw_writel(combiner_data[combiner_nr].irq_mask,
565 base + COMBINER_ENABLE_CLEAR);
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900566}
Kukjin Kimcc511b82011-12-27 08:18:36 +0100567
Thomas Abrahame873a472012-05-15 16:25:23 +0900568#ifdef CONFIG_OF
569static int combiner_irq_domain_xlate(struct irq_domain *d,
570 struct device_node *controller,
571 const u32 *intspec, unsigned int intsize,
572 unsigned long *out_hwirq,
573 unsigned int *out_type)
574{
575 if (d->of_node != controller)
576 return -EINVAL;
577
578 if (intsize < 2)
579 return -EINVAL;
580
581 *out_hwirq = intspec[0] * MAX_IRQ_IN_COMBINER + intspec[1];
582 *out_type = 0;
583
584 return 0;
585}
586#else
587static int combiner_irq_domain_xlate(struct irq_domain *d,
588 struct device_node *controller,
589 const u32 *intspec, unsigned int intsize,
590 unsigned long *out_hwirq,
591 unsigned int *out_type)
592{
593 return -EINVAL;
594}
595#endif
596
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900597static int combiner_irq_domain_map(struct irq_domain *d, unsigned int irq,
598 irq_hw_number_t hw)
599{
600 irq_set_chip_and_handler(irq, &combiner_chip, handle_level_irq);
601 irq_set_chip_data(irq, &combiner_data[hw >> 3]);
602 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100603
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900604 return 0;
605}
606
607static struct irq_domain_ops combiner_irq_domain_ops = {
Thomas Abrahame873a472012-05-15 16:25:23 +0900608 .xlate = combiner_irq_domain_xlate,
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900609 .map = combiner_irq_domain_map,
610};
611
Sachin Kamat2a2b0e22012-07-12 16:34:51 +0900612static void __init combiner_init(void __iomem *combiner_base,
613 struct device_node *np)
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900614{
Thomas Abrahame873a472012-05-15 16:25:23 +0900615 int i, irq, irq_base;
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900616 unsigned int max_nr, nr_irq;
617
Thomas Abrahame873a472012-05-15 16:25:23 +0900618 if (np) {
619 if (of_property_read_u32(np, "samsung,combiner-nr", &max_nr)) {
620 pr_warning("%s: number of combiners not specified, "
621 "setting default as %d.\n",
622 __func__, EXYNOS4_MAX_COMBINER_NR);
623 max_nr = EXYNOS4_MAX_COMBINER_NR;
624 }
625 } else {
626 max_nr = soc_is_exynos5250() ? EXYNOS5_MAX_COMBINER_NR :
627 EXYNOS4_MAX_COMBINER_NR;
628 }
Thomas Abraham1e60bc02012-05-15 16:18:35 +0900629 nr_irq = max_nr * MAX_IRQ_IN_COMBINER;
630
631 irq_base = irq_alloc_descs(COMBINER_IRQ(0, 0), 1, nr_irq, 0);
632 if (IS_ERR_VALUE(irq_base)) {
633 irq_base = COMBINER_IRQ(0, 0);
634 pr_warning("%s: irq desc alloc failed. Continuing with %d as linux irq base\n", __func__, irq_base);
635 }
636
637 combiner_irq_domain = irq_domain_add_legacy(np, nr_irq, irq_base, 0,
638 &combiner_irq_domain_ops, &combiner_data);
639 if (WARN_ON(!combiner_irq_domain)) {
640 pr_warning("%s: irq domain init failed\n", __func__);
641 return;
642 }
643
644 for (i = 0; i < max_nr; i++) {
645 combiner_init_one(i, combiner_base + (i >> 2) * 0x10);
Arnd Bergmann820f3dd2012-05-16 22:10:14 +0200646 irq = IRQ_SPI(i);
647#ifdef CONFIG_OF
648 if (np)
649 irq = irq_of_parse_and_map(np, i);
650#endif
Thomas Abrahame873a472012-05-15 16:25:23 +0900651 combiner_cascade_irq(i, irq);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100652 }
653}
654
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000655#ifdef CONFIG_OF
Thomas Abrahame873a472012-05-15 16:25:23 +0900656int __init combiner_of_init(struct device_node *np, struct device_node *parent)
657{
658 void __iomem *combiner_base;
659
660 combiner_base = of_iomap(np, 0);
661 if (!combiner_base) {
662 pr_err("%s: failed to map combiner registers\n", __func__);
663 return -ENXIO;
664 }
665
666 combiner_init(combiner_base, np);
667
668 return 0;
669}
670
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900671static const struct of_device_id exynos_dt_irq_match[] = {
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000672 { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, },
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900673 { .compatible = "arm,cortex-a15-gic", .data = gic_of_init, },
Thomas Abrahame873a472012-05-15 16:25:23 +0900674 { .compatible = "samsung,exynos4210-combiner",
675 .data = combiner_of_init, },
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000676 {},
677};
678#endif
Kukjin Kimcc511b82011-12-27 08:18:36 +0100679
680void __init exynos4_init_irq(void)
681{
Arnd Bergmann40ba95f2012-01-07 11:51:28 +0000682 unsigned int gic_bank_offset;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100683
684 gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
685
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000686 if (!of_have_populated_dt())
Grant Likely75294952012-02-14 14:06:57 -0700687 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000688#ifdef CONFIG_OF
689 else
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900690 of_irq_init(exynos_dt_irq_match);
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000691#endif
Kukjin Kimcc511b82011-12-27 08:18:36 +0100692
Thomas Abrahame873a472012-05-15 16:25:23 +0900693 if (!of_have_populated_dt())
694 combiner_init(S5P_VA_COMBINER_BASE, NULL);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100695
696 /*
697 * The parameters of s5p_init_irq() are for VIC init.
698 * Theses parameters should be NULL and 0 because EXYNOS4
699 * uses GIC instead of VIC.
700 */
701 s5p_init_irq(NULL, 0);
702}
703
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900704void __init exynos5_init_irq(void)
705{
Tushar Behera6fff5a12012-04-24 13:25:01 -0700706#ifdef CONFIG_OF
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900707 of_irq_init(exynos_dt_irq_match);
Tushar Behera6fff5a12012-04-24 13:25:01 -0700708#endif
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900709 /*
710 * The parameters of s5p_init_irq() are for VIC init.
711 * Theses parameters should be NULL and 0 because EXYNOS4
712 * uses GIC instead of VIC.
713 */
714 s5p_init_irq(NULL, 0);
715}
716
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900717struct bus_type exynos_subsys = {
718 .name = "exynos-core",
719 .dev_name = "exynos-core",
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900720};
721
Linus Torvalds7affca32012-01-07 12:03:30 -0800722static struct device exynos4_dev = {
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900723 .bus = &exynos_subsys,
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900724};
725
726static int __init exynos_core_init(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100727{
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900728 return subsys_system_register(&exynos_subsys, NULL);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100729}
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900730core_initcall(exynos_core_init);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100731
732#ifdef CONFIG_CACHE_L2X0
733static int __init exynos4_l2x0_cache_init(void)
734{
Il Hane1b19942012-04-05 07:59:36 -0700735 int ret;
736
Kukjin Kim2edb36c2012-11-15 15:48:56 +0900737 if (soc_is_exynos5250() || soc_is_exynos5440())
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900738 return 0;
739
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -0800740 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
741 if (!ret) {
742 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
743 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
744 return 0;
745 }
Kukjin Kimcc511b82011-12-27 08:18:36 +0100746
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800747 if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
748 l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
749 /* TAG, Data Latency Control: 2 cycles */
750 l2x0_saved_regs.tag_latency = 0x110;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100751
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800752 if (soc_is_exynos4212() || soc_is_exynos4412())
753 l2x0_saved_regs.data_latency = 0x120;
754 else
755 l2x0_saved_regs.data_latency = 0x110;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100756
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800757 l2x0_saved_regs.prefetch_ctrl = 0x30000007;
758 l2x0_saved_regs.pwr_ctrl =
759 (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100760
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800761 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100762
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800763 __raw_writel(l2x0_saved_regs.tag_latency,
764 S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
765 __raw_writel(l2x0_saved_regs.data_latency,
766 S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
767
768 /* L2X0 Prefetch Control */
769 __raw_writel(l2x0_saved_regs.prefetch_ctrl,
770 S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
771
772 /* L2X0 Power Control */
773 __raw_writel(l2x0_saved_regs.pwr_ctrl,
774 S5P_VA_L2CC + L2X0_POWER_CTRL);
775
776 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
777 clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
778 }
Kukjin Kimcc511b82011-12-27 08:18:36 +0100779
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -0800780 l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100781 return 0;
782}
Kukjin Kimcc511b82011-12-27 08:18:36 +0100783early_initcall(exynos4_l2x0_cache_init);
784#endif
785
Kukjin Kim906c7892012-02-11 21:27:08 +0900786static int __init exynos_init(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100787{
788 printk(KERN_INFO "EXYNOS: Initializing architecture\n");
Kukjin Kim94c7ca72012-02-11 22:15:45 +0900789
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900790 return device_register(&exynos4_dev);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100791}
792
Kukjin Kimcc511b82011-12-27 08:18:36 +0100793/* uart registration process */
794
Kukjin Kim920f4882012-01-24 20:52:52 +0900795static void __init exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100796{
797 struct s3c2410_uartcfg *tcfg = cfg;
798 u32 ucnt;
799
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000800 for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
801 tcfg->has_fracval = 1;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100802
Kukjin Kim171c0672012-02-10 11:57:53 +0900803 if (soc_is_exynos5250())
804 s3c24xx_init_uartdevs("exynos4210-uart", exynos5_uart_resources, cfg, no);
805 else
806 s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100807}
808
Eunki Kim330c90a2012-03-14 01:43:31 -0700809static void __iomem *exynos_eint_base;
810
Kukjin Kimcc511b82011-12-27 08:18:36 +0100811static DEFINE_SPINLOCK(eint_lock);
812
813static unsigned int eint0_15_data[16];
814
Eunki Kim330c90a2012-03-14 01:43:31 -0700815static inline int exynos4_irq_to_gpio(unsigned int irq)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100816{
Eunki Kim330c90a2012-03-14 01:43:31 -0700817 if (irq < IRQ_EINT(0))
818 return -EINVAL;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100819
Eunki Kim330c90a2012-03-14 01:43:31 -0700820 irq -= IRQ_EINT(0);
821 if (irq < 8)
822 return EXYNOS4_GPX0(irq);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100823
Eunki Kim330c90a2012-03-14 01:43:31 -0700824 irq -= 8;
825 if (irq < 8)
826 return EXYNOS4_GPX1(irq);
827
828 irq -= 8;
829 if (irq < 8)
830 return EXYNOS4_GPX2(irq);
831
832 irq -= 8;
833 if (irq < 8)
834 return EXYNOS4_GPX3(irq);
835
836 return -EINVAL;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100837}
838
Eunki Kim330c90a2012-03-14 01:43:31 -0700839static inline int exynos5_irq_to_gpio(unsigned int irq)
840{
841 if (irq < IRQ_EINT(0))
842 return -EINVAL;
843
844 irq -= IRQ_EINT(0);
845 if (irq < 8)
846 return EXYNOS5_GPX0(irq);
847
848 irq -= 8;
849 if (irq < 8)
850 return EXYNOS5_GPX1(irq);
851
852 irq -= 8;
853 if (irq < 8)
854 return EXYNOS5_GPX2(irq);
855
856 irq -= 8;
857 if (irq < 8)
858 return EXYNOS5_GPX3(irq);
859
860 return -EINVAL;
861}
862
Kukjin Kimbb19a752012-01-25 13:48:11 +0900863static unsigned int exynos4_eint0_15_src_int[16] = {
864 EXYNOS4_IRQ_EINT0,
865 EXYNOS4_IRQ_EINT1,
866 EXYNOS4_IRQ_EINT2,
867 EXYNOS4_IRQ_EINT3,
868 EXYNOS4_IRQ_EINT4,
869 EXYNOS4_IRQ_EINT5,
870 EXYNOS4_IRQ_EINT6,
871 EXYNOS4_IRQ_EINT7,
872 EXYNOS4_IRQ_EINT8,
873 EXYNOS4_IRQ_EINT9,
874 EXYNOS4_IRQ_EINT10,
875 EXYNOS4_IRQ_EINT11,
876 EXYNOS4_IRQ_EINT12,
877 EXYNOS4_IRQ_EINT13,
878 EXYNOS4_IRQ_EINT14,
879 EXYNOS4_IRQ_EINT15,
880};
Kukjin Kimcc511b82011-12-27 08:18:36 +0100881
Kukjin Kimbb19a752012-01-25 13:48:11 +0900882static unsigned int exynos5_eint0_15_src_int[16] = {
883 EXYNOS5_IRQ_EINT0,
884 EXYNOS5_IRQ_EINT1,
885 EXYNOS5_IRQ_EINT2,
886 EXYNOS5_IRQ_EINT3,
887 EXYNOS5_IRQ_EINT4,
888 EXYNOS5_IRQ_EINT5,
889 EXYNOS5_IRQ_EINT6,
890 EXYNOS5_IRQ_EINT7,
891 EXYNOS5_IRQ_EINT8,
892 EXYNOS5_IRQ_EINT9,
893 EXYNOS5_IRQ_EINT10,
894 EXYNOS5_IRQ_EINT11,
895 EXYNOS5_IRQ_EINT12,
896 EXYNOS5_IRQ_EINT13,
897 EXYNOS5_IRQ_EINT14,
898 EXYNOS5_IRQ_EINT15,
899};
Eunki Kim330c90a2012-03-14 01:43:31 -0700900static inline void exynos_irq_eint_mask(struct irq_data *data)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100901{
902 u32 mask;
903
904 spin_lock(&eint_lock);
Eunki Kim330c90a2012-03-14 01:43:31 -0700905 mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
906 mask |= EINT_OFFSET_BIT(data->irq);
907 __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100908 spin_unlock(&eint_lock);
909}
910
Eunki Kim330c90a2012-03-14 01:43:31 -0700911static void exynos_irq_eint_unmask(struct irq_data *data)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100912{
913 u32 mask;
914
915 spin_lock(&eint_lock);
Eunki Kim330c90a2012-03-14 01:43:31 -0700916 mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
917 mask &= ~(EINT_OFFSET_BIT(data->irq));
918 __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100919 spin_unlock(&eint_lock);
920}
921
Eunki Kim330c90a2012-03-14 01:43:31 -0700922static inline void exynos_irq_eint_ack(struct irq_data *data)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100923{
Eunki Kim330c90a2012-03-14 01:43:31 -0700924 __raw_writel(EINT_OFFSET_BIT(data->irq),
925 EINT_PEND(exynos_eint_base, data->irq));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100926}
927
Eunki Kim330c90a2012-03-14 01:43:31 -0700928static void exynos_irq_eint_maskack(struct irq_data *data)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100929{
Eunki Kim330c90a2012-03-14 01:43:31 -0700930 exynos_irq_eint_mask(data);
931 exynos_irq_eint_ack(data);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100932}
933
Eunki Kim330c90a2012-03-14 01:43:31 -0700934static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100935{
936 int offs = EINT_OFFSET(data->irq);
937 int shift;
938 u32 ctrl, mask;
939 u32 newvalue = 0;
940
941 switch (type) {
942 case IRQ_TYPE_EDGE_RISING:
943 newvalue = S5P_IRQ_TYPE_EDGE_RISING;
944 break;
945
946 case IRQ_TYPE_EDGE_FALLING:
947 newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
948 break;
949
950 case IRQ_TYPE_EDGE_BOTH:
951 newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
952 break;
953
954 case IRQ_TYPE_LEVEL_LOW:
955 newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
956 break;
957
958 case IRQ_TYPE_LEVEL_HIGH:
959 newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
960 break;
961
962 default:
963 printk(KERN_ERR "No such irq type %d", type);
964 return -EINVAL;
965 }
966
967 shift = (offs & 0x7) * 4;
968 mask = 0x7 << shift;
969
970 spin_lock(&eint_lock);
Eunki Kim330c90a2012-03-14 01:43:31 -0700971 ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100972 ctrl &= ~mask;
973 ctrl |= newvalue << shift;
Eunki Kim330c90a2012-03-14 01:43:31 -0700974 __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100975 spin_unlock(&eint_lock);
976
Eunki Kim330c90a2012-03-14 01:43:31 -0700977 if (soc_is_exynos5250())
978 s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
979 else
980 s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
Kukjin Kimcc511b82011-12-27 08:18:36 +0100981
982 return 0;
983}
984
Eunki Kim330c90a2012-03-14 01:43:31 -0700985static struct irq_chip exynos_irq_eint = {
986 .name = "exynos-eint",
987 .irq_mask = exynos_irq_eint_mask,
988 .irq_unmask = exynos_irq_eint_unmask,
989 .irq_mask_ack = exynos_irq_eint_maskack,
990 .irq_ack = exynos_irq_eint_ack,
991 .irq_set_type = exynos_irq_eint_set_type,
Kukjin Kimcc511b82011-12-27 08:18:36 +0100992#ifdef CONFIG_PM
993 .irq_set_wake = s3c_irqext_wake,
994#endif
995};
996
997/*
998 * exynos4_irq_demux_eint
999 *
1000 * This function demuxes the IRQ from from EINTs 16 to 31.
1001 * It is designed to be inlined into the specific handler
1002 * s5p_irq_demux_eintX_Y.
1003 *
1004 * Each EINT pend/mask registers handle eight of them.
1005 */
Eunki Kim330c90a2012-03-14 01:43:31 -07001006static inline void exynos_irq_demux_eint(unsigned int start)
Kukjin Kimcc511b82011-12-27 08:18:36 +01001007{
1008 unsigned int irq;
1009
Eunki Kim330c90a2012-03-14 01:43:31 -07001010 u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
1011 u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
Kukjin Kimcc511b82011-12-27 08:18:36 +01001012
1013 status &= ~mask;
1014 status &= 0xff;
1015
1016 while (status) {
1017 irq = fls(status) - 1;
1018 generic_handle_irq(irq + start);
1019 status &= ~(1 << irq);
1020 }
1021}
1022
Eunki Kim330c90a2012-03-14 01:43:31 -07001023static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
Kukjin Kimcc511b82011-12-27 08:18:36 +01001024{
1025 struct irq_chip *chip = irq_get_chip(irq);
1026 chained_irq_enter(chip, desc);
Eunki Kim330c90a2012-03-14 01:43:31 -07001027 exynos_irq_demux_eint(IRQ_EINT(16));
1028 exynos_irq_demux_eint(IRQ_EINT(24));
Kukjin Kimcc511b82011-12-27 08:18:36 +01001029 chained_irq_exit(chip, desc);
1030}
1031
Kukjin Kimbb19a752012-01-25 13:48:11 +09001032static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
Kukjin Kimcc511b82011-12-27 08:18:36 +01001033{
1034 u32 *irq_data = irq_get_handler_data(irq);
1035 struct irq_chip *chip = irq_get_chip(irq);
1036
1037 chained_irq_enter(chip, desc);
1038 chip->irq_mask(&desc->irq_data);
1039
1040 if (chip->irq_ack)
1041 chip->irq_ack(&desc->irq_data);
1042
1043 generic_handle_irq(*irq_data);
1044
1045 chip->irq_unmask(&desc->irq_data);
1046 chained_irq_exit(chip, desc);
1047}
1048
Eunki Kim330c90a2012-03-14 01:43:31 -07001049static int __init exynos_init_irq_eint(void)
Kukjin Kimcc511b82011-12-27 08:18:36 +01001050{
1051 int irq;
1052
Thomas Abrahamfef05c22012-09-07 06:07:40 +09001053#ifdef CONFIG_PINCTRL_SAMSUNG
1054 /*
1055 * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
1056 * functionality along with support for external gpio and wakeup
1057 * interrupts. If the samsung pinctrl driver is enabled and includes
1058 * the wakeup interrupt support, then the setting up external wakeup
1059 * interrupts here can be skipped. This check here is temporary to
1060 * allow exynos4 platforms that do not use Samsung pinctrl driver to
1061 * co-exist with platforms that do. When all of the Samsung Exynos4
1062 * platforms switch over to using the pinctrl driver, the wakeup
1063 * interrupt support code here can be completely removed.
1064 */
1065 struct device_node *pctrl_np, *wkup_np;
1066 const char *pctrl_compat = "samsung,pinctrl-exynos4210";
1067 const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
1068
1069 for_each_compatible_node(pctrl_np, NULL, pctrl_compat) {
1070 if (of_device_is_available(pctrl_np)) {
1071 wkup_np = of_find_compatible_node(pctrl_np, NULL,
1072 wkup_compat);
1073 if (wkup_np)
1074 return -ENODEV;
1075 }
1076 }
1077#endif
Kukjin Kim2edb36c2012-11-15 15:48:56 +09001078 if (soc_is_exynos5440())
1079 return 0;
Thomas Abrahamfef05c22012-09-07 06:07:40 +09001080
Kukjin Kim94c7ca72012-02-11 22:15:45 +09001081 if (soc_is_exynos5250())
Eunki Kim330c90a2012-03-14 01:43:31 -07001082 exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
1083 else
1084 exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
1085
1086 if (exynos_eint_base == NULL) {
1087 pr_err("unable to ioremap for EINT base address\n");
1088 return -ENOMEM;
1089 }
Kukjin Kim94c7ca72012-02-11 22:15:45 +09001090
Kukjin Kimcc511b82011-12-27 08:18:36 +01001091 for (irq = 0 ; irq <= 31 ; irq++) {
Eunki Kim330c90a2012-03-14 01:43:31 -07001092 irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
Kukjin Kimcc511b82011-12-27 08:18:36 +01001093 handle_level_irq);
1094 set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
1095 }
1096
Eunki Kim330c90a2012-03-14 01:43:31 -07001097 irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
Kukjin Kimcc511b82011-12-27 08:18:36 +01001098
1099 for (irq = 0 ; irq <= 15 ; irq++) {
1100 eint0_15_data[irq] = IRQ_EINT(irq);
1101
Kukjin Kimbb19a752012-01-25 13:48:11 +09001102 if (soc_is_exynos5250()) {
1103 irq_set_handler_data(exynos5_eint0_15_src_int[irq],
1104 &eint0_15_data[irq]);
1105 irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
1106 exynos_irq_eint0_15);
1107 } else {
1108 irq_set_handler_data(exynos4_eint0_15_src_int[irq],
1109 &eint0_15_data[irq]);
1110 irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
1111 exynos_irq_eint0_15);
1112 }
Kukjin Kimcc511b82011-12-27 08:18:36 +01001113 }
1114
1115 return 0;
1116}
Eunki Kim330c90a2012-03-14 01:43:31 -07001117arch_initcall(exynos_init_irq_eint);