1f55c73aeSArchana Sathyakumar // SPDX-License-Identifier: GPL-2.0
2f55c73aeSArchana Sathyakumar /*
3b2bb01edSLina Iyer * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
4f55c73aeSArchana Sathyakumar */
5f55c73aeSArchana Sathyakumar
6f55c73aeSArchana Sathyakumar #include <linux/err.h>
7f55c73aeSArchana Sathyakumar #include <linux/init.h>
8e71374c0SMaulik Shah #include <linux/interrupt.h>
9f55c73aeSArchana Sathyakumar #include <linux/irq.h>
10f55c73aeSArchana Sathyakumar #include <linux/irqchip.h>
11f55c73aeSArchana Sathyakumar #include <linux/irqdomain.h>
12f55c73aeSArchana Sathyakumar #include <linux/io.h>
13f55c73aeSArchana Sathyakumar #include <linux/kernel.h>
144acd8a4bSSaravana Kannan #include <linux/module.h>
15f55c73aeSArchana Sathyakumar #include <linux/of.h>
16f55c73aeSArchana Sathyakumar #include <linux/of_address.h>
174acd8a4bSSaravana Kannan #include <linux/of_irq.h>
1881ef8bf8SLina Iyer #include <linux/soc/qcom/irq.h>
19f55c73aeSArchana Sathyakumar #include <linux/spinlock.h>
20f55c73aeSArchana Sathyakumar #include <linux/slab.h>
21f55c73aeSArchana Sathyakumar #include <linux/types.h>
22f55c73aeSArchana Sathyakumar
2381ef8bf8SLina Iyer #define PDC_MAX_GPIO_IRQS 256
24f55c73aeSArchana Sathyakumar
25*5873d380SNeil Armstrong /* Valid only on HW version < 3.2 */
26f55c73aeSArchana Sathyakumar #define IRQ_ENABLE_BANK 0x10
27f55c73aeSArchana Sathyakumar #define IRQ_i_CFG 0x110
28f55c73aeSArchana Sathyakumar
29*5873d380SNeil Armstrong /* Valid only on HW version >= 3.2 */
30*5873d380SNeil Armstrong #define IRQ_i_CFG_IRQ_ENABLE 3
31*5873d380SNeil Armstrong
32*5873d380SNeil Armstrong #define IRQ_i_CFG_TYPE_MASK GENMASK(2, 0)
33*5873d380SNeil Armstrong
34*5873d380SNeil Armstrong #define PDC_VERSION_REG 0x1000
35*5873d380SNeil Armstrong
36*5873d380SNeil Armstrong /* Notable PDC versions */
37*5873d380SNeil Armstrong #define PDC_VERSION_3_2 0x30200
38*5873d380SNeil Armstrong
39f55c73aeSArchana Sathyakumar struct pdc_pin_region {
40f55c73aeSArchana Sathyakumar u32 pin_base;
41f55c73aeSArchana Sathyakumar u32 parent_base;
42f55c73aeSArchana Sathyakumar u32 cnt;
43f55c73aeSArchana Sathyakumar };
44f55c73aeSArchana Sathyakumar
458d4c9989SMarc Zyngier #define pin_to_hwirq(r, p) ((r)->parent_base + (p) - (r)->pin_base)
468d4c9989SMarc Zyngier
47f55c73aeSArchana Sathyakumar static DEFINE_RAW_SPINLOCK(pdc_lock);
48f55c73aeSArchana Sathyakumar static void __iomem *pdc_base;
49f55c73aeSArchana Sathyakumar static struct pdc_pin_region *pdc_region;
50f55c73aeSArchana Sathyakumar static int pdc_region_cnt;
51*5873d380SNeil Armstrong static unsigned int pdc_version;
52f55c73aeSArchana Sathyakumar
pdc_reg_write(int reg,u32 i,u32 val)53f55c73aeSArchana Sathyakumar static void pdc_reg_write(int reg, u32 i, u32 val)
54f55c73aeSArchana Sathyakumar {
55f55c73aeSArchana Sathyakumar writel_relaxed(val, pdc_base + reg + i * sizeof(u32));
56f55c73aeSArchana Sathyakumar }
57f55c73aeSArchana Sathyakumar
pdc_reg_read(int reg,u32 i)58f55c73aeSArchana Sathyakumar static u32 pdc_reg_read(int reg, u32 i)
59f55c73aeSArchana Sathyakumar {
60f55c73aeSArchana Sathyakumar return readl_relaxed(pdc_base + reg + i * sizeof(u32));
61f55c73aeSArchana Sathyakumar }
62f55c73aeSArchana Sathyakumar
__pdc_enable_intr(int pin_out,bool on)63*5873d380SNeil Armstrong static void __pdc_enable_intr(int pin_out, bool on)
64f55c73aeSArchana Sathyakumar {
65d2febf6bSMarc Zyngier unsigned long enable;
66*5873d380SNeil Armstrong
67*5873d380SNeil Armstrong if (pdc_version < PDC_VERSION_3_2) {
68f55c73aeSArchana Sathyakumar u32 index, mask;
69f55c73aeSArchana Sathyakumar
70f55c73aeSArchana Sathyakumar index = pin_out / 32;
71f55c73aeSArchana Sathyakumar mask = pin_out % 32;
72f55c73aeSArchana Sathyakumar
73f55c73aeSArchana Sathyakumar enable = pdc_reg_read(IRQ_ENABLE_BANK, index);
74d2febf6bSMarc Zyngier __assign_bit(mask, &enable, on);
75f55c73aeSArchana Sathyakumar pdc_reg_write(IRQ_ENABLE_BANK, index, enable);
76*5873d380SNeil Armstrong } else {
77*5873d380SNeil Armstrong enable = pdc_reg_read(IRQ_i_CFG, pin_out);
78*5873d380SNeil Armstrong __assign_bit(IRQ_i_CFG_IRQ_ENABLE, &enable, on);
79*5873d380SNeil Armstrong pdc_reg_write(IRQ_i_CFG, pin_out, enable);
80*5873d380SNeil Armstrong }
81*5873d380SNeil Armstrong }
82*5873d380SNeil Armstrong
pdc_enable_intr(struct irq_data * d,bool on)83*5873d380SNeil Armstrong static void pdc_enable_intr(struct irq_data *d, bool on)
84*5873d380SNeil Armstrong {
85*5873d380SNeil Armstrong unsigned long flags;
86*5873d380SNeil Armstrong
87*5873d380SNeil Armstrong raw_spin_lock_irqsave(&pdc_lock, flags);
88*5873d380SNeil Armstrong __pdc_enable_intr(d->hwirq, on);
89a6aca2f4SMarc Zyngier raw_spin_unlock_irqrestore(&pdc_lock, flags);
90f55c73aeSArchana Sathyakumar }
91f55c73aeSArchana Sathyakumar
qcom_pdc_gic_disable(struct irq_data * d)92da3f875aSLina Iyer static void qcom_pdc_gic_disable(struct irq_data *d)
93f55c73aeSArchana Sathyakumar {
94f55c73aeSArchana Sathyakumar pdc_enable_intr(d, false);
95da3f875aSLina Iyer irq_chip_disable_parent(d);
96da3f875aSLina Iyer }
97da3f875aSLina Iyer
qcom_pdc_gic_enable(struct irq_data * d)98da3f875aSLina Iyer static void qcom_pdc_gic_enable(struct irq_data *d)
99da3f875aSLina Iyer {
100da3f875aSLina Iyer pdc_enable_intr(d, true);
101da3f875aSLina Iyer irq_chip_enable_parent(d);
102da3f875aSLina Iyer }
103da3f875aSLina Iyer
104f55c73aeSArchana Sathyakumar /*
105f55c73aeSArchana Sathyakumar * GIC does not handle falling edge or active low. To allow falling edge and
106f55c73aeSArchana Sathyakumar * active low interrupts to be handled at GIC, PDC has an inverter that inverts
107f55c73aeSArchana Sathyakumar * falling edge into a rising edge and active low into an active high.
108f55c73aeSArchana Sathyakumar * For the inverter to work, the polarity bit in the IRQ_CONFIG register has to
109f55c73aeSArchana Sathyakumar * set as per the table below.
110f55c73aeSArchana Sathyakumar * Level sensitive active low LOW
111f55c73aeSArchana Sathyakumar * Rising edge sensitive NOT USED
112f55c73aeSArchana Sathyakumar * Falling edge sensitive LOW
113f55c73aeSArchana Sathyakumar * Dual Edge sensitive NOT USED
114f55c73aeSArchana Sathyakumar * Level sensitive active High HIGH
115f55c73aeSArchana Sathyakumar * Falling Edge sensitive NOT USED
116f55c73aeSArchana Sathyakumar * Rising edge sensitive HIGH
117f55c73aeSArchana Sathyakumar * Dual Edge sensitive HIGH
118f55c73aeSArchana Sathyakumar */
119f55c73aeSArchana Sathyakumar enum pdc_irq_config_bits {
120f55c73aeSArchana Sathyakumar PDC_LEVEL_LOW = 0b000,
121f55c73aeSArchana Sathyakumar PDC_EDGE_FALLING = 0b010,
122f55c73aeSArchana Sathyakumar PDC_LEVEL_HIGH = 0b100,
123f55c73aeSArchana Sathyakumar PDC_EDGE_RISING = 0b110,
124f55c73aeSArchana Sathyakumar PDC_EDGE_DUAL = 0b111,
125f55c73aeSArchana Sathyakumar };
126f55c73aeSArchana Sathyakumar
127f55c73aeSArchana Sathyakumar /**
128f55c73aeSArchana Sathyakumar * qcom_pdc_gic_set_type: Configure PDC for the interrupt
129f55c73aeSArchana Sathyakumar *
130f55c73aeSArchana Sathyakumar * @d: the interrupt data
131f55c73aeSArchana Sathyakumar * @type: the interrupt type
132f55c73aeSArchana Sathyakumar *
133f55c73aeSArchana Sathyakumar * If @type is edge triggered, forward that as Rising edge as PDC
134f55c73aeSArchana Sathyakumar * takes care of converting falling edge to rising edge signal
135f55c73aeSArchana Sathyakumar * If @type is level, then forward that as level high as PDC
136f55c73aeSArchana Sathyakumar * takes care of converting falling edge to rising edge signal
137f55c73aeSArchana Sathyakumar */
qcom_pdc_gic_set_type(struct irq_data * d,unsigned int type)138f55c73aeSArchana Sathyakumar static int qcom_pdc_gic_set_type(struct irq_data *d, unsigned int type)
139f55c73aeSArchana Sathyakumar {
140f55c73aeSArchana Sathyakumar enum pdc_irq_config_bits pdc_type;
1412f5fbc43SDouglas Anderson enum pdc_irq_config_bits old_pdc_type;
1422f5fbc43SDouglas Anderson int ret;
143f55c73aeSArchana Sathyakumar
144f55c73aeSArchana Sathyakumar switch (type) {
145f55c73aeSArchana Sathyakumar case IRQ_TYPE_EDGE_RISING:
146f55c73aeSArchana Sathyakumar pdc_type = PDC_EDGE_RISING;
147f55c73aeSArchana Sathyakumar break;
148f55c73aeSArchana Sathyakumar case IRQ_TYPE_EDGE_FALLING:
149f55c73aeSArchana Sathyakumar pdc_type = PDC_EDGE_FALLING;
150f55c73aeSArchana Sathyakumar type = IRQ_TYPE_EDGE_RISING;
151f55c73aeSArchana Sathyakumar break;
152f55c73aeSArchana Sathyakumar case IRQ_TYPE_EDGE_BOTH:
153f55c73aeSArchana Sathyakumar pdc_type = PDC_EDGE_DUAL;
1547bae48b2SLina Iyer type = IRQ_TYPE_EDGE_RISING;
155f55c73aeSArchana Sathyakumar break;
156f55c73aeSArchana Sathyakumar case IRQ_TYPE_LEVEL_HIGH:
157f55c73aeSArchana Sathyakumar pdc_type = PDC_LEVEL_HIGH;
158f55c73aeSArchana Sathyakumar break;
159f55c73aeSArchana Sathyakumar case IRQ_TYPE_LEVEL_LOW:
160f55c73aeSArchana Sathyakumar pdc_type = PDC_LEVEL_LOW;
161f55c73aeSArchana Sathyakumar type = IRQ_TYPE_LEVEL_HIGH;
162f55c73aeSArchana Sathyakumar break;
163f55c73aeSArchana Sathyakumar default:
164f55c73aeSArchana Sathyakumar WARN_ON(1);
165f55c73aeSArchana Sathyakumar return -EINVAL;
166f55c73aeSArchana Sathyakumar }
167f55c73aeSArchana Sathyakumar
1689d4f24bfSMarc Zyngier old_pdc_type = pdc_reg_read(IRQ_i_CFG, d->hwirq);
169*5873d380SNeil Armstrong pdc_type |= (old_pdc_type & ~IRQ_i_CFG_TYPE_MASK);
1709d4f24bfSMarc Zyngier pdc_reg_write(IRQ_i_CFG, d->hwirq, pdc_type);
171f55c73aeSArchana Sathyakumar
1722f5fbc43SDouglas Anderson ret = irq_chip_set_type_parent(d, type);
1732f5fbc43SDouglas Anderson if (ret)
1742f5fbc43SDouglas Anderson return ret;
1752f5fbc43SDouglas Anderson
1762f5fbc43SDouglas Anderson /*
1772f5fbc43SDouglas Anderson * When we change types the PDC can give a phantom interrupt.
1782f5fbc43SDouglas Anderson * Clear it. Specifically the phantom shows up when reconfiguring
1792f5fbc43SDouglas Anderson * polarity of interrupt without changing the state of the signal
1802f5fbc43SDouglas Anderson * but let's be consistent and clear it always.
1812f5fbc43SDouglas Anderson *
1822f5fbc43SDouglas Anderson * Doing this works because we have IRQCHIP_SET_TYPE_MASKED so the
1832f5fbc43SDouglas Anderson * interrupt will be cleared before the rest of the system sees it.
1842f5fbc43SDouglas Anderson */
1852f5fbc43SDouglas Anderson if (old_pdc_type != pdc_type)
1862f5fbc43SDouglas Anderson irq_chip_set_parent_state(d, IRQCHIP_STATE_PENDING, false);
1872f5fbc43SDouglas Anderson
1882f5fbc43SDouglas Anderson return 0;
189f55c73aeSArchana Sathyakumar }
190f55c73aeSArchana Sathyakumar
191f55c73aeSArchana Sathyakumar static struct irq_chip qcom_pdc_gic_chip = {
192f55c73aeSArchana Sathyakumar .name = "PDC",
193f55c73aeSArchana Sathyakumar .irq_eoi = irq_chip_eoi_parent,
1949d4f24bfSMarc Zyngier .irq_mask = irq_chip_mask_parent,
1959d4f24bfSMarc Zyngier .irq_unmask = irq_chip_unmask_parent,
196da3f875aSLina Iyer .irq_disable = qcom_pdc_gic_disable,
197da3f875aSLina Iyer .irq_enable = qcom_pdc_gic_enable,
1989d4f24bfSMarc Zyngier .irq_get_irqchip_state = irq_chip_get_parent_state,
1999d4f24bfSMarc Zyngier .irq_set_irqchip_state = irq_chip_set_parent_state,
200f55c73aeSArchana Sathyakumar .irq_retrigger = irq_chip_retrigger_hierarchy,
201f55c73aeSArchana Sathyakumar .irq_set_type = qcom_pdc_gic_set_type,
202f55c73aeSArchana Sathyakumar .flags = IRQCHIP_MASK_ON_SUSPEND |
203f55c73aeSArchana Sathyakumar IRQCHIP_SET_TYPE_MASKED |
204299d7890SMaulik Shah IRQCHIP_SKIP_SET_WAKE |
205299d7890SMaulik Shah IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND,
206f55c73aeSArchana Sathyakumar .irq_set_vcpu_affinity = irq_chip_set_vcpu_affinity_parent,
207f55c73aeSArchana Sathyakumar .irq_set_affinity = irq_chip_set_affinity_parent,
208f55c73aeSArchana Sathyakumar };
209f55c73aeSArchana Sathyakumar
get_pin_region(int pin)2108d4c9989SMarc Zyngier static struct pdc_pin_region *get_pin_region(int pin)
211f55c73aeSArchana Sathyakumar {
212f55c73aeSArchana Sathyakumar int i;
213f55c73aeSArchana Sathyakumar
214f55c73aeSArchana Sathyakumar for (i = 0; i < pdc_region_cnt; i++) {
2158d4c9989SMarc Zyngier if (pin >= pdc_region[i].pin_base &&
2168d4c9989SMarc Zyngier pin < pdc_region[i].pin_base + pdc_region[i].cnt)
2178d4c9989SMarc Zyngier return &pdc_region[i];
218f55c73aeSArchana Sathyakumar }
219f55c73aeSArchana Sathyakumar
2208d4c9989SMarc Zyngier return NULL;
221f55c73aeSArchana Sathyakumar }
222f55c73aeSArchana Sathyakumar
qcom_pdc_alloc(struct irq_domain * domain,unsigned int virq,unsigned int nr_irqs,void * data)223f55c73aeSArchana Sathyakumar static int qcom_pdc_alloc(struct irq_domain *domain, unsigned int virq,
224f55c73aeSArchana Sathyakumar unsigned int nr_irqs, void *data)
225f55c73aeSArchana Sathyakumar {
226f55c73aeSArchana Sathyakumar struct irq_fwspec *fwspec = data;
227f55c73aeSArchana Sathyakumar struct irq_fwspec parent_fwspec;
2288d4c9989SMarc Zyngier struct pdc_pin_region *region;
2298d4c9989SMarc Zyngier irq_hw_number_t hwirq;
230f55c73aeSArchana Sathyakumar unsigned int type;
231f55c73aeSArchana Sathyakumar int ret;
232f55c73aeSArchana Sathyakumar
233d494d088SMarc Zyngier ret = irq_domain_translate_twocell(domain, fwspec, &hwirq, &type);
234f55c73aeSArchana Sathyakumar if (ret)
23581ef8bf8SLina Iyer return ret;
236f55c73aeSArchana Sathyakumar
2379d4f24bfSMarc Zyngier if (hwirq == GPIO_NO_WAKE_IRQ)
2389d4f24bfSMarc Zyngier return irq_domain_disconnect_hierarchy(domain, virq);
2399d4f24bfSMarc Zyngier
24081ef8bf8SLina Iyer ret = irq_domain_set_hwirq_and_chip(domain, virq, hwirq,
24181ef8bf8SLina Iyer &qcom_pdc_gic_chip, NULL);
24281ef8bf8SLina Iyer if (ret)
24381ef8bf8SLina Iyer return ret;
24481ef8bf8SLina Iyer
2458d4c9989SMarc Zyngier region = get_pin_region(hwirq);
2468d4c9989SMarc Zyngier if (!region)
2479d4f24bfSMarc Zyngier return irq_domain_disconnect_hierarchy(domain->parent, virq);
24881ef8bf8SLina Iyer
24981ef8bf8SLina Iyer if (type & IRQ_TYPE_EDGE_BOTH)
25081ef8bf8SLina Iyer type = IRQ_TYPE_EDGE_RISING;
25181ef8bf8SLina Iyer
25281ef8bf8SLina Iyer if (type & IRQ_TYPE_LEVEL_MASK)
25381ef8bf8SLina Iyer type = IRQ_TYPE_LEVEL_HIGH;
25481ef8bf8SLina Iyer
25581ef8bf8SLina Iyer parent_fwspec.fwnode = domain->parent->fwnode;
25681ef8bf8SLina Iyer parent_fwspec.param_count = 3;
25781ef8bf8SLina Iyer parent_fwspec.param[0] = 0;
2588d4c9989SMarc Zyngier parent_fwspec.param[1] = pin_to_hwirq(region, hwirq);
25981ef8bf8SLina Iyer parent_fwspec.param[2] = type;
26081ef8bf8SLina Iyer
26181ef8bf8SLina Iyer return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs,
26281ef8bf8SLina Iyer &parent_fwspec);
26381ef8bf8SLina Iyer }
26481ef8bf8SLina Iyer
2654dc70713SMarc Zyngier static const struct irq_domain_ops qcom_pdc_ops = {
266d494d088SMarc Zyngier .translate = irq_domain_translate_twocell,
2674dc70713SMarc Zyngier .alloc = qcom_pdc_alloc,
26881ef8bf8SLina Iyer .free = irq_domain_free_irqs_common,
26981ef8bf8SLina Iyer };
27081ef8bf8SLina Iyer
pdc_setup_pin_mapping(struct device_node * np)271f55c73aeSArchana Sathyakumar static int pdc_setup_pin_mapping(struct device_node *np)
272f55c73aeSArchana Sathyakumar {
273d7bc63faSMaulik Shah int ret, n, i;
274f55c73aeSArchana Sathyakumar
275f55c73aeSArchana Sathyakumar n = of_property_count_elems_of_size(np, "qcom,pdc-ranges", sizeof(u32));
276f55c73aeSArchana Sathyakumar if (n <= 0 || n % 3)
277f55c73aeSArchana Sathyakumar return -EINVAL;
278f55c73aeSArchana Sathyakumar
279f55c73aeSArchana Sathyakumar pdc_region_cnt = n / 3;
280f55c73aeSArchana Sathyakumar pdc_region = kcalloc(pdc_region_cnt, sizeof(*pdc_region), GFP_KERNEL);
281f55c73aeSArchana Sathyakumar if (!pdc_region) {
282f55c73aeSArchana Sathyakumar pdc_region_cnt = 0;
283f55c73aeSArchana Sathyakumar return -ENOMEM;
284f55c73aeSArchana Sathyakumar }
285f55c73aeSArchana Sathyakumar
286f55c73aeSArchana Sathyakumar for (n = 0; n < pdc_region_cnt; n++) {
287f55c73aeSArchana Sathyakumar ret = of_property_read_u32_index(np, "qcom,pdc-ranges",
288f55c73aeSArchana Sathyakumar n * 3 + 0,
289f55c73aeSArchana Sathyakumar &pdc_region[n].pin_base);
290f55c73aeSArchana Sathyakumar if (ret)
291f55c73aeSArchana Sathyakumar return ret;
292f55c73aeSArchana Sathyakumar ret = of_property_read_u32_index(np, "qcom,pdc-ranges",
293f55c73aeSArchana Sathyakumar n * 3 + 1,
294f55c73aeSArchana Sathyakumar &pdc_region[n].parent_base);
295f55c73aeSArchana Sathyakumar if (ret)
296f55c73aeSArchana Sathyakumar return ret;
297f55c73aeSArchana Sathyakumar ret = of_property_read_u32_index(np, "qcom,pdc-ranges",
298f55c73aeSArchana Sathyakumar n * 3 + 2,
299f55c73aeSArchana Sathyakumar &pdc_region[n].cnt);
300f55c73aeSArchana Sathyakumar if (ret)
301f55c73aeSArchana Sathyakumar return ret;
302d7bc63faSMaulik Shah
303*5873d380SNeil Armstrong for (i = 0; i < pdc_region[n].cnt; i++)
304*5873d380SNeil Armstrong __pdc_enable_intr(i + pdc_region[n].pin_base, 0);
305f55c73aeSArchana Sathyakumar }
306f55c73aeSArchana Sathyakumar
307f55c73aeSArchana Sathyakumar return 0;
308f55c73aeSArchana Sathyakumar }
309f55c73aeSArchana Sathyakumar
310*5873d380SNeil Armstrong #define QCOM_PDC_SIZE 0x30000
311*5873d380SNeil Armstrong
qcom_pdc_init(struct device_node * node,struct device_node * parent)312f55c73aeSArchana Sathyakumar static int qcom_pdc_init(struct device_node *node, struct device_node *parent)
313f55c73aeSArchana Sathyakumar {
3144dc70713SMarc Zyngier struct irq_domain *parent_domain, *pdc_domain;
315*5873d380SNeil Armstrong resource_size_t res_size;
316*5873d380SNeil Armstrong struct resource res;
317f55c73aeSArchana Sathyakumar int ret;
318f55c73aeSArchana Sathyakumar
319*5873d380SNeil Armstrong /* compat with old sm8150 DT which had very small region for PDC */
320*5873d380SNeil Armstrong if (of_address_to_resource(node, 0, &res))
321*5873d380SNeil Armstrong return -EINVAL;
322*5873d380SNeil Armstrong
323*5873d380SNeil Armstrong res_size = max_t(resource_size_t, resource_size(&res), QCOM_PDC_SIZE);
324*5873d380SNeil Armstrong if (res_size > resource_size(&res))
325*5873d380SNeil Armstrong pr_warn("%pOF: invalid reg size, please fix DT\n", node);
326*5873d380SNeil Armstrong
327*5873d380SNeil Armstrong pdc_base = ioremap(res.start, res_size);
328f55c73aeSArchana Sathyakumar if (!pdc_base) {
329f55c73aeSArchana Sathyakumar pr_err("%pOF: unable to map PDC registers\n", node);
330f55c73aeSArchana Sathyakumar return -ENXIO;
331f55c73aeSArchana Sathyakumar }
332f55c73aeSArchana Sathyakumar
333*5873d380SNeil Armstrong pdc_version = pdc_reg_read(PDC_VERSION_REG, 0);
334*5873d380SNeil Armstrong
335f55c73aeSArchana Sathyakumar parent_domain = irq_find_host(parent);
336f55c73aeSArchana Sathyakumar if (!parent_domain) {
337f55c73aeSArchana Sathyakumar pr_err("%pOF: unable to find PDC's parent domain\n", node);
338f55c73aeSArchana Sathyakumar ret = -ENXIO;
339f55c73aeSArchana Sathyakumar goto fail;
340f55c73aeSArchana Sathyakumar }
341f55c73aeSArchana Sathyakumar
342f55c73aeSArchana Sathyakumar ret = pdc_setup_pin_mapping(node);
343f55c73aeSArchana Sathyakumar if (ret) {
344f55c73aeSArchana Sathyakumar pr_err("%pOF: failed to init PDC pin-hwirq mapping\n", node);
345f55c73aeSArchana Sathyakumar goto fail;
346f55c73aeSArchana Sathyakumar }
347f55c73aeSArchana Sathyakumar
3484dc70713SMarc Zyngier pdc_domain = irq_domain_create_hierarchy(parent_domain,
3494dc70713SMarc Zyngier IRQ_DOMAIN_FLAG_QCOM_PDC_WAKEUP,
3504dc70713SMarc Zyngier PDC_MAX_GPIO_IRQS,
351f55c73aeSArchana Sathyakumar of_fwnode_handle(node),
352f55c73aeSArchana Sathyakumar &qcom_pdc_ops, NULL);
353f55c73aeSArchana Sathyakumar if (!pdc_domain) {
3544dc70713SMarc Zyngier pr_err("%pOF: PDC domain add failed\n", node);
355f55c73aeSArchana Sathyakumar ret = -ENOMEM;
356f55c73aeSArchana Sathyakumar goto fail;
357f55c73aeSArchana Sathyakumar }
358f55c73aeSArchana Sathyakumar
3594dc70713SMarc Zyngier irq_domain_update_bus_token(pdc_domain, DOMAIN_BUS_WAKEUP);
36081ef8bf8SLina Iyer
361f55c73aeSArchana Sathyakumar return 0;
362f55c73aeSArchana Sathyakumar
363f55c73aeSArchana Sathyakumar fail:
364f55c73aeSArchana Sathyakumar kfree(pdc_region);
365f55c73aeSArchana Sathyakumar iounmap(pdc_base);
366f55c73aeSArchana Sathyakumar return ret;
367f55c73aeSArchana Sathyakumar }
368f55c73aeSArchana Sathyakumar
3694acd8a4bSSaravana Kannan IRQCHIP_PLATFORM_DRIVER_BEGIN(qcom_pdc)
3704acd8a4bSSaravana Kannan IRQCHIP_MATCH("qcom,pdc", qcom_pdc_init)
3714acd8a4bSSaravana Kannan IRQCHIP_PLATFORM_DRIVER_END(qcom_pdc)
3724acd8a4bSSaravana Kannan MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Power Domain Controller");
3734acd8a4bSSaravana Kannan MODULE_LICENSE("GPL v2");
374