diff options
author | Tom Rini <trini@konsulko.com> | 2022-02-11 12:02:31 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-02-11 12:02:31 -0500 |
commit | dd1c255cbc6d3bdf3211a7c9d8fd36e7696e39bb (patch) | |
tree | 5886f2d3c62f227f62cb4c67ac30a8f8ed9712f8 /drivers/button/button-adc.c | |
parent | 86752b2814091bd8df30bdbf38768924b60cccab (diff) | |
parent | 73cde90c8badbeba32524c2708d26fea805fba1e (diff) |
Merge branch '2022-02-11-assorted-updates-and-fixes'
A partial list:
- fw_env updates, a new testcase for mkimage -o ..., nop-phy reset-gpios
support, DFU updates, kaslr-seed support in extlinux.conf, modern
"partitions" support in mtd device tree
Diffstat (limited to 'drivers/button/button-adc.c')
-rw-r--r-- | drivers/button/button-adc.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/drivers/button/button-adc.c b/drivers/button/button-adc.c index fd896c76f9d..9c24c960e6f 100644 --- a/drivers/button/button-adc.c +++ b/drivers/button/button-adc.c @@ -55,7 +55,7 @@ static int button_adc_of_to_plat(struct udevice *dev) struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev); struct button_adc_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args args; - u32 threshold, up_threshold, t; + u32 down_threshold = 0, up_threshold, voltage, t; ofnode node; int ret; @@ -78,7 +78,7 @@ static int button_adc_of_to_plat(struct udevice *dev) return ret; ret = ofnode_read_u32(dev_ofnode(dev), "press-threshold-microvolt", - &threshold); + &voltage); if (ret) return ret; @@ -87,13 +87,24 @@ static int button_adc_of_to_plat(struct udevice *dev) if (ret) return ret; - if (t > threshold) + if (t > voltage && t < up_threshold) up_threshold = t; + else if (t < voltage && t > down_threshold) + down_threshold = t; } priv->channel = args.args[0]; - priv->min = threshold; - priv->max = up_threshold; + + /* + * Define the voltage range such that the button is only pressed + * when the voltage is closest to its own press-threshold-microvolt + */ + if (down_threshold == 0) + priv->min = 0; + else + priv->min = down_threshold + (voltage - down_threshold) / 2; + + priv->max = voltage + (up_threshold - voltage) / 2; return ret; } |