mirror of
https://github.com/torvalds/linux.git
synced 2026-06-01 11:03:43 +02:00
power: supply: max77705_charger: add writable properties
Add INPUT_CURRENT_LIMIT, CONSTANT_CHARGE_CURRENT properties as writeable to be able to control input power consumption and charging speed. Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
55af7b9bb6
commit
baedd8be70
|
|
@ -105,6 +105,17 @@ static int max77705_get_online(struct regmap *regmap, int *val)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int max77705_set_integer(struct max77705_charger_data *chg, enum max77705_field_idx fidx,
|
||||
unsigned int clamp_min, unsigned int clamp_max,
|
||||
unsigned int div, int val)
|
||||
{
|
||||
unsigned int regval;
|
||||
|
||||
regval = clamp_val(val, clamp_min, clamp_max) / div;
|
||||
|
||||
return regmap_field_write(chg->rfield[fidx], regval);
|
||||
}
|
||||
|
||||
static int max77705_check_battery(struct max77705_charger_data *chg, int *val)
|
||||
{
|
||||
unsigned int reg_data;
|
||||
|
|
@ -384,12 +395,55 @@ static int max77705_chg_get_property(struct power_supply *psy,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int max77705_set_property(struct power_supply *psy,
|
||||
enum power_supply_property psp,
|
||||
const union power_supply_propval *val)
|
||||
{
|
||||
struct max77705_charger_data *chg = power_supply_get_drvdata(psy);
|
||||
int err = 0;
|
||||
|
||||
switch (psp) {
|
||||
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
|
||||
err = max77705_set_integer(chg, MAX77705_CHG_CC_LIM,
|
||||
MAX77705_CURRENT_CHGIN_MIN,
|
||||
MAX77705_CURRENT_CHGIN_MAX,
|
||||
MAX77705_CURRENT_CHG_STEP,
|
||||
val->intval);
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
|
||||
err = max77705_set_integer(chg, MAX77705_CHG_CHGIN_LIM,
|
||||
MAX77705_CURRENT_CHGIN_MIN,
|
||||
MAX77705_CURRENT_CHGIN_MAX,
|
||||
MAX77705_CURRENT_CHGIN_STEP,
|
||||
val->intval);
|
||||
break;
|
||||
default:
|
||||
err = -EINVAL;
|
||||
}
|
||||
|
||||
return err;
|
||||
};
|
||||
|
||||
static int max77705_property_is_writeable(struct power_supply *psy,
|
||||
enum power_supply_property psp)
|
||||
{
|
||||
switch (psp) {
|
||||
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
|
||||
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct power_supply_desc max77705_charger_psy_desc = {
|
||||
.name = "max77705-charger",
|
||||
.type = POWER_SUPPLY_TYPE_USB,
|
||||
.type = POWER_SUPPLY_TYPE_USB,
|
||||
.properties = max77705_charger_props,
|
||||
.property_is_writeable = max77705_property_is_writeable,
|
||||
.num_properties = ARRAY_SIZE(max77705_charger_props),
|
||||
.get_property = max77705_chg_get_property,
|
||||
.set_property = max77705_set_property,
|
||||
};
|
||||
|
||||
static void max77705_chgin_isr_work(struct work_struct *work)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user