VIM3: add support for checking 'Function' button state
A message that is not in the archive (sent off-list or not yet received): CGME20201222085638eucas1p158d91ce4a22d13623b19706b26374078@eucas1p1.samsung.com
v4 cover 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
if button Function
then
echo Selected alternative boot ...
fi
--->8---
Best regards
Marek Szyprowski
Samsung R&D Institute Poland
Changelog:
v4:
- rebased onto uboot-amlogic/u-boot-amlogic-next and dropped merged patches
- added adc-keys bindings docs (copied from Linux kernel)
- minor code adjustments pointed by Simon
- enabled driver also in khadas-vim3l_defconfig
v3: https://lists.denx.de/pipermail/u-boot/2020-December/435072.html
- removed 'button' env variable
- extended kconfig and patch descriptions
v2: https://lists.denx.de/pipermail/u-boot/2020-December/434991.html
- 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 (3):
dt-bindings: input: adc-keys bindings documentation
button: add a simple Analog to Digital Converter device based button
driver
configs: khadas-vim3(l): enable Function button support
configs/khadas-vim3_defconfig | 2 + configs/khadas-vim3l_defconfig | 2 + doc/device-tree-bindings/input/adc-keys.txt | 49 ++++++++ drivers/button/Kconfig | 8 ++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 121 ++++++++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 doc/device-tree-bindings/input/adc-keys.txt create mode 100644 drivers/button/button-adc.c
Signature · 1 line
2.17.1
PATCH v4 1/3 dt-bindings: input: adc-keys bindings documentation
Dump adc-keys bindings documentation from Linux kernel source tree v5.10.
--- doc/device-tree-bindings/input/adc-keys.txt | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 doc/device-tree-bindings/input/adc-keys.txt
doc/device-tree-bindings/input/adc-keys.txt new file +49 -0
@@ -0,0 +1,49 @@ +ADC attached resistor ladder buttons +------------------------------------ + +Required properties: + - compatible: "adc-keys" + - io-channels: Phandle to an ADC channel + - io-channel-names = "buttons"; + - keyup-threshold-microvolt: Voltage at which all the keys are considered up. + +Optional properties: + - poll-interval: Poll interval time in milliseconds + - autorepeat: Boolean, Enable auto repeat feature of Linux input + subsystem. + +Each button (key) is represented as a sub-node of "adc-keys": + +Required subnode-properties: + - label: Descriptive name of the key. + - linux,code: Keycode to emit. + - press-threshold-microvolt: Voltage ADC input when this key is pressed. + +Example: + +#include <dt-bindings/input/input.h> + + adc-keys { + compatible = "adc-keys"; + io-channels = <&lradc 0>; + io-channel-names = "buttons"; + keyup-threshold-microvolt = <2000000>; + + button-up { + label = "Volume Up"; + linux,code = <KEY_VOLUMEUP>; + press-threshold-microvolt = <1500000>; + }; + + button-down { + label = "Volume Down"; + linux,code = <KEY_VOLUMEDOWN>; + press-threshold-microvolt = <1000000>; + }; + + button-enter { + label = "Enter"; + linux,code = <KEY_ENTER>; + press-threshold-microvolt = <500000>; + }; + };
Signature · 1 line
2.17.1
Re: [PATCH v4 1/3] dt-bindings: input: adc-keys bindings documentation
Quoted 24 lines · Marek Szyprowski
Dump adc-keys bindings documentation from Linux kernel source tree v5.10.
Signed-off-by Marek Szyprowski <[email protected]>--- doc/device-tree-bindings/input/adc-keys.txt | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+)create mode 100644
doc/device-tree-bindings/input/adc-keys.txtdoc/device-tree-bindings/input/adc-keys.txt new file +10
-0@@ -0,0 +1,49 @@ +ADC attached resistor ladder buttons +------------------------------------ + +Required properties: + - compatible: "adc-keys" + - io-channels: Phandle to an ADC channel + - io-channel-names = "buttons"; + - keyup-threshold-microvolt: Voltage at which all the keys are considered up. + +Optional properties:
doc/device-tree-bindings/input/adc-keys.txt line 20
Quoted 10 lines
doc/device-tree-bindings/input/adc-keys.txt new file +10
-0+ - poll-interval: Poll interval time in milliseconds + - autorepeat: Boolean, Enable auto repeat feature of Linux input + subsystem. + +Each button (key) is represented as a sub-node of "adc-keys": + +Required subnode-properties: + - label: Descriptive name of the key. + - linux,code: Keycode to emit. + - press-threshold-microvolt: Voltage ADC input when this key is pressed.
https://www.merriam-webster.com/dictionary/threshold
defines threshold as "a level, point, or value above which something is true or will take place and below which it is not or will not"
"when this key is pressed" leaves it completely open if a key is considered pressed below or above the threshold. Please, replace the word 'when' by either 'above which' or 'below which'.
In the example keyup-threshold-microvolt is larger than keyup-threshold-microvolt all values of press-threshold-microvolt. So one might assume that 'above' is the intended meaning and the interpretation of the example might be:
2.000.000 <= value: no key pressed
1.500.000 <= value < 2.000.000: KEY_VOLUMEUP pressed 1.000.000 <= value < 1.500.000: KEY_VOLUMEDOWN pressed 500.000 <= value < 1.000.000: KEY_ENTER pressed value < 500.000: no key pressed
Both directions 'above' and 'below' make sense. So maybe if keyup-threshold-microvolt is lower than all press-threshold-microvolt you want to invert the logic?
The binding lacks a hysteresis which is needed for a reliable function.
If you look into drivers/input/keyboard/adc-keys.c in the Linux source, you can see that it is not using the threshold value as a threshold at all. Instead is uses abs(st->map[i].voltage - value) to find the nearest "threshold" voltage level.
Could you, please, try to bring this text into a form that cannot be misinterpreted and reconcile with upstream. This should include
* a results table for the example
* a definition if keyup-threshold-microvolt must be higher than all press-threshold-microvolt or may be lower than all press-threshold-microvolt
* a sentence forbidding keyup-threshold-microvolt to be between two press-threshold-microvolt
* a definition if or when any of the thresholds is a lower or upper boundary
Best regards
Heinrich
Quoted 30 lines
doc/device-tree-bindings/input/adc-keys.txt new file +29
-0+ +Example: + +#include <dt-bindings/input/input.h> + + adc-keys { + compatible = "adc-keys"; + io-channels = <&lradc 0>; + io-channel-names = "buttons"; + keyup-threshold-microvolt = <2000000>; + + button-up { + label = "Volume Up"; + linux,code = <KEY_VOLUMEUP>; + press-threshold-microvolt = <1500000>; + }; + + button-down { + label = "Volume Down"; + linux,code = <KEY_VOLUMEDOWN>; + press-threshold-microvolt = <1000000>; + }; + + button-enter { + label = "Enter"; + linux,code = <KEY_ENTER>; + press-threshold-microvolt = <500000>; + }; + };
Re: [PATCH v4 1/3] dt-bindings: input: adc-keys bindings documentation
Quoted 72 lines · Heinrich Schuchardt
Quoted 36 lines · Marek Szyprowski
Dump adc-keys bindings documentation from Linux kernel source tree v5.10.
Signed-off-by Marek Szyprowski <[email protected]>---
?doc/device-tree-bindings/input/adc-keys.txt| 49 +++++++++++++++++++++ ? 1 file changed, 49 insertions(+)
? create mode 100644doc/device-tree-bindings/input/adc-keys.txtdoc/device-tree-bindings/input/adc-keys.txt new file +8
-0@@ -0,0 +1,49 @@ +ADC attached resistor ladder buttons +------------------------------------ + +Required properties: + - compatible: "adc-keys" + - io-channels: Phandle to an ADC channel + - io-channel-names = "buttons"; + - keyup-threshold-microvolt: Voltage at which all the keys areconsidered up.
doc/device-tree-bindings/input/adc-keys.txt new file +12
-0+ +Optional properties: +??? - poll-interval: Poll interval time in milliseconds +??? - autorepeat: Boolean, Enable auto repeat feature of Linux input +????? subsystem. + +Each button (key) is represented as a sub-node of "adc-keys": + +Required subnode-properties: +??? - label: Descriptive name of the key. +??? - linux,code: Keycode to emit. +??? - press-threshold-microvolt: Voltage ADC input when this key isQuoted 1 line
pressed.
https://www.merriam-webster.com/dictionary/threshold
defines threshold as "a level, point, or value above which something is true or will take place and below which it is not or will not""when this key is pressed" leaves it completely open if a key is considered pressed below or above the threshold. Please, replace the word 'when' by either 'above which' or 'below which'.
In the example keyup-threshold-microvolt is larger than keyup-threshold-microvolt all values of press-threshold-microvolt. So one might assume that 'above' is the intended meaning and the interpretation of the example might be:
2.000.000 <= value: no key pressed
1.500.000 <= value < 2.000.000:KEY_VOLUMEUPpressed 1.000.000 <= value < 1.500.000:KEY_VOLUMEDOWNpressed 500.000 <= value < 1.000.000:KEY_ENTERpressed value < 500.000: no key pressedBoth directions 'above' and 'below' make sense. So maybe if keyup-threshold-microvolt is lower than all press-threshold-microvolt you want to invert the logic?
The binding lacks a hysteresis which is needed for a reliable function.
If you look into
drivers/input/keyboard/adc-keys.cin the Linux source, you can see that it is not using the threshold value as a threshold at all. Instead is usesabs(st->map[i].voltage - value)to find the nearest "threshold" voltage level.Could you, please, try to bring this text into a form that cannot be misinterpreted and reconcile with upstream. This should include
Quoted 8 lines
* a results table for the example
* a definition if keyup-threshold-microvolt must be higher than all ? press-threshold-microvolt or may be lower than all
? press-threshold-microvolt
* a sentence forbidding keyup-threshold-microvolt to be between two ? press-threshold-microvolt
* a definition if or when any of the thresholds is a lower or upper ? boundary
Cf. [PATCH 1/1] dt-bindings: adc-keys.txt: clarify description
https://lore.kernel.org/linux-input/20201222110815.24121-1-xypron.glpk at gmx.de/T/#u
Best regards
Heinrich
Quoted 36 lines
Best regards
Heinrich
Quoted 30 lines
doc/device-tree-bindings/input/adc-keys.txt new file +29
-0+ +Example: + +#include <dt-bindings/input/input.h> + +??? adc-keys { +??????? compatible = "adc-keys"; +??????? io-channels = <&lradc 0>; +??????? io-channel-names = "buttons"; +??????? keyup-threshold-microvolt = <2000000>; + +??????? button-up { +??????????? label = "Volume Up"; +??????????? linux,code = <KEY_VOLUMEUP>; +??????????? press-threshold-microvolt = <1500000>; +??????? }; + +??????? button-down { +??????????? label = "Volume Down"; +??????????? linux,code = <KEY_VOLUMEDOWN>; +??????????? press-threshold-microvolt = <1000000>; +??????? }; + +??????? button-enter { +??????????? label = "Enter"; +??????????? linux,code = <KEY_ENTER>; +??????????? press-threshold-microvolt = <500000>; +??????? }; +??? };
PATCH v4 1/3 dt-bindings: input: adc-keys bindings documentation
Quoted 83 lines · Heinrich Schuchardt
Quoted 73 lines · Heinrich Schuchardt
Quoted 37 lines · Marek Szyprowski
Dump adc-keys bindings documentation from Linux kernel source tree v5.10.
Signed-off-by Marek Szyprowski <[email protected]>---
?doc/device-tree-bindings/input/adc-keys.txt| 49 +++++++++++++++++++++ ? 1 file changed, 49 insertions(+)
? create mode 100644doc/device-tree-bindings/input/adc-keys.txtdoc/device-tree-bindings/input/adc-keys.txt new file +8
-0@@ -0,0 +1,49 @@ +ADC attached resistor ladder buttons +------------------------------------ + +Required properties: + - compatible: "adc-keys" + - io-channels: Phandle to an ADC channel + - io-channel-names = "buttons"; + - keyup-threshold-microvolt: Voltage at which all the keys areconsidered up.
doc/device-tree-bindings/input/adc-keys.txt new file +12
-0+ +Optional properties: +??? - poll-interval: Poll interval time in milliseconds +??? - autorepeat: Boolean, Enable auto repeat feature of Linux input +????? subsystem. + +Each button (key) is represented as a sub-node of "adc-keys": + +Required subnode-properties: +??? - label: Descriptive name of the key. +??? - linux,code: Keycode to emit. +??? - press-threshold-microvolt: Voltage ADC input when this key isQuoted 1 line
pressed.
https://www.merriam-webster.com/dictionary/threshold
defines threshold as "a level, point, or value above which something is true or will take place and below which it is not or will not""when this key is pressed" leaves it completely open if a key is considered pressed below or above the threshold. Please, replace the word 'when' by either 'above which' or 'below which'.
In the example keyup-threshold-microvolt is larger than keyup-threshold-microvolt all values of press-threshold-microvolt. So one might assume that 'above' is the intended meaning and the interpretation of the example might be:
2.000.000 <= value: no key pressed
1.500.000 <= value < 2.000.000:KEY_VOLUMEUPpressed 1.000.000 <= value < 1.500.000:KEY_VOLUMEDOWNpressed 500.000 <= value < 1.000.000:KEY_ENTERpressed value < 500.000: no key pressedBoth directions 'above' and 'below' make sense. So maybe if keyup-threshold-microvolt is lower than all press-threshold-microvolt you want to invert the logic?
The binding lacks a hysteresis which is needed for a reliable function.
If you look into
drivers/input/keyboard/adc-keys.cin the Linux source, you can see that it is not using the threshold value as a threshold at all. Instead is usesabs(st->map[i].voltage - value)to find the nearest "threshold" voltage level.Could you, please, try to bring this text into a form that cannot be misinterpreted and reconcile with upstream. This should include
Quoted 8 lines
* a results table for the example
* a definition if keyup-threshold-microvolt must be higher than all ?? press-threshold-microvolt or may be lower than all
?? press-threshold-microvolt
* a sentence forbidding keyup-threshold-microvolt to be between two ?? press-threshold-microvolt
* a definition if or when any of the thresholds is a lower or upper ?? boundary
Quoted 2 lines
Cf. [PATCH 1/1] dt-bindings: adc-keys.txt: clarify description
https://lore.kernel.org/linux-input/20201222110815.24121-1-xypron.glpk at gmx.de/T/#u
My patch has been accepted into Linux next.
Best regards
Heinrich
Quoted 32 lines
Quoted 31 lines
Quoted 30 lines
doc/device-tree-bindings/input/adc-keys.txt new file +29
-0+ +Example: + +#include <dt-bindings/input/input.h> + +??? adc-keys { +??????? compatible = "adc-keys"; +??????? io-channels = <&lradc 0>; +??????? io-channel-names = "buttons"; +??????? keyup-threshold-microvolt = <2000000>; + +??????? button-up { +??????????? label = "Volume Up"; +??????????? linux,code = <KEY_VOLUMEUP>; +??????????? press-threshold-microvolt = <1500000>; +??????? }; + +??????? button-down { +??????????? label = "Volume Down"; +??????????? linux,code = <KEY_VOLUMEDOWN>; +??????????? press-threshold-microvolt = <1000000>; +??????? }; + +??????? button-enter { +??????????? label = "Enter"; +??????????? linux,code = <KEY_ENTER>; +??????????? press-threshold-microvolt = <500000>; +??????? }; +??? };
PATCH v4 2/3 button: add a simple Analog to Digital Converter device based button driver
In reply to Marek SzyprowskiAdd a simple Analog to Digital Converter device based button driver. This driver binds to the 'adc-keys' device tree node.
--- drivers/button/Kconfig | 8 +++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 121 ++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 drivers/button/button-adc.c
drivers/button/Kconfig +8 -0
@@ -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 Analog to Digital + Converter device. The ADC driver must use driver model. Buttons are + configured using the device tree. + config BUTTON_GPIO bool "Button gpio" depends on BUTTON
drivers/button/Makefile +1 -0
@@ -3,4 +3,5 @@ # Copyright (C) 2020 Philippe Reynes <[email protected]> obj-$(CONFIG_BUTTON) += button-uclass.o +obj-$(CONFIG_BUTTON_ADC) += button-adc.o obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o
drivers/button/button-adc.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 2/3 button: add a simple Analog to Digital Converter device based button driver
Quoted 130 lines · Marek Szyprowski
Add a simple Analog to Digital Converter device based button driver. This driver binds to the 'adc-keys' device tree node.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/button/Kconfig | 8 +++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 121 ++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+)create mode 100644
drivers/button/button-adc.cdrivers/button/Kconfig +8
-0@@ -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 Analog to Digital + Converter device. The ADC driver must use driver model. Buttons are + configured using the device tree. + config BUTTON_GPIO bool "Button gpio" depends on BUTTONdrivers/button/Makefile +1
-0@@ -3,4 +3,5 @@ # Copyright (C) 2020 Philippe Reynes <[email protected]> obj-$(CONFIG_BUTTON) += button-uclass.o +obj-$(CONFIG_BUTTON_ADC) += button-adc.o obj-$(CONFIG_BUTTON_GPIO) += button-gpio.odrivers/button/button-adc.c new file +84
-0@@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2020 Samsung Electronics Co., Ltd. +* http://www.samsung.com +* Author: Marek Szyprowski <[email protected]> +*/ + +#include <common.h> +#include <adc.h> +#include <button.h> +#include <dm.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> + +/** +* struct button_adc_priv - private data for button-adc driver. +* +* @adc: Analog to Digital Converter device to which button is connected. +* @channel: channel of the ADC device to probe the button state. +*/ +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_ofnode (UCLASS_ADC , 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;
drivers/button/button-adc.c line 94
Quoted 10 lines
drivers/button/button-adc.c new file +10
-0+ + 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);
This code does not match the binding. The binding defines a voltage ladder where you have multiple voltage ranges and multiple buttons.
You need to consider the threshold voltages.
Have a look at Linux' drivers/input/keyboard/adc-keys.c. Beware that code is also incorrect as the author ignores the meaning of "threshold" and uses it it as closest voltage.
Best regards
Heinrich
Quoted 28 lines
drivers/button/button-adc.c new file +27
-0+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, +};
PATCH v4 2/3 button: add a simple Analog to Digital Converter device based button driver
Hi,
Quoted 146 lines · Heinrich Schuchardt
Quoted 130 lines · Marek Szyprowski
Add a simple Analog to Digital Converter device based button driver. This driver binds to the 'adc-keys' device tree node.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/button/Kconfig | 8 +++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 121 ++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+)create mode 100644
drivers/button/button-adc.cdrivers/button/Kconfig +8
-0@@ -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 Analog to Digital + Converter device. The ADC driver must use driver model. Buttons are + configured using the device tree. + config BUTTON_GPIO bool "Button gpio" depends on BUTTONdrivers/button/Makefile +1
-0@@ -3,4 +3,5 @@ # Copyright (C) 2020 Philippe Reynes <[email protected]> obj-$(CONFIG_BUTTON) += button-uclass.o +obj-$(CONFIG_BUTTON_ADC) += button-adc.o obj-$(CONFIG_BUTTON_GPIO) += button-gpio.odrivers/button/button-adc.c new file +84
-0@@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2020 Samsung Electronics Co., Ltd. +* http://www.samsung.com +* Author: Marek Szyprowski <[email protected]> +*/ + +#include <common.h> +#include <adc.h> +#include <button.h> +#include <dm.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> + +/** +* struct button_adc_priv - private data for button-adc driver. +* +* @adc: Analog to Digital Converter device to which button is connected. +* @channel: channel of the ADC device to probe the button state. +*/ +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_ofnode (UCLASS_ADC , 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;drivers/button/button-adc.c line 94
Quoted 10 lines
drivers/button/button-adc.c new file +10
-0+ + 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);This code does not match the binding. The binding defines a voltage ladder where you have multiple voltage ranges and multiple buttons.
Quoted 5 lines
You need to consider the threshold voltages.
Have a look at Linux'
drivers/input/keyboard/adc-keys.c. Beware that code is also incorrect as the author ignores the meaning of "threshold" and uses it it as closest voltage.
Apart from that, from a DM point of view, this looks good.
Regards,
Simon
PATCH v4 3/3 configs: khadas-vim3(l): enable Function button support
In reply to Marek SzyprowskiAdd options required to check the 'Function' button state.
--- configs/khadas-vim3_defconfig | 2 ++ configs/khadas-vim3l_defconfig | 2 ++ 2 files changed, 4 insertions(+)
configs/khadas-vim3_defconfig +2 -0
@@ -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
configs/khadas-vim3l_defconfig +2 -0
@@ -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
Signature · 1 line
2.17.1
v4 cover VIM3: add support for checking 'Function' button state
In reply to Marek SzyprowskiHi,
Quoted 33 lines · Marek Szyprowski
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
if button Function
thenecho Selected alternative boot ...fi
--->8---Best regards
Marek Szyprowski
Samsung R&D Institute PolandChangelog:
v4:
- rebased onto uboot-amlogic/u-boot-amlogic-next and dropped merged patches
- added adc-keys bindings docs (copied from Linux kernel)
- minor code adjustments pointed by Simon
- enabled driver also in khadas-vim3l_defconfigv3: https://lists.denx.de/pipermail/u-boot/2020-December/435072.html
- removed 'button' env variable
- extended kconfig and patch descriptions
Quoted 6 lines
v2: https://lists.denx.de/pipermail/u-boot/2020-December/434991.html
- removed Change-Id tags
- split defconfig changes into ADC and button relatedv1: https://lists.denx.de/pipermail/u-boot/2020-December/434875.html
- initial submission
What's the state of the patchset ?
Neil
Quoted 20 lines
Patch summary:
Marek Szyprowski (3):
dt-bindings: input: adc-keys bindings documentation
button: add a simple Analog to Digital Converter device based button
driver
configs: khadas-vim3(l): enable Function button supportconfigs/khadas-vim3_defconfig | 2 + configs/khadas-vim3l_defconfig | 2 + doc/device-tree-bindings/input/adc-keys.txt | 49 ++++++++ drivers/button/Kconfig | 8 ++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 121 ++++++++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 doc/device-tree-bindings/input/adc-keys.txt create mode 100644 drivers/button/button-adc.c
v4 cover VIM3: add support for checking 'Function' button state
Quoted 36 lines · Neil Armstrong
Hi,
Quoted 33 lines · Marek Szyprowski
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
if button Function
thenecho Selected alternative boot ...fi
--->8---Best regards
Marek Szyprowski
Samsung R&D Institute PolandChangelog:
v4:
- rebased onto uboot-amlogic/u-boot-amlogic-next and dropped merged patches
- added adc-keys bindings docs (copied from Linux kernel)
- minor code adjustments pointed by Simon
- enabled driver also in khadas-vim3l_defconfigv3: https://lists.denx.de/pipermail/u-boot/2020-December/435072.html
- removed 'button' env variable
- extended kconfig and patch descriptions
Quoted 8 lines
Quoted 6 lines
v2: https://lists.denx.de/pipermail/u-boot/2020-December/434991.html
- removed Change-Id tags
- split defconfig changes into ADC and button relatedv1: https://lists.denx.de/pipermail/u-boot/2020-December/434875.html
- initial submissionWhat's the state of the patchset ?
Hello Neil,
the series is assigned to you. Patch 2 is incorrect. Patch 1 can be updated to match Linux. So I suggest to set the status for the series to "changes requested".
Best regards
Heinrich
Quoted 24 lines
Neil
Quoted 20 lines
Patch summary:
Marek Szyprowski (3):
dt-bindings: input: adc-keys bindings documentation
button: add a simple Analog to Digital Converter device based button
driver
configs: khadas-vim3(l): enable Function button supportconfigs/khadas-vim3_defconfig | 2 + configs/khadas-vim3l_defconfig | 2 + doc/device-tree-bindings/input/adc-keys.txt | 49 ++++++++ drivers/button/Kconfig | 8 ++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 121 ++++++++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 doc/device-tree-bindings/input/adc-keys.txt create mode 100644 drivers/button/button-adc.c
v4 cover VIM3: add support for checking 'Function' button state
Hi,
Quoted 44 lines · Heinrich Schuchardt
Quoted 43 lines · Neil Armstrong
Hi,
Quoted 39 lines · Marek Szyprowski
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
if button Function
thenecho Selected alternative boot ...fi
--->8---Best regards
Marek Szyprowski
Samsung R&D Institute PolandChangelog:
v4:
- rebased onto uboot-amlogic/u-boot-amlogic-next and dropped merged patches
- added adc-keys bindings docs (copied from Linux kernel)
- minor code adjustments pointed by Simon
- enabled driver also in khadas-vim3l_defconfigv3: https://lists.denx.de/pipermail/u-boot/2020-December/435072.html
- removed 'button' env variable
- extended kconfig and patch descriptionsv2: https://lists.denx.de/pipermail/u-boot/2020-December/434991.html
- removed Change-Id tags
- split defconfig changes into ADC and button relatedv1: https://lists.denx.de/pipermail/u-boot/2020-December/434875.html
- initial submission
Quoted 8 lines
Quoted 1 line
What's the state of the patchset ?
Hello Neil,
the series is assigned to you. Patch 2 is incorrect. Patch 1 can be updated to match Linux. So I suggest to set the status for the series to "changes requested".
Sure, it was more a question to Marek, but yeah I'll tag them "changes requested"
Neil
Quoted 29 lines
Best regards
Heinrich
Quoted 24 lines
Neil
Quoted 20 lines
Patch summary:
Marek Szyprowski (3):
dt-bindings: input: adc-keys bindings documentation
button: add a simple Analog to Digital Converter device based button
driver
configs: khadas-vim3(l): enable Function button supportconfigs/khadas-vim3_defconfig | 2 + configs/khadas-vim3l_defconfig | 2 + doc/device-tree-bindings/input/adc-keys.txt | 49 ++++++++ drivers/button/Kconfig | 8 ++ drivers/button/Makefile | 1 + drivers/button/button-adc.c | 121 ++++++++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 doc/device-tree-bindings/input/adc-keys.txt create mode 100644 drivers/button/button-adc.c
v4 cover VIM3: add support for checking 'Function' button state
Hi Neil,
Quoted 42 lines · Neil Armstrong
Quoted 41 lines · Heinrich Schuchardt
Quoted 40 lines · Neil Armstrong
Quoted 39 lines · Marek Szyprowski
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
if button Function
thenecho Selected alternative boot ...fi
--->8---Best regards
Marek Szyprowski
Samsung R&D Institute PolandChangelog:
v4:
- rebased onto uboot-amlogic/u-boot-amlogic-next and dropped merged patches
- added adc-keys bindings docs (copied from Linux kernel)
- minor code adjustments pointed by Simon
- enabled driver also in khadas-vim3l_defconfigv3: https://protect2.fireeye.com/v1/url?k=fc4a4b97-a3d1734e-fc4bc0d8-0cc47a3356b2-eb4ba315795a3f17&q=1&e=b660ed0e-7d37-47e8-877d-c8391317e3e0&u=https%3A%2F%2Flists.denx.de%2Fpipermail%2Fu-boot%2F2020-December%2F435072.html
- removed 'button' env variable
- extended kconfig and patch descriptionsv2: https://protect2.fireeye.com/v1/url?k=11f0ed69-4e6bd5b0-11f16626-0cc47a3356b2-f341d16b01448534&q=1&e=b660ed0e-7d37-47e8-877d-c8391317e3e0&u=https%3A%2F%2Flists.denx.de%2Fpipermail%2Fu-boot%2F2020-December%2F434991.html
- removed Change-Id tags
- split defconfig changes into ADC and button related
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
What's the state of the patchset ?
Hello Neil,
the series is assigned to you. Patch 2 is incorrect. Patch 1 can be updated to match Linux. So I suggest to set the status for the series to "changes requested".
Sure, it was more a question to Marek, but yeah I'll tag them "changes requested"
I'm sorry for the late reply, I've been busy with other stuff. I will try to update the adc-keys driver to use the threshold values and add the updated device tree bindings soon.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland