[U-Boot] [PATCH 1/2] sunxi: Fix dram initialization not working on some a33 devices

When porting the allwinner dram init code to u-boot we missed some code setting an extra bit when doing auto dram config.
This commits add this bit, fixing dram init not working on the ga10h 10" a33 tablet which I'm bringing up atm.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c index d03f00d..979bb3c 100644 --- a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c +++ b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c @@ -195,7 +195,7 @@ static int mctl_train_dram(struct dram_para *para) (struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
mctl_data_train_cfg(para); - mctl_set_pir(0x1f3); + mctl_set_pir(0x5f3);
return ((readl(&mctl_ctl->pgsr0) >> 20) & 0xff) ? -EIO : 0; }

Some A33 based boards use odt, while others do not, so make this configurable.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c | 3 +-- board/sunxi/Kconfig | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c index 979bb3c..a7a0a2e 100644 --- a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c +++ b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c @@ -19,7 +19,6 @@ #define DRAM_CLK_MUL 2 #define DRAM_CLK_DIV 4 #define DRAM_SIGMA_DELTA_ENABLE 1 -#define DRAM_ODT_EN 0
struct dram_para { u8 cs1; @@ -215,7 +214,7 @@ static int mctl_channel_init(struct dram_para *para) clrbits_le32(&mctl_ctl->pgcr0, 0x3f << 0);
/* Set ODT */ - if ((CONFIG_DRAM_CLK > 400) && DRAM_ODT_EN) { + if ((CONFIG_DRAM_CLK > 400) && CONFIG_DRAM_ODT_EN) { setbits_le32(DXnGCR0(0), 0x3 << 9); setbits_le32(DXnGCR0(1), 0x3 << 9); } else { diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig index 940b6c7..d4ae6c7 100644 --- a/board/sunxi/Kconfig +++ b/board/sunxi/Kconfig @@ -95,6 +95,14 @@ config DRAM_ZQ ---help--- Set the dram zq value.
+if MACH_SUN8I_A33 +config DRAM_ODT_EN + int "sunxi dram odt enable" + default 0 + ---help--- + Set this to 1 to enable dram odt (on die termination) +endif + if MACH_SUN4I || MACH_SUN5I || MACH_SUN7I config DRAM_EMR1 int "sunxi dram emr1 value"

On Wed, 2015-05-13 at 17:09 +0200, Hans de Goede wrote:
diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig index 940b6c7..d4ae6c7 100644 --- a/board/sunxi/Kconfig +++ b/board/sunxi/Kconfig @@ -95,6 +95,14 @@ config DRAM_ZQ ---help--- Set the dram zq value.
+if MACH_SUN8I_A33
Shouldn't this be a "depends on MACH_SUN8I_A33" in the entry itself? I see we use if a lot in this file, is there a reason for that or just how it has been done?
In any case using if here is at least consistent so no strong objection on that grounds.
+config DRAM_ODT_EN
- int "sunxi dram odt enable"
- default 0
- ---help---
- Set this to 1 to enable dram odt (on die termination)
Why is this an int rather than a bool?

Hi,
On 05/13/2015 09:26 PM, Ian Campbell wrote:
On Wed, 2015-05-13 at 17:09 +0200, Hans de Goede wrote:
diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig index 940b6c7..d4ae6c7 100644 --- a/board/sunxi/Kconfig +++ b/board/sunxi/Kconfig @@ -95,6 +95,14 @@ config DRAM_ZQ ---help--- Set the dram zq value.
+if MACH_SUN8I_A33
Shouldn't this be a "depends on MACH_SUN8I_A33" in the entry itself? I see we use if a lot in this file, is there a reason for that or just how it has been done?
No special reason, just copy paste from elsewhere.
In any case using if here is at least consistent so no strong objection on that grounds.
+config DRAM_ODT_EN
- int "sunxi dram odt enable"
- default 0
- ---help---
- Set this to 1 to enable dram odt (on die termination)
Why is this an int rather than a bool?
Because it is used directly as an int in the code, otherwise I need to add #ifdef-ery. I guess I could make it a bool and use IS_ENABLED(), but that does lead to slightly less readable code IMHO.
Regards,
Hans

On Thu, 2015-05-14 at 18:55 +0200, Hans de Goede wrote:
+config DRAM_ODT_EN
- int "sunxi dram odt enable"
- default 0
- ---help---
- Set this to 1 to enable dram odt (on die termination)
Why is this an int rather than a bool?
Because it is used directly as an int in the code, otherwise I need to add #ifdef-ery. I guess I could make it a bool and use IS_ENABLED(), but that does lead to slightly less readable code IMHO.
I'm afraid I think IS_ENABLED is the way to go though, it's the lesser of two evils compared with using an int for a boolean option.
Ian.

Hi,
On 14-05-15 20:41, Ian Campbell wrote:
On Thu, 2015-05-14 at 18:55 +0200, Hans de Goede wrote:
+config DRAM_ODT_EN
- int "sunxi dram odt enable"
- default 0
- ---help---
- Set this to 1 to enable dram odt (on die termination)
Why is this an int rather than a bool?
Because it is used directly as an int in the code, otherwise I need to add #ifdef-ery. I guess I could make it a bool and use IS_ENABLED(), but that does lead to slightly less readable code IMHO.
I'm afraid I think IS_ENABLED is the way to go though, it's the lesser of two evils compared with using an int for a boolean option.
Ok, so while trying to fix this I noticed that there already is a definition of CONFIG_DRAM_ODT_EN in board/sunxi/Kconfig inside a
#if MACH_SUN4I || MACH_SUN5I || MACH_SUN7I
block, and that one actually really is an int (it goes from 0-3). so I'm going to leave this as an int, and use the existing option moving it outside of the #if MACH_SUN4I || MACH_SUN5I || MACH_SUN7I block.
v2 coming up.
Regards,
Hans

On Wed, 2015-05-13 at 17:09 +0200, Hans de Goede wrote:
When porting the allwinner dram init code to u-boot we missed some code setting an extra bit when doing auto dram config.
This commits add this bit, fixing dram init not working on the ga10h 10" a33 tablet which I'm bringing up atm.
Signed-off-by: Hans de Goede hdegoede@redhat.com
Acked-by: Ian Campbell ijc@hellion.org.uk

Hello Hans,
On Wed, 13 May 2015 17:09:33 +0200 Hans de Goede hdegoede@redhat.com wrote:
When porting the allwinner dram init code to u-boot we missed some code setting an extra bit when doing auto dram config.
This "extra bit" actually has a name. Not using named constants instead of the magic numbers makes the code rather difficult to review. Your persistent refusal to use the nicely available DRAM controller documentation may be interpreted as an act of disrespect towards the reviewers of your code.
Basically, the A31, A23 and now A33 DRAM initialization code was (and still is) a quick and dirty copy/paste hack. And you made exactly no effort to make it reviewable, despite having been requested to do so multiple times. Yes, it is nice that this code is at least able to boot. But this alone can't tell us anything about its quality (after all, the Allwinner's 3.4 kernel is able to boot a pretty functional Android system too, but it contains a lot of rather questionable or outright buggy code under the hood). The DRAM setup is really critical for the system reliability and has long lasting effects. The bugs in the vast majority of the rest of the U-Boot code are much less important because, because they have no chance to cause any troubles after the OS takes over. The DRAM initialization is different and the "reckless cowboy" approach is simply very dangerous (assuming that the end users may want to use their Allwinner based devices for something more serious than just toying with them for fun).
This commits add this bit, fixing dram init not working on the ga10h 10" a33 tablet which I'm bringing up atm.
Signed-off-by: Hans de Goede hdegoede@redhat.com
We were just lucky that this particular bug was too easy to notice and fix. Are you sure that there are no other similar, but more subtle problems, which are just more difficult to reproduce and may remain unnoticed longer?
Based on a quick search in the mailing list archives, I have already provided you with a link to the "spruhn7a.pdf" document 4 (!) times. This is the fifth attempt and I'm seriously starting to lose patience. No offense intended, but you are probably the most dense person that I have ever met :-) There is even an updated C revision of this document: http://www.ti.com/lit/ug/spruhn7c/spruhn7c.pdf
arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c index d03f00d..979bb3c 100644 --- a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c +++ b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c @@ -195,7 +195,7 @@ static int mctl_train_dram(struct dram_para *para) (struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
mctl_data_train_cfg(para);
- mctl_set_pir(0x1f3);
mctl_set_pir(0x5f3);
return ((readl(&mctl_ctl->pgsr0) >> 20) & 0xff) ? -EIO : 0;
}
Now some questions to Ian Campbell. Are you really happy about the non-descriptive commit messages like "Initial u-boot port by Vishnu Patekar, major cleanup / rewrite by Hans de Goede" in http://git.denx.de/?p=u-boot.git;a=commit;h=ffc0ae0c70decbe5a910 ? And are you also happy with neglecting the documentation and keeping all these magic constants in the code? Have you in fact done the review of the code logic? Or at least verified that it had been transplanted from boot0 correctly without introducing any potentially problematic functional changes?

Hi Sairhei,
On 18-05-15 12:30, Siarhei Siamashka wrote:
Hello Hans,
On Wed, 13 May 2015 17:09:33 +0200 Hans de Goede hdegoede@redhat.com wrote:
When porting the allwinner dram init code to u-boot we missed some code setting an extra bit when doing auto dram config.
This "extra bit" actually has a name. Not using named constants instead of the magic numbers makes the code rather difficult to review. Your persistent refusal to use the nicely available DRAM controller documentation may be interpreted as an act of disrespect towards the reviewers of your code.
Basically, the A31, A23 and now A33 DRAM initialization code was (and still is) a quick and dirty copy/paste hack. And you made exactly no effort to make it reviewable, despite having been requested to do so multiple times. Yes, it is nice that this code is at least able to boot. But this alone can't tell us anything about its quality (after all, the Allwinner's 3.4 kernel is able to boot a pretty functional Android system too, but it contains a lot of rather questionable or outright buggy code under the hood). The DRAM setup is really critical for the system reliability and has long lasting effects. The bugs in the vast majority of the rest of the U-Boot code are much less important because, because they have no chance to cause any troubles after the OS takes over. The DRAM initialization is different and the "reckless cowboy" approach is simply very dangerous (assuming that the end users may want to use their Allwinner based devices for something more serious than just toying with them for fun).
This commits add this bit, fixing dram init not working on the ga10h 10" a33 tablet which I'm bringing up atm.
Signed-off-by: Hans de Goede hdegoede@redhat.com
We were just lucky that this particular bug was too easy to notice and fix. Are you sure that there are no other similar, but more subtle problems, which are just more difficult to reproduce and may remain unnoticed longer?
Based on a quick search in the mailing list archives, I have already provided you with a link to the "spruhn7a.pdf" document 4 (!) times. This is the fifth attempt and I'm seriously starting to lose patience. No offense intended, but you are probably the most dense person that I have ever met :-) There is even an updated C revision of this document: http://www.ti.com/lit/ug/spruhn7c/spruhn7c.pdf
Last time you provided that link it was when discussing the a23 (or was it the a31?) dram controller, and now you provide the same link for the a33, this makes no sense since all 3 dram controllers are actually quite different.
We simply do not have reliable dram controller documentation. Yes there may be some common ancestry between the ti dram controller you're linking to and the allwinner ones, but allwinner has been consistently tweaking there dram controller with each new soc generation, so even if that document is correct for one generation it certainly will not be for other generations.
arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c index d03f00d..979bb3c 100644 --- a/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c +++ b/arch/arm/cpu/armv7/sunxi/dram_sun8i_a33.c @@ -195,7 +195,7 @@ static int mctl_train_dram(struct dram_para *para) (struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
mctl_data_train_cfg(para);
- mctl_set_pir(0x1f3);
mctl_set_pir(0x5f3);
return ((readl(&mctl_ctl->pgsr0) >> 20) & 0xff) ? -EIO : 0; }
Now some questions to Ian Campbell. Are you really happy about the non-descriptive commit messages like "Initial u-boot port by Vishnu Patekar, major cleanup / rewrite by Hans de Goede" in http://git.denx.de/?p=u-boot.git;a=commit;h=ffc0ae0c70decbe5a910 ? And are you also happy with neglecting the documentation
There is NO documentation. What you're doing is the same as giving someone the manual for a sony video recorder and then telling him to use that to program recording of his favorite show into a jvc recorder, yes there are going to be similarities, that does not make the manual from manufacturer a going to apply to a device from manufacturer b.
Last time we had this discussion it was trivial to point out various places where the documentation did not match up, and that was like 3 generations of dram controllers ago ...
With all that said you're welcome to find things which do match and provide patches to convert magic constants to useful symbolic names.
What you're not welcome to do is trash my work and throw mud at me, it would greatly help if you were to use a more constructive tone in future email.
Regards,
Hans
participants (3)
-
Hans de Goede
-
Ian Campbell
-
Siarhei Siamashka