]> err.no Git - linux-2.6/blobdiff - drivers/media/dvb/dvb-usb/dibusb-common.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-2.6
[linux-2.6] / drivers / media / dvb / dvb-usb / dibusb-common.c
index a32ff63d170bc97043b0904222379326d6560d93..fd3a9902f98d472662f69ee96690c5d11d673814 100644 (file)
@@ -18,12 +18,12 @@ MODULE_LICENSE("GPL");
 #define deb_info(args...) dprintk(debug,0x01,args)
 
 /* common stuff used by the different dibusb modules */
-int dibusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
+int dibusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
-       if (d->priv != NULL) {
-               struct dibusb_state *st = d->priv;
+       if (adap->priv != NULL) {
+               struct dibusb_state *st = adap->priv;
                if (st->ops.fifo_ctrl != NULL)
-                       if (st->ops.fifo_ctrl(d->fe,onoff)) {
+                       if (st->ops.fifo_ctrl(adap->fe,onoff)) {
                                err("error while controlling the fifo of the demod.");
                                return -ENODEV;
                        }
@@ -32,23 +32,23 @@ int dibusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
 }
 EXPORT_SYMBOL(dibusb_streaming_ctrl);
 
-int dibusb_pid_filter(struct dvb_usb_device *d, int index, u16 pid, int onoff)
+int dibusb_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
 {
-       if (d->priv != NULL) {
-               struct dibusb_state *st = d->priv;
+       if (adap->priv != NULL) {
+               struct dibusb_state *st = adap->priv;
                if (st->ops.pid_ctrl != NULL)
-                       st->ops.pid_ctrl(d->fe,index,pid,onoff);
+                       st->ops.pid_ctrl(adap->fe,index,pid,onoff);
        }
        return 0;
 }
 EXPORT_SYMBOL(dibusb_pid_filter);
 
-int dibusb_pid_filter_ctrl(struct dvb_usb_device *d, int onoff)
+int dibusb_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
-       if (d->priv != NULL) {
-               struct dibusb_state *st = d->priv;
+       if (adap->priv != NULL) {
+               struct dibusb_state *st = adap->priv;
                if (st->ops.pid_parse != NULL)
-                       if (st->ops.pid_parse(d->fe,onoff) < 0)
+                       if (st->ops.pid_parse(adap->fe,onoff) < 0)
                                err("could not handle pid_parser");
        }
        return 0;
@@ -68,24 +68,24 @@ int dibusb_power_ctrl(struct dvb_usb_device *d, int onoff)
 }
 EXPORT_SYMBOL(dibusb_power_ctrl);
 
-int dibusb2_0_streaming_ctrl(struct dvb_usb_device *d, int onoff)
+int dibusb2_0_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
        u8 b[3] = { 0 };
        int ret;
 
-       if ((ret = dibusb_streaming_ctrl(d,onoff)) < 0)
+       if ((ret = dibusb_streaming_ctrl(adap,onoff)) < 0)
                return ret;
 
        if (onoff) {
                b[0] = DIBUSB_REQ_SET_STREAMING_MODE;
                b[1] = 0x00;
-               if ((ret = dvb_usb_generic_write(d,b,2)) < 0)
+               if ((ret = dvb_usb_generic_write(adap->dev,b,2)) < 0)
                        return ret;
        }
 
        b[0] = DIBUSB_REQ_SET_IOCTL;
        b[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM : DIBUSB_IOCTL_CMD_DISABLE_STREAM;
-       return dvb_usb_generic_write(d,b,3);
+       return dvb_usb_generic_write(adap->dev,b,3);
 }
 EXPORT_SYMBOL(dibusb2_0_streaming_ctrl);
 
@@ -131,9 +131,6 @@ static int dibusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
        if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
                return -EAGAIN;
 
-       if (num > 2)
-               warn("more than 2 i2c messages at a time is not handled yet. TODO.");
-
        for (i = 0; i < num; i++) {
                /* write/read request */
                if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
@@ -168,106 +165,135 @@ int dibusb_read_eeprom_byte(struct dvb_usb_device *d, u8 offs, u8 *val)
 }
 EXPORT_SYMBOL(dibusb_read_eeprom_byte);
 
-static struct mt2060_config stk3000p_mt2060_config = {
-       .i2c_address = 0x60,
+/* 3000MC/P stuff */
+// Config Adjacent channels  Perf -cal22
+static struct dibx000_agc_config dib3000p_mt2060_agc_config = {
+       .band_caps = BAND_VHF | BAND_UHF,
+       .setup     = (0 << 15) | (0 << 14) | (1 << 13) | (1 << 12) | (29 << 0),
+
+       .agc1_max = 48497,
+       .agc1_min = 23593,
+       .agc2_max = 46531,
+       .agc2_min = 24904,
+
+       .agc1_pt1 = 0x65,
+       .agc1_pt2 = 0x69,
+
+       .agc1_slope1 = 0x51,
+       .agc1_slope2 = 0x27,
+
+       .agc2_pt1 = 0,
+       .agc2_pt2 = 0x33,
+
+       .agc2_slope1 = 0x35,
+       .agc2_slope2 = 0x37,
 };
 
-static int dibusb_tuner_init(struct dvb_frontend *fe)
-{
-       struct dvb_usb_device *d = fe->dvb->priv;
-       struct dibusb_state *st = d->priv;
-
-       if (d->tuner_pass_ctrl && st->mt2060_present) {
-               int ret;
-               d->tuner_pass_ctrl(d->fe, 1, stk3000p_mt2060_config.i2c_address);
-               ret = mt2060_init(&st->mt2060);
-               d->tuner_pass_ctrl(d->fe, 0, 0);
-               return ret;
-       }
-       return dvb_usb_pll_init_i2c(fe);
-}
+static struct dib3000mc_config stk3000p_dib3000p_config = {
+       &dib3000p_mt2060_agc_config,
 
-static int dibusb_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
-{
-       struct dvb_usb_device *d = fe->dvb->priv;
-       struct dibusb_state *st = d->priv;
-
-       if (d->tuner_pass_ctrl && st->mt2060_present) {
-               int ret;
-               d->tuner_pass_ctrl(d->fe, 1, stk3000p_mt2060_config.i2c_address);
-               ret = mt2060_set(&st->mt2060,fep);
-               d->tuner_pass_ctrl(d->fe,0,0);
-               return ret;
-       }
-       return dvb_usb_pll_set_i2c(fe,fep);
-}
+       .max_time     = 0x196,
+       .ln_adc_level = 0x1cc7,
 
-static const struct dib3000p_agc_config dib3000p_agc_panasonic_env57h1xd5 = {
-       { 0x51, 0x301d, 0x0, 0x1cc7, 0xdc29, 0x570a,
-       0xbae1, 0x8ccd, 0x3b6d, 0x551d, 0xa, 0x951e }
+       .output_mpeg2_in_188_bytes = 1,
 };
 
-static const struct dib3000p_agc_config dib3000p_agc_microtune_mt2060 = {
-       { 0x196, 0x301d, 0x0, 0x1cc7, 0xffff, 0x5c29,
-       0xa8f6, 0x5eb8, 0x65ff, 0x40ff, 0x8a, 0x1114 }
+static struct dibx000_agc_config dib3000p_panasonic_agc_config = {
+       .setup    = (0 << 15) | (0 << 14) | (1 << 13) | (1 << 12) | (29 << 0),
+
+       .agc1_max = 56361,
+       .agc1_min = 22282,
+       .agc2_max = 47841,
+       .agc2_min = 36045,
+
+       .agc1_pt1 = 0x3b,
+       .agc1_pt2 = 0x6b,
+
+       .agc1_slope1 = 0x55,
+       .agc1_slope2 = 0x1d,
+
+       .agc2_pt1 = 0,
+       .agc2_pt2 = 0x0a,
+
+       .agc2_slope1 = 0x95,
+       .agc2_slope2 = 0x1e,
 };
 
-int dibusb_dib3000mc_frontend_attach(struct dvb_usb_device *d)
-{
-       struct dib3000_config demod_cfg;
-       struct dibusb_state *st = d->priv;
+static struct dib3000mc_config mod3000p_dib3000p_config = {
+       &dib3000p_panasonic_agc_config,
 
-       demod_cfg.agc      = &dib3000p_agc_panasonic_env57h1xd5;
-       demod_cfg.pll_set  = dibusb_tuner_set;
-       demod_cfg.pll_init = dibusb_tuner_init;
+       .max_time     = 0x51,
+       .ln_adc_level = 0x1cc7,
 
-       for (demod_cfg.demod_address = 0x8; demod_cfg.demod_address < 0xd; demod_cfg.demod_address++)
-               if ((d->fe = dib3000mc_attach(&demod_cfg,&d->i2c_adap,&st->ops)) != NULL) {
-                       d->tuner_pass_ctrl = st->ops.tuner_pass_ctrl;
-                       return 0;
-               }
+       .output_mpeg2_in_188_bytes = 1,
+};
 
+int dibusb_dib3000mc_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       if ((adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap, DEFAULT_DIB3000P_I2C_ADDRESS,  &mod3000p_dib3000p_config)) != NULL ||
+               (adap->fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap, DEFAULT_DIB3000MC_I2C_ADDRESS, &mod3000p_dib3000p_config)) != NULL) {
+               if (adap->priv != NULL) {
+                       struct dibusb_state *st = adap->priv;
+                       st->ops.pid_parse = dib3000mc_pid_parse;
+                       st->ops.pid_ctrl  = dib3000mc_pid_control;
+               }
+               return 0;
+       }
        return -ENODEV;
 }
 EXPORT_SYMBOL(dibusb_dib3000mc_frontend_attach);
 
-int dibusb_dib3000mc_tuner_attach (struct dvb_usb_device *d)
+static struct mt2060_config stk3000p_mt2060_config = {
+       0x60
+};
+
+int dibusb_dib3000mc_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       int ret;
+       struct dibusb_state *st = adap->priv;
        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);
-               // 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;
-               } else {
-                       st->mt2060_present = 1;
-                       /* set the correct agc parameters for the dib3000p */
-                       dib3000mc_set_agc_config(d->fe, &dib3000p_agc_microtune_mt2060);
+       struct i2c_adapter *tun_i2c;
+
+       // First IF calibration for Liteon Sticks
+       if (adap->dev->udev->descriptor.idVendor  == USB_VID_LITEON &&
+               adap->dev->udev->descriptor.idProduct == USB_PID_LITEON_DVB_T_WARM) {
+
+               dibusb_read_eeprom_byte(adap->dev,0x7E,&a);
+               dibusb_read_eeprom_byte(adap->dev,0x7F,&b);
+
+               if (a == 0x00)
+                       if1 += b;
+               else if (a == 0x80)
+                       if1 -= b;
+               else
+                       warn("LITE-ON DVB-T: Strange IF1 calibration :%2X %2X\n", a, b);
+
+       } else if (adap->dev->udev->descriptor.idVendor  == USB_VID_DIBCOM &&
+                  adap->dev->udev->descriptor.idProduct == USB_PID_DIBCOM_MOD3001_WARM) {
+               u8 desc;
+               dibusb_read_eeprom_byte(adap->dev, 7, &desc);
+               if (desc == 2) {
+                       a = 127;
+                       do {
+                               dibusb_read_eeprom_byte(adap->dev, a, &desc);
+                               a--;
+                       } while (a > 7 && (desc == 0xff || desc == 0x00));
+                       if (desc & 0x80)
+                               if1 -= (0xff - desc);
+                       else
+                               if1 += desc;
                }
-               d->tuner_pass_ctrl(d->fe,0,0);
+       }
+
+       tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
+       if (dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk3000p_mt2060_config, if1) == NULL) {
+               /* not found - use panasonic pll parameters */
+               if (dvb_attach(dvb_pll_attach, adap->fe, 0x60, tun_i2c, &dvb_pll_env57h1xd5) == NULL)
+                       return -ENOMEM;
+       } else {
+               st->mt2060_present = 1;
+               /* set the correct parameters for the dib3000p */
+               dib3000mc_set_config(adap->fe, &stk3000p_dib3000p_config);
        }
        return 0;
 }