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/slab.h>
25 #include <linux/delay.h>
26 #include <linux/videodev2.h>
27 #include "tuner-i2c.h"
33 module_param(debug, int, 0644);
34 MODULE_PARM_DESC(debug, "enable verbose debug messages");
36 static int deemphasis_50;
37 module_param(deemphasis_50, int, 0644);
38 MODULE_PARM_DESC(deemphasis_50, "0 - 75us deemphasis; 1 - 50us deemphasis");
40 /* ---------------------------------------------------------------------- */
43 struct tuner_i2c_props i2c_props;
45 unsigned char tda8290_easy_mode;
47 unsigned char tda827x_addr;
56 struct tda827x_config cfg;
59 /*---------------------------------------------------------------------*/
61 static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
63 struct tda8290_priv *priv = fe->analog_demod_priv;
65 unsigned char enable[2] = { 0x21, 0xC0 };
66 unsigned char disable[2] = { 0x21, 0x00 };
71 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
72 /* let the bridge stabilize */
76 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
82 static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
84 struct tda8290_priv *priv = fe->analog_demod_priv;
86 unsigned char enable[2] = { 0x45, 0xc1 };
87 unsigned char disable[2] = { 0x46, 0x00 };
88 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
93 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
94 /* let the bridge stabilize */
98 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
99 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
103 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
107 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
113 /*---------------------------------------------------------------------*/
115 static void set_audio(struct dvb_frontend *fe,
116 struct analog_parameters *params)
118 struct tda8290_priv *priv = fe->analog_demod_priv;
121 if (params->std & V4L2_STD_MN) {
122 priv->tda8290_easy_mode = 0x01;
124 } else if (params->std & V4L2_STD_B) {
125 priv->tda8290_easy_mode = 0x02;
127 } else if (params->std & V4L2_STD_GH) {
128 priv->tda8290_easy_mode = 0x04;
130 } else if (params->std & V4L2_STD_PAL_I) {
131 priv->tda8290_easy_mode = 0x08;
133 } else if (params->std & V4L2_STD_DK) {
134 priv->tda8290_easy_mode = 0x10;
136 } else if (params->std & V4L2_STD_SECAM_L) {
137 priv->tda8290_easy_mode = 0x20;
139 } else if (params->std & V4L2_STD_SECAM_LC) {
140 priv->tda8290_easy_mode = 0x40;
143 priv->tda8290_easy_mode = 0x10;
147 if (params->mode == V4L2_TUNER_RADIO) {
148 /* Set TDA8295 to FM radio; Start TDA8290 with MN values */
149 priv->tda8290_easy_mode = (priv->ver & TDA8295) ? 0x80 : 0x01;
150 tuner_dbg("setting to radio FM\n");
152 tuner_dbg("setting tda829x to system %s\n", mode);
157 unsigned char seq[2];
159 { { 0x01, 0x81} }, /* Put device into expert mode */
160 { { 0x03, 0x48} }, /* Disable NOTCH and VIDEO filters */
161 { { 0x04, 0x04} }, /* Disable color carrier filter (SSIF) */
162 { { 0x05, 0x04} }, /* ADC headroom */
163 { { 0x06, 0x10} }, /* group delay flat */
165 { { 0x07, 0x00} }, /* use the same radio DTO values as a tda8295 */
172 { { 0x0d, 0x00} }, /* PLL off, no video carrier detect */
173 { { 0x14, 0x00} }, /* disable auto mute if no video */
176 static void tda8290_set_params(struct dvb_frontend *fe,
177 struct analog_parameters *params)
179 struct tda8290_priv *priv = fe->analog_demod_priv;
181 unsigned char soft_reset[] = { 0x00, 0x00 };
182 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
183 unsigned char expert_mode[] = { 0x01, 0x80 };
184 unsigned char agc_out_on[] = { 0x02, 0x00 };
185 unsigned char gainset_off[] = { 0x28, 0x14 };
186 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
187 unsigned char adc_head_6[] = { 0x05, 0x04 };
188 unsigned char adc_head_9[] = { 0x05, 0x02 };
189 unsigned char adc_head_12[] = { 0x05, 0x01 };
190 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
191 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
192 unsigned char gainset_2[] = { 0x28, 0x64 };
193 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
194 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
195 unsigned char if_agc_set[] = { 0x0f, 0x81 };
196 unsigned char addr_adc_sat = 0x1a;
197 unsigned char addr_agc_stat = 0x1d;
198 unsigned char addr_pll_stat = 0x1b;
199 unsigned char adc_sat, agc_stat,
203 set_audio(fe, params);
205 if (priv->cfg.config)
206 tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config);
207 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
208 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
209 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
212 if (params->mode == V4L2_TUNER_RADIO) {
213 unsigned char deemphasis[] = { 0x13, 1 };
215 /* FIXME: allow using a different deemphasis */
220 for (i = 0; i < ARRAY_SIZE(fm_mode); i++)
221 tuner_i2c_xfer_send(&priv->i2c_props, fm_mode[i].seq, 2);
223 tuner_i2c_xfer_send(&priv->i2c_props, deemphasis, 2);
225 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
226 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
227 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
228 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
229 if (priv->tda8290_easy_mode & 0x60)
230 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
232 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
233 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
236 tda8290_i2c_bridge(fe, 1);
238 if (fe->ops.tuner_ops.set_analog_params)
239 fe->ops.tuner_ops.set_analog_params(fe, params);
241 for (i = 0; i < 3; i++) {
242 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
243 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
244 if (pll_stat & 0x80) {
245 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
246 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
247 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
248 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
249 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
252 tuner_dbg("tda8290 not locked, no signal?\n");
256 /* adjust headroom resp. gain */
257 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
258 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
259 agc_stat, adc_sat, pll_stat & 0x80);
260 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
262 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
263 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
264 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
265 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
266 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
267 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
268 agc_stat, pll_stat & 0x80);
272 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
273 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
274 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
275 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
276 if((agc_stat > 115) || !(pll_stat & 0x80)) {
277 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
278 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
279 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
285 /* l/ l' deadlock? */
286 if(priv->tda8290_easy_mode & 0x60) {
287 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
288 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
289 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
290 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
291 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
292 tuner_dbg("trying to resolve SECAM L deadlock\n");
293 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
295 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
299 tda8290_i2c_bridge(fe, 0);
300 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
303 /*---------------------------------------------------------------------*/
305 static void tda8295_power(struct dvb_frontend *fe, int enable)
307 struct tda8290_priv *priv = fe->analog_demod_priv;
308 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
310 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
311 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
318 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
321 static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
323 struct tda8290_priv *priv = fe->analog_demod_priv;
324 unsigned char buf[] = { 0x01, 0x00 };
326 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
327 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
330 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
332 buf[1] = 0x00; /* reset active bit */
334 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
337 static void tda8295_set_video_std(struct dvb_frontend *fe)
339 struct tda8290_priv *priv = fe->analog_demod_priv;
340 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
342 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
344 tda8295_set_easy_mode(fe, 1);
346 tda8295_set_easy_mode(fe, 0);
349 /*---------------------------------------------------------------------*/
351 static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
353 struct tda8290_priv *priv = fe->analog_demod_priv;
354 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
356 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
357 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
364 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
367 static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
369 struct tda8290_priv *priv = fe->analog_demod_priv;
370 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
371 unsigned char set_gpio_val[] = { 0x46, 0x00 };
373 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
374 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
375 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
376 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
378 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
381 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
382 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
384 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
385 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
388 static int tda8295_has_signal(struct dvb_frontend *fe)
390 struct tda8290_priv *priv = fe->analog_demod_priv;
392 unsigned char hvpll_stat = 0x26;
395 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
396 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
397 return (ret & 0x01) ? 65535 : 0;
400 /*---------------------------------------------------------------------*/
402 static void tda8295_set_params(struct dvb_frontend *fe,
403 struct analog_parameters *params)
405 struct tda8290_priv *priv = fe->analog_demod_priv;
407 unsigned char blanking_mode[] = { 0x1d, 0x00 };
409 set_audio(fe, params);
411 tuner_dbg("%s: freq = %d\n", __func__, params->frequency);
413 tda8295_power(fe, 1);
414 tda8295_agc1_out(fe, 1);
416 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
417 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
419 tda8295_set_video_std(fe);
421 blanking_mode[1] = 0x03;
422 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
425 tda8295_i2c_bridge(fe, 1);
427 if (fe->ops.tuner_ops.set_analog_params)
428 fe->ops.tuner_ops.set_analog_params(fe, params);
433 if (tda8295_has_signal(fe))
434 tuner_dbg("tda8295 is locked\n");
436 tuner_dbg("tda8295 not locked, no signal?\n");
438 tda8295_i2c_bridge(fe, 0);
441 /*---------------------------------------------------------------------*/
443 static int tda8290_has_signal(struct dvb_frontend *fe)
445 struct tda8290_priv *priv = fe->analog_demod_priv;
447 unsigned char i2c_get_afc[1] = { 0x1B };
448 unsigned char afc = 0;
450 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
451 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
452 return (afc & 0x80)? 65535:0;
455 /*---------------------------------------------------------------------*/
457 static void tda8290_standby(struct dvb_frontend *fe)
459 struct tda8290_priv *priv = fe->analog_demod_priv;
461 unsigned char cb1[] = { 0x30, 0xD0 };
462 unsigned char tda8290_standby[] = { 0x00, 0x02 };
463 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
464 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
466 tda8290_i2c_bridge(fe, 1);
467 if (priv->ver & TDA8275A)
469 i2c_transfer(priv->i2c_props.adap, &msg, 1);
470 tda8290_i2c_bridge(fe, 0);
471 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
472 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
475 static void tda8295_standby(struct dvb_frontend *fe)
477 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
479 tda8295_power(fe, 0);
482 static void tda8290_init_if(struct dvb_frontend *fe)
484 struct tda8290_priv *priv = fe->analog_demod_priv;
486 unsigned char set_VS[] = { 0x30, 0x6F };
487 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
488 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
490 if ((priv->cfg.config == 1) || (priv->cfg.config == 2))
491 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
493 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
494 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
497 static void tda8295_init_if(struct dvb_frontend *fe)
499 struct tda8290_priv *priv = fe->analog_demod_priv;
501 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
502 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
503 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
504 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
505 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
506 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
507 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
509 tda8295_power(fe, 1);
511 tda8295_set_easy_mode(fe, 0);
512 tda8295_set_video_std(fe);
514 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
515 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
516 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
517 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
518 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
519 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
520 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
522 tda8295_agc1_out(fe, 0);
523 tda8295_agc2_out(fe, 0);
526 static void tda8290_init_tuner(struct dvb_frontend *fe)
528 struct tda8290_priv *priv = fe->analog_demod_priv;
529 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
530 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
531 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
532 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
533 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
534 .buf=tda8275_init, .len = 14};
535 if (priv->ver & TDA8275A)
536 msg.buf = tda8275a_init;
538 tda8290_i2c_bridge(fe, 1);
539 i2c_transfer(priv->i2c_props.adap, &msg, 1);
540 tda8290_i2c_bridge(fe, 0);
543 /*---------------------------------------------------------------------*/
545 static void tda829x_release(struct dvb_frontend *fe)
547 struct tda8290_priv *priv = fe->analog_demod_priv;
549 /* only try to release the tuner if we've
550 * attached it from within this module */
551 if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
552 if (fe->ops.tuner_ops.release)
553 fe->ops.tuner_ops.release(fe);
555 kfree(fe->analog_demod_priv);
556 fe->analog_demod_priv = NULL;
559 static struct tda18271_config tda829x_tda18271_config = {
560 .gate = TDA18271_GATE_ANALOG,
563 static int tda829x_find_tuner(struct dvb_frontend *fe)
565 struct tda8290_priv *priv = fe->analog_demod_priv;
566 struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
567 int i, ret, tuners_found;
570 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
572 if (!analog_ops->i2c_gate_ctrl) {
573 printk(KERN_ERR "tda8290: no gate control were provided!\n");
578 analog_ops->i2c_gate_ctrl(fe, 1);
580 /* probe for tuner chip */
583 for (i = 0x60; i <= 0x63; i++) {
585 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
588 tuner_addrs = (tuner_addrs << 8) + i;
591 /* if there is more than one tuner, we expect the right one is
592 behind the bridge and we choose the highest address that doesn't
596 analog_ops->i2c_gate_ctrl(fe, 0);
598 if (tuners_found > 1)
599 for (i = 0; i < tuners_found; i++) {
600 msg.addr = tuner_addrs & 0xff;
601 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
603 tuner_addrs = tuner_addrs >> 8;
608 if (tuner_addrs == 0) {
610 tuner_info("could not clearly identify tuner address, "
611 "defaulting to %x\n", tuner_addrs);
613 tuner_addrs = tuner_addrs & 0xff;
614 tuner_info("setting tuner address to %x\n", tuner_addrs);
616 priv->tda827x_addr = tuner_addrs;
617 msg.addr = tuner_addrs;
619 analog_ops->i2c_gate_ctrl(fe, 1);
620 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
623 tuner_warn("tuner access failed!\n");
624 analog_ops->i2c_gate_ctrl(fe, 0);
628 if ((data == 0x83) || (data == 0x84)) {
629 priv->ver |= TDA18271;
630 tda829x_tda18271_config.config = priv->cfg.config;
631 dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
632 priv->i2c_props.adap, &tda829x_tda18271_config);
634 if ((data & 0x3c) == 0)
635 priv->ver |= TDA8275;
637 priv->ver |= TDA8275A;
639 dvb_attach(tda827x_attach, fe, priv->tda827x_addr,
640 priv->i2c_props.adap, &priv->cfg);
641 priv->cfg.switch_addr = priv->i2c_props.addr;
643 if (fe->ops.tuner_ops.init)
644 fe->ops.tuner_ops.init(fe);
646 if (fe->ops.tuner_ops.sleep)
647 fe->ops.tuner_ops.sleep(fe);
649 analog_ops->i2c_gate_ctrl(fe, 0);
654 static int tda8290_probe(struct tuner_i2c_props *i2c_props)
656 #define TDA8290_ID 0x89
657 unsigned char tda8290_id[] = { 0x1f, 0x00 };
660 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
661 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
663 if (tda8290_id[1] == TDA8290_ID) {
665 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
666 __func__, i2c_adapter_id(i2c_props->adap),
674 static int tda8295_probe(struct tuner_i2c_props *i2c_props)
676 #define TDA8295_ID 0x8a
677 #define TDA8295C2_ID 0x8b
678 unsigned char tda8295_id[] = { 0x2f, 0x00 };
681 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
682 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
684 if ((tda8295_id[1] & 0xfe) == TDA8295_ID) {
686 printk(KERN_DEBUG "%s: %s detected @ %d-%04x\n",
687 __func__, (tda8295_id[1] == TDA8295_ID) ?
688 "tda8295c1" : "tda8295c2",
689 i2c_adapter_id(i2c_props->adap),
697 static struct analog_demod_ops tda8290_ops = {
698 .set_params = tda8290_set_params,
699 .has_signal = tda8290_has_signal,
700 .standby = tda8290_standby,
701 .release = tda829x_release,
702 .i2c_gate_ctrl = tda8290_i2c_bridge,
705 static struct analog_demod_ops tda8295_ops = {
706 .set_params = tda8295_set_params,
707 .has_signal = tda8295_has_signal,
708 .standby = tda8295_standby,
709 .release = tda829x_release,
710 .i2c_gate_ctrl = tda8295_i2c_bridge,
713 struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
714 struct i2c_adapter *i2c_adap, u8 i2c_addr,
715 struct tda829x_config *cfg)
717 struct tda8290_priv *priv = NULL;
720 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
723 fe->analog_demod_priv = priv;
725 priv->i2c_props.addr = i2c_addr;
726 priv->i2c_props.adap = i2c_adap;
727 priv->i2c_props.name = "tda829x";
729 priv->cfg.config = cfg->lna_cfg;
731 if (tda8290_probe(&priv->i2c_props) == 0) {
733 memcpy(&fe->ops.analog_ops, &tda8290_ops,
734 sizeof(struct analog_demod_ops));
737 if (tda8295_probe(&priv->i2c_props) == 0) {
739 memcpy(&fe->ops.analog_ops, &tda8295_ops,
740 sizeof(struct analog_demod_ops));
743 if ((!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) &&
744 (tda829x_find_tuner(fe) < 0))
754 case TDA8290 | TDA8275:
757 case TDA8295 | TDA8275:
760 case TDA8290 | TDA8275A:
761 name = "tda8290+75a";
763 case TDA8295 | TDA8275A:
764 name = "tda8295+75a";
766 case TDA8290 | TDA18271:
767 name = "tda8290+18271";
769 case TDA8295 | TDA18271:
770 name = "tda8295+18271";
775 tuner_info("type set to %s\n", name);
777 fe->ops.analog_ops.info.name = name;
779 if (priv->ver & TDA8290) {
780 if (priv->ver & (TDA8275 | TDA8275A))
781 tda8290_init_tuner(fe);
783 } else if (priv->ver & TDA8295)
792 EXPORT_SYMBOL_GPL(tda829x_attach);
794 int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
796 struct tuner_i2c_props i2c_props = {
801 unsigned char soft_reset[] = { 0x00, 0x00 };
802 unsigned char easy_mode_b[] = { 0x01, 0x02 };
803 unsigned char easy_mode_g[] = { 0x01, 0x04 };
804 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
805 unsigned char addr_dto_lsb = 0x07;
807 #define PROBE_BUFFER_SIZE 8
808 unsigned char buf[PROBE_BUFFER_SIZE];
811 /* rule out tda9887, which would return the same byte repeatedly */
812 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
813 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
814 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
815 if (buf[i] != buf[0])
819 /* all bytes are equal, not a tda829x - probably a tda9887 */
820 if (i == PROBE_BUFFER_SIZE)
823 if ((tda8290_probe(&i2c_props) == 0) ||
824 (tda8295_probe(&i2c_props) == 0))
827 /* fall back to old probing method */
828 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
829 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
830 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
831 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
833 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
834 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
835 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
836 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
841 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
844 EXPORT_SYMBOL_GPL(tda829x_probe);
846 MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
847 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
848 MODULE_LICENSE("GPL");
851 * Overrides for Emacs so that we follow Linus's tabbing style.
852 * ---------------------------------------------------------------------------