kernel: backport of_request_module()
[openwrt/staging/dedeckeh.git] / target / linux / bcm27xx / patches-5.15 / 950-0723-media-i2c-Add-ov7251_detect_chip.patch
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()
5
6 .probe() is quite busy for this driver; make it cleaner by moving the
7 chip verification to a dedicated function.
8
9 Signed-off-by: Daniel Scally <djrscally@gmail.com>
10 ---
11 drivers/media/i2c/ov7251.c | 62 +++++++++++++++++++++-----------------
12 1 file changed, 35 insertions(+), 27 deletions(-)
13
14 --- a/drivers/media/i2c/ov7251.c
15 +++ b/drivers/media/i2c/ov7251.c
16 @@ -1442,12 +1442,44 @@ out_free_bus_cfg:
17 return ret;
18 }
19
20 +static int ov7251_detect_chip(struct ov7251 *ov7251)
21 +{
22 + u8 chip_id_high, chip_id_low, chip_rev;
23 + int ret;
24 +
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");
29 +
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");
34 +
35 + ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev);
36 + if (ret < 0)
37 + return dev_err_probe(ov7251->dev, -ENODEV,
38 + "could not read revision\n");
39 + chip_rev >>= 4;
40 +
41 + dev_info(ov7251->dev,
42 + "OV7251 revision %x (%s) detected at address 0x%02x\n",
43 + chip_rev,
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);
49 +
50 + return 0;
51 +}
52 +
53 static int ov7251_probe(struct i2c_client *client)
54 {
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;
60 int ret;
61 int i;
62 @@ -1589,34 +1621,10 @@ static int ov7251_probe(struct i2c_clien
63 goto free_entity;
64 }
65
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");
69 - ret = -ENODEV;
70 - goto power_down;
71 - }
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");
75 - ret = -ENODEV;
76 - goto power_down;
77 - }
78 -
79 - ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev);
80 - if (ret < 0) {
81 - dev_err(dev, "could not read revision\n");
82 - ret = -ENODEV;
83 + ret = ov7251_detect_chip(ov7251);
84 + if (ret)
85 goto power_down;
86 - }
87 - chip_rev >>= 4;
88
89 - dev_info(dev, "OV7251 revision %x (%s) detected at address 0x%02x\n",
90 - chip_rev,
91 - chip_rev == 0x4 ? "1A / 1B" :
92 - chip_rev == 0x5 ? "1C / 1D" :
93 - chip_rev == 0x6 ? "1E" :
94 - chip_rev == 0x7 ? "1F" : "unknown",
95 - client->addr);
96
97 ret = ov7251_read_reg(ov7251, OV7251_PRE_ISP_00,
98 &ov7251->pre_isp_00);