Skip to content

Commit 45ac019

Browse files
AngeloGioacchino Del RegnoMarc Zyngier
authored andcommitted
irqchip/irq-mtk-cirq: Move register offsets to const array
In preparation to add support for new SoCs having a different register layout, add an enumeration that documents register offsets and move the definitions for the same to a u32 array; Selecting the right register offsets array is done by adding an of_device_id array containing all of the currently supported compatible strings pointing to the "v1" offsets array (as data): since no devicetree declares the `mediatek,mtk-cirq` compatible without a SoC-specific one, it wasn't necessary to provide any legacy fallback. Every usage of the aforemementioned definitions was changed to get a register address through a newly introduced `mtk_cirq_reg()` accessor. This change brings no functional changes. Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20221128092217.36552-4-angelogioacchino.delregno@collabora.com
1 parent 85de640 commit 45ac019

1 file changed

Lines changed: 65 additions & 17 deletions

File tree

drivers/irqchip/irq-mtk-cirq.c

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,29 @@
1515
#include <linux/slab.h>
1616
#include <linux/syscore_ops.h>
1717

18-
#define CIRQ_ACK 0x40
19-
#define CIRQ_MASK_SET 0xc0
20-
#define CIRQ_MASK_CLR 0x100
21-
#define CIRQ_SENS_SET 0x180
22-
#define CIRQ_SENS_CLR 0x1c0
23-
#define CIRQ_POL_SET 0x240
24-
#define CIRQ_POL_CLR 0x280
25-
#define CIRQ_CONTROL 0x300
18+
enum mtk_cirq_regoffs_index {
19+
CIRQ_STA,
20+
CIRQ_ACK,
21+
CIRQ_MASK_SET,
22+
CIRQ_MASK_CLR,
23+
CIRQ_SENS_SET,
24+
CIRQ_SENS_CLR,
25+
CIRQ_POL_SET,
26+
CIRQ_POL_CLR,
27+
CIRQ_CONTROL
28+
};
29+
30+
static const u32 mtk_cirq_regoffs_v1[] = {
31+
[CIRQ_STA] = 0x0,
32+
[CIRQ_ACK] = 0x40,
33+
[CIRQ_MASK_SET] = 0xc0,
34+
[CIRQ_MASK_CLR] = 0x100,
35+
[CIRQ_SENS_SET] = 0x180,
36+
[CIRQ_SENS_CLR] = 0x1c0,
37+
[CIRQ_POL_SET] = 0x240,
38+
[CIRQ_POL_CLR] = 0x280,
39+
[CIRQ_CONTROL] = 0x300,
40+
};
2641

2742
#define CIRQ_EN 0x1
2843
#define CIRQ_EDGE 0x2
@@ -32,18 +47,32 @@ struct mtk_cirq_chip_data {
3247
void __iomem *base;
3348
unsigned int ext_irq_start;
3449
unsigned int ext_irq_end;
50+
const u32 *offsets;
3551
struct irq_domain *domain;
3652
};
3753

3854
static struct mtk_cirq_chip_data *cirq_data;
3955

40-
static void mtk_cirq_write_mask(struct irq_data *data, unsigned int offset)
56+
static void __iomem *mtk_cirq_reg(struct mtk_cirq_chip_data *chip_data,
57+
enum mtk_cirq_regoffs_index idx)
58+
{
59+
return chip_data->base + chip_data->offsets[idx];
60+
}
61+
62+
static void __iomem *mtk_cirq_irq_reg(struct mtk_cirq_chip_data *chip_data,
63+
enum mtk_cirq_regoffs_index idx,
64+
unsigned int cirq_num)
65+
{
66+
return mtk_cirq_reg(chip_data, idx) + (cirq_num / 32) * 4;
67+
}
68+
69+
static void mtk_cirq_write_mask(struct irq_data *data, enum mtk_cirq_regoffs_index idx)
4170
{
4271
struct mtk_cirq_chip_data *chip_data = data->chip_data;
4372
unsigned int cirq_num = data->hwirq;
4473
u32 mask = 1 << (cirq_num % 32);
4574

46-
writel_relaxed(mask, chip_data->base + offset + (cirq_num / 32) * 4);
75+
writel_relaxed(mask, mtk_cirq_irq_reg(chip_data, idx, cirq_num));
4776
}
4877

4978
static void mtk_cirq_mask(struct irq_data *data)
@@ -160,6 +189,7 @@ static const struct irq_domain_ops cirq_domain_ops = {
160189
#ifdef CONFIG_PM_SLEEP
161190
static int mtk_cirq_suspend(void)
162191
{
192+
void __iomem *reg;
163193
u32 value, mask;
164194
unsigned int irq, hwirq_num;
165195
bool pending, masked;
@@ -200,31 +230,34 @@ static int mtk_cirq_suspend(void)
200230
continue;
201231
}
202232

233+
reg = mtk_cirq_irq_reg(cirq_data, CIRQ_ACK, i);
203234
mask = 1 << (i % 32);
204-
writel_relaxed(mask, cirq_data->base + CIRQ_ACK + (i / 32) * 4);
235+
writel_relaxed(mask, reg);
205236
}
206237

207238
/* set edge_only mode, record edge-triggerd interrupts */
208239
/* enable cirq */
209-
value = readl_relaxed(cirq_data->base + CIRQ_CONTROL);
240+
reg = mtk_cirq_reg(cirq_data, CIRQ_CONTROL);
241+
value = readl_relaxed(reg);
210242
value |= (CIRQ_EDGE | CIRQ_EN);
211-
writel_relaxed(value, cirq_data->base + CIRQ_CONTROL);
243+
writel_relaxed(value, reg);
212244

213245
return 0;
214246
}
215247

216248
static void mtk_cirq_resume(void)
217249
{
250+
void __iomem *reg = mtk_cirq_reg(cirq_data, CIRQ_CONTROL);
218251
u32 value;
219252

220253
/* flush recorded interrupts, will send signals to parent controller */
221-
value = readl_relaxed(cirq_data->base + CIRQ_CONTROL);
222-
writel_relaxed(value | CIRQ_FLUSH, cirq_data->base + CIRQ_CONTROL);
254+
value = readl_relaxed(reg);
255+
writel_relaxed(value | CIRQ_FLUSH, reg);
223256

224257
/* disable cirq */
225-
value = readl_relaxed(cirq_data->base + CIRQ_CONTROL);
258+
value = readl_relaxed(reg);
226259
value &= ~(CIRQ_EDGE | CIRQ_EN);
227-
writel_relaxed(value, cirq_data->base + CIRQ_CONTROL);
260+
writel_relaxed(value, reg);
228261
}
229262

230263
static struct syscore_ops mtk_cirq_syscore_ops = {
@@ -240,10 +273,18 @@ static void mtk_cirq_syscore_init(void)
240273
static inline void mtk_cirq_syscore_init(void) {}
241274
#endif
242275

276+
static const struct of_device_id mtk_cirq_of_match[] = {
277+
{ .compatible = "mediatek,mt2701-cirq", .data = &mtk_cirq_regoffs_v1 },
278+
{ .compatible = "mediatek,mt8135-cirq", .data = &mtk_cirq_regoffs_v1 },
279+
{ .compatible = "mediatek,mt8173-cirq", .data = &mtk_cirq_regoffs_v1 },
280+
{ /* sentinel */ }
281+
};
282+
243283
static int __init mtk_cirq_of_init(struct device_node *node,
244284
struct device_node *parent)
245285
{
246286
struct irq_domain *domain, *domain_parent;
287+
const struct of_device_id *match;
247288
unsigned int irq_num;
248289
int ret;
249290

@@ -274,6 +315,13 @@ static int __init mtk_cirq_of_init(struct device_node *node,
274315
if (ret)
275316
goto out_unmap;
276317

318+
match = of_match_node(mtk_cirq_of_match, node);
319+
if (!match) {
320+
ret = -ENODEV;
321+
goto out_unmap;
322+
}
323+
cirq_data->offsets = match->data;
324+
277325
irq_num = cirq_data->ext_irq_end - cirq_data->ext_irq_start + 1;
278326
domain = irq_domain_add_hierarchy(domain_parent, 0,
279327
irq_num, node,

0 commit comments

Comments
 (0)