change i2c_transfer func
author柯飞雄 <kfx@rock-chips.com>
Mon, 17 May 2010 08:44:06 +0000 (08:44 +0000)
committer黄涛 <huangtao@rock-chips.com>
Mon, 21 Jun 2010 05:34:55 +0000 (13:34 +0800)
drivers/rtc/rtc-HYM8563.c

index 1356e748927b2a7b5e6385f8fe4fa834a18df349..a9434d98e395fa4fe3232309fbec4845036fc2b8 100644 (file)
 static int hym8563_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], unsigned len)
 {
        int ret;
+       struct i2c_adapter *adap = client->adapter;
+       struct i2c_msg msgs[2];
+       msgs[0].addr = client->addr;
+       msgs[0].buf = &reg;
+       msgs[0].flags = client->flags;
+       msgs[0].len = 1;
+       msgs[0].scl_rate = 400 * 1000; /* set 400kHz, but real is about 300kHz */
+
+       msgs[1].buf = buf;
+       msgs[1].addr = client->addr;
+       msgs[1].flags = client->flags | I2C_M_RD;
+       msgs[1].len = len;
+       msgs[1].scl_rate = 4000 * 1000; 
+
+       ret = i2c_transfer(adap, msgs, 2);
+       /*
        struct i2c_msg msgs[1] = {
                { client->addr, 1, len, buf },
        };
@@ -40,13 +56,29 @@ static int hym8563_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], un
        ret = i2c_transfer(client->adapter, msgs, 1);
        if (ret > 0)
                ret = 0;
-       
+       */
        return ret;
 }
 
 static int hym8563_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[], __u16 len)
 {
        int ret;
+       struct i2c_adapter *adap = client->adapter;
+       struct i2c_msg msg;
+       char tx_buf[len + 1];
+
+       tx_buf[0] = reg;
+       memcpy(tx_buf + 1, buf, len);
+
+       msg.addr = client->addr;
+       msg.buf = tx_buf;
+       msg.len = len + 1;
+       msg.flags = client->flags;
+       msg.scl_rate = 400 * 1000;
+
+       ret = i2c_transfer(adap, &msg, 1);
+
+       /*
        u8 i2c_buf[HYM8563_REG_LEN + 1];
        struct i2c_msg msgs[1] = {
                { client->addr, 0, len + 1, i2c_buf }
@@ -62,7 +94,7 @@ static int hym8563_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[
        ret = i2c_transfer(client->adapter, msgs, 1);
        if (ret > 0)
                ret = 0;
-       
+       */
        return ret;
 }