From 05400f3b6392f7480303781bcf96eb64896ba5d4 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 10 Oct 2004 12:03:48 +0000 Subject: [PATCH] Retry on read errors. Contributed by David Knierim. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2719 7894878c-1315-0410-8ee3-d5d059ff63e0 --- kernel/chips/lm87.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/kernel/chips/lm87.c b/kernel/chips/lm87.c index d7ce044e..acdf1d8b 100644 --- a/kernel/chips/lm87.c +++ b/kernel/chips/lm87.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "version.h" #include "sensors_vid.h" @@ -468,8 +469,8 @@ static int lm87_detach_client(struct i2c_client *client) sysctl_id); if ((err = i2c_detach_client(client))) { - printk - ("lm87.o: Client deregistration failed, client not detached.\n"); + printk(KERN_ERR "lm87.o: Client deregistration failed, " + "client not detached\n"); return err; } @@ -478,9 +479,24 @@ static int lm87_detach_client(struct i2c_client *client) return 0; } +#define MAX_RETRIES 5 + static int lm87_read_value(struct i2c_client *client, u8 reg) { - return 0xFF & i2c_smbus_read_byte_data(client, reg); + int value, i; + + /* Retry in case of read errors */ + for (i = 1; i <= MAX_RETRIES; i++) { + if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) + return value; + + printk(KERN_WARNING "lm87.o: Read byte data failed, " + "address 0x%02x\n", reg); + mdelay(i); + } + + /* what to return in case of error? */ + return 0; } static int lm87_write_value(struct i2c_client *client, u8 reg, u8 value) @@ -943,7 +959,7 @@ void lm87_vrm(struct i2c_client *client, int operation, int ctl_name, static int __init sm_lm87_init(void) { - printk("lm87.o version %s (%s)\n", LM_VERSION, LM_DATE); + printk(KERN_INFO "lm87.o version %s (%s)\n", LM_VERSION, LM_DATE); return i2c_add_driver(&LM87_driver); }