Commit e7a7f510 authored by Erik Andrén's avatar Erik Andrén Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (10015): gspca - m5602: Add initial read sensor implementation

parent fce65f65
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -136,4 +136,7 @@ int m5602_write_bridge(
int m5602_write_sensor(struct sd *sd, const u8 address,
		       u8 *i2c_data, const u8 len);

int m5602_read_sensor(struct sd *sd, const u8 address,
		      u8 *i2c_data, const u8 len);

#endif
+36 −0
Original line number Diff line number Diff line
@@ -80,6 +80,42 @@ int m5602_write_bridge(struct sd *sd, u8 address, u8 i2c_data)
	return (err < 0) ? err : 0;
}

int m5602_read_sensor(struct sd *sd, const u8 address,
		       u8 *i2c_data, const u8 len)
{
	int err, i;

	do {
		err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
	} while ((*i2c_data & I2C_BUSY) && !err);

	err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
				 sd->sensor->i2c_slave_id);
	if (err < 0)
		goto out;

	err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
	if (err < 0)
		goto out;

	err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x10 + len);
	if (err < 0)
		goto out;

	err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08);
	if (err < 0)
		goto out;

	for (i = 0; (i < len) && !err; i++) {
		err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));

		PDEBUG(D_CONF, "Reading sensor register "
			       "0x%x containing 0x%x ", address, *i2c_data);
	}
out:
	return err;
}

int m5602_write_sensor(struct sd *sd, const u8 address,
			u8 *i2c_data, const u8 len)
{