Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / media / dvb / frontends / tda10086.c
blobdfa617b5b469e42278f39b4e88c0d59fe8361c57
1 /*
2 Driver for Philips tda10086 DVBS Demodulator
4 (c) 2006 Andrew de Quincey
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
15 GNU General Public License for more details.
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.
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/device.h>
26 #include <linux/jiffies.h>
27 #include <linux/string.h>
28 #include <linux/slab.h>
30 #include "dvb_frontend.h"
31 #include "tda10086.h"
33 #define SACLK 96000000
35 struct tda10086_state {
36 struct i2c_adapter* i2c;
37 const struct tda10086_config* config;
38 struct dvb_frontend frontend;
40 /* private demod data */
41 u32 frequency;
42 u32 symbol_rate;
43 bool has_lock;
46 static int debug = 0;
47 #define dprintk(args...) \
48 do { \
49 if (debug) printk(KERN_DEBUG "tda10086: " args); \
50 } while (0)
52 static int tda10086_write_byte(struct tda10086_state *state, int reg, int data)
54 int ret;
55 u8 b0[] = { reg, data };
56 struct i2c_msg msg = { .flags = 0, .buf = b0, .len = 2 };
58 msg.addr = state->config->demod_address;
59 ret = i2c_transfer(state->i2c, &msg, 1);
61 if (ret != 1)
62 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
63 __FUNCTION__, reg, data, ret);
65 return (ret != 1) ? ret : 0;
68 static int tda10086_read_byte(struct tda10086_state *state, int reg)
70 int ret;
71 u8 b0[] = { reg };
72 u8 b1[] = { 0 };
73 struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
74 { .flags = I2C_M_RD, .buf = b1, .len = 1 }};
76 msg[0].addr = state->config->demod_address;
77 msg[1].addr = state->config->demod_address;
78 ret = i2c_transfer(state->i2c, msg, 2);
80 if (ret != 2) {
81 dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__, reg,
82 ret);
83 return ret;
86 return b1[0];
89 static int tda10086_write_mask(struct tda10086_state *state, int reg, int mask, int data)
91 int val;
93 // read a byte and check
94 val = tda10086_read_byte(state, reg);
95 if (val < 0)
96 return val;
98 // mask if off
99 val = val & ~mask;
100 val |= data & 0xff;
102 // write it out again
103 return tda10086_write_byte(state, reg, val);
106 static int tda10086_init(struct dvb_frontend* fe)
108 struct tda10086_state* state = fe->demodulator_priv;
109 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
110 =======
111 u8 t22k_off = 0x80;
112 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
114 dprintk ("%s\n", __FUNCTION__);
116 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
117 =======
118 if (state->config->diseqc_tone)
119 t22k_off = 0;
120 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
121 // reset
122 tda10086_write_byte(state, 0x00, 0x00);
123 msleep(10);
125 // misc setup
126 tda10086_write_byte(state, 0x01, 0x94);
127 tda10086_write_byte(state, 0x02, 0x35); // NOTE: TT drivers appear to disable CSWP
128 tda10086_write_byte(state, 0x03, 0xe4);
129 tda10086_write_byte(state, 0x04, 0x43);
130 tda10086_write_byte(state, 0x0c, 0x0c);
131 tda10086_write_byte(state, 0x1b, 0xb0); // noise threshold
132 tda10086_write_byte(state, 0x20, 0x89); // misc
133 tda10086_write_byte(state, 0x30, 0x04); // acquisition period length
134 tda10086_write_byte(state, 0x32, 0x00); // irq off
135 tda10086_write_byte(state, 0x31, 0x56); // setup AFC
137 // setup PLL (assumes 16Mhz XIN)
138 tda10086_write_byte(state, 0x55, 0x2c); // misc PLL setup
139 tda10086_write_byte(state, 0x3a, 0x0b); // M=12
140 tda10086_write_byte(state, 0x3b, 0x01); // P=2
141 tda10086_write_mask(state, 0x55, 0x20, 0x00); // powerup PLL
143 // setup TS interface
144 tda10086_write_byte(state, 0x11, 0x81);
145 tda10086_write_byte(state, 0x12, 0x81);
146 tda10086_write_byte(state, 0x19, 0x40); // parallel mode A + MSBFIRST
147 tda10086_write_byte(state, 0x56, 0x80); // powerdown WPLL - unused in the mode we use
148 tda10086_write_byte(state, 0x57, 0x08); // bypass WPLL - unused in the mode we use
149 tda10086_write_byte(state, 0x10, 0x2a);
151 // setup ADC
152 tda10086_write_byte(state, 0x58, 0x61); // ADC setup
153 tda10086_write_mask(state, 0x58, 0x01, 0x00); // powerup ADC
155 // setup AGC
156 tda10086_write_byte(state, 0x05, 0x0B);
157 tda10086_write_byte(state, 0x37, 0x63);
158 tda10086_write_byte(state, 0x3f, 0x0a); // NOTE: flydvb varies it
159 tda10086_write_byte(state, 0x40, 0x64);
160 tda10086_write_byte(state, 0x41, 0x4f);
161 tda10086_write_byte(state, 0x42, 0x43);
163 // setup viterbi
164 tda10086_write_byte(state, 0x1a, 0x11); // VBER 10^6, DVB, QPSK
166 // setup carrier recovery
167 tda10086_write_byte(state, 0x3d, 0x80);
169 // setup SEC
170 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
171 tda10086_write_byte(state, 0x36, 0x80); // all SEC off, no 22k tone
172 =======
173 tda10086_write_byte(state, 0x36, t22k_off); // all SEC off, 22k tone
174 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
175 tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000))); // } tone frequency
176 tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8); // }
178 return 0;
181 static void tda10086_diseqc_wait(struct tda10086_state *state)
183 unsigned long timeout = jiffies + msecs_to_jiffies(200);
184 while (!(tda10086_read_byte(state, 0x50) & 0x01)) {
185 if(time_after(jiffies, timeout)) {
186 printk("%s: diseqc queue not ready, command may be lost.\n", __FUNCTION__);
187 break;
189 msleep(10);
193 static int tda10086_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
195 struct tda10086_state* state = fe->demodulator_priv;
196 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
197 =======
198 u8 t22k_off = 0x80;
199 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
201 dprintk ("%s\n", __FUNCTION__);
203 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
204 =======
205 if (state->config->diseqc_tone)
206 t22k_off = 0;
208 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
209 switch (tone) {
210 case SEC_TONE_OFF:
211 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
212 tda10086_write_byte(state, 0x36, 0x80);
213 =======
214 tda10086_write_byte(state, 0x36, t22k_off);
215 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
216 break;
218 case SEC_TONE_ON:
219 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
220 tda10086_write_byte(state, 0x36, 0x81);
221 =======
222 tda10086_write_byte(state, 0x36, 0x01 + t22k_off);
223 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
224 break;
227 return 0;
230 static int tda10086_send_master_cmd (struct dvb_frontend* fe,
231 struct dvb_diseqc_master_cmd* cmd)
233 struct tda10086_state* state = fe->demodulator_priv;
234 int i;
235 u8 oldval;
236 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
237 =======
238 u8 t22k_off = 0x80;
239 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
241 dprintk ("%s\n", __FUNCTION__);
243 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
244 =======
245 if (state->config->diseqc_tone)
246 t22k_off = 0;
248 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
249 if (cmd->msg_len > 6)
250 return -EINVAL;
251 oldval = tda10086_read_byte(state, 0x36);
253 for(i=0; i< cmd->msg_len; i++) {
254 tda10086_write_byte(state, 0x48+i, cmd->msg[i]);
256 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
257 tda10086_write_byte(state, 0x36, 0x88 | ((cmd->msg_len - 1) << 4));
258 =======
259 tda10086_write_byte(state, 0x36, (0x08 + t22k_off)
260 | ((cmd->msg_len - 1) << 4));
261 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
263 tda10086_diseqc_wait(state);
265 tda10086_write_byte(state, 0x36, oldval);
267 return 0;
270 static int tda10086_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
272 struct tda10086_state* state = fe->demodulator_priv;
273 u8 oldval = tda10086_read_byte(state, 0x36);
274 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
275 =======
276 u8 t22k_off = 0x80;
277 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
279 dprintk ("%s\n", __FUNCTION__);
281 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
282 =======
283 if (state->config->diseqc_tone)
284 t22k_off = 0;
286 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
287 switch(minicmd) {
288 case SEC_MINI_A:
289 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
290 tda10086_write_byte(state, 0x36, 0x84);
291 =======
292 tda10086_write_byte(state, 0x36, 0x04 + t22k_off);
293 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
294 break;
296 case SEC_MINI_B:
297 <<<<<<< HEAD:drivers/media/dvb/frontends/tda10086.c
298 tda10086_write_byte(state, 0x36, 0x86);
299 =======
300 tda10086_write_byte(state, 0x36, 0x06 + t22k_off);
301 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/dvb/frontends/tda10086.c
302 break;
305 tda10086_diseqc_wait(state);
307 tda10086_write_byte(state, 0x36, oldval);
309 return 0;
312 static int tda10086_set_inversion(struct tda10086_state *state,
313 struct dvb_frontend_parameters *fe_params)
315 u8 invval = 0x80;
317 dprintk ("%s %i %i\n", __FUNCTION__, fe_params->inversion, state->config->invert);
319 switch(fe_params->inversion) {
320 case INVERSION_OFF:
321 if (state->config->invert)
322 invval = 0x40;
323 break;
324 case INVERSION_ON:
325 if (!state->config->invert)
326 invval = 0x40;
327 break;
328 case INVERSION_AUTO:
329 invval = 0x00;
330 break;
332 tda10086_write_mask(state, 0x0c, 0xc0, invval);
334 return 0;
337 static int tda10086_set_symbol_rate(struct tda10086_state *state,
338 struct dvb_frontend_parameters *fe_params)
340 u8 dfn = 0;
341 u8 afs = 0;
342 u8 byp = 0;
343 u8 reg37 = 0x43;
344 u8 reg42 = 0x43;
345 u64 big;
346 u32 tmp;
347 u32 bdr;
348 u32 bdri;
349 u32 symbol_rate = fe_params->u.qpsk.symbol_rate;
351 dprintk ("%s %i\n", __FUNCTION__, symbol_rate);
353 // setup the decimation and anti-aliasing filters..
354 if (symbol_rate < (u32) (SACLK * 0.0137)) {
355 dfn=4;
356 afs=1;
357 } else if (symbol_rate < (u32) (SACLK * 0.0208)) {
358 dfn=4;
359 afs=0;
360 } else if (symbol_rate < (u32) (SACLK * 0.0270)) {
361 dfn=3;
362 afs=1;
363 } else if (symbol_rate < (u32) (SACLK * 0.0416)) {
364 dfn=3;
365 afs=0;
366 } else if (symbol_rate < (u32) (SACLK * 0.0550)) {
367 dfn=2;
368 afs=1;
369 } else if (symbol_rate < (u32) (SACLK * 0.0833)) {
370 dfn=2;
371 afs=0;
372 } else if (symbol_rate < (u32) (SACLK * 0.1100)) {
373 dfn=1;
374 afs=1;
375 } else if (symbol_rate < (u32) (SACLK * 0.1666)) {
376 dfn=1;
377 afs=0;
378 } else if (symbol_rate < (u32) (SACLK * 0.2200)) {
379 dfn=0;
380 afs=1;
381 } else if (symbol_rate < (u32) (SACLK * 0.3333)) {
382 dfn=0;
383 afs=0;
384 } else {
385 reg37 = 0x63;
386 reg42 = 0x4f;
387 byp=1;
390 // calculate BDR
391 big = (1ULL<<21) * ((u64) symbol_rate/1000ULL) * (1ULL<<dfn);
392 big += ((SACLK/1000ULL)-1ULL);
393 do_div(big, (SACLK/1000ULL));
394 bdr = big & 0xfffff;
396 // calculate BDRI
397 tmp = (1<<dfn)*(symbol_rate/1000);
398 bdri = ((32 * (SACLK/1000)) + (tmp-1)) / tmp;
400 tda10086_write_byte(state, 0x21, (afs << 7) | dfn);
401 tda10086_write_mask(state, 0x20, 0x08, byp << 3);
402 tda10086_write_byte(state, 0x06, bdr);
403 tda10086_write_byte(state, 0x07, bdr >> 8);
404 tda10086_write_byte(state, 0x08, bdr >> 16);
405 tda10086_write_byte(state, 0x09, bdri);
406 tda10086_write_byte(state, 0x37, reg37);
407 tda10086_write_byte(state, 0x42, reg42);
409 return 0;
412 static int tda10086_set_fec(struct tda10086_state *state,
413 struct dvb_frontend_parameters *fe_params)
415 u8 fecval;
417 dprintk ("%s %i\n", __FUNCTION__, fe_params->u.qpsk.fec_inner);
419 switch(fe_params->u.qpsk.fec_inner) {
420 case FEC_1_2:
421 fecval = 0x00;
422 break;
423 case FEC_2_3:
424 fecval = 0x01;
425 break;
426 case FEC_3_4:
427 fecval = 0x02;
428 break;
429 case FEC_4_5:
430 fecval = 0x03;
431 break;
432 case FEC_5_6:
433 fecval = 0x04;
434 break;
435 case FEC_6_7:
436 fecval = 0x05;
437 break;
438 case FEC_7_8:
439 fecval = 0x06;
440 break;
441 case FEC_8_9:
442 fecval = 0x07;
443 break;
444 case FEC_AUTO:
445 fecval = 0x08;
446 break;
447 default:
448 return -1;
450 tda10086_write_byte(state, 0x0d, fecval);
452 return 0;
455 static int tda10086_set_frontend(struct dvb_frontend* fe,
456 struct dvb_frontend_parameters *fe_params)
458 struct tda10086_state *state = fe->demodulator_priv;
459 int ret;
460 u32 freq = 0;
461 int freqoff;
463 dprintk ("%s\n", __FUNCTION__);
465 // modify parameters for tuning
466 tda10086_write_byte(state, 0x02, 0x35);
467 state->has_lock = false;
469 // set params
470 if (fe->ops.tuner_ops.set_params) {
471 fe->ops.tuner_ops.set_params(fe, fe_params);
472 if (fe->ops.i2c_gate_ctrl)
473 fe->ops.i2c_gate_ctrl(fe, 0);
475 if (fe->ops.tuner_ops.get_frequency)
476 fe->ops.tuner_ops.get_frequency(fe, &freq);
477 if (fe->ops.i2c_gate_ctrl)
478 fe->ops.i2c_gate_ctrl(fe, 0);
481 // calcluate the frequency offset (in *Hz* not kHz)
482 freqoff = fe_params->frequency - freq;
483 freqoff = ((1<<16) * freqoff) / (SACLK/1000);
484 tda10086_write_byte(state, 0x3d, 0x80 | ((freqoff >> 8) & 0x7f));
485 tda10086_write_byte(state, 0x3e, freqoff);
487 if ((ret = tda10086_set_inversion(state, fe_params)) < 0)
488 return ret;
489 if ((ret = tda10086_set_symbol_rate(state, fe_params)) < 0)
490 return ret;
491 if ((ret = tda10086_set_fec(state, fe_params)) < 0)
492 return ret;
494 // soft reset + disable TS output until lock
495 tda10086_write_mask(state, 0x10, 0x40, 0x40);
496 tda10086_write_mask(state, 0x00, 0x01, 0x00);
498 state->symbol_rate = fe_params->u.qpsk.symbol_rate;
499 state->frequency = fe_params->frequency;
500 return 0;
503 static int tda10086_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *fe_params)
505 struct tda10086_state* state = fe->demodulator_priv;
506 u8 val;
507 int tmp;
508 u64 tmp64;
510 dprintk ("%s\n", __FUNCTION__);
512 // check for invalid symbol rate
513 if (fe_params->u.qpsk.symbol_rate < 500000)
514 return -EINVAL;
516 // calculate the updated frequency (note: we convert from Hz->kHz)
517 tmp64 = tda10086_read_byte(state, 0x52);
518 tmp64 |= (tda10086_read_byte(state, 0x51) << 8);
519 if (tmp64 & 0x8000)
520 tmp64 |= 0xffffffffffff0000ULL;
521 tmp64 = (tmp64 * (SACLK/1000ULL));
522 do_div(tmp64, (1ULL<<15) * (1ULL<<1));
523 fe_params->frequency = (int) state->frequency + (int) tmp64;
525 // the inversion
526 val = tda10086_read_byte(state, 0x0c);
527 if (val & 0x80) {
528 switch(val & 0x40) {
529 case 0x00:
530 fe_params->inversion = INVERSION_OFF;
531 if (state->config->invert)
532 fe_params->inversion = INVERSION_ON;
533 break;
534 default:
535 fe_params->inversion = INVERSION_ON;
536 if (state->config->invert)
537 fe_params->inversion = INVERSION_OFF;
538 break;
540 } else {
541 tda10086_read_byte(state, 0x0f);
542 switch(val & 0x02) {
543 case 0x00:
544 fe_params->inversion = INVERSION_OFF;
545 if (state->config->invert)
546 fe_params->inversion = INVERSION_ON;
547 break;
548 default:
549 fe_params->inversion = INVERSION_ON;
550 if (state->config->invert)
551 fe_params->inversion = INVERSION_OFF;
552 break;
556 // calculate the updated symbol rate
557 tmp = tda10086_read_byte(state, 0x1d);
558 if (tmp & 0x80)
559 tmp |= 0xffffff00;
560 tmp = (tmp * 480 * (1<<1)) / 128;
561 tmp = ((state->symbol_rate/1000) * tmp) / (1000000/1000);
562 fe_params->u.qpsk.symbol_rate = state->symbol_rate + tmp;
564 // the FEC
565 val = (tda10086_read_byte(state, 0x0d) & 0x70) >> 4;
566 switch(val) {
567 case 0x00:
568 fe_params->u.qpsk.fec_inner = FEC_1_2;
569 break;
570 case 0x01:
571 fe_params->u.qpsk.fec_inner = FEC_2_3;
572 break;
573 case 0x02:
574 fe_params->u.qpsk.fec_inner = FEC_3_4;
575 break;
576 case 0x03:
577 fe_params->u.qpsk.fec_inner = FEC_4_5;
578 break;
579 case 0x04:
580 fe_params->u.qpsk.fec_inner = FEC_5_6;
581 break;
582 case 0x05:
583 fe_params->u.qpsk.fec_inner = FEC_6_7;
584 break;
585 case 0x06:
586 fe_params->u.qpsk.fec_inner = FEC_7_8;
587 break;
588 case 0x07:
589 fe_params->u.qpsk.fec_inner = FEC_8_9;
590 break;
593 return 0;
596 static int tda10086_read_status(struct dvb_frontend* fe, fe_status_t *fe_status)
598 struct tda10086_state* state = fe->demodulator_priv;
599 u8 val;
601 dprintk ("%s\n", __FUNCTION__);
603 val = tda10086_read_byte(state, 0x0e);
604 *fe_status = 0;
605 if (val & 0x01)
606 *fe_status |= FE_HAS_SIGNAL;
607 if (val & 0x02)
608 *fe_status |= FE_HAS_CARRIER;
609 if (val & 0x04)
610 *fe_status |= FE_HAS_VITERBI;
611 if (val & 0x08)
612 *fe_status |= FE_HAS_SYNC;
613 if (val & 0x10) {
614 *fe_status |= FE_HAS_LOCK;
615 if (!state->has_lock) {
616 state->has_lock = true;
617 // modify parameters for stable reception
618 tda10086_write_byte(state, 0x02, 0x00);
622 return 0;
625 static int tda10086_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
627 struct tda10086_state* state = fe->demodulator_priv;
628 u8 _str;
630 dprintk ("%s\n", __FUNCTION__);
632 _str = 0xff - tda10086_read_byte(state, 0x43);
633 *signal = (_str << 8) | _str;
635 return 0;
638 static int tda10086_read_snr(struct dvb_frontend* fe, u16 * snr)
640 struct tda10086_state* state = fe->demodulator_priv;
641 u8 _snr;
643 dprintk ("%s\n", __FUNCTION__);
645 _snr = 0xff - tda10086_read_byte(state, 0x1c);
646 *snr = (_snr << 8) | _snr;
648 return 0;
651 static int tda10086_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
653 struct tda10086_state* state = fe->demodulator_priv;
655 dprintk ("%s\n", __FUNCTION__);
657 // read it
658 *ucblocks = tda10086_read_byte(state, 0x18) & 0x7f;
660 // reset counter
661 tda10086_write_byte(state, 0x18, 0x00);
662 tda10086_write_byte(state, 0x18, 0x80);
664 return 0;
667 static int tda10086_read_ber(struct dvb_frontend* fe, u32* ber)
669 struct tda10086_state* state = fe->demodulator_priv;
671 dprintk ("%s\n", __FUNCTION__);
673 // read it
674 *ber = 0;
675 *ber |= tda10086_read_byte(state, 0x15);
676 *ber |= tda10086_read_byte(state, 0x16) << 8;
677 *ber |= (tda10086_read_byte(state, 0x17) & 0xf) << 16;
679 return 0;
682 static int tda10086_sleep(struct dvb_frontend* fe)
684 struct tda10086_state* state = fe->demodulator_priv;
686 dprintk ("%s\n", __FUNCTION__);
688 tda10086_write_mask(state, 0x00, 0x08, 0x08);
690 return 0;
693 static int tda10086_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
695 struct tda10086_state* state = fe->demodulator_priv;
697 dprintk ("%s\n", __FUNCTION__);
699 if (enable) {
700 tda10086_write_mask(state, 0x00, 0x10, 0x10);
701 } else {
702 tda10086_write_mask(state, 0x00, 0x10, 0x00);
705 return 0;
708 static int tda10086_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
710 if (fesettings->parameters.u.qpsk.symbol_rate > 20000000) {
711 fesettings->min_delay_ms = 50;
712 fesettings->step_size = 2000;
713 fesettings->max_drift = 8000;
714 } else if (fesettings->parameters.u.qpsk.symbol_rate > 12000000) {
715 fesettings->min_delay_ms = 100;
716 fesettings->step_size = 1500;
717 fesettings->max_drift = 9000;
718 } else if (fesettings->parameters.u.qpsk.symbol_rate > 8000000) {
719 fesettings->min_delay_ms = 100;
720 fesettings->step_size = 1000;
721 fesettings->max_drift = 8000;
722 } else if (fesettings->parameters.u.qpsk.symbol_rate > 4000000) {
723 fesettings->min_delay_ms = 100;
724 fesettings->step_size = 500;
725 fesettings->max_drift = 7000;
726 } else if (fesettings->parameters.u.qpsk.symbol_rate > 2000000) {
727 fesettings->min_delay_ms = 200;
728 fesettings->step_size = (fesettings->parameters.u.qpsk.symbol_rate / 8000);
729 fesettings->max_drift = 14 * fesettings->step_size;
730 } else {
731 fesettings->min_delay_ms = 200;
732 fesettings->step_size = (fesettings->parameters.u.qpsk.symbol_rate / 8000);
733 fesettings->max_drift = 18 * fesettings->step_size;
736 return 0;
739 static void tda10086_release(struct dvb_frontend* fe)
741 struct tda10086_state *state = fe->demodulator_priv;
742 tda10086_sleep(fe);
743 kfree(state);
746 static struct dvb_frontend_ops tda10086_ops = {
748 .info = {
749 .name = "Philips TDA10086 DVB-S",
750 .type = FE_QPSK,
751 .frequency_min = 950000,
752 .frequency_max = 2150000,
753 .frequency_stepsize = 125, /* kHz for QPSK frontends */
754 .symbol_rate_min = 1000000,
755 .symbol_rate_max = 45000000,
756 .caps = FE_CAN_INVERSION_AUTO |
757 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
758 FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
759 FE_CAN_QPSK
762 .release = tda10086_release,
764 .init = tda10086_init,
765 .sleep = tda10086_sleep,
766 .i2c_gate_ctrl = tda10086_i2c_gate_ctrl,
768 .set_frontend = tda10086_set_frontend,
769 .get_frontend = tda10086_get_frontend,
770 .get_tune_settings = tda10086_get_tune_settings,
772 .read_status = tda10086_read_status,
773 .read_ber = tda10086_read_ber,
774 .read_signal_strength = tda10086_read_signal_strength,
775 .read_snr = tda10086_read_snr,
776 .read_ucblocks = tda10086_read_ucblocks,
778 .diseqc_send_master_cmd = tda10086_send_master_cmd,
779 .diseqc_send_burst = tda10086_send_burst,
780 .set_tone = tda10086_set_tone,
783 struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
784 struct i2c_adapter* i2c)
786 struct tda10086_state *state;
788 dprintk ("%s\n", __FUNCTION__);
790 /* allocate memory for the internal state */
791 state = kmalloc(sizeof(struct tda10086_state), GFP_KERNEL);
792 if (!state)
793 return NULL;
795 /* setup the state */
796 state->config = config;
797 state->i2c = i2c;
799 /* check if the demod is there */
800 if (tda10086_read_byte(state, 0x1e) != 0xe1) {
801 kfree(state);
802 return NULL;
805 /* create dvb_frontend */
806 memcpy(&state->frontend.ops, &tda10086_ops, sizeof(struct dvb_frontend_ops));
807 state->frontend.demodulator_priv = state;
808 return &state->frontend;
811 module_param(debug, int, 0644);
812 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
814 MODULE_DESCRIPTION("Philips TDA10086 DVB-S Demodulator");
815 MODULE_AUTHOR("Andrew de Quincey");
816 MODULE_LICENSE("GPL");
818 EXPORT_SYMBOL(tda10086_attach);