From patchwork Sat Jan 21 09:05:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 92131 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp395458qgi; Sat, 21 Jan 2017 01:08:33 -0800 (PST) X-Received: by 10.223.148.230 with SMTP id 93mr13703043wrr.13.1484989713198; Sat, 21 Jan 2017 01:08:33 -0800 (PST) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id e63si6467532wmi.104.2017.01.21.01.08.32; Sat, 21 Jan 2017 01:08:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5244D4B5CF; Sat, 21 Jan 2017 10:07:29 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JyUVHbQVxIRu; Sat, 21 Jan 2017 10:07:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A4908A75C9; Sat, 21 Jan 2017 10:07:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D90674A99B for ; Sat, 21 Jan 2017 10:06:15 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t-qs9a4QFxdA for ; Sat, 21 Jan 2017 10:06:15 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-11.nifty.com (conuserg-11.nifty.com [210.131.2.78]) by theia.denx.de (Postfix) with ESMTPS id BAF9D4A08A for ; Sat, 21 Jan 2017 10:06:11 +0100 (CET) Received: from grover.sesame (FL1-111-169-71-157.osk.mesh.ad.jp [111.169.71.157]) (authenticated) by conuserg-11.nifty.com with ESMTP id v0L95cw4001124; Sat, 21 Jan 2017 18:05:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com v0L95cw4001124 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1484989545; bh=9fRd0qlxHp+kpdTyDAWky7UWK69vXn15rcieRxWvsJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dm91rvE3Fc1wcCxp7SG4lQzfslCxaGz91UWeVcKcOyiH5NcR1F0KPb0TiSmA19xh8 u0OmPMn5zkOWvmLjS5SdEAMziDy2VNoi56g97M98meze05UICsuWsDcFHEOhzV6lLk pyHGkku0KOb6r0cEtm/9py7lLS9Ctwlp5XGHijdI245QXFmLiMnOHb56aiYaQDxjgM BLtvgGgVdYXY5BrNjywB55pUOiNiB+n6YVRS6cjGuojvI7fE/tbSjKa3eYPCxIWRCM 3ufSsFNYj2+U44RZuw9reTI5JYM4UpmXisv89ZI/OoWNQrj+2ABlYGExRItgSmoxH7 1CrwWs6b0E6Gg== X-Nifty-SrcIP: [111.169.71.157] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Sat, 21 Jan 2017 18:05:27 +0900 Message-Id: <1484989531-11985-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484989531-11985-1-git-send-email-yamada.masahiro@socionext.com> References: <1484989531-11985-1-git-send-email-yamada.masahiro@socionext.com> Cc: Albert Aribaud Subject: [U-Boot] [PATCH 07/11] ARM: uniphier: add macro to generate SoC data look-up function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" There are similar functions that look up SoC data by the SoC ID. The new macro UNIPHIER_DEFINE_SOCDATA_FUNC will be helpful to avoid the code duplication. Signed-off-by: Masahiro Yamada --- arch/arm/mach-uniphier/board_init.c | 20 +++----------------- arch/arm/mach-uniphier/soc-info.h | 18 ++++++++++++++++++ arch/arm/mach-uniphier/spl_board_init.c | 18 ++---------------- 3 files changed, 23 insertions(+), 33 deletions(-) -- 2.7.4 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/arch/arm/mach-uniphier/board_init.c b/arch/arm/mach-uniphier/board_init.c index 413b338..ac7e3a6 100644 --- a/arch/arm/mach-uniphier/board_init.c +++ b/arch/arm/mach-uniphier/board_init.c @@ -169,32 +169,18 @@ static const struct uniphier_initdata uniphier_initdata[] = { }, #endif }; - -static const struct uniphier_initdata *uniphier_get_initdata( - unsigned int soc_id) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(uniphier_initdata); i++) { - if (uniphier_initdata[i].soc_id == soc_id) - return &uniphier_initdata[i]; - } - - return NULL; -} +UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_initdata, uniphier_initdata) int board_init(void) { const struct uniphier_initdata *initdata; - unsigned int soc_id; int ret; led_puts("U0"); - soc_id = uniphier_get_soc_id(); - initdata = uniphier_get_initdata(soc_id); + initdata = uniphier_get_initdata(); if (!initdata) { - pr_err("unsupported board\n"); + pr_err("unsupported SoC\n"); return -EINVAL; } diff --git a/arch/arm/mach-uniphier/soc-info.h b/arch/arm/mach-uniphier/soc-info.h index aeaaf83..a85df23 100644 --- a/arch/arm/mach-uniphier/soc-info.h +++ b/arch/arm/mach-uniphier/soc-info.h @@ -7,6 +7,9 @@ #ifndef __UNIPHIER_SOC_INFO_H__ #define __UNIPHIER_SOC_INFO_H__ +#include +#include + #define UNIPHIER_SLD3_ID 0x25 #define UNIPHIER_LD4_ID 0x26 #define UNIPHIER_PRO4_ID 0x28 @@ -21,4 +24,19 @@ unsigned int uniphier_get_soc_id(void); unsigned int uniphier_get_soc_model(void); unsigned int uniphier_get_soc_revision(void); +#define UNIPHIER_DEFINE_SOCDATA_FUNC(__func_name, __table) \ +static typeof(&__table[0]) __func_name(void) \ +{ \ + unsigned int soc_id; \ + int i; \ + \ + soc_id = uniphier_get_soc_id(); \ + for (i = 0; i < ARRAY_SIZE(__table); i++) { \ + if (__table[i].soc_id == soc_id) \ + return &__table[i]; \ + } \ + \ + return NULL; \ +} + #endif /* __UNIPHIER_SOC_INFO_H__ */ diff --git a/arch/arm/mach-uniphier/spl_board_init.c b/arch/arm/mach-uniphier/spl_board_init.c index 83851ef..da749a3 100644 --- a/arch/arm/mach-uniphier/spl_board_init.c +++ b/arch/arm/mach-uniphier/spl_board_init.c @@ -118,25 +118,12 @@ static const struct uniphier_spl_initdata uniphier_spl_initdata[] = { }, #endif }; - -static const struct uniphier_spl_initdata *uniphier_get_spl_initdata( - unsigned int soc_id) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(uniphier_spl_initdata); i++) { - if (uniphier_spl_initdata[i].soc_id == soc_id) - return &uniphier_spl_initdata[i]; - } - - return NULL; -} +UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_spl_initdata, uniphier_spl_initdata) void spl_board_init(void) { const struct uniphier_board_data *bd; const struct uniphier_spl_initdata *initdata; - unsigned int soc_id; int ret; #ifdef CONFIG_DEBUG_UART @@ -147,8 +134,7 @@ void spl_board_init(void) if (!bd) hang(); - soc_id = uniphier_get_soc_id(); - initdata = uniphier_get_spl_initdata(soc_id); + initdata = uniphier_get_spl_initdata(); if (!initdata) hang();