From patchwork Thu Feb 4 09:11:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 376239 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp1082743jah; Thu, 4 Feb 2021 01:12:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzd9xqkPNLsDeVl57hfxYuBa4t5YElEIDj7cj+GfwuupRSczN/LYvFd73B7TX2lf+qB+swF X-Received: by 2002:a17:906:a2da:: with SMTP id by26mr7383105ejb.191.1612429938336; Thu, 04 Feb 2021 01:12:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612429938; cv=none; d=google.com; s=arc-20160816; b=C+UL2qy32H+QA3utTbIQQ6WjQ0eCtJHkNpIycKuhgD5M1gtQy1+89YyYC3K0hOxzn3 JkR3AF2ZIolG+WUrQqHABbpUO8AVdJf/TlvlBiYeAgS3TjQ76JpYsOgw6jnvtBsJKKvV NUKUGr5ubvtHcDaYNDN2QFh5uFmse2s7pYTjgpVLasjnkwAjdtoJoBThd4akiq9atpAG udSZFgSX0CCVA/vSrele0XWza4N3F46NtdWsZluzUY3t1NjyXW5iyM5lxqCbCn+kd2H3 Hs5+lz8IyCMy2izS0wJ5sDuYYAhl9+6Y8+cJ50UV1MWKLv+XwUm07cicC5X4eo2dgZ54 amLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:cms-type:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=hbKfH+dD4LwqzT7uHxG34UxXEXe58KY5aIIsesqXs4A=; b=TZRqbYNlFp1GkUP4vsjMqlP3aipF1ayxCKQ90RzURAzwqL5XoLZSWB8K+vlnpYKsVG WkooaCz/qXJq2bmea5PK2in1ogo6z6CeiIFm1x8ic9+ZEKeEjuDTZ5to0Kl8KHICd8tK tmWq8AlVzbrv+NbvS1rSifP1pyBUjkbhLvQQEuYr5ETm+FT29fgpPrPSqpNWCG7sFD7T U9gu/VFI8zJ2yNjzqHGYzUlr36bdiqJhSNogLRpt9norhzcuiH2SBmMEQK7OWFJhEqvf 8tFllTgVwjaTOLi4kO3x1P8PBGwCAYSTw6je3FBeIHM0SgBKgb1pcGQIwObjsQBlmb/K dk1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tB16hYY+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id k23si2922397ejo.402.2021.02.04.01.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 01:12:18 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tB16hYY+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0A098827A4; Thu, 4 Feb 2021 10:12:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.b="tB16hYY+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3227827C5; Thu, 4 Feb 2021 10:12:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 96D6F82785 for ; Thu, 4 Feb 2021 10:12:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=m.szyprowski@samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20210204091156euoutp02eb3358aa89a5c39dbeaf914ec7bbea3e~ggHdigUKb1921219212euoutp022 for ; Thu, 4 Feb 2021 09:11:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20210204091156euoutp02eb3358aa89a5c39dbeaf914ec7bbea3e~ggHdigUKb1921219212euoutp022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1612429916; bh=hbKfH+dD4LwqzT7uHxG34UxXEXe58KY5aIIsesqXs4A=; h=From:To:Cc:Subject:Date:References:From; b=tB16hYY+1L+/jD3X6+9JcaWpXbmK57G/52Bw1QObiIgtgBoOVNA3znclGUtz5w6de i9FJxjUM6TC4MKnypsUQ6IA2nQhZsAvCfSdgU/fJ5ttJ3iLRyuMCgLXl6HDMfCHwKv NGm1woFb9gMobN6zZmmgxu6u4QNYAjQGkGZEs9nk= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20210204091156eucas1p187e4ce9c4844d1436f56292558684b3b~ggHdQvayg1107311073eucas1p1p; Thu, 4 Feb 2021 09:11:56 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id E1.09.44805.C5ABB106; Thu, 4 Feb 2021 09:11:56 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20210204091156eucas1p2c0ef39f48be756ff3c40dd7be3dac684~ggHc1EErm0291102911eucas1p2d; Thu, 4 Feb 2021 09:11:56 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20210204091156eusmtrp2c677914a5d4d359f77e984eabeb163c7~ggHc0bz8m0049700497eusmtrp2t; Thu, 4 Feb 2021 09:11:56 +0000 (GMT) X-AuditID: cbfec7f4-b37ff7000000af05-88-601bba5c969a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 5A.53.16282.B5ABB106; Thu, 4 Feb 2021 09:11:55 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20210204091155eusmtip1955dad171f21ee2712956c02a0dff532~ggHca3ws11410114101eusmtip1m; Thu, 4 Feb 2021 09:11:55 +0000 (GMT) From: Marek Szyprowski To: u-boot@lists.denx.de, u-boot-amlogic@groups.io Cc: Marek Szyprowski , Neil Armstrong , Jaehoon Chung , Bartlomiej Zolnierkiewicz Subject: [PATCH] board: amlogic: odroid: add runtime detection of the N2/N2+/C4/HC4 variants Date: Thu, 4 Feb 2021 10:11:45 +0100 Message-Id: <20210204091145.19201-1-m.szyprowski@samsung.com> X-Mailer: git-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ZzByeoBWjxFKckWioxVxUnAgAHF3VF2wDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLLMWRmVeSWpSXmKPExsVy+t/xu7rRu6QTDI5OtLLYOGM9q8WNX22s FmuP3GW3ONQXbTFpwi82i7d7O9kd2Dze32hl95jf+Z3J4+ydHYwefVtWMQawROnZFOWXlqQq ZOQXl9gqRRtaGOkZWlroGZlY6hkam8daGZkq6dvZpKTmZJalFunbJehlHDvHUvDSoGL/h5cs DYwrNboYOTkkBEwkvm1cxNLFyMUhJLCUUeJJxzEWiISMxMlpDawQtrDEn2tdbBBFnxglli/v BkuwCRhKdL0FSXByiABNOtl1CSzOLLCXUaJvpyeILSwQIzHzy0EmEJtFQFXi/rsFYDW8ArYS 85dOZoJYIC+xesMB5gmMPAsYGVYxiqSWFuem5xYb6RUn5haX5qXrJefnbmIEhtu2Yz+37GBc +eqj3iFGJg7GQ4wSHMxKIryJbVIJQrwpiZVVqUX58UWlOanFhxhNgfZNZJYSTc4HBnxeSbyh mYGpoYmZpYGppZmxkjivyZE18UIC6YklqdmpqQWpRTB9TBycUg1MsXHbn/n3HL5tb3RS6mmN cIW8x9Z9BsK1Z4UZf7YoJLr+fPF3/9MdT/gmZccohH4Or10h8PTXE9NNFotNOXnz6hmTbIO2 2uyZe7z5YnKnzyffLNO/6z6tfuKQLvEsIbmv+pZRTJGTZmGEfvzODEWt3W3a8qsfzJ15WaTi SQHjpx+9iyOcgxauWX/D8HTVlhzOVddui/2ZOv9iF7f4u7SzJxIk7Z26jDxZjTd6bN2vw3rn 1E31e9K+i6Tycw6YXJxeX3XrZOJ/oy0Pdx7vEOS9m1kvU6L7cOq2TTo1ahc9939UcjvqFrJp YsIB+67tTlbr339bvPxf3G+v4u9vv0vbPmJbre66UWC71DtLhdTvSizFGYmGWsxFxYkAPqI9 dMACAAA= X-CMS-MailID: 20210204091156eucas1p2c0ef39f48be756ff3c40dd7be3dac684 X-Msg-Generator: CA X-RootMTR: 20210204091156eucas1p2c0ef39f48be756ff3c40dd7be3dac684 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20210204091156eucas1p2c0ef39f48be756ff3c40dd7be3dac684 References: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Use the ADC channel 1 to check the hardware revision of the board and detect the N2 vs. N2+ and the C4 vs. HC4 variants. Each of them use different dtb file, so adjust fdtfile environment variable to the detected variant. The ADC min/max values for each variant are taken from the vendor code, adjusted to the 12-bit ADC driver operation mode (vendor code use 10-bit mode). Signed-off-by: Marek Szyprowski --- The relevant vendor's code is here: https://github.com/hardkernel/u-boot/blob/odroidg12-v2015.01/board/hardkernel/odroid-common/board.c#L55 --- arch/arm/dts/meson-g12b-odroid-n2-u-boot.dtsi | 6 ++ arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi | 6 ++ board/amlogic/odroid-n2/odroid-n2.c | 80 +++++++++++++++++++ configs/odroid-c4_defconfig | 4 +- configs/odroid-n2_defconfig | 4 +- 5 files changed, 98 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Jaehoon Chung diff --git a/arch/arm/dts/meson-g12b-odroid-n2-u-boot.dtsi b/arch/arm/dts/meson-g12b-odroid-n2-u-boot.dtsi index 236f2468dc..a92f9e9ff1 100644 --- a/arch/arm/dts/meson-g12b-odroid-n2-u-boot.dtsi +++ b/arch/arm/dts/meson-g12b-odroid-n2-u-boot.dtsi @@ -5,3 +5,9 @@ */ #include "meson-g12-common-u-boot.dtsi" + +/* SARADC is needed for proper board variant detection */ +&saradc { + status = "okay"; + vref-supply = <&vddao_1v8>; +}; diff --git a/arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi b/arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi index fbcc8287c5..963bf96b25 100644 --- a/arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi +++ b/arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi @@ -12,6 +12,12 @@ snps,reset-active-low; }; +/* SARADC is needed for proper board variant detection */ +&saradc { + status = "okay"; + vref-supply = <&vddao_1v8>; +}; + &tflash_vdd { gpio = <&gpio_ao GPIOAO_3 GPIO_OPEN_DRAIN>; }; diff --git a/board/amlogic/odroid-n2/odroid-n2.c b/board/amlogic/odroid-n2/odroid-n2.c index d9955433bf..2eb7fa93be 100644 --- a/board/amlogic/odroid-n2/odroid-n2.c +++ b/board/amlogic/odroid-n2/odroid-n2.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -19,6 +20,11 @@ #define EFUSE_MAC_SIZE 12 #define MAC_ADDR_LEN 6 +#define ODROID_HW_VS_ADC_CHANNEL 1 + +#define MESON_SOC_ID_G12B 0x29 +#define MESON_SOC_ID_SM1 0x2b + int mmc_get_env_dev(void) { if (meson_get_boot_device() == BOOT_DEVICE_EMMC) @@ -26,6 +32,79 @@ int mmc_get_env_dev(void) return 0; } +/* Variant detection is based on the ADC RAW values for the channel #1 */ +static struct meson_odroid_boards { + unsigned int soc_id; + unsigned int adc_min; + unsigned int adc_max; + char *variant; +} boards[] = { + /* OdroidN2 rev 2018,7,23 */ + { MESON_SOC_ID_G12B, 80 * 4, 90 * 4, "n2" }, + /* OdroidN2 rev 2018,12,6 */ + { MESON_SOC_ID_G12B, 160 * 4, 170 * 4, "n2" }, + /* OdroidN2 rev 2019,1,17 */ + { MESON_SOC_ID_G12B, 245 * 4, 255 * 4, "n2" }, + /* OdroidN2 rev 2019,2,7 */ + { MESON_SOC_ID_G12B, 330 * 4, 350 * 4, "n2" }, + /* OdroidN2plus rev 2019,11,20 */ + { MESON_SOC_ID_G12B, 410 * 4, 430 * 4, "n2_plus" }, + /* OdroidC4 rev 2020,01,29 */ + { MESON_SOC_ID_SM1, 80 * 4, 100 * 4, "c4" }, + /* OdroidHC4 rev 2019,12,10 */ + { MESON_SOC_ID_SM1, 300 * 4, 320 * 4, "hc4" }, + /* OdroidC4 rev 2019,11,29 */ + { MESON_SOC_ID_SM1, 335 * 4, 345 * 4, "c4" }, + /* OdroidHC4 rev 2020,8,7 */ + { MESON_SOC_ID_SM1, 590 * 4, 610 * 4, "hc4" }, +}; + +static void odroid_set_fdtfile(char *soc, char *variant) +{ + char s[128]; + + snprintf(s, sizeof(s), "amlogic/meson-%s-odroid-%s.dtb", soc, variant); + env_set("fdtfile", s); +} + +static int odroid_detect_variant(void) +{ + char *variant = "", *soc = ""; + unsigned int adcval = 0; + int ret, i, soc_id = 0; + + if (of_machine_is_compatible("amlogic,sm1")) { + soc_id = MESON_SOC_ID_SM1; + soc = "sm1"; + } else if (of_machine_is_compatible("amlogic,g12b")) { + soc_id = MESON_SOC_ID_G12B; + soc = "g12b"; + } else { + return -1; + } + + ret = adc_channel_single_shot("adc@9000", ODROID_HW_VS_ADC_CHANNEL, + &adcval); + if (ret) + return ret; + + for (i = 0 ; i < ARRAY_SIZE(boards) ; ++i) { + if (soc_id == boards[i].soc_id && + adcval >= boards[i].adc_min && + adcval < boards[i].adc_max) { + variant = boards[i].variant; + break; + } + } + + printf("Board variant: %s\n", variant); + env_set("variant", variant); + + odroid_set_fdtfile(soc, variant); + + return 0; +} + int misc_init_r(void) { u8 mac_addr[MAC_ADDR_LEN]; @@ -58,5 +137,6 @@ int misc_init_r(void) meson_generate_serial_ethaddr(); } + odroid_detect_variant(); return 0; } diff --git a/configs/odroid-c4_defconfig b/configs/odroid-c4_defconfig index 367d22db0b..8a9b8b0c02 100644 --- a/configs/odroid-c4_defconfig +++ b/configs/odroid-c4_defconfig @@ -8,7 +8,7 @@ CONFIG_DM_GPIO=y CONFIG_MESON_G12A=y CONFIG_DEBUG_UART_BASE=0xff803000 CONFIG_DEBUG_UART_CLOCK=24000000 -CONFIG_IDENT_STRING=" odroid-c4" +CONFIG_IDENT_STRING=" odroid-c4/hc4" CONFIG_DEFAULT_DEVICE_TREE="meson-sm1-odroid-c4" CONFIG_DEBUG_UART=y CONFIG_OF_BOARD_SETUP=y @@ -26,6 +26,8 @@ CONFIG_CMD_REGULATOR=y CONFIG_OF_CONTROL=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_ADC=y +CONFIG_SARADC_MESON=y CONFIG_DM_MMC=y CONFIG_MMC_MESON_GX=y CONFIG_PHY_REALTEK=y diff --git a/configs/odroid-n2_defconfig b/configs/odroid-n2_defconfig index 76c60ab032..b82bd78f2d 100644 --- a/configs/odroid-n2_defconfig +++ b/configs/odroid-n2_defconfig @@ -8,7 +8,7 @@ CONFIG_DM_GPIO=y CONFIG_MESON_G12A=y CONFIG_DEBUG_UART_BASE=0xff803000 CONFIG_DEBUG_UART_CLOCK=24000000 -CONFIG_IDENT_STRING=" odroid-n2" +CONFIG_IDENT_STRING=" odroid-n2/n2_plus" CONFIG_DEFAULT_DEVICE_TREE="meson-g12b-odroid-n2" CONFIG_DEBUG_UART=y CONFIG_OF_BOARD_SETUP=y @@ -26,6 +26,8 @@ CONFIG_CMD_REGULATOR=y CONFIG_OF_CONTROL=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_ADC=y +CONFIG_SARADC_MESON=y CONFIG_DM_MMC=y CONFIG_MMC_MESON_GX=y CONFIG_PHY_REALTEK=y