From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: Angus Ainslie <angus@akkea.ca>, Rob Herring <robh+dt@kernel.org>,
Sebastian Reichel <sre@kernel.org>,
Yauhen Kharuzhy <jekhor@gmail.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org
Subject: [PATCH v3 2/8] power: bq25890: fix ADC mode configuration
Date: Mon, 04 May 2020 21:47:45 +0200 [thread overview]
Message-ID: <e898499881c3a95daf11c117ac16de49bab9ea73.1588621247.git.mirq-linux@rere.qmqm.pl> (raw)
In-Reply-To: <cover.1588621247.git.mirq-linux@rere.qmqm.pl>
Datasheet describes two modes for reading ADC measurements:
1. continuous, 1 Hz - enabled and started by CONV_RATE bit
2. one-shot - triggered by CONV_START bit
In continuous mode, CONV_START is read-only and signifies an ongoing
conversion.
Change the code to follow the datasheet and really disable continuous
mode for power saving.
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
v3: drop dependency on new input/output properties
---
drivers/power/supply/bq25890_charger.c | 31 +++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 70ecc38fe772..325fdd1b1d23 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -126,6 +126,7 @@ static const struct regmap_access_table bq25890_writeable_regs = {
static const struct regmap_range bq25890_volatile_reg_ranges[] = {
regmap_reg_range(0x00, 0x00),
+ regmap_reg_range(0x02, 0x02),
regmap_reg_range(0x09, 0x09),
regmap_reg_range(0x0b, 0x14),
};
@@ -374,18 +375,38 @@ enum bq25890_chrg_fault {
CHRG_FAULT_TIMER_EXPIRED,
};
+static bool bq25890_is_adc_property(enum power_supply_property psp)
+{
+ switch (psp) {
+ case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+ case POWER_SUPPLY_PROP_CURRENT_NOW:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
static int bq25890_power_supply_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
- int ret;
struct bq25890_device *bq = power_supply_get_drvdata(psy);
struct bq25890_state state;
+ bool do_adc_conv;
+ int ret;
mutex_lock(&bq->lock);
state = bq->state;
+ do_adc_conv = !state.online && bq25890_is_adc_property(psp);
+ if (do_adc_conv)
+ bq25890_field_write(bq, F_CONV_START, 1);
mutex_unlock(&bq->lock);
+ if (do_adc_conv)
+ regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START],
+ ret, !ret, 25000, 1000000);
+
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
if (!state.online)
@@ -623,8 +644,8 @@ static int bq25890_hw_init(struct bq25890_device *bq)
}
}
- /* Configure ADC for continuous conversions. This does not enable it. */
- ret = bq25890_field_write(bq, F_CONV_RATE, 1);
+ /* Configure ADC for continuous conversions when charging */
+ ret = bq25890_field_write(bq, F_CONV_RATE, !!bq->state.online);
if (ret < 0) {
dev_dbg(bq->dev, "Config ADC failed %d\n", ret);
return ret;
@@ -966,7 +987,7 @@ static int bq25890_suspend(struct device *dev)
* If charger is removed, while in suspend, make sure ADC is diabled
* since it consumes slightly more power.
*/
- return bq25890_field_write(bq, F_CONV_START, 0);
+ return bq25890_field_write(bq, F_CONV_RATE, 0);
}
static int bq25890_resume(struct device *dev)
@@ -982,7 +1003,7 @@ static int bq25890_resume(struct device *dev)
/* Re-enable ADC only if charger is plugged in. */
if (bq->state.online) {
- ret = bq25890_field_write(bq, F_CONV_START, 1);
+ ret = bq25890_field_write(bq, F_CONV_RATE, 1);
if (ret < 0)
return ret;
}
--
2.20.1
next prev parent reply other threads:[~2020-05-04 19:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-04 19:47 [PATCH v3 0/8] power: supply: bq25890: fix and extend Michał Mirosław
2020-05-04 19:47 ` [PATCH v3 1/8] power: bq25890: use proper CURRENT_NOW property for I_BAT Michał Mirosław
2020-05-04 19:47 ` [PATCH v3 3/8] power: bq25890: update state on property read Michał Mirosław
2020-05-04 19:47 ` Michał Mirosław [this message]
2020-05-04 19:47 ` [PATCH v3 4/8] power: bq25890: implement CHARGE_TYPE property Michał Mirosław
2020-05-04 19:47 ` [PATCH v3 5/8] power: bq25890: implement PRECHARGE_CURRENT property Michał Mirosław
2020-05-04 19:47 ` [PATCH v3 6/8] power: bq25890: implement INPUT_CURRENT_LIMIT property Michał Mirosław
2020-05-04 19:47 ` [PATCH v3 8/8] power: bq25890: document IBAT compensation DT properties Michał Mirosław
2020-05-12 22:59 ` Rob Herring
2020-05-04 19:47 ` [PATCH v3 7/8] power: bq25890: support IBAT compensation Michał Mirosław
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=e898499881c3a95daf11c117ac16de49bab9ea73.1588621247.git.mirq-linux@rere.qmqm.pl \
--to=mirq-linux@rere.qmqm.pl \
--cc=angus@akkea.ca \
--cc=devicetree@vger.kernel.org \
--cc=jekhor@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=robh+dt@kernel.org \
--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).