linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] Fix stream hangs with au0828
@ 2014-05-21 18:19 Mauro Carvalho Chehab
  2014-05-21 18:19 ` [PATCH 1/8] [media] au0828: Cancel stream-restart operation if frontend is disconnected Mauro Carvalho Chehab
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:19 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

There are several conditions that make au0828 stream to hang. Those
were independently detected by me, Reynaldo and Trevor.

Trevor kindly provided a code that make this error visible: running
it ~10-15 times on a loop makes the au0828 to stop sending stream.
Once it stops, not even removing/reinserting the driver is enough to
restore its behavior. The device needs to be physically removed, or
a reset command should be sent via I2C.

On my research, this seems to be due to some hardware bug, caused
by (at least) two factors:
	- TS should be stopped before setting the frontend;
	- xc5000 cannot suspend, if userspace is in a loop of
	  open/stream/close.

This patch series address both issues.

While here, it also fixes most checkpatch issues at xc5000.

Reynaldo/Trevor,

Please test, and send your tested-by, if this fixes the issue.

Thanks,
Mauro

Changbing Xiong (1):
  [media] au0828: Cancel stream-restart operation if frontend is
    disconnected

Mauro Carvalho Chehab (7):
  [media] au0828: Improve debug messages for urb_completion
  [media] Reset au0828 streaming when a new frequency is set
  xc5000: get rid of positive error codes
  xc5000: Don't wrap msleep()
  xc5000: fix CamelCase
  xc5000: Don't use whitespace before tabs
  xc5000: delay tuner sleep to 5 seconds

 drivers/media/tuners/xc5000.c         | 302 ++++++++++++++++++----------------
 drivers/media/usb/au0828/au0828-dvb.c |  57 ++++++-
 drivers/media/usb/au0828/au0828.h     |   2 +
 3 files changed, 210 insertions(+), 151 deletions(-)
 mode change 100644 => 100755 drivers/media/usb/au0828/au0828-dvb.c

-- 
1.9.0


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

* [PATCH 1/8] [media] au0828: Cancel stream-restart operation if frontend is disconnected
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
@ 2014-05-21 18:19 ` Mauro Carvalho Chehab
  2014-05-21 18:19 ` [PATCH 2/8] [media] au0828: Improve debug messages for urb_completion Mauro Carvalho Chehab
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:19 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Linux Media Mailing List,
	Mauro Carvalho Chehab, Mauro Carvalho Chehab

From: Changbing Xiong <cb.xiong@samsung.com>

X-Patchwork-Delegate: mchehab@redhat.com
If the tuner is already disconnected, It is meaningless to go on doing the
stream-restart operation, It is better to cancel this operation.

Signed-off-by: Changbing Xiong <cb.xiong@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/usb/au0828/au0828-dvb.c | 2 ++
 1 file changed, 2 insertions(+)
 mode change 100644 => 100755 drivers/media/usb/au0828/au0828-dvb.c

diff --git a/drivers/media/usb/au0828/au0828-dvb.c b/drivers/media/usb/au0828/au0828-dvb.c
old mode 100644
new mode 100755
index 4ae8b1074649..2019e4a168b2
--- a/drivers/media/usb/au0828/au0828-dvb.c
+++ b/drivers/media/usb/au0828/au0828-dvb.c
@@ -471,6 +471,8 @@ void au0828_dvb_unregister(struct au0828_dev *dev)
 	if (dvb->frontend == NULL)
 		return;
 
+	cancel_work_sync(&dev->restart_streaming);
+
 	dvb_net_release(&dvb->net);
 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
 	dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
-- 
1.9.0


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

* [PATCH 2/8] [media] au0828: Improve debug messages for urb_completion
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
  2014-05-21 18:19 ` [PATCH 1/8] [media] au0828: Cancel stream-restart operation if frontend is disconnected Mauro Carvalho Chehab
@ 2014-05-21 18:19 ` Mauro Carvalho Chehab
  2014-05-22  8:36   ` Ricardo Ribalda Delgado
  2014-05-21 18:19 ` [PATCH 3/8] [media] Reset au0828 streaming when a new frequency is set Mauro Carvalho Chehab
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:19 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

Sometimes, it helps to know how much data was received by
urb_completion. Add that information to the optional debug
log.

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

diff --git a/drivers/media/usb/au0828/au0828-dvb.c b/drivers/media/usb/au0828/au0828-dvb.c
index 2019e4a168b2..ab5f93643021 100755
--- a/drivers/media/usb/au0828/au0828-dvb.c
+++ b/drivers/media/usb/au0828/au0828-dvb.c
@@ -114,16 +114,20 @@ static void urb_completion(struct urb *purb)
 	int ptype = usb_pipetype(purb->pipe);
 	unsigned char *ptr;
 
-	dprintk(2, "%s()\n", __func__);
+	dprintk(2, "%s: %d\n", __func__, purb->actual_length);
 
-	if (!dev)
+	if (!dev) {
+		dprintk(2, "%s: no dev!\n", __func__);
 		return;
+	}
 
-	if (dev->urb_streaming == 0)
+	if (dev->urb_streaming == 0) {
+		dprintk(2, "%s: not streaming!\n", __func__);
 		return;
+	}
 
 	if (ptype != PIPE_BULK) {
-		printk(KERN_ERR "%s() Unsupported URB type %d\n",
+		printk(KERN_ERR "%s: Unsupported URB type %d\n",
 		       __func__, ptype);
 		return;
 	}
-- 
1.9.0


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

* [PATCH 3/8] [media] Reset au0828 streaming when a new frequency is set
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
  2014-05-21 18:19 ` [PATCH 1/8] [media] au0828: Cancel stream-restart operation if frontend is disconnected Mauro Carvalho Chehab
  2014-05-21 18:19 ` [PATCH 2/8] [media] au0828: Improve debug messages for urb_completion Mauro Carvalho Chehab
@ 2014-05-21 18:19 ` Mauro Carvalho Chehab
  2014-05-21 18:19 ` [PATCH 4/8] xc5000: get rid of positive error codes Mauro Carvalho Chehab
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:19 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

As reported by Trevor, doing several opening/streaming/closing
operations to the demux causes it to fail.

I was able to simulate this bug too. I also noticed that,
sometimes, changing channels with au0828, the same thing
happens.

Most of the issues seem to be due to some hardware bug, that
causes the device to not fill all the URBs allocated. When
the bug happens, the only known fix is to either replug the
device, or to send an USB reset to it.

There's also a hack a the au0828 driver that starts a thread
that tries to reset the device when a package doesn't start
with a sync.

One of the culpits for this bad hardware behavior seem to be
caused by the lack of stopping and restarting the stream every
time a new channel is set.

This patch warrants that the stream will be properly reset
every time the set_frontend callback is called, partially
solving the problem.

A complete fix, however, would also need to check the PM
conditions for the tuner and demux.

Reported-by: Trevor Graffa <tlgraffa@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/usb/au0828/au0828-dvb.c | 43 +++++++++++++++++++++++++++++++++--
 drivers/media/usb/au0828/au0828.h     |  2 ++
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-dvb.c b/drivers/media/usb/au0828/au0828-dvb.c
index ab5f93643021..d8b5d9480279 100755
--- a/drivers/media/usb/au0828/au0828-dvb.c
+++ b/drivers/media/usb/au0828/au0828-dvb.c
@@ -256,8 +256,6 @@ static void au0828_stop_transport(struct au0828_dev *dev, int full_stop)
 	au0828_write(dev, 0x60b, 0x00);
 }
 
-
-
 static int au0828_dvb_start_feed(struct dvb_demux_feed *feed)
 {
 	struct dvb_demux *demux = feed->demux;
@@ -300,6 +298,8 @@ static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed)
 	dprintk(1, "%s()\n", __func__);
 
 	if (dvb) {
+		cancel_work_sync(&dev->restart_streaming);
+
 		mutex_lock(&dvb->lock);
 		dvb->stop_count++;
 		dprintk(1, "%s(), start_count: %d, stop_count: %d\n", __func__,
@@ -342,6 +342,41 @@ static void au0828_restart_dvb_streaming(struct work_struct *work)
 	mutex_unlock(&dvb->lock);
 }
 
+static int au0828_set_frontend(struct dvb_frontend *fe)
+{
+	struct au0828_dev *dev = fe->dvb->priv;
+	struct au0828_dvb *dvb = &dev->dvb;
+	int ret, was_streaming;
+
+	mutex_lock(&dvb->lock);
+	was_streaming = dev->urb_streaming;
+	if (was_streaming) {
+		au0828_stop_transport(dev, 1);
+
+		/*
+		 * We can't hold a mutex here, as the restart_streaming
+		 * kthread may also hold it.
+		 */
+		mutex_unlock(&dvb->lock);
+		cancel_work_sync(&dev->restart_streaming);
+		mutex_lock(&dvb->lock);
+
+		stop_urb_transfer(dev);
+	}
+	mutex_unlock(&dvb->lock);
+
+	ret = dvb->set_frontend(fe);
+
+	if (was_streaming) {
+		mutex_lock(&dvb->lock);
+		au0828_start_transport(dev);
+		start_urb_transfer(dev);
+		mutex_unlock(&dvb->lock);
+	}
+
+	return ret;
+}
+
 static int dvb_register(struct au0828_dev *dev)
 {
 	struct au0828_dvb *dvb = &dev->dvb;
@@ -386,6 +421,10 @@ static int dvb_register(struct au0828_dev *dev)
 		goto fail_frontend;
 	}
 
+	/* Hook dvb frontend */
+	dvb->set_frontend = dvb->frontend->ops.set_frontend;
+	dvb->frontend->ops.set_frontend = au0828_set_frontend;
+
 	/* register demux stuff */
 	dvb->demux.dmx.capabilities =
 		DMX_TS_FILTERING | DMX_SECTION_FILTERING |
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index 5439772c1551..7112b9d956fa 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -104,6 +104,8 @@ struct au0828_dvb {
 	int feeding;
 	int start_count;
 	int stop_count;
+
+	int (*set_frontend)(struct dvb_frontend *fe);
 };
 
 enum au0828_stream_state {
-- 
1.9.0


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

* [PATCH 4/8] xc5000: get rid of positive error codes
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
                   ` (2 preceding siblings ...)
  2014-05-21 18:19 ` [PATCH 3/8] [media] Reset au0828 streaming when a new frequency is set Mauro Carvalho Chehab
@ 2014-05-21 18:19 ` Mauro Carvalho Chehab
  2014-05-21 18:19 ` [PATCH 5/8] xc5000: Don't wrap msleep() Mauro Carvalho Chehab
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:19 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

Errors should also be negative and should follow the Kernel
standards.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/tuners/xc5000.c | 104 +++++++++++++++++++-----------------------
 1 file changed, 48 insertions(+), 56 deletions(-)

diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index 5cd09a681b6a..94278cc5f3ef 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -75,13 +75,6 @@ struct xc5000_priv {
 #define XC_RF_MODE_AIR			0
 #define XC_RF_MODE_CABLE		1
 
-/* Result codes */
-#define XC_RESULT_SUCCESS		0
-#define XC_RESULT_RESET_FAILURE		1
-#define XC_RESULT_I2C_WRITE_FAILURE	2
-#define XC_RESULT_I2C_READ_FAILURE	3
-#define XC_RESULT_OUT_OF_RANGE		5
-
 /* Product id */
 #define XC_PRODUCT_ID_FW_NOT_LOADED	0x2000
 #define XC_PRODUCT_ID_FW_LOADED 	0x1388
@@ -258,9 +251,9 @@ static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
 
 	if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
 		printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n", len);
-		return XC_RESULT_I2C_WRITE_FAILURE;
+		return -EREMOTEIO;
 	}
-	return XC_RESULT_SUCCESS;
+	return 0;
 }
 
 #if 0
@@ -297,7 +290,7 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
 	}
 
 	*val = (bval[0] << 8) | bval[1];
-	return XC_RESULT_SUCCESS;
+	return 0;
 }
 
 static void xc_wait(int wait_ms)
@@ -320,13 +313,13 @@ static int xc5000_TunerReset(struct dvb_frontend *fe)
 					   XC5000_TUNER_RESET, 0);
 		if (ret) {
 			printk(KERN_ERR "xc5000: reset failed\n");
-			return XC_RESULT_RESET_FAILURE;
+			return ret;
 		}
 	} else {
 		printk(KERN_ERR "xc5000: no tuner reset callback function, fatal\n");
-		return XC_RESULT_RESET_FAILURE;
+		return -EINVAL;
 	}
-	return XC_RESULT_SUCCESS;
+	return 0;
 }
 
 static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
@@ -340,11 +333,11 @@ static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
 	buf[2] = (i2cData >> 8) & 0xFF;
 	buf[3] = i2cData & 0xFF;
 	result = xc_send_i2c_data(priv, buf, 4);
-	if (result == XC_RESULT_SUCCESS) {
+	if (result == 0) {
 		/* wait for busy flag to clear */
-		while ((WatchDogTimer > 0) && (result == XC_RESULT_SUCCESS)) {
+		while ((WatchDogTimer > 0) && (result == 0)) {
 			result = xc5000_readreg(priv, XREG_BUSY, (u16 *)buf);
-			if (result == XC_RESULT_SUCCESS) {
+			if (result == 0) {
 				if ((buf[0] == 0) && (buf[1] == 0)) {
 					/* busy flag cleared */
 					break;
@@ -356,7 +349,7 @@ static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
 		}
 	}
 	if (WatchDogTimer <= 0)
-		result = XC_RESULT_I2C_WRITE_FAILURE;
+		result = -EREMOTEIO;
 
 	return result;
 }
@@ -377,7 +370,7 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
 			/* RESET command */
 			result = xc5000_TunerReset(fe);
 			index += 2;
-			if (result != XC_RESULT_SUCCESS)
+			if (result != 0)
 				return result;
 		} else if (len & 0x8000) {
 			/* WAIT command */
@@ -404,7 +397,7 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
 				result = xc_send_i2c_data(priv, buf,
 					nbytes_to_send);
 
-				if (result != XC_RESULT_SUCCESS)
+				if (result != 0)
 					return result;
 
 				pos += nbytes_to_send - 2;
@@ -412,7 +405,7 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
 			index += len;
 		}
 	}
-	return XC_RESULT_SUCCESS;
+	return 0;
 }
 
 static int xc_initialize(struct xc5000_priv *priv)
@@ -437,7 +430,7 @@ static int xc_SetTVStandard(struct xc5000_priv *priv,
 	}
 
 	ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode);
-	if (ret == XC_RESULT_SUCCESS)
+	if (ret == 0)
 		ret = xc_write_reg(priv, XREG_AUDIO_MODE, AudioMode);
 
 	return ret;
@@ -467,7 +460,7 @@ static int xc_set_RF_frequency(struct xc5000_priv *priv, u32 freq_hz)
 
 	if ((freq_hz > xc5000_tuner_ops.info.frequency_max) ||
 		(freq_hz < xc5000_tuner_ops.info.frequency_min))
-		return XC_RESULT_OUT_OF_RANGE;
+		return -EINVAL;
 
 	freq_code = (u16)(freq_hz / 15625);
 
@@ -500,7 +493,7 @@ static int xc_get_frequency_error(struct xc5000_priv *priv, u32 *freq_error_hz)
 	u32 tmp;
 
 	result = xc5000_readreg(priv, XREG_FREQ_ERROR, &regData);
-	if (result != XC_RESULT_SUCCESS)
+	if (result != 0)
 		return result;
 
 	tmp = (u32)regData;
@@ -521,7 +514,7 @@ static int xc_get_version(struct xc5000_priv *priv,
 	int result;
 
 	result = xc5000_readreg(priv, XREG_VERSION, &data);
-	if (result != XC_RESULT_SUCCESS)
+	if (result != 0)
 		return result;
 
 	(*hw_majorversion) = (data >> 12) & 0x0F;
@@ -543,7 +536,7 @@ static int xc_get_hsync_freq(struct xc5000_priv *priv, u32 *hsync_freq_hz)
 	int result;
 
 	result = xc5000_readreg(priv, XREG_HSYNC_FREQ, &regData);
-	if (result != XC_RESULT_SUCCESS)
+	if (result != 0)
 		return result;
 
 	(*hsync_freq_hz) = ((regData & 0x0fff) * 763)/100;
@@ -593,7 +586,7 @@ static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
 
 	dprintk(1, "%s(%u)\n", __func__, freq_hz);
 
-	if (xc_set_RF_frequency(priv, freq_hz) != XC_RESULT_SUCCESS)
+	if (xc_set_RF_frequency(priv, freq_hz) != 0)
 		return 0;
 
 	if (mode == XC_TUNE_ANALOG) {
@@ -607,7 +600,7 @@ static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
 static int xc_set_xtal(struct dvb_frontend *fe)
 {
 	struct xc5000_priv *priv = fe->tuner_priv;
-	int ret = XC_RESULT_SUCCESS;
+	int ret = 0;
 
 	switch (priv->chip_id) {
 	default:
@@ -649,23 +642,22 @@ static int xc5000_fwupload(struct dvb_frontend *fe)
 		priv->i2c_props.adap->dev.parent);
 	if (ret) {
 		printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n");
-		ret = XC_RESULT_RESET_FAILURE;
 		goto out;
 	} else {
 		printk(KERN_DEBUG "xc5000: firmware read %Zu bytes.\n",
 		       fw->size);
-		ret = XC_RESULT_SUCCESS;
+		ret = 0;
 	}
 
 	if (fw->size != desired_fw->size) {
 		printk(KERN_ERR "xc5000: firmware incorrect size\n");
-		ret = XC_RESULT_RESET_FAILURE;
+		ret = -EINVAL;
 	} else {
 		printk(KERN_INFO "xc5000: firmware uploading...\n");
 		ret = xc_load_i2c_sequence(fe,  fw->data);
-		if (XC_RESULT_SUCCESS == ret)
+		if (0 == ret)
 			ret = xc_set_xtal(fe);
-		if (XC_RESULT_SUCCESS == ret)
+		if (0 == ret)
 			printk(KERN_INFO "xc5000: firmware upload complete...\n");
 		else
 			printk(KERN_ERR "xc5000: firmware upload failed...\n");
@@ -744,7 +736,7 @@ static int xc5000_set_params(struct dvb_frontend *fe)
 	u32 freq = fe->dtv_property_cache.frequency;
 	u32 delsys  = fe->dtv_property_cache.delivery_system;
 
-	if (xc_load_fw_and_init_tuner(fe, 0) != XC_RESULT_SUCCESS) {
+	if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
 		dprintk(1, "Unable to load firmware and init tuner\n");
 		return -EINVAL;
 	}
@@ -821,7 +813,7 @@ static int xc5000_set_params(struct dvb_frontend *fe)
 		__func__, freq, priv->freq_hz);
 
 	ret = xc_SetSignalSource(priv, priv->rf_mode);
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR
 			"xc5000: xc_SetSignalSource(%d) failed\n",
 			priv->rf_mode);
@@ -831,13 +823,13 @@ static int xc5000_set_params(struct dvb_frontend *fe)
 	ret = xc_SetTVStandard(priv,
 		XC5000_Standard[priv->video_standard].VideoMode,
 		XC5000_Standard[priv->video_standard].AudioMode, 0);
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
 		return -EREMOTEIO;
 	}
 
 	ret = xc_set_IF_frequency(priv, priv->if_khz);
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",
 		       priv->if_khz);
 		return -EIO;
@@ -862,15 +854,15 @@ static int xc5000_is_firmware_loaded(struct dvb_frontend *fe)
 	u16 id;
 
 	ret = xc5000_readreg(priv, XREG_PRODUCT_ID, &id);
-	if (ret == XC_RESULT_SUCCESS) {
+	if (ret == 0) {
 		if (id == XC_PRODUCT_ID_FW_NOT_LOADED)
-			ret = XC_RESULT_RESET_FAILURE;
+			ret = -ENOENT;
 		else
-			ret = XC_RESULT_SUCCESS;
+			ret = 0;
 	}
 
 	dprintk(1, "%s() returns %s id = 0x%x\n", __func__,
-		ret == XC_RESULT_SUCCESS ? "True" : "False", id);
+		ret == 0 ? "True" : "False", id);
 	return ret;
 }
 
@@ -937,7 +929,7 @@ static int xc5000_set_tv_freq(struct dvb_frontend *fe,
 
 tune_channel:
 	ret = xc_SetSignalSource(priv, priv->rf_mode);
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR
 			"xc5000: xc_SetSignalSource(%d) failed\n",
 			priv->rf_mode);
@@ -947,7 +939,7 @@ tune_channel:
 	ret = xc_SetTVStandard(priv,
 		XC5000_Standard[priv->video_standard].VideoMode,
 		XC5000_Standard[priv->video_standard].AudioMode, 0);
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
 		return -EREMOTEIO;
 	}
@@ -966,7 +958,7 @@ tune_channel:
 			/* PLL is unlocked, force reload of the firmware */
 			dprintk(1, "xc5000: PLL not locked (0x%x).  Reloading...\n",
 				pll_lock_status);
-			if (xc_load_fw_and_init_tuner(fe, 1) != XC_RESULT_SUCCESS) {
+			if (xc_load_fw_and_init_tuner(fe, 1) != 0) {
 				printk(KERN_ERR "xc5000: Unable to reload fw\n");
 				return -EREMOTEIO;
 			}
@@ -1011,13 +1003,13 @@ static int xc5000_set_radio_freq(struct dvb_frontend *fe,
 	ret = xc_SetTVStandard(priv, XC5000_Standard[radio_input].VideoMode,
 			       XC5000_Standard[radio_input].AudioMode, radio_input);
 
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
 		return -EREMOTEIO;
 	}
 
 	ret = xc_SetSignalSource(priv, priv->rf_mode);
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR
 			"xc5000: xc_SetSignalSource(%d) failed\n",
 			priv->rf_mode);
@@ -1044,7 +1036,7 @@ static int xc5000_set_analog_params(struct dvb_frontend *fe,
 	if (priv->i2c_props.adap == NULL)
 		return -EINVAL;
 
-	if (xc_load_fw_and_init_tuner(fe, 0) != XC_RESULT_SUCCESS) {
+	if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
 		dprintk(1, "Unable to load firmware and init tuner\n");
 		return -EINVAL;
 	}
@@ -1105,23 +1097,23 @@ static int xc5000_get_status(struct dvb_frontend *fe, u32 *status)
 static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)
 {
 	struct xc5000_priv *priv = fe->tuner_priv;
-	int ret = XC_RESULT_SUCCESS;
+	int ret = 0;
 	u16 pll_lock_status;
 	u16 fw_ck;
 
-	if (force || xc5000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS) {
+	if (force || xc5000_is_firmware_loaded(fe) != 0) {
 
 fw_retry:
 
 		ret = xc5000_fwupload(fe);
-		if (ret != XC_RESULT_SUCCESS)
+		if (ret != 0)
 			return ret;
 
 		msleep(20);
 
 		if (priv->fw_checksum_supported) {
 			if (xc5000_readreg(priv, XREG_FW_CHECKSUM, &fw_ck)
-			    != XC_RESULT_SUCCESS) {
+			    != 0) {
 				dprintk(1, "%s() FW checksum reading failed.\n",
 					__func__);
 				goto fw_retry;
@@ -1137,7 +1129,7 @@ fw_retry:
 		/* Start the tuner self-calibration process */
 		ret |= xc_initialize(priv);
 
-		if (ret != XC_RESULT_SUCCESS)
+		if (ret != 0)
 			goto fw_retry;
 
 		/* Wait for calibration to complete.
@@ -1148,7 +1140,7 @@ fw_retry:
 		xc_wait(100);
 
 		if (priv->init_status_supported) {
-			if (xc5000_readreg(priv, XREG_INIT_STATUS, &fw_ck) != XC_RESULT_SUCCESS) {
+			if (xc5000_readreg(priv, XREG_INIT_STATUS, &fw_ck) != 0) {
 				dprintk(1, "%s() FW failed reading init status.\n",
 					__func__);
 				goto fw_retry;
@@ -1191,13 +1183,13 @@ static int xc5000_sleep(struct dvb_frontend *fe)
 	   was removed in newer versions of the firmware.  The "supported"
 	   way to sleep the tuner is to pull the reset pin low for 10ms */
 	ret = xc5000_TunerReset(fe);
-	if (ret != XC_RESULT_SUCCESS) {
+	if (ret != 0) {
 		printk(KERN_ERR
 			"xc5000: %s() unable to shutdown tuner\n",
 			__func__);
 		return -EREMOTEIO;
 	} else
-		return XC_RESULT_SUCCESS;
+		return 0;
 }
 
 static int xc5000_init(struct dvb_frontend *fe)
@@ -1205,7 +1197,7 @@ static int xc5000_init(struct dvb_frontend *fe)
 	struct xc5000_priv *priv = fe->tuner_priv;
 	dprintk(1, "%s()\n", __func__);
 
-	if (xc_load_fw_and_init_tuner(fe, 0) != XC_RESULT_SUCCESS) {
+	if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
 		printk(KERN_ERR "xc5000: Unable to initialise tuner\n");
 		return -EREMOTEIO;
 	}
@@ -1327,7 +1319,7 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
 	/* Check if firmware has been loaded. It is possible that another
 	   instance of the driver has loaded the firmware.
 	 */
-	if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != XC_RESULT_SUCCESS)
+	if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
 		goto fail;
 
 	switch (id) {
-- 
1.9.0


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

* [PATCH 5/8] xc5000: Don't wrap msleep()
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
                   ` (3 preceding siblings ...)
  2014-05-21 18:19 ` [PATCH 4/8] xc5000: get rid of positive error codes Mauro Carvalho Chehab
@ 2014-05-21 18:19 ` Mauro Carvalho Chehab
  2014-05-21 18:20 ` [PATCH 6/8] xc5000: fix CamelCase Mauro Carvalho Chehab
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:19 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

There's absolutely no reason to wrap msleep() call here.
Just rename all occurences of xc_wait() with msleep() and
remove the wrapper function.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/tuners/xc5000.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index 94278cc5f3ef..a5dff9714836 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -293,11 +293,6 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
 	return 0;
 }
 
-static void xc_wait(int wait_ms)
-{
-	msleep(wait_ms);
-}
-
 static int xc5000_TunerReset(struct dvb_frontend *fe)
 {
 	struct xc5000_priv *priv = fe->tuner_priv;
@@ -342,7 +337,7 @@ static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
 					/* busy flag cleared */
 					break;
 				} else {
-					xc_wait(5); /* wait 5 ms */
+					msleep(5); /* wait 5 ms */
 					WatchDogTimer--;
 				}
 			}
@@ -374,7 +369,7 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
 				return result;
 		} else if (len & 0x8000) {
 			/* WAIT command */
-			xc_wait(len & 0x7FFF);
+			msleep(len & 0x7FFF);
 			index += 2;
 		} else {
 			/* Send i2c data whilst ensuring individual transactions
@@ -571,7 +566,7 @@ static u16 WaitForLock(struct xc5000_priv *priv)
 	while ((lockState == 0) && (watchDogCount > 0)) {
 		xc_get_lock_status(priv, &lockState);
 		if (lockState != 1) {
-			xc_wait(5);
+			msleep(5);
 			watchDogCount--;
 		}
 	}
@@ -687,7 +682,7 @@ static void xc_debug_dump(struct xc5000_priv *priv)
 	 * Frame Lines needs two frame times after initial lock
 	 * before it is valid.
 	 */
-	xc_wait(100);
+	msleep(100);
 
 	xc_get_ADC_Envelope(priv,  &adc_envelope);
 	dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
@@ -1137,7 +1132,7 @@ fw_retry:
 		 * I2C transactions until calibration is complete.  This way we
 		 * don't have to rely on clock stretching working.
 		 */
-		xc_wait(100);
+		msleep(100);
 
 		if (priv->init_status_supported) {
 			if (xc5000_readreg(priv, XREG_INIT_STATUS, &fw_ck) != 0) {
-- 
1.9.0


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

* [PATCH 6/8] xc5000: fix CamelCase
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
                   ` (4 preceding siblings ...)
  2014-05-21 18:19 ` [PATCH 5/8] xc5000: Don't wrap msleep() Mauro Carvalho Chehab
@ 2014-05-21 18:20 ` Mauro Carvalho Chehab
  2014-05-21 18:20 ` [PATCH 7/8] xc5000: Don't use whitespace before tabs Mauro Carvalho Chehab
  2014-05-21 18:20 ` [PATCH 8/8] xc5000: delay tuner sleep to 5 seconds Mauro Carvalho Chehab
  7 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:20 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

There are several CamelCase non-codingstyle compliances here.

Fix them.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/tuners/xc5000.c | 138 +++++++++++++++++++++---------------------
 1 file changed, 69 insertions(+), 69 deletions(-)

diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index a5dff9714836..da4c29ed48bd 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -145,16 +145,16 @@ struct xc5000_priv {
 
 */
 struct XC_TV_STANDARD {
-	char *Name;
-	u16 AudioMode;
-	u16 VideoMode;
+	char *name;
+	u16 audio_mode;
+	u16 video_mode;
 };
 
 /* Tuner standards */
 #define MN_NTSC_PAL_BTSC	0
 #define MN_NTSC_PAL_A2		1
 #define MN_NTSC_PAL_EIAJ	2
-#define MN_NTSC_PAL_Mono	3
+#define MN_NTSC_PAL_MONO	3
 #define BG_PAL_A2		4
 #define BG_PAL_NICAM		5
 #define BG_PAL_MONO		6
@@ -172,11 +172,11 @@ struct XC_TV_STANDARD {
 #define DTV8			18
 #define DTV7_8			19
 #define DTV7			20
-#define FM_Radio_INPUT2 	21
-#define FM_Radio_INPUT1 	22
-#define FM_Radio_INPUT1_MONO	23
+#define FM_RADIO_INPUT2 	21
+#define FM_RADIO_INPUT1 	22
+#define FM_RADIO_INPUT1_MONO	23
 
-static struct XC_TV_STANDARD XC5000_Standard[MAX_TV_STANDARD] = {
+static struct XC_TV_STANDARD xc5000_standard[MAX_TV_STANDARD] = {
 	{"M/N-NTSC/PAL-BTSC", 0x0400, 0x8020},
 	{"M/N-NTSC/PAL-A2",   0x0600, 0x8020},
 	{"M/N-NTSC/PAL-EIAJ", 0x0440, 0x8020},
@@ -242,7 +242,7 @@ static inline const struct xc5000_fw_cfg *xc5000_assign_firmware(int chip_id)
 static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force);
 static int xc5000_is_firmware_loaded(struct dvb_frontend *fe);
 static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val);
-static int xc5000_TunerReset(struct dvb_frontend *fe);
+static int xc5000_tuner_reset(struct dvb_frontend *fe);
 
 static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
 {
@@ -293,7 +293,7 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
 	return 0;
 }
 
-static int xc5000_TunerReset(struct dvb_frontend *fe)
+static int xc5000_tuner_reset(struct dvb_frontend *fe)
 {
 	struct xc5000_priv *priv = fe->tuner_priv;
 	int ret;
@@ -317,20 +317,20 @@ static int xc5000_TunerReset(struct dvb_frontend *fe)
 	return 0;
 }
 
-static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
+static int xc_write_reg(struct xc5000_priv *priv, u16 reg_addr, u16 i2c_data)
 {
 	u8 buf[4];
-	int WatchDogTimer = 100;
+	int watch_dog_timer = 100;
 	int result;
 
-	buf[0] = (regAddr >> 8) & 0xFF;
-	buf[1] = regAddr & 0xFF;
-	buf[2] = (i2cData >> 8) & 0xFF;
-	buf[3] = i2cData & 0xFF;
+	buf[0] = (reg_addr >> 8) & 0xFF;
+	buf[1] = reg_addr & 0xFF;
+	buf[2] = (i2c_data >> 8) & 0xFF;
+	buf[3] = i2c_data & 0xFF;
 	result = xc_send_i2c_data(priv, buf, 4);
 	if (result == 0) {
 		/* wait for busy flag to clear */
-		while ((WatchDogTimer > 0) && (result == 0)) {
+		while ((watch_dog_timer > 0) && (result == 0)) {
 			result = xc5000_readreg(priv, XREG_BUSY, (u16 *)buf);
 			if (result == 0) {
 				if ((buf[0] == 0) && (buf[1] == 0)) {
@@ -338,12 +338,12 @@ static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
 					break;
 				} else {
 					msleep(5); /* wait 5 ms */
-					WatchDogTimer--;
+					watch_dog_timer--;
 				}
 			}
 		}
 	}
-	if (WatchDogTimer <= 0)
+	if (watch_dog_timer <= 0)
 		result = -EREMOTEIO;
 
 	return result;
@@ -363,7 +363,7 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
 		len = i2c_sequence[index] * 256 + i2c_sequence[index+1];
 		if (len == 0x0000) {
 			/* RESET command */
-			result = xc5000_TunerReset(fe);
+			result = xc5000_tuner_reset(fe);
 			index += 2;
 			if (result != 0)
 				return result;
@@ -409,29 +409,29 @@ static int xc_initialize(struct xc5000_priv *priv)
 	return xc_write_reg(priv, XREG_INIT, 0);
 }
 
-static int xc_SetTVStandard(struct xc5000_priv *priv,
-	u16 VideoMode, u16 AudioMode, u8 RadioMode)
+static int xc_set_tv_standard(struct xc5000_priv *priv,
+	u16 video_mode, u16 audio_mode, u8 radio_mode)
 {
 	int ret;
-	dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, VideoMode, AudioMode);
-	if (RadioMode) {
+	dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, video_mode, audio_mode);
+	if (radio_mode) {
 		dprintk(1, "%s() Standard = %s\n",
 			__func__,
-			XC5000_Standard[RadioMode].Name);
+			xc5000_standard[radio_mode].name);
 	} else {
 		dprintk(1, "%s() Standard = %s\n",
 			__func__,
-			XC5000_Standard[priv->video_standard].Name);
+			xc5000_standard[priv->video_standard].name);
 	}
 
-	ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode);
+	ret = xc_write_reg(priv, XREG_VIDEO_MODE, video_mode);
 	if (ret == 0)
-		ret = xc_write_reg(priv, XREG_AUDIO_MODE, AudioMode);
+		ret = xc_write_reg(priv, XREG_AUDIO_MODE, audio_mode);
 
 	return ret;
 }
 
-static int xc_SetSignalSource(struct xc5000_priv *priv, u16 rf_mode)
+static int xc_set_signal_source(struct xc5000_priv *priv, u16 rf_mode)
 {
 	dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode,
 		rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
@@ -447,7 +447,7 @@ static int xc_SetSignalSource(struct xc5000_priv *priv, u16 rf_mode)
 
 static const struct dvb_tuner_ops xc5000_tuner_ops;
 
-static int xc_set_RF_frequency(struct xc5000_priv *priv, u32 freq_hz)
+static int xc_set_rf_frequency(struct xc5000_priv *priv, u32 freq_hz)
 {
 	u16 freq_code;
 
@@ -476,7 +476,7 @@ static int xc_set_IF_frequency(struct xc5000_priv *priv, u32 freq_khz)
 }
 
 
-static int xc_get_ADC_Envelope(struct xc5000_priv *priv, u16 *adc_envelope)
+static int xc_get_adc_envelope(struct xc5000_priv *priv, u16 *adc_envelope)
 {
 	return xc5000_readreg(priv, XREG_ADC_ENV, adc_envelope);
 }
@@ -484,14 +484,14 @@ static int xc_get_ADC_Envelope(struct xc5000_priv *priv, u16 *adc_envelope)
 static int xc_get_frequency_error(struct xc5000_priv *priv, u32 *freq_error_hz)
 {
 	int result;
-	u16 regData;
+	u16 reg_data;
 	u32 tmp;
 
-	result = xc5000_readreg(priv, XREG_FREQ_ERROR, &regData);
+	result = xc5000_readreg(priv, XREG_FREQ_ERROR, &reg_data);
 	if (result != 0)
 		return result;
 
-	tmp = (u32)regData;
+	tmp = (u32)reg_data;
 	(*freq_error_hz) = (tmp * 15625) / 1000;
 	return result;
 }
@@ -527,14 +527,14 @@ static int xc_get_buildversion(struct xc5000_priv *priv, u16 *buildrev)
 
 static int xc_get_hsync_freq(struct xc5000_priv *priv, u32 *hsync_freq_hz)
 {
-	u16 regData;
+	u16 reg_data;
 	int result;
 
-	result = xc5000_readreg(priv, XREG_HSYNC_FREQ, &regData);
+	result = xc5000_readreg(priv, XREG_HSYNC_FREQ, &reg_data);
 	if (result != 0)
 		return result;
 
-	(*hsync_freq_hz) = ((regData & 0x0fff) * 763)/100;
+	(*hsync_freq_hz) = ((reg_data & 0x0fff) * 763)/100;
 	return result;
 }
 
@@ -558,19 +558,19 @@ static int xc_get_totalgain(struct xc5000_priv *priv, u16 *totalgain)
 	return xc5000_readreg(priv, XREG_TOTALGAIN, totalgain);
 }
 
-static u16 WaitForLock(struct xc5000_priv *priv)
+static u16 wait_for_lock(struct xc5000_priv *priv)
 {
-	u16 lockState = 0;
-	int watchDogCount = 40;
+	u16 lock_state = 0;
+	int watch_dog_count = 40;
 
-	while ((lockState == 0) && (watchDogCount > 0)) {
-		xc_get_lock_status(priv, &lockState);
-		if (lockState != 1) {
+	while ((lock_state == 0) && (watch_dog_count > 0)) {
+		xc_get_lock_status(priv, &lock_state);
+		if (lock_state != 1) {
 			msleep(5);
-			watchDogCount--;
+			watch_dog_count--;
 		}
 	}
-	return lockState;
+	return lock_state;
 }
 
 #define XC_TUNE_ANALOG  0
@@ -581,11 +581,11 @@ static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
 
 	dprintk(1, "%s(%u)\n", __func__, freq_hz);
 
-	if (xc_set_RF_frequency(priv, freq_hz) != 0)
+	if (xc_set_rf_frequency(priv, freq_hz) != 0)
 		return 0;
 
 	if (mode == XC_TUNE_ANALOG) {
-		if (WaitForLock(priv) == 1)
+		if (wait_for_lock(priv) == 1)
 			found = 1;
 	}
 
@@ -684,7 +684,7 @@ static void xc_debug_dump(struct xc5000_priv *priv)
 	 */
 	msleep(100);
 
-	xc_get_ADC_Envelope(priv,  &adc_envelope);
+	xc_get_adc_envelope(priv,  &adc_envelope);
 	dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
 
 	xc_get_frequency_error(priv, &freq_error_hz);
@@ -807,19 +807,19 @@ static int xc5000_set_params(struct dvb_frontend *fe)
 	dprintk(1, "%s() frequency=%d (compensated to %d)\n",
 		__func__, freq, priv->freq_hz);
 
-	ret = xc_SetSignalSource(priv, priv->rf_mode);
+	ret = xc_set_signal_source(priv, priv->rf_mode);
 	if (ret != 0) {
 		printk(KERN_ERR
-			"xc5000: xc_SetSignalSource(%d) failed\n",
+			"xc5000: xc_set_signal_source(%d) failed\n",
 			priv->rf_mode);
 		return -EREMOTEIO;
 	}
 
-	ret = xc_SetTVStandard(priv,
-		XC5000_Standard[priv->video_standard].VideoMode,
-		XC5000_Standard[priv->video_standard].AudioMode, 0);
+	ret = xc_set_tv_standard(priv,
+		xc5000_standard[priv->video_standard].video_mode,
+		xc5000_standard[priv->video_standard].audio_mode, 0);
 	if (ret != 0) {
-		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
+		printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
 		return -EREMOTEIO;
 	}
 
@@ -923,19 +923,19 @@ static int xc5000_set_tv_freq(struct dvb_frontend *fe,
 	}
 
 tune_channel:
-	ret = xc_SetSignalSource(priv, priv->rf_mode);
+	ret = xc_set_signal_source(priv, priv->rf_mode);
 	if (ret != 0) {
 		printk(KERN_ERR
-			"xc5000: xc_SetSignalSource(%d) failed\n",
+			"xc5000: xc_set_signal_source(%d) failed\n",
 			priv->rf_mode);
 		return -EREMOTEIO;
 	}
 
-	ret = xc_SetTVStandard(priv,
-		XC5000_Standard[priv->video_standard].VideoMode,
-		XC5000_Standard[priv->video_standard].AudioMode, 0);
+	ret = xc_set_tv_standard(priv,
+		xc5000_standard[priv->video_standard].video_mode,
+		xc5000_standard[priv->video_standard].audio_mode, 0);
 	if (ret != 0) {
-		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
+		printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
 		return -EREMOTEIO;
 	}
 
@@ -980,11 +980,11 @@ static int xc5000_set_radio_freq(struct dvb_frontend *fe,
 	}
 
 	if (priv->radio_input == XC5000_RADIO_FM1)
-		radio_input = FM_Radio_INPUT1;
+		radio_input = FM_RADIO_INPUT1;
 	else if  (priv->radio_input == XC5000_RADIO_FM2)
-		radio_input = FM_Radio_INPUT2;
+		radio_input = FM_RADIO_INPUT2;
 	else if  (priv->radio_input == XC5000_RADIO_FM1_MONO)
-		radio_input = FM_Radio_INPUT1_MONO;
+		radio_input = FM_RADIO_INPUT1_MONO;
 	else {
 		dprintk(1, "%s() unknown radio input %d\n", __func__,
 			priv->radio_input);
@@ -995,18 +995,18 @@ static int xc5000_set_radio_freq(struct dvb_frontend *fe,
 
 	priv->rf_mode = XC_RF_MODE_AIR;
 
-	ret = xc_SetTVStandard(priv, XC5000_Standard[radio_input].VideoMode,
-			       XC5000_Standard[radio_input].AudioMode, radio_input);
+	ret = xc_set_tv_standard(priv, xc5000_standard[radio_input].video_mode,
+			       xc5000_standard[radio_input].audio_mode, radio_input);
 
 	if (ret != 0) {
-		printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
+		printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
 		return -EREMOTEIO;
 	}
 
-	ret = xc_SetSignalSource(priv, priv->rf_mode);
+	ret = xc_set_signal_source(priv, priv->rf_mode);
 	if (ret != 0) {
 		printk(KERN_ERR
-			"xc5000: xc_SetSignalSource(%d) failed\n",
+			"xc5000: xc_set_signal_source(%d) failed\n",
 			priv->rf_mode);
 		return -EREMOTEIO;
 	}
@@ -1177,7 +1177,7 @@ static int xc5000_sleep(struct dvb_frontend *fe)
 	/* According to Xceive technical support, the "powerdown" register
 	   was removed in newer versions of the firmware.  The "supported"
 	   way to sleep the tuner is to pull the reset pin low for 10ms */
-	ret = xc5000_TunerReset(fe);
+	ret = xc5000_tuner_reset(fe);
 	if (ret != 0) {
 		printk(KERN_ERR
 			"xc5000: %s() unable to shutdown tuner\n",
-- 
1.9.0


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

* [PATCH 7/8] xc5000: Don't use whitespace before tabs
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
                   ` (5 preceding siblings ...)
  2014-05-21 18:20 ` [PATCH 6/8] xc5000: fix CamelCase Mauro Carvalho Chehab
@ 2014-05-21 18:20 ` Mauro Carvalho Chehab
  2014-05-21 18:20 ` [PATCH 8/8] xc5000: delay tuner sleep to 5 seconds Mauro Carvalho Chehab
  7 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:20 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

WARNING: please, no space before tabs
+#define XC_PRODUCT_ID_FW_LOADED ^I0x1388$

WARNING: please, no space before tabs
+#define DK_SECAM_A2LDK3 ^I13$

WARNING: please, no space before tabs
+#define DK_SECAM_A2MONO ^I14$

WARNING: please, no space before tabs
+#define FM_RADIO_INPUT2 ^I21$

WARNING: please, no space before tabs
+#define FM_RADIO_INPUT1 ^I22$

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/tuners/xc5000.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index da4c29ed48bd..8df92619883f 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -77,7 +77,7 @@ struct xc5000_priv {
 
 /* Product id */
 #define XC_PRODUCT_ID_FW_NOT_LOADED	0x2000
-#define XC_PRODUCT_ID_FW_LOADED 	0x1388
+#define XC_PRODUCT_ID_FW_LOADED	0x1388
 
 /* Registers */
 #define XREG_INIT         0x00
@@ -164,16 +164,16 @@ struct XC_TV_STANDARD {
 #define DK_PAL_NICAM		10
 #define DK_PAL_MONO		11
 #define DK_SECAM_A2DK1		12
-#define DK_SECAM_A2LDK3 	13
-#define DK_SECAM_A2MONO 	14
+#define DK_SECAM_A2LDK3		13
+#define DK_SECAM_A2MONO		14
 #define L_SECAM_NICAM		15
 #define LC_SECAM_NICAM		16
 #define DTV6			17
 #define DTV8			18
 #define DTV7_8			19
 #define DTV7			20
-#define FM_RADIO_INPUT2 	21
-#define FM_RADIO_INPUT1 	22
+#define FM_RADIO_INPUT2		21
+#define FM_RADIO_INPUT1		22
 #define FM_RADIO_INPUT1_MONO	23
 
 static struct XC_TV_STANDARD xc5000_standard[MAX_TV_STANDARD] = {
-- 
1.9.0


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

* [PATCH 8/8] xc5000: delay tuner sleep to 5 seconds
  2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
                   ` (6 preceding siblings ...)
  2014-05-21 18:20 ` [PATCH 7/8] xc5000: Don't use whitespace before tabs Mauro Carvalho Chehab
@ 2014-05-21 18:20 ` Mauro Carvalho Chehab
  7 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-21 18:20 UTC (permalink / raw)
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Mauro Carvalho Chehab,
	Linux Media Mailing List, Mauro Carvalho Chehab

Some drivers, like au0828 are very sensitive to tuner sleep and may
break if the sleep happens too fast. Also, by keeping the tuner alive
for a while could speedup tuning process during channel scan. So,
change the logic to delay the actual sleep to 5 seconds after its
command.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/tuners/xc5000.c | 43 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index 8df92619883f..2b3d514be672 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -25,6 +25,7 @@
 #include <linux/moduleparam.h>
 #include <linux/videodev2.h>
 #include <linux/delay.h>
+#include <linux/workqueue.h>
 #include <linux/dvb/frontend.h>
 #include <linux/i2c.h>
 
@@ -65,12 +66,18 @@ struct xc5000_priv {
 	u16 pll_register_no;
 	u8 init_status_supported;
 	u8 fw_checksum_supported;
+
+	struct dvb_frontend *fe;
+	struct delayed_work timer_sleep;
 };
 
 /* Misc Defines */
 #define MAX_TV_STANDARD			24
 #define XC_MAX_I2C_WRITE_LENGTH		64
 
+/* Time to suspend after the .sleep callback is called */
+#define XC5000_SLEEP_TIME		5000 /* ms */
+
 /* Signal Types */
 #define XC_RF_MODE_AIR			0
 #define XC_RF_MODE_CABLE		1
@@ -1096,6 +1103,8 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)
 	u16 pll_lock_status;
 	u16 fw_ck;
 
+	cancel_delayed_work(&priv->timer_sleep);
+
 	if (force || xc5000_is_firmware_loaded(fe) != 0) {
 
 fw_retry:
@@ -1164,27 +1173,39 @@ fw_retry:
 	return ret;
 }
 
-static int xc5000_sleep(struct dvb_frontend *fe)
+static void xc5000_do_timer_sleep(struct work_struct *timer_sleep)
 {
+	struct xc5000_priv *priv =container_of(timer_sleep, struct xc5000_priv,
+					       timer_sleep.work);
+	struct dvb_frontend *fe = priv->fe;
 	int ret;
 
 	dprintk(1, "%s()\n", __func__);
 
-	/* Avoid firmware reload on slow devices */
-	if (no_poweroff)
-		return 0;
-
 	/* According to Xceive technical support, the "powerdown" register
 	   was removed in newer versions of the firmware.  The "supported"
 	   way to sleep the tuner is to pull the reset pin low for 10ms */
 	ret = xc5000_tuner_reset(fe);
-	if (ret != 0) {
+	if (ret != 0)
 		printk(KERN_ERR
 			"xc5000: %s() unable to shutdown tuner\n",
 			__func__);
-		return -EREMOTEIO;
-	} else
+}
+
+static int xc5000_sleep(struct dvb_frontend *fe)
+{
+	struct xc5000_priv *priv = fe->tuner_priv;
+
+	dprintk(1, "%s()\n", __func__);
+
+	/* Avoid firmware reload on slow devices */
+	if (no_poweroff)
 		return 0;
+
+	schedule_delayed_work(&priv->timer_sleep,
+			      msecs_to_jiffies(XC5000_SLEEP_TIME));
+
+	return 0;
 }
 
 static int xc5000_init(struct dvb_frontend *fe)
@@ -1211,8 +1232,10 @@ static int xc5000_release(struct dvb_frontend *fe)
 
 	mutex_lock(&xc5000_list_mutex);
 
-	if (priv)
+	if (priv) {
+		cancel_delayed_work(&priv->timer_sleep);
 		hybrid_tuner_release_state(priv);
+	}
 
 	mutex_unlock(&xc5000_list_mutex);
 
@@ -1284,6 +1307,8 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
 		/* new tuner instance */
 		priv->bandwidth = 6000000;
 		fe->tuner_priv = priv;
+		priv->fe = fe;
+		INIT_DELAYED_WORK(&priv->timer_sleep, xc5000_do_timer_sleep);
 		break;
 	default:
 		/* existing tuner instance */
-- 
1.9.0


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

* Re: [PATCH 2/8] [media] au0828: Improve debug messages for urb_completion
  2014-05-21 18:19 ` [PATCH 2/8] [media] au0828: Improve debug messages for urb_completion Mauro Carvalho Chehab
@ 2014-05-22  8:36   ` Ricardo Ribalda Delgado
  2014-05-22 10:15     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 11+ messages in thread
From: Ricardo Ribalda Delgado @ 2014-05-22  8:36 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Linux Media Mailing List,
	Mauro Carvalho Chehab

Hello Mauro

Are you aware that using dynamic printk you can decide to print
__func__ on demand?

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/dynamic-debug-howto.txt#n213


Perhaps it is better to not add __func__

Regards!

On Wed, May 21, 2014 at 8:19 PM, Mauro Carvalho Chehab
<m.chehab@samsung.com> wrote:
> Sometimes, it helps to know how much data was received by
> urb_completion. Add that information to the optional debug
> log.
>
> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> ---
>  drivers/media/usb/au0828/au0828-dvb.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/usb/au0828/au0828-dvb.c b/drivers/media/usb/au0828/au0828-dvb.c
> index 2019e4a168b2..ab5f93643021 100755
> --- a/drivers/media/usb/au0828/au0828-dvb.c
> +++ b/drivers/media/usb/au0828/au0828-dvb.c
> @@ -114,16 +114,20 @@ static void urb_completion(struct urb *purb)
>         int ptype = usb_pipetype(purb->pipe);
>         unsigned char *ptr;
>
> -       dprintk(2, "%s()\n", __func__);
> +       dprintk(2, "%s: %d\n", __func__, purb->actual_length);
>
> -       if (!dev)
> +       if (!dev) {
> +               dprintk(2, "%s: no dev!\n", __func__);
>                 return;
> +       }
>
> -       if (dev->urb_streaming == 0)
> +       if (dev->urb_streaming == 0) {
> +               dprintk(2, "%s: not streaming!\n", __func__);
>                 return;
> +       }
>
>         if (ptype != PIPE_BULK) {
> -               printk(KERN_ERR "%s() Unsupported URB type %d\n",
> +               printk(KERN_ERR "%s: Unsupported URB type %d\n",
>                        __func__, ptype);
>                 return;
>         }
> --
> 1.9.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Ricardo Ribalda

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

* Re: [PATCH 2/8] [media] au0828: Improve debug messages for urb_completion
  2014-05-22  8:36   ` Ricardo Ribalda Delgado
@ 2014-05-22 10:15     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 11+ messages in thread
From: Mauro Carvalho Chehab @ 2014-05-22 10:15 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado
  Cc: Devin Heitmueller, Changbing Xiong, Trevor G,
	Reynaldo H. Verdejo Pinochet, Linux Media Mailing List,
	Mauro Carvalho Chehab

Em Thu, 22 May 2014 10:36:24 +0200
Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> escreveu:

> Hello Mauro
> 
> Are you aware that using dynamic printk you can decide to print
> __func__ on demand?
> 
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/dynamic-debug-howto.txt#n213

Yes, I'm aware.

Yet, but changing the driver to use the dynamic printk's should
be done on a separate patch that would convert all printks to use the
dev_* printk macros. 

The goal of this specific patch is just to make the already existing
debug macros more useful, allowing to see when the DMA stuck, like:

[  248.733896] au0828/0: urb_completion: 0
[  248.733900] au0828/0: urb_completion: not streaming!
[  248.733998] au0828/0: urb_completion: 0
[  248.734005] au0828/0: urb_completion: not streaming!
[  248.734042] au0828/0: urb_completion: 0
[  248.734045] au0828/0: urb_completion: not streaming!
[  248.734097] au0828/0: urb_completion: 1536
[  248.734101] au0828/0: urb_completion: not streaming!
[  248.734164] au0828/0: urb_completion: 2048
[  248.734168] au0828/0: urb_completion: not streaming!
[  248.734200] au0828/0: urb_completion: 514
[  248.734204] au0828/0: urb_completion: not streaming!
...
> 
> 
> Perhaps it is better to not add __func__
> 
> Regards!
> 
> On Wed, May 21, 2014 at 8:19 PM, Mauro Carvalho Chehab
> <m.chehab@samsung.com> wrote:
> > Sometimes, it helps to know how much data was received by
> > urb_completion. Add that information to the optional debug
> > log.
> >
> > Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> > ---
> >  drivers/media/usb/au0828/au0828-dvb.c | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/media/usb/au0828/au0828-dvb.c b/drivers/media/usb/au0828/au0828-dvb.c
> > index 2019e4a168b2..ab5f93643021 100755
> > --- a/drivers/media/usb/au0828/au0828-dvb.c
> > +++ b/drivers/media/usb/au0828/au0828-dvb.c
> > @@ -114,16 +114,20 @@ static void urb_completion(struct urb *purb)
> >         int ptype = usb_pipetype(purb->pipe);
> >         unsigned char *ptr;
> >
> > -       dprintk(2, "%s()\n", __func__);
> > +       dprintk(2, "%s: %d\n", __func__, purb->actual_length);
> >
> > -       if (!dev)
> > +       if (!dev) {
> > +               dprintk(2, "%s: no dev!\n", __func__);
> >                 return;
> > +       }
> >
> > -       if (dev->urb_streaming == 0)
> > +       if (dev->urb_streaming == 0) {
> > +               dprintk(2, "%s: not streaming!\n", __func__);
> >                 return;
> > +       }
> >
> >         if (ptype != PIPE_BULK) {
> > -               printk(KERN_ERR "%s() Unsupported URB type %d\n",
> > +               printk(KERN_ERR "%s: Unsupported URB type %d\n",
> >                        __func__, ptype);
> >                 return;
> >         }
> > --
> > 1.9.0
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-media" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 
> 

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

end of thread, other threads:[~2014-05-22 10:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-21 18:19 [PATCH 0/8] Fix stream hangs with au0828 Mauro Carvalho Chehab
2014-05-21 18:19 ` [PATCH 1/8] [media] au0828: Cancel stream-restart operation if frontend is disconnected Mauro Carvalho Chehab
2014-05-21 18:19 ` [PATCH 2/8] [media] au0828: Improve debug messages for urb_completion Mauro Carvalho Chehab
2014-05-22  8:36   ` Ricardo Ribalda Delgado
2014-05-22 10:15     ` Mauro Carvalho Chehab
2014-05-21 18:19 ` [PATCH 3/8] [media] Reset au0828 streaming when a new frequency is set Mauro Carvalho Chehab
2014-05-21 18:19 ` [PATCH 4/8] xc5000: get rid of positive error codes Mauro Carvalho Chehab
2014-05-21 18:19 ` [PATCH 5/8] xc5000: Don't wrap msleep() Mauro Carvalho Chehab
2014-05-21 18:20 ` [PATCH 6/8] xc5000: fix CamelCase Mauro Carvalho Chehab
2014-05-21 18:20 ` [PATCH 7/8] xc5000: Don't use whitespace before tabs Mauro Carvalho Chehab
2014-05-21 18:20 ` [PATCH 8/8] xc5000: delay tuner sleep to 5 seconds Mauro Carvalho Chehab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).