Skip to contentSkip to conversation

bttv: fix muting/unmuting on probing, first open and last close

RFC PATCH In review Frank Schäfer 2 participants 10 messages Mar 10, 2013 – Mar 15, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover bttv: fix muting/unmuting on probing, first open and last close

This patch series fixes some remaining issues with regards to device muting/unmuting on probing, first open and last close with the bttv driver.

The first 2 patches are preparatory patches, patches 3 to 6 the actual fixes.

Changes since v1:
- splitted patch 1 to 4 separate patches (patches 1-4)
- dropped patch 2 (mute on last close of the radio device node)
- added patches 5+6

Frank Schäfer (6):
bttv: audio_mux() use a local variable "gpio_mute" instead of
modifying the function parameter "mute"
bttv: audio_mux(): do not change the value of the v4l2 mute control
bttv: fix mute on last close of the video device node
bttv: do not unmute the device before the first open
bttv: avoid mute on last close when the radio device node is still
open
bttv: radio: apply mute settings on open

 drivers/media/pci/bt8xx/bttv-driver.c |   34 +++++++++++++++++++--------------

1 Datei geändert, 20 Zeilen hinzugefügt(+), 14 Zeilen entfernt(-)

Signature · 1 line
1.7.10.4
#1 lore raw

RFC PATCH v2 1/6 bttv: audio_mux() use a local variable "gpio_mute" instead of modifying the function parameter "mute"

Function audio_mux() actually deals with two types of mute: gpio mute and subdevice muting.
This patch claryfies the meaning of these values, but mainly prepares the code for the next patch.

---
 drivers/media/pci/bt8xx/bttv-driver.c |    8 ++++----

1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +4 -4
index 8610b6a..a584d82 100644
@@ -992,7 +992,7 @@ static char *audio_modes[] = {
 static int
 audio_mux(struct bttv *btv, int input, int mute)
 {
-	int gpio_val, signal;
+	int gpio_val, signal, mute_gpio;
 	struct v4l2_ctrl *ctrl;
 
 	gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
@@ -1003,10 +1003,10 @@ audio_mux(struct bttv *btv, int input, int mute)
 	btv->audio = input;
 
 	/* automute */
-	mute = mute || (btv->opt_automute && (!signal || !btv->users)
+	mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users)
 				&& !btv->has_radio_tuner);
 
-	if (mute)
+	if (mute_gpio)
 		gpio_val = bttv_tvcards[btv->c.type].gpiomute;
 	else
 		gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
@@ -1022,7 +1022,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 	}
 
 	if (bttv_gpio)
-		bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]);
+		bttv_gpio_tracking(btv, audio_modes[mute_gpio ? 4 : input]);
 	if (in_interrupt())
 		return 0;
 
Signature · 1 line
1.7.10.4
Acked-by on v2 1/6
#2 lore raw

Re: [RFC PATCH v2 1/6] bttv: audio_mux() use a local variable "gpio_mute" instead of modifying the function parameter "mute"

Quoted 6 lines · On Sun 10 March 2013 22:53:49 Frank Schäfer wrote:

Function audio_mux() actually deals with two types of mute: gpio mute and subdevice muting.
This patch claryfies the meaning of these values, but mainly prepares the code for the next patch.

Regards,

Hans

Quoted 40 lines
---
 drivers/media/pci/bt8xx/bttv-driver.c |    8 ++++----

1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +4 -4
index 8610b6a..a584d82 100644
@@ -992,7 +992,7 @@ static char *audio_modes[] = {
 static int
 audio_mux(struct bttv *btv, int input, int mute)
 {
-	int gpio_val, signal;
+	int gpio_val, signal, mute_gpio;
 	struct v4l2_ctrl *ctrl;
 
 	gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
@@ -1003,10 +1003,10 @@ audio_mux(struct bttv *btv, int input, int mute)
 	btv->audio = input;
 
 	/* automute */
-	mute = mute || (btv->opt_automute && (!signal || !btv->users)
+	mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users)
 				&& !btv->has_radio_tuner);
 
-	if (mute)
+	if (mute_gpio)
 		gpio_val = bttv_tvcards[btv->c.type].gpiomute;
 	else
 		gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
@@ -1022,7 +1022,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 	}
 
 	if (bttv_gpio)
-		bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]);
+		bttv_gpio_tracking(btv, audio_modes[mute_gpio ? 4 : input]);
 	if (in_interrupt())
 		return 0;
 
#3 lore raw

RFC PATCH v2 2/6 bttv: audio_mux(): do not change the value of the v4l2 mute control

In reply to Frank Schäfer

There are cases where we want to call audio_mux() without changing the value of the v4l2 mute control, for example
- mute mute on last close
- mute on device probing

---
 drivers/media/pci/bt8xx/bttv-driver.c |    8 ++++----

1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +4 -4
index a584d82..a082ab4 100644
@@ -999,7 +999,6 @@ audio_mux(struct bttv *btv, int input, int mute)
 		   bttv_tvcards[btv->c.type].gpiomask);
 	signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC;
 
-	btv->mute = mute;
 	btv->audio = input;
 
 	/* automute */
@@ -1031,7 +1030,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 
 		ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 
 		/* Note: the inputs tuner/radio/extern/intern are translated
 		   to msp routings. This assumes common behavior for all msp3400
@@ -1080,7 +1079,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 		ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 		v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
 				input, 0, 0);
 	}
@@ -1088,7 +1087,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 		ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 	}
 	return 0;
 }
@@ -1300,6 +1299,7 @@ static int bttv_s_ctrl(struct v4l2_ctrl *c)
 		break;
 	case V4L2_CID_AUDIO_MUTE:
 		audio_mute(btv, c->val);
+		btv->mute = c->val;
 		break;
 	case V4L2_CID_AUDIO_VOLUME:
 		btv->volume_gpio(btv, c->val);
Signature · 1 line
1.7.10.4
Acked-by on v2 2/6
#4 lore raw

Re: [RFC PATCH v2 2/6] bttv: audio_mux(): do not change the value of the v4l2 mute control

Quoted 6 lines · On Sun 10 March 2013 22:53:50 Frank Schäfer wrote:

There are cases where we want to call audio_mux() without changing the value of the v4l2 mute control, for example
- mute mute on last close
- mute on device probing

I think it might be a good idea to take this one step further: pull the btv->audio assignment out of audio_mux as well. In other words, audio_mux no longer changes the bttv state.

I also think that the audio_mute and audio_input functions should be removed, just let the code call audio_mux directly. I think that is more transparent and one less intermediate call.

A next step would be to untangle the audio routing code and mute code from audio_mux: that's probably the core of all the confusion. The code relating to the input selection should be put in a separate function that is called only when you really want to switch inputs.

I'm not sure if you want to spend time on that last step, if not, then just do the first two suggestions and I'll test the result. But without really going to the core of the problem (one function mixing up muting and input selection) it remains hard to prove correctness of the code. If you have some time, then it would be very nice if this mess can be resolved once and for all.

Regards,

Hans

Quoted 52 lines
---
 drivers/media/pci/bt8xx/bttv-driver.c |    8 ++++----

1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +4 -4
index a584d82..a082ab4 100644
@@ -999,7 +999,6 @@ audio_mux(struct bttv *btv, int input, int mute)
 		   bttv_tvcards[btv->c.type].gpiomask);
 	signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC;
 
-	btv->mute = mute;
 	btv->audio = input;
 
 	/* automute */
@@ -1031,7 +1030,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 
 		ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 
 		/* Note: the inputs tuner/radio/extern/intern are translated
 		   to msp routings. This assumes common behavior for all msp3400
@@ -1080,7 +1079,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 		ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 		v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
 				input, 0, 0);
 	}
@@ -1088,7 +1087,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 		ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 	}
 	return 0;
 }
@@ -1300,6 +1299,7 @@ static int bttv_s_ctrl(struct v4l2_ctrl *c)
 		break;
 	case V4L2_CID_AUDIO_MUTE:
 		audio_mute(btv, c->val);
+		btv->mute = c->val;
 		break;
 	case V4L2_CID_AUDIO_VOLUME:
 		btv->volume_gpio(btv, c->val);
#5 lore raw

Re: [RFC PATCH v2 2/6] bttv: audio_mux(): do not change the value of the v4l2 mute control

Hi Hans,

thank you for reviewing and sorry for the delayed reply !

Am 12.03.2013 14:41, schrieb Hans Verkuil:

Quoted 6 lines · On Sun 10 March 2013 22:53:50 Frank Schäfer wrote:
Quoted 5 lines

There are cases where we want to call audio_mux() without changing the value of the v4l2 mute control, for example
- mute mute on last close
- mute on device probing

Quoted 7 lines
Quoted 1 line

I think it might be a good idea to take this one step further: pull the btv->audio assignment out of audio_mux as well. In other words, audio_mux no longer changes the bttv state.

Yes, that should be easy to do.

Quoted 3 lines

I also think that the audio_mute and audio_input functions should be removed, just let the code call audio_mux directly. I think that is more transparent and one less intermediate call.

OTOH I think they improve readability.
Anyway, this will become obsolete with the next step you're suggesting:

Quoted 4 lines

A next step would be to untangle the audio routing code and mute code from audio_mux: that's probably the core of all the confusion. The code relating to the input selection should be put in a separate function that is called only when you really want to switch inputs.

Yeah, it would be nice if we could do that, but I'm not sure if it's entirely possible.
Mute + automute and the selected input seem to be coupled via gpio settings. See the first third
of function audio_mux().
I will have to take a deeper look into the code to see if splitting the function really makes sense...

Quoted 6 lines

I'm not sure if you want to spend time on that last step, if not, then just do the first two suggestions and I'll test the result. But without really going to the core of the problem (one function mixing up muting and input selection) it remains hard to prove correctness of the code. If you have some time, then it would be very nice if this mess can be resolved once and for all.

I've put it on my TODO list, but I'm not sure if I'll find some time for it this weekend.

Regards,
Frank

Quoted 56 lines

Regards,

Hans

Quoted 52 lines
---
 drivers/media/pci/bt8xx/bttv-driver.c |    8 ++++----

1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +4 -4
index a584d82..a082ab4 100644
@@ -999,7 +999,6 @@ audio_mux(struct bttv *btv, int input, int mute)
 		   bttv_tvcards[btv->c.type].gpiomask);
 	signal = btread(BT848_DSTATUS) & BT848_DSTATUS_HLOC;
 
-	btv->mute = mute;
 	btv->audio = input;
 
 	/* automute */
@@ -1031,7 +1030,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 
 		ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 
 		/* Note: the inputs tuner/radio/extern/intern are translated
 		   to msp routings. This assumes common behavior for all msp3400
@@ -1080,7 +1079,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 		ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 		v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
 				input, 0, 0);
 	}
@@ -1088,7 +1087,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 		ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 
 		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, btv->mute);
+			v4l2_ctrl_s_ctrl(ctrl, mute);
 	}
 	return 0;
 }
@@ -1300,6 +1299,7 @@ static int bttv_s_ctrl(struct v4l2_ctrl *c)
 		break;
 	case V4L2_CID_AUDIO_MUTE:
 		audio_mute(btv, c->val);
+		btv->mute = c->val;
 		break;
 	case V4L2_CID_AUDIO_VOLUME:
 		btv->volume_gpio(btv, c->val);
#6 lore raw

RFC PATCH v2 3/6 bttv: fix mute on last close of the video device node

In reply to Frank Schäfer
---
 drivers/media/pci/bt8xx/bttv-driver.c |    2 +-

1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +1 -1
index a082ab4..945ecd2 100644
@@ -3124,7 +3124,7 @@ static int bttv_release(struct file *file)
 	bttv_field_count(btv);
 
 	if (!btv->users)
-		audio_mute(btv, btv->mute);
+		audio_mute(btv, 1);
 
 	v4l2_fh_del(&fh->fh);
 	v4l2_fh_exit(&fh->fh);
Signature · 1 line
1.7.10.4
#7 lore raw

RFC PATCH v2 4/6 bttv: do not unmute the device before the first open

In reply to Frank Schäfer
---
 drivers/media/pci/bt8xx/bttv-driver.c |    8 +++++---

1 Datei geändert, 5 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +5 -3
index 945ecd2..6432bfe 100644
@@ -3062,8 +3062,7 @@ static int bttv_open(struct file *file)
 			    sizeof(struct bttv_buffer),
 			    fh, &btv->lock);
 	set_tvnorm(btv,btv->tvnorm);
-	set_input(btv, btv->input, btv->tvnorm);
-
+	set_input(btv, btv->input, btv->tvnorm); /* also (un)mutes audio */
 
 	/* The V4L2 spec requires one global set of cropping parameters
 	   which only change on request. These are stored in btv->crop[1].
@@ -4209,11 +4208,14 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
 	btv->std = V4L2_STD_PAL;
 	init_irqreg(btv);
 	v4l2_ctrl_handler_setup(hdl);
-
 	if (hdl->error) {
 		result = hdl->error;
 		goto fail2;
 	}
+
+	/* mute device */
+	audio_mute(btv, 1);
+
 	/* register video4linux + input */
 	if (!bttv_tvcards[btv->c.type].no_video) {
 		v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl,
Signature · 1 line
1.7.10.4
#8 lore raw

RFC PATCH v2 5/6 bttv: avoid mute on last close when the radio device node is still open

In reply to Frank Schäfer

In contrast to video devices, radio devices should not be muted on the last close of the device node.
In cases where a device provides a video and a radio device node, tuner ownership has to be taken into account.

The current code doesn't handle tuner ownership yet, so never mute the device if the radio device node is still open.
Also add a comment about this issue.

---
 drivers/media/pci/bt8xx/bttv-driver.c |    6 ++++--

1 Datei geändert, 4 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-driver.c +4 -2
index 6432bfe..7459ad6 100644
@@ -3114,7 +3114,6 @@ static int bttv_release(struct file *file)
 	}
 
 	/* free stuff */
-
 	videobuf_mmap_free(&fh->cap);
 	videobuf_mmap_free(&fh->vbi);
 	file->private_data = NULL;
@@ -3122,8 +3121,11 @@ static int bttv_release(struct file *file)
 	btv->users--;
 	bttv_field_count(btv);
 
-	if (!btv->users)
+	if (!btv->users && !btv->radio_user)
 		audio_mute(btv, 1);
+	/* FIXME: should also depend on tuner ownership ! */
+	/* NOTE as long as we don't handle the tuner ownership properly,
+	 * only mute the device if the radio device node isn't open. */
 
 	v4l2_fh_del(&fh->fh);
 	v4l2_fh_exit(&fh->fh);
Signature · 1 line
1.7.10.4
#9 lore raw

RFC PATCH v2 6/6 bttv: radio: apply mute settings on open

In reply to Frank Schäfer

In contrast to the video device node, radio_open() doesn't select an input (which would also applies the mute setting).
Hence the device needs to be muted/unmuted with an explicit call to audio_mux() in this function.

---
 drivers/media/pci/bt8xx/bttv-driver.c |    2 ++

1 Datei geändert, 2 Zeilen hinzugefügt(+)

drivers/media/pci/bt8xx/bttv-driver.c +2 -0
index 7459ad6..5031b6e 100644
@@ -3232,6 +3232,8 @@ static int radio_open(struct file *file)
 
 	v4l2_fh_add(&fh->fh);
 
+	audio_mute(btv, btv->mute);
+
 	return 0;
 }
 
Signature · 1 line
1.7.10.4