All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: u-boot@lists.denx.de, "Marek Behún" <kabel@kernel.org>
Subject: [PATCH u-boot-marvell 16/16] arm: mvebu: turris_omnia: Support old DDR3 training
Date: Tue, 18 Jun 2024 17:34:39 +0200	[thread overview]
Message-ID: <20240618153439.9518-17-kabel@kernel.org> (raw)
In-Reply-To: <20240618153439.9518-1-kabel@kernel.org>

Support old DDR3 training code on Turris Omnia, selectable via EEPROM
field.

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 EEPROM
field "Use old DDR training":
  eeprom update "Use old DDR training" 1

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/eeprom.c            | 37 ++++++++++-
 board/CZ.NIC/turris_omnia/old_ddr3_training.c | 63 +++++++++++++++++++
 board/CZ.NIC/turris_omnia/turris_omnia.c      | 18 +++++-
 5 files changed, 117 insertions(+), 3 deletions(-)
 create mode 100644 board/CZ.NIC/turris_omnia/old_ddr3_training.c

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 216e11958a..d1ef5cb860 100644
--- a/board/CZ.NIC/turris_omnia/Makefile
+++ b/board/CZ.NIC/turris_omnia/Makefile
@@ -4,3 +4,4 @@
 
 obj-y	:= turris_omnia.o ../turris_atsha_otp.o ../turris_common.o
 obj-$(CONFIG_CMD_EEPROM_LAYOUT)	+= eeprom.o
+obj-$(CONFIG_SPL_BUILD)		+= old_ddr3_training.o
diff --git a/board/CZ.NIC/turris_omnia/eeprom.c b/board/CZ.NIC/turris_omnia/eeprom.c
index 32572481ce..6e2640ad2a 100644
--- a/board/CZ.NIC/turris_omnia/eeprom.c
+++ b/board/CZ.NIC/turris_omnia/eeprom.c
@@ -91,13 +91,48 @@ static int eeprom_field_update_ddr_speed(struct eeprom_field *field,
 	return 0;
 }
 
+static void eeprom_field_print_bool(const struct eeprom_field *field)
+{
+	unsigned char val = field->buf[0];
+
+	printf(PRINT_FIELD_SEGMENT, field->name);
+
+	if (val == 0xff)
+		puts("(empty, defaults to 0)\n");
+	else
+		printf("%u\n", val);
+}
+
+static int eeprom_field_update_bool(struct eeprom_field *field, char *value)
+{
+	unsigned char *val = &field->buf[0];
+
+	if (value[0] == '\0') {
+		/* setting default value */
+		*val = 0xff;
+
+		return 0;
+	}
+
+	if (value[1] != '\0')
+		return -1;
+
+	if (value[0] == '1' || value[0] == '0')
+		*val = value[0] - '0';
+	else
+		return -1;
+
+	return 0;
+}
+
 static struct eeprom_field omnia_layout[] = {
 	_DEF_FIELD("Magic constant", 4, bin),
 	_DEF_FIELD("RAM size in GB", 4, ramsz),
 	_DEF_FIELD("Wi-Fi Region", 4, region),
 	_DEF_FIELD("CRC32 checksum", 4, bin),
 	_DEF_FIELD("DDR speed", 5, ddr_speed),
-	_DEF_FIELD("Extended reserved fields", 39, reserved),
+	_DEF_FIELD("Use old DDR training", 1, bool),
+	_DEF_FIELD("Extended reserved fields", 38, reserved),
 	_DEF_FIELD("Extended CRC32 checksum", 4, bin),
 };
 
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..cdb3487ad9
--- /dev/null
+++ b/board/CZ.NIC/turris_omnia/old_ddr3_training.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2024 Marek Behún <kabel@kernel.org>
+ */
+
+#include <asm/arch/soc.h>
+#include <asm/io.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;
+}
+
+__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 544784e860..2f29d26edf 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -432,7 +432,8 @@ struct omnia_eeprom {
 
 	/* second part (only considered if crc2 is not all-ones) */
 	char ddr_speed[5];
-	u8 reserved[39];
+	u8 old_ddr_training;
+	u8 reserved[38];
 	u32 crc2;
 };
 
@@ -496,7 +497,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;
@@ -521,6 +522,19 @@ static int omnia_get_ram_size_gb(void)
 	return ram_size;
 }
 
+bool board_use_old_ddr3_training(void)
+{
+	struct omnia_eeprom oep;
+
+	if (!omnia_read_eeprom(&oep))
+		return false;
+
+	if (!is_omnia_eeprom_second_part_valid(&oep))
+		return false;
+
+	return oep.old_ddr_training == 1;
+}
+
 static const char *omnia_get_ddr_speed(void)
 {
 	struct omnia_eeprom oep;
-- 
2.44.2


  parent reply	other threads:[~2024-06-18 15:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 15:34 [PATCH u-boot-marvell 00/16] Turris Omnia DDR training changes Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 01/16] arm: mvebu: turris_omnia: Disable ext4 write support in defconfig Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 02/16] ddr: marvell: a38x: debug: return from ddr3_tip_print_log() early if we won't print anything Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 03/16] ddr: marvell: a38x: debug: Remove unused variables Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 04/16] ddr: marvell: a38x: debug: Define DDR_VIEWER_TOOL variables only if needed, and make them static Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 05/16] ddr: marvell: a38x: debug: Allow compiling with immutable debug settings to reduce binary size Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 06/16] arm: mvebu: turris_omnia: Enable immutable debug settings in DDR3 training by default Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 07/16] arm: mvebu: turris_omnia: Fix ethernet PHY reset gpio FDT fixup Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 08/16] arm: mvebu: turris_omnia: Implement EEPROM layout for the 'eeprom' command Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 09/16] arm: mvebu: turris_omnia: Enable " Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 10/16] arm: mvebu: turris_omnia: Extend EEPROM info structure Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 11/16] arm: mvebu: turris_omnia: Read DDR speed from EEPROM Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 12/16] ddr: marvell: a38x: Import old DDR training code from 2017 version of U-Boot Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 13/16] ddr: marvell: a38x: old: Fix some compiler warning of the old code Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 14/16] ddr: marvell: a38x: old: Backport immutable debug settings Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 15/16] arm: mvebu: a38x: Add optional support for using old DDR3 training code Marek Behún
2024-06-18 15:34 ` Marek Behún [this message]
2024-07-08 14:16 ` [PATCH u-boot-marvell 00/16] Turris Omnia DDR training changes Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240618153439.9518-17-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.