power_supply: platform/chrome: wilco_ec: Add charging config driver
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v5 1/1 power_supply: platform/chrome: wilco_ec: Add charging config driver
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.
v5 changes:
-Remove OP_SYNC, it has no immediate use case.
-Merge properties.h into wilco-ec.h
-Remove enum get_set_sync_op from the public interface,
since without OP_SYNC they are irrelevant.
-Fix Kconfigs and Makefiles so they actually work
with the v4 changes
-Tweak some formatting, spacing, and comments
-Fix validation of charge_type so illegal values
can't be set. Before negative error codes were accidentally getting casted to positive numbers
-Remove more unneeded parentheses.
v4 changes:
-Use put_unaligned_le32() to store PID in request.
-Move implementation from
drivers/platform/chrome/wilco_ec/charge_config.c to drivers/power/supply/wilco_charger.c
-Move drivers/platform/chrome/wilco_ec/properties.h to
include/linux/platform_data/wilco-ec-properties.h
-Remove parentheses in switch statement in psp_val_to_charge_mode() -Check for any negatvie return code from psp_val_to_charge_mode()
instead of just -EINVAL so its less brittle
-Tweak comments in wilco-ec-properties.h
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
--- .../ABI/testing/sysfs-class-power-wilco | 30 +++ drivers/platform/chrome/wilco_ec/Kconfig | 9 + drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/core.c | 13 ++ drivers/platform/chrome/wilco_ec/properties.c | 134 ++++++++++++ drivers/power/supply/Makefile | 1 + drivers/power/supply/wilco-charger.c | 190 ++++++++++++++++++ include/linux/platform_data/wilco-ec.h | 73 +++++++ 8 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-class-power-wilco create mode 100644 drivers/platform/chrome/wilco_ec/properties.c create mode 100644 drivers/power/supply/wilco-charger.c
Documentation/ABI/testing/sysfs-class-power-wilco new file +30 -0
@@ -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].
drivers/platform/chrome/wilco_ec/Kconfig +9 -0
@@ -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 CHARGER_WILCO + tristate "Enable charger 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)
drivers/platform/chrome/wilco_ec/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -wilco_ec-objs := core.o mailbox.o +wilco_ec-objs := core.o mailbox.o properties.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o wilco_ec_debugfs-objs := debugfs.o obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
drivers/platform/chrome/wilco_ec/core.c +13 -0
@@ -89,8 +89,20 @@ static int wilco_ec_probe(struct platform_device *pdev) goto unregister_debugfs; } +/* Register child device to be found by charger config driver. */ + ec->charger_pdev =platform_device_register_data (dev,"wilco-charger" , +PLATFORM_DEVID_AUTO , +NULL ,0 ); +if (IS_ERR (ec->charger_pdev)) { +dev_err (dev,"Failed to create charger platform device\n" ); + ret =PTR_ERR (ec->charger_pdev); + goto unregister_rtc; + } +return 0 ; +unregister_rtc: +platform_device_unregister (ec->rtc_pdev); unregister_debugfs:if (ec->debugfs_pdev)platform_device_unregister (ec->debugfs_pdev);
@@ -102,6 +114,7 @@ static int wilco_ec_remove(struct platform_device *pdev) {struct wilco_ec_device *ec =platform_get_drvdata (pdev); +platform_device_unregister (ec->charger_pdev);platform_device_unregister (ec->rtc_pdev);if (ec->debugfs_pdev)platform_device_unregister (ec->debugfs_pdev);
drivers/platform/chrome/wilco_ec/properties.c new file +134 -0
134 lines not on this page · raw message
drivers/power/supply/Makefile +1 -0
@@ -87,3 +87,4 @@ obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o obj-$(CONFIG_CHARGER_CROS_USBPD) += cros_usbpd-charger.o obj-$(CONFIG_CHARGER_SC2731) += sc2731_charger.o obj-$(CONFIG_FUEL_GAUGE_SC27XX) += sc27xx_fuel_gauge.o +obj-$(CONFIG_CHARGER_WILCO) += wilco-charger.o
drivers/power/supply/wilco-charger.c new file +190 -0
190 lines not on this page · raw message
include/linux/platform_data/wilco-ec.h +73 -0
89 lines not on this page · raw message
Signature · 1 line
2.20.1
kbuild test robot
build bot[PATCH] power_supply: platform/chrome: wilco_ec: fix ptr_ret.cocci warnings
drivers/power/supply/wilco-charger.c:173:1-3: WARNING: PTR_ERR_OR_ZERO can be used
From: kbuild test robot <[email protected]>
drivers/power/supply/wilco-charger.c:173:1-3: WARNING: PTR_ERR_OR_ZERO can be used
Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
Generated by: scripts/coccinelle/api/ptr_ret.cocci
---
wilco-charger.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/power/supply/wilco-charger.c +1 -4
@@ -170,10 +170,7 @@ static int wilco_charge_probe(struct pla psy_cfg.drv_data = ec; psy =devm_power_supply_register (&pdev->dev, &wilco_ps_desc, &psy_cfg); -if (IS_ERR (psy)) -return PTR_ERR (psy); - -return 0 ; +return PTR_ERR_OR_ZERO (psy); }static struct platform_driver wilco_charge_driver = {
kbuild test robot
build botThank you for the patch! Perhaps something to improve:
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-rc5 next-20190418]
[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-platform-chrome-wilco_ec-Add-charging-config-driver/20190420-041913
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'If you fix the issue, kindly add following tag
sparse warnings: (new ones prefixed by >>)
drivers/power/supply/wilco-charger.c:46:14: sparse: undefined identifier 'POWER_SUPPLY_CHARGE_TYPE_STANDARD' drivers/power/supply/wilco-charger.c:48:14: sparse: undefined identifier 'POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE' drivers/power/supply/wilco-charger.c:50:14: sparse: undefined identifier 'POWER_SUPPLY_CHARGE_TYPE_CUSTOM'
>> drivers/power/supply/wilco-charger.c:46:14: sparse: incompatible types for 'case' statement
drivers/power/supply/wilco-charger.c:48:14: sparse: incompatible types for 'case' statement drivers/power/supply/wilco-charger.c:50:14: sparse: incompatible types for 'case' statement drivers/power/supply/wilco-charger.c:66:24: sparse: undefined identifier 'POWER_SUPPLY_CHARGE_TYPE_STANDARD' drivers/power/supply/wilco-charger.c:68:24: sparse: undefined identifier 'POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE' drivers/power/supply/wilco-charger.c:70:24: sparse: undefined identifier 'POWER_SUPPLY_CHARGE_TYPE_CUSTOM' drivers/power/supply/wilco-charger.c:78:9: sparse: undefined identifier 'POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD' drivers/power/supply/wilco-charger.c:79:9: sparse: undefined identifier 'POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD' drivers/power/supply/wilco-charger.c:95:14: sparse: undefined identifier 'POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD' drivers/power/supply/wilco-charger.c:98:14: sparse: undefined identifier 'POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD' drivers/power/supply/wilco-charger.c:95:14: sparse: incompatible types for 'case' statement drivers/power/supply/wilco-charger.c:98:14: sparse: incompatible types for 'case' statement drivers/power/supply/wilco-charger.c:132:14: sparse: undefined identifier 'POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD' drivers/power/supply/wilco-charger.c:138:14: sparse: undefined identifier 'POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD' drivers/power/supply/wilco-charger.c:132:14: sparse: incompatible types for 'case' statement drivers/power/supply/wilco-charger.c:138:14: sparse: incompatible types for 'case' statement drivers/power/supply/wilco-charger.c:46:14: sparse: Expected constant expression in case statement drivers/power/supply/wilco-charger.c:48:14: sparse: Expected constant expression in case statement drivers/power/supply/wilco-charger.c:50:14: sparse: Expected constant expression in case statement drivers/power/supply/wilco-charger.c:95:14: sparse: Expected constant expression in case statement drivers/power/supply/wilco-charger.c:98:14: sparse: Expected constant expression in case statement drivers/power/supply/wilco-charger.c:132:14: sparse: Expected constant expression in case statement drivers/power/supply/wilco-charger.c:138:14: sparse: Expected constant expression in case statement
vim +/case +46 drivers/power/supply/wilco-charger.c
37
38 /* Convert from POWER_SUPPLY_PROP_CHARGE_TYPE value to the EC's charge mode */
39 static enum charge_mode psp_val_to_charge_mode(int psp_val)
40 {
41 switch (psp_val) {
42 case POWER_SUPPLY_CHARGE_TYPE_TRICKLE:
43 return CHARGE_MODE_AC;
44 case POWER_SUPPLY_CHARGE_TYPE_FAST:
45 return CHARGE_MODE_EXP;
> 46 case POWER_SUPPLY_CHARGE_TYPE_STANDARD:
47 return CHARGE_MODE_STD;
48 case POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE:
49 return CHARGE_MODE_AUTO;
50 case POWER_SUPPLY_CHARGE_TYPE_CUSTOM:
51 return CHARGE_MODE_CUSTOM;
52 default:
53 return CHARGE_MODE_ILLEGAL;
54 }
55 }
56 ---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation