blob: 61bb28d7b19b9a11776b6563293a6e2fd281aa0f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +01002 * Copyright (C) 2015 Dmitry Eremin-Solenikov
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright (C) 1999-2001 Nicolas Pitre
4 *
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +01005 * Generic IRQ handling for the SA11x0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/init.h>
12#include <linux/module.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010013#include <linux/interrupt.h>
Russell King31696632012-06-06 11:42:36 +010014#include <linux/io.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010015#include <linux/irq.h>
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +010016#include <linux/irqdomain.h>
Rafael J. Wysocki90533982011-04-22 22:03:03 +020017#include <linux/syscore_ops.h>
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +010018#include <linux/irqchip/irq-sa11x0.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Dmitry Eremin-Solenikova657d7f2015-05-18 16:01:19 +010020#include <soc/sa1100/pwer.h>
21
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +010022#include <asm/exception.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010024#define ICIP 0x00 /* IC IRQ Pending reg. */
25#define ICMR 0x04 /* IC Mask Reg. */
26#define ICLR 0x08 /* IC Level Reg. */
27#define ICCR 0x0C /* IC Control Reg. */
28#define ICFP 0x10 /* IC FIQ Pending reg. */
29#define ICPR 0x20 /* IC Pending Reg. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010031static void __iomem *iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33/*
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010034 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
35 * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
36 */
37static void sa1100_mask_irq(struct irq_data *d)
38{
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010039 u32 reg;
40
41 reg = readl_relaxed(iobase + ICMR);
42 reg &= ~BIT(d->hwirq);
43 writel_relaxed(reg, iobase + ICMR);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010044}
45
46static void sa1100_unmask_irq(struct irq_data *d)
47{
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010048 u32 reg;
49
50 reg = readl_relaxed(iobase + ICMR);
51 reg |= BIT(d->hwirq);
52 writel_relaxed(reg, iobase + ICMR);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010053}
54
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010055static int sa1100_set_wake(struct irq_data *d, unsigned int on)
56{
Dmitry Eremin-Solenikova657d7f2015-05-18 16:01:19 +010057 return sa11x0_sc_set_wake(d->hwirq, on);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010058}
59
60static struct irq_chip sa1100_normal_chip = {
61 .name = "SC",
62 .irq_ack = sa1100_mask_irq,
63 .irq_mask = sa1100_mask_irq,
64 .irq_unmask = sa1100_unmask_irq,
65 .irq_set_wake = sa1100_set_wake,
66};
67
68static int sa1100_normal_irqdomain_map(struct irq_domain *d,
69 unsigned int irq, irq_hw_number_t hwirq)
70{
71 irq_set_chip_and_handler(irq, &sa1100_normal_chip,
72 handle_level_irq);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010073
74 return 0;
75}
76
Krzysztof Kozlowski9827e8e2015-04-27 14:55:12 +010077static const struct irq_domain_ops sa1100_normal_irqdomain_ops = {
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010078 .map = sa1100_normal_irqdomain_map,
79 .xlate = irq_domain_xlate_onetwocell,
80};
81
82static struct irq_domain *sa1100_normal_irqdomain;
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static struct sa1100irq_state {
85 unsigned int saved;
86 unsigned int icmr;
87 unsigned int iclr;
88 unsigned int iccr;
89} sa1100irq_state;
90
Rafael J. Wysocki90533982011-04-22 22:03:03 +020091static int sa1100irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 struct sa1100irq_state *st = &sa1100irq_state;
94
95 st->saved = 1;
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010096 st->icmr = readl_relaxed(iobase + ICMR);
97 st->iclr = readl_relaxed(iobase + ICLR);
98 st->iccr = readl_relaxed(iobase + ICCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 /*
101 * Disable all GPIO-based interrupts.
102 */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100103 writel_relaxed(st->icmr & 0xfffff000, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return 0;
106}
107
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200108static void sa1100irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 struct sa1100irq_state *st = &sa1100irq_state;
111
112 if (st->saved) {
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100113 writel_relaxed(st->iccr, iobase + ICCR);
114 writel_relaxed(st->iclr, iobase + ICLR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100116 writel_relaxed(st->icmr, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200120static struct syscore_ops sa1100irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 .suspend = sa1100irq_suspend,
122 .resume = sa1100irq_resume,
123};
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125static int __init sa1100irq_init_devicefs(void)
126{
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200127 register_syscore_ops(&sa1100irq_syscore_ops);
128 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131device_initcall(sa1100irq_init_devicefs);
132
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100133static asmlinkage void __exception_irq_entry
134sa1100_handle_irq(struct pt_regs *regs)
135{
136 uint32_t icip, icmr, mask;
137
138 do {
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100139 icip = readl_relaxed(iobase + ICIP);
140 icmr = readl_relaxed(iobase + ICMR);
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100141 mask = icip & icmr;
142
143 if (mask == 0)
144 break;
145
Dmitry Eremin-Solenikov364e3862015-01-15 02:33:23 +0100146 handle_domain_irq(sa1100_normal_irqdomain,
147 ffs(mask) - 1, regs);
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100148 } while (1);
149}
150
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +0100151void __init sa11x0_init_irq_nodt(int irq_start, resource_size_t io_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +0100153 iobase = ioremap(io_start, SZ_64K);
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100154 if (WARN_ON(!iobase))
155 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /* disable all IRQs */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100158 writel_relaxed(0, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 /* all IRQs are IRQ, not FIQ */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100161 writel_relaxed(0, iobase + ICLR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /*
164 * Whatever the doc says, this has to be set for the wait-on-irq
165 * instruction to work... on a SA1100 rev 9 at least.
166 */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100167 writel_relaxed(1, iobase + ICCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Dmitry Eremin-Solenikova82be3f2015-01-15 02:31:48 +0100169 sa1100_normal_irqdomain = irq_domain_add_simple(NULL,
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +0100170 32, irq_start,
Dmitry Eremin-Solenikov83508092015-01-15 02:29:16 +0100171 &sa1100_normal_irqdomain_ops, NULL);
172
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100173 set_handle_irq(sa1100_handle_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}