Skip to content

Commit ba7e053

Browse files
refractionwaresre
authored andcommitted
power: supply: max77693: Expose input current limit and CC current properties
There are two charger current limit registers: - Fast charge current limit (which controls current going from the charger to the battery); - CHGIN input current limit (which controls current going into the charger through the cable). Add the necessary functions to retrieve the CHGIN input limit (from CHARGER regulator) and maximum fast charge current values, and expose them as power supply properties. Tested-by: Henrik Grimler <[email protected]> Signed-off-by: Artur Weber <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 3a3acf8 commit ba7e053

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

drivers/power/supply/max77693_charger.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,58 @@ static int max77693_get_online(struct regmap *regmap, int *val)
197197
return 0;
198198
}
199199

200+
/*
201+
* There are *two* current limit registers:
202+
* - CHGIN limit, which limits the input current from the external charger;
203+
* - Fast charge current limit, which limits the current going to the battery.
204+
*/
205+
206+
static int max77693_get_input_current_limit(struct regmap *regmap, int *val)
207+
{
208+
unsigned int data;
209+
int ret;
210+
211+
ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_09, &data);
212+
if (ret < 0)
213+
return ret;
214+
215+
data &= CHG_CNFG_09_CHGIN_ILIM_MASK;
216+
data >>= CHG_CNFG_09_CHGIN_ILIM_SHIFT;
217+
218+
if (data <= 0x03)
219+
/* The first four values (0x00..0x03) are 60mA */
220+
*val = 60000;
221+
else
222+
*val = data * 20000; /* 20mA steps */
223+
224+
return 0;
225+
}
226+
227+
static int max77693_get_fast_charge_current(struct regmap *regmap, int *val)
228+
{
229+
unsigned int data;
230+
int ret;
231+
232+
ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_02, &data);
233+
if (ret < 0)
234+
return ret;
235+
236+
data &= CHG_CNFG_02_CC_MASK;
237+
data >>= CHG_CNFG_02_CC_SHIFT;
238+
239+
*val = data * 33300; /* 33.3mA steps */
240+
241+
return 0;
242+
}
243+
200244
static enum power_supply_property max77693_charger_props[] = {
201245
POWER_SUPPLY_PROP_STATUS,
202246
POWER_SUPPLY_PROP_CHARGE_TYPE,
203247
POWER_SUPPLY_PROP_HEALTH,
204248
POWER_SUPPLY_PROP_PRESENT,
205249
POWER_SUPPLY_PROP_ONLINE,
250+
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
251+
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
206252
POWER_SUPPLY_PROP_MODEL_NAME,
207253
POWER_SUPPLY_PROP_MANUFACTURER,
208254
};
@@ -231,6 +277,12 @@ static int max77693_charger_get_property(struct power_supply *psy,
231277
case POWER_SUPPLY_PROP_ONLINE:
232278
ret = max77693_get_online(regmap, &val->intval);
233279
break;
280+
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
281+
ret = max77693_get_input_current_limit(regmap, &val->intval);
282+
break;
283+
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
284+
ret = max77693_get_fast_charge_current(regmap, &val->intval);
285+
break;
234286
case POWER_SUPPLY_PROP_MODEL_NAME:
235287
val->strval = max77693_charger_model;
236288
break;

include/linux/mfd/max77693-private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ enum max77693_charger_battery_state {
217217
#define CHG_CNFG_01_CHGRSTRT_MASK (0x3 << CHG_CNFG_01_CHGRSTRT_SHIFT)
218218
#define CHG_CNFG_01_PQEN_MAKS BIT(CHG_CNFG_01_PQEN_SHIFT)
219219

220+
/* MAX77693_CHG_REG_CHG_CNFG_02 register */
221+
#define CHG_CNFG_02_CC_SHIFT 0
222+
#define CHG_CNFG_02_CC_MASK 0x3F
223+
220224
/* MAX77693_CHG_REG_CHG_CNFG_03 register */
221225
#define CHG_CNFG_03_TOITH_SHIFT 0
222226
#define CHG_CNFG_03_TOTIME_SHIFT 3
@@ -244,6 +248,7 @@ enum max77693_charger_battery_state {
244248
#define CHG_CNFG_12_VCHGINREG_MASK (0x3 << CHG_CNFG_12_VCHGINREG_SHIFT)
245249

246250
/* MAX77693 CHG_CNFG_09 Register */
251+
#define CHG_CNFG_09_CHGIN_ILIM_SHIFT 0
247252
#define CHG_CNFG_09_CHGIN_ILIM_MASK 0x7F
248253

249254
/* MAX77693 CHG_CTRL Register */

0 commit comments

Comments
 (0)