9 #include <linux/videodev2.h>
20 #define TUNER_SIMPLE_MAX 64
21 static unsigned int simple_devcount;
47 #define TEMIC_SET_PAL_I 0x05
48 #define TEMIC_SET_PAL_DK 0x09
49 #define TEMIC_SET_PAL_L 0x0a
50 #define TEMIC_SET_PAL_L2 0x0b
51 #define TEMIC_SET_PAL_BG 0x0c
63 #define PHILIPS_SET_PAL_I 0x01
64 #define PHILIPS_SET_PAL_BGDK 0x09
65 #define PHILIPS_SET_PAL_L2 0x0a
66 #define PHILIPS_SET_PAL_L 0x0b
77 #define PHILIPS_MF_SET_STD_BG 0x01
78 #define PHILIPS_MF_SET_STD_L 0x03
79 #define PHILIPS_MF_SET_STD_LC 0x02
83 #define TUNER_RATIO_MASK 0x06
84 #define TUNER_RATIO_SELECT_50 0x00
85 #define TUNER_RATIO_SELECT_32 0x02
86 #define TUNER_RATIO_SELECT_166 0x04
87 #define TUNER_RATIO_SELECT_62 0x06
89 #define TUNER_CHARGE_PUMP 0x40
93 #define TUNER_POR 0x80
95 #define TUNER_MODE 0x38
96 #define TUNER_AFC 0x07
97 #define TUNER_SIGNAL 0x07
98 #define TUNER_STEREO 0x10
100 #define TUNER_PLL_LOCKED 0x40
101 #define TUNER_STEREO_MK3 0x04
104 static LIST_HEAD(hybrid_tuner_instance_list);
127 if (1 != tuner_i2c_xfer_recv(&priv->
i2c_props, &byte, 1))
133 static inline int tuner_signal(
const int status)
138 static inline int tuner_stereo(
const int type,
const int status)
141 case TUNER_PHILIPS_FM1216ME_MK3:
142 case TUNER_PHILIPS_FM1236_MK3:
143 case TUNER_PHILIPS_FM1256_IH3:
144 case TUNER_LG_NTSC_TAPE:
145 case TUNER_TCL_MF02GIP_5N:
147 case TUNER_PHILIPS_FM1216MK5:
154 static inline int tuner_islocked(
const int status)
159 static inline int tuner_afcstatus(
const int status)
173 tuner_status = tuner_read_status(fe);
177 if (tuner_islocked(tuner_status))
179 if (tuner_stereo(priv->
type, tuner_status))
182 tuner_dbg(
"AFC Status: %d\n", tuner_afcstatus(tuner_status));
187 static int simple_get_rf_strength(
struct dvb_frontend *fe,
u16 *strength)
195 signal = tuner_signal(tuner_read_status(fe));
199 tuner_dbg(
"Signal strength: %d\n", signal);
206 static inline char *tuner_param_name(
enum param_type type)
240 for (i = 0; i < tun->
count; i++)
241 if (desired_type == tun->
params[i].type)
245 if (i == tun->
count) {
246 tuner_dbg(
"desired params (%s) undefined for tuner %d\n",
247 tuner_param_name(desired_type), priv->
type);
251 tuner_dbg(
"using tuner params #%d (%s)\n", i,
252 tuner_param_name(tun->
params[i].type));
257 static int simple_config_lookup(
struct dvb_frontend *fe,
264 for (i = 0; i < t_params->
count; i++) {
265 if (*frequency > t_params->
ranges[i].limit)
269 if (i == t_params->
count) {
270 tuner_dbg(
"frequency out of range (%d > %d)\n",
271 *frequency, t_params->
ranges[i - 1].limit);
272 *frequency = t_params->
ranges[--
i].limit;
274 *config = t_params->
ranges[
i].config;
277 tuner_dbg(
"freq = %d.%02d (%d), range = %d, "
278 "config = 0x%02x, cb = 0x%02x\n",
279 *frequency / 16, *frequency % 16 * 100 / 16, *frequency,
287 static void simple_set_rf_input(
struct dvb_frontend *fe,
288 u8 *config,
u8 *cb,
unsigned int rf)
292 switch (priv->
type) {
293 case TUNER_PHILIPS_TUV1236D:
303 case TUNER_PHILIPS_FCV1236D:
326 switch (priv->
type) {
327 case TUNER_PHILIPS_SECAM:
341 case TUNER_TEMIC_4046FM5:
359 case TUNER_PHILIPS_FQ1216ME:
374 case TUNER_PHILIPS_FCV1236D:
384 case TUNER_MICROTUNE_4042FI5:
389 case TUNER_PHILIPS_TUV1236D:
396 u8 buffer[4] = { 0x14, 0x00, 0x17, 0x00};
404 rc = tuner_i2c_xfer_send(&i2c, &buffer[0], 2);
407 "(should be 2)\n", rc);
408 rc = tuner_i2c_xfer_send(&i2c, &buffer[2], 2);
411 "(should be 2)\n", rc);
415 if (atv_input[priv->
nr])
416 simple_set_rf_input(fe, config, cb, atv_input[priv->
nr]);
427 buffer[0] = (config & ~0x38) | 0x18;
430 tuner_dbg(
"setting aux byte: 0x%02x 0x%02x\n", buffer[0], buffer[1]);
432 rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 2);
434 tuner_warn(
"i2c i/o error: rc == %d (should be 2)\n", rc);
436 return rc == 2 ? 0 :
rc;
445 switch (priv->
type) {
446 case TUNER_LG_TDVS_H06XF:
447 simple_set_aux_byte(fe, config, 0x20);
449 case TUNER_PHILIPS_FQ1216LME_MK3:
450 simple_set_aux_byte(fe, config, 0x60);
452 case TUNER_MICROTUNE_4042FI5:
462 rc = tuner_i2c_xfer_recv(&priv->
i2c_props,
466 "(should be 1)\n", rc);
476 buffer[0] = (div>>8) & 0x7f;
477 buffer[1] = div & 0xff;
480 tuner_dbg(
"tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
481 buffer[0], buffer[1], buffer[2], buffer[3]);
483 rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 4);
486 "(should be 4)\n", rc);
494 static int simple_radio_bandswitch(
struct dvb_frontend *fe,
u8 *buffer)
498 switch (priv->
type) {
499 case TUNER_TENA_9533_DI:
500 case TUNER_YMEC_TVF_5533MF:
502 "Most cards have a TEA5767 for FM\n");
504 case TUNER_PHILIPS_FM1216ME_MK3:
505 case TUNER_PHILIPS_FM1236_MK3:
506 case TUNER_PHILIPS_FMD1216ME_MK3:
507 case TUNER_PHILIPS_FMD1216MEX_MK3:
508 case TUNER_LG_NTSC_TAPE:
509 case TUNER_PHILIPS_FM1256_IH3:
510 case TUNER_TCL_MF02GIP_5N:
513 case TUNER_PHILIPS_FM1216MK5:
517 case TUNER_TNF_5335MF:
520 case TUNER_LG_PAL_FM:
523 case TUNER_THOMSON_DTT761X:
526 case TUNER_PHILIPS_FQ1216LME_MK3:
527 case TUNER_PHILIPS_FQ1236_MK5:
528 tuner_err(
"This tuner doesn't have FM\n");
532 case TUNER_MICROTUNE_4049FM5:
581 t_params = simple_tuner_params(fe, desired_type);
583 i = simple_config_lookup(fe, t_params, ¶ms->
frequency,
588 tuner_dbg(
"Freq= %d.%02d MHz, V_IF=%d.%02d MHz, "
589 "Offset=%d.%02d MHz, div=%0d\n",
591 IFPCoff / 16, IFPCoff % 16 * 100 / 16,
592 offset / 16, offset % 16 * 100 / 16, div);
595 simple_std_setup(fe, params, &config, &cb);
600 buffer[2] = (div>>8) & 0x7f;
601 buffer[3] = div & 0xff;
603 buffer[0] = (div>>8) & 0x7f;
604 buffer[1] = div & 0xff;
617 tda9887_cfg.
tuner = TUNER_TDA9887;
618 tda9887_cfg.priv = &tda_config;
622 tda_config |= TDA9887_PORT1_ACTIVE;
624 tda_config |= TDA9887_PORT2_ACTIVE;
627 tda_config |= TDA9887_PORT1_ACTIVE;
629 tda_config |= TDA9887_PORT2_ACTIVE;
632 tda_config |= TDA9887_INTERCARRIER;
649 tda_config |= TDA9887_GATING_18;
653 tuner_dbg(
"tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
654 buffer[0], buffer[1], buffer[2], buffer[3]);
656 rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 4);
658 tuner_warn(
"i2c i/o error: rc == %d (should be 4)\n", rc);
660 simple_post_tune(fe, &buffer[0], div, config, cb);
665 static int simple_set_radio_freq(
struct dvb_frontend *fe,
678 for (j = tun->
count-1; j > 0; j--)
687 freq += (
unsigned int)(10.7*16000);
690 freq += (
unsigned int)(33.3*16000);
693 freq += (
unsigned int)(41.3*16000);
705 simple_radio_bandswitch(fe, &buffer[0]);
710 div = (freq + 400) / 800;
713 buffer[0] = buffer[2];
714 buffer[1] = buffer[3];
715 buffer[2] = (div>>8) & 0x7f;
716 buffer[3] = div & 0xff;
718 buffer[0] = (div>>8) & 0x7f;
719 buffer[1] = div & 0xff;
722 tuner_dbg(
"radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
723 buffer[0], buffer[1], buffer[2], buffer[3]);
730 tda9887_cfg.
tuner = TUNER_TDA9887;
731 tda9887_cfg.priv = &
config;
735 config |= TDA9887_PORT1_ACTIVE;
738 config |= TDA9887_PORT2_ACTIVE;
740 config |= TDA9887_INTERCARRIER;
744 config |= TDA9887_GAIN_NORMAL;
746 config |= TDA9887_RIF_41_3;
750 rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 4);
752 tuner_warn(
"i2c i/o error: rc == %d (should be 4)\n", rc);
755 switch (priv->
type) {
756 case TUNER_PHILIPS_FM1216ME_MK3:
759 rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 4);
761 tuner_warn(
"i2c i/o error: rc == %d (should be 4)\n", rc);
777 switch (params->
mode) {
779 ret = simple_set_radio_freq(fe, params);
784 ret = simple_set_tv_freq(fe, params);
800 switch (priv->
type) {
801 case TUNER_PHILIPS_FMD1216ME_MK3:
802 case TUNER_PHILIPS_FMD1216MEX_MK3:
803 if (bandwidth == 8000000 &&
804 frequency >= 158870000)
807 case TUNER_PHILIPS_TD1316:
809 buf[3] |= (frequency < 161000000) ? 1 :
810 (frequency < 444000000) ? 2 : 4;
813 if (bandwidth == 8000000)
816 case TUNER_PHILIPS_TUV1236D:
817 case TUNER_PHILIPS_FCV1236D:
821 if (dtv_input[priv->
nr])
822 new_rf = dtv_input[priv->
nr];
833 simple_set_rf_input(fe, &buf[2], &buf[3], new_rf);
853 u32 frequency = freq / 62500;
858 tuner_err(
"attempt to treat tuner %d (%s) as digital tuner "
859 "without stepsize defined.\n",
865 ret = simple_config_lookup(fe, t_params, &frequency, &config, &cb);
869 div = ((frequency + t_params->
iffreq) * 62500 + offset +
877 simple_set_dvb(fe, buf, delsys, freq, bw);
879 tuner_dbg(
"%s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
880 tun->
name, div, buf[0], buf[1], buf[2], buf[3]);
886 static int simple_dvb_calc_regs(
struct dvb_frontend *fe,
887 u8 *buf,
int buf_len)
898 frequency = simple_dvb_configure(fe, buf+1, delsys, c->
frequency, bw);
910 static int simple_dvb_set_params(
struct dvb_frontend *fe)
918 u32 prev_freq, prev_bw;
928 frequency = simple_dvb_configure(fe, buf+1, delsys, freq, bw);
938 if (fe->
ops.analog_ops.standby)
939 fe->
ops.analog_ops.standby(fe);
941 if (fe->
ops.i2c_gate_ctrl)
942 fe->
ops.i2c_gate_ctrl(fe, 1);
946 ret = tuner_i2c_xfer_send(&priv->
i2c_props, buf+1, 4);
966 if (priv->
tun->initdata) {
969 if (fe->
ops.i2c_gate_ctrl)
970 fe->
ops.i2c_gate_ctrl(fe, 1);
972 ret = tuner_i2c_xfer_send(&priv->
i2c_props,
973 priv->
tun->initdata + 1,
974 priv->
tun->initdata[0]);
975 if (ret != priv->
tun->initdata[0])
989 if (priv->
tun->sleepdata) {
992 if (fe->
ops.i2c_gate_ctrl)
993 fe->
ops.i2c_gate_ctrl(fe, 1);
995 ret = tuner_i2c_xfer_send(&priv->
i2c_props,
996 priv->
tun->sleepdata + 1,
997 priv->
tun->sleepdata[0]);
998 if (ret != priv->
tun->sleepdata[0])
1021 static int simple_get_frequency(
struct dvb_frontend *fe,
u32 *frequency)
1028 static int simple_get_bandwidth(
struct dvb_frontend *fe,
u32 *bandwidth)
1036 .init = simple_init,
1037 .sleep = simple_sleep,
1038 .set_analog_params = simple_set_params,
1039 .set_params = simple_dvb_set_params,
1040 .calc_regs = simple_dvb_calc_regs,
1041 .release = simple_release,
1042 .get_frequency = simple_get_frequency,
1043 .get_bandwidth = simple_get_bandwidth,
1044 .get_status = simple_get_status,
1045 .get_rf_strength = simple_get_rf_strength,
1066 if (i2c_adap !=
NULL) {
1073 if (fe->
ops.i2c_gate_ctrl)
1074 fe->
ops.i2c_gate_ctrl(fe, 1);
1078 "unable to probe %s, proceeding anyway.",
1079 i2c_adapter_id(i2c_adap), i2c_addr,
1082 if (fe->
ops.i2c_gate_ctrl)
1083 fe->
ops.i2c_gate_ctrl(fe, 0);
1089 hybrid_tuner_instance_list,
1101 priv->
nr = simple_devcount++;
1110 memcpy(&fe->
ops.tuner_ops, &simple_tuner_ops,
1113 if (type != priv->
type)
1114 tuner_warn(
"couldn't set type to %d. Using %d (%s) instead\n",
1115 type, priv->
type, priv->
tun->name);
1120 if ((
debug) || ((atv_input[priv->
nr] > 0) ||
1121 (dtv_input[priv->
nr] > 0))) {
1122 if (0 == atv_input[priv->
nr])
1124 "autoselected\n", priv->
nr);
1127 "set to input %d (insmod option)\n",
1128 priv->
nr, atv_input[priv->
nr]);
1129 if (0 == dtv_input[priv->
nr])
1131 "autoselected\n", priv->
nr);
1134 "set to input %d (insmod option)\n",
1135 priv->
nr, dtv_input[priv->
nr]);
1139 sizeof(fe->
ops.tuner_ops.info.name));