From patchwork Tue Apr 30 01:48:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1092923 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nic.cz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="FEaIS6+2"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44tPd32cqJz9s9T for ; Tue, 30 Apr 2019 11:51:03 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E659BC21DB3; Tue, 30 Apr 2019 01:50:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3EB7DC21E36; Tue, 30 Apr 2019 01:48:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5F330C21BE5; Tue, 30 Apr 2019 01:48:27 +0000 (UTC) Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) by lists.denx.de (Postfix) with ESMTPS id 8B716C21D8A for ; Tue, 30 Apr 2019 01:48:27 +0000 (UTC) Received: from dellmb.labs.office.nic.cz (unknown [172.20.6.125]) by mail.nic.cz (Postfix) with ESMTP id 3F6276385F; Tue, 30 Apr 2019 03:48:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1556588907; bh=mrX6I4UKFUXN8KKaZrdVcq8XZshiZEjWQW/eyR2VFvs=; h=From:To:Date; b=FEaIS6+2Z7b/ZR3prnJpqVnMakuMDjl7BBFdPdNxCRKrpGTL0keQVgJIr4dxyijZV v8ff+EQVGov0kwffOMXrl3KHGk1W7uHojYDT+wWF6owVQDZD7vSFfBgVlzQSudw65N kDSupJ+1QvPJQ10QC6POngCzXoTn5/l7mKkghTbg= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de Date: Tue, 30 Apr 2019 03:48:20 +0200 Message-Id: <20190430014825.30553-11-marek.behun@nic.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430014825.30553-1-marek.behun@nic.cz> References: <20190430014825.30553-1-marek.behun@nic.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at mail X-Virus-Status: Clean Cc: Stefan Roese Subject: [U-Boot] [PATCH u-boot-marvell v2 10/15] arm: mvebu: turris_omnia: refactor more code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Refactor RAM size reading from EEPROM in preparation for next patch. Signed-off-by: Marek BehĂșn 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; } +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 == 0x2) + ram_size = 2; + else + ram_size = 1; + } else { + /* Hardcoded fallback */ + puts("Memory config from EEPROM read failed!\n"); + puts("Falling back to default 1 GiB!\n"); + ram_size = 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 = { 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 == 0x2) - mem = 2; - else - mem = 1; - } - -out: - /* Hardcoded fallback */ - if (mem == 0) { - puts("WARNING: Memory config from EEPROM read failed.\n"); - puts("Falling back to default 1GiB map.\n"); - mem = 1; - } - - /* Return the board topology as defined in the board code */ - if (mem == 1) - return &board_topology_map_1g; - if (mem == 2) + if (omnia_get_ram_size_gb() == 2) return &board_topology_map_2g; - - return &board_topology_map_1g; + else + return &board_topology_map_1g; } #ifndef CONFIG_SPL_BUILD