blob: 186357f3b4db54e2b4141f149ec1920628b35d66 [file] [log] [blame]
Saeed Bisharaedabd382009-08-06 15:12:43 +03001/*
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>
Rob Herringce915742012-08-29 10:16:55 -050021#include <plat/orion-gpio.h>
Saeed Bisharaedabd382009-08-06 15:12:43 +030022#include "common.h"
23
Lennert Buytenhekaa456a62010-11-29 10:27:47 +010024static void pmu_irq_mask(struct irq_data *d)
Saeed Bisharaedabd382009-08-06 15:12:43 +030025{
Lennert Buytenhekaa456a62010-11-29 10:27:47 +010026 int pin = irq_to_pmu(d->irq);
Saeed Bisharaedabd382009-08-06 15:12:43 +030027 u32 u;
28
29 u = readl(PMU_INTERRUPT_MASK);
30 u &= ~(1 << (pin & 31));
31 writel(u, PMU_INTERRUPT_MASK);
32}
33
Lennert Buytenhekaa456a62010-11-29 10:27:47 +010034static void pmu_irq_unmask(struct irq_data *d)
Saeed Bisharaedabd382009-08-06 15:12:43 +030035{
Lennert Buytenhekaa456a62010-11-29 10:27:47 +010036 int pin = irq_to_pmu(d->irq);
Saeed Bisharaedabd382009-08-06 15:12:43 +030037 u32 u;
38
39 u = readl(PMU_INTERRUPT_MASK);
40 u |= 1 << (pin & 31);
41 writel(u, PMU_INTERRUPT_MASK);
42}
43
Lennert Buytenhekaa456a62010-11-29 10:27:47 +010044static void pmu_irq_ack(struct irq_data *d)
Saeed Bisharaedabd382009-08-06 15:12:43 +030045{
Lennert Buytenhekaa456a62010-11-29 10:27:47 +010046 int pin = irq_to_pmu(d->irq);
Saeed Bisharaedabd382009-08-06 15:12:43 +030047 u32 u;
48
49 u = ~(1 << (pin & 31));
50 writel(u, PMU_INTERRUPT_CAUSE);
51}
52
53static struct irq_chip pmu_irq_chip = {
54 .name = "pmu_irq",
Lennert Buytenhekaa456a62010-11-29 10:27:47 +010055 .irq_mask = pmu_irq_mask,
56 .irq_unmask = pmu_irq_unmask,
57 .irq_ack = pmu_irq_ack,
Saeed Bisharaedabd382009-08-06 15:12:43 +030058};
59
60static void pmu_irq_handler(unsigned int irq, struct irq_desc *desc)
61{
62 unsigned long cause = readl(PMU_INTERRUPT_CAUSE);
63
64 cause &= readl(PMU_INTERRUPT_MASK);
65 if (cause == 0) {
66 do_bad_IRQ(irq, desc);
67 return;
68 }
69
70 for (irq = 0; irq < NR_PMU_IRQS; irq++) {
71 if (!(cause & (1 << irq)))
72 continue;
73 irq = pmu_to_irq(irq);
Thomas Gleixnercf0d6b72011-03-24 12:33:40 +010074 generic_handle_irq(irq);
Saeed Bisharaedabd382009-08-06 15:12:43 +030075 }
76}
77
Andrew Lunn278b45b2012-06-27 13:40:04 +020078static int __initdata gpio0_irqs[4] = {
79 IRQ_DOVE_GPIO_0_7,
80 IRQ_DOVE_GPIO_8_15,
81 IRQ_DOVE_GPIO_16_23,
82 IRQ_DOVE_GPIO_24_31,
83};
84
85static int __initdata gpio1_irqs[4] = {
86 IRQ_DOVE_HIGH_GPIO,
87 0,
88 0,
89 0,
90};
91
92static int __initdata gpio2_irqs[4] = {
93 0,
94 0,
95 0,
96 0,
97};
98
Saeed Bisharaedabd382009-08-06 15:12:43 +030099void __init dove_init_irq(void)
100{
101 int i;
102
103 orion_irq_init(0, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF));
104 orion_irq_init(32, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF));
105
106 /*
Lennert Buytenhek9eac6d02010-12-14 12:54:03 +0100107 * Initialize gpiolib for GPIOs 0-71.
Saeed Bisharaedabd382009-08-06 15:12:43 +0300108 */
Andrew Lunn278b45b2012-06-27 13:40:04 +0200109 orion_gpio_init(NULL, 0, 32, (void __iomem *)DOVE_GPIO_LO_VIRT_BASE, 0,
110 IRQ_DOVE_GPIO_START, gpio0_irqs);
Lennert Buytenhek9eac6d02010-12-14 12:54:03 +0100111
Andrew Lunn278b45b2012-06-27 13:40:04 +0200112 orion_gpio_init(NULL, 32, 32, (void __iomem *)DOVE_GPIO_HI_VIRT_BASE, 0,
113 IRQ_DOVE_GPIO_START + 32, gpio1_irqs);
Lennert Buytenhek9eac6d02010-12-14 12:54:03 +0100114
Andrew Lunn278b45b2012-06-27 13:40:04 +0200115 orion_gpio_init(NULL, 64, 8, (void __iomem *)DOVE_GPIO2_VIRT_BASE, 0,
116 IRQ_DOVE_GPIO_START + 64, gpio2_irqs);
Saeed Bisharaedabd382009-08-06 15:12:43 +0300117
118 /*
119 * Mask and clear PMU interrupts
120 */
121 writel(0, PMU_INTERRUPT_MASK);
122 writel(0, PMU_INTERRUPT_CAUSE);
123
Saeed Bisharaedabd382009-08-06 15:12:43 +0300124 for (i = IRQ_DOVE_PMU_START; i < NR_IRQS; i++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100125 irq_set_chip_and_handler(i, &pmu_irq_chip, handle_level_irq);
Thomas Gleixnercf0d6b72011-03-24 12:33:40 +0100126 irq_set_status_flags(i, IRQ_LEVEL);
Saeed Bisharaedabd382009-08-06 15:12:43 +0300127 set_irq_flags(i, IRQF_VALID);
128 }
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100129 irq_set_chained_handler(IRQ_DOVE_PMU, pmu_irq_handler);
Saeed Bisharaedabd382009-08-06 15:12:43 +0300130}