3 * (c) 2005 Hartmut Hackmann
4 * (c) 2007 Michael Krufky
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.
21 #include <linux/module.h>
22 #include <asm/types.h>
23 #include <linux/dvb/frontend.h>
24 #include <linux/videodev2.h>
29 module_param(debug, int, 0644);
30 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
32 #define dprintk(args...) \
34 if (debug) printk(KERN_DEBUG "tda827x: " args); \
39 struct i2c_adapter *i2c_adap;
40 struct tda827x_config *cfg;
49 static void tda827x_set_std(struct dvb_frontend *fe,
50 struct analog_parameters *params)
52 struct tda827x_priv *priv = fe->tuner_priv;
56 if (params->std & V4L2_STD_MN) {
60 } else if (params->std & V4L2_STD_B) {
63 } else if (params->std & V4L2_STD_GH) {
66 } else if (params->std & V4L2_STD_PAL_I) {
69 } else if (params->std & V4L2_STD_DK) {
72 } else if (params->std & V4L2_STD_SECAM_L) {
75 } else if (params->std & V4L2_STD_SECAM_LC) {
83 if (params->mode == V4L2_TUNER_RADIO)
84 priv->sgIF = 88; /* if frequency is 5.5 MHz */
86 dprintk("setting tda827x to system %s\n", mode);
90 /* ------------------------------------------------------------------ */
102 static const struct tda827x_data tda827x_table[] = {
103 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
104 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
105 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
106 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
107 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
108 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
109 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
110 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
111 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
112 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
113 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
114 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
115 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
116 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
117 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
118 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
119 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
120 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
121 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
122 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
123 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
124 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
125 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
126 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
127 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
128 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
129 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
130 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
131 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
134 static int tda827xo_set_params(struct dvb_frontend *fe,
135 struct dvb_frontend_parameters *params)
137 struct tda827x_priv *priv = fe->tuner_priv;
140 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
141 .buf = buf, .len = sizeof(buf) };
142 int i, tuner_freq, if_freq;
145 dprintk("%s:\n", __FUNCTION__);
146 switch (params->u.ofdm.bandwidth) {
147 case BANDWIDTH_6_MHZ:
150 case BANDWIDTH_7_MHZ:
153 default: /* 8 MHz or Auto */
157 tuner_freq = params->frequency + if_freq;
160 while (tda827x_table[i].lomax < tuner_freq) {
161 if (tda827x_table[i + 1].lomax == 0)
166 N = ((tuner_freq + 125000) / 250000) << (tda827x_table[i].spd + 2);
168 buf[1] = (N>>8) | 0x40;
172 buf[5] = (tda827x_table[i].spd << 6) + (tda827x_table[i].div1p5 << 5) +
173 (tda827x_table[i].bs << 3) +
175 buf[6] = (tda827x_table[i].gc3 << 4) + 0x8f;
185 if (fe->ops.i2c_gate_ctrl)
186 fe->ops.i2c_gate_ctrl(fe, 1);
187 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
188 printk("%s: could not write to tuner at addr: 0x%02x\n",
189 __FUNCTION__, priv->i2c_addr << 1);
193 /* correct CP value */
195 buf[1] = 0x50 + tda827x_table[i].cp;
198 if (fe->ops.i2c_gate_ctrl)
199 fe->ops.i2c_gate_ctrl(fe, 1);
200 i2c_transfer(priv->i2c_adap, &msg, 1);
202 priv->frequency = tuner_freq - if_freq; // FIXME
203 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
208 static int tda827xo_sleep(struct dvb_frontend *fe)
210 struct tda827x_priv *priv = fe->tuner_priv;
211 static u8 buf[] = { 0x30, 0xd0 };
212 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
213 .buf = buf, .len = sizeof(buf) };
215 dprintk("%s:\n", __FUNCTION__);
216 if (fe->ops.i2c_gate_ctrl)
217 fe->ops.i2c_gate_ctrl(fe, 1);
218 i2c_transfer(priv->i2c_adap, &msg, 1);
220 if (priv->cfg && priv->cfg->sleep)
221 priv->cfg->sleep(fe);
226 /* ------------------------------------------------------------------ */
228 static int tda827xo_set_analog_params(struct dvb_frontend *fe,
229 struct analog_parameters *params)
231 unsigned char tuner_reg[8];
232 unsigned char reg2[2];
235 struct tda827x_priv *priv = fe->tuner_priv;
236 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0 };
237 unsigned int freq = params->frequency;
239 tda827x_set_std(fe, params);
241 if (params->mode == V4L2_TUNER_RADIO)
244 N = freq + priv->sgIF;
247 while (tda827x_table[i].lomax < N * 62500) {
248 if (tda827x_table[i + 1].lomax == 0)
253 N = N << tda827x_table[i].spd;
256 tuner_reg[1] = (unsigned char)(N>>8);
257 tuner_reg[2] = (unsigned char) N;
259 tuner_reg[4] = 0x52 + (priv->lpsel << 5);
260 tuner_reg[5] = (tda827x_table[i].spd << 6) +
261 (tda827x_table[i].div1p5 << 5) +
262 (tda827x_table[i].bs << 3) + tda827x_table[i].bp;
263 tuner_reg[6] = 0x8f + (tda827x_table[i].gc3 << 4);
268 i2c_transfer(priv->i2c_adap, &msg, 1);
274 i2c_transfer(priv->i2c_adap, &msg, 1);
278 i2c_transfer(priv->i2c_adap, &msg, 1);
281 reg2[1] = tuner_reg[4] + 0x80;
282 i2c_transfer(priv->i2c_adap, &msg, 1);
286 reg2[1] = tuner_reg[4] + 4;
287 i2c_transfer(priv->i2c_adap, &msg, 1);
291 reg2[1] = tuner_reg[4];
292 i2c_transfer(priv->i2c_adap, &msg, 1);
296 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_table[i].cp;
297 i2c_transfer(priv->i2c_adap, &msg, 1);
301 i2c_transfer(priv->i2c_adap, &msg, 1);
304 reg2[1] = 0x08; /* Vsync en */
305 i2c_transfer(priv->i2c_adap, &msg, 1);
307 priv->frequency = freq * 62500;
312 static void tda827xo_agcf(struct dvb_frontend *fe)
314 struct tda827x_priv *priv = fe->tuner_priv;
315 unsigned char data[] = { 0x80, 0x0c };
316 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
317 .buf = data, .len = 2};
319 i2c_transfer(priv->i2c_adap, &msg, 1);
322 /* ------------------------------------------------------------------ */
324 struct tda827xa_data {
333 static const struct tda827xa_data tda827xa_dvbt[] = {
334 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
335 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
336 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
337 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
338 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
339 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
340 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
341 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
342 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
343 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
344 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
345 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
346 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
347 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
348 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
349 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
350 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
351 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
352 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
353 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
354 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
355 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
356 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
357 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
358 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
359 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
360 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
363 static struct tda827xa_data tda827xa_analog[] = {
364 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3},
365 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
366 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
367 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
368 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
369 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
370 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
371 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
372 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
373 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
374 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3},
375 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3},
376 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
377 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
378 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
379 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
380 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
381 { .lomax = 554000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
382 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
383 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
384 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
385 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
386 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
387 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
388 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
389 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
392 static int tda827xa_set_params(struct dvb_frontend *fe,
393 struct dvb_frontend_parameters *params)
395 struct tda827x_priv *priv = fe->tuner_priv;
398 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
399 .buf = buf, .len = sizeof(buf) };
401 int i, tuner_freq, if_freq;
404 dprintk("%s:\n", __FUNCTION__);
405 if (priv->cfg && priv->cfg->lna_gain)
406 priv->cfg->lna_gain(fe, 1);
409 switch (params->u.ofdm.bandwidth) {
410 case BANDWIDTH_6_MHZ:
413 case BANDWIDTH_7_MHZ:
416 default: /* 8 MHz or Auto */
420 tuner_freq = params->frequency + if_freq;
423 while (tda827xa_dvbt[i].lomax < tuner_freq) {
424 if(tda827xa_dvbt[i + 1].lomax == 0)
429 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
430 buf[0] = 0; // subaddress
435 buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
436 tda827xa_dvbt[i].sbs;
437 buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
443 if (fe->ops.i2c_gate_ctrl)
444 fe->ops.i2c_gate_ctrl(fe, 1);
445 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
446 printk("%s: could not write to tuner at addr: 0x%02x\n",
447 __FUNCTION__, priv->i2c_addr << 1);
454 buf[4] = 0x59; // lpsel, for 6MHz + 2
456 if (fe->ops.i2c_gate_ctrl)
457 fe->ops.i2c_gate_ctrl(fe, 1);
458 i2c_transfer(priv->i2c_adap, &msg, 1);
463 if (fe->ops.i2c_gate_ctrl)
464 fe->ops.i2c_gate_ctrl(fe, 1);
465 i2c_transfer(priv->i2c_adap, &msg, 1);
468 msg.flags = I2C_M_RD;
469 if (fe->ops.i2c_gate_ctrl)
470 fe->ops.i2c_gate_ctrl(fe, 1);
471 i2c_transfer(priv->i2c_adap, &msg, 1);
475 dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);
477 if (priv->cfg && priv->cfg->lna_gain)
478 priv->cfg->lna_gain(fe, 0);
481 if (fe->ops.i2c_gate_ctrl)
482 fe->ops.i2c_gate_ctrl(fe, 1);
483 i2c_transfer(priv->i2c_adap, &msg, 1);
487 buf[1] = 0x99; // lpsel, for 6MHz + 2
488 if (fe->ops.i2c_gate_ctrl)
489 fe->ops.i2c_gate_ctrl(fe, 1);
490 i2c_transfer(priv->i2c_adap, &msg, 1);
494 if (fe->ops.i2c_gate_ctrl)
495 fe->ops.i2c_gate_ctrl(fe, 1);
496 i2c_transfer(priv->i2c_adap, &msg, 1);
498 /* correct CP value */
500 buf[1] = 0x10 + tda827xa_dvbt[i].scr;
501 if (fe->ops.i2c_gate_ctrl)
502 fe->ops.i2c_gate_ctrl(fe, 1);
503 i2c_transfer(priv->i2c_adap, &msg, 1);
507 buf[1] = 0x39; // lpsel, for 6MHz + 2
508 if (fe->ops.i2c_gate_ctrl)
509 fe->ops.i2c_gate_ctrl(fe, 1);
510 i2c_transfer(priv->i2c_adap, &msg, 1);
515 buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
516 if (fe->ops.i2c_gate_ctrl)
517 fe->ops.i2c_gate_ctrl(fe, 1);
518 i2c_transfer(priv->i2c_adap, &msg, 1);
520 priv->frequency = tuner_freq - if_freq; // FIXME
521 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
526 static int tda827xa_sleep(struct dvb_frontend *fe)
528 struct tda827x_priv *priv = fe->tuner_priv;
529 static u8 buf[] = { 0x30, 0x90 };
530 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
531 .buf = buf, .len = sizeof(buf) };
533 dprintk("%s:\n", __FUNCTION__);
534 if (fe->ops.i2c_gate_ctrl)
535 fe->ops.i2c_gate_ctrl(fe, 1);
537 i2c_transfer(priv->i2c_adap, &msg, 1);
539 if (fe->ops.i2c_gate_ctrl)
540 fe->ops.i2c_gate_ctrl(fe, 0);
542 if (priv->cfg && priv->cfg->sleep)
543 priv->cfg->sleep(fe);
548 /* ------------------------------------------------------------------ */
550 static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
551 struct analog_parameters *params)
553 struct tda827x_priv *priv = fe->tuner_priv;
554 unsigned char buf[] = {0x22, 0x01};
556 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
557 .buf = buf, .len = sizeof(buf) };
559 if (priv->cfg->config) {
561 dprintk("setting LNA to high gain\n");
563 dprintk("setting LNA to low gain\n");
565 switch (*priv->cfg->config) {
568 case 1: /* switch is GPIO 0 of tda8290 */
571 if (params->std & V4L2_STD_MN)
575 if (priv->cfg->tuner_callback)
576 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
578 buf[1] = high ? 0 : 1;
579 if (*priv->cfg->config == 2)
580 buf[1] = high ? 1 : 0;
581 i2c_transfer(priv->i2c_adap, &msg, 1);
583 case 3: /* switch with GPIO of saa713x */
584 if (priv->cfg->tuner_callback)
585 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
591 static int tda827xa_set_analog_params(struct dvb_frontend *fe,
592 struct analog_parameters *params)
594 unsigned char tuner_reg[11];
597 struct tda827x_priv *priv = fe->tuner_priv;
598 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
599 .buf = tuner_reg, .len = sizeof(tuner_reg) };
600 unsigned int freq = params->frequency;
602 tda827x_set_std(fe, params);
604 tda827xa_lna_gain(fe, 1, params);
607 if (params->mode == V4L2_TUNER_RADIO)
610 N = freq + priv->sgIF;
613 while (tda827xa_analog[i].lomax < N * 62500) {
614 if (tda827xa_analog[i + 1].lomax == 0)
619 N = N << tda827xa_analog[i].spd;
622 tuner_reg[1] = (unsigned char)(N>>8);
623 tuner_reg[2] = (unsigned char) N;
626 tuner_reg[5] = (tda827xa_analog[i].spd << 5) +
627 (tda827xa_analog[i].svco << 3) +
628 tda827xa_analog[i].sbs;
629 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
633 tuner_reg[10] = 0x00;
635 i2c_transfer(priv->i2c_adap, &msg, 1);
641 tuner_reg[4] = 0x99 + (priv->lpsel << 1);
643 i2c_transfer(priv->i2c_adap, &msg, 1);
648 i2c_transfer(priv->i2c_adap, &msg, 1);
651 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
652 i2c_transfer(priv->i2c_adap, &msg, 1);
654 msg.flags = I2C_M_RD;
655 i2c_transfer(priv->i2c_adap, &msg, 1);
658 dprintk("AGC2 gain is: %d\n", tuner_reg[1]);
659 if (tuner_reg[1] < 1)
660 tda827xa_lna_gain(fe, 0, params);
665 i2c_transfer(priv->i2c_adap, &msg, 1);
669 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
670 i2c_transfer(priv->i2c_adap, &msg, 1);
674 i2c_transfer(priv->i2c_adap, &msg, 1);
678 i2c_transfer(priv->i2c_adap, &msg, 1);
681 tuner_reg[1] = 0x19 + (priv->lpsel << 1);
682 i2c_transfer(priv->i2c_adap, &msg, 1);
684 priv->frequency = freq * 62500;
689 static void tda827xa_agcf(struct dvb_frontend *fe)
691 struct tda827x_priv *priv = fe->tuner_priv;
692 unsigned char data[] = {0x80, 0x2c};
693 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
694 .buf = data, .len = 2};
695 i2c_transfer(priv->i2c_adap, &msg, 1);
698 /* ------------------------------------------------------------------ */
700 static int tda827x_release(struct dvb_frontend *fe)
702 kfree(fe->tuner_priv);
703 fe->tuner_priv = NULL;
707 static int tda827x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
709 struct tda827x_priv *priv = fe->tuner_priv;
710 *frequency = priv->frequency;
714 static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
716 struct tda827x_priv *priv = fe->tuner_priv;
717 *bandwidth = priv->bandwidth;
721 static int tda827x_init(struct dvb_frontend *fe)
723 struct tda827x_priv *priv = fe->tuner_priv;
724 dprintk("%s:\n", __FUNCTION__);
725 if (priv->cfg && priv->cfg->init)
731 static int tda827x_probe_version(struct dvb_frontend *fe);
733 static int tda827x_initial_init(struct dvb_frontend *fe)
736 ret = tda827x_probe_version(fe);
739 return fe->ops.tuner_ops.init(fe);
742 static int tda827x_initial_sleep(struct dvb_frontend *fe)
745 ret = tda827x_probe_version(fe);
748 return fe->ops.tuner_ops.sleep(fe);
751 static struct dvb_tuner_ops tda827xo_tuner_ops = {
753 .name = "Philips TDA827X",
754 .frequency_min = 55000000,
755 .frequency_max = 860000000,
756 .frequency_step = 250000
758 .release = tda827x_release,
759 .init = tda827x_initial_init,
760 .sleep = tda827x_initial_sleep,
761 .set_params = tda827xo_set_params,
762 .set_analog_params = tda827xo_set_analog_params,
763 .get_frequency = tda827x_get_frequency,
764 .get_bandwidth = tda827x_get_bandwidth,
767 static struct dvb_tuner_ops tda827xa_tuner_ops = {
769 .name = "Philips TDA827XA",
770 .frequency_min = 44000000,
771 .frequency_max = 906000000,
772 .frequency_step = 62500
774 .release = tda827x_release,
775 .init = tda827x_init,
776 .sleep = tda827xa_sleep,
777 .set_params = tda827xa_set_params,
778 .set_analog_params = tda827xa_set_analog_params,
779 .get_frequency = tda827x_get_frequency,
780 .get_bandwidth = tda827x_get_bandwidth,
783 static int tda827x_probe_version(struct dvb_frontend *fe)
785 struct tda827x_priv *priv = fe->tuner_priv;
786 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,
787 .buf = &data, .len = 1 };
788 if (fe->ops.i2c_gate_ctrl)
789 fe->ops.i2c_gate_ctrl(fe, 1);
790 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
791 printk("%s: could not read from tuner at addr: 0x%02x\n",
792 __FUNCTION__, msg.addr << 1);
795 if ((data & 0x3c) == 0) {
796 dprintk("tda827x tuner found\n");
797 fe->ops.tuner_ops.init = tda827x_init;
798 fe->ops.tuner_ops.sleep = tda827xo_sleep;
799 priv->cfg->agcf = tda827xo_agcf;
801 dprintk("tda827xa tuner found\n");
802 memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));
803 priv->cfg->agcf = tda827xa_agcf;
808 struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
809 struct i2c_adapter *i2c,
810 struct tda827x_config *cfg)
812 struct tda827x_priv *priv = NULL;
814 dprintk("%s:\n", __FUNCTION__);
815 priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);
819 priv->i2c_addr = addr;
820 priv->i2c_adap = i2c;
822 memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops));
823 fe->tuner_priv = priv;
825 dprintk("type set to %s\n", fe->ops.tuner_ops.info.name);
829 EXPORT_SYMBOL_GPL(tda827x_attach);
831 MODULE_DESCRIPTION("DVB TDA827x driver");
832 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
833 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
834 MODULE_LICENSE("GPL");
837 * Overrides for Emacs so that we follow Linus's tabbing style.
838 * ---------------------------------------------------------------------------