From: Tony Lindgren <tony@atomide.com>
To: Liam Breck <liam@networkimprov.net>
Cc: Sebastian Reichel <sre@kernel.org>,
"Mark A . Greer" <mgreer@animalcreek.com>,
linux-pm@vger.kernel.org, linux-omap@vger.kernel.org,
Liam Breck <kernel@networkimprov.net>,
Matt Ranostay <matt@ranostay.consulting>
Subject: Re: [PATCH 4/6] power: bq24190_charger: Don't read fault register outside irq_handle_thread()
Date: Thu, 12 Jan 2017 08:22:59 -0800 [thread overview]
Message-ID: <20170112162259.GF2630@atomide.com> (raw)
In-Reply-To: <CAKvHMgQ3=7xwG=QW7-04RE8Y2bW4vZabW9aYazHsO3D3Zfd0cw@mail.gmail.com>
* Liam Breck <liam@networkimprov.net> [170111 18:12]:
> On Wed, Jan 11, 2017 at 4:41 PM, Tony Lindgren <tony@atomide.com> wrote:
> > From: Liam Breck <kernel@networkimprov.net>
> >
> > Caching the fault register after a single read may not keep an accurate
> > value.
> >
> > Fix the issue by doing two reads of the fault register as specified in the
> > data sheet. And let's do this only irq_handle_thread() to avoid accidentally
> > clearing the fault status as specified in the data sheet:
> >
> > "When a fault occurs, the charger device sends out INT
> > and keeps the fault state in REG09 until the host reads the fault register.
> > Before the host reads REG09 and all the faults are cleared, the charger
> > device would not send any INT upon new faults. In order to read the
> > current fault status, the host has to read REG09 two times consecutively.
> > The 1st reads fault register status from the last read [1] and the 2nd reads
> > the current fault register status."
> >
> > [1] presumably a typo; should be "last fault"
> >
> > Fixes: d7bf353fd0aa3 ("bq24190_charger: Add support for TI BQ24190 Battery
> > Charger")
> > Cc: Mark A. Greer <mgreer@animalcreek.com>
> > Cc: Matt Ranostay <matt@ranostay.consulting>
> > Signed-off-by: Liam Breck <kernel@networkimprov.net>
> > [tony@atomide.com: cleaned up a bit]
> > Signed-off-by: Tony Lindgren <tony@atomide.com>
> > ---
> > drivers/power/supply/bq24190_charger.c | 99 ++++++++++------------------------
> > 1 file changed, 29 insertions(+), 70 deletions(-)
> >
> > diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
> > --- a/drivers/power/supply/bq24190_charger.c
> > +++ b/drivers/power/supply/bq24190_charger.c
> > @@ -144,10 +144,7 @@
> > * so the first read after a fault returns the latched value and subsequent
> > * reads return the current value. In order to return the fault status
> > * to the user, have the interrupt handler save the reg's value and retrieve
> > - * it in the appropriate health/status routine. Each routine has its own
> > - * flag indicating whether it should use the value stored by the last run
> > - * of the interrupt handler or do an actual reg read. That way each routine
> > - * can report back whatever fault may have occured.
> > + * it in the appropriate health/status routine.
> > */
> > struct bq24190_dev_info {
> > struct i2c_client *client;
> > @@ -159,9 +156,6 @@ struct bq24190_dev_info {
> > unsigned int gpio_int;
> > unsigned int irq;
> > struct mutex f_reg_lock;
> > - bool charger_health_valid;
> > - bool battery_health_valid;
> > - bool battery_status_valid;
> > u8 f_reg;
> > u8 ss_reg;
> > u8 watchdog;
> > @@ -635,21 +629,11 @@ static int bq24190_charger_get_health(struct bq24190_dev_info *bdi,
> > union power_supply_propval *val)
> > {
> > u8 v;
> > - int health, ret;
> > + int health;
> >
> > mutex_lock(&bdi->f_reg_lock);
> > -
> > - if (bdi->charger_health_valid) {
> > - v = bdi->f_reg;
> > - bdi->charger_health_valid = false;
> > - mutex_unlock(&bdi->f_reg_lock);
> > - } else {
> > - mutex_unlock(&bdi->f_reg_lock);
> > -
> > - ret = bq24190_read(bdi, BQ24190_REG_F, &v);
> > - if (ret < 0)
> > - return ret;
> > - }
> > + v = bdi->f_reg;
> > + mutex_unlock(&bdi->f_reg_lock);
>
> bdi->f_reg is the only thing protected by the mutex, and is only ever
> set or read. Is it OK to use an atomic type here?
Yeah seems that should work if we don't need to protect any longer
sections of the code with the mutex. Such as a read-write over I2c
to the bq24190 registers.
Regards,
Tony
next prev parent reply other threads:[~2017-01-12 16:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-12 0:41 [PATCH 0/6] Few bq24190-charger fixes and improvments Tony Lindgren
2017-01-12 0:41 ` [PATCH 1/6] power: bq24190_charger: Call enable_irq() only at the end of probe() Tony Lindgren
2017-01-12 17:44 ` Sebastian Reichel
2017-01-12 20:02 ` Liam Breck
2017-01-12 20:58 ` Tony Lindgren
2017-01-12 21:40 ` Sebastian Reichel
2017-01-12 22:17 ` Liam Breck
2017-01-12 0:41 ` [PATCH 2/6] power: bq24190_charger: Fix irq triggering to IRQF_TRIGGER_FALLING Tony Lindgren
2017-01-12 0:41 ` [PATCH 3/6] power: bq24190_charger: Call power_supply_changed() only for relevant component Tony Lindgren
2017-01-12 0:41 ` [PATCH 4/6] power: bq24190_charger: Don't read fault register outside irq_handle_thread() Tony Lindgren
2017-01-12 1:32 ` Liam Breck
2017-01-12 2:11 ` Liam Breck
2017-01-12 16:22 ` Tony Lindgren [this message]
2017-01-12 0:41 ` [PATCH 5/6] power: bq24190_charger: Check the interrupt status on resume Tony Lindgren
2017-01-12 2:05 ` Liam Breck
2017-01-12 15:49 ` Tony Lindgren
2017-01-16 19:15 ` Mark Greer
2017-01-12 0:41 ` [PATCH 6/6] power: bq24190_charger: Use PM runtime autosuspend Tony Lindgren
2017-01-12 2:02 ` Liam Breck
2017-01-12 15:46 ` Tony Lindgren
2017-01-16 19:22 ` Mark Greer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170112162259.GF2630@atomide.com \
--to=tony@atomide.com \
--cc=kernel@networkimprov.net \
--cc=liam@networkimprov.net \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=matt@ranostay.consulting \
--cc=mgreer@animalcreek.com \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).