2 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
5 * Common Codes for EXYNOS
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.
12 #include <linux/kernel.h>
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
16 #include <linux/device.h>
17 #include <linux/gpio.h>
18 #include <linux/sched.h>
19 #include <linux/serial_core.h>
21 #include <linux/of_irq.h>
23 #include <asm/proc-fns.h>
24 #include <asm/exception.h>
25 #include <asm/hardware/cache-l2x0.h>
26 #include <asm/hardware/gic.h>
27 #include <asm/mach/map.h>
28 #include <asm/mach/irq.h>
29 #include <asm/cacheflush.h>
31 #include <mach/regs-irq.h>
32 #include <mach/regs-pmu.h>
33 #include <mach/regs-gpio.h>
37 #include <plat/clock.h>
38 #include <plat/devs.h>
40 #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>
50 #define L2_AUX_VAL 0x7C470001
51 #define L2_AUX_MASK 0xC200ffff
53 static const char name_exynos4210
[] = "EXYNOS4210";
54 static const char name_exynos4212
[] = "EXYNOS4212";
55 static const char name_exynos4412
[] = "EXYNOS4412";
56 static const char name_exynos5250
[] = "EXYNOS5250";
58 static void exynos4_map_io(void);
59 static void exynos5_map_io(void);
60 static void exynos4_init_clocks(int xtal
);
61 static void exynos5_init_clocks(int xtal
);
62 static void exynos_init_uarts(struct s3c2410_uartcfg
*cfg
, int no
);
63 static int exynos_init(void);
65 static struct cpu_table cpu_ids
[] __initdata
= {
67 .idcode
= EXYNOS4210_CPU_ID
,
68 .idmask
= EXYNOS4_CPU_MASK
,
69 .map_io
= exynos4_map_io
,
70 .init_clocks
= exynos4_init_clocks
,
71 .init_uarts
= exynos_init_uarts
,
73 .name
= name_exynos4210
,
75 .idcode
= EXYNOS4212_CPU_ID
,
76 .idmask
= EXYNOS4_CPU_MASK
,
77 .map_io
= exynos4_map_io
,
78 .init_clocks
= exynos4_init_clocks
,
79 .init_uarts
= exynos_init_uarts
,
81 .name
= name_exynos4212
,
83 .idcode
= EXYNOS4412_CPU_ID
,
84 .idmask
= EXYNOS4_CPU_MASK
,
85 .map_io
= exynos4_map_io
,
86 .init_clocks
= exynos4_init_clocks
,
87 .init_uarts
= exynos_init_uarts
,
89 .name
= name_exynos4412
,
91 .idcode
= EXYNOS5250_SOC_ID
,
92 .idmask
= EXYNOS5_SOC_MASK
,
93 .map_io
= exynos5_map_io
,
94 .init_clocks
= exynos5_init_clocks
,
95 .init_uarts
= exynos_init_uarts
,
97 .name
= name_exynos5250
,
101 /* Initial IO mappings */
103 static struct map_desc exynos_iodesc
[] __initdata
= {
105 .virtual = (unsigned long)S5P_VA_CHIPID
,
106 .pfn
= __phys_to_pfn(EXYNOS_PA_CHIPID
),
112 static struct map_desc exynos4_iodesc
[] __initdata
= {
114 .virtual = (unsigned long)S3C_VA_SYS
,
115 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSCON
),
119 .virtual = (unsigned long)S3C_VA_TIMER
,
120 .pfn
= __phys_to_pfn(EXYNOS4_PA_TIMER
),
124 .virtual = (unsigned long)S3C_VA_WATCHDOG
,
125 .pfn
= __phys_to_pfn(EXYNOS4_PA_WATCHDOG
),
129 .virtual = (unsigned long)S5P_VA_SROMC
,
130 .pfn
= __phys_to_pfn(EXYNOS4_PA_SROMC
),
134 .virtual = (unsigned long)S5P_VA_SYSTIMER
,
135 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSTIMER
),
139 .virtual = (unsigned long)S5P_VA_PMU
,
140 .pfn
= __phys_to_pfn(EXYNOS4_PA_PMU
),
144 .virtual = (unsigned long)S5P_VA_COMBINER_BASE
,
145 .pfn
= __phys_to_pfn(EXYNOS4_PA_COMBINER
),
149 .virtual = (unsigned long)S5P_VA_GIC_CPU
,
150 .pfn
= __phys_to_pfn(EXYNOS4_PA_GIC_CPU
),
154 .virtual = (unsigned long)S5P_VA_GIC_DIST
,
155 .pfn
= __phys_to_pfn(EXYNOS4_PA_GIC_DIST
),
159 .virtual = (unsigned long)S3C_VA_UART
,
160 .pfn
= __phys_to_pfn(EXYNOS4_PA_UART
),
164 .virtual = (unsigned long)S5P_VA_CMU
,
165 .pfn
= __phys_to_pfn(EXYNOS4_PA_CMU
),
169 .virtual = (unsigned long)S5P_VA_COREPERI_BASE
,
170 .pfn
= __phys_to_pfn(EXYNOS4_PA_COREPERI
),
174 .virtual = (unsigned long)S5P_VA_L2CC
,
175 .pfn
= __phys_to_pfn(EXYNOS4_PA_L2CC
),
179 .virtual = (unsigned long)S5P_VA_GPIO1
,
180 .pfn
= __phys_to_pfn(EXYNOS4_PA_GPIO1
),
184 .virtual = (unsigned long)S5P_VA_GPIO2
,
185 .pfn
= __phys_to_pfn(EXYNOS4_PA_GPIO2
),
189 .virtual = (unsigned long)S5P_VA_GPIO3
,
190 .pfn
= __phys_to_pfn(EXYNOS4_PA_GPIO3
),
194 .virtual = (unsigned long)S5P_VA_DMC0
,
195 .pfn
= __phys_to_pfn(EXYNOS4_PA_DMC0
),
199 .virtual = (unsigned long)S5P_VA_DMC1
,
200 .pfn
= __phys_to_pfn(EXYNOS4_PA_DMC1
),
204 .virtual = (unsigned long)S3C_VA_USB_HSPHY
,
205 .pfn
= __phys_to_pfn(EXYNOS4_PA_HSPHY
),
211 static struct map_desc exynos4_iodesc0
[] __initdata
= {
213 .virtual = (unsigned long)S5P_VA_SYSRAM
,
214 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSRAM0
),
220 static struct map_desc exynos4_iodesc1
[] __initdata
= {
222 .virtual = (unsigned long)S5P_VA_SYSRAM
,
223 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSRAM1
),
229 static struct map_desc exynos5_iodesc
[] __initdata
= {
231 .virtual = (unsigned long)S3C_VA_SYS
,
232 .pfn
= __phys_to_pfn(EXYNOS5_PA_SYSCON
),
236 .virtual = (unsigned long)S3C_VA_TIMER
,
237 .pfn
= __phys_to_pfn(EXYNOS5_PA_TIMER
),
241 .virtual = (unsigned long)S3C_VA_WATCHDOG
,
242 .pfn
= __phys_to_pfn(EXYNOS5_PA_WATCHDOG
),
246 .virtual = (unsigned long)S5P_VA_SROMC
,
247 .pfn
= __phys_to_pfn(EXYNOS5_PA_SROMC
),
251 .virtual = (unsigned long)S5P_VA_SYSTIMER
,
252 .pfn
= __phys_to_pfn(EXYNOS5_PA_SYSTIMER
),
256 .virtual = (unsigned long)S5P_VA_SYSRAM
,
257 .pfn
= __phys_to_pfn(EXYNOS5_PA_SYSRAM
),
261 .virtual = (unsigned long)S5P_VA_CMU
,
262 .pfn
= __phys_to_pfn(EXYNOS5_PA_CMU
),
263 .length
= 144 * SZ_1K
,
266 .virtual = (unsigned long)S5P_VA_PMU
,
267 .pfn
= __phys_to_pfn(EXYNOS5_PA_PMU
),
271 .virtual = (unsigned long)S5P_VA_COMBINER_BASE
,
272 .pfn
= __phys_to_pfn(EXYNOS5_PA_COMBINER
),
276 .virtual = (unsigned long)S3C_VA_UART
,
277 .pfn
= __phys_to_pfn(EXYNOS5_PA_UART
),
281 .virtual = (unsigned long)S5P_VA_GIC_CPU
,
282 .pfn
= __phys_to_pfn(EXYNOS5_PA_GIC_CPU
),
286 .virtual = (unsigned long)S5P_VA_GIC_DIST
,
287 .pfn
= __phys_to_pfn(EXYNOS5_PA_GIC_DIST
),
293 void exynos4_restart(char mode
, const char *cmd
)
295 __raw_writel(0x1, S5P_SWRESET
);
298 void exynos5_restart(char mode
, const char *cmd
)
300 __raw_writel(0x1, EXYNOS_SWRESET
);
306 * register the standard cpu IO areas
309 void __init
exynos_init_io(struct map_desc
*mach_desc
, int size
)
311 /* initialize the io descriptors we need for initialization */
312 iotable_init(exynos_iodesc
, ARRAY_SIZE(exynos_iodesc
));
314 iotable_init(mach_desc
, size
);
316 /* detect cpu id and rev. */
317 s5p_init_cpu(S5P_VA_CHIPID
);
319 s3c_init_cpu(samsung_cpu_id
, cpu_ids
, ARRAY_SIZE(cpu_ids
));
322 static void __init
exynos4_map_io(void)
324 iotable_init(exynos4_iodesc
, ARRAY_SIZE(exynos4_iodesc
));
326 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0
)
327 iotable_init(exynos4_iodesc0
, ARRAY_SIZE(exynos4_iodesc0
));
329 iotable_init(exynos4_iodesc1
, ARRAY_SIZE(exynos4_iodesc1
));
331 /* initialize device information early */
332 exynos4_default_sdhci0();
333 exynos4_default_sdhci1();
334 exynos4_default_sdhci2();
335 exynos4_default_sdhci3();
337 s3c_adc_setname("samsung-adc-v3");
339 s3c_fimc_setname(0, "exynos4-fimc");
340 s3c_fimc_setname(1, "exynos4-fimc");
341 s3c_fimc_setname(2, "exynos4-fimc");
342 s3c_fimc_setname(3, "exynos4-fimc");
344 /* The I2C bus controllers are directly compatible with s3c2440 */
345 s3c_i2c0_setname("s3c2440-i2c");
346 s3c_i2c1_setname("s3c2440-i2c");
347 s3c_i2c2_setname("s3c2440-i2c");
349 s5p_fb_setname(0, "exynos4-fb");
350 s5p_hdmi_setname("exynos4-hdmi");
353 static void __init
exynos5_map_io(void)
355 iotable_init(exynos5_iodesc
, ARRAY_SIZE(exynos5_iodesc
));
357 s3c_device_i2c0
.resource
[0].start
= EXYNOS5_PA_IIC(0);
358 s3c_device_i2c0
.resource
[0].end
= EXYNOS5_PA_IIC(0) + SZ_4K
- 1;
359 s3c_device_i2c0
.resource
[1].start
= EXYNOS5_IRQ_IIC
;
360 s3c_device_i2c0
.resource
[1].end
= EXYNOS5_IRQ_IIC
;
362 /* The I2C bus controllers are directly compatible with s3c2440 */
363 s3c_i2c0_setname("s3c2440-i2c");
364 s3c_i2c1_setname("s3c2440-i2c");
365 s3c_i2c2_setname("s3c2440-i2c");
368 static void __init
exynos4_init_clocks(int xtal
)
370 printk(KERN_DEBUG
"%s: initializing clocks\n", __func__
);
372 s3c24xx_register_baseclocks(xtal
);
373 s5p_register_clocks(xtal
);
375 if (soc_is_exynos4210())
376 exynos4210_register_clocks();
377 else if (soc_is_exynos4212() || soc_is_exynos4412())
378 exynos4212_register_clocks();
380 exynos4_register_clocks();
381 exynos4_setup_clocks();
384 static void __init
exynos5_init_clocks(int xtal
)
386 printk(KERN_DEBUG
"%s: initializing clocks\n", __func__
);
388 s3c24xx_register_baseclocks(xtal
);
389 s5p_register_clocks(xtal
);
391 exynos5_register_clocks();
392 exynos5_setup_clocks();
395 #define COMBINER_ENABLE_SET 0x0
396 #define COMBINER_ENABLE_CLEAR 0x4
397 #define COMBINER_INT_STATUS 0xC
399 static DEFINE_SPINLOCK(irq_controller_lock
);
401 struct combiner_chip_data
{
402 unsigned int irq_offset
;
403 unsigned int irq_mask
;
407 static struct combiner_chip_data combiner_data
[MAX_COMBINER_NR
];
409 static inline void __iomem
*combiner_base(struct irq_data
*data
)
411 struct combiner_chip_data
*combiner_data
=
412 irq_data_get_irq_chip_data(data
);
414 return combiner_data
->base
;
417 static void combiner_mask_irq(struct irq_data
*data
)
419 u32 mask
= 1 << (data
->irq
% 32);
421 __raw_writel(mask
, combiner_base(data
) + COMBINER_ENABLE_CLEAR
);
424 static void combiner_unmask_irq(struct irq_data
*data
)
426 u32 mask
= 1 << (data
->irq
% 32);
428 __raw_writel(mask
, combiner_base(data
) + COMBINER_ENABLE_SET
);
431 static void combiner_handle_cascade_irq(unsigned int irq
, struct irq_desc
*desc
)
433 struct combiner_chip_data
*chip_data
= irq_get_handler_data(irq
);
434 struct irq_chip
*chip
= irq_get_chip(irq
);
435 unsigned int cascade_irq
, combiner_irq
;
436 unsigned long status
;
438 chained_irq_enter(chip
, desc
);
440 spin_lock(&irq_controller_lock
);
441 status
= __raw_readl(chip_data
->base
+ COMBINER_INT_STATUS
);
442 spin_unlock(&irq_controller_lock
);
443 status
&= chip_data
->irq_mask
;
448 combiner_irq
= __ffs(status
);
450 cascade_irq
= combiner_irq
+ (chip_data
->irq_offset
& ~31);
451 if (unlikely(cascade_irq
>= NR_IRQS
))
452 do_bad_IRQ(cascade_irq
, desc
);
454 generic_handle_irq(cascade_irq
);
457 chained_irq_exit(chip
, desc
);
460 static struct irq_chip combiner_chip
= {
462 .irq_mask
= combiner_mask_irq
,
463 .irq_unmask
= combiner_unmask_irq
,
466 static void __init
combiner_cascade_irq(unsigned int combiner_nr
, unsigned int irq
)
470 if (soc_is_exynos5250())
471 max_nr
= EXYNOS5_MAX_COMBINER_NR
;
473 max_nr
= EXYNOS4_MAX_COMBINER_NR
;
475 if (combiner_nr
>= max_nr
)
477 if (irq_set_handler_data(irq
, &combiner_data
[combiner_nr
]) != 0)
479 irq_set_chained_handler(irq
, combiner_handle_cascade_irq
);
482 static void __init
combiner_init(unsigned int combiner_nr
, void __iomem
*base
,
483 unsigned int irq_start
)
488 if (soc_is_exynos5250())
489 max_nr
= EXYNOS5_MAX_COMBINER_NR
;
491 max_nr
= EXYNOS4_MAX_COMBINER_NR
;
493 if (combiner_nr
>= max_nr
)
496 combiner_data
[combiner_nr
].base
= base
;
497 combiner_data
[combiner_nr
].irq_offset
= irq_start
;
498 combiner_data
[combiner_nr
].irq_mask
= 0xff << ((combiner_nr
% 4) << 3);
500 /* Disable all interrupts */
502 __raw_writel(combiner_data
[combiner_nr
].irq_mask
,
503 base
+ COMBINER_ENABLE_CLEAR
);
505 /* Setup the Linux IRQ subsystem */
507 for (i
= irq_start
; i
< combiner_data
[combiner_nr
].irq_offset
508 + MAX_IRQ_IN_COMBINER
; i
++) {
509 irq_set_chip_and_handler(i
, &combiner_chip
, handle_level_irq
);
510 irq_set_chip_data(i
, &combiner_data
[combiner_nr
]);
511 set_irq_flags(i
, IRQF_VALID
| IRQF_PROBE
);
516 static const struct of_device_id exynos4_dt_irq_match
[] = {
517 { .compatible
= "arm,cortex-a9-gic", .data
= gic_of_init
, },
522 void __init
exynos4_init_irq(void)
525 unsigned int gic_bank_offset
;
527 gic_bank_offset
= soc_is_exynos4412() ? 0x4000 : 0x8000;
529 if (!of_have_populated_dt())
530 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST
, S5P_VA_GIC_CPU
, gic_bank_offset
);
533 of_irq_init(exynos4_dt_irq_match
);
536 for (irq
= 0; irq
< EXYNOS4_MAX_COMBINER_NR
; irq
++) {
538 combiner_init(irq
, (void __iomem
*)S5P_VA_COMBINER(irq
),
539 COMBINER_IRQ(irq
, 0));
540 combiner_cascade_irq(irq
, IRQ_SPI(irq
));
544 * The parameters of s5p_init_irq() are for VIC init.
545 * Theses parameters should be NULL and 0 because EXYNOS4
546 * uses GIC instead of VIC.
548 s5p_init_irq(NULL
, 0);
551 void __init
exynos5_init_irq(void)
555 gic_init(0, IRQ_PPI(0), S5P_VA_GIC_DIST
, S5P_VA_GIC_CPU
);
557 for (irq
= 0; irq
< EXYNOS5_MAX_COMBINER_NR
; irq
++) {
558 combiner_init(irq
, (void __iomem
*)S5P_VA_COMBINER(irq
),
559 COMBINER_IRQ(irq
, 0));
560 combiner_cascade_irq(irq
, IRQ_SPI(irq
));
564 * The parameters of s5p_init_irq() are for VIC init.
565 * Theses parameters should be NULL and 0 because EXYNOS4
566 * uses GIC instead of VIC.
568 s5p_init_irq(NULL
, 0);
571 struct bus_type exynos4_subsys
= {
572 .name
= "exynos4-core",
573 .dev_name
= "exynos4-core",
576 struct bus_type exynos5_subsys
= {
577 .name
= "exynos5-core",
578 .dev_name
= "exynos5-core",
581 static struct device exynos4_dev
= {
582 .bus
= &exynos4_subsys
,
585 static struct device exynos5_dev
= {
586 .bus
= &exynos5_subsys
,
589 static int __init
exynos_core_init(void)
591 if (soc_is_exynos5250())
592 return subsys_system_register(&exynos5_subsys
, NULL
);
594 return subsys_system_register(&exynos4_subsys
, NULL
);
596 core_initcall(exynos_core_init
);
598 #ifdef CONFIG_CACHE_L2X0
599 static int __init
exynos4_l2x0_cache_init(void)
601 if (soc_is_exynos5250())
605 ret
= l2x0_of_init(L2_AUX_VAL
, L2_AUX_MASK
);
607 l2x0_regs_phys
= virt_to_phys(&l2x0_saved_regs
);
608 clean_dcache_area(&l2x0_regs_phys
, sizeof(unsigned long));
612 if (!(__raw_readl(S5P_VA_L2CC
+ L2X0_CTRL
) & 0x1)) {
613 l2x0_saved_regs
.phy_base
= EXYNOS4_PA_L2CC
;
614 /* TAG, Data Latency Control: 2 cycles */
615 l2x0_saved_regs
.tag_latency
= 0x110;
617 if (soc_is_exynos4212() || soc_is_exynos4412())
618 l2x0_saved_regs
.data_latency
= 0x120;
620 l2x0_saved_regs
.data_latency
= 0x110;
622 l2x0_saved_regs
.prefetch_ctrl
= 0x30000007;
623 l2x0_saved_regs
.pwr_ctrl
=
624 (L2X0_DYNAMIC_CLK_GATING_EN
| L2X0_STNDBY_MODE_EN
);
626 l2x0_regs_phys
= virt_to_phys(&l2x0_saved_regs
);
628 __raw_writel(l2x0_saved_regs
.tag_latency
,
629 S5P_VA_L2CC
+ L2X0_TAG_LATENCY_CTRL
);
630 __raw_writel(l2x0_saved_regs
.data_latency
,
631 S5P_VA_L2CC
+ L2X0_DATA_LATENCY_CTRL
);
633 /* L2X0 Prefetch Control */
634 __raw_writel(l2x0_saved_regs
.prefetch_ctrl
,
635 S5P_VA_L2CC
+ L2X0_PREFETCH_CTRL
);
637 /* L2X0 Power Control */
638 __raw_writel(l2x0_saved_regs
.pwr_ctrl
,
639 S5P_VA_L2CC
+ L2X0_POWER_CTRL
);
641 clean_dcache_area(&l2x0_regs_phys
, sizeof(unsigned long));
642 clean_dcache_area(&l2x0_saved_regs
, sizeof(struct l2x0_regs
));
645 l2x0_init(S5P_VA_L2CC
, L2_AUX_VAL
, L2_AUX_MASK
);
648 early_initcall(exynos4_l2x0_cache_init
);
651 static int __init
exynos5_l2_cache_init(void)
655 if (!soc_is_exynos5250())
658 asm volatile("mrc p15, 0, %0, c1, c0, 0\n"
659 "bic %0, %0, #(1 << 2)\n" /* cache disable */
660 "mcr p15, 0, %0, c1, c0, 0\n"
661 "mrc p15, 1, %0, c9, c0, 2\n"
664 val
|= (1 << 9) | (1 << 5) | (2 << 6) | (2 << 0);
666 asm volatile("mcr p15, 1, %0, c9, c0, 2\n" : : "r"(val
));
667 asm volatile("mrc p15, 0, %0, c1, c0, 0\n"
668 "orr %0, %0, #(1 << 2)\n" /* cache enable */
669 "mcr p15, 0, %0, c1, c0, 0\n"
674 early_initcall(exynos5_l2_cache_init
);
676 static int __init
exynos_init(void)
678 printk(KERN_INFO
"EXYNOS: Initializing architecture\n");
680 if (soc_is_exynos5250())
681 return device_register(&exynos5_dev
);
683 return device_register(&exynos4_dev
);
686 /* uart registration process */
688 static void __init
exynos_init_uarts(struct s3c2410_uartcfg
*cfg
, int no
)
690 struct s3c2410_uartcfg
*tcfg
= cfg
;
693 for (ucnt
= 0; ucnt
< no
; ucnt
++, tcfg
++)
694 tcfg
->has_fracval
= 1;
696 if (soc_is_exynos5250())
697 s3c24xx_init_uartdevs("exynos4210-uart", exynos5_uart_resources
, cfg
, no
);
699 s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources
, cfg
, no
);
702 static void __iomem
*exynos_eint_base
;
704 static DEFINE_SPINLOCK(eint_lock
);
706 static unsigned int eint0_15_data
[16];
708 static inline int exynos4_irq_to_gpio(unsigned int irq
)
710 if (irq
< IRQ_EINT(0))
715 return EXYNOS4_GPX0(irq
);
719 return EXYNOS4_GPX1(irq
);
723 return EXYNOS4_GPX2(irq
);
727 return EXYNOS4_GPX3(irq
);
732 static inline int exynos5_irq_to_gpio(unsigned int irq
)
734 if (irq
< IRQ_EINT(0))
739 return EXYNOS5_GPX0(irq
);
743 return EXYNOS5_GPX1(irq
);
747 return EXYNOS5_GPX2(irq
);
751 return EXYNOS5_GPX3(irq
);
756 static unsigned int exynos4_eint0_15_src_int
[16] = {
775 static unsigned int exynos5_eint0_15_src_int
[16] = {
793 static inline void exynos_irq_eint_mask(struct irq_data
*data
)
797 spin_lock(&eint_lock
);
798 mask
= __raw_readl(EINT_MASK(exynos_eint_base
, data
->irq
));
799 mask
|= EINT_OFFSET_BIT(data
->irq
);
800 __raw_writel(mask
, EINT_MASK(exynos_eint_base
, data
->irq
));
801 spin_unlock(&eint_lock
);
804 static void exynos_irq_eint_unmask(struct irq_data
*data
)
808 spin_lock(&eint_lock
);
809 mask
= __raw_readl(EINT_MASK(exynos_eint_base
, data
->irq
));
810 mask
&= ~(EINT_OFFSET_BIT(data
->irq
));
811 __raw_writel(mask
, EINT_MASK(exynos_eint_base
, data
->irq
));
812 spin_unlock(&eint_lock
);
815 static inline void exynos_irq_eint_ack(struct irq_data
*data
)
817 __raw_writel(EINT_OFFSET_BIT(data
->irq
),
818 EINT_PEND(exynos_eint_base
, data
->irq
));
821 static void exynos_irq_eint_maskack(struct irq_data
*data
)
823 exynos_irq_eint_mask(data
);
824 exynos_irq_eint_ack(data
);
827 static int exynos_irq_eint_set_type(struct irq_data
*data
, unsigned int type
)
829 int offs
= EINT_OFFSET(data
->irq
);
835 case IRQ_TYPE_EDGE_RISING
:
836 newvalue
= S5P_IRQ_TYPE_EDGE_RISING
;
839 case IRQ_TYPE_EDGE_FALLING
:
840 newvalue
= S5P_IRQ_TYPE_EDGE_FALLING
;
843 case IRQ_TYPE_EDGE_BOTH
:
844 newvalue
= S5P_IRQ_TYPE_EDGE_BOTH
;
847 case IRQ_TYPE_LEVEL_LOW
:
848 newvalue
= S5P_IRQ_TYPE_LEVEL_LOW
;
851 case IRQ_TYPE_LEVEL_HIGH
:
852 newvalue
= S5P_IRQ_TYPE_LEVEL_HIGH
;
856 printk(KERN_ERR
"No such irq type %d", type
);
860 shift
= (offs
& 0x7) * 4;
863 spin_lock(&eint_lock
);
864 ctrl
= __raw_readl(EINT_CON(exynos_eint_base
, data
->irq
));
866 ctrl
|= newvalue
<< shift
;
867 __raw_writel(ctrl
, EINT_CON(exynos_eint_base
, data
->irq
));
868 spin_unlock(&eint_lock
);
870 if (soc_is_exynos5250())
871 s3c_gpio_cfgpin(exynos5_irq_to_gpio(data
->irq
), S3C_GPIO_SFN(0xf));
873 s3c_gpio_cfgpin(exynos4_irq_to_gpio(data
->irq
), S3C_GPIO_SFN(0xf));
878 static struct irq_chip exynos_irq_eint
= {
879 .name
= "exynos-eint",
880 .irq_mask
= exynos_irq_eint_mask
,
881 .irq_unmask
= exynos_irq_eint_unmask
,
882 .irq_mask_ack
= exynos_irq_eint_maskack
,
883 .irq_ack
= exynos_irq_eint_ack
,
884 .irq_set_type
= exynos_irq_eint_set_type
,
886 .irq_set_wake
= s3c_irqext_wake
,
891 * exynos4_irq_demux_eint
893 * This function demuxes the IRQ from from EINTs 16 to 31.
894 * It is designed to be inlined into the specific handler
895 * s5p_irq_demux_eintX_Y.
897 * Each EINT pend/mask registers handle eight of them.
899 static inline void exynos_irq_demux_eint(unsigned int start
)
903 u32 status
= __raw_readl(EINT_PEND(exynos_eint_base
, start
));
904 u32 mask
= __raw_readl(EINT_MASK(exynos_eint_base
, start
));
910 irq
= fls(status
) - 1;
911 generic_handle_irq(irq
+ start
);
912 status
&= ~(1 << irq
);
916 static void exynos_irq_demux_eint16_31(unsigned int irq
, struct irq_desc
*desc
)
918 struct irq_chip
*chip
= irq_get_chip(irq
);
919 chained_irq_enter(chip
, desc
);
920 exynos_irq_demux_eint(IRQ_EINT(16));
921 exynos_irq_demux_eint(IRQ_EINT(24));
922 chained_irq_exit(chip
, desc
);
925 static void exynos_irq_eint0_15(unsigned int irq
, struct irq_desc
*desc
)
927 u32
*irq_data
= irq_get_handler_data(irq
);
928 struct irq_chip
*chip
= irq_get_chip(irq
);
930 chained_irq_enter(chip
, desc
);
931 chip
->irq_mask(&desc
->irq_data
);
934 chip
->irq_ack(&desc
->irq_data
);
936 generic_handle_irq(*irq_data
);
938 chip
->irq_unmask(&desc
->irq_data
);
939 chained_irq_exit(chip
, desc
);
942 static int __init
exynos_init_irq_eint(void)
946 if (soc_is_exynos5250())
947 exynos_eint_base
= ioremap(EXYNOS5_PA_GPIO1
, SZ_4K
);
949 exynos_eint_base
= ioremap(EXYNOS4_PA_GPIO2
, SZ_4K
);
951 if (exynos_eint_base
== NULL
) {
952 pr_err("unable to ioremap for EINT base address\n");
956 for (irq
= 0 ; irq
<= 31 ; irq
++) {
957 irq_set_chip_and_handler(IRQ_EINT(irq
), &exynos_irq_eint
,
959 set_irq_flags(IRQ_EINT(irq
), IRQF_VALID
);
962 irq_set_chained_handler(EXYNOS_IRQ_EINT16_31
, exynos_irq_demux_eint16_31
);
964 for (irq
= 0 ; irq
<= 15 ; irq
++) {
965 eint0_15_data
[irq
] = IRQ_EINT(irq
);
967 if (soc_is_exynos5250()) {
968 irq_set_handler_data(exynos5_eint0_15_src_int
[irq
],
969 &eint0_15_data
[irq
]);
970 irq_set_chained_handler(exynos5_eint0_15_src_int
[irq
],
971 exynos_irq_eint0_15
);
973 irq_set_handler_data(exynos4_eint0_15_src_int
[irq
],
974 &eint0_15_data
[irq
]);
975 irq_set_chained_handler(exynos4_eint0_15_src_int
[irq
],
976 exynos_irq_eint0_15
);
982 arch_initcall(exynos_init_irq_eint
);