[media] rtl2832_sdr: clamp bandwidth to nearest legal value in automode
authorAntti Palosaari <crope@iki.fi>
Mon, 10 Mar 2014 17:28:45 +0000 (14:28 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Fri, 14 Mar 2014 08:39:58 +0000 (05:39 -0300)
Clamp bandwidth to nearest legal value in automode in order to pass
v4l2-compliance test.

Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/staging/media/rtl2832u_sdr/rtl2832_sdr.c

index 141fc8b428bac8099a3b5993809a4af9c477359f..b09f7d8c12cf8faf3dfbc844bd13f8d88fa82196 100644 (file)
@@ -1322,8 +1322,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;