Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7871597a authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab
Browse files

[media] tvp5150: Restructure version detection



Move the version detection code to a separate function and restructure
it to prepare for TVP5151 support.

Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarJavier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 7d3ccfe6
Loading
Loading
Loading
Loading
+45 −34
Original line number Diff line number Diff line
@@ -1105,24 +1105,15 @@ static const struct v4l2_subdev_ops tvp5150_ops = {
			I2C Client & Driver
 ****************************************************************************/

static int tvp5150_probe(struct i2c_client *c,
			 const struct i2c_device_id *id)
static int tvp5150_detect_version(struct tvp5150 *core)
{
	struct tvp5150 *core;
	struct v4l2_subdev *sd;
	int tvp5150_id[4];
	int i, res;

	/* Check if the adapter supports the needed features */
	if (!i2c_check_functionality(c->adapter,
	     I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
		return -EIO;

	core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
	if (!core)
		return -ENOMEM;
	sd = &core->sd;
	v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
	struct v4l2_subdev *sd = &core->sd;
	struct i2c_client *c = v4l2_get_subdevdata(sd);
	unsigned int i;
	u16 dev_id;
	u16 rom_ver;
	u8 regs[4];
	int res;

	/*
	 * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID,
@@ -1132,31 +1123,51 @@ static int tvp5150_probe(struct i2c_client *c,
		res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i);
		if (res < 0)
			return res;
		tvp5150_id[i] = res;
		regs[i] = res;
	}

	v4l_info(c, "chip found @ 0x%02x (%s)\n",
		 c->addr << 1, c->adapter->name);
	dev_id = (regs[0] << 8) | regs[1];
	rom_ver = (regs[2] << 8) | regs[3];

	v4l2_info(sd, "tvp%04x (%u.%u) chip found @ 0x%02x (%s)\n",
		  dev_id, regs[2], regs[3], c->addr << 1, c->adapter->name);

	if (tvp5150_id[2] == 4 && tvp5150_id[3] == 0) { /* Is TVP5150AM1 */
		v4l2_info(sd, "tvp%02x%02xam1 detected.\n",
			  tvp5150_id[0], tvp5150_id[1]);
	if (dev_id == 0x5150 && rom_ver == 0x0321) { /* TVP51510A */
		v4l2_info(sd, "tvp5150a detected.\n");
	} else if (dev_id == 0x5150 && rom_ver == 0x0400) { /* TVP5150AM1 */
		v4l2_info(sd, "tvp5150am1 detected.\n");

		/* ITU-T BT.656.4 timing */
		tvp5150_write(sd, TVP5150_REV_SELECT, 0);
	} else {
		/* Is TVP5150A */
		if (tvp5150_id[2] == 3 || tvp5150_id[3] == 0x21) {
			v4l2_info(sd, "tvp%02x%02xa detected.\n",
				  tvp5150_id[0], tvp5150_id[1]);
		} else {
			v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
				  tvp5150_id[0], tvp5150_id[1]);
			v4l2_info(sd, "*** Rom ver is %d.%d\n",
				  tvp5150_id[2], tvp5150_id[3]);
		v4l2_info(sd, "*** unknown tvp%04x chip detected.\n", dev_id);
	}

	return 0;
}

static int tvp5150_probe(struct i2c_client *c,
			 const struct i2c_device_id *id)
{
	struct tvp5150 *core;
	struct v4l2_subdev *sd;
	int res;

	/* Check if the adapter supports the needed features */
	if (!i2c_check_functionality(c->adapter,
	     I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
		return -EIO;

	core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
	if (!core)
		return -ENOMEM;
	sd = &core->sd;
	v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);

	res = tvp5150_detect_version(core);
	if (res < 0)
		return res;

	core->norm = V4L2_STD_ALL;	/* Default is autodetect */
	core->input = TVP5150_COMPOSITE1;
	core->enable = 1;