Commit ba7e053e authored by Artur Weber's avatar Artur Weber Committed by Sebastian Reichel

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: default avatarHenrik Grimler <henrik@grimler.se>
Signed-off-by: default avatarArtur Weber <aweber.kernel@gmail.com>
Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240816-max77693-charger-extcon-v4-3-050a0a9bfea0@gmail.comSigned-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 3a3acf83
...@@ -197,12 +197,58 @@ static int max77693_get_online(struct regmap *regmap, int *val) ...@@ -197,12 +197,58 @@ static int max77693_get_online(struct regmap *regmap, int *val)
return 0; return 0;
} }
/*
* There are *two* current limit registers:
* - CHGIN limit, which limits the input current from the external charger;
* - Fast charge current limit, which limits the current going to the battery.
*/
static int max77693_get_input_current_limit(struct regmap *regmap, int *val)
{
unsigned int data;
int ret;
ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_09, &data);
if (ret < 0)
return ret;
data &= CHG_CNFG_09_CHGIN_ILIM_MASK;
data >>= CHG_CNFG_09_CHGIN_ILIM_SHIFT;
if (data <= 0x03)
/* The first four values (0x00..0x03) are 60mA */
*val = 60000;
else
*val = data * 20000; /* 20mA steps */
return 0;
}
static int max77693_get_fast_charge_current(struct regmap *regmap, int *val)
{
unsigned int data;
int ret;
ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_02, &data);
if (ret < 0)
return ret;
data &= CHG_CNFG_02_CC_MASK;
data >>= CHG_CNFG_02_CC_SHIFT;
*val = data * 33300; /* 33.3mA steps */
return 0;
}
static enum power_supply_property max77693_charger_props[] = { static enum power_supply_property max77693_charger_props[] = {
POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_CHARGE_TYPE, POWER_SUPPLY_PROP_CHARGE_TYPE,
POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_MANUFACTURER,
}; };
...@@ -231,6 +277,12 @@ static int max77693_charger_get_property(struct power_supply *psy, ...@@ -231,6 +277,12 @@ static int max77693_charger_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_ONLINE: case POWER_SUPPLY_PROP_ONLINE:
ret = max77693_get_online(regmap, &val->intval); ret = max77693_get_online(regmap, &val->intval);
break; break;
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
ret = max77693_get_input_current_limit(regmap, &val->intval);
break;
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
ret = max77693_get_fast_charge_current(regmap, &val->intval);
break;
case POWER_SUPPLY_PROP_MODEL_NAME: case POWER_SUPPLY_PROP_MODEL_NAME:
val->strval = max77693_charger_model; val->strval = max77693_charger_model;
break; break;
......
...@@ -217,6 +217,10 @@ enum max77693_charger_battery_state { ...@@ -217,6 +217,10 @@ enum max77693_charger_battery_state {
#define CHG_CNFG_01_CHGRSTRT_MASK (0x3 << CHG_CNFG_01_CHGRSTRT_SHIFT) #define CHG_CNFG_01_CHGRSTRT_MASK (0x3 << CHG_CNFG_01_CHGRSTRT_SHIFT)
#define CHG_CNFG_01_PQEN_MAKS BIT(CHG_CNFG_01_PQEN_SHIFT) #define CHG_CNFG_01_PQEN_MAKS BIT(CHG_CNFG_01_PQEN_SHIFT)
/* MAX77693_CHG_REG_CHG_CNFG_02 register */
#define CHG_CNFG_02_CC_SHIFT 0
#define CHG_CNFG_02_CC_MASK 0x3F
/* MAX77693_CHG_REG_CHG_CNFG_03 register */ /* MAX77693_CHG_REG_CHG_CNFG_03 register */
#define CHG_CNFG_03_TOITH_SHIFT 0 #define CHG_CNFG_03_TOITH_SHIFT 0
#define CHG_CNFG_03_TOTIME_SHIFT 3 #define CHG_CNFG_03_TOTIME_SHIFT 3
...@@ -244,6 +248,7 @@ enum max77693_charger_battery_state { ...@@ -244,6 +248,7 @@ enum max77693_charger_battery_state {
#define CHG_CNFG_12_VCHGINREG_MASK (0x3 << CHG_CNFG_12_VCHGINREG_SHIFT) #define CHG_CNFG_12_VCHGINREG_MASK (0x3 << CHG_CNFG_12_VCHGINREG_SHIFT)
/* MAX77693 CHG_CNFG_09 Register */ /* MAX77693 CHG_CNFG_09 Register */
#define CHG_CNFG_09_CHGIN_ILIM_SHIFT 0
#define CHG_CNFG_09_CHGIN_ILIM_MASK 0x7F #define CHG_CNFG_09_CHGIN_ILIM_MASK 0x7F
/* MAX77693 CHG_CTRL Register */ /* MAX77693 CHG_CTRL Register */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment