Skip to content

Commit 182fc88

Browse files
jeff-dagenaissre
authored andcommitted
power: supply: sbs-battery: add ability to disable charger broadcasts
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 unnecessarily and sometimes undesirably 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 <[email protected]> [rebased code] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent f0318bc commit 182fc88

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Optional properties :
1616
after an external change notification.
1717
- sbs,battery-detect-gpios : The gpio which signals battery detection and
1818
a flag specifying its polarity.
19+
- sbs,disable-charger-broadcasts: for systems without sbs compliant chargers
1920

2021
Example:
2122

@@ -25,4 +26,5 @@ Example:
2526
sbs,i2c-retry-count = <2>;
2627
sbs,poll-retry-count = <10>;
2728
sbs,battery-detect-gpios = <&gpio-controller 122 1>;
29+
sbs,disable-charger-broadcasts;
2830
}

drivers/power/supply/sbs-battery.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum sbs_capacity_mode {
6868
CAPACITY_MODE_AMPS = 0,
6969
CAPACITY_MODE_WATTS = BATTERY_MODE_CAPACITY_MASK
7070
};
71+
#define BATTERY_MODE_CHARGER_MASK (1<<14)
7172

7273
/* manufacturer access defines */
7374
#define MANUFACTURER_ACCESS_STATUS 0x0006
@@ -193,6 +194,7 @@ struct sbs_info {
193194
bool is_present;
194195
struct gpio_desc *gpio_detect;
195196
bool enable_detection;
197+
bool charger_broadcasts;
196198
int last_state;
197199
int poll_time;
198200
u32 i2c_retry_count;
@@ -207,6 +209,27 @@ static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
207209
static char chemistry[I2C_SMBUS_BLOCK_MAX + 1];
208210
static bool force_load;
209211

212+
static int sbs_read_word_data(struct i2c_client *client, u8 address);
213+
static int sbs_write_word_data(struct i2c_client *client, u8 address, u16 value);
214+
215+
static void sbs_disable_charger_broadcasts(struct sbs_info *chip)
216+
{
217+
int val = sbs_read_word_data(chip->client, BATTERY_MODE_OFFSET);
218+
if (val < 0)
219+
goto exit;
220+
221+
val |= BATTERY_MODE_CHARGER_MASK;
222+
223+
val = sbs_write_word_data(chip->client, BATTERY_MODE_OFFSET, val);
224+
225+
exit:
226+
if (val < 0)
227+
dev_err(&chip->client->dev,
228+
"Failed to disable charger broadcasting: %d\n", val);
229+
else
230+
dev_dbg(&chip->client->dev, "%s\n", __func__);
231+
}
232+
210233
static int sbs_update_presence(struct sbs_info *chip, bool is_present)
211234
{
212235
struct i2c_client *client = chip->client;
@@ -260,6 +283,9 @@ static int sbs_update_presence(struct sbs_info *chip, bool is_present)
260283
dev_dbg(&client->dev, "PEC: %s\n", (client->flags & I2C_CLIENT_PEC) ?
261284
"enabled" : "disabled");
262285

286+
if (!chip->is_present && is_present && !chip->charger_broadcasts)
287+
sbs_disable_charger_broadcasts(chip);
288+
263289
chip->is_present = true;
264290

265291
return 0;
@@ -1017,6 +1043,9 @@ static int sbs_probe(struct i2c_client *client,
10171043
}
10181044
chip->i2c_retry_count = chip->i2c_retry_count + 1;
10191045

1046+
chip->charger_broadcasts = !of_property_read_bool(client->dev.of_node,
1047+
"sbs,disable-charger-broadcasts");
1048+
10201049
chip->gpio_detect = devm_gpiod_get_optional(&client->dev,
10211050
"sbs,battery-detect", GPIOD_IN);
10221051
if (IS_ERR(chip->gpio_detect)) {

0 commit comments

Comments
 (0)