blob: dbccc7dafbf8743456e60b09c0b1036691585ceb [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +01003 * Copyright (C) 2015 Dmitry Eremin-Solenikov
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 1999-2001 Nicolas Pitre
5 *
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +01006 * Generic IRQ handling for the SA11x0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8#include <linux/init.h>
9#include <linux/module.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010010#include <linux/interrupt.h>
Russell King31696632012-06-06 11:42:36 +010011#include <linux/io.h>
Thomas Gleixner119c6412006-07-01 22:32:38 +010012#include <linux/irq.h>
Dmitry Eremin-Solenikov1eca42b2014-11-28 15:56:54 +010013#include <linux/irqdomain.h>
Rafael J. Wysocki90533982011-04-22 22:03:03 +020014#include <linux/syscore_ops.h>
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +010015#include <linux/irqchip/irq-sa11x0.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Dmitry Eremin-Solenikova657d7f2015-05-18 16:01:19 +010017#include <soc/sa1100/pwer.h>
18
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +010019#include <asm/exception.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010021#define ICIP 0x00 /* IC IRQ Pending reg. */
22#define ICMR 0x04 /* IC Mask Reg. */
23#define ICLR 0x08 /* IC Level Reg. */
24#define ICCR 0x0C /* IC Control Reg. */
25#define ICFP 0x10 /* IC FIQ Pending reg. */
26#define ICPR 0x20 /* IC Pending Reg. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010028static void __iomem *iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30/*
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010031 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
32 * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
33 */
34static void sa1100_mask_irq(struct irq_data *d)
35{
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010036 u32 reg;
37
38 reg = readl_relaxed(iobase + ICMR);
39 reg &= ~BIT(d->hwirq);
40 writel_relaxed(reg, iobase + ICMR);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010041}
42
43static void sa1100_unmask_irq(struct irq_data *d)
44{
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010045 u32 reg;
46
47 reg = readl_relaxed(iobase + ICMR);
48 reg |= BIT(d->hwirq);
49 writel_relaxed(reg, iobase + ICMR);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010050}
51
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010052static int sa1100_set_wake(struct irq_data *d, unsigned int on)
53{
Dmitry Eremin-Solenikova657d7f2015-05-18 16:01:19 +010054 return sa11x0_sc_set_wake(d->hwirq, on);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010055}
56
57static struct irq_chip sa1100_normal_chip = {
58 .name = "SC",
59 .irq_ack = sa1100_mask_irq,
60 .irq_mask = sa1100_mask_irq,
61 .irq_unmask = sa1100_unmask_irq,
62 .irq_set_wake = sa1100_set_wake,
63};
64
65static int sa1100_normal_irqdomain_map(struct irq_domain *d,
66 unsigned int irq, irq_hw_number_t hwirq)
67{
68 irq_set_chip_and_handler(irq, &sa1100_normal_chip,
69 handle_level_irq);
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010070
71 return 0;
72}
73
Krzysztof Kozlowski9827e8e2015-04-27 14:55:12 +010074static const struct irq_domain_ops sa1100_normal_irqdomain_ops = {
Dmitry Eremin-Solenikovab71f992014-11-28 15:57:52 +010075 .map = sa1100_normal_irqdomain_map,
76 .xlate = irq_domain_xlate_onetwocell,
77};
78
79static struct irq_domain *sa1100_normal_irqdomain;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static struct sa1100irq_state {
82 unsigned int saved;
83 unsigned int icmr;
84 unsigned int iclr;
85 unsigned int iccr;
86} sa1100irq_state;
87
Rafael J. Wysocki90533982011-04-22 22:03:03 +020088static int sa1100irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 struct sa1100irq_state *st = &sa1100irq_state;
91
92 st->saved = 1;
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +010093 st->icmr = readl_relaxed(iobase + ICMR);
94 st->iclr = readl_relaxed(iobase + ICLR);
95 st->iccr = readl_relaxed(iobase + ICCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 /*
98 * Disable all GPIO-based interrupts.
99 */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100100 writel_relaxed(st->icmr & 0xfffff000, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return 0;
103}
104
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200105static void sa1100irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 struct sa1100irq_state *st = &sa1100irq_state;
108
109 if (st->saved) {
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100110 writel_relaxed(st->iccr, iobase + ICCR);
111 writel_relaxed(st->iclr, iobase + ICLR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100113 writel_relaxed(st->icmr, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115}
116
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200117static struct syscore_ops sa1100irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .suspend = sa1100irq_suspend,
119 .resume = sa1100irq_resume,
120};
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static int __init sa1100irq_init_devicefs(void)
123{
Rafael J. Wysocki90533982011-04-22 22:03:03 +0200124 register_syscore_ops(&sa1100irq_syscore_ops);
125 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
128device_initcall(sa1100irq_init_devicefs);
129
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100130static asmlinkage void __exception_irq_entry
131sa1100_handle_irq(struct pt_regs *regs)
132{
133 uint32_t icip, icmr, mask;
134
135 do {
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100136 icip = readl_relaxed(iobase + ICIP);
137 icmr = readl_relaxed(iobase + ICMR);
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100138 mask = icip & icmr;
139
140 if (mask == 0)
141 break;
142
Dmitry Eremin-Solenikov364e3862015-01-15 02:33:23 +0100143 handle_domain_irq(sa1100_normal_irqdomain,
144 ffs(mask) - 1, regs);
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100145 } while (1);
146}
147
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +0100148void __init sa11x0_init_irq_nodt(int irq_start, resource_size_t io_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +0100150 iobase = ioremap(io_start, SZ_64K);
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100151 if (WARN_ON(!iobase))
152 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 /* disable all IRQs */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100155 writel_relaxed(0, iobase + ICMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /* all IRQs are IRQ, not FIQ */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100158 writel_relaxed(0, iobase + ICLR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 /*
161 * Whatever the doc says, this has to be set for the wait-on-irq
162 * instruction to work... on a SA1100 rev 9 at least.
163 */
Dmitry Eremin-Solenikov60c06c42015-05-18 16:02:47 +0100164 writel_relaxed(1, iobase + ICCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Dmitry Eremin-Solenikova82be3f2015-01-15 02:31:48 +0100166 sa1100_normal_irqdomain = irq_domain_add_simple(NULL,
Dmitry Eremin-Solenikov85e6f092015-05-19 16:16:14 +0100167 32, irq_start,
Dmitry Eremin-Solenikov83508092015-01-15 02:29:16 +0100168 &sa1100_normal_irqdomain_ops, NULL);
169
Dmitry Eremin-Solenikovaffcab32014-11-28 15:55:16 +0100170 set_handle_irq(sa1100_handle_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}