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 */
85 dprintk("setting tda827x to radio FM\n");
87 dprintk("setting tda827x to system %s\n", mode
);
91 /* ------------------------------------------------------------------ */
103 static const struct tda827x_data tda827x_table
[] = {
104 { .lomax
= 62000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
105 { .lomax
= 66000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1},
106 { .lomax
= 76000000, .spd
= 3, .bs
= 1, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
107 { .lomax
= 84000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0},
108 { .lomax
= 93000000, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
109 { .lomax
= 98000000, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0},
110 { .lomax
= 109000000, .spd
= 3, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
111 { .lomax
= 123000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
112 { .lomax
= 133000000, .spd
= 2, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1},
113 { .lomax
= 151000000, .spd
= 2, .bs
= 1, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
114 { .lomax
= 154000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0},
115 { .lomax
= 181000000, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 0, .div1p5
= 0},
116 { .lomax
= 185000000, .spd
= 2, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
117 { .lomax
= 217000000, .spd
= 2, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
118 { .lomax
= 244000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
119 { .lomax
= 265000000, .spd
= 1, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1},
120 { .lomax
= 302000000, .spd
= 1, .bs
= 1, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
121 { .lomax
= 324000000, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0},
122 { .lomax
= 370000000, .spd
= 1, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
123 { .lomax
= 454000000, .spd
= 1, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
124 { .lomax
= 493000000, .spd
= 0, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
125 { .lomax
= 530000000, .spd
= 0, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1},
126 { .lomax
= 554000000, .spd
= 0, .bs
= 1, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0},
127 { .lomax
= 604000000, .spd
= 0, .bs
= 1, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
128 { .lomax
= 696000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
129 { .lomax
= 740000000, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
130 { .lomax
= 820000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0},
131 { .lomax
= 865000000, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0},
132 { .lomax
= 0, .spd
= 0, .bs
= 0, .bp
= 0, .cp
= 0, .gc3
= 0, .div1p5
= 0}
135 static int tuner_transfer(struct dvb_frontend
*fe
,
140 struct tda827x_priv
*priv
= fe
->tuner_priv
;
142 if (fe
->ops
.i2c_gate_ctrl
)
143 fe
->ops
.i2c_gate_ctrl(fe
, 1);
144 rc
= i2c_transfer(priv
->i2c_adap
, msg
, size
);
145 if (fe
->ops
.i2c_gate_ctrl
)
146 fe
->ops
.i2c_gate_ctrl(fe
, 0);
148 if (rc
>= 0 && rc
!= size
)
154 static int tda827xo_set_params(struct dvb_frontend
*fe
,
155 struct dvb_frontend_parameters
*params
)
157 struct tda827x_priv
*priv
= fe
->tuner_priv
;
161 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
162 .buf
= buf
, .len
= sizeof(buf
) };
163 int i
, tuner_freq
, if_freq
;
166 dprintk("%s:\n", __func__
);
167 switch (params
->u
.ofdm
.bandwidth
) {
168 case BANDWIDTH_6_MHZ
:
171 case BANDWIDTH_7_MHZ
:
174 default: /* 8 MHz or Auto */
178 tuner_freq
= params
->frequency
+ if_freq
;
181 while (tda827x_table
[i
].lomax
< tuner_freq
) {
182 if (tda827x_table
[i
+ 1].lomax
== 0)
187 N
= ((tuner_freq
+ 125000) / 250000) << (tda827x_table
[i
].spd
+ 2);
189 buf
[1] = (N
>>8) | 0x40;
193 buf
[5] = (tda827x_table
[i
].spd
<< 6) + (tda827x_table
[i
].div1p5
<< 5) +
194 (tda827x_table
[i
].bs
<< 3) +
196 buf
[6] = (tda827x_table
[i
].gc3
<< 4) + 0x8f;
206 rc
= tuner_transfer(fe
, &msg
, 1);
211 /* correct CP value */
213 buf
[1] = 0x50 + tda827x_table
[i
].cp
;
216 rc
= tuner_transfer(fe
, &msg
, 1);
220 priv
->frequency
= params
->frequency
;
221 priv
->bandwidth
= (fe
->ops
.info
.type
== FE_OFDM
) ? params
->u
.ofdm
.bandwidth
: 0;
226 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
227 __func__
, priv
->i2c_addr
<< 1);
231 static int tda827xo_sleep(struct dvb_frontend
*fe
)
233 struct tda827x_priv
*priv
= fe
->tuner_priv
;
234 static u8 buf
[] = { 0x30, 0xd0 };
235 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
236 .buf
= buf
, .len
= sizeof(buf
) };
238 dprintk("%s:\n", __func__
);
239 tuner_transfer(fe
, &msg
, 1);
241 if (priv
->cfg
&& priv
->cfg
->sleep
)
242 priv
->cfg
->sleep(fe
);
247 /* ------------------------------------------------------------------ */
249 static int tda827xo_set_analog_params(struct dvb_frontend
*fe
,
250 struct analog_parameters
*params
)
252 unsigned char tuner_reg
[8];
253 unsigned char reg2
[2];
256 struct tda827x_priv
*priv
= fe
->tuner_priv
;
257 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0 };
258 unsigned int freq
= params
->frequency
;
260 tda827x_set_std(fe
, params
);
262 if (params
->mode
== V4L2_TUNER_RADIO
)
265 N
= freq
+ priv
->sgIF
;
268 while (tda827x_table
[i
].lomax
< N
* 62500) {
269 if (tda827x_table
[i
+ 1].lomax
== 0)
274 N
= N
<< tda827x_table
[i
].spd
;
277 tuner_reg
[1] = (unsigned char)(N
>>8);
278 tuner_reg
[2] = (unsigned char) N
;
280 tuner_reg
[4] = 0x52 + (priv
->lpsel
<< 5);
281 tuner_reg
[5] = (tda827x_table
[i
].spd
<< 6) +
282 (tda827x_table
[i
].div1p5
<< 5) +
283 (tda827x_table
[i
].bs
<< 3) + tda827x_table
[i
].bp
;
284 tuner_reg
[6] = 0x8f + (tda827x_table
[i
].gc3
<< 4);
289 tuner_transfer(fe
, &msg
, 1);
295 tuner_transfer(fe
, &msg
, 1);
299 tuner_transfer(fe
, &msg
, 1);
302 reg2
[1] = tuner_reg
[4] + 0x80;
303 tuner_transfer(fe
, &msg
, 1);
307 reg2
[1] = tuner_reg
[4] + 4;
308 tuner_transfer(fe
, &msg
, 1);
312 reg2
[1] = tuner_reg
[4];
313 tuner_transfer(fe
, &msg
, 1);
317 reg2
[1] = (tuner_reg
[4] & 0xfc) + tda827x_table
[i
].cp
;
318 tuner_transfer(fe
, &msg
, 1);
322 tuner_transfer(fe
, &msg
, 1);
325 reg2
[1] = 0x08; /* Vsync en */
326 tuner_transfer(fe
, &msg
, 1);
328 priv
->frequency
= params
->frequency
;
333 static void tda827xo_agcf(struct dvb_frontend
*fe
)
335 struct tda827x_priv
*priv
= fe
->tuner_priv
;
336 unsigned char data
[] = { 0x80, 0x0c };
337 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
338 .buf
= data
, .len
= 2};
340 tuner_transfer(fe
, &msg
, 1);
343 /* ------------------------------------------------------------------ */
345 struct tda827xa_data
{
354 static struct tda827xa_data tda827xa_dvbt
[] = {
355 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 1},
356 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
357 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
358 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 1},
359 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
360 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
361 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
362 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
363 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
364 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
365 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
366 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
367 { .lomax
= 290000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
368 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
369 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
370 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 1},
371 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
372 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
373 { .lomax
= 550000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
374 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
375 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
376 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
377 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
378 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
379 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
380 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
381 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
384 static struct tda827xa_data tda827xa_dvbc
[] = {
385 { .lomax
= 50125000, .svco
= 2, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
386 { .lomax
= 58500000, .svco
= 3, .spd
= 4, .scr
= 2, .sbs
= 0, .gc3
= 3},
387 { .lomax
= 69250000, .svco
= 0, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
388 { .lomax
= 83625000, .svco
= 1, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
389 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 0, .gc3
= 3},
390 { .lomax
= 100250000, .svco
= 2, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
391 { .lomax
= 117000000, .svco
= 3, .spd
= 3, .scr
= 2, .sbs
= 1, .gc3
= 1},
392 { .lomax
= 138500000, .svco
= 0, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
393 { .lomax
= 167250000, .svco
= 1, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
394 { .lomax
= 187000000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 1, .gc3
= 1},
395 { .lomax
= 200500000, .svco
= 2, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 1},
396 { .lomax
= 234000000, .svco
= 3, .spd
= 2, .scr
= 2, .sbs
= 2, .gc3
= 3},
397 { .lomax
= 277000000, .svco
= 0, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 3},
398 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 2, .gc3
= 1},
399 { .lomax
= 334500000, .svco
= 1, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
400 { .lomax
= 401000000, .svco
= 2, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 3},
401 { .lomax
= 468000000, .svco
= 3, .spd
= 1, .scr
= 2, .sbs
= 3, .gc3
= 1},
402 { .lomax
= 535000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
403 { .lomax
= 554000000, .svco
= 0, .spd
= 0, .scr
= 2, .sbs
= 3, .gc3
= 1},
404 { .lomax
= 638000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
405 { .lomax
= 669000000, .svco
= 1, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
406 { .lomax
= 720000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
407 { .lomax
= 802000000, .svco
= 2, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
408 { .lomax
= 835000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
409 { .lomax
= 885000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 1},
410 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 1},
411 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
414 static struct tda827xa_data tda827xa_analog
[] = {
415 { .lomax
= 56875000, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 3},
416 { .lomax
= 67250000, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
417 { .lomax
= 81250000, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
418 { .lomax
= 97500000, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3},
419 { .lomax
= 113750000, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1},
420 { .lomax
= 134500000, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
421 { .lomax
= 154000000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
422 { .lomax
= 162500000, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
423 { .lomax
= 183000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1},
424 { .lomax
= 195000000, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1},
425 { .lomax
= 227500000, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 3},
426 { .lomax
= 269000000, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 3},
427 { .lomax
= 325000000, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1},
428 { .lomax
= 390000000, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
429 { .lomax
= 455000000, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3},
430 { .lomax
= 520000000, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
431 { .lomax
= 538000000, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1},
432 { .lomax
= 554000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1},
433 { .lomax
= 620000000, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
434 { .lomax
= 650000000, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
435 { .lomax
= 700000000, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
436 { .lomax
= 780000000, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
437 { .lomax
= 820000000, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0},
438 { .lomax
= 870000000, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0},
439 { .lomax
= 911000000, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0},
440 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0}
443 static int tda827xa_sleep(struct dvb_frontend
*fe
)
445 struct tda827x_priv
*priv
= fe
->tuner_priv
;
446 static u8 buf
[] = { 0x30, 0x90 };
447 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
448 .buf
= buf
, .len
= sizeof(buf
) };
450 dprintk("%s:\n", __func__
);
452 tuner_transfer(fe
, &msg
, 1);
454 if (priv
->cfg
&& priv
->cfg
->sleep
)
455 priv
->cfg
->sleep(fe
);
460 static void tda827xa_lna_gain(struct dvb_frontend
*fe
, int high
,
461 struct analog_parameters
*params
)
463 struct tda827x_priv
*priv
= fe
->tuner_priv
;
464 unsigned char buf
[] = {0x22, 0x01};
467 struct i2c_msg msg
= { .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
469 if (NULL
== priv
->cfg
) {
470 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
473 msg
.addr
= priv
->cfg
->switch_addr
;
474 if (priv
->cfg
->config
) {
476 dprintk("setting LNA to high gain\n");
478 dprintk("setting LNA to low gain\n");
480 switch (priv
->cfg
->config
) {
483 case 1: /* switch is GPIO 0 of tda8290 */
485 if (params
== NULL
) {
491 if (params
->std
& V4L2_STD_MN
)
497 fe
->callback(priv
->i2c_adap
->algo_data
,
498 DVB_FRONTEND_COMPONENT_TUNER
,
500 buf
[1] = high
? 0 : 1;
501 if (priv
->cfg
->config
== 2)
502 buf
[1] = high
? 1 : 0;
503 tuner_transfer(fe
, &msg
, 1);
505 case 3: /* switch with GPIO of saa713x */
507 fe
->callback(priv
->i2c_adap
->algo_data
,
508 DVB_FRONTEND_COMPONENT_TUNER
, 0, high
);
513 static int tda827xa_set_params(struct dvb_frontend
*fe
,
514 struct dvb_frontend_parameters
*params
)
516 struct tda827x_priv
*priv
= fe
->tuner_priv
;
517 struct tda827xa_data
*frequency_map
= tda827xa_dvbt
;
520 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
521 .buf
= buf
, .len
= sizeof(buf
) };
523 int i
, tuner_freq
, if_freq
, rc
;
526 dprintk("%s:\n", __func__
);
528 tda827xa_lna_gain(fe
, 1, NULL
);
531 switch (params
->u
.ofdm
.bandwidth
) {
532 case BANDWIDTH_6_MHZ
:
535 case BANDWIDTH_7_MHZ
:
538 default: /* 8 MHz or Auto */
542 tuner_freq
= params
->frequency
+ if_freq
;
544 if (fe
->ops
.info
.type
== FE_QAM
) {
545 dprintk("%s select tda827xa_dvbc\n", __func__
);
546 frequency_map
= tda827xa_dvbc
;
550 while (frequency_map
[i
].lomax
< tuner_freq
) {
551 if (frequency_map
[i
+ 1].lomax
== 0)
556 N
= ((tuner_freq
+ 31250) / 62500) << frequency_map
[i
].spd
;
557 buf
[0] = 0; // subaddress
562 buf
[5] = (frequency_map
[i
].spd
<< 5) + (frequency_map
[i
].svco
<< 3) +
563 frequency_map
[i
].sbs
;
564 buf
[6] = 0x4b + (frequency_map
[i
].gc3
<< 4);
570 rc
= tuner_transfer(fe
, &msg
, 1);
578 buf
[4] = 0x59; // lpsel, for 6MHz + 2
580 rc
= tuner_transfer(fe
, &msg
, 1);
587 rc
= tuner_transfer(fe
, &msg
, 1);
592 msg
.flags
= I2C_M_RD
;
593 rc
= tuner_transfer(fe
, &msg
, 1);
599 dprintk("tda8275a AGC2 gain is: %d\n", buf
[1]);
601 tda827xa_lna_gain(fe
, 0, NULL
);
604 rc
= tuner_transfer(fe
, &msg
, 1);
610 buf
[1] = 0x99; // lpsel, for 6MHz + 2
611 rc
= tuner_transfer(fe
, &msg
, 1);
617 rc
= tuner_transfer(fe
, &msg
, 1);
621 /* correct CP value */
623 buf
[1] = 0x10 + frequency_map
[i
].scr
;
624 rc
= tuner_transfer(fe
, &msg
, 1);
630 buf
[1] = 0x39; // lpsel, for 6MHz + 2
631 rc
= tuner_transfer(fe
, &msg
, 1);
638 buf
[1] = 0x4f + (frequency_map
[i
].gc3
<< 4);
639 rc
= tuner_transfer(fe
, &msg
, 1);
643 priv
->frequency
= params
->frequency
;
644 priv
->bandwidth
= (fe
->ops
.info
.type
== FE_OFDM
) ? params
->u
.ofdm
.bandwidth
: 0;
650 printk(KERN_ERR
"%s: could not write to tuner at addr: 0x%02x\n",
651 __func__
, priv
->i2c_addr
<< 1);
656 static int tda827xa_set_analog_params(struct dvb_frontend
*fe
,
657 struct analog_parameters
*params
)
659 unsigned char tuner_reg
[11];
662 struct tda827x_priv
*priv
= fe
->tuner_priv
;
663 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= 0,
664 .buf
= tuner_reg
, .len
= sizeof(tuner_reg
) };
665 unsigned int freq
= params
->frequency
;
667 tda827x_set_std(fe
, params
);
669 tda827xa_lna_gain(fe
, 1, params
);
672 if (params
->mode
== V4L2_TUNER_RADIO
)
675 N
= freq
+ priv
->sgIF
;
678 while (tda827xa_analog
[i
].lomax
< N
* 62500) {
679 if (tda827xa_analog
[i
+ 1].lomax
== 0)
684 N
= N
<< tda827xa_analog
[i
].spd
;
687 tuner_reg
[1] = (unsigned char)(N
>>8);
688 tuner_reg
[2] = (unsigned char) N
;
691 tuner_reg
[5] = (tda827xa_analog
[i
].spd
<< 5) +
692 (tda827xa_analog
[i
].svco
<< 3) +
693 tda827xa_analog
[i
].sbs
;
694 tuner_reg
[6] = 0x8b + (tda827xa_analog
[i
].gc3
<< 4);
698 tuner_reg
[10] = 0x00;
700 tuner_transfer(fe
, &msg
, 1);
706 tuner_reg
[4] = 0x99 + (priv
->lpsel
<< 1);
708 tuner_transfer(fe
, &msg
, 1);
713 tuner_transfer(fe
, &msg
, 1);
716 tuner_reg
[1] = 0x10 + tda827xa_analog
[i
].scr
;
717 tuner_transfer(fe
, &msg
, 1);
719 msg
.flags
= I2C_M_RD
;
720 tuner_transfer(fe
, &msg
, 1);
723 dprintk("AGC2 gain is: %d\n", tuner_reg
[1]);
724 if (tuner_reg
[1] < 1)
725 tda827xa_lna_gain(fe
, 0, params
);
730 tuner_transfer(fe
, &msg
, 1);
734 tuner_reg
[1] = 0x8f + (tda827xa_analog
[i
].gc3
<< 4);
735 tuner_transfer(fe
, &msg
, 1);
739 tuner_transfer(fe
, &msg
, 1);
743 tuner_transfer(fe
, &msg
, 1);
746 tuner_reg
[1] = 0x19 + (priv
->lpsel
<< 1);
747 tuner_transfer(fe
, &msg
, 1);
749 priv
->frequency
= params
->frequency
;
754 static void tda827xa_agcf(struct dvb_frontend
*fe
)
756 struct tda827x_priv
*priv
= fe
->tuner_priv
;
757 unsigned char data
[] = {0x80, 0x2c};
758 struct i2c_msg msg
= {.addr
= priv
->i2c_addr
, .flags
= 0,
759 .buf
= data
, .len
= 2};
760 tuner_transfer(fe
, &msg
, 1);
763 /* ------------------------------------------------------------------ */
765 static int tda827x_release(struct dvb_frontend
*fe
)
767 kfree(fe
->tuner_priv
);
768 fe
->tuner_priv
= NULL
;
772 static int tda827x_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
774 struct tda827x_priv
*priv
= fe
->tuner_priv
;
775 *frequency
= priv
->frequency
;
779 static int tda827x_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
781 struct tda827x_priv
*priv
= fe
->tuner_priv
;
782 *bandwidth
= priv
->bandwidth
;
786 static int tda827x_init(struct dvb_frontend
*fe
)
788 struct tda827x_priv
*priv
= fe
->tuner_priv
;
789 dprintk("%s:\n", __func__
);
790 if (priv
->cfg
&& priv
->cfg
->init
)
796 static int tda827x_probe_version(struct dvb_frontend
*fe
);
798 static int tda827x_initial_init(struct dvb_frontend
*fe
)
801 ret
= tda827x_probe_version(fe
);
804 return fe
->ops
.tuner_ops
.init(fe
);
807 static int tda827x_initial_sleep(struct dvb_frontend
*fe
)
810 ret
= tda827x_probe_version(fe
);
813 return fe
->ops
.tuner_ops
.sleep(fe
);
816 static struct dvb_tuner_ops tda827xo_tuner_ops
= {
818 .name
= "Philips TDA827X",
819 .frequency_min
= 55000000,
820 .frequency_max
= 860000000,
821 .frequency_step
= 250000
823 .release
= tda827x_release
,
824 .init
= tda827x_initial_init
,
825 .sleep
= tda827x_initial_sleep
,
826 .set_params
= tda827xo_set_params
,
827 .set_analog_params
= tda827xo_set_analog_params
,
828 .get_frequency
= tda827x_get_frequency
,
829 .get_bandwidth
= tda827x_get_bandwidth
,
832 static struct dvb_tuner_ops tda827xa_tuner_ops
= {
834 .name
= "Philips TDA827XA",
835 .frequency_min
= 44000000,
836 .frequency_max
= 906000000,
837 .frequency_step
= 62500
839 .release
= tda827x_release
,
840 .init
= tda827x_init
,
841 .sleep
= tda827xa_sleep
,
842 .set_params
= tda827xa_set_params
,
843 .set_analog_params
= tda827xa_set_analog_params
,
844 .get_frequency
= tda827x_get_frequency
,
845 .get_bandwidth
= tda827x_get_bandwidth
,
848 static int tda827x_probe_version(struct dvb_frontend
*fe
)
852 struct tda827x_priv
*priv
= fe
->tuner_priv
;
853 struct i2c_msg msg
= { .addr
= priv
->i2c_addr
, .flags
= I2C_M_RD
,
854 .buf
= &data
, .len
= 1 };
856 rc
= tuner_transfer(fe
, &msg
, 1);
859 printk("%s: could not read from tuner at addr: 0x%02x\n",
860 __func__
, msg
.addr
<< 1);
863 if ((data
& 0x3c) == 0) {
864 dprintk("tda827x tuner found\n");
865 fe
->ops
.tuner_ops
.init
= tda827x_init
;
866 fe
->ops
.tuner_ops
.sleep
= tda827xo_sleep
;
868 priv
->cfg
->agcf
= tda827xo_agcf
;
870 dprintk("tda827xa tuner found\n");
871 memcpy(&fe
->ops
.tuner_ops
, &tda827xa_tuner_ops
, sizeof(struct dvb_tuner_ops
));
873 priv
->cfg
->agcf
= tda827xa_agcf
;
878 struct dvb_frontend
*tda827x_attach(struct dvb_frontend
*fe
, int addr
,
879 struct i2c_adapter
*i2c
,
880 struct tda827x_config
*cfg
)
882 struct tda827x_priv
*priv
= NULL
;
884 dprintk("%s:\n", __func__
);
885 priv
= kzalloc(sizeof(struct tda827x_priv
), GFP_KERNEL
);
889 priv
->i2c_addr
= addr
;
890 priv
->i2c_adap
= i2c
;
892 memcpy(&fe
->ops
.tuner_ops
, &tda827xo_tuner_ops
, sizeof(struct dvb_tuner_ops
));
893 fe
->tuner_priv
= priv
;
895 dprintk("type set to %s\n", fe
->ops
.tuner_ops
.info
.name
);
899 EXPORT_SYMBOL_GPL(tda827x_attach
);
901 MODULE_DESCRIPTION("DVB TDA827x driver");
902 MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
903 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
904 MODULE_LICENSE("GPL");
907 * Overrides for Emacs so that we follow Linus's tabbing style.
908 * ---------------------------------------------------------------------------