1fa74a025SManivannan Sadhasivam // SPDX-License-Identifier: GPL-2.0-only
2fa74a025SManivannan Sadhasivam /*
3fa74a025SManivannan Sadhasivam * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
4fa74a025SManivannan Sadhasivam */
5fa74a025SManivannan Sadhasivam
6fa74a025SManivannan Sadhasivam #include <linux/bitfield.h>
7fa74a025SManivannan Sadhasivam #include <linux/interrupt.h>
8fa74a025SManivannan Sadhasivam #include <linux/irq.h>
9fa74a025SManivannan Sadhasivam #include <linux/irqdomain.h>
10fa74a025SManivannan Sadhasivam #include <linux/mailbox_controller.h>
11fa74a025SManivannan Sadhasivam #include <linux/module.h>
12fa74a025SManivannan Sadhasivam #include <linux/platform_device.h>
13fa74a025SManivannan Sadhasivam
14fa74a025SManivannan Sadhasivam #include <dt-bindings/mailbox/qcom-ipcc.h>
15fa74a025SManivannan Sadhasivam
16fa74a025SManivannan Sadhasivam /* IPCC Register offsets */
17fa74a025SManivannan Sadhasivam #define IPCC_REG_SEND_ID 0x0c
18fa74a025SManivannan Sadhasivam #define IPCC_REG_RECV_ID 0x10
19fa74a025SManivannan Sadhasivam #define IPCC_REG_RECV_SIGNAL_ENABLE 0x14
20fa74a025SManivannan Sadhasivam #define IPCC_REG_RECV_SIGNAL_DISABLE 0x18
21fa74a025SManivannan Sadhasivam #define IPCC_REG_RECV_SIGNAL_CLEAR 0x1c
22fa74a025SManivannan Sadhasivam #define IPCC_REG_CLIENT_CLEAR 0x38
23fa74a025SManivannan Sadhasivam
24fa74a025SManivannan Sadhasivam #define IPCC_SIGNAL_ID_MASK GENMASK(15, 0)
25fa74a025SManivannan Sadhasivam #define IPCC_CLIENT_ID_MASK GENMASK(31, 16)
26fa74a025SManivannan Sadhasivam
27fa74a025SManivannan Sadhasivam #define IPCC_NO_PENDING_IRQ GENMASK(31, 0)
28fa74a025SManivannan Sadhasivam
29fa74a025SManivannan Sadhasivam /**
30fa74a025SManivannan Sadhasivam * struct qcom_ipcc_chan_info - Per-mailbox-channel info
31fa74a025SManivannan Sadhasivam * @client_id: The client-id to which the interrupt has to be triggered
32fa74a025SManivannan Sadhasivam * @signal_id: The signal-id to which the interrupt has to be triggered
33fa74a025SManivannan Sadhasivam */
34fa74a025SManivannan Sadhasivam struct qcom_ipcc_chan_info {
35fa74a025SManivannan Sadhasivam u16 client_id;
36fa74a025SManivannan Sadhasivam u16 signal_id;
37fa74a025SManivannan Sadhasivam };
38fa74a025SManivannan Sadhasivam
39fa74a025SManivannan Sadhasivam /**
40fa74a025SManivannan Sadhasivam * struct qcom_ipcc - Holder for the mailbox driver
41fa74a025SManivannan Sadhasivam * @dev: Device associated with this instance
42fa74a025SManivannan Sadhasivam * @base: Base address of the IPCC frame associated to APSS
43fa74a025SManivannan Sadhasivam * @irq_domain: The irq_domain associated with this instance
44a022c7c9SKrzysztof Kozlowski * @chans: The mailbox channels array
45fa74a025SManivannan Sadhasivam * @mchan: The per-mailbox channel info array
46fa74a025SManivannan Sadhasivam * @mbox: The mailbox controller
47a022c7c9SKrzysztof Kozlowski * @num_chans: Number of @chans elements
48fa74a025SManivannan Sadhasivam * @irq: Summary irq
49fa74a025SManivannan Sadhasivam */
50fa74a025SManivannan Sadhasivam struct qcom_ipcc {
51fa74a025SManivannan Sadhasivam struct device *dev;
52fa74a025SManivannan Sadhasivam void __iomem *base;
53fa74a025SManivannan Sadhasivam struct irq_domain *irq_domain;
54e9d50e4bSHuang Yiwei struct mbox_chan *chans;
55e9d50e4bSHuang Yiwei struct qcom_ipcc_chan_info *mchan;
56fa74a025SManivannan Sadhasivam struct mbox_controller mbox;
57e9d50e4bSHuang Yiwei int num_chans;
58fa74a025SManivannan Sadhasivam int irq;
59fa74a025SManivannan Sadhasivam };
60fa74a025SManivannan Sadhasivam
to_qcom_ipcc(struct mbox_controller * mbox)61fa74a025SManivannan Sadhasivam static inline struct qcom_ipcc *to_qcom_ipcc(struct mbox_controller *mbox)
62fa74a025SManivannan Sadhasivam {
63fa74a025SManivannan Sadhasivam return container_of(mbox, struct qcom_ipcc, mbox);
64fa74a025SManivannan Sadhasivam }
65fa74a025SManivannan Sadhasivam
qcom_ipcc_get_hwirq(u16 client_id,u16 signal_id)66fa74a025SManivannan Sadhasivam static inline u32 qcom_ipcc_get_hwirq(u16 client_id, u16 signal_id)
67fa74a025SManivannan Sadhasivam {
68fa74a025SManivannan Sadhasivam return FIELD_PREP(IPCC_CLIENT_ID_MASK, client_id) |
69fa74a025SManivannan Sadhasivam FIELD_PREP(IPCC_SIGNAL_ID_MASK, signal_id);
70fa74a025SManivannan Sadhasivam }
71fa74a025SManivannan Sadhasivam
qcom_ipcc_irq_fn(int irq,void * data)72fa74a025SManivannan Sadhasivam static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data)
73fa74a025SManivannan Sadhasivam {
74fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc = data;
75fa74a025SManivannan Sadhasivam u32 hwirq;
76fa74a025SManivannan Sadhasivam int virq;
77fa74a025SManivannan Sadhasivam
78fa74a025SManivannan Sadhasivam for (;;) {
79fa74a025SManivannan Sadhasivam hwirq = readl(ipcc->base + IPCC_REG_RECV_ID);
80fa74a025SManivannan Sadhasivam if (hwirq == IPCC_NO_PENDING_IRQ)
81fa74a025SManivannan Sadhasivam break;
82fa74a025SManivannan Sadhasivam
83fa74a025SManivannan Sadhasivam virq = irq_find_mapping(ipcc->irq_domain, hwirq);
84fa74a025SManivannan Sadhasivam writel(hwirq, ipcc->base + IPCC_REG_RECV_SIGNAL_CLEAR);
85fa74a025SManivannan Sadhasivam generic_handle_irq(virq);
86fa74a025SManivannan Sadhasivam }
87fa74a025SManivannan Sadhasivam
88fa74a025SManivannan Sadhasivam return IRQ_HANDLED;
89fa74a025SManivannan Sadhasivam }
90fa74a025SManivannan Sadhasivam
qcom_ipcc_mask_irq(struct irq_data * irqd)91fa74a025SManivannan Sadhasivam static void qcom_ipcc_mask_irq(struct irq_data *irqd)
92fa74a025SManivannan Sadhasivam {
93fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc = irq_data_get_irq_chip_data(irqd);
94fa74a025SManivannan Sadhasivam irq_hw_number_t hwirq = irqd_to_hwirq(irqd);
95fa74a025SManivannan Sadhasivam
96fa74a025SManivannan Sadhasivam writel(hwirq, ipcc->base + IPCC_REG_RECV_SIGNAL_DISABLE);
97fa74a025SManivannan Sadhasivam }
98fa74a025SManivannan Sadhasivam
qcom_ipcc_unmask_irq(struct irq_data * irqd)99fa74a025SManivannan Sadhasivam static void qcom_ipcc_unmask_irq(struct irq_data *irqd)
100fa74a025SManivannan Sadhasivam {
101fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc = irq_data_get_irq_chip_data(irqd);
102fa74a025SManivannan Sadhasivam irq_hw_number_t hwirq = irqd_to_hwirq(irqd);
103fa74a025SManivannan Sadhasivam
104fa74a025SManivannan Sadhasivam writel(hwirq, ipcc->base + IPCC_REG_RECV_SIGNAL_ENABLE);
105fa74a025SManivannan Sadhasivam }
106fa74a025SManivannan Sadhasivam
107fa74a025SManivannan Sadhasivam static struct irq_chip qcom_ipcc_irq_chip = {
108fa74a025SManivannan Sadhasivam .name = "ipcc",
109fa74a025SManivannan Sadhasivam .irq_mask = qcom_ipcc_mask_irq,
110fa74a025SManivannan Sadhasivam .irq_unmask = qcom_ipcc_unmask_irq,
111fa74a025SManivannan Sadhasivam .flags = IRQCHIP_SKIP_SET_WAKE,
112fa74a025SManivannan Sadhasivam };
113fa74a025SManivannan Sadhasivam
qcom_ipcc_domain_map(struct irq_domain * d,unsigned int irq,irq_hw_number_t hw)114fa74a025SManivannan Sadhasivam static int qcom_ipcc_domain_map(struct irq_domain *d, unsigned int irq,
115fa74a025SManivannan Sadhasivam irq_hw_number_t hw)
116fa74a025SManivannan Sadhasivam {
117fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc = d->host_data;
118fa74a025SManivannan Sadhasivam
119fa74a025SManivannan Sadhasivam irq_set_chip_and_handler(irq, &qcom_ipcc_irq_chip, handle_level_irq);
120fa74a025SManivannan Sadhasivam irq_set_chip_data(irq, ipcc);
121fa74a025SManivannan Sadhasivam irq_set_noprobe(irq);
122fa74a025SManivannan Sadhasivam
123fa74a025SManivannan Sadhasivam return 0;
124fa74a025SManivannan Sadhasivam }
125fa74a025SManivannan Sadhasivam
qcom_ipcc_domain_xlate(struct irq_domain * d,struct device_node * node,const u32 * intspec,unsigned int intsize,unsigned long * out_hwirq,unsigned int * out_type)126fa74a025SManivannan Sadhasivam static int qcom_ipcc_domain_xlate(struct irq_domain *d,
127fa74a025SManivannan Sadhasivam struct device_node *node, const u32 *intspec,
128fa74a025SManivannan Sadhasivam unsigned int intsize,
129fa74a025SManivannan Sadhasivam unsigned long *out_hwirq,
130fa74a025SManivannan Sadhasivam unsigned int *out_type)
131fa74a025SManivannan Sadhasivam {
132fa74a025SManivannan Sadhasivam if (intsize != 3)
133fa74a025SManivannan Sadhasivam return -EINVAL;
134fa74a025SManivannan Sadhasivam
135fa74a025SManivannan Sadhasivam *out_hwirq = qcom_ipcc_get_hwirq(intspec[0], intspec[1]);
136fa74a025SManivannan Sadhasivam *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK;
137fa74a025SManivannan Sadhasivam
138fa74a025SManivannan Sadhasivam return 0;
139fa74a025SManivannan Sadhasivam }
140fa74a025SManivannan Sadhasivam
141fa74a025SManivannan Sadhasivam static const struct irq_domain_ops qcom_ipcc_irq_ops = {
142fa74a025SManivannan Sadhasivam .map = qcom_ipcc_domain_map,
143fa74a025SManivannan Sadhasivam .xlate = qcom_ipcc_domain_xlate,
144fa74a025SManivannan Sadhasivam };
145fa74a025SManivannan Sadhasivam
qcom_ipcc_mbox_send_data(struct mbox_chan * chan,void * data)146fa74a025SManivannan Sadhasivam static int qcom_ipcc_mbox_send_data(struct mbox_chan *chan, void *data)
147fa74a025SManivannan Sadhasivam {
148fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc = to_qcom_ipcc(chan->mbox);
149fa74a025SManivannan Sadhasivam struct qcom_ipcc_chan_info *mchan = chan->con_priv;
150fa74a025SManivannan Sadhasivam u32 hwirq;
151fa74a025SManivannan Sadhasivam
152fa74a025SManivannan Sadhasivam hwirq = qcom_ipcc_get_hwirq(mchan->client_id, mchan->signal_id);
153fa74a025SManivannan Sadhasivam writel(hwirq, ipcc->base + IPCC_REG_SEND_ID);
154fa74a025SManivannan Sadhasivam
155fa74a025SManivannan Sadhasivam return 0;
156fa74a025SManivannan Sadhasivam }
157fa74a025SManivannan Sadhasivam
qcom_ipcc_mbox_shutdown(struct mbox_chan * chan)158d6fbfdbcSSibi Sankar static void qcom_ipcc_mbox_shutdown(struct mbox_chan *chan)
159d6fbfdbcSSibi Sankar {
160d6fbfdbcSSibi Sankar chan->con_priv = NULL;
161d6fbfdbcSSibi Sankar }
162d6fbfdbcSSibi Sankar
qcom_ipcc_mbox_xlate(struct mbox_controller * mbox,const struct of_phandle_args * ph)163fa74a025SManivannan Sadhasivam static struct mbox_chan *qcom_ipcc_mbox_xlate(struct mbox_controller *mbox,
164fa74a025SManivannan Sadhasivam const struct of_phandle_args *ph)
165fa74a025SManivannan Sadhasivam {
166fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc = to_qcom_ipcc(mbox);
167fa74a025SManivannan Sadhasivam struct qcom_ipcc_chan_info *mchan;
168fa74a025SManivannan Sadhasivam struct mbox_chan *chan;
169e9d50e4bSHuang Yiwei struct device *dev;
170e9d50e4bSHuang Yiwei int chan_id;
171e9d50e4bSHuang Yiwei
172e9d50e4bSHuang Yiwei dev = ipcc->dev;
173fa74a025SManivannan Sadhasivam
174fa74a025SManivannan Sadhasivam if (ph->args_count != 2)
175fa74a025SManivannan Sadhasivam return ERR_PTR(-EINVAL);
176fa74a025SManivannan Sadhasivam
177e9d50e4bSHuang Yiwei for (chan_id = 0; chan_id < mbox->num_chans; chan_id++) {
178e9d50e4bSHuang Yiwei chan = &ipcc->chans[chan_id];
179e9d50e4bSHuang Yiwei mchan = chan->con_priv;
180e9d50e4bSHuang Yiwei
181e9d50e4bSHuang Yiwei if (!mchan)
182e9d50e4bSHuang Yiwei break;
183e9d50e4bSHuang Yiwei else if (mchan->client_id == ph->args[0] &&
184e9d50e4bSHuang Yiwei mchan->signal_id == ph->args[1])
185e9d50e4bSHuang Yiwei return ERR_PTR(-EBUSY);
186e9d50e4bSHuang Yiwei }
187e9d50e4bSHuang Yiwei
188e9d50e4bSHuang Yiwei if (chan_id >= mbox->num_chans)
189e9d50e4bSHuang Yiwei return ERR_PTR(-EBUSY);
190e9d50e4bSHuang Yiwei
191e9d50e4bSHuang Yiwei mchan = devm_kzalloc(dev, sizeof(*mchan), GFP_KERNEL);
192e9d50e4bSHuang Yiwei if (!mchan)
193e9d50e4bSHuang Yiwei return ERR_PTR(-ENOMEM);
194e9d50e4bSHuang Yiwei
195fa74a025SManivannan Sadhasivam mchan->client_id = ph->args[0];
196fa74a025SManivannan Sadhasivam mchan->signal_id = ph->args[1];
197fa74a025SManivannan Sadhasivam chan->con_priv = mchan;
198fa74a025SManivannan Sadhasivam
199e9d50e4bSHuang Yiwei return chan;
200fa74a025SManivannan Sadhasivam }
201fa74a025SManivannan Sadhasivam
202fa74a025SManivannan Sadhasivam static const struct mbox_chan_ops ipcc_mbox_chan_ops = {
203fa74a025SManivannan Sadhasivam .send_data = qcom_ipcc_mbox_send_data,
204d6fbfdbcSSibi Sankar .shutdown = qcom_ipcc_mbox_shutdown,
205fa74a025SManivannan Sadhasivam };
206fa74a025SManivannan Sadhasivam
qcom_ipcc_setup_mbox(struct qcom_ipcc * ipcc,struct device_node * controller_dn)207e9d50e4bSHuang Yiwei static int qcom_ipcc_setup_mbox(struct qcom_ipcc *ipcc,
208e9d50e4bSHuang Yiwei struct device_node *controller_dn)
209fa74a025SManivannan Sadhasivam {
210e9d50e4bSHuang Yiwei struct of_phandle_args curr_ph;
211e9d50e4bSHuang Yiwei struct device_node *client_dn;
212fa74a025SManivannan Sadhasivam struct mbox_controller *mbox;
213fa74a025SManivannan Sadhasivam struct device *dev = ipcc->dev;
214e9d50e4bSHuang Yiwei int i, j, ret;
215e9d50e4bSHuang Yiwei
216e9d50e4bSHuang Yiwei /*
217e9d50e4bSHuang Yiwei * Find out the number of clients interested in this mailbox
218e9d50e4bSHuang Yiwei * and create channels accordingly.
219e9d50e4bSHuang Yiwei */
220e9d50e4bSHuang Yiwei ipcc->num_chans = 0;
221e9d50e4bSHuang Yiwei for_each_node_with_property(client_dn, "mboxes") {
222e9d50e4bSHuang Yiwei if (!of_device_is_available(client_dn))
223e9d50e4bSHuang Yiwei continue;
224e9d50e4bSHuang Yiwei i = of_count_phandle_with_args(client_dn,
225e9d50e4bSHuang Yiwei "mboxes", "#mbox-cells");
226e9d50e4bSHuang Yiwei for (j = 0; j < i; j++) {
227e9d50e4bSHuang Yiwei ret = of_parse_phandle_with_args(client_dn, "mboxes",
228e9d50e4bSHuang Yiwei "#mbox-cells", j, &curr_ph);
229e9d50e4bSHuang Yiwei of_node_put(curr_ph.np);
230*a4932080SJonathan Marek if (!ret && curr_ph.np == controller_dn)
231e9d50e4bSHuang Yiwei ipcc->num_chans++;
232e9d50e4bSHuang Yiwei }
233e9d50e4bSHuang Yiwei }
234e9d50e4bSHuang Yiwei
235e9d50e4bSHuang Yiwei /* If no clients are found, skip registering as a mbox controller */
236e9d50e4bSHuang Yiwei if (!ipcc->num_chans)
237e9d50e4bSHuang Yiwei return 0;
238e9d50e4bSHuang Yiwei
239e9d50e4bSHuang Yiwei ipcc->chans = devm_kcalloc(dev, ipcc->num_chans,
240e9d50e4bSHuang Yiwei sizeof(struct mbox_chan), GFP_KERNEL);
241e9d50e4bSHuang Yiwei if (!ipcc->chans)
242e9d50e4bSHuang Yiwei return -ENOMEM;
243fa74a025SManivannan Sadhasivam
244fa74a025SManivannan Sadhasivam mbox = &ipcc->mbox;
245fa74a025SManivannan Sadhasivam mbox->dev = dev;
246e9d50e4bSHuang Yiwei mbox->num_chans = ipcc->num_chans;
247e9d50e4bSHuang Yiwei mbox->chans = ipcc->chans;
248fa74a025SManivannan Sadhasivam mbox->ops = &ipcc_mbox_chan_ops;
249fa74a025SManivannan Sadhasivam mbox->of_xlate = qcom_ipcc_mbox_xlate;
250fa74a025SManivannan Sadhasivam mbox->txdone_irq = false;
251fa74a025SManivannan Sadhasivam mbox->txdone_poll = false;
252fa74a025SManivannan Sadhasivam
253fa74a025SManivannan Sadhasivam return devm_mbox_controller_register(dev, mbox);
254fa74a025SManivannan Sadhasivam }
255fa74a025SManivannan Sadhasivam
qcom_ipcc_pm_resume(struct device * dev)256c25f7789SPrasad Sodagudi static int qcom_ipcc_pm_resume(struct device *dev)
257c25f7789SPrasad Sodagudi {
258c25f7789SPrasad Sodagudi struct qcom_ipcc *ipcc = dev_get_drvdata(dev);
259c25f7789SPrasad Sodagudi u32 hwirq;
260c25f7789SPrasad Sodagudi int virq;
261c25f7789SPrasad Sodagudi
262c25f7789SPrasad Sodagudi hwirq = readl(ipcc->base + IPCC_REG_RECV_ID);
263c25f7789SPrasad Sodagudi if (hwirq == IPCC_NO_PENDING_IRQ)
264c25f7789SPrasad Sodagudi return 0;
265c25f7789SPrasad Sodagudi
266c25f7789SPrasad Sodagudi virq = irq_find_mapping(ipcc->irq_domain, hwirq);
267c25f7789SPrasad Sodagudi
268c25f7789SPrasad Sodagudi dev_dbg(dev, "virq: %d triggered client-id: %ld; signal-id: %ld\n", virq,
269c25f7789SPrasad Sodagudi FIELD_GET(IPCC_CLIENT_ID_MASK, hwirq), FIELD_GET(IPCC_SIGNAL_ID_MASK, hwirq));
270c25f7789SPrasad Sodagudi
271c25f7789SPrasad Sodagudi return 0;
272c25f7789SPrasad Sodagudi }
273c25f7789SPrasad Sodagudi
qcom_ipcc_probe(struct platform_device * pdev)274fa74a025SManivannan Sadhasivam static int qcom_ipcc_probe(struct platform_device *pdev)
275fa74a025SManivannan Sadhasivam {
276fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc;
2771f43e523SHuang Yiwei static int id;
2781f43e523SHuang Yiwei char *name;
279fa74a025SManivannan Sadhasivam int ret;
280fa74a025SManivannan Sadhasivam
281fa74a025SManivannan Sadhasivam ipcc = devm_kzalloc(&pdev->dev, sizeof(*ipcc), GFP_KERNEL);
282fa74a025SManivannan Sadhasivam if (!ipcc)
283fa74a025SManivannan Sadhasivam return -ENOMEM;
284fa74a025SManivannan Sadhasivam
285fa74a025SManivannan Sadhasivam ipcc->dev = &pdev->dev;
286fa74a025SManivannan Sadhasivam
287fa74a025SManivannan Sadhasivam ipcc->base = devm_platform_ioremap_resource(pdev, 0);
288fa74a025SManivannan Sadhasivam if (IS_ERR(ipcc->base))
289fa74a025SManivannan Sadhasivam return PTR_ERR(ipcc->base);
290fa74a025SManivannan Sadhasivam
291fa74a025SManivannan Sadhasivam ipcc->irq = platform_get_irq(pdev, 0);
292fa74a025SManivannan Sadhasivam if (ipcc->irq < 0)
293fa74a025SManivannan Sadhasivam return ipcc->irq;
294fa74a025SManivannan Sadhasivam
2951f43e523SHuang Yiwei name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "ipcc_%d", id++);
2961f43e523SHuang Yiwei if (!name)
2971f43e523SHuang Yiwei return -ENOMEM;
2981f43e523SHuang Yiwei
299fa74a025SManivannan Sadhasivam ipcc->irq_domain = irq_domain_add_tree(pdev->dev.of_node,
300fa74a025SManivannan Sadhasivam &qcom_ipcc_irq_ops, ipcc);
301fa74a025SManivannan Sadhasivam if (!ipcc->irq_domain)
302fa74a025SManivannan Sadhasivam return -ENOMEM;
303fa74a025SManivannan Sadhasivam
304e9d50e4bSHuang Yiwei ret = qcom_ipcc_setup_mbox(ipcc, pdev->dev.of_node);
305fa74a025SManivannan Sadhasivam if (ret)
306fa74a025SManivannan Sadhasivam goto err_mbox;
307fa74a025SManivannan Sadhasivam
308fa74a025SManivannan Sadhasivam ret = devm_request_irq(&pdev->dev, ipcc->irq, qcom_ipcc_irq_fn,
309b8ae88e1SEric Chanudet IRQF_TRIGGER_HIGH | IRQF_NO_SUSPEND |
310b8ae88e1SEric Chanudet IRQF_NO_THREAD, name, ipcc);
311fa74a025SManivannan Sadhasivam if (ret < 0) {
312fa74a025SManivannan Sadhasivam dev_err(&pdev->dev, "Failed to register the irq: %d\n", ret);
313e9d50e4bSHuang Yiwei goto err_req_irq;
314fa74a025SManivannan Sadhasivam }
315fa74a025SManivannan Sadhasivam
316fa74a025SManivannan Sadhasivam platform_set_drvdata(pdev, ipcc);
317fa74a025SManivannan Sadhasivam
318fa74a025SManivannan Sadhasivam return 0;
319fa74a025SManivannan Sadhasivam
320e9d50e4bSHuang Yiwei err_req_irq:
321e9d50e4bSHuang Yiwei if (ipcc->num_chans)
322e9d50e4bSHuang Yiwei mbox_controller_unregister(&ipcc->mbox);
323fa74a025SManivannan Sadhasivam err_mbox:
324fa74a025SManivannan Sadhasivam irq_domain_remove(ipcc->irq_domain);
325fa74a025SManivannan Sadhasivam
326fa74a025SManivannan Sadhasivam return ret;
327fa74a025SManivannan Sadhasivam }
328fa74a025SManivannan Sadhasivam
qcom_ipcc_remove(struct platform_device * pdev)329fa74a025SManivannan Sadhasivam static int qcom_ipcc_remove(struct platform_device *pdev)
330fa74a025SManivannan Sadhasivam {
331fa74a025SManivannan Sadhasivam struct qcom_ipcc *ipcc = platform_get_drvdata(pdev);
332fa74a025SManivannan Sadhasivam
333fa74a025SManivannan Sadhasivam disable_irq_wake(ipcc->irq);
334fa74a025SManivannan Sadhasivam irq_domain_remove(ipcc->irq_domain);
335fa74a025SManivannan Sadhasivam
336fa74a025SManivannan Sadhasivam return 0;
337fa74a025SManivannan Sadhasivam }
338fa74a025SManivannan Sadhasivam
339fa74a025SManivannan Sadhasivam static const struct of_device_id qcom_ipcc_of_match[] = {
340fa74a025SManivannan Sadhasivam { .compatible = "qcom,ipcc"},
341fa74a025SManivannan Sadhasivam {}
342fa74a025SManivannan Sadhasivam };
343fa74a025SManivannan Sadhasivam MODULE_DEVICE_TABLE(of, qcom_ipcc_of_match);
344fa74a025SManivannan Sadhasivam
345c25f7789SPrasad Sodagudi static const struct dev_pm_ops qcom_ipcc_dev_pm_ops = {
34679f9fbe3SNathan Chancellor NOIRQ_SYSTEM_SLEEP_PM_OPS(NULL, qcom_ipcc_pm_resume)
347c25f7789SPrasad Sodagudi };
348c25f7789SPrasad Sodagudi
349fa74a025SManivannan Sadhasivam static struct platform_driver qcom_ipcc_driver = {
350fa74a025SManivannan Sadhasivam .probe = qcom_ipcc_probe,
351fa74a025SManivannan Sadhasivam .remove = qcom_ipcc_remove,
352fa74a025SManivannan Sadhasivam .driver = {
353fa74a025SManivannan Sadhasivam .name = "qcom-ipcc",
354fa74a025SManivannan Sadhasivam .of_match_table = qcom_ipcc_of_match,
3558d7e5908SAmit Pundir .suppress_bind_attrs = true,
356c25f7789SPrasad Sodagudi .pm = pm_sleep_ptr(&qcom_ipcc_dev_pm_ops),
357fa74a025SManivannan Sadhasivam },
358fa74a025SManivannan Sadhasivam };
359fa74a025SManivannan Sadhasivam
qcom_ipcc_init(void)360fa74a025SManivannan Sadhasivam static int __init qcom_ipcc_init(void)
361fa74a025SManivannan Sadhasivam {
362fa74a025SManivannan Sadhasivam return platform_driver_register(&qcom_ipcc_driver);
363fa74a025SManivannan Sadhasivam }
364fa74a025SManivannan Sadhasivam arch_initcall(qcom_ipcc_init);
365fa74a025SManivannan Sadhasivam
366fa74a025SManivannan Sadhasivam MODULE_AUTHOR("Venkata Narendra Kumar Gutta <vnkgutta@codeaurora.org>");
367fa74a025SManivannan Sadhasivam MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
368fa74a025SManivannan Sadhasivam MODULE_DESCRIPTION("Qualcomm Technologies, Inc. IPCC driver");
369fa74a025SManivannan Sadhasivam MODULE_LICENSE("GPL v2");
370