in mailbox-sti.c [404:483]
static int sti_mbox_probe(struct platform_device *pdev)
{
const struct of_device_id *match;
struct mbox_controller *mbox;
struct sti_mbox_device *mdev;
struct device_node *np = pdev->dev.of_node;
struct mbox_chan *chans;
int irq;
int ret;
match = of_match_device(sti_mailbox_match, &pdev->dev);
if (!match) {
dev_err(&pdev->dev, "No configuration found\n");
return -ENODEV;
}
pdev->dev.platform_data = (struct sti_mbox_pdata *) match->data;
mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL);
if (!mdev)
return -ENOMEM;
platform_set_drvdata(pdev, mdev);
mdev->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(mdev->base))
return PTR_ERR(mdev->base);
ret = of_property_read_string(np, "mbox-name", &mdev->name);
if (ret)
mdev->name = np->full_name;
mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL);
if (!mbox)
return -ENOMEM;
chans = devm_kcalloc(&pdev->dev,
STI_MBOX_CHAN_MAX, sizeof(*chans), GFP_KERNEL);
if (!chans)
return -ENOMEM;
mdev->dev = &pdev->dev;
mdev->mbox = mbox;
spin_lock_init(&mdev->lock);
/* STi Mailbox does not have a Tx-Done or Tx-Ready IRQ */
mbox->txdone_irq = false;
mbox->txdone_poll = true;
mbox->txpoll_period = 100;
mbox->ops = &sti_mbox_ops;
mbox->dev = mdev->dev;
mbox->of_xlate = sti_mbox_xlate;
mbox->chans = chans;
mbox->num_chans = STI_MBOX_CHAN_MAX;
ret = devm_mbox_controller_register(&pdev->dev, mbox);
if (ret)
return ret;
/* It's okay for Tx Mailboxes to not supply IRQs */
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
dev_info(&pdev->dev,
"%s: Registered Tx only Mailbox\n", mdev->name);
return 0;
}
ret = devm_request_threaded_irq(&pdev->dev, irq,
sti_mbox_irq_handler,
sti_mbox_thread_handler,
IRQF_ONESHOT, mdev->name, mdev);
if (ret) {
dev_err(&pdev->dev, "Can't claim IRQ %d\n", irq);
return -EINVAL;
}
dev_info(&pdev->dev, "%s: Registered Tx/Rx Mailbox\n", mdev->name);
return 0;
}