Commit e35ce2e4 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] tvp5150: Use i2c_smbus_(read|write)_byte_data

X-Patchwork-Delegate: mchehab@redhat.com
Replace the custom I2C read/write implementation with SMBUS functions to
simplify the driver.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 385dded8
...@@ -56,38 +56,29 @@ static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) ...@@ -56,38 +56,29 @@ static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr) static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
{ {
struct i2c_client *c = v4l2_get_subdevdata(sd); struct i2c_client *c = v4l2_get_subdevdata(sd);
unsigned char buffer[1];
int rc; int rc;
struct i2c_msg msg[] = {
{ .addr = c->addr, .flags = 0, rc = i2c_smbus_read_byte_data(c, addr);
.buf = &addr, .len = 1 }, if (rc < 0) {
{ .addr = c->addr, .flags = I2C_M_RD, v4l2_err(sd, "i2c i/o error: rc == %d\n", rc);
.buf = buffer, .len = 1 } return rc;
};
rc = i2c_transfer(c->adapter, msg, 2);
if (rc < 0 || rc != 2) {
v4l2_err(sd, "i2c i/o error: rc == %d (should be 2)\n", rc);
return rc < 0 ? rc : -EIO;
} }
v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]); v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, rc);
return (buffer[0]); return rc;
} }
static inline void tvp5150_write(struct v4l2_subdev *sd, unsigned char addr, static inline void tvp5150_write(struct v4l2_subdev *sd, unsigned char addr,
unsigned char value) unsigned char value)
{ {
struct i2c_client *c = v4l2_get_subdevdata(sd); struct i2c_client *c = v4l2_get_subdevdata(sd);
unsigned char buffer[2];
int rc; int rc;
buffer[0] = addr; v4l2_dbg(2, debug, sd, "tvp5150: writing 0x%02x 0x%02x\n", addr, value);
buffer[1] = value; rc = i2c_smbus_write_byte_data(c, addr, value);
v4l2_dbg(2, debug, sd, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]); if (rc < 0)
if (2 != (rc = i2c_master_send(c, buffer, 2))) v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d\n", rc);
v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 2)\n", rc);
} }
static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init, static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init,
......
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