All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liam Breck <liam@networkimprov.net>
To: "Andrew F. Davis" <afd@ti.com>, linux-pm@vger.kernel.org
Cc: Liam Breck <kernel@networkimprov.net>
Subject: [PATCH v12.6 11/11] power: bq27xxx_battery: Disable flash/NVM data memory update
Date: Sun,  9 Apr 2017 22:07:12 -0700	[thread overview]
Message-ID: <20170410050712.930-8-liam@networkimprov.net> (raw)
In-Reply-To: <20170410050712.930-1-liam@networkimprov.net>

From: Liam Breck <kernel@networkimprov.net>

On chips with flash/NVM data memory, it's not clear whether battery
characteristics from devicetree monitored-battery or data memory should
take precedence. The gauge may be packaged in a smart battery or resident
on the circuit board, and in either case, the battery type may have changed
since the dtb was installed. However, it is safe to assume that a device
vendor who includes battery characteristics in devicetree knows what
they're doing.

Drop module param use_monitored_battery. If devicetree monitored-battery
values differ from data memory registers, emit a warning instead of
updating flash/NVM.

This is controversial; the patch author believes ignoring devicetree is
the wrong decision, that its integrity should be trusted. But as the
patch does not impact him directly, he suggests others lobby the
maintainers to revert it :-)

Signed-off-by: Liam Breck <kernel@networkimprov.net>
---
 drivers/power/supply/bq27xxx_battery.c | 13 ++++++-------
 include/linux/power/bq27xxx_battery.h  |  1 +
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index b579304..7234e6f 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -809,11 +809,6 @@ static u32 bq27xxx_unseal_keys[] = {
 };
 
 
-static bool bq27xxx_dt_battery = true;
-module_param_named(use_monitored_battery, bq27xxx_dt_battery, bool, S_IRUGO);
-MODULE_PARM_DESC(use_monitored_battery,
- "Use devicetree monitored-battery config if present. Default is 1/y.");
-
 static int poll_interval_param_set(const char *val, const struct kernel_param *kp)
 {
 	struct bq27xxx_device_info *di;
@@ -1035,8 +1030,10 @@ static void bq27xxx_battery_update_dm_block(struct bq27xxx_device_info *di,
 		return;
 	}
 
-	if (!bq27xxx_dt_battery) {
-		dev_warn(di->dev, "%s has %u; update to %u disallowed by use_monitored_battery=0\n",
+	if (!di->ram_chip) {
+		/* devicetree and NVM differ; defer to NVM. this may be wrong.   */
+		/* revert this or allow override via DT property or module param */
+		dev_warn(di->dev, "%s has %u; update to %u disallowed for flash/NVM\n",
 		         str, be16_to_cpup(prev), val);
 		return;
 	}
@@ -1822,6 +1819,8 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
 
 	bq27xxx_battery_dbg_regs_dupes(di);
 
+	di->ram_chip = di->chip == BQ27421 || di->chip == BQ27441 || di->chip == BQ27621;
+
 	di->unseal_key = bq27xxx_unseal_keys[di->chip];
 	di->dm_regs = bq27xxx_dm_regs[di->chip];
 	di->chip = bq27xxx_chips[di->chip];
diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h
index 7c0f3d3..4702b86 100644
--- a/include/linux/power/bq27xxx_battery.h
+++ b/include/linux/power/bq27xxx_battery.h
@@ -76,6 +76,7 @@ struct bq27xxx_device_info {
 	struct device *dev;
 	int id;
 	enum bq27xxx_chip chip;
+	bool ram_chip;
 	const char *name;
 	struct bq27xxx_dm_reg *dm_regs;
 	u32 unseal_key;
-- 
2.9.3

  parent reply	other threads:[~2017-04-10  5:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-10  5:07 [PATCH v12.6 0/11] bq27xxx_battery partial series Liam Breck
2017-04-10  5:07 ` [PATCH v12.6 05/11] power: bq27xxx_battery: Add chip data memory read/write support Liam Breck
2017-04-10 14:47   ` Andrew F. Davis
2017-04-10  5:07 ` [PATCH v12.6 06/11] power: bq27xxx_battery: Add power_supply_battery_info support Liam Breck
2017-04-10  5:07 ` [PATCH v12.6 07/11] power: bq27xxx_battery: Enable data memory update for certain chips Liam Breck
2017-04-10  5:07 ` [PATCH v12.6 08/11] devicetree: power: bq27xxx: Add monitored-battery documentation Liam Breck
2017-04-13 20:15   ` Rob Herring
2017-04-10  5:07 ` [PATCH v12.6 09/11] power: bq27xxx_battery: Flag identical register maps when in debug mode Liam Breck
2017-04-10  5:07 ` [PATCH v12.6 10/11] power: bq27xxx_battery: Remove duplicate register arrays Liam Breck
2017-04-10  5:07 ` Liam Breck [this message]
2017-04-10 14:46 ` [PATCH v12.6 0/11] bq27xxx_battery partial series Andrew F. Davis

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=20170410050712.930-8-liam@networkimprov.net \
    --to=liam@networkimprov.net \
    --cc=afd@ti.com \
    --cc=kernel@networkimprov.net \
    --cc=linux-pm@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.