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: Daniel Scally <djrscally@gmail.com>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
This commit is contained in:
Daniel Scally 2022-05-06 01:03:55 +02:00 committed by Mauro Carvalho Chehab
parent ed9566ce19
commit e92932c3e5

View File

@ -1439,11 +1439,43 @@ out_free_bus_cfg:
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;
ret = ov7251_detect_chip(ov7251);
if (ret)
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;
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);