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>
This commit is contained in:
committed by
Anton Vorontsov
parent
bb87910160
commit
ff28fcef1b
@@ -156,30 +156,55 @@ struct bq20z75_info {
|
|||||||
|
|
||||||
static int bq20z75_read_word_data(struct i2c_client *client, u8 address)
|
static int bq20z75_read_word_data(struct i2c_client *client, u8 address)
|
||||||
{
|
{
|
||||||
s32 ret;
|
struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client);
|
||||||
|
s32 ret = 0;
|
||||||
|
int retries = 1;
|
||||||
|
|
||||||
|
if (bq20z75_device->pdata)
|
||||||
|
retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1);
|
||||||
|
|
||||||
|
while (retries > 0) {
|
||||||
|
ret = i2c_smbus_read_word_data(client, address);
|
||||||
|
if (ret >= 0)
|
||||||
|
break;
|
||||||
|
retries--;
|
||||||
|
}
|
||||||
|
|
||||||
ret = i2c_smbus_read_word_data(client, address);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&client->dev,
|
dev_warn(&client->dev,
|
||||||
"%s: i2c read at address 0x%x failed\n",
|
"%s: i2c read at address 0x%x failed\n",
|
||||||
__func__, address);
|
__func__, address);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return le16_to_cpu(ret);
|
return le16_to_cpu(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bq20z75_write_word_data(struct i2c_client *client, u8 address,
|
static int bq20z75_write_word_data(struct i2c_client *client, u8 address,
|
||||||
u16 value)
|
u16 value)
|
||||||
{
|
{
|
||||||
s32 ret;
|
struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client);
|
||||||
|
s32 ret = 0;
|
||||||
|
int retries = 1;
|
||||||
|
|
||||||
|
if (bq20z75_device->pdata)
|
||||||
|
retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1);
|
||||||
|
|
||||||
|
while (retries > 0) {
|
||||||
|
ret = i2c_smbus_write_word_data(client, address,
|
||||||
|
le16_to_cpu(value));
|
||||||
|
if (ret >= 0)
|
||||||
|
break;
|
||||||
|
retries--;
|
||||||
|
}
|
||||||
|
|
||||||
ret = i2c_smbus_write_word_data(client, address, le16_to_cpu(value));
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&client->dev,
|
dev_warn(&client->dev,
|
||||||
"%s: i2c write to address 0x%x failed\n",
|
"%s: i2c write to address 0x%x failed\n",
|
||||||
__func__, address);
|
__func__, address);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,10 +28,12 @@
|
|||||||
* struct bq20z75_platform_data - platform data for bq20z75 devices
|
* struct bq20z75_platform_data - platform data for bq20z75 devices
|
||||||
* @battery_detect: GPIO which is used to detect battery presence
|
* @battery_detect: GPIO which is used to detect battery presence
|
||||||
* @battery_detect_present: gpio state when battery is present (0 / 1)
|
* @battery_detect_present: gpio state when battery is present (0 / 1)
|
||||||
|
* @i2c_retry_count: # of times to retry on i2c IO failure
|
||||||
*/
|
*/
|
||||||
struct bq20z75_platform_data {
|
struct bq20z75_platform_data {
|
||||||
int battery_detect;
|
int battery_detect;
|
||||||
int battery_detect_present;
|
int battery_detect_present;
|
||||||
|
int i2c_retry_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user