1 // SPDX-License-Identifier: GPL-2.0
3 #define pr_fmt(fmt) "irq-ls-extirq: " fmt
6 #include <linux/irqchip.h>
7 #include <linux/irqdomain.h>
9 #include <linux/of_address.h>
10 #include <linux/slab.h>
12 #include <dt-bindings/interrupt-controller/arm-gic.h>
15 #define LS1021A_SCFGREVCR 0x200
17 struct ls_extirq_data
{
21 bool is_ls1021a_or_ls1043a
;
23 struct irq_fwspec map
[MAXIRQ
];
26 static void ls_extirq_intpcr_rmw(struct ls_extirq_data
*priv
, u32 mask
,
32 * Serialize concurrent calls to ls_extirq_set_type() from multiple
33 * IRQ descriptors, making sure the read-modify-write is atomic.
35 raw_spin_lock(&priv
->lock
);
38 intpcr
= ioread32be(priv
->intpcr
);
40 intpcr
= ioread32(priv
->intpcr
);
46 iowrite32be(intpcr
, priv
->intpcr
);
48 iowrite32(intpcr
, priv
->intpcr
);
50 raw_spin_unlock(&priv
->lock
);
54 ls_extirq_set_type(struct irq_data
*data
, unsigned int type
)
56 struct ls_extirq_data
*priv
= data
->chip_data
;
57 irq_hw_number_t hwirq
= data
->hwirq
;
60 if (priv
->is_ls1021a_or_ls1043a
)
61 mask
= 1U << (31 - hwirq
);
66 case IRQ_TYPE_LEVEL_LOW
:
67 type
= IRQ_TYPE_LEVEL_HIGH
;
70 case IRQ_TYPE_EDGE_FALLING
:
71 type
= IRQ_TYPE_EDGE_RISING
;
74 case IRQ_TYPE_LEVEL_HIGH
:
75 case IRQ_TYPE_EDGE_RISING
:
82 ls_extirq_intpcr_rmw(priv
, mask
, value
);
84 return irq_chip_set_type_parent(data
, type
);
87 static struct irq_chip ls_extirq_chip
= {
89 .irq_mask
= irq_chip_mask_parent
,
90 .irq_unmask
= irq_chip_unmask_parent
,
91 .irq_eoi
= irq_chip_eoi_parent
,
92 .irq_set_type
= ls_extirq_set_type
,
93 .irq_retrigger
= irq_chip_retrigger_hierarchy
,
94 .irq_set_affinity
= irq_chip_set_affinity_parent
,
95 .flags
= IRQCHIP_SET_TYPE_MASKED
| IRQCHIP_SKIP_SET_WAKE
,
99 ls_extirq_domain_alloc(struct irq_domain
*domain
, unsigned int virq
,
100 unsigned int nr_irqs
, void *arg
)
102 struct ls_extirq_data
*priv
= domain
->host_data
;
103 struct irq_fwspec
*fwspec
= arg
;
104 irq_hw_number_t hwirq
;
106 if (fwspec
->param_count
!= 2)
109 hwirq
= fwspec
->param
[0];
110 if (hwirq
>= priv
->nirq
)
113 irq_domain_set_hwirq_and_chip(domain
, virq
, hwirq
, &ls_extirq_chip
,
116 return irq_domain_alloc_irqs_parent(domain
, virq
, 1, &priv
->map
[hwirq
]);
119 static const struct irq_domain_ops extirq_domain_ops
= {
120 .xlate
= irq_domain_xlate_twocell
,
121 .alloc
= ls_extirq_domain_alloc
,
122 .free
= irq_domain_free_irqs_common
,
126 ls_extirq_parse_map(struct ls_extirq_data
*priv
, struct device_node
*node
)
132 map
= of_get_property(node
, "interrupt-map", &mapsize
);
135 if (mapsize
% sizeof(*map
))
137 mapsize
/= sizeof(*map
);
140 struct device_node
*ipar
;
141 u32 hwirq
, intsize
, j
;
145 hwirq
= be32_to_cpup(map
);
148 priv
->nirq
= max(priv
->nirq
, hwirq
+ 1);
150 ipar
= of_find_node_by_phandle(be32_to_cpup(map
+ 2));
155 priv
->map
[hwirq
].fwnode
= &ipar
->fwnode
;
156 ret
= of_property_read_u32(ipar
, "#interrupt-cells", &intsize
);
160 if (intsize
> mapsize
)
163 priv
->map
[hwirq
].param_count
= intsize
;
164 for (j
= 0; j
< intsize
; ++j
)
165 priv
->map
[hwirq
].param
[j
] = be32_to_cpup(map
++);
172 ls_extirq_of_init(struct device_node
*node
, struct device_node
*parent
)
174 struct irq_domain
*domain
, *parent_domain
;
175 struct ls_extirq_data
*priv
;
178 parent_domain
= irq_find_host(parent
);
179 if (!parent_domain
) {
180 pr_err("Cannot find parent domain\n");
182 goto err_irq_find_host
;
185 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
192 * All extirq OF nodes are under a scfg/syscon node with
193 * the 'ranges' property
195 priv
->intpcr
= of_iomap(node
, 0);
197 pr_err("Cannot ioremap OF node %pOF\n", node
);
202 ret
= ls_extirq_parse_map(priv
, node
);
206 priv
->big_endian
= of_device_is_big_endian(node
->parent
);
207 priv
->is_ls1021a_or_ls1043a
= of_device_is_compatible(node
, "fsl,ls1021a-extirq") ||
208 of_device_is_compatible(node
, "fsl,ls1043a-extirq");
209 raw_spin_lock_init(&priv
->lock
);
211 domain
= irq_domain_add_hierarchy(parent_domain
, 0, priv
->nirq
, node
,
212 &extirq_domain_ops
, priv
);
215 goto err_add_hierarchy
;
222 iounmap(priv
->intpcr
);
230 IRQCHIP_DECLARE(ls1021a_extirq
, "fsl,ls1021a-extirq", ls_extirq_of_init
);
231 IRQCHIP_DECLARE(ls1043a_extirq
, "fsl,ls1043a-extirq", ls_extirq_of_init
);
232 IRQCHIP_DECLARE(ls1088a_extirq
, "fsl,ls1088a-extirq", ls_extirq_of_init
);