All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ] LM87: Add code to retry reads on error
@ 2005-05-19  6:25 David Knierim
  2005-05-19  6:25 ` David Knierim
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Knierim @ 2005-05-19  6:25 UTC (permalink / raw)
  To: lm-sensors

This patch adds code to retry if there are any read errors.   This code has been copied almost verbatim from the LM93 driver (Thanks, Mark!).  

Just as in the LM93, it's not clear what the right thing would be to do if the retries all fail, so I return 0, just as the LM93 does.

David

--- lm_sensors/kernel/chips/lm87.c.orig	2004-09-27 13:00:26.000000000 -0400
+++ lm_sensors/kernel/chips/lm87.c	2004-09-27 13:19:23.000000000 -0400
@@ -27,6 +27,7 @@
 #include <linux/i2c.h>
 #include <linux/i2c-proc.h>
 #include <linux/init.h>
+#include <linux/delay.h>
 #include "version.h"
 #include "sensors_vid.h"
 
@@ -487,7 +488,7 @@
 
 	if ((err = i2c_detach_client(client))) {
 		printk
-		    ("lm87.o: Client deregistration failed, client not detached.\n");
+		    (KERN_ERR "lm87.o: Client deregistration failed, client not detached.\n");
 		return err;
 	}
 
@@ -496,9 +497,26 @@
 	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;
+		} else {
+			printk(KERN_WARNING "lm87.o: read byte data failed, "
+				"address 0x%02x.\n", reg);
+			mdelay(i);
+		}
+
+	}
+
+	/* <TODO> what to return in case of error? */
+	return 0;
 }
 
 static int lm87_write_value(struct i2c_client *client, u8 reg, u8 value)
@@ -964,7 +982,7 @@
 
 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);
 }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-05-19  6:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-19  6:25 [PATCH ] LM87: Add code to retry reads on error David Knierim
2005-05-19  6:25 ` David Knierim
2005-05-19  6:25 ` Jean Delvare
2005-05-19  6:25 ` Jean Delvare
2005-05-19  6:25 ` David Knierim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.