Merge branch 'master'
[powerpc.git] / drivers / i2c / chips / ds1337.c
index c4762ac..01b0370 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>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
 #include <linux/string.h>
 #include <linux/rtc.h>         /* get the user-level API */
 #include <linux/bcd.h>
@@ -40,9 +38,8 @@
  * Functions declaration
  */
 static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END };
-static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
 
-SENSORS_INSMOD_1(ds1337);
+I2C_CLIENT_INSMOD_1(ds1337);
 
 static int ds1337_attach_adapter(struct i2c_adapter *adapter);
 static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind);
@@ -69,13 +66,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)
@@ -168,7 +163,7 @@ static int ds1337_set_datetime(struct i2c_client *client, struct rtc_time *dt)
        buf[0] = 0;             /* reg offset */
        buf[1] = BIN2BCD(dt->tm_sec);
        buf[2] = BIN2BCD(dt->tm_min);
-       buf[3] = BIN2BCD(dt->tm_hour) | (1 << 6);
+       buf[3] = BIN2BCD(dt->tm_hour);
        buf[4] = BIN2BCD(dt->tm_wday) + 1;
        buf[5] = BIN2BCD(dt->tm_mday);
        buf[6] = BIN2BCD(dt->tm_mon) + 1;
@@ -213,7 +208,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;
@@ -221,7 +216,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);
        }
 
@@ -230,7 +225,7 @@ int ds1337_do_command(int id, int cmd, void *arg)
 
 static int ds1337_attach_adapter(struct i2c_adapter *adapter)
 {
-       return i2c_detect(adapter, &addr_data, ds1337_detect);
+       return i2c_probe(adapter, &addr_data, ds1337_detect);
 }
 
 /*
@@ -248,11 +243,10 @@ static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind)
                                     I2C_FUNC_I2C))
                goto exit;
 
-       if (!(data = kmalloc(sizeof(struct ds1337_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct ds1337_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct ds1337_data));
        INIT_LIST_HEAD(&data->list);
 
        /* The common I2C client data is placed right before the
@@ -331,7 +325,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;
@@ -348,9 +341,9 @@ static void ds1337_init_client(struct i2c_client *client)
 
        /* Ensure that device is set in 24-hour mode */
        val = i2c_smbus_read_byte_data(client, DS1337_REG_HOUR);
-       if ((val >= 0) && (val & (1 << 6)) == 0)
+       if ((val >= 0) && (val & (1 << 6)))
                i2c_smbus_write_byte_data(client, DS1337_REG_HOUR,
-                                         val | (1 << 6));
+                                         val & 0x3f);
 }
 
 static int ds1337_detach_client(struct i2c_client *client)
@@ -358,11 +351,8 @@ static int ds1337_detach_client(struct i2c_client *client)
        int err;
        struct ds1337_data *data = i2c_get_clientdata(client);
 
-       if ((err = i2c_detach_client(client))) {
-               dev_err(&client->dev, "Client deregistration failed, "
-                       "client not detached.\n");
+       if ((err = i2c_detach_client(client)))
                return err;
-       }
 
        list_del(&data->list);
        kfree(data);
@@ -383,5 +373,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);