[PATCH] fix m920x tuner identification failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fixes qt1010 identification bug with megasky.
Apply after Quantek QT1010 tuner module -patch.

Signed-off-by: Aapo Tahkola <aet@xxxxxxxxxxxxxx>

-- 
Aapo Tahkola
diff -r 1d3437c60b5d linux/drivers/media/dvb/dvb-usb/m920x.c
--- a/linux/drivers/media/dvb/dvb-usb/m920x.c	Sun Jan 21 11:06:48 2007 +0200
+++ b/linux/drivers/media/dvb/dvb-usb/m920x.c	Sun Jan 21 11:07:36 2007 +0200
@@ -141,6 +141,7 @@ static int m9206_i2c_xfer(struct i2c_ada
 static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
 {
 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
+	struct m9206_state *m = d->priv;
 	int i;
 	int ret = 0;
 
@@ -151,8 +152,6 @@ static int m9206_i2c_xfer(struct i2c_ada
 		return -EINVAL;
 
 	for (i = 0; i < num; i++) {
-		u8 w_len;
-
 		if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].addr, 0x80)) != 0)
 			goto unlock;
 
@@ -160,13 +159,19 @@ static int m9206_i2c_xfer(struct i2c_ada
 			goto unlock;
 
 		if (i + 1 < num && msg[i + 1].flags & I2C_M_RD) {
-			/* Possibly device dependant */
-			if (msg[i].addr == d->adapter[0].pll_addr)
-				w_len = 0xc5;
-			else
-				w_len = 0x1f;
-
-			if ((ret = m9206_write(d->udev, M9206_I2C, w_len, 0x80)) != 0)
+			int i2c_i;
+
+			for (i2c_i = 0; i2c_i < M9206_I2C_MAX; i2c_i++)
+				if (msg[i].addr == m->i2c_r[i2c_i].addr)
+					break;
+
+			if (i2c_i >= M9206_I2C_MAX) {
+				deb_rc("No magic for i2c addr!\n");
+				ret = -EINVAL;
+				goto unlock;
+			}
+
+			if ((ret = m9206_write(d->udev, M9206_I2C, m->i2c_r[i2c_i].magic, 0x80)) != 0)
 				goto unlock;
 
 			if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x60, msg[i + 1].buf, msg[i + 1].len)) != 0)
@@ -245,11 +250,17 @@ static struct mt352_config megasky_mt352
 
 static int megasky_frontend_attach(struct dvb_usb_adapter *adap)
 {
+	struct m9206_state *m = adap->dev->priv;
+
 	deb_rc("megasky_frontend_attach!\n");
 
-	if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) != NULL)
-		return 0;
-	return -EIO;
+	m->i2c_r[M9206_I2C_DEMOD].addr = megasky_mt352_config.demod_address;
+	m->i2c_r[M9206_I2C_DEMOD].magic = 0x1f;
+
+	if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL)
+		return -EIO;
+
+	return 0;
 }
 
 static int m9206_set_filter(struct dvb_usb_adapter *adap, int type, int idx, int pid)
@@ -401,6 +412,23 @@ static int megasky_tuner_attach(struct d
 	                  &megasky_qt1010_config) == NULL ? -ENODEV : 0;
 }
 
+static struct qt1010_config megasky_qt1010_config = {
+	.i2c_address = 0xc4
+};
+
+static int megasky_tuner_attach(struct dvb_usb_adapter *adap)
+{
+	struct m9206_state *m = adap->dev->priv;
+
+	m->i2c_r[M9206_I2C_TUNER].addr = megasky_qt1010_config.i2c_address;
+	m->i2c_r[M9206_I2C_TUNER].magic = 0xc5;
+
+	if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &megasky_qt1010_config) == NULL)
+		return -ENODEV;
+
+	return 0;
+}
+
 /* DVB USB Driver stuff */
 static struct dvb_usb_device_properties megasky_properties;
 
diff -r 1d3437c60b5d linux/drivers/media/dvb/dvb-usb/m920x.h
--- a/linux/drivers/media/dvb/dvb-usb/m920x.h	Sun Jan 21 11:06:48 2007 +0200
+++ b/linux/drivers/media/dvb/dvb-usb/m920x.h	Sun Jan 21 11:07:36 2007 +0200
@@ -18,9 +18,18 @@
 #define M9206_FW	0x30
 
 #define M9206_MAX_FILTERS 8
+
+#define M9206_I2C_TUNER	0
+#define M9206_I2C_DEMOD	1
+#define M9206_I2C_MAX	2
+
 struct m9206_state {
 	u16 filters[M9206_MAX_FILTERS];
 	int filtering_enabled;
 	int rep_count;
+	struct {
+		unsigned char addr;
+		unsigned char magic;
+	}i2c_r[M9206_I2C_MAX];
 };
 #endif
_______________________________________________
linux-dvb mailing list
linux-dvb@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linux-dvb

[Index of Archives]     [Linux Media]     [Video 4 Linux]     [Asterisk]     [Samba]     [Xorg]     [Xfree86]     [Linux USB]

  Powered by Linux