[media] cx25840: Prevent device probe failure due to volume control ERANGE error
authorAndy Walls <awalls@md.metrocast.net>
Sun, 5 Dec 2010 22:42:30 +0000 (19:42 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 3 Jan 2011 11:08:16 +0000 (09:08 -0200)
This patch fixes a regression that crept into 2.6.36.

The volume control scale in the cx25840 driver has an unusual mapping
from register values to v4l2 volume control values.  Enforce the mapping
limits, so that the default volume control setting does not fall out of
bounds to prevent the cx25840 module device probe from failing.

Signed-off-by: Andy Walls <awalls@md.metrocast.net>
Cc: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/cx25840/cx25840-core.c

index dfb198d0415bc200b0152c1be105d722261653c5..f16461844c5c0063e281da22b8cd3e27fe6d28f4 100644 (file)
@@ -1989,8 +1989,23 @@ static int cx25840_probe(struct i2c_client *client,
        v4l2_ctrl_new_std(&state->hdl, &cx25840_ctrl_ops,
                        V4L2_CID_HUE, -128, 127, 1, 0);
        if (!is_cx2583x(state)) {
-               default_volume = 228 - cx25840_read(client, 0x8d4);
-               default_volume = ((default_volume / 2) + 23) << 9;
+               default_volume = cx25840_read(client, 0x8d4);
+               /*
+                * Enforce the legacy PVR-350/MSP3400 to PVR-150/CX25843 volume
+                * scale mapping limits to avoid -ERANGE errors when
+                * initializing the volume control
+                */
+               if (default_volume > 228) {
+                       /* Bottom out at -96 dB, v4l2 vol range 0x2e00-0x2fff */
+                       default_volume = 228;
+                       cx25840_write(client, 0x8d4, 228);
+               }
+               else if (default_volume < 20) {
+                       /* Top out at + 8 dB, v4l2 vol range 0xfe00-0xffff */
+                       default_volume = 20;
+                       cx25840_write(client, 0x8d4, 20);
+               }
+               default_volume = (((228 - default_volume) >> 1) + 23) << 9;
 
                state->volume = v4l2_ctrl_new_std(&state->hdl,
                        &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_VOLUME,