public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: sunil at amarulasolutions.com <sunil@amarulasolutions.com>
To: u-boot@lists.denx.de
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	[thread overview]
Message-ID: <1590170608-12229-4-git-send-email-sunil@amarulasolutions.com> (raw)
In-Reply-To: <1590170608-12229-1-git-send-email-sunil@amarulasolutions.com>

From: Suniel Mahesh <sunil@amarulasolutions.com>

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 <sunil@amarulasolutions.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
 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 <i2c.h>
+
+#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
-- 
2.7.4

  parent reply	other threads:[~2020-05-22 18:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22 18:03 [PATCH 0/5] Enable I2C in SPL, support runtime detection of add-on board sunil at amarulasolutions.com
2020-05-22 18:03 ` [PATCH 1/5] rockchip: spl: Move board_early_init_f after cpu timer sunil at amarulasolutions.com
2020-05-22 18:03 ` [PATCH 2/5] roc-pc-rk3399: Enable I2C in SPL for add-on board detection sunil at amarulasolutions.com
2020-05-22 18:03 ` sunil at amarulasolutions.com [this message]
2020-05-22 18:03 ` [PATCH 4/5] rk3399: drop ROC-RK3399-PC Mezzanine board sunil at amarulasolutions.com
2020-05-22 18:12   ` Jagan Teki
2020-05-22 18:03 ` [PATCH 5/5] roc-pc-rk3399: Enable PCIe/M.2, NVMe sunil at amarulasolutions.com
2020-05-22 18:13   ` Jagan Teki
2020-05-23  2:07 ` [PATCH 0/5] Enable I2C in SPL, support runtime detection of add-on board Chen-Yu Tsai
2020-05-29  9:54   ` Kever Yang
2020-05-29 11:06     ` Jagan Teki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1590170608-12229-4-git-send-email-sunil@amarulasolutions.com \
    --to=sunil@amarulasolutions.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox