]> git.baikalelectronics.ru Git - kernel.git/commitdiff
media: i2c: Add ov7251_detect_chip()
authorDaniel Scally <djrscally@gmail.com>
Thu, 5 May 2022 23:03:55 +0000 (01:03 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Tue, 17 May 2022 07:50:56 +0000 (09:50 +0200)
.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>
drivers/media/i2c/ov7251.c

index 98848b3f62a933f557479e8447af4dd088f05de3..88875275b7b43c617e26ccd92c8cafca5c74eb9d 100644 (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;
-               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);