From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCE44C77B7C for ; Wed, 10 May 2023 15:56:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D87EE8606E; Wed, 10 May 2023 17:56:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="M1ZroErU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B462185830; Wed, 10 May 2023 17:55:59 +0200 (CEST) Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CD33F8606E for ; Wed, 10 May 2023 17:55:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=macroalpha82@gmail.com Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6ab0c70801dso1366911a34.0 for ; Wed, 10 May 2023 08:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683734155; x=1686326155; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=E8XGQ8KznNpVJaQ2uUQd7jU1KKqDE0SuGAArhY6ryKA=; b=M1ZroErU5FhOnXHUP6jA0Rb45hGOwVOyekZJiiY1yMwirpzv8MCWx2C46weZRn1iZT RliHPPraBIT1mtbDdi0FERLZzXAXgXZza5niBaZsGlDJIYG9GIg1wPzGXDkzhicAp/nx uO9lpQSLspd4LbB6J2vXPz0Uaacx03HXAAljybYI5Fow7Kg0Y/CHOt9e2YNz/bX7Uuda r8mg12wRTotwOyTlQCXGZJCxbOPAq6qQhK8xGMBqokqecB/iHMQhxJa2JwdWzz2NyZaq jLImAHaK19d34whoNntyktfFqX931g3krgN6UCdeZ/TsxubeDg9avHl/5LYXwc43I7/X L8aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683734155; x=1686326155; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E8XGQ8KznNpVJaQ2uUQd7jU1KKqDE0SuGAArhY6ryKA=; b=N2Mvb8iIWd47JJoOptHjR4ZRYJA84S1cumeZG27pCWMFNcTvFIP3+NrQ0vkpLVkFar qO71SEy3RDMLg9OrffQL1z6Beuwyk4kV1aXqiaZwo4O53s5+CHkdXFsb5+WeMYsD5gv6 NMMu2bk+BfgzY598Hi9WANYZNMxZI0jRe7dxNzNR6+K4Gs0T3cnV68/lR03lY2GE6vrz t+1kq4QnDN+RmMtLsLJNku1D1BrZLHzXqm9c8UR2FWj41XcjxOeUW6+DIYjmLX7PWab0 V2136NI/tECXZBB27R2wT7zi5lbSeOu32q6jIgko91+8qR1IlBPx3VojYqWTAA6D3cNV NguA== X-Gm-Message-State: AC+VfDwvHQQ+1MMfMxG1Z5sjaMkkCELmu4Rm8c/Ecg5ygjDnqNSgzH+A QkKls/jph4/LhgKp11s2e3Hd/7Zlj1Jr7A== X-Google-Smtp-Source: ACHHUZ6rq8Id9UEZswgO0SVrnTkWsrB/TYrQEgZGe3Hoiwp4VixBTL+a6yJs+adzkvnqfLPzUyEe/w== X-Received: by 2002:a9d:6d17:0:b0:6ab:27b5:d202 with SMTP id o23-20020a9d6d17000000b006ab27b5d202mr2328865otp.37.1683734154998; Wed, 10 May 2023 08:55:54 -0700 (PDT) Received: from localhost.localdomain ([76.244.6.13]) by smtp.gmail.com with ESMTPSA id e18-20020a9d5612000000b006a1287ccce6sm6350045oti.31.2023.05.10.08.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 08:55:54 -0700 (PDT) From: Chris Morgan To: u-boot@lists.denx.de Cc: heiko.stuebner@theobroma-systems.com, Chris Morgan Subject: [PATCH] rockchip: board: Update Odroid Go2 to Support Additional Revisions Date: Wed, 10 May 2023 10:55:50 -0500 Message-Id: <20230510155550.2871505-1-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean From: Chris Morgan Update the board.c file for the Odroid Go Advance to support the Black Edition and the Odroid Go Super. The Odroid Go Advance Black Edition differs from the original model with the addition of 2 extra buttons and an ESP8266 WiFi module. The Odroid Go Super adds an additional 2 buttons compared to the Black Edition, along with a larger panel and larger battery. This change uses the value of ADC0 to determine which of these 3 models it is, and then changes the ${fdtfile} environment variable to match the proper devicetree name in mainline Linux. Tested on an Odroid Go Advance (first revision) and an Odroid Go Super. The correct ${fdtfile} variable was set for each device. Signed-off-by: Chris Morgan --- board/hardkernel/odroid_go2/go2.c | 103 ++++++++++++++++++++++++++++++ configs/odroid-go2_defconfig | 1 + 2 files changed, 104 insertions(+) diff --git a/board/hardkernel/odroid_go2/go2.c b/board/hardkernel/odroid_go2/go2.c index 29464ae63e..a0338ead3b 100644 --- a/board/hardkernel/odroid_go2/go2.c +++ b/board/hardkernel/odroid_go2/go2.c @@ -2,3 +2,106 @@ /* * (C) Copyright 2019 Rockchip Electronics Co., Ltd */ + +#include +#include +#include +#include +#include +#include + +#define DTB_DIR "rockchip/" + +struct oga_model { + const u16 adc_value; + const char *board; + const char *board_name; + const char *fdtfile; +}; + +enum oga_device_id { + OGA, + OGA_V11, + OGS, +}; + +/* + * All ADC values from schematic of Odroid Go Advance Black Edition. + * Value for OGS is inferred based on schematic and observed values. + */ +static const struct oga_model oga_model_details[] = { + [OGA] = { + 856, + "rk3326-odroid-go2", + "ODROID-GO Advance", + DTB_DIR "rk3326-odroid-go2.dtb", + }, + [OGA_V11] = { + 677, + "rk3326-odroid-go2-v11", + "ODROID-GO Advance Black Edition", + DTB_DIR "rk3326-odroid-go2-v11.dtb", + }, + [OGS] = { + 85, + "rk3326-odroid-go3", + "ODROID-GO Super", + DTB_DIR "rk3326-odroid-go3.dtb", + }, +}; + +/* Detect which Odroid Go Advance device we are using so as to load the + * correct devicetree for Linux. Set an environment variable once + * found. The detection depends on the value of ADC channel 0. + */ +int oga_detect_device(void) +{ + u32 adc_info; + int ret, i; + int board_id = -ENXIO; + + ret = adc_channel_single_shot("saradc@ff288000", 0, &adc_info); + if (ret) { + printf("Read SARADC failed with error %d\n", ret); + return ret; + } + + /* + * Get the correct device from the table. The ADC value is + * determined by a resistor on ADC channel 0. The manufacturer + * accounted for this with a 5% tolerance, so assume a +- value + * of 50 should be enough. + */ + for (i = 0; i < ARRAY_SIZE(oga_model_details); i++) { + u32 adc_min = oga_model_details[i].adc_value - 50; + u32 adc_max = oga_model_details[i].adc_value + 50; + + if (adc_min < adc_info && adc_max > adc_info) { + board_id = i; + break; + } + } + + if (board_id < 0) + return board_id; + + env_set("board", oga_model_details[board_id].board); + env_set("board_name", + oga_model_details[board_id].board_name); + env_set("fdtfile", oga_model_details[board_id].fdtfile); + + return 0; +} + +int rk_board_late_init(void) +{ + int ret; + + ret = oga_detect_device(); + if (ret) { + printf("Unable to detect device type: %d\n", ret); + return ret; + } + + return 0; +} diff --git a/configs/odroid-go2_defconfig b/configs/odroid-go2_defconfig index 459ae3d59c..bdc2288af6 100644 --- a/configs/odroid-go2_defconfig +++ b/configs/odroid-go2_defconfig @@ -35,6 +35,7 @@ CONFIG_DEFAULT_FDT_FILE="rockchip/rk3326-odroid-go2.dtb" # CONFIG_CONSOLE_MUX is not set # CONFIG_DISPLAY_CPUINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_BOARD_LATE_INIT=y CONFIG_MISC_INIT_R=y CONFIG_SPL_MAX_SIZE=0x20000 CONFIG_SPL_PAD_TO=0x7f8000 -- 2.34.1