aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorRhyland Klein <rklein@nvidia.com>2011-02-28 19:55:29 -0500
committerAnton Vorontsov <cbouatmailru@gmail.com>2011-03-01 14:24:19 -0500
commitff28fcef1bedcfbdf49500fee1573dc2f3eedb22 (patch)
treec9aa6c77a3c79b997114717ccb7f4e7604b8a9fc /drivers/power
parentbb879101606dd7235d8f4ecd0f707b63281d0838 (diff)
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>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/bq20z75.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/drivers/power/bq20z75.c b/drivers/power/bq20z75.c
index a51e98d74d34..e82d10e25e8c 100644
--- a/drivers/power/bq20z75.c
+++ b/drivers/power/bq20z75.c
@@ -156,30 +156,55 @@ struct bq20z75_info {
156 156
157static int bq20z75_read_word_data(struct i2c_client *client, u8 address) 157static int bq20z75_read_word_data(struct i2c_client *client, u8 address)
158{ 158{
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 }
160 172
161 ret = i2c_smbus_read_word_data(client, address);
162 if (ret < 0) { 173 if (ret < 0) {
163 dev_err(&client->dev, 174 dev_warn(&client->dev,
164 "%s: i2c read at address 0x%x failed\n", 175 "%s: i2c read at address 0x%x failed\n",
165 __func__, address); 176 __func__, address);
166 return ret; 177 return ret;
167 } 178 }
179
168 return le16_to_cpu(ret); 180 return le16_to_cpu(ret);
169} 181}
170 182
171static int bq20z75_write_word_data(struct i2c_client *client, u8 address, 183static int bq20z75_write_word_data(struct i2c_client *client, u8 address,
172 u16 value) 184 u16 value)
173{ 185{
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 }
175 200
176 ret = i2c_smbus_write_word_data(client, address, le16_to_cpu(value));
177 if (ret < 0) { 201 if (ret < 0) {
178 dev_err(&client->dev, 202 dev_warn(&client->dev,
179 "%s: i2c write to address 0x%x failed\n", 203 "%s: i2c write to address 0x%x failed\n",
180 __func__, address); 204 __func__, address);
181 return ret; 205 return ret;
182 } 206 }
207
183 return 0; 208 return 0;
184} 209}
185 210