Re: [PATCH v3 2/2] power_supply: platform/chrome: wilco_ec: Add charging config driver

2019-04-15 Thread Enric Balletbo i Serra
Hi Nick,


On 12/4/19 2:20, Nick Crews wrote:
> Add control of the charging algorithm used on Wilco devices.
> See Documentation/ABI/testing/sysfs-class-power-wilco for the
> userspace interface and other info.
> 
> v3 changes:
> -Add this changelog
> -Fix commit message tags
> v2 changes:
> -Update Documentation to say KernelVersion 5.2
> -Update Documentation to explain Trickle mode better.
> -rename things from using *PCC* to *CHARGE*
> -Split up conversions between POWER_SUPPLY_PROP_CHARGE_TYPE values
> and Wilco EC codes
> -Use devm_ flavor of power_supply_register(), which simplifies things
> -Add extra error checking on property messages received from the EC
> -Fix bug in memcpy() calls in properties.c
> -Refactor fill_property_id()
> -Add valid input checks to charge_type
> -Properly convert charge_type when get()ting
> 
> Signed-off-by: Nick Crews 
> ---
>  .../ABI/testing/sysfs-class-power-wilco   |  30 +++

Oh, I see the doc now :-) I think that part of this documentation should be 
generic.

>  drivers/platform/chrome/wilco_ec/Kconfig  |   9 +
>  drivers/platform/chrome/wilco_ec/Makefile |   2 +
>  .../platform/chrome/wilco_ec/charge_config.c  | 190 ++
>  drivers/platform/chrome/wilco_ec/core.c   |  14 ++
>  drivers/platform/chrome/wilco_ec/properties.c | 134 
>  drivers/platform/chrome/wilco_ec/properties.h |  68 +++
>  include/linux/platform_data/wilco-ec.h|   2 +
>  8 files changed, 449 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-class-power-wilco
>  create mode 100644 drivers/platform/chrome/wilco_ec/charge_config.c
>  create mode 100644 drivers/platform/chrome/wilco_ec/properties.c
>  create mode 100644 drivers/platform/chrome/wilco_ec/properties.h
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-power-wilco 
> b/Documentation/ABI/testing/sysfs-class-power-wilco
> new file mode 100644
> index ..7f3b01310476
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-class-power-wilco
> @@ -0,0 +1,30 @@
> +What:/sys/class/power_supply/wilco_charger/charge_type
> +Date:April 2019
> +KernelVersion:   5.2
> +Description:
> + What charging algorithm to use:
> +
> + Standard: Fully charges battery at a standard rate.
> + Adaptive: Battery settings adaptively optimized based on
> + typical battery usage pattern.
> + Fast: Battery charges over a shorter period.
> + Trickle: Extends battery lifespan, intended for users who
> + primarily use their Chromebook while connected to AC.
> + Custom: A low and high threshold percentage is specified.
> + Charging begins when level drops below
> + charge_control_start_threshold, and ceases when
> + level is above charge_control_end_threshold.
> +
> +What:
> /sys/class/power_supply/wilco_charger/charge_control_start_threshold
> +Date:April 2019
> +KernelVersion:   5.2
> +Description:
> + Used when charge_type="Custom", as described above. Measured in
> + percentages. The valid range is [50, 95].
> +
> +What:
> /sys/class/power_supply/wilco_charger/charge_control_end_threshold
> +Date:April 2019
> +KernelVersion:   5.2
> +Description:
> + Used when charge_type="Custom", as described above. Measured in
> + percentages. The valid range is [55, 100].
> diff --git a/drivers/platform/chrome/wilco_ec/Kconfig 
> b/drivers/platform/chrome/wilco_ec/Kconfig
> index e09e4cebe9b4..1c427830bd57 100644
> --- a/drivers/platform/chrome/wilco_ec/Kconfig
> +++ b/drivers/platform/chrome/wilco_ec/Kconfig
> @@ -18,3 +18,12 @@ config WILCO_EC_DEBUGFS
> manipulation and allow for testing arbitrary commands.  This
> interface is intended for debug only and will not be present
> on production devices.
> +
> +config WILCO_EC_CHARGE_CNTL
> + tristate "Enable charging control"
> + depends on WILCO_EC
> + help
> +   If you say Y here, you get support to control the charging
> +   routines performed by the Wilco Embedded Controller.
> +   Further information can be found in
> +   Documentation/ABI/testing/sysfs-class-power-wilco)
> diff --git a/drivers/platform/chrome/wilco_ec/Makefile 
> b/drivers/platform/chrome/wilco_ec/Makefile
> index 063e7fb4ea17..7e980f56f793 100644
> --- a/drivers/platform/chrome/wilco_ec/Makefile
> +++ b/drivers/platform/chrome/wilco_ec/Makefile
> @@ -4,3 +4,5 @@ wilco_ec-objs := core.o mailbox.o
>  obj-$(CONFIG_WILCO_EC)   += wilco_ec.o
>  wilco_ec_debugfs-objs:= debugfs.o
>  obj-$(CONFIG_WILCO_EC_DEBUGFS)   += wilco_ec_debugfs.o
> +wilco_ec_charging-objs   := charge_config.o properties.o
> 

Re: [PATCH v3 2/2] power_supply: platform/chrome: wilco_ec: Add charging config driver

2019-04-12 Thread kbuild test robot
Hi Nick,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc4 next-20190412]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Nick-Crews/power_supply-Add-more-charge-types-and-CHARGE_CONTROL_-properties/20190412-211253


coccinelle warnings: (new ones prefixed by >>)

>> drivers/platform/chrome/wilco_ec/charge_config.c:173:1-3: WARNING: 
>> PTR_ERR_OR_ZERO can be used

Please review and possibly fold the followup patch.

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


[PATCH v3 2/2] power_supply: platform/chrome: wilco_ec: Add charging config driver

2019-04-11 Thread Nick Crews
Add control of the charging algorithm used on Wilco devices.
See Documentation/ABI/testing/sysfs-class-power-wilco for the
userspace interface and other info.

v3 changes:
-Add this changelog
-Fix commit message tags
v2 changes:
-Update Documentation to say KernelVersion 5.2
-Update Documentation to explain Trickle mode better.
-rename things from using *PCC* to *CHARGE*
-Split up conversions between POWER_SUPPLY_PROP_CHARGE_TYPE values
and Wilco EC codes
-Use devm_ flavor of power_supply_register(), which simplifies things
-Add extra error checking on property messages received from the EC
-Fix bug in memcpy() calls in properties.c
-Refactor fill_property_id()
-Add valid input checks to charge_type
-Properly convert charge_type when get()ting

Signed-off-by: Nick Crews 
---
 .../ABI/testing/sysfs-class-power-wilco   |  30 +++
 drivers/platform/chrome/wilco_ec/Kconfig  |   9 +
 drivers/platform/chrome/wilco_ec/Makefile |   2 +
 .../platform/chrome/wilco_ec/charge_config.c  | 190 ++
 drivers/platform/chrome/wilco_ec/core.c   |  14 ++
 drivers/platform/chrome/wilco_ec/properties.c | 134 
 drivers/platform/chrome/wilco_ec/properties.h |  68 +++
 include/linux/platform_data/wilco-ec.h|   2 +
 8 files changed, 449 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-power-wilco
 create mode 100644 drivers/platform/chrome/wilco_ec/charge_config.c
 create mode 100644 drivers/platform/chrome/wilco_ec/properties.c
 create mode 100644 drivers/platform/chrome/wilco_ec/properties.h

diff --git a/Documentation/ABI/testing/sysfs-class-power-wilco 
b/Documentation/ABI/testing/sysfs-class-power-wilco
new file mode 100644
index ..7f3b01310476
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-power-wilco
@@ -0,0 +1,30 @@
+What:  /sys/class/power_supply/wilco_charger/charge_type
+Date:  April 2019
+KernelVersion: 5.2
+Description:
+   What charging algorithm to use:
+
+   Standard: Fully charges battery at a standard rate.
+   Adaptive: Battery settings adaptively optimized based on
+   typical battery usage pattern.
+   Fast: Battery charges over a shorter period.
+   Trickle: Extends battery lifespan, intended for users who
+   primarily use their Chromebook while connected to AC.
+   Custom: A low and high threshold percentage is specified.
+   Charging begins when level drops below
+   charge_control_start_threshold, and ceases when
+   level is above charge_control_end_threshold.
+
+What:  
/sys/class/power_supply/wilco_charger/charge_control_start_threshold
+Date:  April 2019
+KernelVersion: 5.2
+Description:
+   Used when charge_type="Custom", as described above. Measured in
+   percentages. The valid range is [50, 95].
+
+What:  
/sys/class/power_supply/wilco_charger/charge_control_end_threshold
+Date:  April 2019
+KernelVersion: 5.2
+Description:
+   Used when charge_type="Custom", as described above. Measured in
+   percentages. The valid range is [55, 100].
diff --git a/drivers/platform/chrome/wilco_ec/Kconfig 
b/drivers/platform/chrome/wilco_ec/Kconfig
index e09e4cebe9b4..1c427830bd57 100644
--- a/drivers/platform/chrome/wilco_ec/Kconfig
+++ b/drivers/platform/chrome/wilco_ec/Kconfig
@@ -18,3 +18,12 @@ config WILCO_EC_DEBUGFS
  manipulation and allow for testing arbitrary commands.  This
  interface is intended for debug only and will not be present
  on production devices.
+
+config WILCO_EC_CHARGE_CNTL
+   tristate "Enable charging control"
+   depends on WILCO_EC
+   help
+ If you say Y here, you get support to control the charging
+ routines performed by the Wilco Embedded Controller.
+ Further information can be found in
+ Documentation/ABI/testing/sysfs-class-power-wilco)
diff --git a/drivers/platform/chrome/wilco_ec/Makefile 
b/drivers/platform/chrome/wilco_ec/Makefile
index 063e7fb4ea17..7e980f56f793 100644
--- a/drivers/platform/chrome/wilco_ec/Makefile
+++ b/drivers/platform/chrome/wilco_ec/Makefile
@@ -4,3 +4,5 @@ wilco_ec-objs   := core.o mailbox.o
 obj-$(CONFIG_WILCO_EC) += wilco_ec.o
 wilco_ec_debugfs-objs  := debugfs.o
 obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
+wilco_ec_charging-objs := charge_config.o properties.o
+obj-$(CONFIG_WILCO_EC_CHARGE_CNTL) += wilco_ec_charging.o
diff --git a/drivers/platform/chrome/wilco_ec/charge_config.c 
b/drivers/platform/chrome/wilco_ec/charge_config.c
new file mode 100644
index ..7c41b847396d
--- /dev/null
+++ b/drivers/platform/chrome/wilco_ec/charge_config.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Charging