1 From d67eece3a8ba9e8961e6050129f6f76d31924d62 Mon Sep 17 00:00:00 2001
2 From: Daniel Scally <djrscally@gmail.com>
3 Date: Tue, 15 Feb 2022 23:07:34 +0000
4 Subject: [PATCH] media: i2c: Add ov7251_detect_chip()
6 .probe() is quite busy for this driver; make it cleaner by moving the
7 chip verification to a dedicated function.
9 Signed-off-by: Daniel Scally <djrscally@gmail.com>
11 drivers/media/i2c/ov7251.c | 62 +++++++++++++++++++++-----------------
12 1 file changed, 35 insertions(+), 27 deletions(-)
14 --- a/drivers/media/i2c/ov7251.c
15 +++ b/drivers/media/i2c/ov7251.c
16 @@ -1442,12 +1442,44 @@ out_free_bus_cfg:
20 +static int ov7251_detect_chip(struct ov7251 *ov7251)
22 + u8 chip_id_high, chip_id_low, chip_rev;
25 + ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_HIGH, &chip_id_high);
26 + if (ret < 0 || chip_id_high != OV7251_CHIP_ID_HIGH_BYTE)
27 + return dev_err_probe(ov7251->dev, -ENODEV,
28 + "could not read ID high\n");
30 + ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_LOW, &chip_id_low);
31 + if (ret < 0 || chip_id_low != OV7251_CHIP_ID_LOW_BYTE)
32 + return dev_err_probe(ov7251->dev, -ENODEV,
33 + "could not read ID low\n");
35 + ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev);
37 + return dev_err_probe(ov7251->dev, -ENODEV,
38 + "could not read revision\n");
41 + dev_info(ov7251->dev,
42 + "OV7251 revision %x (%s) detected at address 0x%02x\n",
44 + chip_rev == 0x4 ? "1A / 1B" :
45 + chip_rev == 0x5 ? "1C / 1D" :
46 + chip_rev == 0x6 ? "1E" :
47 + chip_rev == 0x7 ? "1F" : "unknown",
48 + ov7251->i2c_client->addr);
53 static int ov7251_probe(struct i2c_client *client)
55 struct v4l2_fwnode_device_properties props;
56 struct device *dev = &client->dev;
57 struct ov7251 *ov7251;
58 - u8 chip_id_high, chip_id_low, chip_rev;
59 unsigned int rate = 0;
62 @@ -1589,34 +1621,10 @@ static int ov7251_probe(struct i2c_clien
66 - ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_HIGH, &chip_id_high);
67 - if (ret < 0 || chip_id_high != OV7251_CHIP_ID_HIGH_BYTE) {
68 - dev_err(dev, "could not read ID high\n");
72 - ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_LOW, &chip_id_low);
73 - if (ret < 0 || chip_id_low != OV7251_CHIP_ID_LOW_BYTE) {
74 - dev_err(dev, "could not read ID low\n");
79 - ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev);
81 - dev_err(dev, "could not read revision\n");
83 + ret = ov7251_detect_chip(ov7251);
89 - dev_info(dev, "OV7251 revision %x (%s) detected at address 0x%02x\n",
91 - chip_rev == 0x4 ? "1A / 1B" :
92 - chip_rev == 0x5 ? "1C / 1D" :
93 - chip_rev == 0x6 ? "1E" :
94 - chip_rev == 0x7 ? "1F" : "unknown",
97 ret = ov7251_read_reg(ov7251, OV7251_PRE_ISP_00,