Lines Matching +full:mbox +full:- +full:name
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
99 int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, in apple_mbox_send() argument
107 spin_lock_irqsave(&mbox->tx_lock, flags); in apple_mbox_send()
108 mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->a2i_control); in apple_mbox_send()
110 while (mbox_ctrl & mbox->hw->control_full) { in apple_mbox_send()
113 mbox->regs + mbox->hw->a2i_control, mbox_ctrl, in apple_mbox_send()
114 !(mbox_ctrl & mbox->hw->control_full), 100, in apple_mbox_send()
118 spin_unlock_irqrestore(&mbox->tx_lock, flags); in apple_mbox_send()
133 if (mbox->hw->has_irq_controls) { in apple_mbox_send()
134 writel_relaxed(mbox->hw->irq_bit_send_empty, in apple_mbox_send()
135 mbox->regs + mbox->hw->irq_ack); in apple_mbox_send()
137 enable_irq(mbox->irq_send_empty); in apple_mbox_send()
138 reinit_completion(&mbox->tx_empty); in apple_mbox_send()
139 spin_unlock_irqrestore(&mbox->tx_lock, flags); in apple_mbox_send()
142 &mbox->tx_empty, in apple_mbox_send()
147 return -ETIMEDOUT; in apple_mbox_send()
149 spin_lock_irqsave(&mbox->tx_lock, flags); in apple_mbox_send()
150 mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->a2i_control); in apple_mbox_send()
153 writeq_relaxed(msg.msg0, mbox->regs + mbox->hw->a2i_send0); in apple_mbox_send()
155 mbox->regs + mbox->hw->a2i_send1); in apple_mbox_send()
157 spin_unlock_irqrestore(&mbox->tx_lock, flags); in apple_mbox_send()
165 struct apple_mbox *mbox = data; in apple_mbox_send_empty_irq() local
174 spin_lock(&mbox->tx_lock); in apple_mbox_send_empty_irq()
175 disable_irq_nosync(mbox->irq_send_empty); in apple_mbox_send_empty_irq()
176 complete(&mbox->tx_empty); in apple_mbox_send_empty_irq()
177 spin_unlock(&mbox->tx_lock); in apple_mbox_send_empty_irq()
182 static int apple_mbox_poll_locked(struct apple_mbox *mbox) in apple_mbox_poll_locked() argument
187 u32 mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->i2a_control); in apple_mbox_poll_locked()
189 while (!(mbox_ctrl & mbox->hw->control_empty)) { in apple_mbox_poll_locked()
190 msg.msg0 = readq_relaxed(mbox->regs + mbox->hw->i2a_recv0); in apple_mbox_poll_locked()
193 readq_relaxed(mbox->regs + mbox->hw->i2a_recv1)); in apple_mbox_poll_locked()
195 mbox->rx(mbox, msg, mbox->cookie); in apple_mbox_poll_locked()
197 mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->i2a_control); in apple_mbox_poll_locked()
208 if (mbox->hw->has_irq_controls) { in apple_mbox_poll_locked()
209 writel_relaxed(mbox->hw->irq_bit_recv_not_empty, in apple_mbox_poll_locked()
210 mbox->regs + mbox->hw->irq_ack); in apple_mbox_poll_locked()
218 struct apple_mbox *mbox = data; in apple_mbox_recv_irq() local
220 spin_lock(&mbox->rx_lock); in apple_mbox_recv_irq()
221 apple_mbox_poll_locked(mbox); in apple_mbox_recv_irq()
222 spin_unlock(&mbox->rx_lock); in apple_mbox_recv_irq()
227 int apple_mbox_poll(struct apple_mbox *mbox) in apple_mbox_poll() argument
232 spin_lock_irqsave(&mbox->rx_lock, flags); in apple_mbox_poll()
233 ret = apple_mbox_poll_locked(mbox); in apple_mbox_poll()
234 spin_unlock_irqrestore(&mbox->rx_lock, flags); in apple_mbox_poll()
240 int apple_mbox_start(struct apple_mbox *mbox) in apple_mbox_start() argument
244 if (mbox->active) in apple_mbox_start()
247 ret = pm_runtime_resume_and_get(mbox->dev); in apple_mbox_start()
259 if (mbox->hw->has_irq_controls) { in apple_mbox_start()
260 writel_relaxed(mbox->hw->irq_bit_recv_not_empty | in apple_mbox_start()
261 mbox->hw->irq_bit_send_empty, in apple_mbox_start()
262 mbox->regs + mbox->hw->irq_enable); in apple_mbox_start()
265 enable_irq(mbox->irq_recv_not_empty); in apple_mbox_start()
266 mbox->active = true; in apple_mbox_start()
271 void apple_mbox_stop(struct apple_mbox *mbox) in apple_mbox_stop() argument
273 if (!mbox->active) in apple_mbox_stop()
276 mbox->active = false; in apple_mbox_stop()
277 disable_irq(mbox->irq_recv_not_empty); in apple_mbox_stop()
278 pm_runtime_mark_last_busy(mbox->dev); in apple_mbox_stop()
279 pm_runtime_put_autosuspend(mbox->dev); in apple_mbox_stop()
287 struct apple_mbox *mbox; in apple_mbox_get() local
290 ret = of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells", in apple_mbox_get()
299 return ERR_PTR(-EPROBE_DEFER); in apple_mbox_get()
301 mbox = platform_get_drvdata(pdev); in apple_mbox_get()
302 if (!mbox) in apple_mbox_get()
303 return ERR_PTR(-EPROBE_DEFER); in apple_mbox_get()
305 if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) in apple_mbox_get()
306 return ERR_PTR(-ENODEV); in apple_mbox_get()
308 return mbox; in apple_mbox_get()
312 struct apple_mbox *apple_mbox_get_byname(struct device *dev, const char *name) in apple_mbox_get_byname() argument
316 index = of_property_match_string(dev->of_node, "mbox-names", name); in apple_mbox_get_byname()
328 struct apple_mbox *mbox; in apple_mbox_probe() local
329 struct device *dev = &pdev->dev; in apple_mbox_probe()
331 mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); in apple_mbox_probe()
332 if (!mbox) in apple_mbox_probe()
333 return -ENOMEM; in apple_mbox_probe()
335 mbox->dev = &pdev->dev; in apple_mbox_probe()
336 mbox->hw = of_device_get_match_data(dev); in apple_mbox_probe()
337 if (!mbox->hw) in apple_mbox_probe()
338 return -EINVAL; in apple_mbox_probe()
340 mbox->regs = devm_platform_ioremap_resource(pdev, 0); in apple_mbox_probe()
341 if (IS_ERR(mbox->regs)) in apple_mbox_probe()
342 return PTR_ERR(mbox->regs); in apple_mbox_probe()
344 mbox->irq_recv_not_empty = in apple_mbox_probe()
345 platform_get_irq_byname(pdev, "recv-not-empty"); in apple_mbox_probe()
346 if (mbox->irq_recv_not_empty < 0) in apple_mbox_probe()
347 return -ENODEV; in apple_mbox_probe()
349 mbox->irq_send_empty = platform_get_irq_byname(pdev, "send-empty"); in apple_mbox_probe()
350 if (mbox->irq_send_empty < 0) in apple_mbox_probe()
351 return -ENODEV; in apple_mbox_probe()
353 spin_lock_init(&mbox->rx_lock); in apple_mbox_probe()
354 spin_lock_init(&mbox->tx_lock); in apple_mbox_probe()
355 init_completion(&mbox->tx_empty); in apple_mbox_probe()
357 irqname = devm_kasprintf(dev, GFP_KERNEL, "%s-recv", dev_name(dev)); in apple_mbox_probe()
359 return -ENOMEM; in apple_mbox_probe()
361 ret = devm_request_irq(dev, mbox->irq_recv_not_empty, in apple_mbox_probe()
363 IRQF_NO_AUTOEN | IRQF_NO_SUSPEND, irqname, mbox); in apple_mbox_probe()
367 irqname = devm_kasprintf(dev, GFP_KERNEL, "%s-send", dev_name(dev)); in apple_mbox_probe()
369 return -ENOMEM; in apple_mbox_probe()
371 ret = devm_request_irq(dev, mbox->irq_send_empty, in apple_mbox_probe()
373 IRQF_NO_AUTOEN | IRQF_NO_SUSPEND, irqname, mbox); in apple_mbox_probe()
381 platform_set_drvdata(pdev, mbox); in apple_mbox_probe()
420 { .compatible = "apple,asc-mailbox-v4", .data = &apple_mbox_asc_hw },
421 { .compatible = "apple,m3-mailbox-v2", .data = &apple_mbox_m3_hw },
428 .name = "apple-mailbox",