This commit was generated by cvs2svn to compensate for changes in r1129,
[linux-2.6.git] / drivers / i2c / chips / rtc8564.c
index acfd3f8..ceaa6b0 100644 (file)
  */
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/bcd.h>
 #include <linux/i2c.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/rtc.h>         /* get the user-level API */
 #include <linux/init.h>
-#include <linux/init.h>
 
 #include "rtc8564.h"
 
@@ -53,9 +53,6 @@ static inline u8 _rtc8564_ctrl2(struct i2c_client *client)
 #define CTRL1(c) _rtc8564_ctrl1(c)
 #define CTRL2(c) _rtc8564_ctrl2(c)
 
-#define BCD_TO_BIN(val) (((val)&15) + ((val)>>4)*10)
-#define BIN_TO_BCD(val) ((((val)/10)<<4) + (val)%10)
-
 static int debug;;
 module_param(debug, int, S_IRUGO | S_IWUSR);
 
@@ -66,12 +63,8 @@ static unsigned short normal_addr[] = { 0x51, I2C_CLIENT_END };
 
 static struct i2c_client_address_data addr_data = {
        .normal_i2c             = normal_addr,
-       .normal_i2c_range       = ignore,
        .probe                  = ignore,
-       .probe_range            = ignore,
        .ignore                 = ignore,
-       .ignore_range           = ignore,
-       .force                  = ignore,
 };
 
 static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem);
@@ -89,7 +82,7 @@ static int rtc8564_read(struct i2c_client *client, unsigned char adr,
 
        _DBG(1, "client=%p, adr=%d, buf=%p, len=%d", client, adr, buf, len);
 
-       if (!buf || !client) {
+       if (!buf) {
                ret = -EINVAL;
                goto done;
        }
@@ -111,7 +104,7 @@ static int rtc8564_write(struct i2c_client *client, unsigned char adr,
        struct i2c_msg wr;
        int i;
 
-       if (!client || !data || len > 15) {
+       if (!data || len > 15) {
                ret = -EINVAL;
                goto done;
        }
@@ -153,24 +146,20 @@ static int rtc8564_attach(struct i2c_adapter *adap, int addr, int kind)
                {addr, I2C_M_RD, 2, data}
        };
 
-       d = kmalloc(sizeof(struct rtc8564_data), GFP_KERNEL);
+       d = kzalloc(sizeof(struct rtc8564_data), GFP_KERNEL);
        if (!d) {
                ret = -ENOMEM;
                goto done;
        }
-       memset(d, 0, sizeof(struct rtc8564_data));
        new_client = &d->client;
 
        strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE);
        i2c_set_clientdata(new_client, d);
-       new_client->id = rtc8564_driver.id;
-       new_client->flags = I2C_CLIENT_ALLOW_USE | I2C_DF_NOTIFY;
        new_client->addr = addr;
        new_client->adapter = adap;
        new_client->driver = &rtc8564_driver;
 
        _DBG(1, "client=%p", new_client);
-       _DBG(1, "client.id=%d", new_client->id);
 
        /* init ctrl1 reg */
        data[0] = 0;
@@ -222,7 +211,7 @@ static int rtc8564_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
 
        _DBG(1, "client=%p, dt=%p", client, dt);
 
-       if (!dt || !client)
+       if (!dt)
                return -EINVAL;
 
        memset(buf, 0, sizeof(buf));
@@ -232,16 +221,16 @@ static int rtc8564_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
                return ret;
 
        /* century stored in minute alarm reg */
-       dt->year = BCD_TO_BIN(buf[RTC8564_REG_YEAR]);
-       dt->year += 100 * BCD_TO_BIN(buf[RTC8564_REG_AL_MIN] & 0x3f);
-       dt->mday = BCD_TO_BIN(buf[RTC8564_REG_DAY] & 0x3f);
-       dt->wday = BCD_TO_BIN(buf[RTC8564_REG_WDAY] & 7);
-       dt->mon = BCD_TO_BIN(buf[RTC8564_REG_MON_CENT] & 0x1f);
+       dt->year = BCD2BIN(buf[RTC8564_REG_YEAR]);
+       dt->year += 100 * BCD2BIN(buf[RTC8564_REG_AL_MIN] & 0x3f);
+       dt->mday = BCD2BIN(buf[RTC8564_REG_DAY] & 0x3f);
+       dt->wday = BCD2BIN(buf[RTC8564_REG_WDAY] & 7);
+       dt->mon = BCD2BIN(buf[RTC8564_REG_MON_CENT] & 0x1f);
 
-       dt->secs = BCD_TO_BIN(buf[RTC8564_REG_SEC] & 0x7f);
+       dt->secs = BCD2BIN(buf[RTC8564_REG_SEC] & 0x7f);
        dt->vl = (buf[RTC8564_REG_SEC] & 0x80) == 0x80;
-       dt->mins = BCD_TO_BIN(buf[RTC8564_REG_MIN] & 0x7f);
-       dt->hours = BCD_TO_BIN(buf[RTC8564_REG_HR] & 0x3f);
+       dt->mins = BCD2BIN(buf[RTC8564_REG_MIN] & 0x7f);
+       dt->hours = BCD2BIN(buf[RTC8564_REG_HR] & 0x3f);
 
        _DBGRTCTM(2, *dt);
 
@@ -256,25 +245,25 @@ rtc8564_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo)
 
        _DBG(1, "client=%p, dt=%p", client, dt);
 
-       if (!dt || !client)
+       if (!dt)
                return -EINVAL;
 
        _DBGRTCTM(2, *dt);
 
        buf[RTC8564_REG_CTRL1] = CTRL1(client) | RTC8564_CTRL1_STOP;
        buf[RTC8564_REG_CTRL2] = CTRL2(client);
-       buf[RTC8564_REG_SEC] = BIN_TO_BCD(dt->secs);
-       buf[RTC8564_REG_MIN] = BIN_TO_BCD(dt->mins);
-       buf[RTC8564_REG_HR] = BIN_TO_BCD(dt->hours);
+       buf[RTC8564_REG_SEC] = BIN2BCD(dt->secs);
+       buf[RTC8564_REG_MIN] = BIN2BCD(dt->mins);
+       buf[RTC8564_REG_HR] = BIN2BCD(dt->hours);
 
        if (datetoo) {
                len += 5;
-               buf[RTC8564_REG_DAY] = BIN_TO_BCD(dt->mday);
-               buf[RTC8564_REG_WDAY] = BIN_TO_BCD(dt->wday);
-               buf[RTC8564_REG_MON_CENT] = BIN_TO_BCD(dt->mon) & 0x1f;
+               buf[RTC8564_REG_DAY] = BIN2BCD(dt->mday);
+               buf[RTC8564_REG_WDAY] = BIN2BCD(dt->wday);
+               buf[RTC8564_REG_MON_CENT] = BIN2BCD(dt->mon) & 0x1f;
                /* century stored in minute alarm reg */
-               buf[RTC8564_REG_YEAR] = BIN_TO_BCD(dt->year % 100);
-               buf[RTC8564_REG_AL_MIN] = BIN_TO_BCD(dt->year / 100);
+               buf[RTC8564_REG_YEAR] = BIN2BCD(dt->year % 100);
+               buf[RTC8564_REG_AL_MIN] = BIN2BCD(dt->year / 100);
        }
 
        ret = rtc8564_write(client, 0, buf, len);
@@ -295,7 +284,7 @@ static int rtc8564_get_ctrl(struct i2c_client *client, unsigned int *ctrl)
 {
        struct rtc8564_data *data = i2c_get_clientdata(client);
 
-       if (!ctrl || !client)
+       if (!ctrl)
                return -1;
 
        *ctrl = data->ctrl;
@@ -307,7 +296,7 @@ static int rtc8564_set_ctrl(struct i2c_client *client, unsigned int *ctrl)
        struct rtc8564_data *data = i2c_get_clientdata(client);
        unsigned char buf[2];
 
-       if (!ctrl || !client)
+       if (!ctrl)
                return -1;
 
        buf[0] = *ctrl & 0xff;
@@ -320,7 +309,7 @@ static int rtc8564_set_ctrl(struct i2c_client *client, unsigned int *ctrl)
 static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem)
 {
 
-       if (!mem || !client)
+       if (!mem)
                return -EINVAL;
 
        return rtc8564_read(client, mem->loc, mem->data, mem->nr);
@@ -329,7 +318,7 @@ static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem)
 static int rtc8564_write_mem(struct i2c_client *client, struct mem *mem)
 {
 
-       if (!mem || !client)
+       if (!mem)
                return -EINVAL;
 
        return rtc8564_write(client, mem->loc, mem->data, mem->nr);
@@ -369,10 +358,10 @@ rtc8564_command(struct i2c_client *client, unsigned int cmd, void *arg)
 }
 
 static struct i2c_driver rtc8564_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "RTC8564",
+       .driver = {
+               .name   = "RTC8564",
+       },
        .id             = I2C_DRIVERID_RTC8564,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = rtc8564_probe,
        .detach_client  = rtc8564_detach,
        .command        = rtc8564_command