Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Leonard Crestez and committed by
Lee Jones
e25547f8 907bf9d6

+42
+42
drivers/mfd/rohm-bd718x7.c
··· 81 81 .cache_type = REGCACHE_RBTREE, 82 82 }; 83 83 84 + static int bd718xx_init_press_duration(struct bd718xx *bd718xx) 85 + { 86 + struct device* dev = bd718xx->chip.dev; 87 + u32 short_press_ms, long_press_ms; 88 + u32 short_press_value, long_press_value; 89 + int ret; 90 + 91 + ret = of_property_read_u32(dev->of_node, "rohm,short-press-ms", 92 + &short_press_ms); 93 + if (!ret) { 94 + short_press_value = min(15u, (short_press_ms + 250) / 500); 95 + ret = regmap_update_bits(bd718xx->chip.regmap, 96 + BD718XX_REG_PWRONCONFIG0, 97 + BD718XX_PWRBTN_PRESS_DURATION_MASK, 98 + short_press_value); 99 + if (ret) { 100 + dev_err(dev, "Failed to init pwron short press\n"); 101 + return ret; 102 + } 103 + } 104 + 105 + ret = of_property_read_u32(dev->of_node, "rohm,long-press-ms", 106 + &long_press_ms); 107 + if (!ret) { 108 + long_press_value = min(15u, (long_press_ms + 500) / 1000); 109 + ret = regmap_update_bits(bd718xx->chip.regmap, 110 + BD718XX_REG_PWRONCONFIG1, 111 + BD718XX_PWRBTN_PRESS_DURATION_MASK, 112 + long_press_value); 113 + if (ret) { 114 + dev_err(dev, "Failed to init pwron long press\n"); 115 + return ret; 116 + } 117 + } 118 + 119 + return 0; 120 + } 121 + 84 122 static int bd718xx_i2c_probe(struct i2c_client *i2c, 85 123 const struct i2c_device_id *id) 86 124 { ··· 155 117 dev_err(&i2c->dev, "Failed to add irq_chip\n"); 156 118 return ret; 157 119 } 120 + 121 + ret = bd718xx_init_press_duration(bd718xx); 122 + if (ret) 123 + return ret; 158 124 159 125 ret = regmap_irq_get_virq(bd718xx->irq_data, BD718XX_INT_PWRBTN_S); 160 126