3 * Henrik Nordstrom <henrik@henriknordstrom.net>
5 * SPDX-License-Identifier: GPL-2.0+
11 static int axp152_write(enum axp152_reg reg, u8 val)
13 return i2c_write(0x30, reg, 1, &val, 1);
16 static int axp152_read(enum axp152_reg reg, u8 *val)
18 return i2c_read(0x30, reg, 1, val, 1);
21 static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
28 return (mvolt - min) / div;
31 int axp152_set_dcdc2(int mvolt)
36 target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
38 /* Do we really need to be this gentle? It has built-in voltage slope */
39 while ((rc = axp152_read(AXP152_DCDC2_VOLTAGE, ¤t)) == 0 &&
45 rc = axp152_write(AXP152_DCDC2_VOLTAGE, current);
52 int axp152_set_dcdc3(int mvolt)
54 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
56 return axp152_write(AXP152_DCDC3_VOLTAGE, target);
59 int axp152_set_dcdc4(int mvolt)
61 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
63 return axp152_write(AXP152_DCDC4_VOLTAGE, target);
66 int axp152_set_ldo2(int mvolt)
68 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
70 return axp152_write(AXP152_LDO2_VOLTAGE, target);
78 rc = axp152_read(AXP152_CHIP_VERSION, &ver);