Commit e92932c3 authored by Daniel Scally's avatar Daniel Scally Committed by Mauro Carvalho Chehab
Browse files

media: i2c: Add ov7251_detect_chip()



.probe() is quite busy for this driver; make it cleaner by moving the
chip verification to a dedicated function.

Signed-off-by: default avatarDaniel Scally <djrscally@gmail.com>
Acked-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent ed9566ce
Loading
Loading
Loading
Loading
+35 −27
Original line number Diff line number Diff line
@@ -1439,11 +1439,43 @@ static int ov7251_check_hwcfg(struct ov7251 *ov7251)
	return ret;
}

static int ov7251_detect_chip(struct ov7251 *ov7251)
{
	u8 chip_id_high, chip_id_low, chip_rev;
	int ret;

	ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_HIGH, &chip_id_high);
	if (ret < 0 || chip_id_high != OV7251_CHIP_ID_HIGH_BYTE)
		return dev_err_probe(ov7251->dev, -ENODEV,
				     "could not read ID high\n");

	ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_LOW, &chip_id_low);
	if (ret < 0 || chip_id_low != OV7251_CHIP_ID_LOW_BYTE)
		return dev_err_probe(ov7251->dev, -ENODEV,
				     "could not read ID low\n");

	ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev);
	if (ret < 0)
		return dev_err_probe(ov7251->dev, -ENODEV,
				     "could not read revision\n");
	chip_rev >>= 4;

	dev_info(ov7251->dev,
		 "OV7251 revision %x (%s) detected at address 0x%02x\n",
		 chip_rev,
		 chip_rev == 0x4 ? "1A / 1B" :
		 chip_rev == 0x5 ? "1C / 1D" :
		 chip_rev == 0x6 ? "1E" :
		 chip_rev == 0x7 ? "1F" : "unknown",
		 ov7251->i2c_client->addr);

	return 0;
}

static int ov7251_probe(struct i2c_client *client)
{
	struct device *dev = &client->dev;
	struct ov7251 *ov7251;
	u8 chip_id_high, chip_id_low, chip_rev;
	unsigned int rate = 0, clk_rate = 0;
	s64 pixel_rate;
	int ret;
@@ -1586,34 +1618,10 @@ static int ov7251_probe(struct i2c_client *client)
		goto free_entity;
	}

	ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_HIGH, &chip_id_high);
	if (ret < 0 || chip_id_high != OV7251_CHIP_ID_HIGH_BYTE) {
		dev_err(dev, "could not read ID high\n");
		ret = -ENODEV;
		goto power_down;
	}
	ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_LOW, &chip_id_low);
	if (ret < 0 || chip_id_low != OV7251_CHIP_ID_LOW_BYTE) {
		dev_err(dev, "could not read ID low\n");
		ret = -ENODEV;
		goto power_down;
	}

	ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev);
	if (ret < 0) {
		dev_err(dev, "could not read revision\n");
		ret = -ENODEV;
	ret = ov7251_detect_chip(ov7251);
	if (ret)
		goto power_down;
	}
	chip_rev >>= 4;

	dev_info(dev, "OV7251 revision %x (%s) detected at address 0x%02x\n",
		 chip_rev,
		 chip_rev == 0x4 ? "1A / 1B" :
		 chip_rev == 0x5 ? "1C / 1D" :
		 chip_rev == 0x6 ? "1E" :
		 chip_rev == 0x7 ? "1F" : "unknown",
		 client->addr);

	ret = ov7251_read_reg(ov7251, OV7251_PRE_ISP_00,
			      &ov7251->pre_isp_00);