arm: Move chained_irq_(enter|exit) to a generic file
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / plat-samsung / irq-vic-timer.c
CommitLineData
7162ba03
BD
1/* arch/arm/plat-samsung/irq-vic-timer.c
2 * originally part of arch/arm/plat-s3c64xx/irq.c
3 *
4 * Copyright 2008 Openmoko, Inc.
5 * Copyright 2008 Simtec Electronics
6 * Ben Dooks <ben@simtec.co.uk>
7 * http://armlinux.simtec.co.uk/
8 *
9 * S3C64XX - Interrupt handling
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/kernel.h>
17#include <linux/interrupt.h>
18#include <linux/irq.h>
de88cbb7 19#include <linux/irqchip/chained_irq.h>
7162ba03
BD
20#include <linux/io.h>
21
22#include <mach/map.h>
bb19a751 23#include <plat/cpu.h>
7162ba03
BD
24#include <plat/irq-vic-timer.h>
25#include <plat/regs-timer.h>
26
27static void s3c_irq_demux_vic_timer(unsigned int irq, struct irq_desc *desc)
28{
995b528a
MS
29 struct irq_chip *chip = irq_get_chip(irq);
30 chained_irq_enter(chip, desc);
04ea1cc8 31 generic_handle_irq((int)desc->irq_data.handler_data);
995b528a 32 chained_irq_exit(chip, desc);
7162ba03
BD
33}
34
35/* We assume the IRQ_TIMER0..IRQ_TIMER4 range is continuous. */
2d2e1d3c 36static void s3c_irq_timer_ack(struct irq_data *d)
7162ba03 37{
2d2e1d3c
TG
38 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
39 u32 mask = (1 << 5) << (d->irq - gc->irq_base);
7162ba03 40
2d2e1d3c 41 irq_reg_writel(mask | gc->mask_cache, gc->reg_base);
7162ba03
BD
42}
43
7162ba03
BD
44/**
45 * s3c_init_vic_timer_irq() - initialise timer irq chanined off VIC.\
2d2e1d3c
TG
46 * @num: Number of timers to initialize
47 * @timer_irq: Base IRQ number to be used for the timers.
7162ba03
BD
48 *
49 * Register the necessary IRQ chaining and support for the timer IRQs
50 * chained of the VIC.
51 */
2d2e1d3c 52void __init s3c_init_vic_timer_irq(unsigned int num, unsigned int timer_irq)
7162ba03 53{
2d2e1d3c
TG
54 unsigned int pirq[5] = { IRQ_TIMER0_VIC, IRQ_TIMER1_VIC, IRQ_TIMER2_VIC,
55 IRQ_TIMER3_VIC, IRQ_TIMER4_VIC };
56 struct irq_chip_generic *s3c_tgc;
57 struct irq_chip_type *ct;
58 unsigned int i;
7162ba03 59
bb19a751
KK
60#ifdef CONFIG_ARCH_EXYNOS
61 if (soc_is_exynos5250()) {
62 pirq[0] = EXYNOS5_IRQ_TIMER0_VIC;
63 pirq[1] = EXYNOS5_IRQ_TIMER1_VIC;
64 pirq[2] = EXYNOS5_IRQ_TIMER2_VIC;
65 pirq[3] = EXYNOS5_IRQ_TIMER3_VIC;
66 pirq[4] = EXYNOS5_IRQ_TIMER4_VIC;
67 } else {
68 pirq[0] = EXYNOS4_IRQ_TIMER0_VIC;
69 pirq[1] = EXYNOS4_IRQ_TIMER1_VIC;
70 pirq[2] = EXYNOS4_IRQ_TIMER2_VIC;
71 pirq[3] = EXYNOS4_IRQ_TIMER3_VIC;
72 pirq[4] = EXYNOS4_IRQ_TIMER4_VIC;
73 }
74#endif
2d2e1d3c
TG
75 s3c_tgc = irq_alloc_generic_chip("s3c-timer", 1, timer_irq,
76 S3C64XX_TINT_CSTAT, handle_level_irq);
691abd0a
TP
77
78 if (!s3c_tgc) {
79 pr_err("%s: irq_alloc_generic_chip for IRQ %d failed\n",
80 __func__, timer_irq);
81 return;
82 }
83
2d2e1d3c
TG
84 ct = s3c_tgc->chip_types;
85 ct->chip.irq_mask = irq_gc_mask_clr_bit;
86 ct->chip.irq_unmask = irq_gc_mask_set_bit;
87 ct->chip.irq_ack = s3c_irq_timer_ack;
88 irq_setup_generic_chip(s3c_tgc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
89 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
90 /* Clear the upper bits of the mask_cache*/
91 s3c_tgc->mask_cache &= 0x1f;
7162ba03 92
2d2e1d3c
TG
93 for (i = 0; i < num; i++, timer_irq++) {
94 irq_set_chained_handler(pirq[i], s3c_irq_demux_vic_timer);
95 irq_set_handler_data(pirq[i], (void *)timer_irq);
96 }
7162ba03 97}