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", __func__);
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 __func__, 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", __func__);
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_sleep(struct dvb_frontend *fe)
394 struct tda827x_priv *priv = fe->tuner_priv;
395 static u8 buf[] = { 0x30, 0x90 };
396 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
397 .buf = buf, .len = sizeof(buf) };
399 dprintk("%s:\n", __func__);
400 if (fe->ops.i2c_gate_ctrl)
401 fe->ops.i2c_gate_ctrl(fe, 1);
403 i2c_transfer(priv->i2c_adap, &msg, 1);
405 if (fe->ops.i2c_gate_ctrl)
406 fe->ops.i2c_gate_ctrl(fe, 0);
408 if (priv->cfg && priv->cfg->sleep)
409 priv->cfg->sleep(fe);
414 static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
415 struct analog_parameters *params)
417 struct tda827x_priv *priv = fe->tuner_priv;
418 unsigned char buf[] = {0x22, 0x01};
421 struct i2c_msg msg = { .flags = 0, .buf = buf, .len = sizeof(buf) };
423 if (NULL == priv->cfg) {
424 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
427 msg.addr = priv->cfg->switch_addr;
428 if (priv->cfg->config) {
430 dprintk("setting LNA to high gain\n");
432 dprintk("setting LNA to low gain\n");
434 switch (priv->cfg->config) {
437 case 1: /* switch is GPIO 0 of tda8290 */
439 if (params == NULL) {
445 if (params->std & V4L2_STD_MN)
451 fe->callback(priv->i2c_adap->algo_data,
452 DVB_FRONTEND_COMPONENT_TUNER,
454 buf[1] = high ? 0 : 1;
455 if (priv->cfg->config == 2)
456 buf[1] = high ? 1 : 0;
457 i2c_transfer(priv->i2c_adap, &msg, 1);
459 case 3: /* switch with GPIO of saa713x */
461 fe->callback(priv->i2c_adap->algo_data,
462 DVB_FRONTEND_COMPONENT_TUNER, 0, high);
467 static int tda827xa_set_params(struct dvb_frontend *fe,
468 struct dvb_frontend_parameters *params)
470 struct tda827x_priv *priv = fe->tuner_priv;
473 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
474 .buf = buf, .len = sizeof(buf) };
476 int i, tuner_freq, if_freq;
479 dprintk("%s:\n", __func__);
481 tda827xa_lna_gain(fe, 1, NULL);
484 switch (params->u.ofdm.bandwidth) {
485 case BANDWIDTH_6_MHZ:
488 case BANDWIDTH_7_MHZ:
491 default: /* 8 MHz or Auto */
495 tuner_freq = params->frequency + if_freq;
498 while (tda827xa_dvbt[i].lomax < tuner_freq) {
499 if(tda827xa_dvbt[i + 1].lomax == 0)
504 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
505 buf[0] = 0; // subaddress
510 buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
511 tda827xa_dvbt[i].sbs;
512 buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
518 if (fe->ops.i2c_gate_ctrl)
519 fe->ops.i2c_gate_ctrl(fe, 1);
520 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
521 printk("%s: could not write to tuner at addr: 0x%02x\n",
522 __func__, priv->i2c_addr << 1);
529 buf[4] = 0x59; // lpsel, for 6MHz + 2
531 if (fe->ops.i2c_gate_ctrl)
532 fe->ops.i2c_gate_ctrl(fe, 1);
533 i2c_transfer(priv->i2c_adap, &msg, 1);
538 if (fe->ops.i2c_gate_ctrl)
539 fe->ops.i2c_gate_ctrl(fe, 1);
540 i2c_transfer(priv->i2c_adap, &msg, 1);
543 msg.flags = I2C_M_RD;
544 if (fe->ops.i2c_gate_ctrl)
545 fe->ops.i2c_gate_ctrl(fe, 1);
546 i2c_transfer(priv->i2c_adap, &msg, 1);
550 dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);
552 tda827xa_lna_gain(fe, 0, NULL);
555 if (fe->ops.i2c_gate_ctrl)
556 fe->ops.i2c_gate_ctrl(fe, 1);
557 i2c_transfer(priv->i2c_adap, &msg, 1);
561 buf[1] = 0x99; // lpsel, for 6MHz + 2
562 if (fe->ops.i2c_gate_ctrl)
563 fe->ops.i2c_gate_ctrl(fe, 1);
564 i2c_transfer(priv->i2c_adap, &msg, 1);
568 if (fe->ops.i2c_gate_ctrl)
569 fe->ops.i2c_gate_ctrl(fe, 1);
570 i2c_transfer(priv->i2c_adap, &msg, 1);
572 /* correct CP value */
574 buf[1] = 0x10 + tda827xa_dvbt[i].scr;
575 if (fe->ops.i2c_gate_ctrl)
576 fe->ops.i2c_gate_ctrl(fe, 1);
577 i2c_transfer(priv->i2c_adap, &msg, 1);
581 buf[1] = 0x39; // lpsel, for 6MHz + 2
582 if (fe->ops.i2c_gate_ctrl)
583 fe->ops.i2c_gate_ctrl(fe, 1);
584 i2c_transfer(priv->i2c_adap, &msg, 1);
589 buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
590 if (fe->ops.i2c_gate_ctrl)
591 fe->ops.i2c_gate_ctrl(fe, 1);
592 i2c_transfer(priv->i2c_adap, &msg, 1);
594 priv->frequency = tuner_freq - if_freq; // FIXME
595 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
601 static int tda827xa_set_analog_params(struct dvb_frontend *fe,
602 struct analog_parameters *params)
604 unsigned char tuner_reg[11];
607 struct tda827x_priv *priv = fe->tuner_priv;
608 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
609 .buf = tuner_reg, .len = sizeof(tuner_reg) };
610 unsigned int freq = params->frequency;
612 tda827x_set_std(fe, params);
614 tda827xa_lna_gain(fe, 1, params);
617 if (params->mode == V4L2_TUNER_RADIO)
620 N = freq + priv->sgIF;
623 while (tda827xa_analog[i].lomax < N * 62500) {
624 if (tda827xa_analog[i + 1].lomax == 0)
629 N = N << tda827xa_analog[i].spd;
632 tuner_reg[1] = (unsigned char)(N>>8);
633 tuner_reg[2] = (unsigned char) N;
636 tuner_reg[5] = (tda827xa_analog[i].spd << 5) +
637 (tda827xa_analog[i].svco << 3) +
638 tda827xa_analog[i].sbs;
639 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
643 tuner_reg[10] = 0x00;
645 i2c_transfer(priv->i2c_adap, &msg, 1);
651 tuner_reg[4] = 0x99 + (priv->lpsel << 1);
653 i2c_transfer(priv->i2c_adap, &msg, 1);
658 i2c_transfer(priv->i2c_adap, &msg, 1);
661 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
662 i2c_transfer(priv->i2c_adap, &msg, 1);
664 msg.flags = I2C_M_RD;
665 i2c_transfer(priv->i2c_adap, &msg, 1);
668 dprintk("AGC2 gain is: %d\n", tuner_reg[1]);
669 if (tuner_reg[1] < 1)
670 tda827xa_lna_gain(fe, 0, params);
675 i2c_transfer(priv->i2c_adap, &msg, 1);
679 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
680 i2c_transfer(priv->i2c_adap, &msg, 1);
684 i2c_transfer(priv->i2c_adap, &msg, 1);
688 i2c_transfer(priv->i2c_adap, &msg, 1);
691 tuner_reg[1] = 0x19 + (priv->lpsel << 1);
692 i2c_transfer(priv->i2c_adap, &msg, 1);
694 priv->frequency = freq * 62500;
699 static void tda827xa_agcf(struct dvb_frontend *fe)
701 struct tda827x_priv *priv = fe->tuner_priv;
702 unsigned char data[] = {0x80, 0x2c};
703 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
704 .buf = data, .len = 2};
705 i2c_transfer(priv->i2c_adap, &msg, 1);
708 /* ------------------------------------------------------------------ */
710 static int tda827x_release(struct dvb_frontend *fe)
712 kfree(fe->tuner_priv);
713 fe->tuner_priv = NULL;
717 static int tda827x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
719 struct tda827x_priv *priv = fe->tuner_priv;
720 *frequency = priv->frequency;
724 static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
726 struct tda827x_priv *priv = fe->tuner_priv;
727 *bandwidth = priv->bandwidth;
731 static int tda827x_init(struct dvb_frontend *fe)
733 struct tda827x_priv *priv = fe->tuner_priv;
734 dprintk("%s:\n", __func__);
735 if (priv->cfg && priv->cfg->init)
741 static int tda827x_probe_version(struct dvb_frontend *fe);
743 static int tda827x_initial_init(struct dvb_frontend *fe)
746 ret = tda827x_probe_version(fe);
749 return fe->ops.tuner_ops.init(fe);
752 static int tda827x_initial_sleep(struct dvb_frontend *fe)
755 ret = tda827x_probe_version(fe);
758 return fe->ops.tuner_ops.sleep(fe);
761 static struct dvb_tuner_ops tda827xo_tuner_ops = {
763 .name = "Philips TDA827X",
764 .frequency_min = 55000000,
765 .frequency_max = 860000000,
766 .frequency_step = 250000
768 .release = tda827x_release,
769 .init = tda827x_initial_init,
770 .sleep = tda827x_initial_sleep,
771 .set_params = tda827xo_set_params,
772 .set_analog_params = tda827xo_set_analog_params,
773 .get_frequency = tda827x_get_frequency,
774 .get_bandwidth = tda827x_get_bandwidth,
777 static struct dvb_tuner_ops tda827xa_tuner_ops = {
779 .name = "Philips TDA827XA",
780 .frequency_min = 44000000,
781 .frequency_max = 906000000,
782 .frequency_step = 62500
784 .release = tda827x_release,
785 .init = tda827x_init,
786 .sleep = tda827xa_sleep,
787 .set_params = tda827xa_set_params,
788 .set_analog_params = tda827xa_set_analog_params,
789 .get_frequency = tda827x_get_frequency,
790 .get_bandwidth = tda827x_get_bandwidth,
793 static int tda827x_probe_version(struct dvb_frontend *fe)
795 struct tda827x_priv *priv = fe->tuner_priv;
796 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,
797 .buf = &data, .len = 1 };
798 if (fe->ops.i2c_gate_ctrl)
799 fe->ops.i2c_gate_ctrl(fe, 1);
800 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
801 printk("%s: could not read from tuner at addr: 0x%02x\n",
802 __func__, msg.addr << 1);
805 if ((data & 0x3c) == 0) {
806 dprintk("tda827x tuner found\n");
807 fe->ops.tuner_ops.init = tda827x_init;
808 fe->ops.tuner_ops.sleep = tda827xo_sleep;
810 priv->cfg->agcf = tda827xo_agcf;
812 dprintk("tda827xa tuner found\n");
813 memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));
815 priv->cfg->agcf = tda827xa_agcf;
820 struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
821 struct i2c_adapter *i2c,
822 struct tda827x_config *cfg)
824 struct tda827x_priv *priv = NULL;
826 dprintk("%s:\n", __func__);
827 priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);
831 priv->i2c_addr = addr;
832 priv->i2c_adap = i2c;
834 memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops));
835 fe->tuner_priv = priv;
837 dprintk("type set to %s\n", fe->ops.tuner_ops.info.name);
841 EXPORT_SYMBOL_GPL(tda827x_attach);
843 MODULE_DESCRIPTION("DVB TDA827x driver");
844 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
845 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
846 MODULE_LICENSE("GPL");
849 * Overrides for Emacs so that we follow Linus's tabbing style.
850 * ---------------------------------------------------------------------------