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 static void exynos_idle(void)
221 void exynos4_restart(char mode
, const char *cmd
)
223 __raw_writel(0x1, S5P_SWRESET
);
229 * register the standard cpu IO areas
232 void __init
exynos_init_io(struct map_desc
*mach_desc
, int size
)
234 /* initialize the io descriptors we need for initialization */
235 iotable_init(exynos_iodesc
, ARRAY_SIZE(exynos_iodesc
));
237 iotable_init(mach_desc
, size
);
239 /* detect cpu id and rev. */
240 s5p_init_cpu(S5P_VA_CHIPID
);
242 s3c_init_cpu(samsung_cpu_id
, cpu_ids
, ARRAY_SIZE(cpu_ids
));
245 void __init
exynos4_map_io(void)
247 iotable_init(exynos4_iodesc
, ARRAY_SIZE(exynos4_iodesc
));
249 if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0
)
250 iotable_init(exynos4_iodesc0
, ARRAY_SIZE(exynos4_iodesc0
));
252 iotable_init(exynos4_iodesc1
, ARRAY_SIZE(exynos4_iodesc1
));
254 /* initialize device information early */
255 exynos4_default_sdhci0();
256 exynos4_default_sdhci1();
257 exynos4_default_sdhci2();
258 exynos4_default_sdhci3();
260 s3c_adc_setname("samsung-adc-v3");
262 s3c_fimc_setname(0, "exynos4-fimc");
263 s3c_fimc_setname(1, "exynos4-fimc");
264 s3c_fimc_setname(2, "exynos4-fimc");
265 s3c_fimc_setname(3, "exynos4-fimc");
267 /* The I2C bus controllers are directly compatible with s3c2440 */
268 s3c_i2c0_setname("s3c2440-i2c");
269 s3c_i2c1_setname("s3c2440-i2c");
270 s3c_i2c2_setname("s3c2440-i2c");
272 s5p_fb_setname(0, "exynos4-fb");
273 s5p_hdmi_setname("exynos4-hdmi");
276 void __init
exynos4_init_clocks(int xtal
)
278 printk(KERN_DEBUG
"%s: initializing clocks\n", __func__
);
280 s3c24xx_register_baseclocks(xtal
);
281 s5p_register_clocks(xtal
);
283 if (soc_is_exynos4210())
284 exynos4210_register_clocks();
285 else if (soc_is_exynos4212() || soc_is_exynos4412())
286 exynos4212_register_clocks();
288 exynos4_register_clocks();
289 exynos4_setup_clocks();
292 #define COMBINER_ENABLE_SET 0x0
293 #define COMBINER_ENABLE_CLEAR 0x4
294 #define COMBINER_INT_STATUS 0xC
296 static DEFINE_SPINLOCK(irq_controller_lock
);
298 struct combiner_chip_data
{
299 unsigned int irq_offset
;
300 unsigned int irq_mask
;
304 static struct combiner_chip_data combiner_data
[MAX_COMBINER_NR
];
306 static inline void __iomem
*combiner_base(struct irq_data
*data
)
308 struct combiner_chip_data
*combiner_data
=
309 irq_data_get_irq_chip_data(data
);
311 return combiner_data
->base
;
314 static void combiner_mask_irq(struct irq_data
*data
)
316 u32 mask
= 1 << (data
->irq
% 32);
318 __raw_writel(mask
, combiner_base(data
) + COMBINER_ENABLE_CLEAR
);
321 static void combiner_unmask_irq(struct irq_data
*data
)
323 u32 mask
= 1 << (data
->irq
% 32);
325 __raw_writel(mask
, combiner_base(data
) + COMBINER_ENABLE_SET
);
328 static void combiner_handle_cascade_irq(unsigned int irq
, struct irq_desc
*desc
)
330 struct combiner_chip_data
*chip_data
= irq_get_handler_data(irq
);
331 struct irq_chip
*chip
= irq_get_chip(irq
);
332 unsigned int cascade_irq
, combiner_irq
;
333 unsigned long status
;
335 chained_irq_enter(chip
, desc
);
337 spin_lock(&irq_controller_lock
);
338 status
= __raw_readl(chip_data
->base
+ COMBINER_INT_STATUS
);
339 spin_unlock(&irq_controller_lock
);
340 status
&= chip_data
->irq_mask
;
345 combiner_irq
= __ffs(status
);
347 cascade_irq
= combiner_irq
+ (chip_data
->irq_offset
& ~31);
348 if (unlikely(cascade_irq
>= NR_IRQS
))
349 do_bad_IRQ(cascade_irq
, desc
);
351 generic_handle_irq(cascade_irq
);
354 chained_irq_exit(chip
, desc
);
357 static struct irq_chip combiner_chip
= {
359 .irq_mask
= combiner_mask_irq
,
360 .irq_unmask
= combiner_unmask_irq
,
363 static void __init
combiner_cascade_irq(unsigned int combiner_nr
, unsigned int irq
)
365 if (combiner_nr
>= MAX_COMBINER_NR
)
367 if (irq_set_handler_data(irq
, &combiner_data
[combiner_nr
]) != 0)
369 irq_set_chained_handler(irq
, combiner_handle_cascade_irq
);
372 static void __init
combiner_init(unsigned int combiner_nr
, void __iomem
*base
,
373 unsigned int irq_start
)
377 if (combiner_nr
>= MAX_COMBINER_NR
)
380 combiner_data
[combiner_nr
].base
= base
;
381 combiner_data
[combiner_nr
].irq_offset
= irq_start
;
382 combiner_data
[combiner_nr
].irq_mask
= 0xff << ((combiner_nr
% 4) << 3);
384 /* Disable all interrupts */
386 __raw_writel(combiner_data
[combiner_nr
].irq_mask
,
387 base
+ COMBINER_ENABLE_CLEAR
);
389 /* Setup the Linux IRQ subsystem */
391 for (i
= irq_start
; i
< combiner_data
[combiner_nr
].irq_offset
392 + MAX_IRQ_IN_COMBINER
; i
++) {
393 irq_set_chip_and_handler(i
, &combiner_chip
, handle_level_irq
);
394 irq_set_chip_data(i
, &combiner_data
[combiner_nr
]);
395 set_irq_flags(i
, IRQF_VALID
| IRQF_PROBE
);
400 static const struct of_device_id exynos4_dt_irq_match
[] = {
401 { .compatible
= "arm,cortex-a9-gic", .data
= gic_of_init
, },
406 void __init
exynos4_init_irq(void)
409 unsigned int gic_bank_offset
;
411 gic_bank_offset
= soc_is_exynos4412() ? 0x4000 : 0x8000;
413 if (!of_have_populated_dt())
414 gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST
, S5P_VA_GIC_CPU
, gic_bank_offset
);
417 of_irq_init(exynos4_dt_irq_match
);
420 for (irq
= 0; irq
< MAX_COMBINER_NR
; irq
++) {
422 combiner_init(irq
, (void __iomem
*)S5P_VA_COMBINER(irq
),
423 COMBINER_IRQ(irq
, 0));
424 combiner_cascade_irq(irq
, IRQ_SPI(irq
));
428 * The parameters of s5p_init_irq() are for VIC init.
429 * Theses parameters should be NULL and 0 because EXYNOS4
430 * uses GIC instead of VIC.
432 s5p_init_irq(NULL
, 0);
435 struct bus_type exynos4_subsys
= {
436 .name
= "exynos4-core",
437 .dev_name
= "exynos4-core",
440 static struct device exynos4_dev
= {
441 .bus
= &exynos4_subsys
,
444 static int __init
exynos4_core_init(void)
446 return subsys_system_register(&exynos4_subsys
, NULL
);
448 core_initcall(exynos4_core_init
);
450 #ifdef CONFIG_CACHE_L2X0
451 static int __init
exynos4_l2x0_cache_init(void)
454 ret
= l2x0_of_init(L2_AUX_VAL
, L2_AUX_MASK
);
456 l2x0_regs_phys
= virt_to_phys(&l2x0_saved_regs
);
457 clean_dcache_area(&l2x0_regs_phys
, sizeof(unsigned long));
461 if (!(__raw_readl(S5P_VA_L2CC
+ L2X0_CTRL
) & 0x1)) {
462 l2x0_saved_regs
.phy_base
= EXYNOS4_PA_L2CC
;
463 /* TAG, Data Latency Control: 2 cycles */
464 l2x0_saved_regs
.tag_latency
= 0x110;
466 if (soc_is_exynos4212() || soc_is_exynos4412())
467 l2x0_saved_regs
.data_latency
= 0x120;
469 l2x0_saved_regs
.data_latency
= 0x110;
471 l2x0_saved_regs
.prefetch_ctrl
= 0x30000007;
472 l2x0_saved_regs
.pwr_ctrl
=
473 (L2X0_DYNAMIC_CLK_GATING_EN
| L2X0_STNDBY_MODE_EN
);
475 l2x0_regs_phys
= virt_to_phys(&l2x0_saved_regs
);
477 __raw_writel(l2x0_saved_regs
.tag_latency
,
478 S5P_VA_L2CC
+ L2X0_TAG_LATENCY_CTRL
);
479 __raw_writel(l2x0_saved_regs
.data_latency
,
480 S5P_VA_L2CC
+ L2X0_DATA_LATENCY_CTRL
);
482 /* L2X0 Prefetch Control */
483 __raw_writel(l2x0_saved_regs
.prefetch_ctrl
,
484 S5P_VA_L2CC
+ L2X0_PREFETCH_CTRL
);
486 /* L2X0 Power Control */
487 __raw_writel(l2x0_saved_regs
.pwr_ctrl
,
488 S5P_VA_L2CC
+ L2X0_POWER_CTRL
);
490 clean_dcache_area(&l2x0_regs_phys
, sizeof(unsigned long));
491 clean_dcache_area(&l2x0_saved_regs
, sizeof(struct l2x0_regs
));
494 l2x0_init(S5P_VA_L2CC
, L2_AUX_VAL
, L2_AUX_MASK
);
498 early_initcall(exynos4_l2x0_cache_init
);
501 int __init
exynos_init(void)
503 printk(KERN_INFO
"EXYNOS: Initializing architecture\n");
505 /* set idle function */
506 pm_idle
= exynos_idle
;
508 return device_register(&exynos4_dev
);
511 /* uart registration process */
513 void __init
exynos4_init_uarts(struct s3c2410_uartcfg
*cfg
, int no
)
515 struct s3c2410_uartcfg
*tcfg
= cfg
;
518 for (ucnt
= 0; ucnt
< no
; ucnt
++, tcfg
++)
519 tcfg
->has_fracval
= 1;
521 s3c24xx_init_uartdevs("exynos4210-uart", s5p_uart_resources
, cfg
, no
);
524 static DEFINE_SPINLOCK(eint_lock
);
526 static unsigned int eint0_15_data
[16];
528 static unsigned int exynos4_get_irq_nr(unsigned int number
)
534 ret
= (number
+ IRQ_EINT0
);
537 ret
= (number
+ (IRQ_EINT4
- 4));
540 ret
= (number
+ (IRQ_EINT8
- 8));
543 printk(KERN_ERR
"number available : %d\n", number
);
549 static inline void exynos4_irq_eint_mask(struct irq_data
*data
)
553 spin_lock(&eint_lock
);
554 mask
= __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data
->irq
)));
555 mask
|= eint_irq_to_bit(data
->irq
);
556 __raw_writel(mask
, S5P_EINT_MASK(EINT_REG_NR(data
->irq
)));
557 spin_unlock(&eint_lock
);
560 static void exynos4_irq_eint_unmask(struct irq_data
*data
)
564 spin_lock(&eint_lock
);
565 mask
= __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data
->irq
)));
566 mask
&= ~(eint_irq_to_bit(data
->irq
));
567 __raw_writel(mask
, S5P_EINT_MASK(EINT_REG_NR(data
->irq
)));
568 spin_unlock(&eint_lock
);
571 static inline void exynos4_irq_eint_ack(struct irq_data
*data
)
573 __raw_writel(eint_irq_to_bit(data
->irq
),
574 S5P_EINT_PEND(EINT_REG_NR(data
->irq
)));
577 static void exynos4_irq_eint_maskack(struct irq_data
*data
)
579 exynos4_irq_eint_mask(data
);
580 exynos4_irq_eint_ack(data
);
583 static int exynos4_irq_eint_set_type(struct irq_data
*data
, unsigned int type
)
585 int offs
= EINT_OFFSET(data
->irq
);
591 case IRQ_TYPE_EDGE_RISING
:
592 newvalue
= S5P_IRQ_TYPE_EDGE_RISING
;
595 case IRQ_TYPE_EDGE_FALLING
:
596 newvalue
= S5P_IRQ_TYPE_EDGE_FALLING
;
599 case IRQ_TYPE_EDGE_BOTH
:
600 newvalue
= S5P_IRQ_TYPE_EDGE_BOTH
;
603 case IRQ_TYPE_LEVEL_LOW
:
604 newvalue
= S5P_IRQ_TYPE_LEVEL_LOW
;
607 case IRQ_TYPE_LEVEL_HIGH
:
608 newvalue
= S5P_IRQ_TYPE_LEVEL_HIGH
;
612 printk(KERN_ERR
"No such irq type %d", type
);
616 shift
= (offs
& 0x7) * 4;
619 spin_lock(&eint_lock
);
620 ctrl
= __raw_readl(S5P_EINT_CON(EINT_REG_NR(data
->irq
)));
622 ctrl
|= newvalue
<< shift
;
623 __raw_writel(ctrl
, S5P_EINT_CON(EINT_REG_NR(data
->irq
)));
624 spin_unlock(&eint_lock
);
628 s3c_gpio_cfgpin(EINT_GPIO_0(offs
& 0x7), EINT_MODE
);
631 s3c_gpio_cfgpin(EINT_GPIO_1(offs
& 0x7), EINT_MODE
);
634 s3c_gpio_cfgpin(EINT_GPIO_2(offs
& 0x7), EINT_MODE
);
637 s3c_gpio_cfgpin(EINT_GPIO_3(offs
& 0x7), EINT_MODE
);
640 printk(KERN_ERR
"No such irq number %d", offs
);
646 static struct irq_chip exynos4_irq_eint
= {
647 .name
= "exynos4-eint",
648 .irq_mask
= exynos4_irq_eint_mask
,
649 .irq_unmask
= exynos4_irq_eint_unmask
,
650 .irq_mask_ack
= exynos4_irq_eint_maskack
,
651 .irq_ack
= exynos4_irq_eint_ack
,
652 .irq_set_type
= exynos4_irq_eint_set_type
,
654 .irq_set_wake
= s3c_irqext_wake
,
659 * exynos4_irq_demux_eint
661 * This function demuxes the IRQ from from EINTs 16 to 31.
662 * It is designed to be inlined into the specific handler
663 * s5p_irq_demux_eintX_Y.
665 * Each EINT pend/mask registers handle eight of them.
667 static inline void exynos4_irq_demux_eint(unsigned int start
)
671 u32 status
= __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start
)));
672 u32 mask
= __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start
)));
678 irq
= fls(status
) - 1;
679 generic_handle_irq(irq
+ start
);
680 status
&= ~(1 << irq
);
684 static void exynos4_irq_demux_eint16_31(unsigned int irq
, struct irq_desc
*desc
)
686 struct irq_chip
*chip
= irq_get_chip(irq
);
687 chained_irq_enter(chip
, desc
);
688 exynos4_irq_demux_eint(IRQ_EINT(16));
689 exynos4_irq_demux_eint(IRQ_EINT(24));
690 chained_irq_exit(chip
, desc
);
693 static void exynos4_irq_eint0_15(unsigned int irq
, struct irq_desc
*desc
)
695 u32
*irq_data
= irq_get_handler_data(irq
);
696 struct irq_chip
*chip
= irq_get_chip(irq
);
698 chained_irq_enter(chip
, desc
);
699 chip
->irq_mask(&desc
->irq_data
);
702 chip
->irq_ack(&desc
->irq_data
);
704 generic_handle_irq(*irq_data
);
706 chip
->irq_unmask(&desc
->irq_data
);
707 chained_irq_exit(chip
, desc
);
710 int __init
exynos4_init_irq_eint(void)
714 for (irq
= 0 ; irq
<= 31 ; irq
++) {
715 irq_set_chip_and_handler(IRQ_EINT(irq
), &exynos4_irq_eint
,
717 set_irq_flags(IRQ_EINT(irq
), IRQF_VALID
);
720 irq_set_chained_handler(IRQ_EINT16_31
, exynos4_irq_demux_eint16_31
);
722 for (irq
= 0 ; irq
<= 15 ; irq
++) {
723 eint0_15_data
[irq
] = IRQ_EINT(irq
);
725 irq_set_handler_data(exynos4_get_irq_nr(irq
),
726 &eint0_15_data
[irq
]);
727 irq_set_chained_handler(exynos4_get_irq_nr(irq
),
728 exynos4_irq_eint0_15
);
733 arch_initcall(exynos4_init_irq_eint
);