Lines Matching +full:mbox +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
36 #define MBOX_BASE(mdev, inst) ((mdev)->base + ((inst) * 4))
39 * struct sti_mbox_device - STi Mailbox device data
42 * @mbox: Representation of a communication channel controller
55 struct mbox_controller *mbox; member
63 * struct sti_mbox_pdata - STi Mailbox platform specific configuration
74 * struct sti_channel - STi Mailbox allocated channel information
88 struct sti_channel *chan_info = chan->con_priv; in sti_mbox_channel_is_enabled()
89 struct sti_mbox_device *mdev = chan_info->mdev; in sti_mbox_channel_is_enabled()
90 unsigned int instance = chan_info->instance; in sti_mbox_channel_is_enabled()
91 unsigned int channel = chan_info->channel; in sti_mbox_channel_is_enabled()
93 return mdev->enabled[instance] & BIT(channel); in sti_mbox_channel_is_enabled()
97 struct mbox_chan *sti_mbox_to_channel(struct mbox_controller *mbox, in sti_mbox_to_channel() argument
104 for (i = 0; i < mbox->num_chans; i++) { in sti_mbox_to_channel()
105 chan_info = mbox->chans[i].con_priv; in sti_mbox_to_channel()
107 chan_info->instance == instance && in sti_mbox_to_channel()
108 chan_info->channel == channel) in sti_mbox_to_channel()
109 return &mbox->chans[i]; in sti_mbox_to_channel()
112 dev_err(mbox->dev, in sti_mbox_to_channel()
121 struct sti_channel *chan_info = chan->con_priv; in sti_mbox_enable_channel()
122 struct sti_mbox_device *mdev = chan_info->mdev; in sti_mbox_enable_channel()
123 unsigned int instance = chan_info->instance; in sti_mbox_enable_channel()
124 unsigned int channel = chan_info->channel; in sti_mbox_enable_channel()
128 spin_lock_irqsave(&mdev->lock, flags); in sti_mbox_enable_channel()
129 mdev->enabled[instance] |= BIT(channel); in sti_mbox_enable_channel()
131 spin_unlock_irqrestore(&mdev->lock, flags); in sti_mbox_enable_channel()
136 struct sti_channel *chan_info = chan->con_priv; in sti_mbox_disable_channel()
137 struct sti_mbox_device *mdev = chan_info->mdev; in sti_mbox_disable_channel()
138 unsigned int instance = chan_info->instance; in sti_mbox_disable_channel()
139 unsigned int channel = chan_info->channel; in sti_mbox_disable_channel()
143 spin_lock_irqsave(&mdev->lock, flags); in sti_mbox_disable_channel()
144 mdev->enabled[instance] &= ~BIT(channel); in sti_mbox_disable_channel()
146 spin_unlock_irqrestore(&mdev->lock, flags); in sti_mbox_disable_channel()
151 struct sti_channel *chan_info = chan->con_priv; in sti_mbox_clear_irq()
152 struct sti_mbox_device *mdev = chan_info->mdev; in sti_mbox_clear_irq()
153 unsigned int instance = chan_info->instance; in sti_mbox_clear_irq()
154 unsigned int channel = chan_info->channel; in sti_mbox_clear_irq()
163 struct mbox_controller *mbox = mdev->mbox; in sti_mbox_irq_to_channel() local
179 chan = sti_mbox_to_channel(mbox, instance, channel); in sti_mbox_irq_to_channel()
181 dev_dbg(mbox->dev, in sti_mbox_irq_to_channel()
194 struct sti_mbox_pdata *pdata = dev_get_platdata(mdev->dev); in sti_mbox_thread_handler()
198 for (instance = 0; instance < pdata->num_inst; instance++) { in sti_mbox_thread_handler()
216 struct sti_mbox_pdata *pdata = dev_get_platdata(mdev->dev); in sti_mbox_irq_handler()
222 for (instance = 0; instance < pdata->num_inst; instance++) { in sti_mbox_irq_handler()
226 chan_info = chan->con_priv; in sti_mbox_irq_handler()
229 dev_warn(mdev->dev, in sti_mbox_irq_handler()
232 mdev->name, chan_info->instance, in sti_mbox_irq_handler()
233 chan_info->channel, mdev->enabled[instance]); in sti_mbox_irq_handler()
246 dev_err(mdev->dev, "Spurious IRQ - was a channel requested?\n"); in sti_mbox_irq_handler()
253 struct sti_channel *chan_info = chan->con_priv; in sti_mbox_tx_is_ready()
254 struct sti_mbox_device *mdev = chan_info->mdev; in sti_mbox_tx_is_ready()
255 unsigned int instance = chan_info->instance; in sti_mbox_tx_is_ready()
256 unsigned int channel = chan_info->channel; in sti_mbox_tx_is_ready()
260 dev_dbg(mdev->dev, "Mbox: %s: inst: %d, chan: %d disabled\n", in sti_mbox_tx_is_ready()
261 mdev->name, instance, channel); in sti_mbox_tx_is_ready()
266 dev_dbg(mdev->dev, "Mbox: %s: inst: %d, chan: %d not ready\n", in sti_mbox_tx_is_ready()
267 mdev->name, instance, channel); in sti_mbox_tx_is_ready()
276 struct sti_channel *chan_info = chan->con_priv; in sti_mbox_send_data()
277 struct sti_mbox_device *mdev = chan_info->mdev; in sti_mbox_send_data()
278 unsigned int instance = chan_info->instance; in sti_mbox_send_data()
279 unsigned int channel = chan_info->channel; in sti_mbox_send_data()
282 /* Send event to co-processor */ in sti_mbox_send_data()
285 dev_dbg(mdev->dev, in sti_mbox_send_data()
287 mdev->name, instance, channel); in sti_mbox_send_data()
302 struct sti_channel *chan_info = chan->con_priv; in sti_mbox_shutdown_chan()
303 struct mbox_controller *mbox = chan_info->mdev->mbox; in sti_mbox_shutdown_chan() local
306 for (i = 0; i < mbox->num_chans; i++) in sti_mbox_shutdown_chan()
307 if (chan == &mbox->chans[i]) in sti_mbox_shutdown_chan()
310 if (mbox->num_chans == i) { in sti_mbox_shutdown_chan()
311 dev_warn(mbox->dev, "Request to free non-existent channel\n"); in sti_mbox_shutdown_chan()
318 chan->con_priv = NULL; in sti_mbox_shutdown_chan()
321 static struct mbox_chan *sti_mbox_xlate(struct mbox_controller *mbox, in sti_mbox_xlate() argument
324 struct sti_mbox_device *mdev = dev_get_drvdata(mbox->dev); in sti_mbox_xlate()
325 struct sti_mbox_pdata *pdata = dev_get_platdata(mdev->dev); in sti_mbox_xlate()
328 unsigned int instance = spec->args[0]; in sti_mbox_xlate()
329 unsigned int channel = spec->args[1]; in sti_mbox_xlate()
333 if (instance >= pdata->num_inst || channel >= pdata->num_chan) { in sti_mbox_xlate()
334 dev_err(mbox->dev, in sti_mbox_xlate()
337 return ERR_PTR(-EINVAL); in sti_mbox_xlate()
340 for (i = 0; i < mbox->num_chans; i++) { in sti_mbox_xlate()
341 chan_info = mbox->chans[i].con_priv; in sti_mbox_xlate()
345 mbox->dev == chan_info->mdev->dev && in sti_mbox_xlate()
346 instance == chan_info->instance && in sti_mbox_xlate()
347 channel == chan_info->channel) { in sti_mbox_xlate()
349 dev_err(mbox->dev, "Channel in use\n"); in sti_mbox_xlate()
350 return ERR_PTR(-EBUSY); in sti_mbox_xlate()
358 chan = &mbox->chans[i]; in sti_mbox_xlate()
362 dev_err(mbox->dev, "No free channels left\n"); in sti_mbox_xlate()
363 return ERR_PTR(-EBUSY); in sti_mbox_xlate()
366 chan_info = devm_kzalloc(mbox->dev, sizeof(*chan_info), GFP_KERNEL); in sti_mbox_xlate()
368 return ERR_PTR(-ENOMEM); in sti_mbox_xlate()
370 chan_info->mdev = mdev; in sti_mbox_xlate()
371 chan_info->instance = instance; in sti_mbox_xlate()
372 chan_info->channel = channel; in sti_mbox_xlate()
374 chan->con_priv = chan_info; in sti_mbox_xlate()
376 dev_info(mbox->dev, in sti_mbox_xlate()
377 "Mbox: %s: Created channel: instance: %d channel: %d\n", in sti_mbox_xlate()
378 mdev->name, instance, channel); in sti_mbox_xlate()
397 .compatible = "st,stih407-mailbox",
406 struct mbox_controller *mbox; in sti_mbox_probe() local
408 struct device_node *np = pdev->dev.of_node; in sti_mbox_probe()
413 pdev->dev.platform_data = (struct sti_mbox_pdata *)device_get_match_data(&pdev->dev); in sti_mbox_probe()
414 if (!pdev->dev.platform_data) { in sti_mbox_probe()
415 dev_err(&pdev->dev, "No configuration found\n"); in sti_mbox_probe()
416 return -ENODEV; in sti_mbox_probe()
419 mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL); in sti_mbox_probe()
421 return -ENOMEM; in sti_mbox_probe()
425 mdev->base = devm_platform_ioremap_resource(pdev, 0); in sti_mbox_probe()
426 if (IS_ERR(mdev->base)) in sti_mbox_probe()
427 return PTR_ERR(mdev->base); in sti_mbox_probe()
429 ret = of_property_read_string(np, "mbox-name", &mdev->name); in sti_mbox_probe()
431 mdev->name = np->full_name; in sti_mbox_probe()
433 mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL); in sti_mbox_probe()
434 if (!mbox) in sti_mbox_probe()
435 return -ENOMEM; in sti_mbox_probe()
437 chans = devm_kcalloc(&pdev->dev, in sti_mbox_probe()
440 return -ENOMEM; in sti_mbox_probe()
442 mdev->dev = &pdev->dev; in sti_mbox_probe()
443 mdev->mbox = mbox; in sti_mbox_probe()
445 spin_lock_init(&mdev->lock); in sti_mbox_probe()
447 /* STi Mailbox does not have a Tx-Done or Tx-Ready IRQ */ in sti_mbox_probe()
448 mbox->txdone_irq = false; in sti_mbox_probe()
449 mbox->txdone_poll = true; in sti_mbox_probe()
450 mbox->txpoll_period = 100; in sti_mbox_probe()
451 mbox->ops = &sti_mbox_ops; in sti_mbox_probe()
452 mbox->dev = mdev->dev; in sti_mbox_probe()
453 mbox->of_xlate = sti_mbox_xlate; in sti_mbox_probe()
454 mbox->chans = chans; in sti_mbox_probe()
455 mbox->num_chans = STI_MBOX_CHAN_MAX; in sti_mbox_probe()
457 ret = devm_mbox_controller_register(&pdev->dev, mbox); in sti_mbox_probe()
464 dev_info(&pdev->dev, in sti_mbox_probe()
465 "%s: Registered Tx only Mailbox\n", mdev->name); in sti_mbox_probe()
469 ret = devm_request_threaded_irq(&pdev->dev, irq, in sti_mbox_probe()
472 IRQF_ONESHOT, mdev->name, mdev); in sti_mbox_probe()
474 dev_err(&pdev->dev, "Can't claim IRQ %d\n", irq); in sti_mbox_probe()
475 return -EINVAL; in sti_mbox_probe()
478 dev_info(&pdev->dev, "%s: Registered Tx/Rx Mailbox\n", mdev->name); in sti_mbox_probe()
486 .name = "sti-mailbox",
495 MODULE_ALIAS("platform:mailbox-sti");