@@ -8,3 +8,16 @@ Description:
Valid values:
- 1: enabled
- 0: disabled
+
+What: /sys/class/power_supply/adp5061/charging_vlim_enabled
+Description:
+ Enable/disable charging voltage limit
+
+ The ADP5061 charging voltage limit can be enabled by setting
+ this attribute to 1. When enabled, the charger prevents charging
+ until the battery voltage drops bellow the VCHG_VLIM threshold.
+ See device datasheet for details.
+
+ Valid values:
+ - 1: enabled
+ - 0: disabled
@@ -78,6 +78,10 @@
#define ADP5061_FUNC_SET_1_EN_CHG_MSK BIT(0)
#define ADP5061_FUNC_SET_1_EN_CHG_MODE(x) (((x) & 0x01) << 0)
+/* ADP5061_FUNC_SET_2 */
+#define ADP5061_FUNC_SET_2_EN_CHG_VLIM_MSK BIT(5)
+#define ADP5061_FUNC_SET_2_EN_CHG_VLIM_MODE(x) (((x) & 0x01) << 5)
+
/* ADP5061_IEND */
#define ADP5061_IEND_IEND_MSK GENMASK(7, 5)
#define ADP5061_IEND_IEND_MODE(x) (((x) & 0x07) << 5)
@@ -735,11 +739,54 @@ static int adp5061_set_charging_enabled(struct device *dev,
return count;
}
+static int adp5061_get_chg_vlim_enabled(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct power_supply *psy = dev_get_drvdata(dev);
+ struct adp5061_state *st = power_supply_get_drvdata(psy);
+ unsigned int regval;
+ int ret;
+
+ ret = regmap_read(st->regmap, ADP5061_FUNC_SET_2, ®val);
+ if (ret < 0)
+ return ret;
+
+ regval = (regval & ADP5061_FUNC_SET_2_EN_CHG_VLIM_MSK) >> 5;
+ return sprintf(buf, "%d\n", regval);
+}
+
+static int adp5061_set_chg_vlim_enabled(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct power_supply *psy = dev_get_drvdata(dev);
+ struct adp5061_state *st = power_supply_get_drvdata(psy);
+ u8 chg_vlim_en;
+ int ret;
+
+ ret = kstrtou8(buf, 0, &chg_vlim_en);
+ if (ret < 0)
+ return ret;
+
+ ret = regmap_update_bits(st->regmap, ADP5061_FUNC_SET_2,
+ ADP5061_FUNC_SET_2_EN_CHG_VLIM_MSK,
+ ADP5061_FUNC_SET_2_EN_CHG_VLIM_MODE(!!chg_vlim_en));
+
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+
static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
adp5061_set_charging_enabled);
+static DEVICE_ATTR(charging_vlim_enabled, 0644, adp5061_get_chg_vlim_enabled,
+ adp5061_set_chg_vlim_enabled);
static struct attribute *adp5061_attributes[] = {
&dev_attr_charging_enabled.attr,
+ &dev_attr_charging_vlim_enabled.attr,
NULL
};