Proof of concept device tree overlays
Subsystems (2)
cover Proof of concept device tree overlays
Hi all,
This is a kind request for comments with regard to the new feature that enables barebox to provide device tree overlays to the kernel.
The first patch adds support for the hardware id detection on the Rockchip RK3568 EVB. The voltage tresholds are taken from the EVB1 schematic.
The second patch applies a fictional device tree overlay (that is assumed to reside in rootfs/boot/) to the kernel for the EVB7.
Is this how you all envisaged the usage of this new feature? Or do you have any suggestions?
Thanks and best regards,
Michael
Michael Riesch (2):
arm: rockchip-rk3568-evb: add hardware id detection
arm: rockchip-rk3568-evb: apply dt overlay for evb7
arch/arm/boards/rockchip-rk3568-evb/board.c | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+)
--
2.20.1
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
RFC PATCH 1/2 arm: rockchip-rk3568-evb: add hardware id detection
--- arch/arm/boards/rockchip-rk3568-evb/board.c | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+)
arch/arm/boards/rockchip-rk3568-evb/board.c +36 -0
@@ -2,6 +2,7 @@#include <common.h> #include <init.h> #include <mach/bbu.h> +#include <aiodev.h> #include <bootsource.h> static int rk3568_evb_probe (struct device_d *dev)
@@ -34,3 +35,38 @@ static struct driver_d rk3568_evb_board_driver = { .of_compatible = rk3568_evb_of_match, };coredevice_platform_driver (rk3568_evb_board_driver); + +static int rk3568_evb_detect_version (void ) +{ +int ret =0 ; +int evb_hw_id =0 ; +int evb_hw_id_voltage =1800 ; +struct aiochannel *evb_hw_id_chan; + + evb_hw_id_chan =aiochannel_by_name ("aiodev0.in_value1_mV" ); +if (!IS_ERR (evb_hw_id_chan)) + ret =aiochannel_get_value (evb_hw_id_chan, &evb_hw_id_voltage); +if (ret ||IS_ERR (evb_hw_id_chan)) +pr_warn ("couldn't retrieve hardware ID" ); + +if (evb_hw_id_voltage >1650 ) { + evb_hw_id =1 ; + }else if (evb_hw_id_voltage >1350 ) { + evb_hw_id =2 ; + }else if (evb_hw_id_voltage >1050 ) { + evb_hw_id =3 ; + }else if (evb_hw_id_voltage >750 ) { + evb_hw_id =4 ; + }else if (evb_hw_id_voltage >450 ) { + evb_hw_id =5 ; + }else if (evb_hw_id_voltage >150 ) { + evb_hw_id =6 ; + }else { + evb_hw_id =7 ; + } + +pr_info ("Detected RK3568 EVB%d\n" , evb_hw_id); + +return 0 ; +} +late_initcall (rk3568_evb_detect_version);
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC PATCH 1/2] arm: rockchip-rk3568-evb: add hardware id detection
Hello Michael,
Trent already commented on the device tree overlay part. This commit here seems applicable regardless, so in case you want to resend it for upstream inclusion, some comments are inline.
Quoted 1 line · Michael Riesch
Signed-off-by Michael Riesch <[email protected]>
A short commit message here would be nice, e.g.:
The rk3568 EVB uses a voltage divider to ... etc.
Quoted 17 lines
--- arch/arm/boards/rockchip-rk3568-evb/board.c | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+)arch/arm/boards/rockchip-rk3568-evb/board.c +1
-0@@ -2,6 +2,7 @@#include <common.h> #include <init.h> #include <mach/bbu.h> +#include <aiodev.h> #include <bootsource.h> static int rk3568_evb_probe (struct device_d *dev)
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 40
Quoted 6 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +3
-0@@ -34,3 +35,38 @@ static struct driver_d rk3568_evb_board_driver = { .of_compatible = rk3568_evb_of_match, };coredevice_platform_driver (rk3568_evb_board_driver); + +static int rk3568_evb_detect_version (void ) +{
Once more 64-bit rockchip boards are added, they would all execute this initcall if this board is enabled. For this reason, you need a compatible check here.
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 42
Quoted 2 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +2
-0+int ret =0 ; +int evb_hw_id =0 ;
Nitpick: Initializing variables with values that are never read risks introducing silent bugs once the code that uses it later on changes. If you leave it uninitialized you get a compiler warning if it's referenced without initialization.
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 43
Quoted 1 line
arch/arm/boards/rockchip-rk3568-evb/board.c +1
-0+int evb_hw_id_voltage =1800 ;
I am not sure it's a good idea to report the EVB is v1 when the driver isn't enabled.
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 47
Quoted 4 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +4
-0+struct aiochannel *evb_hw_id_chan; + + evb_hw_id_chan =aiochannel_by_name ("aiodev0.in_value1_mV" ); +if (!IS_ERR (evb_hw_id_chan))
In the error case it makes no sense to continue here, you should early exit.
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 50
Quoted 3 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +3
-0+ ret =aiochannel_get_value (evb_hw_id_chan, &evb_hw_id_voltage); +if (ret ||IS_ERR (evb_hw_id_chan)) +pr_warn ("couldn't retrieve hardware ID" );
early exit
Quoted 8 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +8
-0+ +if (evb_hw_id_voltage >1650 ) { + evb_hw_id =1 ; + }else if (evb_hw_id_voltage >1350 ) { + evb_hw_id =2 ; + }else if (evb_hw_id_voltage >1050 ) { + evb_hw_id =3 ; + }else if (evb_hw_id_voltage >750 ) {
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 68
Quoted 10 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +10
-0+ evb_hw_id =4 ; + }else if (evb_hw_id_voltage >450 ) { + evb_hw_id =5 ; + }else if (evb_hw_id_voltage >150 ) { + evb_hw_id =6 ; + }else { + evb_hw_id =7 ; + } + +pr_info ("Detected RK3568 EVB%d\n" , evb_hw_id);
You could populate a variable, e.g. global.board.revision here. That would allow using this info in scripts as Trent has described.
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 72
Quoted 4 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +4
-0+ +return 0 ; +} +late_initcall (rk3568_evb_detect_version);
Optimally, you would call the function from the board driver probe above. At postcore initcall, you wouldn't find the ADC yet, but if you return EPROBE_DEFER on error from the probe, the probe will be retried later on at which time it will succeed.
With the deep probe patches Sascha just merged, it is possible to directly probe dependencies instead of retrying later and hoping it was probed in-between. It's still not enabled for the EVB here though and it also needs some code added to aiodev, so for now you could go the EPROBE_DEFER route (or add a compatible check).
Cheers,
Ahmad
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC PATCH 1/2] arm: rockchip-rk3568-evb: add hardware id detection
Hello Ahmad,
Quoted 6 lines · Ahmad Fatoum
Hello Michael,
Trent already commented on the device tree overlay part. This commit here seems applicable regardless, so in case you want to resend it for upstream inclusion, some comments are inline.
Thanks for your feedback. OK, I'll separate this part and resend a non-RFC patch (not sure when, though).
Quoted 43 lines · Michael Riesch
Quoted 1 line
Signed-off-by Michael Riesch <[email protected]>A short commit message here would be nice, e.g.:
The rk3568 EVB uses a voltage divider to ... etc.
Quoted 17 lines
--- arch/arm/boards/rockchip-rk3568-evb/board.c | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+)arch/arm/boards/rockchip-rk3568-evb/board.c +1
-0@@ -2,6 +2,7 @@#include <common.h> #include <init.h> #include <mach/bbu.h> +#include <aiodev.h> #include <bootsource.h> static int rk3568_evb_probe (struct device_d *dev)arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 40
Quoted 6 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +3
-0@@ -34,3 +35,38 @@ static struct driver_d rk3568_evb_board_driver = { .of_compatible = rk3568_evb_of_match, };coredevice_platform_driver (rk3568_evb_board_driver); + +static int rk3568_evb_detect_version (void ) +{Once more 64-bit rockchip boards are added, they would all execute this initcall if this board is enabled. For this reason, you need a compatible check here.
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 42
Quoted 2 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +2
-0+int ret =0 ; +int evb_hw_id =0 ;Nitpick: Initializing variables with values that are never read risks introducing silent bugs once the code that uses it later on changes. If you leave it uninitialized you get a compiler warning if it's referenced without initialization.
Quoted 4 lines
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 43
Quoted 1 line
arch/arm/boards/rockchip-rk3568-evb/board.c +1
-0+int evb_hw_id_voltage =1800 ;I am not sure it's a good idea to report the EVB is v1 when the driver isn't enabled.
This default is based on the assumption that the EVB1 device tree works for all variants and does not require any overlays. The other variants do require a specific overlay. This assumption was somewhat valid in the scope of this RFC patch series but cannot be applied in general...
Quoted 27 lines
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 47
Quoted 5 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +4
-0+struct aiochannel *evb_hw_id_chan; + + evb_hw_id_chan =aiochannel_by_name ("aiodev0.in_value1_mV" ); +if (!IS_ERR (evb_hw_id_chan))In the error case it makes no sense to continue here, you should early exit.
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 50
Quoted 3 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +3
-0+ ret =aiochannel_get_value (evb_hw_id_chan, &evb_hw_id_voltage); +if (ret ||IS_ERR (evb_hw_id_chan)) +pr_warn ("couldn't retrieve hardware ID" );early exit
Quoted 13 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +13
-0+ +if (evb_hw_id_voltage >1650 ) { + evb_hw_id =1 ; + }else if (evb_hw_id_voltage >1350 ) { + evb_hw_id =2 ; + }else if (evb_hw_id_voltage >1050 ) { + evb_hw_id =3 ; + }else if (evb_hw_id_voltage >750 ) { + evb_hw_id =4 ; + }else if (evb_hw_id_voltage >450 ) { + evb_hw_id =5 ; + }else if (evb_hw_id_voltage >150 ) { + evb_hw_id =6 ;
Quoted 8 lines
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 68
Quoted 5 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +5
-0+ }else { + evb_hw_id =7 ; + } + +pr_info ("Detected RK3568 EVB%d\n" , evb_hw_id);You could populate a variable, e.g. global.board.revision here. That would allow using this info in scripts as Trent has described.
... so what should happen if the board variant cannot be detected? Should the variable be empty? Not set at all? Set to "unknown"?
Quoted 10 lines
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 72
Quoted 4 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +4
-0+ +return 0 ; +} +late_initcall (rk3568_evb_detect_version);Optimally, you would call the function from the board driver probe above. At postcore initcall, you wouldn't find the ADC yet, but if you return
EPROBE_DEFERon error from the probe, the probe will be retried later on at which time it will succeed.
Quoted 5 lines
With the deep probe patches Sascha just merged, it is possible to directly probe dependencies instead of retrying later and hoping it was probed in-between. It's still not enabled for the EVB here though and it also needs some code added to aiodev, so for now you could go the
EPROBE_DEFERroute (or add a compatible check).
I think I'll stick to the late_initcall with compatible check as this seems to be the most straightforward solution right now.
Regards,
Michael
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC PATCH 1/2] arm: rockchip-rk3568-evb: add hardware id detection
In reply to Ahmad FatoumQuoted 30 lines · Ahmad Fatoum
Hello Michael,
Trent already commented on the device tree overlay part. This commit here seems applicable regardless, so in case you want to resend it for upstream inclusion, some comments are inline.
Quoted 1 line · Michael Riesch
Signed-off-by Michael Riesch <[email protected]>A short commit message here would be nice, e.g.:
The rk3568 EVB uses a voltage divider to ... etc.
Quoted 15 lines
--- arch/arm/boards/rockchip-rk3568-evb/board.c | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+)arch/arm/boards/rockchip-rk3568-evb/board.c +1
-0@@ -2,6 +2,7 @@#include <common.h> #include <init.h> #include <mach/bbu.h> +#include <aiodev.h> #include <bootsource.h>
Quoted 12 lines
arch/arm/boards/rockchip-rk3568-evb/board.c static struct driver_d rk3568_evb_board_driver = { · line 40
Quoted 8 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +3
-0static int rk3568_evb_probe (struct device_d *dev)@@ -34,3 +35,38 @@ static struct driver_d rk3568_evb_board_driver = { .of_compatible = rk3568_evb_of_match, };coredevice_platform_driver (rk3568_evb_board_driver); + +static int rk3568_evb_detect_version (void ) +{Once more 64-bit rockchip boards are added, they would all execute this initcall if this board is enabled. For this reason, you need a compatible check here.
Instead of a compatible check I'd prefer a
static bool machine_is_rk3568_evb;
Set it to true in the driver above and test for it in additional initcalls.
Testing for a variable is cheaper in terms of binary size and runtime penalty than compatible checks.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC PATCH 2/2 arm: rockchip-rk3568-evb: apply dt overlay for evb7
In reply to Michael Riesch--- arch/arm/boards/rockchip-rk3568-evb/board.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/boards/rockchip-rk3568-evb/board.c +4 -0
@@ -4,6 +4,7 @@#include <mach/bbu.h> #include <aiodev.h> #include <bootsource.h> +#include <environment.h> static int rk3568_evb_probe (struct device_d *dev) {
@@ -63,6 +64,9 @@ static int rk3568_evb_detect_version(void) evb_hw_id =6 ; }else { evb_hw_id =7 ; +setenv ("global.of.overlay.dir" ,"boot" ); +setenv ("global.of.overlay.filepattern" , +"rk3568-evb7-overlay.dtb*" ); }pr_info ("Detected RK3568 EVB%d\n" , evb_hw_id);
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC PATCH 2/2] arm: rockchip-rk3568-evb: apply dt overlay for evb7
arch/arm/boards/rockchip-rk3568-evb/board.c static int rk3568_evb_detect_version(void) · line 67
Quoted 5 lines · Michael Riesch
arch/arm/boards/rockchip-rk3568-evb/board.c +1
-0@@ -63,6 +64,9 @@ static int rk3568_evb_detect_version(void) evb_hw_id =6 ; }else { evb_hw_id =7 ; +setenv ("global.of.overlay.dir" ,"boot" );
Hardcoding the location of boot files in the rootfs into board code doesn't seem right to me.
Seems like either creating a nv/global.of.overlay.dir file in the default env for the board or creating an init script that sets that variable would be the way to set this.
arch/arm/boards/rockchip-rk3568-evb/board.c static int rk3568_evb_detect_version(void) · line 69
Quoted 2 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +2
-0+setenv ("global.of.overlay.filepattern" , +"rk3568-evb7-overlay.dtb*" );
What if one had a board magicvar, something like:
globalvar_add_simple("board.variant", "rk3568-evb7"); // Or just evb7 if rk3568 is already somewhere else BAREBOX_MAGICVAR(global.board.variant, "The board variant");
Then an init script could easily construct the overlay:
env/init/board-overlay:
global of.overlay.filepattern="${global.of.overlay.filepattern} ${global.board.variant}-overlay.dtbo"
Since every overlay file is added to the same variable, some care needs to be taken to ensure different initscripts work together. Thus the append in the above script.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC PATCH 2/2] arm: rockchip-rk3568-evb: apply dt overlay for evb7
Hello Trent,
Thanks for your comments, much appreciated!
Quoted 11 lines · Trent Piepho
arch/arm/boards/rockchip-rk3568-evb/board.c static int rk3568_evb_detect_version(void) · line 67
Quoted 5 lines · Michael Riesch
arch/arm/boards/rockchip-rk3568-evb/board.c +1
-0@@ -63,6 +64,9 @@ static int rk3568_evb_detect_version(void) evb_hw_id =6 ; }else { evb_hw_id =7 ; +setenv ("global.of.overlay.dir" ,"boot" );Hardcoding the location of boot files in the rootfs into board code doesn't seem right to me.
Quoted 3 lines
Seems like either creating a nv/global.of.overlay.dir file in the default env for the board or creating an init script that sets that variable would be the way to set this.
Right, this approach seems to be more flexible.
Quoted 11 lines
arch/arm/boards/rockchip-rk3568-evb/board.c static int rk3568_evb_detect_version(void) · line 69
Quoted 2 lines
arch/arm/boards/rockchip-rk3568-evb/board.c +2
-0+setenv ("global.of.overlay.filepattern" , +"rk3568-evb7-overlay.dtb*" );What if one had a board magicvar, something like:
globalvar_add_simple("board.variant", "rk3568-evb7"); // Or just evb7 if rk3568 is already somewhere elseBAREBOX_MAGICVAR(global.board.variant, "The board variant");Then an init script could easily construct the overlay:
Quoted 7 lines
env/init/board-overlay:
global of.overlay.filepattern="${global.of.overlay.filepattern} ${global.board.variant}-overlay.dtbo"Since every overlay file is added to the same variable, some care needs to be taken to ensure different initscripts work together. Thus the append in the above script.
Thanks for the hint, I think I'll go along this direction.
Regards, Michael
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox