Message ID | 20220720181854.547881-4-aouledameur@baylibre.com (mailing list archive) |
---|---|
State | New, archived |
Delegated to: | Daniel Lezcano |
Headers | show |
Series | thermal: mediatek: Add support for MT8365 SoC | expand |
Il 20/07/22 20:18, Amjad Ouled-Ameur ha scritto: > From: Markus Schneider-Pargmann <msp@baylibre.com> > > Add logic in order to be able to turn on the control buffer on MT8365. > This change now allows to have control buffer support for MTK_THERMAL_V1, > and it allows to define the register offset, and mask used to enable it. > > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> > Signed-off-by: Fabien Parent <fparent@baylibre.com> > Reviewed-by: Amjad Ouled-Ameur <aouledameur@baylibre.com> > Tested-by: Amjad Ouled-Ameur <aouledameur@baylibre.com> > --- > drivers/thermal/mtk_thermal.c | 23 +++++++++++++++++------ > 1 file changed, 17 insertions(+), 6 deletions(-) > > diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c > index 216eb0d61c5b..1dc276f8c4f1 100644 > --- a/drivers/thermal/mtk_thermal.c > +++ b/drivers/thermal/mtk_thermal.c > @@ -283,6 +283,9 @@ struct mtk_thermal_data { > bool need_switch_bank; > struct thermal_bank_cfg bank_data[MAX_NUM_ZONES]; > enum mtk_thermal_version version; > + u32 apmixed_buffer_ctl_reg; > + u32 apmixed_buffer_ctl_mask; > + u32 apmixed_buffer_ctl_set; > }; > > struct mtk_thermal { > @@ -578,6 +581,9 @@ static const struct mtk_thermal_data mt7622_thermal_data = { > .adcpnp = mt7622_adcpnp, > .sensor_mux_values = mt7622_mux_values, > .version = MTK_THERMAL_V2, > + .apmixed_buffer_ctl_reg = APMIXED_SYS_TS_CON1, > + .apmixed_buffer_ctl_mask = ~0x37, This is effectively GENMASK(31, 6) | BIT(3) :-) > + .apmixed_buffer_ctl_set = 0x1, ...and this is BIT(0) > }; > > /* > @@ -1031,14 +1037,18 @@ static const struct of_device_id mtk_thermal_of_match[] = { > }; > MODULE_DEVICE_TABLE(of, mtk_thermal_of_match); > > -static void mtk_thermal_turn_on_buffer(void __iomem *apmixed_base) > +static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, > + void __iomem *apmixed_base) > { > int tmp; Since you're practically restructuring this function, please fix this wrong variable type, as this should be a u32. Regards, Angelo
On 20/07/2022 20:18, Amjad Ouled-Ameur wrote: > From: Markus Schneider-Pargmann <msp@baylibre.com> > > Add logic in order to be able to turn on the control buffer on MT8365. > This change now allows to have control buffer support for MTK_THERMAL_V1, > and it allows to define the register offset, and mask used to enable it. > > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> > Signed-off-by: Fabien Parent <fparent@baylibre.com> > Reviewed-by: Amjad Ouled-Ameur <aouledameur@baylibre.com> > Tested-by: Amjad Ouled-Ameur <aouledameur@baylibre.com> Here we will need your Signed-off-by as you are sending the patch :) Regards, Matthias > --- > drivers/thermal/mtk_thermal.c | 23 +++++++++++++++++------ > 1 file changed, 17 insertions(+), 6 deletions(-) > > diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c > index 216eb0d61c5b..1dc276f8c4f1 100644 > --- a/drivers/thermal/mtk_thermal.c > +++ b/drivers/thermal/mtk_thermal.c > @@ -283,6 +283,9 @@ struct mtk_thermal_data { > bool need_switch_bank; > struct thermal_bank_cfg bank_data[MAX_NUM_ZONES]; > enum mtk_thermal_version version; > + u32 apmixed_buffer_ctl_reg; > + u32 apmixed_buffer_ctl_mask; > + u32 apmixed_buffer_ctl_set; > }; > > struct mtk_thermal { > @@ -578,6 +581,9 @@ static const struct mtk_thermal_data mt7622_thermal_data = { > .adcpnp = mt7622_adcpnp, > .sensor_mux_values = mt7622_mux_values, > .version = MTK_THERMAL_V2, > + .apmixed_buffer_ctl_reg = APMIXED_SYS_TS_CON1, > + .apmixed_buffer_ctl_mask = ~0x37, > + .apmixed_buffer_ctl_set = 0x1, > }; > > /* > @@ -1031,14 +1037,18 @@ static const struct of_device_id mtk_thermal_of_match[] = { > }; > MODULE_DEVICE_TABLE(of, mtk_thermal_of_match); > > -static void mtk_thermal_turn_on_buffer(void __iomem *apmixed_base) > +static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, > + void __iomem *apmixed_base) > { > int tmp; > > - tmp = readl(apmixed_base + APMIXED_SYS_TS_CON1); > - tmp &= ~(0x37); > - tmp |= 0x1; > - writel(tmp, apmixed_base + APMIXED_SYS_TS_CON1); > + if (!mt->conf->apmixed_buffer_ctl_reg) > + return; > + > + tmp = readl(apmixed_base + mt->conf->apmixed_buffer_ctl_reg); > + tmp &= mt->conf->apmixed_buffer_ctl_mask; > + tmp |= mt->conf->apmixed_buffer_ctl_set; > + writel(tmp, apmixed_base + mt->conf->apmixed_buffer_ctl_reg); > udelay(200); > } > > @@ -1138,8 +1148,9 @@ static int mtk_thermal_probe(struct platform_device *pdev) > goto err_disable_clk_auxadc; > } > > + mtk_thermal_turn_on_buffer(mt, apmixed_base); > + > if (mt->conf->version == MTK_THERMAL_V2) { > - mtk_thermal_turn_on_buffer(apmixed_base); > mtk_thermal_release_periodic_ts(mt, auxadc_base); > } >
Hi Angelo, On 7/21/22 10:11, AngeloGioacchino Del Regno wrote: > Il 20/07/22 20:18, Amjad Ouled-Ameur ha scritto: >> From: Markus Schneider-Pargmann <msp@baylibre.com> >> >> Add logic in order to be able to turn on the control buffer on MT8365. >> This change now allows to have control buffer support for >> MTK_THERMAL_V1, >> and it allows to define the register offset, and mask used to enable it. >> >> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> >> Signed-off-by: Fabien Parent <fparent@baylibre.com> >> Reviewed-by: Amjad Ouled-Ameur <aouledameur@baylibre.com> >> Tested-by: Amjad Ouled-Ameur <aouledameur@baylibre.com> >> --- >> drivers/thermal/mtk_thermal.c | 23 +++++++++++++++++------ >> 1 file changed, 17 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/thermal/mtk_thermal.c >> b/drivers/thermal/mtk_thermal.c >> index 216eb0d61c5b..1dc276f8c4f1 100644 >> --- a/drivers/thermal/mtk_thermal.c >> +++ b/drivers/thermal/mtk_thermal.c >> @@ -283,6 +283,9 @@ struct mtk_thermal_data { >> bool need_switch_bank; >> struct thermal_bank_cfg bank_data[MAX_NUM_ZONES]; >> enum mtk_thermal_version version; >> + u32 apmixed_buffer_ctl_reg; >> + u32 apmixed_buffer_ctl_mask; >> + u32 apmixed_buffer_ctl_set; >> }; >> struct mtk_thermal { >> @@ -578,6 +581,9 @@ static const struct mtk_thermal_data >> mt7622_thermal_data = { >> .adcpnp = mt7622_adcpnp, >> .sensor_mux_values = mt7622_mux_values, >> .version = MTK_THERMAL_V2, >> + .apmixed_buffer_ctl_reg = APMIXED_SYS_TS_CON1, >> + .apmixed_buffer_ctl_mask = ~0x37, > > This is effectively GENMASK(31, 6) | BIT(3) :-) > >> + .apmixed_buffer_ctl_set = 0x1, > > ...and this is BIT(0) > Thank you for the catch, will update them appropriately. >> }; > >> /* >> @@ -1031,14 +1037,18 @@ static const struct of_device_id >> mtk_thermal_of_match[] = { >> }; >> MODULE_DEVICE_TABLE(of, mtk_thermal_of_match); >> -static void mtk_thermal_turn_on_buffer(void __iomem *apmixed_base) >> +static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, >> + void __iomem *apmixed_base) >> { >> int tmp; > > Since you're practically restructuring this function, please fix this > wrong > variable type, as this should be a u32. > Sure agreed. Thank you Angelo for the review. Regards, Amjad > Regards, > Angelo
diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 216eb0d61c5b..1dc276f8c4f1 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -283,6 +283,9 @@ struct mtk_thermal_data { bool need_switch_bank; struct thermal_bank_cfg bank_data[MAX_NUM_ZONES]; enum mtk_thermal_version version; + u32 apmixed_buffer_ctl_reg; + u32 apmixed_buffer_ctl_mask; + u32 apmixed_buffer_ctl_set; }; struct mtk_thermal { @@ -578,6 +581,9 @@ static const struct mtk_thermal_data mt7622_thermal_data = { .adcpnp = mt7622_adcpnp, .sensor_mux_values = mt7622_mux_values, .version = MTK_THERMAL_V2, + .apmixed_buffer_ctl_reg = APMIXED_SYS_TS_CON1, + .apmixed_buffer_ctl_mask = ~0x37, + .apmixed_buffer_ctl_set = 0x1, }; /* @@ -1031,14 +1037,18 @@ static const struct of_device_id mtk_thermal_of_match[] = { }; MODULE_DEVICE_TABLE(of, mtk_thermal_of_match); -static void mtk_thermal_turn_on_buffer(void __iomem *apmixed_base) +static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, + void __iomem *apmixed_base) { int tmp; - tmp = readl(apmixed_base + APMIXED_SYS_TS_CON1); - tmp &= ~(0x37); - tmp |= 0x1; - writel(tmp, apmixed_base + APMIXED_SYS_TS_CON1); + if (!mt->conf->apmixed_buffer_ctl_reg) + return; + + tmp = readl(apmixed_base + mt->conf->apmixed_buffer_ctl_reg); + tmp &= mt->conf->apmixed_buffer_ctl_mask; + tmp |= mt->conf->apmixed_buffer_ctl_set; + writel(tmp, apmixed_base + mt->conf->apmixed_buffer_ctl_reg); udelay(200); } @@ -1138,8 +1148,9 @@ static int mtk_thermal_probe(struct platform_device *pdev) goto err_disable_clk_auxadc; } + mtk_thermal_turn_on_buffer(mt, apmixed_base); + if (mt->conf->version == MTK_THERMAL_V2) { - mtk_thermal_turn_on_buffer(apmixed_base); mtk_thermal_release_periodic_ts(mt, auxadc_base); }