Blame view

drivers/irqchip/irq-clps711x.c 5.97 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
2
3
4
5
  /*
   *  CLPS711X IRQ driver
   *
   *  Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru>
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
6
7
8
9
   */
  
  #include <linux/io.h>
  #include <linux/irq.h>
41a83e06e   Joel Porquet   irqchip: Prepare ...
10
  #include <linux/irqchip.h>
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
11
12
13
14
15
16
17
  #include <linux/irqdomain.h>
  #include <linux/of_address.h>
  #include <linux/of_irq.h>
  #include <linux/slab.h>
  
  #include <asm/exception.h>
  #include <asm/mach/irq.h>
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  #define CLPS711X_INTSR1	(0x0240)
  #define CLPS711X_INTMR1	(0x0280)
  #define CLPS711X_BLEOI	(0x0600)
  #define CLPS711X_MCEOI	(0x0640)
  #define CLPS711X_TEOI	(0x0680)
  #define CLPS711X_TC1EOI	(0x06c0)
  #define CLPS711X_TC2EOI	(0x0700)
  #define CLPS711X_RTCEOI	(0x0740)
  #define CLPS711X_UMSEOI	(0x0780)
  #define CLPS711X_COEOI	(0x07c0)
  #define CLPS711X_INTSR2	(0x1240)
  #define CLPS711X_INTMR2	(0x1280)
  #define CLPS711X_SRXEOF	(0x1600)
  #define CLPS711X_KBDEOI	(0x1700)
  #define CLPS711X_INTSR3	(0x2240)
  #define CLPS711X_INTMR3	(0x2280)
  
  static const struct {
  #define CLPS711X_FLAG_EN	(1 << 0)
  #define CLPS711X_FLAG_FIQ	(1 << 1)
  	unsigned int	flags;
  	phys_addr_t	eoi;
  } clps711x_irqs[] = {
  	[1]	= { CLPS711X_FLAG_FIQ, CLPS711X_BLEOI, },
  	[3]	= { CLPS711X_FLAG_FIQ, CLPS711X_MCEOI, },
  	[4]	= { CLPS711X_FLAG_EN, CLPS711X_COEOI, },
  	[5]	= { CLPS711X_FLAG_EN, },
  	[6]	= { CLPS711X_FLAG_EN, },
  	[7]	= { CLPS711X_FLAG_EN, },
  	[8]	= { CLPS711X_FLAG_EN, CLPS711X_TC1EOI, },
  	[9]	= { CLPS711X_FLAG_EN, CLPS711X_TC2EOI, },
  	[10]	= { CLPS711X_FLAG_EN, CLPS711X_RTCEOI, },
  	[11]	= { CLPS711X_FLAG_EN, CLPS711X_TEOI, },
  	[12]	= { CLPS711X_FLAG_EN, },
  	[13]	= { CLPS711X_FLAG_EN, },
  	[14]	= { CLPS711X_FLAG_EN, CLPS711X_UMSEOI, },
  	[15]	= { CLPS711X_FLAG_EN, CLPS711X_SRXEOF, },
  	[16]	= { CLPS711X_FLAG_EN, CLPS711X_KBDEOI, },
  	[17]	= { CLPS711X_FLAG_EN, },
  	[18]	= { CLPS711X_FLAG_EN, },
  	[28]	= { CLPS711X_FLAG_EN, },
  	[29]	= { CLPS711X_FLAG_EN, },
  	[32]	= { CLPS711X_FLAG_FIQ, },
  };
  
  static struct {
  	void __iomem		*base;
  	void __iomem		*intmr[3];
  	void __iomem		*intsr[3];
  	struct irq_domain	*domain;
  	struct irq_domain_ops	ops;
  } *clps711x_intc;
  
  static asmlinkage void __exception_irq_entry clps711x_irqh(struct pt_regs *regs)
  {
a8e10cb76   Marc Zyngier   irqchip: clps711x...
73
  	u32 irqstat;
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
74
75
76
77
  
  	do {
  		irqstat = readw_relaxed(clps711x_intc->intmr[0]) &
  			  readw_relaxed(clps711x_intc->intsr[0]);
a8e10cb76   Marc Zyngier   irqchip: clps711x...
78
79
80
  		if (irqstat)
  			handle_domain_irq(clps711x_intc->domain,
  					  fls(irqstat) - 1, regs);
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
81
82
83
  
  		irqstat = readw_relaxed(clps711x_intc->intmr[1]) &
  			  readw_relaxed(clps711x_intc->intsr[1]);
a8e10cb76   Marc Zyngier   irqchip: clps711x...
84
85
86
  		if (irqstat)
  			handle_domain_irq(clps711x_intc->domain,
  					  fls(irqstat) - 1 + 16, regs);
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  	} while (irqstat);
  }
  
  static void clps711x_intc_eoi(struct irq_data *d)
  {
  	irq_hw_number_t hwirq = irqd_to_hwirq(d);
  
  	writel_relaxed(0, clps711x_intc->base + clps711x_irqs[hwirq].eoi);
  }
  
  static void clps711x_intc_mask(struct irq_data *d)
  {
  	irq_hw_number_t hwirq = irqd_to_hwirq(d);
  	void __iomem *intmr = clps711x_intc->intmr[hwirq / 16];
  	u32 tmp;
  
  	tmp = readl_relaxed(intmr);
  	tmp &= ~(1 << (hwirq % 16));
  	writel_relaxed(tmp, intmr);
  }
  
  static void clps711x_intc_unmask(struct irq_data *d)
  {
  	irq_hw_number_t hwirq = irqd_to_hwirq(d);
  	void __iomem *intmr = clps711x_intc->intmr[hwirq / 16];
  	u32 tmp;
  
  	tmp = readl_relaxed(intmr);
  	tmp |= 1 << (hwirq % 16);
  	writel_relaxed(tmp, intmr);
  }
  
  static struct irq_chip clps711x_intc_chip = {
  	.name		= "clps711x-intc",
  	.irq_eoi	= clps711x_intc_eoi,
  	.irq_mask	= clps711x_intc_mask,
  	.irq_unmask	= clps711x_intc_unmask,
  };
  
  static int __init clps711x_intc_irq_map(struct irq_domain *h, unsigned int virq,
  					irq_hw_number_t hw)
  {
  	irq_flow_handler_t handler = handle_level_irq;
d17cab445   Rob Herring   irqchip: Kill off...
130
  	unsigned int flags = 0;
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
131
132
133
134
135
136
  
  	if (!clps711x_irqs[hw].flags)
  		return 0;
  
  	if (clps711x_irqs[hw].flags & CLPS711X_FLAG_FIQ) {
  		handler = handle_bad_irq;
d17cab445   Rob Herring   irqchip: Kill off...
137
  		flags |= IRQ_NOAUTOEN;
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
138
139
140
141
142
143
144
145
146
  	} else if (clps711x_irqs[hw].eoi) {
  		handler = handle_fasteoi_irq;
  	}
  
  	/* Clear down pending interrupt */
  	if (clps711x_irqs[hw].eoi)
  		writel_relaxed(0, clps711x_intc->base + clps711x_irqs[hw].eoi);
  
  	irq_set_chip_and_handler(virq, &clps711x_intc_chip, handler);
d17cab445   Rob Herring   irqchip: Kill off...
147
  	irq_modify_status(virq, IRQ_NOPROBE, flags);
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  
  	return 0;
  }
  
  static int __init _clps711x_intc_init(struct device_node *np,
  				      phys_addr_t base, resource_size_t size)
  {
  	int err;
  
  	clps711x_intc = kzalloc(sizeof(*clps711x_intc), GFP_KERNEL);
  	if (!clps711x_intc)
  		return -ENOMEM;
  
  	clps711x_intc->base = ioremap(base, size);
  	if (!clps711x_intc->base) {
  		err = -ENOMEM;
  		goto out_kfree;
  	}
  
  	clps711x_intc->intsr[0] = clps711x_intc->base + CLPS711X_INTSR1;
  	clps711x_intc->intmr[0] = clps711x_intc->base + CLPS711X_INTMR1;
  	clps711x_intc->intsr[1] = clps711x_intc->base + CLPS711X_INTSR2;
  	clps711x_intc->intmr[1] = clps711x_intc->base + CLPS711X_INTMR2;
  	clps711x_intc->intsr[2] = clps711x_intc->base + CLPS711X_INTSR3;
  	clps711x_intc->intmr[2] = clps711x_intc->base + CLPS711X_INTMR3;
  
  	/* Mask all interrupts */
  	writel_relaxed(0, clps711x_intc->intmr[0]);
  	writel_relaxed(0, clps711x_intc->intmr[1]);
  	writel_relaxed(0, clps711x_intc->intmr[2]);
  
  	err = irq_alloc_descs(-1, 0, ARRAY_SIZE(clps711x_irqs), numa_node_id());
287980e49   Arnd Bergmann   remove lots of IS...
180
  	if (err < 0)
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  		goto out_iounmap;
  
  	clps711x_intc->ops.map = clps711x_intc_irq_map;
  	clps711x_intc->ops.xlate = irq_domain_xlate_onecell;
  	clps711x_intc->domain =
  		irq_domain_add_legacy(np, ARRAY_SIZE(clps711x_irqs),
  				      0, 0, &clps711x_intc->ops, NULL);
  	if (!clps711x_intc->domain) {
  		err = -ENOMEM;
  		goto out_irqfree;
  	}
  
  	irq_set_default_host(clps711x_intc->domain);
  	set_handle_irq(clps711x_irqh);
  
  #ifdef CONFIG_FIQ
  	init_FIQ(0);
  #endif
  
  	return 0;
  
  out_irqfree:
  	irq_free_descs(0, ARRAY_SIZE(clps711x_irqs));
  
  out_iounmap:
  	iounmap(clps711x_intc->base);
  
  out_kfree:
  	kfree(clps711x_intc);
  
  	return err;
  }
  
  void __init clps711x_intc_init(phys_addr_t base, resource_size_t size)
  {
  	BUG_ON(_clps711x_intc_init(NULL, base, size));
  }
  
  #ifdef CONFIG_IRQCHIP
  static int __init clps711x_intc_init_dt(struct device_node *np,
  					struct device_node *parent)
  {
  	struct resource res;
  	int err;
  
  	err = of_address_to_resource(np, 0, &res);
  	if (err)
  		return err;
  
  	return _clps711x_intc_init(np, res.start, resource_size(&res));
  }
4b4d99495   Alexander Shiyan   irqchip: clps711x...
232
  IRQCHIP_DECLARE(clps711x, "cirrus,ep7209-intc", clps711x_intc_init_dt);
afc98d908   Alexander Shiyan   ARM: clps711x: Ad...
233
  #endif