From patchwork Fri May 22 18:03:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suniel Mahesh X-Patchwork-Id: 1296431 X-Patchwork-Delegate: ykai007@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=FWE3Al7u; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49TDt50Mdgz9sSc for ; Sat, 23 May 2020 04:05:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5AD0C81865; Fri, 22 May 2020 20:04:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.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=amarulasolutions.com header.i=@amarulasolutions.com header.b="FWE3Al7u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A616E81743; Fri, 22 May 2020 20:04:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) (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 8AE638168A for ; Fri, 22 May 2020 20:04:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sunil@amarulasolutions.com Received: by mail-pj1-x1044.google.com with SMTP id s69so5248283pjb.4 for ; Fri, 22 May 2020 11:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uhrJAnz+dRaIRcJyUeZniEGJG0HrbK0XnHsVrm7Od6w=; b=FWE3Al7u5CtiKD9fFTmhifd//Gf3eMemnQc7tcCsUNX8HhgWDR4OsscrZwNu4XZM4F lHrl1DhtA6bgiM+cRM/5OG+Im9miIGxk9FfKbcjVphzG7NXGqyEEM/FwvHtVqReoyvpp GtrOdWYfRmGakt6J+Jkz1EAuGfUA2LzjOPoqA= 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=uhrJAnz+dRaIRcJyUeZniEGJG0HrbK0XnHsVrm7Od6w=; b=GCr1xNDTmBJLeBbTZnwvdYEBYpizj7hWX5+0UUdYnT532tiEwGhQwMKLF/z+t5I598 2g7LsyfsFsldv0B9tAVRjVObyJKXfCz2yit0qcfShZGSW+xTsEs4qJyeVseybgHwZsGi Xy2nmqK1upObIBCvcjRgkzkMf0Ooxp1NYWJRvuwJ9xjYEEvSKGZp1cQe9J+f11Ze4Un2 sUgH2HwTmtjmI53jPBZ/DGNbwo0tgmaLm50Csgnv3kO3Mj5vHeEFIu3rhRl2sRwtbjuo V9G6ZHLOM7vjsZEoYtP/62BVKCwuwWvpInJb6TLETjpebHMIlP7FbNpxyc0FY0VI4P7b Y7aw== X-Gm-Message-State: AOAM5323HS5FJXXqI/RjsvT29wSnB0HyOIzgu+4tAz9cMEluX/TViLCo 9BGW7wlIOKNrVUCYxK/SrO/gaQ== X-Google-Smtp-Source: ABdhPJxczsGwvP3CfWL6SkQz+icz8q8Fl7EXGBDqNu5bzr1XIGJgjHLOFbIt/+KUT+F+vkNQMhUCbQ== X-Received: by 2002:a17:90a:6b08:: with SMTP id v8mr5572642pjj.151.1590170673860; Fri, 22 May 2020 11:04:33 -0700 (PDT) Received: from localhost.localdomain ([49.204.227.108]) by smtp.gmail.com with ESMTPSA id 15sm790726pfw.189.2020.05.22.11.04.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 May 2020 11:04:33 -0700 (PDT) From: sunil@amarulasolutions.com To: djw@t-chip.com.cn, kever.yang@rock-chips.com, sjg@chromium.org, philipp.tomsich@theobroma-systems.com Cc: u-boot@lists.denx.de, jagan@amarulasolutions.com, Suniel Mahesh Subject: [PATCH 3/5] roc-pc-rk3399: Add support for add-on board run-time detection Date: Fri, 22 May 2020 23:33:26 +0530 Message-Id: <1590170608-12229-4-git-send-email-sunil@amarulasolutions.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590170608-12229-1-git-send-email-sunil@amarulasolutions.com> References: <1590170608-12229-1-git-send-email-sunil@amarulasolutions.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean From: Suniel Mahesh roc-pc-rk3399 target has an add-on board, this add-on board hosts a CW2015 chip which is connected as slave to I2C2. In order to dynamically detect this add-on board at runtime, I2C2 is probed in SPL. If probe is successfull then a corresponding dtb is loaded, else regular dtb is loaded for the u-boot proper. Signed-off-by: Suniel Mahesh Signed-off-by: Jagan Teki --- board/firefly/roc-pc-rk3399/roc-pc-rk3399.c | 56 +++++++++++++++++++++++++++++ configs/roc-pc-rk3399_defconfig | 2 ++ 2 files changed, 58 insertions(+) diff --git a/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c b/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c index 7c3a803..b3cbfaa 100644 --- a/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c +++ b/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c @@ -32,6 +32,62 @@ out: } #endif +#if !defined(CONFIG_TPL_BUILD) && defined(CONFIG_SPL_BUILD) + +#include + +#define BUS_NUM 2 +#define ROC_RK3399_MEZZ_BAT_ADDR 0x62 + +enum roc_rk3399_pc_board_type { + ROC_RK3399_PC, /* roc-rk3399-pc base board */ + ROC_RK3399_MEZZ_M2_POE, /* roc-rk3399-Mezz M.2 PoE */ +}; + +int board_early_init_f(void) +{ + struct udevice *bus, *dev; + int ret; + + /* default board type */ + gd->board_type = ROC_RK3399_PC; + + ret = uclass_get_device_by_seq(UCLASS_I2C, BUS_NUM, &bus); + if (ret) { + debug("failed to get i2c bus 2\n"); + return ret; + } + + ret = dm_i2c_probe(bus, ROC_RK3399_MEZZ_BAT_ADDR, 0, &dev); + if (ret) { + debug("failed to probe i2c2 battery controller IC\n"); + return ret; + } + + gd->board_type = ROC_RK3399_MEZZ_M2_POE; + + return 0; +} + +#ifdef CONFIG_SPL_LOAD_FIT +int board_fit_config_name_match(const char *name) +{ + if (gd->board_type == ROC_RK3399_PC) { + if (!strcmp(name, "rk3399-roc-pc.dtb")) + return 0; + } + + if (gd->board_type == ROC_RK3399_MEZZ_M2_POE) { + if (!strcmp(name, "rk3399-roc-pc-mezzanine.dtb")) + return 0; + } + + return -EINVAL; +} +#endif + +#endif /* CONFIG_SPL_BUILD */ + #if defined(CONFIG_TPL_BUILD) #define GPIO0_BASE 0xff720000 diff --git a/configs/roc-pc-rk3399_defconfig b/configs/roc-pc-rk3399_defconfig index 4d1a077..e56fd3d 100644 --- a/configs/roc-pc-rk3399_defconfig +++ b/configs/roc-pc-rk3399_defconfig @@ -10,6 +10,7 @@ CONFIG_DEBUG_UART_CLOCK=24000000 CONFIG_DEBUG_UART=y CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-roc-pc.dtb" CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_BOARD_TYPES=y # CONFIG_SPL_RAW_IMAGE_SUPPORT is not set CONFIG_SPL_STACK_R=y CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x10000 @@ -25,6 +26,7 @@ CONFIG_CMD_USB=y CONFIG_CMD_TIME=y CONFIG_SPL_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="rk3399-roc-pc" +CONFIG_OF_LIST="rk3399-roc-pc rk3399-roc-pc-mezzanine" CONFIG_OF_SPL_REMOVE_PROPS="clock-names interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents" CONFIG_ENV_IS_IN_MMC=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y