3 * Henrik Nordstrom <henrik@henriknordstrom.net>
5 * SPDX-License-Identifier: GPL-2.0+
12 AXP152_CHIP_VERSION = 0x3,
13 AXP152_DCDC2_VOLTAGE = 0x23,
14 AXP152_DCDC3_VOLTAGE = 0x27,
15 AXP152_DCDC4_VOLTAGE = 0x2B,
16 AXP152_LDO2_VOLTAGE = 0x2A,
17 AXP152_SHUTDOWN = 0x32,
20 #define AXP152_POWEROFF (1 << 7)
22 static int axp152_write(enum axp152_reg reg, u8 val)
24 return i2c_write(0x30, reg, 1, &val, 1);
27 static int axp152_read(enum axp152_reg reg, u8 *val)
29 return i2c_read(0x30, reg, 1, val, 1);
32 static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
39 return (mvolt - min) / div;
42 int axp152_set_dcdc2(int mvolt)
47 target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
49 /* Do we really need to be this gentle? It has built-in voltage slope */
50 while ((rc = axp152_read(AXP152_DCDC2_VOLTAGE, ¤t)) == 0 &&
56 rc = axp152_write(AXP152_DCDC2_VOLTAGE, current);
63 int axp152_set_dcdc3(int mvolt)
65 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
67 return axp152_write(AXP152_DCDC3_VOLTAGE, target);
70 int axp152_set_dcdc4(int mvolt)
72 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
74 return axp152_write(AXP152_DCDC4_VOLTAGE, target);
77 int axp152_set_ldo2(int mvolt)
79 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
81 return axp152_write(AXP152_LDO2_VOLTAGE, target);
89 rc = axp152_read(AXP152_CHIP_VERSION, &ver);