diff options
author | Leonard Crestez <leonard.crestez@nxp.com> | 2019-05-21 23:41:14 +0300 |
---|---|---|
committer | Lee Jones <lee.jones@linaro.org> | 2019-07-02 14:11:31 +0300 |
commit | e25547f899a531ecea1fcca975752872682ec564 (patch) | |
tree | 115e02c15074a3738b5cb14b6c5ce7854140fa6d /drivers | |
parent | 907bf9d65f2da9b7ea1b5aa0c1b8d5950f29356d (diff) | |
download | linux-e25547f899a531ecea1fcca975752872682ec564.tar.xz |
mfd: bd718x7: Make power button press duration configurable
Allow overwriting the values in BD718XX_REG_PWRONCONFIG0 and
BD718XX_REG_PWRONCONFIG1 via devicetree. Read values in milliseconds and
attempt to round them to something supported by the hardware.
Keep existing values (from bootloader or OTP) if property is not
present.
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-By: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
[Lee: Fixed-up merge/API conflict]
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mfd/rohm-bd718x7.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/mfd/rohm-bd718x7.c b/drivers/mfd/rohm-bd718x7.c index af91092c7fca..85e7f5133365 100644 --- a/drivers/mfd/rohm-bd718x7.c +++ b/drivers/mfd/rohm-bd718x7.c @@ -81,6 +81,44 @@ static const struct regmap_config bd718xx_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +static int bd718xx_init_press_duration(struct bd718xx *bd718xx) +{ + struct device* dev = bd718xx->chip.dev; + u32 short_press_ms, long_press_ms; + u32 short_press_value, long_press_value; + int ret; + + ret = of_property_read_u32(dev->of_node, "rohm,short-press-ms", + &short_press_ms); + if (!ret) { + short_press_value = min(15u, (short_press_ms + 250) / 500); + ret = regmap_update_bits(bd718xx->chip.regmap, + BD718XX_REG_PWRONCONFIG0, + BD718XX_PWRBTN_PRESS_DURATION_MASK, + short_press_value); + if (ret) { + dev_err(dev, "Failed to init pwron short press\n"); + return ret; + } + } + + ret = of_property_read_u32(dev->of_node, "rohm,long-press-ms", + &long_press_ms); + if (!ret) { + long_press_value = min(15u, (long_press_ms + 500) / 1000); + ret = regmap_update_bits(bd718xx->chip.regmap, + BD718XX_REG_PWRONCONFIG1, + BD718XX_PWRBTN_PRESS_DURATION_MASK, + long_press_value); + if (ret) { + dev_err(dev, "Failed to init pwron long press\n"); + return ret; + } + } + + return 0; +} + static int bd718xx_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -118,6 +156,10 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c, return ret; } + ret = bd718xx_init_press_duration(bd718xx); + if (ret) + return ret; + ret = regmap_irq_get_virq(bd718xx->irq_data, BD718XX_INT_PWRBTN_S); if (ret < 0) { |