power: supply: qti_battery_charger: Implement charging_enabled node

Change-Id: Id927c07bab305a63665edfe44228051d76951933
This commit is contained in:
Tommaso Fonda 2025-01-06 21:23:26 +01:00 committed by Michael Bestas
parent 3bc8134025
commit 7a0d694b18

View file

@ -1786,6 +1786,55 @@ static ssize_t ship_mode_en_show(struct class *c, struct class_attribute *attr,
}
static CLASS_ATTR_RW(ship_mode_en);
static ssize_t charging_enabled_store(struct class *c,
struct class_attribute *attr,
const char *buf, size_t count)
{
struct battery_chg_dev *bcdev = container_of(c, struct battery_chg_dev,
battery_class);
int rc;
bool val;
if (kstrtobool(buf, &val))
return -EINVAL;
if (val) {
/*
* Enable charging, i.e. set the restricted current back to
* its default value and unset the restriction boolean flag.
*/
rc = __battery_psy_set_charge_current(bcdev,
DEFAULT_RESTRICT_FCC_UA);
if (rc < 0)
return rc;
bcdev->restrict_fcc_ua = DEFAULT_RESTRICT_FCC_UA;
bcdev->restrict_chg_en = 0;
} else {
/*
* Disable charging, i.e. set the restricted current to zero
* and set the restriction boolean flag.
*/
rc = __battery_psy_set_charge_current(bcdev, 0 /* 0 uA */);
if (rc < 0)
return rc;
bcdev->restrict_fcc_ua = 0;
bcdev->restrict_chg_en = 1;
}
return count;
}
static ssize_t charging_enabled_show(struct class *c,
struct class_attribute *attr, char *buf)
{
struct battery_chg_dev *bcdev = container_of(c, struct battery_chg_dev,
battery_class);
bool val = !bcdev->restrict_chg_en && bcdev->restrict_fcc_ua;
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}
static CLASS_ATTR_RW(charging_enabled);
static struct attribute *battery_class_attrs[] = {
&class_attr_soh.attr,
&class_attr_resistance.attr,
@ -1802,6 +1851,7 @@ static struct attribute *battery_class_attrs[] = {
&class_attr_restrict_cur.attr,
&class_attr_usb_real_type.attr,
&class_attr_usb_typec_compliant.attr,
&class_attr_charging_enabled.attr,
NULL,
};
ATTRIBUTE_GROUPS(battery_class);