Skip to contentSkip to conversation

cx18: Use the control framework.

PATCH Andy Walls 2 participants 4 messages Dec 12, 2010 – Dec 13, 2010 Media (V4L/DVB)

lore
Share & tools
lore

Andy Walls

author
#0 lore raw

Hi Hans,

It looks like it should. I'm looking at things on my phone while out and about - not the best environment for code review.

You just need to ensure default vol is >= 0 and <= 65535 which may not be the case if reg 8d4 has a value near 0.

Two other topics while I'm here:

1. Why set the vol step to 655, when the volume will actaully step at increments of 512?

2. Why should failure to initialize a data structure for user controls mean failure to init otherwise working hardware? We never let user control init cause subdev driver probe failure before, so why now? I'd prefer a working device without user controls in case of user control init failure.

Regards,
Andy

Quoted 68 lines · Hans Verkuil
Quoted 6 lines · On Sunday, December 12, 2010 19:09:36 Andy Walls wrote:

Hans,

This has at least the same two problems the change for cx25840 had:

1. Volume control init should use 65535 not 65335

Quoted 9 lines

2. You cannot trust reg 0x8d4 to have a value in it for the default volume that won't give an ERANGE error when you go to init the volume control. Subdev probe will fail. See my previous cx25840 patches sent to the list, awaiting action.

(The cx25840 code that trusts the volume register to be in range is already in 2.6.36 and breaks IR and analog for CX23885/7/8 chips.)

I'll give this whole patch a harder look later this evening if I can.

Regards,
Andy

Would the patch below fix these issues? It compiles, but I didn't test it.

Regards,

Hans

drivers/media/video/cx18/cx18-av-core.c +17 -3
index e1f58f1..73b6f4d 100644
@@ -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);
Signature · 6 lines
-- 
Hans Verkuil - video4linux developer - sponsored by Cisco
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 9 lines · On Sunday, December 12, 2010 19:46:33 Andy Walls wrote:

Hi Hans,

It looks like it should. I'm looking at things on my phone while out and about - not the best environment for code review.

You just need to ensure default vol is >= 0 and <= 65535 which may not be the case if reg 8d4 has a value near 0.

Two other topics while I'm here:

1. Why set the vol step to 655, when the volume will actaully step at increments of 512?

The goal of the exercise is to convert to the control framework. I don't like to mix changes like that with lots of other unrelated changes, so I kept this the same as it was.

Quoted 1 line

2. Why should failure to initialize a data structure for user controls mean failure to init otherwise working hardware? We never let user control init cause subdev driver probe failure before, so why now? I'd prefer a working device without user controls in case of user control init failure.

Huh? If you fail to allocate the memory for such data structures then I'm pretty sure you will encounter other problems as well. It's a highly unlikely scenario anyway since if you have so little memory that you can't allocate these data structures, then it is just about impossible that you could allocate the memory for the video buffers.

Regards,

Hans

Quoted 70 lines

Regards,
Andy

Quoted 62 lines · Hans Verkuil
Quoted 6 lines · On Sunday, December 12, 2010 19:09:36 Andy Walls wrote:

Hans,

This has at least the same two problems the change for cx25840 had:

1. Volume control init should use 65535 not 65335

Quoted 9 lines

2. You cannot trust reg 0x8d4 to have a value in it for the default volume that won't give an ERANGE error when you go to init the volume control. Subdev probe will fail. See my previous cx25840 patches sent to the list, awaiting action.

(The cx25840 code that trusts the volume register to be in range is already in 2.6.36 and breaks IR and analog for CX23885/7/8 chips.)

I'll give this whole patch a harder look later this evening if I can.

Regards,
Andy

Would the patch below fix these issues? It compiles, but I didn't test it.

Regards,

Hans

drivers/media/video/cx18/cx18-av-core.c +17 -3
index e1f58f1..73b6f4d 100644
@@ -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);
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by Cisco
author
#2 lore raw
Quoted 1 line · Hans Verkuil

On Sunday, December 12, 2010 19:46:33 Andy Walls wrote:

Hi Hans,

Quoted 5 lines
Quoted 1 line

1. Why set the vol step to 655, when the volume will actaully step at increments of 512?

The goal of the exercise is to convert to the control framework. I don't like to mix changes like that with lots of other unrelated changes, so I kept this the same as it was.

Sounds fine to me.

Quoted 8 lines
Quoted 1 line

2. Why should failure to initialize a data structure for user

controls mean failure to init otherwise working hardware? We never let user control init cause subdev driver probe failure before, so why now? I'd prefer a working device without user controls in case of user control init failure.

Huh? If you fail to allocate the memory for such data structures then I'm pretty sure you will encounter other problems as well.

ENOMEM is not why I bring this up. The new control framework can also return ERANGE and EINVAL.

Granted, both look like they can only result due to subdev driver bugs. However, when one is mass converting subdev and bridge drivers, bugs are going to get introduced. In my specific case, the ERANGE error, aborting the the init of the CX23888 A/V core in the cx25840 driver, meant the CX23888 IR unit doesn't get a good clock. IR didn't work because of a *volume control*!? That is the only reason I noticed the bug.

I perceive a dearth of non-developers testing the changes in the GIT trees. I don't have confidence that the majority of subdev driver bugs introduced by the conversion to the new framework will get caught until after a kernel release. As I am discovering, the process for getting regressions fixed and into stable kernels is much longer than the time to introduce bugs.

I would prefer deployed hardware still be as operational as possible under newly released kernels. That's why I'll still suggest user control init failure, for something other than ENOMEM, be a non-fatal error. The move to the new control framework has no immediate, user-visible changes, except for symptoms of any introduced bugs. The bugs found so far (msp3400 and cx25840) had pretty severe symptoms, and were noticed way too late.

My $0.02.

Regards,
Andy

#3 lore raw
Quoted 26 lines · On Monday, December 13, 2010 14:31:18 Andy Walls wrote:
Quoted 1 line · Hans Verkuil

On Sunday, December 12, 2010 19:46:33 Andy Walls wrote:

Hi Hans,

Quoted 5 lines
Quoted 1 line

1. Why set the vol step to 655, when the volume will actaully step at increments of 512?

The goal of the exercise is to convert to the control framework. I don't like to mix changes like that with lots of other unrelated changes, so I kept this the same as it was.

Sounds fine to me.

Quoted 8 lines
Quoted 1 line

2. Why should failure to initialize a data structure for user

controls mean failure to init otherwise working hardware? We never let user control init cause subdev driver probe failure before, so why now? I'd prefer a working device without user controls in case of user control init failure.

Huh? If you fail to allocate the memory for such data structures then I'm pretty sure you will encounter other problems as well.

ENOMEM is not why I bring this up. The new control framework can also return ERANGE and EINVAL.

Quoted 7 lines

Granted, both look like they can only result due to subdev driver bugs. However, when one is mass converting subdev and bridge drivers, bugs are going to get introduced. In my specific case, the ERANGE error, aborting the the init of the CX23888 A/V core in the cx25840 driver, meant the CX23888 IR unit doesn't get a good clock. IR didn't work because of a *volume control*!? That is the only reason I noticed the bug.

But would you have noticed it if it would just skip the control due to a driver bug? I much rather like to see a clear failure then that a control silently disappears.

Quoted 7 lines

I perceive a dearth of non-developers testing the changes in the GIT trees. I don't have confidence that the majority of subdev driver bugs introduced by the conversion to the new framework will get caught until after a kernel release. As I am discovering, the process for getting regressions fixed and into stable kernels is much longer than the time to introduce bugs.

Quoted 7 lines

I would prefer deployed hardware still be as operational as possible under newly released kernels. That's why I'll still suggest user control init failure, for something other than ENOMEM, be a non-fatal error. The move to the new control framework has no immediate, user-visible changes, except for symptoms of any introduced bugs. The bugs found so far (msp3400 and cx25840) had pretty severe symptoms, and were noticed way too late.

I think this was more bad luck than anything else. From what I can remember, these were pretty much the only regressions that we had. Based on other large conversions I did in the past (e.g. the conversion to the subdevice API) the number of regressions that they caused was surprisingly small.

The motivation of the move to the control framework is to make drivers more predictable for userspace applications. Right now control handling is wildly different between drivers. By moving everything over we should have better and more consistent drivers in the end.

Regards,

Hans

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by Cisco