diff mbox

cx231xx: Provide signal lock status in G_INPUT

Message ID CAGoCfiz4Ry27iYDZqMLwM_kK=6y0Wgu8kDeBPhsdQ_2txndwMA@mail.gmail.com (mailing list archive)
State Accepted
Headers show

Commit Message

Devin Heitmueller July 24, 2011, 8:07 p.m. UTC
The attached patch reports the signal lock statistics to userland,
which allows apps to know if there is a signal present even in cases
where it cannot rely on G_TUNER since it won't make calls for such if
the device lacks a tuner.

Devin
diff mbox

Patch

cx231xx: show real signal status in G_INPUT/ENUM_INPUT ioctl results

From: Devin Heitmueller <dheitmueller@kernellabs.com>

Make use of the signal state registers to properly populate the signal lock
registers in the cx231xx driver.

This allows applications to know whether there is a signal present even in
devices which lack a tuner (since such apps typically won't call G_TUNER if
no tuner is present).

Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>

diff --git a/drivers/media/video/cx231xx/cx231xx-video.c b/drivers/media/video/cx231xx/cx231xx-video.c
index a69c24d..9ed56b7 100644
--- a/drivers/media/video/cx231xx/cx231xx-video.c
+++ b/drivers/media/video/cx231xx/cx231xx-video.c
@@ -1179,7 +1179,8 @@  static int vidioc_enum_input(struct file *file, void *priv,
 {
 	struct cx231xx_fh *fh = priv;
 	struct cx231xx *dev = fh->dev;
-	unsigned int n;
+	u32 gen_stat;
+	unsigned int ret, n;
 
 	n = i->index;
 	if (n >= MAX_CX231XX_INPUT)
@@ -1198,6 +1199,20 @@  static int vidioc_enum_input(struct file *file, void *priv,
 
 	i->std = dev->vdev->tvnorms;
 
+	/* If they are asking about the active input, read signal status */
+	if (n == dev->video_input) {
+		ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
+					    GEN_STAT, 2, &gen_stat, 4);
+		if (ret > 0) {
+			if ((gen_stat & FLD_VPRES) == 0x00) {
+				i->status |= V4L2_IN_ST_NO_SIGNAL;
+			}
+			if ((gen_stat & FLD_HLOCK) == 0x00) {
+				i->status |= V4L2_IN_ST_NO_H_LOCK;
+			}
+		}
+	}
+
 	return 0;
 }