From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-12 08:14:15
Due to the change of tuning implementation, it's no longer necessary to
use the "starfive,sysreg" property in dts, so remove it from required.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
---
Documentation/devicetree/bindings/mmc/starfive,jh7110-mmc.yaml | 2 --
1 file changed, 2 deletions(-)
From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-12 08:14:18
Before, we used syscon to achieve tuning, but the actual measurement
showed little effect, so the tuning implementation was modified here,
and it was realized by reading and writing the UHS_REG_EXT register.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
---
drivers/mmc/host/dw_mmc-starfive.c | 137 +++++++++--------------------
1 file changed, 40 insertions(+), 97 deletions(-)
@@ -44,117 +39,65 @@ static void dw_mci_starfive_set_ios(struct dw_mci *host, struct mmc_ios *ios)}}+staticvoiddw_mci_starfive_set_sample_phase(structdw_mci*host,u32smpl_phase)+{+/* change driver phase and sample phase */+u32reg_value=mci_readl(host,UHS_REG_EXT);++/* In UHS_REG_EXT, only 5 bits valid in DRV_PHASE and SMPL_PHASE */+reg_value&=~STARFIVE_SMPL_PHASE;+reg_value|=FIELD_PREP(STARFIVE_SMPL_PHASE,smpl_phase);+mci_writel(host,UHS_REG_EXT,reg_value);++/* We should delay 1ms wait for timing setting finished. */+mdelay(1);+}+staticintdw_mci_starfive_execute_tuning(structdw_mci_slot*slot,u32opcode){staticconstintgrade=MAX_DELAY_CHAIN;structdw_mci*host=slot->host;-structstarfive_priv*priv=host->priv;-intrise_point=-1,fall_point=-1;-interr,prev_err=0;-inti;-boolfound=0;-u32regval;--/*-*Usegradeasthemaxdelaychain,andusetherise_pointand-*fall_pointtoensurethebestsamplingpointofadatainput-*signals.-*/-for(i=0;i<grade;i++){-regval=i<<priv->syscon_shift;-err=regmap_update_bits(priv->reg_syscon,priv->syscon_offset,-priv->syscon_mask,regval);-if(err)-returnerr;+intsmpl_phase,smpl_raise=-1,smpl_fall=-1;+intret;++for(smpl_phase=0;smpl_phase<grade;smpl_phase++){+dw_mci_starfive_set_sample_phase(host,smpl_phase);mci_writel(host,RINTSTS,ALL_INT_CLR);-err=mmc_send_tuning(slot->mmc,opcode,NULL);-if(!err)-found=1;+ret=mmc_send_tuning(slot->mmc,opcode,NULL);-if(i>0){-if(err&&!prev_err)-fall_point=i-1;-if(!err&&prev_err)-rise_point=i;+if(!ret&&smpl_raise<0){+smpl_raise=smpl_phase;+}elseif(ret&&smpl_raise>=0){+smpl_fall=smpl_phase-1;+break;}--if(rise_point!=-1&&fall_point!=-1)-gototuning_out;--prev_err=err;-err=0;}-tuning_out:-if(found){-if(rise_point==-1)-rise_point=0;-if(fall_point==-1)-fall_point=grade-1;-if(fall_point<rise_point){-if((rise_point+fall_point)>-(grade-1))-i=fall_point/2;-else-i=(rise_point+grade-1)/2;-}else{-i=(rise_point+fall_point)/2;-}--regval=i<<priv->syscon_shift;-err=regmap_update_bits(priv->reg_syscon,priv->syscon_offset,-priv->syscon_mask,regval);-if(err)-returnerr;-mci_writel(host,RINTSTS,ALL_INT_CLR);+if(smpl_phase>=grade&&smpl_raise>=0)+smpl_fall=grade-1;-dev_info(host->dev,"Found valid delay chain! use it [delay=%d]\n",i);-}else{+if(smpl_raise<0){+smpl_phase=0;dev_err(host->dev,"No valid delay chain! use default\n");-err=-EINVAL;+ret=-EINVAL;+gotoout;}-mci_writel(host,RINTSTS,ALL_INT_CLR);-returnerr;-}--staticintdw_mci_starfive_parse_dt(structdw_mci*host)-{-structof_phandle_argsargs;-structstarfive_priv*priv;-intret;--priv=devm_kzalloc(host->dev,sizeof(*priv),GFP_KERNEL);-if(!priv)-return-ENOMEM;+smpl_phase=(smpl_raise+smpl_fall)/2;+dev_dbg(host->dev,"Found valid delay chain! use it [delay=%d]\n",smpl_phase);+ret=0;-ret=of_parse_phandle_with_fixed_args(host->dev->of_node,-"starfive,sysreg",3,0,&args);-if(ret){-dev_err(host->dev,"Failed to parse starfive,sysreg\n");-return-EINVAL;-}--priv->reg_syscon=syscon_node_to_regmap(args.np);-of_node_put(args.np);-if(IS_ERR(priv->reg_syscon))-returnPTR_ERR(priv->reg_syscon);--priv->syscon_offset=args.args[0];-priv->syscon_shift=args.args[1];-priv->syscon_mask=args.args[2];--host->priv=priv;--return0;+out:+dw_mci_starfive_set_sample_phase(host,smpl_phase);+mci_writel(host,RINTSTS,ALL_INT_CLR);+returnret;}staticconststructdw_mci_drv_datastarfive_data={.common_caps=MMC_CAP_CMD23,.set_ios=dw_mci_starfive_set_ios,-.parse_dt=dw_mci_starfive_parse_dt,.execute_tuning=dw_mci_starfive_execute_tuning,};
From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-12 08:14:21
Drop unused properties and limit cclk_in to 50M, thus cancelling the
internal frequency and adopting the by-pass mode.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
---
.../riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi | 4 ++++
arch/riscv/boot/dts/starfive/jh7110.dtsi | 2 --
2 files changed, 4 insertions(+), 2 deletions(-)
From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-12 08:14:23
Before, we used syscon to achieve tuning, but the actual measurement
showed little effect, so the tuning implementation was modified here,
and it was realized by reading and writing the UHS_REG_EXT register.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
---
drivers/mmc/host/dw_mmc-starfive.c | 137 +++++++++--------------------
1 file changed, 40 insertions(+), 97 deletions(-)
@@ -44,117 +38,66 @@ static void dw_mci_starfive_set_ios(struct dw_mci *host, struct mmc_ios *ios)}}+staticvoiddw_mci_starfive_set_sample_phase(structdw_mci*host,u32smpl_phase)+{+/* change driver phase and sample phase */+u32mask=0x1f;+u32reg_value=mci_readl(host,UHS_REG_EXT);++/* In UHS_REG_EXT, only 5 bits valid in DRV_PHASE and SMPL_PHASE */+reg_value&=~STARFIVE_SMPL_PHASE;+reg_value|=FIELD_PREP(STARFIVE_SMPL_PHASE,smpl_phase);+mci_writel(host,UHS_REG_EXT,reg_value);++/* We should delay 1ms wait for timing setting finished. */+mdelay(1);+}+staticintdw_mci_starfive_execute_tuning(structdw_mci_slot*slot,u32opcode){staticconstintgrade=MAX_DELAY_CHAIN;structdw_mci*host=slot->host;-structstarfive_priv*priv=host->priv;-intrise_point=-1,fall_point=-1;-interr,prev_err=0;-inti;-boolfound=0;-u32regval;--/*-*Usegradeasthemaxdelaychain,andusetherise_pointand-*fall_pointtoensurethebestsamplingpointofadatainput-*signals.-*/-for(i=0;i<grade;i++){-regval=i<<priv->syscon_shift;-err=regmap_update_bits(priv->reg_syscon,priv->syscon_offset,-priv->syscon_mask,regval);-if(err)-returnerr;+intsmpl_phase,smpl_raise=-1,smpl_fall=-1;+intret;++for(smpl_phase=0;smpl_phase<grade;smpl_phase++){+dw_mci_starfive_set_sample_phase(host,smpl_phase);mci_writel(host,RINTSTS,ALL_INT_CLR);-err=mmc_send_tuning(slot->mmc,opcode,NULL);-if(!err)-found=1;+ret=mmc_send_tuning(slot->mmc,opcode,NULL);-if(i>0){-if(err&&!prev_err)-fall_point=i-1;-if(!err&&prev_err)-rise_point=i;+if(!ret&&smpl_raise<0){+smpl_raise=smpl_phase;+}elseif(ret&&smpl_raise>=0){+smpl_fall=smpl_phase-1;+break;}--if(rise_point!=-1&&fall_point!=-1)-gototuning_out;--prev_err=err;-err=0;}-tuning_out:-if(found){-if(rise_point==-1)-rise_point=0;-if(fall_point==-1)-fall_point=grade-1;-if(fall_point<rise_point){-if((rise_point+fall_point)>-(grade-1))-i=fall_point/2;-else-i=(rise_point+grade-1)/2;-}else{-i=(rise_point+fall_point)/2;-}--regval=i<<priv->syscon_shift;-err=regmap_update_bits(priv->reg_syscon,priv->syscon_offset,-priv->syscon_mask,regval);-if(err)-returnerr;-mci_writel(host,RINTSTS,ALL_INT_CLR);+if(smpl_phase>=grade&&smpl_raise>=0)+smpl_fall=grade-1;-dev_info(host->dev,"Found valid delay chain! use it [delay=%d]\n",i);-}else{+if(smpl_raise<0){+smpl_phase=0;dev_err(host->dev,"No valid delay chain! use default\n");-err=-EINVAL;+ret=-EINVAL;+gotoout;}-mci_writel(host,RINTSTS,ALL_INT_CLR);-returnerr;-}--staticintdw_mci_starfive_parse_dt(structdw_mci*host)-{-structof_phandle_argsargs;-structstarfive_priv*priv;-intret;--priv=devm_kzalloc(host->dev,sizeof(*priv),GFP_KERNEL);-if(!priv)-return-ENOMEM;+smpl_phase=(smpl_raise+smpl_fall)/2;+dev_dbg(host->dev,"Found valid delay chain! use it [delay=%d]\n",smpl_phase);+ret=0;-ret=of_parse_phandle_with_fixed_args(host->dev->of_node,-"starfive,sysreg",3,0,&args);-if(ret){-dev_err(host->dev,"Failed to parse starfive,sysreg\n");-return-EINVAL;-}--priv->reg_syscon=syscon_node_to_regmap(args.np);-of_node_put(args.np);-if(IS_ERR(priv->reg_syscon))-returnPTR_ERR(priv->reg_syscon);--priv->syscon_offset=args.args[0];-priv->syscon_shift=args.args[1];-priv->syscon_mask=args.args[2];--host->priv=priv;--return0;+out:+dw_mci_starfive_set_sample_phase(host,smpl_phase);+mci_writel(host,RINTSTS,ALL_INT_CLR);+returnret;}staticconststructdw_mci_drv_datastarfive_data={.common_caps=MMC_CAP_CMD23,.set_ios=dw_mci_starfive_set_ios,-.parse_dt=dw_mci_starfive_parse_dt,.execute_tuning=dw_mci_starfive_execute_tuning,};
From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-12 08:14:26
Drop unused properties and limit cclk_in to 50M, thus cancelling the
internal frequency and adopting the by-pass mode.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
---
.../riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi | 4 ++++
arch/riscv/boot/dts/starfive/jh7110.dtsi | 2 --
2 files changed, 4 insertions(+), 2 deletions(-)
From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-12 08:14:28
Hi,
This series of patches changes the tuning implementation, from the
previous way of reading and writing system controller registers to
reading and writing UHS_REG_EXT register, thus optimizing the tuning
of obtaining delay-chain.
Changes v1->v2:
- Rebased to v6.6rc1.
- Keeped "starfive,sysreg" in dt-bindings but removed from required.
- Changed the function interface name.
- Maked the code implementation more concise.
The patch series is based on v6.6rc1.
William Qiu (3):
dt-bindings: mmc: Remove properties from required
mmc: starfive: Change tuning implementation
riscv: dts: starfive: Drop unused properties and limit frquency
.../bindings/mmc/starfive,jh7110-mmc.yaml | 2 -
.../jh7110-starfive-visionfive-2.dtsi | 4 +
arch/riscv/boot/dts/starfive/jh7110.dtsi | 2 -
drivers/mmc/host/dw_mmc-starfive.c | 137 +++++-------------
4 files changed, 44 insertions(+), 101 deletions(-)
--
2.34.1
From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-12 08:14:35
Due to the change of tuning implementation, it's no longer necessary to
use the "starfive,sysreg" property in dts, so remove it from required.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
---
Documentation/devicetree/bindings/mmc/starfive,jh7110-mmc.yaml | 2 --
1 file changed, 2 deletions(-)
From: Emil Renner Berthing <hidden> Date: 2023-09-12 09:12:50
William Qiu wrote:
Due to the change of tuning implementation, it's no longer necessary to
use the "starfive,sysreg" property in dts, so remove it from required.
nit: again the device tree should be a description of the hardware, so the
justification here shouldn't be that the Linux driver doesn't use the field,
but that it turns out the registers aren't required for the peripheral to work
properly. Don't respin the series just for this though.
Reviewed-by: Emil Renner Berthing <redacted>
From: Emil Renner Berthing <hidden> Date: 2023-09-12 13:20:17
William Qiu wrote:
quoted hunk
Before, we used syscon to achieve tuning, but the actual measurement
showed little effect, so the tuning implementation was modified here,
and it was realized by reading and writing the UHS_REG_EXT register.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
---
drivers/mmc/host/dw_mmc-starfive.c | 137 +++++++++--------------------
1 file changed, 40 insertions(+), 97 deletions(-)
@@ -44,117 +39,65 @@ static void dw_mci_starfive_set_ios(struct dw_mci *host, struct mmc_ios *ios)}}+staticvoiddw_mci_starfive_set_sample_phase(structdw_mci*host,u32smpl_phase)+{+/* change driver phase and sample phase */+u32reg_value=mci_readl(host,UHS_REG_EXT);++/* In UHS_REG_EXT, only 5 bits valid in DRV_PHASE and SMPL_PHASE */+reg_value&=~STARFIVE_SMPL_PHASE;+reg_value|=FIELD_PREP(STARFIVE_SMPL_PHASE,smpl_phase);+mci_writel(host,UHS_REG_EXT,reg_value);++/* We should delay 1ms wait for timing setting finished. */+mdelay(1);+}+staticintdw_mci_starfive_execute_tuning(structdw_mci_slot*slot,u32opcode){staticconstintgrade=MAX_DELAY_CHAIN;structdw_mci*host=slot->host;-structstarfive_priv*priv=host->priv;-intrise_point=-1,fall_point=-1;-interr,prev_err=0;-inti;-boolfound=0;-u32regval;--/*-*Usegradeasthemaxdelaychain,andusetherise_pointand-*fall_pointtoensurethebestsamplingpointofadatainput-*signals.-*/-for(i=0;i<grade;i++){-regval=i<<priv->syscon_shift;-err=regmap_update_bits(priv->reg_syscon,priv->syscon_offset,-priv->syscon_mask,regval);-if(err)-returnerr;+intsmpl_phase,smpl_raise=-1,smpl_fall=-1;+intret;++for(smpl_phase=0;smpl_phase<grade;smpl_phase++){+dw_mci_starfive_set_sample_phase(host,smpl_phase);mci_writel(host,RINTSTS,ALL_INT_CLR);-err=mmc_send_tuning(slot->mmc,opcode,NULL);-if(!err)-found=1;+ret=mmc_send_tuning(slot->mmc,opcode,NULL);-if(i>0){-if(err&&!prev_err)-fall_point=i-1;-if(!err&&prev_err)-rise_point=i;+if(!ret&&smpl_raise<0){+smpl_raise=smpl_phase;+}elseif(ret&&smpl_raise>=0){+smpl_fall=smpl_phase-1;+break;}--if(rise_point!=-1&&fall_point!=-1)-gototuning_out;--prev_err=err;-err=0;}-tuning_out:-if(found){-if(rise_point==-1)-rise_point=0;-if(fall_point==-1)-fall_point=grade-1;-if(fall_point<rise_point){-if((rise_point+fall_point)>-(grade-1))-i=fall_point/2;-else-i=(rise_point+grade-1)/2;-}else{-i=(rise_point+fall_point)/2;-}--regval=i<<priv->syscon_shift;-err=regmap_update_bits(priv->reg_syscon,priv->syscon_offset,-priv->syscon_mask,regval);-if(err)-returnerr;-mci_writel(host,RINTSTS,ALL_INT_CLR);+if(smpl_phase>=grade&&smpl_raise>=0)+smpl_fall=grade-1;
If you switch the order of the two if's above and below you won't need the
smpl_raise >= 0 clause here. With that cleaned up:
Reviewed-by: Emil Renner Berthing <redacted>
From: Emil Renner Berthing <hidden> Date: 2023-09-12 13:23:47
William Qiu wrote:
Drop unused properties and limit cclk_in to 50M, thus cancelling the
internal frequency and adopting the by-pass mode.
That's two unrelated changes which should really be in different patches. But
again the hardware still has the relevant field in the syscon registers even if
the driver doesn't use it, so maybe just leave them and just keep this patch
adding the assigned-clock* properties.
/Emil
On Tue, Sep 12, 2023 at 04:14:00PM +0800, William Qiu wrote:
Due to the change of tuning implementation, it's no longer necessary to
use the "starfive,sysreg" property in dts, so remove it from required.
Signed-off-by: William Qiu <william.qiu@starfivetech.com>
$subject probably should be more specific about what binding is being
modified.
Otherwise,
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Thanks,
Conor.
On Tue, Sep 12, 2023 at 02:12:44AM -0700, Emil Renner Berthing wrote:
William Qiu wrote:
quoted
Due to the change of tuning implementation, it's no longer necessary to
use the "starfive,sysreg" property in dts, so remove it from required.
nit: again the device tree should be a description of the hardware, so the
justification here shouldn't be that the Linux driver doesn't use the field,
but that it turns out the registers aren't required for the peripheral to work
properly. Don't respin the series just for this though.
Reviewed-by: Emil Renner Berthing <redacted>
The fact that I can't actually apply this without breaking bisection
kinda hints at removing it in this patch is incorrect.
From: Rob Herring <robh@kernel.org> Date: 2023-09-12 17:55:56
On Tue, Sep 12, 2023 at 04:13:59PM +0800, William Qiu wrote:
Hi,
This series of patches changes the tuning implementation, from the
previous way of reading and writing system controller registers to
reading and writing UHS_REG_EXT register, thus optimizing the tuning
of obtaining delay-chain.
Changes v1->v2:
Please don't send new versions as a reply to the prior version.
- Rebased to v6.6rc1.
- Keeped "starfive,sysreg" in dt-bindings but removed from required.
- Changed the function interface name.
- Maked the code implementation more concise.
The patch series is based on v6.6rc1.
William Qiu (3):
dt-bindings: mmc: Remove properties from required
mmc: starfive: Change tuning implementation
riscv: dts: starfive: Drop unused properties and limit frquency
.../bindings/mmc/starfive,jh7110-mmc.yaml | 2 -
.../jh7110-starfive-visionfive-2.dtsi | 4 +
arch/riscv/boot/dts/starfive/jh7110.dtsi | 2 -
drivers/mmc/host/dw_mmc-starfive.c | 137 +++++-------------
4 files changed, 44 insertions(+), 101 deletions(-)
--
2.34.1
From: William Qiu <william.qiu@starfivetech.com> Date: 2023-09-13 10:50:40
On 2023/9/12 21:23, Emil Renner Berthing wrote:
William Qiu wrote:
quoted
Drop unused properties and limit cclk_in to 50M, thus cancelling the
internal frequency and adopting the by-pass mode.
That's two unrelated changes which should really be in different patches. But
again the hardware still has the relevant field in the syscon registers even if
the driver doesn't use it, so maybe just leave them and just keep this patch
adding the assigned-clock* properties.
/Emil