All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Trimarchi <michael@amarulasolutions.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery
Date: Sun, 17 Nov 2019 11:17:02 +0100	[thread overview]
Message-ID: <20191117101702.14783-1-michael@amarulasolutions.com> (raw)

Add a way to detect board id and pcb id.

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
 arch/arm/dts/rk3288-tinker.dtsi              | 33 ++++++++
 board/rockchip/tinker_rk3288/tinker-rk3288.c | 83 ++++++++++++++++++++
 2 files changed, 116 insertions(+)

diff --git a/arch/arm/dts/rk3288-tinker.dtsi b/arch/arm/dts/rk3288-tinker.dtsi
index 2f816af47f..67a0374050 100644
--- a/arch/arm/dts/rk3288-tinker.dtsi
+++ b/arch/arm/dts/rk3288-tinker.dtsi
@@ -53,6 +53,21 @@
 		#clock-cells = <0>;
 	};
 
+	board_info: board-info {
+		tinker,pcbid0 = <&gpio2 8 GPIO_ACTIVE_HIGH>;
+		tinker,pcbid1 = <&gpio2 9 GPIO_ACTIVE_HIGH>;
+		tinker,pcbid2 = <&gpio2 10 GPIO_ACTIVE_HIGH>;
+		tinker,pid0 = <&gpio2 1 GPIO_ACTIVE_HIGH>;
+		tinker,pid1 = <&gpio2 2 GPIO_ACTIVE_HIGH>;
+		tinker,pid2 = <&gpio2 3 GPIO_ACTIVE_HIGH>;
+	};
+
+	board_control: board-control {
+		tinker,sdp = <&gpio6 5 GPIO_ACTIVE_HIGH>;
+		tinker,usblimit = <&gpio6 6 GPIO_ACTIVE_HIGH>;
+		tinker,maskemmc = <&gpio6 7 GPIO_ACTIVE_HIGH>;
+	};
+
 	gpio-keys {
 		compatible = "gpio-keys";
 		autorepeat;
@@ -461,6 +476,10 @@
 };
 
 &pinctrl {
+	/* Pins that are not explicitely used by any devices */
+	pinctrl-names = "default";
+	pinctrl-0 = <&tinker_pin_hog>;
+
 	pcfg_pull_none_drv_8ma: pcfg-pull-none-drv-8ma {
 		drive-strength = <8>;
 	};
@@ -482,6 +501,20 @@
 		};
 	};
 
+	hog {
+		tinker_pin_hog: tinker-pin-hog {
+			rockchip,pins = <2 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>, /* project id 0 */
+					<2 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>, /* project id 1 */
+					<2 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>, /* project id 2 */
+					<2 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>, /* pcb id 0 */
+					<2 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>, /* pcb id 1 */
+					<2 RK_PB2 RK_FUNC_GPIO &pcfg_pull_none>, /* pcb id 2 */
+					<6 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>, /* sdp detect */
+					<6 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>, /* current limit */
+					<6 RK_PA7 RK_FUNC_GPIO &pcfg_pull_none>; /* emmc mask */
+		};
+	};
+
 	eth_phy {
 		eth_phy_pwr: eth-phy-pwr {
 			rockchip,pins = <0 6 RK_FUNC_GPIO &pcfg_pull_none>;
diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c b/board/rockchip/tinker_rk3288/tinker-rk3288.c
index 7a0c3c997d..7c65521f55 100644
--- a/board/rockchip/tinker_rk3288/tinker-rk3288.c
+++ b/board/rockchip/tinker_rk3288/tinker-rk3288.c
@@ -5,12 +5,26 @@
 
 #include <common.h>
 #include <dm.h>
+#include <dm/device-internal.h>
+#include <asm/gpio.h>
+#include <dt-bindings/pinctrl/rockchip.h>
 #include <env.h>
 #include <i2c_eeprom.h>
 #include <netdev.h>
 #include <asm/arch-rockchip/bootrom.h>
 #include <asm/io.h>
 
+enum project_id {
+	tinker_board_s = 0,
+	tinker_board = 7,
+};
+
+enum pcb_id {
+	SR,
+	ER,
+	PR,
+};
+
 static int get_ethaddr_from_eeprom(u8 *addr)
 {
 	int ret;
@@ -23,10 +37,14 @@ static int get_ethaddr_from_eeprom(u8 *addr)
 	return i2c_eeprom_read(dev, 0, addr, 6);
 }
 
+int detect_board_init(void);
+
 int rk3288_board_late_init(void)
 {
 	u8 ethaddr[6];
 
+	detect_board_init();
+
 	if (get_ethaddr_from_eeprom(ethaddr))
 		return 0;
 
@@ -45,3 +63,68 @@ int mmc_get_env_dev(void)
 
 	return 1;
 }
+
+int detect_board_init(void)
+{
+	int ret = 0, i;
+	ofnode node;
+	struct udevice *gpio_dev2 = NULL;
+	struct udevice *gpio_dev6 = NULL;
+	struct gpio_desc pcbid[3];
+	struct gpio_desc pid[3];
+	enum project_id prjid;
+	char gpio_name[64];
+	enum pcb_id pcbversion;
+
+	debug("%s: detect boad\n", __func__);
+
+	if (uclass_get_device_by_name(UCLASS_GPIO, "gpio2 at ff790000", &gpio_dev2) ||
+	    uclass_get_device_by_name(UCLASS_GPIO, "gpio6 at ff7d0000", &gpio_dev6)) {
+		printf("Could not get GPIO device.\n");
+		return -EINVAL;
+	}
+
+	ret = device_probe(gpio_dev2);
+	if (ret)
+		pr_err("%s - probe failed: %d\n", gpio_dev2->name, ret);
+
+	ret = device_probe(gpio_dev6);
+	if (ret)
+		pr_err("%s - probe failed: %d\n", gpio_dev6->name, ret);
+
+	node = ofnode_path("/board-info");
+	if (!ofnode_valid(node)) {
+		pr_err("%s: no /board-info node?\n", __func__);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < 3; i++) {
+		snprintf(gpio_name, 64, "tinker,pid%d", i);
+		if (gpio_request_by_name_nodev(node, gpio_name, 0,
+					&pid[i], GPIOD_IS_IN)) {
+			printf("Failed to request %s\n", gpio_name);
+			continue;
+		}
+        }
+
+	for (i = 0; i < 3; i++) {
+		snprintf(gpio_name, 64, "tinker,pcbid%d", i);
+		if (gpio_request_by_name_nodev(node, gpio_name, 0,
+						&pcbid[i], GPIOD_IS_IN)) {
+			printf("Failed to request %s\n", gpio_name);
+			continue;
+		}
+        }
+
+	prjid = dm_gpio_get_value(&pid[0]) | \
+		dm_gpio_get_value(&pid[1]) << 1 | \
+		dm_gpio_get_value(&pid[2]) << 2;
+	pcbversion = dm_gpio_get_value(&pcbid[0]) | \
+		dm_gpio_get_value(&pcbid[1]) << 1 | \
+		dm_gpio_get_value(&pcbid[2]) << 2;
+
+	printf("Detect %s rev %d\n",
+		prjid == tinker_board ? "Tinker" : "Tinker S", pcbversion);
+
+	return ret;
+}
-- 
2.17.1

             reply	other threads:[~2019-11-17 10:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-17 10:17 Michael Trimarchi [this message]
2019-11-18 11:25 ` [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery Jagan Teki
2019-11-18 12:02   ` Michael Nazzareno Trimarchi
2019-11-18 21:36   ` Michael Trimarchi
2019-11-19  0:39 ` Kever Yang
2019-11-19  7:01   ` Michael Nazzareno Trimarchi

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=20191117101702.14783-1-michael@amarulasolutions.com \
    --to=michael@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.