Message ID | 20210211084757.22759-6-m.szyprowski@samsung.com |
---|---|
State | Superseded |
Headers | show |
Series | VIM3: add support for checking 'Function' button state | expand |
On 11.02.21 09:47, Marek Szyprowski wrote: > Add adc-keys device to the sandbox/test.dts and connect it to the channel > #3 of the sandbox_adc driver. The default values sampled by sandbox_adc > driver determines that button3 and button4 are released and button5 is > pressed. > > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> > --- > arch/sandbox/dts/test.dts | 24 ++++++++++++++++++- > configs/sandbox_defconfig | 1 + > test/dm/button.c | 50 +++++++++++++++++++++++++++++++++++++-- > 3 files changed, 72 insertions(+), 3 deletions(-) > > diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts > index e95f4631bf..a32b019ae7 100644 > --- a/arch/sandbox/dts/test.dts > +++ b/arch/sandbox/dts/test.dts > @@ -69,6 +69,27 @@ > }; > }; > > + buttons2 { > + compatible = "adc-keys"; > + io-channels = <&adc 3>; > + keyup-threshold-microvolt = <3000000>; > + > + button-up { > + label = "button3"; > + press-threshold-microvolt = <1500000>; In patch 1/5 you wrote that "linux,code" is a required property. Even if you don't use the property currently, I suggest to keep test.dts compliant. Best regards Heinrich > + }; > + > + button-down { > + label = "button4"; > + press-threshold-microvolt = <1000000>; > + }; > + > + button-enter { > + label = "button5"; > + press-threshold-microvolt = <500000>; > + }; > + }; > + > cros_ec: cros-ec { > reg = <0 0>; > compatible = "google,cros-ec-sandbox"; > @@ -587,8 +608,9 @@ > i2c-eeprom = <&bootcount_i2c>; > }; > > - adc@0 { > + adc: adc@0 { > compatible = "sandbox,adc"; > + #io-channel-cells = <1>; > vdd-supply = <&buck2>; > vss-microvolts = <0>; > }; > diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig > index 0c7674efc9..3731bf05ff 100644 > --- a/configs/sandbox_defconfig > +++ b/configs/sandbox_defconfig > @@ -122,6 +122,7 @@ CONFIG_DM_BOOTCOUNT=y > CONFIG_DM_BOOTCOUNT_RTC=y > CONFIG_DM_BOOTCOUNT_I2C_EEPROM=y > CONFIG_BUTTON=y > +CONFIG_BUTTON_ADC=y > CONFIG_BUTTON_GPIO=y > CONFIG_CLK=y > CONFIG_CLK_COMPOSITE_CCF=y > diff --git a/test/dm/button.c b/test/dm/button.c > index ecaa47cf5f..f8a7fab61d 100644 > --- a/test/dm/button.c > +++ b/test/dm/button.c > @@ -7,7 +7,10 @@ > > #include <common.h> > #include <dm.h> > +#include <adc.h> > #include <button.h> > +#include <power/regulator.h> > +#include <power/sandbox_pmic.h> > #include <asm/gpio.h> > #include <dm/test.h> > #include <test/ut.h> > @@ -17,11 +20,20 @@ static int dm_test_button_base(struct unit_test_state *uts) > { > struct udevice *dev; > > - /* Get the top-level device */ > + /* Get the top-level gpio buttons device */ > ut_assertok(uclass_get_device(UCLASS_BUTTON, 0, &dev)); > + /* Get the 2 gpio buttons */ > ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &dev)); > ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, &dev)); > - ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 3, &dev)); > + > + /* Get the top-level adc buttons device */ > + ut_assertok(uclass_get_device(UCLASS_BUTTON, 3, &dev)); > + /* Get the 3 adc buttons */ > + ut_assertok(uclass_get_device(UCLASS_BUTTON, 4, &dev)); > + ut_assertok(uclass_get_device(UCLASS_BUTTON, 5, &dev)); > + ut_assertok(uclass_get_device(UCLASS_BUTTON, 6, &dev)); > + > + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 7, &dev)); > > return 0; > } > @@ -72,3 +84,37 @@ static int dm_test_button_label(struct unit_test_state *uts) > return 0; > } > DM_TEST(dm_test_button_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); > + > +/* Test adc-keys driver */ > +static int dm_test_button_keys_adc(struct unit_test_state *uts) > +{ > + struct udevice *supply; > + struct udevice *dev; > + int uV; > + > + ut_assertok(uclass_get_device_by_name(UCLASS_ADC, "adc@0", &dev)); > + > + ut_assertok(regulator_get_by_devname(SANDBOX_BUCK2_DEVNAME, &supply)); > + ut_assertok(regulator_set_value(supply, SANDBOX_BUCK2_SET_UV)); > + ut_asserteq(SANDBOX_BUCK2_SET_UV, regulator_get_value(supply)); > + /* Update ADC plat and get new Vdd value */ > + ut_assertok(adc_vdd_value(dev, &uV)); > + ut_asserteq(SANDBOX_BUCK2_SET_UV, uV); > + > + /* > + * sandbox-adc returns constant value on channel 3, is used by adc-keys: > + * SANDBOX_ADC_CHANNEL3_DATA * SANDBOX_BUCK2_SET_UV / SANDBOX_ADC_DATA_MASK = > + * 0x3000 * 3300000 / 0xffff = 618759uV > + * This means that button3 and button4 are released and button5 > + * is pressed. > + */ > + ut_assertok(button_get_by_label("button3", &dev)); > + ut_asserteq(BUTTON_OFF, button_get_state(dev)); > + ut_assertok(button_get_by_label("button4", &dev)); > + ut_asserteq(BUTTON_OFF, button_get_state(dev)); > + ut_assertok(button_get_by_label("button5", &dev)); > + ut_asserteq(BUTTON_ON, button_get_state(dev)); > + > + return 0; > +} > +DM_TEST(dm_test_button_keys_adc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); >
On Thu, 11 Feb 2021 at 01:48, Marek Szyprowski <m.szyprowski@samsung.com> wrote: > > Add adc-keys device to the sandbox/test.dts and connect it to the channel > #3 of the sandbox_adc driver. The default values sampled by sandbox_adc > driver determines that button3 and button4 are released and button5 is > pressed. > > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> > --- > arch/sandbox/dts/test.dts | 24 ++++++++++++++++++- > configs/sandbox_defconfig | 1 + > test/dm/button.c | 50 +++++++++++++++++++++++++++++++++++++-- > 3 files changed, 72 insertions(+), 3 deletions(-) > Reviewed-by: Simon Glass <sjg@chromium.org>
Hi Marek, On 11/02/2021 09:47, Marek Szyprowski wrote: > Add adc-keys device to the sandbox/test.dts and connect it to the channel > #3 of the sandbox_adc driver. The default values sampled by sandbox_adc > driver determines that button3 and button4 are released and button5 is > pressed. > > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> > --- > arch/sandbox/dts/test.dts | 24 ++++++++++++++++++- > configs/sandbox_defconfig | 1 + > test/dm/button.c | 50 +++++++++++++++++++++++++++++++++++++-- > 3 files changed, 72 insertions(+), 3 deletions(-) > [...] Everything is reviewed, can you re-send with the missing "linux,code" ? and I'll push it. Neil
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index e95f4631bf..a32b019ae7 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -69,6 +69,27 @@ }; }; + buttons2 { + compatible = "adc-keys"; + io-channels = <&adc 3>; + keyup-threshold-microvolt = <3000000>; + + button-up { + label = "button3"; + press-threshold-microvolt = <1500000>; + }; + + button-down { + label = "button4"; + press-threshold-microvolt = <1000000>; + }; + + button-enter { + label = "button5"; + press-threshold-microvolt = <500000>; + }; + }; + cros_ec: cros-ec { reg = <0 0>; compatible = "google,cros-ec-sandbox"; @@ -587,8 +608,9 @@ i2c-eeprom = <&bootcount_i2c>; }; - adc@0 { + adc: adc@0 { compatible = "sandbox,adc"; + #io-channel-cells = <1>; vdd-supply = <&buck2>; vss-microvolts = <0>; }; diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 0c7674efc9..3731bf05ff 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -122,6 +122,7 @@ CONFIG_DM_BOOTCOUNT=y CONFIG_DM_BOOTCOUNT_RTC=y CONFIG_DM_BOOTCOUNT_I2C_EEPROM=y CONFIG_BUTTON=y +CONFIG_BUTTON_ADC=y CONFIG_BUTTON_GPIO=y CONFIG_CLK=y CONFIG_CLK_COMPOSITE_CCF=y diff --git a/test/dm/button.c b/test/dm/button.c index ecaa47cf5f..f8a7fab61d 100644 --- a/test/dm/button.c +++ b/test/dm/button.c @@ -7,7 +7,10 @@ #include <common.h> #include <dm.h> +#include <adc.h> #include <button.h> +#include <power/regulator.h> +#include <power/sandbox_pmic.h> #include <asm/gpio.h> #include <dm/test.h> #include <test/ut.h> @@ -17,11 +20,20 @@ static int dm_test_button_base(struct unit_test_state *uts) { struct udevice *dev; - /* Get the top-level device */ + /* Get the top-level gpio buttons device */ ut_assertok(uclass_get_device(UCLASS_BUTTON, 0, &dev)); + /* Get the 2 gpio buttons */ ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &dev)); ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, &dev)); - ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 3, &dev)); + + /* Get the top-level adc buttons device */ + ut_assertok(uclass_get_device(UCLASS_BUTTON, 3, &dev)); + /* Get the 3 adc buttons */ + ut_assertok(uclass_get_device(UCLASS_BUTTON, 4, &dev)); + ut_assertok(uclass_get_device(UCLASS_BUTTON, 5, &dev)); + ut_assertok(uclass_get_device(UCLASS_BUTTON, 6, &dev)); + + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 7, &dev)); return 0; } @@ -72,3 +84,37 @@ static int dm_test_button_label(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_button_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/* Test adc-keys driver */ +static int dm_test_button_keys_adc(struct unit_test_state *uts) +{ + struct udevice *supply; + struct udevice *dev; + int uV; + + ut_assertok(uclass_get_device_by_name(UCLASS_ADC, "adc@0", &dev)); + + ut_assertok(regulator_get_by_devname(SANDBOX_BUCK2_DEVNAME, &supply)); + ut_assertok(regulator_set_value(supply, SANDBOX_BUCK2_SET_UV)); + ut_asserteq(SANDBOX_BUCK2_SET_UV, regulator_get_value(supply)); + /* Update ADC plat and get new Vdd value */ + ut_assertok(adc_vdd_value(dev, &uV)); + ut_asserteq(SANDBOX_BUCK2_SET_UV, uV); + + /* + * sandbox-adc returns constant value on channel 3, is used by adc-keys: + * SANDBOX_ADC_CHANNEL3_DATA * SANDBOX_BUCK2_SET_UV / SANDBOX_ADC_DATA_MASK = + * 0x3000 * 3300000 / 0xffff = 618759uV + * This means that button3 and button4 are released and button5 + * is pressed. + */ + ut_assertok(button_get_by_label("button3", &dev)); + ut_asserteq(BUTTON_OFF, button_get_state(dev)); + ut_assertok(button_get_by_label("button4", &dev)); + ut_asserteq(BUTTON_OFF, button_get_state(dev)); + ut_assertok(button_get_by_label("button5", &dev)); + ut_asserteq(BUTTON_ON, button_get_state(dev)); + + return 0; +} +DM_TEST(dm_test_button_keys_adc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Add adc-keys device to the sandbox/test.dts and connect it to the channel #3 of the sandbox_adc driver. The default values sampled by sandbox_adc driver determines that button3 and button4 are released and button5 is pressed. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> --- arch/sandbox/dts/test.dts | 24 ++++++++++++++++++- configs/sandbox_defconfig | 1 + test/dm/button.c | 50 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 3 deletions(-) -- 2.17.1