[PATCH v2 0/7] VIM3: add support for checking 'Function' button state

Hi All,
This patchset adds all building blocks needed for checking the 'Function' button state in the boot script on Amlogic A311D based VIM3 board. This button is connected to the ADC lines of the SoC, so it required to enable meson SARADC, the clocks needed for it and a simple button-adc drivers.
Once applied, one can use following commands in the boot scripts: -->8--- echo Checking Func button state: \c button Function if test ${button} = on then echo Selected alternative boot ... fi --->8---
Best regards Marek Szyprowski Samsung R&D Institute Poland
Changelog: v2: - removed Change-Id tags - split defconfig changes into ADC and button related
v1: https://lists.denx.de/pipermail/u-boot/2020-December/434875.html - initial submission
Patch summary:
Marek Szyprowski (7): clk: meson: add minimal driver for g12a-ao clocks adc: meson-saradc: add G12A variant adc: meson-saradc: skip hardware init only if ADC is enabled configs: khadas-vim3: enable ADC device support button: add a simple ADC-based button driver cmd: button: store button state in the 'button' env configs: khadas-vim3: enable Function button support
cmd/button.c | 4 +- configs/khadas-vim3_defconfig | 4 ++ drivers/adc/meson-saradc.c | 9 ++- drivers/button/Kconfig | 8 +++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 117 ++++++++++++++++++++++++++++++++++ drivers/clk/meson/Makefile | 1 + drivers/clk/meson/g12a-ao.c | 83 ++++++++++++++++++++++++ 8 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 drivers/button/button-adc.c create mode 100644 drivers/clk/meson/g12a-ao.c

Add minimal driver AO clocks on meson G12A family. Only ADC related clocks are supported.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com Reviewed-by: Neil Armstrong narmstrong@baylibre.com Tested-by: Jaehoon Chung jh80.chung@samsung.com Reviewed-by: Jaehoon Chung jh80.chung@samsung.com --- drivers/clk/meson/Makefile | 1 + drivers/clk/meson/g12a-ao.c | 83 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 drivers/clk/meson/g12a-ao.c
diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile index c873d6976f..7204383e17 100644 --- a/drivers/clk/meson/Makefile +++ b/drivers/clk/meson/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_CLK_MESON_GX) += gxbb.o obj-$(CONFIG_CLK_MESON_AXG) += axg.o obj-$(CONFIG_CLK_MESON_G12A) += g12a.o +obj-$(CONFIG_CLK_MESON_G12A) += g12a-ao.o
diff --git a/drivers/clk/meson/g12a-ao.c b/drivers/clk/meson/g12a-ao.c new file mode 100644 index 0000000000..7a0abea77c --- /dev/null +++ b/drivers/clk/meson/g12a-ao.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <common.h> +#include <log.h> +#include <asm/io.h> +#include <clk-uclass.h> +#include <dm.h> +#include <regmap.h> +#include <syscon.h> +#include <dt-bindings/clock/g12a-aoclkc.h> + +#include "clk_meson.h" + +struct meson_clk { + struct regmap *map; +}; + +#define AO_CLK_GATE0 0x4c +#define AO_SAR_CLK 0x90 + +static struct meson_gate gates[] = { + MESON_GATE(CLKID_AO_SAR_ADC, AO_CLK_GATE0, 8), + MESON_GATE(CLKID_AO_SAR_ADC_CLK, AO_SAR_CLK, 8), +}; + +static int meson_set_gate(struct clk *clk, bool on) +{ + struct meson_clk *priv = dev_get_priv(clk->dev); + struct meson_gate *gate; + + if (clk->id >= ARRAY_SIZE(gates)) + return -ENOENT; + + gate = &gates[clk->id]; + + if (gate->reg == 0) + return 0; + + regmap_update_bits(priv->map, gate->reg, + BIT(gate->bit), on ? BIT(gate->bit) : 0); + + return 0; +} + +static int meson_clk_enable(struct clk *clk) +{ + return meson_set_gate(clk, true); +} + +static int meson_clk_disable(struct clk *clk) +{ + return meson_set_gate(clk, false); +} + +static int meson_clk_probe(struct udevice *dev) +{ + struct meson_clk *priv = dev_get_priv(dev); + + priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node); + if (IS_ERR(priv->map)) + return PTR_ERR(priv->map); + + return 0; +} + +static struct clk_ops meson_clk_ops = { + .disable = meson_clk_disable, + .enable = meson_clk_enable, +}; + +static const struct udevice_id meson_clk_ids[] = { + { .compatible = "amlogic,meson-g12a-aoclkc" }, + { } +}; + +U_BOOT_DRIVER(meson_clk_axg) = { + .name = "meson_clk_g12a_ao", + .id = UCLASS_CLK, + .of_match = meson_clk_ids, + .priv_auto_alloc_size = sizeof(struct meson_clk), + .ops = &meson_clk_ops, + .probe = meson_clk_probe, +};

Add support for the SARADC variant found on the G12A SoCs family.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com Reviewed-by: Neil Armstrong narmstrong@baylibre.com Tested-by: Jaehoon Chung jh80.chung@samsung.com Reviewed-by: Jaehoon Chung jh80.chung@samsung.com --- drivers/adc/meson-saradc.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c index 72b0cc4e5b..998cef24d8 100644 --- a/drivers/adc/meson-saradc.c +++ b/drivers/adc/meson-saradc.c @@ -711,6 +711,8 @@ static const struct udevice_id meson_saradc_ids[] = { .data = (ulong)&gxl_saradc_data }, { .compatible = "amlogic,meson-gxm-saradc", .data = (ulong)&gxl_saradc_data }, + { .compatible = "amlogic,meson-g12a-saradc", + .data = (ulong)&gxl_saradc_data }, { } };

The driver skips hardware initialization if it is already configured by the earlier bootloader stage (BL30). Skip the initialization only if the hardware is really initialized and enabled.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com Reviewed-by: Neil Armstrong narmstrong@baylibre.com Tested-by: Jaehoon Chung jh80.chung@samsung.com Reviewed-by: Jaehoon Chung jh80.chung@samsung.com --- drivers/adc/meson-saradc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c index 998cef24d8..ce7ae990ad 100644 --- a/drivers/adc/meson-saradc.c +++ b/drivers/adc/meson-saradc.c @@ -512,8 +512,11 @@ static int meson_saradc_init(struct meson_saradc_priv *priv) * reading the temperature sensor. */ regmap_read(priv->regmap, MESON_SAR_ADC_REG3, ®val); - if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED) - return 0; + if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED) { + regmap_read(priv->regmap, MESON_SAR_ADC_REG3, ®val); + if (regval & MESON_SAR_ADC_REG3_ADC_EN) + return 0; + }
meson_saradc_stop_sample_engine(priv);

ADC device (Meson SARADC) will be used for probing 'Function' button state.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com --- configs/khadas-vim3_defconfig | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/configs/khadas-vim3_defconfig b/configs/khadas-vim3_defconfig index 9d7ba72d44..5d16652fd6 100644 --- a/configs/khadas-vim3_defconfig +++ b/configs/khadas-vim3_defconfig @@ -29,6 +29,8 @@ CONFIG_CMD_REGULATOR=y CONFIG_OF_CONTROL=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_ADC=y +CONFIG_SARADC_MESON=y CONFIG_DM_I2C=y CONFIG_SYS_I2C_MESON=y CONFIG_DM_MMC=y

Add a simple ADC-based button driver. This driver binds to the 'adc-keys' device tree node.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com --- drivers/button/Kconfig | 8 +++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 117 ++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 drivers/button/button-adc.c
diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig index 6b3ec7e55d..283367f2bd 100644 --- a/drivers/button/Kconfig +++ b/drivers/button/Kconfig @@ -9,6 +9,14 @@ config BUTTON can provide access to board-specific buttons. Use of the device tree for configuration is encouraged.
+config BUTTON_ADC + bool "Button adc" + depends on BUTTON + help + Enable support for buttons which are connected to ADC lines. The ADC + driver must use driver model. Buttons are configured using the device + tree. + config BUTTON_GPIO bool "Button gpio" depends on BUTTON diff --git a/drivers/button/Makefile b/drivers/button/Makefile index fcc10ebe8d..bbd18af149 100644 --- a/drivers/button/Makefile +++ b/drivers/button/Makefile @@ -3,4 +3,5 @@ # Copyright (C) 2020 Philippe Reynes philippe.reynes@softathome.com
obj-$(CONFIG_BUTTON) += button-uclass.o +obj-$(CONFIG_BUTTON_ADC) += button-adc.o obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o diff --git a/drivers/button/button-adc.c b/drivers/button/button-adc.c new file mode 100644 index 0000000000..086c676c02 --- /dev/null +++ b/drivers/button/button-adc.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * Author: Marek Szyprowski m.szyprowski@samsung.com + */ + +#include <common.h> +#include <button.h> +#include <dm.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> +#include <log.h> +#include <adc.h> + +struct button_adc_priv { + struct udevice *adc; + int channel; +}; + +static enum button_state_t button_adc_get_state(struct udevice *dev) +{ + struct button_adc_priv *priv = dev_get_priv(dev); + unsigned int val, mask; + int ret; + + ret = adc_start_channel(priv->adc, priv->channel); + if (ret) + return ret; + + ret = adc_channel_data(priv->adc, priv->channel, &val); + if (ret) + return ret; + + ret = adc_data_mask(priv->adc, &mask); + if (ret) + return ret; + + /* getting state is simplified a bit */ + if (ret == 0) + return (val < mask / 2) ? BUTTON_ON : BUTTON_OFF; + + return ret; +} + +static int button_adc_probe(struct udevice *dev) +{ + struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev); + struct button_adc_priv *priv = dev_get_priv(dev); + struct ofnode_phandle_args args; + int ret; + + /* Ignore the top-level button node */ + if (!uc_plat->label) + return 0; + + ret = dev_read_phandle_with_args(dev->parent, "io-channels", + "#io-channel-cells", 0, 0, &args); + if (ret) + return ret; + + ret = uclass_get_device_by_name(UCLASS_ADC, ofnode_get_name(args.node), + &priv->adc); + if (ret) + return ret; + + priv->channel = args.args[0]; + + return ret; +} + +static int button_adc_bind(struct udevice *parent) +{ + struct udevice *dev; + ofnode node; + int ret; + + dev_for_each_subnode(node, parent) { + struct button_uc_plat *uc_plat; + const char *label; + + label = ofnode_read_string(node, "label"); + if (!label) { + debug("%s: node %s has no label\n", __func__, + ofnode_get_name(node)); + return -EINVAL; + } + ret = device_bind_driver_to_node(parent, "button_adc", + ofnode_get_name(node), + node, &dev); + if (ret) + return ret; + uc_plat = dev_get_uclass_platdata(dev); + uc_plat->label = label; + } + + return 0; +} + +static const struct button_ops button_adc_ops = { + .get_state = button_adc_get_state, +}; + +static const struct udevice_id button_adc_ids[] = { + { .compatible = "adc-keys" }, + { } +}; + +U_BOOT_DRIVER(button_adc) = { + .name = "button_adc", + .id = UCLASS_BUTTON, + .of_match = button_adc_ids, + .ops = &button_adc_ops, + .priv_auto_alloc_size = sizeof(struct button_adc_priv), + .bind = button_adc_bind, + .probe = button_adc_probe, +};

On 12/15/20 3:42 PM, Marek Szyprowski wrote:
Add a simple ADC-based button driver. This driver binds to the 'adc-keys' device tree node.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com
drivers/button/Kconfig | 8 +++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 117 ++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 drivers/button/button-adc.c
diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig index 6b3ec7e55d..283367f2bd 100644 --- a/drivers/button/Kconfig +++ b/drivers/button/Kconfig @@ -9,6 +9,14 @@ config BUTTON can provide access to board-specific buttons. Use of the device tree for configuration is encouraged.
+config BUTTON_ADC
- bool "Button adc"
- depends on BUTTON
- help
Enable support for buttons which are connected to ADC lines. The ADC
ADC might stand for "Analog to Digital Converter", or "Automated Data Collection", or "Automatic Distance Control, or something else. Please, replace the abbreviation by the full expression.
Best regards
Heinrich
driver must use driver model. Buttons are configured using the device
tree.
- config BUTTON_GPIO bool "Button gpio" depends on BUTTON
diff --git a/drivers/button/Makefile b/drivers/button/Makefile index fcc10ebe8d..bbd18af149 100644 --- a/drivers/button/Makefile +++ b/drivers/button/Makefile @@ -3,4 +3,5 @@ # Copyright (C) 2020 Philippe Reynes philippe.reynes@softathome.com
obj-$(CONFIG_BUTTON) += button-uclass.o +obj-$(CONFIG_BUTTON_ADC) += button-adc.o obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o diff --git a/drivers/button/button-adc.c b/drivers/button/button-adc.c new file mode 100644 index 0000000000..086c676c02 --- /dev/null +++ b/drivers/button/button-adc.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/*
- Copyright (C) 2020 Samsung Electronics Co., Ltd.
http://www.samsung.com
- Author: Marek Szyprowski m.szyprowski@samsung.com
- */
+#include <common.h> +#include <button.h> +#include <dm.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> +#include <log.h> +#include <adc.h>
+struct button_adc_priv {
- struct udevice *adc;
- int channel;
+};
+static enum button_state_t button_adc_get_state(struct udevice *dev) +{
- struct button_adc_priv *priv = dev_get_priv(dev);
- unsigned int val, mask;
- int ret;
- ret = adc_start_channel(priv->adc, priv->channel);
- if (ret)
return ret;
- ret = adc_channel_data(priv->adc, priv->channel, &val);
- if (ret)
return ret;
- ret = adc_data_mask(priv->adc, &mask);
- if (ret)
return ret;
- /* getting state is simplified a bit */
- if (ret == 0)
return (val < mask / 2) ? BUTTON_ON : BUTTON_OFF;
- return ret;
+}
+static int button_adc_probe(struct udevice *dev) +{
- struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
- struct button_adc_priv *priv = dev_get_priv(dev);
- struct ofnode_phandle_args args;
- int ret;
- /* Ignore the top-level button node */
- if (!uc_plat->label)
return 0;
- ret = dev_read_phandle_with_args(dev->parent, "io-channels",
"#io-channel-cells", 0, 0, &args);
- if (ret)
return ret;
- ret = uclass_get_device_by_name(UCLASS_ADC, ofnode_get_name(args.node),
&priv->adc);
- if (ret)
return ret;
- priv->channel = args.args[0];
- return ret;
+}
+static int button_adc_bind(struct udevice *parent) +{
- struct udevice *dev;
- ofnode node;
- int ret;
- dev_for_each_subnode(node, parent) {
struct button_uc_plat *uc_plat;
const char *label;
label = ofnode_read_string(node, "label");
if (!label) {
debug("%s: node %s has no label\n", __func__,
ofnode_get_name(node));
return -EINVAL;
}
ret = device_bind_driver_to_node(parent, "button_adc",
ofnode_get_name(node),
node, &dev);
if (ret)
return ret;
uc_plat = dev_get_uclass_platdata(dev);
uc_plat->label = label;
- }
- return 0;
+}
+static const struct button_ops button_adc_ops = {
- .get_state = button_adc_get_state,
+};
+static const struct udevice_id button_adc_ids[] = {
- { .compatible = "adc-keys" },
- { }
+};
+U_BOOT_DRIVER(button_adc) = {
- .name = "button_adc",
- .id = UCLASS_BUTTON,
- .of_match = button_adc_ids,
- .ops = &button_adc_ops,
- .priv_auto_alloc_size = sizeof(struct button_adc_priv),
- .bind = button_adc_bind,
- .probe = button_adc_probe,
+};

Save examined button state in 'button' environment variable to enable checking button state in the scripts.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com Change-Id: I78b539e1516573fcfea4401f75469291844daae4 --- cmd/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmd/button.c b/cmd/button.c index 64c5a8fa04..8da911068a 100644 --- a/cmd/button.c +++ b/cmd/button.c @@ -23,8 +23,10 @@ static int show_button_state(struct udevice *dev) ret = button_get_state(dev); if (ret >= BUTTON_COUNT) ret = -EINVAL; - if (ret >= 0) + if (ret >= 0) { printf("%s\n", state_label[ret]); + env_set("button", state_label[ret]); + }
return ret; }

Save examined button state in 'button' environment variable to enable checking button state in the scripts.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com --- Resend reason: get rid of the Change-Id tag, that was still in v2. --- cmd/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmd/button.c b/cmd/button.c index 64c5a8fa04..8da911068a 100644 --- a/cmd/button.c +++ b/cmd/button.c @@ -23,8 +23,10 @@ static int show_button_state(struct udevice *dev) ret = button_get_state(dev); if (ret >= BUTTON_COUNT) ret = -EINVAL; - if (ret >= 0) + if (ret >= 0) { printf("%s\n", state_label[ret]); + env_set("button", state_label[ret]); + }
return ret; }

On 12/15/20 5:54 PM, Marek Szyprowski wrote:
Save examined button state in 'button' environment variable to enable checking button state in the scripts.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com
Resend reason: get rid of the Change-Id tag, that was still in v2.
cmd/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmd/button.c b/cmd/button.c index 64c5a8fa04..8da911068a 100644 --- a/cmd/button.c +++ b/cmd/button.c @@ -23,8 +23,10 @@ static int show_button_state(struct udevice *dev) ret = button_get_state(dev); if (ret >= BUTTON_COUNT) ret = -EINVAL;
- if (ret >= 0)
- if (ret >= 0) { printf("%s\n", state_label[ret]);
env_set("button", state_label[ret]);
Using a hard coded environment variable does not make much sense to me. The button command has a return value. So just use
button mybutton; setenv myvar $?
Best regards
Heinrich
}
return ret; }

On 15.12.2020 20:07, Heinrich Schuchardt wrote:
On 12/15/20 5:54 PM, Marek Szyprowski wrote:
Save examined button state in 'button' environment variable to enable checking button state in the scripts.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com
Resend reason: get rid of the Change-Id tag, that was still in v2.
cmd/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmd/button.c b/cmd/button.c index 64c5a8fa04..8da911068a 100644 --- a/cmd/button.c +++ b/cmd/button.c @@ -23,8 +23,10 @@ static int show_button_state(struct udevice *dev) ret = button_get_state(dev); if (ret >= BUTTON_COUNT) ret = -EINVAL; - if (ret >= 0) + if (ret >= 0) { printf("%s\n", state_label[ret]); + env_set("button", state_label[ret]);
Using a hard coded environment variable does not make much sense to me. The button command has a return value. So just use
button mybutton; setenv myvar $?
Thanks for the hint, I wasn't aware that uboot supports '$?'. By setting the 'button' env variable I've tried to mimic the behavior of the various network and file related commands, which sets 'filesize' env variable.
I will need to add the return value propagation to the button command anyway to make it usable from the scripts.
Best regards

On 12/16/20 8:08 AM, Marek Szyprowski wrote:
On 15.12.2020 20:07, Heinrich Schuchardt wrote:
On 12/15/20 5:54 PM, Marek Szyprowski wrote:
Save examined button state in 'button' environment variable to enable checking button state in the scripts.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com
Resend reason: get rid of the Change-Id tag, that was still in v2.
cmd/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmd/button.c b/cmd/button.c index 64c5a8fa04..8da911068a 100644 --- a/cmd/button.c +++ b/cmd/button.c @@ -23,8 +23,10 @@ static int show_button_state(struct udevice *dev) ret = button_get_state(dev); if (ret >= BUTTON_COUNT) ret = -EINVAL; - if (ret >= 0) + if (ret >= 0) { printf("%s\n", state_label[ret]); + env_set("button", state_label[ret]);
Using a hard coded environment variable does not make much sense to me. The button command has a return value. So just use
button mybutton; setenv myvar $?
Thanks for the hint, I wasn't aware that uboot supports '$?'. By setting the 'button' env variable I've tried to mimic the behavior of the various network and file related commands, which sets 'filesize' env variable.
I will need to add the return value propagation to the button command anyway to make it usable from the scripts.
Nothing to be done for the button command. Since
a6bfd71a96201127836d59736abcb54dc2d5e1a5 cmd/button: return button status
the button command returns
0 (true) - pressed, on 1 (false) - not pressed, off
Best regards
Heinrich

On 16.12.2020 08:29, Heinrich Schuchardt wrote:
On 12/16/20 8:08 AM, Marek Szyprowski wrote:
On 15.12.2020 20:07, Heinrich Schuchardt wrote:
On 12/15/20 5:54 PM, Marek Szyprowski wrote:
Save examined button state in 'button' environment variable to enable checking button state in the scripts.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com
Resend reason: get rid of the Change-Id tag, that was still in v2.
cmd/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmd/button.c b/cmd/button.c index 64c5a8fa04..8da911068a 100644 --- a/cmd/button.c +++ b/cmd/button.c @@ -23,8 +23,10 @@ static int show_button_state(struct udevice *dev) ret = button_get_state(dev); if (ret >= BUTTON_COUNT) ret = -EINVAL; - if (ret >= 0) + if (ret >= 0) { printf("%s\n", state_label[ret]); + env_set("button", state_label[ret]);
Using a hard coded environment variable does not make much sense to me. The button command has a return value. So just use
button mybutton; setenv myvar $?
Thanks for the hint, I wasn't aware that uboot supports '$?'. By setting the 'button' env variable I've tried to mimic the behavior of the various network and file related commands, which sets 'filesize' env variable.
I will need to add the return value propagation to the button command anyway to make it usable from the scripts.
Nothing to be done for the button command. Since
a6bfd71a96201127836d59736abcb54dc2d5e1a5 cmd/button: return button status
the button command returns
0 (true) - pressed, on 1 (false) - not pressed, off
Right, I've missed that commit. I've developed my code on top of v2020.10 release.
Best regards

Hi Marek,
On Tue, 15 Dec 2020 at 09:55, Marek Szyprowski m.szyprowski@samsung.com wrote:
Save examined button state in 'button' environment variable to enable checking button state in the scripts.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com
Resend reason: get rid of the Change-Id tag, that was still in v2.
If you use patman it does that for you.
Regards, Simon

Add options needed to check the 'Function' button state.
Signed-off-by: Marek Szyprowski m.szyprowski@samsung.com --- configs/khadas-vim3_defconfig | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/configs/khadas-vim3_defconfig b/configs/khadas-vim3_defconfig index 5d16652fd6..bc17430569 100644 --- a/configs/khadas-vim3_defconfig +++ b/configs/khadas-vim3_defconfig @@ -31,6 +31,8 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y CONFIG_ADC=y CONFIG_SARADC_MESON=y +CONFIG_BUTTON=y +CONFIG_BUTTON_ADC=y CONFIG_DM_I2C=y CONFIG_SYS_I2C_MESON=y CONFIG_DM_MMC=y
participants (3)
-
Heinrich Schuchardt
-
Marek Szyprowski
-
Simon Glass