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>
15 #include <linux/irqchip.h>
17 #include <linux/device.h>
18 #include <linux/gpio.h>
19 #include <linux/sched.h>
20 #include <linux/serial_core.h>
22 #include <linux/of_fdt.h>
23 #include <linux/of_irq.h>
24 #include <linux/export.h>
25 #include <linux/irqdomain.h>
26 #include <linux/irqchip.h>
27 #include <linux/of_address.h>
28 #include <linux/clocksource.h>
29 #include <linux/clk-provider.h>
30 #include <linux/irqchip/arm-gic.h>
32 #include <asm/proc-fns.h>
33 #include <asm/exception.h>
34 #include <asm/hardware/cache-l2x0.h>
35 #include <asm/mach/map.h>
36 #include <asm/mach/irq.h>
37 #include <asm/cacheflush.h>
39 #include <mach/regs-irq.h>
40 #include <mach/regs-pmu.h>
41 #include <mach/regs-gpio.h>
44 #include <plat/devs.h>
46 #include <plat/sdhci.h>
47 #include <plat/gpio-cfg.h>
48 #include <plat/adc-core.h>
49 #include <plat/fb-core.h>
50 #include <plat/fimc-core.h>
51 #include <plat/iic-core.h>
52 #include <plat/tv-core.h>
53 #include <plat/spi-core.h>
54 #include <plat/regs-serial.h>
57 #define L2_AUX_VAL 0x7C470001
58 #define L2_AUX_MASK 0xC200ffff
60 static const char name_exynos4210[] = "EXYNOS4210";
61 static const char name_exynos4212[] = "EXYNOS4212";
62 static const char name_exynos4412[] = "EXYNOS4412";
63 static const char name_exynos5250[] = "EXYNOS5250";
64 static const char name_exynos5440[] = "EXYNOS5440";
66 static void exynos4_map_io(void);
67 static void exynos5_map_io(void);
68 static void exynos5440_map_io(void);
69 static void exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no);
70 static int exynos_init(void);
72 static struct cpu_table cpu_ids[] __initdata = {
74 .idcode = EXYNOS4210_CPU_ID,
75 .idmask = EXYNOS4_CPU_MASK,
76 .map_io = exynos4_map_io,
77 .init_uarts = exynos4_init_uarts,
79 .name = name_exynos4210,
81 .idcode = EXYNOS4212_CPU_ID,
82 .idmask = EXYNOS4_CPU_MASK,
83 .map_io = exynos4_map_io,
84 .init_uarts = exynos4_init_uarts,
86 .name = name_exynos4212,
88 .idcode = EXYNOS4412_CPU_ID,
89 .idmask = EXYNOS4_CPU_MASK,
90 .map_io = exynos4_map_io,
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,
99 .name = name_exynos5250,
101 .idcode = EXYNOS5440_SOC_ID,
102 .idmask = EXYNOS5_SOC_MASK,
103 .map_io = exynos5440_map_io,
105 .name = name_exynos5440,
109 /* Initial IO mappings */
111 static struct map_desc exynos_iodesc[] __initdata = {
113 .virtual = (unsigned long)S5P_VA_CHIPID,
114 .pfn = __phys_to_pfn(EXYNOS_PA_CHIPID),
120 #ifdef CONFIG_ARCH_EXYNOS5
121 static struct map_desc exynos5440_iodesc[] __initdata = {
123 .virtual = (unsigned long)S5P_VA_CHIPID,
124 .pfn = __phys_to_pfn(EXYNOS5440_PA_CHIPID),
131 static struct map_desc exynos4_iodesc[] __initdata = {
133 .virtual = (unsigned long)S3C_VA_SYS,
134 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
138 .virtual = (unsigned long)S3C_VA_TIMER,
139 .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
143 .virtual = (unsigned long)S3C_VA_WATCHDOG,
144 .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
148 .virtual = (unsigned long)S5P_VA_SROMC,
149 .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
153 .virtual = (unsigned long)S5P_VA_SYSTIMER,
154 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
158 .virtual = (unsigned long)S5P_VA_PMU,
159 .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
163 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
164 .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
168 .virtual = (unsigned long)S5P_VA_GIC_CPU,
169 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
173 .virtual = (unsigned long)S5P_VA_GIC_DIST,
174 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
178 .virtual = (unsigned long)S3C_VA_UART,
179 .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
183 .virtual = (unsigned long)S5P_VA_CMU,
184 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
188 .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
189 .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
193 .virtual = (unsigned long)S5P_VA_L2CC,
194 .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
198 .virtual = (unsigned long)S5P_VA_DMC0,
199 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
203 .virtual = (unsigned long)S5P_VA_DMC1,
204 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
208 .virtual = (unsigned long)S3C_VA_USB_HSPHY,
209 .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
215 static struct map_desc exynos4_iodesc0[] __initdata = {
217 .virtual = (unsigned long)S5P_VA_SYSRAM,
218 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
224 static struct map_desc exynos4_iodesc1[] __initdata = {
226 .virtual = (unsigned long)S5P_VA_SYSRAM,
227 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
233 static struct map_desc exynos5_iodesc[] __initdata = {
235 .virtual = (unsigned long)S3C_VA_SYS,
236 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
240 .virtual = (unsigned long)S3C_VA_TIMER,
241 .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
245 .virtual = (unsigned long)S3C_VA_WATCHDOG,
246 .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
250 .virtual = (unsigned long)S5P_VA_SROMC,
251 .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
255 .virtual = (unsigned long)S5P_VA_SYSRAM,
256 .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
260 .virtual = (unsigned long)S5P_VA_CMU,
261 .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
262 .length = 144 * SZ_1K,
265 .virtual = (unsigned long)S5P_VA_PMU,
266 .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
270 .virtual = (unsigned long)S3C_VA_UART,
271 .pfn = __phys_to_pfn(EXYNOS5_PA_UART),
277 static struct map_desc exynos5440_iodesc0[] __initdata = {
279 .virtual = (unsigned long)S3C_VA_UART,
280 .pfn = __phys_to_pfn(EXYNOS5440_PA_UART0),
286 void exynos4_restart(char mode, const char *cmd)
288 __raw_writel(0x1, S5P_SWRESET);
291 void exynos5_restart(char mode, const char *cmd)
293 struct device_node *np;
297 if (of_machine_is_compatible("samsung,exynos5250")) {
299 addr = EXYNOS_SWRESET;
300 } else if (of_machine_is_compatible("samsung,exynos5440")) {
301 np = of_find_compatible_node(NULL, NULL, "samsung,exynos5440-clock");
302 addr = of_iomap(np, 0) + 0xcc;
303 val = (0xfff << 20) | (0x1 << 16);
305 pr_err("%s: cannot support non-DT\n", __func__);
309 __raw_writel(val, addr);
312 void __init exynos_init_late(void)
314 if (of_machine_is_compatible("samsung,exynos5440"))
315 /* to be supported later */
318 exynos_pm_late_initcall();
324 * register the standard cpu IO areas
327 void __init exynos_init_io(struct map_desc *mach_desc, int size)
329 struct map_desc *iodesc = exynos_iodesc;
330 int iodesc_sz = ARRAY_SIZE(exynos_iodesc);
331 #if defined(CONFIG_OF) && defined(CONFIG_ARCH_EXYNOS5)
332 unsigned long root = of_get_flat_dt_root();
334 /* initialize the io descriptors we need for initialization */
335 if (of_flat_dt_is_compatible(root, "samsung,exynos5440")) {
336 iodesc = exynos5440_iodesc;
337 iodesc_sz = ARRAY_SIZE(exynos5440_iodesc);
341 iotable_init(iodesc, iodesc_sz);
344 iotable_init(mach_desc, size);
346 /* detect cpu id and rev. */
347 s5p_init_cpu(S5P_VA_CHIPID);
349 s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
352 static void __init exynos4_map_io(void)
354 iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
356 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
357 iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
359 iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
361 /* initialize device information early */
362 exynos4_default_sdhci0();
363 exynos4_default_sdhci1();
364 exynos4_default_sdhci2();
365 exynos4_default_sdhci3();
367 s3c_adc_setname("samsung-adc-v3");
369 s3c_fimc_setname(0, "exynos4-fimc");
370 s3c_fimc_setname(1, "exynos4-fimc");
371 s3c_fimc_setname(2, "exynos4-fimc");
372 s3c_fimc_setname(3, "exynos4-fimc");
374 s3c_sdhci_setname(0, "exynos4-sdhci");
375 s3c_sdhci_setname(1, "exynos4-sdhci");
376 s3c_sdhci_setname(2, "exynos4-sdhci");
377 s3c_sdhci_setname(3, "exynos4-sdhci");
379 /* The I2C bus controllers are directly compatible with s3c2440 */
380 s3c_i2c0_setname("s3c2440-i2c");
381 s3c_i2c1_setname("s3c2440-i2c");
382 s3c_i2c2_setname("s3c2440-i2c");
384 s5p_fb_setname(0, "exynos4-fb");
385 s5p_hdmi_setname("exynos4-hdmi");
387 s3c64xx_spi_setname("exynos4210-spi");
390 static void __init exynos5_map_io(void)
392 iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
395 static void __init exynos5440_map_io(void)
397 iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
400 void __init exynos_init_time(void)
402 if (of_have_populated_dt()) {
405 clocksource_of_init();
408 /* todo: remove after migrating legacy E4 platforms to dt */
409 exynos4_clk_init(NULL);
414 void __init exynos4_init_irq(void)
416 unsigned int gic_bank_offset;
418 gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
420 if (!of_have_populated_dt())
421 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
427 if (!of_have_populated_dt())
428 combiner_init(S5P_VA_COMBINER_BASE, NULL);
431 * The parameters of s5p_init_irq() are for VIC init.
432 * Theses parameters should be NULL and 0 because EXYNOS4
433 * uses GIC instead of VIC.
435 s5p_init_irq(NULL, 0);
438 void __init exynos5_init_irq(void)
444 * The parameters of s5p_init_irq() are for VIC init.
445 * Theses parameters should be NULL and 0 because EXYNOS4
446 * uses GIC instead of VIC.
448 if (!of_machine_is_compatible("samsung,exynos5440"))
449 s5p_init_irq(NULL, 0);
451 gic_arch_extn.irq_set_wake = s3c_irq_wake;
454 struct bus_type exynos_subsys = {
455 .name = "exynos-core",
456 .dev_name = "exynos-core",
459 static struct device exynos4_dev = {
460 .bus = &exynos_subsys,
463 static int __init exynos_core_init(void)
465 return subsys_system_register(&exynos_subsys, NULL);
467 core_initcall(exynos_core_init);
469 #ifdef CONFIG_CACHE_L2X0
470 static int __init exynos4_l2x0_cache_init(void)
474 if (soc_is_exynos5250() || soc_is_exynos5440())
477 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
479 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
480 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
484 if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
485 l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
486 /* TAG, Data Latency Control: 2 cycles */
487 l2x0_saved_regs.tag_latency = 0x110;
489 if (soc_is_exynos4212() || soc_is_exynos4412())
490 l2x0_saved_regs.data_latency = 0x120;
492 l2x0_saved_regs.data_latency = 0x110;
494 l2x0_saved_regs.prefetch_ctrl = 0x30000007;
495 l2x0_saved_regs.pwr_ctrl =
496 (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
498 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
500 __raw_writel(l2x0_saved_regs.tag_latency,
501 S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
502 __raw_writel(l2x0_saved_regs.data_latency,
503 S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
505 /* L2X0 Prefetch Control */
506 __raw_writel(l2x0_saved_regs.prefetch_ctrl,
507 S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
509 /* L2X0 Power Control */
510 __raw_writel(l2x0_saved_regs.pwr_ctrl,
511 S5P_VA_L2CC + L2X0_POWER_CTRL);
513 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
514 clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
517 l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
520 early_initcall(exynos4_l2x0_cache_init);
523 static int __init exynos_init(void)
525 printk(KERN_INFO "EXYNOS: Initializing architecture\n");
527 return device_register(&exynos4_dev);
530 /* uart registration process */
532 static void __init exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no)
534 struct s3c2410_uartcfg *tcfg = cfg;
537 for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
538 tcfg->has_fracval = 1;
540 s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no);
543 static void __iomem *exynos_eint_base;
545 static DEFINE_SPINLOCK(eint_lock);
547 static unsigned int eint0_15_data[16];
549 static inline int exynos4_irq_to_gpio(unsigned int irq)
551 if (irq < IRQ_EINT(0))
556 return EXYNOS4_GPX0(irq);
560 return EXYNOS4_GPX1(irq);
564 return EXYNOS4_GPX2(irq);
568 return EXYNOS4_GPX3(irq);
573 static inline int exynos5_irq_to_gpio(unsigned int irq)
575 if (irq < IRQ_EINT(0))
580 return EXYNOS5_GPX0(irq);
584 return EXYNOS5_GPX1(irq);
588 return EXYNOS5_GPX2(irq);
592 return EXYNOS5_GPX3(irq);
597 static unsigned int exynos4_eint0_15_src_int[16] = {
616 static unsigned int exynos5_eint0_15_src_int[16] = {
634 static inline void exynos_irq_eint_mask(struct irq_data *data)
638 spin_lock(&eint_lock);
639 mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
640 mask |= EINT_OFFSET_BIT(data->irq);
641 __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
642 spin_unlock(&eint_lock);
645 static void exynos_irq_eint_unmask(struct irq_data *data)
649 spin_lock(&eint_lock);
650 mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
651 mask &= ~(EINT_OFFSET_BIT(data->irq));
652 __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
653 spin_unlock(&eint_lock);
656 static inline void exynos_irq_eint_ack(struct irq_data *data)
658 __raw_writel(EINT_OFFSET_BIT(data->irq),
659 EINT_PEND(exynos_eint_base, data->irq));
662 static void exynos_irq_eint_maskack(struct irq_data *data)
664 exynos_irq_eint_mask(data);
665 exynos_irq_eint_ack(data);
668 static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
670 int offs = EINT_OFFSET(data->irq);
676 case IRQ_TYPE_EDGE_RISING:
677 newvalue = S5P_IRQ_TYPE_EDGE_RISING;
680 case IRQ_TYPE_EDGE_FALLING:
681 newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
684 case IRQ_TYPE_EDGE_BOTH:
685 newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
688 case IRQ_TYPE_LEVEL_LOW:
689 newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
692 case IRQ_TYPE_LEVEL_HIGH:
693 newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
697 printk(KERN_ERR "No such irq type %d", type);
701 shift = (offs & 0x7) * 4;
704 spin_lock(&eint_lock);
705 ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
707 ctrl |= newvalue << shift;
708 __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
709 spin_unlock(&eint_lock);
711 if (soc_is_exynos5250())
712 s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
714 s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
719 static struct irq_chip exynos_irq_eint = {
720 .name = "exynos-eint",
721 .irq_mask = exynos_irq_eint_mask,
722 .irq_unmask = exynos_irq_eint_unmask,
723 .irq_mask_ack = exynos_irq_eint_maskack,
724 .irq_ack = exynos_irq_eint_ack,
725 .irq_set_type = exynos_irq_eint_set_type,
727 .irq_set_wake = s3c_irqext_wake,
732 * exynos4_irq_demux_eint
734 * This function demuxes the IRQ from from EINTs 16 to 31.
735 * It is designed to be inlined into the specific handler
736 * s5p_irq_demux_eintX_Y.
738 * Each EINT pend/mask registers handle eight of them.
740 static inline void exynos_irq_demux_eint(unsigned int start)
744 u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
745 u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
751 irq = fls(status) - 1;
752 generic_handle_irq(irq + start);
753 status &= ~(1 << irq);
757 static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
759 struct irq_chip *chip = irq_get_chip(irq);
760 chained_irq_enter(chip, desc);
761 exynos_irq_demux_eint(IRQ_EINT(16));
762 exynos_irq_demux_eint(IRQ_EINT(24));
763 chained_irq_exit(chip, desc);
766 static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
768 u32 *irq_data = irq_get_handler_data(irq);
769 struct irq_chip *chip = irq_get_chip(irq);
771 chained_irq_enter(chip, desc);
772 generic_handle_irq(*irq_data);
773 chained_irq_exit(chip, desc);
776 static int __init exynos_init_irq_eint(void)
780 #ifdef CONFIG_PINCTRL_SAMSUNG
782 * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
783 * functionality along with support for external gpio and wakeup
784 * interrupts. If the samsung pinctrl driver is enabled and includes
785 * the wakeup interrupt support, then the setting up external wakeup
786 * interrupts here can be skipped. This check here is temporary to
787 * allow exynos4 platforms that do not use Samsung pinctrl driver to
788 * co-exist with platforms that do. When all of the Samsung Exynos4
789 * platforms switch over to using the pinctrl driver, the wakeup
790 * interrupt support code here can be completely removed.
792 static const struct of_device_id exynos_pinctrl_ids[] = {
793 { .compatible = "samsung,exynos4210-pinctrl", },
794 { .compatible = "samsung,exynos4x12-pinctrl", },
796 struct device_node *pctrl_np, *wkup_np;
797 const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
799 for_each_matching_node(pctrl_np, exynos_pinctrl_ids) {
800 if (of_device_is_available(pctrl_np)) {
801 wkup_np = of_find_compatible_node(pctrl_np, NULL,
808 if (soc_is_exynos5440())
811 if (soc_is_exynos5250())
812 exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
814 exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
816 if (exynos_eint_base == NULL) {
817 pr_err("unable to ioremap for EINT base address\n");
821 for (irq = 0 ; irq <= 31 ; irq++) {
822 irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
824 set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
827 irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
829 for (irq = 0 ; irq <= 15 ; irq++) {
830 eint0_15_data[irq] = IRQ_EINT(irq);
832 if (soc_is_exynos5250()) {
833 irq_set_handler_data(exynos5_eint0_15_src_int[irq],
834 &eint0_15_data[irq]);
835 irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
836 exynos_irq_eint0_15);
838 irq_set_handler_data(exynos4_eint0_15_src_int[irq],
839 &eint0_15_data[irq]);
840 irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
841 exynos_irq_eint0_15);
847 arch_initcall(exynos_init_irq_eint);