diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/media/dvb/frontends/sp8870.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/media/dvb/frontends/sp8870.c')
-rw-r--r-- | drivers/media/dvb/frontends/sp8870.c | 614 |
1 files changed, 614 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/sp8870.c b/drivers/media/dvb/frontends/sp8870.c new file mode 100644 index 000000000000..58ad34ef0a00 --- /dev/null +++ b/drivers/media/dvb/frontends/sp8870.c | |||
@@ -0,0 +1,614 @@ | |||
1 | /* | ||
2 | Driver for Spase SP8870 demodulator | ||
3 | |||
4 | Copyright (C) 1999 Juergen Peitz | ||
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 | |||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software | ||
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | |||
21 | */ | ||
22 | /* | ||
23 | * This driver needs external firmware. Please use the command | ||
24 | * "<kerneldir>/Documentation/dvb/get_dvb_firmware alps_tdlb7" to | ||
25 | * download/extract it, and then copy it to /usr/lib/hotplug/firmware. | ||
26 | */ | ||
27 | #define SP8870_DEFAULT_FIRMWARE "dvb-fe-sp8870.fw" | ||
28 | |||
29 | #include <linux/init.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/moduleparam.h> | ||
32 | #include <linux/device.h> | ||
33 | #include <linux/firmware.h> | ||
34 | #include <linux/delay.h> | ||
35 | |||
36 | #include "dvb_frontend.h" | ||
37 | #include "sp8870.h" | ||
38 | |||
39 | |||
40 | struct sp8870_state { | ||
41 | |||
42 | struct i2c_adapter* i2c; | ||
43 | |||
44 | struct dvb_frontend_ops ops; | ||
45 | |||
46 | const struct sp8870_config* config; | ||
47 | |||
48 | struct dvb_frontend frontend; | ||
49 | |||
50 | /* demodulator private data */ | ||
51 | u8 initialised:1; | ||
52 | }; | ||
53 | |||
54 | static int debug; | ||
55 | #define dprintk(args...) \ | ||
56 | do { \ | ||
57 | if (debug) printk(KERN_DEBUG "sp8870: " args); \ | ||
58 | } while (0) | ||
59 | |||
60 | /* firmware size for sp8870 */ | ||
61 | #define SP8870_FIRMWARE_SIZE 16382 | ||
62 | |||
63 | /* starting point for firmware in file 'Sc_main.mc' */ | ||
64 | #define SP8870_FIRMWARE_OFFSET 0x0A | ||
65 | |||
66 | static int sp8870_writereg (struct sp8870_state* state, u16 reg, u16 data) | ||
67 | { | ||
68 | u8 buf [] = { reg >> 8, reg & 0xff, data >> 8, data & 0xff }; | ||
69 | struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 4 }; | ||
70 | int err; | ||
71 | |||
72 | if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { | ||
73 | dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __FUNCTION__, err, reg, data); | ||
74 | return -EREMOTEIO; | ||
75 | } | ||
76 | |||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static int sp8870_readreg (struct sp8870_state* state, u16 reg) | ||
81 | { | ||
82 | int ret; | ||
83 | u8 b0 [] = { reg >> 8 , reg & 0xff }; | ||
84 | u8 b1 [] = { 0, 0 }; | ||
85 | struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 2 }, | ||
86 | { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 2 } }; | ||
87 | |||
88 | ret = i2c_transfer (state->i2c, msg, 2); | ||
89 | |||
90 | if (ret != 2) { | ||
91 | dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); | ||
92 | return -1; | ||
93 | } | ||
94 | |||
95 | return (b1[0] << 8 | b1[1]); | ||
96 | } | ||
97 | |||
98 | static int sp8870_firmware_upload (struct sp8870_state* state, const struct firmware *fw) | ||
99 | { | ||
100 | struct i2c_msg msg; | ||
101 | char *fw_buf = fw->data; | ||
102 | int fw_pos; | ||
103 | u8 tx_buf[255]; | ||
104 | int tx_len; | ||
105 | int err = 0; | ||
106 | |||
107 | dprintk ("%s: ...\n", __FUNCTION__); | ||
108 | |||
109 | if (fw->size < SP8870_FIRMWARE_SIZE + SP8870_FIRMWARE_OFFSET) | ||
110 | return -EINVAL; | ||
111 | |||
112 | // system controller stop | ||
113 | sp8870_writereg(state, 0x0F00, 0x0000); | ||
114 | |||
115 | // instruction RAM register hiword | ||
116 | sp8870_writereg(state, 0x8F08, ((SP8870_FIRMWARE_SIZE / 2) & 0xFFFF)); | ||
117 | |||
118 | // instruction RAM MWR | ||
119 | sp8870_writereg(state, 0x8F0A, ((SP8870_FIRMWARE_SIZE / 2) >> 16)); | ||
120 | |||
121 | // do firmware upload | ||
122 | fw_pos = SP8870_FIRMWARE_OFFSET; | ||
123 | while (fw_pos < SP8870_FIRMWARE_SIZE + SP8870_FIRMWARE_OFFSET){ | ||
124 | tx_len = (fw_pos <= SP8870_FIRMWARE_SIZE + SP8870_FIRMWARE_OFFSET - 252) ? 252 : SP8870_FIRMWARE_SIZE + SP8870_FIRMWARE_OFFSET - fw_pos; | ||
125 | // write register 0xCF0A | ||
126 | tx_buf[0] = 0xCF; | ||
127 | tx_buf[1] = 0x0A; | ||
128 | memcpy(&tx_buf[2], fw_buf + fw_pos, tx_len); | ||
129 | msg.addr = state->config->demod_address; | ||
130 | msg.flags = 0; | ||
131 | msg.buf = tx_buf; | ||
132 | msg.len = tx_len + 2; | ||
133 | if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { | ||
134 | printk("%s: firmware upload failed!\n", __FUNCTION__); | ||
135 | printk ("%s: i2c error (err == %i)\n", __FUNCTION__, err); | ||
136 | return err; | ||
137 | } | ||
138 | fw_pos += tx_len; | ||
139 | } | ||
140 | |||
141 | dprintk ("%s: done!\n", __FUNCTION__); | ||
142 | return 0; | ||
143 | }; | ||
144 | |||
145 | static void sp8870_microcontroller_stop (struct sp8870_state* state) | ||
146 | { | ||
147 | sp8870_writereg(state, 0x0F08, 0x000); | ||
148 | sp8870_writereg(state, 0x0F09, 0x000); | ||
149 | |||
150 | // microcontroller STOP | ||
151 | sp8870_writereg(state, 0x0F00, 0x000); | ||
152 | } | ||
153 | |||
154 | static void sp8870_microcontroller_start (struct sp8870_state* state) | ||
155 | { | ||
156 | sp8870_writereg(state, 0x0F08, 0x000); | ||
157 | sp8870_writereg(state, 0x0F09, 0x000); | ||
158 | |||
159 | // microcontroller START | ||
160 | sp8870_writereg(state, 0x0F00, 0x001); | ||
161 | // not documented but if we don't read 0x0D01 out here | ||
162 | // we don't get a correct data valid signal | ||
163 | sp8870_readreg(state, 0x0D01); | ||
164 | } | ||
165 | |||
166 | static int sp8870_read_data_valid_signal(struct sp8870_state* state) | ||
167 | { | ||
168 | return (sp8870_readreg(state, 0x0D02) > 0); | ||
169 | } | ||
170 | |||
171 | static int configure_reg0xc05 (struct dvb_frontend_parameters *p, u16 *reg0xc05) | ||
172 | { | ||
173 | int known_parameters = 1; | ||
174 | |||
175 | *reg0xc05 = 0x000; | ||
176 | |||
177 | switch (p->u.ofdm.constellation) { | ||
178 | case QPSK: | ||
179 | break; | ||
180 | case QAM_16: | ||
181 | *reg0xc05 |= (1 << 10); | ||
182 | break; | ||
183 | case QAM_64: | ||
184 | *reg0xc05 |= (2 << 10); | ||
185 | break; | ||
186 | case QAM_AUTO: | ||
187 | known_parameters = 0; | ||
188 | break; | ||
189 | default: | ||
190 | return -EINVAL; | ||
191 | }; | ||
192 | |||
193 | switch (p->u.ofdm.hierarchy_information) { | ||
194 | case HIERARCHY_NONE: | ||
195 | break; | ||
196 | case HIERARCHY_1: | ||
197 | *reg0xc05 |= (1 << 7); | ||
198 | break; | ||
199 | case HIERARCHY_2: | ||
200 | *reg0xc05 |= (2 << 7); | ||
201 | break; | ||
202 | case HIERARCHY_4: | ||
203 | *reg0xc05 |= (3 << 7); | ||
204 | break; | ||
205 | case HIERARCHY_AUTO: | ||
206 | known_parameters = 0; | ||
207 | break; | ||
208 | default: | ||
209 | return -EINVAL; | ||
210 | }; | ||
211 | |||
212 | switch (p->u.ofdm.code_rate_HP) { | ||
213 | case FEC_1_2: | ||
214 | break; | ||
215 | case FEC_2_3: | ||
216 | *reg0xc05 |= (1 << 3); | ||
217 | break; | ||
218 | case FEC_3_4: | ||
219 | *reg0xc05 |= (2 << 3); | ||
220 | break; | ||
221 | case FEC_5_6: | ||
222 | *reg0xc05 |= (3 << 3); | ||
223 | break; | ||
224 | case FEC_7_8: | ||
225 | *reg0xc05 |= (4 << 3); | ||
226 | break; | ||
227 | case FEC_AUTO: | ||
228 | known_parameters = 0; | ||
229 | break; | ||
230 | default: | ||
231 | return -EINVAL; | ||
232 | }; | ||
233 | |||
234 | if (known_parameters) | ||
235 | *reg0xc05 |= (2 << 1); /* use specified parameters */ | ||
236 | else | ||
237 | *reg0xc05 |= (1 << 1); /* enable autoprobing */ | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | static int sp8870_wake_up(struct sp8870_state* state) | ||
243 | { | ||
244 | // enable TS output and interface pins | ||
245 | return sp8870_writereg(state, 0xC18, 0x00D); | ||
246 | } | ||
247 | |||
248 | static int sp8870_set_frontend_parameters (struct dvb_frontend* fe, | ||
249 | struct dvb_frontend_parameters *p) | ||
250 | { | ||
251 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
252 | int err; | ||
253 | u16 reg0xc05; | ||
254 | |||
255 | if ((err = configure_reg0xc05(p, ®0xc05))) | ||
256 | return err; | ||
257 | |||
258 | // system controller stop | ||
259 | sp8870_microcontroller_stop(state); | ||
260 | |||
261 | // set tuner parameters | ||
262 | sp8870_writereg(state, 0x206, 0x001); | ||
263 | state->config->pll_set(fe, p); | ||
264 | sp8870_writereg(state, 0x206, 0x000); | ||
265 | |||
266 | // sample rate correction bit [23..17] | ||
267 | sp8870_writereg(state, 0x0319, 0x000A); | ||
268 | |||
269 | // sample rate correction bit [16..0] | ||
270 | sp8870_writereg(state, 0x031A, 0x0AAB); | ||
271 | |||
272 | // integer carrier offset | ||
273 | sp8870_writereg(state, 0x0309, 0x0400); | ||
274 | |||
275 | // fractional carrier offset | ||
276 | sp8870_writereg(state, 0x030A, 0x0000); | ||
277 | |||
278 | // filter for 6/7/8 Mhz channel | ||
279 | if (p->u.ofdm.bandwidth == BANDWIDTH_6_MHZ) | ||
280 | sp8870_writereg(state, 0x0311, 0x0002); | ||
281 | else if (p->u.ofdm.bandwidth == BANDWIDTH_7_MHZ) | ||
282 | sp8870_writereg(state, 0x0311, 0x0001); | ||
283 | else | ||
284 | sp8870_writereg(state, 0x0311, 0x0000); | ||
285 | |||
286 | // scan order: 2k first = 0x0000, 8k first = 0x0001 | ||
287 | if (p->u.ofdm.transmission_mode == TRANSMISSION_MODE_2K) | ||
288 | sp8870_writereg(state, 0x0338, 0x0000); | ||
289 | else | ||
290 | sp8870_writereg(state, 0x0338, 0x0001); | ||
291 | |||
292 | sp8870_writereg(state, 0xc05, reg0xc05); | ||
293 | |||
294 | // read status reg in order to clear pending irqs | ||
295 | sp8870_readreg(state, 0x200); | ||
296 | |||
297 | // system controller start | ||
298 | sp8870_microcontroller_start(state); | ||
299 | |||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static int sp8870_init (struct dvb_frontend* fe) | ||
304 | { | ||
305 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
306 | const struct firmware *fw = NULL; | ||
307 | |||
308 | sp8870_wake_up(state); | ||
309 | if (state->initialised) return 0; | ||
310 | state->initialised = 1; | ||
311 | |||
312 | dprintk ("%s\n", __FUNCTION__); | ||
313 | |||
314 | |||
315 | /* request the firmware, this will block until someone uploads it */ | ||
316 | printk("sp8870: waiting for firmware upload (%s)...\n", SP8870_DEFAULT_FIRMWARE); | ||
317 | if (state->config->request_firmware(fe, &fw, SP8870_DEFAULT_FIRMWARE)) { | ||
318 | printk("sp8870: no firmware upload (timeout or file not found?)\n"); | ||
319 | release_firmware(fw); | ||
320 | return -EIO; | ||
321 | } | ||
322 | |||
323 | if (sp8870_firmware_upload(state, fw)) { | ||
324 | printk("sp8870: writing firmware to device failed\n"); | ||
325 | release_firmware(fw); | ||
326 | return -EIO; | ||
327 | } | ||
328 | printk("sp8870: firmware upload complete\n"); | ||
329 | |||
330 | /* enable TS output and interface pins */ | ||
331 | sp8870_writereg(state, 0xc18, 0x00d); | ||
332 | |||
333 | // system controller stop | ||
334 | sp8870_microcontroller_stop(state); | ||
335 | |||
336 | // ADC mode | ||
337 | sp8870_writereg(state, 0x0301, 0x0003); | ||
338 | |||
339 | // Reed Solomon parity bytes passed to output | ||
340 | sp8870_writereg(state, 0x0C13, 0x0001); | ||
341 | |||
342 | // MPEG clock is suppressed if no valid data | ||
343 | sp8870_writereg(state, 0x0C14, 0x0001); | ||
344 | |||
345 | /* bit 0x010: enable data valid signal */ | ||
346 | sp8870_writereg(state, 0x0D00, 0x010); | ||
347 | sp8870_writereg(state, 0x0D01, 0x000); | ||
348 | |||
349 | /* setup PLL */ | ||
350 | if (state->config->pll_init) { | ||
351 | sp8870_writereg(state, 0x206, 0x001); | ||
352 | state->config->pll_init(fe); | ||
353 | sp8870_writereg(state, 0x206, 0x000); | ||
354 | } | ||
355 | |||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | static int sp8870_read_status (struct dvb_frontend* fe, fe_status_t * fe_status) | ||
360 | { | ||
361 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
362 | int status; | ||
363 | int signal; | ||
364 | |||
365 | *fe_status = 0; | ||
366 | |||
367 | status = sp8870_readreg (state, 0x0200); | ||
368 | if (status < 0) | ||
369 | return -EIO; | ||
370 | |||
371 | signal = sp8870_readreg (state, 0x0303); | ||
372 | if (signal < 0) | ||
373 | return -EIO; | ||
374 | |||
375 | if (signal > 0x0F) | ||
376 | *fe_status |= FE_HAS_SIGNAL; | ||
377 | if (status & 0x08) | ||
378 | *fe_status |= FE_HAS_SYNC; | ||
379 | if (status & 0x04) | ||
380 | *fe_status |= FE_HAS_LOCK | FE_HAS_CARRIER | FE_HAS_VITERBI; | ||
381 | |||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | static int sp8870_read_ber (struct dvb_frontend* fe, u32 * ber) | ||
386 | { | ||
387 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
388 | int ret; | ||
389 | u32 tmp; | ||
390 | |||
391 | *ber = 0; | ||
392 | |||
393 | ret = sp8870_readreg(state, 0xC08); | ||
394 | if (ret < 0) | ||
395 | return -EIO; | ||
396 | |||
397 | tmp = ret & 0x3F; | ||
398 | |||
399 | ret = sp8870_readreg(state, 0xC07); | ||
400 | if (ret < 0) | ||
401 | return -EIO; | ||
402 | |||
403 | tmp = ret << 6; | ||
404 | |||
405 | if (tmp >= 0x3FFF0) | ||
406 | tmp = ~0; | ||
407 | |||
408 | *ber = tmp; | ||
409 | |||
410 | return 0; | ||
411 | } | ||
412 | |||
413 | static int sp8870_read_signal_strength(struct dvb_frontend* fe, u16 * signal) | ||
414 | { | ||
415 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
416 | int ret; | ||
417 | u16 tmp; | ||
418 | |||
419 | *signal = 0; | ||
420 | |||
421 | ret = sp8870_readreg (state, 0x306); | ||
422 | if (ret < 0) | ||
423 | return -EIO; | ||
424 | |||
425 | tmp = ret << 8; | ||
426 | |||
427 | ret = sp8870_readreg (state, 0x303); | ||
428 | if (ret < 0) | ||
429 | return -EIO; | ||
430 | |||
431 | tmp |= ret; | ||
432 | |||
433 | if (tmp) | ||
434 | *signal = 0xFFFF - tmp; | ||
435 | |||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | static int sp8870_read_uncorrected_blocks (struct dvb_frontend* fe, u32* ublocks) | ||
440 | { | ||
441 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
442 | int ret; | ||
443 | |||
444 | *ublocks = 0; | ||
445 | |||
446 | ret = sp8870_readreg(state, 0xC0C); | ||
447 | if (ret < 0) | ||
448 | return -EIO; | ||
449 | |||
450 | if (ret == 0xFFFF) | ||
451 | ret = ~0; | ||
452 | |||
453 | *ublocks = ret; | ||
454 | |||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | // number of trials to recover from lockup | ||
459 | #define MAXTRIALS 5 | ||
460 | // maximum checks for data valid signal | ||
461 | #define MAXCHECKS 100 | ||
462 | |||
463 | // only for debugging: counter for detected lockups | ||
464 | static int lockups = 0; | ||
465 | // only for debugging: counter for channel switches | ||
466 | static int switches = 0; | ||
467 | |||
468 | static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_parameters *p) | ||
469 | { | ||
470 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
471 | |||
472 | /* | ||
473 | The firmware of the sp8870 sometimes locks up after setting frontend parameters. | ||
474 | We try to detect this by checking the data valid signal. | ||
475 | If it is not set after MAXCHECKS we try to recover the lockup by setting | ||
476 | the frontend parameters again. | ||
477 | */ | ||
478 | |||
479 | int err = 0; | ||
480 | int valid = 0; | ||
481 | int trials = 0; | ||
482 | int check_count = 0; | ||
483 | |||
484 | dprintk("%s: frequency = %i\n", __FUNCTION__, p->frequency); | ||
485 | |||
486 | for (trials = 1; trials <= MAXTRIALS; trials++) { | ||
487 | |||
488 | if ((err = sp8870_set_frontend_parameters(fe, p))) | ||
489 | return err; | ||
490 | |||
491 | for (check_count = 0; check_count < MAXCHECKS; check_count++) { | ||
492 | // valid = ((sp8870_readreg(i2c, 0x0200) & 4) == 0); | ||
493 | valid = sp8870_read_data_valid_signal(state); | ||
494 | if (valid) { | ||
495 | dprintk("%s: delay = %i usec\n", | ||
496 | __FUNCTION__, check_count * 10); | ||
497 | break; | ||
498 | } | ||
499 | udelay(10); | ||
500 | } | ||
501 | if (valid) | ||
502 | break; | ||
503 | } | ||
504 | |||
505 | if (!valid) { | ||
506 | printk("%s: firmware crash!!!!!!\n", __FUNCTION__); | ||
507 | return -EIO; | ||
508 | } | ||
509 | |||
510 | if (debug) { | ||
511 | if (valid) { | ||
512 | if (trials > 1) { | ||
513 | printk("%s: firmware lockup!!!\n", __FUNCTION__); | ||
514 | printk("%s: recovered after %i trial(s))\n", __FUNCTION__, trials - 1); | ||
515 | lockups++; | ||
516 | } | ||
517 | } | ||
518 | switches++; | ||
519 | printk("%s: switches = %i lockups = %i\n", __FUNCTION__, switches, lockups); | ||
520 | } | ||
521 | |||
522 | return 0; | ||
523 | } | ||
524 | |||
525 | static int sp8870_sleep(struct dvb_frontend* fe) | ||
526 | { | ||
527 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
528 | |||
529 | // tristate TS output and disable interface pins | ||
530 | return sp8870_writereg(state, 0xC18, 0x000); | ||
531 | } | ||
532 | |||
533 | static int sp8870_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) | ||
534 | { | ||
535 | fesettings->min_delay_ms = 350; | ||
536 | fesettings->step_size = 0; | ||
537 | fesettings->max_drift = 0; | ||
538 | return 0; | ||
539 | } | ||
540 | |||
541 | static void sp8870_release(struct dvb_frontend* fe) | ||
542 | { | ||
543 | struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; | ||
544 | kfree(state); | ||
545 | } | ||
546 | |||
547 | static struct dvb_frontend_ops sp8870_ops; | ||
548 | |||
549 | struct dvb_frontend* sp8870_attach(const struct sp8870_config* config, | ||
550 | struct i2c_adapter* i2c) | ||
551 | { | ||
552 | struct sp8870_state* state = NULL; | ||
553 | |||
554 | /* allocate memory for the internal state */ | ||
555 | state = (struct sp8870_state*) kmalloc(sizeof(struct sp8870_state), GFP_KERNEL); | ||
556 | if (state == NULL) goto error; | ||
557 | |||
558 | /* setup the state */ | ||
559 | state->config = config; | ||
560 | state->i2c = i2c; | ||
561 | memcpy(&state->ops, &sp8870_ops, sizeof(struct dvb_frontend_ops)); | ||
562 | state->initialised = 0; | ||
563 | |||
564 | /* check if the demod is there */ | ||
565 | if (sp8870_readreg(state, 0x0200) < 0) goto error; | ||
566 | |||
567 | /* create dvb_frontend */ | ||
568 | state->frontend.ops = &state->ops; | ||
569 | state->frontend.demodulator_priv = state; | ||
570 | return &state->frontend; | ||
571 | |||
572 | error: | ||
573 | kfree(state); | ||
574 | return NULL; | ||
575 | } | ||
576 | |||
577 | static struct dvb_frontend_ops sp8870_ops = { | ||
578 | |||
579 | .info = { | ||
580 | .name = "Spase SP8870 DVB-T", | ||
581 | .type = FE_OFDM, | ||
582 | .frequency_min = 470000000, | ||
583 | .frequency_max = 860000000, | ||
584 | .frequency_stepsize = 166666, | ||
585 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | | ||
586 | FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | | ||
587 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | | ||
588 | FE_CAN_QPSK | FE_CAN_QAM_16 | | ||
589 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | | ||
590 | FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | ||
591 | }, | ||
592 | |||
593 | .release = sp8870_release, | ||
594 | |||
595 | .init = sp8870_init, | ||
596 | .sleep = sp8870_sleep, | ||
597 | |||
598 | .set_frontend = sp8870_set_frontend, | ||
599 | .get_tune_settings = sp8870_get_tune_settings, | ||
600 | |||
601 | .read_status = sp8870_read_status, | ||
602 | .read_ber = sp8870_read_ber, | ||
603 | .read_signal_strength = sp8870_read_signal_strength, | ||
604 | .read_ucblocks = sp8870_read_uncorrected_blocks, | ||
605 | }; | ||
606 | |||
607 | module_param(debug, int, 0644); | ||
608 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); | ||
609 | |||
610 | MODULE_DESCRIPTION("Spase SP8870 DVB-T Demodulator driver"); | ||
611 | MODULE_AUTHOR("Juergen Peitz"); | ||
612 | MODULE_LICENSE("GPL"); | ||
613 | |||
614 | EXPORT_SYMBOL(sp8870_attach); | ||