Skip to content

Commit 0af932c

Browse files
AngeloGioacchino Del RegnoJassi Brar
authored andcommitted
mailbox: mtk-cmdq: Move and partially refactor clocks probe
Move the clocks probe to a new cmdq_get_clocks() function; while at it, partially refactor the code: Drop the clk_names[] array and assign clock names to the array of clk_bulk_data with devm_kasprintf() instead, slightly reduce the indentation for the multi-gce clock probe path and add a comment describing the reason why we get clocks of other GCE instance instead of just the clock from the one that it is getting probed. Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent db93448 commit 0af932c

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

drivers/mailbox/mtk-cmdq-mailbox.c

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -578,16 +578,59 @@ static struct mbox_chan *cmdq_xlate(struct mbox_controller *mbox,
578578
return &mbox->chans[ind];
579579
}
580580

581+
static int cmdq_get_clocks(struct device *dev, struct cmdq *cmdq)
582+
{
583+
static const char * const gce_name = "gce";
584+
struct device_node *node, *parent = dev->of_node->parent;
585+
struct clk_bulk_data *clks;
586+
587+
if (cmdq->pdata->gce_num == 1) {
588+
clks = &cmdq->clocks[0];
589+
590+
clks->id = gce_name;
591+
clks->clk = devm_clk_get(dev, NULL);
592+
if (IS_ERR(clks->clk))
593+
return dev_err_probe(dev, PTR_ERR(clks->clk),
594+
"failed to get gce clock\n");
595+
596+
return 0;
597+
}
598+
599+
/*
600+
* If there is more than one GCE, get the clocks for the others too,
601+
* as the clock of the main GCE must be enabled for additional IPs
602+
* to be reachable.
603+
*/
604+
for_each_child_of_node(parent, node) {
605+
int alias_id = of_alias_get_id(node, gce_name);
606+
607+
if (alias_id < 0 || alias_id >= cmdq->pdata->gce_num)
608+
continue;
609+
610+
clks = &cmdq->clocks[alias_id];
611+
612+
clks->id = devm_kasprintf(dev, GFP_KERNEL, "gce%d", alias_id);
613+
if (!clks->id) {
614+
of_node_put(node);
615+
return -ENOMEM;
616+
}
617+
618+
clks->clk = of_clk_get(node, 0);
619+
if (IS_ERR(clks->clk)) {
620+
of_node_put(node);
621+
return dev_err_probe(dev, PTR_ERR(clks->clk),
622+
"failed to get gce%d clock\n", alias_id);
623+
}
624+
}
625+
626+
return 0;
627+
}
628+
581629
static int cmdq_probe(struct platform_device *pdev)
582630
{
583631
struct device *dev = &pdev->dev;
584632
struct cmdq *cmdq;
585633
int err, i;
586-
struct device_node *phandle = dev->of_node;
587-
struct device_node *node;
588-
int alias_id = 0;
589-
static const char * const clk_name = "gce";
590-
static const char * const clk_names[] = { "gce0", "gce1" };
591634

592635
cmdq = devm_kzalloc(dev, sizeof(*cmdq), GFP_KERNEL);
593636
if (!cmdq)
@@ -612,29 +655,9 @@ static int cmdq_probe(struct platform_device *pdev)
612655
dev_dbg(dev, "cmdq device: addr:0x%p, va:0x%p, irq:%d\n",
613656
dev, cmdq->base, cmdq->irq);
614657

615-
if (cmdq->pdata->gce_num > 1) {
616-
for_each_child_of_node(phandle->parent, node) {
617-
alias_id = of_alias_get_id(node, clk_name);
618-
if (alias_id >= 0 && alias_id < cmdq->pdata->gce_num) {
619-
cmdq->clocks[alias_id].id = clk_names[alias_id];
620-
cmdq->clocks[alias_id].clk = of_clk_get(node, 0);
621-
if (IS_ERR(cmdq->clocks[alias_id].clk)) {
622-
of_node_put(node);
623-
return dev_err_probe(dev,
624-
PTR_ERR(cmdq->clocks[alias_id].clk),
625-
"failed to get gce clk: %d\n",
626-
alias_id);
627-
}
628-
}
629-
}
630-
} else {
631-
cmdq->clocks[alias_id].id = clk_name;
632-
cmdq->clocks[alias_id].clk = devm_clk_get(&pdev->dev, NULL);
633-
if (IS_ERR(cmdq->clocks[alias_id].clk)) {
634-
return dev_err_probe(dev, PTR_ERR(cmdq->clocks[alias_id].clk),
635-
"failed to get gce clk\n");
636-
}
637-
}
658+
err = cmdq_get_clocks(dev, cmdq);
659+
if (err)
660+
return err;
638661

639662
cmdq->mbox.dev = dev;
640663
cmdq->mbox.chans = devm_kcalloc(dev, cmdq->pdata->thread_nr,

0 commit comments

Comments
 (0)