2018-04-04 08:20:27

by Stefan Popa

[permalink] [raw]
Subject: [PATCH 3/3] adp5061: Add support for charging voltage limit enable

This patch adds the option to activate/deactivate the charging voltage
limit. If activated, the charger prevents charging until the battery
voltage drops below the VCHG_VLIM threshold.

This option is not configurable via the power_supply properties,
therefore, access via sysfs was provided to examine and modify this
attribute on the fly.

Signed-off-by: Stefan Popa <[email protected]>
---
.../ABI/testing/sysfs-class-power-adp5061 | 13 ++++++
drivers/power/supply/adp5061.c | 46 ++++++++++++++++++++++
2 files changed, 59 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-power-adp5061 b/Documentation/ABI/testing/sysfs-class-power-adp5061
index 0d056aa..25064c1 100644
--- a/Documentation/ABI/testing/sysfs-class-power-adp5061
+++ b/Documentation/ABI/testing/sysfs-class-power-adp5061
@@ -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
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
index 7cd2e67..5931e45 100644
--- a/drivers/power/supply/adp5061.c
+++ b/drivers/power/supply/adp5061.c
@@ -83,6 +83,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)
+
#define ADP5061_NO_BATTERY 0x01
#define ADP5061_ICHG_MAX 1300 // mA

@@ -736,10 +740,52 @@ static int charging_enabled_store(struct device *dev,
return count;
}

+static int charging_vlim_enabled_show(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, &regval);
+ if (ret < 0)
+ return ret;
+
+ regval = (regval & ADP5061_FUNC_SET_2_EN_CHG_VLIM_MSK) >> 5;
+ return sprintf(buf, "%d\n", regval);
+}
+
+static int charging_vlim_enabled_store(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_RW(charging_enabled);
+static DEVICE_ATTR_RW(charging_vlim_enabled);

static struct attribute *adp5061_attributes[] = {
&dev_attr_charging_enabled.attr,
+ &dev_attr_charging_vlim_enabled.attr,
NULL
};

--
2.7.4



2018-04-10 09:57:45

by Stefan Popa

[permalink] [raw]
Subject: [PATCH v2 3/3] adp5061: Add support for charging voltage limit enable

This patch adds the option to activate/deactivate the charging voltage
limit. If activated, the charger prevents charging until the battery
voltage drops below the VCHG_VLIM threshold.

This option is not configurable via the power_supply properties,
therefore, access via sysfs was provided to examine and modify this
attribute on the fly.

Signed-off-by: Stefan Popa <[email protected]>
---
Changes in v2:
- Fixed the kbuild test error by changing the type of the
charging_vlim_enabled_show() and charging_vlim_enabled_store()
functions from int to ssize_t.

.../ABI/testing/sysfs-class-power-adp5061 | 13 ++++++
drivers/power/supply/adp5061.c | 46 ++++++++++++++++++++++
2 files changed, 59 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-power-adp5061 b/Documentation/ABI/testing/sysfs-class-power-adp5061
index 0d056aa..25064c1 100644
--- a/Documentation/ABI/testing/sysfs-class-power-adp5061
+++ b/Documentation/ABI/testing/sysfs-class-power-adp5061
@@ -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
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
index 99871e6..9716059 100644
--- a/drivers/power/supply/adp5061.c
+++ b/drivers/power/supply/adp5061.c
@@ -84,6 +84,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)
+
#define ADP5061_NO_BATTERY 0x01
#define ADP5061_ICHG_MAX 1300 // mA

@@ -737,10 +741,52 @@ static ssize_t charging_enabled_store(struct device *dev,
return count;
}

+static ssize_t charging_vlim_enabled_show(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, &regval);
+ if (ret < 0)
+ return ret;
+
+ regval = (regval & ADP5061_FUNC_SET_2_EN_CHG_VLIM_MSK) >> 5;
+ return sprintf(buf, "%d\n", regval);
+}
+
+static ssize_t charging_vlim_enabled_store(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_RW(charging_enabled);
+static DEVICE_ATTR_RW(charging_vlim_enabled);

static struct attribute *adp5061_attributes[] = {
&dev_attr_charging_enabled.attr,
+ &dev_attr_charging_vlim_enabled.attr,
NULL
};

--
2.7.4


2018-04-11 15:16:36

by Stefan Popa

[permalink] [raw]
Subject: [PATCH v3 4/4] adp5061: Add support for charging voltage limit enable

This patch adds the option to activate/deactivate the charging voltage
limit. If activated, the charger prevents charging until the battery
voltage drops below the VCHG_VLIM threshold.

This option is not configurable via the power_supply properties,
therefore, access via sysfs was provided to examine and modify this
attribute on the fly.

Signed-off-by: Stefan Popa <[email protected]>
---
Changes in v2:
- Fixed the kbuild test error by changing the type of the
charging_vlim_enabled_show() and charging_vlim_enabled_store()
functions from int to ssize_t.
Changes in v3:
- Nothing changed, just to follow the patch set version.

.../ABI/testing/sysfs-class-power-adp5061 | 13 ++++++
drivers/power/supply/adp5061.c | 46 ++++++++++++++++++++++
2 files changed, 59 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-power-adp5061 b/Documentation/ABI/testing/sysfs-class-power-adp5061
index 0d056aa..25064c1 100644
--- a/Documentation/ABI/testing/sysfs-class-power-adp5061
+++ b/Documentation/ABI/testing/sysfs-class-power-adp5061
@@ -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
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
index 99871e6..9716059 100644
--- a/drivers/power/supply/adp5061.c
+++ b/drivers/power/supply/adp5061.c
@@ -84,6 +84,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)
+
#define ADP5061_NO_BATTERY 0x01
#define ADP5061_ICHG_MAX 1300 // mA

@@ -737,10 +741,52 @@ static ssize_t charging_enabled_store(struct device *dev,
return count;
}

+static ssize_t charging_vlim_enabled_show(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, &regval);
+ if (ret < 0)
+ return ret;
+
+ regval = (regval & ADP5061_FUNC_SET_2_EN_CHG_VLIM_MSK) >> 5;
+ return sprintf(buf, "%d\n", regval);
+}
+
+static ssize_t charging_vlim_enabled_store(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_RW(charging_enabled);
+static DEVICE_ATTR_RW(charging_vlim_enabled);

static struct attribute *adp5061_attributes[] = {
&dev_attr_charging_enabled.attr,
+ &dev_attr_charging_vlim_enabled.attr,
NULL
};

--
2.7.4


2019-10-11 11:02:58

by Alexandru Ardelean

[permalink] [raw]
Subject: [PATCH v3][RESEND] adp5061: Add support for charging voltage limit enable

From: Stefan Popa <[email protected]>

This patch adds the option to activate/deactivate the charging voltage
limit. If activated, the charger prevents charging until the battery
voltage drops below the VCHG_VLIM threshold.

This option is not configurable via the power_supply properties,
therefore, access via sysfs was provided to examine and modify this
attribute on the fly.

Signed-off-by: Stefan Popa <[email protected]>
Signed-off-by: Alexandru Ardelean <[email protected]>
---

I could not find any traces about this patch being denied and why.
So this is a RESEND to [re]trigger a discussion if needed.

.../ABI/testing/sysfs-class-power-adp5061 | 13 +++++
drivers/power/supply/adp5061.c | 47 +++++++++++++++++++
2 files changed, 60 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-power-adp5061 b/Documentation/ABI/testing/sysfs-class-power-adp5061
index 0d056aa103b5..25064c13ea7b 100644
--- a/Documentation/ABI/testing/sysfs-class-power-adp5061
+++ b/Documentation/ABI/testing/sysfs-class-power-adp5061
@@ -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
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
index 6e09a6b710e8..41b24cadd2c9 100644
--- a/drivers/power/supply/adp5061.c
+++ b/drivers/power/supply/adp5061.c
@@ -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, &regval);
+ 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
};

--
2.20.1