Skip to content

Commit 2caeb56

Browse files
Villemoesalexandrebelloni
authored andcommitted
rtc: isl12022: add support for trip level DT binding
Implement support for using the values given in the isil,battery-trip-levels-microvolt property to set appropriate values in the VB85TP/VB75TP bits in the PWR_VBAT register. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Link: https://lore.kernel.org/r/20230615105826.411953-5-linux@rasmusvillemoes.dk Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 69b569c commit 2caeb56

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

drivers/rtc/rtc-isl12022.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include <linux/bcd.h>
12+
#include <linux/bitfield.h>
1213
#include <linux/err.h>
1314
#include <linux/hwmon.h>
1415
#include <linux/i2c.h>
@@ -31,6 +32,8 @@
3132
#define ISL12022_REG_SR 0x07
3233
#define ISL12022_REG_INT 0x08
3334

35+
#define ISL12022_REG_PWR_VBAT 0x0a
36+
3437
#define ISL12022_REG_BETA 0x0d
3538
#define ISL12022_REG_TEMP_L 0x28
3639

@@ -42,6 +45,9 @@
4245

4346
#define ISL12022_INT_WRTC (1 << 6)
4447

48+
#define ISL12022_REG_VB85_MASK GENMASK(5, 3)
49+
#define ISL12022_REG_VB75_MASK GENMASK(2, 0)
50+
4551
#define ISL12022_BETA_TSE (1 << 7)
4652

4753
static umode_t isl12022_hwmon_is_visible(const void *data,
@@ -209,6 +215,38 @@ static const struct regmap_config regmap_config = {
209215
.use_single_write = true,
210216
};
211217

218+
static const u32 trip_levels[2][7] = {
219+
{ 2125000, 2295000, 2550000, 2805000, 3060000, 4250000, 4675000 },
220+
{ 1875000, 2025000, 2250000, 2475000, 2700000, 3750000, 4125000 },
221+
};
222+
223+
static void isl12022_set_trip_levels(struct device *dev)
224+
{
225+
struct regmap *regmap = dev_get_drvdata(dev);
226+
u32 levels[2] = {0, 0};
227+
int ret, i, j, x[2];
228+
u8 val, mask;
229+
230+
device_property_read_u32_array(dev, "isil,battery-trip-levels-microvolt",
231+
levels, 2);
232+
233+
for (i = 0; i < 2; i++) {
234+
for (j = 0; j < ARRAY_SIZE(trip_levels[i]) - 1; j++) {
235+
if (levels[i] <= trip_levels[i][j])
236+
break;
237+
}
238+
x[i] = j;
239+
}
240+
241+
val = FIELD_PREP(ISL12022_REG_VB85_MASK, x[0]) |
242+
FIELD_PREP(ISL12022_REG_VB75_MASK, x[1]);
243+
mask = ISL12022_REG_VB85_MASK | ISL12022_REG_VB75_MASK;
244+
245+
ret = regmap_update_bits(regmap, ISL12022_REG_PWR_VBAT, mask, val);
246+
if (ret)
247+
dev_warn(dev, "unable to set battery alarm levels: %d\n", ret);
248+
}
249+
212250
static int isl12022_probe(struct i2c_client *client)
213251
{
214252
struct rtc_device *rtc;
@@ -225,6 +263,7 @@ static int isl12022_probe(struct i2c_client *client)
225263

226264
dev_set_drvdata(&client->dev, regmap);
227265

266+
isl12022_set_trip_levels(&client->dev);
228267
isl12022_hwmon_register(&client->dev);
229268

230269
rtc = devm_rtc_allocate_device(&client->dev);

0 commit comments

Comments
 (0)