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 (NULL
== priv
->cfg
) {
560 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
564 if (priv
->cfg
->config
) {
566 dprintk("setting LNA to high gain\n");
568 dprintk("setting LNA to low gain\n");
570 switch (*priv
->cfg
->config
) {
573 case 1: /* switch is GPIO 0 of tda8290 */
576 if (params
->std
& V4L2_STD_MN
)
580 if (priv
->cfg
->tuner_callback
)
581 priv
->cfg
->tuner_callback(priv
->i2c_adap
->algo_data
,
583 buf
[1] = high
? 0 : 1;
584 if (*priv
->cfg
->config
== 2)
585 buf
[1] = high
? 1 : 0;
586 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
588 case 3: /* switch with GPIO of saa713x */
589 if (priv
->cfg
->tuner_callback
)
590 priv
->cfg
->tuner_callback(priv
->i2c_adap
->algo_data
,
596 static int tda827xa_set_analog_params(struct dvb_frontend
*fe
,
597 struct analog_parameters
*params
)
599 unsigned char tuner_reg
[11];
602 struct tda827x_priv
*priv
= fe
->tuner_priv
;
603 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
604 .buf
= tuner_reg
, .len
= sizeof(tuner_reg
) };
605 unsigned int freq
= params
->frequency
;
607 tda827x_set_std(fe
, params
);
609 tda827xa_lna_gain(fe
, 1, params
);
612 if (params
->mode
== V4L2_TUNER_RADIO
)
615 N
= freq
+ priv
->sgIF
;
618 while (tda827xa_analog
[i
].lomax
< N
* 62500) {
619 if (tda827xa_analog
[i
+ 1].lomax
== 0)
624 N
= N
<< tda827xa_analog
[i
].spd
;
627 tuner_reg
[1] = (unsigned char)(N
>>8);
628 tuner_reg
[2] = (unsigned char) N
;
631 tuner_reg
[5] = (tda827xa_analog
[i
].spd
<< 5) +
632 (tda827xa_analog
[i
].svco
<< 3) +
633 tda827xa_analog
[i
].sbs
;
634 tuner_reg
[6] = 0x8b + (tda827xa_analog
[i
].gc3
<< 4);
638 tuner_reg
[10] = 0x00;
640 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
646 tuner_reg
[4] = 0x99 + (priv
->lpsel
<< 1);
648 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
653 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
656 tuner_reg
[1] = 0x10 + tda827xa_analog
[i
].scr
;
657 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
659 msg
.flags
= I2C_M_RD
;
660 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
663 dprintk("AGC2 gain is: %d\n", tuner_reg
[1]);
664 if (tuner_reg
[1] < 1)
665 tda827xa_lna_gain(fe
, 0, params
);
670 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
674 tuner_reg
[1] = 0x8f + (tda827xa_analog
[i
].gc3
<< 4);
675 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
679 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
683 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
686 tuner_reg
[1] = 0x19 + (priv
->lpsel
<< 1);
687 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
689 priv
->frequency
= freq
* 62500;
694 static void tda827xa_agcf(struct dvb_frontend
*fe
)
696 struct tda827x_priv
*priv
= fe
->tuner_priv
;
697 unsigned char data
[] = {0x80, 0x2c};
698 struct i2c_msg msg
= {.addr
= priv
->i2c_addr
, .flags
= 0,
699 .buf
= data
, .len
= 2};
700 i2c_transfer(priv
->i2c_adap
, &msg
, 1);
703 /* ------------------------------------------------------------------ */
705 static int tda827x_release(struct dvb_frontend
*fe
)
707 kfree(fe
->tuner_priv
);
708 fe
->tuner_priv
= NULL
;
712 static int tda827x_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
714 struct tda827x_priv
*priv
= fe
->tuner_priv
;
715 *frequency
= priv
->frequency
;
719 static int tda827x_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
721 struct tda827x_priv
*priv
= fe
->tuner_priv
;
722 *bandwidth
= priv
->bandwidth
;
726 static int tda827x_init(struct dvb_frontend
*fe
)
728 struct tda827x_priv
*priv
= fe
->tuner_priv
;
729 dprintk("%s:\n", __FUNCTION__
);
730 if (priv
->cfg
&& priv
->cfg
->init
)
736 static int tda827x_probe_version(struct dvb_frontend
*fe
);
738 static int tda827x_initial_init(struct dvb_frontend
*fe
)
741 ret
= tda827x_probe_version(fe
);
744 return fe
->ops
.tuner_ops
.init(fe
);
747 static int tda827x_initial_sleep(struct dvb_frontend
*fe
)
750 ret
= tda827x_probe_version(fe
);
753 return fe
->ops
.tuner_ops
.sleep(fe
);
756 static struct dvb_tuner_ops tda827xo_tuner_ops
= {
758 .name
= "Philips TDA827X",
759 .frequency_min
= 55000000,
760 .frequency_max
= 860000000,
761 .frequency_step
= 250000
763 .release
= tda827x_release
,
764 .init
= tda827x_initial_init
,
765 .sleep
= tda827x_initial_sleep
,
766 .set_params
= tda827xo_set_params
,
767 .set_analog_params
= tda827xo_set_analog_params
,
768 .get_frequency
= tda827x_get_frequency
,
769 .get_bandwidth
= tda827x_get_bandwidth
,
772 static struct dvb_tuner_ops tda827xa_tuner_ops
= {
774 .name
= "Philips TDA827XA",
775 .frequency_min
= 44000000,
776 .frequency_max
= 906000000,
777 .frequency_step
= 62500
779 .release
= tda827x_release
,
780 .init
= tda827x_init
,
781 .sleep
= tda827xa_sleep
,
782 .set_params
= tda827xa_set_params
,
783 .set_analog_params
= tda827xa_set_analog_params
,
784 .get_frequency
= tda827x_get_frequency
,
785 .get_bandwidth
= tda827x_get_bandwidth
,
788 static int tda827x_probe_version(struct dvb_frontend
*fe
)
790 struct tda827x_priv
*priv
= fe
->tuner_priv
;
791 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= I2C_M_RD
,
792 .buf
= &data
, .len
= 1 };
793 if (fe
->ops
.i2c_gate_ctrl
)
794 fe
->ops
.i2c_gate_ctrl(fe
, 1);
795 if (i2c_transfer(priv
->i2c_adap
, &msg
, 1) != 1) {
796 printk("%s: could not read from tuner at addr: 0x%02x\n",
797 __FUNCTION__
, msg
.addr
<< 1);
800 if ((data
& 0x3c) == 0) {
801 dprintk("tda827x tuner found\n");
802 fe
->ops
.tuner_ops
.init
= tda827x_init
;
803 fe
->ops
.tuner_ops
.sleep
= tda827xo_sleep
;
805 priv
->cfg
->agcf
= tda827xo_agcf
;
807 dprintk("tda827xa tuner found\n");
808 memcpy(&fe
->ops
.tuner_ops
, &tda827xa_tuner_ops
, sizeof(struct dvb_tuner_ops
));
810 priv
->cfg
->agcf
= tda827xa_agcf
;
815 struct dvb_frontend
*tda827x_attach(struct dvb_frontend
*fe
, int addr
,
816 struct i2c_adapter
*i2c
,
817 struct tda827x_config
*cfg
)
819 struct tda827x_priv
*priv
= NULL
;
821 dprintk("%s:\n", __FUNCTION__
);
822 priv
= kzalloc(sizeof(struct tda827x_priv
), GFP_KERNEL
);
826 priv
->i2c_addr
= addr
;
827 priv
->i2c_adap
= i2c
;
829 memcpy(&fe
->ops
.tuner_ops
, &tda827xo_tuner_ops
, sizeof(struct dvb_tuner_ops
));
830 fe
->tuner_priv
= priv
;
832 dprintk("type set to %s\n", fe
->ops
.tuner_ops
.info
.name
);
836 EXPORT_SYMBOL_GPL(tda827x_attach
);
838 MODULE_DESCRIPTION("DVB TDA827x driver");
839 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
840 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
841 MODULE_LICENSE("GPL");
844 * Overrides for Emacs so that we follow Linus's tabbing style.
845 * ---------------------------------------------------------------------------