Re: [PATCH v3][RESEND] adp5061: Add support for battery charging enable

2019-10-13 Thread kbuild test robot
Hi Alexandru,

I love your patch! Yet something to improve:

[auto build test ERROR on power-supply/for-next]
[cannot apply to v5.4-rc2 next-20191011]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Alexandru-Ardelean/adp5061-Add-support-for-battery-charging-enable/20191014-035456
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git 
for-next
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/kobject.h:20:0,
from include/linux/module.h:17,
from drivers/power/supply/adp5061.c:9:
>> drivers/power/supply/adp5061.c:738:44: error: initialization from 
>> incompatible pointer type [-Werror=incompatible-pointer-types]
static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
   ^
   include/linux/sysfs.h:104:10: note: in definition of macro '__ATTR'
 .show = _show,  \
 ^
>> drivers/power/supply/adp5061.c:738:8: note: in expansion of macro 
>> 'DEVICE_ATTR'
static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
   ^~~
   drivers/power/supply/adp5061.c:738:44: note: (near initialization for 
'dev_attr_charging_enabled.show')
static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
   ^
   include/linux/sysfs.h:104:10: note: in definition of macro '__ATTR'
 .show = _show,  \
 ^
>> drivers/power/supply/adp5061.c:738:8: note: in expansion of macro 
>> 'DEVICE_ATTR'
static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
   ^~~
   drivers/power/supply/adp5061.c:739:6: error: initialization from 
incompatible pointer type [-Werror=incompatible-pointer-types]
 adp5061_set_charging_enabled);
 ^
   include/linux/sysfs.h:105:11: note: in definition of macro '__ATTR'
 .store = _store,  \
  ^~
>> drivers/power/supply/adp5061.c:738:8: note: in expansion of macro 
>> 'DEVICE_ATTR'
static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
   ^~~
   drivers/power/supply/adp5061.c:739:6: note: (near initialization for 
'dev_attr_charging_enabled.store')
 adp5061_set_charging_enabled);
 ^
   include/linux/sysfs.h:105:11: note: in definition of macro '__ATTR'
 .store = _store,  \
  ^~
>> drivers/power/supply/adp5061.c:738:8: note: in expansion of macro 
>> 'DEVICE_ATTR'
static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
   ^~~
   cc1: some warnings being treated as errors

vim +738 drivers/power/supply/adp5061.c

   737  
 > 738  static DEVICE_ATTR(charging_enabled, 0644, adp5061_get_charging_enabled,
   739 adp5061_set_charging_enabled);
   740  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH v3][RESEND] adp5061: Add support for battery charging enable

2019-10-11 Thread Alexandru Ardelean
From: Stefan Popa 

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 
Signed-off-by: Alexandru Ardelean 
---

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 ..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, );
+   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, _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[] = {
+   _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(>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(>psy->dev.kobj, _attr_group);
+   if (ret < 0) {
+   dev_err(>dev, "failed to create sysfs group\n");
+   return ret;
+   }
+
return 0;
 }
 
-- 
2.20.1