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 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 | 9 ++++++--- drivers/power/supply/cpcap-charger.c | 7 ++++--- 2 files changed, 10 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 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/power/supply/cpcap-battery.c +6 -3
@@ -562,12 +562,15 @@ 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 >=0 && + latest->voltage <=3100000 ) {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
Re: [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff
Quoted 20 lines · Tony Lindgren
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_poweroffin 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.
+++
b/drivers/power/supply/cpcap-battery.cdrivers/power/supply/cpcap-battery.c +2
-1@@ -562,12 +562,15 @@ 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 ;
drivers/power/supply/cpcap-battery.c static irqreturn_t cpcap_battery_irq_thread(int irq, void *data) · line 575
Quoted 10 lines
drivers/power/supply/cpcap-battery.c +4
-2case CPCAP_BATTERY_IRQ_ACTION_POWEROFF : -if (latest->current_ua >=0 ) { +if (latest->current_ua >=0 && latest->voltage >=0 && + latest->voltage <=3100000 ) {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); }
Hmm.
So if latest->voltage is < 0, I'd preffer to shut down the machine, too.
Actually, if we got POWEROFF irq, and voltage is close to 3.1V (like maybe < 3.2V), maybe it would be good to shutdown anyway?
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff
Quoted 34 lines · Pavel Machek
Quoted 20 lines · Tony Lindgren
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_poweroffin 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.
+++
b/drivers/power/supply/cpcap-battery.cdrivers/power/supply/cpcap-battery.c +2
-1@@ -562,12 +562,15 @@ 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 ;drivers/power/supply/cpcap-battery.c static irqreturn_t cpcap_battery_irq_thread(int irq, void *data) · line 575
Quoted 10 lines
drivers/power/supply/cpcap-battery.c +4
-2case CPCAP_BATTERY_IRQ_ACTION_POWEROFF : -if (latest->current_ua >=0 ) { +if (latest->current_ua >=0 && latest->voltage >=0 && + latest->voltage <=3100000 ) {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); }Hmm.
Quoted 2 lines
So if
latest->voltageis < 0, I'd preffer to shut down the machine, too.
Hmm I need to recheck if that is needed or not when booting without a battery on a power supply.
Quoted 2 lines
Actually, if we got POWEROFF irq, and voltage is close to 3.1V (like maybe < 3.2V), maybe it would be good to shutdown anyway?
No, this is some spurious interrupt issue that I've seen triggering at way higher voltages than it should be happening at.
Regards,
Tony
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