2 * descriptions + helper functions for simple dvb plls.
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
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/dvb/frontend.h>
23 #include <asm/types.h>
27 /* ----------------------------------------------------------- */
30 struct dvb_pll_desc dvb_pll_thomson_dtt7579
= {
31 .name
= "Thomson dtt7579",
36 { 0, 36166667, 166666, 0xb4, 0x03 }, /* go sleep */
37 { 443250000, 36166667, 166666, 0xb4, 0x02 },
38 { 542000000, 36166667, 166666, 0xb4, 0x08 },
39 { 771000000, 36166667, 166666, 0xbc, 0x08 },
40 { 999999999, 36166667, 166666, 0xf4, 0x08 },
43 EXPORT_SYMBOL(dvb_pll_thomson_dtt7579
);
45 struct dvb_pll_desc dvb_pll_thomson_dtt7610
= {
46 .name
= "Thomson dtt7610",
51 { 157250000, 44000000, 62500, 0x8e, 0x39 },
52 { 454000000, 44000000, 62500, 0x8e, 0x3a },
53 { 999999999, 44000000, 62500, 0x8e, 0x3c },
56 EXPORT_SYMBOL(dvb_pll_thomson_dtt7610
);
58 static void thomson_dtt759x_bw(u8
*buf
, u32 freq
, int bandwidth
)
60 if (BANDWIDTH_7_MHZ
== bandwidth
)
64 struct dvb_pll_desc dvb_pll_thomson_dtt759x
= {
65 .name
= "Thomson dtt759x",
68 .setbw
= thomson_dtt759x_bw
,
71 { 0, 36166667, 166666, 0x84, 0x03 },
72 { 264000000, 36166667, 166666, 0xb4, 0x02 },
73 { 470000000, 36166667, 166666, 0xbc, 0x02 },
74 { 735000000, 36166667, 166666, 0xbc, 0x08 },
75 { 835000000, 36166667, 166666, 0xf4, 0x08 },
76 { 999999999, 36166667, 166666, 0xfc, 0x08 },
79 EXPORT_SYMBOL(dvb_pll_thomson_dtt759x
);
81 struct dvb_pll_desc dvb_pll_lg_z201
= {
87 { 0, 36166667, 166666, 0xbc, 0x03 },
88 { 157500000, 36166667, 166666, 0xbc, 0x01 },
89 { 443250000, 36166667, 166666, 0xbc, 0x02 },
90 { 542000000, 36166667, 166666, 0xbc, 0x04 },
91 { 830000000, 36166667, 166666, 0xf4, 0x04 },
92 { 999999999, 36166667, 166666, 0xfc, 0x04 },
95 EXPORT_SYMBOL(dvb_pll_lg_z201
);
97 struct dvb_pll_desc dvb_pll_microtune_4042
= {
98 .name
= "Microtune 4042 FI5",
103 { 162000000, 44000000, 62500, 0x8e, 0xa1 },
104 { 457000000, 44000000, 62500, 0x8e, 0x91 },
105 { 999999999, 44000000, 62500, 0x8e, 0x31 },
108 EXPORT_SYMBOL(dvb_pll_microtune_4042
);
110 struct dvb_pll_desc dvb_pll_thomson_dtt761x
= {
111 /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
112 .name
= "Thomson dtt761x",
117 { 147000000, 44000000, 62500, 0x8e, 0x39 },
118 { 417000000, 44000000, 62500, 0x8e, 0x3a },
119 { 999999999, 44000000, 62500, 0x8e, 0x3c },
122 EXPORT_SYMBOL(dvb_pll_thomson_dtt761x
);
124 struct dvb_pll_desc dvb_pll_unknown_1
= {
125 .name
= "unknown 1", /* used by dntv live dvb-t */
130 { 150000000, 36166667, 166666, 0xb4, 0x01 },
131 { 173000000, 36166667, 166666, 0xbc, 0x01 },
132 { 250000000, 36166667, 166666, 0xb4, 0x02 },
133 { 400000000, 36166667, 166666, 0xbc, 0x02 },
134 { 420000000, 36166667, 166666, 0xf4, 0x02 },
135 { 470000000, 36166667, 166666, 0xfc, 0x02 },
136 { 600000000, 36166667, 166666, 0xbc, 0x08 },
137 { 730000000, 36166667, 166666, 0xf4, 0x08 },
138 { 999999999, 36166667, 166666, 0xfc, 0x08 },
141 EXPORT_SYMBOL(dvb_pll_unknown_1
);
143 /* Infineon TUA6010XS
144 * used in Thomson Cable Tuner
146 struct dvb_pll_desc dvb_pll_tua6010xs
= {
147 .name
= "Infineon TUA6010XS",
152 { 115750000, 36125000, 62500, 0x8e, 0x03 },
153 { 403250000, 36125000, 62500, 0x8e, 0x06 },
154 { 999999999, 36125000, 62500, 0x8e, 0x85 },
157 EXPORT_SYMBOL(dvb_pll_tua6010xs
);
159 /* Panasonic env57h1xd5 (some Philips PLL ?) */
160 struct dvb_pll_desc dvb_pll_env57h1xd5
= {
161 .name
= "Panasonic ENV57H1XD5",
166 { 153000000, 36291666, 166666, 0xc2, 0x41 },
167 { 470000000, 36291666, 166666, 0xc2, 0x42 },
168 { 526000000, 36291666, 166666, 0xc2, 0x84 },
169 { 999999999, 36291666, 166666, 0xc2, 0xa4 },
172 EXPORT_SYMBOL(dvb_pll_env57h1xd5
);
174 /* Philips TDA6650/TDA6651
175 * used in Panasonic ENV77H11D5
177 static void tda665x_bw(u8
*buf
, u32 freq
, int bandwidth
)
179 if (bandwidth
== BANDWIDTH_8_MHZ
)
183 struct dvb_pll_desc dvb_pll_tda665x
= {
184 .name
= "Philips TDA6650/TDA6651",
190 { 93834000, 36249333, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
191 { 123834000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
192 { 161000000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
193 { 163834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
194 { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
195 { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
196 { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
197 { 444000000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
198 { 583834000, 36249333, 166667, 0xca, 0x63 /* 011 0 0 0 11 */ },
199 { 793834000, 36249333, 166667, 0xca, 0xa3 /* 101 0 0 0 11 */ },
200 { 444834000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
201 { 861000000, 36249333, 166667, 0xca, 0xe3 /* 111 0 0 0 11 */ },
204 EXPORT_SYMBOL(dvb_pll_tda665x
);
207 * used in LG TDTP E102P
209 static void tua6034_bw(u8
*buf
, u32 freq
, int bandwidth
)
211 if (BANDWIDTH_7_MHZ
!= bandwidth
)
215 struct dvb_pll_desc dvb_pll_tua6034
= {
216 .name
= "Infineon TUA6034",
222 { 174500000, 36166667, 62500, 0xce, 0x01 },
223 { 230000000, 36166667, 62500, 0xce, 0x02 },
224 { 999999999, 36166667, 62500, 0xce, 0x04 },
227 EXPORT_SYMBOL(dvb_pll_tua6034
);
230 * used in LG TDVS-H061F, LG TDVS-H062F and LG TDVS-H064F
232 struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf
= {
233 .name
= "LG TDVS-H06xF",
238 { 165000000, 44000000, 62500, 0xce, 0x01 },
239 { 450000000, 44000000, 62500, 0xce, 0x02 },
240 { 999999999, 44000000, 62500, 0xce, 0x04 },
243 EXPORT_SYMBOL(dvb_pll_lg_tdvs_h06xf
);
246 * used in Medion Hybrid PCMCIA card and USB Box
248 static void fmd1216me_bw(u8
*buf
, u32 freq
, int bandwidth
)
250 if (bandwidth
== BANDWIDTH_8_MHZ
&& freq
>= 158870000)
254 struct dvb_pll_desc dvb_pll_fmd1216me
= {
255 .name
= "Philips FMD1216ME",
258 .setbw
= fmd1216me_bw
,
261 { 143870000, 36213333, 166667, 0xbc, 0x41 },
262 { 158870000, 36213333, 166667, 0xf4, 0x41 },
263 { 329870000, 36213333, 166667, 0xbc, 0x42 },
264 { 441870000, 36213333, 166667, 0xf4, 0x42 },
265 { 625870000, 36213333, 166667, 0xbc, 0x44 },
266 { 803870000, 36213333, 166667, 0xf4, 0x44 },
267 { 999999999, 36213333, 166667, 0xfc, 0x44 },
270 EXPORT_SYMBOL(dvb_pll_fmd1216me
);
273 * used in Nebula-Cards and USB boxes
275 static void tded4_bw(u8
*buf
, u32 freq
, int bandwidth
)
277 if (bandwidth
== BANDWIDTH_8_MHZ
)
281 struct dvb_pll_desc dvb_pll_tded4
= {
282 .name
= "ALPS TDED4",
288 { 153000000, 36166667, 166667, 0x85, 0x01 },
289 { 470000000, 36166667, 166667, 0x85, 0x02 },
290 { 823000000, 36166667, 166667, 0x85, 0x08 },
291 { 999999999, 36166667, 166667, 0x85, 0x88 },
294 EXPORT_SYMBOL(dvb_pll_tded4
);
297 * used in AverTVHD MCE A180
299 struct dvb_pll_desc dvb_pll_tdhu2
= {
300 .name
= "ALPS TDHU2",
305 { 162000000, 44000000, 62500, 0x85, 0x01 },
306 { 426000000, 44000000, 62500, 0x85, 0x02 },
307 { 782000000, 44000000, 62500, 0x85, 0x08 },
308 { 999999999, 44000000, 62500, 0x85, 0x88 },
311 EXPORT_SYMBOL(dvb_pll_tdhu2
);
314 * used in ATI HDTV Wonder
316 struct dvb_pll_desc dvb_pll_tuv1236d
= {
317 .name
= "Philips TUV1236D",
322 { 157250000, 44000000, 62500, 0xc6, 0x41 },
323 { 454000000, 44000000, 62500, 0xc6, 0x42 },
324 { 999999999, 44000000, 62500, 0xc6, 0x44 },
327 EXPORT_SYMBOL(dvb_pll_tuv1236d
);
329 /* Samsung TBMV30111IN / TBMV30712IN1
330 * used in Air2PC ATSC - 2nd generation (nxt2002)
332 struct dvb_pll_desc dvb_pll_samsung_tbmv
= {
333 .name
= "Samsung TBMV30111IN / TBMV30712IN1",
338 { 172000000, 44000000, 166666, 0xb4, 0x01 },
339 { 214000000, 44000000, 166666, 0xb4, 0x02 },
340 { 467000000, 44000000, 166666, 0xbc, 0x02 },
341 { 721000000, 44000000, 166666, 0xbc, 0x08 },
342 { 841000000, 44000000, 166666, 0xf4, 0x08 },
343 { 999999999, 44000000, 166666, 0xfc, 0x02 },
346 EXPORT_SYMBOL(dvb_pll_samsung_tbmv
);
349 * Philips SD1878 Tuner.
351 struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261
= {
352 .name
= "Philips SD1878",
357 { 1250000, 499, 500, 0xc4, 0x00},
358 { 1550000, 499, 500, 0xc4, 0x40},
359 { 2050000, 499, 500, 0xc4, 0x80},
360 { 2150000, 499, 500, 0xc4, 0xc0},
363 EXPORT_SYMBOL(dvb_pll_philips_sd1878_tda8261
);
366 * Philips TD1316 Tuner.
368 static void td1316_bw(u8
*buf
, u32 freq
, int bandwidth
)
373 if (freq
< 161000000)
375 else if (freq
< 444000000)
382 /* setup PLL filter */
383 if (bandwidth
== BANDWIDTH_8_MHZ
)
387 struct dvb_pll_desc dvb_pll_philips_td1316
= {
388 .name
= "Philips TD1316",
394 { 93834000, 36166000, 166666, 0xca, 0x60},
395 { 123834000, 36166000, 166666, 0xca, 0xa0},
396 { 163834000, 36166000, 166666, 0xca, 0xc0},
397 { 253834000, 36166000, 166666, 0xca, 0x60},
398 { 383834000, 36166000, 166666, 0xca, 0xa0},
399 { 443834000, 36166000, 166666, 0xca, 0xc0},
400 { 583834000, 36166000, 166666, 0xca, 0x60},
401 { 793834000, 36166000, 166666, 0xca, 0xa0},
402 { 858834000, 36166000, 166666, 0xca, 0xe0},
405 EXPORT_SYMBOL(dvb_pll_philips_td1316
);
407 /* FE6600 used on DViCO Hybrid */
408 struct dvb_pll_desc dvb_pll_thomson_fe6600
= {
409 .name
= "Thomson FE6600",
414 { 250000000, 36213333, 166667, 0xb4, 0x12 },
415 { 455000000, 36213333, 166667, 0xfe, 0x11 },
416 { 775500000, 36213333, 166667, 0xbc, 0x18 },
417 { 999999999, 36213333, 166667, 0xf4, 0x18 },
420 EXPORT_SYMBOL(dvb_pll_thomson_fe6600
);
422 struct dvb_pll_priv
{
425 struct i2c_adapter
*i2c
;
427 /* the PLL descriptor */
428 struct dvb_pll_desc
*pll_desc
;
430 /* cached frequency/bandwidth */
435 /* ----------------------------------------------------------- */
438 static int debug
= 0;
439 module_param(debug
, int, 0644);
440 MODULE_PARM_DESC(debug
, "enable verbose debug messages");
442 int dvb_pll_configure(struct dvb_pll_desc
*desc
, u8
*buf
,
443 u32 freq
, int bandwidth
)
448 if (freq
!= 0 && (freq
< desc
->min
|| freq
> desc
->max
))
451 for (i
= 0; i
< desc
->count
; i
++) {
452 if (freq
> desc
->entries
[i
].limit
)
457 printk("pll: %s: freq=%d bw=%d | i=%d/%d\n",
458 desc
->name
, freq
, bandwidth
, i
, desc
->count
);
459 if (i
== desc
->count
)
462 div
= (freq
+ desc
->entries
[i
].offset
) / desc
->entries
[i
].stepsize
;
465 buf
[2] = desc
->entries
[i
].config
;
466 buf
[3] = desc
->entries
[i
].cb
;
469 desc
->setbw(buf
, freq
, bandwidth
);
472 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
473 desc
->name
, div
, buf
[0], buf
[1], buf
[2], buf
[3]);
477 EXPORT_SYMBOL(dvb_pll_configure
);
479 static int dvb_pll_release(struct dvb_frontend
*fe
)
482 kfree(fe
->tuner_priv
);
483 fe
->tuner_priv
= NULL
;
487 static int dvb_pll_sleep(struct dvb_frontend
*fe
)
489 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
492 { .addr
= priv
->pll_i2c_address
, .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
496 for (i
= 0; i
< priv
->pll_desc
->count
; i
++) {
497 if (priv
->pll_desc
->entries
[i
].limit
== 0)
500 if (i
== priv
->pll_desc
->count
)
505 buf
[2] = priv
->pll_desc
->entries
[i
].config
;
506 buf
[3] = priv
->pll_desc
->entries
[i
].cb
;
508 if (fe
->ops
.i2c_gate_ctrl
)
509 fe
->ops
.i2c_gate_ctrl(fe
, 1);
510 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
517 static int dvb_pll_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
519 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
522 { .addr
= priv
->pll_i2c_address
, .flags
= 0, .buf
= buf
, .len
= sizeof(buf
) };
528 if (priv
->i2c
== NULL
)
531 // DVBT bandwidth only just now
532 if (fe
->ops
.info
.type
== FE_OFDM
) {
533 bandwidth
= params
->u
.ofdm
.bandwidth
;
536 if ((result
= dvb_pll_configure(priv
->pll_desc
, buf
, params
->frequency
, bandwidth
)) != 0)
539 if (fe
->ops
.i2c_gate_ctrl
)
540 fe
->ops
.i2c_gate_ctrl(fe
, 1);
541 if ((result
= i2c_transfer(priv
->i2c
, &msg
, 1)) != 1) {
545 // calculate the frequency we set it to
546 for (i
= 0; i
< priv
->pll_desc
->count
; i
++) {
547 if (params
->frequency
> priv
->pll_desc
->entries
[i
].limit
)
551 div
= (params
->frequency
+ priv
->pll_desc
->entries
[i
].offset
) / priv
->pll_desc
->entries
[i
].stepsize
;
552 priv
->frequency
= (div
* priv
->pll_desc
->entries
[i
].stepsize
) - priv
->pll_desc
->entries
[i
].offset
;
553 priv
->bandwidth
= bandwidth
;
558 static int dvb_pll_calc_regs(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
, u8
*buf
, int buf_len
)
560 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
569 // DVBT bandwidth only just now
570 if (fe
->ops
.info
.type
== FE_OFDM
) {
571 bandwidth
= params
->u
.ofdm
.bandwidth
;
574 if ((result
= dvb_pll_configure(priv
->pll_desc
, buf
+1, params
->frequency
, bandwidth
)) != 0)
576 buf
[0] = priv
->pll_i2c_address
;
578 // calculate the frequency we set it to
579 for (i
= 0; i
< priv
->pll_desc
->count
; i
++) {
580 if (params
->frequency
> priv
->pll_desc
->entries
[i
].limit
)
584 div
= (params
->frequency
+ priv
->pll_desc
->entries
[i
].offset
) / priv
->pll_desc
->entries
[i
].stepsize
;
585 priv
->frequency
= (div
* priv
->pll_desc
->entries
[i
].stepsize
) - priv
->pll_desc
->entries
[i
].offset
;
586 priv
->bandwidth
= bandwidth
;
591 static int dvb_pll_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
593 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
594 *frequency
= priv
->frequency
;
598 static int dvb_pll_get_bandwidth(struct dvb_frontend
*fe
, u32
*bandwidth
)
600 struct dvb_pll_priv
*priv
= fe
->tuner_priv
;
601 *bandwidth
= priv
->bandwidth
;
605 static struct dvb_tuner_ops dvb_pll_tuner_ops
= {
606 .release
= dvb_pll_release
,
607 .sleep
= dvb_pll_sleep
,
608 .set_params
= dvb_pll_set_params
,
609 .calc_regs
= dvb_pll_calc_regs
,
610 .get_frequency
= dvb_pll_get_frequency
,
611 .get_bandwidth
= dvb_pll_get_bandwidth
,
614 int dvb_pll_attach(struct dvb_frontend
*fe
, int pll_addr
, struct i2c_adapter
*i2c
, struct dvb_pll_desc
*desc
)
616 struct dvb_pll_priv
*priv
= NULL
;
618 priv
= kzalloc(sizeof(struct dvb_pll_priv
), GFP_KERNEL
);
622 priv
->pll_i2c_address
= pll_addr
;
624 priv
->pll_desc
= desc
;
626 memcpy(&fe
->ops
.tuner_ops
, &dvb_pll_tuner_ops
, sizeof(struct dvb_tuner_ops
));
627 strncpy(fe
->ops
.tuner_ops
.info
.name
, desc
->name
, 128);
628 fe
->ops
.tuner_ops
.info
.frequency_min
= desc
->min
;
629 fe
->ops
.tuner_ops
.info
.frequency_min
= desc
->max
;
631 fe
->tuner_priv
= priv
;
634 EXPORT_SYMBOL(dvb_pll_attach
);
636 MODULE_DESCRIPTION("dvb pll library");
637 MODULE_AUTHOR("Gerd Knorr");
638 MODULE_LICENSE("GPL");