cpcap charger and battery fixes
v2 cover cpcap charger and battery fixes
Hi,
Here are few fixes for cpcap charger and battery. These can probably wait for v5.5 if preferred that way and can be applied separate from the 4.2V charger fix.
Regards,
Tony
Changes since v2:
- Drop the pointless test for latest->voltage >= 0 as noted by Pavel
- Allow poweroff to trigger at 3.2V and lower as suggested by Pavel
Changes since v1:
- Sent the updated 4.2V voltage fix separately
Tony Lindgren (2):
power: supply: cpcap-battery: Check voltage before orderly_poweroff
power: supply: cpcap-charger: Improve battery detection
drivers/power/supply/cpcap-battery.c | 8 +++++--- drivers/power/supply/cpcap-charger.c | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.23.0
PATCH v2 1/2 power: supply: cpcap-battery: Check voltage before orderly_poweroff
We can get the low voltage interrupt trigger sometimes way too early, maybe because of CPU load spikes. This causes orderly_poweroff() be called too easily.
Let's check the voltage before orderly_poweroff in case it was not yet a permanent condition. We will be getting more interrupts anyways if the condition persists.
Let's also show the measured voltages for low battery and battery empty warnings since we have them.
--- drivers/power/supply/cpcap-battery.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/power/supply/cpcap-battery.c +5 -3
@@ -562,12 +562,14 @@ static irqreturn_t cpcap_battery_irq_thread(int irq, void *data)switch (d->action) {case CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW :if (latest->current_ua >=0 ) -dev_warn (ddata->dev,"Battery low at 3.3V!\n" ); +dev_warn (ddata->dev,"Battery low at %imV!\n" , + latest->voltage /1000 );break ;case CPCAP_BATTERY_IRQ_ACTION_POWEROFF : -if (latest->current_ua >=0 ) { +if (latest->current_ua >=0 && latest->voltage <=3200000 ) {dev_emerg (ddata->dev, -"Battery empty at 3.1V, powering off\n" ); +"Battery empty at %imV, powering off\n" , + latest->voltage /1000 );orderly_poweroff (true); }break ;
Signature · 1 line
2.23.0
PATCH v2 2/2 power: supply: cpcap-charger: Improve battery detection
In reply to Tony LindgrenWe are currently using a wrong ADC range for the battery detection. The ADC returns the battery temperature if connected.
--- drivers/power/supply/cpcap-charger.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/power/supply/cpcap-charger.c +4 -3
@@ -176,20 +176,21 @@ static enum power_supply_property cpcap_charger_props[] = { POWER_SUPPLY_PROP_CURRENT_NOW, }; +/* No battery always shows temperature of -40000 */ static bool cpcap_charger_battery_found (struct cpcap_charger_ddata *ddata) {struct iio_channel *channel; -int error, value; +int error, temperature; channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET ]; - error =iio_read_channel_raw (channel, &value); + error =iio_read_channel_processed (channel, &temperature);if (error <0 ) {dev_warn (ddata->dev,"%s failed: %i\n" , __func__, error);return false; } -return value ==1 ; +return temperature >-20000 && temperature <60000 ; }static int cpcap_charger_get_charge_voltage (struct cpcap_charger_ddata *ddata)
Signature · 1 line
2.23.0
Sebastian Reichel
maintainerHi,
Quoted 20 lines · Tony Lindgren
Hi,
Here are few fixes for cpcap charger and battery. These can probably wait for v5.5 if preferred that way and can be applied separate from the 4.2V charger fix.
Regards,
Tony
Changes since v2:
- Drop the pointless test for
latest->voltage>= 0 as noted by Pavel- Allow poweroff to trigger at 3.2V and lower as suggested by Pavel
Changes since v1:
- Sent the updated 4.2V voltage fix separately
Quoted 7 lines
Tony Lindgren (2):
power: supply: cpcap-battery: Check voltage beforeorderly_poweroff
power: supply: cpcap-charger: Improve battery detectiondrivers/power/supply/cpcap-battery.c | 8 +++++--- drivers/power/supply/cpcap-charger.c | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-)
Thanks, queued.
-- Sebastian