aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/tuners
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/common/tuners')
-rw-r--r--drivers/media/common/tuners/mt2060.c38
-rw-r--r--drivers/media/common/tuners/mxl5007t.c1
-rw-r--r--drivers/media/common/tuners/tda18271-fe.c1
-rw-r--r--drivers/media/common/tuners/tda827x.c12
-rw-r--r--drivers/media/common/tuners/tda827x.h1
-rw-r--r--drivers/media/common/tuners/tda8290.c4
-rw-r--r--drivers/media/common/tuners/tda8290.h1
-rw-r--r--drivers/media/common/tuners/tda9887.c1
-rw-r--r--drivers/media/common/tuners/tuner-simple.c3
-rw-r--r--drivers/media/common/tuners/tuner-types.c22
-rw-r--r--drivers/media/common/tuners/tuner-xc2028.c74
-rw-r--r--drivers/media/common/tuners/tuner-xc2028.h11
-rw-r--r--drivers/media/common/tuners/xc5000.c109
-rw-r--r--drivers/media/common/tuners/xc5000.h8
-rw-r--r--drivers/media/common/tuners/xc5000_priv.h37
15 files changed, 200 insertions, 123 deletions
diff --git a/drivers/media/common/tuners/mt2060.c b/drivers/media/common/tuners/mt2060.c
index 1305b0e63ce5..12206d75dd4e 100644
--- a/drivers/media/common/tuners/mt2060.c
+++ b/drivers/media/common/tuners/mt2060.c
@@ -170,6 +170,9 @@ static int mt2060_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
170 b[0] = REG_LO1B1; 170 b[0] = REG_LO1B1;
171 b[1] = 0xFF; 171 b[1] = 0xFF;
172 172
173 if (fe->ops.i2c_gate_ctrl)
174 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
175
173 mt2060_writeregs(priv,b,2); 176 mt2060_writeregs(priv,b,2);
174 177
175 freq = params->frequency / 1000; // Hz -> kHz 178 freq = params->frequency / 1000; // Hz -> kHz
@@ -233,6 +236,9 @@ static int mt2060_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
233 i++; 236 i++;
234 } while (i<10); 237 } while (i<10);
235 238
239 if (fe->ops.i2c_gate_ctrl)
240 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
241
236 return ret; 242 return ret;
237} 243}
238 244
@@ -296,13 +302,35 @@ static int mt2060_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
296static int mt2060_init(struct dvb_frontend *fe) 302static int mt2060_init(struct dvb_frontend *fe)
297{ 303{
298 struct mt2060_priv *priv = fe->tuner_priv; 304 struct mt2060_priv *priv = fe->tuner_priv;
299 return mt2060_writereg(priv, REG_VGAG, (priv->cfg->clock_out << 6) | 0x33); 305 int ret;
306
307 if (fe->ops.i2c_gate_ctrl)
308 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
309
310 ret = mt2060_writereg(priv, REG_VGAG,
311 (priv->cfg->clock_out << 6) | 0x33);
312
313 if (fe->ops.i2c_gate_ctrl)
314 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
315
316 return ret;
300} 317}
301 318
302static int mt2060_sleep(struct dvb_frontend *fe) 319static int mt2060_sleep(struct dvb_frontend *fe)
303{ 320{
304 struct mt2060_priv *priv = fe->tuner_priv; 321 struct mt2060_priv *priv = fe->tuner_priv;
305 return mt2060_writereg(priv, REG_VGAG, (priv->cfg->clock_out << 6) | 0x30); 322 int ret;
323
324 if (fe->ops.i2c_gate_ctrl)
325 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
326
327 ret = mt2060_writereg(priv, REG_VGAG,
328 (priv->cfg->clock_out << 6) | 0x30);
329
330 if (fe->ops.i2c_gate_ctrl)
331 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
332
333 return ret;
306} 334}
307 335
308static int mt2060_release(struct dvb_frontend *fe) 336static int mt2060_release(struct dvb_frontend *fe)
@@ -344,6 +372,9 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter
344 priv->i2c = i2c; 372 priv->i2c = i2c;
345 priv->if1_freq = if1; 373 priv->if1_freq = if1;
346 374
375 if (fe->ops.i2c_gate_ctrl)
376 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
377
347 if (mt2060_readreg(priv,REG_PART_REV,&id) != 0) { 378 if (mt2060_readreg(priv,REG_PART_REV,&id) != 0) {
348 kfree(priv); 379 kfree(priv);
349 return NULL; 380 return NULL;
@@ -360,6 +391,9 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter
360 391
361 mt2060_calibrate(priv); 392 mt2060_calibrate(priv);
362 393
394 if (fe->ops.i2c_gate_ctrl)
395 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
396
363 return fe; 397 return fe;
364} 398}
365EXPORT_SYMBOL(mt2060_attach); 399EXPORT_SYMBOL(mt2060_attach);
diff --git a/drivers/media/common/tuners/mxl5007t.c b/drivers/media/common/tuners/mxl5007t.c
index cb25e43502fe..64379f2bf237 100644
--- a/drivers/media/common/tuners/mxl5007t.c
+++ b/drivers/media/common/tuners/mxl5007t.c
@@ -979,7 +979,6 @@ struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
979 switch (instance) { 979 switch (instance) {
980 case 0: 980 case 0:
981 goto fail; 981 goto fail;
982 break;
983 case 1: 982 case 1:
984 /* new tuner instance */ 983 /* new tuner instance */
985 state->config = cfg; 984 state->config = cfg;
diff --git a/drivers/media/common/tuners/tda18271-fe.c b/drivers/media/common/tuners/tda18271-fe.c
index 93063c6fbbf6..1b48b5d0bf1e 100644
--- a/drivers/media/common/tuners/tda18271-fe.c
+++ b/drivers/media/common/tuners/tda18271-fe.c
@@ -1155,7 +1155,6 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1155 switch (instance) { 1155 switch (instance) {
1156 case 0: 1156 case 0:
1157 goto fail; 1157 goto fail;
1158 break;
1159 case 1: 1158 case 1:
1160 /* new tuner instance */ 1159 /* new tuner instance */
1161 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO; 1160 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
diff --git a/drivers/media/common/tuners/tda827x.c b/drivers/media/common/tuners/tda827x.c
index 8555d9cf9051..4a74f65e759a 100644
--- a/drivers/media/common/tuners/tda827x.c
+++ b/drivers/media/common/tuners/tda827x.c
@@ -447,17 +447,19 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
447 else 447 else
448 arg = 0; 448 arg = 0;
449 } 449 }
450 if (priv->cfg->tuner_callback) 450 if (fe->callback)
451 priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 451 fe->callback(priv->i2c_adap->algo_data,
452 gp_func, arg); 452 DVB_FRONTEND_COMPONENT_TUNER,
453 gp_func, arg);
453 buf[1] = high ? 0 : 1; 454 buf[1] = high ? 0 : 1;
454 if (priv->cfg->config == 2) 455 if (priv->cfg->config == 2)
455 buf[1] = high ? 1 : 0; 456 buf[1] = high ? 1 : 0;
456 i2c_transfer(priv->i2c_adap, &msg, 1); 457 i2c_transfer(priv->i2c_adap, &msg, 1);
457 break; 458 break;
458 case 3: /* switch with GPIO of saa713x */ 459 case 3: /* switch with GPIO of saa713x */
459 if (priv->cfg->tuner_callback) 460 if (fe->callback)
460 priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 0, high); 461 fe->callback(priv->i2c_adap->algo_data,
462 DVB_FRONTEND_COMPONENT_TUNER, 0, high);
461 break; 463 break;
462 } 464 }
463} 465}
diff --git a/drivers/media/common/tuners/tda827x.h b/drivers/media/common/tuners/tda827x.h
index 7850a9a1dc8f..7d72ce0a0c2d 100644
--- a/drivers/media/common/tuners/tda827x.h
+++ b/drivers/media/common/tuners/tda827x.h
@@ -36,7 +36,6 @@ struct tda827x_config
36 /* interface to tda829x driver */ 36 /* interface to tda829x driver */
37 unsigned int config; 37 unsigned int config;
38 int switch_addr; 38 int switch_addr;
39 int (*tuner_callback) (void *dev, int command, int arg);
40 39
41 void (*agcf)(struct dvb_frontend *fe); 40 void (*agcf)(struct dvb_frontend *fe);
42}; 41};
diff --git a/drivers/media/common/tuners/tda8290.c b/drivers/media/common/tuners/tda8290.c
index 91204d3f282d..c112bdd4e0f0 100644
--- a/drivers/media/common/tuners/tda8290.c
+++ b/drivers/media/common/tuners/tda8290.c
@@ -672,10 +672,8 @@ struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
672 priv->i2c_props.addr = i2c_addr; 672 priv->i2c_props.addr = i2c_addr;
673 priv->i2c_props.adap = i2c_adap; 673 priv->i2c_props.adap = i2c_adap;
674 priv->i2c_props.name = "tda829x"; 674 priv->i2c_props.name = "tda829x";
675 if (cfg) { 675 if (cfg)
676 priv->cfg.config = cfg->lna_cfg; 676 priv->cfg.config = cfg->lna_cfg;
677 priv->cfg.tuner_callback = cfg->tuner_callback;
678 }
679 677
680 if (tda8290_probe(&priv->i2c_props) == 0) { 678 if (tda8290_probe(&priv->i2c_props) == 0) {
681 priv->ver = TDA8290; 679 priv->ver = TDA8290;
diff --git a/drivers/media/common/tuners/tda8290.h b/drivers/media/common/tuners/tda8290.h
index aa074f3f0c07..7e288b26fcc3 100644
--- a/drivers/media/common/tuners/tda8290.h
+++ b/drivers/media/common/tuners/tda8290.h
@@ -22,7 +22,6 @@
22 22
23struct tda829x_config { 23struct tda829x_config {
24 unsigned int lna_cfg; 24 unsigned int lna_cfg;
25 int (*tuner_callback) (void *dev, int command, int arg);
26 25
27 unsigned int probe_tuner:1; 26 unsigned int probe_tuner:1;
28#define TDA829X_PROBE_TUNER 0 27#define TDA829X_PROBE_TUNER 0
diff --git a/drivers/media/common/tuners/tda9887.c b/drivers/media/common/tuners/tda9887.c
index 72abf0b73486..ff1788cc5d48 100644
--- a/drivers/media/common/tuners/tda9887.c
+++ b/drivers/media/common/tuners/tda9887.c
@@ -686,7 +686,6 @@ struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
686 case 0: 686 case 0:
687 mutex_unlock(&tda9887_list_mutex); 687 mutex_unlock(&tda9887_list_mutex);
688 return NULL; 688 return NULL;
689 break;
690 case 1: 689 case 1:
691 fe->analog_demod_priv = priv; 690 fe->analog_demod_priv = priv;
692 priv->mode = T_STANDBY; 691 priv->mode = T_STANDBY;
diff --git a/drivers/media/common/tuners/tuner-simple.c b/drivers/media/common/tuners/tuner-simple.c
index aa773a658a2a..2a1aac1cc755 100644
--- a/drivers/media/common/tuners/tuner-simple.c
+++ b/drivers/media/common/tuners/tuner-simple.c
@@ -142,6 +142,7 @@ static inline int tuner_stereo(const int type, const int status)
142 case TUNER_PHILIPS_FM1236_MK3: 142 case TUNER_PHILIPS_FM1236_MK3:
143 case TUNER_PHILIPS_FM1256_IH3: 143 case TUNER_PHILIPS_FM1256_IH3:
144 case TUNER_LG_NTSC_TAPE: 144 case TUNER_LG_NTSC_TAPE:
145 case TUNER_TCL_MF02GIP_5N:
145 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3); 146 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
146 default: 147 default:
147 return status & TUNER_STEREO; 148 return status & TUNER_STEREO;
@@ -494,6 +495,7 @@ static int simple_radio_bandswitch(struct dvb_frontend *fe, u8 *buffer)
494 case TUNER_PHILIPS_FMD1216ME_MK3: 495 case TUNER_PHILIPS_FMD1216ME_MK3:
495 case TUNER_LG_NTSC_TAPE: 496 case TUNER_LG_NTSC_TAPE:
496 case TUNER_PHILIPS_FM1256_IH3: 497 case TUNER_PHILIPS_FM1256_IH3:
498 case TUNER_TCL_MF02GIP_5N:
497 buffer[3] = 0x19; 499 buffer[3] = 0x19;
498 break; 500 break;
499 case TUNER_TNF_5335MF: 501 case TUNER_TNF_5335MF:
@@ -1038,7 +1040,6 @@ struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
1038 case 0: 1040 case 0:
1039 mutex_unlock(&tuner_simple_list_mutex); 1041 mutex_unlock(&tuner_simple_list_mutex);
1040 return NULL; 1042 return NULL;
1041 break;
1042 case 1: 1043 case 1:
1043 fe->tuner_priv = priv; 1044 fe->tuner_priv = priv;
1044 1045
diff --git a/drivers/media/common/tuners/tuner-types.c b/drivers/media/common/tuners/tuner-types.c
index 10dddca8b5d1..04961a1f44be 100644
--- a/drivers/media/common/tuners/tuner-types.c
+++ b/drivers/media/common/tuners/tuner-types.c
@@ -1216,6 +1216,23 @@ static struct tuner_params tuner_samsung_tcpg_6121p30a_params[] = {
1216 }, 1216 },
1217}; 1217};
1218 1218
1219/* ------------ TUNER_TCL_MF02GIP-5N-E - TCL MF02GIP-5N ------------ */
1220
1221static struct tuner_range tuner_tcl_mf02gip_5n_ntsc_ranges[] = {
1222 { 16 * 172.00 /*MHz*/, 0x8e, 0x01, },
1223 { 16 * 448.00 /*MHz*/, 0x8e, 0x02, },
1224 { 16 * 999.99 , 0x8e, 0x04, },
1225};
1226
1227static struct tuner_params tuner_tcl_mf02gip_5n_params[] = {
1228 {
1229 .type = TUNER_PARAM_TYPE_NTSC,
1230 .ranges = tuner_tcl_mf02gip_5n_ntsc_ranges,
1231 .count = ARRAY_SIZE(tuner_tcl_mf02gip_5n_ntsc_ranges),
1232 .cb_first_if_lower_freq = 1,
1233 },
1234};
1235
1219/* --------------------------------------------------------------------- */ 1236/* --------------------------------------------------------------------- */
1220 1237
1221struct tunertype tuners[] = { 1238struct tunertype tuners[] = {
@@ -1641,6 +1658,11 @@ struct tunertype tuners[] = {
1641 .name = "Xceive 5000 tuner", 1658 .name = "Xceive 5000 tuner",
1642 /* see xc5000.c for details */ 1659 /* see xc5000.c for details */
1643 }, 1660 },
1661 [TUNER_TCL_MF02GIP_5N] = { /* TCL tuner MF02GIP-5N-E */
1662 .name = "TCL tuner MF02GIP-5N-E",
1663 .params = tuner_tcl_mf02gip_5n_params,
1664 .count = ARRAY_SIZE(tuner_tcl_mf02gip_5n_params),
1665 },
1644}; 1666};
1645EXPORT_SYMBOL(tuners); 1667EXPORT_SYMBOL(tuners);
1646 1668
diff --git a/drivers/media/common/tuners/tuner-xc2028.c b/drivers/media/common/tuners/tuner-xc2028.c
index 4dd1d2421cc5..b65e6803e6c6 100644
--- a/drivers/media/common/tuners/tuner-xc2028.c
+++ b/drivers/media/common/tuners/tuner-xc2028.c
@@ -71,9 +71,6 @@ struct firmware_properties {
71struct xc2028_data { 71struct xc2028_data {
72 struct list_head hybrid_tuner_instance_list; 72 struct list_head hybrid_tuner_instance_list;
73 struct tuner_i2c_props i2c_props; 73 struct tuner_i2c_props i2c_props;
74 int (*tuner_callback) (void *dev,
75 int command, int arg);
76 void *video_dev;
77 __u32 frequency; 74 __u32 frequency;
78 75
79 struct firmware_description *firm; 76 struct firmware_description *firm;
@@ -492,6 +489,23 @@ ret:
492 return i; 489 return i;
493} 490}
494 491
492static inline int do_tuner_callback(struct dvb_frontend *fe, int cmd, int arg)
493{
494 struct xc2028_data *priv = fe->tuner_priv;
495
496 /* analog side (tuner-core) uses i2c_adap->algo_data.
497 * digital side is not guaranteed to have algo_data defined.
498 *
499 * digital side will always have fe->dvb defined.
500 * analog side (tuner-core) doesn't (yet) define fe->dvb.
501 */
502
503 return (!fe->callback) ? -EINVAL :
504 fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
505 fe->dvb->priv : priv->i2c_props.adap->algo_data,
506 DVB_FRONTEND_COMPONENT_TUNER, cmd, arg);
507}
508
495static int load_firmware(struct dvb_frontend *fe, unsigned int type, 509static int load_firmware(struct dvb_frontend *fe, unsigned int type,
496 v4l2_std_id *id) 510 v4l2_std_id *id)
497{ 511{
@@ -530,8 +544,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
530 544
531 if (!size) { 545 if (!size) {
532 /* Special callback command received */ 546 /* Special callback command received */
533 rc = priv->tuner_callback(priv->video_dev, 547 rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
534 XC2028_TUNER_RESET, 0);
535 if (rc < 0) { 548 if (rc < 0) {
536 tuner_err("Error at RESET code %d\n", 549 tuner_err("Error at RESET code %d\n",
537 (*p) & 0x7f); 550 (*p) & 0x7f);
@@ -542,8 +555,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
542 if (size >= 0xff00) { 555 if (size >= 0xff00) {
543 switch (size) { 556 switch (size) {
544 case 0xff00: 557 case 0xff00:
545 rc = priv->tuner_callback(priv->video_dev, 558 rc = do_tuner_callback(fe, XC2028_RESET_CLK, 0);
546 XC2028_RESET_CLK, 0);
547 if (rc < 0) { 559 if (rc < 0) {
548 tuner_err("Error at RESET code %d\n", 560 tuner_err("Error at RESET code %d\n",
549 (*p) & 0x7f); 561 (*p) & 0x7f);
@@ -715,8 +727,7 @@ retry:
715 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw)); 727 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
716 728
717 /* Reset is needed before loading firmware */ 729 /* Reset is needed before loading firmware */
718 rc = priv->tuner_callback(priv->video_dev, 730 rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
719 XC2028_TUNER_RESET, 0);
720 if (rc < 0) 731 if (rc < 0)
721 goto fail; 732 goto fail;
722 733
@@ -933,7 +944,7 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
933 The reset CLK is needed only with tm6000. 944 The reset CLK is needed only with tm6000.
934 Driver should work fine even if this fails. 945 Driver should work fine even if this fails.
935 */ 946 */
936 priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1); 947 do_tuner_callback(fe, XC2028_RESET_CLK, 1);
937 948
938 msleep(10); 949 msleep(10);
939 950
@@ -1002,11 +1013,6 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1002 1013
1003 tuner_dbg("%s called\n", __func__); 1014 tuner_dbg("%s called\n", __func__);
1004 1015
1005 if (priv->ctrl.d2633)
1006 type |= D2633;
1007 else
1008 type |= D2620;
1009
1010 switch(fe->ops.info.type) { 1016 switch(fe->ops.info.type) {
1011 case FE_OFDM: 1017 case FE_OFDM:
1012 bw = p->u.ofdm.bandwidth; 1018 bw = p->u.ofdm.bandwidth;
@@ -1021,10 +1027,8 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1021 break; 1027 break;
1022 case FE_ATSC: 1028 case FE_ATSC:
1023 bw = BANDWIDTH_6_MHZ; 1029 bw = BANDWIDTH_6_MHZ;
1024 /* The only ATSC firmware (at least on v2.7) is D2633, 1030 /* The only ATSC firmware (at least on v2.7) is D2633 */
1025 so overrides ctrl->d2633 */ 1031 type |= ATSC | D2633;
1026 type |= ATSC| D2633;
1027 type &= ~D2620;
1028 break; 1032 break;
1029 /* DVB-S is not supported */ 1033 /* DVB-S is not supported */
1030 default: 1034 default:
@@ -1057,6 +1061,28 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1057 tuner_err("error: bandwidth not supported.\n"); 1061 tuner_err("error: bandwidth not supported.\n");
1058 }; 1062 };
1059 1063
1064 /*
1065 Selects between D2633 or D2620 firmware.
1066 It doesn't make sense for ATSC, since it should be D2633 on all cases
1067 */
1068 if (fe->ops.info.type != FE_ATSC) {
1069 switch (priv->ctrl.type) {
1070 case XC2028_D2633:
1071 type |= D2633;
1072 break;
1073 case XC2028_D2620:
1074 type |= D2620;
1075 break;
1076 case XC2028_AUTO:
1077 default:
1078 /* Zarlink seems to need D2633 */
1079 if (priv->ctrl.demod == XC3028_FE_ZARLINK456)
1080 type |= D2633;
1081 else
1082 type |= D2620;
1083 }
1084 }
1085
1060 /* All S-code tables need a 200kHz shift */ 1086 /* All S-code tables need a 200kHz shift */
1061 if (priv->ctrl.demod) 1087 if (priv->ctrl.demod)
1062 demod = priv->ctrl.demod + 200; 1088 demod = priv->ctrl.demod + 200;
@@ -1177,20 +1203,10 @@ struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
1177 break; 1203 break;
1178 case 1: 1204 case 1:
1179 /* new tuner instance */ 1205 /* new tuner instance */
1180 priv->tuner_callback = cfg->callback;
1181 priv->ctrl.max_len = 13; 1206 priv->ctrl.max_len = 13;
1182 1207
1183 mutex_init(&priv->lock); 1208 mutex_init(&priv->lock);
1184 1209
1185 /* analog side (tuner-core) uses i2c_adap->algo_data.
1186 * digital side is not guaranteed to have algo_data defined.
1187 *
1188 * digital side will always have fe->dvb defined.
1189 * analog side (tuner-core) doesn't (yet) define fe->dvb.
1190 */
1191 priv->video_dev = ((fe->dvb) && (fe->dvb->priv)) ?
1192 fe->dvb->priv : cfg->i2c_adap->algo_data;
1193
1194 fe->tuner_priv = priv; 1210 fe->tuner_priv = priv;
1195 break; 1211 break;
1196 case 2: 1212 case 2:
diff --git a/drivers/media/common/tuners/tuner-xc2028.h b/drivers/media/common/tuners/tuner-xc2028.h
index 216025cf5d4b..19de7928a74e 100644
--- a/drivers/media/common/tuners/tuner-xc2028.h
+++ b/drivers/media/common/tuners/tuner-xc2028.h
@@ -10,6 +10,7 @@
10#include "dvb_frontend.h" 10#include "dvb_frontend.h"
11 11
12#define XC2028_DEFAULT_FIRMWARE "xc3028-v27.fw" 12#define XC2028_DEFAULT_FIRMWARE "xc3028-v27.fw"
13#define XC3028L_DEFAULT_FIRMWARE "xc3028L-v36.fw"
13 14
14/* Dmoduler IF (kHz) */ 15/* Dmoduler IF (kHz) */
15#define XC3028_FE_DEFAULT 0 /* Don't load SCODE */ 16#define XC3028_FE_DEFAULT 0 /* Don't load SCODE */
@@ -23,24 +24,28 @@
23#define XC3028_FE_ZARLINK456 4560 24#define XC3028_FE_ZARLINK456 4560
24#define XC3028_FE_CHINA 5200 25#define XC3028_FE_CHINA 5200
25 26
27enum firmware_type {
28 XC2028_AUTO = 0, /* By default, auto-detects */
29 XC2028_D2633,
30 XC2028_D2620,
31};
32
26struct xc2028_ctrl { 33struct xc2028_ctrl {
27 char *fname; 34 char *fname;
28 int max_len; 35 int max_len;
29 unsigned int scode_table; 36 unsigned int scode_table;
30 unsigned int mts :1; 37 unsigned int mts :1;
31 unsigned int d2633 :1;
32 unsigned int input1:1; 38 unsigned int input1:1;
33 unsigned int vhfbw7:1; 39 unsigned int vhfbw7:1;
34 unsigned int uhfbw8:1; 40 unsigned int uhfbw8:1;
35 unsigned int demod; 41 unsigned int demod;
42 enum firmware_type type:2;
36}; 43};
37 44
38struct xc2028_config { 45struct xc2028_config {
39 struct i2c_adapter *i2c_adap; 46 struct i2c_adapter *i2c_adap;
40 u8 i2c_addr; 47 u8 i2c_addr;
41 void *video_dev;
42 struct xc2028_ctrl *ctrl; 48 struct xc2028_ctrl *ctrl;
43 int (*callback) (void *dev, int command, int arg);
44}; 49};
45 50
46/* xc2028 commands for callback */ 51/* xc2028 commands for callback */
diff --git a/drivers/media/common/tuners/xc5000.c b/drivers/media/common/tuners/xc5000.c
index dcddfa803a75..f9c2bb917f54 100644
--- a/drivers/media/common/tuners/xc5000.c
+++ b/drivers/media/common/tuners/xc5000.c
@@ -30,7 +30,7 @@
30#include "dvb_frontend.h" 30#include "dvb_frontend.h"
31 31
32#include "xc5000.h" 32#include "xc5000.h"
33#include "xc5000_priv.h" 33#include "tuner-i2c.h"
34 34
35static int debug; 35static int debug;
36module_param(debug, int, 0644); 36module_param(debug, int, 0644);
@@ -40,12 +40,26 @@ static int xc5000_load_fw_on_attach;
40module_param_named(init_fw, xc5000_load_fw_on_attach, int, 0644); 40module_param_named(init_fw, xc5000_load_fw_on_attach, int, 0644);
41MODULE_PARM_DESC(init_fw, "Load firmware during driver initialization."); 41MODULE_PARM_DESC(init_fw, "Load firmware during driver initialization.");
42 42
43static DEFINE_MUTEX(xc5000_list_mutex);
44static LIST_HEAD(hybrid_tuner_instance_list);
45
43#define dprintk(level,fmt, arg...) if (debug >= level) \ 46#define dprintk(level,fmt, arg...) if (debug >= level) \
44 printk(KERN_INFO "%s: " fmt, "xc5000", ## arg) 47 printk(KERN_INFO "%s: " fmt, "xc5000", ## arg)
45 48
46#define XC5000_DEFAULT_FIRMWARE "dvb-fe-xc5000-1.1.fw" 49#define XC5000_DEFAULT_FIRMWARE "dvb-fe-xc5000-1.1.fw"
47#define XC5000_DEFAULT_FIRMWARE_SIZE 12332 50#define XC5000_DEFAULT_FIRMWARE_SIZE 12332
48 51
52struct xc5000_priv {
53 struct tuner_i2c_props i2c_props;
54 struct list_head hybrid_tuner_instance_list;
55
56 u32 if_khz;
57 u32 freq_hz;
58 u32 bandwidth;
59 u8 video_standard;
60 u8 rf_mode;
61};
62
49/* Misc Defines */ 63/* Misc Defines */
50#define MAX_TV_STANDARD 23 64#define MAX_TV_STANDARD 23
51#define XC_MAX_I2C_WRITE_LENGTH 64 65#define XC_MAX_I2C_WRITE_LENGTH 64
@@ -216,9 +230,12 @@ static void xc5000_TunerReset(struct dvb_frontend *fe)
216 230
217 dprintk(1, "%s()\n", __func__); 231 dprintk(1, "%s()\n", __func__);
218 232
219 if (priv->cfg->tuner_callback) { 233 if (fe->callback) {
220 ret = priv->cfg->tuner_callback(priv->devptr, 234 ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
221 XC5000_TUNER_RESET, 0); 235 fe->dvb->priv :
236 priv->i2c_props.adap->algo_data,
237 DVB_FRONTEND_COMPONENT_TUNER,
238 XC5000_TUNER_RESET, 0);
222 if (ret) 239 if (ret)
223 printk(KERN_ERR "xc5000: reset failed\n"); 240 printk(KERN_ERR "xc5000: reset failed\n");
224 } else 241 } else
@@ -509,13 +526,13 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
509 u8 buf[2] = { reg >> 8, reg & 0xff }; 526 u8 buf[2] = { reg >> 8, reg & 0xff };
510 u8 bval[2] = { 0, 0 }; 527 u8 bval[2] = { 0, 0 };
511 struct i2c_msg msg[2] = { 528 struct i2c_msg msg[2] = {
512 { .addr = priv->cfg->i2c_address, 529 { .addr = priv->i2c_props.addr,
513 .flags = 0, .buf = &buf[0], .len = 2 }, 530 .flags = 0, .buf = &buf[0], .len = 2 },
514 { .addr = priv->cfg->i2c_address, 531 { .addr = priv->i2c_props.addr,
515 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 }, 532 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
516 }; 533 };
517 534
518 if (i2c_transfer(priv->i2c, msg, 2) != 2) { 535 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
519 printk(KERN_WARNING "xc5000: I2C read failed\n"); 536 printk(KERN_WARNING "xc5000: I2C read failed\n");
520 return -EREMOTEIO; 537 return -EREMOTEIO;
521 } 538 }
@@ -526,10 +543,10 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
526 543
527static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len) 544static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len)
528{ 545{
529 struct i2c_msg msg = { .addr = priv->cfg->i2c_address, 546 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
530 .flags = 0, .buf = buf, .len = len }; 547 .flags = 0, .buf = buf, .len = len };
531 548
532 if (i2c_transfer(priv->i2c, &msg, 1) != 1) { 549 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
533 printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n", 550 printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n",
534 (int)len); 551 (int)len);
535 return -EREMOTEIO; 552 return -EREMOTEIO;
@@ -539,10 +556,10 @@ static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len)
539 556
540static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len) 557static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len)
541{ 558{
542 struct i2c_msg msg = { .addr = priv->cfg->i2c_address, 559 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
543 .flags = I2C_M_RD, .buf = buf, .len = len }; 560 .flags = I2C_M_RD, .buf = buf, .len = len };
544 561
545 if (i2c_transfer(priv->i2c, &msg, 1) != 1) { 562 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
546 printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n",(int)len); 563 printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n",(int)len);
547 return -EREMOTEIO; 564 return -EREMOTEIO;
548 } 565 }
@@ -559,7 +576,7 @@ static int xc5000_fwupload(struct dvb_frontend* fe)
559 printk(KERN_INFO "xc5000: waiting for firmware upload (%s)...\n", 576 printk(KERN_INFO "xc5000: waiting for firmware upload (%s)...\n",
560 XC5000_DEFAULT_FIRMWARE); 577 XC5000_DEFAULT_FIRMWARE);
561 578
562 ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE, &priv->i2c->dev); 579 ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE, &priv->i2c_props.adap->dev);
563 if (ret) { 580 if (ret) {
564 printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n"); 581 printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n");
565 ret = XC_RESULT_RESET_FAILURE; 582 ret = XC_RESULT_RESET_FAILURE;
@@ -675,10 +692,10 @@ static int xc5000_set_params(struct dvb_frontend *fe,
675 return -EREMOTEIO; 692 return -EREMOTEIO;
676 } 693 }
677 694
678 ret = xc_set_IF_frequency(priv, priv->cfg->if_khz); 695 ret = xc_set_IF_frequency(priv, priv->if_khz);
679 if (ret != XC_RESULT_SUCCESS) { 696 if (ret != XC_RESULT_SUCCESS) {
680 printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n", 697 printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",
681 priv->cfg->if_khz); 698 priv->if_khz);
682 return -EIO; 699 return -EIO;
683 } 700 }
684 701
@@ -897,9 +914,19 @@ static int xc5000_init(struct dvb_frontend *fe)
897 914
898static int xc5000_release(struct dvb_frontend *fe) 915static int xc5000_release(struct dvb_frontend *fe)
899{ 916{
917 struct xc5000_priv *priv = fe->tuner_priv;
918
900 dprintk(1, "%s()\n", __func__); 919 dprintk(1, "%s()\n", __func__);
901 kfree(fe->tuner_priv); 920
921 mutex_lock(&xc5000_list_mutex);
922
923 if (priv)
924 hybrid_tuner_release_state(priv);
925
926 mutex_unlock(&xc5000_list_mutex);
927
902 fe->tuner_priv = NULL; 928 fe->tuner_priv = NULL;
929
903 return 0; 930 return 0;
904} 931}
905 932
@@ -924,29 +951,43 @@ static const struct dvb_tuner_ops xc5000_tuner_ops = {
924 951
925struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe, 952struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
926 struct i2c_adapter *i2c, 953 struct i2c_adapter *i2c,
927 struct xc5000_config *cfg, void *devptr) 954 struct xc5000_config *cfg)
928{ 955{
929 struct xc5000_priv *priv = NULL; 956 struct xc5000_priv *priv = NULL;
957 int instance;
930 u16 id = 0; 958 u16 id = 0;
931 959
932 dprintk(1, "%s()\n", __func__); 960 dprintk(1, "%s(%d-%04x)\n", __func__,
961 i2c ? i2c_adapter_id(i2c) : -1,
962 cfg ? cfg->i2c_address : -1);
933 963
934 priv = kzalloc(sizeof(struct xc5000_priv), GFP_KERNEL); 964 mutex_lock(&xc5000_list_mutex);
935 if (priv == NULL)
936 return NULL;
937 965
938 priv->cfg = cfg; 966 instance = hybrid_tuner_request_state(struct xc5000_priv, priv,
939 priv->bandwidth = BANDWIDTH_6_MHZ; 967 hybrid_tuner_instance_list,
940 priv->i2c = i2c; 968 i2c, cfg->i2c_address, "xc5000");
941 priv->devptr = devptr; 969 switch (instance) {
970 case 0:
971 goto fail;
972 break;
973 case 1:
974 /* new tuner instance */
975 priv->bandwidth = BANDWIDTH_6_MHZ;
976 priv->if_khz = cfg->if_khz;
977
978 fe->tuner_priv = priv;
979 break;
980 default:
981 /* existing tuner instance */
982 fe->tuner_priv = priv;
983 break;
984 }
942 985
943 /* Check if firmware has been loaded. It is possible that another 986 /* Check if firmware has been loaded. It is possible that another
944 instance of the driver has loaded the firmware. 987 instance of the driver has loaded the firmware.
945 */ 988 */
946 if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0) { 989 if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
947 kfree(priv); 990 goto fail;
948 return NULL;
949 }
950 991
951 switch(id) { 992 switch(id) {
952 case XC_PRODUCT_ID_FW_LOADED: 993 case XC_PRODUCT_ID_FW_LOADED:
@@ -967,19 +1008,23 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
967 printk(KERN_ERR 1008 printk(KERN_ERR
968 "xc5000: Device not found at addr 0x%02x (0x%x)\n", 1009 "xc5000: Device not found at addr 0x%02x (0x%x)\n",
969 cfg->i2c_address, id); 1010 cfg->i2c_address, id);
970 kfree(priv); 1011 goto fail;
971 return NULL;
972 } 1012 }
973 1013
1014 mutex_unlock(&xc5000_list_mutex);
1015
974 memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops, 1016 memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops,
975 sizeof(struct dvb_tuner_ops)); 1017 sizeof(struct dvb_tuner_ops));
976 1018
977 fe->tuner_priv = priv;
978
979 if (xc5000_load_fw_on_attach) 1019 if (xc5000_load_fw_on_attach)
980 xc5000_init(fe); 1020 xc5000_init(fe);
981 1021
982 return fe; 1022 return fe;
1023fail:
1024 mutex_unlock(&xc5000_list_mutex);
1025
1026 xc5000_release(fe);
1027 return NULL;
983} 1028}
984EXPORT_SYMBOL(xc5000_attach); 1029EXPORT_SYMBOL(xc5000_attach);
985 1030
diff --git a/drivers/media/common/tuners/xc5000.h b/drivers/media/common/tuners/xc5000.h
index 5389f740945a..cf1a558e0e7f 100644
--- a/drivers/media/common/tuners/xc5000.h
+++ b/drivers/media/common/tuners/xc5000.h
@@ -30,8 +30,6 @@ struct i2c_adapter;
30struct xc5000_config { 30struct xc5000_config {
31 u8 i2c_address; 31 u8 i2c_address;
32 u32 if_khz; 32 u32 if_khz;
33
34 int (*tuner_callback) (void *priv, int command, int arg);
35}; 33};
36 34
37/* xc5000 callback command */ 35/* xc5000 callback command */
@@ -49,13 +47,11 @@ struct xc5000_config {
49 (defined(CONFIG_MEDIA_TUNER_XC5000_MODULE) && defined(MODULE)) 47 (defined(CONFIG_MEDIA_TUNER_XC5000_MODULE) && defined(MODULE))
50extern struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe, 48extern struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
51 struct i2c_adapter *i2c, 49 struct i2c_adapter *i2c,
52 struct xc5000_config *cfg, 50 struct xc5000_config *cfg);
53 void *devptr);
54#else 51#else
55static inline struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe, 52static inline struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
56 struct i2c_adapter *i2c, 53 struct i2c_adapter *i2c,
57 struct xc5000_config *cfg, 54 struct xc5000_config *cfg)
58 void *devptr)
59{ 55{
60 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
61 return NULL; 57 return NULL;
diff --git a/drivers/media/common/tuners/xc5000_priv.h b/drivers/media/common/tuners/xc5000_priv.h
deleted file mode 100644
index b2a0074c99c9..000000000000
--- a/drivers/media/common/tuners/xc5000_priv.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef XC5000_PRIV_H
23#define XC5000_PRIV_H
24
25struct xc5000_priv {
26 struct xc5000_config *cfg;
27 struct i2c_adapter *i2c;
28
29 u32 freq_hz;
30 u32 bandwidth;
31 u8 video_standard;
32 u8 rf_mode;
33
34 void *devptr;
35};
36
37#endif