From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 2 May 2019 16:53:33 +0200 Subject: [U-Boot] [PATCH u-boot-marvell v3 10/17] arm: mvebu: turris_omnia: refactor more code In-Reply-To: <20190502145340.16072-1-marek.behun@nic.cz> References: <20190502145340.16072-1-marek.behun@nic.cz> Message-ID: <20190502145340.16072-11-marek.behun@nic.cz> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Refactor RAM size reading from EEPROM in preparation for next patch. Signed-off-by: Marek Beh=C3=BAn Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_omnia/turris_omnia.c | 58 ++++++++++++------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris= _omnia/turris_omnia.c index 640ee2a2a3..8571541b0a 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -236,6 +236,31 @@ static bool omnia_read_eeprom(struct omnia_eeprom *oep) return true; } =20 +static int omnia_get_ram_size_gb(void) +{ + static int ram_size; + struct omnia_eeprom oep; + + if (!ram_size) { + /* Get the board config from EEPROM */ + if (omnia_read_eeprom(&oep)) { + debug("Memory config in EEPROM: 0x%02x\n", oep.ramsize); + + if (oep.ramsize =3D=3D 0x2) + ram_size =3D 2; + else + ram_size =3D 1; + } else { + /* Hardcoded fallback */ + puts("Memory config from EEPROM read failed!\n"); + puts("Falling back to default 1 GiB!\n"); + ram_size =3D 1; + } + } + + return ram_size; +} + /* * Define the DDR layout / topology here in the board file. This will * be used by the DDR3 init code in the SPL U-Boot version to configure @@ -287,37 +312,10 @@ static struct mv_ddr_topology_map board_topology_map_= 2g =3D { =20 struct mv_ddr_topology_map *mv_ddr_topology_map_get(void) { - static int mem; - struct omnia_eeprom oep; - - /* Get the board config from EEPROM */ - if (!mem) { - if (!omnia_read_eeprom(&oep)) - goto out; - - printf("Memory config in EEPROM: 0x%02x\n", oep.ramsize); - - if (oep.ramsize =3D=3D 0x2) - mem =3D 2; - else - mem =3D 1; - } - -out: - /* Hardcoded fallback */ - if (mem =3D=3D 0) { - puts("WARNING: Memory config from EEPROM read failed.\n"); - puts("Falling back to default 1GiB map.\n"); - mem =3D 1; - } - - /* Return the board topology as defined in the board code */ - if (mem =3D=3D 1) - return &board_topology_map_1g; - if (mem =3D=3D 2) + if (omnia_get_ram_size_gb() =3D=3D 2) return &board_topology_map_2g; - - return &board_topology_map_1g; + else + return &board_topology_map_1g; } =20 #ifndef CONFIG_SPL_BUILD --=20 2.21.0