blob: 9f2fd1001746ff88a7de67437778d922e67e48d1 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * arch/arm/mach-dove/irq.c
3 *
4 * Dove IRQ handling.
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/irq.h>
14#include <linux/gpio.h>
15#include <linux/io.h>
16#include <asm/mach/arch.h>
17#include <plat/irq.h>
18#include <asm/mach/irq.h>
19#include <mach/pm.h>
20#include <mach/bridge-regs.h>
21#include "common.h"
22
23static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
24{
25 int irqoff;
26 BUG_ON(irq < IRQ_DOVE_GPIO_0_7 || irq > IRQ_DOVE_HIGH_GPIO);
27
28 irqoff = irq <= IRQ_DOVE_GPIO_16_23 ? irq - IRQ_DOVE_GPIO_0_7 :
29 3 + irq - IRQ_DOVE_GPIO_24_31;
30
31 orion_gpio_irq_handler(irqoff << 3);
32 if (irq == IRQ_DOVE_HIGH_GPIO) {
33 orion_gpio_irq_handler(40);
34 orion_gpio_irq_handler(48);
35 orion_gpio_irq_handler(56);
36 }
37}
38
39static void pmu_irq_mask(struct irq_data *d)
40{
41 int pin = irq_to_pmu(d->irq);
42 u32 u;
43
44 u = readl(PMU_INTERRUPT_MASK);
45 u &= ~(1 << (pin & 31));
46 writel(u, PMU_INTERRUPT_MASK);
47}
48
49static void pmu_irq_unmask(struct irq_data *d)
50{
51 int pin = irq_to_pmu(d->irq);
52 u32 u;
53
54 u = readl(PMU_INTERRUPT_MASK);
55 u |= 1 << (pin & 31);
56 writel(u, PMU_INTERRUPT_MASK);
57}
58
59static void pmu_irq_ack(struct irq_data *d)
60{
61 int pin = irq_to_pmu(d->irq);
62 u32 u;
63
64 /*
65 * The PMU mask register is not RW0C: it is RW. This means that
66 * the bits take whatever value is written to them; if you write
67 * a '1', you will set the interrupt.
68 *
69 * Unfortunately this means there is NO race free way to clear
70 * these interrupts.
71 *
72 * So, let's structure the code so that the window is as small as
73 * possible.
74 */
75 u = ~(1 << (pin & 31));
76 u &= readl_relaxed(PMU_INTERRUPT_CAUSE);
77 writel_relaxed(u, PMU_INTERRUPT_CAUSE);
78}
79
80static struct irq_chip pmu_irq_chip = {
81 .name = "pmu_irq",
82 .irq_mask = pmu_irq_mask,
83 .irq_unmask = pmu_irq_unmask,
84 .irq_ack = pmu_irq_ack,
85};
86
87static void pmu_irq_handler(unsigned int irq, struct irq_desc *desc)
88{
89 unsigned long cause = readl(PMU_INTERRUPT_CAUSE);
90
91 cause &= readl(PMU_INTERRUPT_MASK);
92 if (cause == 0) {
93 do_bad_IRQ(irq, desc);
94 return;
95 }
96
97 for (irq = 0; irq < NR_PMU_IRQS; irq++) {
98 if (!(cause & (1 << irq)))
99 continue;
100 irq = pmu_to_irq(irq);
101 generic_handle_irq(irq);
102 }
103}
104
105void __init dove_init_irq(void)
106{
107 int i;
108
109 orion_irq_init(0, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF));
110 orion_irq_init(32, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF));
111
112 /*
113 * Initialize gpiolib for GPIOs 0-71.
114 */
115 orion_gpio_init(0, 32, DOVE_GPIO_LO_VIRT_BASE, 0,
116 IRQ_DOVE_GPIO_START);
117 irq_set_chained_handler(IRQ_DOVE_GPIO_0_7, gpio_irq_handler);
118 irq_set_chained_handler(IRQ_DOVE_GPIO_8_15, gpio_irq_handler);
119 irq_set_chained_handler(IRQ_DOVE_GPIO_16_23, gpio_irq_handler);
120 irq_set_chained_handler(IRQ_DOVE_GPIO_24_31, gpio_irq_handler);
121
122 orion_gpio_init(32, 32, DOVE_GPIO_HI_VIRT_BASE, 0,
123 IRQ_DOVE_GPIO_START + 32);
124 irq_set_chained_handler(IRQ_DOVE_HIGH_GPIO, gpio_irq_handler);
125
126 orion_gpio_init(64, 8, DOVE_GPIO2_VIRT_BASE, 0,
127 IRQ_DOVE_GPIO_START + 64);
128
129 /*
130 * Mask and clear PMU interrupts
131 */
132 writel(0, PMU_INTERRUPT_MASK);
133 writel(0, PMU_INTERRUPT_CAUSE);
134
135 for (i = IRQ_DOVE_PMU_START; i < NR_IRQS; i++) {
136 irq_set_chip_and_handler(i, &pmu_irq_chip, handle_level_irq);
137 irq_set_status_flags(i, IRQ_LEVEL);
138 set_irq_flags(i, IRQF_VALID);
139 }
140 irq_set_chained_handler(IRQ_DOVE_PMU, pmu_irq_handler);
141}