diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2006-09-23 19:40:20 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-02-21 10:34:50 -0500 |
commit | 017cf012570c955c3e1ff025802d7cb46fd1d37b (patch) | |
tree | 7cceec55fdfdbc40751198d267c89f8ea13473bd /drivers | |
parent | 2a2bfa7d61b29170b7f9bbf42712a77229e6b935 (diff) |
V4L/DVB (5129): M920x: break out qt1010 tuner code into a separate file
qt1010 is a tuner used in some other devices, so this code should be put
into a separate file so that it could be reused by other drivers.
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/dvb/dvb-usb/m920x.c | 204 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/qt1010.h | 221 |
2 files changed, 222 insertions, 203 deletions
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c index 5ab16b15b95c..292805aad69a 100644 --- a/drivers/media/dvb/dvb-usb/m920x.c +++ b/drivers/media/dvb/dvb-usb/m920x.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include "mt352.h" | 14 | #include "mt352.h" |
15 | #include "mt352_priv.h" | 15 | #include "mt352_priv.h" |
16 | #include "qt1010.h" | ||
16 | 17 | ||
17 | /* debug */ | 18 | /* debug */ |
18 | int dvb_usb_m920x_debug; | 19 | int dvb_usb_m920x_debug; |
@@ -226,209 +227,6 @@ static int megasky_mt352_demod_init(struct dvb_frontend *fe) | |||
226 | 227 | ||
227 | struct mt352_state; | 228 | struct mt352_state; |
228 | 229 | ||
229 | #define W 0 | ||
230 | #define R 1 | ||
231 | /* Not actual hw limits. */ | ||
232 | #define QT1010_MIN_STEP 2000000 | ||
233 | #define QT1010_MIN_FREQ 48000000 | ||
234 | |||
235 | int qt1010_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8 *buf, int buf_len) | ||
236 | { | ||
237 | int i; | ||
238 | int div, mod; | ||
239 | struct { | ||
240 | u8 read, reg, value; | ||
241 | } rd[46] = { { W, 0x01, 0x80 }, | ||
242 | { W, 0x02, 0x3f }, | ||
243 | { W, 0x05, 0xff }, /* c */ | ||
244 | { W, 0x06, 0x44 }, | ||
245 | { W, 0x07, 0xff }, /* c */ | ||
246 | { W, 0x08, 0x08 }, | ||
247 | { W, 0x09, 0xff }, /* c */ | ||
248 | { W, 0x0a, 0xff }, /* c */ | ||
249 | { W, 0x0b, 0xff }, /* c */ | ||
250 | { W, 0x0c, 0xe1 }, | ||
251 | { W, 0x1a, 0xff }, /* 10 c */ | ||
252 | { W, 0x1b, 0x00 }, | ||
253 | { W, 0x1c, 0x89 }, | ||
254 | { W, 0x11, 0xff }, /* c */ | ||
255 | { W, 0x12, 0x91 }, | ||
256 | { W, 0x22, 0xff }, /* c */ | ||
257 | { W, 0x1e, 0x00 }, | ||
258 | { W, 0x1e, 0xd0 }, | ||
259 | { R, 0x22, 0xff }, /* c read */ | ||
260 | { W, 0x1e, 0x00 }, | ||
261 | { R, 0x05, 0xff }, /* 20 c read */ | ||
262 | { R, 0x22, 0xff }, /* c read */ | ||
263 | { W, 0x23, 0xd0 }, | ||
264 | { W, 0x1e, 0x00 }, | ||
265 | { W, 0x1e, 0xe0 }, | ||
266 | { R, 0x23, 0xff }, /* c read */ | ||
267 | { W, 0x1e, 0x00 }, | ||
268 | { W, 0x24, 0xd0 }, | ||
269 | { W, 0x1e, 0x00 }, | ||
270 | { W, 0x1e, 0xf0 }, | ||
271 | { R, 0x24, 0xff }, /* 30 c read */ | ||
272 | { W, 0x1e, 0x00 }, | ||
273 | { W, 0x14, 0x7f }, | ||
274 | { W, 0x15, 0x7f }, | ||
275 | { W, 0x05, 0xff }, /* c */ | ||
276 | { W, 0x06, 0x00 }, | ||
277 | { W, 0x15, 0x1f }, | ||
278 | { W, 0x16, 0xff }, | ||
279 | { W, 0x18, 0xff }, | ||
280 | { W, 0x1f, 0xff }, /* c */ | ||
281 | { W, 0x20, 0xff }, /* 40 c */ | ||
282 | { W, 0x21, 0x53 }, | ||
283 | { W, 0x25, 0xbd }, | ||
284 | { W, 0x26, 0x15 }, | ||
285 | { W, 0x02, 0x00 }, | ||
286 | { W, 0x01, 0x00 }, | ||
287 | }; | ||
288 | struct i2c_msg msg; | ||
289 | struct dvb_usb_device *d = fe->dvb->priv; | ||
290 | unsigned long freq = params->frequency; | ||
291 | |||
292 | if (freq % QT1010_MIN_STEP) | ||
293 | deb_rc("frequency not supported.\n"); | ||
294 | |||
295 | (void) buf; | ||
296 | (void) buf_len; | ||
297 | |||
298 | div = (freq - QT1010_MIN_FREQ) / QT1010_MIN_STEP; | ||
299 | mod = (div + 16 - 9) % 16; | ||
300 | |||
301 | /* 0x5 */ | ||
302 | if (div >= 377) | ||
303 | rd[2].value = 0x74; | ||
304 | else if (div >= 265) | ||
305 | rd[2].value = 0x54; | ||
306 | else if (div >= 121) | ||
307 | rd[2].value = 0x34; | ||
308 | else | ||
309 | rd[2].value = 0x14; | ||
310 | |||
311 | /* 0x7 */ | ||
312 | rd[4].value = (((freq - QT1010_MIN_FREQ) / 1000000) * 9975 + 12960000) / 320000; | ||
313 | |||
314 | /* 09 */ | ||
315 | if (mod < 4) | ||
316 | rd[6].value = 0x1d; | ||
317 | else | ||
318 | rd[6].value = 0x1c; | ||
319 | |||
320 | /* 0a */ | ||
321 | if (mod < 2) | ||
322 | rd[7].value = 0x09; | ||
323 | else if (mod < 4) | ||
324 | rd[7].value = 0x08; | ||
325 | else if (mod < 6) | ||
326 | rd[7].value = 0x0f; | ||
327 | else if (mod < 8) | ||
328 | rd[7].value = 0x0e; | ||
329 | else if (mod < 10) | ||
330 | rd[7].value = 0x0d; | ||
331 | else if (mod < 12) | ||
332 | rd[7].value = 0x0c; | ||
333 | else if (mod < 14) | ||
334 | rd[7].value = 0x0b; | ||
335 | else | ||
336 | rd[7].value = 0x0a; | ||
337 | |||
338 | /* 0b */ | ||
339 | if (div & 1) | ||
340 | rd[8].value = 0x45; | ||
341 | else | ||
342 | rd[8].value = 0x44; | ||
343 | |||
344 | /* 1a */ | ||
345 | if (div & 1) | ||
346 | rd[10].value = 0x78; | ||
347 | else | ||
348 | rd[10].value = 0xf8; | ||
349 | |||
350 | /* 11 */ | ||
351 | if (div >= 265) | ||
352 | rd[13].value = 0xf9; | ||
353 | else if (div >= 121) | ||
354 | rd[13].value = 0xfd; | ||
355 | else | ||
356 | rd[13].value = 0xf9; | ||
357 | |||
358 | /* 22 */ | ||
359 | if (div < 201) | ||
360 | rd[15].value = 0xd0; | ||
361 | else if (div < 217) | ||
362 | rd[15].value = 0xd3; | ||
363 | else if (div < 233) | ||
364 | rd[15].value = 0xd6; | ||
365 | else if (div < 249) | ||
366 | rd[15].value = 0xd9; | ||
367 | else if (div < 265) | ||
368 | rd[15].value = 0xda; | ||
369 | else | ||
370 | rd[15].value = 0xd0; | ||
371 | |||
372 | /* 05 */ | ||
373 | if (div >= 377) | ||
374 | rd[34].value = 0x70; | ||
375 | else if (div >= 265) | ||
376 | rd[34].value = 0x50; | ||
377 | else if (div >= 121) | ||
378 | rd[34].value = 0x30; | ||
379 | else | ||
380 | rd[34].value = 0x10; | ||
381 | |||
382 | /* 1f */ | ||
383 | if (mod < 4) | ||
384 | rd[39].value = 0x64; | ||
385 | else if (mod < 6) | ||
386 | rd[39].value = 0x66; | ||
387 | else if (mod < 8) | ||
388 | rd[39].value = 0x67; | ||
389 | else if (mod < 12) | ||
390 | rd[39].value = 0x68; | ||
391 | else if (mod < 14) | ||
392 | rd[39].value = 0x69; | ||
393 | else | ||
394 | rd[39].value = 0x6a; | ||
395 | |||
396 | /* 20 */ | ||
397 | if (mod < 4) | ||
398 | rd[40].value = 0x10; | ||
399 | else if (mod < 6) | ||
400 | rd[40].value = 0x11; | ||
401 | else if (mod < 10) | ||
402 | rd[40].value = 0x12; | ||
403 | else if (mod < 12) | ||
404 | rd[40].value = 0x13; | ||
405 | else if (mod < 14) | ||
406 | rd[40].value = 0x14; | ||
407 | else | ||
408 | rd[40].value = 0x15; | ||
409 | |||
410 | deb_rc("Now tuning... "); | ||
411 | for (i = 0; i < sizeof(rd) / sizeof(*rd); i++) { | ||
412 | if (rd[i].read) | ||
413 | continue; | ||
414 | |||
415 | msg.flags = 0; | ||
416 | msg.len = 2; | ||
417 | msg.addr = 0xc4; | ||
418 | msg.buf = &rd[i].reg; | ||
419 | |||
420 | if (i2c_transfer(&d->i2c_adap, &msg, 1) != 1) { | ||
421 | deb_rc("tuner write failed\n"); | ||
422 | return -EIO; | ||
423 | } | ||
424 | } | ||
425 | deb_rc("done\n"); | ||
426 | |||
427 | return 0; | ||
428 | } | ||
429 | #undef W | ||
430 | #undef R | ||
431 | |||
432 | static struct mt352_config megasky_mt352_config = { | 230 | static struct mt352_config megasky_mt352_config = { |
433 | .demod_address = 0x1e, | 231 | .demod_address = 0x1e, |
434 | .demod_init = megasky_mt352_demod_init, | 232 | .demod_init = megasky_mt352_demod_init, |
diff --git a/drivers/media/dvb/frontends/qt1010.h b/drivers/media/dvb/frontends/qt1010.h new file mode 100644 index 000000000000..e526e3c23265 --- /dev/null +++ b/drivers/media/dvb/frontends/qt1010.h | |||
@@ -0,0 +1,221 @@ | |||
1 | /* | ||
2 | * qt1010.h - DVB-T Tuner support | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | #ifndef _QT1010_H_ | ||
20 | #define _QT1010_H_ | ||
21 | |||
22 | #define QT1010_W 0 | ||
23 | #define QT1010_R 1 | ||
24 | /* Not actual hw limits. */ | ||
25 | #define QT1010_MIN_STEP 2000000 | ||
26 | #define QT1010_MIN_FREQ 48000000 | ||
27 | |||
28 | static int qt1010_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8 *buf, int buf_len) | ||
29 | { | ||
30 | int i; | ||
31 | int div, mod; | ||
32 | struct { | ||
33 | u8 read, reg, value; | ||
34 | } rd[46] = { { QT1010_W, 0x01, 0x80 }, | ||
35 | { QT1010_W, 0x02, 0x3f }, | ||
36 | { QT1010_W, 0x05, 0xff }, /* c */ | ||
37 | { QT1010_W, 0x06, 0x44 }, | ||
38 | { QT1010_W, 0x07, 0xff }, /* c */ | ||
39 | { QT1010_W, 0x08, 0x08 }, | ||
40 | { QT1010_W, 0x09, 0xff }, /* c */ | ||
41 | { QT1010_W, 0x0a, 0xff }, /* c */ | ||
42 | { QT1010_W, 0x0b, 0xff }, /* c */ | ||
43 | { QT1010_W, 0x0c, 0xe1 }, | ||
44 | { QT1010_W, 0x1a, 0xff }, /* 10 c */ | ||
45 | { QT1010_W, 0x1b, 0x00 }, | ||
46 | { QT1010_W, 0x1c, 0x89 }, | ||
47 | { QT1010_W, 0x11, 0xff }, /* c */ | ||
48 | { QT1010_W, 0x12, 0x91 }, | ||
49 | { QT1010_W, 0x22, 0xff }, /* c */ | ||
50 | { QT1010_W, 0x1e, 0x00 }, | ||
51 | { QT1010_W, 0x1e, 0xd0 }, | ||
52 | { QT1010_R, 0x22, 0xff }, /* c read */ | ||
53 | { QT1010_W, 0x1e, 0x00 }, | ||
54 | { QT1010_R, 0x05, 0xff }, /* 20 c read */ | ||
55 | { QT1010_R, 0x22, 0xff }, /* c read */ | ||
56 | { QT1010_W, 0x23, 0xd0 }, | ||
57 | { QT1010_W, 0x1e, 0x00 }, | ||
58 | { QT1010_W, 0x1e, 0xe0 }, | ||
59 | { QT1010_R, 0x23, 0xff }, /* c read */ | ||
60 | { QT1010_W, 0x1e, 0x00 }, | ||
61 | { QT1010_W, 0x24, 0xd0 }, | ||
62 | { QT1010_W, 0x1e, 0x00 }, | ||
63 | { QT1010_W, 0x1e, 0xf0 }, | ||
64 | { QT1010_R, 0x24, 0xff }, /* 30 c read */ | ||
65 | { QT1010_W, 0x1e, 0x00 }, | ||
66 | { QT1010_W, 0x14, 0x7f }, | ||
67 | { QT1010_W, 0x15, 0x7f }, | ||
68 | { QT1010_W, 0x05, 0xff }, /* c */ | ||
69 | { QT1010_W, 0x06, 0x00 }, | ||
70 | { QT1010_W, 0x15, 0x1f }, | ||
71 | { QT1010_W, 0x16, 0xff }, | ||
72 | { QT1010_W, 0x18, 0xff }, | ||
73 | { QT1010_W, 0x1f, 0xff }, /* c */ | ||
74 | { QT1010_W, 0x20, 0xff }, /* 40 c */ | ||
75 | { QT1010_W, 0x21, 0x53 }, | ||
76 | { QT1010_W, 0x25, 0xbd }, | ||
77 | { QT1010_W, 0x26, 0x15 }, | ||
78 | { QT1010_W, 0x02, 0x00 }, | ||
79 | { QT1010_W, 0x01, 0x00 }, | ||
80 | }; | ||
81 | struct i2c_msg msg; | ||
82 | struct dvb_usb_device *d = fe->dvb->priv; | ||
83 | unsigned long freq = params->frequency; | ||
84 | |||
85 | if (freq % QT1010_MIN_STEP) | ||
86 | printk("frequency not supported.\n"); | ||
87 | |||
88 | (void) buf; | ||
89 | (void) buf_len; | ||
90 | |||
91 | div = (freq - QT1010_MIN_FREQ) / QT1010_MIN_STEP; | ||
92 | mod = (div + 16 - 9) % 16; | ||
93 | |||
94 | /* 0x5 */ | ||
95 | if (div >= 377) | ||
96 | rd[2].value = 0x74; | ||
97 | else if (div >= 265) | ||
98 | rd[2].value = 0x54; | ||
99 | else if (div >= 121) | ||
100 | rd[2].value = 0x34; | ||
101 | else | ||
102 | rd[2].value = 0x14; | ||
103 | |||
104 | /* 0x7 */ | ||
105 | rd[4].value = (((freq - QT1010_MIN_FREQ) / 1000000) * 9975 + 12960000) / 320000; | ||
106 | |||
107 | /* 09 */ | ||
108 | if (mod < 4) | ||
109 | rd[6].value = 0x1d; | ||
110 | else | ||
111 | rd[6].value = 0x1c; | ||
112 | |||
113 | /* 0a */ | ||
114 | if (mod < 2) | ||
115 | rd[7].value = 0x09; | ||
116 | else if (mod < 4) | ||
117 | rd[7].value = 0x08; | ||
118 | else if (mod < 6) | ||
119 | rd[7].value = 0x0f; | ||
120 | else if (mod < 8) | ||
121 | rd[7].value = 0x0e; | ||
122 | else if (mod < 10) | ||
123 | rd[7].value = 0x0d; | ||
124 | else if (mod < 12) | ||
125 | rd[7].value = 0x0c; | ||
126 | else if (mod < 14) | ||
127 | rd[7].value = 0x0b; | ||
128 | else | ||
129 | rd[7].value = 0x0a; | ||
130 | |||
131 | /* 0b */ | ||
132 | if (div & 1) | ||
133 | rd[8].value = 0x45; | ||
134 | else | ||
135 | rd[8].value = 0x44; | ||
136 | |||
137 | /* 1a */ | ||
138 | if (div & 1) | ||
139 | rd[10].value = 0x78; | ||
140 | else | ||
141 | rd[10].value = 0xf8; | ||
142 | |||
143 | /* 11 */ | ||
144 | if (div >= 265) | ||
145 | rd[13].value = 0xf9; | ||
146 | else if (div >= 121) | ||
147 | rd[13].value = 0xfd; | ||
148 | else | ||
149 | rd[13].value = 0xf9; | ||
150 | |||
151 | /* 22 */ | ||
152 | if (div < 201) | ||
153 | rd[15].value = 0xd0; | ||
154 | else if (div < 217) | ||
155 | rd[15].value = 0xd3; | ||
156 | else if (div < 233) | ||
157 | rd[15].value = 0xd6; | ||
158 | else if (div < 249) | ||
159 | rd[15].value = 0xd9; | ||
160 | else if (div < 265) | ||
161 | rd[15].value = 0xda; | ||
162 | else | ||
163 | rd[15].value = 0xd0; | ||
164 | |||
165 | /* 05 */ | ||
166 | if (div >= 377) | ||
167 | rd[34].value = 0x70; | ||
168 | else if (div >= 265) | ||
169 | rd[34].value = 0x50; | ||
170 | else if (div >= 121) | ||
171 | rd[34].value = 0x30; | ||
172 | else | ||
173 | rd[34].value = 0x10; | ||
174 | |||
175 | /* 1f */ | ||
176 | if (mod < 4) | ||
177 | rd[39].value = 0x64; | ||
178 | else if (mod < 6) | ||
179 | rd[39].value = 0x66; | ||
180 | else if (mod < 8) | ||
181 | rd[39].value = 0x67; | ||
182 | else if (mod < 12) | ||
183 | rd[39].value = 0x68; | ||
184 | else if (mod < 14) | ||
185 | rd[39].value = 0x69; | ||
186 | else | ||
187 | rd[39].value = 0x6a; | ||
188 | |||
189 | /* 20 */ | ||
190 | if (mod < 4) | ||
191 | rd[40].value = 0x10; | ||
192 | else if (mod < 6) | ||
193 | rd[40].value = 0x11; | ||
194 | else if (mod < 10) | ||
195 | rd[40].value = 0x12; | ||
196 | else if (mod < 12) | ||
197 | rd[40].value = 0x13; | ||
198 | else if (mod < 14) | ||
199 | rd[40].value = 0x14; | ||
200 | else | ||
201 | rd[40].value = 0x15; | ||
202 | |||
203 | for (i = 0; i < sizeof(rd) / sizeof(*rd); i++) { | ||
204 | if (rd[i].read) | ||
205 | continue; | ||
206 | |||
207 | msg.flags = 0; | ||
208 | msg.len = 2; | ||
209 | msg.addr = 0xc4; | ||
210 | msg.buf = &rd[i].reg; | ||
211 | |||
212 | if (i2c_transfer(&d->i2c_adap, &msg, 1) != 1) { | ||
213 | printk("tuner write failed\n"); | ||
214 | return -EIO; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | #endif | ||