blob: 5a2758ab055e613d42e619b797ba1a28d020ec53 [file] [log] [blame]
Kukjin Kimc81a24f2011-02-14 16:10:55 +09001/* linux/arch/arm/mach-exynos4/irq-combiner.c
Changhwan Youn84bbc162010-07-16 12:12:07 +09002 *
Kukjin Kimc81a24f2011-02-14 16:10:55 +09003 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
Changhwan Youn84bbc162010-07-16 12:12:07 +09004 * http://www.samsung.com
5 *
6 * Based on arch/arm/common/gic.c
7 *
8 * IRQ COMBINER support
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <linux/io.h>
16
17#include <asm/mach/irq.h>
18
19#define COMBINER_ENABLE_SET 0x0
20#define COMBINER_ENABLE_CLEAR 0x4
21#define COMBINER_INT_STATUS 0xC
22
23static DEFINE_SPINLOCK(irq_controller_lock);
24
25struct combiner_chip_data {
26 unsigned int irq_offset;
Changhwan Youn85140ad2010-11-29 17:05:16 +090027 unsigned int irq_mask;
Changhwan Youn84bbc162010-07-16 12:12:07 +090028 void __iomem *base;
29};
30
31static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
32
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010033static inline void __iomem *combiner_base(struct irq_data *data)
Changhwan Youn84bbc162010-07-16 12:12:07 +090034{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010035 struct combiner_chip_data *combiner_data =
36 irq_data_get_irq_chip_data(data);
37
Changhwan Youn84bbc162010-07-16 12:12:07 +090038 return combiner_data->base;
39}
40
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010041static void combiner_mask_irq(struct irq_data *data)
Changhwan Youn84bbc162010-07-16 12:12:07 +090042{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010043 u32 mask = 1 << (data->irq % 32);
Changhwan Youn84bbc162010-07-16 12:12:07 +090044
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010045 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
Changhwan Youn84bbc162010-07-16 12:12:07 +090046}
47
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010048static void combiner_unmask_irq(struct irq_data *data)
Changhwan Youn84bbc162010-07-16 12:12:07 +090049{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010050 u32 mask = 1 << (data->irq % 32);
Changhwan Youn84bbc162010-07-16 12:12:07 +090051
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010052 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
Changhwan Youn84bbc162010-07-16 12:12:07 +090053}
54
55static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
56{
Thomas Gleixner6845664a2011-03-24 13:25:22 +010057 struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
58 struct irq_chip *chip = irq_get_chip(irq);
Changhwan Youn84bbc162010-07-16 12:12:07 +090059 unsigned int cascade_irq, combiner_irq;
60 unsigned long status;
61
Will Deacon0f435632011-02-21 14:37:43 +000062 chained_irq_enter(chip, desc);
Changhwan Youn84bbc162010-07-16 12:12:07 +090063
64 spin_lock(&irq_controller_lock);
65 status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
66 spin_unlock(&irq_controller_lock);
Changhwan Youn85140ad2010-11-29 17:05:16 +090067 status &= chip_data->irq_mask;
Changhwan Youn84bbc162010-07-16 12:12:07 +090068
69 if (status == 0)
70 goto out;
71
Changhwan Youn0c0f9092010-09-29 20:31:42 +090072 combiner_irq = __ffs(status);
Changhwan Youn84bbc162010-07-16 12:12:07 +090073
74 cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
75 if (unlikely(cascade_irq >= NR_IRQS))
76 do_bad_IRQ(cascade_irq, desc);
77 else
78 generic_handle_irq(cascade_irq);
79
80 out:
Will Deacon0f435632011-02-21 14:37:43 +000081 chained_irq_exit(chip, desc);
Changhwan Youn84bbc162010-07-16 12:12:07 +090082}
83
84static struct irq_chip combiner_chip = {
85 .name = "COMBINER",
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010086 .irq_mask = combiner_mask_irq,
87 .irq_unmask = combiner_unmask_irq,
Changhwan Youn84bbc162010-07-16 12:12:07 +090088};
89
90void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
91{
92 if (combiner_nr >= MAX_COMBINER_NR)
93 BUG();
Thomas Gleixner6845664a2011-03-24 13:25:22 +010094 if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
Changhwan Youn84bbc162010-07-16 12:12:07 +090095 BUG();
Thomas Gleixner6845664a2011-03-24 13:25:22 +010096 irq_set_chained_handler(irq, combiner_handle_cascade_irq);
Changhwan Youn84bbc162010-07-16 12:12:07 +090097}
98
99void __init combiner_init(unsigned int combiner_nr, void __iomem *base,
100 unsigned int irq_start)
101{
102 unsigned int i;
103
104 if (combiner_nr >= MAX_COMBINER_NR)
105 BUG();
106
107 combiner_data[combiner_nr].base = base;
108 combiner_data[combiner_nr].irq_offset = irq_start;
Changhwan Youn85140ad2010-11-29 17:05:16 +0900109 combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3);
Changhwan Youn84bbc162010-07-16 12:12:07 +0900110
111 /* Disable all interrupts */
112
Changhwan Youn85140ad2010-11-29 17:05:16 +0900113 __raw_writel(combiner_data[combiner_nr].irq_mask,
114 base + COMBINER_ENABLE_CLEAR);
Changhwan Youn84bbc162010-07-16 12:12:07 +0900115
116 /* Setup the Linux IRQ subsystem */
117
118 for (i = irq_start; i < combiner_data[combiner_nr].irq_offset
119 + MAX_IRQ_IN_COMBINER; i++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100120 irq_set_chip_and_handler(i, &combiner_chip, handle_level_irq);
Thomas Gleixner9323f2612011-03-24 13:29:39 +0100121 irq_set_chip_data(i, &combiner_data[combiner_nr]);
Changhwan Youn84bbc162010-07-16 12:12:07 +0900122 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
123 }
124}