All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] au0828: fix analog streaming and add PAL-M support
@ 2014-06-08 16:54 Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 1/8] au8522: move input_mode out one level Mauro Carvalho Chehab
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab


This patch series fixes a very nasty bug on au0828: if usb_set_interface
is called more than once to set alternate 5, the URBs are shutdown.
This is likely due to a hardware bug.

It also adds support for PAL-M. So, now, both NTSC-M and PAL-M are
working (both tested).

It also does a few cleanups.

After the patches, both xawtv and qv4l2 are working fine, with
either PAL-M or NTSC-M.

I may eventually add support for PAL-BG when I have some spare time.

PS.: At least here, there's still an unrelated issue with xawtv:
it keeps suffering from underrun errors. Fixing it would likely
require to add some quirks at usb-snd-audio, for it to select
a better latency interval.

Mauro Carvalho Chehab (8):
  au8522: move input_mode out one level
  au8522: be sure that the setup will happen at streamon time
  au8522: be sure that we'll setup audio routing at the right time
  au8522: cleanup s-video settings at setup_decoder_defaults()
  au8522: Fix demod analog mode setting
  au0828/au8522: Add PAL-M support
  au0828: Only alt setting logic when needed
  au0828: don't hardcode height/width

 drivers/media/dvb-frontends/au8522_decoder.c | 180 ++++++++++++++++++---------
 drivers/media/dvb-frontends/au8522_priv.h    |   2 +
 drivers/media/usb/au0828/au0828-video.c      |  60 +++++----
 3 files changed, 157 insertions(+), 85 deletions(-)

-- 
1.9.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/8] au8522: move input_mode out one level
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 2/8] au8522: be sure that the setup will happen at streamon time Mauro Carvalho Chehab
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

The input mode is used not only inside the setup_decoder_defaults()
but also at au8522_*_mode routines.

So, move it one level up. As an advantage, we can now group the
function that sets the input into just one.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/dvb-frontends/au8522_decoder.c | 93 ++++++++++++++++++++--------
 1 file changed, 67 insertions(+), 26 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 23a0d05ba426..21d204914524 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -346,7 +346,7 @@ static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
 	au8522_writereg(state, AU8522_REG436H, 0x3c);
 }
 
-static void au8522_setup_cvbs_mode(struct au8522_state *state)
+static void au8522_setup_cvbs_mode(struct au8522_state *state, u8 input_mode)
 {
 	/* here we're going to try the pre-programmed route */
 	au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
@@ -358,16 +358,16 @@ static void au8522_setup_cvbs_mode(struct au8522_state *state)
 	/* Enable clamping control */
 	au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
 
-	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
-			AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
+	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
 
-	setup_decoder_defaults(state, AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
+	setup_decoder_defaults(state, input_mode);
 
 	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
 			AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
 }
 
-static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state)
+static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state,
+					 u8 input_mode)
 {
 	/* here we're going to try the pre-programmed route */
 	au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
@@ -384,24 +384,22 @@ static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state)
 	au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10);
 
 	/* Set input mode to CVBS on channel 4 with SIF audio input enabled */
-	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
-			AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF);
+	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
 
-	setup_decoder_defaults(state,
-			       AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF);
+	setup_decoder_defaults(state, input_mode);
 
 	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
 			AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
 }
 
-static void au8522_setup_svideo_mode(struct au8522_state *state)
+static void au8522_setup_svideo_mode(struct au8522_state *state,
+				     u8 input_mode)
 {
 	au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
 			AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO);
 
 	/* Set input to Y on Channe1, C on Channel 3 */
-	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
-			AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
+	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
 
 	/* PGA in automatic mode */
 	au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
@@ -409,8 +407,7 @@ static void au8522_setup_svideo_mode(struct au8522_state *state)
 	/* Enable clamping control */
 	au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
 
-	setup_decoder_defaults(state,
-			       AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
+	setup_decoder_defaults(state, input_mode);
 
 	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
 			AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
@@ -558,10 +555,8 @@ static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
 	return 0;
 }
 
-static int au8522_reset(struct v4l2_subdev *sd, u32 val)
+static int __au8522_reset(struct au8522_state *state)
 {
-	struct au8522_state *state = to_state(sd);
-
 	state->operational_mode = AU8522_ANALOG_MODE;
 
 	/* Clear out any state associated with the digital side of the
@@ -574,23 +569,69 @@ static int au8522_reset(struct v4l2_subdev *sd, u32 val)
 	return 0;
 }
 
+static int au8522_reset(struct v4l2_subdev *sd, u32 val)
+{
+	struct au8522_state *state = to_state(sd);
+
+	return __au8522_reset(state);
+}
+
+static void au8522_video_set(struct au8522_state *state)
+
+{
+	u8 input_mode;
+
+	__au8522_reset(state);
+
+	switch (state->vid_input) {
+	case AU8522_COMPOSITE_CH1:
+		input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH1;
+		au8522_setup_cvbs_mode(state, input_mode);
+		break;
+	case AU8522_COMPOSITE_CH2:
+		input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH2;
+		au8522_setup_cvbs_mode(state, input_mode);
+		break;
+	case AU8522_COMPOSITE_CH3:
+		input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH3;
+		au8522_setup_cvbs_mode(state, input_mode);
+		break;
+	case AU8522_COMPOSITE_CH4:
+		input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH4;
+		au8522_setup_cvbs_mode(state, input_mode);
+		break;
+	case AU8522_SVIDEO_CH13:
+		input_mode = AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13;
+		au8522_setup_svideo_mode(state, input_mode);
+		break;
+	case AU8522_SVIDEO_CH24:
+		input_mode = AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24;
+		au8522_setup_svideo_mode(state, input_mode);
+		break;
+	default:
+	case AU8522_COMPOSITE_CH4_SIF:
+		input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF;
+		au8522_setup_cvbs_tuner_mode(state, input_mode);
+		break;
+	}
+}
+
 static int au8522_s_video_routing(struct v4l2_subdev *sd,
 					u32 input, u32 output, u32 config)
 {
 	struct au8522_state *state = to_state(sd);
 
-	au8522_reset(sd, 0);
-
-	if (input == AU8522_COMPOSITE_CH1) {
-		au8522_setup_cvbs_mode(state);
-	} else if (input == AU8522_SVIDEO_CH13) {
-		au8522_setup_svideo_mode(state);
-	} else if (input == AU8522_COMPOSITE_CH4_SIF) {
-		au8522_setup_cvbs_tuner_mode(state);
-	} else {
+	switch(input) {
+	case AU8522_COMPOSITE_CH1:
+	case AU8522_SVIDEO_CH13:
+	case AU8522_COMPOSITE_CH4_SIF:
+		state->vid_input = input;
+		break;
+	default:
 		printk(KERN_ERR "au8522 mode not currently supported\n");
 		return -EINVAL;
 	}
+	au8522_video_set(state);
 	return 0;
 }
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/8] au8522: be sure that the setup will happen at streamon time
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 1/8] au8522: move input_mode out one level Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 3/8] au8522: be sure that we'll setup audio routing at the right time Mauro Carvalho Chehab
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

The same demod is used on both analog and digital mode. We should
not let the commands for analog mode to happen while the device
is in digital mode. So, monitor it via streamon.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/dvb-frontends/au8522_decoder.c | 80 +++++++++++++---------------
 drivers/media/dvb-frontends/au8522_priv.h    |  1 +
 2 files changed, 37 insertions(+), 44 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 21d204914524..b2b9f04a1340 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -536,52 +536,11 @@ static int au8522_s_register(struct v4l2_subdev *sd,
 }
 #endif
 
-static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
-{
-	struct au8522_state *state = to_state(sd);
-
-	if (enable) {
-		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
-				0x01);
-		msleep(1);
-		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
-				AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
-	} else {
-		/* This does not completely power down the device
-		   (it only reduces it from around 140ma to 80ma) */
-		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
-				1 << 5);
-	}
-	return 0;
-}
-
-static int __au8522_reset(struct au8522_state *state)
-{
-	state->operational_mode = AU8522_ANALOG_MODE;
-
-	/* Clear out any state associated with the digital side of the
-	   chip, so that when it gets powered back up it won't think
-	   that it is already tuned */
-	state->current_frequency = 0;
-
-	au8522_writereg(state, 0xa4, 1 << 5);
-
-	return 0;
-}
-
-static int au8522_reset(struct v4l2_subdev *sd, u32 val)
-{
-	struct au8522_state *state = to_state(sd);
-
-	return __au8522_reset(state);
-}
-
 static void au8522_video_set(struct au8522_state *state)
-
 {
 	u8 input_mode;
 
-	__au8522_reset(state);
+	au8522_writereg(state, 0xa4, 1 << 5);
 
 	switch (state->vid_input) {
 	case AU8522_COMPOSITE_CH1:
@@ -616,6 +575,37 @@ static void au8522_video_set(struct au8522_state *state)
 	}
 }
 
+static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct au8522_state *state = to_state(sd);
+
+	if (enable) {
+		state->operational_mode = AU8522_ANALOG_MODE;
+
+		/*
+		 * Clear out any state associated with the digital side of the
+		 * chip, so that when it gets powered back up it won't think
+		 * that it is already tuned
+		 */
+		state->current_frequency = 0;
+
+		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
+				0x01);
+		msleep(1);
+		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
+				AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
+
+		au8522_video_set(state);
+	} else {
+		/* This does not completely power down the device
+		   (it only reduces it from around 140ma to 80ma) */
+		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
+				1 << 5);
+		state->operational_mode = AU8522_SUSPEND_MODE;
+	}
+	return 0;
+}
+
 static int au8522_s_video_routing(struct v4l2_subdev *sd,
 					u32 input, u32 output, u32 config)
 {
@@ -631,7 +621,10 @@ static int au8522_s_video_routing(struct v4l2_subdev *sd,
 		printk(KERN_ERR "au8522 mode not currently supported\n");
 		return -EINVAL;
 	}
-	au8522_video_set(state);
+
+	if (state->operational_mode == AU8522_ANALOG_MODE)
+		au8522_video_set(state);
+
 	return 0;
 }
 
@@ -670,7 +663,6 @@ static int au8522_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
 
 static const struct v4l2_subdev_core_ops au8522_core_ops = {
 	.log_status = v4l2_ctrl_subdev_log_status,
-	.reset = au8522_reset,
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	.g_register = au8522_g_register,
 	.s_register = au8522_s_register,
diff --git a/drivers/media/dvb-frontends/au8522_priv.h b/drivers/media/dvb-frontends/au8522_priv.h
index aa0f16d6b610..a781489520fb 100644
--- a/drivers/media/dvb-frontends/au8522_priv.h
+++ b/drivers/media/dvb-frontends/au8522_priv.h
@@ -37,6 +37,7 @@
 
 #define AU8522_ANALOG_MODE 0
 #define AU8522_DIGITAL_MODE 1
+#define AU8522_SUSPEND_MODE 2
 
 struct au8522_state {
 	struct i2c_client *c;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/8] au8522: be sure that we'll setup audio routing at the right time
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 1/8] au8522: move input_mode out one level Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 2/8] au8522: be sure that the setup will happen at streamon time Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 4/8] au8522: cleanup s-video settings at setup_decoder_defaults() Mauro Carvalho Chehab
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

Let's set the the audio routing also at stream start. With this change,
we don't risk enabling the analog demux while not streaming, reducing
the risk of interfering with a DVB demux that might be happening.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/dvb-frontends/au8522_decoder.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index b2b9f04a1340..53f6dea6b3cb 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -429,8 +429,9 @@ static void disable_audio_input(struct au8522_state *state)
 }
 
 /* 0=disable, 1=SIF */
-static void set_audio_input(struct au8522_state *state, int aud_input)
+static void set_audio_input(struct au8522_state *state)
 {
+	int aud_input = state->aud_input;
 	int i;
 
 	/* Note that this function needs to be used in conjunction with setting
@@ -580,8 +581,6 @@ static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
 	struct au8522_state *state = to_state(sd);
 
 	if (enable) {
-		state->operational_mode = AU8522_ANALOG_MODE;
-
 		/*
 		 * Clear out any state associated with the digital side of the
 		 * chip, so that when it gets powered back up it won't think
@@ -596,6 +595,10 @@ static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
 				AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
 
 		au8522_video_set(state);
+
+		set_audio_input(state);
+
+		state->operational_mode = AU8522_ANALOG_MODE;
 	} else {
 		/* This does not completely power down the device
 		   (it only reduces it from around 140ma to 80ma) */
@@ -632,7 +635,12 @@ static int au8522_s_audio_routing(struct v4l2_subdev *sd,
 					u32 input, u32 output, u32 config)
 {
 	struct au8522_state *state = to_state(sd);
-	set_audio_input(state, input);
+
+	state->aud_input = input;
+
+	if (state->operational_mode == AU8522_ANALOG_MODE)
+		set_audio_input(state);
+
 	return 0;
 }
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/8] au8522: cleanup s-video settings at setup_decoder_defaults()
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
                   ` (2 preceding siblings ...)
  2014-06-08 16:54 ` [PATCH 3/8] au8522: be sure that we'll setup audio routing at the right time Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 5/8] au8522: Fix demod analog mode setting Mauro Carvalho Chehab
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

setup_decoder_defaults() doesn't really care about the input
port. All it needs to know is if the input port is s-video or
not.

As the caller function already knows that, just pass a boolean
instead.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/dvb-frontends/au8522_decoder.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 53f6dea6b3cb..569922232eb8 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -220,7 +220,7 @@ static void setup_vbi(struct au8522_state *state, int aud_input)
 
 }
 
-static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
+static void setup_decoder_defaults(struct au8522_state *state, bool is_svideo)
 {
 	int i;
 	int filter_coef_type;
@@ -237,13 +237,10 @@ static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
 	/* Other decoder registers */
 	au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0x00);
 
-	if (input_mode == 0x23) {
-		/* S-Video input mapping */
+	if (is_svideo)
 		au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x04);
-	} else {
-		/* All other modes (CVBS/ATVRF etc.) */
+	else
 		au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x00);
-	}
 
 	au8522_writereg(state, AU8522_TVDEC_PGA_REG012H,
 			AU8522_TVDEC_PGA_REG012H_CVBS);
@@ -275,8 +272,7 @@ static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
 			AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS);
 	au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH,
 			AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS);
-	if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 ||
-	    input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) {
+	if (is_svideo) {
 		au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
 				AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO);
 		au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
@@ -317,8 +313,7 @@ static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
 
 	setup_vbi(state, 0);
 
-	if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 ||
-	    input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) {
+	if (is_svideo) {
 		/* Despite what the table says, for the HVR-950q we still need
 		   to be in CVBS mode for the S-Video input (reason unknown). */
 		/* filter_coef_type = 3; */
@@ -360,7 +355,7 @@ static void au8522_setup_cvbs_mode(struct au8522_state *state, u8 input_mode)
 
 	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
 
-	setup_decoder_defaults(state, input_mode);
+	setup_decoder_defaults(state, false);
 
 	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
 			AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
@@ -386,7 +381,7 @@ static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state,
 	/* Set input mode to CVBS on channel 4 with SIF audio input enabled */
 	au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
 
-	setup_decoder_defaults(state, input_mode);
+	setup_decoder_defaults(state, false);
 
 	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
 			AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
@@ -407,7 +402,7 @@ static void au8522_setup_svideo_mode(struct au8522_state *state,
 	/* Enable clamping control */
 	au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
 
-	setup_decoder_defaults(state, input_mode);
+	setup_decoder_defaults(state, true);
 
 	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
 			AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/8] au8522: Fix demod analog mode setting
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
                   ` (3 preceding siblings ...)
  2014-06-08 16:54 ` [PATCH 4/8] au8522: cleanup s-video settings at setup_decoder_defaults() Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 6/8] au0828/au8522: Add PAL-M support Mauro Carvalho Chehab
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

There are several issues on the current code:
	1) msleep(1) is actually equivalent to msleep(10);
	2) au8522_video_set() will set reg 0xa4 to the
	   proper value for SIF, CVBS or S-Video. No need
	   to force it to CVBS;
	3) Let's not hardcode 0x9d for CBS on audio_set.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/dvb-frontends/au8522_decoder.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 569922232eb8..b971c20624bf 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -458,8 +458,9 @@ static void set_audio_input(struct au8522_state *state)
 	au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84);
 	msleep(150);
 	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x00);
-	msleep(1);
-	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x9d);
+	msleep(10);
+	au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
+			AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
 	msleep(50);
 	au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
 	au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
@@ -585,12 +586,9 @@ static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
 
 		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
 				0x01);
-		msleep(1);
-		au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
-				AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
+		msleep(10);
 
 		au8522_video_set(state);
-
 		set_audio_input(state);
 
 		state->operational_mode = AU8522_ANALOG_MODE;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/8] au0828/au8522: Add PAL-M support
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
                   ` (4 preceding siblings ...)
  2014-06-08 16:54 ` [PATCH 5/8] au8522: Fix demod analog mode setting Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 7/8] au0828: Only alt setting logic when needed Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 8/8] au0828: don't hardcode height/width Mauro Carvalho Chehab
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/dvb-frontends/au8522_decoder.c | 40 +++++++++++++++++++++++-----
 drivers/media/dvb-frontends/au8522_priv.h    |  1 +
 drivers/media/usb/au0828/au0828-video.c      | 10 ++++---
 3 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index b971c20624bf..33aa9410b624 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -248,12 +248,23 @@ static void setup_decoder_defaults(struct au8522_state *state, bool is_svideo)
 			AU8522_TVDEC_COMB_MODE_REG015H_CVBS);
 	au8522_writereg(state, AU8522_TVDED_DBG_MODE_REG060H,
 			AU8522_TVDED_DBG_MODE_REG060H_CVBS);
-	au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
-			AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525 |
-			AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492 |
-			AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_MN);
-	au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
-			AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC);
+
+	if (state->std == V4L2_STD_PAL_M) {
+		au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
+				AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525 |
+				AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492 |
+				AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_AUTO);
+		au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
+				AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_PAL_M);
+	} else {
+		/* NTSC */
+		au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
+				AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525 |
+				AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492 |
+				AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_MN);
+		au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
+				AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC);
+	}
 	au8522_writereg(state, AU8522_TVDEC_VCR_DET_LLIM_REG063H,
 			AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS);
 	au8522_writereg(state, AU8522_TVDEC_VCR_DET_HLIM_REG064H,
@@ -624,6 +635,21 @@ static int au8522_s_video_routing(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int au8522_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
+{
+	struct au8522_state *state = to_state(sd);
+
+	if ((std & (V4L2_STD_PAL_M | V4L2_STD_NTSC_M)) == 0)
+		return -EINVAL;
+
+	state->std = std;
+
+	if (state->operational_mode == AU8522_ANALOG_MODE)
+		au8522_video_set(state);
+
+	return 0;
+}
+
 static int au8522_s_audio_routing(struct v4l2_subdev *sd,
 					u32 input, u32 output, u32 config)
 {
@@ -681,6 +707,7 @@ static const struct v4l2_subdev_audio_ops au8522_audio_ops = {
 static const struct v4l2_subdev_video_ops au8522_video_ops = {
 	.s_routing = au8522_s_video_routing,
 	.s_stream = au8522_s_stream,
+	.s_std = au8522_s_std,
 };
 
 static const struct v4l2_subdev_ops au8522_ops = {
@@ -763,6 +790,7 @@ static int au8522_probe(struct i2c_client *client,
 	}
 
 	state->c = client;
+	state->std = V4L2_STD_NTSC_M;
 	state->vid_input = AU8522_COMPOSITE_CH1;
 	state->aud_input = AU8522_AUDIO_NONE;
 	state->id = 8522;
diff --git a/drivers/media/dvb-frontends/au8522_priv.h b/drivers/media/dvb-frontends/au8522_priv.h
index a781489520fb..b8aca1c84786 100644
--- a/drivers/media/dvb-frontends/au8522_priv.h
+++ b/drivers/media/dvb-frontends/au8522_priv.h
@@ -348,6 +348,7 @@ int au8522_led_ctrl(struct au8522_state *state, int led);
 /* Format control 2 */
 #define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_AUTODETECT	0x00
 #define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC		0x01
+#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_PAL_M		0x02
 
 
 #define AU8522_INPUT_CONTROL_REG081H_ATSC               	0xC4
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 9038194513c5..4aa1d7a1641b 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -1364,9 +1364,11 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
 
 	i2c_gate_ctrl(dev, 1);
 
-	/* FIXME: when we support something other than NTSC, we are going to
-	   have to make the au0828 bridge adjust the size of its capture
-	   buffer, which is currently hardcoded at 720x480 */
+	/*
+	 * FIXME: when we support something other than 60Hz standards,
+	 * we are going to have to make the au0828 bridge adjust the size
+	 * of its capture buffer, which is currently hardcoded at 720x480
+	 */
 
 	v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, norm);
 
@@ -1915,7 +1917,7 @@ static const struct video_device au0828_video_template = {
 	.fops                       = &au0828_v4l_fops,
 	.release                    = video_device_release,
 	.ioctl_ops 		    = &video_ioctl_ops,
-	.tvnorms                    = V4L2_STD_NTSC_M,
+	.tvnorms                    = V4L2_STD_NTSC_M | V4L2_STD_PAL_M,
 };
 
 /**************************************************************************/
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 7/8] au0828: Only alt setting logic when needed
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
                   ` (5 preceding siblings ...)
  2014-06-08 16:54 ` [PATCH 6/8] au0828/au8522: Add PAL-M support Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  2014-06-08 16:54 ` [PATCH 8/8] au0828: don't hardcode height/width Mauro Carvalho Chehab
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab, stable

It seems that there's a bug at au0828 hardware/firmware
related to alternate setting: when the device is already at
alt 5, a further call causes the URBs to receive -ESHUTDOWN.

I found two different encarnations of this issue:

1) at qv4l2, it fails the second time we try to open the
video screen;
2) at xawtv, when audio underrun occurs, with is very
frequent, at least on my test machine.

The fix is simple: just check if alt=5 before calling
set_usb_interface().

Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/usb/au0828/au0828-video.c | 34 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 4aa1d7a1641b..85d83ca5a4cd 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -787,11 +787,27 @@ static int au0828_i2s_init(struct au0828_dev *dev)
 
 /*
  * Auvitek au0828 analog stream enable
- * Please set interface0 to AS5 before enable the stream
  */
 static int au0828_analog_stream_enable(struct au0828_dev *d)
 {
+	struct usb_interface *iface;
+	int ret;
+
 	dprintk(1, "au0828_analog_stream_enable called\n");
+
+	iface = usb_ifnum_to_if(d->usbdev, 0);
+	if (iface && iface->cur_altsetting->desc.bAlternateSetting != 5) {
+		dprintk(1, "Changing intf#0 to alt 5\n");
+		/* set au0828 interface0 to AS5 here again */
+		ret = usb_set_interface(d->usbdev, 0, 5);
+		if (ret < 0) {
+			printk(KERN_INFO "Au0828 can't set alt setting to 5!\n");
+			return -EBUSY;
+		}
+	}
+
+	/* FIXME: size should be calculated using d->width, d->height */
+
 	au0828_writereg(d, AU0828_SENSORCTRL_VBI_103, 0x00);
 	au0828_writereg(d, 0x106, 0x00);
 	/* set x position */
@@ -1002,15 +1018,6 @@ static int au0828_v4l2_open(struct file *filp)
 		return -ERESTARTSYS;
 	}
 	if (dev->users == 0) {
-		/* set au0828 interface0 to AS5 here again */
-		ret = usb_set_interface(dev->usbdev, 0, 5);
-		if (ret < 0) {
-			mutex_unlock(&dev->lock);
-			printk(KERN_INFO "Au0828 can't set alternate to 5!\n");
-			kfree(fh);
-			return -EBUSY;
-		}
-
 		au0828_analog_stream_enable(dev);
 		au0828_analog_stream_reset(dev);
 
@@ -1252,13 +1259,6 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
 		}
 	}
 
-	/* set au0828 interface0 to AS5 here again */
-	ret = usb_set_interface(dev->usbdev, 0, 5);
-	if (ret < 0) {
-		printk(KERN_INFO "Au0828 can't set alt setting to 5!\n");
-		return -EBUSY;
-	}
-
 	au0828_analog_stream_enable(dev);
 
 	return 0;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 8/8] au0828: don't hardcode height/width
  2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
                   ` (6 preceding siblings ...)
  2014-06-08 16:54 ` [PATCH 7/8] au0828: Only alt setting logic when needed Mauro Carvalho Chehab
@ 2014-06-08 16:54 ` Mauro Carvalho Chehab
  7 siblings, 0 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2014-06-08 16:54 UTC (permalink / raw)
  Cc: Devin Heitmueller, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

While this device doesn't have a scaler (or have it disabled),
the screen dimentions are a function of the standard. Ok, right
now, only 480 lines standards are implemented, although it
supports other ones. Yet, let's calculate the size, to make
easier to add more standards latter.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/usb/au0828/au0828-video.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 85d83ca5a4cd..385894a1ff68 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -791,7 +791,7 @@ static int au0828_i2s_init(struct au0828_dev *dev)
 static int au0828_analog_stream_enable(struct au0828_dev *d)
 {
 	struct usb_interface *iface;
-	int ret;
+	int ret, h, w;
 
 	dprintk(1, "au0828_analog_stream_enable called\n");
 
@@ -806,20 +806,21 @@ static int au0828_analog_stream_enable(struct au0828_dev *d)
 		}
 	}
 
-	/* FIXME: size should be calculated using d->width, d->height */
+	h = d->height / 2 + 2;
+	w = d->width * 2;
 
 	au0828_writereg(d, AU0828_SENSORCTRL_VBI_103, 0x00);
 	au0828_writereg(d, 0x106, 0x00);
 	/* set x position */
 	au0828_writereg(d, 0x110, 0x00);
 	au0828_writereg(d, 0x111, 0x00);
-	au0828_writereg(d, 0x114, 0xa0);
-	au0828_writereg(d, 0x115, 0x05);
+	au0828_writereg(d, 0x114, w & 0xff);
+	au0828_writereg(d, 0x115, w >> 8);
 	/* set y position */
 	au0828_writereg(d, 0x112, 0x00);
 	au0828_writereg(d, 0x113, 0x00);
-	au0828_writereg(d, 0x116, 0xf2);
-	au0828_writereg(d, 0x117, 0x00);
+	au0828_writereg(d, 0x116, h & 0xff);
+	au0828_writereg(d, 0x117, h >> 8);
 	au0828_writereg(d, AU0828_SENSORCTRL_100, 0xb3);
 
 	return 0;
@@ -1725,6 +1726,7 @@ static int vidioc_streamoff(struct file *file, void *priv,
 		dev->vid_timeout_running = 0;
 		del_timer_sync(&dev->vid_timeout);
 
+		au0828_analog_stream_disable(dev);
 		v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
 		rc = au0828_stream_interrupt(dev);
 		if (rc != 0)
@@ -1930,7 +1932,8 @@ int au0828_analog_register(struct au0828_dev *dev,
 	struct usb_endpoint_descriptor *endpoint;
 	int i, ret;
 
-	dprintk(1, "au0828_analog_register called!\n");
+	dprintk(1, "au0828_analog_register called for intf#%d!\n",
+		interface->cur_altsetting->desc.bInterfaceNumber);
 
 	/* set au0828 usb interface0 to as5 */
 	retval = usb_set_interface(dev->usbdev,
@@ -1954,6 +1957,9 @@ int au0828_analog_register(struct au0828_dev *dev,
 			dev->max_pkt_size = (tmp & 0x07ff) *
 				(((tmp & 0x1800) >> 11) + 1);
 			dev->isoc_in_endpointaddr = endpoint->bEndpointAddress;
+			dprintk(1,
+				"Found isoc endpoint 0x%02x, max size = %d\n",
+				dev->isoc_in_endpointaddr, dev->max_pkt_size);
 		}
 	}
 	if (!(dev->isoc_in_endpointaddr)) {
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-06-09 17:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-08 16:54 [PATCH 0/8] au0828: fix analog streaming and add PAL-M support Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 1/8] au8522: move input_mode out one level Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 2/8] au8522: be sure that the setup will happen at streamon time Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 3/8] au8522: be sure that we'll setup audio routing at the right time Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 4/8] au8522: cleanup s-video settings at setup_decoder_defaults() Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 5/8] au8522: Fix demod analog mode setting Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 6/8] au0828/au8522: Add PAL-M support Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 7/8] au0828: Only alt setting logic when needed Mauro Carvalho Chehab
2014-06-08 16:54 ` [PATCH 8/8] au0828: don't hardcode height/width Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.