diff mbox series

[u-boot-mvebu,10/10] arm: mvebu: turris_omnia: Support old DDR3 training, selectable via env var

Message ID 20240415163043.7482-11-kabel@kernel.org
State Superseded
Delegated to: Stefan Roese
Headers show
Series Turris Omnia DDR training changes | expand

Commit Message

Marek Behún April 15, 2024, 4:30 p.m. UTC
Support old DDR3 training code on Turris Omnia, selectable by U-Boot
enviroment variable.

Users experiencing DDR3 initialization failures or random crashes of the
operating system due to incorrect DDR3 configuration can select the old
DDR3 training implementation to fix those issues by setting the
environment variable
  env set omnia_ddr3_training old
  env save

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 arch/arm/mach-mvebu/Kconfig                   |  1 +
 board/CZ.NIC/turris_omnia/Makefile            |  1 +
 board/CZ.NIC/turris_omnia/old_ddr3_training.c | 79 +++++++++++++++++++
 board/CZ.NIC/turris_omnia/turris_omnia.c      |  2 +-
 4 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 board/CZ.NIC/turris_omnia/old_ddr3_training.c

Comments

Stefan Roese May 6, 2024, 10:03 a.m. UTC | #1
Hi Marek,

On 4/15/24 18:30, Marek Behún wrote:
> Support old DDR3 training code on Turris Omnia, selectable by U-Boot
> enviroment variable.
> 
> Users experiencing DDR3 initialization failures or random crashes of the
> operating system due to incorrect DDR3 configuration can select the old
> DDR3 training implementation to fix those issues by setting the
> environment variable
>    env set omnia_ddr3_training old
>    env save
> 
> Signed-off-by: Marek Behún <kabel@kernel.org>
> ---
>   arch/arm/mach-mvebu/Kconfig                   |  1 +
>   board/CZ.NIC/turris_omnia/Makefile            |  1 +
>   board/CZ.NIC/turris_omnia/old_ddr3_training.c | 79 +++++++++++++++++++
>   board/CZ.NIC/turris_omnia/turris_omnia.c      |  2 +-
>   4 files changed, 82 insertions(+), 1 deletion(-)
>   create mode 100644 board/CZ.NIC/turris_omnia/old_ddr3_training.c

For turris_omnia_defconfig, this is dropped when compiled:

drivers/ddr/marvell/a38x/old/ddr3_debug.c:776:12: warning: 
'ddr3_tip_access_atr' declared 'static' but never defined 
[-Wunused-function]
   776 | static int ddr3_tip_access_atr(u32 dev_num, u32 flag_id, u32 
value, u32 **ptr);
       |            ^~~~~~~~~~~~~~~~~~~

Please take a look.

Thanks,
Stefan

> diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
> index e377e8a48a..4a8328760e 100644
> --- a/arch/arm/mach-mvebu/Kconfig
> +++ b/arch/arm/mach-mvebu/Kconfig
> @@ -149,6 +149,7 @@ config TARGET_TURRIS_OMNIA
>   	select SPL_SYS_MALLOC_SIMPLE
>   	select SYS_I2C_MVTWSI
>   	select ATSHA204A
> +	select ARMADA_38X_SUPPORT_OLD_DDR3_TRAINING
>   
>   config TARGET_TURRIS_MOX
>   	bool "Support CZ.NIC's Turris Mox / RIPE Atlas Probe"
> diff --git a/board/CZ.NIC/turris_omnia/Makefile b/board/CZ.NIC/turris_omnia/Makefile
> index 341378b4e5..28142cca7e 100644
> --- a/board/CZ.NIC/turris_omnia/Makefile
> +++ b/board/CZ.NIC/turris_omnia/Makefile
> @@ -3,3 +3,4 @@
>   # Copyright (C) 2017 Marek Behún <kabel@kernel.org>
>   
>   obj-y	:= turris_omnia.o ../turris_atsha_otp.o ../turris_common.o
> +obj-$(CONFIG_SPL_BUILD)	+= old_ddr3_training.o
> diff --git a/board/CZ.NIC/turris_omnia/old_ddr3_training.c b/board/CZ.NIC/turris_omnia/old_ddr3_training.c
> new file mode 100644
> index 0000000000..f7e89c58d4
> --- /dev/null
> +++ b/board/CZ.NIC/turris_omnia/old_ddr3_training.c
> @@ -0,0 +1,79 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2024 Marek Behún <kabel@kernel.org>
> + */
> +
> +#include <common.h>
> +#include <asm/io.h>
> +#include <env.h>
> +
> +#include "../drivers/ddr/marvell/a38x/old/ddr3_init.h"
> +
> +static struct hws_topology_map board_topology_map_1g = {
> +	0x1, /* active interfaces */
> +	/* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
> +	{ { { {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0} },
> +	    SPEED_BIN_DDR_1600K,	/* speed_bin */
> +	    BUS_WIDTH_16,		/* memory_width */
> +	    MEM_4G,			/* mem_size */
> +	    DDR_FREQ_800,		/* frequency */
> +	    0, 0,			/* cas_l cas_wl */
> +	    HWS_TEMP_NORMAL,		/* temperature */
> +	    HWS_TIM_2T} },              /* timing (force 2t) */
> +	5,				/* Num Of Bus Per Interface*/
> +	BUS_MASK_32BIT			/* Busses mask */
> +};
> +
> +static struct hws_topology_map board_topology_map_2g = {
> +	0x1, /* active interfaces */
> +	/* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
> +	{ { { {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0},
> +	      {0x1, 0, 0, 0} },
> +	    SPEED_BIN_DDR_1600K,	/* speed_bin */
> +	    BUS_WIDTH_16,		/* memory_width */
> +	    MEM_8G,			/* mem_size */
> +	    DDR_FREQ_800,		/* frequency */
> +	    0, 0,			/* cas_l cas_wl */
> +	    HWS_TEMP_NORMAL,		/* temperature */
> +	    HWS_TIM_2T} },              /* timing (force 2t) */
> +	5,				/* Num Of Bus Per Interface*/
> +	BUS_MASK_32BIT			/* Busses mask */
> +};
> +
> +/* defined in turris_omnia.c */
> +extern int omnia_get_ram_size_gb(void);
> +
> +struct hws_topology_map *ddr3_get_topology_map(void)
> +{
> +	if (omnia_get_ram_size_gb() == 2)
> +		return &board_topology_map_2g;
> +	else
> +		return &board_topology_map_1g;
> +}
> +
> +bool board_use_old_ddr3_training(void)
> +{
> +	const char *env_val = NULL;
> +
> +	if (CONFIG_IS_ENABLED(ENV_SUPPORT) && !env_init())
> +		env_val = env_get("omnia_ddr3_training");
> +
> +	if (env_val && !strcmp(env_val, "old")) {
> +		printf("Using old DDR3 training implementation\n");
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
> +__weak u32 sys_env_get_topology_update_info(struct topology_update_info *tui)
> +{
> +	return MV_OK;
> +}
> diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
> index 3b7a71bdad..225c6f4bc5 100644
> --- a/board/CZ.NIC/turris_omnia/turris_omnia.c
> +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
> @@ -465,7 +465,7 @@ static bool omnia_read_eeprom(struct omnia_eeprom *oep)
>   	return true;
>   }
>   
> -static int omnia_get_ram_size_gb(void)
> +int omnia_get_ram_size_gb(void)
>   {
>   	static int ram_size;
>   	struct omnia_eeprom oep;

Viele Grüße,
Stefan Roese
Marek Behún May 15, 2024, 8:59 a.m. UTC | #2
On Mon, 6 May 2024 12:03:55 +0200
Stefan Roese <sr@denx.de> wrote:

> Hi Marek,
> 
> On 4/15/24 18:30, Marek Behún wrote:
> > Support old DDR3 training code on Turris Omnia, selectable by U-Boot
> > enviroment variable.
> > 
> > Users experiencing DDR3 initialization failures or random crashes of the
> > operating system due to incorrect DDR3 configuration can select the old
> > DDR3 training implementation to fix those issues by setting the
> > environment variable
> >    env set omnia_ddr3_training old
> >    env save
> > 
> > Signed-off-by: Marek Behún <kabel@kernel.org>
> > ---
> >   arch/arm/mach-mvebu/Kconfig                   |  1 +
> >   board/CZ.NIC/turris_omnia/Makefile            |  1 +
> >   board/CZ.NIC/turris_omnia/old_ddr3_training.c | 79 +++++++++++++++++++
> >   board/CZ.NIC/turris_omnia/turris_omnia.c      |  2 +-
> >   4 files changed, 82 insertions(+), 1 deletion(-)
> >   create mode 100644 board/CZ.NIC/turris_omnia/old_ddr3_training.c  
> 
> For turris_omnia_defconfig, this is dropped when compiled:
> 
> drivers/ddr/marvell/a38x/old/ddr3_debug.c:776:12: warning: 
> 'ddr3_tip_access_atr' declared 'static' but never defined 
> [-Wunused-function]
>    776 | static int ddr3_tip_access_atr(u32 dev_num, u32 flag_id, u32 
> value, u32 **ptr);
>        |            ^~~~~~~~~~~~~~~~~~~

And it also seems that there is still something wrong with this
old DDR training code port. Some boards still experience random bugs
with this, but not with the U-Boot from 2015. :-(
Stefan Roese May 15, 2024, 9:10 a.m. UTC | #3
Hi Marek,

On 5/15/24 10:59, Marek Behún wrote:
> On Mon, 6 May 2024 12:03:55 +0200
> Stefan Roese <sr@denx.de> wrote:
> 
>> Hi Marek,
>>
>> On 4/15/24 18:30, Marek Behún wrote:
>>> Support old DDR3 training code on Turris Omnia, selectable by U-Boot
>>> enviroment variable.
>>>
>>> Users experiencing DDR3 initialization failures or random crashes of the
>>> operating system due to incorrect DDR3 configuration can select the old
>>> DDR3 training implementation to fix those issues by setting the
>>> environment variable
>>>     env set omnia_ddr3_training old
>>>     env save
>>>
>>> Signed-off-by: Marek Behún <kabel@kernel.org>
>>> ---
>>>    arch/arm/mach-mvebu/Kconfig                   |  1 +
>>>    board/CZ.NIC/turris_omnia/Makefile            |  1 +
>>>    board/CZ.NIC/turris_omnia/old_ddr3_training.c | 79 +++++++++++++++++++
>>>    board/CZ.NIC/turris_omnia/turris_omnia.c      |  2 +-
>>>    4 files changed, 82 insertions(+), 1 deletion(-)
>>>    create mode 100644 board/CZ.NIC/turris_omnia/old_ddr3_training.c
>>
>> For turris_omnia_defconfig, this is dropped when compiled:
>>
>> drivers/ddr/marvell/a38x/old/ddr3_debug.c:776:12: warning:
>> 'ddr3_tip_access_atr' declared 'static' but never defined
>> [-Wunused-function]
>>     776 | static int ddr3_tip_access_atr(u32 dev_num, u32 flag_id, u32
>> value, u32 **ptr);
>>         |            ^~~~~~~~~~~~~~~~~~~
> 
> And it also seems that there is still something wrong with this
> old DDR training code port. Some boards still experience random bugs
> with this, but not with the U-Boot from 2015. :-(

Hmmm, strange.

How to continue? Are these "old DDR training patches" on hold for now?

Thanks,
Stefan
Marek Behún May 15, 2024, 9:24 a.m. UTC | #4
On Wed, 15 May 2024 11:10:09 +0200
Stefan Roese <sr@denx.de> wrote:

> Hi Marek,
> 
> On 5/15/24 10:59, Marek Behún wrote:
> > On Mon, 6 May 2024 12:03:55 +0200
> > Stefan Roese <sr@denx.de> wrote:
> >   
> >> Hi Marek,
> >>
> >> On 4/15/24 18:30, Marek Behún wrote:  
> >>> Support old DDR3 training code on Turris Omnia, selectable by U-Boot
> >>> enviroment variable.
> >>>
> >>> Users experiencing DDR3 initialization failures or random crashes of the
> >>> operating system due to incorrect DDR3 configuration can select the old
> >>> DDR3 training implementation to fix those issues by setting the
> >>> environment variable
> >>>     env set omnia_ddr3_training old
> >>>     env save
> >>>
> >>> Signed-off-by: Marek Behún <kabel@kernel.org>
> >>> ---
> >>>    arch/arm/mach-mvebu/Kconfig                   |  1 +
> >>>    board/CZ.NIC/turris_omnia/Makefile            |  1 +
> >>>    board/CZ.NIC/turris_omnia/old_ddr3_training.c | 79 +++++++++++++++++++
> >>>    board/CZ.NIC/turris_omnia/turris_omnia.c      |  2 +-
> >>>    4 files changed, 82 insertions(+), 1 deletion(-)
> >>>    create mode 100644 board/CZ.NIC/turris_omnia/old_ddr3_training.c  
> >>
> >> For turris_omnia_defconfig, this is dropped when compiled:
> >>
> >> drivers/ddr/marvell/a38x/old/ddr3_debug.c:776:12: warning:
> >> 'ddr3_tip_access_atr' declared 'static' but never defined
> >> [-Wunused-function]
> >>     776 | static int ddr3_tip_access_atr(u32 dev_num, u32 flag_id, u32
> >> value, u32 **ptr);
> >>         |            ^~~~~~~~~~~~~~~~~~~  
> > 
> > And it also seems that there is still something wrong with this
> > old DDR training code port. Some boards still experience random bugs
> > with this, but not with the U-Boot from 2015. :-(  
> 
> Hmmm, strange.
> 
> How to continue? Are these "old DDR training patches" on hold for now?

The first 5 patches should be fine, the "old DDR training" comes in the
second half. Is it possible to merge only the first 5? And also the one
patch I sent on April 30:
  arm: mvebu: turris_omnia: Fix ethernet PHY reset gpio FDT fixup

Marek
Stefan Roese May 15, 2024, 3:11 p.m. UTC | #5
On 5/15/24 11:24, Marek Behún wrote:
> On Wed, 15 May 2024 11:10:09 +0200
> Stefan Roese <sr@denx.de> wrote:
> 
>> Hi Marek,
>>
>> On 5/15/24 10:59, Marek Behún wrote:
>>> On Mon, 6 May 2024 12:03:55 +0200
>>> Stefan Roese <sr@denx.de> wrote:
>>>    
>>>> Hi Marek,
>>>>
>>>> On 4/15/24 18:30, Marek Behún wrote:
>>>>> Support old DDR3 training code on Turris Omnia, selectable by U-Boot
>>>>> enviroment variable.
>>>>>
>>>>> Users experiencing DDR3 initialization failures or random crashes of the
>>>>> operating system due to incorrect DDR3 configuration can select the old
>>>>> DDR3 training implementation to fix those issues by setting the
>>>>> environment variable
>>>>>      env set omnia_ddr3_training old
>>>>>      env save
>>>>>
>>>>> Signed-off-by: Marek Behún <kabel@kernel.org>
>>>>> ---
>>>>>     arch/arm/mach-mvebu/Kconfig                   |  1 +
>>>>>     board/CZ.NIC/turris_omnia/Makefile            |  1 +
>>>>>     board/CZ.NIC/turris_omnia/old_ddr3_training.c | 79 +++++++++++++++++++
>>>>>     board/CZ.NIC/turris_omnia/turris_omnia.c      |  2 +-
>>>>>     4 files changed, 82 insertions(+), 1 deletion(-)
>>>>>     create mode 100644 board/CZ.NIC/turris_omnia/old_ddr3_training.c
>>>>
>>>> For turris_omnia_defconfig, this is dropped when compiled:
>>>>
>>>> drivers/ddr/marvell/a38x/old/ddr3_debug.c:776:12: warning:
>>>> 'ddr3_tip_access_atr' declared 'static' but never defined
>>>> [-Wunused-function]
>>>>      776 | static int ddr3_tip_access_atr(u32 dev_num, u32 flag_id, u32
>>>> value, u32 **ptr);
>>>>          |            ^~~~~~~~~~~~~~~~~~~
>>>
>>> And it also seems that there is still something wrong with this
>>> old DDR training code port. Some boards still experience random bugs
>>> with this, but not with the U-Boot from 2015. :-(
>>
>> Hmmm, strange.
>>
>> How to continue? Are these "old DDR training patches" on hold for now?
> 
> The first 5 patches should be fine, the "old DDR training" comes in the
> second half. Is it possible to merge only the first 5? And also the one
> patch I sent on April 30:
>    arm: mvebu: turris_omnia: Fix ethernet PHY reset gpio FDT fixup

Yes, that might be possible. Let me check...

Thanks,
Stefan
diff mbox series

Patch

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index e377e8a48a..4a8328760e 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -149,6 +149,7 @@  config TARGET_TURRIS_OMNIA
 	select SPL_SYS_MALLOC_SIMPLE
 	select SYS_I2C_MVTWSI
 	select ATSHA204A
+	select ARMADA_38X_SUPPORT_OLD_DDR3_TRAINING
 
 config TARGET_TURRIS_MOX
 	bool "Support CZ.NIC's Turris Mox / RIPE Atlas Probe"
diff --git a/board/CZ.NIC/turris_omnia/Makefile b/board/CZ.NIC/turris_omnia/Makefile
index 341378b4e5..28142cca7e 100644
--- a/board/CZ.NIC/turris_omnia/Makefile
+++ b/board/CZ.NIC/turris_omnia/Makefile
@@ -3,3 +3,4 @@ 
 # Copyright (C) 2017 Marek Behún <kabel@kernel.org>
 
 obj-y	:= turris_omnia.o ../turris_atsha_otp.o ../turris_common.o
+obj-$(CONFIG_SPL_BUILD)	+= old_ddr3_training.o
diff --git a/board/CZ.NIC/turris_omnia/old_ddr3_training.c b/board/CZ.NIC/turris_omnia/old_ddr3_training.c
new file mode 100644
index 0000000000..f7e89c58d4
--- /dev/null
+++ b/board/CZ.NIC/turris_omnia/old_ddr3_training.c
@@ -0,0 +1,79 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2024 Marek Behún <kabel@kernel.org>
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <env.h>
+
+#include "../drivers/ddr/marvell/a38x/old/ddr3_init.h"
+
+static struct hws_topology_map board_topology_map_1g = {
+	0x1, /* active interfaces */
+	/* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
+	{ { { {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0} },
+	    SPEED_BIN_DDR_1600K,	/* speed_bin */
+	    BUS_WIDTH_16,		/* memory_width */
+	    MEM_4G,			/* mem_size */
+	    DDR_FREQ_800,		/* frequency */
+	    0, 0,			/* cas_l cas_wl */
+	    HWS_TEMP_NORMAL,		/* temperature */
+	    HWS_TIM_2T} },              /* timing (force 2t) */
+	5,				/* Num Of Bus Per Interface*/
+	BUS_MASK_32BIT			/* Busses mask */
+};
+
+static struct hws_topology_map board_topology_map_2g = {
+	0x1, /* active interfaces */
+	/* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
+	{ { { {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0},
+	      {0x1, 0, 0, 0} },
+	    SPEED_BIN_DDR_1600K,	/* speed_bin */
+	    BUS_WIDTH_16,		/* memory_width */
+	    MEM_8G,			/* mem_size */
+	    DDR_FREQ_800,		/* frequency */
+	    0, 0,			/* cas_l cas_wl */
+	    HWS_TEMP_NORMAL,		/* temperature */
+	    HWS_TIM_2T} },              /* timing (force 2t) */
+	5,				/* Num Of Bus Per Interface*/
+	BUS_MASK_32BIT			/* Busses mask */
+};
+
+/* defined in turris_omnia.c */
+extern int omnia_get_ram_size_gb(void);
+
+struct hws_topology_map *ddr3_get_topology_map(void)
+{
+	if (omnia_get_ram_size_gb() == 2)
+		return &board_topology_map_2g;
+	else
+		return &board_topology_map_1g;
+}
+
+bool board_use_old_ddr3_training(void)
+{
+	const char *env_val = NULL;
+
+	if (CONFIG_IS_ENABLED(ENV_SUPPORT) && !env_init())
+		env_val = env_get("omnia_ddr3_training");
+
+	if (env_val && !strcmp(env_val, "old")) {
+		printf("Using old DDR3 training implementation\n");
+		return true;
+	}
+
+	return false;
+}
+
+__weak u32 sys_env_get_topology_update_info(struct topology_update_info *tui)
+{
+	return MV_OK;
+}
diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 3b7a71bdad..225c6f4bc5 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -465,7 +465,7 @@  static bool omnia_read_eeprom(struct omnia_eeprom *oep)
 	return true;
 }
 
-static int omnia_get_ram_size_gb(void)
+int omnia_get_ram_size_gb(void)
 {
 	static int ram_size;
 	struct omnia_eeprom oep;