07c929ac49908ffb32ccb944d5076050b209e45b
[openwrt/staging/robimarko.git] /
1 From d5517d71c77ba67cb9dc1985a649ff11017eca0e Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Wed, 10 Feb 2021 10:18:53 +0000
4 Subject: [PATCH] media: i2c: imx477: Remove auto frame length
5 adjusting
6
7 The V4L2_CID_EXPOSURE_AUTO_PRIORITY was used to let the sensor control
8 frame length (effectively framerate) based on the requested exposure
9 time requested. Remove this feature as it is never used, and goes
10 against how V4L2 likes to handle exposure and vblank controls.
11
12 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
13 ---
14 drivers/media/i2c/imx477.c | 83 +++-----------------------------------
15 1 file changed, 6 insertions(+), 77 deletions(-)
16
17 --- a/drivers/media/i2c/imx477.c
18 +++ b/drivers/media/i2c/imx477.c
19 @@ -1082,8 +1082,6 @@ struct imx477 {
20 struct v4l2_ctrl *hflip;
21 struct v4l2_ctrl *vblank;
22 struct v4l2_ctrl *hblank;
23 - /* This ctrl allows automatic variable framerate */
24 - struct v4l2_ctrl *exposure_auto;
25
26 /* Current mode */
27 const struct imx477_mode *mode;
28 @@ -1280,66 +1278,14 @@ static int imx477_open(struct v4l2_subde
29 return 0;
30 }
31
32 -static int imx477_set_exposure(struct imx477 *imx477, unsigned int val)
33 -{
34 - int ret;
35 -
36 - ret = imx477_write_reg(imx477, IMX477_REG_EXPOSURE,
37 - IMX477_REG_VALUE_16BIT, val);
38 -
39 - /* Setup the frame length in the case of auto framerate mode. */
40 - if (imx477->exposure_auto->val) {
41 - unsigned int frame_length, frame_length_max, frame_length_min;
42 -
43 - frame_length_min = imx477->vblank->minimum +
44 - imx477->mode->height;
45 - frame_length_max = imx477->vblank->maximum +
46 - imx477->mode->height;
47 - frame_length = max(frame_length_min,
48 - val + IMX477_EXPOSURE_OFFSET);
49 - frame_length = min(frame_length_max, frame_length);
50 - ret += imx477_write_reg(imx477, IMX477_REG_FRAME_LENGTH,
51 - IMX477_REG_VALUE_16BIT, frame_length);
52 - }
53 -
54 - return ret;
55 -}
56 -
57 static void imx477_adjust_exposure_range(struct imx477 *imx477,
58 struct v4l2_ctrl *ctrl)
59 {
60 int exposure_max, exposure_def;
61
62 - if (ctrl->id == V4L2_CID_VBLANK || !ctrl->val) {
63 - /*
64 - * Either VBLANK has been changed or auto framerate
65 - * adjusting has been disabled. Honour the VBLANK limits
66 - * when setting exposure.
67 - */
68 - exposure_max = imx477->mode->height + imx477->vblank->val -
69 - IMX477_EXPOSURE_OFFSET;
70 -
71 - if (ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
72 - /*
73 - * Allow VBLANK adjustments since the driver is not
74 - * handling frame length control automatically.
75 - */
76 - __v4l2_ctrl_grab(imx477->vblank, false);
77 - }
78 - } else {
79 - /*
80 - * Auto framerate adjusting has been enabled. VBLANK
81 - * ctrl has been disabled and exposure can ramp up
82 - * to the maximum allowable value.
83 - */
84 - exposure_max = IMX477_EXPOSURE_MAX;
85 - /*
86 - * Do not allow VBLANK adjustments if the driver is
87 - * handling it frame length control automatically.
88 - */
89 - __v4l2_ctrl_grab(imx477->vblank, true);
90 - }
91 -
92 + /* Honour the VBLANK limits when setting exposure. */
93 + exposure_max = imx477->mode->height + imx477->vblank->val -
94 + IMX477_EXPOSURE_OFFSET;
95 exposure_def = min(exposure_max, imx477->exposure->val);
96 __v4l2_ctrl_modify_range(imx477->exposure, imx477->exposure->minimum,
97 exposure_max, imx477->exposure->step,
98 @@ -1353,14 +1299,8 @@ static int imx477_set_ctrl(struct v4l2_c
99 struct i2c_client *client = v4l2_get_subdevdata(&imx477->sd);
100 int ret = 0;
101
102 - if (ctrl->id == V4L2_CID_VBLANK ||
103 - ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
104 - /*
105 - * These controls may change the limits of usable exposure,
106 - * so check and adjust if necessary.
107 - */
108 + if (ctrl->id == V4L2_CID_VBLANK)
109 imx477_adjust_exposure_range(imx477, ctrl);
110 - }
111
112 /*
113 * Applying V4L2 control value only happens
114 @@ -1375,14 +1315,8 @@ static int imx477_set_ctrl(struct v4l2_c
115 IMX477_REG_VALUE_16BIT, ctrl->val);
116 break;
117 case V4L2_CID_EXPOSURE:
118 - ret = imx477_set_exposure(imx477, ctrl->val);
119 - break;
120 - case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
121 - /*
122 - * imx477_set_exposure() will recalculate the frame length
123 - * to adjust the framerate to match the exposure.
124 - */
125 - ret = imx477_set_exposure(imx477, imx477->exposure->val);
126 + ret = imx477_write_reg(imx477, IMX477_REG_EXPOSURE,
127 + IMX477_REG_VALUE_16BIT, ctrl->val);
128 break;
129 case V4L2_CID_DIGITAL_GAIN:
130 ret = imx477_write_reg(imx477, IMX477_REG_DIGITAL_GAIN,
131 @@ -2005,11 +1939,6 @@ static int imx477_init_controls(struct i
132 IMX477_DGTL_GAIN_MIN, IMX477_DGTL_GAIN_MAX,
133 IMX477_DGTL_GAIN_STEP, IMX477_DGTL_GAIN_DEFAULT);
134
135 - imx477->exposure_auto =
136 - v4l2_ctrl_new_std(ctrl_hdlr, &imx477_ctrl_ops,
137 - V4L2_CID_EXPOSURE_AUTO_PRIORITY,
138 - 0, 1, 1, 0);
139 -
140 imx477->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx477_ctrl_ops,
141 V4L2_CID_HFLIP, 0, 1, 1, 0);
142 if (imx477->hflip)