mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-11 07:24:46 +00:00
button: qcom-pmic: add software debounce
This helps with reliability on some platforms. We should probably also configure the hardware debounce timer eventually. Link: https://lore.kernel.org/r/20241113045109.1838241-1-caleb.connolly@linaro.org Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
This commit is contained in:
parent
8376161a03
commit
709ecea592
1 changed files with 12 additions and 2 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <power/pmic.h>
|
||||
#include <spmi/spmi.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <time.h>
|
||||
|
||||
#define REG_TYPE 0x4
|
||||
#define REG_SUBTYPE 0x5
|
||||
|
@ -31,6 +32,7 @@ struct qcom_pmic_btn_priv {
|
|||
u32 status_bit;
|
||||
int code;
|
||||
struct udevice *pmic;
|
||||
ulong last_release_time;
|
||||
};
|
||||
|
||||
#define PON_INT_RT_STS 0x10
|
||||
|
@ -42,13 +44,21 @@ struct qcom_pmic_btn_priv {
|
|||
static enum button_state_t qcom_pwrkey_get_state(struct udevice *dev)
|
||||
{
|
||||
struct qcom_pmic_btn_priv *priv = dev_get_priv(dev);
|
||||
bool pressed;
|
||||
int reg;
|
||||
|
||||
int reg = pmic_reg_read(priv->pmic, priv->base + PON_INT_RT_STS);
|
||||
if (get_timer_us(0) - priv->last_release_time < 25000)
|
||||
return BUTTON_OFF;
|
||||
|
||||
reg = pmic_reg_read(priv->pmic, priv->base + PON_INT_RT_STS);
|
||||
if (reg < 0)
|
||||
return 0;
|
||||
|
||||
return (reg & BIT(priv->status_bit)) != 0;
|
||||
pressed = !!(reg & BIT(priv->status_bit));
|
||||
if (!pressed)
|
||||
priv->last_release_time = get_timer_us(0);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
static int qcom_pwrkey_get_code(struct udevice *dev)
|
||||
|
|
Loading…
Add table
Reference in a new issue