blob: 08f929efddbca39edb8cfe2d4320a7ca91ec9747 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/irq.c
3 *
4 * Copyright (C) 1999-2001 Nicolas Pitre
5 *
6 * Generic IRQ handling for the SA11x0, GPIO 11-27 IRQ demultiplexing.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/init.h>
13#include <linux/module.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010014#include <linux/interrupt.h>
Russell King31696632012-06-06 11:42:36 +010015#include <linux/io.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010016#include <linux/irq.h>
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +010017#include <linux/irqdomain.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/ioport.h>
Rafael J. Wysocki90533982011-04-22 22:03:03 +020019#include <linux/syscore_ops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Dmitry Eremin-Solenikova657d7f2015-05-18 16:01:19 +010021#include <soc/sa1100/pwer.h>
22
Rob Herringf314f332012-02-24 00:06:51 +010023#include <mach/irqs.h>
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +010024#include <asm/exception.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include "generic.h"
27
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010028#define ICIP 0x00 /* IC IRQ Pending reg. */
29#define ICMR 0x04 /* IC Mask Reg. */
30#define ICLR 0x08 /* IC Level Reg. */
31#define ICCR 0x0C /* IC Control Reg. */
32#define ICFP 0x10 /* IC FIQ Pending reg. */
33#define ICPR 0x20 /* IC Pending Reg. */
34
35static void __iomem *iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010038 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
39 * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
40 */
41static void sa1100_mask_irq(struct irq_data *d)
42{
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010043 u32 reg;
44
45 reg = readl_relaxed(iobase + ICMR);
46 reg &= ~BIT(d->hwirq);
47 writel_relaxed(reg, iobase + ICMR);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010048}
49
50static void sa1100_unmask_irq(struct irq_data *d)
51{
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010052 u32 reg;
53
54 reg = readl_relaxed(iobase + ICMR);
55 reg |= BIT(d->hwirq);
56 writel_relaxed(reg, iobase + ICMR);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010057}
58
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010059static int sa1100_set_wake(struct irq_data *d, unsigned int on)
60{
Dmitry Eremin-Solenikova657d7f2015-05-18 16:01:19 +010061 return sa11x0_sc_set_wake(d->hwirq, on);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010062}
63
64static struct irq_chip sa1100_normal_chip = {
65 .name = "SC",
66 .irq_ack = sa1100_mask_irq,
67 .irq_mask = sa1100_mask_irq,
68 .irq_unmask = sa1100_unmask_irq,
69 .irq_set_wake = sa1100_set_wake,
70};
71
72static int sa1100_normal_irqdomain_map(struct irq_domain *d,
73 unsigned int irq, irq_hw_number_t hwirq)
74{
75 irq_set_chip_and_handler(irq, &sa1100_normal_chip,
76 handle_level_irq);
77 set_irq_flags(irq, IRQF_VALID);
78
79 return 0;
80}
81
82static struct irq_domain_ops sa1100_normal_irqdomain_ops = {
83 .map = sa1100_normal_irqdomain_map,
84 .xlate = irq_domain_xlate_onetwocell,
85};
86
87static struct irq_domain *sa1100_normal_irqdomain;
88
Russell Kinga1810992012-01-12 10:25:29 +000089static struct resource irq_resource =
90 DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92static struct sa1100irq_state {
93 unsigned int saved;
94 unsigned int icmr;
95 unsigned int iclr;
96 unsigned int iccr;
97} sa1100irq_state;
98
Rafael J. Wysocki90533982011-04-22 22:03:03 +020099static int sa1100irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 struct sa1100irq_state *st = &sa1100irq_state;
102
103 st->saved = 1;
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100104 st->icmr = readl_relaxed(iobase + ICMR);
105 st->iclr = readl_relaxed(iobase + ICLR);
106 st->iccr = readl_relaxed(iobase + ICCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /*
109 * Disable all GPIO-based interrupts.
110 */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100111 writel_relaxed(st->icmr & 0xfffff000, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return 0;
114}
115
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200116static void sa1100irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 struct sa1100irq_state *st = &sa1100irq_state;
119
120 if (st->saved) {
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100121 writel_relaxed(st->iccr, iobase + ICCR);
122 writel_relaxed(st->iclr, iobase + ICLR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100124 writel_relaxed(st->icmr, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200128static struct syscore_ops sa1100irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 .suspend = sa1100irq_suspend,
130 .resume = sa1100irq_resume,
131};
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static int __init sa1100irq_init_devicefs(void)
134{
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200135 register_syscore_ops(&sa1100irq_syscore_ops);
136 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
139device_initcall(sa1100irq_init_devicefs);
140
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100141static asmlinkage void __exception_irq_entry
142sa1100_handle_irq(struct pt_regs *regs)
143{
144 uint32_t icip, icmr, mask;
145
146 do {
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100147 icip = readl_relaxed(iobase + ICIP);
148 icmr = readl_relaxed(iobase + ICMR);
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100149 mask = icip & icmr;
150
151 if (mask == 0)
152 break;
153
Dmitry Eremin-Solenikov364e3862015-01-15 02:33:23 +0100154 handle_domain_irq(sa1100_normal_irqdomain,
155 ffs(mask) - 1, regs);
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100156 } while (1);
157}
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159void __init sa1100_init_irq(void)
160{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 request_resource(&iomem_resource, &irq_resource);
162
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100163 iobase = ioremap(irq_resource.start, SZ_64K);
164 if (WARN_ON(!iobase))
165 return;
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 /* disable all IRQs */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100168 writel_relaxed(0, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /* all IRQs are IRQ, not FIQ */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100171 writel_relaxed(0, iobase + ICLR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 /*
174 * Whatever the doc says, this has to be set for the wait-on-irq
175 * instruction to work... on a SA1100 rev 9 at least.
176 */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100177 writel_relaxed(1, iobase + ICCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Dmitry Eremin-Solenikova82be3f2015-01-15 02:31:48 +0100179 sa1100_normal_irqdomain = irq_domain_add_simple(NULL,
180 32, IRQ_GPIO0_SC,
Dmitry Eremin-Solenikov83508092015-01-15 02:29:16 +0100181 &sa1100_normal_irqdomain_ops, NULL);
182
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100183 set_handle_irq(sa1100_handle_irq);
184
Dmitry Baryshkov45528e32008-04-10 13:31:47 +0100185 sa1100_init_gpio();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}