Skip to contentSkip to conversation

bttv: refactor audio_mux() and fix muting/unmuting

PATCH New Frank Schäfer 1 participant 9 messages Mar 21, 2013

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

cover bttv: refactor audio_mux() and fix muting/unmuting

This patch series refactors function audio_mux() and fixes several issues related to muting/unmuting on probing and first open.

Mute on last close will be fixed with further patches which are currently under review.

Tested with a Hauppauge WinTV Theatre (model 37284, Rev B421).

Frank Schäfer (8):
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: do not save the audio input in audio_mux()
bttv: rename field 'audio' in struct 'bttv' to 'audio_input'
bttv: separate GPIO part from function audio_mux()
bttv: untangle audio input and mute setting
bttv: do not unmute the device before the first open
bttv: apply mute settings on open

 drivers/media/pci/bt8xx/bttv-cards.c  |    2 +-
 drivers/media/pci/bt8xx/bttv-driver.c |   94 ++++++++++++++++++---------------
 drivers/media/pci/bt8xx/bttvp.h       |    2 +-

3 Dateien geändert, 52 Zeilen hinzugefügt(+), 46 Zeilen entfernt(-)

Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/8 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
#2 lore raw

PATCH 2/8 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
#3 lore raw

PATCH 3/8 bttv: do not save the audio input in audio_mux()

In reply to Frank Schäfer

We can't and do not save the mute setting in function audio_mux(), so we should also not save the input in this function for consistency.

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

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

drivers/media/pci/bt8xx/bttv-driver.c +5 -5
index a082ab4..e01a8d8 100644
@@ -999,8 +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->audio = input;
-
 	/* automute */
 	mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users)
 				&& !btv->has_radio_tuner);
@@ -1197,8 +1195,9 @@ set_input(struct bttv *btv, unsigned int input, unsigned int norm)
 	} else {
 		video_mux(btv,input);
 	}
-	audio_input(btv, (btv->tuner_type != TUNER_ABSENT && input == 0) ?
-			 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN);
+	btv->audio = (btv->tuner_type != TUNER_ABSENT && input == 0) ?
+			 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN;
+	audio_input(btv, btv->audio);
 	set_tvnorm(btv, norm);
 }
 
@@ -1707,7 +1706,8 @@ static void radio_enable(struct bttv *btv)
 	if (!btv->has_radio_tuner) {
 		btv->has_radio_tuner = 1;
 		bttv_call_all(btv, tuner, s_radio);
-		audio_input(btv, TVAUDIO_INPUT_RADIO);
+		btv->audio = TVAUDIO_INPUT_RADIO;
+		audio_input(btv, btv->audio);
 	}
 }
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/8 bttv: rename field 'audio' in struct 'bttv' to 'audio_input'

In reply to Frank Schäfer

'audio_input' better describes the meaning of this field.

---
 drivers/media/pci/bt8xx/bttv-cards.c  |    2 +-
 drivers/media/pci/bt8xx/bttv-driver.c |   12 ++++++------
 drivers/media/pci/bt8xx/bttvp.h       |    2 +-

3 Dateien geändert, 8 Zeilen hinzugefügt(+), 8 Zeilen entfernt(-)

drivers/media/pci/bt8xx/bttv-cards.c +1 -1
index fa0faaa..b7dc921 100644
@@ -3947,7 +3947,7 @@ static void avermedia_eeprom(struct bttv *btv)
 u32 bttv_tda9880_setnorm(struct bttv *btv, u32 gpiobits)
 {
 
-	if (btv->audio == TVAUDIO_INPUT_TUNER) {
+	if (btv->audio_input == TVAUDIO_INPUT_TUNER) {
 		if (bttv_tvnorms[btv->tvnorm].v4l2_id & V4L2_STD_MN)
 			gpiobits |= 0x10000;
 		else
drivers/media/pci/bt8xx/bttv-driver.c +6 -6
index e01a8d8..81ee70d 100644
@@ -1093,7 +1093,7 @@ audio_mux(struct bttv *btv, int input, int mute)
 static inline int
 audio_mute(struct bttv *btv, int mute)
 {
-	return audio_mux(btv, btv->audio, mute);
+	return audio_mux(btv, btv->audio_input, mute);
 }
 
 static inline int
@@ -1195,9 +1195,9 @@ set_input(struct bttv *btv, unsigned int input, unsigned int norm)
 	} else {
 		video_mux(btv,input);
 	}
-	btv->audio = (btv->tuner_type != TUNER_ABSENT && input == 0) ?
-			 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN;
-	audio_input(btv, btv->audio);
+	btv->audio_input = (btv->tuner_type != TUNER_ABSENT && input == 0) ?
+				TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN;
+	audio_input(btv, btv->audio_input);
 	set_tvnorm(btv, norm);
 }
 
@@ -1706,8 +1706,8 @@ static void radio_enable(struct bttv *btv)
 	if (!btv->has_radio_tuner) {
 		btv->has_radio_tuner = 1;
 		bttv_call_all(btv, tuner, s_radio);
-		btv->audio = TVAUDIO_INPUT_RADIO;
-		audio_input(btv, btv->audio);
+		btv->audio_input = TVAUDIO_INPUT_RADIO;
+		audio_input(btv, btv->audio_input);
 	}
 }
 
drivers/media/pci/bt8xx/bttvp.h +1 -1
index e7910e0..9c1cc2c 100644
@@ -423,7 +423,7 @@ struct bttv {
 
 	/* video state */
 	unsigned int input;
-	unsigned int audio;
+	unsigned int audio_input;
 	unsigned int mute;
 	unsigned long tv_freq;
 	unsigned int tvnorm;
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 5/8 bttv: separate GPIO part from function audio_mux()

In reply to Frank Schäfer

Move the GPIO part of function audio_mux() to a separate function audio_mux_gpio().
This prepares the code for the next patch which will separate mute and input setting.

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

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

drivers/media/pci/bt8xx/bttv-driver.c +12 -6
index 81ee70d..f1cb0db 100644
@@ -989,11 +989,10 @@ static char *audio_modes[] = {
 	"audio: intern", "audio: mute"
 };
 
-static int
-audio_mux(struct bttv *btv, int input, int mute)
+static void
+audio_mux_gpio(struct bttv *btv, int input, int mute)
 {
 	int gpio_val, signal, mute_gpio;
-	struct v4l2_ctrl *ctrl;
 
 	gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
 		   bttv_tvcards[btv->c.type].gpiomask);
@@ -1020,8 +1019,14 @@ audio_mux(struct bttv *btv, int input, int mute)
 
 	if (bttv_gpio)
 		bttv_gpio_tracking(btv, audio_modes[mute_gpio ? 4 : input]);
-	if (in_interrupt())
-		return 0;
+}
+
+static int
+audio_mux(struct bttv *btv, int input, int mute)
+{
+	struct v4l2_ctrl *ctrl;
+
+	audio_mux_gpio(btv, input, mute);
 
 	if (btv->sd_msp34xx) {
 		u32 in;
@@ -3846,7 +3851,8 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
 			bttv_irq_switch_video(btv);
 
 		if ((astat & BT848_INT_HLOCK)  &&  btv->opt_automute)
-			audio_mute(btv, btv->mute);  /* trigger automute */
+			/* trigger automute */
+			audio_mux_gpio(btv, btv->audio_input, btv->mute);
 
 		if (astat & (BT848_INT_SCERR|BT848_INT_OCERR)) {
 			pr_info("%d: %s%s @ %08x,",
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 6/8 bttv: untangle audio input and mute setting

In reply to Frank Schäfer

Split function audio_mux():
move the mute setting part to function audio_mute() and the input setting part to function audio_input().

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

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

drivers/media/pci/bt8xx/bttv-driver.c +24 -27
index f1cb0db..0df4a16 100644
@@ -1022,18 +1022,37 @@ audio_mux_gpio(struct bttv *btv, int input, int mute)
 }
 
 static int
-audio_mux(struct bttv *btv, int input, int mute)
+audio_mute(struct bttv *btv, int mute)
 {
 	struct v4l2_ctrl *ctrl;
 
-	audio_mux_gpio(btv, input, mute);
+	audio_mux_gpio(btv, btv->audio_input, mute);
 
 	if (btv->sd_msp34xx) {
-		u32 in;
-
 		ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE);
 		if (ctrl)
 			v4l2_ctrl_s_ctrl(ctrl, mute);
+	}
+	if (btv->sd_tvaudio) {
+		ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
+		if (ctrl)
+			v4l2_ctrl_s_ctrl(ctrl, mute);
+	}
+	if (btv->sd_tda7432) {
+		ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
+		if (ctrl)
+			v4l2_ctrl_s_ctrl(ctrl, mute);
+	}
+	return 0;
+}
+
+static int
+audio_input(struct bttv *btv, int input)
+{
+	audio_mux_gpio(btv, input, btv->mute);
+
+	if (btv->sd_msp34xx) {
+		u32 in;
 
 		/* Note: the inputs tuner/radio/extern/intern are translated
 		   to msp routings. This assumes common behavior for all msp3400
@@ -1079,34 +1098,12 @@ audio_mux(struct bttv *btv, int input, int mute)
 			       in, MSP_OUTPUT_DEFAULT, 0);
 	}
 	if (btv->sd_tvaudio) {
-		ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
-
-		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, mute);
 		v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
-				input, 0, 0);
-	}
-	if (btv->sd_tda7432) {
-		ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
-
-		if (ctrl)
-			v4l2_ctrl_s_ctrl(ctrl, mute);
+				 input, 0, 0);
 	}
 	return 0;
 }
 
-static inline int
-audio_mute(struct bttv *btv, int mute)
-{
-	return audio_mux(btv, btv->audio_input, mute);
-}
-
-static inline int
-audio_input(struct bttv *btv, int input)
-{
-	return audio_mux(btv, input, btv->mute);
-}
-
 static void
 bttv_crop_calc_limits(struct bttv_crop *c)
 {
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 7/8 bttv: do not unmute the device before the first open

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

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

drivers/media/pci/bt8xx/bttv-driver.c +3 -1
index 0df4a16..55eab61 100644
@@ -4212,11 +4212,13 @@ 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

PATCH 8/8 bttv: apply mute settings on open

In reply to Frank Schäfer

Previously, this has been done implicitly for video device nodes by calling set_input() (which calls audio_input() and also modified the mute setting).
Since input and mute setting are now untangled (as much as possible), we need to apply the mute setting with an explicit call to audio_mute().
Also apply the mute setting when the radio device node gets opened.

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

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

drivers/media/pci/bt8xx/bttv-driver.c +2 -1
index 55eab61..2fb2168 100644
@@ -3065,7 +3065,7 @@ static int bttv_open(struct file *file)
 			    fh, &btv->lock);
 	set_tvnorm(btv,btv->tvnorm);
 	set_input(btv, btv->input, btv->tvnorm);
-
+	audio_mute(btv, btv->mute);
 
 	/* The V4L2 spec requires one global set of cropping parameters
 	   which only change on request. These are stored in btv->crop[1].
@@ -3230,6 +3230,7 @@ static int radio_open(struct file *file)
 	v4l2_fh_init(&fh->fh, vdev);
 
 	btv->radio_user++;
+	audio_mute(btv, btv->mute);
 
 	v4l2_fh_add(&fh->fh);
 
Signature · 1 line
1.7.10.4