Lines Matching +full:mbox +full:- +full:num +full:- +full:fifos

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2006-2009 Nokia Corporation. All rights reserved.
6 * Copyright (C) 2013-2021 Texas Instruments Incorporated - https://www.ti.com
9 * Suman Anna <s-anna@ti.com>
97 return __raw_readl(mdev->mbox_base + ofs); in mbox_read_reg()
103 __raw_writel(val, mdev->mbox_base + ofs); in mbox_write_reg()
107 static u32 mbox_fifo_read(struct omap_mbox *mbox) in mbox_fifo_read() argument
109 struct omap_mbox_fifo *fifo = &mbox->rx_fifo; in mbox_fifo_read()
111 return mbox_read_reg(mbox->parent, fifo->msg); in mbox_fifo_read()
114 static void mbox_fifo_write(struct omap_mbox *mbox, u32 msg) in mbox_fifo_write() argument
116 struct omap_mbox_fifo *fifo = &mbox->tx_fifo; in mbox_fifo_write()
118 mbox_write_reg(mbox->parent, msg, fifo->msg); in mbox_fifo_write()
121 static int mbox_fifo_empty(struct omap_mbox *mbox) in mbox_fifo_empty() argument
123 struct omap_mbox_fifo *fifo = &mbox->rx_fifo; in mbox_fifo_empty()
125 return (mbox_read_reg(mbox->parent, fifo->msg_stat) == 0); in mbox_fifo_empty()
128 static int mbox_fifo_full(struct omap_mbox *mbox) in mbox_fifo_full() argument
130 struct omap_mbox_fifo *fifo = &mbox->tx_fifo; in mbox_fifo_full()
132 return mbox_read_reg(mbox->parent, fifo->fifo_stat); in mbox_fifo_full()
136 static void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) in ack_mbox_irq() argument
139 &mbox->tx_fifo : &mbox->rx_fifo; in ack_mbox_irq()
140 u32 bit = fifo->intr_bit; in ack_mbox_irq()
141 u32 irqstatus = fifo->irqstatus; in ack_mbox_irq()
143 mbox_write_reg(mbox->parent, bit, irqstatus); in ack_mbox_irq()
146 mbox_read_reg(mbox->parent, irqstatus); in ack_mbox_irq()
149 static int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) in is_mbox_irq() argument
152 &mbox->tx_fifo : &mbox->rx_fifo; in is_mbox_irq()
153 u32 bit = fifo->intr_bit; in is_mbox_irq()
154 u32 irqenable = fifo->irqenable; in is_mbox_irq()
155 u32 irqstatus = fifo->irqstatus; in is_mbox_irq()
157 u32 enable = mbox_read_reg(mbox->parent, irqenable); in is_mbox_irq()
158 u32 status = mbox_read_reg(mbox->parent, irqstatus); in is_mbox_irq()
163 static void omap_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) in omap_mbox_enable_irq() argument
167 &mbox->tx_fifo : &mbox->rx_fifo; in omap_mbox_enable_irq()
168 u32 bit = fifo->intr_bit; in omap_mbox_enable_irq()
169 u32 irqenable = fifo->irqenable; in omap_mbox_enable_irq()
171 l = mbox_read_reg(mbox->parent, irqenable); in omap_mbox_enable_irq()
173 mbox_write_reg(mbox->parent, l, irqenable); in omap_mbox_enable_irq()
176 static void omap_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) in omap_mbox_disable_irq() argument
179 &mbox->tx_fifo : &mbox->rx_fifo; in omap_mbox_disable_irq()
180 u32 bit = fifo->intr_bit; in omap_mbox_disable_irq()
181 u32 irqdisable = fifo->irqdisable; in omap_mbox_disable_irq()
184 * Read and update the interrupt configuration register for pre-OMAP4. in omap_mbox_disable_irq()
187 if (!mbox->intr_type) in omap_mbox_disable_irq()
188 bit = mbox_read_reg(mbox->parent, irqdisable) & ~bit; in omap_mbox_disable_irq()
190 mbox_write_reg(mbox->parent, bit, irqdisable); in omap_mbox_disable_irq()
196 static void __mbox_tx_interrupt(struct omap_mbox *mbox) in __mbox_tx_interrupt() argument
198 omap_mbox_disable_irq(mbox, IRQ_TX); in __mbox_tx_interrupt()
199 ack_mbox_irq(mbox, IRQ_TX); in __mbox_tx_interrupt()
200 mbox_chan_txdone(mbox->chan, 0); in __mbox_tx_interrupt()
203 static void __mbox_rx_interrupt(struct omap_mbox *mbox) in __mbox_rx_interrupt() argument
207 while (!mbox_fifo_empty(mbox)) { in __mbox_rx_interrupt()
208 msg = mbox_fifo_read(mbox); in __mbox_rx_interrupt()
209 mbox_chan_received_data(mbox->chan, (void *)(uintptr_t)msg); in __mbox_rx_interrupt()
213 ack_mbox_irq(mbox, IRQ_RX); in __mbox_rx_interrupt()
218 struct omap_mbox *mbox = p; in mbox_interrupt() local
220 if (is_mbox_irq(mbox, IRQ_TX)) in mbox_interrupt()
221 __mbox_tx_interrupt(mbox); in mbox_interrupt()
223 if (is_mbox_irq(mbox, IRQ_RX)) in mbox_interrupt()
224 __mbox_rx_interrupt(mbox); in mbox_interrupt()
229 static int omap_mbox_startup(struct omap_mbox *mbox) in omap_mbox_startup() argument
233 ret = request_threaded_irq(mbox->irq, NULL, mbox_interrupt, in omap_mbox_startup()
234 IRQF_SHARED | IRQF_ONESHOT, mbox->name, in omap_mbox_startup()
235 mbox); in omap_mbox_startup()
241 if (mbox->send_no_irq) in omap_mbox_startup()
242 mbox->chan->txdone_method = TXDONE_BY_ACK; in omap_mbox_startup()
244 omap_mbox_enable_irq(mbox, IRQ_RX); in omap_mbox_startup()
249 static void omap_mbox_fini(struct omap_mbox *mbox) in omap_mbox_fini() argument
251 omap_mbox_disable_irq(mbox, IRQ_RX); in omap_mbox_fini()
252 free_irq(mbox->irq, mbox); in omap_mbox_fini()
257 struct omap_mbox *mbox = chan->con_priv; in omap_mbox_chan_startup() local
258 struct omap_mbox_device *mdev = mbox->parent; in omap_mbox_chan_startup()
261 mutex_lock(&mdev->cfg_lock); in omap_mbox_chan_startup()
262 pm_runtime_get_sync(mdev->dev); in omap_mbox_chan_startup()
263 ret = omap_mbox_startup(mbox); in omap_mbox_chan_startup()
265 pm_runtime_put_sync(mdev->dev); in omap_mbox_chan_startup()
266 mutex_unlock(&mdev->cfg_lock); in omap_mbox_chan_startup()
272 struct omap_mbox *mbox = chan->con_priv; in omap_mbox_chan_shutdown() local
273 struct omap_mbox_device *mdev = mbox->parent; in omap_mbox_chan_shutdown()
275 mutex_lock(&mdev->cfg_lock); in omap_mbox_chan_shutdown()
276 omap_mbox_fini(mbox); in omap_mbox_chan_shutdown()
277 pm_runtime_put_sync(mdev->dev); in omap_mbox_chan_shutdown()
278 mutex_unlock(&mdev->cfg_lock); in omap_mbox_chan_shutdown()
281 static int omap_mbox_chan_send_noirq(struct omap_mbox *mbox, u32 msg) in omap_mbox_chan_send_noirq() argument
283 if (mbox_fifo_full(mbox)) in omap_mbox_chan_send_noirq()
284 return -EBUSY; in omap_mbox_chan_send_noirq()
286 omap_mbox_enable_irq(mbox, IRQ_RX); in omap_mbox_chan_send_noirq()
287 mbox_fifo_write(mbox, msg); in omap_mbox_chan_send_noirq()
288 omap_mbox_disable_irq(mbox, IRQ_RX); in omap_mbox_chan_send_noirq()
291 mbox_fifo_read(mbox); in omap_mbox_chan_send_noirq()
292 ack_mbox_irq(mbox, IRQ_RX); in omap_mbox_chan_send_noirq()
297 static int omap_mbox_chan_send(struct omap_mbox *mbox, u32 msg) in omap_mbox_chan_send() argument
299 if (mbox_fifo_full(mbox)) { in omap_mbox_chan_send()
301 omap_mbox_enable_irq(mbox, IRQ_TX); in omap_mbox_chan_send()
302 return -EBUSY; in omap_mbox_chan_send()
305 mbox_fifo_write(mbox, msg); in omap_mbox_chan_send()
308 omap_mbox_enable_irq(mbox, IRQ_TX); in omap_mbox_chan_send()
314 struct omap_mbox *mbox = chan->con_priv; in omap_mbox_chan_send_data() local
318 if (!mbox) in omap_mbox_chan_send_data()
319 return -EINVAL; in omap_mbox_chan_send_data()
321 if (mbox->send_no_irq) in omap_mbox_chan_send_data()
322 ret = omap_mbox_chan_send_noirq(mbox, msg); in omap_mbox_chan_send_data()
324 ret = omap_mbox_chan_send(mbox, msg); in omap_mbox_chan_send_data()
344 for (fifo = 0; fifo < mdev->num_fifos; fifo++) { in omap_mbox_suspend()
346 dev_err(mdev->dev, "fifo %d has unexpected unread messages\n", in omap_mbox_suspend()
348 return -EBUSY; in omap_mbox_suspend()
352 for (usr = 0; usr < mdev->num_users; usr++) { in omap_mbox_suspend()
353 reg = MAILBOX_IRQENABLE(mdev->intr_type, usr); in omap_mbox_suspend()
354 mdev->irq_ctx[usr] = mbox_read_reg(mdev, reg); in omap_mbox_suspend()
368 for (usr = 0; usr < mdev->num_users; usr++) { in omap_mbox_resume()
369 reg = MAILBOX_IRQENABLE(mdev->intr_type, usr); in omap_mbox_resume()
370 mbox_write_reg(mdev, mdev->irq_ctx[usr], reg); in omap_mbox_resume()
386 .compatible = "ti,omap2-mailbox",
390 .compatible = "ti,omap3-mailbox",
394 .compatible = "ti,omap4-mailbox",
398 .compatible = "ti,am654-mailbox",
402 .compatible = "ti,am64-mailbox",
414 phandle phandle = sp->args[0]; in omap_mbox_of_xlate()
417 struct omap_mbox *mbox; in omap_mbox_of_xlate() local
420 mdev = dev_get_drvdata(controller->dev); in omap_mbox_of_xlate()
422 return ERR_PTR(-EINVAL); in omap_mbox_of_xlate()
428 return ERR_PTR(-ENODEV); in omap_mbox_of_xlate()
431 for (i = 0; i < controller->num_chans; i++) { in omap_mbox_of_xlate()
432 mbox = controller->chans[i].con_priv; in omap_mbox_of_xlate()
433 if (!strcmp(mbox->name, node->name)) { in omap_mbox_of_xlate()
435 return &controller->chans[i]; in omap_mbox_of_xlate()
440 return ERR_PTR(-ENOENT); in omap_mbox_of_xlate()
447 struct omap_mbox *mbox; in omap_mbox_probe() local
450 struct device_node *node = pdev->dev.of_node; in omap_mbox_probe()
461 pr_err("%s: only DT-based devices are supported\n", __func__); in omap_mbox_probe()
462 return -ENODEV; in omap_mbox_probe()
465 match_data = of_device_get_match_data(&pdev->dev); in omap_mbox_probe()
467 return -ENODEV; in omap_mbox_probe()
468 intr_type = match_data->intr_type; in omap_mbox_probe()
470 if (of_property_read_u32(node, "ti,mbox-num-users", &num_users)) in omap_mbox_probe()
471 return -ENODEV; in omap_mbox_probe()
473 if (of_property_read_u32(node, "ti,mbox-num-fifos", &num_fifos)) in omap_mbox_probe()
474 return -ENODEV; in omap_mbox_probe()
478 dev_err(&pdev->dev, "no available mbox devices found\n"); in omap_mbox_probe()
479 return -ENODEV; in omap_mbox_probe()
482 mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL); in omap_mbox_probe()
484 return -ENOMEM; in omap_mbox_probe()
486 mdev->mbox_base = devm_platform_ioremap_resource(pdev, 0); in omap_mbox_probe()
487 if (IS_ERR(mdev->mbox_base)) in omap_mbox_probe()
488 return PTR_ERR(mdev->mbox_base); in omap_mbox_probe()
490 mdev->irq_ctx = devm_kcalloc(&pdev->dev, num_users, sizeof(u32), in omap_mbox_probe()
492 if (!mdev->irq_ctx) in omap_mbox_probe()
493 return -ENOMEM; in omap_mbox_probe()
495 chnls = devm_kcalloc(&pdev->dev, info_count + 1, sizeof(*chnls), in omap_mbox_probe()
498 return -ENOMEM; in omap_mbox_probe()
505 mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL); in omap_mbox_probe()
506 if (!mbox) in omap_mbox_probe()
507 return -ENOMEM; in omap_mbox_probe()
510 ret = of_property_read_u32_array(child, "ti,mbox-tx", tmp, in omap_mbox_probe()
518 ret = of_property_read_u32_array(child, "ti,mbox-rx", tmp, in omap_mbox_probe()
528 return -EINVAL; in omap_mbox_probe()
530 fifo = &mbox->tx_fifo; in omap_mbox_probe()
531 fifo->msg = MAILBOX_MESSAGE(tx_id); in omap_mbox_probe()
532 fifo->fifo_stat = MAILBOX_FIFOSTATUS(tx_id); in omap_mbox_probe()
533 fifo->intr_bit = MAILBOX_IRQ_NOTFULL(tx_id); in omap_mbox_probe()
534 fifo->irqenable = MAILBOX_IRQENABLE(intr_type, tx_usr); in omap_mbox_probe()
535 fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, tx_usr); in omap_mbox_probe()
536 fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, tx_usr); in omap_mbox_probe()
538 fifo = &mbox->rx_fifo; in omap_mbox_probe()
539 fifo->msg = MAILBOX_MESSAGE(rx_id); in omap_mbox_probe()
540 fifo->msg_stat = MAILBOX_MSGSTATUS(rx_id); in omap_mbox_probe()
541 fifo->intr_bit = MAILBOX_IRQ_NEWMSG(rx_id); in omap_mbox_probe()
542 fifo->irqenable = MAILBOX_IRQENABLE(intr_type, rx_usr); in omap_mbox_probe()
543 fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, rx_usr); in omap_mbox_probe()
544 fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, rx_usr); in omap_mbox_probe()
546 mbox->send_no_irq = of_property_read_bool(child, "ti,mbox-send-noirq"); in omap_mbox_probe()
547 mbox->intr_type = intr_type; in omap_mbox_probe()
549 mbox->parent = mdev; in omap_mbox_probe()
550 mbox->name = child->name; in omap_mbox_probe()
551 mbox->irq = platform_get_irq(pdev, tx_irq); in omap_mbox_probe()
552 if (mbox->irq < 0) in omap_mbox_probe()
553 return mbox->irq; in omap_mbox_probe()
554 mbox->chan = &chnls[i]; in omap_mbox_probe()
555 chnls[i].con_priv = mbox; in omap_mbox_probe()
558 mutex_init(&mdev->cfg_lock); in omap_mbox_probe()
559 mdev->dev = &pdev->dev; in omap_mbox_probe()
560 mdev->num_users = num_users; in omap_mbox_probe()
561 mdev->num_fifos = num_fifos; in omap_mbox_probe()
562 mdev->intr_type = intr_type; in omap_mbox_probe()
564 controller = devm_kzalloc(&pdev->dev, sizeof(*controller), GFP_KERNEL); in omap_mbox_probe()
566 return -ENOMEM; in omap_mbox_probe()
568 * OMAP/K3 Mailbox IP does not have a Tx-Done IRQ, but rather a Tx-Ready in omap_mbox_probe()
571 controller->txdone_irq = true; in omap_mbox_probe()
572 controller->dev = mdev->dev; in omap_mbox_probe()
573 controller->ops = &omap_mbox_chan_ops; in omap_mbox_probe()
574 controller->chans = chnls; in omap_mbox_probe()
575 controller->num_chans = info_count; in omap_mbox_probe()
576 controller->of_xlate = omap_mbox_of_xlate; in omap_mbox_probe()
577 ret = devm_mbox_controller_register(mdev->dev, controller); in omap_mbox_probe()
582 devm_pm_runtime_enable(mdev->dev); in omap_mbox_probe()
584 ret = pm_runtime_resume_and_get(mdev->dev); in omap_mbox_probe()
593 dev_info(mdev->dev, "omap mailbox rev 0x%x\n", l); in omap_mbox_probe()
595 ret = pm_runtime_put_sync(mdev->dev); in omap_mbox_probe()
596 if (ret < 0 && ret != -ENOSYS) in omap_mbox_probe()
605 .name = "omap-mailbox",