5ce44ac638352755e17c4b653b93a278b78b7aea
[openwrt/staging/jow.git] /
1 From 53bfa82420b36fb13c8efac38b7a334ea5e71a3c Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Sun, 16 Oct 2022 09:15:17 +0300
4 Subject: [PATCH] media: i2c: imx290: Split control initialization to
5 separate function
6
7 Upstream commit 72c87b7ad560.
8
9 The imx290_probe() function is too large. Split control initialzation to
10 a dedicated function to increase code readability.
11
12 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
13 Acked-by: Alexander Stein <alexander.stein@ew.tq-group.com>
14 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
15 ---
16 drivers/media/i2c/imx290.c | 109 +++++++++++++++++++++----------------
17 1 file changed, 61 insertions(+), 48 deletions(-)
18
19 --- a/drivers/media/i2c/imx290.c
20 +++ b/drivers/media/i2c/imx290.c
21 @@ -878,6 +878,62 @@ static const struct media_entity_operati
22 .link_validate = v4l2_subdev_link_validate,
23 };
24
25 +static int imx290_ctrl_init(struct imx290 *imx290)
26 +{
27 + int ret;
28 +
29 + v4l2_ctrl_handler_init(&imx290->ctrls, 5);
30 + imx290->ctrls.lock = &imx290->lock;
31 +
32 + /*
33 + * The sensor has an analog gain and a digital gain, both controlled
34 + * through a single gain value, expressed in 0.3dB increments. Values
35 + * from 0.0dB (0) to 30.0dB (100) apply analog gain only, higher values
36 + * up to 72.0dB (240) add further digital gain. Limit the range to
37 + * analog gain only, support for digital gain can be added separately
38 + * if needed.
39 + *
40 + * The IMX327 and IMX462 are largely compatible with the IMX290, but
41 + * have an analog gain range of 0.0dB to 29.4dB and 42dB of digital
42 + * gain. When support for those sensors gets added to the driver, the
43 + * gain control should be adjusted accordingly.
44 + */
45 + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
46 + V4L2_CID_GAIN, 0, 100, 1, 0);
47 +
48 + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
49 + V4L2_CID_EXPOSURE, 1, IMX290_VMAX_DEFAULT - 2, 1,
50 + IMX290_VMAX_DEFAULT - 2);
51 +
52 + imx290->link_freq =
53 + v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,
54 + V4L2_CID_LINK_FREQ,
55 + imx290_link_freqs_num(imx290) - 1, 0,
56 + imx290_link_freqs_ptr(imx290));
57 + if (imx290->link_freq)
58 + imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
59 +
60 + imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
61 + V4L2_CID_PIXEL_RATE,
62 + 1, INT_MAX, 1,
63 + imx290_calc_pixel_rate(imx290));
64 +
65 + v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops,
66 + V4L2_CID_TEST_PATTERN,
67 + ARRAY_SIZE(imx290_test_pattern_menu) - 1,
68 + 0, 0, imx290_test_pattern_menu);
69 +
70 + imx290->sd.ctrl_handler = &imx290->ctrls;
71 +
72 + if (imx290->ctrls.error) {
73 + ret = imx290->ctrls.error;
74 + v4l2_ctrl_handler_free(&imx290->ctrls);
75 + return ret;
76 + }
77 +
78 + return 0;
79 +}
80 +
81 /*
82 * Returns 0 if all link frequencies used by the driver for the given number
83 * of MIPI data lanes are mentioned in the device tree, or the value of the
84 @@ -1016,54 +1072,10 @@ static int imx290_probe(struct i2c_clien
85 */
86 imx290_entity_init_cfg(&imx290->sd, NULL);
87
88 - v4l2_ctrl_handler_init(&imx290->ctrls, 5);
89 - imx290->ctrls.lock = &imx290->lock;
90 -
91 - /*
92 - * The sensor has an analog gain and a digital gain, both controlled
93 - * through a single gain value, expressed in 0.3dB increments. Values
94 - * from 0.0dB (0) to 30.0dB (100) apply analog gain only, higher values
95 - * up to 72.0dB (240) add further digital gain. Limit the range to
96 - * analog gain only, support for digital gain can be added separately
97 - * if needed.
98 - *
99 - * The IMX327 and IMX462 are largely compatible with the IMX290, but
100 - * have an analog gain range of 0.0dB to 29.4dB and 42dB of digital
101 - * gain. When support for those sensors gets added to the driver, the
102 - * gain control should be adjusted accordingly.
103 - */
104 - v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
105 - V4L2_CID_GAIN, 0, 100, 1, 0);
106 -
107 - v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
108 - V4L2_CID_EXPOSURE, 1, IMX290_VMAX_DEFAULT - 2, 1,
109 - IMX290_VMAX_DEFAULT - 2);
110 -
111 - imx290->link_freq =
112 - v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,
113 - V4L2_CID_LINK_FREQ,
114 - imx290_link_freqs_num(imx290) - 1, 0,
115 - imx290_link_freqs_ptr(imx290));
116 - if (imx290->link_freq)
117 - imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
118 -
119 - imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
120 - V4L2_CID_PIXEL_RATE,
121 - 1, INT_MAX, 1,
122 - imx290_calc_pixel_rate(imx290));
123 -
124 - v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops,
125 - V4L2_CID_TEST_PATTERN,
126 - ARRAY_SIZE(imx290_test_pattern_menu) - 1,
127 - 0, 0, imx290_test_pattern_menu);
128 -
129 - imx290->sd.ctrl_handler = &imx290->ctrls;
130 -
131 - if (imx290->ctrls.error) {
132 - dev_err(dev, "Control initialization error %d\n",
133 - imx290->ctrls.error);
134 - ret = imx290->ctrls.error;
135 - goto free_ctrl;
136 + ret = imx290_ctrl_init(imx290);
137 + if (ret < 0) {
138 + dev_err(dev, "Control initialization error %d\n", ret);
139 + goto free_mutex;
140 }
141
142 v4l2_i2c_subdev_init(&imx290->sd, client, &imx290_subdev_ops);
143 @@ -1104,6 +1116,7 @@ free_entity:
144 media_entity_cleanup(&imx290->sd.entity);
145 free_ctrl:
146 v4l2_ctrl_handler_free(&imx290->ctrls);
147 +free_mutex:
148 mutex_destroy(&imx290->lock);
149 free_err:
150 v4l2_fwnode_endpoint_free(&ep);