From: Tony Lindgren <tony@atomide.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: "Mark A . Greer" <mgreer@animalcreek.com>,
linux-pm@vger.kernel.org, linux-omap@vger.kernel.org,
Matt Ranostay <matt@ranostay.consulting>,
Liam Breck <kernel@networkimprov.net>
Subject: [PATCH 5/6] power: bq24190_charger: Check the interrupt status on resume
Date: Wed, 11 Jan 2017 16:41:53 -0800 [thread overview]
Message-ID: <20170112004154.31568-6-tony@atomide.com> (raw)
In-Reply-To: <20170112004154.31568-1-tony@atomide.com>
Some SoCs like omap3 can configure GPIO irqs to use Linux generic
dedicated wakeirq support. If the dedicated wakeirq is configured,
the SoC will use a always-on interrupt controller to produce wake-up
events.
If bq24190 is configured for dedicated wakeirq, we need to check the
interrupt status on PM runtime resume. This is because the Linux
generic wakeirq will call pm_runtime_resume() on the device on a
wakeirq. And as the bq24190 interrupt is falling edge sensitive
and only active for 250 us, there will be no device interrupt seen
by the runtime SoC IRQ controller.
Note that this can cause spurious interrupts on omap3 devices with
bq24190 connected to gpio banks 2 - 5 as there's a glitch on those
pins waking from off mode as listed in "Advisory 1.45". Devices
with this issue should not configure the optional wakeirq interrupt
in the dts file.
Cc: Mark A. Greer <mgreer@animalcreek.com>
Cc: Matt Ranostay <matt@ranostay.consulting>
Cc: Liam Breck <kernel@networkimprov.net>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
drivers/power/supply/bq24190_charger.c | 58 ++++++++++++++++++++++++++++------
1 file changed, 49 insertions(+), 9 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
@@ -156,6 +156,8 @@ struct bq24190_dev_info {
unsigned int gpio_int;
unsigned int irq;
struct mutex f_reg_lock;
+ bool initialized;
+ bool irq_event;
u8 f_reg;
u8 ss_reg;
u8 watchdog;
@@ -1157,9 +1159,8 @@ static const struct power_supply_desc bq24190_battery_desc = {
.property_is_writeable = bq24190_battery_property_is_writeable,
};
-static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
+static void bq24190_check_status(struct bq24190_dev_info *bdi)
{
- struct bq24190_dev_info *bdi = data;
const u8 battery_mask_ss = BQ24190_REG_SS_CHRG_STAT_MASK;
const u8 battery_mask_f = BQ24190_REG_F_BAT_FAULT_MASK |
BQ24190_REG_F_NTC_FAULT_MASK;
@@ -1167,15 +1168,13 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
u8 ss_reg = 0, f_reg = 0;
int i, ret;
- pm_runtime_get_sync(bdi->dev);
-
/* We need to read f_reg twice if fault is set to get correct value */
i = 0;
do {
ret = bq24190_read(bdi, BQ24190_REG_F, &f_reg);
if (ret < 0) {
dev_err(bdi->dev, "Can't read F reg: %d\n", ret);
- goto out;
+ return;
}
} while (f_reg && ++i < 2);
@@ -1231,11 +1230,18 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
if (alert_battery)
power_supply_changed(bdi->battery);
-out:
- pm_runtime_put_sync(bdi->dev);
-
dev_dbg(bdi->dev, "ss_reg: 0x%02x, f_reg: 0x%02x\n", ss_reg, f_reg);
+}
+static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
+{
+ struct bq24190_dev_info *bdi = data;
+
+ bdi->irq_event = true;
+ pm_runtime_get_sync(bdi->dev);
+ bq24190_check_status(bdi);
+ pm_runtime_put_sync(bdi->dev);
+ bdi->irq_event = false;
return IRQ_HANDLED;
}
@@ -1404,6 +1410,7 @@ static int bq24190_probe(struct i2c_client *client,
}
enable_irq(bdi->irq);
+ bdi->initialized = 1;
return 0;
@@ -1439,6 +1446,35 @@ static int bq24190_remove(struct i2c_client *client)
return 0;
}
+static int bq24190_runtime_suspend(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
+
+ if (!bdi->initialized)
+ return 0;
+
+ dev_dbg(bdi->dev, "%s\n", __func__);
+
+ return 0;
+}
+
+static int bq24190_runtime_resume(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
+
+ if (!bdi->initialized)
+ return 0;
+
+ if (!bdi->irq_event) {
+ dev_dbg(bdi->dev, "checking events on possible wakeirq\n");
+ bq24190_check_status(bdi);
+ }
+
+ return 0;
+}
+
#ifdef CONFIG_PM_SLEEP
static int bq24190_pm_suspend(struct device *dev)
{
@@ -1474,7 +1510,11 @@ static int bq24190_pm_resume(struct device *dev)
}
#endif
-static SIMPLE_DEV_PM_OPS(bq24190_pm_ops, bq24190_pm_suspend, bq24190_pm_resume);
+static const struct dev_pm_ops bq24190_pm_ops = {
+ SET_RUNTIME_PM_OPS(bq24190_runtime_suspend, bq24190_runtime_resume,
+ NULL)
+ SET_SYSTEM_SLEEP_PM_OPS(bq24190_pm_suspend, bq24190_pm_resume)
+};
/*
* Only support the bq24190 right now. The bq24192, bq24192i, and bq24193
--
2.11.0
next prev parent reply other threads:[~2017-01-12 0:41 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
2017-01-12 0:41 ` Tony Lindgren [this message]
2017-01-12 2:05 ` [PATCH 5/6] power: bq24190_charger: Check the interrupt status on resume 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=20170112004154.31568-6-tony@atomide.com \
--to=tony@atomide.com \
--cc=kernel@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).