Re: [PATCH 7/8] sunxi: Parameterize bit delay code in H616 DRAM driver

2023-01-04 Thread Jernej Škrabec
Dne sreda, 04. januar 2023 ob 01:37:47 CET je Andre Przywara napisal(a):
> On Sun, 11 Dec 2022 17:32:12 +0100
> Jernej Skrabec  wrote:
> 
> Hi Jernej,
> 
> > These values are highly board specific and thus make sense to add
> > parameter for them. To ease adding support for new boards, let's make
> > them same as in vendor DRAM settings.
> 
> So scrolling up and down: does this patch miss the TPR11 and TPR12
> values in the OPi-Zero2 defconfig? 

No, because 0 (which is default) is correct here.

> And should we not default to 0 in
> Kconfig to help spotting this omission more easily for new boards?

Not all boards need to set all the values. I set default values for symbols 
which seem to have same value for multiple boards.

> If I pieced the bits together correctly, we end up with the same values
> in the register with TPR11=0xfffedddb and TPR12=0xeddca998, and ODT_EN
> being irrelevant.
> 
> > Signed-off-by: Jernej Skrabec 
> > ---
> > 
> >  .../include/asm/arch-sunxi/dram_sun50i_h616.h |   4 +
> >  arch/arm/mach-sunxi/Kconfig   |  18 ++
> >  arch/arm/mach-sunxi/dram_sun50i_h616.c| 189 +-
> >  3 files changed, 162 insertions(+), 49 deletions(-)
> > 
> > diff --git a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> > b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h index
> > b5140c79b70e..c7890c83391f 100644
> > --- a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> > +++ b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> > @@ -145,6 +145,7 @@ check_member(sunxi_mctl_ctl_reg, unk_0x4240, 0x4240);
> > 
> >  #define TPR10_READ_CALIBRATION BIT(21)
> >  #define TPR10_READ_TRAININGBIT(22)
> >  #define TPR10_WRITE_TRAINING   BIT(23)
> > 
> > +#define TPR10_UNKNOWN_FEAT3BIT(30)
> 
> As mentioned in the other patch: if we don't know the meaning of this
> bit, I'd prefer using BIT(30) directly, or at least encode BIT30
> in the name.
> 
> >  struct dram_para {
> >  
> > u32 clk;
> > 
> > @@ -156,7 +157,10 @@ struct dram_para {
> > 
> > u32 dx_odt;
> > u32 dx_dri;
> > u32 ca_dri;
> > 
> > +   u32 odt_en;
> > 
> > u32 tpr10;
> > 
> > +   u32 tpr11;
> > +   u32 tpr12;
> > 
> >  };
> > 
> > diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> > index 778304b77e26..b050f0a56971 100644
> > --- a/arch/arm/mach-sunxi/Kconfig
> > +++ b/arch/arm/mach-sunxi/Kconfig
> > @@ -67,11 +67,29 @@ config DRAM_SUN50I_H616_CA_DRI
> > 
> > help
> > 
> >   CA DRI value from vendor DRAM settings.
> > 
> > +config DRAM_SUN50I_H616_ODT_EN
> > +   hex "H616 DRAM ODT EN parameter"
> > +   default 0x1
> > +   help
> > + ODT EN value from vendor DRAM settings.
> > +
> > 
> >  config DRAM_SUN50I_H616_TPR10
> >  
> > hex "H616 DRAM TPR10 parameter"
> > help
> > 
> >   TPR10 value from vendor DRAM settings. It tells which features
> >   should be configured, like write leveling, read calibration, 
etc.
> > 
> > +
> > +config DRAM_SUN50I_H616_TPR11
> > +   hex "H616 DRAM TPR11 parameter"
> > +   default 0x0
> > +   help
> > + TPR11 value from vendor DRAM settings.
> > +
> > +config DRAM_SUN50I_H616_TPR12
> > +   hex "H616 DRAM TPR12 parameter"
> > +   default 0x0
> > +   help
> > + TPR12 value from vendor DRAM settings.
> > 
> >  endif
> >  
> >  config SUN6I_PRCM
> > 
> > diff --git a/arch/arm/mach-sunxi/dram_sun50i_h616.c
> > b/arch/arm/mach-sunxi/dram_sun50i_h616.c index 3b2ba168498c..df06cea42464
> > 100644
> > --- a/arch/arm/mach-sunxi/dram_sun50i_h616.c
> > +++ b/arch/arm/mach-sunxi/dram_sun50i_h616.c
> > @@ -574,7 +574,7 @@ static bool mctl_phy_write_training(struct dram_para
> > *para)> 
> >  static void mctl_phy_bit_delay_compensation(struct dram_para *para)
> >  {
> > 
> > -   u32 *ptr;
> > +   u32 *ptr, val;
> > 
> > int i;
> > 
> > if (para->tpr10 & TPR10_UNKNOWN_FEAT2) {
> > 
> > @@ -582,49 +582,93 @@ static void mctl_phy_bit_delay_compensation(struct
> > dram_para *para)> 
> > setbits_le32(SUNXI_DRAM_PHY0_BASE + 8, 8);
> > clrbits_le32(SUNXI_DRAM_PHY0_BASE + 0x190, 0x10);
> > 
> > +   if (para->tpr10 & TPR10_UNKNOWN_FEAT3)
> > +   val = para->tpr11 & 0x3f;
> > +   else
> > +   val = (para->tpr11 & 0xf) << 1;
> > +
> > 
> > ptr = (u32 *)(SUNXI_DRAM_PHY0_BASE + 0x484);
> > for (i = 0; i < 9; i++) {
> > 
> > -   writel_relaxed(0x16, ptr);
> > -   writel_relaxed(0x16, ptr + 0x30);
> > +   writel_relaxed(val, ptr);
> > +   writel_relaxed(val, ptr + 0x30);
> > 
> > ptr += 2;
> > 
> > }
> > 
> > -   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x4d0);
> > -   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x590);
> > -   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x4cc);
> > -   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x58c);
> > +
> 

Re: [PATCH 7/8] sunxi: Parameterize bit delay code in H616 DRAM driver

2023-01-03 Thread Andre Przywara
On Sun, 11 Dec 2022 17:32:12 +0100
Jernej Skrabec  wrote:

Hi Jernej,

> These values are highly board specific and thus make sense to add
> parameter for them. To ease adding support for new boards, let's make
> them same as in vendor DRAM settings.

So scrolling up and down: does this patch miss the TPR11 and TPR12
values in the OPi-Zero2 defconfig? And should we not default to 0 in
Kconfig to help spotting this omission more easily for new boards?
If I pieced the bits together correctly, we end up with the same values
in the register with TPR11=0xfffedddb and TPR12=0xeddca998, and ODT_EN
being irrelevant.

> Signed-off-by: Jernej Skrabec 
> ---
>  .../include/asm/arch-sunxi/dram_sun50i_h616.h |   4 +
>  arch/arm/mach-sunxi/Kconfig   |  18 ++
>  arch/arm/mach-sunxi/dram_sun50i_h616.c| 189 +-
>  3 files changed, 162 insertions(+), 49 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h 
> b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> index b5140c79b70e..c7890c83391f 100644
> --- a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> +++ b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
> @@ -145,6 +145,7 @@ check_member(sunxi_mctl_ctl_reg, unk_0x4240, 0x4240);
>  #define TPR10_READ_CALIBRATION   BIT(21)
>  #define TPR10_READ_TRAINING  BIT(22)
>  #define TPR10_WRITE_TRAINING BIT(23)
> +#define TPR10_UNKNOWN_FEAT3  BIT(30)

As mentioned in the other patch: if we don't know the meaning of this
bit, I'd prefer using BIT(30) directly, or at least encode BIT30
in the name.

>  
>  struct dram_para {
>   u32 clk;
> @@ -156,7 +157,10 @@ struct dram_para {
>   u32 dx_odt;
>   u32 dx_dri;
>   u32 ca_dri;
> + u32 odt_en;
>   u32 tpr10;
> + u32 tpr11;
> + u32 tpr12;
>  };
>  
>  
> diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> index 778304b77e26..b050f0a56971 100644
> --- a/arch/arm/mach-sunxi/Kconfig
> +++ b/arch/arm/mach-sunxi/Kconfig
> @@ -67,11 +67,29 @@ config DRAM_SUN50I_H616_CA_DRI
>   help
> CA DRI value from vendor DRAM settings.
>  
> +config DRAM_SUN50I_H616_ODT_EN
> + hex "H616 DRAM ODT EN parameter"
> + default 0x1
> + help
> +   ODT EN value from vendor DRAM settings.
> +
>  config DRAM_SUN50I_H616_TPR10
>   hex "H616 DRAM TPR10 parameter"
>   help
> TPR10 value from vendor DRAM settings. It tells which features
> should be configured, like write leveling, read calibration, etc.
> +
> +config DRAM_SUN50I_H616_TPR11
> + hex "H616 DRAM TPR11 parameter"
> + default 0x0
> + help
> +   TPR11 value from vendor DRAM settings.
> +
> +config DRAM_SUN50I_H616_TPR12
> + hex "H616 DRAM TPR12 parameter"
> + default 0x0
> + help
> +   TPR12 value from vendor DRAM settings.
>  endif
>  
>  config SUN6I_PRCM
> diff --git a/arch/arm/mach-sunxi/dram_sun50i_h616.c 
> b/arch/arm/mach-sunxi/dram_sun50i_h616.c
> index 3b2ba168498c..df06cea42464 100644
> --- a/arch/arm/mach-sunxi/dram_sun50i_h616.c
> +++ b/arch/arm/mach-sunxi/dram_sun50i_h616.c
> @@ -574,7 +574,7 @@ static bool mctl_phy_write_training(struct dram_para 
> *para)
>  
>  static void mctl_phy_bit_delay_compensation(struct dram_para *para)
>  {
> - u32 *ptr;
> + u32 *ptr, val;
>   int i;
>  
>   if (para->tpr10 & TPR10_UNKNOWN_FEAT2) {
> @@ -582,49 +582,93 @@ static void mctl_phy_bit_delay_compensation(struct 
> dram_para *para)
>   setbits_le32(SUNXI_DRAM_PHY0_BASE + 8, 8);
>   clrbits_le32(SUNXI_DRAM_PHY0_BASE + 0x190, 0x10);
>  
> + if (para->tpr10 & TPR10_UNKNOWN_FEAT3)
> + val = para->tpr11 & 0x3f;
> + else
> + val = (para->tpr11 & 0xf) << 1;
> +
>   ptr = (u32 *)(SUNXI_DRAM_PHY0_BASE + 0x484);
>   for (i = 0; i < 9; i++) {
> - writel_relaxed(0x16, ptr);
> - writel_relaxed(0x16, ptr + 0x30);
> + writel_relaxed(val, ptr);
> + writel_relaxed(val, ptr + 0x30);
>   ptr += 2;
>   }
> - writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x4d0);
> - writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x590);
> - writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x4cc);
> - writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x58c);
> +
> + if (para->tpr10 & TPR10_UNKNOWN_FEAT3)
> + val = (para->odt_en >> 15) & 0x1e;

So I guess odt_en stands for "ODT enable". Looking at the D1 DRAM
driver, they have a boot0 parameter odt_en which is either 0x0 or 0x1,
so it looks like a boolean value. This seems to be also the case here?
In the D1 driver, this seems to gate the ZQ value being used, which
provides the actual timing values.
So is TPR10_UNKNOWN_FEAT3 actually this ODT_EN switch, and the variable
containing the timing bits should be zq_value or CONFIG_DRAM_ZQ?

[PATCH 7/8] sunxi: Parameterize bit delay code in H616 DRAM driver

2022-12-11 Thread Jernej Skrabec
These values are highly board specific and thus make sense to add
parameter for them. To ease adding support for new boards, let's make
them same as in vendor DRAM settings.

Signed-off-by: Jernej Skrabec 
---
 .../include/asm/arch-sunxi/dram_sun50i_h616.h |   4 +
 arch/arm/mach-sunxi/Kconfig   |  18 ++
 arch/arm/mach-sunxi/dram_sun50i_h616.c| 189 +-
 3 files changed, 162 insertions(+), 49 deletions(-)

diff --git a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h 
b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
index b5140c79b70e..c7890c83391f 100644
--- a/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
+++ b/arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h
@@ -145,6 +145,7 @@ check_member(sunxi_mctl_ctl_reg, unk_0x4240, 0x4240);
 #define TPR10_READ_CALIBRATION BIT(21)
 #define TPR10_READ_TRAININGBIT(22)
 #define TPR10_WRITE_TRAINING   BIT(23)
+#define TPR10_UNKNOWN_FEAT3BIT(30)
 
 struct dram_para {
u32 clk;
@@ -156,7 +157,10 @@ struct dram_para {
u32 dx_odt;
u32 dx_dri;
u32 ca_dri;
+   u32 odt_en;
u32 tpr10;
+   u32 tpr11;
+   u32 tpr12;
 };
 
 
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 778304b77e26..b050f0a56971 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -67,11 +67,29 @@ config DRAM_SUN50I_H616_CA_DRI
help
  CA DRI value from vendor DRAM settings.
 
+config DRAM_SUN50I_H616_ODT_EN
+   hex "H616 DRAM ODT EN parameter"
+   default 0x1
+   help
+ ODT EN value from vendor DRAM settings.
+
 config DRAM_SUN50I_H616_TPR10
hex "H616 DRAM TPR10 parameter"
help
  TPR10 value from vendor DRAM settings. It tells which features
  should be configured, like write leveling, read calibration, etc.
+
+config DRAM_SUN50I_H616_TPR11
+   hex "H616 DRAM TPR11 parameter"
+   default 0x0
+   help
+ TPR11 value from vendor DRAM settings.
+
+config DRAM_SUN50I_H616_TPR12
+   hex "H616 DRAM TPR12 parameter"
+   default 0x0
+   help
+ TPR12 value from vendor DRAM settings.
 endif
 
 config SUN6I_PRCM
diff --git a/arch/arm/mach-sunxi/dram_sun50i_h616.c 
b/arch/arm/mach-sunxi/dram_sun50i_h616.c
index 3b2ba168498c..df06cea42464 100644
--- a/arch/arm/mach-sunxi/dram_sun50i_h616.c
+++ b/arch/arm/mach-sunxi/dram_sun50i_h616.c
@@ -574,7 +574,7 @@ static bool mctl_phy_write_training(struct dram_para *para)
 
 static void mctl_phy_bit_delay_compensation(struct dram_para *para)
 {
-   u32 *ptr;
+   u32 *ptr, val;
int i;
 
if (para->tpr10 & TPR10_UNKNOWN_FEAT2) {
@@ -582,49 +582,93 @@ static void mctl_phy_bit_delay_compensation(struct 
dram_para *para)
setbits_le32(SUNXI_DRAM_PHY0_BASE + 8, 8);
clrbits_le32(SUNXI_DRAM_PHY0_BASE + 0x190, 0x10);
 
+   if (para->tpr10 & TPR10_UNKNOWN_FEAT3)
+   val = para->tpr11 & 0x3f;
+   else
+   val = (para->tpr11 & 0xf) << 1;
+
ptr = (u32 *)(SUNXI_DRAM_PHY0_BASE + 0x484);
for (i = 0; i < 9; i++) {
-   writel_relaxed(0x16, ptr);
-   writel_relaxed(0x16, ptr + 0x30);
+   writel_relaxed(val, ptr);
+   writel_relaxed(val, ptr + 0x30);
ptr += 2;
}
-   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x4d0);
-   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x590);
-   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x4cc);
-   writel_relaxed(0x1c, SUNXI_DRAM_PHY0_BASE + 0x58c);
+
+   if (para->tpr10 & TPR10_UNKNOWN_FEAT3)
+   val = (para->odt_en >> 15) & 0x1e;
+   else
+   val = (para->tpr11 >> 15) & 0x1e;
+
+   writel_relaxed(val, SUNXI_DRAM_PHY0_BASE + 0x4d0);
+   writel_relaxed(val, SUNXI_DRAM_PHY0_BASE + 0x590);
+   writel_relaxed(val, SUNXI_DRAM_PHY0_BASE + 0x4cc);
+   writel_relaxed(val, SUNXI_DRAM_PHY0_BASE + 0x58c);
+
+   if (para->tpr10 & TPR10_UNKNOWN_FEAT3)
+   val = (para->tpr11 >> 8) & 0x3f;
+   else
+   val = (para->tpr11 >> 3) & 0x1e;
 
ptr = (u32 *)(SUNXI_DRAM_PHY0_BASE + 0x4d8);
for (i = 0; i < 9; i++) {
-   writel_relaxed(0x1a, ptr);
-   writel_relaxed(0x1a, ptr + 0x30);
+   writel_relaxed(val, ptr);
+   writel_relaxed(val, ptr + 0x30);
ptr += 2;
}
-   writel_relaxed(0x1e, SUNXI_DRAM_PHY0_BASE + 0x524);
-   writel_relaxed(0x1e, SUNXI_DRAM_PHY0_BASE + 0x5e4);
-   writel_relaxed(0x1e, SUNXI_DRAM_PHY0_BASE + 0x520);
-