* [PATCH] arm: baltos: export DIP switch value
@ 2020-07-17 18:04 yegorslists
2020-07-17 19:07 ` Oleksij Rempel
2020-08-11 7:39 ` Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: yegorslists @ 2020-07-17 18:04 UTC (permalink / raw)
To: barebox
From: Yegor Yefremov <yegorslists@googlemail.com>
Some device in the OnRISC device family provide four DIP switches.
Read them and provide their value as a hex in the global variable
"board.dip".
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
---
arch/arm/boards/vscom-baltos/board.c | 42 ++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/arch/arm/boards/vscom-baltos/board.c b/arch/arm/boards/vscom-baltos/board.c
index 800f42df3..59782d299 100644
--- a/arch/arm/boards/vscom-baltos/board.c
+++ b/arch/arm/boards/vscom-baltos/board.c
@@ -45,6 +45,43 @@ struct bsp_vs_hwparam {
uint8_t MAC3[6];
} __attribute__ ((packed));
+static uint8_t get_dip_switch(uint16_t id, uint32_t rev)
+{
+ uint16_t maj, min;
+ uint8_t dip = 0;
+
+ maj = rev >> 16;
+ min = rev & 0xffff;
+
+ if ((id == 220 || id == 222) && (maj == 1 && min == 2))
+ id = 214;
+
+ switch(id) {
+ case 214:
+ case 215:
+ dip = !gpio_get_value(44);
+ dip += !gpio_get_value(45) << 1;
+ dip += !gpio_get_value(46) << 2;
+ dip += !gpio_get_value(47) << 3;
+ break;
+ case 212:
+ case 221:
+ case 223:
+ case 224:
+ case 225:
+ case 226:
+ case 227:
+ case 230:
+ dip = !gpio_get_value(82);
+ dip += !gpio_get_value(83) << 1;
+ dip += !gpio_get_value(105) << 2;
+ dip += !gpio_get_value(106) << 3;
+ break;
+ }
+
+ return dip;
+}
+
static int baltos_read_eeprom(void)
{
struct bsp_vs_hwparam hw_param;
@@ -52,6 +89,7 @@ static int baltos_read_eeprom(void)
char *buf, var_buf[32];
int rc;
unsigned char mac_addr[6];
+ uint8_t dip;
if (!of_machine_is_compatible("vscom,onrisc"))
return 0;
@@ -109,6 +147,10 @@ static int baltos_read_eeprom(void)
gpio_direction_output(135, 0);
}
+ dip = get_dip_switch(hw_param.SystemId, hw_param.HwRev);
+ sprintf(var_buf, "%02x", dip);
+ globalvar_add_simple("board.dip", var_buf);
+
return 0;
}
environment_initcall(baltos_read_eeprom);
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arm: baltos: export DIP switch value
2020-07-17 18:04 [PATCH] arm: baltos: export DIP switch value yegorslists
@ 2020-07-17 19:07 ` Oleksij Rempel
2020-08-11 7:39 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2020-07-17 19:07 UTC (permalink / raw)
To: yegorslists, barebox
Hi!
next week i wont to send a patch to introduce helper function to read array of gpios and covert them
in to a value.
May be it will reduce your code.
Am 17.07.20 um 20:04 schrieb yegorslists@googlemail.com:
> From: Yegor Yefremov <yegorslists@googlemail.com>
>
> Some device in the OnRISC device family provide four DIP switches.
> Read them and provide their value as a hex in the global variable
> "board.dip".
>
> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
> ---
> arch/arm/boards/vscom-baltos/board.c | 42 ++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
>
> diff --git a/arch/arm/boards/vscom-baltos/board.c b/arch/arm/boards/vscom-baltos/board.c
> index 800f42df3..59782d299 100644
> --- a/arch/arm/boards/vscom-baltos/board.c
> +++ b/arch/arm/boards/vscom-baltos/board.c
> @@ -45,6 +45,43 @@ struct bsp_vs_hwparam {
> uint8_t MAC3[6];
> } __attribute__ ((packed));
>
> +static uint8_t get_dip_switch(uint16_t id, uint32_t rev)
> +{
> + uint16_t maj, min;
> + uint8_t dip = 0;
> +
> + maj = rev >> 16;
> + min = rev & 0xffff;
> +
> + if ((id == 220 || id == 222) && (maj == 1 && min == 2))
> + id = 214;
> +
> + switch(id) {
> + case 214:
> + case 215:
> + dip = !gpio_get_value(44);
> + dip += !gpio_get_value(45) << 1;
> + dip += !gpio_get_value(46) << 2;
> + dip += !gpio_get_value(47) << 3;
> + break;
> + case 212:
> + case 221:
> + case 223:
> + case 224:
> + case 225:
> + case 226:
> + case 227:
> + case 230:
> + dip = !gpio_get_value(82);
> + dip += !gpio_get_value(83) << 1;
> + dip += !gpio_get_value(105) << 2;
> + dip += !gpio_get_value(106) << 3;
> + break;
> + }
> +
> + return dip;
> +}
> +
> static int baltos_read_eeprom(void)
> {
> struct bsp_vs_hwparam hw_param;
> @@ -52,6 +89,7 @@ static int baltos_read_eeprom(void)
> char *buf, var_buf[32];
> int rc;
> unsigned char mac_addr[6];
> + uint8_t dip;
>
> if (!of_machine_is_compatible("vscom,onrisc"))
> return 0;
> @@ -109,6 +147,10 @@ static int baltos_read_eeprom(void)
> gpio_direction_output(135, 0);
> }
>
> + dip = get_dip_switch(hw_param.SystemId, hw_param.HwRev);
> + sprintf(var_buf, "%02x", dip);
> + globalvar_add_simple("board.dip", var_buf);
> +
> return 0;
> }
> environment_initcall(baltos_read_eeprom);
>
--
Regards,
Oleksij
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arm: baltos: export DIP switch value
2020-07-17 18:04 [PATCH] arm: baltos: export DIP switch value yegorslists
2020-07-17 19:07 ` Oleksij Rempel
@ 2020-08-11 7:39 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2020-08-11 7:39 UTC (permalink / raw)
To: yegorslists; +Cc: barebox
On Fri, Jul 17, 2020 at 08:04:43PM +0200, yegorslists@googlemail.com wrote:
> From: Yegor Yefremov <yegorslists@googlemail.com>
>
> Some device in the OnRISC device family provide four DIP switches.
> Read them and provide their value as a hex in the global variable
> "board.dip".
>
> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
> ---
> arch/arm/boards/vscom-baltos/board.c | 42 ++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
Applied, thanks.
Indeed Oleksijs function to read an id from an gpio array might be of
help here, it could be converted once the series is merged.
Sascha
>
> diff --git a/arch/arm/boards/vscom-baltos/board.c b/arch/arm/boards/vscom-baltos/board.c
> index 800f42df3..59782d299 100644
> --- a/arch/arm/boards/vscom-baltos/board.c
> +++ b/arch/arm/boards/vscom-baltos/board.c
> @@ -45,6 +45,43 @@ struct bsp_vs_hwparam {
> uint8_t MAC3[6];
> } __attribute__ ((packed));
>
> +static uint8_t get_dip_switch(uint16_t id, uint32_t rev)
> +{
> + uint16_t maj, min;
> + uint8_t dip = 0;
> +
> + maj = rev >> 16;
> + min = rev & 0xffff;
> +
> + if ((id == 220 || id == 222) && (maj == 1 && min == 2))
> + id = 214;
> +
> + switch(id) {
> + case 214:
> + case 215:
> + dip = !gpio_get_value(44);
> + dip += !gpio_get_value(45) << 1;
> + dip += !gpio_get_value(46) << 2;
> + dip += !gpio_get_value(47) << 3;
> + break;
> + case 212:
> + case 221:
> + case 223:
> + case 224:
> + case 225:
> + case 226:
> + case 227:
> + case 230:
> + dip = !gpio_get_value(82);
> + dip += !gpio_get_value(83) << 1;
> + dip += !gpio_get_value(105) << 2;
> + dip += !gpio_get_value(106) << 3;
> + break;
> + }
> +
> + return dip;
> +}
> +
> static int baltos_read_eeprom(void)
> {
> struct bsp_vs_hwparam hw_param;
> @@ -52,6 +89,7 @@ static int baltos_read_eeprom(void)
> char *buf, var_buf[32];
> int rc;
> unsigned char mac_addr[6];
> + uint8_t dip;
>
> if (!of_machine_is_compatible("vscom,onrisc"))
> return 0;
> @@ -109,6 +147,10 @@ static int baltos_read_eeprom(void)
> gpio_direction_output(135, 0);
> }
>
> + dip = get_dip_switch(hw_param.SystemId, hw_param.HwRev);
> + sprintf(var_buf, "%02x", dip);
> + globalvar_add_simple("board.dip", var_buf);
> +
> return 0;
> }
> environment_initcall(baltos_read_eeprom);
> --
> 2.17.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
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] 3+ messages in thread
end of thread, other threads:[~2020-08-11 7:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 18:04 [PATCH] arm: baltos: export DIP switch value yegorslists
2020-07-17 19:07 ` Oleksij Rempel
2020-08-11 7:39 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox