[PATCH] v4l: add DVB support for DViCO FusionHDTV3 Gold-T
[safe/jmp/linux-2.6] / drivers / media / dvb / frontends / dvb-pll.c
1 /*
2  * descriptions + helper functions for simple dvb plls.
3  *
4  * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include <linux/module.h>
22 #include <linux/dvb/frontend.h>
23 #include <asm/types.h>
24
25 #include "dvb-pll.h"
26
27 /* ----------------------------------------------------------- */
28 /* descriptions                                                */
29
30 struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
31         .name  = "Thomson dtt7579",
32         .min   = 177000000,
33         .max   = 858000000,
34         .count = 5,
35         .entries = {
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 },
41         },
42 };
43 EXPORT_SYMBOL(dvb_pll_thomson_dtt7579);
44
45 struct dvb_pll_desc dvb_pll_thomson_dtt7610 = {
46         .name  = "Thomson dtt7610",
47         .min   =  44000000,
48         .max   = 958000000,
49         .count = 3,
50         .entries = {
51                 { 157250000, 44000000, 62500, 0x8e, 0x39 },
52                 { 454000000, 44000000, 62500, 0x8e, 0x3a },
53                 { 999999999, 44000000, 62500, 0x8e, 0x3c },
54         },
55 };
56 EXPORT_SYMBOL(dvb_pll_thomson_dtt7610);
57
58 static void thomson_dtt759x_bw(u8 *buf, u32 freq, int bandwidth)
59 {
60         if (BANDWIDTH_7_MHZ == bandwidth)
61                 buf[3] |= 0x10;
62 }
63
64 struct dvb_pll_desc dvb_pll_thomson_dtt759x = {
65         .name  = "Thomson dtt759x",
66         .min   = 177000000,
67         .max   = 896000000,
68         .setbw = thomson_dtt759x_bw,
69         .count = 6,
70         .entries = {
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 },
77         },
78 };
79 EXPORT_SYMBOL(dvb_pll_thomson_dtt759x);
80
81 struct dvb_pll_desc dvb_pll_lg_z201 = {
82         .name  = "LG z201",
83         .min   = 174000000,
84         .max   = 862000000,
85         .count = 5,
86         .entries = {
87                 {          0, 36166667, 166666, 0xbc, 0x03 },
88                 {  443250000, 36166667, 166666, 0xbc, 0x01 },
89                 {  542000000, 36166667, 166666, 0xbc, 0x02 },
90                 {  830000000, 36166667, 166666, 0xf4, 0x02 },
91                 {  999999999, 36166667, 166666, 0xfc, 0x02 },
92         },
93 };
94 EXPORT_SYMBOL(dvb_pll_lg_z201);
95
96 struct dvb_pll_desc dvb_pll_microtune_4042 = {
97         .name  = "Microtune 4042 FI5",
98         .min   =  57000000,
99         .max   = 858000000,
100         .count = 3,
101         .entries = {
102                 { 162000000, 44000000, 62500, 0x8e, 0xa1 },
103                 { 457000000, 44000000, 62500, 0x8e, 0x91 },
104                 { 999999999, 44000000, 62500, 0x8e, 0x31 },
105         },
106 };
107 EXPORT_SYMBOL(dvb_pll_microtune_4042);
108
109 struct dvb_pll_desc dvb_pll_thomson_dtt7611 = {
110         .name  = "Thomson dtt7611",
111         .min   =  44000000,
112         .max   = 958000000,
113         .count = 3,
114         .entries = {
115                 { 157250000, 44000000, 62500, 0x8e, 0x39 },
116                 { 454000000, 44000000, 62500, 0x8e, 0x3a },
117                 { 999999999, 44000000, 62500, 0x8e, 0x3c },
118         },
119 };
120 EXPORT_SYMBOL(dvb_pll_thomson_dtt7611);
121
122 struct dvb_pll_desc dvb_pll_unknown_1 = {
123         .name  = "unknown 1", /* used by dntv live dvb-t */
124         .min   = 174000000,
125         .max   = 862000000,
126         .count = 9,
127         .entries = {
128                 {  150000000, 36166667, 166666, 0xb4, 0x01 },
129                 {  173000000, 36166667, 166666, 0xbc, 0x01 },
130                 {  250000000, 36166667, 166666, 0xb4, 0x02 },
131                 {  400000000, 36166667, 166666, 0xbc, 0x02 },
132                 {  420000000, 36166667, 166666, 0xf4, 0x02 },
133                 {  470000000, 36166667, 166666, 0xfc, 0x02 },
134                 {  600000000, 36166667, 166666, 0xbc, 0x08 },
135                 {  730000000, 36166667, 166666, 0xf4, 0x08 },
136                 {  999999999, 36166667, 166666, 0xfc, 0x08 },
137         },
138 };
139 EXPORT_SYMBOL(dvb_pll_unknown_1);
140
141 /* Infineon TUA6010XS
142  * used in Thomson Cable Tuner
143  */
144 struct dvb_pll_desc dvb_pll_tua6010xs = {
145         .name  = "Infineon TUA6010XS",
146         .min   =  44250000,
147         .max   = 858000000,
148         .count = 3,
149         .entries = {
150                 {  115750000, 36125000, 62500, 0x8e, 0x03 },
151                 {  403250000, 36125000, 62500, 0x8e, 0x06 },
152                 {  999999999, 36125000, 62500, 0x8e, 0x85 },
153         },
154 };
155 EXPORT_SYMBOL(dvb_pll_tua6010xs);
156
157 /* Panasonic env57h1xd5 (some Philips PLL ?) */
158 struct dvb_pll_desc dvb_pll_env57h1xd5 = {
159         .name  = "Panasonic ENV57H1XD5",
160         .min   =  44250000,
161         .max   = 858000000,
162         .count = 4,
163         .entries = {
164                 {  153000000, 36291666, 166666, 0xc2, 0x41 },
165                 {  470000000, 36291666, 166666, 0xc2, 0x42 },
166                 {  526000000, 36291666, 166666, 0xc2, 0x84 },
167                 {  999999999, 36291666, 166666, 0xc2, 0xa4 },
168         },
169 };
170 EXPORT_SYMBOL(dvb_pll_env57h1xd5);
171
172 /* Philips TDA6650/TDA6651
173  * used in Panasonic ENV77H11D5
174  */
175 static void tda665x_bw(u8 *buf, u32 freq, int bandwidth)
176 {
177         if (bandwidth == BANDWIDTH_8_MHZ)
178                 buf[3] |= 0x08;
179 }
180
181 struct dvb_pll_desc dvb_pll_tda665x = {
182         .name  = "Philips TDA6650/TDA6651",
183         .min   =  44250000,
184         .max   = 858000000,
185         .setbw = tda665x_bw,
186         .count = 12,
187         .entries = {
188                 {   93834000, 36249333, 166667, 0xca, 0x61 /* 011 0 0 0  01 */ },
189                 {  123834000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0  01 */ },
190                 {  161000000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0  01 */ },
191                 {  163834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0  10 */ },
192                 {  253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0  10 */ },
193                 {  383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0  10 */ },
194                 {  443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0  10 */ },
195                 {  444000000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0  11 */ },
196                 {  583834000, 36249333, 166667, 0xca, 0x63 /* 011 0 0 0  11 */ },
197                 {  793834000, 36249333, 166667, 0xca, 0xa3 /* 101 0 0 0  11 */ },
198                 {  444834000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0  11 */ },
199                 {  861000000, 36249333, 166667, 0xca, 0xe3 /* 111 0 0 0  11 */ },
200         }
201 };
202 EXPORT_SYMBOL(dvb_pll_tda665x);
203
204 /* Infineon TUA6034
205  * used in LG TDTP E102P
206  */
207 static void tua6034_bw(u8 *buf, u32 freq, int bandwidth)
208 {
209         if (BANDWIDTH_7_MHZ != bandwidth)
210                 buf[3] |= 0x08;
211 }
212
213 struct dvb_pll_desc dvb_pll_tua6034 = {
214         .name  = "Infineon TUA6034",
215         .min   =  44250000,
216         .max   = 858000000,
217         .count = 3,
218         .setbw = tua6034_bw,
219         .entries = {
220                 {  174500000, 36166667, 62500, 0xce, 0x01 },
221                 {  230000000, 36166667, 62500, 0xce, 0x02 },
222                 {  999999999, 36166667, 62500, 0xce, 0x04 },
223         },
224 };
225 EXPORT_SYMBOL(dvb_pll_tua6034);
226
227 /* Philips FMD1216ME
228  * used in Medion Hybrid PCMCIA card and USB Box
229  */
230 static void fmd1216me_bw(u8 *buf, u32 freq, int bandwidth)
231 {
232         if (bandwidth == BANDWIDTH_8_MHZ && freq >= 158870000)
233                 buf[3] |= 0x08;
234 }
235
236 struct dvb_pll_desc dvb_pll_fmd1216me = {
237         .name = "Philips FMD1216ME",
238         .min = 50870000,
239         .max = 858000000,
240         .setbw = fmd1216me_bw,
241         .count = 7,
242         .entries = {
243                 { 143870000, 36213333, 166667, 0xbc, 0x41 },
244                 { 158870000, 36213333, 166667, 0xf4, 0x41 },
245                 { 329870000, 36213333, 166667, 0xbc, 0x42 },
246                 { 441870000, 36213333, 166667, 0xf4, 0x42 },
247                 { 625870000, 36213333, 166667, 0xbc, 0x44 },
248                 { 803870000, 36213333, 166667, 0xf4, 0x44 },
249                 { 999999999, 36213333, 166667, 0xfc, 0x44 },
250         }
251 };
252 EXPORT_SYMBOL(dvb_pll_fmd1216me);
253
254 /* ALPS TDED4
255  * used in Nebula-Cards and USB boxes
256  */
257 static void tded4_bw(u8 *buf, u32 freq, int bandwidth)
258 {
259         if (bandwidth == BANDWIDTH_8_MHZ)
260                 buf[3] |= 0x04;
261 }
262
263 struct dvb_pll_desc dvb_pll_tded4 = {
264         .name = "ALPS TDED4",
265         .min = 47000000,
266         .max = 863000000,
267         .setbw = tded4_bw,
268         .count = 4,
269         .entries = {
270                 { 153000000, 36166667, 166667, 0x85, 0x01 },
271                 { 470000000, 36166667, 166667, 0x85, 0x02 },
272                 { 823000000, 36166667, 166667, 0x85, 0x08 },
273                 { 999999999, 36166667, 166667, 0x85, 0x88 },
274         }
275 };
276 EXPORT_SYMBOL(dvb_pll_tded4);
277
278 /* ----------------------------------------------------------- */
279 /* code                                                        */
280
281 static int debug = 0;
282 module_param(debug, int, 0644);
283 MODULE_PARM_DESC(debug, "enable verbose debug messages");
284
285 int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
286                       u32 freq, int bandwidth)
287 {
288         u32 div;
289         int i;
290
291         if (freq != 0 && (freq < desc->min || freq > desc->max))
292             return -EINVAL;
293
294         for (i = 0; i < desc->count; i++) {
295                 if (freq > desc->entries[i].limit)
296                         continue;
297                 break;
298         }
299         if (debug)
300                 printk("pll: %s: freq=%d bw=%d | i=%d/%d\n",
301                        desc->name, freq, bandwidth, i, desc->count);
302         BUG_ON(i == desc->count);
303
304         div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize;
305         buf[0] = div >> 8;
306         buf[1] = div & 0xff;
307         buf[2] = desc->entries[i].cb1;
308         buf[3] = desc->entries[i].cb2;
309
310         if (desc->setbw)
311                 desc->setbw(buf, freq, bandwidth);
312
313         if (debug)
314                 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
315                        desc->name, div, buf[0], buf[1], buf[2], buf[3]);
316
317         return 0;
318 }
319 EXPORT_SYMBOL(dvb_pll_configure);
320
321 MODULE_DESCRIPTION("dvb pll library");
322 MODULE_AUTHOR("Gerd Knorr");
323 MODULE_LICENSE("GPL");