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";
61 static const char name_exynos5440[] = "EXYNOS5440";
63 static void exynos4_map_io(void);
64 static void exynos5_map_io(void);
65 static void exynos5440_map_io(void);
66 static void exynos4_init_clocks(int xtal);
67 static void exynos5_init_clocks(int xtal);
68 static void exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no);
69 static int exynos_init(void);
71 static struct cpu_table cpu_ids[] __initdata = {
73 .idcode = EXYNOS4210_CPU_ID,
74 .idmask = EXYNOS4_CPU_MASK,
75 .map_io = exynos4_map_io,
76 .init_clocks = exynos4_init_clocks,
77 .init_uarts = exynos_init_uarts,
79 .name = name_exynos4210,
81 .idcode = EXYNOS4212_CPU_ID,
82 .idmask = EXYNOS4_CPU_MASK,
83 .map_io = exynos4_map_io,
84 .init_clocks = exynos4_init_clocks,
85 .init_uarts = exynos_init_uarts,
87 .name = name_exynos4212,
89 .idcode = EXYNOS4412_CPU_ID,
90 .idmask = EXYNOS4_CPU_MASK,
91 .map_io = exynos4_map_io,
92 .init_clocks = exynos4_init_clocks,
93 .init_uarts = exynos_init_uarts,
95 .name = name_exynos4412,
97 .idcode = EXYNOS5250_SOC_ID,
98 .idmask = EXYNOS5_SOC_MASK,
99 .map_io = exynos5_map_io,
100 .init_clocks = exynos5_init_clocks,
101 .init_uarts = exynos_init_uarts,
103 .name = name_exynos5250,
105 .idcode = EXYNOS5440_SOC_ID,
106 .idmask = EXYNOS5_SOC_MASK,
107 .map_io = exynos5440_map_io,
109 .name = name_exynos5440,
113 /* Initial IO mappings */
115 static struct map_desc exynos_iodesc[] __initdata = {
117 .virtual = (unsigned long)S5P_VA_CHIPID,
118 .pfn = __phys_to_pfn(EXYNOS_PA_CHIPID),
124 static struct map_desc exynos5440_iodesc[] __initdata = {
126 .virtual = (unsigned long)S5P_VA_CHIPID,
127 .pfn = __phys_to_pfn(EXYNOS5440_PA_CHIPID),
133 static struct map_desc exynos4_iodesc[] __initdata = {
135 .virtual = (unsigned long)S3C_VA_SYS,
136 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
140 .virtual = (unsigned long)S3C_VA_TIMER,
141 .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
145 .virtual = (unsigned long)S3C_VA_WATCHDOG,
146 .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
150 .virtual = (unsigned long)S5P_VA_SROMC,
151 .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
155 .virtual = (unsigned long)S5P_VA_SYSTIMER,
156 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
160 .virtual = (unsigned long)S5P_VA_PMU,
161 .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
165 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
166 .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
170 .virtual = (unsigned long)S5P_VA_GIC_CPU,
171 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
175 .virtual = (unsigned long)S5P_VA_GIC_DIST,
176 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
180 .virtual = (unsigned long)S3C_VA_UART,
181 .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
185 .virtual = (unsigned long)S5P_VA_CMU,
186 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
190 .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
191 .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
195 .virtual = (unsigned long)S5P_VA_L2CC,
196 .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
200 .virtual = (unsigned long)S5P_VA_DMC0,
201 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
205 .virtual = (unsigned long)S5P_VA_DMC1,
206 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
210 .virtual = (unsigned long)S3C_VA_USB_HSPHY,
211 .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
217 static struct map_desc exynos4_iodesc0[] __initdata = {
219 .virtual = (unsigned long)S5P_VA_SYSRAM,
220 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
226 static struct map_desc exynos4_iodesc1[] __initdata = {
228 .virtual = (unsigned long)S5P_VA_SYSRAM,
229 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
235 static struct map_desc exynos5_iodesc[] __initdata = {
237 .virtual = (unsigned long)S3C_VA_SYS,
238 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
242 .virtual = (unsigned long)S3C_VA_TIMER,
243 .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
247 .virtual = (unsigned long)S3C_VA_WATCHDOG,
248 .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
252 .virtual = (unsigned long)S5P_VA_SROMC,
253 .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
257 .virtual = (unsigned long)S5P_VA_SYSTIMER,
258 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSTIMER),
262 .virtual = (unsigned long)S5P_VA_SYSRAM,
263 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
267 .virtual = (unsigned long)S5P_VA_CMU,
268 .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
269 .length = 144 * SZ_1K,
272 .virtual = (unsigned long)S5P_VA_PMU,
273 .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
277 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
278 .pfn = __phys_to_pfn(EXYNOS5_PA_COMBINER),
282 .virtual = (unsigned long)S3C_VA_UART,
283 .pfn = __phys_to_pfn(EXYNOS5_PA_UART),
287 .virtual = (unsigned long)S5P_VA_GIC_CPU,
288 .pfn = __phys_to_pfn(EXYNOS5_PA_GIC_CPU),
292 .virtual = (unsigned long)S5P_VA_GIC_DIST,
293 .pfn = __phys_to_pfn(EXYNOS5_PA_GIC_DIST),
299 static struct map_desc exynos5440_iodesc0[] __initdata = {
301 .virtual = (unsigned long)S3C_VA_UART,
302 .pfn = __phys_to_pfn(EXYNOS5440_PA_UART0),
308 void exynos4_restart(char mode, const char *cmd)
310 __raw_writel(0x1, S5P_SWRESET);
313 void exynos5_restart(char mode, const char *cmd)
318 if (of_machine_is_compatible("samsung,exynos5250")) {
320 addr = EXYNOS_SWRESET;
321 } else if (of_machine_is_compatible("samsung,exynos5440")) {
322 val = (0x10 << 20) | (0x1 << 16);
323 addr = EXYNOS5440_SWRESET;
325 pr_err("%s: cannot support non-DT\n", __func__);
329 __raw_writel(val, addr);
332 void __init exynos_init_late(void)
334 if (of_machine_is_compatible("samsung,exynos5440"))
335 /* to be supported later */
338 exynos_pm_late_initcall();
344 * register the standard cpu IO areas
347 void __init exynos_init_io(struct map_desc *mach_desc, int size)
349 /* initialize the io descriptors we need for initialization */
350 if (of_machine_is_compatible("samsung,exynos5440"))
351 iotable_init(exynos5440_iodesc, ARRAY_SIZE(exynos5440_iodesc));
353 iotable_init(exynos_iodesc, ARRAY_SIZE(exynos_iodesc));
356 iotable_init(mach_desc, size);
358 /* detect cpu id and rev. */
359 s5p_init_cpu(S5P_VA_CHIPID);
361 s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
364 static void __init exynos4_map_io(void)
366 iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
368 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
369 iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
371 iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
373 /* initialize device information early */
374 exynos4_default_sdhci0();
375 exynos4_default_sdhci1();
376 exynos4_default_sdhci2();
377 exynos4_default_sdhci3();
379 s3c_adc_setname("samsung-adc-v3");
381 s3c_fimc_setname(0, "exynos4-fimc");
382 s3c_fimc_setname(1, "exynos4-fimc");
383 s3c_fimc_setname(2, "exynos4-fimc");
384 s3c_fimc_setname(3, "exynos4-fimc");
386 s3c_sdhci_setname(0, "exynos4-sdhci");
387 s3c_sdhci_setname(1, "exynos4-sdhci");
388 s3c_sdhci_setname(2, "exynos4-sdhci");
389 s3c_sdhci_setname(3, "exynos4-sdhci");
391 /* The I2C bus controllers are directly compatible with s3c2440 */
392 s3c_i2c0_setname("s3c2440-i2c");
393 s3c_i2c1_setname("s3c2440-i2c");
394 s3c_i2c2_setname("s3c2440-i2c");
396 s5p_fb_setname(0, "exynos4-fb");
397 s5p_hdmi_setname("exynos4-hdmi");
399 s3c64xx_spi_setname("exynos4210-spi");
402 static void __init exynos5_map_io(void)
404 iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
406 s3c_device_i2c0.resource[0].start = EXYNOS5_PA_IIC(0);
407 s3c_device_i2c0.resource[0].end = EXYNOS5_PA_IIC(0) + SZ_4K - 1;
408 s3c_device_i2c0.resource[1].start = EXYNOS5_IRQ_IIC;
409 s3c_device_i2c0.resource[1].end = EXYNOS5_IRQ_IIC;
411 s3c_sdhci_setname(0, "exynos4-sdhci");
412 s3c_sdhci_setname(1, "exynos4-sdhci");
413 s3c_sdhci_setname(2, "exynos4-sdhci");
414 s3c_sdhci_setname(3, "exynos4-sdhci");
416 /* The I2C bus controllers are directly compatible with s3c2440 */
417 s3c_i2c0_setname("s3c2440-i2c");
418 s3c_i2c1_setname("s3c2440-i2c");
419 s3c_i2c2_setname("s3c2440-i2c");
421 s3c64xx_spi_setname("exynos4210-spi");
424 static void __init exynos4_init_clocks(int xtal)
426 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
428 s3c24xx_register_baseclocks(xtal);
429 s5p_register_clocks(xtal);
431 if (soc_is_exynos4210())
432 exynos4210_register_clocks();
433 else if (soc_is_exynos4212() || soc_is_exynos4412())
434 exynos4212_register_clocks();
436 exynos4_register_clocks();
437 exynos4_setup_clocks();
440 static void __init exynos5440_map_io(void)
442 iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
445 static void __init exynos5_init_clocks(int xtal)
447 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
449 s3c24xx_register_baseclocks(xtal);
450 s5p_register_clocks(xtal);
452 exynos5_register_clocks();
453 exynos5_setup_clocks();
456 #define COMBINER_ENABLE_SET 0x0
457 #define COMBINER_ENABLE_CLEAR 0x4
458 #define COMBINER_INT_STATUS 0xC
460 static DEFINE_SPINLOCK(irq_controller_lock);
462 struct combiner_chip_data {
463 unsigned int irq_offset;
464 unsigned int irq_mask;
468 static struct irq_domain *combiner_irq_domain;
469 static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
471 static inline void __iomem *combiner_base(struct irq_data *data)
473 struct combiner_chip_data *combiner_data =
474 irq_data_get_irq_chip_data(data);
476 return combiner_data->base;
479 static void combiner_mask_irq(struct irq_data *data)
481 u32 mask = 1 << (data->hwirq % 32);
483 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
486 static void combiner_unmask_irq(struct irq_data *data)
488 u32 mask = 1 << (data->hwirq % 32);
490 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
493 static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
495 struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
496 struct irq_chip *chip = irq_get_chip(irq);
497 unsigned int cascade_irq, combiner_irq;
498 unsigned long status;
500 chained_irq_enter(chip, desc);
502 spin_lock(&irq_controller_lock);
503 status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
504 spin_unlock(&irq_controller_lock);
505 status &= chip_data->irq_mask;
510 combiner_irq = __ffs(status);
512 cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
513 if (unlikely(cascade_irq >= NR_IRQS))
514 do_bad_IRQ(cascade_irq, desc);
516 generic_handle_irq(cascade_irq);
519 chained_irq_exit(chip, desc);
522 static struct irq_chip combiner_chip = {
524 .irq_mask = combiner_mask_irq,
525 .irq_unmask = combiner_unmask_irq,
528 static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
532 if (soc_is_exynos5250())
533 max_nr = EXYNOS5_MAX_COMBINER_NR;
535 max_nr = EXYNOS4_MAX_COMBINER_NR;
537 if (combiner_nr >= max_nr)
539 if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
541 irq_set_chained_handler(irq, combiner_handle_cascade_irq);
544 static void __init combiner_init_one(unsigned int combiner_nr,
547 combiner_data[combiner_nr].base = base;
548 combiner_data[combiner_nr].irq_offset = irq_find_mapping(
549 combiner_irq_domain, combiner_nr * MAX_IRQ_IN_COMBINER);
550 combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3);
552 /* Disable all interrupts */
553 __raw_writel(combiner_data[combiner_nr].irq_mask,
554 base + COMBINER_ENABLE_CLEAR);
558 static int combiner_irq_domain_xlate(struct irq_domain *d,
559 struct device_node *controller,
560 const u32 *intspec, unsigned int intsize,
561 unsigned long *out_hwirq,
562 unsigned int *out_type)
564 if (d->of_node != controller)
570 *out_hwirq = intspec[0] * MAX_IRQ_IN_COMBINER + intspec[1];
576 static int combiner_irq_domain_xlate(struct irq_domain *d,
577 struct device_node *controller,
578 const u32 *intspec, unsigned int intsize,
579 unsigned long *out_hwirq,
580 unsigned int *out_type)
586 static int combiner_irq_domain_map(struct irq_domain *d, unsigned int irq,
589 irq_set_chip_and_handler(irq, &combiner_chip, handle_level_irq);
590 irq_set_chip_data(irq, &combiner_data[hw >> 3]);
591 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
596 static struct irq_domain_ops combiner_irq_domain_ops = {
597 .xlate = combiner_irq_domain_xlate,
598 .map = combiner_irq_domain_map,
601 static void __init combiner_init(void __iomem *combiner_base,
602 struct device_node *np)
604 int i, irq, irq_base;
605 unsigned int max_nr, nr_irq;
608 if (of_property_read_u32(np, "samsung,combiner-nr", &max_nr)) {
609 pr_warning("%s: number of combiners not specified, "
610 "setting default as %d.\n",
611 __func__, EXYNOS4_MAX_COMBINER_NR);
612 max_nr = EXYNOS4_MAX_COMBINER_NR;
615 max_nr = soc_is_exynos5250() ? EXYNOS5_MAX_COMBINER_NR :
616 EXYNOS4_MAX_COMBINER_NR;
618 nr_irq = max_nr * MAX_IRQ_IN_COMBINER;
620 irq_base = irq_alloc_descs(COMBINER_IRQ(0, 0), 1, nr_irq, 0);
621 if (IS_ERR_VALUE(irq_base)) {
622 irq_base = COMBINER_IRQ(0, 0);
623 pr_warning("%s: irq desc alloc failed. Continuing with %d as linux irq base\n", __func__, irq_base);
626 combiner_irq_domain = irq_domain_add_legacy(np, nr_irq, irq_base, 0,
627 &combiner_irq_domain_ops, &combiner_data);
628 if (WARN_ON(!combiner_irq_domain)) {
629 pr_warning("%s: irq domain init failed\n", __func__);
633 for (i = 0; i < max_nr; i++) {
634 combiner_init_one(i, combiner_base + (i >> 2) * 0x10);
638 irq = irq_of_parse_and_map(np, i);
640 combiner_cascade_irq(i, irq);
645 int __init combiner_of_init(struct device_node *np, struct device_node *parent)
647 void __iomem *combiner_base;
649 combiner_base = of_iomap(np, 0);
650 if (!combiner_base) {
651 pr_err("%s: failed to map combiner registers\n", __func__);
655 combiner_init(combiner_base, np);
660 static const struct of_device_id exynos_dt_irq_match[] = {
661 { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, },
662 { .compatible = "arm,cortex-a15-gic", .data = gic_of_init, },
663 { .compatible = "samsung,exynos4210-combiner",
664 .data = combiner_of_init, },
669 void __init exynos4_init_irq(void)
671 unsigned int gic_bank_offset;
673 gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
675 if (!of_have_populated_dt())
676 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
679 of_irq_init(exynos_dt_irq_match);
682 if (!of_have_populated_dt())
683 combiner_init(S5P_VA_COMBINER_BASE, NULL);
686 * The parameters of s5p_init_irq() are for VIC init.
687 * Theses parameters should be NULL and 0 because EXYNOS4
688 * uses GIC instead of VIC.
690 s5p_init_irq(NULL, 0);
693 void __init exynos5_init_irq(void)
696 of_irq_init(exynos_dt_irq_match);
699 * The parameters of s5p_init_irq() are for VIC init.
700 * Theses parameters should be NULL and 0 because EXYNOS4
701 * uses GIC instead of VIC.
703 s5p_init_irq(NULL, 0);
706 struct bus_type exynos_subsys = {
707 .name = "exynos-core",
708 .dev_name = "exynos-core",
711 static struct device exynos4_dev = {
712 .bus = &exynos_subsys,
715 static int __init exynos_core_init(void)
717 return subsys_system_register(&exynos_subsys, NULL);
719 core_initcall(exynos_core_init);
721 #ifdef CONFIG_CACHE_L2X0
722 static int __init exynos4_l2x0_cache_init(void)
726 if (soc_is_exynos5250() || soc_is_exynos5440())
729 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
731 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
732 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
736 if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
737 l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
738 /* TAG, Data Latency Control: 2 cycles */
739 l2x0_saved_regs.tag_latency = 0x110;
741 if (soc_is_exynos4212() || soc_is_exynos4412())
742 l2x0_saved_regs.data_latency = 0x120;
744 l2x0_saved_regs.data_latency = 0x110;
746 l2x0_saved_regs.prefetch_ctrl = 0x30000007;
747 l2x0_saved_regs.pwr_ctrl =
748 (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
750 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
752 __raw_writel(l2x0_saved_regs.tag_latency,
753 S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
754 __raw_writel(l2x0_saved_regs.data_latency,
755 S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
757 /* L2X0 Prefetch Control */
758 __raw_writel(l2x0_saved_regs.prefetch_ctrl,
759 S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
761 /* L2X0 Power Control */
762 __raw_writel(l2x0_saved_regs.pwr_ctrl,
763 S5P_VA_L2CC + L2X0_POWER_CTRL);
765 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
766 clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
769 l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
772 early_initcall(exynos4_l2x0_cache_init);
775 static int __init exynos_init(void)
777 printk(KERN_INFO "EXYNOS: Initializing architecture\n");
779 return device_register(&exynos4_dev);
782 /* uart registration process */
784 static void __init exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no)
786 struct s3c2410_uartcfg *tcfg = cfg;
789 for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
790 tcfg->has_fracval = 1;
792 if (soc_is_exynos5250())
793 s3c24xx_init_uartdevs("exynos4210-uart", exynos5_uart_resources, cfg, no);
795 s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no);
798 static void __iomem *exynos_eint_base;
800 static DEFINE_SPINLOCK(eint_lock);
802 static unsigned int eint0_15_data[16];
804 static inline int exynos4_irq_to_gpio(unsigned int irq)
806 if (irq < IRQ_EINT(0))
811 return EXYNOS4_GPX0(irq);
815 return EXYNOS4_GPX1(irq);
819 return EXYNOS4_GPX2(irq);
823 return EXYNOS4_GPX3(irq);
828 static inline int exynos5_irq_to_gpio(unsigned int irq)
830 if (irq < IRQ_EINT(0))
835 return EXYNOS5_GPX0(irq);
839 return EXYNOS5_GPX1(irq);
843 return EXYNOS5_GPX2(irq);
847 return EXYNOS5_GPX3(irq);
852 static unsigned int exynos4_eint0_15_src_int[16] = {
871 static unsigned int exynos5_eint0_15_src_int[16] = {
889 static inline void exynos_irq_eint_mask(struct irq_data *data)
893 spin_lock(&eint_lock);
894 mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
895 mask |= EINT_OFFSET_BIT(data->irq);
896 __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
897 spin_unlock(&eint_lock);
900 static void exynos_irq_eint_unmask(struct irq_data *data)
904 spin_lock(&eint_lock);
905 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));
908 spin_unlock(&eint_lock);
911 static inline void exynos_irq_eint_ack(struct irq_data *data)
913 __raw_writel(EINT_OFFSET_BIT(data->irq),
914 EINT_PEND(exynos_eint_base, data->irq));
917 static void exynos_irq_eint_maskack(struct irq_data *data)
919 exynos_irq_eint_mask(data);
920 exynos_irq_eint_ack(data);
923 static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
925 int offs = EINT_OFFSET(data->irq);
931 case IRQ_TYPE_EDGE_RISING:
932 newvalue = S5P_IRQ_TYPE_EDGE_RISING;
935 case IRQ_TYPE_EDGE_FALLING:
936 newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
939 case IRQ_TYPE_EDGE_BOTH:
940 newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
943 case IRQ_TYPE_LEVEL_LOW:
944 newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
947 case IRQ_TYPE_LEVEL_HIGH:
948 newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
952 printk(KERN_ERR "No such irq type %d", type);
956 shift = (offs & 0x7) * 4;
959 spin_lock(&eint_lock);
960 ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
962 ctrl |= newvalue << shift;
963 __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
964 spin_unlock(&eint_lock);
966 if (soc_is_exynos5250())
967 s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
969 s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
974 static struct irq_chip exynos_irq_eint = {
975 .name = "exynos-eint",
976 .irq_mask = exynos_irq_eint_mask,
977 .irq_unmask = exynos_irq_eint_unmask,
978 .irq_mask_ack = exynos_irq_eint_maskack,
979 .irq_ack = exynos_irq_eint_ack,
980 .irq_set_type = exynos_irq_eint_set_type,
982 .irq_set_wake = s3c_irqext_wake,
987 * exynos4_irq_demux_eint
989 * This function demuxes the IRQ from from EINTs 16 to 31.
990 * It is designed to be inlined into the specific handler
991 * s5p_irq_demux_eintX_Y.
993 * Each EINT pend/mask registers handle eight of them.
995 static inline void exynos_irq_demux_eint(unsigned int start)
999 u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
1000 u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
1006 irq = fls(status) - 1;
1007 generic_handle_irq(irq + start);
1008 status &= ~(1 << irq);
1012 static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
1014 struct irq_chip *chip = irq_get_chip(irq);
1015 chained_irq_enter(chip, desc);
1016 exynos_irq_demux_eint(IRQ_EINT(16));
1017 exynos_irq_demux_eint(IRQ_EINT(24));
1018 chained_irq_exit(chip, desc);
1021 static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
1023 u32 *irq_data = irq_get_handler_data(irq);
1024 struct irq_chip *chip = irq_get_chip(irq);
1026 chained_irq_enter(chip, desc);
1027 chip->irq_mask(&desc->irq_data);
1030 chip->irq_ack(&desc->irq_data);
1032 generic_handle_irq(*irq_data);
1034 chip->irq_unmask(&desc->irq_data);
1035 chained_irq_exit(chip, desc);
1038 static int __init exynos_init_irq_eint(void)
1042 #ifdef CONFIG_PINCTRL_SAMSUNG
1044 * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
1045 * functionality along with support for external gpio and wakeup
1046 * interrupts. If the samsung pinctrl driver is enabled and includes
1047 * the wakeup interrupt support, then the setting up external wakeup
1048 * interrupts here can be skipped. This check here is temporary to
1049 * allow exynos4 platforms that do not use Samsung pinctrl driver to
1050 * co-exist with platforms that do. When all of the Samsung Exynos4
1051 * platforms switch over to using the pinctrl driver, the wakeup
1052 * interrupt support code here can be completely removed.
1054 struct device_node *pctrl_np, *wkup_np;
1055 const char *pctrl_compat = "samsung,pinctrl-exynos4210";
1056 const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
1058 for_each_compatible_node(pctrl_np, NULL, pctrl_compat) {
1059 if (of_device_is_available(pctrl_np)) {
1060 wkup_np = of_find_compatible_node(pctrl_np, NULL,
1067 if (soc_is_exynos5440())
1070 if (soc_is_exynos5250())
1071 exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
1073 exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
1075 if (exynos_eint_base == NULL) {
1076 pr_err("unable to ioremap for EINT base address\n");
1080 for (irq = 0 ; irq <= 31 ; irq++) {
1081 irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
1083 set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
1086 irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
1088 for (irq = 0 ; irq <= 15 ; irq++) {
1089 eint0_15_data[irq] = IRQ_EINT(irq);
1091 if (soc_is_exynos5250()) {
1092 irq_set_handler_data(exynos5_eint0_15_src_int[irq],
1093 &eint0_15_data[irq]);
1094 irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
1095 exynos_irq_eint0_15);
1097 irq_set_handler_data(exynos4_eint0_15_src_int[irq],
1098 &eint0_15_data[irq]);
1099 irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
1100 exynos_irq_eint0_15);
1106 arch_initcall(exynos_init_irq_eint);