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>
22 #include <linux/export.h>
23 #include <linux/irqdomain.h>
24 #include <linux/of_address.h>
26 #include <asm/proc-fns.h>
27 #include <asm/exception.h>
28 #include <asm/hardware/cache-l2x0.h>
29 #include <asm/hardware/gic.h>
30 #include <asm/mach/map.h>
31 #include <asm/mach/irq.h>
32 #include <asm/cacheflush.h>
34 #include <mach/regs-irq.h>
35 #include <mach/regs-pmu.h>
36 #include <mach/regs-gpio.h>
40 #include <plat/clock.h>
41 #include <plat/devs.h>
43 #include <plat/sdhci.h>
44 #include <plat/gpio-cfg.h>
45 #include <plat/adc-core.h>
46 #include <plat/fb-core.h>
47 #include <plat/fimc-core.h>
48 #include <plat/iic-core.h>
49 #include <plat/tv-core.h>
50 #include <plat/spi-core.h>
51 #include <plat/regs-serial.h>
54 #define L2_AUX_VAL 0x7C470001
55 #define L2_AUX_MASK 0xC200ffff
57 static const char name_exynos4210
[] = "EXYNOS4210";
58 static const char name_exynos4212
[] = "EXYNOS4212";
59 static const char name_exynos4412
[] = "EXYNOS4412";
60 static const char name_exynos5250
[] = "EXYNOS5250";
62 static void exynos4_map_io(void);
63 static void exynos5_map_io(void);
64 static void exynos4_init_clocks(int xtal
);
65 static void exynos5_init_clocks(int xtal
);
66 static void exynos4_init_uarts(struct s3c2410_uartcfg
*cfg
, int no
);
67 static int exynos_init(void);
69 static struct cpu_table cpu_ids
[] __initdata
= {
71 .idcode
= EXYNOS4210_CPU_ID
,
72 .idmask
= EXYNOS4_CPU_MASK
,
73 .map_io
= exynos4_map_io
,
74 .init_clocks
= exynos4_init_clocks
,
75 .init_uarts
= exynos4_init_uarts
,
77 .name
= name_exynos4210
,
79 .idcode
= EXYNOS4212_CPU_ID
,
80 .idmask
= EXYNOS4_CPU_MASK
,
81 .map_io
= exynos4_map_io
,
82 .init_clocks
= exynos4_init_clocks
,
83 .init_uarts
= exynos4_init_uarts
,
85 .name
= name_exynos4212
,
87 .idcode
= EXYNOS4412_CPU_ID
,
88 .idmask
= EXYNOS4_CPU_MASK
,
89 .map_io
= exynos4_map_io
,
90 .init_clocks
= exynos4_init_clocks
,
91 .init_uarts
= exynos4_init_uarts
,
93 .name
= name_exynos4412
,
95 .idcode
= EXYNOS5250_SOC_ID
,
96 .idmask
= EXYNOS5_SOC_MASK
,
97 .map_io
= exynos5_map_io
,
98 .init_clocks
= exynos5_init_clocks
,
100 .name
= name_exynos5250
,
104 /* Initial IO mappings */
106 static struct map_desc exynos_iodesc
[] __initdata
= {
108 .virtual = (unsigned long)S5P_VA_CHIPID
,
109 .pfn
= __phys_to_pfn(EXYNOS_PA_CHIPID
),
115 static struct map_desc exynos4_iodesc
[] __initdata
= {
117 .virtual = (unsigned long)S3C_VA_SYS
,
118 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSCON
),
122 .virtual = (unsigned long)S3C_VA_TIMER
,
123 .pfn
= __phys_to_pfn(EXYNOS4_PA_TIMER
),
127 .virtual = (unsigned long)S3C_VA_WATCHDOG
,
128 .pfn
= __phys_to_pfn(EXYNOS4_PA_WATCHDOG
),
132 .virtual = (unsigned long)S5P_VA_SROMC
,
133 .pfn
= __phys_to_pfn(EXYNOS4_PA_SROMC
),
137 .virtual = (unsigned long)S5P_VA_SYSTIMER
,
138 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSTIMER
),
142 .virtual = (unsigned long)S5P_VA_PMU
,
143 .pfn
= __phys_to_pfn(EXYNOS4_PA_PMU
),
147 .virtual = (unsigned long)S5P_VA_COMBINER_BASE
,
148 .pfn
= __phys_to_pfn(EXYNOS4_PA_COMBINER
),
152 .virtual = (unsigned long)S5P_VA_GIC_CPU
,
153 .pfn
= __phys_to_pfn(EXYNOS4_PA_GIC_CPU
),
157 .virtual = (unsigned long)S5P_VA_GIC_DIST
,
158 .pfn
= __phys_to_pfn(EXYNOS4_PA_GIC_DIST
),
162 .virtual = (unsigned long)S3C_VA_UART
,
163 .pfn
= __phys_to_pfn(EXYNOS4_PA_UART
),
167 .virtual = (unsigned long)S5P_VA_CMU
,
168 .pfn
= __phys_to_pfn(EXYNOS4_PA_CMU
),
172 .virtual = (unsigned long)S5P_VA_COREPERI_BASE
,
173 .pfn
= __phys_to_pfn(EXYNOS4_PA_COREPERI
),
177 .virtual = (unsigned long)S5P_VA_L2CC
,
178 .pfn
= __phys_to_pfn(EXYNOS4_PA_L2CC
),
182 .virtual = (unsigned long)S5P_VA_DMC0
,
183 .pfn
= __phys_to_pfn(EXYNOS4_PA_DMC0
),
187 .virtual = (unsigned long)S5P_VA_DMC1
,
188 .pfn
= __phys_to_pfn(EXYNOS4_PA_DMC1
),
192 .virtual = (unsigned long)S3C_VA_USB_HSPHY
,
193 .pfn
= __phys_to_pfn(EXYNOS4_PA_HSPHY
),
199 static struct map_desc exynos4_iodesc0
[] __initdata
= {
201 .virtual = (unsigned long)S5P_VA_SYSRAM
,
202 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSRAM0
),
208 static struct map_desc exynos4_iodesc1
[] __initdata
= {
210 .virtual = (unsigned long)S5P_VA_SYSRAM
,
211 .pfn
= __phys_to_pfn(EXYNOS4_PA_SYSRAM1
),
217 static struct map_desc exynos5_iodesc
[] __initdata
= {
219 .virtual = (unsigned long)S3C_VA_SYS
,
220 .pfn
= __phys_to_pfn(EXYNOS5_PA_SYSCON
),
224 .virtual = (unsigned long)S3C_VA_TIMER
,
225 .pfn
= __phys_to_pfn(EXYNOS5_PA_TIMER
),
229 .virtual = (unsigned long)S3C_VA_WATCHDOG
,
230 .pfn
= __phys_to_pfn(EXYNOS5_PA_WATCHDOG
),
234 .virtual = (unsigned long)S5P_VA_SROMC
,
235 .pfn
= __phys_to_pfn(EXYNOS5_PA_SROMC
),
239 .virtual = (unsigned long)S5P_VA_SYSTIMER
,
240 .pfn
= __phys_to_pfn(EXYNOS5_PA_SYSTIMER
),
244 .virtual = (unsigned long)S5P_VA_SYSRAM
,
245 .pfn
= __phys_to_pfn(EXYNOS5_PA_SYSRAM
),
249 .virtual = (unsigned long)S5P_VA_CMU
,
250 .pfn
= __phys_to_pfn(EXYNOS5_PA_CMU
),
251 .length
= 144 * SZ_1K
,
254 .virtual = (unsigned long)S5P_VA_PMU
,
255 .pfn
= __phys_to_pfn(EXYNOS5_PA_PMU
),
259 .virtual = (unsigned long)S3C_VA_UART
,
260 .pfn
= __phys_to_pfn(EXYNOS5_PA_UART
),
266 void exynos4_restart(char mode
, const char *cmd
)
268 __raw_writel(0x1, S5P_SWRESET
);
271 void exynos5_restart(char mode
, const char *cmd
)
273 __raw_writel(0x1, EXYNOS_SWRESET
);
276 void __init
exynos_init_late(void)
278 exynos_pm_late_initcall();
284 * register the standard cpu IO areas
287 void __init
exynos_init_io(struct map_desc
*mach_desc
, int size
)
289 /* initialize the io descriptors we need for initialization */
290 iotable_init(exynos_iodesc
, ARRAY_SIZE(exynos_iodesc
));
292 iotable_init(mach_desc
, size
);
294 /* detect cpu id and rev. */
295 s5p_init_cpu(S5P_VA_CHIPID
);
297 s3c_init_cpu(samsung_cpu_id
, cpu_ids
, ARRAY_SIZE(cpu_ids
));
300 static void __init
exynos4_map_io(void)
302 iotable_init(exynos4_iodesc
, ARRAY_SIZE(exynos4_iodesc
));
304 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0
)
305 iotable_init(exynos4_iodesc0
, ARRAY_SIZE(exynos4_iodesc0
));
307 iotable_init(exynos4_iodesc1
, ARRAY_SIZE(exynos4_iodesc1
));
309 /* initialize device information early */
310 exynos4_default_sdhci0();
311 exynos4_default_sdhci1();
312 exynos4_default_sdhci2();
313 exynos4_default_sdhci3();
315 s3c_adc_setname("samsung-adc-v3");
317 s3c_fimc_setname(0, "exynos4-fimc");
318 s3c_fimc_setname(1, "exynos4-fimc");
319 s3c_fimc_setname(2, "exynos4-fimc");
320 s3c_fimc_setname(3, "exynos4-fimc");
322 s3c_sdhci_setname(0, "exynos4-sdhci");
323 s3c_sdhci_setname(1, "exynos4-sdhci");
324 s3c_sdhci_setname(2, "exynos4-sdhci");
325 s3c_sdhci_setname(3, "exynos4-sdhci");
327 /* The I2C bus controllers are directly compatible with s3c2440 */
328 s3c_i2c0_setname("s3c2440-i2c");
329 s3c_i2c1_setname("s3c2440-i2c");
330 s3c_i2c2_setname("s3c2440-i2c");
332 s5p_fb_setname(0, "exynos4-fb");
333 s5p_hdmi_setname("exynos4-hdmi");
335 s3c64xx_spi_setname("exynos4210-spi");
338 static void __init
exynos5_map_io(void)
340 iotable_init(exynos5_iodesc
, ARRAY_SIZE(exynos5_iodesc
));
342 s3c_device_i2c0
.resource
[0].start
= EXYNOS5_PA_IIC(0);
343 s3c_device_i2c0
.resource
[0].end
= EXYNOS5_PA_IIC(0) + SZ_4K
- 1;
344 s3c_device_i2c0
.resource
[1].start
= EXYNOS5_IRQ_IIC
;
345 s3c_device_i2c0
.resource
[1].end
= EXYNOS5_IRQ_IIC
;
347 s3c_sdhci_setname(0, "exynos4-sdhci");
348 s3c_sdhci_setname(1, "exynos4-sdhci");
349 s3c_sdhci_setname(2, "exynos4-sdhci");
350 s3c_sdhci_setname(3, "exynos4-sdhci");
352 /* The I2C bus controllers are directly compatible with s3c2440 */
353 s3c_i2c0_setname("s3c2440-i2c");
354 s3c_i2c1_setname("s3c2440-i2c");
355 s3c_i2c2_setname("s3c2440-i2c");
357 s3c64xx_spi_setname("exynos4210-spi");
360 static void __init
exynos4_init_clocks(int xtal
)
362 printk(KERN_DEBUG
"%s: initializing clocks\n", __func__
);
364 s3c24xx_register_baseclocks(xtal
);
365 s5p_register_clocks(xtal
);
367 if (soc_is_exynos4210())
368 exynos4210_register_clocks();
369 else if (soc_is_exynos4212() || soc_is_exynos4412())
370 exynos4212_register_clocks();
372 exynos4_register_clocks();
373 exynos4_setup_clocks();
376 static void __init
exynos5_init_clocks(int xtal
)
378 printk(KERN_DEBUG
"%s: initializing clocks\n", __func__
);
380 s3c24xx_register_baseclocks(xtal
);
381 s5p_register_clocks(xtal
);
383 exynos5_register_clocks();
384 exynos5_setup_clocks();
387 #define COMBINER_ENABLE_SET 0x0
388 #define COMBINER_ENABLE_CLEAR 0x4
389 #define COMBINER_INT_STATUS 0xC
391 static DEFINE_SPINLOCK(irq_controller_lock
);
393 struct combiner_chip_data
{
394 unsigned int irq_offset
;
395 unsigned int irq_mask
;
399 static struct irq_domain
*combiner_irq_domain
;
400 static struct combiner_chip_data combiner_data
[MAX_COMBINER_NR
];
402 static inline void __iomem
*combiner_base(struct irq_data
*data
)
404 struct combiner_chip_data
*combiner_data
=
405 irq_data_get_irq_chip_data(data
);
407 return combiner_data
->base
;
410 static void combiner_mask_irq(struct irq_data
*data
)
412 u32 mask
= 1 << (data
->hwirq
% 32);
414 __raw_writel(mask
, combiner_base(data
) + COMBINER_ENABLE_CLEAR
);
417 static void combiner_unmask_irq(struct irq_data
*data
)
419 u32 mask
= 1 << (data
->hwirq
% 32);
421 __raw_writel(mask
, combiner_base(data
) + COMBINER_ENABLE_SET
);
424 static void combiner_handle_cascade_irq(unsigned int irq
, struct irq_desc
*desc
)
426 struct combiner_chip_data
*chip_data
= irq_get_handler_data(irq
);
427 struct irq_chip
*chip
= irq_get_chip(irq
);
428 unsigned int cascade_irq
, combiner_irq
;
429 unsigned long status
;
431 chained_irq_enter(chip
, desc
);
433 spin_lock(&irq_controller_lock
);
434 status
= __raw_readl(chip_data
->base
+ COMBINER_INT_STATUS
);
435 spin_unlock(&irq_controller_lock
);
436 status
&= chip_data
->irq_mask
;
441 combiner_irq
= __ffs(status
);
443 cascade_irq
= combiner_irq
+ (chip_data
->irq_offset
& ~31);
444 if (unlikely(cascade_irq
>= NR_IRQS
))
445 do_bad_IRQ(cascade_irq
, desc
);
447 generic_handle_irq(cascade_irq
);
450 chained_irq_exit(chip
, desc
);
453 static struct irq_chip combiner_chip
= {
455 .irq_mask
= combiner_mask_irq
,
456 .irq_unmask
= combiner_unmask_irq
,
459 static void __init
combiner_cascade_irq(unsigned int combiner_nr
, unsigned int irq
)
463 if (soc_is_exynos5250())
464 max_nr
= EXYNOS5_MAX_COMBINER_NR
;
466 max_nr
= EXYNOS4_MAX_COMBINER_NR
;
468 if (combiner_nr
>= max_nr
)
470 if (irq_set_handler_data(irq
, &combiner_data
[combiner_nr
]) != 0)
472 irq_set_chained_handler(irq
, combiner_handle_cascade_irq
);
475 static void __init
combiner_init_one(unsigned int combiner_nr
,
478 combiner_data
[combiner_nr
].base
= base
;
479 combiner_data
[combiner_nr
].irq_offset
= irq_find_mapping(
480 combiner_irq_domain
, combiner_nr
* MAX_IRQ_IN_COMBINER
);
481 combiner_data
[combiner_nr
].irq_mask
= 0xff << ((combiner_nr
% 4) << 3);
483 /* Disable all interrupts */
484 __raw_writel(combiner_data
[combiner_nr
].irq_mask
,
485 base
+ COMBINER_ENABLE_CLEAR
);
489 static int combiner_irq_domain_xlate(struct irq_domain
*d
,
490 struct device_node
*controller
,
491 const u32
*intspec
, unsigned int intsize
,
492 unsigned long *out_hwirq
,
493 unsigned int *out_type
)
495 if (d
->of_node
!= controller
)
501 *out_hwirq
= intspec
[0] * MAX_IRQ_IN_COMBINER
+ intspec
[1];
507 static int combiner_irq_domain_xlate(struct irq_domain
*d
,
508 struct device_node
*controller
,
509 const u32
*intspec
, unsigned int intsize
,
510 unsigned long *out_hwirq
,
511 unsigned int *out_type
)
517 static int combiner_irq_domain_map(struct irq_domain
*d
, unsigned int irq
,
520 irq_set_chip_and_handler(irq
, &combiner_chip
, handle_level_irq
);
521 irq_set_chip_data(irq
, &combiner_data
[hw
>> 3]);
522 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
527 static struct irq_domain_ops combiner_irq_domain_ops
= {
528 .xlate
= combiner_irq_domain_xlate
,
529 .map
= combiner_irq_domain_map
,
532 static void __init
combiner_init(void __iomem
*combiner_base
,
533 struct device_node
*np
)
535 int i
, irq
, irq_base
;
536 unsigned int max_nr
, nr_irq
;
539 if (of_property_read_u32(np
, "samsung,combiner-nr", &max_nr
)) {
540 pr_warning("%s: number of combiners not specified, "
541 "setting default as %d.\n",
542 __func__
, EXYNOS4_MAX_COMBINER_NR
);
543 max_nr
= EXYNOS4_MAX_COMBINER_NR
;
546 max_nr
= soc_is_exynos5250() ? EXYNOS5_MAX_COMBINER_NR
:
547 EXYNOS4_MAX_COMBINER_NR
;
549 nr_irq
= max_nr
* MAX_IRQ_IN_COMBINER
;
551 irq_base
= irq_alloc_descs(COMBINER_IRQ(0, 0), 1, nr_irq
, 0);
552 if (IS_ERR_VALUE(irq_base
)) {
553 irq_base
= COMBINER_IRQ(0, 0);
554 pr_warning("%s: irq desc alloc failed. Continuing with %d as linux irq base\n", __func__
, irq_base
);
557 combiner_irq_domain
= irq_domain_add_legacy(np
, nr_irq
, irq_base
, 0,
558 &combiner_irq_domain_ops
, &combiner_data
);
559 if (WARN_ON(!combiner_irq_domain
)) {
560 pr_warning("%s: irq domain init failed\n", __func__
);
564 for (i
= 0; i
< max_nr
; i
++) {
565 combiner_init_one(i
, combiner_base
+ (i
>> 2) * 0x10);
569 irq
= irq_of_parse_and_map(np
, i
);
571 combiner_cascade_irq(i
, irq
);
576 int __init
combiner_of_init(struct device_node
*np
, struct device_node
*parent
)
578 void __iomem
*combiner_base
;
580 combiner_base
= of_iomap(np
, 0);
581 if (!combiner_base
) {
582 pr_err("%s: failed to map combiner registers\n", __func__
);
586 combiner_init(combiner_base
, np
);
591 static const struct of_device_id exynos4_dt_irq_match
[] = {
592 { .compatible
= "arm,cortex-a9-gic", .data
= gic_of_init
, },
593 { .compatible
= "samsung,exynos4210-combiner",
594 .data
= combiner_of_init
, },
599 void __init
exynos4_init_irq(void)
601 unsigned int gic_bank_offset
;
603 gic_bank_offset
= soc_is_exynos4412() ? 0x4000 : 0x8000;
605 if (!of_have_populated_dt())
606 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST
, S5P_VA_GIC_CPU
, gic_bank_offset
, NULL
);
609 of_irq_init(exynos4_dt_irq_match
);
612 if (!of_have_populated_dt())
613 combiner_init(S5P_VA_COMBINER_BASE
, NULL
);
616 * The parameters of s5p_init_irq() are for VIC init.
617 * Theses parameters should be NULL and 0 because EXYNOS4
618 * uses GIC instead of VIC.
620 s5p_init_irq(NULL
, 0);
623 void __init
exynos5_init_irq(void)
626 of_irq_init(exynos4_dt_irq_match
);
629 * The parameters of s5p_init_irq() are for VIC init.
630 * Theses parameters should be NULL and 0 because EXYNOS4
631 * uses GIC instead of VIC.
633 s5p_init_irq(NULL
, 0);
636 struct bus_type exynos_subsys
= {
637 .name
= "exynos-core",
638 .dev_name
= "exynos-core",
641 static struct device exynos4_dev
= {
642 .bus
= &exynos_subsys
,
645 static int __init
exynos_core_init(void)
647 return subsys_system_register(&exynos_subsys
, NULL
);
649 core_initcall(exynos_core_init
);
651 #ifdef CONFIG_CACHE_L2X0
652 static int __init
exynos4_l2x0_cache_init(void)
656 if (soc_is_exynos5250())
659 ret
= l2x0_of_init(L2_AUX_VAL
, L2_AUX_MASK
);
661 l2x0_regs_phys
= virt_to_phys(&l2x0_saved_regs
);
662 clean_dcache_area(&l2x0_regs_phys
, sizeof(unsigned long));
666 if (!(__raw_readl(S5P_VA_L2CC
+ L2X0_CTRL
) & 0x1)) {
667 l2x0_saved_regs
.phy_base
= EXYNOS4_PA_L2CC
;
668 /* TAG, Data Latency Control: 2 cycles */
669 l2x0_saved_regs
.tag_latency
= 0x110;
671 if (soc_is_exynos4212() || soc_is_exynos4412())
672 l2x0_saved_regs
.data_latency
= 0x120;
674 l2x0_saved_regs
.data_latency
= 0x110;
676 l2x0_saved_regs
.prefetch_ctrl
= 0x30000007;
677 l2x0_saved_regs
.pwr_ctrl
=
678 (L2X0_DYNAMIC_CLK_GATING_EN
| L2X0_STNDBY_MODE_EN
);
680 l2x0_regs_phys
= virt_to_phys(&l2x0_saved_regs
);
682 __raw_writel(l2x0_saved_regs
.tag_latency
,
683 S5P_VA_L2CC
+ L2X0_TAG_LATENCY_CTRL
);
684 __raw_writel(l2x0_saved_regs
.data_latency
,
685 S5P_VA_L2CC
+ L2X0_DATA_LATENCY_CTRL
);
687 /* L2X0 Prefetch Control */
688 __raw_writel(l2x0_saved_regs
.prefetch_ctrl
,
689 S5P_VA_L2CC
+ L2X0_PREFETCH_CTRL
);
691 /* L2X0 Power Control */
692 __raw_writel(l2x0_saved_regs
.pwr_ctrl
,
693 S5P_VA_L2CC
+ L2X0_POWER_CTRL
);
695 clean_dcache_area(&l2x0_regs_phys
, sizeof(unsigned long));
696 clean_dcache_area(&l2x0_saved_regs
, sizeof(struct l2x0_regs
));
699 l2x0_init(S5P_VA_L2CC
, L2_AUX_VAL
, L2_AUX_MASK
);
702 early_initcall(exynos4_l2x0_cache_init
);
705 static int __init
exynos_init(void)
707 printk(KERN_INFO
"EXYNOS: Initializing architecture\n");
709 return device_register(&exynos4_dev
);
712 /* uart registration process */
714 static void __init
exynos4_init_uarts(struct s3c2410_uartcfg
*cfg
, int no
)
716 struct s3c2410_uartcfg
*tcfg
= cfg
;
719 for (ucnt
= 0; ucnt
< no
; ucnt
++, tcfg
++)
720 tcfg
->has_fracval
= 1;
722 s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources
, cfg
, no
);
725 static void __iomem
*exynos_eint_base
;
727 static DEFINE_SPINLOCK(eint_lock
);
729 static unsigned int eint0_15_data
[16];
731 static inline int exynos4_irq_to_gpio(unsigned int irq
)
733 if (irq
< IRQ_EINT(0))
738 return EXYNOS4_GPX0(irq
);
742 return EXYNOS4_GPX1(irq
);
746 return EXYNOS4_GPX2(irq
);
750 return EXYNOS4_GPX3(irq
);
755 static inline int exynos5_irq_to_gpio(unsigned int irq
)
757 if (irq
< IRQ_EINT(0))
762 return EXYNOS5_GPX0(irq
);
766 return EXYNOS5_GPX1(irq
);
770 return EXYNOS5_GPX2(irq
);
774 return EXYNOS5_GPX3(irq
);
779 static unsigned int exynos4_eint0_15_src_int
[16] = {
798 static unsigned int exynos5_eint0_15_src_int
[16] = {
816 static inline void exynos_irq_eint_mask(struct irq_data
*data
)
820 spin_lock(&eint_lock
);
821 mask
= __raw_readl(EINT_MASK(exynos_eint_base
, data
->irq
));
822 mask
|= EINT_OFFSET_BIT(data
->irq
);
823 __raw_writel(mask
, EINT_MASK(exynos_eint_base
, data
->irq
));
824 spin_unlock(&eint_lock
);
827 static void exynos_irq_eint_unmask(struct irq_data
*data
)
831 spin_lock(&eint_lock
);
832 mask
= __raw_readl(EINT_MASK(exynos_eint_base
, data
->irq
));
833 mask
&= ~(EINT_OFFSET_BIT(data
->irq
));
834 __raw_writel(mask
, EINT_MASK(exynos_eint_base
, data
->irq
));
835 spin_unlock(&eint_lock
);
838 static inline void exynos_irq_eint_ack(struct irq_data
*data
)
840 __raw_writel(EINT_OFFSET_BIT(data
->irq
),
841 EINT_PEND(exynos_eint_base
, data
->irq
));
844 static void exynos_irq_eint_maskack(struct irq_data
*data
)
846 exynos_irq_eint_mask(data
);
847 exynos_irq_eint_ack(data
);
850 static int exynos_irq_eint_set_type(struct irq_data
*data
, unsigned int type
)
852 int offs
= EINT_OFFSET(data
->irq
);
858 case IRQ_TYPE_EDGE_RISING
:
859 newvalue
= S5P_IRQ_TYPE_EDGE_RISING
;
862 case IRQ_TYPE_EDGE_FALLING
:
863 newvalue
= S5P_IRQ_TYPE_EDGE_FALLING
;
866 case IRQ_TYPE_EDGE_BOTH
:
867 newvalue
= S5P_IRQ_TYPE_EDGE_BOTH
;
870 case IRQ_TYPE_LEVEL_LOW
:
871 newvalue
= S5P_IRQ_TYPE_LEVEL_LOW
;
874 case IRQ_TYPE_LEVEL_HIGH
:
875 newvalue
= S5P_IRQ_TYPE_LEVEL_HIGH
;
879 printk(KERN_ERR
"No such irq type %d", type
);
883 shift
= (offs
& 0x7) * 4;
886 spin_lock(&eint_lock
);
887 ctrl
= __raw_readl(EINT_CON(exynos_eint_base
, data
->irq
));
889 ctrl
|= newvalue
<< shift
;
890 __raw_writel(ctrl
, EINT_CON(exynos_eint_base
, data
->irq
));
891 spin_unlock(&eint_lock
);
893 if (soc_is_exynos5250())
894 s3c_gpio_cfgpin(exynos5_irq_to_gpio(data
->irq
), S3C_GPIO_SFN(0xf));
896 s3c_gpio_cfgpin(exynos4_irq_to_gpio(data
->irq
), S3C_GPIO_SFN(0xf));
901 static struct irq_chip exynos_irq_eint
= {
902 .name
= "exynos-eint",
903 .irq_mask
= exynos_irq_eint_mask
,
904 .irq_unmask
= exynos_irq_eint_unmask
,
905 .irq_mask_ack
= exynos_irq_eint_maskack
,
906 .irq_ack
= exynos_irq_eint_ack
,
907 .irq_set_type
= exynos_irq_eint_set_type
,
909 .irq_set_wake
= s3c_irqext_wake
,
914 * exynos4_irq_demux_eint
916 * This function demuxes the IRQ from from EINTs 16 to 31.
917 * It is designed to be inlined into the specific handler
918 * s5p_irq_demux_eintX_Y.
920 * Each EINT pend/mask registers handle eight of them.
922 static inline void exynos_irq_demux_eint(unsigned int start
)
926 u32 status
= __raw_readl(EINT_PEND(exynos_eint_base
, start
));
927 u32 mask
= __raw_readl(EINT_MASK(exynos_eint_base
, start
));
933 irq
= fls(status
) - 1;
934 generic_handle_irq(irq
+ start
);
935 status
&= ~(1 << irq
);
939 static void exynos_irq_demux_eint16_31(unsigned int irq
, struct irq_desc
*desc
)
941 struct irq_chip
*chip
= irq_get_chip(irq
);
942 chained_irq_enter(chip
, desc
);
943 exynos_irq_demux_eint(IRQ_EINT(16));
944 exynos_irq_demux_eint(IRQ_EINT(24));
945 chained_irq_exit(chip
, desc
);
948 static void exynos_irq_eint0_15(unsigned int irq
, struct irq_desc
*desc
)
950 u32
*irq_data
= irq_get_handler_data(irq
);
951 struct irq_chip
*chip
= irq_get_chip(irq
);
953 chained_irq_enter(chip
, desc
);
954 chip
->irq_mask(&desc
->irq_data
);
957 chip
->irq_ack(&desc
->irq_data
);
959 generic_handle_irq(*irq_data
);
961 chip
->irq_unmask(&desc
->irq_data
);
962 chained_irq_exit(chip
, desc
);
965 static int __init
exynos_init_irq_eint(void)
969 #ifdef CONFIG_PINCTRL_SAMSUNG
971 * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
972 * functionality along with support for external gpio and wakeup
973 * interrupts. If the samsung pinctrl driver is enabled and includes
974 * the wakeup interrupt support, then the setting up external wakeup
975 * interrupts here can be skipped. This check here is temporary to
976 * allow exynos4 platforms that do not use Samsung pinctrl driver to
977 * co-exist with platforms that do. When all of the Samsung Exynos4
978 * platforms switch over to using the pinctrl driver, the wakeup
979 * interrupt support code here can be completely removed.
981 struct device_node
*pctrl_np
, *wkup_np
;
982 const char *pctrl_compat
= "samsung,pinctrl-exynos4210";
983 const char *wkup_compat
= "samsung,exynos4210-wakeup-eint";
985 for_each_compatible_node(pctrl_np
, NULL
, pctrl_compat
) {
986 if (of_device_is_available(pctrl_np
)) {
987 wkup_np
= of_find_compatible_node(pctrl_np
, NULL
,
995 if (soc_is_exynos5250())
996 exynos_eint_base
= ioremap(EXYNOS5_PA_GPIO1
, SZ_4K
);
998 exynos_eint_base
= ioremap(EXYNOS4_PA_GPIO2
, SZ_4K
);
1000 if (exynos_eint_base
== NULL
) {
1001 pr_err("unable to ioremap for EINT base address\n");
1005 for (irq
= 0 ; irq
<= 31 ; irq
++) {
1006 irq_set_chip_and_handler(IRQ_EINT(irq
), &exynos_irq_eint
,
1008 set_irq_flags(IRQ_EINT(irq
), IRQF_VALID
);
1011 irq_set_chained_handler(EXYNOS_IRQ_EINT16_31
, exynos_irq_demux_eint16_31
);
1013 for (irq
= 0 ; irq
<= 15 ; irq
++) {
1014 eint0_15_data
[irq
] = IRQ_EINT(irq
);
1016 if (soc_is_exynos5250()) {
1017 irq_set_handler_data(exynos5_eint0_15_src_int
[irq
],
1018 &eint0_15_data
[irq
]);
1019 irq_set_chained_handler(exynos5_eint0_15_src_int
[irq
],
1020 exynos_irq_eint0_15
);
1022 irq_set_handler_data(exynos4_eint0_15_src_int
[irq
],
1023 &eint0_15_data
[irq
]);
1024 irq_set_chained_handler(exynos4_eint0_15_src_int
[irq
],
1025 exynos_irq_eint0_15
);
1031 arch_initcall(exynos_init_irq_eint
);