Lines Matching +full:recv +full:- +full:not +full:- +full:empty
1 // SPDX-License-Identifier: GPL-2.0-only OR MIT
9 * exchange 64+32 bit messages between the main CPU and a co-processor.
13 * Both the main CPU and the co-processor see the same set of registers but
19 #include <linux/apple-mailbox.h>
113 readl_relaxed(apple_mbox->regs + apple_mbox->hw->a2i_control); in apple_mbox_hw_can_send()
115 return !(mbox_ctrl & apple_mbox->hw->control_full); in apple_mbox_hw_can_send()
121 readl_relaxed(apple_mbox->regs + apple_mbox->hw->a2i_control); in apple_mbox_hw_send_empty()
123 return mbox_ctrl & apple_mbox->hw->control_empty; in apple_mbox_hw_send_empty()
130 return -EBUSY; in apple_mbox_hw_send()
132 dev_dbg(apple_mbox->dev, "> TX %016llx %08x\n", msg->msg0, msg->msg1); in apple_mbox_hw_send()
134 writeq_relaxed(msg->msg0, apple_mbox->regs + apple_mbox->hw->a2i_send0); in apple_mbox_hw_send()
135 writeq_relaxed(FIELD_PREP(APPLE_MBOX_MSG1_MSG, msg->msg1), in apple_mbox_hw_send()
136 apple_mbox->regs + apple_mbox->hw->a2i_send1); in apple_mbox_hw_send()
144 readl_relaxed(apple_mbox->regs + apple_mbox->hw->i2a_control); in apple_mbox_hw_can_recv()
146 return !(mbox_ctrl & apple_mbox->hw->control_empty); in apple_mbox_hw_can_recv()
153 return -ENOMSG; in apple_mbox_hw_recv()
155 msg->msg0 = readq_relaxed(apple_mbox->regs + apple_mbox->hw->i2a_recv0); in apple_mbox_hw_recv()
156 msg->msg1 = FIELD_GET( in apple_mbox_hw_recv()
158 readq_relaxed(apple_mbox->regs + apple_mbox->hw->i2a_recv1)); in apple_mbox_hw_recv()
160 dev_dbg(apple_mbox->dev, "< RX %016llx %08x\n", msg->msg0, msg->msg1); in apple_mbox_hw_recv()
167 struct apple_mbox *apple_mbox = chan->con_priv; in apple_mbox_chan_send_data()
177 * FIFO is empty. It will also keep firing if the FIFO was empty in apple_mbox_chan_send_data()
181 * If the FIFO is already empty before the ack it will fire again in apple_mbox_chan_send_data()
184 if (apple_mbox->hw->has_irq_controls) { in apple_mbox_chan_send_data()
185 writel_relaxed(apple_mbox->hw->irq_bit_send_empty, in apple_mbox_chan_send_data()
186 apple_mbox->regs + apple_mbox->hw->irq_ack); in apple_mbox_chan_send_data()
188 enable_irq(apple_mbox->irq_send_empty); in apple_mbox_chan_send_data()
204 disable_irq_nosync(apple_mbox->irq_send_empty); in apple_mbox_send_empty_irq()
205 mbox_chan_txdone(&apple_mbox->chan, 0); in apple_mbox_send_empty_irq()
215 mbox_chan_received_data(&apple_mbox->chan, (void *)&msg); in apple_mbox_poll()
227 if (apple_mbox->hw->has_irq_controls) { in apple_mbox_poll()
228 writel_relaxed(apple_mbox->hw->irq_bit_recv_not_empty, in apple_mbox_poll()
229 apple_mbox->regs + apple_mbox->hw->irq_ack); in apple_mbox_poll()
239 spin_lock(&apple_mbox->rx_lock); in apple_mbox_recv_irq()
241 spin_unlock(&apple_mbox->rx_lock); in apple_mbox_recv_irq()
248 struct apple_mbox *apple_mbox = chan->con_priv; in apple_mbox_chan_peek_data()
252 spin_lock_irqsave(&apple_mbox->rx_lock, flags); in apple_mbox_chan_peek_data()
254 spin_unlock_irqrestore(&apple_mbox->rx_lock, flags); in apple_mbox_chan_peek_data()
261 struct apple_mbox *apple_mbox = chan->con_priv; in apple_mbox_chan_flush()
266 mbox_chan_txdone(&apple_mbox->chan, 0); in apple_mbox_chan_flush()
273 return -ETIME; in apple_mbox_chan_flush()
278 struct apple_mbox *apple_mbox = chan->con_priv; in apple_mbox_chan_startup()
288 if (apple_mbox->hw->has_irq_controls) { in apple_mbox_chan_startup()
289 writel_relaxed(apple_mbox->hw->irq_bit_recv_not_empty | in apple_mbox_chan_startup()
290 apple_mbox->hw->irq_bit_send_empty, in apple_mbox_chan_startup()
291 apple_mbox->regs + apple_mbox->hw->irq_enable); in apple_mbox_chan_startup()
294 enable_irq(apple_mbox->irq_recv_not_empty); in apple_mbox_chan_startup()
300 struct apple_mbox *apple_mbox = chan->con_priv; in apple_mbox_chan_shutdown()
302 disable_irq(apple_mbox->irq_recv_not_empty); in apple_mbox_chan_shutdown()
316 if (args->args_count != 0) in apple_mbox_of_xlate()
317 return ERR_PTR(-EINVAL); in apple_mbox_of_xlate()
319 return &mbox->chans[0]; in apple_mbox_of_xlate()
328 struct device *dev = &pdev->dev; in apple_mbox_probe()
330 match = of_match_node(apple_mbox_of_match, pdev->dev.of_node); in apple_mbox_probe()
332 return -EINVAL; in apple_mbox_probe()
333 if (!match->data) in apple_mbox_probe()
334 return -EINVAL; in apple_mbox_probe()
338 return -ENOMEM; in apple_mbox_probe()
341 mbox->dev = dev; in apple_mbox_probe()
342 mbox->regs = devm_platform_ioremap_resource(pdev, 0); in apple_mbox_probe()
343 if (IS_ERR(mbox->regs)) in apple_mbox_probe()
344 return PTR_ERR(mbox->regs); in apple_mbox_probe()
346 mbox->hw = match->data; in apple_mbox_probe()
347 mbox->irq_recv_not_empty = in apple_mbox_probe()
348 platform_get_irq_byname(pdev, "recv-not-empty"); in apple_mbox_probe()
349 if (mbox->irq_recv_not_empty < 0) in apple_mbox_probe()
350 return -ENODEV; in apple_mbox_probe()
352 mbox->irq_send_empty = platform_get_irq_byname(pdev, "send-empty"); in apple_mbox_probe()
353 if (mbox->irq_send_empty < 0) in apple_mbox_probe()
354 return -ENODEV; in apple_mbox_probe()
356 mbox->controller.dev = mbox->dev; in apple_mbox_probe()
357 mbox->controller.num_chans = 1; in apple_mbox_probe()
358 mbox->controller.chans = &mbox->chan; in apple_mbox_probe()
359 mbox->controller.ops = &apple_mbox_ops; in apple_mbox_probe()
360 mbox->controller.txdone_irq = true; in apple_mbox_probe()
361 mbox->controller.of_xlate = apple_mbox_of_xlate; in apple_mbox_probe()
362 mbox->chan.con_priv = mbox; in apple_mbox_probe()
363 spin_lock_init(&mbox->rx_lock); in apple_mbox_probe()
365 irqname = devm_kasprintf(dev, GFP_KERNEL, "%s-recv", dev_name(dev)); in apple_mbox_probe()
367 return -ENOMEM; in apple_mbox_probe()
369 ret = devm_request_threaded_irq(dev, mbox->irq_recv_not_empty, NULL, in apple_mbox_probe()
376 irqname = devm_kasprintf(dev, GFP_KERNEL, "%s-send", dev_name(dev)); in apple_mbox_probe()
378 return -ENOMEM; in apple_mbox_probe()
380 ret = devm_request_irq(dev, mbox->irq_send_empty, in apple_mbox_probe()
386 return devm_mbox_controller_register(dev, &mbox->controller); in apple_mbox_probe()
424 { .compatible = "apple,asc-mailbox-v4", .data = &apple_mbox_asc_hw },
425 { .compatible = "apple,m3-mailbox-v2", .data = &apple_mbox_m3_hw },
432 .name = "apple-mailbox",