diff mbox

[RFC/PATCH,03/19] cx18: Use the control framework.

Message ID 201012121933.21498.hverkuil@xs4all.nl (mailing list archive)
State RFC
Headers show

Commit Message

Hans Verkuil Dec. 12, 2010, 6:33 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/media/video/cx18/cx18-av-core.c b/drivers/media/video/cx18/cx18-av-core.c
index e1f58f1..73b6f4d 100644
--- a/drivers/media/video/cx18/cx18-av-core.c
+++ b/drivers/media/video/cx18/cx18-av-core.c
@@ -248,8 +248,22 @@  static void cx18_av_initialize(struct v4l2_subdev *sd)
 /*      	CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x6628021F); */
 /*    } */
 	cx18_av_write4(cx, CXADEC_SRC_COMB_CFG, 0x6628021F);
-	default_volume = 228 - cx18_av_read(cx, 0x8d4);
-	default_volume = ((default_volume / 2) + 23) << 9;
+	default_volume = cx18_av_read(cx, 0x8d4);
+	/*
+	 * Enforce the legacy 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;
+		cx18_av_write(cx, 0x8d4, 228);
+	}
+	else if (default_volume < 20) {
+		/* Top out at + 8 dB, v4l2 vol range 0xfe00-0xffff */
+		default_volume = 20;
+		cx18_av_write(cx, 0x8d4, 20);
+	}
+	default_volume = (((228 - default_volume) >> 1) + 23) << 9;
 	state->volume->cur.val = state->volume->default_value = default_volume;
 	v4l2_ctrl_handler_setup(&state->hdl);
 }
@@ -1359,7 +1373,7 @@  int cx18_av_probe(struct cx18 *cx)
 
 	state->volume = v4l2_ctrl_new_std(&state->hdl,
 			&cx18_av_audio_ctrl_ops, V4L2_CID_AUDIO_VOLUME,
-			0, 65335, 65535 / 100, 0);
+			0, 65535, 65535 / 100, 0);
 	v4l2_ctrl_new_std(&state->hdl,
 			&cx18_av_audio_ctrl_ops, V4L2_CID_AUDIO_MUTE,
 			0, 1, 1, 0);