rockchip: tinker: Add automatic board discovery
Subsystems (2)
RFC PATCH 1/1 rockchip: tinker: Add automatic board discovery
Add a way to detect board id and pcb id.
--- arch/arm/dts/rk3288-tinker.dtsi | 33 ++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 83 ++++++++++++++++++++ 2 files changed, 116 insertions(+)
arch/arm/dts/rk3288-tinker.dtsi +33 -0
@@ -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>;
board/rockchip/tinker_rk3288/tinker-rk3288.c +83 -0
108 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 1/1 rockchip: tinker: Add automatic board discovery
Quoted 22 lines · Michael Trimarchi
Add a way to detect board id and pcb id.
Signed-off-by Michael Trimarchi <[email protected]>--- arch/arm/dts/rk3288-tinker.dtsi | 33 ++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 83 ++++++++++++++++++++ 2 files changed, 116 insertions(+)arch/arm/dts/rk3288-tinker.dtsi +5
-0@@ -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>;
arch/arm/dts/rk3288-tinker.dtsi line 70
Quoted 10 lines
arch/arm/dts/rk3288-tinker.dtsi +10
-0+ 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
Quoted 22 lines
arch/arm/dts/rk3288-tinker.dtsi +8
-0gpio-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 */
arch/arm/dts/rk3288-tinker.dtsi line 517
Quoted 10 lines
arch/arm/dts/rk3288-tinker.dtsi +10
-0+ <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.
Quoted 35 lines
arch/arm/dts/rk3288-tinker.dtsi +0
-0eth_phy { eth_phy_pwr: eth-phy-pwr { rockchip,pins = <0 6 RK_FUNC_GPIO &pcfg_pull_none>;board/rockchip/tinker_rk3288/tinker-rk3288.c +14
-0@@ -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;
board/rockchip/tinker_rk3288/tinker-rk3288.c static int get_ethaddr_from_eeprom(u8 *addr) · line 40
Quoted 4 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c +1
-0@@ -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.
Quoted 66 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c +55
-0+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 ; + } + }
board/rockchip/tinker_rk3288/tinker-rk3288.c int mmc_get_env_dev(void) · line 127
Quoted 10 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c +10
-0+ + 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?
RFC PATCH 1/1 rockchip: tinker: Add automatic board discovery
Hi
Quoted 65 lines · Jagan Teki
Quoted 22 lines · Michael Trimarchi
Add a way to detect board id and pcb id.
Signed-off-by Michael Trimarchi <[email protected]>--- arch/arm/dts/rk3288-tinker.dtsi | 33 ++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 83 ++++++++++++++++++++ 2 files changed, 116 insertions(+)arch/arm/dts/rk3288-tinker.dtsi +5
-0@@ -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>;arch/arm/dts/rk3288-tinker.dtsi line 70
Quoted 10 lines
arch/arm/dts/rk3288-tinker.dtsi +10
-0+ 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.dtsiQuoted 27 lines
arch/arm/dts/rk3288-tinker.dtsi +13
-0gpio-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 */
Quoted 8 lines
arch/arm/dts/rk3288-tinker.dtsi line 517
Quoted 5 lines
arch/arm/dts/rk3288-tinker.dtsi +5
-0+ <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
Quoted 21 lines
Quoted 21 lines
arch/arm/dts/rk3288-tinker.dtsi +0
-0eth_phy { eth_phy_pwr: eth-phy-pwr { rockchip,pins = <0 6 RK_FUNC_GPIO &pcfg_pull_none>;board/rockchip/tinker_rk3288/tinker-rk3288.c +3
-0@@ -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>
Quoted 11 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c line 27
Quoted 11 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c +11
-0+enum project_id { + tinker_board_s =0 , + tinker_board =7 , +}; + +enum pcb_id { +SR , +ER , +PR , +}; +
In the old code pcb version are those
Quoted 11 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c static int get_ethaddr_from_eeprom(u8 *addr) · line 40
Quoted 8 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c +1
-0static 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
Quoted 80 lines
Quoted 66 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c +55
-0+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 ; + } + }board/rockchip/tinker_rk3288/tinker-rk3288.c int mmc_get_env_dev(void) · line 127
Quoted 10 lines
board/rockchip/tinker_rk3288/tinker-rk3288.c +10
-0+ + 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
Quoted 1 line
But the back side of PCB show REV 1.2 any clue?
Understand, I should ask to asus
Michael
Signature · 4 lines
| Michael Nazzareno Trimarchi Amarula Solutions BV | | COO - Founder Cruquiuskade 47 | | +31(0)851119172 Amsterdam 1018 AM NL | | [`as] http://www.amarulasolutions.com |
RFC PATCH 1/1 rockchip: tinker: Add automatic board discovery
In reply to Jagan TekiHi
Quoted 5 lines · Jagan Teki
Quoted 3 lines · Michael Trimarchi
Add a way to detect board id and pcb id.
Quoted 7 lines
arch/arm/dts/rk3288-tinker.dtsi
Quoted 7 lines
Signed-off-by Michael Trimarchi <[email protected]>--- arch/arm/dts/rk3288-tinker.dtsi | 33 ++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 83 ++++++++++++++++++++ 2 files changed, 116 insertions(+)arch/arm/dts/rk3288-tinker.dtsi +0
-0
This is a way better
RFC PATCH 1/1 rockchip: tinker: Add automatic board discovery
In reply to Michael TrimarchiQuoted 1 line · Michael Trimarchi
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?
Quoted 18 lines
Signed-off-by Michael Trimarchi <[email protected]>--- arch/arm/dts/rk3288-tinker.dtsi | 33 ++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 83 ++++++++++++++++++++ 2 files changed, 116 insertions(+)arch/arm/dts/rk3288-tinker.dtsi +3
-0@@ -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>;
arch/arm/dts/rk3288-tinker.dtsi line 68
Quoted 10 lines
arch/arm/dts/rk3288-tinker.dtsi +10
-0+ 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
Quoted 152 lines
arch/arm/dts/rk3288-tinker.dtsi +20
-0+ }; + 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>;board/rockchip/tinker_rk3288/tinker-rk3288.c +83
-0@@ -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; +}
RFC PATCH 1/1 rockchip: tinker: Add automatic board discovery
Hi Kever
Quoted 11 lines · Kever Yang
Quoted 1 line · Michael Trimarchi
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
Quoted 15 lines
Quoted 15 lines
Signed-off-by Michael Trimarchi <[email protected]>--- arch/arm/dts/rk3288-tinker.dtsi | 33 ++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 83 ++++++++++++++++++++ 2 files changed, 116 insertions(+)arch/arm/dts/rk3288-tinker.dtsi +0
-0@@ -53,6 +53,21 @@ #clock-cells = <0>; };
Quoted 16 lines
arch/arm/dts/rk3288-tinker.dtsi line 68
Quoted 13 lines
arch/arm/dts/rk3288-tinker.dtsi +13
-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
Quoted 159 lines
Thanks,
- Kever
Quoted 152 lines
arch/arm/dts/rk3288-tinker.dtsi +20
-0+ }; + 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>;board/rockchip/tinker_rk3288/tinker-rk3288.c +83
-0@@ -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; +}
Signature · 4 lines
| Michael Nazzareno Trimarchi Amarula Solutions BV | | COO - Founder Cruquiuskade 47 | | +31(0)851119172 Amsterdam 1018 AM NL | | [`as] http://www.amarulasolutions.com |