Skip to content

Commit 7077ac4

Browse files
glneoJassi Brar
authored andcommitted
mailbox: omap: Merge mailbox child node setup loops
Currently the driver loops through all mailbox child nodes twice, once to read in data from each node, and again to make use of this data. Instead read the data and make use of it in one pass. This removes the need for several temporary data structures and reduces the complexity of this main loop in probe. Signed-off-by: Andrew Davis <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent e4e8b1f commit 7077ac4

File tree

1 file changed

+46
-73
lines changed

1 file changed

+46
-73
lines changed

drivers/mailbox/omap-mailbox.c

Lines changed: 46 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@ struct omap_mbox_device {
8989
struct mbox_controller controller;
9090
};
9191

92-
struct omap_mbox_fifo_info {
93-
int tx_id;
94-
int tx_usr;
95-
int tx_irq;
96-
97-
int rx_id;
98-
int rx_usr;
99-
int rx_irq;
100-
101-
const char *name;
102-
bool send_no_irq;
103-
};
104-
10592
struct omap_mbox {
10693
const char *name;
10794
int irq;
@@ -574,8 +561,7 @@ static int omap_mbox_probe(struct platform_device *pdev)
574561
{
575562
int ret;
576563
struct mbox_chan *chnls;
577-
struct omap_mbox **list, *mbox, *mboxblk;
578-
struct omap_mbox_fifo_info *finfo, *finfoblk;
564+
struct omap_mbox **list, *mbox;
579565
struct omap_mbox_device *mdev;
580566
struct omap_mbox_fifo *fifo;
581567
struct device_node *node = pdev->dev.of_node;
@@ -609,40 +595,6 @@ static int omap_mbox_probe(struct platform_device *pdev)
609595
return -ENODEV;
610596
}
611597

612-
finfoblk = devm_kcalloc(&pdev->dev, info_count, sizeof(*finfoblk),
613-
GFP_KERNEL);
614-
if (!finfoblk)
615-
return -ENOMEM;
616-
617-
finfo = finfoblk;
618-
child = NULL;
619-
for (i = 0; i < info_count; i++, finfo++) {
620-
child = of_get_next_available_child(node, child);
621-
ret = of_property_read_u32_array(child, "ti,mbox-tx", tmp,
622-
ARRAY_SIZE(tmp));
623-
if (ret)
624-
return ret;
625-
finfo->tx_id = tmp[0];
626-
finfo->tx_irq = tmp[1];
627-
finfo->tx_usr = tmp[2];
628-
629-
ret = of_property_read_u32_array(child, "ti,mbox-rx", tmp,
630-
ARRAY_SIZE(tmp));
631-
if (ret)
632-
return ret;
633-
finfo->rx_id = tmp[0];
634-
finfo->rx_irq = tmp[1];
635-
finfo->rx_usr = tmp[2];
636-
637-
finfo->name = child->name;
638-
639-
finfo->send_no_irq = of_property_read_bool(child, "ti,mbox-send-noirq");
640-
641-
if (finfo->tx_id >= num_fifos || finfo->rx_id >= num_fifos ||
642-
finfo->tx_usr >= num_users || finfo->rx_usr >= num_users)
643-
return -EINVAL;
644-
}
645-
646598
mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL);
647599
if (!mdev)
648600
return -ENOMEM;
@@ -667,36 +619,58 @@ static int omap_mbox_probe(struct platform_device *pdev)
667619
if (!chnls)
668620
return -ENOMEM;
669621

670-
mboxblk = devm_kcalloc(&pdev->dev, info_count, sizeof(*mbox),
671-
GFP_KERNEL);
672-
if (!mboxblk)
673-
return -ENOMEM;
622+
child = NULL;
623+
for (i = 0; i < info_count; i++) {
624+
int tx_id, tx_irq, tx_usr;
625+
int rx_id, rx_usr;
626+
627+
mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL);
628+
if (!mbox)
629+
return -ENOMEM;
630+
631+
child = of_get_next_available_child(node, child);
632+
ret = of_property_read_u32_array(child, "ti,mbox-tx", tmp,
633+
ARRAY_SIZE(tmp));
634+
if (ret)
635+
return ret;
636+
tx_id = tmp[0];
637+
tx_irq = tmp[1];
638+
tx_usr = tmp[2];
639+
640+
ret = of_property_read_u32_array(child, "ti,mbox-rx", tmp,
641+
ARRAY_SIZE(tmp));
642+
if (ret)
643+
return ret;
644+
rx_id = tmp[0];
645+
/* rx_irq = tmp[1]; */
646+
rx_usr = tmp[2];
647+
648+
if (tx_id >= num_fifos || rx_id >= num_fifos ||
649+
tx_usr >= num_users || rx_usr >= num_users)
650+
return -EINVAL;
674651

675-
mbox = mboxblk;
676-
finfo = finfoblk;
677-
for (i = 0; i < info_count; i++, finfo++) {
678652
fifo = &mbox->tx_fifo;
679-
fifo->msg = MAILBOX_MESSAGE(finfo->tx_id);
680-
fifo->fifo_stat = MAILBOX_FIFOSTATUS(finfo->tx_id);
681-
fifo->intr_bit = MAILBOX_IRQ_NOTFULL(finfo->tx_id);
682-
fifo->irqenable = MAILBOX_IRQENABLE(intr_type, finfo->tx_usr);
683-
fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, finfo->tx_usr);
684-
fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, finfo->tx_usr);
653+
fifo->msg = MAILBOX_MESSAGE(tx_id);
654+
fifo->fifo_stat = MAILBOX_FIFOSTATUS(tx_id);
655+
fifo->intr_bit = MAILBOX_IRQ_NOTFULL(tx_id);
656+
fifo->irqenable = MAILBOX_IRQENABLE(intr_type, tx_usr);
657+
fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, tx_usr);
658+
fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, tx_usr);
685659

686660
fifo = &mbox->rx_fifo;
687-
fifo->msg = MAILBOX_MESSAGE(finfo->rx_id);
688-
fifo->msg_stat = MAILBOX_MSGSTATUS(finfo->rx_id);
689-
fifo->intr_bit = MAILBOX_IRQ_NEWMSG(finfo->rx_id);
690-
fifo->irqenable = MAILBOX_IRQENABLE(intr_type, finfo->rx_usr);
691-
fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, finfo->rx_usr);
692-
fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, finfo->rx_usr);
693-
694-
mbox->send_no_irq = finfo->send_no_irq;
661+
fifo->msg = MAILBOX_MESSAGE(rx_id);
662+
fifo->msg_stat = MAILBOX_MSGSTATUS(rx_id);
663+
fifo->intr_bit = MAILBOX_IRQ_NEWMSG(rx_id);
664+
fifo->irqenable = MAILBOX_IRQENABLE(intr_type, rx_usr);
665+
fifo->irqstatus = MAILBOX_IRQSTATUS(intr_type, rx_usr);
666+
fifo->irqdisable = MAILBOX_IRQDISABLE(intr_type, rx_usr);
667+
668+
mbox->send_no_irq = of_property_read_bool(child, "ti,mbox-send-noirq");
695669
mbox->intr_type = intr_type;
696670

697671
mbox->parent = mdev;
698-
mbox->name = finfo->name;
699-
mbox->irq = platform_get_irq(pdev, finfo->tx_irq);
672+
mbox->name = child->name;
673+
mbox->irq = platform_get_irq(pdev, tx_irq);
700674
if (mbox->irq < 0)
701675
return mbox->irq;
702676
mbox->chan = &chnls[i];
@@ -743,7 +717,6 @@ static int omap_mbox_probe(struct platform_device *pdev)
743717
if (ret < 0 && ret != -ENOSYS)
744718
return ret;
745719

746-
devm_kfree(&pdev->dev, finfoblk);
747720
return 0;
748721
}
749722

0 commit comments

Comments
 (0)