aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb/dvb-usb
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <m.chehab@samsung.com>2014-05-29 08:20:15 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-06-17 11:04:49 -0400
commit8abe4a0a3f6d4217b16a1a3f68cd5c72ab5a058e (patch)
tree39c885e72ee0ad7600a160fdc8cd632769a7e5d2 /drivers/media/usb/dvb-usb
parent7f67d96ab181aff4af2074ba0a56b3f81333e896 (diff)
[media] dib7000: export just one symbol
Exporting multiple symbols don't work as it causes compilation breakages, due to the way dvb_attach() works. This were reported several times, like: drivers/built-in.o: In function `cxusb_dualdig4_rev2_tuner_attach': >> cxusb.c:(.text+0x27d4b5): undefined reference to `dib7000p_get_i2c_master' drivers/built-in.o: In function `dib7070_set_param_override': cxusb.c:(.text+0x27d5a5): undefined reference to `dib0070_wbd_offset' >> cxusb.c:(.text+0x27d5be): undefined reference to `dib7000p_set_wbd_ref' drivers/built-in.o: In function `dib7070_tuner_reset': >> cxusb.c:(.text+0x27d5f9): undefined reference to `dib7000p_set_gpio' drivers/built-in.o: In function `cxusb_dualdig4_rev2_frontend_attach': >> cxusb.c:(.text+0x27df5c): undefined reference to `dib7000p_i2c_enumeration' In this specific report: CONFIG_DVB_USB_CXUSB=y CONFIG_DVB_DIB7000P=m But the same type of bug can happen if: CONFIG_DVB_DIB7000P=m and one of the bridge drivers is compiled builtin (cxusb, cx23885-dvb and/or dib0700). As a bonus, dib7000p won't be loaded anymore if the device uses a different frontend, reducing the memory footprint. Tested with Hauppauge Nova-TD (2 frontends). Reported-by: Fengguang Wu <fengguang.wu@intel.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/usb/dvb-usb')
-rw-r--r--drivers/media/usb/dvb-usb/cxusb.c39
-rw-r--r--drivers/media/usb/dvb-usb/dib0700_devices.c326
2 files changed, 243 insertions, 122 deletions
diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
index e81a2fd54960..6acde5ee4324 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -1070,8 +1070,15 @@ static struct dib7000p_config cxusb_dualdig4_rev2_config = {
1070 .hostbus_diversity = 1, 1070 .hostbus_diversity = 1,
1071}; 1071};
1072 1072
1073struct dib0700_adapter_state {
1074 int (*set_param_save)(struct dvb_frontend *);
1075 struct dib7000p_ops dib7000p_ops;
1076};
1077
1073static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap) 1078static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1074{ 1079{
1080 struct dib0700_adapter_state *state = adap->priv;
1081
1075 if (usb_set_interface(adap->dev->udev, 0, 1) < 0) 1082 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1076 err("set interface failed"); 1083 err("set interface failed");
1077 1084
@@ -1079,14 +1086,17 @@ static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1079 1086
1080 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1); 1087 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1081 1088
1082 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 1089 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
1083 &cxusb_dualdig4_rev2_config) < 0) { 1090 return -ENODEV;
1091
1092 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1093 &cxusb_dualdig4_rev2_config) < 0) {
1084 printk(KERN_WARNING "Unable to enumerate dib7000p\n"); 1094 printk(KERN_WARNING "Unable to enumerate dib7000p\n");
1085 return -ENODEV; 1095 return -ENODEV;
1086 } 1096 }
1087 1097
1088 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x80, 1098 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
1089 &cxusb_dualdig4_rev2_config); 1099 &cxusb_dualdig4_rev2_config);
1090 if (adap->fe_adap[0].fe == NULL) 1100 if (adap->fe_adap[0].fe == NULL)
1091 return -EIO; 1101 return -EIO;
1092 1102
@@ -1095,7 +1105,10 @@ static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1095 1105
1096static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff) 1106static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
1097{ 1107{
1098 return dib7000p_set_gpio(fe, 8, 0, !onoff); 1108 struct dvb_usb_adapter *adap = fe->dvb->priv;
1109 struct dib0700_adapter_state *state = adap->priv;
1110
1111 return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
1099} 1112}
1100 1113
1101static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff) 1114static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
@@ -1110,10 +1123,6 @@ static struct dib0070_config dib7070p_dib0070_config = {
1110 .clock_khz = 12000, 1123 .clock_khz = 12000,
1111}; 1124};
1112 1125
1113struct dib0700_adapter_state {
1114 int (*set_param_save) (struct dvb_frontend *);
1115};
1116
1117static int dib7070_set_param_override(struct dvb_frontend *fe) 1126static int dib7070_set_param_override(struct dvb_frontend *fe)
1118{ 1127{
1119 struct dtv_frontend_properties *p = &fe->dtv_property_cache; 1128 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
@@ -1128,7 +1137,7 @@ static int dib7070_set_param_override(struct dvb_frontend *fe)
1128 case BAND_UHF: offset = 550; break; 1137 case BAND_UHF: offset = 550; break;
1129 } 1138 }
1130 1139
1131 dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe)); 1140 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
1132 1141
1133 return state->set_param_save(fe); 1142 return state->set_param_save(fe);
1134} 1143}
@@ -1136,8 +1145,14 @@ static int dib7070_set_param_override(struct dvb_frontend *fe)
1136static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap) 1145static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
1137{ 1146{
1138 struct dib0700_adapter_state *st = adap->priv; 1147 struct dib0700_adapter_state *st = adap->priv;
1139 struct i2c_adapter *tun_i2c = 1148 struct i2c_adapter *tun_i2c;
1140 dib7000p_get_i2c_master(adap->fe_adap[0].fe, 1149
1150 /*
1151 * No need to call dvb7000p_attach here, as it was called
1152 * already, as frontend_attach method is called first, and
1153 * tuner_attach is only called on sucess.
1154 */
1155 tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
1141 DIBX000_I2C_INTERFACE_TUNER, 1); 1156 DIBX000_I2C_INTERFACE_TUNER, 1);
1142 1157
1143 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, 1158 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 3585089c805c..c09505f5f18b 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -32,6 +32,7 @@ MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplif
32struct dib0700_adapter_state { 32struct dib0700_adapter_state {
33 int (*set_param_save) (struct dvb_frontend *); 33 int (*set_param_save) (struct dvb_frontend *);
34 const struct firmware *frontend_firmware; 34 const struct firmware *frontend_firmware;
35 struct dib7000p_ops dib7000p_ops;
35}; 36};
36 37
37/* Hauppauge Nova-T 500 (aka Bristol) 38/* Hauppauge Nova-T 500 (aka Bristol)
@@ -262,6 +263,11 @@ static struct mt2266_config stk7700d_mt2266_config[2] = {
262 263
263static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap) 264static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
264{ 265{
266 struct dib0700_adapter_state *state = adap->priv;
267
268 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
269 return -ENODEV;
270
265 if (adap->id == 0) { 271 if (adap->id == 0) {
266 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); 272 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
267 msleep(10); 273 msleep(10);
@@ -272,16 +278,16 @@ static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
272 msleep(10); 278 msleep(10);
273 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); 279 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
274 msleep(10); 280 msleep(10);
275 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 281 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
276 stk7700d_dib7000p_mt2266_config) 282 stk7700d_dib7000p_mt2266_config)
277 != 0) { 283 != 0) {
278 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__); 284 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n", __func__);
285 dvb_detach(&state->dib7000p_ops);
279 return -ENODEV; 286 return -ENODEV;
280 } 287 }
281 } 288 }
282 289
283 adap->fe_adap[0].fe = 290 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
284 dvb_attach(dib7000p_init, &adap->dev->i2c_adap,
285 0x80 + (adap->id << 1), 291 0x80 + (adap->id << 1),
286 &stk7700d_dib7000p_mt2266_config[adap->id]); 292 &stk7700d_dib7000p_mt2266_config[adap->id]);
287 293
@@ -290,6 +296,11 @@ static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
290 296
291static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap) 297static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
292{ 298{
299 struct dib0700_adapter_state *state = adap->priv;
300
301 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
302 return -ENODEV;
303
293 if (adap->id == 0) { 304 if (adap->id == 0) {
294 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); 305 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
295 msleep(10); 306 msleep(10);
@@ -301,16 +312,16 @@ static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
301 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); 312 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
302 msleep(10); 313 msleep(10);
303 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 314 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
304 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, 315 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
305 stk7700d_dib7000p_mt2266_config) 316 stk7700d_dib7000p_mt2266_config)
306 != 0) { 317 != 0) {
307 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__); 318 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n", __func__);
319 dvb_detach(&state->dib7000p_ops);
308 return -ENODEV; 320 return -ENODEV;
309 } 321 }
310 } 322 }
311 323
312 adap->fe_adap[0].fe = 324 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
313 dvb_attach(dib7000p_init, &adap->dev->i2c_adap,
314 0x80 + (adap->id << 1), 325 0x80 + (adap->id << 1),
315 &stk7700d_dib7000p_mt2266_config[adap->id]); 326 &stk7700d_dib7000p_mt2266_config[adap->id]);
316 327
@@ -320,7 +331,10 @@ static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
320static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap) 331static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
321{ 332{
322 struct i2c_adapter *tun_i2c; 333 struct i2c_adapter *tun_i2c;
323 tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1); 334 struct dib0700_adapter_state *state = adap->priv;
335
336 tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
337 DIBX000_I2C_INTERFACE_TUNER, 1);
324 return dvb_attach(mt2266_attach, adap->fe_adap[0].fe, tun_i2c, 338 return dvb_attach(mt2266_attach, adap->fe_adap[0].fe, tun_i2c,
325 &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0; 339 &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;
326} 340}
@@ -397,12 +411,14 @@ static int stk7700ph_xc3028_callback(void *ptr, int component,
397 int command, int arg) 411 int command, int arg)
398{ 412{
399 struct dvb_usb_adapter *adap = ptr; 413 struct dvb_usb_adapter *adap = ptr;
414 struct dib0700_adapter_state *state = adap->priv;
400 415
401 switch (command) { 416 switch (command) {
402 case XC2028_TUNER_RESET: 417 case XC2028_TUNER_RESET:
403 /* Send the tuner in then out of reset */ 418 /* Send the tuner in then out of reset */
404 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 0); msleep(10); 419 state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
405 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1); 420 msleep(10);
421 state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
406 break; 422 break;
407 case XC2028_RESET_CLK: 423 case XC2028_RESET_CLK:
408 break; 424 break;
@@ -428,12 +444,16 @@ static struct xc2028_config stk7700ph_xc3028_config = {
428static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap) 444static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
429{ 445{
430 struct usb_device_descriptor *desc = &adap->dev->udev->descriptor; 446 struct usb_device_descriptor *desc = &adap->dev->udev->descriptor;
447 struct dib0700_adapter_state *state = adap->priv;
448
449 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
450 return -ENODEV;
431 451
432 if (desc->idVendor == cpu_to_le16(USB_VID_PINNACLE) && 452 if (desc->idVendor == cpu_to_le16(USB_VID_PINNACLE) &&
433 desc->idProduct == cpu_to_le16(USB_PID_PINNACLE_EXPRESSCARD_320CX)) 453 desc->idProduct == cpu_to_le16(USB_PID_PINNACLE_EXPRESSCARD_320CX))
434 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); 454 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
435 else 455 else
436 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); 456 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
437 msleep(20); 457 msleep(20);
438 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1); 458 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
439 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1); 459 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
@@ -445,14 +465,15 @@ static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
445 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 465 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
446 msleep(10); 466 msleep(10);
447 467
448 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 468 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
449 &stk7700ph_dib7700_xc3028_config) != 0) { 469 &stk7700ph_dib7700_xc3028_config) != 0) {
450 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", 470 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n",
451 __func__); 471 __func__);
472 dvb_detach(&state->dib7000p_ops);
452 return -ENODEV; 473 return -ENODEV;
453 } 474 }
454 475
455 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x80, 476 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
456 &stk7700ph_dib7700_xc3028_config); 477 &stk7700ph_dib7700_xc3028_config);
457 478
458 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 479 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
@@ -461,8 +482,9 @@ static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
461static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap) 482static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
462{ 483{
463 struct i2c_adapter *tun_i2c; 484 struct i2c_adapter *tun_i2c;
485 struct dib0700_adapter_state *state = adap->priv;
464 486
465 tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, 487 tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
466 DIBX000_I2C_INTERFACE_TUNER, 1); 488 DIBX000_I2C_INTERFACE_TUNER, 1);
467 489
468 stk7700ph_xc3028_config.i2c_adap = tun_i2c; 490 stk7700ph_xc3028_config.i2c_adap = tun_i2c;
@@ -673,6 +695,11 @@ static struct dib7000p_config stk7700p_dib7000p_config = {
673static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap) 695static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
674{ 696{
675 struct dib0700_state *st = adap->dev->priv; 697 struct dib0700_state *st = adap->dev->priv;
698 struct dib0700_adapter_state *state = adap->priv;
699
700 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
701 return -ENODEV;
702
676 /* unless there is no real power management in DVB - we leave the device on GPIO6 */ 703 /* unless there is no real power management in DVB - we leave the device on GPIO6 */
677 704
678 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); 705 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
@@ -689,11 +716,14 @@ static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
689 716
690 st->mt2060_if1[0] = 1220; 717 st->mt2060_if1[0] = 1220;
691 718
692 if (dib7000pc_detection(&adap->dev->i2c_adap)) { 719 if (state->dib7000p_ops.dib7000pc_detection(&adap->dev->i2c_adap)) {
693 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config); 720 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
694 st->is_dib7000pc = 1; 721 st->is_dib7000pc = 1;
695 } else 722 } else {
723 dvb_detach(&state->dib7000p_ops);
724 memset(&state->dib7000p_ops, 0, sizeof(state->dib7000p_ops));
696 adap->fe_adap[0].fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config); 725 adap->fe_adap[0].fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
726 }
697 727
698 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 728 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
699} 729}
@@ -707,14 +737,16 @@ static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
707 struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap; 737 struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap;
708 struct dib0700_state *st = adap->dev->priv; 738 struct dib0700_state *st = adap->dev->priv;
709 struct i2c_adapter *tun_i2c; 739 struct i2c_adapter *tun_i2c;
740 struct dib0700_adapter_state *state = adap->priv;
710 s8 a; 741 s8 a;
711 int if1=1220; 742 int if1=1220;
743
712 if (adap->dev->udev->descriptor.idVendor == cpu_to_le16(USB_VID_HAUPPAUGE) && 744 if (adap->dev->udev->descriptor.idVendor == cpu_to_le16(USB_VID_HAUPPAUGE) &&
713 adap->dev->udev->descriptor.idProduct == cpu_to_le16(USB_PID_HAUPPAUGE_NOVA_T_STICK)) { 745 adap->dev->udev->descriptor.idProduct == cpu_to_le16(USB_PID_HAUPPAUGE_NOVA_T_STICK)) {
714 if (!eeprom_read(prim_i2c,0x58,&a)) if1=1220+a; 746 if (!eeprom_read(prim_i2c,0x58,&a)) if1=1220+a;
715 } 747 }
716 if (st->is_dib7000pc) 748 if (st->is_dib7000pc)
717 tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1); 749 tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
718 else 750 else
719 tun_i2c = dib7000m_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1); 751 tun_i2c = dib7000m_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
720 752
@@ -767,14 +799,20 @@ static struct dibx000_agc_config dib7070_agc_config = {
767 799
768static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff) 800static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
769{ 801{
802 struct dvb_usb_adapter *adap = fe->dvb->priv;
803 struct dib0700_adapter_state *state = adap->priv;
804
770 deb_info("reset: %d", onoff); 805 deb_info("reset: %d", onoff);
771 return dib7000p_set_gpio(fe, 8, 0, !onoff); 806 return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
772} 807}
773 808
774static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff) 809static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
775{ 810{
811 struct dvb_usb_adapter *adap = fe->dvb->priv;
812 struct dib0700_adapter_state *state = adap->priv;
813
776 deb_info("sleep: %d", onoff); 814 deb_info("sleep: %d", onoff);
777 return dib7000p_set_gpio(fe, 9, 0, onoff); 815 return state->dib7000p_ops.set_gpio(fe, 9, 0, onoff);
778} 816}
779 817
780static struct dib0070_config dib7070p_dib0070_config[2] = { 818static struct dib0070_config dib7070p_dib0070_config[2] = {
@@ -818,7 +856,7 @@ static int dib7070_set_param_override(struct dvb_frontend *fe)
818 default: offset = 550; break; 856 default: offset = 550; break;
819 } 857 }
820 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe)); 858 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
821 dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe)); 859 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
822 return state->set_param_save(fe); 860 return state->set_param_save(fe);
823} 861}
824 862
@@ -832,39 +870,39 @@ static int dib7770_set_param_override(struct dvb_frontend *fe)
832 u8 band = BAND_OF_FREQUENCY(p->frequency/1000); 870 u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
833 switch (band) { 871 switch (band) {
834 case BAND_VHF: 872 case BAND_VHF:
835 dib7000p_set_gpio(fe, 0, 0, 1); 873 state->dib7000p_ops.set_gpio(fe, 0, 0, 1);
836 offset = 850; 874 offset = 850;
837 break; 875 break;
838 case BAND_UHF: 876 case BAND_UHF:
839 default: 877 default:
840 dib7000p_set_gpio(fe, 0, 0, 0); 878 state->dib7000p_ops.set_gpio(fe, 0, 0, 0);
841 offset = 250; 879 offset = 250;
842 break; 880 break;
843 } 881 }
844 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe)); 882 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
845 dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe)); 883 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
846 return state->set_param_save(fe); 884 return state->set_param_save(fe);
847} 885}
848 886
849static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap) 887static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap)
850{ 888{
851 struct dib0700_adapter_state *st = adap->priv; 889 struct dib0700_adapter_state *st = adap->priv;
852 struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, 890 struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
853 DIBX000_I2C_INTERFACE_TUNER, 1); 891 DIBX000_I2C_INTERFACE_TUNER, 1);
854 892
855 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, 893 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
856 &dib7770p_dib0070_config) == NULL) 894 &dib7770p_dib0070_config) == NULL)
857 return -ENODEV; 895 return -ENODEV;
858 896
859 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params; 897 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
860 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7770_set_param_override; 898 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7770_set_param_override;
861 return 0; 899 return 0;
862} 900}
863 901
864static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap) 902static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
865{ 903{
866 struct dib0700_adapter_state *st = adap->priv; 904 struct dib0700_adapter_state *st = adap->priv;
867 struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1); 905 struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
868 906
869 if (adap->id == 0) { 907 if (adap->id == 0) {
870 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL) 908 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
@@ -882,28 +920,33 @@ static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
882static int stk7700p_pid_filter(struct dvb_usb_adapter *adapter, int index, 920static int stk7700p_pid_filter(struct dvb_usb_adapter *adapter, int index,
883 u16 pid, int onoff) 921 u16 pid, int onoff)
884{ 922{
923 struct dib0700_adapter_state *state = adapter->priv;
885 struct dib0700_state *st = adapter->dev->priv; 924 struct dib0700_state *st = adapter->dev->priv;
925
886 if (st->is_dib7000pc) 926 if (st->is_dib7000pc)
887 return dib7000p_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff); 927 return state->dib7000p_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
888 return dib7000m_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff); 928 return dib7000m_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
889} 929}
890 930
891static int stk7700p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff) 931static int stk7700p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
892{ 932{
893 struct dib0700_state *st = adapter->dev->priv; 933 struct dib0700_state *st = adapter->dev->priv;
934 struct dib0700_adapter_state *state = adapter->priv;
894 if (st->is_dib7000pc) 935 if (st->is_dib7000pc)
895 return dib7000p_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff); 936 return state->dib7000p_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
896 return dib7000m_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff); 937 return dib7000m_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
897} 938}
898 939
899static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff) 940static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
900{ 941{
901 return dib7000p_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff); 942 struct dib0700_adapter_state *state = adapter->priv;
943 return state->dib7000p_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
902} 944}
903 945
904static int stk70x0p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff) 946static int stk70x0p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
905{ 947{
906 return dib7000p_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff); 948 struct dib0700_adapter_state *state = adapter->priv;
949 return state->dib7000p_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
907} 950}
908 951
909static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = { 952static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
@@ -936,6 +979,11 @@ static struct dib7000p_config dib7070p_dib7000p_config = {
936static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap) 979static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
937{ 980{
938 struct usb_device_descriptor *p = &adap->dev->udev->descriptor; 981 struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
982 struct dib0700_adapter_state *state = adap->priv;
983
984 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
985 return -ENODEV;
986
939 if (p->idVendor == cpu_to_le16(USB_VID_PINNACLE) && 987 if (p->idVendor == cpu_to_le16(USB_VID_PINNACLE) &&
940 p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E)) 988 p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
941 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); 989 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
@@ -954,14 +1002,15 @@ static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
954 msleep(10); 1002 msleep(10);
955 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 1003 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
956 1004
957 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 1005 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
958 &dib7070p_dib7000p_config) != 0) { 1006 &dib7070p_dib7000p_config) != 0) {
959 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", 1007 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n",
960 __func__); 1008 __func__);
1009 dvb_detach(&state->dib7000p_ops);
961 return -ENODEV; 1010 return -ENODEV;
962 } 1011 }
963 1012
964 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x80, 1013 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
965 &dib7070p_dib7000p_config); 1014 &dib7070p_dib7000p_config);
966 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 1015 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
967} 1016}
@@ -988,6 +1037,11 @@ static struct dib7000p_config dib7770p_dib7000p_config = {
988static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap) 1037static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap)
989{ 1038{
990 struct usb_device_descriptor *p = &adap->dev->udev->descriptor; 1039 struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
1040 struct dib0700_adapter_state *state = adap->priv;
1041
1042 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
1043 return -ENODEV;
1044
991 if (p->idVendor == cpu_to_le16(USB_VID_PINNACLE) && 1045 if (p->idVendor == cpu_to_le16(USB_VID_PINNACLE) &&
992 p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E)) 1046 p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
993 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); 1047 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
@@ -1006,14 +1060,15 @@ static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap)
1006 msleep(10); 1060 msleep(10);
1007 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 1061 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1008 1062
1009 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 1063 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1010 &dib7770p_dib7000p_config) != 0) { 1064 &dib7770p_dib7000p_config) != 0) {
1011 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", 1065 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n",
1012 __func__); 1066 __func__);
1067 dvb_detach(&state->dib7000p_ops);
1013 return -ENODEV; 1068 return -ENODEV;
1014 } 1069 }
1015 1070
1016 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x80, 1071 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
1017 &dib7770p_dib7000p_config); 1072 &dib7770p_dib7000p_config);
1018 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 1073 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1019} 1074}
@@ -2479,14 +2534,14 @@ static int dib7090_agc_startup(struct dvb_frontend *fe)
2479 memset(&pll, 0, sizeof(struct dibx000_bandwidth_config)); 2534 memset(&pll, 0, sizeof(struct dibx000_bandwidth_config));
2480 dib0090_pwm_gain_reset(fe); 2535 dib0090_pwm_gain_reset(fe);
2481 target = (dib0090_get_wbd_target(fe) * 8 + 1) / 2; 2536 target = (dib0090_get_wbd_target(fe) * 8 + 1) / 2;
2482 dib7000p_set_wbd_ref(fe, target); 2537 state->dib7000p_ops.set_wbd_ref(fe, target);
2483 2538
2484 if (dib7090p_get_best_sampling(fe, &adc) == 0) { 2539 if (dib7090p_get_best_sampling(fe, &adc) == 0) {
2485 pll.pll_ratio = adc.pll_loopdiv; 2540 pll.pll_ratio = adc.pll_loopdiv;
2486 pll.pll_prediv = adc.pll_prediv; 2541 pll.pll_prediv = adc.pll_prediv;
2487 2542
2488 dib7000p_update_pll(fe, &pll); 2543 state->dib7000p_ops.update_pll(fe, &pll);
2489 dib7000p_ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf); 2544 state->dib7000p_ops.ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
2490 } 2545 }
2491 return 0; 2546 return 0;
2492} 2547}
@@ -2501,14 +2556,17 @@ static int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart)
2501 2556
2502static int tfe7790p_update_lna(struct dvb_frontend *fe, u16 agc_global) 2557static int tfe7790p_update_lna(struct dvb_frontend *fe, u16 agc_global)
2503{ 2558{
2559 struct dvb_usb_adapter *adap = fe->dvb->priv;
2560 struct dib0700_adapter_state *state = adap->priv;
2561
2504 deb_info("update LNA: agc global=%i", agc_global); 2562 deb_info("update LNA: agc global=%i", agc_global);
2505 2563
2506 if (agc_global < 25000) { 2564 if (agc_global < 25000) {
2507 dib7000p_set_gpio(fe, 8, 0, 0); 2565 state->dib7000p_ops.set_gpio(fe, 8, 0, 0);
2508 dib7000p_set_agc1_min(fe, 0); 2566 state->dib7000p_ops.set_agc1_min(fe, 0);
2509 } else { 2567 } else {
2510 dib7000p_set_gpio(fe, 8, 0, 1); 2568 state->dib7000p_ops.set_gpio(fe, 8, 0, 1);
2511 dib7000p_set_agc1_min(fe, 32768); 2569 state->dib7000p_ops.set_agc1_min(fe, 32768);
2512 } 2570 }
2513 2571
2514 return 0; 2572 return 0;
@@ -2644,13 +2702,16 @@ static struct dib7000p_config nim7090_dib7000p_config = {
2644 2702
2645static int tfe7090p_pvr_update_lna(struct dvb_frontend *fe, u16 agc_global) 2703static int tfe7090p_pvr_update_lna(struct dvb_frontend *fe, u16 agc_global)
2646{ 2704{
2705 struct dvb_usb_adapter *adap = fe->dvb->priv;
2706 struct dib0700_adapter_state *state = adap->priv;
2707
2647 deb_info("TFE7090P-PVR update LNA: agc global=%i", agc_global); 2708 deb_info("TFE7090P-PVR update LNA: agc global=%i", agc_global);
2648 if (agc_global < 25000) { 2709 if (agc_global < 25000) {
2649 dib7000p_set_gpio(fe, 5, 0, 0); 2710 state->dib7000p_ops.set_gpio(fe, 5, 0, 0);
2650 dib7000p_set_agc1_min(fe, 0); 2711 state->dib7000p_ops.set_agc1_min(fe, 0);
2651 } else { 2712 } else {
2652 dib7000p_set_gpio(fe, 5, 0, 1); 2713 state->dib7000p_ops.set_gpio(fe, 5, 0, 1);
2653 dib7000p_set_agc1_min(fe, 32768); 2714 state->dib7000p_ops.set_agc1_min(fe, 32768);
2654 } 2715 }
2655 2716
2656 return 0; 2717 return 0;
@@ -2714,7 +2775,7 @@ static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
2714 } 2775 }
2715}; 2776};
2716 2777
2717static const struct dib0090_config nim7090_dib0090_config = { 2778static struct dib0090_config nim7090_dib0090_config = {
2718 .io.clock_khz = 12000, 2779 .io.clock_khz = 12000,
2719 .io.pll_bypass = 0, 2780 .io.pll_bypass = 0,
2720 .io.pll_range = 0, 2781 .io.pll_range = 0,
@@ -2722,14 +2783,10 @@ static const struct dib0090_config nim7090_dib0090_config = {
2722 .io.pll_loopdiv = 6, 2783 .io.pll_loopdiv = 6,
2723 .io.adc_clock_ratio = 0, 2784 .io.adc_clock_ratio = 0,
2724 .io.pll_int_loop_filt = 0, 2785 .io.pll_int_loop_filt = 0,
2725 .reset = dib7090_tuner_sleep,
2726 .sleep = dib7090_tuner_sleep,
2727 2786
2728 .freq_offset_khz_uhf = 0, 2787 .freq_offset_khz_uhf = 0,
2729 .freq_offset_khz_vhf = 0, 2788 .freq_offset_khz_vhf = 0,
2730 2789
2731 .get_adc_power = dib7090_get_adc_power,
2732
2733 .clkouttobamse = 1, 2790 .clkouttobamse = 1,
2734 .analog_output = 0, 2791 .analog_output = 0,
2735 2792
@@ -2776,7 +2833,7 @@ static struct dib7000p_config tfe7790p_dib7000p_config = {
2776 .enMpegOutput = 1, 2833 .enMpegOutput = 1,
2777}; 2834};
2778 2835
2779static const struct dib0090_config tfe7790p_dib0090_config = { 2836static struct dib0090_config tfe7790p_dib0090_config = {
2780 .io.clock_khz = 12000, 2837 .io.clock_khz = 12000,
2781 .io.pll_bypass = 0, 2838 .io.pll_bypass = 0,
2782 .io.pll_range = 0, 2839 .io.pll_range = 0,
@@ -2784,14 +2841,10 @@ static const struct dib0090_config tfe7790p_dib0090_config = {
2784 .io.pll_loopdiv = 6, 2841 .io.pll_loopdiv = 6,
2785 .io.adc_clock_ratio = 0, 2842 .io.adc_clock_ratio = 0,
2786 .io.pll_int_loop_filt = 0, 2843 .io.pll_int_loop_filt = 0,
2787 .reset = dib7090_tuner_sleep,
2788 .sleep = dib7090_tuner_sleep,
2789 2844
2790 .freq_offset_khz_uhf = 0, 2845 .freq_offset_khz_uhf = 0,
2791 .freq_offset_khz_vhf = 0, 2846 .freq_offset_khz_vhf = 0,
2792 2847
2793 .get_adc_power = dib7090_get_adc_power,
2794
2795 .clkouttobamse = 1, 2848 .clkouttobamse = 1,
2796 .analog_output = 0, 2849 .analog_output = 0,
2797 2850
@@ -2813,7 +2866,7 @@ static const struct dib0090_config tfe7790p_dib0090_config = {
2813 .force_crystal_mode = 1, 2866 .force_crystal_mode = 1,
2814}; 2867};
2815 2868
2816static const struct dib0090_config tfe7090pvr_dib0090_config[2] = { 2869static struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2817 { 2870 {
2818 .io.clock_khz = 12000, 2871 .io.clock_khz = 12000,
2819 .io.pll_bypass = 0, 2872 .io.pll_bypass = 0,
@@ -2822,14 +2875,10 @@ static const struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2822 .io.pll_loopdiv = 6, 2875 .io.pll_loopdiv = 6,
2823 .io.adc_clock_ratio = 0, 2876 .io.adc_clock_ratio = 0,
2824 .io.pll_int_loop_filt = 0, 2877 .io.pll_int_loop_filt = 0,
2825 .reset = dib7090_tuner_sleep,
2826 .sleep = dib7090_tuner_sleep,
2827 2878
2828 .freq_offset_khz_uhf = 50, 2879 .freq_offset_khz_uhf = 50,
2829 .freq_offset_khz_vhf = 70, 2880 .freq_offset_khz_vhf = 70,
2830 2881
2831 .get_adc_power = dib7090_get_adc_power,
2832
2833 .clkouttobamse = 1, 2882 .clkouttobamse = 1,
2834 .analog_output = 0, 2883 .analog_output = 0,
2835 2884
@@ -2854,14 +2903,10 @@ static const struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2854 .io.pll_loopdiv = 6, 2903 .io.pll_loopdiv = 6,
2855 .io.adc_clock_ratio = 0, 2904 .io.adc_clock_ratio = 0,
2856 .io.pll_int_loop_filt = 0, 2905 .io.pll_int_loop_filt = 0,
2857 .reset = dib7090_tuner_sleep,
2858 .sleep = dib7090_tuner_sleep,
2859 2906
2860 .freq_offset_khz_uhf = -50, 2907 .freq_offset_khz_uhf = -50,
2861 .freq_offset_khz_vhf = -70, 2908 .freq_offset_khz_vhf = -70,
2862 2909
2863 .get_adc_power = dib7090_get_adc_power,
2864
2865 .clkouttobamse = 1, 2910 .clkouttobamse = 1,
2866 .analog_output = 0, 2911 .analog_output = 0,
2867 2912
@@ -2883,6 +2928,11 @@ static const struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2883 2928
2884static int nim7090_frontend_attach(struct dvb_usb_adapter *adap) 2929static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
2885{ 2930{
2931 struct dib0700_adapter_state *state = adap->priv;
2932
2933 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
2934 return -ENODEV;
2935
2886 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); 2936 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2887 msleep(20); 2937 msleep(20);
2888 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1); 2938 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
@@ -2895,11 +2945,12 @@ static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
2895 msleep(20); 2945 msleep(20);
2896 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 2946 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2897 2947
2898 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, &nim7090_dib7000p_config) != 0) { 2948 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, &nim7090_dib7000p_config) != 0) {
2899 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__); 2949 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n", __func__);
2950 dvb_detach(&state->dib7000p_ops);
2900 return -ENODEV; 2951 return -ENODEV;
2901 } 2952 }
2902 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config); 2953 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config);
2903 2954
2904 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 2955 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
2905} 2956}
@@ -2907,12 +2958,16 @@ static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
2907static int nim7090_tuner_attach(struct dvb_usb_adapter *adap) 2958static int nim7090_tuner_attach(struct dvb_usb_adapter *adap)
2908{ 2959{
2909 struct dib0700_adapter_state *st = adap->priv; 2960 struct dib0700_adapter_state *st = adap->priv;
2910 struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe); 2961 struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
2962
2963 nim7090_dib0090_config.reset = st->dib7000p_ops.tuner_sleep,
2964 nim7090_dib0090_config.sleep = st->dib7000p_ops.tuner_sleep,
2965 nim7090_dib0090_config.get_adc_power = st->dib7000p_ops.get_adc_power;
2911 2966
2912 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &nim7090_dib0090_config) == NULL) 2967 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &nim7090_dib0090_config) == NULL)
2913 return -ENODEV; 2968 return -ENODEV;
2914 2969
2915 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1); 2970 st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2916 2971
2917 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params; 2972 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
2918 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup; 2973 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
@@ -2922,6 +2977,10 @@ static int nim7090_tuner_attach(struct dvb_usb_adapter *adap)
2922static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap) 2977static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
2923{ 2978{
2924 struct dib0700_state *st = adap->dev->priv; 2979 struct dib0700_state *st = adap->dev->priv;
2980 struct dib0700_adapter_state *state = adap->priv;
2981
2982 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
2983 return -ENODEV;
2925 2984
2926 /* The TFE7090 requires the dib0700 to not be in master mode */ 2985 /* The TFE7090 requires the dib0700 to not be in master mode */
2927 st->disable_streaming_master_mode = 1; 2986 st->disable_streaming_master_mode = 1;
@@ -2939,17 +2998,18 @@ static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
2939 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 2998 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2940 2999
2941 /* initialize IC 0 */ 3000 /* initialize IC 0 */
2942 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, &tfe7090pvr_dib7000p_config[0]) != 0) { 3001 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, &tfe7090pvr_dib7000p_config[0]) != 0) {
2943 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__); 3002 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n", __func__);
3003 dvb_detach(&state->dib7000p_ops);
2944 return -ENODEV; 3004 return -ENODEV;
2945 } 3005 }
2946 3006
2947 dib0700_set_i2c_speed(adap->dev, 340); 3007 dib0700_set_i2c_speed(adap->dev, 340);
2948 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]); 3008 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]);
2949 if (adap->fe_adap[0].fe == NULL) 3009 if (adap->fe_adap[0].fe == NULL)
2950 return -ENODEV; 3010 return -ENODEV;
2951 3011
2952 dib7090_slave_reset(adap->fe_adap[0].fe); 3012 state->dib7000p_ops.slave_reset(adap->fe_adap[0].fe);
2953 3013
2954 return 0; 3014 return 0;
2955} 3015}
@@ -2957,19 +3017,24 @@ static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
2957static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap) 3017static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap)
2958{ 3018{
2959 struct i2c_adapter *i2c; 3019 struct i2c_adapter *i2c;
3020 struct dib0700_adapter_state *state = adap->priv;
2960 3021
2961 if (adap->dev->adapter[0].fe_adap[0].fe == NULL) { 3022 if (adap->dev->adapter[0].fe_adap[0].fe == NULL) {
2962 err("the master dib7090 has to be initialized first"); 3023 err("the master dib7090 has to be initialized first");
2963 return -ENODEV; /* the master device has not been initialized */ 3024 return -ENODEV; /* the master device has not been initialized */
2964 } 3025 }
2965 3026
2966 i2c = dib7000p_get_i2c_master(adap->dev->adapter[0].fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1); 3027 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
2967 if (dib7000p_i2c_enumeration(i2c, 1, 0x10, &tfe7090pvr_dib7000p_config[1]) != 0) { 3028 return -ENODEV;
2968 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__); 3029
3030 i2c = state->dib7000p_ops.get_i2c_master(adap->dev->adapter[0].fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1);
3031 if (state->dib7000p_ops.i2c_enumeration(i2c, 1, 0x10, &tfe7090pvr_dib7000p_config[1]) != 0) {
3032 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n", __func__);
3033 dvb_detach(&state->dib7000p_ops);
2969 return -ENODEV; 3034 return -ENODEV;
2970 } 3035 }
2971 3036
2972 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, i2c, 0x92, &tfe7090pvr_dib7000p_config[1]); 3037 adap->fe_adap[0].fe = state->dib7000p_ops.init(i2c, 0x92, &tfe7090pvr_dib7000p_config[1]);
2973 dib0700_set_i2c_speed(adap->dev, 200); 3038 dib0700_set_i2c_speed(adap->dev, 200);
2974 3039
2975 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 3040 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
@@ -2978,12 +3043,16 @@ static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap)
2978static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap) 3043static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap)
2979{ 3044{
2980 struct dib0700_adapter_state *st = adap->priv; 3045 struct dib0700_adapter_state *st = adap->priv;
2981 struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe); 3046 struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
3047
3048 tfe7090pvr_dib0090_config[0].reset = st->dib7000p_ops.tuner_sleep;
3049 tfe7090pvr_dib0090_config[0].sleep = st->dib7000p_ops.tuner_sleep;
3050 tfe7090pvr_dib0090_config[0].get_adc_power = st->dib7000p_ops.get_adc_power;
2982 3051
2983 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL) 3052 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL)
2984 return -ENODEV; 3053 return -ENODEV;
2985 3054
2986 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1); 3055 st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2987 3056
2988 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params; 3057 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
2989 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup; 3058 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
@@ -2993,12 +3062,16 @@ static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap)
2993static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap) 3062static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
2994{ 3063{
2995 struct dib0700_adapter_state *st = adap->priv; 3064 struct dib0700_adapter_state *st = adap->priv;
2996 struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe); 3065 struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
3066
3067 tfe7090pvr_dib0090_config[1].reset = st->dib7000p_ops.tuner_sleep;
3068 tfe7090pvr_dib0090_config[1].sleep = st->dib7000p_ops.tuner_sleep;
3069 tfe7090pvr_dib0090_config[1].get_adc_power = st->dib7000p_ops.get_adc_power;
2997 3070
2998 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL) 3071 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL)
2999 return -ENODEV; 3072 return -ENODEV;
3000 3073
3001 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1); 3074 st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3002 3075
3003 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params; 3076 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
3004 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup; 3077 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
@@ -3008,6 +3081,10 @@ static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
3008static int tfe7790p_frontend_attach(struct dvb_usb_adapter *adap) 3081static int tfe7790p_frontend_attach(struct dvb_usb_adapter *adap)
3009{ 3082{
3010 struct dib0700_state *st = adap->dev->priv; 3083 struct dib0700_state *st = adap->dev->priv;
3084 struct dib0700_adapter_state *state = adap->priv;
3085
3086 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3087 return -ENODEV;
3011 3088
3012 /* The TFE7790P requires the dib0700 to not be in master mode */ 3089 /* The TFE7790P requires the dib0700 to not be in master mode */
3013 st->disable_streaming_master_mode = 1; 3090 st->disable_streaming_master_mode = 1;
@@ -3024,13 +3101,14 @@ static int tfe7790p_frontend_attach(struct dvb_usb_adapter *adap)
3024 msleep(20); 3101 msleep(20);
3025 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 3102 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3026 3103
3027 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 3104 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap,
3028 1, 0x10, &tfe7790p_dib7000p_config) != 0) { 3105 1, 0x10, &tfe7790p_dib7000p_config) != 0) {
3029 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", 3106 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n",
3030 __func__); 3107 __func__);
3108 dvb_detach(&state->dib7000p_ops);
3031 return -ENODEV; 3109 return -ENODEV;
3032 } 3110 }
3033 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 3111 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
3034 0x80, &tfe7790p_dib7000p_config); 3112 0x80, &tfe7790p_dib7000p_config);
3035 3113
3036 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 3114 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
@@ -3040,13 +3118,18 @@ static int tfe7790p_tuner_attach(struct dvb_usb_adapter *adap)
3040{ 3118{
3041 struct dib0700_adapter_state *st = adap->priv; 3119 struct dib0700_adapter_state *st = adap->priv;
3042 struct i2c_adapter *tun_i2c = 3120 struct i2c_adapter *tun_i2c =
3043 dib7090_get_i2c_tuner(adap->fe_adap[0].fe); 3121 st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
3122
3123
3124 tfe7790p_dib0090_config.reset = st->dib7000p_ops.tuner_sleep;
3125 tfe7790p_dib0090_config.sleep = st->dib7000p_ops.tuner_sleep;
3126 tfe7790p_dib0090_config.get_adc_power = st->dib7000p_ops.get_adc_power;
3044 3127
3045 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, 3128 if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
3046 &tfe7790p_dib0090_config) == NULL) 3129 &tfe7790p_dib0090_config) == NULL)
3047 return -ENODEV; 3130 return -ENODEV;
3048 3131
3049 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1); 3132 st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3050 3133
3051 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params; 3134 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
3052 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup; 3135 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
@@ -3103,25 +3186,36 @@ static void stk7070pd_init(struct dvb_usb_device *dev)
3103 3186
3104static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap) 3187static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
3105{ 3188{
3189 struct dib0700_adapter_state *state = adap->priv;
3190
3191 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3192 return -ENODEV;
3193
3106 stk7070pd_init(adap->dev); 3194 stk7070pd_init(adap->dev);
3107 3195
3108 msleep(10); 3196 msleep(10);
3109 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 3197 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3110 3198
3111 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, 3199 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
3112 stk7070pd_dib7000p_config) != 0) { 3200 stk7070pd_dib7000p_config) != 0) {
3113 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", 3201 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n",
3114 __func__); 3202 __func__);
3203 dvb_detach(&state->dib7000p_ops);
3115 return -ENODEV; 3204 return -ENODEV;
3116 } 3205 }
3117 3206
3118 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]); 3207 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
3119 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 3208 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3120} 3209}
3121 3210
3122static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap) 3211static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
3123{ 3212{
3124 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]); 3213 struct dib0700_adapter_state *state = adap->priv;
3214
3215 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3216 return -ENODEV;
3217
3218 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
3125 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; 3219 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3126} 3220}
3127 3221
@@ -3164,6 +3258,10 @@ static int novatd_frontend_attach(struct dvb_usb_adapter *adap)
3164{ 3258{
3165 struct dvb_usb_device *dev = adap->dev; 3259 struct dvb_usb_device *dev = adap->dev;
3166 struct dib0700_state *st = dev->priv; 3260 struct dib0700_state *st = dev->priv;
3261 struct dib0700_adapter_state *state = adap->priv;
3262
3263 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3264 return -ENODEV;
3167 3265
3168 if (adap->id == 0) { 3266 if (adap->id == 0) {
3169 stk7070pd_init(dev); 3267 stk7070pd_init(dev);
@@ -3173,15 +3271,16 @@ static int novatd_frontend_attach(struct dvb_usb_adapter *adap)
3173 dib0700_set_gpio(dev, GPIO1, GPIO_OUT, 0); 3271 dib0700_set_gpio(dev, GPIO1, GPIO_OUT, 0);
3174 dib0700_set_gpio(dev, GPIO2, GPIO_OUT, 1); 3272 dib0700_set_gpio(dev, GPIO2, GPIO_OUT, 1);
3175 3273
3176 if (dib7000p_i2c_enumeration(&dev->i2c_adap, 2, 18, 3274 if (state->dib7000p_ops.i2c_enumeration(&dev->i2c_adap, 2, 18,
3177 stk7070pd_dib7000p_config) != 0) { 3275 stk7070pd_dib7000p_config) != 0) {
3178 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", 3276 err("%s: state->dib7000p_ops.i2c_enumeration failed. Cannot continue\n",
3179 __func__); 3277 __func__);
3278 dvb_detach(&state->dib7000p_ops);
3180 return -ENODEV; 3279 return -ENODEV;
3181 } 3280 }
3182 } 3281 }
3183 3282
3184 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &dev->i2c_adap, 3283 adap->fe_adap[0].fe = state->dib7000p_ops.init(&dev->i2c_adap,
3185 adap->id == 0 ? 0x80 : 0x82, 3284 adap->id == 0 ? 0x80 : 0x82,
3186 &stk7070pd_dib7000p_config[adap->id]); 3285 &stk7070pd_dib7000p_config[adap->id]);
3187 3286
@@ -3291,12 +3390,13 @@ static int dib0700_xc4000_tuner_callback(void *priv, int component,
3291 int command, int arg) 3390 int command, int arg)
3292{ 3391{
3293 struct dvb_usb_adapter *adap = priv; 3392 struct dvb_usb_adapter *adap = priv;
3393 struct dib0700_adapter_state *state = adap->priv;
3294 3394
3295 if (command == XC4000_TUNER_RESET) { 3395 if (command == XC4000_TUNER_RESET) {
3296 /* Reset the tuner */ 3396 /* Reset the tuner */
3297 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 0); 3397 state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
3298 msleep(10); 3398 msleep(10);
3299 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1); 3399 state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3300 } else { 3400 } else {
3301 err("xc4000: unknown tuner callback command: %d\n", command); 3401 err("xc4000: unknown tuner callback command: %d\n", command);
3302 return -EINVAL; 3402 return -EINVAL;
@@ -3374,6 +3474,10 @@ static struct dib7000p_config pctv_340e_config = {
3374static int pctv340e_frontend_attach(struct dvb_usb_adapter *adap) 3474static int pctv340e_frontend_attach(struct dvb_usb_adapter *adap)
3375{ 3475{
3376 struct dib0700_state *st = adap->dev->priv; 3476 struct dib0700_state *st = adap->dev->priv;
3477 struct dib0700_adapter_state *state = adap->priv;
3478
3479 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3480 return -ENODEV;
3377 3481
3378 /* Power Supply on */ 3482 /* Power Supply on */
3379 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); 3483 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
@@ -3397,12 +3501,13 @@ static int pctv340e_frontend_attach(struct dvb_usb_adapter *adap)
3397 3501
3398 msleep(500); 3502 msleep(500);
3399 3503
3400 if (dib7000pc_detection(&adap->dev->i2c_adap) == 0) { 3504 if (state->dib7000p_ops.dib7000pc_detection(&adap->dev->i2c_adap) == 0) {
3401 /* Demodulator not found for some reason? */ 3505 /* Demodulator not found for some reason? */
3506 dvb_detach(&state->dib7000p_ops);
3402 return -ENODEV; 3507 return -ENODEV;
3403 } 3508 }
3404 3509
3405 adap->fe_adap[0].fe = dvb_attach(dib7000p_init, &adap->dev->i2c_adap, 0x12, 3510 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x12,
3406 &pctv_340e_config); 3511 &pctv_340e_config);
3407 st->is_dib7000pc = 1; 3512 st->is_dib7000pc = 1;
3408 3513
@@ -3420,9 +3525,10 @@ static struct xc4000_config dib7000p_xc4000_tunerconfig = {
3420static int xc4000_tuner_attach(struct dvb_usb_adapter *adap) 3525static int xc4000_tuner_attach(struct dvb_usb_adapter *adap)
3421{ 3526{
3422 struct i2c_adapter *tun_i2c; 3527 struct i2c_adapter *tun_i2c;
3528 struct dib0700_adapter_state *state = adap->priv;
3423 3529
3424 /* The xc4000 is not on the main i2c bus */ 3530 /* The xc4000 is not on the main i2c bus */
3425 tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, 3531 tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
3426 DIBX000_I2C_INTERFACE_TUNER, 1); 3532 DIBX000_I2C_INTERFACE_TUNER, 1);
3427 if (tun_i2c == NULL) { 3533 if (tun_i2c == NULL) {
3428 printk(KERN_ERR "Could not reach tuner i2c bus\n"); 3534 printk(KERN_ERR "Could not reach tuner i2c bus\n");