Messages in this thread Patch in this message | | | From | Alexandru Ardelean <> | Subject | [PATCH v3][RESEND] adp5061: Add support for battery charging enable | Date | Fri, 11 Oct 2019 13:56:49 +0300 |
| |
From: Stefan Popa <stefan.popa@analog.com>
This patch adds the option to enable/disable battery charging. 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 <stefan.popa@analog.com> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> ---
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 | 10 +++ drivers/power/supply/adp5061.c | 63 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-power-adp5061
diff --git a/Documentation/ABI/testing/sysfs-class-power-adp5061 b/Documentation/ABI/testing/sysfs-class-power-adp5061 new file mode 100644 index 000000000000..0d056aa103b5 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-power-adp5061 @@ -0,0 +1,10 @@ +What: /sys/class/power_supply/adp5061/charging_enabled +Description: + Enable/disable battery charging. + + The ADP5061 charging function can be enabled by setting + this attribute to 1. 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 003557043ab3..6e09a6b710e8 100644 --- a/drivers/power/supply/adp5061.c +++ b/drivers/power/supply/adp5061.c @@ -74,6 +74,10 @@ #define ADP5061_CHG_STATUS_2_RCH_LIM_INFO(x) (((x) >> 3) & 0x1) #define ADP5061_CHG_STATUS_2_BAT_STATUS(x) (((x) >> 0) & 0x7) +/* ADP5061_FUNC_SET_1 */ +#define ADP5061_FUNC_SET_1_EN_CHG_MSK BIT(0) +#define ADP5061_FUNC_SET_1_EN_CHG_MODE(x) (((x) & 0x01) << 0) + /* ADP5061_IEND */ #define ADP5061_IEND_IEND_MSK GENMASK(7, 5) #define ADP5061_IEND_IEND_MODE(x) (((x) & 0x07) << 5) @@ -691,11 +695,64 @@ static const struct power_supply_desc adp5061_desc = { .num_properties = ARRAY_SIZE(adp5061_props), }; +static int adp5061_get_charging_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_1, ®val); + if (ret < 0) + return ret; + + regval &= ADP5061_FUNC_SET_1_EN_CHG_MSK; + return sprintf(buf, "%d\n", regval); +} + +static int adp5061_set_charging_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_en; + int ret; + + ret = kstrtou8(buf, 0, &chg_en); + if (ret < 0) + return ret; + + ret = regmap_update_bits(st->regmap, ADP5061_FUNC_SET_1, + ADP5061_FUNC_SET_1_EN_CHG_MSK, + ADP5061_FUNC_SET_1_EN_CHG_MODE(!!chg_en)); + + if (ret < 0) + return ret; + + return count; +} + +static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled, + adp5061_set_charging_enabled); + +static struct attribute *adp5061_attributes[] = { + &dev_attr_charging_enabled.attr, + NULL +}; + +static const struct attribute_group adp5061_attr_group = { + .attrs = adp5061_attributes, +}; + static int adp5061_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct power_supply_config psy_cfg = {}; struct adp5061_state *st; + int ret; st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); if (!st) @@ -721,6 +778,12 @@ static int adp5061_probe(struct i2c_client *client, return PTR_ERR(st->psy); } + ret = sysfs_create_group(&st->psy->dev.kobj, &adp5061_attr_group); + if (ret < 0) { + dev_err(&client->dev, "failed to create sysfs group\n"); + return ret; + } + return 0; } -- 2.20.1
| |