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>
29 #define MHU_CHANS 3 /* Secure, Non-Secure High and Low Priority */
47 * struct mhu_db_channel - ARM MHU Mailbox allocated channel information
49 * @mhu: Pointer to parent mailbox device
50 * @pchan: Physical channel within which this doorbell resides in
51 * @doorbell: doorbell number pertaining to this channel
54 struct arm_mhu *mhu; member
56 unsigned int doorbell; member
61 unsigned int doorbell) in mhu_db_mbox_to_channel() argument
66 for (i = 0; i < mbox->num_chans; i++) { in mhu_db_mbox_to_channel()
67 chan_info = mbox->chans[i].con_priv; in mhu_db_mbox_to_channel()
68 if (chan_info && chan_info->pchan == pchan && in mhu_db_mbox_to_channel()
69 chan_info->doorbell == doorbell) in mhu_db_mbox_to_channel()
70 return &mbox->chans[i]; in mhu_db_mbox_to_channel()
78 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_mbox_clear_irq()
79 void __iomem *base = chan_info->mhu->mlink[chan_info->pchan].rx_reg; in mhu_db_mbox_clear_irq()
81 writel_relaxed(BIT(chan_info->doorbell), base + INTR_CLR_OFS); in mhu_db_mbox_clear_irq()
84 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
89 if (mhu->mlink[pchan].irq == irq) in mhu_db_mbox_irq_to_pchan_num()
95 mhu_db_mbox_irq_to_channel(struct arm_mhu *mhu, unsigned int pchan) in mhu_db_mbox_irq_to_channel() argument
98 unsigned int doorbell; in mhu_db_mbox_irq_to_channel() local
100 struct mbox_controller *mbox = &mhu->mbox; in mhu_db_mbox_irq_to_channel()
101 void __iomem *base = mhu->mlink[pchan].rx_reg; in mhu_db_mbox_irq_to_channel()
109 for (doorbell = 0; bits; doorbell++) { in mhu_db_mbox_irq_to_channel()
110 if (!test_and_clear_bit(doorbell, &bits)) in mhu_db_mbox_irq_to_channel()
113 chan = mhu_db_mbox_to_channel(mbox, pchan, doorbell); in mhu_db_mbox_irq_to_channel()
116 dev_err(mbox->dev, in mhu_db_mbox_irq_to_channel()
117 "Channel not registered: pchan: %d doorbell: %d\n", in mhu_db_mbox_irq_to_channel()
118 pchan, doorbell); in mhu_db_mbox_irq_to_channel()
127 struct arm_mhu *mhu = data; in mhu_db_mbox_rx_handler() local
128 unsigned int pchan = mhu_db_mbox_irq_to_pchan_num(mhu, irq); in mhu_db_mbox_rx_handler()
130 while (NULL != (chan = mhu_db_mbox_irq_to_channel(mhu, pchan))) { in mhu_db_mbox_rx_handler()
140 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_last_tx_done()
141 void __iomem *base = chan_info->mhu->mlink[chan_info->pchan].tx_reg; in mhu_db_last_tx_done()
143 if (readl_relaxed(base + INTR_STAT_OFS) & BIT(chan_info->doorbell)) in mhu_db_last_tx_done()
151 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_send_data()
152 void __iomem *base = chan_info->mhu->mlink[chan_info->pchan].tx_reg; in mhu_db_send_data()
154 /* Send event to co-processor */ in mhu_db_send_data()
155 writel_relaxed(BIT(chan_info->doorbell), base + INTR_SET_OFS); in mhu_db_send_data()
168 struct mhu_db_channel *chan_info = chan->con_priv; in mhu_db_shutdown()
169 struct mbox_controller *mbox = &chan_info->mhu->mbox; in mhu_db_shutdown()
172 for (i = 0; i < mbox->num_chans; i++) in mhu_db_shutdown()
173 if (chan == &mbox->chans[i]) in mhu_db_shutdown()
176 if (mbox->num_chans == i) { in mhu_db_shutdown()
177 dev_warn(mbox->dev, "Request to free non-existent channel\n"); in mhu_db_shutdown()
183 devm_kfree(mbox->dev, chan->con_priv); in mhu_db_shutdown()
184 chan->con_priv = NULL; in mhu_db_shutdown()
190 struct arm_mhu *mhu = dev_get_drvdata(mbox->dev); in mhu_db_mbox_xlate() local
193 unsigned int pchan = spec->args[0]; in mhu_db_mbox_xlate()
194 unsigned int doorbell = spec->args[1]; in mhu_db_mbox_xlate() local
198 if (pchan >= MHU_CHANS || doorbell >= MHU_NUM_DOORBELLS) { in mhu_db_mbox_xlate()
199 dev_err(mbox->dev, in mhu_db_mbox_xlate()
200 "Invalid channel requested pchan: %d doorbell: %d\n", in mhu_db_mbox_xlate()
201 pchan, doorbell); in mhu_db_mbox_xlate()
202 return ERR_PTR(-EINVAL); in mhu_db_mbox_xlate()
206 chan = mhu_db_mbox_to_channel(mbox, pchan, doorbell); in mhu_db_mbox_xlate()
208 dev_err(mbox->dev, "Channel in use: pchan: %d doorbell: %d\n", in mhu_db_mbox_xlate()
209 pchan, doorbell); in mhu_db_mbox_xlate()
210 return ERR_PTR(-EBUSY); in mhu_db_mbox_xlate()
214 for (i = 0; i < mbox->num_chans; i++) in mhu_db_mbox_xlate()
215 if (!mbox->chans[i].con_priv) in mhu_db_mbox_xlate()
218 if (mbox->num_chans == i) { in mhu_db_mbox_xlate()
219 dev_err(mbox->dev, "No free channels left\n"); in mhu_db_mbox_xlate()
220 return ERR_PTR(-EBUSY); in mhu_db_mbox_xlate()
223 chan = &mbox->chans[i]; in mhu_db_mbox_xlate()
225 chan_info = devm_kzalloc(mbox->dev, sizeof(*chan_info), GFP_KERNEL); in mhu_db_mbox_xlate()
227 return ERR_PTR(-ENOMEM); in mhu_db_mbox_xlate()
229 chan_info->mhu = mhu; in mhu_db_mbox_xlate()
230 chan_info->pchan = pchan; in mhu_db_mbox_xlate()
231 chan_info->doorbell = doorbell; in mhu_db_mbox_xlate()
233 chan->con_priv = chan_info; in mhu_db_mbox_xlate()
235 dev_dbg(mbox->dev, "mbox: created channel phys: %d doorbell: %d\n", in mhu_db_mbox_xlate()
236 pchan, doorbell); in mhu_db_mbox_xlate()
252 struct arm_mhu *mhu; in mhu_db_probe() local
254 struct device *dev = &adev->dev; in mhu_db_probe()
255 struct device_node *np = dev->of_node; in mhu_db_probe()
260 if (!of_device_is_compatible(np, "arm,mhu-doorbell")) in mhu_db_probe()
261 return -ENODEV; in mhu_db_probe()
263 err = of_property_read_u32(np, "#mbox-cells", &cell_count); in mhu_db_probe()
265 dev_err(dev, "failed to read #mbox-cells in '%pOF'\n", np); in mhu_db_probe()
272 dev_err(dev, "incorrect value of #mbox-cells in '%pOF'\n", np); in mhu_db_probe()
273 return -EINVAL; in mhu_db_probe()
276 mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); in mhu_db_probe()
277 if (!mhu) in mhu_db_probe()
278 return -ENOMEM; in mhu_db_probe()
280 mhu->base = devm_ioremap_resource(dev, &adev->res); in mhu_db_probe()
281 if (IS_ERR(mhu->base)) in mhu_db_probe()
282 return PTR_ERR(mhu->base); in mhu_db_probe()
286 return -ENOMEM; in mhu_db_probe()
288 mhu->dev = dev; in mhu_db_probe()
289 mhu->mbox.dev = dev; in mhu_db_probe()
290 mhu->mbox.chans = chans; in mhu_db_probe()
291 mhu->mbox.num_chans = max_chans; in mhu_db_probe()
292 mhu->mbox.txdone_irq = false; in mhu_db_probe()
293 mhu->mbox.txdone_poll = true; in mhu_db_probe()
294 mhu->mbox.txpoll_period = 1; in mhu_db_probe()
296 mhu->mbox.of_xlate = mhu_db_mbox_xlate; in mhu_db_probe()
297 amba_set_drvdata(adev, mhu); in mhu_db_probe()
299 mhu->mbox.ops = &mhu_db_ops; in mhu_db_probe()
301 err = devm_mbox_controller_register(dev, &mhu->mbox); in mhu_db_probe()
308 int irq = mhu->mlink[i].irq = adev->irq[i]; in mhu_db_probe()
315 mhu->mlink[i].rx_reg = mhu->base + mhu_reg[i]; in mhu_db_probe()
316 mhu->mlink[i].tx_reg = mhu->mlink[i].rx_reg + TX_REG_OFFSET; in mhu_db_probe()
320 IRQF_ONESHOT, "mhu_db_link", mhu); in mhu_db_probe()
323 mbox_controller_unregister(&mhu->mbox); in mhu_db_probe()
328 dev_info(dev, "ARM MHU Doorbell mailbox registered\n"); in mhu_db_probe()
343 .name = "mhu-doorbell",
351 MODULE_DESCRIPTION("ARM MHU Doorbell Driver");