Re: [PATCH 0/8] sunxi: Update H616 DRAM driver

2023-01-04 Thread Andre Przywara
On Wed, 04 Jan 2023 22:02:33 +0100
Jernej Škrabec  wrote:

Hi Jernej,

> Dne sreda, 04. januar 2023 ob 01:47:16 CET je Andre Przywara napisal(a):
> > On Sun, 11 Dec 2022 17:32:05 +0100
> > Jernej Skrabec  wrote:
> > 
> > Hi Jernej,
> >   
> > > Current H616 DRAM driver is completely customized to Orange Pi Zero2
> > > board, which is currently the only H616 board supported by U-Boot.
> > > Needless to say, this is not ideal for adding new boards. With changes
> > > in this series, all DDR3 boards are supported and all that is needed is
> > > just vendor DRAM values extracted from Android image. New DRAM types
> > > should also be easier to support, since a lot of constants used before
> > > are not really DRAM type dependent.
> > > 
> > > Changes were verified by decompiling driver and generated values were
> > > compared to previous, hard coded ones. This was done without dram_para
> > > structures, so compiler was able to heavily optimize code and produce
> > > constants.  
> > 
> > so many thanks again for putting this together!
> > I came to like (the idea of) this series very much lately, as this
> > removes timing/delay values from the code, and easily allows putting the
> > vendor provided values in the defconfig.
> > I used that approach as well for the D1 driver, and am wondering if we
> > should extend this to other SoCs, potentially unifying the Kconfig part?  
> 
> While it would be nice, I'm not sure it's worth the effort and there is a 
> chance that something might break during rework.

Fair enough, was just an idea.

> > And you hinted at a v2, can you provide an estimate for this? If you
> > send it still this week, I would like to put it into U-Boot's next
> > branch, otherwise it goes straight into master, should the merge window
> > open next week as planned.  
> 
> I have changes for v2 in my github repo. I don't have any estimation, since I 
> had some time off from programming lately

Sounds good!

> and I'm just only catching up. 
> Weekend at earliest, but no promises.

No worries, that was a genuine question, for my planning. I have plenty
of other things to do, and we have still plenty of time (till end of
January or so) to get things merged.

> > Btw., to verify the feasibility of drivers/ram/sunxi, I moved the H616
> > driver into there, together with the Kconfig parts, I wonder what you
> > think about this? An example of how this looks is in the D1 driver
> > patches.  
> 
> Looks good, but I don't know what are implications regarding interface. Is 
> just code move or that implies that some ram framework must be used?

I don't know what Simon and Tom will say, but I was cheekily just using
the directory, ignoring the current DM_SPL preference for code in
there. For the D1/T113s code this is probably a no-brainer, but
I also found it a nice and simple solution to declutter and cleanup
arch/arm/mach-sunxi and its Kconfig.
So yeah, it's just moving the files and Kconfig stanzas there, and
otherwise leaves the actual code untouched. We still call
sunxi_dram_init() from our legacy SPL code.

Cheers,
Andre


> 
> Best regards,
> Jernej
> 
> > 
> > Cheers,
> > Andre
> >   
> > > Please take a look.
> > > 
> > > Best regards,
> > > Jernej
> > > 
> > > Jernej Skrabec (8):
> > >   sunxi: Fix write to H616 DRAM CR register
> > >   sunxi: cosmetic: Fix H616 DRAM driver code style
> > >   sunxi: parameterize H616 DRAM ODT values
> > >   sunxi: Convert H616 DRAM options to single setting
> > >   sunxi: Always configure ODT on H616 DRAM
> > >   sunxi: Make bit delay function in H616 DRAM code void
> > >   sunxi: Parameterize bit delay code in H616 DRAM driver
> > >   sunxi: Parameterize H616 DRAM code some more
> > >  
> > >  .../include/asm/arch-sunxi/dram_sun50i_h616.h |  18 +
> > >  arch/arm/mach-sunxi/Kconfig   |  67 +--
> > >  arch/arm/mach-sunxi/dram_sun50i_h616.c| 445 +++---
> > >  configs/orangepi_zero2_defconfig  |   8 +-
> > >  4 files changed, 348 insertions(+), 190 deletions(-)  
> 
> 
> 
> 



Re: [PATCH 0/8] sunxi: Update H616 DRAM driver

2023-01-04 Thread Jernej Škrabec
Hi Andre!

Dne sreda, 04. januar 2023 ob 01:47:16 CET je Andre Przywara napisal(a):
> On Sun, 11 Dec 2022 17:32:05 +0100
> Jernej Skrabec  wrote:
> 
> Hi Jernej,
> 
> > Current H616 DRAM driver is completely customized to Orange Pi Zero2
> > board, which is currently the only H616 board supported by U-Boot.
> > Needless to say, this is not ideal for adding new boards. With changes
> > in this series, all DDR3 boards are supported and all that is needed is
> > just vendor DRAM values extracted from Android image. New DRAM types
> > should also be easier to support, since a lot of constants used before
> > are not really DRAM type dependent.
> > 
> > Changes were verified by decompiling driver and generated values were
> > compared to previous, hard coded ones. This was done without dram_para
> > structures, so compiler was able to heavily optimize code and produce
> > constants.
> 
> so many thanks again for putting this together!
> I came to like (the idea of) this series very much lately, as this
> removes timing/delay values from the code, and easily allows putting the
> vendor provided values in the defconfig.
> I used that approach as well for the D1 driver, and am wondering if we
> should extend this to other SoCs, potentially unifying the Kconfig part?

While it would be nice, I'm not sure it's worth the effort and there is a 
chance that something might break during rework.

> 
> And you hinted at a v2, can you provide an estimate for this? If you
> send it still this week, I would like to put it into U-Boot's next
> branch, otherwise it goes straight into master, should the merge window
> open next week as planned.

I have changes for v2 in my github repo. I don't have any estimation, since I 
had some time off from programming lately and I'm just only catching up. 
Weekend at earliest, but no promises.

> 
> Btw., to verify the feasibility of drivers/ram/sunxi, I moved the H616
> driver into there, together with the Kconfig parts, I wonder what you
> think about this? An example of how this looks is in the D1 driver
> patches.

Looks good, but I don't know what are implications regarding interface. Is 
just code move or that implies that some ram framework must be used?

Best regards,
Jernej

> 
> Cheers,
> Andre
> 
> > Please take a look.
> > 
> > Best regards,
> > Jernej
> > 
> > Jernej Skrabec (8):
> >   sunxi: Fix write to H616 DRAM CR register
> >   sunxi: cosmetic: Fix H616 DRAM driver code style
> >   sunxi: parameterize H616 DRAM ODT values
> >   sunxi: Convert H616 DRAM options to single setting
> >   sunxi: Always configure ODT on H616 DRAM
> >   sunxi: Make bit delay function in H616 DRAM code void
> >   sunxi: Parameterize bit delay code in H616 DRAM driver
> >   sunxi: Parameterize H616 DRAM code some more
> >  
> >  .../include/asm/arch-sunxi/dram_sun50i_h616.h |  18 +
> >  arch/arm/mach-sunxi/Kconfig   |  67 +--
> >  arch/arm/mach-sunxi/dram_sun50i_h616.c| 445 +++---
> >  configs/orangepi_zero2_defconfig  |   8 +-
> >  4 files changed, 348 insertions(+), 190 deletions(-)






Re: [PATCH 0/8] sunxi: Update H616 DRAM driver

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

Hi Jernej,

> Current H616 DRAM driver is completely customized to Orange Pi Zero2
> board, which is currently the only H616 board supported by U-Boot.
> Needless to say, this is not ideal for adding new boards. With changes
> in this series, all DDR3 boards are supported and all that is needed is
> just vendor DRAM values extracted from Android image. New DRAM types
> should also be easier to support, since a lot of constants used before
> are not really DRAM type dependent.
> 
> Changes were verified by decompiling driver and generated values were
> compared to previous, hard coded ones. This was done without dram_para
> structures, so compiler was able to heavily optimize code and produce
> constants.

so many thanks again for putting this together!
I came to like (the idea of) this series very much lately, as this
removes timing/delay values from the code, and easily allows putting the
vendor provided values in the defconfig.
I used that approach as well for the D1 driver, and am wondering if we
should extend this to other SoCs, potentially unifying the Kconfig part?

And you hinted at a v2, can you provide an estimate for this? If you
send it still this week, I would like to put it into U-Boot's next
branch, otherwise it goes straight into master, should the merge window
open next week as planned.

Btw., to verify the feasibility of drivers/ram/sunxi, I moved the H616
driver into there, together with the Kconfig parts, I wonder what you
think about this? An example of how this looks is in the D1 driver
patches.

Cheers,
Andre

> 
> Please take a look.
> 
> Best regards,
> Jernej
> 
> Jernej Skrabec (8):
>   sunxi: Fix write to H616 DRAM CR register
>   sunxi: cosmetic: Fix H616 DRAM driver code style
>   sunxi: parameterize H616 DRAM ODT values
>   sunxi: Convert H616 DRAM options to single setting
>   sunxi: Always configure ODT on H616 DRAM
>   sunxi: Make bit delay function in H616 DRAM code void
>   sunxi: Parameterize bit delay code in H616 DRAM driver
>   sunxi: Parameterize H616 DRAM code some more
> 
>  .../include/asm/arch-sunxi/dram_sun50i_h616.h |  18 +
>  arch/arm/mach-sunxi/Kconfig   |  67 +--
>  arch/arm/mach-sunxi/dram_sun50i_h616.c| 445 +++---
>  configs/orangepi_zero2_defconfig  |   8 +-
>  4 files changed, 348 insertions(+), 190 deletions(-)
> 



Re: [PATCH 0/8] sunxi: Update H616 DRAM driver

2022-12-12 Thread Jernej Škrabec
Hi Andre,

Dne ponedeljek, 12. december 2022 ob 02:04:51 CET je Andre Przywara 
napisal(a):
> On Sun, 11 Dec 2022 17:32:05 +0100
> Jernej Skrabec  wrote:
> 
> Hi Jernej,
> 
> many thanks for putting this together!
> I will have a more elaborate look at each patch later.
> 
> > Current H616 DRAM driver is completely customized to Orange Pi Zero2
> > board, which is currently the only H616 board supported by U-Boot.
> 
> Not anymore, I merged the X96 Mate support lately, after the DT got
> merged into the Linux tree.

Right. First part of sentence is still true, although I later remembered that 
some values are based on T95 values, those that are not used by Orange Pi 
Zero2.

> 
> Those are the values for the box I came up with:
> CONFIG_DRAM_SUN50I_H616_DX_ODT=0x03030303
> CONFIG_DRAM_SUN50I_H616_DX_DRI=0x0e0e0e0e
> CONFIG_DRAM_SUN50I_H616_CA_DRI=0x1c12
> CONFIG_DRAM_SUN50I_H616_TPR0=0xcc05
> CONFIG_DRAM_SUN50I_H616_TPR10=0x2f0007
> CONFIG_DRAM_SUN50I_H616_TPR11=0x
> CONFIG_DRAM_SUN50I_H616_TPR12=0xfedf7557
> 
> based on this boot0 found in some firmware update image:
> 00045400  be 02 00 ea 65 47 4f 4e  2e 42 54 30 cc ba f3 80 
> |eGON.BT0| 00045410  00 c0 00 00 30 00 00 00  00 00 00 00 00 00 02
> 00  |0...| 00045420  00 00 02 00 00 00 00 00  00 00 00 00 34 2e
> 30 00  |4.0.| 00045430  00 00 00 00 03 00 00 00  88 02 00 00 03
> 00 00 00  || 00045440  03 03 03 03 0e 0e 0e 0e  12 1c 00 00
> 01 00 00 00  || 00045450  fb 30 00 00 00 00 00 00  40 08 00
> 00 04 00 00 00  |.0..@...| 00045460  08 00 00 00 00 00 00 00  00 00
> 00 00 00 00 00 00  || 00045470  00 00 00 00 00 00 00 00  00
> 00 00 00 00 00 00 00  || 00045480  00 00 00 00 00 00 00 00 
> 00 00 00 00 00 00 00 00  || 00045490  05 0c 00 c0 00 00 00
> 00  00 00 00 00 00 00 00 00  || 000454a0  80 80 80 33 07 00
> 2f 00  dd dd ff ff 57 75 df fe  |...3../.Wu..| 000454b0  40 00 00 00 00
> 00 00 00  00 00 00 00 08 00 02 01  |@...|
> 
> I would be grateful if you could verify this.

Looks correct. I'll use them in my v2 patches.

> 
> I built it, and it reported the 4GB correctly, also managed to boot into
> Linux just fine. No extensive testing, nor didn't I compare register
> dumps or disassembly (yet).
> 
> Cheers,
> Andre
> 
> P.S. Any plans on upstreaming support for your T95  H616 TV
> box? That would probably help the case here.

Not really, X96 Mate is basically the same as T95, except DRAM configuration. 
As I said, I verified that these patches provide same register values as 
before. This includes those which were modeled after T95 DRAM values.

Best regards,
Jernej

> 
> > Needless to say, this is not ideal for adding new boards. With changes
> > in this series, all DDR3 boards are supported and all that is needed is
> > just vendor DRAM values extracted from Android image. New DRAM types
> > should also be easier to support, since a lot of constants used before
> > are not really DRAM type dependent.
> > 
> > Changes were verified by decompiling driver and generated values were
> > compared to previous, hard coded ones. This was done without dram_para
> > structures, so compiler was able to heavily optimize code and produce
> > constants.
> > 
> > Please take a look.
> > 
> > Best regards,
> > Jernej
> > 
> > Jernej Skrabec (8):
> >   sunxi: Fix write to H616 DRAM CR register
> >   sunxi: cosmetic: Fix H616 DRAM driver code style
> >   sunxi: parameterize H616 DRAM ODT values
> >   sunxi: Convert H616 DRAM options to single setting
> >   sunxi: Always configure ODT on H616 DRAM
> >   sunxi: Make bit delay function in H616 DRAM code void
> >   sunxi: Parameterize bit delay code in H616 DRAM driver
> >   sunxi: Parameterize H616 DRAM code some more
> >  
> >  .../include/asm/arch-sunxi/dram_sun50i_h616.h |  18 +
> >  arch/arm/mach-sunxi/Kconfig   |  67 +--
> >  arch/arm/mach-sunxi/dram_sun50i_h616.c| 445 +++---
> >  configs/orangepi_zero2_defconfig  |   8 +-
> >  4 files changed, 348 insertions(+), 190 deletions(-)






Re: [PATCH 0/8] sunxi: Update H616 DRAM driver

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

Hi Jernej,

many thanks for putting this together!
I will have a more elaborate look at each patch later.

> Current H616 DRAM driver is completely customized to Orange Pi Zero2
> board, which is currently the only H616 board supported by U-Boot.

Not anymore, I merged the X96 Mate support lately, after the DT got
merged into the Linux tree.

Those are the values for the box I came up with:
CONFIG_DRAM_SUN50I_H616_DX_ODT=0x03030303
CONFIG_DRAM_SUN50I_H616_DX_DRI=0x0e0e0e0e
CONFIG_DRAM_SUN50I_H616_CA_DRI=0x1c12
CONFIG_DRAM_SUN50I_H616_TPR0=0xcc05
CONFIG_DRAM_SUN50I_H616_TPR10=0x2f0007
CONFIG_DRAM_SUN50I_H616_TPR11=0x
CONFIG_DRAM_SUN50I_H616_TPR12=0xfedf7557

based on this boot0 found in some firmware update image:
00045400  be 02 00 ea 65 47 4f 4e  2e 42 54 30 cc ba f3 80  |eGON.BT0|
00045410  00 c0 00 00 30 00 00 00  00 00 00 00 00 00 02 00  |0...|
00045420  00 00 02 00 00 00 00 00  00 00 00 00 34 2e 30 00  |4.0.|
00045430  00 00 00 00 03 00 00 00  88 02 00 00 03 00 00 00  ||
00045440  03 03 03 03 0e 0e 0e 0e  12 1c 00 00 01 00 00 00  ||
00045450  fb 30 00 00 00 00 00 00  40 08 00 00 04 00 00 00  |.0..@...|
00045460  08 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ||
00045470  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ||
00045480  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ||
00045490  05 0c 00 c0 00 00 00 00  00 00 00 00 00 00 00 00  ||
000454a0  80 80 80 33 07 00 2f 00  dd dd ff ff 57 75 df fe  |...3../.Wu..|
000454b0  40 00 00 00 00 00 00 00  00 00 00 00 08 00 02 01  |@...|

I would be grateful if you could verify this.

I built it, and it reported the 4GB correctly, also managed to boot into
Linux just fine. No extensive testing, nor didn't I compare register
dumps or disassembly (yet).

Cheers,
Andre

P.S. Any plans on upstreaming support for your T95  H616 TV
box? That would probably help the case here.


> Needless to say, this is not ideal for adding new boards. With changes
> in this series, all DDR3 boards are supported and all that is needed is
> just vendor DRAM values extracted from Android image. New DRAM types
> should also be easier to support, since a lot of constants used before
> are not really DRAM type dependent.
> 
> Changes were verified by decompiling driver and generated values were
> compared to previous, hard coded ones. This was done without dram_para
> structures, so compiler was able to heavily optimize code and produce
> constants.
> 
> Please take a look.
> 
> Best regards,
> Jernej
> 
> Jernej Skrabec (8):
>   sunxi: Fix write to H616 DRAM CR register
>   sunxi: cosmetic: Fix H616 DRAM driver code style
>   sunxi: parameterize H616 DRAM ODT values
>   sunxi: Convert H616 DRAM options to single setting
>   sunxi: Always configure ODT on H616 DRAM
>   sunxi: Make bit delay function in H616 DRAM code void
>   sunxi: Parameterize bit delay code in H616 DRAM driver
>   sunxi: Parameterize H616 DRAM code some more
> 
>  .../include/asm/arch-sunxi/dram_sun50i_h616.h |  18 +
>  arch/arm/mach-sunxi/Kconfig   |  67 +--
>  arch/arm/mach-sunxi/dram_sun50i_h616.c| 445 +++---
>  configs/orangepi_zero2_defconfig  |   8 +-
>  4 files changed, 348 insertions(+), 190 deletions(-)
>