power_supply: Add support for WM8350 PMU
Subsystems (2)
PATCH 1/1 power_supply: Add support for WM8350 PMU
This patch adds support for the PMU provided by the WM8350 which implements battery, line and USB supplies including a battery charger. The hardware functions largely autonomously, with minimal software control required to initiate fast charging.
Support for configuration of the USB supply is not yet implemented. This means that the hardware will remain in the mode configured at startup, by default limiting the current drawn from USB to 100mA.
This driver was originally written by Liam Girdwood with subsequent updates for submission by Mark Brown.
---
This driver depends on support for the AUXADC in the WM8350 which I submitted for merge via the MFD tree earlier (the AUXADC is shared between several compoenents of the WM8350) so I guess it makes sense to merge it via the MFD tree?
drivers/power/Kconfig | 7 + drivers/power/Makefile | 1 + drivers/power/wm8350_power.c | 549 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/wm8350/core.h | 26 ++ include/linux/mfd/wm8350/supply.h | 23 ++- 5 files changed, 605 insertions(+), 1 deletions(-) create mode 100644 drivers/power/wm8350_power.c
drivers/power/Kconfig +7 -0
@@ -29,6 +29,13 @@ config APM_POWER Say Y here to enable support APM status emulation using battery class devices. +config WM8350_POWER + tristate "WM8350 PMU support" + depends on MFD_WM8350 + help + Say Y here to enable support for the power management unit + provided by the Wolfson Microelectronics WM8350 PMIC. + config BATTERY_DS2760 tristate "DS2760 battery driver (HP iPAQ & others)" select W1
drivers/power/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_POWER_SUPPLY) += power_supply.o obj-$(CONFIG_PDA_POWER) += pda_power.o obj-$(CONFIG_APM_POWER) += apm_power.o +obj-$(CONFIG_WM8350_POWER) += wm8350_power.o obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
drivers/power/wm8350_power.c new file +549 -0
549 lines not on this page · raw message
include/linux/mfd/wm8350/core.h +26 -0
@@ -57,6 +57,9 @@#define WM8350_OVER_CURRENT_INT_STATUS_MASK 0x25#define WM8350_GPIO_INT_STATUS_MASK 0x26#define WM8350_COMPARATOR_INT_STATUS_MASK 0x27 +#define WM8350_MISC_OVERRIDES 0xE3 +#define WM8350_COMPARATOR_OVERRIDES 0xE7 +#define WM8350_STATE_MACHINE_STATUS 0xE9#define WM8350_MAX_REGISTER 0xFF
@@ -523,6 +526,29 @@#define WM8350_DC2_STS 0x0002#define WM8350_DC1_STS 0x0001 +/* +* R227 (0xE3) - Misc Overrides +*/ +#define WM8350_USB_LIMIT_OVRDE 0x0400 + +/* +* R227 (0xE7) - Comparator Overrides +*/ +#define WM8350_USB_FB_OVRDE 0x8000 +#define WM8350_WALL_FB_OVRDE 0x4000 +#define WM8350_BATT_FB_OVRDE 0x2000 + + +/* +* R233 (0xE9) - State Machinine Status +*/ +#define WM8350_USB_SM_MASK 0x0700 +#define WM8350_USB_SM_SHIFT 8 + +#define WM8350_USB_SM_100_SLV 1 +#define WM8350_USB_SM_500_SLV 5 +#define WM8350_USB_SM_STDBY_SLV 7 +/* WM8350 wake up conditions */ #define WM8350_IRQ_WKUP_OFF_STATE 43#define WM8350_IRQ_WKUP_HIB_STATE 44
include/linux/mfd/wm8350/supply.h +22 -1
@@ -13,7 +13,8 @@#ifndef __LINUX_MFD_WM8350_SUPPLY_H_#define __LINUX_MFD_WM8350_SUPPLY_H_ -#include <linux/platform_device.h> +#include <linux/mutex.h> +#include <linux/power_supply.h> /* * Charger registers
@@ -104,8 +105,28 @@#define WM8350_IRQ_EXT_WALL_FB 37#define WM8350_IRQ_EXT_BAT_FB 38 +/* +* Policy to control charger state machine. +*/ +struct wm8350_charger_policy { + +/* charger state machine policy - set in machine driver */ +int eoc_mA;/* end of charge current (mA) */ +int charge_mV;/* charge voltage */ +int fast_limit_mA;/* fast charge current limit */ +int fast_limit_USB_mA;/* USB fast charge current limit */ +int charge_timeout;/* charge timeout (mins) */ +int trickle_start_mV;/* trickle charge starts at mV */ +int trickle_charge_mA;/* trickle charge current */ +int trickle_charge_USB_mA;/* USB trickle charge current */ +}; +struct wm8350_power {struct platform_device *pdev; +struct power_supply battery; +struct power_supply usb; +struct power_supply ac; +struct wm8350_charger_policy *policy; };#endif
Signature · 1 line
1.5.6.5
Quoted 11 lines · On Thu, 6 Nov 2008 15:15:22 +0000 Mark Brown…
This patch adds support for the PMU provided by the WM8350 which implements battery, line and USB supplies including a battery charger. The hardware functions largely autonomously, with minimal software control required to initiate fast charging.
Support for configuration of the USB supply is not yet implemented. This means that the hardware will remain in the mode configured at startup, by default limiting the current drawn from USB to 100mA.
This driver was originally written by Liam Girdwood with subsequent updates for submission by Mark Brown.
An idle question...
Quoted 9 lines
drivers/power/wm8350_power.c new file +7
-0+ supply ="Battery" ; + supply ="USB" ; + supply ="Line" ; + supply ="Battery and USB" ; + charge ="Charger Off" ; + charge ="Trickle Charging" ; + charge ="Fast Charging" ;
drivers/power/wm8350_power.c line 258
Quoted 10 lines
drivers/power/wm8350_power.c new file +10
-0+dev_err (wm8350->dev,"battery too hot\n" ); +dev_err (wm8350->dev,"battery too cold\n" ); +dev_err (wm8350->dev,"battery failed\n" ); +dev_err (wm8350->dev,"charger timeout\n" ); +dev_dbg (wm8350->dev,"charger stopped\n" ); +dev_dbg (wm8350->dev,"charger started\n" ); +dev_dbg (wm8350->dev,"fast charger ready\n" ); +dev_warn (wm8350->dev,"battery < 3.9V\n" ); +dev_warn (wm8350->dev,"battery < 3.1V\n" ); +dev_warn (wm8350->dev,"battery < 2.85V\n" );
The above constitutes a sort-of userspace interface. A number of the things which are being reported there are fairly common to the technology and other drivers will be able to report them.
But afaict this interface is unique to this particular driver. Has any thought been given to standardising this interface across all similar drivers? Too messy?
Quoted 3 lines · Andrew Morton
Mark Brown <[email protected]> wrote:
An idle question...
[Reordered for conveninece in replying.]
Quoted 7 lines
The above constitutes a sort-of userspace interface. A number of the things which are being reported there are fairly common to the technology and other drivers will be able to report them.
But afaict this interface is unique to this particular driver. Has any thought been given to standardising this interface across all similar drivers? Too messy?
I've got several answers...
Quoted 4 lines
drivers/power/wm8350_power.c line 178
Quoted 4 lines
drivers/power/wm8350_power.c new file +4
-0+ supply ="Battery" ; + supply ="USB" ; + supply ="Line" ; + supply ="Battery and USB" ;
This sysfs file is just redundant and could be removed.
Quoted 3 lines
drivers/power/wm8350_power.c line 206
Quoted 3 lines
drivers/power/wm8350_power.c new file +3
-0+ charge ="Charger Off" ; + charge ="Trickle Charging" ; + charge ="Fast Charging" ;
There's some support for this already (which implemented in the driver) but it doesn't distinguish between fast and trickle charging. It's useful to know for debugging systems but I wasn't able to convince myself it was generically useful enough to add to the class ABI, especially given the existing boolean reporting.
Quoted 4 lines
drivers/power/wm8350_power.c line 233
Quoted 4 lines
drivers/power/wm8350_power.c new file +4
-0+dev_err (wm8350->dev,"battery too hot\n" ); +dev_err (wm8350->dev,"battery too cold\n" ); +dev_err (wm8350->dev,"battery failed\n" ); +dev_err (wm8350->dev,"charger timeout\n" );
These are a bit tricky with the WM8350 since the chip gives latched edge notifications of errors but doesn't provide the current status directly. There is some generic battery health status reporting in the interface (though not quite so specific) but I wasn't comfortable supporting it without being able to read back the current status.
Quoted 3 lines
drivers/power/wm8350_power.c line 243
Quoted 3 lines
drivers/power/wm8350_power.c new file +3
-0+dev_dbg (wm8350->dev,"charger stopped\n" ); +dev_dbg (wm8350->dev,"charger started\n" ); +dev_dbg (wm8350->dev,"fast charger ready\n" );
On a closer look it appears that started and stopped are already notified to user space - the driver should be calling power_supply_changed() when these happen. Reporting the fast charger ready status would fall out if a standard interface for polling this status were implemented.
Quoted 3 lines
drivers/power/wm8350_power.c line 258
Quoted 3 lines
drivers/power/wm8350_power.c new file +3
-0+dev_warn (wm8350->dev,"battery < 3.9V\n" ); +dev_warn (wm8350->dev,"battery < 3.1V\n" ); +dev_warn (wm8350->dev,"battery < 2.85V\n" );
I'm ambivalent on these ones, especially given that none of the other health issues are being reported.