Commit facc23b8 authored by Trent Piepho's avatar Trent Piepho Committed by Alexandre Belloni

rtc: isl1208: Use i2c block read/write routines

The Linux i2c layer has functions to execute common SMBUS/I2C
transactions.  The register access code here is identical to the I2C
read/write block data routines.

Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: default avatarTrent Piepho <tpiepho@impinj.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 41ef3878
...@@ -84,29 +84,13 @@ static int ...@@ -84,29 +84,13 @@ static int
isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
unsigned len) unsigned len)
{ {
u8 reg_addr[1] = { reg };
struct i2c_msg msgs[2] = {
{
.addr = client->addr,
.len = sizeof(reg_addr),
.buf = reg_addr
},
{
.addr = client->addr,
.flags = I2C_M_RD,
.len = len,
.buf = buf
}
};
int ret; int ret;
WARN_ON(reg > ISL1219_REG_YRT); WARN_ON(reg > ISL1219_REG_YRT);
WARN_ON(reg + len > ISL1219_REG_YRT + 1); WARN_ON(reg + len > ISL1219_REG_YRT + 1);
ret = i2c_transfer(client->adapter, msgs, 2); ret = i2c_smbus_read_i2c_block_data(client, reg, len, buf);
if (ret > 0) return (ret < 0) ? ret : 0;
ret = 0;
return ret;
} }
/* block write */ /* block write */
...@@ -114,26 +98,13 @@ static int ...@@ -114,26 +98,13 @@ static int
isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[], isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
unsigned len) unsigned len)
{ {
u8 i2c_buf[ISL1208_REG_USR2 + 2];
struct i2c_msg msgs[1] = {
{
.addr = client->addr,
.len = len + 1,
.buf = i2c_buf
}
};
int ret; int ret;
WARN_ON(reg > ISL1219_REG_YRT); WARN_ON(reg > ISL1219_REG_YRT);
WARN_ON(reg + len > ISL1219_REG_YRT + 1); WARN_ON(reg + len > ISL1219_REG_YRT + 1);
i2c_buf[0] = reg; ret = i2c_smbus_write_i2c_block_data(client, reg, len, buf);
memcpy(&i2c_buf[1], &buf[0], len); return (ret < 0) ? ret : 0;
ret = i2c_transfer(client->adapter, msgs, 1);
if (ret > 0)
ret = 0;
return ret;
} }
/* simple check to see whether we have a isl1208 */ /* simple check to see whether we have a isl1208 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment