3 i2c tv tuner chip device driver
4 controls the philips tda8290+75 tuner chip combo.
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.
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 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 This "tda8290" module was split apart from the original "tuner" module.
23 #include <linux/i2c.h>
24 #include <linux/delay.h>
25 #include <linux/videodev.h>
26 #include "tuner-i2c.h"
30 module_param(debug, int, 0644);
31 MODULE_PARM_DESC(debug, "enable verbose debug messages");
33 #define PREFIX "tda8290 "
35 /* ---------------------------------------------------------------------- */
38 struct tuner_i2c_props i2c_props;
40 unsigned char tda8290_easy_mode;
41 unsigned char tda827x_lpsel;
42 unsigned char tda827x_addr;
43 unsigned char tda827x_ver;
48 unsigned int *lna_cfg;
49 int (*tuner_callback) (void *dev, int command,int arg);
52 /* ---------------------------------------------------------------------- */
64 /* Note lomax entry is lo / 62500 */
66 static struct tda827x_data tda827x_analog[] = {
67 { .lomax = 992, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 62 MHz */
68 { .lomax = 1056, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 66 MHz */
69 { .lomax = 1216, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 76 MHz */
70 { .lomax = 1344, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 84 MHz */
71 { .lomax = 1488, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 93 MHz */
72 { .lomax = 1568, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 98 MHz */
73 { .lomax = 1744, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 109 MHz */
74 { .lomax = 1968, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 123 MHz */
75 { .lomax = 2128, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 133 MHz */
76 { .lomax = 2416, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 151 MHz */
77 { .lomax = 2464, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 154 MHz */
78 { .lomax = 2896, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 181 MHz */
79 { .lomax = 2960, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 185 MHz */
80 { .lomax = 3472, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 217 MHz */
81 { .lomax = 3904, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 244 MHz */
82 { .lomax = 4240, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 265 MHz */
83 { .lomax = 4832, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 302 MHz */
84 { .lomax = 5184, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 324 MHz */
85 { .lomax = 5920, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 370 MHz */
86 { .lomax = 7264, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 454 MHz */
87 { .lomax = 7888, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 493 MHz */
88 { .lomax = 8480, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 530 MHz */
89 { .lomax = 8864, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 554 MHz */
90 { .lomax = 9664, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 604 MHz */
91 { .lomax = 11088, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 696 MHz */
92 { .lomax = 11840, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 740 MHz */
93 { .lomax = 13120, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 820 MHz */
94 { .lomax = 13840, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 865 MHz */
95 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */
98 static void tda827x_set_analog_params(struct dvb_frontend *fe,
99 struct analog_parameters *params)
101 unsigned char tuner_reg[8];
102 unsigned char reg2[2];
105 struct tda8290_priv *priv = fe->tuner_priv;
106 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0};
107 unsigned int freq = params->frequency;
109 if (params->mode == V4L2_TUNER_RADIO)
112 N = freq + priv->sgIF;
114 while (tda827x_analog[i].lomax < N) {
115 if(tda827x_analog[i + 1].lomax == 0)
120 N = N << tda827x_analog[i].spd;
123 tuner_reg[1] = (unsigned char)(N>>8);
124 tuner_reg[2] = (unsigned char) N;
126 tuner_reg[4] = 0x52 + (priv->tda827x_lpsel << 5);
127 tuner_reg[5] = (tda827x_analog[i].spd << 6) + (tda827x_analog[i].div1p5 <<5) +
128 (tda827x_analog[i].bs <<3) + tda827x_analog[i].bp;
129 tuner_reg[6] = 0x8f + (tda827x_analog[i].gc3 << 4);
134 i2c_transfer(priv->i2c_props.adap, &msg, 1);
140 i2c_transfer(priv->i2c_props.adap, &msg, 1);
144 i2c_transfer(priv->i2c_props.adap, &msg, 1);
147 reg2[1] = tuner_reg[4] + 0x80;
148 i2c_transfer(priv->i2c_props.adap, &msg, 1);
152 reg2[1] = tuner_reg[4] + 4;
153 i2c_transfer(priv->i2c_props.adap, &msg, 1);
157 reg2[1] = tuner_reg[4];
158 i2c_transfer(priv->i2c_props.adap, &msg, 1);
162 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ;
163 i2c_transfer(priv->i2c_props.adap, &msg, 1);
167 i2c_transfer(priv->i2c_props.adap, &msg, 1);
170 reg2[1] = 0x08; // Vsync en
171 i2c_transfer(priv->i2c_props.adap, &msg, 1);
174 static void tda827x_agcf(struct dvb_frontend *fe)
176 struct tda8290_priv *priv = fe->tuner_priv;
177 unsigned char data[] = {0x80, 0x0c};
178 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
179 .flags = 0, .len = 2};
180 i2c_transfer(priv->i2c_props.adap, &msg, 1);
183 /* ---------------------------------------------------------------------- */
185 struct tda827xa_data {
194 static struct tda827xa_data tda827xa_analog[] = {
195 { .lomax = 910, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3}, /* 56.875 MHz */
196 { .lomax = 1076, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 67.25 MHz */
197 { .lomax = 1300, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 81.25 MHz */
198 { .lomax = 1560, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 97.5 MHz */
199 { .lomax = 1820, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1}, /* 113.75 MHz */
200 { .lomax = 2152, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 134.5 MHz */
201 { .lomax = 2464, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 154 MHz */
202 { .lomax = 2600, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 162.5 MHz */
203 { .lomax = 2928, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 183 MHz */
204 { .lomax = 3120, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1}, /* 195 MHz */
205 { .lomax = 3640, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3}, /* 227.5 MHz */
206 { .lomax = 4304, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3}, /* 269 MHz */
207 { .lomax = 5200, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1}, /* 325 MHz */
208 { .lomax = 6240, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 390 MHz */
209 { .lomax = 7280, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 455 MHz */
210 { .lomax = 8320, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 520 MHz */
211 { .lomax = 8608, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1}, /* 538 MHz */
212 { .lomax = 8864, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 554 MHz */
213 { .lomax = 9920, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 620 MHz */
214 { .lomax = 10400, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 650 MHz */
215 { .lomax = 11200, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 700 MHz */
216 { .lomax = 12480, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 780 MHz */
217 { .lomax = 13120, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 820 MHz */
218 { .lomax = 13920, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 870 MHz */
219 { .lomax = 14576, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0}, /* 911 MHz */
220 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */
223 static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
224 struct analog_parameters *params)
226 struct tda8290_priv *priv = fe->tuner_priv;
227 unsigned char buf[] = {0x22, 0x01};
229 struct i2c_msg msg = {.addr = priv->i2c_props.addr, .flags = 0, .buf = buf, .len = sizeof(buf)};
231 if ((priv->lna_cfg == NULL) || (priv->tuner_callback == NULL))
234 if (*priv->lna_cfg) {
236 tuner_dbg("setting LNA to high gain\n");
238 tuner_dbg("setting LNA to low gain\n");
240 switch (*priv->lna_cfg) {
243 case 1: /* switch is GPIO 0 of tda8290 */
246 if (params->std & V4L2_STD_MN)
250 if (priv->tuner_callback)
251 priv->tuner_callback(priv->i2c_props.adap->algo_data, 1, arg);
252 buf[1] = high ? 0 : 1;
253 if (*priv->lna_cfg == 2)
254 buf[1] = high ? 1 : 0;
255 i2c_transfer(priv->i2c_props.adap, &msg, 1);
257 case 3: /* switch with GPIO of saa713x */
258 if (priv->tuner_callback)
259 priv->tuner_callback(priv->i2c_props.adap->algo_data, 0, high);
264 static void tda827xa_set_analog_params(struct dvb_frontend *fe,
265 struct analog_parameters *params)
267 unsigned char tuner_reg[11];
270 struct tda8290_priv *priv = fe->tuner_priv;
271 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg};
272 unsigned int freq = params->frequency;
274 tda827xa_lna_gain(fe, 1, params);
277 if (params->mode == V4L2_TUNER_RADIO)
280 N = freq + priv->sgIF;
282 while (tda827xa_analog[i].lomax < N) {
283 if(tda827xa_analog[i + 1].lomax == 0)
288 N = N << tda827xa_analog[i].spd;
291 tuner_reg[1] = (unsigned char)(N>>8);
292 tuner_reg[2] = (unsigned char) N;
295 tuner_reg[5] = (tda827xa_analog[i].spd << 5) + (tda827xa_analog[i].svco << 3) +
296 tda827xa_analog[i].sbs;
297 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
301 tuner_reg[10] = 0x00;
303 i2c_transfer(priv->i2c_props.adap, &msg, 1);
309 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1);
311 i2c_transfer(priv->i2c_props.adap, &msg, 1);
316 i2c_transfer(priv->i2c_props.adap, &msg, 1);
319 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
320 i2c_transfer(priv->i2c_props.adap, &msg, 1);
322 msg.flags = I2C_M_RD;
323 i2c_transfer(priv->i2c_props.adap, &msg, 1);
326 tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]);
327 if (tuner_reg[1] < 1)
328 tda827xa_lna_gain(fe, 0, params);
333 i2c_transfer(priv->i2c_props.adap, &msg, 1);
337 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
338 i2c_transfer(priv->i2c_props.adap, &msg, 1);
342 i2c_transfer(priv->i2c_props.adap, &msg, 1);
346 i2c_transfer(priv->i2c_props.adap, &msg, 1);
349 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1);
350 i2c_transfer(priv->i2c_props.adap, &msg, 1);
353 static void tda827xa_agcf(struct dvb_frontend *fe)
355 struct tda8290_priv *priv = fe->tuner_priv;
356 unsigned char data[] = {0x80, 0x2c};
357 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
358 .flags = 0, .len = 2};
359 i2c_transfer(priv->i2c_props.adap, &msg, 1);
362 /*---------------------------------------------------------------------*/
364 static void tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
366 struct tda8290_priv *priv = fe->tuner_priv;
368 unsigned char enable[2] = { 0x21, 0xC0 };
369 unsigned char disable[2] = { 0x21, 0x00 };
373 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
374 /* let the bridge stabilize */
378 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
382 /*---------------------------------------------------------------------*/
384 static void set_audio(struct dvb_frontend *fe,
385 struct analog_parameters *params)
387 struct tda8290_priv *priv = fe->tuner_priv;
390 priv->tda827x_lpsel = 0;
391 if (params->std & V4L2_STD_MN) {
393 priv->tda8290_easy_mode = 0x01;
394 priv->tda827x_lpsel = 1;
396 } else if (params->std & V4L2_STD_B) {
398 priv->tda8290_easy_mode = 0x02;
400 } else if (params->std & V4L2_STD_GH) {
402 priv->tda8290_easy_mode = 0x04;
404 } else if (params->std & V4L2_STD_PAL_I) {
406 priv->tda8290_easy_mode = 0x08;
408 } else if (params->std & V4L2_STD_DK) {
410 priv->tda8290_easy_mode = 0x10;
412 } else if (params->std & V4L2_STD_SECAM_L) {
414 priv->tda8290_easy_mode = 0x20;
416 } else if (params->std & V4L2_STD_SECAM_LC) {
418 priv->tda8290_easy_mode = 0x40;
422 priv->tda8290_easy_mode = 0x10;
426 if (params->mode == V4L2_TUNER_RADIO)
427 priv->sgIF = 88; /* if frequency is 5.5 MHz */
429 tuner_dbg("setting tda8290 to system %s\n", mode);
432 static int tda8290_set_params(struct dvb_frontend *fe,
433 struct analog_parameters *params)
435 struct tda8290_priv *priv = fe->tuner_priv;
436 unsigned char soft_reset[] = { 0x00, 0x00 };
437 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
438 unsigned char expert_mode[] = { 0x01, 0x80 };
439 unsigned char agc_out_on[] = { 0x02, 0x00 };
440 unsigned char gainset_off[] = { 0x28, 0x14 };
441 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
442 unsigned char adc_head_6[] = { 0x05, 0x04 };
443 unsigned char adc_head_9[] = { 0x05, 0x02 };
444 unsigned char adc_head_12[] = { 0x05, 0x01 };
445 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
446 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
447 unsigned char gainset_2[] = { 0x28, 0x64 };
448 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
449 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
450 unsigned char if_agc_set[] = { 0x0f, 0x81 };
451 unsigned char addr_adc_sat = 0x1a;
452 unsigned char addr_agc_stat = 0x1d;
453 unsigned char addr_pll_stat = 0x1b;
454 unsigned char adc_sat, agc_stat,
458 set_audio(fe, params);
461 tuner_dbg("tda827xa config is 0x%02x\n", *priv->lna_cfg);
462 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
463 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
464 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
467 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
468 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
469 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
470 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
471 if (priv->tda8290_easy_mode & 0x60)
472 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
474 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
475 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
477 tda8290_i2c_bridge(fe, 1);
478 if (priv->tda827x_ver != 0)
479 tda827xa_set_analog_params(fe, params);
481 tda827x_set_analog_params(fe, params);
482 for (i = 0; i < 3; i++) {
483 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
484 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
485 if (pll_stat & 0x80) {
486 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
487 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
488 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
489 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
490 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
493 tuner_dbg("tda8290 not locked, no signal?\n");
497 /* adjust headroom resp. gain */
498 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
499 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
500 agc_stat, adc_sat, pll_stat & 0x80);
501 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
503 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
504 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
505 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
506 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
507 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
508 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
509 agc_stat, pll_stat & 0x80);
510 if (priv->tda827x_ver != 0)
515 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
516 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
517 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
518 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
519 if((agc_stat > 115) || !(pll_stat & 0x80)) {
520 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
521 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
522 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
528 /* l/ l' deadlock? */
529 if(priv->tda8290_easy_mode & 0x60) {
530 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
531 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
532 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
533 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
534 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
535 tuner_dbg("trying to resolve SECAM L deadlock\n");
536 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
538 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
542 tda8290_i2c_bridge(fe, 0);
543 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
545 priv->frequency = (V4L2_TUNER_RADIO == params->mode) ?
546 params->frequency * 125 / 2 : params->frequency * 62500;
551 /*---------------------------------------------------------------------*/
553 static int tda8290_has_signal(struct dvb_frontend *fe)
555 struct tda8290_priv *priv = fe->tuner_priv;
558 unsigned char i2c_get_afc[1] = { 0x1B };
559 unsigned char afc = 0;
561 /* for now, report based on afc status */
562 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
563 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
565 ret = (afc & 0x80) ? 65535 : 0;
567 tuner_dbg("AFC status: %d\n", ret);
572 static int tda8290_get_status(struct dvb_frontend *fe, u32 *status)
576 if (tda8290_has_signal(fe))
577 *status = TUNER_STATUS_LOCKED;
582 static int tda8290_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
584 *strength = tda8290_has_signal(fe);
589 /*---------------------------------------------------------------------*/
591 static int tda8290_standby(struct dvb_frontend *fe)
593 struct tda8290_priv *priv = fe->tuner_priv;
594 unsigned char cb1[] = { 0x30, 0xD0 };
595 unsigned char tda8290_standby[] = { 0x00, 0x02 };
596 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
597 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
599 tda8290_i2c_bridge(fe, 1);
600 if (priv->tda827x_ver != 0)
602 i2c_transfer(priv->i2c_props.adap, &msg, 1);
603 tda8290_i2c_bridge(fe, 0);
604 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
605 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
611 static void tda8290_init_if(struct dvb_frontend *fe)
613 struct tda8290_priv *priv = fe->tuner_priv;
615 unsigned char set_VS[] = { 0x30, 0x6F };
616 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
617 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
619 if ((priv->lna_cfg) &&
620 ((*priv->lna_cfg == 1) || (*priv->lna_cfg == 2)))
621 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
623 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
624 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
627 static void tda8290_init_tuner(struct dvb_frontend *fe)
629 struct tda8290_priv *priv = fe->tuner_priv;
630 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
631 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
632 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
633 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
634 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
635 .buf=tda8275_init, .len = 14};
636 if (priv->tda827x_ver != 0)
637 msg.buf = tda8275a_init;
639 tda8290_i2c_bridge(fe, 1);
640 i2c_transfer(priv->i2c_props.adap, &msg, 1);
641 tda8290_i2c_bridge(fe, 0);
644 /*---------------------------------------------------------------------*/
646 static int tda8290_release(struct dvb_frontend *fe)
648 kfree(fe->tuner_priv);
649 fe->tuner_priv = NULL;
654 static int tda8290_get_frequency(struct dvb_frontend *fe, u32 *frequency)
656 struct tda8290_priv *priv = fe->tuner_priv;
657 *frequency = priv->frequency;
661 static struct dvb_tuner_ops tda8290_tuner_ops = {
662 .sleep = tda8290_standby,
663 .set_analog_params = tda8290_set_params,
664 .release = tda8290_release,
665 .get_frequency = tda8290_get_frequency,
666 .get_status = tda8290_get_status,
667 .get_rf_strength = tda8290_get_rf_strength,
670 struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
671 struct i2c_adapter* i2c_adap,
673 struct tda8290_config *cfg)
675 struct tda8290_priv *priv = NULL;
677 int i, ret, tuners_found;
679 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1};
681 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
684 fe->tuner_priv = priv;
686 priv->i2c_props.addr = i2c_addr;
687 priv->i2c_props.adap = i2c_adap;
689 priv->lna_cfg = cfg->lna_cfg;
690 priv->tuner_callback = cfg->tuner_callback;
693 tda8290_i2c_bridge(fe, 1);
694 /* probe for tuner chip */
697 for (i=0x60; i<= 0x63; i++) {
699 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
702 tuner_addrs = (tuner_addrs << 8) + i;
705 /* if there is more than one tuner, we expect the right one is
706 behind the bridge and we choose the highest address that doesn't
709 tda8290_i2c_bridge(fe, 0);
711 for (i = 0; i < tuners_found; i++) {
712 msg.addr = tuner_addrs & 0xff;
713 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
715 tuner_addrs = tuner_addrs >> 8;
719 if (tuner_addrs == 0) {
721 tuner_info("could not clearly identify tuner address, defaulting to %x\n",
724 tuner_addrs = tuner_addrs & 0xff;
725 tuner_info("setting tuner address to %x\n", tuner_addrs);
727 priv->tda827x_addr = tuner_addrs;
728 msg.addr = tuner_addrs;
730 tda8290_i2c_bridge(fe, 1);
731 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
733 tuner_warn("TDA827x access failed!\n");
735 memcpy(&fe->ops.tuner_ops, &tda8290_tuner_ops,
736 sizeof(struct dvb_tuner_ops));
738 if ((data & 0x3c) == 0) {
739 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75",
740 sizeof(fe->ops.tuner_ops.info.name));
741 fe->ops.tuner_ops.info.frequency_min = 55000000;
742 fe->ops.tuner_ops.info.frequency_max = 860000000;
743 fe->ops.tuner_ops.info.frequency_step = 250000;
744 priv->tda827x_ver = 0;
746 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75a",
747 sizeof(fe->ops.tuner_ops.info.name));
748 fe->ops.tuner_ops.info.frequency_min = 44000000;
749 fe->ops.tuner_ops.info.frequency_max = 906000000;
750 fe->ops.tuner_ops.info.frequency_step = 62500;
751 priv->tda827x_ver = 2;
754 priv->tda827x_lpsel = 0;
756 tda8290_init_tuner(fe);
761 int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr)
763 struct tuner_i2c_props i2c_props = {
768 unsigned char soft_reset[] = { 0x00, 0x00 };
769 unsigned char easy_mode_b[] = { 0x01, 0x02 };
770 unsigned char easy_mode_g[] = { 0x01, 0x04 };
771 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
772 unsigned char addr_dto_lsb = 0x07;
775 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
776 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
777 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
778 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
780 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
781 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
782 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
783 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
788 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
792 EXPORT_SYMBOL_GPL(tda8290_probe);
793 EXPORT_SYMBOL_GPL(tda8290_attach);
795 MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver");
796 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann");
797 MODULE_LICENSE("GPL");
800 * Overrides for Emacs so that we follow Linus's tabbing style.
801 * ---------------------------------------------------------------------------