]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
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. | |
1da177e4 LT |
15 | */ |
16 | ||
5479a582 MCC |
17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
18 | ||
5a0e3ad6 | 19 | #include <linux/slab.h> |
1da177e4 LT |
20 | #include <linux/module.h> |
21 | #include <linux/dvb/frontend.h> | |
22 | #include <asm/types.h> | |
23 | ||
24 | #include "dvb-pll.h" | |
25 | ||
5479a582 MCC |
26 | #define dprintk(fmt, arg...) \ |
27 | printk(KERN_DEBUG pr_fmt("%s: " fmt), __func__, ##arg) | |
28 | ||
05a4611b MK |
29 | struct dvb_pll_priv { |
30 | /* pll number */ | |
31 | int nr; | |
32 | ||
33 | /* i2c details */ | |
34 | int pll_i2c_address; | |
35 | struct i2c_adapter *i2c; | |
36 | ||
37 | /* the PLL descriptor */ | |
548146fb | 38 | const struct dvb_pll_desc *pll_desc; |
05a4611b MK |
39 | |
40 | /* cached frequency/bandwidth */ | |
41 | u32 frequency; | |
42 | u32 bandwidth; | |
43 | }; | |
44 | ||
ff3e7dd5 | 45 | #define DVB_PLL_MAX 64 |
05a4611b MK |
46 | |
47 | static unsigned int dvb_pll_devcount; | |
48 | ||
ff699e6b | 49 | static int debug; |
05a4611b MK |
50 | module_param(debug, int, 0644); |
51 | MODULE_PARM_DESC(debug, "enable verbose debug messages"); | |
52 | ||
704e39bf MK |
53 | static unsigned int id[DVB_PLL_MAX] = |
54 | { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED }; | |
55 | module_param_array(id, int, NULL, 0644); | |
56 | MODULE_PARM_DESC(id, "force pll id to use (DEBUG ONLY)"); | |
57 | ||
05a4611b MK |
58 | /* ----------------------------------------------------------- */ |
59 | ||
47a9991e | 60 | struct dvb_pll_desc { |
548146fb | 61 | const char *name; |
47a9991e MK |
62 | u32 min; |
63 | u32 max; | |
64 | u32 iffreq; | |
80d8d498 | 65 | void (*set)(struct dvb_frontend *fe, u8 *buf); |
47a9991e | 66 | u8 *initdata; |
2b74334d | 67 | u8 *initdata2; |
47a9991e MK |
68 | u8 *sleepdata; |
69 | int count; | |
70 | struct { | |
71 | u32 limit; | |
72 | u32 stepsize; | |
73 | u8 config; | |
74 | u8 cb; | |
548146fb | 75 | } entries[]; |
47a9991e MK |
76 | }; |
77 | ||
1da177e4 LT |
78 | /* ----------------------------------------------------------- */ |
79 | /* descriptions */ | |
80 | ||
548146fb | 81 | static const struct dvb_pll_desc dvb_pll_thomson_dtt7579 = { |
1da177e4 LT |
82 | .name = "Thomson dtt7579", |
83 | .min = 177000000, | |
84 | .max = 858000000, | |
df78cb0a | 85 | .iffreq= 36166667, |
d519dcf6 TP |
86 | .sleepdata = (u8[]){ 2, 0xb4, 0x03 }, |
87 | .count = 4, | |
1da177e4 | 88 | .entries = { |
df78cb0a TP |
89 | { 443250000, 166667, 0xb4, 0x02 }, |
90 | { 542000000, 166667, 0xb4, 0x08 }, | |
91 | { 771000000, 166667, 0xbc, 0x08 }, | |
92 | { 999999999, 166667, 0xf4, 0x08 }, | |
1da177e4 LT |
93 | }, |
94 | }; | |
1da177e4 | 95 | |
80d8d498 | 96 | static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf) |
1da177e4 | 97 | { |
80d8d498 MCC |
98 | u32 bw = fe->dtv_property_cache.bandwidth_hz; |
99 | if (bw == 7000000) | |
1da177e4 LT |
100 | buf[3] |= 0x10; |
101 | } | |
102 | ||
548146fb | 103 | static const struct dvb_pll_desc dvb_pll_thomson_dtt759x = { |
1da177e4 LT |
104 | .name = "Thomson dtt759x", |
105 | .min = 177000000, | |
106 | .max = 896000000, | |
77d67504 | 107 | .set = thomson_dtt759x_bw, |
df78cb0a | 108 | .iffreq= 36166667, |
d519dcf6 TP |
109 | .sleepdata = (u8[]){ 2, 0x84, 0x03 }, |
110 | .count = 5, | |
1da177e4 | 111 | .entries = { |
df78cb0a TP |
112 | { 264000000, 166667, 0xb4, 0x02 }, |
113 | { 470000000, 166667, 0xbc, 0x02 }, | |
114 | { 735000000, 166667, 0xbc, 0x08 }, | |
115 | { 835000000, 166667, 0xf4, 0x08 }, | |
116 | { 999999999, 166667, 0xfc, 0x08 }, | |
1da177e4 LT |
117 | }, |
118 | }; | |
1da177e4 | 119 | |
5fb67074 PC |
120 | static void thomson_dtt7520x_bw(struct dvb_frontend *fe, u8 *buf) |
121 | { | |
122 | u32 bw = fe->dtv_property_cache.bandwidth_hz; | |
123 | if (bw == 8000000) | |
124 | buf[3] ^= 0x10; | |
125 | } | |
126 | ||
548146fb | 127 | static const struct dvb_pll_desc dvb_pll_thomson_dtt7520x = { |
5fb67074 PC |
128 | .name = "Thomson dtt7520x", |
129 | .min = 185000000, | |
130 | .max = 900000000, | |
131 | .set = thomson_dtt7520x_bw, | |
132 | .iffreq = 36166667, | |
133 | .count = 7, | |
134 | .entries = { | |
135 | { 305000000, 166667, 0xb4, 0x12 }, | |
136 | { 405000000, 166667, 0xbc, 0x12 }, | |
137 | { 445000000, 166667, 0xbc, 0x12 }, | |
138 | { 465000000, 166667, 0xf4, 0x18 }, | |
139 | { 735000000, 166667, 0xfc, 0x18 }, | |
140 | { 835000000, 166667, 0xbc, 0x18 }, | |
141 | { 999999999, 166667, 0xfc, 0x18 }, | |
142 | }, | |
143 | }; | |
144 | ||
548146fb | 145 | static const struct dvb_pll_desc dvb_pll_lg_z201 = { |
1da177e4 LT |
146 | .name = "LG z201", |
147 | .min = 174000000, | |
148 | .max = 862000000, | |
df78cb0a | 149 | .iffreq= 36166667, |
d519dcf6 TP |
150 | .sleepdata = (u8[]){ 2, 0xbc, 0x03 }, |
151 | .count = 5, | |
1da177e4 | 152 | .entries = { |
df78cb0a TP |
153 | { 157500000, 166667, 0xbc, 0x01 }, |
154 | { 443250000, 166667, 0xbc, 0x02 }, | |
155 | { 542000000, 166667, 0xbc, 0x04 }, | |
156 | { 830000000, 166667, 0xf4, 0x04 }, | |
157 | { 999999999, 166667, 0xfc, 0x04 }, | |
1da177e4 LT |
158 | }, |
159 | }; | |
1da177e4 | 160 | |
548146fb | 161 | static const struct dvb_pll_desc dvb_pll_unknown_1 = { |
1da177e4 LT |
162 | .name = "unknown 1", /* used by dntv live dvb-t */ |
163 | .min = 174000000, | |
164 | .max = 862000000, | |
df78cb0a | 165 | .iffreq= 36166667, |
1da177e4 LT |
166 | .count = 9, |
167 | .entries = { | |
df78cb0a TP |
168 | { 150000000, 166667, 0xb4, 0x01 }, |
169 | { 173000000, 166667, 0xbc, 0x01 }, | |
170 | { 250000000, 166667, 0xb4, 0x02 }, | |
171 | { 400000000, 166667, 0xbc, 0x02 }, | |
172 | { 420000000, 166667, 0xf4, 0x02 }, | |
173 | { 470000000, 166667, 0xfc, 0x02 }, | |
174 | { 600000000, 166667, 0xbc, 0x08 }, | |
175 | { 730000000, 166667, 0xf4, 0x08 }, | |
176 | { 999999999, 166667, 0xfc, 0x08 }, | |
1da177e4 LT |
177 | }, |
178 | }; | |
1da177e4 | 179 | |
776338e1 JS |
180 | /* Infineon TUA6010XS |
181 | * used in Thomson Cable Tuner | |
182 | */ | |
548146fb | 183 | static const struct dvb_pll_desc dvb_pll_tua6010xs = { |
776338e1 JS |
184 | .name = "Infineon TUA6010XS", |
185 | .min = 44250000, | |
186 | .max = 858000000, | |
df78cb0a | 187 | .iffreq= 36125000, |
776338e1 JS |
188 | .count = 3, |
189 | .entries = { | |
df78cb0a TP |
190 | { 115750000, 62500, 0x8e, 0x03 }, |
191 | { 403250000, 62500, 0x8e, 0x06 }, | |
192 | { 999999999, 62500, 0x8e, 0x85 }, | |
776338e1 JS |
193 | }, |
194 | }; | |
776338e1 JS |
195 | |
196 | /* Panasonic env57h1xd5 (some Philips PLL ?) */ | |
548146fb | 197 | static const struct dvb_pll_desc dvb_pll_env57h1xd5 = { |
776338e1 JS |
198 | .name = "Panasonic ENV57H1XD5", |
199 | .min = 44250000, | |
200 | .max = 858000000, | |
df78cb0a | 201 | .iffreq= 36125000, |
776338e1 JS |
202 | .count = 4, |
203 | .entries = { | |
df78cb0a TP |
204 | { 153000000, 166667, 0xc2, 0x41 }, |
205 | { 470000000, 166667, 0xc2, 0x42 }, | |
206 | { 526000000, 166667, 0xc2, 0x84 }, | |
207 | { 999999999, 166667, 0xc2, 0xa4 }, | |
776338e1 JS |
208 | }, |
209 | }; | |
776338e1 JS |
210 | |
211 | /* Philips TDA6650/TDA6651 | |
212 | * used in Panasonic ENV77H11D5 | |
213 | */ | |
80d8d498 | 214 | static void tda665x_bw(struct dvb_frontend *fe, u8 *buf) |
776338e1 | 215 | { |
80d8d498 MCC |
216 | u32 bw = fe->dtv_property_cache.bandwidth_hz; |
217 | if (bw == 8000000) | |
776338e1 JS |
218 | buf[3] |= 0x08; |
219 | } | |
220 | ||
548146fb | 221 | static const struct dvb_pll_desc dvb_pll_tda665x = { |
776338e1 JS |
222 | .name = "Philips TDA6650/TDA6651", |
223 | .min = 44250000, | |
224 | .max = 858000000, | |
77d67504 | 225 | .set = tda665x_bw, |
df78cb0a | 226 | .iffreq= 36166667, |
fbfee868 | 227 | .initdata = (u8[]){ 4, 0x0b, 0xf5, 0x85, 0xab }, |
776338e1 JS |
228 | .count = 12, |
229 | .entries = { | |
df78cb0a TP |
230 | { 93834000, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ }, |
231 | { 123834000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ }, | |
232 | { 161000000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ }, | |
233 | { 163834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ }, | |
234 | { 253834000, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ }, | |
235 | { 383834000, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ }, | |
236 | { 443834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ }, | |
237 | { 444000000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ }, | |
238 | { 583834000, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ }, | |
239 | { 793834000, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ }, | |
240 | { 444834000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ }, | |
241 | { 861000000, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ }, | |
776338e1 JS |
242 | } |
243 | }; | |
776338e1 JS |
244 | |
245 | /* Infineon TUA6034 | |
246 | * used in LG TDTP E102P | |
247 | */ | |
80d8d498 | 248 | static void tua6034_bw(struct dvb_frontend *fe, u8 *buf) |
776338e1 | 249 | { |
80d8d498 MCC |
250 | u32 bw = fe->dtv_property_cache.bandwidth_hz; |
251 | if (bw == 7000000) | |
776338e1 JS |
252 | buf[3] |= 0x08; |
253 | } | |
254 | ||
548146fb | 255 | static const struct dvb_pll_desc dvb_pll_tua6034 = { |
776338e1 JS |
256 | .name = "Infineon TUA6034", |
257 | .min = 44250000, | |
258 | .max = 858000000, | |
df78cb0a | 259 | .iffreq= 36166667, |
776338e1 | 260 | .count = 3, |
77d67504 | 261 | .set = tua6034_bw, |
776338e1 | 262 | .entries = { |
df78cb0a TP |
263 | { 174500000, 62500, 0xce, 0x01 }, |
264 | { 230000000, 62500, 0xce, 0x02 }, | |
265 | { 999999999, 62500, 0xce, 0x04 }, | |
776338e1 JS |
266 | }, |
267 | }; | |
776338e1 | 268 | |
0589b8e4 PB |
269 | /* ALPS TDED4 |
270 | * used in Nebula-Cards and USB boxes | |
271 | */ | |
80d8d498 | 272 | static void tded4_bw(struct dvb_frontend *fe, u8 *buf) |
0589b8e4 | 273 | { |
80d8d498 MCC |
274 | u32 bw = fe->dtv_property_cache.bandwidth_hz; |
275 | if (bw == 8000000) | |
0589b8e4 PB |
276 | buf[3] |= 0x04; |
277 | } | |
278 | ||
548146fb | 279 | static const struct dvb_pll_desc dvb_pll_tded4 = { |
0589b8e4 PB |
280 | .name = "ALPS TDED4", |
281 | .min = 47000000, | |
282 | .max = 863000000, | |
df78cb0a | 283 | .iffreq= 36166667, |
77d67504 | 284 | .set = tded4_bw, |
0589b8e4 PB |
285 | .count = 4, |
286 | .entries = { | |
df78cb0a TP |
287 | { 153000000, 166667, 0x85, 0x01 }, |
288 | { 470000000, 166667, 0x85, 0x02 }, | |
289 | { 823000000, 166667, 0x85, 0x08 }, | |
290 | { 999999999, 166667, 0x85, 0x88 }, | |
0589b8e4 PB |
291 | } |
292 | }; | |
0589b8e4 | 293 | |
147418c9 KL |
294 | /* ALPS TDHU2 |
295 | * used in AverTVHD MCE A180 | |
296 | */ | |
548146fb | 297 | static const struct dvb_pll_desc dvb_pll_tdhu2 = { |
147418c9 KL |
298 | .name = "ALPS TDHU2", |
299 | .min = 54000000, | |
300 | .max = 864000000, | |
df78cb0a | 301 | .iffreq= 44000000, |
147418c9 KL |
302 | .count = 4, |
303 | .entries = { | |
df78cb0a TP |
304 | { 162000000, 62500, 0x85, 0x01 }, |
305 | { 426000000, 62500, 0x85, 0x02 }, | |
306 | { 782000000, 62500, 0x85, 0x08 }, | |
307 | { 999999999, 62500, 0x85, 0x88 }, | |
147418c9 KL |
308 | } |
309 | }; | |
147418c9 | 310 | |
d76a6179 | 311 | /* Samsung TBMV30111IN / TBMV30712IN1 |
147418c9 KL |
312 | * used in Air2PC ATSC - 2nd generation (nxt2002) |
313 | */ | |
548146fb | 314 | static const struct dvb_pll_desc dvb_pll_samsung_tbmv = { |
28f3d4b3 | 315 | .name = "Samsung TBMV30111IN / TBMV30712IN1", |
147418c9 KL |
316 | .min = 54000000, |
317 | .max = 860000000, | |
df78cb0a | 318 | .iffreq= 44000000, |
17c37efb | 319 | .count = 6, |
147418c9 | 320 | .entries = { |
df78cb0a TP |
321 | { 172000000, 166667, 0xb4, 0x01 }, |
322 | { 214000000, 166667, 0xb4, 0x02 }, | |
323 | { 467000000, 166667, 0xbc, 0x02 }, | |
324 | { 721000000, 166667, 0xbc, 0x08 }, | |
325 | { 841000000, 166667, 0xf4, 0x08 }, | |
326 | { 999999999, 166667, 0xfc, 0x02 }, | |
147418c9 KL |
327 | } |
328 | }; | |
147418c9 | 329 | |
f8bf134d RP |
330 | /* |
331 | * Philips SD1878 Tuner. | |
332 | */ | |
548146fb | 333 | static const struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = { |
f8bf134d RP |
334 | .name = "Philips SD1878", |
335 | .min = 950000, | |
336 | .max = 2150000, | |
df78cb0a | 337 | .iffreq= 249, /* zero-IF, offset 249 is to round up */ |
f8bf134d RP |
338 | .count = 4, |
339 | .entries = { | |
df78cb0a | 340 | { 1250000, 500, 0xc4, 0x00}, |
b3332a98 | 341 | { 1450000, 500, 0xc4, 0x40}, |
df78cb0a TP |
342 | { 2050000, 500, 0xc4, 0x80}, |
343 | { 2150000, 500, 0xc4, 0xc0}, | |
f8bf134d RP |
344 | }, |
345 | }; | |
f8bf134d | 346 | |
80d8d498 | 347 | static void opera1_bw(struct dvb_frontend *fe, u8 *buf) |
941491f3 | 348 | { |
80d8d498 | 349 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
2b74334d | 350 | struct dvb_pll_priv *priv = fe->tuner_priv; |
80d8d498 | 351 | u32 b_w = (c->symbol_rate * 27) / 32000; |
2b74334d MP |
352 | struct i2c_msg msg = { |
353 | .addr = priv->pll_i2c_address, | |
354 | .flags = 0, | |
355 | .buf = buf, | |
356 | .len = 4 | |
357 | }; | |
358 | int result; | |
359 | u8 lpf; | |
360 | ||
361 | if (fe->ops.i2c_gate_ctrl) | |
362 | fe->ops.i2c_gate_ctrl(fe, 1); | |
363 | ||
364 | result = i2c_transfer(priv->i2c, &msg, 1); | |
365 | if (result != 1) | |
5479a582 | 366 | pr_err("%s: i2c_transfer failed:%d", |
2b74334d MP |
367 | __func__, result); |
368 | ||
369 | if (b_w <= 10000) | |
370 | lpf = 0xc; | |
371 | else if (b_w <= 12000) | |
372 | lpf = 0x2; | |
373 | else if (b_w <= 14000) | |
374 | lpf = 0xa; | |
375 | else if (b_w <= 16000) | |
376 | lpf = 0x6; | |
377 | else if (b_w <= 18000) | |
378 | lpf = 0xe; | |
379 | else if (b_w <= 20000) | |
380 | lpf = 0x1; | |
381 | else if (b_w <= 22000) | |
382 | lpf = 0x9; | |
383 | else if (b_w <= 24000) | |
384 | lpf = 0x5; | |
385 | else if (b_w <= 26000) | |
386 | lpf = 0xd; | |
387 | else if (b_w <= 28000) | |
388 | lpf = 0x3; | |
389 | else | |
390 | lpf = 0xb; | |
391 | buf[2] ^= 0x1c; /* Flip bits 3-5 */ | |
392 | /* Set lpf */ | |
393 | buf[2] |= ((lpf >> 2) & 0x3) << 3; | |
394 | buf[3] |= (lpf & 0x3) << 2; | |
395 | ||
396 | return; | |
941491f3 MG |
397 | } |
398 | ||
548146fb | 399 | static const struct dvb_pll_desc dvb_pll_opera1 = { |
941491f3 MG |
400 | .name = "Opera Tuner", |
401 | .min = 900000, | |
402 | .max = 2250000, | |
2b74334d MP |
403 | .initdata = (u8[]){ 4, 0x08, 0xe5, 0xe1, 0x00 }, |
404 | .initdata2 = (u8[]){ 4, 0x08, 0xe5, 0xe5, 0x00 }, | |
941491f3 | 405 | .iffreq= 0, |
77d67504 | 406 | .set = opera1_bw, |
941491f3 MG |
407 | .count = 8, |
408 | .entries = { | |
2b74334d MP |
409 | { 1064000, 500, 0xf9, 0xc2 }, |
410 | { 1169000, 500, 0xf9, 0xe2 }, | |
411 | { 1299000, 500, 0xf9, 0x20 }, | |
412 | { 1444000, 500, 0xf9, 0x40 }, | |
413 | { 1606000, 500, 0xf9, 0x60 }, | |
414 | { 1777000, 500, 0xf9, 0x80 }, | |
415 | { 1941000, 500, 0xf9, 0xa0 }, | |
416 | { 2250000, 500, 0xf9, 0xc0 }, | |
941491f3 MG |
417 | } |
418 | }; | |
47a9991e | 419 | |
80d8d498 | 420 | static void samsung_dtos403ih102a_set(struct dvb_frontend *fe, u8 *buf) |
139dfeb2 AP |
421 | { |
422 | struct dvb_pll_priv *priv = fe->tuner_priv; | |
423 | struct i2c_msg msg = { | |
424 | .addr = priv->pll_i2c_address, | |
425 | .flags = 0, | |
426 | .buf = buf, | |
427 | .len = 4 | |
428 | }; | |
429 | int result; | |
430 | ||
431 | if (fe->ops.i2c_gate_ctrl) | |
432 | fe->ops.i2c_gate_ctrl(fe, 1); | |
433 | ||
434 | result = i2c_transfer(priv->i2c, &msg, 1); | |
435 | if (result != 1) | |
5479a582 | 436 | pr_err("%s: i2c_transfer failed:%d", |
139dfeb2 AP |
437 | __func__, result); |
438 | ||
439 | buf[2] = 0x9e; | |
440 | buf[3] = 0x90; | |
441 | ||
442 | return; | |
443 | } | |
444 | ||
445 | /* unknown pll used in Samsung DTOS403IH102A DVB-C tuner */ | |
548146fb | 446 | static const struct dvb_pll_desc dvb_pll_samsung_dtos403ih102a = { |
139dfeb2 AP |
447 | .name = "Samsung DTOS403IH102A", |
448 | .min = 44250000, | |
449 | .max = 858000000, | |
450 | .iffreq = 36125000, | |
451 | .count = 8, | |
452 | .set = samsung_dtos403ih102a_set, | |
453 | .entries = { | |
454 | { 135000000, 62500, 0xbe, 0x01 }, | |
455 | { 177000000, 62500, 0xf6, 0x01 }, | |
456 | { 370000000, 62500, 0xbe, 0x02 }, | |
457 | { 450000000, 62500, 0xf6, 0x02 }, | |
458 | { 466000000, 62500, 0xfe, 0x02 }, | |
459 | { 538000000, 62500, 0xbe, 0x08 }, | |
460 | { 826000000, 62500, 0xf6, 0x08 }, | |
461 | { 999999999, 62500, 0xfe, 0x08 }, | |
462 | } | |
463 | }; | |
464 | ||
a104ed07 | 465 | /* Samsung TDTC9251DH0 DVB-T NIM, as used on AirStar 2 */ |
548146fb | 466 | static const struct dvb_pll_desc dvb_pll_samsung_tdtc9251dh0 = { |
a104ed07 TP |
467 | .name = "Samsung TDTC9251DH0", |
468 | .min = 48000000, | |
469 | .max = 863000000, | |
470 | .iffreq = 36166667, | |
471 | .count = 3, | |
472 | .entries = { | |
473 | { 157500000, 166667, 0xcc, 0x09 }, | |
474 | { 443000000, 166667, 0xcc, 0x0a }, | |
475 | { 863000000, 166667, 0xcc, 0x08 }, | |
476 | } | |
477 | }; | |
478 | ||
f52c4853 | 479 | /* Samsung TBDU18132 DVB-S NIM with TSA5059 PLL, used in SkyStar2 DVB-S 2.3 */ |
548146fb | 480 | static const struct dvb_pll_desc dvb_pll_samsung_tbdu18132 = { |
f52c4853 TP |
481 | .name = "Samsung TBDU18132", |
482 | .min = 950000, | |
483 | .max = 2150000, /* guesses */ | |
484 | .iffreq = 0, | |
485 | .count = 2, | |
486 | .entries = { | |
487 | { 1550000, 125, 0x84, 0x82 }, | |
488 | { 4095937, 125, 0x84, 0x80 }, | |
489 | } | |
490 | /* TSA5059 PLL has a 17 bit divisor rather than the 15 bits supported | |
491 | * by this driver. The two extra bits are 0x60 in the third byte. 15 | |
492 | * bits is enough for over 4 GHz, which is enough to cover the range | |
493 | * of this tuner. We could use the additional divisor bits by adding | |
494 | * more entries, e.g. | |
495 | { 0x0ffff * 125 + 125/2, 125, 0x84 | 0x20, }, | |
496 | { 0x17fff * 125 + 125/2, 125, 0x84 | 0x40, }, | |
497 | { 0x1ffff * 125 + 125/2, 125, 0x84 | 0x60, }, */ | |
498 | }; | |
499 | ||
9d5d75a9 | 500 | /* Samsung TBMU24112 DVB-S NIM with SL1935 zero-IF tuner */ |
548146fb | 501 | static const struct dvb_pll_desc dvb_pll_samsung_tbmu24112 = { |
9d5d75a9 TP |
502 | .name = "Samsung TBMU24112", |
503 | .min = 950000, | |
504 | .max = 2150000, /* guesses */ | |
505 | .iffreq = 0, | |
506 | .count = 2, | |
507 | .entries = { | |
508 | { 1500000, 125, 0x84, 0x18 }, | |
509 | { 9999999, 125, 0x84, 0x08 }, | |
510 | } | |
511 | }; | |
512 | ||
d799ce57 TP |
513 | /* Alps TDEE4 DVB-C NIM, used on Cablestar 2 */ |
514 | /* byte 4 : 1 * * AGD R3 R2 R1 R0 | |
515 | * byte 5 : C1 * RE RTS BS4 BS3 BS2 BS1 | |
516 | * AGD = 1, R3 R2 R1 R0 = 0 1 0 1 => byte 4 = 1**10101 = 0x95 | |
517 | * Range(MHz) C1 * RE RTS BS4 BS3 BS2 BS1 Byte 5 | |
518 | * 47 - 153 0 * 0 0 0 0 0 1 0x01 | |
519 | * 153 - 430 0 * 0 0 0 0 1 0 0x02 | |
520 | * 430 - 822 0 * 0 0 1 0 0 0 0x08 | |
521 | * 822 - 862 1 * 0 0 1 0 0 0 0x88 */ | |
548146fb | 522 | static const struct dvb_pll_desc dvb_pll_alps_tdee4 = { |
d799ce57 TP |
523 | .name = "ALPS TDEE4", |
524 | .min = 47000000, | |
525 | .max = 862000000, | |
526 | .iffreq = 36125000, | |
527 | .count = 4, | |
528 | .entries = { | |
529 | { 153000000, 62500, 0x95, 0x01 }, | |
530 | { 430000000, 62500, 0x95, 0x02 }, | |
531 | { 822000000, 62500, 0x95, 0x08 }, | |
532 | { 999999999, 62500, 0x95, 0x88 }, | |
533 | } | |
534 | }; | |
535 | ||
47a9991e MK |
536 | /* ----------------------------------------------------------- */ |
537 | ||
548146fb | 538 | static const struct dvb_pll_desc *pll_list[] = { |
47a9991e MK |
539 | [DVB_PLL_UNDEFINED] = NULL, |
540 | [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579, | |
541 | [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x, | |
5fb67074 | 542 | [DVB_PLL_THOMSON_DTT7520X] = &dvb_pll_thomson_dtt7520x, |
47a9991e | 543 | [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201, |
47a9991e MK |
544 | [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1, |
545 | [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs, | |
546 | [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5, | |
547 | [DVB_PLL_TUA6034] = &dvb_pll_tua6034, | |
47a9991e | 548 | [DVB_PLL_TDA665X] = &dvb_pll_tda665x, |
47a9991e | 549 | [DVB_PLL_TDED4] = &dvb_pll_tded4, |
d799ce57 | 550 | [DVB_PLL_TDEE4] = &dvb_pll_alps_tdee4, |
47a9991e MK |
551 | [DVB_PLL_TDHU2] = &dvb_pll_tdhu2, |
552 | [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv, | |
553 | [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261, | |
47a9991e | 554 | [DVB_PLL_OPERA1] = &dvb_pll_opera1, |
139dfeb2 | 555 | [DVB_PLL_SAMSUNG_DTOS403IH102A] = &dvb_pll_samsung_dtos403ih102a, |
a104ed07 | 556 | [DVB_PLL_SAMSUNG_TDTC9251DH0] = &dvb_pll_samsung_tdtc9251dh0, |
f52c4853 | 557 | [DVB_PLL_SAMSUNG_TBDU18132] = &dvb_pll_samsung_tbdu18132, |
9d5d75a9 | 558 | [DVB_PLL_SAMSUNG_TBMU24112] = &dvb_pll_samsung_tbmu24112, |
47a9991e MK |
559 | }; |
560 | ||
1da177e4 LT |
561 | /* ----------------------------------------------------------- */ |
562 | /* code */ | |
563 | ||
5d7802b2 | 564 | static int dvb_pll_configure(struct dvb_frontend *fe, u8 *buf, |
80d8d498 | 565 | const u32 frequency) |
1da177e4 | 566 | { |
5d7802b2 | 567 | struct dvb_pll_priv *priv = fe->tuner_priv; |
548146fb | 568 | const struct dvb_pll_desc *desc = priv->pll_desc; |
1da177e4 LT |
569 | u32 div; |
570 | int i; | |
571 | ||
80d8d498 | 572 | if (frequency && (frequency < desc->min || frequency > desc->max)) |
77d67504 | 573 | return -EINVAL; |
1da177e4 LT |
574 | |
575 | for (i = 0; i < desc->count; i++) { | |
80d8d498 | 576 | if (frequency > desc->entries[i].limit) |
1da177e4 LT |
577 | continue; |
578 | break; | |
579 | } | |
77d67504 | 580 | |
1da177e4 | 581 | if (debug) |
5479a582 | 582 | dprintk("pll: %s: freq=%d | i=%d/%d\n", desc->name, |
80d8d498 | 583 | frequency, i, desc->count); |
272bc4db AQ |
584 | if (i == desc->count) |
585 | return -EINVAL; | |
1da177e4 | 586 | |
80d8d498 | 587 | div = (frequency + desc->iffreq + |
77d67504 | 588 | desc->entries[i].stepsize/2) / desc->entries[i].stepsize; |
1da177e4 LT |
589 | buf[0] = div >> 8; |
590 | buf[1] = div & 0xff; | |
ab66b22f MK |
591 | buf[2] = desc->entries[i].config; |
592 | buf[3] = desc->entries[i].cb; | |
1da177e4 | 593 | |
77d67504 | 594 | if (desc->set) |
80d8d498 | 595 | desc->set(fe, buf); |
1da177e4 LT |
596 | |
597 | if (debug) | |
5479a582 | 598 | dprintk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n", |
1da177e4 LT |
599 | desc->name, div, buf[0], buf[1], buf[2], buf[3]); |
600 | ||
89faeefc | 601 | // calculate the frequency we set it to |
df78cb0a | 602 | return (div * desc->entries[i].stepsize) - desc->iffreq; |
1da177e4 | 603 | } |
1da177e4 | 604 | |
f2709c20 MCC |
605 | static void dvb_pll_release(struct dvb_frontend *fe) |
606 | { | |
607 | kfree(fe->tuner_priv); | |
608 | fe->tuner_priv = NULL; | |
609 | } | |
610 | ||
272bc4db AQ |
611 | static int dvb_pll_sleep(struct dvb_frontend *fe) |
612 | { | |
613 | struct dvb_pll_priv *priv = fe->tuner_priv; | |
272bc4db | 614 | |
c162dff6 CP |
615 | if (priv->i2c == NULL) |
616 | return -EINVAL; | |
617 | ||
d519dcf6 TP |
618 | if (priv->pll_desc->sleepdata) { |
619 | struct i2c_msg msg = { .flags = 0, | |
620 | .addr = priv->pll_i2c_address, | |
621 | .buf = priv->pll_desc->sleepdata + 1, | |
622 | .len = priv->pll_desc->sleepdata[0] }; | |
272bc4db | 623 | |
d519dcf6 | 624 | int result; |
272bc4db | 625 | |
d519dcf6 TP |
626 | if (fe->ops.i2c_gate_ctrl) |
627 | fe->ops.i2c_gate_ctrl(fe, 1); | |
628 | if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) { | |
629 | return result; | |
630 | } | |
631 | return 0; | |
272bc4db | 632 | } |
d519dcf6 TP |
633 | /* Shouldn't be called when initdata is NULL, maybe BUG()? */ |
634 | return -EINVAL; | |
272bc4db AQ |
635 | } |
636 | ||
14d24d14 | 637 | static int dvb_pll_set_params(struct dvb_frontend *fe) |
272bc4db | 638 | { |
80d8d498 | 639 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
272bc4db AQ |
640 | struct dvb_pll_priv *priv = fe->tuner_priv; |
641 | u8 buf[4]; | |
642 | struct i2c_msg msg = | |
47ae9ae8 MK |
643 | { .addr = priv->pll_i2c_address, .flags = 0, |
644 | .buf = buf, .len = sizeof(buf) }; | |
272bc4db | 645 | int result; |
77d67504 | 646 | u32 frequency = 0; |
272bc4db AQ |
647 | |
648 | if (priv->i2c == NULL) | |
649 | return -EINVAL; | |
650 | ||
80d8d498 MCC |
651 | result = dvb_pll_configure(fe, buf, c->frequency); |
652 | if (result < 0) | |
272bc4db | 653 | return result; |
89faeefc MK |
654 | else |
655 | frequency = result; | |
272bc4db | 656 | |
dea74869 PB |
657 | if (fe->ops.i2c_gate_ctrl) |
658 | fe->ops.i2c_gate_ctrl(fe, 1); | |
272bc4db AQ |
659 | if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) { |
660 | return result; | |
661 | } | |
662 | ||
89faeefc | 663 | priv->frequency = frequency; |
c6f56e7d | 664 | priv->bandwidth = c->bandwidth_hz; |
272bc4db AQ |
665 | |
666 | return 0; | |
667 | } | |
668 | ||
47ae9ae8 | 669 | static int dvb_pll_calc_regs(struct dvb_frontend *fe, |
47ae9ae8 | 670 | u8 *buf, int buf_len) |
272bc4db | 671 | { |
249fa0b0 | 672 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
272bc4db AQ |
673 | struct dvb_pll_priv *priv = fe->tuner_priv; |
674 | int result; | |
77d67504 | 675 | u32 frequency = 0; |
272bc4db AQ |
676 | |
677 | if (buf_len < 5) | |
678 | return -EINVAL; | |
679 | ||
249fa0b0 | 680 | result = dvb_pll_configure(fe, buf + 1, c->frequency); |
80d8d498 | 681 | if (result < 0) |
272bc4db | 682 | return result; |
89faeefc MK |
683 | else |
684 | frequency = result; | |
685 | ||
272bc4db AQ |
686 | buf[0] = priv->pll_i2c_address; |
687 | ||
89faeefc | 688 | priv->frequency = frequency; |
249fa0b0 | 689 | priv->bandwidth = c->bandwidth_hz; |
272bc4db AQ |
690 | |
691 | return 5; | |
692 | } | |
693 | ||
694 | static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency) | |
695 | { | |
696 | struct dvb_pll_priv *priv = fe->tuner_priv; | |
697 | *frequency = priv->frequency; | |
698 | return 0; | |
699 | } | |
700 | ||
701 | static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) | |
702 | { | |
703 | struct dvb_pll_priv *priv = fe->tuner_priv; | |
704 | *bandwidth = priv->bandwidth; | |
705 | return 0; | |
706 | } | |
707 | ||
26aed922 TP |
708 | static int dvb_pll_init(struct dvb_frontend *fe) |
709 | { | |
710 | struct dvb_pll_priv *priv = fe->tuner_priv; | |
711 | ||
712 | if (priv->i2c == NULL) | |
713 | return -EINVAL; | |
714 | ||
715 | if (priv->pll_desc->initdata) { | |
716 | struct i2c_msg msg = { .flags = 0, | |
717 | .addr = priv->pll_i2c_address, | |
718 | .buf = priv->pll_desc->initdata + 1, | |
719 | .len = priv->pll_desc->initdata[0] }; | |
720 | ||
721 | int result; | |
722 | if (fe->ops.i2c_gate_ctrl) | |
723 | fe->ops.i2c_gate_ctrl(fe, 1); | |
2b74334d MP |
724 | result = i2c_transfer(priv->i2c, &msg, 1); |
725 | if (result != 1) | |
26aed922 | 726 | return result; |
2b74334d MP |
727 | if (priv->pll_desc->initdata2) { |
728 | msg.buf = priv->pll_desc->initdata2 + 1; | |
729 | msg.len = priv->pll_desc->initdata2[0]; | |
730 | if (fe->ops.i2c_gate_ctrl) | |
731 | fe->ops.i2c_gate_ctrl(fe, 1); | |
732 | result = i2c_transfer(priv->i2c, &msg, 1); | |
733 | if (result != 1) | |
734 | return result; | |
26aed922 TP |
735 | } |
736 | return 0; | |
737 | } | |
738 | /* Shouldn't be called when initdata is NULL, maybe BUG()? */ | |
739 | return -EINVAL; | |
740 | } | |
741 | ||
14c4bf3c | 742 | static const struct dvb_tuner_ops dvb_pll_tuner_ops = { |
f2709c20 | 743 | .release = dvb_pll_release, |
272bc4db | 744 | .sleep = dvb_pll_sleep, |
d519dcf6 | 745 | .init = dvb_pll_init, |
272bc4db | 746 | .set_params = dvb_pll_set_params, |
bd4956b8 | 747 | .calc_regs = dvb_pll_calc_regs, |
272bc4db AQ |
748 | .get_frequency = dvb_pll_get_frequency, |
749 | .get_bandwidth = dvb_pll_get_bandwidth, | |
750 | }; | |
751 | ||
47ae9ae8 MK |
752 | struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, |
753 | struct i2c_adapter *i2c, | |
47a9991e | 754 | unsigned int pll_desc_id) |
272bc4db | 755 | { |
061b623c | 756 | u8 b1 [] = { 0 }; |
47ae9ae8 MK |
757 | struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD, |
758 | .buf = b1, .len = 1 }; | |
272bc4db | 759 | struct dvb_pll_priv *priv = NULL; |
061b623c | 760 | int ret; |
548146fb | 761 | const struct dvb_pll_desc *desc; |
47a9991e | 762 | |
704e39bf MK |
763 | if ((id[dvb_pll_devcount] > DVB_PLL_UNDEFINED) && |
764 | (id[dvb_pll_devcount] < ARRAY_SIZE(pll_list))) | |
765 | pll_desc_id = id[dvb_pll_devcount]; | |
766 | ||
47a9991e MK |
767 | BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list)); |
768 | ||
769 | desc = pll_list[pll_desc_id]; | |
061b623c | 770 | |
55c05b6d AQ |
771 | if (i2c != NULL) { |
772 | if (fe->ops.i2c_gate_ctrl) | |
773 | fe->ops.i2c_gate_ctrl(fe, 1); | |
774 | ||
95faba22 AQ |
775 | ret = i2c_transfer (i2c, &msg, 1); |
776 | if (ret != 1) | |
2bfe031d | 777 | return NULL; |
55c05b6d AQ |
778 | if (fe->ops.i2c_gate_ctrl) |
779 | fe->ops.i2c_gate_ctrl(fe, 0); | |
780 | } | |
272bc4db AQ |
781 | |
782 | priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL); | |
783 | if (priv == NULL) | |
2bfe031d | 784 | return NULL; |
272bc4db AQ |
785 | |
786 | priv->pll_i2c_address = pll_addr; | |
787 | priv->i2c = i2c; | |
788 | priv->pll_desc = desc; | |
a27e5e76 | 789 | priv->nr = dvb_pll_devcount++; |
272bc4db | 790 | |
47ae9ae8 MK |
791 | memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops, |
792 | sizeof(struct dvb_tuner_ops)); | |
793 | ||
982dd1bd TP |
794 | strncpy(fe->ops.tuner_ops.info.name, desc->name, |
795 | sizeof(fe->ops.tuner_ops.info.name)); | |
dea74869 | 796 | fe->ops.tuner_ops.info.frequency_min = desc->min; |
0d84a62b | 797 | fe->ops.tuner_ops.info.frequency_max = desc->max; |
d519dcf6 TP |
798 | if (!desc->initdata) |
799 | fe->ops.tuner_ops.init = NULL; | |
800 | if (!desc->sleepdata) | |
801 | fe->ops.tuner_ops.sleep = NULL; | |
272bc4db AQ |
802 | |
803 | fe->tuner_priv = priv; | |
a27e5e76 | 804 | |
8528fa41 | 805 | if ((debug) || (id[priv->nr] == pll_desc_id)) { |
5479a582 | 806 | dprintk("dvb-pll[%d]", priv->nr); |
a27e5e76 | 807 | if (i2c != NULL) |
5479a582 MCC |
808 | pr_cont(" %d-%04x", i2c_adapter_id(i2c), pll_addr); |
809 | pr_cont(": id# %d (%s) attached, %s\n", pll_desc_id, desc->name, | |
704e39bf MK |
810 | id[priv->nr] == pll_desc_id ? |
811 | "insmod option" : "autodetected"); | |
4562fbea | 812 | } |
a27e5e76 | 813 | |
2bfe031d | 814 | return fe; |
272bc4db AQ |
815 | } |
816 | EXPORT_SYMBOL(dvb_pll_attach); | |
817 | ||
1da177e4 LT |
818 | MODULE_DESCRIPTION("dvb pll library"); |
819 | MODULE_AUTHOR("Gerd Knorr"); | |
820 | MODULE_LICENSE("GPL"); |