Skip to content

Commit 9fcebcb

Browse files
Jason-JH LinJassi Brar
authored andcommitted
mailbox: mtk-cmdq: Refine GCE_GCTL_VALUE setting
Add cmdq_gctl_value_toggle() to configure GCE_CTRL_BY_SW and GCE_DDR_EN together in the same GCE_GCTL_VALUE register. For the SoCs whose GCE is located in MMINFRA and uses MMINFRA_AO power, this allows it to be written without enabling the clocks. Otherwise, all GCE registers should be written after the GCE clocks are enabled. Move this function into cmdq_runtime_resume() and cmdq_runtime_suspend() to ensure it is called when the GCE clock is enabled. Fixes: 7abd037 ("mailbox: mtk-cmdq: add gce ddr enable support flow") Signed-off-by: Jason-JH Lin <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent f5cb07e commit 9fcebcb

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

drivers/mailbox/mtk-cmdq-mailbox.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,6 @@ struct gce_plat {
9292
u32 gce_num;
9393
};
9494

95-
static void cmdq_sw_ddr_enable(struct cmdq *cmdq, bool enable)
96-
{
97-
WARN_ON(clk_bulk_enable(cmdq->pdata->gce_num, cmdq->clocks));
98-
99-
if (enable)
100-
writel(GCE_DDR_EN | GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
101-
else
102-
writel(GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
103-
104-
clk_bulk_disable(cmdq->pdata->gce_num, cmdq->clocks);
105-
}
106-
10795
u8 cmdq_get_shift_pa(struct mbox_chan *chan)
10896
{
10997
struct cmdq *cmdq = container_of(chan->mbox, struct cmdq, mbox);
@@ -112,6 +100,19 @@ u8 cmdq_get_shift_pa(struct mbox_chan *chan)
112100
}
113101
EXPORT_SYMBOL(cmdq_get_shift_pa);
114102

103+
static void cmdq_gctl_value_toggle(struct cmdq *cmdq, bool ddr_enable)
104+
{
105+
u32 val = cmdq->pdata->control_by_sw ? GCE_CTRL_BY_SW : 0;
106+
107+
if (!cmdq->pdata->control_by_sw && !cmdq->pdata->sw_ddr_en)
108+
return;
109+
110+
if (cmdq->pdata->sw_ddr_en && ddr_enable)
111+
val |= GCE_DDR_EN;
112+
113+
writel(val, cmdq->base + GCE_GCTL_VALUE);
114+
}
115+
115116
static int cmdq_thread_suspend(struct cmdq *cmdq, struct cmdq_thread *thread)
116117
{
117118
u32 status;
@@ -140,16 +141,10 @@ static void cmdq_thread_resume(struct cmdq_thread *thread)
140141
static void cmdq_init(struct cmdq *cmdq)
141142
{
142143
int i;
143-
u32 gctl_regval = 0;
144144

145145
WARN_ON(clk_bulk_enable(cmdq->pdata->gce_num, cmdq->clocks));
146-
if (cmdq->pdata->control_by_sw)
147-
gctl_regval = GCE_CTRL_BY_SW;
148-
if (cmdq->pdata->sw_ddr_en)
149-
gctl_regval |= GCE_DDR_EN;
150146

151-
if (gctl_regval)
152-
writel(gctl_regval, cmdq->base + GCE_GCTL_VALUE);
147+
cmdq_gctl_value_toggle(cmdq, true);
153148

154149
writel(CMDQ_THR_ACTIVE_SLOT_CYCLES, cmdq->base + CMDQ_THR_SLOT_CYCLES);
155150
for (i = 0; i <= CMDQ_MAX_EVENT; i++)
@@ -315,14 +310,21 @@ static irqreturn_t cmdq_irq_handler(int irq, void *dev)
315310
static int cmdq_runtime_resume(struct device *dev)
316311
{
317312
struct cmdq *cmdq = dev_get_drvdata(dev);
313+
int ret;
318314

319-
return clk_bulk_enable(cmdq->pdata->gce_num, cmdq->clocks);
315+
ret = clk_bulk_enable(cmdq->pdata->gce_num, cmdq->clocks);
316+
if (ret)
317+
return ret;
318+
319+
cmdq_gctl_value_toggle(cmdq, true);
320+
return 0;
320321
}
321322

322323
static int cmdq_runtime_suspend(struct device *dev)
323324
{
324325
struct cmdq *cmdq = dev_get_drvdata(dev);
325326

327+
cmdq_gctl_value_toggle(cmdq, false);
326328
clk_bulk_disable(cmdq->pdata->gce_num, cmdq->clocks);
327329
return 0;
328330
}
@@ -347,9 +349,6 @@ static int cmdq_suspend(struct device *dev)
347349
if (task_running)
348350
dev_warn(dev, "exist running task(s) in suspend\n");
349351

350-
if (cmdq->pdata->sw_ddr_en)
351-
cmdq_sw_ddr_enable(cmdq, false);
352-
353352
return pm_runtime_force_suspend(dev);
354353
}
355354

@@ -360,19 +359,13 @@ static int cmdq_resume(struct device *dev)
360359
WARN_ON(pm_runtime_force_resume(dev));
361360
cmdq->suspended = false;
362361

363-
if (cmdq->pdata->sw_ddr_en)
364-
cmdq_sw_ddr_enable(cmdq, true);
365-
366362
return 0;
367363
}
368364

369365
static void cmdq_remove(struct platform_device *pdev)
370366
{
371367
struct cmdq *cmdq = platform_get_drvdata(pdev);
372368

373-
if (cmdq->pdata->sw_ddr_en)
374-
cmdq_sw_ddr_enable(cmdq, false);
375-
376369
if (!IS_ENABLED(CONFIG_PM))
377370
cmdq_runtime_suspend(&pdev->dev);
378371

0 commit comments

Comments
 (0)