blob: 02696ac143bd0ccfe5350b3ebffe7294291e2396 [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>
21#include <linux/of_irq.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010022
23#include <asm/proc-fns.h>
Arnd Bergmann40ba95f2012-01-07 11:51:28 +000024#include <asm/exception.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010025#include <asm/hardware/cache-l2x0.h>
26#include <asm/hardware/gic.h>
27#include <asm/mach/map.h>
28#include <asm/mach/irq.h>
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -080029#include <asm/cacheflush.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010030
31#include <mach/regs-irq.h>
32#include <mach/regs-pmu.h>
33#include <mach/regs-gpio.h>
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -080034#include <mach/pmu.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010035
36#include <plat/cpu.h>
37#include <plat/clock.h>
38#include <plat/devs.h>
39#include <plat/pm.h>
Kukjin Kimcc511b82011-12-27 08:18:36 +010040#include <plat/sdhci.h>
41#include <plat/gpio-cfg.h>
42#include <plat/adc-core.h>
43#include <plat/fb-core.h>
44#include <plat/fimc-core.h>
45#include <plat/iic-core.h>
46#include <plat/tv-core.h>
47#include <plat/regs-serial.h>
48
49#include "common.h"
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -080050#define L2_AUX_VAL 0x7C470001
51#define L2_AUX_MASK 0xC200ffff
Kukjin Kimcc511b82011-12-27 08:18:36 +010052
Kukjin Kimcc511b82011-12-27 08:18:36 +010053static const char name_exynos4210[] = "EXYNOS4210";
54static const char name_exynos4212[] = "EXYNOS4212";
55static const char name_exynos4412[] = "EXYNOS4412";
56
57static struct cpu_table cpu_ids[] __initdata = {
58 {
59 .idcode = EXYNOS4210_CPU_ID,
60 .idmask = EXYNOS4_CPU_MASK,
61 .map_io = exynos4_map_io,
62 .init_clocks = exynos4_init_clocks,
63 .init_uarts = exynos4_init_uarts,
64 .init = exynos_init,
65 .name = name_exynos4210,
66 }, {
67 .idcode = EXYNOS4212_CPU_ID,
68 .idmask = EXYNOS4_CPU_MASK,
69 .map_io = exynos4_map_io,
70 .init_clocks = exynos4_init_clocks,
71 .init_uarts = exynos4_init_uarts,
72 .init = exynos_init,
73 .name = name_exynos4212,
74 }, {
75 .idcode = EXYNOS4412_CPU_ID,
76 .idmask = EXYNOS4_CPU_MASK,
77 .map_io = exynos4_map_io,
78 .init_clocks = exynos4_init_clocks,
79 .init_uarts = exynos4_init_uarts,
80 .init = exynos_init,
81 .name = name_exynos4412,
82 },
83};
84
85/* Initial IO mappings */
86
87static struct map_desc exynos_iodesc[] __initdata = {
88 {
89 .virtual = (unsigned long)S5P_VA_CHIPID,
90 .pfn = __phys_to_pfn(EXYNOS4_PA_CHIPID),
91 .length = SZ_4K,
92 .type = MT_DEVICE,
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)S3C_VA_UART,
140 .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
141 .length = SZ_512K,
142 .type = MT_DEVICE,
143 },
144};
145
146static struct map_desc exynos4_iodesc[] __initdata = {
147 {
148 .virtual = (unsigned long)S5P_VA_CMU,
149 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
150 .length = SZ_128K,
151 .type = MT_DEVICE,
152 }, {
153 .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
154 .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
155 .length = SZ_8K,
156 .type = MT_DEVICE,
157 }, {
158 .virtual = (unsigned long)S5P_VA_L2CC,
159 .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
160 .length = SZ_4K,
161 .type = MT_DEVICE,
162 }, {
163 .virtual = (unsigned long)S5P_VA_GPIO1,
164 .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO1),
165 .length = SZ_4K,
166 .type = MT_DEVICE,
167 }, {
168 .virtual = (unsigned long)S5P_VA_GPIO2,
169 .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO2),
170 .length = SZ_4K,
171 .type = MT_DEVICE,
172 }, {
173 .virtual = (unsigned long)S5P_VA_GPIO3,
174 .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO3),
175 .length = SZ_256,
176 .type = MT_DEVICE,
177 }, {
178 .virtual = (unsigned long)S5P_VA_DMC0,
179 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
MyungJoo Ham2bde0b02011-12-01 15:12:30 +0900180 .length = SZ_64K,
181 .type = MT_DEVICE,
182 }, {
183 .virtual = (unsigned long)S5P_VA_DMC1,
184 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
185 .length = SZ_64K,
Kukjin Kimcc511b82011-12-27 08:18:36 +0100186 .type = MT_DEVICE,
187 }, {
Kukjin Kimcc511b82011-12-27 08:18:36 +0100188 .virtual = (unsigned long)S3C_VA_USB_HSPHY,
189 .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
190 .length = SZ_4K,
191 .type = MT_DEVICE,
192 },
193};
194
195static struct map_desc exynos4_iodesc0[] __initdata = {
196 {
197 .virtual = (unsigned long)S5P_VA_SYSRAM,
198 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
199 .length = SZ_4K,
200 .type = MT_DEVICE,
201 },
202};
203
204static struct map_desc exynos4_iodesc1[] __initdata = {
205 {
206 .virtual = (unsigned long)S5P_VA_SYSRAM,
207 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
208 .length = SZ_4K,
209 .type = MT_DEVICE,
210 },
211};
212
213static void exynos_idle(void)
214{
215 if (!need_resched())
216 cpu_do_idle();
217
218 local_irq_enable();
219}
220
Russell King9eb48592012-01-03 11:56:53 +0100221void exynos4_restart(char mode, const char *cmd)
Kukjin Kimcc511b82011-12-27 08:18:36 +0100222{
223 __raw_writel(0x1, S5P_SWRESET);
224}
225
226/*
227 * exynos_map_io
228 *
229 * register the standard cpu IO areas
230 */
231
232void __init exynos_init_io(struct map_desc *mach_desc, int size)
233{
234 /* initialize the io descriptors we need for initialization */
235 iotable_init(exynos_iodesc, ARRAY_SIZE(exynos_iodesc));
236 if (mach_desc)
237 iotable_init(mach_desc, size);
238
239 /* detect cpu id and rev. */
240 s5p_init_cpu(S5P_VA_CHIPID);
241
242 s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
243}
244
245void __init exynos4_map_io(void)
246{
247 iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
248
249 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
250 iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
251 else
252 iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
253
254 /* initialize device information early */
255 exynos4_default_sdhci0();
256 exynos4_default_sdhci1();
257 exynos4_default_sdhci2();
258 exynos4_default_sdhci3();
259
260 s3c_adc_setname("samsung-adc-v3");
261
262 s3c_fimc_setname(0, "exynos4-fimc");
263 s3c_fimc_setname(1, "exynos4-fimc");
264 s3c_fimc_setname(2, "exynos4-fimc");
265 s3c_fimc_setname(3, "exynos4-fimc");
266
267 /* The I2C bus controllers are directly compatible with s3c2440 */
268 s3c_i2c0_setname("s3c2440-i2c");
269 s3c_i2c1_setname("s3c2440-i2c");
270 s3c_i2c2_setname("s3c2440-i2c");
271
272 s5p_fb_setname(0, "exynos4-fb");
273 s5p_hdmi_setname("exynos4-hdmi");
274}
275
276void __init exynos4_init_clocks(int xtal)
277{
278 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
279
280 s3c24xx_register_baseclocks(xtal);
281 s5p_register_clocks(xtal);
282
283 if (soc_is_exynos4210())
284 exynos4210_register_clocks();
285 else if (soc_is_exynos4212() || soc_is_exynos4412())
286 exynos4212_register_clocks();
287
288 exynos4_register_clocks();
289 exynos4_setup_clocks();
290}
291
292#define COMBINER_ENABLE_SET 0x0
293#define COMBINER_ENABLE_CLEAR 0x4
294#define COMBINER_INT_STATUS 0xC
295
296static DEFINE_SPINLOCK(irq_controller_lock);
297
298struct combiner_chip_data {
299 unsigned int irq_offset;
300 unsigned int irq_mask;
301 void __iomem *base;
302};
303
304static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
305
306static inline void __iomem *combiner_base(struct irq_data *data)
307{
308 struct combiner_chip_data *combiner_data =
309 irq_data_get_irq_chip_data(data);
310
311 return combiner_data->base;
312}
313
314static void combiner_mask_irq(struct irq_data *data)
315{
316 u32 mask = 1 << (data->irq % 32);
317
318 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
319}
320
321static void combiner_unmask_irq(struct irq_data *data)
322{
323 u32 mask = 1 << (data->irq % 32);
324
325 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
326}
327
328static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
329{
330 struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
331 struct irq_chip *chip = irq_get_chip(irq);
332 unsigned int cascade_irq, combiner_irq;
333 unsigned long status;
334
335 chained_irq_enter(chip, desc);
336
337 spin_lock(&irq_controller_lock);
338 status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
339 spin_unlock(&irq_controller_lock);
340 status &= chip_data->irq_mask;
341
342 if (status == 0)
343 goto out;
344
345 combiner_irq = __ffs(status);
346
347 cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
348 if (unlikely(cascade_irq >= NR_IRQS))
349 do_bad_IRQ(cascade_irq, desc);
350 else
351 generic_handle_irq(cascade_irq);
352
353 out:
354 chained_irq_exit(chip, desc);
355}
356
357static struct irq_chip combiner_chip = {
358 .name = "COMBINER",
359 .irq_mask = combiner_mask_irq,
360 .irq_unmask = combiner_unmask_irq,
361};
362
363static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
364{
365 if (combiner_nr >= MAX_COMBINER_NR)
366 BUG();
367 if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
368 BUG();
369 irq_set_chained_handler(irq, combiner_handle_cascade_irq);
370}
371
372static void __init combiner_init(unsigned int combiner_nr, void __iomem *base,
373 unsigned int irq_start)
374{
375 unsigned int i;
376
377 if (combiner_nr >= MAX_COMBINER_NR)
378 BUG();
379
380 combiner_data[combiner_nr].base = base;
381 combiner_data[combiner_nr].irq_offset = irq_start;
382 combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3);
383
384 /* Disable all interrupts */
385
386 __raw_writel(combiner_data[combiner_nr].irq_mask,
387 base + COMBINER_ENABLE_CLEAR);
388
389 /* Setup the Linux IRQ subsystem */
390
391 for (i = irq_start; i < combiner_data[combiner_nr].irq_offset
392 + MAX_IRQ_IN_COMBINER; i++) {
393 irq_set_chip_and_handler(i, &combiner_chip, handle_level_irq);
394 irq_set_chip_data(i, &combiner_data[combiner_nr]);
395 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
396 }
397}
398
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000399#ifdef CONFIG_OF
400static const struct of_device_id exynos4_dt_irq_match[] = {
401 { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, },
402 {},
403};
404#endif
Kukjin Kimcc511b82011-12-27 08:18:36 +0100405
406void __init exynos4_init_irq(void)
407{
408 int irq;
Arnd Bergmann40ba95f2012-01-07 11:51:28 +0000409 unsigned int gic_bank_offset;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100410
411 gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
412
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000413 if (!of_have_populated_dt())
414 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset);
415#ifdef CONFIG_OF
416 else
417 of_irq_init(exynos4_dt_irq_match);
418#endif
Kukjin Kimcc511b82011-12-27 08:18:36 +0100419
420 for (irq = 0; irq < MAX_COMBINER_NR; irq++) {
421
422 combiner_init(irq, (void __iomem *)S5P_VA_COMBINER(irq),
423 COMBINER_IRQ(irq, 0));
424 combiner_cascade_irq(irq, IRQ_SPI(irq));
425 }
426
427 /*
428 * The parameters of s5p_init_irq() are for VIC init.
429 * Theses parameters should be NULL and 0 because EXYNOS4
430 * uses GIC instead of VIC.
431 */
432 s5p_init_irq(NULL, 0);
433}
434
Linus Torvalds7affca32012-01-07 12:03:30 -0800435struct bus_type exynos4_subsys = {
436 .name = "exynos4-core",
437 .dev_name = "exynos4-core",
Kukjin Kimcc511b82011-12-27 08:18:36 +0100438};
439
Linus Torvalds7affca32012-01-07 12:03:30 -0800440static struct device exynos4_dev = {
441 .bus = &exynos4_subsys,
Kukjin Kimcc511b82011-12-27 08:18:36 +0100442};
443
444static int __init exynos4_core_init(void)
445{
Linus Torvalds7affca32012-01-07 12:03:30 -0800446 return subsys_system_register(&exynos4_subsys, NULL);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100447}
448core_initcall(exynos4_core_init);
449
450#ifdef CONFIG_CACHE_L2X0
451static int __init exynos4_l2x0_cache_init(void)
452{
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -0800453 int ret;
454 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
455 if (!ret) {
456 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
457 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
458 return 0;
459 }
460
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800461 if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
462 l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
463 /* TAG, Data Latency Control: 2 cycles */
464 l2x0_saved_regs.tag_latency = 0x110;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100465
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800466 if (soc_is_exynos4212() || soc_is_exynos4412())
467 l2x0_saved_regs.data_latency = 0x120;
468 else
469 l2x0_saved_regs.data_latency = 0x110;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100470
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800471 l2x0_saved_regs.prefetch_ctrl = 0x30000007;
472 l2x0_saved_regs.pwr_ctrl =
473 (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100474
Amit Daniel Kachhapb756a502012-03-08 02:07:41 -0800475 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
476
477 __raw_writel(l2x0_saved_regs.tag_latency,
478 S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
479 __raw_writel(l2x0_saved_regs.data_latency,
480 S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
481
482 /* L2X0 Prefetch Control */
483 __raw_writel(l2x0_saved_regs.prefetch_ctrl,
484 S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
485
486 /* L2X0 Power Control */
487 __raw_writel(l2x0_saved_regs.pwr_ctrl,
488 S5P_VA_L2CC + L2X0_POWER_CTRL);
489
490 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
491 clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
492 }
Kukjin Kimcc511b82011-12-27 08:18:36 +0100493
Amit Daniel Kachhap6cdeddc2012-03-08 02:09:12 -0800494 l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100495 return 0;
496}
497
498early_initcall(exynos4_l2x0_cache_init);
499#endif
500
501int __init exynos_init(void)
502{
503 printk(KERN_INFO "EXYNOS: Initializing architecture\n");
504
505 /* set idle function */
506 pm_idle = exynos_idle;
507
Linus Torvalds7affca32012-01-07 12:03:30 -0800508 return device_register(&exynos4_dev);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100509}
510
Kukjin Kimcc511b82011-12-27 08:18:36 +0100511/* uart registration process */
512
513void __init exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no)
514{
515 struct s3c2410_uartcfg *tcfg = cfg;
516 u32 ucnt;
517
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000518 for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
519 tcfg->has_fracval = 1;
Kukjin Kimcc511b82011-12-27 08:18:36 +0100520
Arnd Bergmann237c78b2012-01-07 12:30:20 +0000521 s3c24xx_init_uartdevs("exynos4210-uart", s5p_uart_resources, cfg, no);
Kukjin Kimcc511b82011-12-27 08:18:36 +0100522}
523
524static DEFINE_SPINLOCK(eint_lock);
525
526static unsigned int eint0_15_data[16];
527
528static unsigned int exynos4_get_irq_nr(unsigned int number)
529{
530 u32 ret = 0;
531
532 switch (number) {
533 case 0 ... 3:
534 ret = (number + IRQ_EINT0);
535 break;
536 case 4 ... 7:
537 ret = (number + (IRQ_EINT4 - 4));
538 break;
539 case 8 ... 15:
540 ret = (number + (IRQ_EINT8 - 8));
541 break;
542 default:
543 printk(KERN_ERR "number available : %d\n", number);
544 }
545
546 return ret;
547}
548
549static inline void exynos4_irq_eint_mask(struct irq_data *data)
550{
551 u32 mask;
552
553 spin_lock(&eint_lock);
554 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
555 mask |= eint_irq_to_bit(data->irq);
556 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
557 spin_unlock(&eint_lock);
558}
559
560static void exynos4_irq_eint_unmask(struct irq_data *data)
561{
562 u32 mask;
563
564 spin_lock(&eint_lock);
565 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
566 mask &= ~(eint_irq_to_bit(data->irq));
567 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
568 spin_unlock(&eint_lock);
569}
570
571static inline void exynos4_irq_eint_ack(struct irq_data *data)
572{
573 __raw_writel(eint_irq_to_bit(data->irq),
574 S5P_EINT_PEND(EINT_REG_NR(data->irq)));
575}
576
577static void exynos4_irq_eint_maskack(struct irq_data *data)
578{
579 exynos4_irq_eint_mask(data);
580 exynos4_irq_eint_ack(data);
581}
582
583static int exynos4_irq_eint_set_type(struct irq_data *data, unsigned int type)
584{
585 int offs = EINT_OFFSET(data->irq);
586 int shift;
587 u32 ctrl, mask;
588 u32 newvalue = 0;
589
590 switch (type) {
591 case IRQ_TYPE_EDGE_RISING:
592 newvalue = S5P_IRQ_TYPE_EDGE_RISING;
593 break;
594
595 case IRQ_TYPE_EDGE_FALLING:
596 newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
597 break;
598
599 case IRQ_TYPE_EDGE_BOTH:
600 newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
601 break;
602
603 case IRQ_TYPE_LEVEL_LOW:
604 newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
605 break;
606
607 case IRQ_TYPE_LEVEL_HIGH:
608 newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
609 break;
610
611 default:
612 printk(KERN_ERR "No such irq type %d", type);
613 return -EINVAL;
614 }
615
616 shift = (offs & 0x7) * 4;
617 mask = 0x7 << shift;
618
619 spin_lock(&eint_lock);
620 ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq)));
621 ctrl &= ~mask;
622 ctrl |= newvalue << shift;
623 __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq)));
624 spin_unlock(&eint_lock);
625
626 switch (offs) {
627 case 0 ... 7:
628 s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
629 break;
630 case 8 ... 15:
631 s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
632 break;
633 case 16 ... 23:
634 s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
635 break;
636 case 24 ... 31:
637 s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
638 break;
639 default:
640 printk(KERN_ERR "No such irq number %d", offs);
641 }
642
643 return 0;
644}
645
646static struct irq_chip exynos4_irq_eint = {
647 .name = "exynos4-eint",
648 .irq_mask = exynos4_irq_eint_mask,
649 .irq_unmask = exynos4_irq_eint_unmask,
650 .irq_mask_ack = exynos4_irq_eint_maskack,
651 .irq_ack = exynos4_irq_eint_ack,
652 .irq_set_type = exynos4_irq_eint_set_type,
653#ifdef CONFIG_PM
654 .irq_set_wake = s3c_irqext_wake,
655#endif
656};
657
658/*
659 * exynos4_irq_demux_eint
660 *
661 * This function demuxes the IRQ from from EINTs 16 to 31.
662 * It is designed to be inlined into the specific handler
663 * s5p_irq_demux_eintX_Y.
664 *
665 * Each EINT pend/mask registers handle eight of them.
666 */
667static inline void exynos4_irq_demux_eint(unsigned int start)
668{
669 unsigned int irq;
670
671 u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
672 u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
673
674 status &= ~mask;
675 status &= 0xff;
676
677 while (status) {
678 irq = fls(status) - 1;
679 generic_handle_irq(irq + start);
680 status &= ~(1 << irq);
681 }
682}
683
684static void exynos4_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
685{
686 struct irq_chip *chip = irq_get_chip(irq);
687 chained_irq_enter(chip, desc);
688 exynos4_irq_demux_eint(IRQ_EINT(16));
689 exynos4_irq_demux_eint(IRQ_EINT(24));
690 chained_irq_exit(chip, desc);
691}
692
693static void exynos4_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
694{
695 u32 *irq_data = irq_get_handler_data(irq);
696 struct irq_chip *chip = irq_get_chip(irq);
697
698 chained_irq_enter(chip, desc);
699 chip->irq_mask(&desc->irq_data);
700
701 if (chip->irq_ack)
702 chip->irq_ack(&desc->irq_data);
703
704 generic_handle_irq(*irq_data);
705
706 chip->irq_unmask(&desc->irq_data);
707 chained_irq_exit(chip, desc);
708}
709
710int __init exynos4_init_irq_eint(void)
711{
712 int irq;
713
714 for (irq = 0 ; irq <= 31 ; irq++) {
715 irq_set_chip_and_handler(IRQ_EINT(irq), &exynos4_irq_eint,
716 handle_level_irq);
717 set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
718 }
719
720 irq_set_chained_handler(IRQ_EINT16_31, exynos4_irq_demux_eint16_31);
721
722 for (irq = 0 ; irq <= 15 ; irq++) {
723 eint0_15_data[irq] = IRQ_EINT(irq);
724
725 irq_set_handler_data(exynos4_get_irq_nr(irq),
726 &eint0_15_data[irq]);
727 irq_set_chained_handler(exynos4_get_irq_nr(irq),
728 exynos4_irq_eint0_15);
729 }
730
731 return 0;
732}
733arch_initcall(exynos4_init_irq_eint);