V4L/DVB (4451): MT2060: IF1 Offset from EEPROM, several updates

- AGC gain set to 3
- The tuning sequence has been changed to match the DibCom driver ( from I2C
  spy captures )
- For LITE-ON adapters : The IF1 frequency is now tuned according to the
  calibration values stored in EEPROM.

Signed-off-by: Patrick Boettcher <pb@linuxtv.org>
Signed-off-by: Olivier DANET <odanet@caramail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index e079ba9..88062b21 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-common.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -234,12 +234,31 @@
 int dibusb_dib3000mc_tuner_attach (struct dvb_usb_device *d)
 {
 	int ret;
+	u8 a,b;
+	u16 if1=1220;
 
 	if (d->tuner_pass_ctrl) {
 		struct dibusb_state *st = d->priv;
 		d->tuner_pass_ctrl(d->fe, 1, stk3000p_mt2060_config.i2c_address);
-		/* check for mt2060 */
-		if ((ret = mt2060_attach(&st->mt2060,&stk3000p_mt2060_config, &d->i2c_adap)) != 0) {
+		// First IF calibration for Liteon Sticks
+		if (d->udev->descriptor.idVendor == USB_VID_LITEON &&
+		    d->udev->descriptor.idProduct == USB_PID_LITEON_DVB_T_WARM) {
+			dibusb_read_eeprom_byte(d,0x7E,&a);
+			dibusb_read_eeprom_byte(d,0x7F,&b);
+			if (a == 0xFF && b == 0xFF) {
+				if1 = 1220;
+			} else
+			if (a == 0x00) {
+				if1 = 1220+b;
+			} else
+			if (a == 0x80) {
+				if1 = 1220-b;
+			} else {
+				warn("LITE-ON DVB-T Tuner : Strange IF1 calibration :%2X %2X\n",(int)a,(int)b);
+				if1 = 1220;
+			}
+		}
+		if ((ret = mt2060_attach(&st->mt2060,&stk3000p_mt2060_config, &d->i2c_adap,if1)) != 0) {
 			/* not found - use panasonic pll parameters */
 			d->pll_addr = 0x60;
 			d->pll_desc = &dvb_pll_env57h1xd5;