Clamp bandwidth to nearest legal value in automode in order to pass
v4l2-compliance test.

Reported-by: Hans Verkuil <hverk...@xs4all.nl>
Signed-off-by: Antti Palosaari <cr...@iki.fi>
---
 drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c 
b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
index bcc632a..c2c3c3d 100644
--- a/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
+++ b/drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c
@@ -1324,8 +1324,16 @@ static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
        switch (ctrl->id) {
        case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
        case V4L2_CID_RF_TUNER_BANDWIDTH:
-               if (s->bandwidth_auto->val)
-                       s->bandwidth->val = s->f_adc;
+               /* TODO: these controls should be moved to tuner drivers */
+               if (s->bandwidth_auto->val) {
+                       /* Round towards the closest legal value */
+                       s32 val = s->f_adc + s->bandwidth->step / 2;
+                       u32 offset;
+                       val = clamp(val, s->bandwidth->minimum, 
s->bandwidth->maximum);
+                       offset = val - s->bandwidth->minimum;
+                       offset = s->bandwidth->step * (offset / 
s->bandwidth->step);
+                       s->bandwidth->val = s->bandwidth->minimum + offset;
+               }
 
                c->bandwidth_hz = s->bandwidth->val;
 
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to