From patchwork Tue Aug 14 13:07:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 10565607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 810D115A6 for ; Tue, 14 Aug 2018 13:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D6B928C08 for ; Tue, 14 Aug 2018 13:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6181D28CD1; Tue, 14 Aug 2018 13:08:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BF6DB28C08 for ; Tue, 14 Aug 2018 13:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=MWNtxLfX5S6eXYxWwKRmTsm7t3rwBENeU9klNbUrYOs=; b=A2AvvtjZ0KeKXOp8fmCOhDXR8n oZRB3tYqkw16AC7LHtHM0XeKeKvOZNLvAjLzWyqz/3g7M/K07k1ObnxeHCml4w4nSpQ/kn80ZQ1Ja deF9AdalpCBvLH7JFL/qmWkfgjqJbR+Wi7etkCTQB7ov/InAbw2Rqcn6vFjrshrF1SLaiMluj0L+l DQ2QT+Vy37iy/AFP2W9qb2zir408oZ74w9aaJuQmWOtiV2Puk3IWgAjHrXmZlHPwgOypRmCPcQZDH fn+xBCXFmtdIP8uaOaSRxJyWiBowCkTBwSNjUE8l3D0nquAFY9ZPEHBPzzqniMg4BSiKa7vdgZCTu GK81ta1w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fpZ41-0000Og-T8; Tue, 14 Aug 2018 13:08:45 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fpZ3x-0000Gk-Al for linux-amlogic@lists.infradead.org; Tue, 14 Aug 2018 13:08:43 +0000 Received: by mail-wr1-x444.google.com with SMTP id h9-v6so17183075wro.3 for ; Tue, 14 Aug 2018 06:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/cPa9g1ttYsZYdUcPwzKBMX632ifU5joE78RzoUZoqk=; b=dlHTFCXHdDfBquu/0D6HJ9ppdQJqe1ZZjaWVK8TJbC2MtJ87bmHy9O9yVA8+Sqhe6w NR+4e7BW6WAAgLOSF0jztJOeHSUMAJDQaZxDJdAVmOSdtURuO1Ja4Y5zZV8pt9OIj4eQ pQSVgM7VzbIf2NfnYpO9WoR0S1wrlRZ3XkKOggM3gjAaNHYj6XhlJn/avW3Pt9CG46/S lgqSjS2Aga9u7lT9iqWueLcsBXXGpBesKWbYUUgVbMyHR5jvJXxZLJyV0ZIJJjO04nkn tCtCDnuP7y5cRP1sfJvgHtLlygXdmqnHDtf7jI8s59TN+i/OJu2qOlv9AtrlQhwtcK7w CwWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/cPa9g1ttYsZYdUcPwzKBMX632ifU5joE78RzoUZoqk=; b=hG4ts0gq6z1mj2t4d228CcYkXqYQms7cZOWU6YGaBLyOEjQ9xuVA7eCE/28Px2WpBv O0DvDbvOZDCHAScXlzA/5hmmrUPnm9Y7dRbUKjGig5epqh3ZmTA3jtkUq8k92mEwluor /5os623Hz8OPheutdseSlBav+KgbBYJn/ZxpxwgZlrzp9CSSx6xTm5pvooLGmXNtQ2w9 V4YioGNLw3p8lJGg0CrJD3ygYIbriOtidfJO1euOn28p6ose9DzG88lp3ktqrIyD2qs2 MynHAl21Y+OnGd4J/Ncf3rQ4RCryO57pMDfYTeAfcTkH1p5ksB7/F3c6XlJdLS43MmCY C6gw== X-Gm-Message-State: AOUpUlFMdy6p9+chxUYxO5vDIRwkE+uGqki4zb7m/6DHHcwN65zyP9RH ieRw77QlIE/SfN//5cU0tIg= X-Google-Smtp-Source: AA+uWPwPwmkfYPZZ/DEBUXC9DNKrjUOR51SjsBstYujCHf2OjgpKo0IWz7Ghejk5wqgpK2J3rcfm+g== X-Received: by 2002:adf:9486:: with SMTP id 6-v6mr10170403wrr.257.1534252107187; Tue, 14 Aug 2018 06:08:27 -0700 (PDT) Received: from sark.homenet.telecomitalia.it ([79.46.68.202]) by smtp.gmail.com with ESMTPSA id r16-v6sm29123997wru.59.2018.08.14.06.08.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Aug 2018 06:08:26 -0700 (PDT) From: Beniamino Galvani To: u-boot@lists.denx.de Subject: [PATCH u-boot 2/3] boards: amlogic: use common function for environment initialization Date: Tue, 14 Aug 2018 15:07:53 +0200 Message-Id: <20180814130754.19294-3-b.galvani@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180814130754.19294-1-b.galvani@gmail.com> References: <20180814130754.19294-1-b.galvani@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180814_060841_440919_C18D9DF2 X-CRM114-Status: GOOD ( 12.48 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Albert Aribaud , Neil Armstrong , Simon Glass , Beniamino Galvani , linux-amlogic@lists.infradead.org MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Clean up board files by moving the duplicate environment initialization to arch code. Signed-off-by: Beniamino Galvani --- arch/arm/include/asm/arch-meson/sm.h | 1 + arch/arm/mach-meson/sm.c | 27 +++++++++++++++++++++++ board/amlogic/khadas-vim/khadas-vim.c | 25 +-------------------- board/amlogic/libretech-cc/libretech-cc.c | 25 +-------------------- board/amlogic/nanopi-k2/nanopi-k2.c | 25 +-------------------- board/amlogic/odroid-c2/odroid-c2.c | 25 +-------------------- board/amlogic/p212/p212.c | 25 +-------------------- 7 files changed, 33 insertions(+), 120 deletions(-) diff --git a/arch/arm/include/asm/arch-meson/sm.h b/arch/arm/include/asm/arch-meson/sm.h index 83d6441803..db2be38fc5 100644 --- a/arch/arm/include/asm/arch-meson/sm.h +++ b/arch/arm/include/asm/arch-meson/sm.h @@ -7,5 +7,6 @@ #define __MESON_SM_H__ ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size); +void meson_init_env_from_efuse(void); #endif /* __MESON_SM_H__ */ diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c index 0bba5e4a07..2628591fe6 100644 --- a/arch/arm/mach-meson/sm.c +++ b/arch/arm/mach-meson/sm.c @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -14,6 +15,11 @@ #define FN_EFUSE_READ 0x82000030 #define FN_EFUSE_WRITE 0x82000031 +#define EFUSE_SN_OFFSET 20 +#define EFUSE_SN_SIZE 16 +#define EFUSE_MAC_OFFSET 52 +#define EFUSE_MAC_SIZE 6 + static void *shmem_input; static void *shmem_output; @@ -54,3 +60,24 @@ ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size) return regs.regs[0]; } + +void meson_init_env_from_efuse(void) +{ + static u8 mac[EFUSE_MAC_SIZE]; + char serial[EFUSE_SN_SIZE]; + ssize_t len; + + if (!eth_env_get_enetaddr("ethaddr", mac)) { + len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, + mac, EFUSE_MAC_SIZE); + if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac)) + eth_env_set_enetaddr("ethaddr", mac); + } + + if (!env_get("serial#")) { + len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, + EFUSE_SN_SIZE); + if (len == EFUSE_SN_SIZE) + env_set("serial#", serial); + } +} diff --git a/board/amlogic/khadas-vim/khadas-vim.c b/board/amlogic/khadas-vim/khadas-vim.c index 692bf2add3..4483a96761 100644 --- a/board/amlogic/khadas-vim/khadas-vim.c +++ b/board/amlogic/khadas-vim/khadas-vim.c @@ -6,18 +6,12 @@ #include #include -#include #include #include #include #include #include -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 - int board_init(void) { return 0; @@ -25,26 +19,9 @@ int board_init(void) int misc_init_r(void) { - u8 mac_addr[EFUSE_MAC_SIZE]; - char serial[EFUSE_SN_SIZE]; - ssize_t len; - meson_gx_eth_init(PHY_INTERFACE_MODE_RMII, MESON_GXL_USE_INTERNAL_RMII_PHY); - - if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { - len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, - mac_addr, EFUSE_MAC_SIZE); - if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr)) - eth_env_set_enetaddr("ethaddr", mac_addr); - } - - if (!env_get("serial#")) { - len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, - EFUSE_SN_SIZE); - if (len == EFUSE_SN_SIZE) - env_set("serial#", serial); - } + meson_init_env_from_efuse(); return 0; } diff --git a/board/amlogic/libretech-cc/libretech-cc.c b/board/amlogic/libretech-cc/libretech-cc.c index ccab1272c5..86b1d213ff 100644 --- a/board/amlogic/libretech-cc/libretech-cc.c +++ b/board/amlogic/libretech-cc/libretech-cc.c @@ -6,18 +6,12 @@ #include #include -#include #include #include #include #include #include -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 - int board_init(void) { return 0; @@ -25,26 +19,9 @@ int board_init(void) int misc_init_r(void) { - u8 mac_addr[EFUSE_MAC_SIZE]; - char serial[EFUSE_SN_SIZE]; - ssize_t len; - meson_gx_eth_init(PHY_INTERFACE_MODE_RMII, MESON_GXL_USE_INTERNAL_RMII_PHY); - - if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { - len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, - mac_addr, EFUSE_MAC_SIZE); - if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr)) - eth_env_set_enetaddr("ethaddr", mac_addr); - } - - if (!env_get("serial#")) { - len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, - EFUSE_SN_SIZE); - if (len == EFUSE_SN_SIZE) - env_set("serial#", serial); - } + meson_init_env_from_efuse(); return 0; } diff --git a/board/amlogic/nanopi-k2/nanopi-k2.c b/board/amlogic/nanopi-k2/nanopi-k2.c index ae29dd6fa4..e61c23f8c6 100644 --- a/board/amlogic/nanopi-k2/nanopi-k2.c +++ b/board/amlogic/nanopi-k2/nanopi-k2.c @@ -5,18 +5,12 @@ #include #include -#include #include #include #include #include #include -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 - int board_init(void) { return 0; @@ -24,25 +18,8 @@ int board_init(void) int misc_init_r(void) { - u8 mac_addr[EFUSE_MAC_SIZE]; - char serial[EFUSE_SN_SIZE]; - ssize_t len; - meson_gx_eth_init(PHY_INTERFACE_MODE_RGMII, 0); - - if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { - len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, - mac_addr, EFUSE_MAC_SIZE); - if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr)) - eth_env_set_enetaddr("ethaddr", mac_addr); - } - - if (!env_get("serial#")) { - len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, - EFUSE_SN_SIZE); - if (len == EFUSE_SN_SIZE) - env_set("serial#", serial); - } + meson_init_env_from_efuse(); return 0; } diff --git a/board/amlogic/odroid-c2/odroid-c2.c b/board/amlogic/odroid-c2/odroid-c2.c index 2a2755c387..fffd225485 100644 --- a/board/amlogic/odroid-c2/odroid-c2.c +++ b/board/amlogic/odroid-c2/odroid-c2.c @@ -5,18 +5,12 @@ #include #include -#include #include #include #include #include #include -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 - int board_init(void) { return 0; @@ -24,25 +18,8 @@ int board_init(void) int misc_init_r(void) { - u8 mac_addr[EFUSE_MAC_SIZE]; - char serial[EFUSE_SN_SIZE]; - ssize_t len; - meson_gx_eth_init(PHY_INTERFACE_MODE_RGMII, 0); - - if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { - len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, - mac_addr, EFUSE_MAC_SIZE); - if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr)) - eth_env_set_enetaddr("ethaddr", mac_addr); - } - - if (!env_get("serial#")) { - len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, - EFUSE_SN_SIZE); - if (len == EFUSE_SN_SIZE) - env_set("serial#", serial); - } + meson_init_env_from_efuse(); return 0; } diff --git a/board/amlogic/p212/p212.c b/board/amlogic/p212/p212.c index 06c2eaee47..57f776f404 100644 --- a/board/amlogic/p212/p212.c +++ b/board/amlogic/p212/p212.c @@ -6,18 +6,12 @@ #include #include -#include #include #include #include #include #include -#define EFUSE_SN_OFFSET 20 -#define EFUSE_SN_SIZE 16 -#define EFUSE_MAC_OFFSET 52 -#define EFUSE_MAC_SIZE 6 - int board_init(void) { return 0; @@ -25,25 +19,8 @@ int board_init(void) int misc_init_r(void) { - u8 mac_addr[EFUSE_MAC_SIZE]; - char serial[EFUSE_SN_SIZE]; - ssize_t len; - meson_gx_eth_init(PHY_INTERFACE_MODE_RMII, 0); - - if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { - len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, - mac_addr, EFUSE_MAC_SIZE); - if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr)) - eth_env_set_enetaddr("ethaddr", mac_addr); - } - - if (!env_get("serial#")) { - len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, - EFUSE_SN_SIZE); - if (len == EFUSE_SN_SIZE) - env_set("serial#", serial); - } + meson_init_env_from_efuse(); return 0; }