From: Sebastian Reichel <sebastian.reichel@collabora.com> To: Sebastian Reichel <sre@kernel.org>, Rob Herring <robh+dt@kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "Rafael J . Wysocki" <rafael@kernel.org> Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Jean-Francois Dagenais <jeff.dagenais@gmail.com>, Sebastian Reichel <sebastian.reichel@collabora.com> Subject: [PATCHv1 15/19] power: supply: sbs-battery: add ability to disable charger broadcasts Date: Wed, 13 May 2020 20:56:11 +0200 [thread overview] Message-ID: <20200513185615.508236-16-sebastian.reichel@collabora.com> (raw) In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> From: Jean-Francois Dagenais <jeff.dagenais@gmail.com> In certain designs, it is possible to add a battery on a populated i2c bus without an sbs compliant charger. In that case, the battery will un-necessarily and sometimes un-desirably master the bus trying to write info in the charger. It is observed in many occasion that these battery "broadcasts" are even corrupting other ongoing master to slave communication. I.e. the multi-master support in the battery is inadequate. Thankfully, the CHARGER_MODE bit allows designers to disable that SBS battery behaviour. This needs to be done once when the battery is first seen on the bus. Signed-off-by: Jean-Francois Dagenais <jeff.dagenais@gmail.com> [rebased code] Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> --- .../bindings/power/supply/sbs_sbs-battery.txt | 2 ++ drivers/power/supply/sbs-battery.c | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt index fa5a8b516dbf..a5093ccef5c5 100644 --- a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt +++ b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt @@ -16,6 +16,7 @@ Optional properties : after an external change notification. - sbs,battery-detect-gpios : The gpio which signals battery detection and a flag specifying its polarity. + - sbs,disable-charger-broadcasts: for systems without sbs compliant chargers Example: @@ -25,4 +26,5 @@ Example: sbs,i2c-retry-count = <2>; sbs,poll-retry-count = <10>; sbs,battery-detect-gpios = <&gpio-controller 122 1>; + sbs,disable-charger-broadcasts; } diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index e3c685b2c247..7c6905a486da 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -68,6 +68,7 @@ enum sbs_capacity_mode { CAPACITY_MODE_AMPS = 0, CAPACITY_MODE_WATTS = BATTERY_MODE_CAPACITY_MASK }; +#define BATTERY_MODE_CHARGER_MASK (1<<14) /* manufacturer access defines */ #define MANUFACTURER_ACCESS_STATUS 0x0006 @@ -193,6 +194,7 @@ struct sbs_info { bool is_present; struct gpio_desc *gpio_detect; bool enable_detection; + bool charger_broadcasts; int last_state; int poll_time; u32 i2c_retry_count; @@ -207,6 +209,27 @@ static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; static char chemistry[I2C_SMBUS_BLOCK_MAX + 1]; static bool force_load; +static int sbs_read_word_data(struct i2c_client *client, u8 address); +static int sbs_write_word_data(struct i2c_client *client, u8 address, u16 value); + +static void sbs_disable_charger_broadcasts(struct sbs_info *chip) +{ + int val = sbs_read_word_data(chip->client, BATTERY_MODE_OFFSET); + if (val < 0) + goto exit; + + val |= BATTERY_MODE_CHARGER_MASK; + + val = sbs_write_word_data(chip->client, BATTERY_MODE_OFFSET, val); + +exit: + if (val < 0) + dev_err(&chip->client->dev, + "Failed to disable charger broadcasting: %d\n", val); + else + dev_dbg(&chip->client->dev, "%s\n", __func__); +} + static int sbs_update_presence(struct sbs_info *chip, bool is_present) { struct i2c_client *client = chip->client; @@ -260,6 +283,9 @@ static int sbs_update_presence(struct sbs_info *chip, bool is_present) dev_dbg(&client->dev, "PEC: %s\n", (client->flags & I2C_CLIENT_PEC) ? "enabled" : "disabled"); + if (!chip->is_present && is_present && !chip->charger_broadcasts) + sbs_disable_charger_broadcasts(chip); + chip->is_present = true; return 0; @@ -1017,6 +1043,9 @@ static int sbs_probe(struct i2c_client *client, } chip->i2c_retry_count = chip->i2c_retry_count + 1; + chip->charger_broadcasts = !of_property_read_bool(client->dev.of_node, + "sbs,disable-charger-broadcasts"); + chip->gpio_detect = devm_gpiod_get_optional(&client->dev, "sbs,battery-detect", GPIOD_IN); if (IS_ERR(chip->gpio_detect)) { -- 2.26.2
next prev parent reply other threads:[~2020-05-13 18:56 UTC|newest] Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-05-13 18:55 [PATCHv1 00/19] Improve SBS battery support Sebastian Reichel 2020-05-13 18:55 ` [PATCHv1 01/19] kobject: increase allowed number of uevent variables Sebastian Reichel 2020-05-14 6:11 ` Greg Kroah-Hartman 2020-05-15 14:45 ` Emil Velikov 2020-05-13 18:55 ` [PATCHv1 02/19] power: supply: core: add capacity error margin property Sebastian Reichel 2020-05-13 18:55 ` [PATCHv1 03/19] power: supply: core: add manufacture date properties Sebastian Reichel 2020-05-15 14:47 ` Emil Velikov 2020-05-15 15:14 ` Sebastian Reichel 2020-05-15 16:01 ` Emil Velikov 2020-05-13 18:56 ` [PATCHv1 04/19] power: supply: core: add POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 05/19] power: supply: sbs-battery: Add TI BQ20Z65 support Sebastian Reichel 2020-05-28 2:37 ` Rob Herring 2020-05-13 18:56 ` [PATCHv1 06/19] power: supply: sbs-battery: add POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN support Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 07/19] power: supply: sbs-battery: simplify read_read_string_data Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 08/19] power: supply: sbs-battery: add PEC support Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 09/19] power: supply: sbs-battery: add POWER_SUPPLY_PROP_CURRENT_AVG support Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 10/19] power: supply: sbs-battery: Improve POWER_SUPPLY_PROP_TECHNOLOGY support Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 11/19] power: supply: sbs-battery: add POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT/VOLTAGE_MAX support Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 12/19] power: supply: sbs-battery: add MANUFACTURE_DATE support Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 13/19] power: supply: sbs-battery: add POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED support Sebastian Reichel 2020-05-15 15:35 ` Emil Velikov 2020-05-13 18:56 ` [PATCHv1 14/19] power: supply: sbs-battery: fix idle battery status Sebastian Reichel 2020-05-13 18:56 ` Sebastian Reichel [this message] 2020-05-15 14:57 ` [PATCHv1 15/19] power: supply: sbs-battery: add ability to disable charger broadcasts Emil Velikov 2020-05-13 18:56 ` [PATCHv1 16/19] power: supply: sbs-battery: switch from of_property_* to device_property_* Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 17/19] power: supply: sbs-battery: switch to i2c's probe_new Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 18/19] power: supply: sbs-battery: constify power-supply property array Sebastian Reichel 2020-05-13 18:56 ` [PATCHv1 19/19] dt-bindings: power: sbs-battery: Convert to yaml Sebastian Reichel 2020-05-28 2:40 ` Rob Herring 2020-05-28 22:44 ` [PATCHv1 00/19] Improve SBS battery support Sebastian Reichel 2020-05-29 16:27 ` Pavel Machek 2020-06-01 21:57 ` Sebastian Reichel [not found] ` <CGME20200601104027eucas1p2b076ee860520d709e8178c41550653f7@eucas1p2.samsung.com> 2020-06-01 10:40 ` Marek Szyprowski 2020-06-01 17:05 ` Sebastian Reichel 2020-06-02 7:17 ` Marek Szyprowski 2020-06-02 18:01 ` Sebastian Reichel 2020-06-03 18:49 ` Marek Szyprowski
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=20200513185615.508236-16-sebastian.reichel@collabora.com \ --to=sebastian.reichel@collabora.com \ --cc=devicetree@vger.kernel.org \ --cc=gregkh@linuxfoundation.org \ --cc=jeff.dagenais@gmail.com \ --cc=kernel@collabora.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pm@vger.kernel.org \ --cc=rafael@kernel.org \ --cc=robh+dt@kernel.org \ --cc=sre@kernel.org \ --subject='Re: [PATCHv1 15/19] power: supply: sbs-battery: add ability to disable charger broadcasts' \ /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
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.