Skip to content

Commit ff28fce

Browse files
rhkleinenomsg
authored andcommitted
bq20z75: Add i2c retry mechanism
With the support of platform data, now adding support for option i2c retries on read/write failures. Ths is specified through the optional platform data. Signed-off-by: Rhyland Klein <rklein@nvidia.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
1 parent bb87910 commit ff28fce

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎drivers/power/bq20z75.c‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,55 @@ struct bq20z75_info {
156156

157157
static int bq20z75_read_word_data(struct i2c_client *client, u8 address)
158158
{
159-
s32 ret;
159+
struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client);
160+
s32 ret = 0;
161+
int retries = 1;
162+
163+
if (bq20z75_device->pdata)
164+
retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1);
165+
166+
while (retries > 0) {
167+
ret = i2c_smbus_read_word_data(client, address);
168+
if (ret >= 0)
169+
break;
170+
retries--;
171+
}
160172

161-
ret = i2c_smbus_read_word_data(client, address);
162173
if (ret < 0) {
163-
dev_err(&client->dev,
174+
dev_warn(&client->dev,
164175
"%s: i2c read at address 0x%x failed\n",
165176
__func__, address);
166177
return ret;
167178
}
179+
168180
return le16_to_cpu(ret);
169181
}
170182

171183
static int bq20z75_write_word_data(struct i2c_client *client, u8 address,
172184
u16 value)
173185
{
174-
s32 ret;
186+
struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client);
187+
s32 ret = 0;
188+
int retries = 1;
189+
190+
if (bq20z75_device->pdata)
191+
retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1);
192+
193+
while (retries > 0) {
194+
ret = i2c_smbus_write_word_data(client, address,
195+
le16_to_cpu(value));
196+
if (ret >= 0)
197+
break;
198+
retries--;
199+
}
175200

176-
ret = i2c_smbus_write_word_data(client, address, le16_to_cpu(value));
177201
if (ret < 0) {
178-
dev_err(&client->dev,
202+
dev_warn(&client->dev,
179203
"%s: i2c write to address 0x%x failed\n",
180204
__func__, address);
181205
return ret;
182206
}
207+
183208
return 0;
184209
}
185210

‎include/linux/power/bq20z75.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
* struct bq20z75_platform_data - platform data for bq20z75 devices
2929
* @battery_detect: GPIO which is used to detect battery presence
3030
* @battery_detect_present: gpio state when battery is present (0 / 1)
31+
* @i2c_retry_count: # of times to retry on i2c IO failure
3132
*/
3233
struct bq20z75_platform_data {
3334
int battery_detect;
3435
int battery_detect_present;
36+
int i2c_retry_count;
3537
};
3638

3739
#endif

0 commit comments

Comments
 (0)