]> err.no Git - linux-2.6/blobdiff - drivers/i2c/chips/ds1337.c
[PATCH] I2C: Fix bugs in the new w83627ehf driver
[linux-2.6] / drivers / i2c / chips / ds1337.c
index 0967ec6d7947b803b346d4498e3b1a70eff63801..74ece8ac1c2355b214af3e4481eddf3c747a5fd6 100644 (file)
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  *
- * Driver for Dallas Semiconductor DS1337 real time clock chip
+ * Driver for Dallas Semiconductor DS1337 and DS1339 real time clock chip
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -69,13 +68,11 @@ static struct i2c_driver ds1337_driver = {
 struct ds1337_data {
        struct i2c_client client;
        struct list_head list;
-       int id;
 };
 
 /*
  * Internal variables
  */
-static int ds1337_id;
 static LIST_HEAD(ds1337_clients);
 
 static inline int ds1337_read(struct i2c_client *client, u8 reg, u8 *value)
@@ -122,7 +119,7 @@ static int ds1337_get_datetime(struct i2c_client *client, struct rtc_time *dt)
                __FUNCTION__, result, buf[0], buf[1], buf[2], buf[3],
                buf[4], buf[5], buf[6]);
 
-       if (result >= 0) {
+       if (result == 2) {
                dt->tm_sec = BCD2BIN(buf[0]);
                dt->tm_min = BCD2BIN(buf[1]);
                val = buf[2] & 0x3f;
@@ -140,12 +137,12 @@ static int ds1337_get_datetime(struct i2c_client *client, struct rtc_time *dt)
                        __FUNCTION__, dt->tm_sec, dt->tm_min,
                        dt->tm_hour, dt->tm_mday,
                        dt->tm_mon, dt->tm_year, dt->tm_wday);
-       } else {
-               dev_err(&client->dev, "error reading data! %d\n", result);
-               result = -EIO;
+
+               return 0;
        }
 
-       return result;
+       dev_err(&client->dev, "error reading data! %d\n", result);
+       return -EIO;
 }
 
 static int ds1337_set_datetime(struct i2c_client *client, struct rtc_time *dt)
@@ -185,14 +182,11 @@ static int ds1337_set_datetime(struct i2c_client *client, struct rtc_time *dt)
        msg[0].buf = &buf[0];
 
        result = i2c_transfer(client->adapter, msg, 1);
-       if (result < 0) {
-               dev_err(&client->dev, "error writing data! %d\n", result);
-               result = -EIO;
-       } else {
-               result = 0;
-       }
+       if (result == 1)
+               return 0;
 
-       return result;
+       dev_err(&client->dev, "error writing data! %d\n", result);
+       return -EIO;
 }
 
 static int ds1337_command(struct i2c_client *client, unsigned int cmd,
@@ -216,7 +210,7 @@ static int ds1337_command(struct i2c_client *client, unsigned int cmd,
  * Public API for access to specific device. Useful for low-level
  * RTC access from kernel code.
  */
-int ds1337_do_command(int id, int cmd, void *arg)
+int ds1337_do_command(int bus, int cmd, void *arg)
 {
        struct list_head *walk;
        struct list_head *tmp;
@@ -224,7 +218,7 @@ int ds1337_do_command(int id, int cmd, void *arg)
 
        list_for_each_safe(walk, tmp, &ds1337_clients) {
                data = list_entry(walk, struct ds1337_data, list);
-               if (data->id == id)
+               if (data->client.adapter->nr == bus)
                        return ds1337_command(&data->client, cmd, arg);
        }
 
@@ -334,7 +328,6 @@ static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind)
        ds1337_init_client(new_client);
 
        /* Add client to local list */
-       data->id = ds1337_id++;
        list_add(&data->list, &ds1337_clients);
 
        return 0;
@@ -386,5 +379,7 @@ MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
 MODULE_DESCRIPTION("DS1337 RTC driver");
 MODULE_LICENSE("GPL");
 
+EXPORT_SYMBOL_GPL(ds1337_do_command);
+
 module_init(ds1337_init);
 module_exit(ds1337_exit);