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
7 Upstream commit 72c87b7ad560.
9 The imx290_probe() function is too large. Split control initialzation to
10 a dedicated function to increase code readability.
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>
16 drivers/media/i2c/imx290.c | 109 +++++++++++++++++++++----------------
17 1 file changed, 61 insertions(+), 48 deletions(-)
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,
25 +static int imx290_ctrl_init(struct imx290 *imx290)
29 + v4l2_ctrl_handler_init(&imx290->ctrls, 5);
30 + imx290->ctrls.lock = &imx290->lock;
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
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.
45 + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
46 + V4L2_CID_GAIN, 0, 100, 1, 0);
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);
53 + v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,
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;
60 + imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
61 + V4L2_CID_PIXEL_RATE,
63 + imx290_calc_pixel_rate(imx290));
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);
70 + imx290->sd.ctrl_handler = &imx290->ctrls;
72 + if (imx290->ctrls.error) {
73 + ret = imx290->ctrls.error;
74 + v4l2_ctrl_handler_free(&imx290->ctrls);
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
86 imx290_entity_init_cfg(&imx290->sd, NULL);
88 - v4l2_ctrl_handler_init(&imx290->ctrls, 5);
89 - imx290->ctrls.lock = &imx290->lock;
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
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.
104 - v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
105 - V4L2_CID_GAIN, 0, 100, 1, 0);
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);
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;
119 - imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
120 - V4L2_CID_PIXEL_RATE,
122 - imx290_calc_pixel_rate(imx290));
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);
129 - imx290->sd.ctrl_handler = &imx290->ctrls;
131 - if (imx290->ctrls.error) {
132 - dev_err(dev, "Control initialization error %d\n",
133 - imx290->ctrls.error);
134 - ret = imx290->ctrls.error;
136 + ret = imx290_ctrl_init(imx290);
138 + dev_err(dev, "Control initialization error %d\n", ret);
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);
146 v4l2_ctrl_handler_free(&imx290->ctrls);
148 mutex_destroy(&imx290->lock);
150 v4l2_fwnode_endpoint_free(&ep);