1 #include <linux/module.h>
2 #include <linux/kernel.h>
4 #include <linux/types.h>
6 #include <linux/errno.h>
8 #include <linux/videodev2.h>
28 static LIST_HEAD(hybrid_tuner_instance_list);
62 #define cVideoTrapBypassOFF 0x00 // bit b0
63 #define cVideoTrapBypassON 0x01 // bit b0
65 #define cAutoMuteFmInactive 0x00 // bit b1
66 #define cAutoMuteFmActive 0x02 // bit b1
68 #define cIntercarrier 0x00 // bit b2
69 #define cQSS 0x04 // bit b2
71 #define cPositiveAmTV 0x00 // bit b3:4
72 #define cFmRadio 0x08 // bit b3:4
73 #define cNegativeFmTV 0x10 // bit b3:4
76 #define cForcedMuteAudioON 0x20 // bit b5
77 #define cForcedMuteAudioOFF 0x00 // bit b5
79 #define cOutputPort1Active 0x00 // bit b6
80 #define cOutputPort1Inactive 0x40 // bit b6
82 #define cOutputPort2Active 0x00 // bit b7
83 #define cOutputPort2Inactive 0x80 // bit b7
87 #define cDeemphasisOFF 0x00 // bit c5
88 #define cDeemphasisON 0x20 // bit c5
90 #define cDeemphasis75 0x00 // bit c6
91 #define cDeemphasis50 0x40 // bit c6
93 #define cAudioGain0 0x00 // bit c7
94 #define cAudioGain6 0x80 // bit c7
96 #define cTopMask 0x1f // bit c0:4
97 #define cTopDefault 0x10 // bit c0:4
100 #define cAudioIF_4_5 0x00 // bit e0:1
101 #define cAudioIF_5_5 0x01 // bit e0:1
102 #define cAudioIF_6_0 0x02 // bit e0:1
103 #define cAudioIF_6_5 0x03 // bit e0:1
106 #define cVideoIFMask 0x1c // bit e2:4
108 #define cVideoIF_58_75 0x00 // bit e2:4
109 #define cVideoIF_45_75 0x04 // bit e2:4
110 #define cVideoIF_38_90 0x08 // bit e2:4
111 #define cVideoIF_38_00 0x0C // bit e2:4
112 #define cVideoIF_33_90 0x10 // bit e2:4
113 #define cVideoIF_33_40 0x14 // bit e2:4
114 #define cRadioIF_45_75 0x18 // bit e2:4
115 #define cRadioIF_38_90 0x1C // bit e2:4
118 #define cRadioIF_33_30 0x00 // bit e2,4 (also 0x10,0x14)
119 #define cRadioIF_41_30 0x04 // bit e2,4
122 #define cRadioAGC_SIF 0x00 // bit e3
123 #define cRadioAGC_FM 0x08 // bit e3
125 #define cTunerGainNormal 0x00 // bit e5
126 #define cTunerGainLow 0x20 // bit e5
128 #define cGating_18 0x00 // bit e6
129 #define cGating_36 0x40 // bit e6
131 #define cAgcOutON 0x80 // bit e7
132 #define cAgcOutOFF 0x00 // bit e7
136 static struct tvnorm tvnorms[] = {
244 static struct tvnorm radio_stereo = {
245 .
name =
"Radio Stereo",
256 static struct tvnorm radio_mono = {
257 .
name =
"Radio Mono",
270 static void dump_read_message(
struct dvb_frontend *fe,
unsigned char *
buf)
274 static char *afc[16] = {
293 tuner_info(
" after power on : %s\n", (buf[0] & 0x01) ?
"yes" :
"no");
294 tuner_info(
" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]);
295 tuner_info(
" fmif level : %s\n", (buf[0] & 0x20) ?
"high" :
"low");
296 tuner_info(
" afc window : %s\n", (buf[0] & 0x40) ?
"in" :
"out");
297 tuner_info(
" vfi level : %s\n", (buf[0] & 0x80) ?
"high" :
"low");
300 static void dump_write_message(
struct dvb_frontend *fe,
unsigned char *buf)
304 static char *sound[4] = {
310 static char *
adjust[32] = {
311 "-16",
"-15",
"-14",
"-13",
"-12",
"-11",
"-10",
"-9",
312 "-8",
"-7",
"-6",
"-5",
"-4",
"-3",
"-2",
"-1",
313 "0",
"+1",
"+2",
"+3",
"+4",
"+5",
"+6",
"+7",
314 "+8",
"+9",
"+10",
"+11",
"+12",
"+13",
"+14",
"+15"
316 static char *deemph[4] = {
317 "no",
"no",
"75",
"50"
319 static char *carrier[4] = {
325 static char *vif[8] = {
335 static char *rif[4] = {
344 (buf[1] & 0x01) ?
"video trap" :
"sound trap");
346 (buf[1] & 0x02) ?
"yes" :
"no");
348 (buf[1] & 0x04) ?
"QSS" :
"Intercarrier");
350 sound[(buf[1] & 0x18) >> 3]);
352 (buf[1] & 0x20) ?
"yes" :
"no");
354 (buf[1] & 0x40) ?
"high (inactive)" :
"low (active)");
356 (buf[1] & 0x80) ?
"high (inactive)" :
"low (active)");
360 adjust[buf[2] & 0x1f]);
362 deemph[(buf[2] & 0x60) >> 5]);
364 (buf[2] & 0x80) ?
"-6" :
"0");
368 carrier[(buf[3] & 0x03)]);
370 (buf[3] & 0x40) ?
"36" :
"13");
375 rif[(buf[3] & 0x0c) >> 2]);
378 ? ((buf[3] & 0x10) ?
"fm-agc radio" :
380 :
"fm radio carrier afc");
384 vif[(buf[3] & 0x1c) >> 2]);
387 ? ((buf[3] & 0x20) ?
"external" :
"normal")
388 : ((buf[3] & 0x20) ?
"minimum" :
"normal"));
390 (buf[3] & 0x80) ? ((buf[3] & 0x20)
391 ?
"pin3 port, pin22 vif agc out"
392 :
"pin22 port, pin3 vif acg ext in")
393 :
"pin3+pin22 port");
404 char *buf = priv->
data;
411 norm = &radio_stereo;
414 if (tvnorms[i].
std & priv->
std) {
421 tuner_dbg(
"Unsupported tvnorm entry - audio muted\n");
432 static unsigned int port1 =
UNSET;
433 static unsigned int port2 =
UNSET;
434 static unsigned int qss =
UNSET;
445 char *buf = priv->
data;
447 if (
UNSET != port1) {
453 if (
UNSET != port2) {
477 char *buf = priv->
data;
479 if (priv->
config & TDA9887_PORT1_ACTIVE)
481 if (priv->
config & TDA9887_PORT1_INACTIVE)
483 if (priv->
config & TDA9887_PORT2_ACTIVE)
485 if (priv->
config & TDA9887_PORT2_INACTIVE)
488 if (priv->
config & TDA9887_QSS)
490 if (priv->
config & TDA9887_INTERCARRIER)
493 if (priv->
config & TDA9887_AUTOMUTE)
495 if (priv->
config & TDA9887_DEEMPHASIS_MASK) {
497 switch (priv->
config & TDA9887_DEEMPHASIS_MASK) {
498 case TDA9887_DEEMPHASIS_NONE:
501 case TDA9887_DEEMPHASIS_50:
504 case TDA9887_DEEMPHASIS_75:
509 if (priv->
config & TDA9887_TOP_SET) {
513 if ((priv->
config & TDA9887_INTERCARRIER_NTSC) &&
516 if (priv->
config & TDA9887_GATING_18)
520 if (priv->
config & TDA9887_RIF_41_3) {
524 if (priv->
config & TDA9887_GAIN_NORMAL)
536 unsigned char buf[1];
539 memset(buf,0,
sizeof(buf));
540 if (1 != (rc = tuner_i2c_xfer_recv(&priv->
i2c_props,buf,1)))
541 tuner_info(
"i2c i/o error: rc == %d (should be 1)\n", rc);
542 dump_read_message(fe, buf);
552 tda9887_set_tvnorm(fe);
570 tda9887_do_config(fe);
571 tda9887_set_insmod(fe);
576 tuner_dbg(
"writing: b=0x%02x c=0x%02x e=0x%02x\n",
579 dump_write_message(fe, priv->
data);
581 if (4 != (rc = tuner_i2c_xfer_send(&priv->
i2c_props,priv->
data,4)))
582 tuner_info(
"i2c i/o error: rc == %d (should be 4)\n", rc);
592 static void tda9887_tuner_status(
struct dvb_frontend *fe)
595 tuner_info(
"Data bytes: b=0x%02x c=0x%02x e=0x%02x\n",
602 static int AFC_BITS_2_kHz[] = {
603 -12500, -37500, -62500, -97500,
604 -112500, -137500, -162500, -187500,
605 187500, 162500, 137500, 112500,
606 97500 , 62500, 37500 , 12500
611 if (1 == tuner_i2c_xfer_recv(&priv->
i2c_props,®,1))
612 afc = AFC_BITS_2_kHz[(reg>>1)&0x0f];
623 tda9887_configure(fe);
635 tda9887_configure(fe);
638 static int tda9887_set_config(
struct dvb_frontend *fe,
void *priv_cfg)
642 priv->
config = *(
unsigned int *)priv_cfg;
643 tda9887_configure(fe);
666 .set_params = tda9887_set_params,
667 .standby = tda9887_standby,
668 .tuner_status = tda9887_tuner_status,
669 .get_afc = tda9887_get_afc,
670 .release = tda9887_release,
671 .set_config = tda9887_set_config,
685 i2c_adap, i2c_addr,
"tda9887");
702 memcpy(&fe->
ops.analog_ops, &tda9887_ops,