From: rklein@nvidia.com
To: Anton Vorontsov <cbouatmailru@gmail.com>
Cc: olof@lixom.net, linux-kernel@vger.kernel.org,
Rhyland Klein <rklein@nvidia.com>
Subject: [PATCH 2/4] power: bq20z75: add i2c retry mechanism
Date: Mon, 28 Feb 2011 16:55:29 -0800 [thread overview]
Message-ID: <1298940931-17552-3-git-send-email-rklein@nvidia.com> (raw)
In-Reply-To: <1298940931-17552-1-git-send-email-rklein@nvidia.com>
From: Rhyland Klein <rklein@nvidia.com>
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>
---
drivers/power/bq20z75.c | 37 +++++++++++++++++++++++++++++++------
include/linux/power/bq20z75.h | 2 ++
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/drivers/power/bq20z75.c b/drivers/power/bq20z75.c
index a51e98d..e82d10e 100644
--- a/drivers/power/bq20z75.c
+++ b/drivers/power/bq20z75.c
@@ -156,30 +156,55 @@ struct bq20z75_info {
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) {
- dev_err(&client->dev,
+ dev_warn(&client->dev,
"%s: i2c read at address 0x%x failed\n",
__func__, address);
return ret;
}
+
return le16_to_cpu(ret);
}
static int bq20z75_write_word_data(struct i2c_client *client, u8 address,
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) {
- dev_err(&client->dev,
+ dev_warn(&client->dev,
"%s: i2c write to address 0x%x failed\n",
__func__, address);
return ret;
}
+
return 0;
}
diff --git a/include/linux/power/bq20z75.h b/include/linux/power/bq20z75.h
index 0e1b8a2..b0843b6 100644
--- a/include/linux/power/bq20z75.h
+++ b/include/linux/power/bq20z75.h
@@ -28,10 +28,12 @@
* struct bq20z75_platform_data - platform data for bq20z75 devices
* @battery_detect: GPIO which is used to detect battery presence
* @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 {
int battery_detect;
int battery_detect_present;
+ int i2c_retry_count;
};
#endif
--
1.7.0.4
next prev parent reply other threads:[~2011-03-01 1:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-01 0:55 [PATCH 0/4] power: bq20z75: update support rklein
2011-03-01 0:55 ` [PATCH 1/4] power: bq20z75: add optional battery detect gpio rklein
2011-03-01 0:55 ` rklein [this message]
2011-03-01 0:55 ` [PATCH 3/4] power: bq20z75: add support for POWER_NOW rklein
2011-03-01 19:39 ` Anton Vorontsov
2011-03-01 0:55 ` [PATCH 4/4] power_supply: update power_supply_is_watt_property rklein
2011-03-01 19:41 ` [PATCH 0/4] power: bq20z75: update support Anton Vorontsov
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=1298940931-17552-3-git-send-email-rklein@nvidia.com \
--to=rklein@nvidia.com \
--cc=cbouatmailru@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=olof@lixom.net \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox