Lines Matching +full:mhu +full:- +full:doorbell

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013-2015 Fujitsu Semiconductor Ltd.
5 * Based on ARM MHU driver by Jassi Brar <jaswinder.singh@linaro.org>
28 #define MHU_CHANS 3 /* Secure, Non-Secure High and Low Priority */
46 * struct mhu_db_channel - ARM MHU Mailbox allocated channel information
48 * @mhu: Pointer to parent mailbox device
49 * @pchan: Physical channel within which this doorbell resides in
50 * @doorbell: doorbell number pertaining to this channel
53 struct arm_mhu *mhu; member
55 unsigned int doorbell; member
60 unsigned int doorbell) in mhu_db_mbox_to_channel() argument
65 for (i = 0; i < mbox->num_chans; i++) { in mhu_db_mbox_to_channel()
66 chan_info = mbox->chans[i].con_priv; in mhu_db_mbox_to_channel()
67 if (chan_info && chan_info->pchan == pchan && in mhu_db_mbox_to_channel()
68 chan_info->doorbell == doorbell) in mhu_db_mbox_to_channel()
69 return &mbox->chans[i]; in mhu_db_mbox_to_channel()
77 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_mbox_clear_irq()
78 void __iomem *base = chan_info->mhu->mlink[chan_info->pchan].rx_reg; in mhu_db_mbox_clear_irq()
80 writel_relaxed(BIT(chan_info->doorbell), base + INTR_CLR_OFS); in mhu_db_mbox_clear_irq()
83 static unsigned int mhu_db_mbox_irq_to_pchan_num(struct arm_mhu *mhu, int irq) in mhu_db_mbox_irq_to_pchan_num() argument
88 if (mhu->mlink[pchan].irq == irq) in mhu_db_mbox_irq_to_pchan_num()
94 mhu_db_mbox_irq_to_channel(struct arm_mhu *mhu, unsigned int pchan) in mhu_db_mbox_irq_to_channel() argument
97 unsigned int doorbell; in mhu_db_mbox_irq_to_channel() local
99 struct mbox_controller *mbox = &mhu->mbox; in mhu_db_mbox_irq_to_channel()
100 void __iomem *base = mhu->mlink[pchan].rx_reg; in mhu_db_mbox_irq_to_channel()
108 for (doorbell = 0; bits; doorbell++) { in mhu_db_mbox_irq_to_channel()
109 if (!test_and_clear_bit(doorbell, &bits)) in mhu_db_mbox_irq_to_channel()
112 chan = mhu_db_mbox_to_channel(mbox, pchan, doorbell); in mhu_db_mbox_irq_to_channel()
115 dev_err(mbox->dev, in mhu_db_mbox_irq_to_channel()
116 "Channel not registered: pchan: %d doorbell: %d\n", in mhu_db_mbox_irq_to_channel()
117 pchan, doorbell); in mhu_db_mbox_irq_to_channel()
126 struct arm_mhu *mhu = data; in mhu_db_mbox_rx_handler() local
127 unsigned int pchan = mhu_db_mbox_irq_to_pchan_num(mhu, irq); in mhu_db_mbox_rx_handler()
129 while (NULL != (chan = mhu_db_mbox_irq_to_channel(mhu, pchan))) { in mhu_db_mbox_rx_handler()
139 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_last_tx_done()
140 void __iomem *base = chan_info->mhu->mlink[chan_info->pchan].tx_reg; in mhu_db_last_tx_done()
142 if (readl_relaxed(base + INTR_STAT_OFS) & BIT(chan_info->doorbell)) in mhu_db_last_tx_done()
150 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_send_data()
151 void __iomem *base = chan_info->mhu->mlink[chan_info->pchan].tx_reg; in mhu_db_send_data()
153 /* Send event to co-processor */ in mhu_db_send_data()
154 writel_relaxed(BIT(chan_info->doorbell), base + INTR_SET_OFS); in mhu_db_send_data()
167 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_shutdown()
168 struct mbox_controller *mbox = &chan_info->mhu->mbox; in mhu_db_shutdown()
171 for (i = 0; i < mbox->num_chans; i++) in mhu_db_shutdown()
172 if (chan == &mbox->chans[i]) in mhu_db_shutdown()
175 if (mbox->num_chans == i) { in mhu_db_shutdown()
176 dev_warn(mbox->dev, "Request to free non-existent channel\n"); in mhu_db_shutdown()
182 devm_kfree(mbox->dev, chan->con_priv); in mhu_db_shutdown()
183 chan->con_priv = NULL; in mhu_db_shutdown()
189 struct arm_mhu *mhu = dev_get_drvdata(mbox->dev); in mhu_db_mbox_xlate() local
192 unsigned int pchan = spec->args[0]; in mhu_db_mbox_xlate()
193 unsigned int doorbell = spec->args[1]; in mhu_db_mbox_xlate() local
197 if (pchan >= MHU_CHANS || doorbell >= MHU_NUM_DOORBELLS) { in mhu_db_mbox_xlate()
198 dev_err(mbox->dev, in mhu_db_mbox_xlate()
199 "Invalid channel requested pchan: %d doorbell: %d\n", in mhu_db_mbox_xlate()
200 pchan, doorbell); in mhu_db_mbox_xlate()
201 return ERR_PTR(-EINVAL); in mhu_db_mbox_xlate()
205 chan = mhu_db_mbox_to_channel(mbox, pchan, doorbell); in mhu_db_mbox_xlate()
207 dev_err(mbox->dev, "Channel in use: pchan: %d doorbell: %d\n", in mhu_db_mbox_xlate()
208 pchan, doorbell); in mhu_db_mbox_xlate()
209 return ERR_PTR(-EBUSY); in mhu_db_mbox_xlate()
213 for (i = 0; i < mbox->num_chans; i++) in mhu_db_mbox_xlate()
214 if (!mbox->chans[i].con_priv) in mhu_db_mbox_xlate()
217 if (mbox->num_chans == i) { in mhu_db_mbox_xlate()
218 dev_err(mbox->dev, "No free channels left\n"); in mhu_db_mbox_xlate()
219 return ERR_PTR(-EBUSY); in mhu_db_mbox_xlate()
222 chan = &mbox->chans[i]; in mhu_db_mbox_xlate()
224 chan_info = devm_kzalloc(mbox->dev, sizeof(*chan_info), GFP_KERNEL); in mhu_db_mbox_xlate()
226 return ERR_PTR(-ENOMEM); in mhu_db_mbox_xlate()
228 chan_info->mhu = mhu; in mhu_db_mbox_xlate()
229 chan_info->pchan = pchan; in mhu_db_mbox_xlate()
230 chan_info->doorbell = doorbell; in mhu_db_mbox_xlate()
232 chan->con_priv = chan_info; in mhu_db_mbox_xlate()
234 dev_dbg(mbox->dev, "mbox: created channel phys: %d doorbell: %d\n", in mhu_db_mbox_xlate()
235 pchan, doorbell); in mhu_db_mbox_xlate()
251 struct arm_mhu *mhu; in mhu_db_probe() local
253 struct device *dev = &adev->dev; in mhu_db_probe()
254 struct device_node *np = dev->of_node; in mhu_db_probe()
259 if (!of_device_is_compatible(np, "arm,mhu-doorbell")) in mhu_db_probe()
260 return -ENODEV; in mhu_db_probe()
262 err = of_property_read_u32(np, "#mbox-cells", &cell_count); in mhu_db_probe()
264 dev_err(dev, "failed to read #mbox-cells in '%pOF'\n", np); in mhu_db_probe()
271 dev_err(dev, "incorrect value of #mbox-cells in '%pOF'\n", np); in mhu_db_probe()
272 return -EINVAL; in mhu_db_probe()
275 mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); in mhu_db_probe()
276 if (!mhu) in mhu_db_probe()
277 return -ENOMEM; in mhu_db_probe()
279 mhu->base = devm_ioremap_resource(dev, &adev->res); in mhu_db_probe()
280 if (IS_ERR(mhu->base)) in mhu_db_probe()
281 return PTR_ERR(mhu->base); in mhu_db_probe()
285 return -ENOMEM; in mhu_db_probe()
287 mhu->dev = dev; in mhu_db_probe()
288 mhu->mbox.dev = dev; in mhu_db_probe()
289 mhu->mbox.chans = chans; in mhu_db_probe()
290 mhu->mbox.num_chans = max_chans; in mhu_db_probe()
291 mhu->mbox.txdone_irq = false; in mhu_db_probe()
292 mhu->mbox.txdone_poll = true; in mhu_db_probe()
293 mhu->mbox.txpoll_period = 1; in mhu_db_probe()
295 mhu->mbox.of_xlate = mhu_db_mbox_xlate; in mhu_db_probe()
296 amba_set_drvdata(adev, mhu); in mhu_db_probe()
298 mhu->mbox.ops = &mhu_db_ops; in mhu_db_probe()
300 err = devm_mbox_controller_register(dev, &mhu->mbox); in mhu_db_probe()
307 int irq = mhu->mlink[i].irq = adev->irq[i]; in mhu_db_probe()
314 mhu->mlink[i].rx_reg = mhu->base + mhu_reg[i]; in mhu_db_probe()
315 mhu->mlink[i].tx_reg = mhu->mlink[i].rx_reg + TX_REG_OFFSET; in mhu_db_probe()
319 IRQF_ONESHOT, "mhu_db_link", mhu); in mhu_db_probe()
322 mbox_controller_unregister(&mhu->mbox); in mhu_db_probe()
327 dev_info(dev, "ARM MHU Doorbell mailbox registered\n"); in mhu_db_probe()
342 .name = "mhu-doorbell",
350 MODULE_DESCRIPTION("ARM MHU Doorbell Driver");