2 Fujitsu MB86A16 DVB-S/DSS DC Receiver driver
4 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
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
14 GNU General Public License for more details.
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.
21 #include <linux/init.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/slab.h>
27 #include "dvb_frontend.h"
29 #include "mb86a16_priv.h"
31 unsigned int verbose
= 5;
32 module_param(verbose
, int, 0644);
34 #define ABS(x) ((x) < 0 ? (-x) : (x))
36 struct mb86a16_state
{
37 struct i2c_adapter
*i2c_adap
;
38 const struct mb86a16_config
*config
;
39 struct dvb_frontend frontend
;
41 /* tuning parameters */
52 #define MB86A16_ERROR 0
53 #define MB86A16_NOTICE 1
54 #define MB86A16_INFO 2
55 #define MB86A16_DEBUG 3
57 #define dprintk(x, y, z, format, arg...) do { \
59 if ((x > MB86A16_ERROR) && (x > y)) \
60 printk(KERN_ERR "%s: " format "\n", __func__, ##arg); \
61 else if ((x > MB86A16_NOTICE) && (x > y)) \
62 printk(KERN_NOTICE "%s: " format "\n", __func__, ##arg); \
63 else if ((x > MB86A16_INFO) && (x > y)) \
64 printk(KERN_INFO "%s: " format "\n", __func__, ##arg); \
65 else if ((x > MB86A16_DEBUG) && (x > y)) \
66 printk(KERN_DEBUG "%s: " format "\n", __func__, ##arg); \
69 printk(format, ##arg); \
73 #define TRACE_IN dprintk(verbose, MB86A16_DEBUG, 1, "-->()")
74 #define TRACE_OUT dprintk(verbose, MB86A16_DEBUG, 1, "()-->")
76 static int mb86a16_write(struct mb86a16_state
*state
, u8 reg
, u8 val
)
79 u8 buf
[] = { reg
, val
};
81 struct i2c_msg msg
= {
82 .addr
= state
->config
->demod_address
,
88 dprintk(verbose
, MB86A16_DEBUG
, 1,
89 "writing to [0x%02x],Reg[0x%02x],Data[0x%02x]",
90 state
->config
->demod_address
, buf
[0], buf
[1]);
92 ret
= i2c_transfer(state
->i2c_adap
, &msg
, 1);
94 return (ret
!= 1) ? -EREMOTEIO
: 0;
97 static int mb86a16_read(struct mb86a16_state
*state
, u8 reg
, u8
*val
)
103 struct i2c_msg msg
[] = {
105 .addr
= state
->config
->demod_address
,
110 .addr
= state
->config
->demod_address
,
116 ret
= i2c_transfer(state
->i2c_adap
, msg
, 2);
118 dprintk(verbose
, MB86A16_ERROR
, 1, "read error(reg=0x%02x, ret=0x%i)",
128 static int CNTM_set(struct mb86a16_state
*state
,
129 unsigned char timint1
,
130 unsigned char timint2
,
135 val
= (timint1
<< 4) | (timint2
<< 2) | cnext
;
136 if (mb86a16_write(state
, MB86A16_CNTMR
, val
) < 0)
142 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
146 static int smrt_set(struct mb86a16_state
*state
, int rate
)
150 unsigned char STOFS0
, STOFS1
;
152 m
= 1 << state
->deci
;
153 tmp
= (8192 * state
->master_clk
- 2 * m
* rate
* 8192 + state
->master_clk
/ 2) / state
->master_clk
;
155 STOFS0
= tmp
& 0x0ff;
156 STOFS1
= (tmp
& 0xf00) >> 8;
158 if (mb86a16_write(state
, MB86A16_SRATE1
, (state
->deci
<< 2) |
162 if (mb86a16_write(state
, MB86A16_SRATE2
, STOFS0
) < 0)
164 if (mb86a16_write(state
, MB86A16_SRATE3
, STOFS1
) < 0)
169 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
173 static int srst(struct mb86a16_state
*state
)
175 if (mb86a16_write(state
, MB86A16_RESET
, 0x04) < 0)
180 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
185 static int afcex_data_set(struct mb86a16_state
*state
,
186 unsigned char AFCEX_L
,
187 unsigned char AFCEX_H
)
189 if (mb86a16_write(state
, MB86A16_AFCEXL
, AFCEX_L
) < 0)
191 if (mb86a16_write(state
, MB86A16_AFCEXH
, AFCEX_H
) < 0)
196 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
201 static int afcofs_data_set(struct mb86a16_state
*state
,
202 unsigned char AFCEX_L
,
203 unsigned char AFCEX_H
)
205 if (mb86a16_write(state
, 0x58, AFCEX_L
) < 0)
207 if (mb86a16_write(state
, 0x59, AFCEX_H
) < 0)
212 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
216 static int stlp_set(struct mb86a16_state
*state
,
220 if (mb86a16_write(state
, MB86A16_STRFILTCOEF1
, (STRBS
<< 3) | (STRAS
)) < 0)
225 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
229 static int Vi_set(struct mb86a16_state
*state
, unsigned char ETH
, unsigned char VIA
)
231 if (mb86a16_write(state
, MB86A16_VISET2
, 0x04) < 0)
233 if (mb86a16_write(state
, MB86A16_VISET3
, 0xf5) < 0)
238 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
242 static int initial_set(struct mb86a16_state
*state
)
244 if (stlp_set(state
, 5, 7))
248 if (afcex_data_set(state
, 0, 0))
252 if (afcofs_data_set(state
, 0, 0))
256 if (mb86a16_write(state
, MB86A16_CRLFILTCOEF1
, 0x16) < 0)
258 if (mb86a16_write(state
, 0x2f, 0x21) < 0)
260 if (mb86a16_write(state
, MB86A16_VIMAG
, 0x38) < 0)
262 if (mb86a16_write(state
, MB86A16_FAGCS1
, 0x00) < 0)
264 if (mb86a16_write(state
, MB86A16_FAGCS2
, 0x1c) < 0)
266 if (mb86a16_write(state
, MB86A16_FAGCS3
, 0x20) < 0)
268 if (mb86a16_write(state
, MB86A16_FAGCS4
, 0x1e) < 0)
270 if (mb86a16_write(state
, MB86A16_FAGCS5
, 0x23) < 0)
272 if (mb86a16_write(state
, 0x54, 0xff) < 0)
274 if (mb86a16_write(state
, MB86A16_TSOUT
, 0x00) < 0)
280 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
284 static int S01T_set(struct mb86a16_state
*state
,
288 if (mb86a16_write(state
, 0x33, (s1t
<< 3) | s0t
) < 0)
293 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
298 static int EN_set(struct mb86a16_state
*state
,
304 val
= 0x7a | (cren
<< 7) | (afcen
<< 2);
305 if (mb86a16_write(state
, 0x49, val
) < 0)
310 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
314 static int AFCEXEN_set(struct mb86a16_state
*state
,
322 else if (smrt
> 9375)
324 else if (smrt
> 2250)
329 if (mb86a16_write(state
, 0x2a, 0x02 | (afcexen
<< 5) | (AFCA
<< 2)) < 0)
335 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
339 static int DAGC_data_set(struct mb86a16_state
*state
,
343 if (mb86a16_write(state
, 0x2d, (DAGCA
<< 3) | DAGCW
) < 0)
349 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
353 static void smrt_info_get(struct mb86a16_state
*state
, int rate
)
356 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 0;
357 } else if (rate
>= 30001) {
358 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 1;
359 } else if (rate
>= 26251) {
360 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 0;
361 } else if (rate
>= 22501) {
362 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 1;
363 } else if (rate
>= 18751) {
364 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 0;
365 } else if (rate
>= 15001) {
366 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 1;
367 } else if (rate
>= 13126) {
368 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 0;
369 } else if (rate
>= 11251) {
370 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 1;
371 } else if (rate
>= 9376) {
372 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 0;
373 } else if (rate
>= 7501) {
374 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 1;
375 } else if (rate
>= 6563) {
376 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 0;
377 } else if (rate
>= 5626) {
378 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 1;
379 } else if (rate
>= 4688) {
380 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 0;
381 } else if (rate
>= 3751) {
382 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 1;
383 } else if (rate
>= 3282) {
384 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 0;
385 } else if (rate
>= 2814) {
386 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 1;
387 } else if (rate
>= 2344) {
388 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 0;
389 } else if (rate
>= 1876) {
390 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 1;
391 } else if (rate
>= 1641) {
392 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 0;
393 } else if (rate
>= 1407) {
394 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 1;
395 } else if (rate
>= 1172) {
396 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 0;
397 } else if (rate
>= 939) {
398 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 1;
399 } else if (rate
>= 821) {
400 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 0;
402 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 1;
405 if (state
->csel
== 0)
406 state
->master_clk
= 92000;
408 state
->master_clk
= 61333;
412 static int signal_det(struct mb86a16_state
*state
,
426 if (CNTM_set(state
, 2, 1, 2) < 0) {
427 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
432 if (CNTM_set(state
, 3, 1, 2) < 0) {
433 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
438 for (i
= 0; i
< 3; i
++) {
440 smrtd
= smrt
* 98 / 100;
444 smrtd
= smrt
* 102 / 100;
445 smrt_info_get(state
, smrtd
);
446 smrt_set(state
, smrtd
);
448 wait_t
= (wait_sym
+ 99 * smrtd
/ 100) / smrtd
;
451 msleep_interruptible(10);
452 if (mb86a16_read(state
, 0x37, &(S
[i
])) != 2) {
453 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
457 if ((S
[1] > S
[0] * 112 / 100) &&
458 (S
[1] > S
[2] * 112 / 100)) {
466 if (CNTM_set(state
, 0, 1, 2) < 0) {
467 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
474 static int rf_val_set(struct mb86a16_state
*state
,
479 unsigned char C
, F
, B
;
481 unsigned char rf_val
[5];
486 else if (smrt
> 18875)
488 else if (smrt
> 5500)
495 else if (smrt
> 9375)
497 else if (smrt
> 4625)
523 M
= f
* (1 << R
) / 2;
525 rf_val
[0] = 0x01 | (C
<< 3) | (F
<< 1);
526 rf_val
[1] = (R
<< 5) | ((M
& 0x1f000) >> 12);
527 rf_val
[2] = (M
& 0x00ff0) >> 4;
528 rf_val
[3] = ((M
& 0x0000f) << 4) | B
;
531 if (mb86a16_write(state
, 0x21, rf_val
[0]) < 0)
533 if (mb86a16_write(state
, 0x22, rf_val
[1]) < 0)
535 if (mb86a16_write(state
, 0x23, rf_val
[2]) < 0)
537 if (mb86a16_write(state
, 0x24, rf_val
[3]) < 0)
539 if (mb86a16_write(state
, 0x25, 0x01) < 0)
542 dprintk(verbose
, MB86A16_ERROR
, 1, "RF Setup - I2C transfer error");
549 static int afcerr_chk(struct mb86a16_state
*state
)
551 unsigned char AFCM_L
, AFCM_H
;
555 if (mb86a16_read(state
, 0x0e, &AFCM_L
) != 2)
557 if (mb86a16_read(state
, 0x0f, &AFCM_H
) != 2)
560 AFCM
= (AFCM_H
<< 8) + AFCM_L
;
566 afcerr
= afcm
* state
->master_clk
/ 8192;
571 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
575 static int dagcm_val_get(struct mb86a16_state
*state
)
578 unsigned char DAGCM_H
, DAGCM_L
;
580 if (mb86a16_read(state
, 0x45, &DAGCM_L
) != 2)
582 if (mb86a16_read(state
, 0x46, &DAGCM_H
) != 2)
585 DAGCM
= (DAGCM_H
<< 8) + DAGCM_L
;
590 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
594 static int mb86a16_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
597 struct mb86a16_state
*state
= fe
->demodulator_priv
;
601 if (mb86a16_read(state
, MB86A16_SIG1
, &stat
) != 2)
603 if (mb86a16_read(state
, MB86A16_SIG2
, &stat2
) != 2)
605 if ((stat
> 25) && (stat2
> 25))
606 *status
|= FE_HAS_SIGNAL
;
607 if ((stat
> 45) && (stat2
> 45))
608 *status
|= FE_HAS_CARRIER
;
610 if (mb86a16_read(state
, MB86A16_STATUS
, &stat
) != 2)
614 *status
|= FE_HAS_SYNC
;
616 *status
|= FE_HAS_VITERBI
;
618 if (mb86a16_read(state
, MB86A16_FRAMESYNC
, &stat
) != 2)
621 if ((stat
& 0x0f) && (*status
& FE_HAS_VITERBI
))
622 *status
|= FE_HAS_LOCK
;
627 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
631 static int sync_chk(struct mb86a16_state
*state
,
637 if (mb86a16_read(state
, 0x0d, &val
) != 2)
640 dprintk(verbose
, MB86A16_INFO
, 1, "Status = %02x,", val
);
642 *VIRM
= (val
& 0x1c) >> 2;
646 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
651 static int freqerr_chk(struct mb86a16_state
*state
,
656 unsigned char CRM
, AFCML
, AFCMH
;
657 unsigned char temp1
, temp2
, temp3
;
659 int crrerr
, afcerr
; /* kHz */
660 int frqerr
; /* MHz */
661 int afcen
, afcexen
= 0;
662 int R
, M
, fOSC
, fOSC_OFS
;
664 if (mb86a16_read(state
, 0x43, &CRM
) != 2)
672 crrerr
= smrt
* crm
/ 256;
673 if (mb86a16_read(state
, 0x49, &temp1
) != 2)
676 afcen
= (temp1
& 0x04) >> 2;
678 if (mb86a16_read(state
, 0x2a, &temp1
) != 2)
680 afcexen
= (temp1
& 0x20) >> 5;
684 if (mb86a16_read(state
, 0x0e, &AFCML
) != 2)
686 if (mb86a16_read(state
, 0x0f, &AFCMH
) != 2)
688 } else if (afcexen
== 1) {
689 if (mb86a16_read(state
, 0x2b, &AFCML
) != 2)
691 if (mb86a16_read(state
, 0x2c, &AFCMH
) != 2)
694 if ((afcen
== 1) || (afcexen
== 1)) {
695 smrt_info_get(state
, smrt
);
696 AFCM
= ((AFCMH
& 0x01) << 8) + AFCML
;
702 afcerr
= afcm
* state
->master_clk
/ 8192;
706 if (mb86a16_read(state
, 0x22, &temp1
) != 2)
708 if (mb86a16_read(state
, 0x23, &temp2
) != 2)
710 if (mb86a16_read(state
, 0x24, &temp3
) != 2)
713 R
= (temp1
& 0xe0) >> 5;
714 M
= ((temp1
& 0x1f) << 12) + (temp2
<< 4) + (temp3
>> 4);
720 fOSC_OFS
= fOSC
- fTP
;
722 if (unit
== 0) { /* MHz */
723 if (crrerr
+ afcerr
+ fOSC_OFS
* 1000 >= 0)
724 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 + 500) / 1000;
726 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 - 500) / 1000;
728 frqerr
= crrerr
+ afcerr
+ fOSC_OFS
* 1000;
733 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
737 static unsigned char vco_dev_get(struct mb86a16_state
*state
, int smrt
)
749 static void swp_info_get(struct mb86a16_state
*state
,
756 unsigned char *AFCEX_L
,
757 unsigned char *AFCEX_H
)
762 crnt_swp_freq
= fOSC_start
* 1000 + v
* swp_ofs
;
765 *fOSC
= (crnt_swp_freq
+ 1000) / 2000 * 2;
767 *fOSC
= (crnt_swp_freq
+ 500) / 1000;
769 if (*fOSC
>= crnt_swp_freq
)
770 *afcex_freq
= *fOSC
* 1000 - crnt_swp_freq
;
772 *afcex_freq
= crnt_swp_freq
- *fOSC
* 1000;
774 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
775 *AFCEX_L
= AFCEX
& 0x00ff;
776 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
780 static int swp_freq_calcuation(struct mb86a16_state
*state
, int i
, int v
, int *V
, int vmax
, int vmin
,
781 int SIGMIN
, int fOSC
, int afcex_freq
, int swp_ofs
, unsigned char *SIG1
)
785 if ((i
% 2 == 1) && (v
<= vmax
)) {
786 /* positive v (case 1) */
787 if ((v
- 1 == vmin
) &&
788 (*(V
+ 30 + v
) >= 0) &&
789 (*(V
+ 30 + v
- 1) >= 0) &&
790 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
791 (*(V
+ 30 + v
- 1) > SIGMIN
)) {
793 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
794 *SIG1
= *(V
+ 30 + v
- 1);
795 } else if ((v
== vmax
) &&
796 (*(V
+ 30 + v
) >= 0) &&
797 (*(V
+ 30 + v
- 1) >= 0) &&
798 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 1)) &&
799 (*(V
+ 30 + v
) > SIGMIN
)) {
801 swp_freq
= fOSC
* 1000 + afcex_freq
;
802 *SIG1
= *(V
+ 30 + v
);
803 } else if ((*(V
+ 30 + v
) > 0) &&
804 (*(V
+ 30 + v
- 1) > 0) &&
805 (*(V
+ 30 + v
- 2) > 0) &&
806 (*(V
+ 30 + v
- 3) > 0) &&
807 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
808 (*(V
+ 30 + v
- 2) > *(V
+ 30 + v
- 3)) &&
809 ((*(V
+ 30 + v
- 1) > SIGMIN
) ||
810 (*(V
+ 30 + v
- 2) > SIGMIN
))) {
812 if (*(V
+ 30 + v
- 1) >= *(V
+ 30 + v
- 2)) {
813 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
814 *SIG1
= *(V
+ 30 + v
- 1);
816 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
* 2;
817 *SIG1
= *(V
+ 30 + v
- 2);
819 } else if ((v
== vmax
) &&
820 (*(V
+ 30 + v
) >= 0) &&
821 (*(V
+ 30 + v
- 1) >= 0) &&
822 (*(V
+ 30 + v
- 2) >= 0) &&
823 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 2)) &&
824 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
- 2)) &&
825 ((*(V
+ 30 + v
) > SIGMIN
) ||
826 (*(V
+ 30 + v
- 1) > SIGMIN
))) {
828 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
- 1)) {
829 swp_freq
= fOSC
* 1000 + afcex_freq
;
830 *SIG1
= *(V
+ 30 + v
);
832 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
833 *SIG1
= *(V
+ 30 + v
- 1);
838 } else if ((i
% 2 == 0) && (v
>= vmin
)) {
839 /* Negative v (case 1) */
840 if ((*(V
+ 30 + v
) > 0) &&
841 (*(V
+ 30 + v
+ 1) > 0) &&
842 (*(V
+ 30 + v
+ 2) > 0) &&
843 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
844 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
845 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
847 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
848 *SIG1
= *(V
+ 30 + v
+ 1);
849 } else if ((v
+ 1 == vmax
) &&
850 (*(V
+ 30 + v
) >= 0) &&
851 (*(V
+ 30 + v
+ 1) >= 0) &&
852 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
853 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
855 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
856 *SIG1
= *(V
+ 30 + v
);
857 } else if ((v
== vmin
) &&
858 (*(V
+ 30 + v
) > 0) &&
859 (*(V
+ 30 + v
+ 1) > 0) &&
860 (*(V
+ 30 + v
+ 2) > 0) &&
861 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 1)) &&
862 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
863 (*(V
+ 30 + v
) > SIGMIN
)) {
865 swp_freq
= fOSC
* 1000 + afcex_freq
;
866 *SIG1
= *(V
+ 30 + v
);
867 } else if ((*(V
+ 30 + v
) >= 0) &&
868 (*(V
+ 30 + v
+ 1) >= 0) &&
869 (*(V
+ 30 + v
+ 2) >= 0) &&
870 (*(V
+ 30 + v
+ 3) >= 0) &&
871 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
872 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
+ 3)) &&
873 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
874 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
876 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
877 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
878 *SIG1
= *(V
+ 30 + v
+ 1);
880 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
881 *SIG1
= *(V
+ 30 + v
+ 2);
883 } else if ((*(V
+ 30 + v
) >= 0) &&
884 (*(V
+ 30 + v
+ 1) >= 0) &&
885 (*(V
+ 30 + v
+ 2) >= 0) &&
886 (*(V
+ 30 + v
+ 3) >= 0) &&
887 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
888 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
889 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 3)) &&
890 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 3)) &&
891 ((*(V
+ 30 + v
) > SIGMIN
) ||
892 (*(V
+ 30 + v
+ 1) > SIGMIN
))) {
894 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
+ 1)) {
895 swp_freq
= fOSC
* 1000 + afcex_freq
;
896 *SIG1
= *(V
+ 30 + v
);
898 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
899 *SIG1
= *(V
+ 30 + v
+ 1);
901 } else if ((v
+ 2 == vmin
) &&
902 (*(V
+ 30 + v
) >= 0) &&
903 (*(V
+ 30 + v
+ 1) >= 0) &&
904 (*(V
+ 30 + v
+ 2) >= 0) &&
905 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
906 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
)) &&
907 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
908 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
910 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
911 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
912 *SIG1
= *(V
+ 30 + v
+ 1);
914 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
915 *SIG1
= *(V
+ 30 + v
+ 2);
917 } else if ((vmax
== 0) && (vmin
== 0) && (*(V
+ 30 + v
) > SIGMIN
)) {
918 swp_freq
= fOSC
* 1000;
919 *SIG1
= *(V
+ 30 + v
);
928 static void swp_info_get2(struct mb86a16_state
*state
,
934 unsigned char *AFCEX_L
,
935 unsigned char *AFCEX_H
)
940 *fOSC
= (swp_freq
+ 1000) / 2000 * 2;
942 *fOSC
= (swp_freq
+ 500) / 1000;
944 if (*fOSC
>= swp_freq
)
945 *afcex_freq
= *fOSC
* 1000 - swp_freq
;
947 *afcex_freq
= swp_freq
- *fOSC
* 1000;
949 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
950 *AFCEX_L
= AFCEX
& 0x00ff;
951 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
954 static void afcex_info_get(struct mb86a16_state
*state
,
956 unsigned char *AFCEX_L
,
957 unsigned char *AFCEX_H
)
961 AFCEX
= afcex_freq
* 8192 / state
->master_clk
;
962 *AFCEX_L
= AFCEX
& 0x00ff;
963 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
966 static int SEQ_set(struct mb86a16_state
*state
, unsigned char loop
)
969 if (mb86a16_write(state
, 0x32, 0x02 | (loop
<< 2)) < 0) {
970 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
977 static int iq_vt_set(struct mb86a16_state
*state
, unsigned char IQINV
)
979 /* Viterbi Rate, IQ Settings */
980 if (mb86a16_write(state
, 0x06, 0xdf | (IQINV
<< 5)) < 0) {
981 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
988 static int FEC_srst(struct mb86a16_state
*state
)
990 if (mb86a16_write(state
, MB86A16_RESET
, 0x02) < 0) {
991 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
998 static int S2T_set(struct mb86a16_state
*state
, unsigned char S2T
)
1000 if (mb86a16_write(state
, 0x34, 0x70 | S2T
) < 0) {
1001 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1008 static int S45T_set(struct mb86a16_state
*state
, unsigned char S4T
, unsigned char S5T
)
1010 if (mb86a16_write(state
, 0x35, 0x00 | (S5T
<< 4) | S4T
) < 0) {
1011 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1019 static int mb86a16_set_fe(struct mb86a16_state
*state
)
1032 unsigned char CREN
, AFCEN
, AFCEXEN
;
1034 unsigned char TIMINT1
, TIMINT2
, TIMEXT
;
1035 unsigned char S0T
, S1T
;
1037 /* unsigned char S2T, S3T; */
1038 unsigned char S4T
, S5T
;
1039 unsigned char AFCEX_L
, AFCEX_H
;
1042 unsigned char ETH
, VIA
;
1048 int vmax_his
, vmin_his
;
1049 int swp_freq
, prev_swp_freq
[20];
1055 int temp_freq
, delta_freq
;
1063 dprintk(verbose
, MB86A16_INFO
, 1, "freq=%d Mhz, symbrt=%d Ksps", state
->frequency
, state
->srate
);
1066 swp_ofs
= state
->srate
/ 4;
1068 for (i
= 0; i
< 60; i
++)
1071 for (i
= 0; i
< 20; i
++)
1072 prev_swp_freq
[i
] = 0;
1076 for (n
= 0; ((n
< 3) && (ret
== -1)); n
++) {
1078 iq_vt_set(state
, 0);
1089 if (initial_set(state
) < 0) {
1090 dprintk(verbose
, MB86A16_ERROR
, 1, "initial set failed");
1093 if (DAGC_data_set(state
, 3, 2) < 0) {
1094 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1097 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1098 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1099 return -1; /* (0, 0) */
1101 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1102 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1103 return -1; /* (1, smrt) = (1, symbolrate) */
1105 if (CNTM_set(state
, TIMINT1
, TIMINT2
, TIMEXT
) < 0) {
1106 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set error");
1107 return -1; /* (0, 1, 2) */
1109 if (S01T_set(state
, S1T
, S0T
) < 0) {
1110 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1111 return -1; /* (0, 0) */
1113 smrt_info_get(state
, state
->srate
);
1114 if (smrt_set(state
, state
->srate
) < 0) {
1115 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt info get error");
1119 R
= vco_dev_get(state
, state
->srate
);
1121 fOSC_start
= state
->frequency
;
1124 if (state
->frequency
% 2 == 0) {
1125 fOSC_start
= state
->frequency
;
1127 fOSC_start
= state
->frequency
+ 1;
1128 if (fOSC_start
> 2150)
1129 fOSC_start
= state
->frequency
- 1;
1133 ftemp
= fOSC_start
* 1000;
1136 ftemp
= ftemp
+ swp_ofs
;
1140 if (ftemp
> 2150000) {
1144 if ((ftemp
== 2150000) ||
1145 (ftemp
- state
->frequency
* 1000 >= fcp
+ state
->srate
/ 4))
1151 ftemp
= fOSC_start
* 1000;
1154 ftemp
= ftemp
- swp_ofs
;
1158 if (ftemp
< 950000) {
1162 if ((ftemp
== 950000) ||
1163 (state
->frequency
* 1000 - ftemp
>= fcp
+ state
->srate
/ 4))
1168 wait_t
= (8000 + state
->srate
/ 2) / state
->srate
;
1182 swp_info_get(state
, fOSC_start
, state
->srate
,
1183 v
, R
, swp_ofs
, &fOSC
,
1184 &afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1187 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1188 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1192 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1193 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1196 if (srst(state
) < 0) {
1197 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1200 msleep_interruptible(wait_t
);
1202 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1203 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1207 swp_freq
= swp_freq_calcuation(state
, i
, v
, V
, vmax
, vmin
,
1208 SIG1MIN
, fOSC
, afcex_freq
,
1209 swp_ofs
, &SIG1
); /* changed */
1212 for (j
= 0; j
< prev_freq_num
; j
++) {
1213 if ((ABS(prev_swp_freq
[j
] - swp_freq
)) < (swp_ofs
* 3 / 2)) {
1215 dprintk(verbose
, MB86A16_INFO
, 1, "Probably Duplicate Signal, j = %d", j
);
1218 if ((signal_dupl
== 0) && (swp_freq
> 0) && (ABS(swp_freq
- state
->frequency
* 1000) < fcp
+ state
->srate
/ 6)) {
1219 dprintk(verbose
, MB86A16_DEBUG
, 1, "------ Signal detect ------ [swp_freq=[%07d, srate=%05d]]", swp_freq
, state
->srate
);
1220 prev_swp_freq
[prev_freq_num
] = swp_freq
;
1222 swp_info_get2(state
, state
->srate
, R
, swp_freq
,
1224 &AFCEX_L
, &AFCEX_H
);
1226 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1227 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1230 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1231 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1234 signal
= signal_det(state
, state
->srate
, &SIG1
);
1236 dprintk(verbose
, MB86A16_ERROR
, 1, "***** Signal Found *****");
1239 dprintk(verbose
, MB86A16_ERROR
, 1, "!!!!! No signal !!!!!, try again...");
1240 smrt_info_get(state
, state
->srate
);
1241 if (smrt_set(state
, state
->srate
) < 0) {
1242 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1253 if ((i
% 2 == 1) && (vmax_his
== 1))
1255 if ((i
% 2 == 0) && (vmin_his
== 1))
1263 if ((vmax_his
== 1) && (vmin_his
== 1))
1268 dprintk(verbose
, MB86A16_INFO
, 1, " Start Freq Error Check");
1275 if (S01T_set(state
, S1T
, S0T
) < 0) {
1276 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1279 smrt_info_get(state
, state
->srate
);
1280 if (smrt_set(state
, state
->srate
) < 0) {
1281 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1284 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1285 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1288 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1289 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1292 afcex_info_get(state
, afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1293 if (afcofs_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1294 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCOFS data set error");
1297 if (srst(state
) < 0) {
1298 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1302 wait_t
= 200000 / state
->master_clk
+ 200000 / state
->srate
;
1304 afcerr
= afcerr_chk(state
);
1308 swp_freq
= fOSC
* 1000 + afcerr
;
1310 if (state
->srate
>= 1500)
1311 smrt_d
= state
->srate
/ 3;
1313 smrt_d
= state
->srate
/ 2;
1314 smrt_info_get(state
, smrt_d
);
1315 if (smrt_set(state
, smrt_d
) < 0) {
1316 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1319 if (AFCEXEN_set(state
, AFCEXEN
, smrt_d
) < 0) {
1320 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1323 R
= vco_dev_get(state
, smrt_d
);
1324 if (DAGC_data_set(state
, 2, 0) < 0) {
1325 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1328 for (i
= 0; i
< 3; i
++) {
1329 temp_freq
= swp_freq
+ (i
- 1) * state
->srate
/ 8;
1330 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1331 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1332 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1335 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1336 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1339 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1341 dagcm
[i
] = dagcm_val_get(state
);
1343 if ((dagcm
[0] > dagcm
[1]) &&
1344 (dagcm
[0] > dagcm
[2]) &&
1345 (dagcm
[0] - dagcm
[1] > 2 * (dagcm
[2] - dagcm
[1]))) {
1347 temp_freq
= swp_freq
- 2 * state
->srate
/ 8;
1348 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1349 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1350 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1353 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1354 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set");
1357 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1359 dagcm
[3] = dagcm_val_get(state
);
1360 if (dagcm
[3] > dagcm
[1])
1361 delta_freq
= (dagcm
[2] - dagcm
[0] + dagcm
[1] - dagcm
[3]) * state
->srate
/ 300;
1364 } else if ((dagcm
[2] > dagcm
[1]) &&
1365 (dagcm
[2] > dagcm
[0]) &&
1366 (dagcm
[2] - dagcm
[1] > 2 * (dagcm
[0] - dagcm
[1]))) {
1368 temp_freq
= swp_freq
+ 2 * state
->srate
/ 8;
1369 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1370 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1371 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set");
1374 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1375 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set");
1378 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1380 dagcm
[3] = dagcm_val_get(state
);
1381 if (dagcm
[3] > dagcm
[1])
1382 delta_freq
= (dagcm
[2] - dagcm
[0] + dagcm
[3] - dagcm
[1]) * state
->srate
/ 300;
1389 dprintk(verbose
, MB86A16_INFO
, 1, "SWEEP Frequency = %d", swp_freq
);
1390 swp_freq
+= delta_freq
;
1391 dprintk(verbose
, MB86A16_INFO
, 1, "Adjusting .., DELTA Freq = %d, SWEEP Freq=%d", delta_freq
, swp_freq
);
1392 if (ABS(state
->frequency
* 1000 - swp_freq
) > 3800) {
1393 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL !");
1402 if (S01T_set(state
, S1T
, S0T
) < 0) {
1403 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1406 if (DAGC_data_set(state
, 0, 0) < 0) {
1407 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1410 R
= vco_dev_get(state
, state
->srate
);
1411 smrt_info_get(state
, state
->srate
);
1412 if (smrt_set(state
, state
->srate
) < 0) {
1413 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1416 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1417 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1420 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1421 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1424 swp_info_get2(state
, state
->srate
, R
, swp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1425 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1426 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1429 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1430 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1433 if (srst(state
) < 0) {
1434 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1437 wait_t
= 7 + (10000 + state
->srate
/ 2) / state
->srate
;
1440 msleep_interruptible(wait_t
);
1441 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1442 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1447 S2T
= 4; S4T
= 1; S5T
= 6; ETH
= 4; VIA
= 6;
1448 wait_t
= 7 + (917504 + state
->srate
/ 2) / state
->srate
;
1449 } else if (SIG1
> 105) {
1450 S2T
= 4; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1451 wait_t
= 7 + (1048576 + state
->srate
/ 2) / state
->srate
;
1452 } else if (SIG1
> 85) {
1453 S2T
= 5; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1454 wait_t
= 7 + (1310720 + state
->srate
/ 2) / state
->srate
;
1455 } else if (SIG1
> 65) {
1456 S2T
= 6; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1457 wait_t
= 7 + (1572864 + state
->srate
/ 2) / state
->srate
;
1459 S2T
= 7; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1460 wait_t
= 7 + (2097152 + state
->srate
/ 2) / state
->srate
;
1462 wait_t
*= 2; /* FOS */
1463 S2T_set(state
, S2T
);
1464 S45T_set(state
, S4T
, S5T
);
1465 Vi_set(state
, ETH
, VIA
);
1467 msleep_interruptible(wait_t
);
1468 sync
= sync_chk(state
, &VIRM
);
1469 dprintk(verbose
, MB86A16_INFO
, 1, "-------- Viterbi=[%d] SYNC=[%d] ---------", VIRM
, sync
);
1474 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1476 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1477 if (state
->srate
< 5000)
1478 /* FIXME ! , should be a long wait ! */
1479 msleep_interruptible(wait_t
);
1481 msleep_interruptible(wait_t
);
1483 if (sync_chk(state
, &junk
) == 0) {
1484 iq_vt_set(state
, 1);
1488 /* 1/2, 2/3, 3/4, 7/8 */
1490 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1492 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1493 msleep_interruptible(wait_t
);
1496 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SYNC");
1502 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL");
1506 sync
= sync_chk(state
, &junk
);
1508 dprintk(verbose
, MB86A16_INFO
, 1, "******* SYNC *******");
1509 freqerr_chk(state
, state
->frequency
, state
->srate
, 1);
1515 mb86a16_read(state
, 0x15, &agcval
);
1516 mb86a16_read(state
, 0x26, &cnmval
);
1517 dprintk(verbose
, MB86A16_INFO
, 1, "AGC = %02x CNM = %02x", agcval
, cnmval
);
1522 static int mb86a16_send_diseqc_msg(struct dvb_frontend
*fe
,
1523 struct dvb_diseqc_master_cmd
*cmd
)
1525 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1529 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1531 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1533 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1538 if (cmd
->msg_len
> 5 || cmd
->msg_len
< 4)
1541 for (i
= 0; i
< cmd
->msg_len
; i
++) {
1542 if (mb86a16_write(state
, regs
, cmd
->msg
[i
]) < 0)
1549 msleep_interruptible(10);
1551 if (mb86a16_write(state
, MB86A16_DCC1
, i
) < 0)
1553 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1559 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1563 static int mb86a16_send_diseqc_burst(struct dvb_frontend
*fe
, fe_sec_mini_cmd_t burst
)
1565 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1569 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1571 MB86A16_DCC1_TBO
) < 0)
1573 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1577 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1578 MB86A16_DCC1_TBEN
) < 0)
1580 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1587 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1591 static int mb86a16_set_tone(struct dvb_frontend
*fe
, fe_sec_tone_mode_t tone
)
1593 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1597 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x00) < 0)
1599 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1600 MB86A16_DCC1_CTOE
) < 0)
1603 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1607 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1609 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1611 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1620 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1624 static enum dvbfe_search
mb86a16_search(struct dvb_frontend
*fe
,
1625 struct dvb_frontend_parameters
*p
)
1627 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1629 state
->frequency
= p
->frequency
/ 1000;
1630 state
->srate
= p
->u
.qpsk
.symbol_rate
/ 1000;
1632 if (!mb86a16_set_fe(state
)) {
1633 dprintk(verbose
, MB86A16_ERROR
, 1, "Succesfully acquired LOCK");
1634 return DVBFE_ALGO_SEARCH_SUCCESS
;
1637 dprintk(verbose
, MB86A16_ERROR
, 1, "Lock acquisition failed!");
1638 return DVBFE_ALGO_SEARCH_FAILED
;
1641 static void mb86a16_release(struct dvb_frontend
*fe
)
1643 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1647 static int mb86a16_init(struct dvb_frontend
*fe
)
1652 static int mb86a16_sleep(struct dvb_frontend
*fe
)
1657 static int mb86a16_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1659 u8 ber_mon
, ber_tab
, ber_lsb
, ber_mid
, ber_msb
, ber_tim
, ber_rst
;
1662 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1665 if (mb86a16_read(state
, MB86A16_BERMON
, &ber_mon
) != 2)
1667 if (mb86a16_read(state
, MB86A16_BERTAB
, &ber_tab
) != 2)
1669 if (mb86a16_read(state
, MB86A16_BERLSB
, &ber_lsb
) != 2)
1671 if (mb86a16_read(state
, MB86A16_BERMID
, &ber_mid
) != 2)
1673 if (mb86a16_read(state
, MB86A16_BERMSB
, &ber_msb
) != 2)
1675 /* BER monitor invalid when BER_EN = 0 */
1676 if (ber_mon
& 0x04) {
1677 /* coarse, fast calculation */
1678 *ber
= ber_tab
& 0x1f;
1679 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER coarse=[0x%02x]", *ber
);
1680 if (ber_mon
& 0x01) {
1682 * BER_SEL = 1, The monitored BER is the estimated
1683 * value with a Reed-Solomon decoder error amount at
1684 * the deinterleaver output.
1685 * monitored BER is expressed as a 20 bit output in total
1687 ber_rst
= ber_mon
>> 3;
1688 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1699 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1702 * BER_SEL = 0, The monitored BER is the estimated
1703 * value with a Viterbi decoder error amount at the
1704 * QPSK demodulator output.
1705 * monitored BER is expressed as a 24 bit output in total
1707 ber_tim
= ber_mon
>> 1;
1708 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1715 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1720 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1724 static int mb86a16_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
1727 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1730 if (mb86a16_read(state
, MB86A16_AGCM
, &agcm
) != 2) {
1731 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1735 *strength
= ((0xff - agcm
) * 100) / 256;
1736 dprintk(verbose
, MB86A16_DEBUG
, 1, "Signal strength=[%d %%]", (u8
) *strength
);
1737 *strength
= (0xffff - 0xff) + agcm
;
1747 static const struct cnr cnr_tab
[] = {
1771 static int mb86a16_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1773 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1775 int low_tide
= 2, high_tide
= 30, q_level
;
1779 if (mb86a16_read(state
, 0x26, &cn
) != 2) {
1780 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1784 for (i
= 0; i
< ARRAY_SIZE(cnr_tab
); i
++) {
1785 if (cn
< cnr_tab
[i
].cn_reg
) {
1786 *snr
= cnr_tab
[i
].cn_val
;
1790 q_level
= (*snr
* 100) / (high_tide
- low_tide
);
1791 dprintk(verbose
, MB86A16_ERROR
, 1, "SNR (Quality) = [%d dB], Level=%d %%", *snr
, q_level
);
1792 *snr
= (0xffff - 0xff) + *snr
;
1797 static int mb86a16_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
1800 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1802 if (mb86a16_read(state
, MB86A16_DISTMON
, &dist
) != 2) {
1803 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1811 static enum dvbfe_algo
mb86a16_frontend_algo(struct dvb_frontend
*fe
)
1813 return DVBFE_ALGO_CUSTOM
;
1816 static struct dvb_frontend_ops mb86a16_ops
= {
1818 .name
= "Fujitsu MB86A16 DVB-S",
1820 .frequency_min
= 950000,
1821 .frequency_max
= 2150000,
1822 .frequency_stepsize
= 3000,
1823 .frequency_tolerance
= 0,
1824 .symbol_rate_min
= 1000000,
1825 .symbol_rate_max
= 45000000,
1826 .symbol_rate_tolerance
= 500,
1827 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
|
1828 FE_CAN_FEC_3_4
| FE_CAN_FEC_5_6
|
1829 FE_CAN_FEC_7_8
| FE_CAN_QPSK
|
1832 .release
= mb86a16_release
,
1834 .get_frontend_algo
= mb86a16_frontend_algo
,
1835 .search
= mb86a16_search
,
1836 .init
= mb86a16_init
,
1837 .sleep
= mb86a16_sleep
,
1838 .read_status
= mb86a16_read_status
,
1840 .read_ber
= mb86a16_read_ber
,
1841 .read_signal_strength
= mb86a16_read_signal_strength
,
1842 .read_snr
= mb86a16_read_snr
,
1843 .read_ucblocks
= mb86a16_read_ucblocks
,
1845 .diseqc_send_master_cmd
= mb86a16_send_diseqc_msg
,
1846 .diseqc_send_burst
= mb86a16_send_diseqc_burst
,
1847 .set_tone
= mb86a16_set_tone
,
1850 struct dvb_frontend
*mb86a16_attach(const struct mb86a16_config
*config
,
1851 struct i2c_adapter
*i2c_adap
)
1854 struct mb86a16_state
*state
= NULL
;
1856 state
= kmalloc(sizeof(struct mb86a16_state
), GFP_KERNEL
);
1860 state
->config
= config
;
1861 state
->i2c_adap
= i2c_adap
;
1863 mb86a16_read(state
, 0x7f, &dev_id
);
1867 memcpy(&state
->frontend
.ops
, &mb86a16_ops
, sizeof(struct dvb_frontend_ops
));
1868 state
->frontend
.demodulator_priv
= state
;
1869 state
->frontend
.ops
.set_voltage
= state
->config
->set_voltage
;
1871 return &state
->frontend
;
1876 EXPORT_SYMBOL(mb86a16_attach
);
1877 MODULE_LICENSE("GPL");
1878 MODULE_AUTHOR("Manu Abraham");