Skip to contentSkip to conversation

various patches for TT S2-3650 CI

PATCH Igor M. Liplianin 1 participant 1 message Sep 23, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

---------- Forwarded Message ----------

Subject: various patches for TT S2-3650 CI
Date: 16 мая 2011, 00:53:18
From: Damien Fouilleul <[email protected]> Получатель: "Igor M. Liplianin" <[email protected]> Копия: Dominik Kuhlen <[email protected]>

Hi Igor,

I do not know what procedure you expect for submitting patches to s2-lilipian, so i apologize in advance if i'm just spamming your mailbox.

i've own a 3650 for a few months, and i could not get it working with the current driver in s2-lilipian on my setup, consisting of universal LNB connected to a Stab HH-100 rotor.
the windows drivers works flawlessly, so i decided to get USB sniffer and compare the linux and windows driver. The following patches are a direct result of a couple of months of investigation.

In a nutshell, the current driver for the LNBP22 SEC does not allow it for providing enough current to power up the rotor, which requires about 300mA for about a second to charge up its DC/DC capacitors. The following patch enable a bit in the driver, which raises the current overload threshold. I've also documented the status register based on my own investigations.

Regarding the pctv452e driver, I fixed an issue with the remote control being too sensitive; i've discovered a bit in the remote control data, which gets flipped every time a key is pressed, and does't when a key is held down. By combining this finding and some code I lifted from the cinergyT2-core (which does a good job at managing repeatable keys), i've come up with the following patch.

I've also modified the USB transfer parameters to match the values used by the windows driver. It does help on my old powerpc macmini running mythtv-backend, it could barely cope with the number of interrupts generated by using the original parameters.

I hope you'll find this useful

Damien

-----------------------------------------

Signature · 2 lines
Igor M. Liplianin
Microsoft Windows Free Zone - Linux used for all Computing Tasks
linux/drivers/media/dvb/frontends/lnbp22.c +79 -31
diff -r 7e47ba1d4ae8 -r c2c6eb5bf6d2 linux/drivers/media/dvb/frontends/lnbp22.c
@@ -48,38 +48,93 @@
 	struct i2c_adapter *i2c;
 };
 
+static int lnbp22_read_config(struct dvb_frontend *fe, u8 *config) {
+        struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
+        struct i2c_msg msg = {  .addr = 0x08, .flags = I2C_M_RD,
+                                .buf = (char*)config,
+                                .len = sizeof(lnbp22->config) };
+
+	if (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) {
+		dprintk(2, "%s: %02X %02X %02X %02X\n", __FUNCTION__,
+			 config[0], config[1], config[2], config[3]);
+		return 0;
+        }
+        return -EIO;
+}
+
+static int lnbp22_write_config(struct dvb_frontend *fe, u8 *config) {
+        struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
+        struct i2c_msg msg = {  .addr = 0x08, .flags = 0,
+                                .buf = (char*)config,
+                                .len = sizeof(lnbp22->config) };
+
+	if (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) {
+		dprintk(2, "%s: %02X %02X %02X %02X\n", __FUNCTION__,
+			 config[0], config[1], config[2], config[3]);
+		return 0;
+        }
+        return -EIO;
+}
+
 static int lnbp22_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) {
 	struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
-	struct i2c_msg msg = {	.addr = 0x08, .flags = 0,
-				.buf = (char*)&lnbp22->config,
-				.len = sizeof(lnbp22->config) };
+	int status;
 
 	dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __FUNCTION__, voltage,
 	       SEC_VOLTAGE_18, SEC_VOLTAGE_13);
 
-	lnbp22->config[3] = 0x60; // Power down
 	switch(voltage) {
-	case SEC_VOLTAGE_OFF:
-		break;
-	case SEC_VOLTAGE_13:
-		lnbp22->config[3] |= LNBP22_EN;
-		break;
-	case SEC_VOLTAGE_18:
-		lnbp22->config[3] |= (LNBP22_EN | LNBP22_VSEL);
-		break;
-	default:
-		return -EINVAL;
-	};
+		case SEC_VOLTAGE_OFF:
+			lnbp22->config[3] &= ~LNBP22_EN;
+			return lnbp22_write_config(fe, lnbp22->config);
+		case SEC_VOLTAGE_13:
+			lnbp22->config[3] |= LNBP22_EN;
+			lnbp22->config[3] &= ~LNBP22_VSEL;
+			break;
+		case SEC_VOLTAGE_18:
+			lnbp22->config[3] |= LNBP22_EN|LNBP22_VSEL;
+			break;
+		default:
+			return -EINVAL;
+	}
 
-	dprintk(1, "%s: 0x%02x)\n", __FUNCTION__, lnbp22->config[3]);
-	return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
+	status = lnbp22_write_config(fe, lnbp22->config);
+	if(  status == 0 ) {
+		u8 config[4];
+		int retries = 20;
+
+		/* byte 0: status
+		    bit 3: open loop
+		    bit 2: in progress/not ready
+		    bit 1: over current limit
+		    bit 0: over voltage limit */
+
+		/* wait up to 2 seconds for voltage to stablize.
+		   It is important to wait that long, especially if there is a
+		   rotor to power on, as DC/DC converter capacitors can take a
+		   while to charge up and could cause a temporary overload */
+		do
+		{
+			msleep(50);
+			status = lnbp22_read_config(fe, config);
+			if( status < 0 )
+				return status;
+		}
+		while( (config[0] & (1<<2)) && retries-- );
+
+		dprintk(1, "%s status=0x%02X\n", __FUNCTION__, config[0]);
+
+		if( retries < 0 )
+			return -EAGAIN;  /* temporary overload ? */
+
+		if( config[0] & (1<<3) )
+			return -ENOLINK; /* open loop */
+	}
+	return status;
 }
 
 static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg) {
 	struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
-	struct i2c_msg msg = {	.addr = 0x08, .flags = 0,
-				.buf = (char*)&lnbp22->config,
-				.len = sizeof(lnbp22->config) };
 
 	dprintk(1, "%s: %d\n", __FUNCTION__, (int)arg);
 	if (arg)
@@ -87,12 +142,11 @@
 	else
 		lnbp22->config[3] &= ~LNBP22_LLC;
 
-	return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
+	return lnbp22_write_config(fe, lnbp22->config);
 }
 
 static void lnbp22_release(struct dvb_frontend *fe)
 {
-
 	dprintk(1, "%s\n", __FUNCTION__);
 	/* LNBP power off */
 	lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF);
@@ -109,20 +163,14 @@
 		return NULL;
 
 	/* default configuration */
-	lnbp22->config[0] = 0x00; /* ? */
+	lnbp22->config[0] = 0x00; /* status */
 	lnbp22->config[1] = 0x28; /* ? */
-	lnbp22->config[2] = 0x48; /* ? */
+	lnbp22->config[2] = 0x49; /* ? */
 	lnbp22->config[3] = 0x60; /* Power down */
 	lnbp22->i2c = i2c;
 	fe->sec_priv = lnbp22;
 
-	/* detect if it is present or not */
-	if (lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF)) {
-		dprintk(0, "%s LNBP22 not found\n", __FUNCTION__);
-		kfree(lnbp22);
-		fe->sec_priv = NULL;
-		return NULL;
-	}
+	lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF);
 
 	/* install release callback */
 	fe->ops.release_sec = lnbp22_release;
linux/drivers/media/dvb/dvb-usb/pctv452e.c +55 -15

119 lines not on this page · raw message