2022-10-06 04:37:07

by Yongqiang Niu

[permalink] [raw]
Subject: [PATCH v9, 0/4] mailbox: mtk-cmdq: add MT8186 support

base linux-next/master

change since v8:
1. move GCE_CTRL_BY_SW modification to the 1st patch
2. add commit message for patch 2 and patch 3

Yongqiang Niu (4):
mailbox: mtk-cmdq: Use GCE_CTRL_BY_SW definition instead of number
mailbox: mtk-cmdq: add gce software ddr enable private data
mailbox: mtk-cmdq: add gce ddr enable support flow
mailbox: mtk-cmdq: add MT8186 support

drivers/mailbox/mtk-cmdq-mailbox.c | 42 +++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)

--
2.25.1


2022-10-06 04:49:37

by Yongqiang Niu

[permalink] [raw]
Subject: [PATCH v9, 3/4] mailbox: mtk-cmdq: add gce ddr enable support flow

add gce ddr enable control flow when gce suspend/resume

when all cmdq instruction task has been processed done,
we need set this gce ddr enable to disable status to tell
cmdq hardware gce there is none task need process, and the hardware
can go into idle mode and no access ddr anymore, then the spm can go
into suspend.

the original issue is gce still access ddr when cmdq suspend function
call, but there is no task run.
so, we need control gce access ddr with this flow.
when cmdq suspend function, there is no task need process, we can
disable gce access ddr, to make sure system go into suspend success.

Signed-off-by: Yongqiang Niu <[email protected]>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index 04eb44d89119..2db82ff838ed 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -94,6 +94,18 @@ struct gce_plat {
u32 gce_num;
};

+static void cmdq_sw_ddr_enable(struct cmdq *cmdq, bool enable)
+{
+ WARN_ON(clk_bulk_enable(cmdq->gce_num, cmdq->clocks));
+
+ if (enable)
+ writel(GCE_DDR_EN | GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
+ else
+ writel(GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
+
+ clk_bulk_disable(cmdq->gce_num, cmdq->clocks);
+}
+
u8 cmdq_get_shift_pa(struct mbox_chan *chan)
{
struct cmdq *cmdq = container_of(chan->mbox, struct cmdq, mbox);
@@ -319,6 +331,9 @@ static int cmdq_suspend(struct device *dev)
if (task_running)
dev_warn(dev, "exist running task(s) in suspend\n");

+ if (cmdq->sw_ddr_en)
+ cmdq_sw_ddr_enable(cmdq, false);
+
clk_bulk_unprepare(cmdq->gce_num, cmdq->clocks);

return 0;
@@ -330,6 +345,10 @@ static int cmdq_resume(struct device *dev)

WARN_ON(clk_bulk_prepare(cmdq->gce_num, cmdq->clocks));
cmdq->suspended = false;
+
+ if (cmdq->sw_ddr_en)
+ cmdq_sw_ddr_enable(cmdq, true);
+
return 0;
}

@@ -337,6 +356,9 @@ static int cmdq_remove(struct platform_device *pdev)
{
struct cmdq *cmdq = platform_get_drvdata(pdev);

+ if (cmdq->sw_ddr_en)
+ cmdq_sw_ddr_enable(cmdq, false);
+
clk_bulk_unprepare(cmdq->gce_num, cmdq->clocks);
return 0;
}
--
2.25.1

2022-10-06 05:06:52

by Yongqiang Niu

[permalink] [raw]
Subject: [PATCH v9, 2/4] mailbox: mtk-cmdq: add gce software ddr enable private data

if gce work control by software, we need set software enable
for MT8186 Soc

there is a handshake flow between gce and ddr hardware,
if not set ddr enable flag of gce, ddr will fall into idle
mode, then gce instructions will not process done.
we need set this flag of gce to tell ddr when gce is idle or busy
controlled by software flow.

0x48[2:0] means control by software
0x48[18:16] means ddr enable
0x48[2:0] is pre-condition of 0x48[18:16].
if we want set 0x48[18:16] ddr enable, 0x48[2:0] must be set at same
time.
and only these bits is useful, other bits is useless bits

Signed-off-by: Yongqiang Niu <[email protected]>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index c3cb24f51699..04eb44d89119 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -39,6 +39,7 @@

#define GCE_GCTL_VALUE 0x48
#define GCE_CTRL_BY_SW GENMASK(2, 0)
+#define GCE_DDR_EN GENMASK(18, 16)

#define CMDQ_THR_ACTIVE_SLOT_CYCLES 0x3200
#define CMDQ_THR_ENABLED 0x1
@@ -81,6 +82,7 @@ struct cmdq {
bool suspended;
u8 shift_pa;
bool control_by_sw;
+ bool sw_ddr_en;
u32 gce_num;
};

@@ -88,6 +90,7 @@ struct gce_plat {
u32 thread_nr;
u8 shift;
bool control_by_sw;
+ bool sw_ddr_en;
u32 gce_num;
};

@@ -132,6 +135,9 @@ static void cmdq_init(struct cmdq *cmdq)
if (cmdq->control_by_sw)
writel(GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);

+ if (cmdq->sw_ddr_en)
+ writel(GCE_DDR_EN | GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
+
writel(CMDQ_THR_ACTIVE_SLOT_CYCLES, cmdq->base + CMDQ_THR_SLOT_CYCLES);
for (i = 0; i <= CMDQ_MAX_EVENT; i++)
writel(i, cmdq->base + CMDQ_SYNC_TOKEN_UPDATE);
@@ -545,6 +551,7 @@ static int cmdq_probe(struct platform_device *pdev)
cmdq->thread_nr = plat_data->thread_nr;
cmdq->shift_pa = plat_data->shift;
cmdq->control_by_sw = plat_data->control_by_sw;
+ cmdq->sw_ddr_en = plat_data->sw_ddr_en;
cmdq->gce_num = plat_data->gce_num;
cmdq->irq_mask = GENMASK(cmdq->thread_nr - 1, 0);
err = devm_request_irq(dev, cmdq->irq, cmdq_irq_handler, IRQF_SHARED,
--
2.25.1

2022-10-06 05:10:25

by Yongqiang Niu

[permalink] [raw]
Subject: [PATCH v9, 4/4] mailbox: mtk-cmdq: add MT8186 support

add MT8186 cmdq support

Signed-off-by: Yongqiang Niu <[email protected]>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index 2db82ff838ed..98eed8d22688 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -691,9 +691,18 @@ static const struct gce_plat gce_plat_v6 = {
.gce_num = 2
};

+static const struct gce_plat gce_plat_v7 = {
+ .thread_nr = 24,
+ .shift = 3,
+ .control_by_sw = true,
+ .sw_ddr_en = true,
+ .gce_num = 1
+};
+
static const struct of_device_id cmdq_of_ids[] = {
{.compatible = "mediatek,mt8173-gce", .data = (void *)&gce_plat_v2},
{.compatible = "mediatek,mt8183-gce", .data = (void *)&gce_plat_v3},
+ {.compatible = "mediatek,mt8186-gce", .data = (void *)&gce_plat_v7},
{.compatible = "mediatek,mt6779-gce", .data = (void *)&gce_plat_v4},
{.compatible = "mediatek,mt8192-gce", .data = (void *)&gce_plat_v5},
{.compatible = "mediatek,mt8195-gce", .data = (void *)&gce_plat_v6},
--
2.25.1

Subject: Re: [PATCH v9, 3/4] mailbox: mtk-cmdq: add gce ddr enable support flow

Il 06/10/22 06:34, Yongqiang Niu ha scritto:
> add gce ddr enable control flow when gce suspend/resume
>
> when all cmdq instruction task has been processed done,
> we need set this gce ddr enable to disable status to tell
> cmdq hardware gce there is none task need process, and the hardware
> can go into idle mode and no access ddr anymore, then the spm can go
> into suspend.
>
> the original issue is gce still access ddr when cmdq suspend function
> call, but there is no task run.
> so, we need control gce access ddr with this flow.
> when cmdq suspend function, there is no task need process, we can
> disable gce access ddr, to make sure system go into suspend success.
>
> Signed-off-by: Yongqiang Niu <[email protected]>


I already gave you my Reviewed-by tag for this patch and here nothing has
changed from v8 to v9. Please retain tags that were given to you in these cases.

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>

Subject: Re: [PATCH v9, 4/4] mailbox: mtk-cmdq: add MT8186 support

Il 06/10/22 06:34, Yongqiang Niu ha scritto:
> add MT8186 cmdq support
>
> Signed-off-by: Yongqiang Niu <[email protected]>

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>


Subject: Re: [PATCH v9, 2/4] mailbox: mtk-cmdq: add gce software ddr enable private data

Il 06/10/22 06:34, Yongqiang Niu ha scritto:
> if gce work control by software, we need set software enable
> for MT8186 Soc
>
> there is a handshake flow between gce and ddr hardware,
> if not set ddr enable flag of gce, ddr will fall into idle
> mode, then gce instructions will not process done.
> we need set this flag of gce to tell ddr when gce is idle or busy
> controlled by software flow.
>
> 0x48[2:0] means control by software
> 0x48[18:16] means ddr enable
> 0x48[2:0] is pre-condition of 0x48[18:16].
> if we want set 0x48[18:16] ddr enable, 0x48[2:0] must be set at same
> time.
> and only these bits is useful, other bits is useless bits
>
> Signed-off-by: Yongqiang Niu <[email protected]>
> ---
> drivers/mailbox/mtk-cmdq-mailbox.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
> index c3cb24f51699..04eb44d89119 100644
> --- a/drivers/mailbox/mtk-cmdq-mailbox.c
> +++ b/drivers/mailbox/mtk-cmdq-mailbox.c
> @@ -39,6 +39,7 @@
>
> #define GCE_GCTL_VALUE 0x48
> #define GCE_CTRL_BY_SW GENMASK(2, 0)
> +#define GCE_DDR_EN GENMASK(18, 16)
>
> #define CMDQ_THR_ACTIVE_SLOT_CYCLES 0x3200
> #define CMDQ_THR_ENABLED 0x1
> @@ -81,6 +82,7 @@ struct cmdq {
> bool suspended;
> u8 shift_pa;
> bool control_by_sw;
> + bool sw_ddr_en;
> u32 gce_num;
> };
>
> @@ -88,6 +90,7 @@ struct gce_plat {
> u32 thread_nr;
> u8 shift;
> bool control_by_sw;
> + bool sw_ddr_en;
> u32 gce_num;
> };
>
> @@ -132,6 +135,9 @@ static void cmdq_init(struct cmdq *cmdq)
> if (cmdq->control_by_sw)
> writel(GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
>
> + if (cmdq->sw_ddr_en)
> + writel(GCE_DDR_EN | GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
> +

No. That's redundant.
Here's a better way:

u32 gctl_regval = 0;

if (cmdq->control_by_sw)
gctl_regval = GCE_CTRL_BY_SW;
if (cmdq->sw_ddr_en)
gctl_regval |= GCE_DDR_EN;

if (val)
writel(gctl_regval, cmdq->base + GCE_GCTL_VALUE);

Regards,
Angelo

> writel(CMDQ_THR_ACTIVE_SLOT_CYCLES, cmdq->base + CMDQ_THR_SLOT_CYCLES);
> for (i = 0; i <= CMDQ_MAX_EVENT; i++)
> writel(i, cmdq->base + CMDQ_SYNC_TOKEN_UPDATE);
> @@ -545,6 +551,7 @@ static int cmdq_probe(struct platform_device *pdev)
> cmdq->thread_nr = plat_data->thread_nr;
> cmdq->shift_pa = plat_data->shift;
> cmdq->control_by_sw = plat_data->control_by_sw;
> + cmdq->sw_ddr_en = plat_data->sw_ddr_en;
> cmdq->gce_num = plat_data->gce_num;
> cmdq->irq_mask = GENMASK(cmdq->thread_nr - 1, 0);
> err = devm_request_irq(dev, cmdq->irq, cmdq_irq_handler, IRQF_SHARED,



Subject: Re: [PATCH v9, 2/4] mailbox: mtk-cmdq: add gce software ddr enable private data

Il 07/10/22 03:51, yongqiang.niu ha scritto:
> On Thu, 2022-10-06 at 11:29 +0200, AngeloGioacchino Del Regno wrote:
>> Il 06/10/22 06:34, Yongqiang Niu ha scritto:
>>> if gce work control by software, we need set software enable
>>> for MT8186 Soc
>>>
>>> there is a handshake flow between gce and ddr hardware,
>>> if not set ddr enable flag of gce, ddr will fall into idle
>>> mode, then gce instructions will not process done.
>>> we need set this flag of gce to tell ddr when gce is idle or busy
>>> controlled by software flow.
>>>
>>> 0x48[2:0] means control by software
>>> 0x48[18:16] means ddr enable
>>> 0x48[2:0] is pre-condition of 0x48[18:16].
>>> if we want set 0x48[18:16] ddr enable, 0x48[2:0] must be set at
>>> same
>>> time.
>>> and only these bits is useful, other bits is useless bits
>>>
>>> Signed-off-by: Yongqiang Niu <[email protected]>
>>> ---
>>> drivers/mailbox/mtk-cmdq-mailbox.c | 7 +++++++
>>> 1 file changed, 7 insertions(+)
>>>
>>> diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c
>>> b/drivers/mailbox/mtk-cmdq-mailbox.c
>>> index c3cb24f51699..04eb44d89119 100644
>>> --- a/drivers/mailbox/mtk-cmdq-mailbox.c
>>> +++ b/drivers/mailbox/mtk-cmdq-mailbox.c
>>> @@ -39,6 +39,7 @@
>>>
>>> #define GCE_GCTL_VALUE 0x48
>>> #define GCE_CTRL_BY_SW GENMASK(2, 0)
>>> +#define GCE_DDR_EN GENMASK(18, 16)
>>>
>>> #define CMDQ_THR_ACTIVE_SLOT_CYCLES 0x3200
>>> #define CMDQ_THR_ENABLED 0x1
>>> @@ -81,6 +82,7 @@ struct cmdq {
>>> bool suspended;
>>> u8 shift_pa;
>>> bool control_by_sw;
>>> + bool sw_ddr_en;
>>> u32 gce_num;
>>> };
>>>
>>> @@ -88,6 +90,7 @@ struct gce_plat {
>>> u32 thread_nr;
>>> u8 shift;
>>> bool control_by_sw;
>>> + bool sw_ddr_en;
>>> u32 gce_num;
>>> };
>>>
>>> @@ -132,6 +135,9 @@ static void cmdq_init(struct cmdq *cmdq)
>>> if (cmdq->control_by_sw)
>>> writel(GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE);
>>>
>>> + if (cmdq->sw_ddr_en)
>>> + writel(GCE_DDR_EN | GCE_CTRL_BY_SW, cmdq->base +
>>> GCE_GCTL_VALUE);
>>> +
>>
>> No. That's redundant.
>> Here's a better way:
>>
>> u32 gctl_regval = 0;
>>
>> if (cmdq->control_by_sw)
>> gctl_regval = GCE_CTRL_BY_SW;
>> if (cmdq->sw_ddr_en)
>> gctl_regval |= GCE_DDR_EN;
>>
>> if (val)
>> writel(gctl_regval, cmdq->base + GCE_GCTL_VALUE);
>>
>> Regards,
>> Angelo
>
> thanks very much for your advise.
> shall i separate this into two patches?
> 1st one is
> u32 gctl_regval = 0;
> if (cmdq->control_by_sw)
>> gctl_regval = GCE_CTRL_BY_SW;
>> if (val)
>> writel(gctl_regval, cmdq->base + GCE_GCTL_VALUE);
>
>
>
> 2nd just add this
> if (cmdq->sw_ddr_en)
>> gctl_regval |= GCE_DDR_EN;
>
> or one patch is ok?
>

One patch is ok.

Thanks,
Angelo

>>
>>> writel(CMDQ_THR_ACTIVE_SLOT_CYCLES, cmdq->base +
>>> CMDQ_THR_SLOT_CYCLES);
>>> for (i = 0; i <= CMDQ_MAX_EVENT; i++)
>>> writel(i, cmdq->base + CMDQ_SYNC_TOKEN_UPDATE);
>>> @@ -545,6 +551,7 @@ static int cmdq_probe(struct platform_device
>>> *pdev)
>>> cmdq->thread_nr = plat_data->thread_nr;
>>> cmdq->shift_pa = plat_data->shift;
>>> cmdq->control_by_sw = plat_data->control_by_sw;
>>> + cmdq->sw_ddr_en = plat_data->sw_ddr_en;
>>> cmdq->gce_num = plat_data->gce_num;
>>> cmdq->irq_mask = GENMASK(cmdq->thread_nr - 1, 0);
>>> err = devm_request_irq(dev, cmdq->irq, cmdq_irq_handler,
>>> IRQF_SHARED,
>>
>>
>>
>