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";
57 static struct cpu_table cpu_ids[] __initdata = {
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,
65 .name = name_exynos4210,
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,
73 .name = name_exynos4212,
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,
81 .name = name_exynos4412,
85 /* Initial IO mappings */
87 static struct map_desc exynos_iodesc[] __initdata = {
89 .virtual = (unsigned long)S5P_VA_CHIPID,
90 .pfn = __phys_to_pfn(EXYNOS4_PA_CHIPID),
94 .virtual = (unsigned long)S3C_VA_SYS,
95 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
99 .virtual = (unsigned long)S3C_VA_TIMER,
100 .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
104 .virtual = (unsigned long)S3C_VA_WATCHDOG,
105 .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
109 .virtual = (unsigned long)S5P_VA_SROMC,
110 .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
114 .virtual = (unsigned long)S5P_VA_SYSTIMER,
115 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
119 .virtual = (unsigned long)S5P_VA_PMU,
120 .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
124 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
125 .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
129 .virtual = (unsigned long)S5P_VA_GIC_CPU,
130 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
134 .virtual = (unsigned long)S5P_VA_GIC_DIST,
135 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
139 .virtual = (unsigned long)S3C_VA_UART,
140 .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
146 static struct map_desc exynos4_iodesc[] __initdata = {
148 .virtual = (unsigned long)S5P_VA_CMU,
149 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
153 .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
154 .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
158 .virtual = (unsigned long)S5P_VA_L2CC,
159 .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
163 .virtual = (unsigned long)S5P_VA_GPIO1,
164 .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO1),
168 .virtual = (unsigned long)S5P_VA_GPIO2,
169 .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO2),
173 .virtual = (unsigned long)S5P_VA_GPIO3,
174 .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO3),
178 .virtual = (unsigned long)S5P_VA_DMC0,
179 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
183 .virtual = (unsigned long)S5P_VA_DMC1,
184 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
188 .virtual = (unsigned long)S3C_VA_USB_HSPHY,
189 .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
195 static struct map_desc exynos4_iodesc0[] __initdata = {
197 .virtual = (unsigned long)S5P_VA_SYSRAM,
198 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
204 static struct map_desc exynos4_iodesc1[] __initdata = {
206 .virtual = (unsigned long)S5P_VA_SYSRAM,
207 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
213 void exynos4_restart(char mode, const char *cmd)
215 __raw_writel(0x1, S5P_SWRESET);
221 * register the standard cpu IO areas
224 void __init exynos_init_io(struct map_desc *mach_desc, int size)
226 /* initialize the io descriptors we need for initialization */
227 iotable_init(exynos_iodesc, ARRAY_SIZE(exynos_iodesc));
229 iotable_init(mach_desc, size);
231 /* detect cpu id and rev. */
232 s5p_init_cpu(S5P_VA_CHIPID);
234 s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
237 void __init exynos4_map_io(void)
239 iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
241 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
242 iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
244 iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
246 /* initialize device information early */
247 exynos4_default_sdhci0();
248 exynos4_default_sdhci1();
249 exynos4_default_sdhci2();
250 exynos4_default_sdhci3();
252 s3c_adc_setname("samsung-adc-v3");
254 s3c_fimc_setname(0, "exynos4-fimc");
255 s3c_fimc_setname(1, "exynos4-fimc");
256 s3c_fimc_setname(2, "exynos4-fimc");
257 s3c_fimc_setname(3, "exynos4-fimc");
259 /* The I2C bus controllers are directly compatible with s3c2440 */
260 s3c_i2c0_setname("s3c2440-i2c");
261 s3c_i2c1_setname("s3c2440-i2c");
262 s3c_i2c2_setname("s3c2440-i2c");
264 s5p_fb_setname(0, "exynos4-fb");
265 s5p_hdmi_setname("exynos4-hdmi");
268 void __init exynos4_init_clocks(int xtal)
270 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
272 s3c24xx_register_baseclocks(xtal);
273 s5p_register_clocks(xtal);
275 if (soc_is_exynos4210())
276 exynos4210_register_clocks();
277 else if (soc_is_exynos4212() || soc_is_exynos4412())
278 exynos4212_register_clocks();
280 exynos4_register_clocks();
281 exynos4_setup_clocks();
284 #define COMBINER_ENABLE_SET 0x0
285 #define COMBINER_ENABLE_CLEAR 0x4
286 #define COMBINER_INT_STATUS 0xC
288 static DEFINE_SPINLOCK(irq_controller_lock);
290 struct combiner_chip_data {
291 unsigned int irq_offset;
292 unsigned int irq_mask;
296 static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
298 static inline void __iomem *combiner_base(struct irq_data *data)
300 struct combiner_chip_data *combiner_data =
301 irq_data_get_irq_chip_data(data);
303 return combiner_data->base;
306 static void combiner_mask_irq(struct irq_data *data)
308 u32 mask = 1 << (data->irq % 32);
310 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
313 static void combiner_unmask_irq(struct irq_data *data)
315 u32 mask = 1 << (data->irq % 32);
317 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
320 static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
322 struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
323 struct irq_chip *chip = irq_get_chip(irq);
324 unsigned int cascade_irq, combiner_irq;
325 unsigned long status;
327 chained_irq_enter(chip, desc);
329 spin_lock(&irq_controller_lock);
330 status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
331 spin_unlock(&irq_controller_lock);
332 status &= chip_data->irq_mask;
337 combiner_irq = __ffs(status);
339 cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
340 if (unlikely(cascade_irq >= NR_IRQS))
341 do_bad_IRQ(cascade_irq, desc);
343 generic_handle_irq(cascade_irq);
346 chained_irq_exit(chip, desc);
349 static struct irq_chip combiner_chip = {
351 .irq_mask = combiner_mask_irq,
352 .irq_unmask = combiner_unmask_irq,
355 static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
357 if (combiner_nr >= MAX_COMBINER_NR)
359 if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
361 irq_set_chained_handler(irq, combiner_handle_cascade_irq);
364 static void __init combiner_init(unsigned int combiner_nr, void __iomem *base,
365 unsigned int irq_start)
369 if (combiner_nr >= MAX_COMBINER_NR)
372 combiner_data[combiner_nr].base = base;
373 combiner_data[combiner_nr].irq_offset = irq_start;
374 combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3);
376 /* Disable all interrupts */
378 __raw_writel(combiner_data[combiner_nr].irq_mask,
379 base + COMBINER_ENABLE_CLEAR);
381 /* Setup the Linux IRQ subsystem */
383 for (i = irq_start; i < combiner_data[combiner_nr].irq_offset
384 + MAX_IRQ_IN_COMBINER; i++) {
385 irq_set_chip_and_handler(i, &combiner_chip, handle_level_irq);
386 irq_set_chip_data(i, &combiner_data[combiner_nr]);
387 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
392 static const struct of_device_id exynos4_dt_irq_match[] = {
393 { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, },
398 void __init exynos4_init_irq(void)
401 unsigned int gic_bank_offset;
403 gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
405 if (!of_have_populated_dt())
406 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset);
409 of_irq_init(exynos4_dt_irq_match);
412 for (irq = 0; irq < MAX_COMBINER_NR; irq++) {
414 combiner_init(irq, (void __iomem *)S5P_VA_COMBINER(irq),
415 COMBINER_IRQ(irq, 0));
416 combiner_cascade_irq(irq, IRQ_SPI(irq));
420 * The parameters of s5p_init_irq() are for VIC init.
421 * Theses parameters should be NULL and 0 because EXYNOS4
422 * uses GIC instead of VIC.
424 s5p_init_irq(NULL, 0);
427 struct bus_type exynos4_subsys = {
428 .name = "exynos4-core",
429 .dev_name = "exynos4-core",
432 static struct device exynos4_dev = {
433 .bus = &exynos4_subsys,
436 static int __init exynos4_core_init(void)
438 return subsys_system_register(&exynos4_subsys, NULL);
440 core_initcall(exynos4_core_init);
442 #ifdef CONFIG_CACHE_L2X0
443 static int __init exynos4_l2x0_cache_init(void)
446 ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
448 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
449 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
453 if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
454 l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
455 /* TAG, Data Latency Control: 2 cycles */
456 l2x0_saved_regs.tag_latency = 0x110;
458 if (soc_is_exynos4212() || soc_is_exynos4412())
459 l2x0_saved_regs.data_latency = 0x120;
461 l2x0_saved_regs.data_latency = 0x110;
463 l2x0_saved_regs.prefetch_ctrl = 0x30000007;
464 l2x0_saved_regs.pwr_ctrl =
465 (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
467 l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
469 __raw_writel(l2x0_saved_regs.tag_latency,
470 S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
471 __raw_writel(l2x0_saved_regs.data_latency,
472 S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
474 /* L2X0 Prefetch Control */
475 __raw_writel(l2x0_saved_regs.prefetch_ctrl,
476 S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
478 /* L2X0 Power Control */
479 __raw_writel(l2x0_saved_regs.pwr_ctrl,
480 S5P_VA_L2CC + L2X0_POWER_CTRL);
482 clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
483 clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
486 l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
490 early_initcall(exynos4_l2x0_cache_init);
493 int __init exynos_init(void)
495 printk(KERN_INFO "EXYNOS: Initializing architecture\n");
496 return device_register(&exynos4_dev);
499 /* uart registration process */
501 void __init exynos4_init_uarts(struct s3c2410_uartcfg *cfg, int no)
503 struct s3c2410_uartcfg *tcfg = cfg;
506 for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
507 tcfg->has_fracval = 1;
509 s3c24xx_init_uartdevs("exynos4210-uart", s5p_uart_resources, cfg, no);
512 static DEFINE_SPINLOCK(eint_lock);
514 static unsigned int eint0_15_data[16];
516 static unsigned int exynos4_get_irq_nr(unsigned int number)
522 ret = (number + IRQ_EINT0);
525 ret = (number + (IRQ_EINT4 - 4));
528 ret = (number + (IRQ_EINT8 - 8));
531 printk(KERN_ERR "number available : %d\n", number);
537 static inline void exynos4_irq_eint_mask(struct irq_data *data)
541 spin_lock(&eint_lock);
542 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
543 mask |= eint_irq_to_bit(data->irq);
544 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
545 spin_unlock(&eint_lock);
548 static void exynos4_irq_eint_unmask(struct irq_data *data)
552 spin_lock(&eint_lock);
553 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
554 mask &= ~(eint_irq_to_bit(data->irq));
555 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
556 spin_unlock(&eint_lock);
559 static inline void exynos4_irq_eint_ack(struct irq_data *data)
561 __raw_writel(eint_irq_to_bit(data->irq),
562 S5P_EINT_PEND(EINT_REG_NR(data->irq)));
565 static void exynos4_irq_eint_maskack(struct irq_data *data)
567 exynos4_irq_eint_mask(data);
568 exynos4_irq_eint_ack(data);
571 static int exynos4_irq_eint_set_type(struct irq_data *data, unsigned int type)
573 int offs = EINT_OFFSET(data->irq);
579 case IRQ_TYPE_EDGE_RISING:
580 newvalue = S5P_IRQ_TYPE_EDGE_RISING;
583 case IRQ_TYPE_EDGE_FALLING:
584 newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
587 case IRQ_TYPE_EDGE_BOTH:
588 newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
591 case IRQ_TYPE_LEVEL_LOW:
592 newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
595 case IRQ_TYPE_LEVEL_HIGH:
596 newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
600 printk(KERN_ERR "No such irq type %d", type);
604 shift = (offs & 0x7) * 4;
607 spin_lock(&eint_lock);
608 ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq)));
610 ctrl |= newvalue << shift;
611 __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq)));
612 spin_unlock(&eint_lock);
616 s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
619 s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
622 s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
625 s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
628 printk(KERN_ERR "No such irq number %d", offs);
634 static struct irq_chip exynos4_irq_eint = {
635 .name = "exynos4-eint",
636 .irq_mask = exynos4_irq_eint_mask,
637 .irq_unmask = exynos4_irq_eint_unmask,
638 .irq_mask_ack = exynos4_irq_eint_maskack,
639 .irq_ack = exynos4_irq_eint_ack,
640 .irq_set_type = exynos4_irq_eint_set_type,
642 .irq_set_wake = s3c_irqext_wake,
647 * exynos4_irq_demux_eint
649 * This function demuxes the IRQ from from EINTs 16 to 31.
650 * It is designed to be inlined into the specific handler
651 * s5p_irq_demux_eintX_Y.
653 * Each EINT pend/mask registers handle eight of them.
655 static inline void exynos4_irq_demux_eint(unsigned int start)
659 u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
660 u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
666 irq = fls(status) - 1;
667 generic_handle_irq(irq + start);
668 status &= ~(1 << irq);
672 static void exynos4_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
674 struct irq_chip *chip = irq_get_chip(irq);
675 chained_irq_enter(chip, desc);
676 exynos4_irq_demux_eint(IRQ_EINT(16));
677 exynos4_irq_demux_eint(IRQ_EINT(24));
678 chained_irq_exit(chip, desc);
681 static void exynos4_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
683 u32 *irq_data = irq_get_handler_data(irq);
684 struct irq_chip *chip = irq_get_chip(irq);
686 chained_irq_enter(chip, desc);
687 chip->irq_mask(&desc->irq_data);
690 chip->irq_ack(&desc->irq_data);
692 generic_handle_irq(*irq_data);
694 chip->irq_unmask(&desc->irq_data);
695 chained_irq_exit(chip, desc);
698 int __init exynos4_init_irq_eint(void)
702 for (irq = 0 ; irq <= 31 ; irq++) {
703 irq_set_chip_and_handler(IRQ_EINT(irq), &exynos4_irq_eint,
705 set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
708 irq_set_chained_handler(IRQ_EINT16_31, exynos4_irq_demux_eint16_31);
710 for (irq = 0 ; irq <= 15 ; irq++) {
711 eint0_15_data[irq] = IRQ_EINT(irq);
713 irq_set_handler_data(exynos4_get_irq_nr(irq),
714 &eint0_15_data[irq]);
715 irq_set_chained_handler(exynos4_get_irq_nr(irq),
716 exynos4_irq_eint0_15);
721 arch_initcall(exynos4_init_irq_eint);