All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery
@ 2019-11-17 10:17 Michael Trimarchi
  2019-11-18 11:25 ` Jagan Teki
  2019-11-19  0:39 ` Kever Yang
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Trimarchi @ 2019-11-17 10:17 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery
  2019-11-17 10:17 [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery Michael Trimarchi
@ 2019-11-18 11:25 ` Jagan Teki
  2019-11-18 12:02   ` Michael Nazzareno Trimarchi
  2019-11-18 21:36   ` Michael Trimarchi
  2019-11-19  0:39 ` Kever Yang
  1 sibling, 2 replies; 6+ messages in thread
From: Jagan Teki @ 2019-11-18 11:25 UTC (permalink / raw)
  To: u-boot

On Sun, Nov 17, 2019 at 3:47 PM Michael Trimarchi
<michael@amarulasolutions.com> wrote:
>
> 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>;
> +       };
> +

Need to move this into -u-boot.dtsi

>         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 */
> +               };
> +       };
> +

hog node is legacy representation, so we need to have a proper node to
define these.

>         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);

Mark this function as static.

> +
>  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);

I can see the output on my tinker as
Detect Tinker rev 2

But the back side of PCB show REV 1.2 any clue?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery
  2019-11-18 11:25 ` Jagan Teki
@ 2019-11-18 12:02   ` Michael Nazzareno Trimarchi
  2019-11-18 21:36   ` Michael Trimarchi
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Nazzareno Trimarchi @ 2019-11-18 12:02 UTC (permalink / raw)
  To: u-boot

Hi

On Mon, Nov 18, 2019 at 12:25 PM Jagan Teki <jagan@amarulasolutions.com> wrote:
>
> On Sun, Nov 17, 2019 at 3:47 PM Michael Trimarchi
> <michael@amarulasolutions.com> wrote:
> >
> > 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>;
> > +       };
> > +
>
> Need to move this into -u-boot.dtsi
>
> >         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 */
> > +               };
> > +       };
> > +
>
> hog node is legacy representation, so we need to have a proper node to
> define these.

This is not easy without create a driver. This is a way to make the
pinctrl work and used by other board too
>
> >         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,
> > +};
> > +


In the old code pcb version are those
> >  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);
>
> Mark this function as static.
>

Ok

> > +
> >  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);
>
> I can see the output on my tinker as
> Detect Tinker rev 2
>
> But the back side of PCB show REV 1.2 any clue?

Understand, I should ask to asus

Michael


-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery
  2019-11-18 11:25 ` Jagan Teki
  2019-11-18 12:02   ` Michael Nazzareno Trimarchi
@ 2019-11-18 21:36   ` Michael Trimarchi
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Trimarchi @ 2019-11-18 21:36 UTC (permalink / raw)
  To: u-boot

Hi

On Mon, Nov 18, 2019 at 04:55:02PM +0530, Jagan Teki wrote:
> On Sun, Nov 17, 2019 at 3:47 PM Michael Trimarchi
> <michael@amarulasolutions.com> wrote:
> >
> > 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

This is a way better

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery
  2019-11-17 10:17 [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery Michael Trimarchi
  2019-11-18 11:25 ` Jagan Teki
@ 2019-11-19  0:39 ` Kever Yang
  2019-11-19  7:01   ` Michael Nazzareno Trimarchi
  1 sibling, 1 reply; 6+ messages in thread
From: Kever Yang @ 2019-11-19  0:39 UTC (permalink / raw)
  To: u-boot


On 2019/11/17 下午6:17, Michael Trimarchi wrote:
> Add a way to detect board id and pcb id.


Is there a document for this from vendor? Are they also use these two ids?

If we can detect tinker vs tinker-s, then we don't need two board 
config/dts, right?

>
> 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>;

These three pin looks like not related to board detect?


Thanks,

- Kever

> +	};
> +
>   	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;
> +}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery
  2019-11-19  0:39 ` Kever Yang
@ 2019-11-19  7:01   ` Michael Nazzareno Trimarchi
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Nazzareno Trimarchi @ 2019-11-19  7:01 UTC (permalink / raw)
  To: u-boot

Hi Kever

On Tue, Nov 19, 2019 at 1:40 AM Kever Yang <kever.yang@rock-chips.com> wrote:
>
>
> On 2019/11/17 下午6:17, Michael Trimarchi wrote:
> > Add a way to detect board id and pcb id.
>
>
> Is there a document for this from vendor? Are they also use these two ids?
>
> If we can detect tinker vs tinker-s, then we don't need two board
> config/dts, right?
>

I'm working to test on some tinker board. I was having only tinker-s.
I prefer to have
both board support and then clean-up after I'm sure

> >
> > 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>;
>
> These three pin looks like not related to board detect?
>

I take from debian_uboot. I'm going to manage those pins and drop from
this patch

Michael

>
> Thanks,
>
> - Kever
>
> > +     };
> > +
> >       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;
> > +}
>
>


-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-19  7:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-17 10:17 [U-Boot] [RFC PATCH] rockchip: tinker: Add automatic board discovery Michael Trimarchi
2019-11-18 11:25 ` 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

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.