On Sun, Nov 17, 2019 at 3:47 PM Michael Trimarchi
<mich...@amarulasolutions.com> wrote:
>
> Add a way to detect board id and pcb id.
>
> Signed-off-by: Michael Trimarchi <mich...@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@ff790000", 
> &gpio_dev2) ||
> +           uclass_get_device_by_name(UCLASS_GPIO, "gpio6@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?
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to