[PATCH: 2.6.14] i2c chips: ds1337 1/2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patch for ds1337 i2c driver:

Add code to handle case where board firmware does not start the
RTC.

This patch was contributed by Michael Burian.

Signed-off-by: Michael Burian <[email protected]>
Signed-off-by: James Chapman <[email protected]>

--
James Chapman
Katalix Systems Ltd
http://www.katalix.com
Catalysts for your Embedded Linux software development



Add code to handle case where board firmware does not start the
RTC.

This patch was contributed by Michael Burian.

Signed-off-by: Michael Burian <[email protected]>
Signed-off-by: James Chapman <[email protected]>

Index: linux-2.6.14/drivers/i2c/chips/ds1337.c
===================================================================
--- linux-2.6.14.orig/drivers/i2c/chips/ds1337.c	2005-11-02 19:30:17.000000000 +0000
+++ linux-2.6.14/drivers/i2c/chips/ds1337.c	2005-11-03 20:14:58.981735046 +0000
@@ -149,12 +149,25 @@
 	u8 buf[8];
 	u8 val;
 	struct i2c_msg msg[1];
+	u8 status, control;
+	int i;
 
 	if (!dt) {
 		dev_dbg(&client->dev, "%s: EINVAL: dt=NULL\n", __FUNCTION__);
 		return -EINVAL;
 	}
 
+	status  = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS);
+	control = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
+	
+	/* On some boards, the RTC isn't configured by boot firmware. 
+	 * Handle that case by starting/configuring the RTC now.
+	 */
+	if ((status & 0x80) || (control & 0x80))
+		/* Initialize all, including STATUS and CONTROL to zero */
+		for (i = 0; i < 16; i++)
+			i2c_smbus_write_byte_data(client, i, 0);
+
 	dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
 		"mday=%d, mon=%d, year=%d, wday=%d\n", __FUNCTION__,
 		dt->tm_sec, dt->tm_min, dt->tm_hour,

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux