* [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection
@ 2021-07-05 16:04 Michael Riesch
2021-07-05 17:18 ` [PATCH] fixup! " Ahmad Fatoum
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Michael Riesch @ 2021-07-05 16:04 UTC (permalink / raw)
To: barebox; +Cc: Michael Riesch
The RK3568 EVB uses a voltage divider to determine the hardware ID of
the board. At the moment, the voltage levels for seven EVB variants are
defined. This commit adds a late_initcall to the board code that reads
out the voltage and populates the hardware ID as environment variable.
Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
---
v2:
- add compatible check
- return early in case the voltage cannot be read
- populate hardware ID as environment variable
arch/arm/boards/rockchip-rk3568-evb/board.c | 56 +++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
index 57c24ed3c..f8b257e57 100644
--- a/arch/arm/boards/rockchip-rk3568-evb/board.c
+++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
@@ -2,7 +2,13 @@
#include <common.h>
#include <init.h>
#include <mach/bbu.h>
+#include <aiodev.h>
#include <bootsource.h>
+#include <environment.h>
+#include <globalvar.h>
+#include <magicvar.h>
+
+static bool machine_is_rk3568_evb = false;
static int rk3568_evb_probe(struct device_d *dev)
{
@@ -11,6 +17,7 @@ static int rk3568_evb_probe(struct device_d *dev)
barebox_set_model("Rockchip RK3568 EVB");
barebox_set_hostname("rk3568-evb");
+ machine_is_rk3568_evb = true;
if (bootsource == BOOTSOURCE_MMC && instance == 1)
of_device_enable_path("/chosen/environment-sd");
@@ -34,3 +41,52 @@ 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_hwid(void)
+{
+ int ret;
+ int evb_hwid_voltage;
+ struct aiochannel *evb_hwid_chan;
+ char *evb_hwid;
+
+ if (!machine_is_rk3568_evb)
+ return 0;
+
+ evb_hwid_chan = aiochannel_by_name("aiodev0.in_value1_mV");
+ if (IS_ERR(evb_hwid_chan)) {
+ ret = PTR_ERR(evb_hwid_chan);
+ goto err_hwid;
+ }
+
+ ret = aiochannel_get_value(evb_hwid_chan, &evb_hwid_voltage);
+ if (ret)
+ goto err_hwid;
+
+ if (evb_hwid_voltage > 1650) {
+ evb_hwid = "1";
+ } else if (evb_hwid_voltage > 1350) {
+ evb_hwid = "2";
+ } else if (evb_hwid_voltage > 1050) {
+ evb_hwid = "3";
+ } else if (evb_hwid_voltage > 750) {
+ evb_hwid = "4";
+ } else if (evb_hwid_voltage > 450) {
+ evb_hwid = "5";
+ } else if (evb_hwid_voltage > 150) {
+ evb_hwid = "6";
+ } else {
+ evb_hwid = "7";
+ }
+ pr_info("Detected RK3568 EVB%s\n", evb_hwid);
+
+ globalvar_add_simple("board.hwid", evb_hwid);
+
+ return 0;
+
+err_hwid:
+ pr_err("couldn't retrieve hardware ID");
+ return ret;
+}
+late_initcall(rk3568_evb_detect_hwid);
+
+BAREBOX_MAGICVAR(global.board.hwid, "The board hardware ID");
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] fixup! arm: rockchip-rk3568-evb: add hardware id detection
2021-07-05 16:04 [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection Michael Riesch
@ 2021-07-05 17:18 ` Ahmad Fatoum
2021-07-05 17:18 ` [PATCH v2] " Ahmad Fatoum
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2021-07-05 17:18 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Ensure the pr_err below has a nice prefix, so users have some context
about the error message without having to consult the source code.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/boards/rockchip-rk3568-evb/board.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
index f8b257e5737c..35f2a2916133 100644
--- a/arch/arm/boards/rockchip-rk3568-evb/board.c
+++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) "rk3568-evb: " fmt
+
#include <common.h>
#include <init.h>
#include <mach/bbu.h>
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection
2021-07-05 16:04 [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection Michael Riesch
2021-07-05 17:18 ` [PATCH] fixup! " Ahmad Fatoum
@ 2021-07-05 17:18 ` Ahmad Fatoum
2021-08-09 18:51 ` Sascha Hauer
2021-08-23 14:11 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2021-07-05 17:18 UTC (permalink / raw)
To: Michael Riesch, barebox
On 05.07.21 18:04, Michael Riesch wrote:
> The RK3568 EVB uses a voltage divider to determine the hardware ID of
> the board. At the moment, the voltage levels for seven EVB variants are
> defined. This commit adds a late_initcall to the board code that reads
> out the voltage and populates the hardware ID as environment variable.
>
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
I just sent out a fixup that Sascha can squash if both patches
are ok with him.
> ---
> v2:
> - add compatible check
> - return early in case the voltage cannot be read
> - populate hardware ID as environment variable
>
> arch/arm/boards/rockchip-rk3568-evb/board.c | 56 +++++++++++++++++++++
> 1 file changed, 56 insertions(+)
>
> diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
> index 57c24ed3c..f8b257e57 100644
> --- a/arch/arm/boards/rockchip-rk3568-evb/board.c
> +++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
> @@ -2,7 +2,13 @@
> #include <common.h>
> #include <init.h>
> #include <mach/bbu.h>
> +#include <aiodev.h>
> #include <bootsource.h>
> +#include <environment.h>
> +#include <globalvar.h>
> +#include <magicvar.h>
> +
> +static bool machine_is_rk3568_evb = false;
>
> static int rk3568_evb_probe(struct device_d *dev)
> {
> @@ -11,6 +17,7 @@ static int rk3568_evb_probe(struct device_d *dev)
>
> barebox_set_model("Rockchip RK3568 EVB");
> barebox_set_hostname("rk3568-evb");
> + machine_is_rk3568_evb = true;
>
> if (bootsource == BOOTSOURCE_MMC && instance == 1)
> of_device_enable_path("/chosen/environment-sd");
> @@ -34,3 +41,52 @@ 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_hwid(void)
> +{
> + int ret;
> + int evb_hwid_voltage;
> + struct aiochannel *evb_hwid_chan;
> + char *evb_hwid;
> +
> + if (!machine_is_rk3568_evb)
> + return 0;
> +
> + evb_hwid_chan = aiochannel_by_name("aiodev0.in_value1_mV");
> + if (IS_ERR(evb_hwid_chan)) {
> + ret = PTR_ERR(evb_hwid_chan);
> + goto err_hwid;
> + }
> +
> + ret = aiochannel_get_value(evb_hwid_chan, &evb_hwid_voltage);
> + if (ret)
> + goto err_hwid;
> +
> + if (evb_hwid_voltage > 1650) {
> + evb_hwid = "1";
> + } else if (evb_hwid_voltage > 1350) {
> + evb_hwid = "2";
> + } else if (evb_hwid_voltage > 1050) {
> + evb_hwid = "3";
> + } else if (evb_hwid_voltage > 750) {
> + evb_hwid = "4";
> + } else if (evb_hwid_voltage > 450) {
> + evb_hwid = "5";
> + } else if (evb_hwid_voltage > 150) {
> + evb_hwid = "6";
> + } else {
> + evb_hwid = "7";
> + }
> + pr_info("Detected RK3568 EVB%s\n", evb_hwid);
> +
> + globalvar_add_simple("board.hwid", evb_hwid);
> +
> + return 0;
> +
> +err_hwid:
> + pr_err("couldn't retrieve hardware ID");
> + return ret;
> +}
> +late_initcall(rk3568_evb_detect_hwid);
> +
> +BAREBOX_MAGICVAR(global.board.hwid, "The board hardware ID");
>
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection
2021-07-05 16:04 [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection Michael Riesch
2021-07-05 17:18 ` [PATCH] fixup! " Ahmad Fatoum
2021-07-05 17:18 ` [PATCH v2] " Ahmad Fatoum
@ 2021-08-09 18:51 ` Sascha Hauer
2021-08-23 14:11 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2021-08-09 18:51 UTC (permalink / raw)
To: Michael Riesch; +Cc: barebox
On Mon, Jul 05, 2021 at 06:04:57PM +0200, Michael Riesch wrote:
> The RK3568 EVB uses a voltage divider to determine the hardware ID of
> the board. At the moment, the voltage levels for seven EVB variants are
> defined. This commit adds a late_initcall to the board code that reads
> out the voltage and populates the hardware ID as environment variable.
>
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
> ---
> v2:
> - add compatible check
> - return early in case the voltage cannot be read
> - populate hardware ID as environment variable
>
> arch/arm/boards/rockchip-rk3568-evb/board.c | 56 +++++++++++++++++++++
> 1 file changed, 56 insertions(+)
Applied with Ahmads fixup, thanks
Sascha
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection
2021-07-05 16:04 [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection Michael Riesch
` (2 preceding siblings ...)
2021-08-09 18:51 ` Sascha Hauer
@ 2021-08-23 14:11 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2021-08-23 14:11 UTC (permalink / raw)
To: Michael Riesch; +Cc: barebox
On Mon, Jul 05, 2021 at 06:04:57PM +0200, Michael Riesch wrote:
> The RK3568 EVB uses a voltage divider to determine the hardware ID of
> the board. At the moment, the voltage levels for seven EVB variants are
> defined. This commit adds a late_initcall to the board code that reads
> out the voltage and populates the hardware ID as environment variable.
>
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
> ---
> v2:
> - add compatible check
> - return early in case the voltage cannot be read
> - populate hardware ID as environment variable
>
> arch/arm/boards/rockchip-rk3568-evb/board.c | 56 +++++++++++++++++++++
> 1 file changed, 56 insertions(+)
>
> diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
> index 57c24ed3c..f8b257e57 100644
> --- a/arch/arm/boards/rockchip-rk3568-evb/board.c
> +++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
> @@ -2,7 +2,13 @@
> #include <common.h>
> #include <init.h>
> #include <mach/bbu.h>
> +#include <aiodev.h>
> #include <bootsource.h>
> +#include <environment.h>
> +#include <globalvar.h>
> +#include <magicvar.h>
> +
> +static bool machine_is_rk3568_evb = false;
>
> static int rk3568_evb_probe(struct device_d *dev)
> {
> @@ -11,6 +17,7 @@ static int rk3568_evb_probe(struct device_d *dev)
>
> barebox_set_model("Rockchip RK3568 EVB");
> barebox_set_hostname("rk3568-evb");
> + machine_is_rk3568_evb = true;
>
> if (bootsource == BOOTSOURCE_MMC && instance == 1)
> of_device_enable_path("/chosen/environment-sd");
> @@ -34,3 +41,52 @@ 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_hwid(void)
> +{
> + int ret;
> + int evb_hwid_voltage;
> + struct aiochannel *evb_hwid_chan;
> + char *evb_hwid;
> +
> + if (!machine_is_rk3568_evb)
> + return 0;
> +
> + evb_hwid_chan = aiochannel_by_name("aiodev0.in_value1_mV");
This fails to link when CONFIG_AIODEV is disabled. I added an early
return at the top of this function to fix that.
Sascha
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-23 14:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-05 16:04 [PATCH v2] arm: rockchip-rk3568-evb: add hardware id detection Michael Riesch
2021-07-05 17:18 ` [PATCH] fixup! " Ahmad Fatoum
2021-07-05 17:18 ` [PATCH v2] " Ahmad Fatoum
2021-08-09 18:51 ` Sascha Hauer
2021-08-23 14:11 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox