change i2c_transfer func

This commit is contained in:
柯飞雄
2010-05-17 08:44:06 +00:00
committed by 黄涛
parent 7109c35641
commit 388f3e70ae

View File

@@ -29,6 +29,22 @@
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 = ®
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;
}