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 <linux/slab.h>
23 #include <asm/types.h>
24 #include <linux/dvb/frontend.h>
25 #include <linux/videodev2.h>
30 module_param(debug
, int, 0644);
31 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
33 #define dprintk(args...) \
35 if (debug) printk(KERN_DEBUG "tda827x: " args); \
40 struct i2c_adapter
*i2c_adap
;
41 struct tda827x_config
*cfg
;
50 static void tda827x_set_std(struct dvb_frontend
*fe
,
51 struct analog_parameters
*params
)
53 struct tda827x_priv
*priv
= fe
->tuner_priv
;
57 if (params
->std
& V4L2_STD_MN
) {
61 } else if (params
->std
& V4L2_STD_B
) {
64 } else if (params
->std
& V4L2_STD_GH
) {
67 } else if (params
->std
& V4L2_STD_PAL_I
) {
70 } else if (params
->std
& V4L2_STD_DK
) {
73 } else if (params
->std
& V4L2_STD_SECAM_L
) {
76 } else if (params
->std
& V4L2_STD_SECAM_LC
) {
84 if (params
->mode
== V4L2_TUNER_RADIO
) {
85 priv
->sgIF
= 88; /* if frequency is 5.5 MHz */
86 dprintk("setting tda827x to radio FM\n");
88 dprintk("setting tda827x to system %s\n", mode
);
92 /* ------------------------------------------------------------------ */
104 static const struct tda827x_data tda827x_table
[] = {
105 { .lomax
= 62000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
106 { .lomax
= 66000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
107 { .lomax
= 76000000, .spd
= 3, .bs
= 1, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
108 { .lomax
= 84000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
109 { .lomax
= 93000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
110 { .lomax
= 98000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
111 { .lomax
= 109000000, .spd
= 3, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
112 { .lomax
= 123000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
113 { .lomax
= 133000000, .spd
= 2, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
114 { .lomax
= 151000000, .spd
= 2, .bs
= 1, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
115 { .lomax
= 154000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
116 { .lomax
= 181000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 0, .div1p5
= 0},
117 { .lomax
= 185000000, .spd
= 2, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
118 { .lomax
= 217000000, .spd
= 2, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
119 { .lomax
= 244000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
120 { .lomax
= 265000000, .spd
= 1, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
121 { .lomax
= 302000000, .spd
= 1, .bs
= 1, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
122 { .lomax
= 324000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
123 { .lomax
= 370000000, .spd
= 1, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
124 { .lomax
= 454000000, .spd
= 1, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
125 { .lomax
= 493000000, .spd
= 0, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
126 { .lomax
= 530000000, .spd
= 0, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
127 { .lomax
= 554000000, .spd
= 0, .bs
= 1, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
128 { .lomax
= 604000000, .spd
= 0, .bs
= 1, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
129 { .lomax
= 696000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
130 { .lomax
= 740000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
131 { .lomax
= 820000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
132 { .lomax
= 865000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
133 { .lomax
= 0, .spd
= 0, .bs
= 0, .bp
= 0, .cp
= 0, .gc3
= 0, .div1p5
= 0}
136 static int tuner_transfer(struct dvb_frontend
*fe
,
141 struct tda827x_priv
*priv
= fe
->tuner_priv
;
143 if (fe
->ops
.i2c_gate_ctrl
)
144 fe
->ops
.i2c_gate_ctrl(fe
, 1);
145 rc
= i2c_transfer(priv
->i2c_adap
, msg
, size
);
146 if (fe
->ops
.i2c_gate_ctrl
)
147 fe
->ops
.i2c_gate_ctrl(fe
, 0);
149 if (rc
>= 0 && rc
!= size
)
155 static int tda827xo_set_params(struct dvb_frontend
*fe
,
156 struct dvb_frontend_parameters
*params
)
158 struct tda827x_priv
*priv
= fe
->tuner_priv
;
162 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
163 .buf
= buf
, .len
= sizeof(buf
) };
164 int i
, tuner_freq
, if_freq
;
167 dprintk("%s:\n", __func__
);
168 switch (params
->u
.ofdm
.bandwidth
) {
169 case BANDWIDTH_6_MHZ
:
172 case BANDWIDTH_7_MHZ
:
175 default: /* 8 MHz or Auto */
179 tuner_freq
= params
->frequency
+ if_freq
;
182 while (tda827x_table
[i
].lomax
< tuner_freq
) {
183 if (tda827x_table
[i
+ 1].lomax
== 0)
188 N
= ((tuner_freq
+ 125000) / 250000) << (tda827x_table
[i
].spd
+ 2);
190 buf
[1] = (N
>>8) | 0x40;
194 buf
[5] = (tda827x_table
[i
].spd
<< 6) + (tda827x_table
[i
].div1p5
<< 5) +
195 (tda827x_table
[i
].bs
<< 3) +
197 buf
[6] = (tda827x_table
[i
].gc3
<< 4) + 0x8f;
207 rc
= tuner_transfer(fe
, &msg
, 1);
212 /* correct CP value */
214 buf
[1] = 0x50 + tda827x_table
[i
].cp
;
217 rc
= tuner_transfer(fe
, &msg
, 1);
221 priv
->frequency
= params
->frequency
;
222 priv
->bandwidth
= (fe
->ops
.info
.type
== FE_OFDM
) ? params
->u
.ofdm
.bandwidth
: 0;
227 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
228 __func__
, priv
->i2c_addr
<< 1);
232 static int tda827xo_sleep(struct dvb_frontend
*fe
)
234 struct tda827x_priv
*priv
= fe
->tuner_priv
;
235 static u8 buf
[] = { 0x30, 0xd0 };
236 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
237 .buf
= buf
, .len
= sizeof(buf
) };
239 dprintk("%s:\n", __func__
);
240 tuner_transfer(fe
, &msg
, 1);
242 if (priv
->cfg
&& priv
->cfg
->sleep
)
243 priv
->cfg
->sleep(fe
);
248 /* ------------------------------------------------------------------ */
250 static int tda827xo_set_analog_params(struct dvb_frontend
*fe
,
251 struct analog_parameters
*params
)
253 unsigned char tuner_reg
[8];
254 unsigned char reg2
[2];
257 struct tda827x_priv
*priv
= fe
->tuner_priv
;
258 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0 };
259 unsigned int freq
= params
->frequency
;
261 tda827x_set_std(fe
, params
);
263 if (params
->mode
== V4L2_TUNER_RADIO
)
266 N
= freq
+ priv
->sgIF
;
269 while (tda827x_table
[i
].lomax
< N
* 62500) {
270 if (tda827x_table
[i
+ 1].lomax
== 0)
275 N
= N
<< tda827x_table
[i
].spd
;
278 tuner_reg
[1] = (unsigned char)(N
>>8);
279 tuner_reg
[2] = (unsigned char) N
;
281 tuner_reg
[4] = 0x52 + (priv
->lpsel
<< 5);
282 tuner_reg
[5] = (tda827x_table
[i
].spd
<< 6) +
283 (tda827x_table
[i
].div1p5
<< 5) +
284 (tda827x_table
[i
].bs
<< 3) + tda827x_table
[i
].bp
;
285 tuner_reg
[6] = 0x8f + (tda827x_table
[i
].gc3
<< 4);
290 tuner_transfer(fe
, &msg
, 1);
296 tuner_transfer(fe
, &msg
, 1);
300 tuner_transfer(fe
, &msg
, 1);
303 reg2
[1] = tuner_reg
[4] + 0x80;
304 tuner_transfer(fe
, &msg
, 1);
308 reg2
[1] = tuner_reg
[4] + 4;
309 tuner_transfer(fe
, &msg
, 1);
313 reg2
[1] = tuner_reg
[4];
314 tuner_transfer(fe
, &msg
, 1);
318 reg2
[1] = (tuner_reg
[4] & 0xfc) + tda827x_table
[i
].cp
;
319 tuner_transfer(fe
, &msg
, 1);
323 tuner_transfer(fe
, &msg
, 1);
326 reg2
[1] = 0x08; /* Vsync en */
327 tuner_transfer(fe
, &msg
, 1);
329 priv
->frequency
= params
->frequency
;
334 static void tda827xo_agcf(struct dvb_frontend
*fe
)
336 struct tda827x_priv
*priv
= fe
->tuner_priv
;
337 unsigned char data
[] = { 0x80, 0x0c };
338 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
339 .buf
= data
, .len
= 2};
341 tuner_transfer(fe
, &msg
, 1);
344 /* ------------------------------------------------------------------ */
346 struct tda827xa_data
{
355 static struct tda827xa_data tda827xa_dvbt
[] = {
356 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 1},
357 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
358 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
359 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
360 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
361 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
362 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
363 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
364 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
365 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
366 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
367 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
368 { .lomax
= 290000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
369 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
370 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
371 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
372 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
373 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
374 { .lomax
= 550000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
375 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
376 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
377 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
378 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
379 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
380 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
381 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
382 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
385 static struct tda827xa_data tda827xa_dvbc
[] = {
386 { .lomax
= 50125000, .svco
= 2, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
387 { .lomax
= 58500000, .svco
= 3, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
388 { .lomax
= 69250000, .svco
= 0, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
389 { .lomax
= 83625000, .svco
= 1, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
390 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
391 { .lomax
= 100250000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
392 { .lomax
= 117000000, .svco
= 3, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
393 { .lomax
= 138500000, .svco
= 0, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
394 { .lomax
= 167250000, .svco
= 1, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
395 { .lomax
= 187000000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
396 { .lomax
= 200500000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 1},
397 { .lomax
= 234000000, .svco
= 3, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 3},
398 { .lomax
= 277000000, .svco
= 0, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 3},
399 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 1},
400 { .lomax
= 334500000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
401 { .lomax
= 401000000, .svco
= 2, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
402 { .lomax
= 468000000, .svco
= 3, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 1},
403 { .lomax
= 535000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
404 { .lomax
= 554000000, .svco
= 0, .spd
= 0, .scr
= 2, .sbs
= 3, .gc3
= 1},
405 { .lomax
= 638000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
406 { .lomax
= 669000000, .svco
= 1, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
407 { .lomax
= 720000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
408 { .lomax
= 802000000, .svco
= 2, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
409 { .lomax
= 835000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
410 { .lomax
= 885000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
411 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
412 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
415 static struct tda827xa_data tda827xa_analog
[] = {
416 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 3},
417 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
418 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
419 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
420 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
421 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
422 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
423 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
424 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
425 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
426 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 3},
427 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 3},
428 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
429 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
430 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
431 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
432 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
433 { .lomax
= 554000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
434 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
435 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
436 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
437 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
438 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
439 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
440 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
441 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
444 static int tda827xa_sleep(struct dvb_frontend
*fe
)
446 struct tda827x_priv
*priv
= fe
->tuner_priv
;
447 static u8 buf
[] = { 0x30, 0x90 };
448 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
449 .buf
= buf
, .len
= sizeof(buf
) };
451 dprintk("%s:\n", __func__
);
453 tuner_transfer(fe
, &msg
, 1);
455 if (priv
->cfg
&& priv
->cfg
->sleep
)
456 priv
->cfg
->sleep(fe
);
461 static void tda827xa_lna_gain(struct dvb_frontend
*fe
, int high
,
462 struct analog_parameters
*params
)
464 struct tda827x_priv
*priv
= fe
->tuner_priv
;
465 unsigned char buf
[] = {0x22, 0x01};
468 struct i2c_msg msg
= { .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
470 if (NULL
== priv
->cfg
) {
471 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
474 msg
.addr
= priv
->cfg
->switch_addr
;
475 if (priv
->cfg
->config
) {
477 dprintk("setting LNA to high gain\n");
479 dprintk("setting LNA to low gain\n");
481 switch (priv
->cfg
->config
) {
484 case 1: /* switch is GPIO 0 of tda8290 */
486 if (params
== NULL
) {
492 if (params
->std
& V4L2_STD_MN
)
498 fe
->callback(priv
->i2c_adap
->algo_data
,
499 DVB_FRONTEND_COMPONENT_TUNER
,
501 buf
[1] = high
? 0 : 1;
502 if (priv
->cfg
->config
== 2)
503 buf
[1] = high
? 1 : 0;
504 tuner_transfer(fe
, &msg
, 1);
506 case 3: /* switch with GPIO of saa713x */
508 fe
->callback(priv
->i2c_adap
->algo_data
,
509 DVB_FRONTEND_COMPONENT_TUNER
, 0, high
);
514 static int tda827xa_set_params(struct dvb_frontend
*fe
,
515 struct dvb_frontend_parameters
*params
)
517 struct tda827x_priv
*priv
= fe
->tuner_priv
;
518 struct tda827xa_data
*frequency_map
= tda827xa_dvbt
;
521 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
522 .buf
= buf
, .len
= sizeof(buf
) };
524 int i
, tuner_freq
, if_freq
, rc
;
527 dprintk("%s:\n", __func__
);
529 tda827xa_lna_gain(fe
, 1, NULL
);
532 switch (params
->u
.ofdm
.bandwidth
) {
533 case BANDWIDTH_6_MHZ
:
536 case BANDWIDTH_7_MHZ
:
539 default: /* 8 MHz or Auto */
543 tuner_freq
= params
->frequency
+ if_freq
;
545 if (fe
->ops
.info
.type
== FE_QAM
) {
546 dprintk("%s select tda827xa_dvbc\n", __func__
);
547 frequency_map
= tda827xa_dvbc
;
551 while (frequency_map
[i
].lomax
< tuner_freq
) {
552 if (frequency_map
[i
+ 1].lomax
== 0)
557 N
= ((tuner_freq
+ 31250) / 62500) << frequency_map
[i
].spd
;
558 buf
[0] = 0; // subaddress
563 buf
[5] = (frequency_map
[i
].spd
<< 5) + (frequency_map
[i
].svco
<< 3) +
564 frequency_map
[i
].sbs
;
565 buf
[6] = 0x4b + (frequency_map
[i
].gc3
<< 4);
571 rc
= tuner_transfer(fe
, &msg
, 1);
579 buf
[4] = 0x59; // lpsel, for 6MHz + 2
581 rc
= tuner_transfer(fe
, &msg
, 1);
588 rc
= tuner_transfer(fe
, &msg
, 1);
593 msg
.flags
= I2C_M_RD
;
594 rc
= tuner_transfer(fe
, &msg
, 1);
600 dprintk("tda8275a AGC2 gain is: %d\n", buf
[1]);
602 tda827xa_lna_gain(fe
, 0, NULL
);
605 rc
= tuner_transfer(fe
, &msg
, 1);
611 buf
[1] = 0x99; // lpsel, for 6MHz + 2
612 rc
= tuner_transfer(fe
, &msg
, 1);
618 rc
= tuner_transfer(fe
, &msg
, 1);
622 /* correct CP value */
624 buf
[1] = 0x10 + frequency_map
[i
].scr
;
625 rc
= tuner_transfer(fe
, &msg
, 1);
631 buf
[1] = 0x39; // lpsel, for 6MHz + 2
632 rc
= tuner_transfer(fe
, &msg
, 1);
639 buf
[1] = 0x4f + (frequency_map
[i
].gc3
<< 4);
640 rc
= tuner_transfer(fe
, &msg
, 1);
644 priv
->frequency
= params
->frequency
;
645 priv
->bandwidth
= (fe
->ops
.info
.type
== FE_OFDM
) ? params
->u
.ofdm
.bandwidth
: 0;
651 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
652 __func__
, priv
->i2c_addr
<< 1);
657 static int tda827xa_set_analog_params(struct dvb_frontend
*fe
,
658 struct analog_parameters
*params
)
660 unsigned char tuner_reg
[11];
663 struct tda827x_priv
*priv
= fe
->tuner_priv
;
664 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
665 .buf
= tuner_reg
, .len
= sizeof(tuner_reg
) };
666 unsigned int freq
= params
->frequency
;
668 tda827x_set_std(fe
, params
);
670 tda827xa_lna_gain(fe
, 1, params
);
673 if (params
->mode
== V4L2_TUNER_RADIO
)
676 N
= freq
+ priv
->sgIF
;
679 while (tda827xa_analog
[i
].lomax
< N
* 62500) {
680 if (tda827xa_analog
[i
+ 1].lomax
== 0)
685 N
= N
<< tda827xa_analog
[i
].spd
;
688 tuner_reg
[1] = (unsigned char)(N
>>8);
689 tuner_reg
[2] = (unsigned char) N
;
692 tuner_reg
[5] = (tda827xa_analog
[i
].spd
<< 5) +
693 (tda827xa_analog
[i
].svco
<< 3) +
694 tda827xa_analog
[i
].sbs
;
695 tuner_reg
[6] = 0x8b + (tda827xa_analog
[i
].gc3
<< 4);
699 tuner_reg
[10] = 0x00;
701 tuner_transfer(fe
, &msg
, 1);
707 tuner_reg
[4] = 0x99 + (priv
->lpsel
<< 1);
709 tuner_transfer(fe
, &msg
, 1);
714 tuner_transfer(fe
, &msg
, 1);
717 tuner_reg
[1] = 0x10 + tda827xa_analog
[i
].scr
;
718 tuner_transfer(fe
, &msg
, 1);
720 msg
.flags
= I2C_M_RD
;
721 tuner_transfer(fe
, &msg
, 1);
724 dprintk("AGC2 gain is: %d\n", tuner_reg
[1]);
725 if (tuner_reg
[1] < 1)
726 tda827xa_lna_gain(fe
, 0, params
);
731 tuner_transfer(fe
, &msg
, 1);
735 tuner_reg
[1] = 0x8f + (tda827xa_analog
[i
].gc3
<< 4);
736 tuner_transfer(fe
, &msg
, 1);
740 tuner_transfer(fe
, &msg
, 1);
744 tuner_transfer(fe
, &msg
, 1);
747 tuner_reg
[1] = 0x19 + (priv
->lpsel
<< 1);
748 tuner_transfer(fe
, &msg
, 1);
750 priv
->frequency
= params
->frequency
;
755 static void tda827xa_agcf(struct dvb_frontend
*fe
)
757 struct tda827x_priv
*priv
= fe
->tuner_priv
;
758 unsigned char data
[] = {0x80, 0x2c};
759 struct i2c_msg msg
= {.addr
= priv
->i2c_addr
, .flags
= 0,
760 .buf
= data
, .len
= 2};
761 tuner_transfer(fe
, &msg
, 1);
764 /* ------------------------------------------------------------------ */
766 static int tda827x_release(struct dvb_frontend
*fe
)
768 kfree(fe
->tuner_priv
);
769 fe
->tuner_priv
= NULL
;
773 static int tda827x_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
775 struct tda827x_priv
*priv
= fe
->tuner_priv
;
776 *frequency
= priv
->frequency
;
780 static int tda827x_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
782 struct tda827x_priv
*priv
= fe
->tuner_priv
;
783 *bandwidth
= priv
->bandwidth
;
787 static int tda827x_init(struct dvb_frontend
*fe
)
789 struct tda827x_priv
*priv
= fe
->tuner_priv
;
790 dprintk("%s:\n", __func__
);
791 if (priv
->cfg
&& priv
->cfg
->init
)
797 static int tda827x_probe_version(struct dvb_frontend
*fe
);
799 static int tda827x_initial_init(struct dvb_frontend
*fe
)
802 ret
= tda827x_probe_version(fe
);
805 return fe
->ops
.tuner_ops
.init(fe
);
808 static int tda827x_initial_sleep(struct dvb_frontend
*fe
)
811 ret
= tda827x_probe_version(fe
);
814 return fe
->ops
.tuner_ops
.sleep(fe
);
817 static struct dvb_tuner_ops tda827xo_tuner_ops
= {
819 .name
= "Philips TDA827X",
820 .frequency_min
= 55000000,
821 .frequency_max
= 860000000,
822 .frequency_step
= 250000
824 .release
= tda827x_release
,
825 .init
= tda827x_initial_init
,
826 .sleep
= tda827x_initial_sleep
,
827 .set_params
= tda827xo_set_params
,
828 .set_analog_params
= tda827xo_set_analog_params
,
829 .get_frequency
= tda827x_get_frequency
,
830 .get_bandwidth
= tda827x_get_bandwidth
,
833 static struct dvb_tuner_ops tda827xa_tuner_ops
= {
835 .name
= "Philips TDA827XA",
836 .frequency_min
= 44000000,
837 .frequency_max
= 906000000,
838 .frequency_step
= 62500
840 .release
= tda827x_release
,
841 .init
= tda827x_init
,
842 .sleep
= tda827xa_sleep
,
843 .set_params
= tda827xa_set_params
,
844 .set_analog_params
= tda827xa_set_analog_params
,
845 .get_frequency
= tda827x_get_frequency
,
846 .get_bandwidth
= tda827x_get_bandwidth
,
849 static int tda827x_probe_version(struct dvb_frontend
*fe
)
853 struct tda827x_priv
*priv
= fe
->tuner_priv
;
854 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= I2C_M_RD
,
855 .buf
= &data
, .len
= 1 };
857 rc
= tuner_transfer(fe
, &msg
, 1);
860 printk("%s: could not read from tuner at addr: 0x%02x\n",
861 __func__
, msg
.addr
<< 1);
864 if ((data
& 0x3c) == 0) {
865 dprintk("tda827x tuner found\n");
866 fe
->ops
.tuner_ops
.init
= tda827x_init
;
867 fe
->ops
.tuner_ops
.sleep
= tda827xo_sleep
;
869 priv
->cfg
->agcf
= tda827xo_agcf
;
871 dprintk("tda827xa tuner found\n");
872 memcpy(&fe
->ops
.tuner_ops
, &tda827xa_tuner_ops
, sizeof(struct dvb_tuner_ops
));
874 priv
->cfg
->agcf
= tda827xa_agcf
;
879 struct dvb_frontend
*tda827x_attach(struct dvb_frontend
*fe
, int addr
,
880 struct i2c_adapter
*i2c
,
881 struct tda827x_config
*cfg
)
883 struct tda827x_priv
*priv
= NULL
;
885 dprintk("%s:\n", __func__
);
886 priv
= kzalloc(sizeof(struct tda827x_priv
), GFP_KERNEL
);
890 priv
->i2c_addr
= addr
;
891 priv
->i2c_adap
= i2c
;
893 memcpy(&fe
->ops
.tuner_ops
, &tda827xo_tuner_ops
, sizeof(struct dvb_tuner_ops
));
894 fe
->tuner_priv
= priv
;
896 dprintk("type set to %s\n", fe
->ops
.tuner_ops
.info
.name
);
900 EXPORT_SYMBOL_GPL(tda827x_attach
);
902 MODULE_DESCRIPTION("DVB TDA827x driver");
903 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
904 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
905 MODULE_LICENSE("GPL");
908 * Overrides for Emacs so that we follow Linus's tabbing style.
909 * ---------------------------------------------------------------------------