mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-16 05:26:07 +00:00
power: supply: gpio-charger: add support for default charge current limit
With DT properties charge-current-limit-gpios and charge-current-limit-mapping one can define charge current limits in uA using up to 32 GPIOs. At the moment the driver defaults to smallest charge current limitation for safety reasons. When disabling charging is supported, which should be common, the driver defaults to non charging on probe. By having a default, charging can be enabled on probe for such devices. Signed-off-by: Dimitri Fedrau <dimitri.fedrau@liebherr.com> Link: https://lore.kernel.org/r/20241218-default-charge-current-limit-v3-2-b26118cf06b5@liebherr.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
0a219d6fd7
commit
de68987480
@ -195,6 +195,8 @@ static int init_charge_current_limit(struct device *dev,
|
||||
{
|
||||
int i, len;
|
||||
u32 cur_limit = U32_MAX;
|
||||
bool set_def_limit;
|
||||
u32 def_limit;
|
||||
|
||||
gpio_charger->current_limit_gpios = devm_gpiod_get_array_optional(dev,
|
||||
"charge-current-limit", GPIOD_OUT_LOW);
|
||||
@ -228,6 +230,9 @@ static int init_charge_current_limit(struct device *dev,
|
||||
if (len < 0)
|
||||
return len;
|
||||
|
||||
set_def_limit = !device_property_read_u32(dev,
|
||||
"charge-current-limit-default-microamp",
|
||||
&def_limit);
|
||||
for (i=0; i < gpio_charger->current_limit_map_size; i++) {
|
||||
if (gpio_charger->current_limit_map[i].limit_ua > cur_limit) {
|
||||
dev_err(dev, "charge-current-limit-mapping not sorted by current in descending order\n");
|
||||
@ -235,7 +240,15 @@ static int init_charge_current_limit(struct device *dev,
|
||||
}
|
||||
|
||||
cur_limit = gpio_charger->current_limit_map[i].limit_ua;
|
||||
if (set_def_limit && def_limit == cur_limit) {
|
||||
set_charge_current_limit(gpio_charger, cur_limit);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (set_def_limit)
|
||||
dev_warn(dev, "charge-current-limit-default-microamp %u not listed in charge-current-limit-mapping\n",
|
||||
def_limit);
|
||||
|
||||
/* default to smallest current limitation for safety reasons */
|
||||
len = gpio_charger->current_limit_map_size - 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user