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 <media/dvb_frontend.h>
29 #include "mb86a16_priv.h"
31 static 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=%i)",
130 static int CNTM_set(struct mb86a16_state
*state
,
131 unsigned char timint1
,
132 unsigned char timint2
,
137 val
= (timint1
<< 4) | (timint2
<< 2) | cnext
;
138 if (mb86a16_write(state
, MB86A16_CNTMR
, val
) < 0)
144 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
148 static int smrt_set(struct mb86a16_state
*state
, int rate
)
152 unsigned char STOFS0
, STOFS1
;
154 m
= 1 << state
->deci
;
155 tmp
= (8192 * state
->master_clk
- 2 * m
* rate
* 8192 + state
->master_clk
/ 2) / state
->master_clk
;
157 STOFS0
= tmp
& 0x0ff;
158 STOFS1
= (tmp
& 0xf00) >> 8;
160 if (mb86a16_write(state
, MB86A16_SRATE1
, (state
->deci
<< 2) |
164 if (mb86a16_write(state
, MB86A16_SRATE2
, STOFS0
) < 0)
166 if (mb86a16_write(state
, MB86A16_SRATE3
, STOFS1
) < 0)
171 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
175 static int srst(struct mb86a16_state
*state
)
177 if (mb86a16_write(state
, MB86A16_RESET
, 0x04) < 0)
182 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
187 static int afcex_data_set(struct mb86a16_state
*state
,
188 unsigned char AFCEX_L
,
189 unsigned char AFCEX_H
)
191 if (mb86a16_write(state
, MB86A16_AFCEXL
, AFCEX_L
) < 0)
193 if (mb86a16_write(state
, MB86A16_AFCEXH
, AFCEX_H
) < 0)
198 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
203 static int afcofs_data_set(struct mb86a16_state
*state
,
204 unsigned char AFCEX_L
,
205 unsigned char AFCEX_H
)
207 if (mb86a16_write(state
, 0x58, AFCEX_L
) < 0)
209 if (mb86a16_write(state
, 0x59, AFCEX_H
) < 0)
214 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
218 static int stlp_set(struct mb86a16_state
*state
,
222 if (mb86a16_write(state
, MB86A16_STRFILTCOEF1
, (STRBS
<< 3) | (STRAS
)) < 0)
227 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
231 static int Vi_set(struct mb86a16_state
*state
, unsigned char ETH
, unsigned char VIA
)
233 if (mb86a16_write(state
, MB86A16_VISET2
, 0x04) < 0)
235 if (mb86a16_write(state
, MB86A16_VISET3
, 0xf5) < 0)
240 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
244 static int initial_set(struct mb86a16_state
*state
)
246 if (stlp_set(state
, 5, 7))
250 if (afcex_data_set(state
, 0, 0))
254 if (afcofs_data_set(state
, 0, 0))
258 if (mb86a16_write(state
, MB86A16_CRLFILTCOEF1
, 0x16) < 0)
260 if (mb86a16_write(state
, 0x2f, 0x21) < 0)
262 if (mb86a16_write(state
, MB86A16_VIMAG
, 0x38) < 0)
264 if (mb86a16_write(state
, MB86A16_FAGCS1
, 0x00) < 0)
266 if (mb86a16_write(state
, MB86A16_FAGCS2
, 0x1c) < 0)
268 if (mb86a16_write(state
, MB86A16_FAGCS3
, 0x20) < 0)
270 if (mb86a16_write(state
, MB86A16_FAGCS4
, 0x1e) < 0)
272 if (mb86a16_write(state
, MB86A16_FAGCS5
, 0x23) < 0)
274 if (mb86a16_write(state
, 0x54, 0xff) < 0)
276 if (mb86a16_write(state
, MB86A16_TSOUT
, 0x00) < 0)
282 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
286 static int S01T_set(struct mb86a16_state
*state
,
290 if (mb86a16_write(state
, 0x33, (s1t
<< 3) | s0t
) < 0)
295 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
300 static int EN_set(struct mb86a16_state
*state
,
306 val
= 0x7a | (cren
<< 7) | (afcen
<< 2);
307 if (mb86a16_write(state
, 0x49, val
) < 0)
312 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
316 static int AFCEXEN_set(struct mb86a16_state
*state
,
324 else if (smrt
> 9375)
326 else if (smrt
> 2250)
331 if (mb86a16_write(state
, 0x2a, 0x02 | (afcexen
<< 5) | (AFCA
<< 2)) < 0)
337 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
341 static int DAGC_data_set(struct mb86a16_state
*state
,
345 if (mb86a16_write(state
, 0x2d, (DAGCA
<< 3) | DAGCW
) < 0)
351 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
355 static void smrt_info_get(struct mb86a16_state
*state
, int rate
)
358 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 0;
359 } else if (rate
>= 30001) {
360 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 1;
361 } else if (rate
>= 26251) {
362 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 0;
363 } else if (rate
>= 22501) {
364 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 1;
365 } else if (rate
>= 18751) {
366 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 0;
367 } else if (rate
>= 15001) {
368 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 1;
369 } else if (rate
>= 13126) {
370 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 0;
371 } else if (rate
>= 11251) {
372 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 1;
373 } else if (rate
>= 9376) {
374 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 0;
375 } else if (rate
>= 7501) {
376 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 1;
377 } else if (rate
>= 6563) {
378 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 0;
379 } else if (rate
>= 5626) {
380 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 1;
381 } else if (rate
>= 4688) {
382 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 0;
383 } else if (rate
>= 3751) {
384 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 1;
385 } else if (rate
>= 3282) {
386 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 0;
387 } else if (rate
>= 2814) {
388 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 1;
389 } else if (rate
>= 2344) {
390 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 0;
391 } else if (rate
>= 1876) {
392 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 1;
393 } else if (rate
>= 1641) {
394 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 0;
395 } else if (rate
>= 1407) {
396 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 1;
397 } else if (rate
>= 1172) {
398 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 0;
399 } else if (rate
>= 939) {
400 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 1;
401 } else if (rate
>= 821) {
402 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 0;
404 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 1;
407 if (state
->csel
== 0)
408 state
->master_clk
= 92000;
410 state
->master_clk
= 61333;
414 static int signal_det(struct mb86a16_state
*state
,
424 if (CNTM_set(state
, 2, 1, 2) < 0) {
425 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
429 if (CNTM_set(state
, 3, 1, 2) < 0) {
430 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
434 for (i
= 0; i
< 3; i
++) {
436 smrtd
= smrt
* 98 / 100;
440 smrtd
= smrt
* 102 / 100;
441 smrt_info_get(state
, smrtd
);
442 smrt_set(state
, smrtd
);
444 msleep_interruptible(10);
445 if (mb86a16_read(state
, 0x37, &(S
[i
])) != 2) {
446 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
450 if ((S
[1] > S
[0] * 112 / 100) && (S
[1] > S
[2] * 112 / 100))
457 if (CNTM_set(state
, 0, 1, 2) < 0) {
458 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
465 static int rf_val_set(struct mb86a16_state
*state
,
470 unsigned char C
, F
, B
;
472 unsigned char rf_val
[5];
477 else if (smrt
> 18875)
479 else if (smrt
> 5500)
486 else if (smrt
> 9375)
488 else if (smrt
> 4625)
514 M
= f
* (1 << R
) / 2;
516 rf_val
[0] = 0x01 | (C
<< 3) | (F
<< 1);
517 rf_val
[1] = (R
<< 5) | ((M
& 0x1f000) >> 12);
518 rf_val
[2] = (M
& 0x00ff0) >> 4;
519 rf_val
[3] = ((M
& 0x0000f) << 4) | B
;
522 if (mb86a16_write(state
, 0x21, rf_val
[0]) < 0)
524 if (mb86a16_write(state
, 0x22, rf_val
[1]) < 0)
526 if (mb86a16_write(state
, 0x23, rf_val
[2]) < 0)
528 if (mb86a16_write(state
, 0x24, rf_val
[3]) < 0)
530 if (mb86a16_write(state
, 0x25, 0x01) < 0)
533 dprintk(verbose
, MB86A16_ERROR
, 1, "RF Setup - I2C transfer error");
540 static int afcerr_chk(struct mb86a16_state
*state
)
542 unsigned char AFCM_L
, AFCM_H
;
546 if (mb86a16_read(state
, 0x0e, &AFCM_L
) != 2)
548 if (mb86a16_read(state
, 0x0f, &AFCM_H
) != 2)
551 AFCM
= (AFCM_H
<< 8) + AFCM_L
;
557 afcerr
= afcm
* state
->master_clk
/ 8192;
562 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
566 static int dagcm_val_get(struct mb86a16_state
*state
)
569 unsigned char DAGCM_H
, DAGCM_L
;
571 if (mb86a16_read(state
, 0x45, &DAGCM_L
) != 2)
573 if (mb86a16_read(state
, 0x46, &DAGCM_H
) != 2)
576 DAGCM
= (DAGCM_H
<< 8) + DAGCM_L
;
581 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
585 static int mb86a16_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
588 struct mb86a16_state
*state
= fe
->demodulator_priv
;
592 if (mb86a16_read(state
, MB86A16_SIG1
, &stat
) != 2)
594 if (mb86a16_read(state
, MB86A16_SIG2
, &stat2
) != 2)
596 if ((stat
> 25) && (stat2
> 25))
597 *status
|= FE_HAS_SIGNAL
;
598 if ((stat
> 45) && (stat2
> 45))
599 *status
|= FE_HAS_CARRIER
;
601 if (mb86a16_read(state
, MB86A16_STATUS
, &stat
) != 2)
605 *status
|= FE_HAS_SYNC
;
607 *status
|= FE_HAS_VITERBI
;
609 if (mb86a16_read(state
, MB86A16_FRAMESYNC
, &stat
) != 2)
612 if ((stat
& 0x0f) && (*status
& FE_HAS_VITERBI
))
613 *status
|= FE_HAS_LOCK
;
618 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
622 static int sync_chk(struct mb86a16_state
*state
,
628 if (mb86a16_read(state
, 0x0d, &val
) != 2)
631 dprintk(verbose
, MB86A16_INFO
, 1, "Status = %02x,", val
);
633 *VIRM
= (val
& 0x1c) >> 2;
637 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
643 static int freqerr_chk(struct mb86a16_state
*state
,
648 unsigned char CRM
, AFCML
, AFCMH
;
649 unsigned char temp1
, temp2
, temp3
;
651 int crrerr
, afcerr
; /* kHz */
652 int frqerr
; /* MHz */
653 int afcen
, afcexen
= 0;
654 int R
, M
, fOSC
, fOSC_OFS
;
656 if (mb86a16_read(state
, 0x43, &CRM
) != 2)
664 crrerr
= smrt
* crm
/ 256;
665 if (mb86a16_read(state
, 0x49, &temp1
) != 2)
668 afcen
= (temp1
& 0x04) >> 2;
670 if (mb86a16_read(state
, 0x2a, &temp1
) != 2)
672 afcexen
= (temp1
& 0x20) >> 5;
676 if (mb86a16_read(state
, 0x0e, &AFCML
) != 2)
678 if (mb86a16_read(state
, 0x0f, &AFCMH
) != 2)
680 } else if (afcexen
== 1) {
681 if (mb86a16_read(state
, 0x2b, &AFCML
) != 2)
683 if (mb86a16_read(state
, 0x2c, &AFCMH
) != 2)
686 if ((afcen
== 1) || (afcexen
== 1)) {
687 smrt_info_get(state
, smrt
);
688 AFCM
= ((AFCMH
& 0x01) << 8) + AFCML
;
694 afcerr
= afcm
* state
->master_clk
/ 8192;
698 if (mb86a16_read(state
, 0x22, &temp1
) != 2)
700 if (mb86a16_read(state
, 0x23, &temp2
) != 2)
702 if (mb86a16_read(state
, 0x24, &temp3
) != 2)
705 R
= (temp1
& 0xe0) >> 5;
706 M
= ((temp1
& 0x1f) << 12) + (temp2
<< 4) + (temp3
>> 4);
712 fOSC_OFS
= fOSC
- fTP
;
714 if (unit
== 0) { /* MHz */
715 if (crrerr
+ afcerr
+ fOSC_OFS
* 1000 >= 0)
716 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 + 500) / 1000;
718 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 - 500) / 1000;
720 frqerr
= crrerr
+ afcerr
+ fOSC_OFS
* 1000;
725 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
729 static unsigned char vco_dev_get(struct mb86a16_state
*state
, int smrt
)
741 static void swp_info_get(struct mb86a16_state
*state
,
748 unsigned char *AFCEX_L
,
749 unsigned char *AFCEX_H
)
754 crnt_swp_freq
= fOSC_start
* 1000 + v
* swp_ofs
;
757 *fOSC
= (crnt_swp_freq
+ 1000) / 2000 * 2;
759 *fOSC
= (crnt_swp_freq
+ 500) / 1000;
761 if (*fOSC
>= crnt_swp_freq
)
762 *afcex_freq
= *fOSC
* 1000 - crnt_swp_freq
;
764 *afcex_freq
= crnt_swp_freq
- *fOSC
* 1000;
766 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
767 *AFCEX_L
= AFCEX
& 0x00ff;
768 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
772 static int swp_freq_calcuation(struct mb86a16_state
*state
, int i
, int v
, int *V
, int vmax
, int vmin
,
773 int SIGMIN
, int fOSC
, int afcex_freq
, int swp_ofs
, unsigned char *SIG1
)
777 if ((i
% 2 == 1) && (v
<= vmax
)) {
778 /* positive v (case 1) */
779 if ((v
- 1 == vmin
) &&
780 (*(V
+ 30 + v
) >= 0) &&
781 (*(V
+ 30 + v
- 1) >= 0) &&
782 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
783 (*(V
+ 30 + v
- 1) > SIGMIN
)) {
785 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
786 *SIG1
= *(V
+ 30 + v
- 1);
787 } else if ((v
== vmax
) &&
788 (*(V
+ 30 + v
) >= 0) &&
789 (*(V
+ 30 + v
- 1) >= 0) &&
790 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 1)) &&
791 (*(V
+ 30 + v
) > SIGMIN
)) {
793 swp_freq
= fOSC
* 1000 + afcex_freq
;
794 *SIG1
= *(V
+ 30 + v
);
795 } else if ((*(V
+ 30 + v
) > 0) &&
796 (*(V
+ 30 + v
- 1) > 0) &&
797 (*(V
+ 30 + v
- 2) > 0) &&
798 (*(V
+ 30 + v
- 3) > 0) &&
799 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
800 (*(V
+ 30 + v
- 2) > *(V
+ 30 + v
- 3)) &&
801 ((*(V
+ 30 + v
- 1) > SIGMIN
) ||
802 (*(V
+ 30 + v
- 2) > SIGMIN
))) {
804 if (*(V
+ 30 + v
- 1) >= *(V
+ 30 + v
- 2)) {
805 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
806 *SIG1
= *(V
+ 30 + v
- 1);
808 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
* 2;
809 *SIG1
= *(V
+ 30 + v
- 2);
811 } else if ((v
== vmax
) &&
812 (*(V
+ 30 + v
) >= 0) &&
813 (*(V
+ 30 + v
- 1) >= 0) &&
814 (*(V
+ 30 + v
- 2) >= 0) &&
815 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 2)) &&
816 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
- 2)) &&
817 ((*(V
+ 30 + v
) > SIGMIN
) ||
818 (*(V
+ 30 + v
- 1) > SIGMIN
))) {
820 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
- 1)) {
821 swp_freq
= fOSC
* 1000 + afcex_freq
;
822 *SIG1
= *(V
+ 30 + v
);
824 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
825 *SIG1
= *(V
+ 30 + v
- 1);
830 } else if ((i
% 2 == 0) && (v
>= vmin
)) {
831 /* Negative v (case 1) */
832 if ((*(V
+ 30 + v
) > 0) &&
833 (*(V
+ 30 + v
+ 1) > 0) &&
834 (*(V
+ 30 + v
+ 2) > 0) &&
835 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
836 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
837 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
839 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
840 *SIG1
= *(V
+ 30 + v
+ 1);
841 } else if ((v
+ 1 == vmax
) &&
842 (*(V
+ 30 + v
) >= 0) &&
843 (*(V
+ 30 + v
+ 1) >= 0) &&
844 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
845 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
847 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
848 *SIG1
= *(V
+ 30 + v
);
849 } else if ((v
== vmin
) &&
850 (*(V
+ 30 + v
) > 0) &&
851 (*(V
+ 30 + v
+ 1) > 0) &&
852 (*(V
+ 30 + v
+ 2) > 0) &&
853 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 1)) &&
854 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
855 (*(V
+ 30 + v
) > SIGMIN
)) {
857 swp_freq
= fOSC
* 1000 + afcex_freq
;
858 *SIG1
= *(V
+ 30 + v
);
859 } else if ((*(V
+ 30 + v
) >= 0) &&
860 (*(V
+ 30 + v
+ 1) >= 0) &&
861 (*(V
+ 30 + v
+ 2) >= 0) &&
862 (*(V
+ 30 + v
+ 3) >= 0) &&
863 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
864 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
+ 3)) &&
865 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
866 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
868 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
869 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
870 *SIG1
= *(V
+ 30 + v
+ 1);
872 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
873 *SIG1
= *(V
+ 30 + v
+ 2);
875 } else if ((*(V
+ 30 + v
) >= 0) &&
876 (*(V
+ 30 + v
+ 1) >= 0) &&
877 (*(V
+ 30 + v
+ 2) >= 0) &&
878 (*(V
+ 30 + v
+ 3) >= 0) &&
879 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
880 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
881 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 3)) &&
882 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 3)) &&
883 ((*(V
+ 30 + v
) > SIGMIN
) ||
884 (*(V
+ 30 + v
+ 1) > SIGMIN
))) {
886 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
+ 1)) {
887 swp_freq
= fOSC
* 1000 + afcex_freq
;
888 *SIG1
= *(V
+ 30 + v
);
890 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
891 *SIG1
= *(V
+ 30 + v
+ 1);
893 } else if ((v
+ 2 == vmin
) &&
894 (*(V
+ 30 + v
) >= 0) &&
895 (*(V
+ 30 + v
+ 1) >= 0) &&
896 (*(V
+ 30 + v
+ 2) >= 0) &&
897 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
898 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
)) &&
899 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
900 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
902 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
903 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
904 *SIG1
= *(V
+ 30 + v
+ 1);
906 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
907 *SIG1
= *(V
+ 30 + v
+ 2);
909 } else if ((vmax
== 0) && (vmin
== 0) && (*(V
+ 30 + v
) > SIGMIN
)) {
910 swp_freq
= fOSC
* 1000;
911 *SIG1
= *(V
+ 30 + v
);
920 static void swp_info_get2(struct mb86a16_state
*state
,
926 unsigned char *AFCEX_L
,
927 unsigned char *AFCEX_H
)
932 *fOSC
= (swp_freq
+ 1000) / 2000 * 2;
934 *fOSC
= (swp_freq
+ 500) / 1000;
936 if (*fOSC
>= swp_freq
)
937 *afcex_freq
= *fOSC
* 1000 - swp_freq
;
939 *afcex_freq
= swp_freq
- *fOSC
* 1000;
941 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
942 *AFCEX_L
= AFCEX
& 0x00ff;
943 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
946 static void afcex_info_get(struct mb86a16_state
*state
,
948 unsigned char *AFCEX_L
,
949 unsigned char *AFCEX_H
)
953 AFCEX
= afcex_freq
* 8192 / state
->master_clk
;
954 *AFCEX_L
= AFCEX
& 0x00ff;
955 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
958 static int SEQ_set(struct mb86a16_state
*state
, unsigned char loop
)
961 if (mb86a16_write(state
, 0x32, 0x02 | (loop
<< 2)) < 0) {
962 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
969 static int iq_vt_set(struct mb86a16_state
*state
, unsigned char IQINV
)
971 /* Viterbi Rate, IQ Settings */
972 if (mb86a16_write(state
, 0x06, 0xdf | (IQINV
<< 5)) < 0) {
973 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
980 static int FEC_srst(struct mb86a16_state
*state
)
982 if (mb86a16_write(state
, MB86A16_RESET
, 0x02) < 0) {
983 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
990 static int S2T_set(struct mb86a16_state
*state
, unsigned char S2T
)
992 if (mb86a16_write(state
, 0x34, 0x70 | S2T
) < 0) {
993 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1000 static int S45T_set(struct mb86a16_state
*state
, unsigned char S4T
, unsigned char S5T
)
1002 if (mb86a16_write(state
, 0x35, 0x00 | (S5T
<< 4) | S4T
) < 0) {
1003 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1011 static int mb86a16_set_fe(struct mb86a16_state
*state
)
1024 unsigned char CREN
, AFCEN
, AFCEXEN
;
1026 unsigned char TIMINT1
, TIMINT2
, TIMEXT
;
1027 unsigned char S0T
, S1T
;
1029 /* unsigned char S2T, S3T; */
1030 unsigned char S4T
, S5T
;
1031 unsigned char AFCEX_L
, AFCEX_H
;
1034 unsigned char ETH
, VIA
;
1040 int vmax_his
, vmin_his
;
1041 int swp_freq
, prev_swp_freq
[20];
1047 int temp_freq
, delta_freq
;
1055 dprintk(verbose
, MB86A16_INFO
, 1, "freq=%d Mhz, symbrt=%d Ksps", state
->frequency
, state
->srate
);
1058 swp_ofs
= state
->srate
/ 4;
1060 for (i
= 0; i
< 60; i
++)
1063 for (i
= 0; i
< 20; i
++)
1064 prev_swp_freq
[i
] = 0;
1068 for (n
= 0; ((n
< 3) && (ret
== -1)); n
++) {
1070 iq_vt_set(state
, 0);
1081 if (initial_set(state
) < 0) {
1082 dprintk(verbose
, MB86A16_ERROR
, 1, "initial set failed");
1085 if (DAGC_data_set(state
, 3, 2) < 0) {
1086 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1089 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1090 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1091 return -1; /* (0, 0) */
1093 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1094 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1095 return -1; /* (1, smrt) = (1, symbolrate) */
1097 if (CNTM_set(state
, TIMINT1
, TIMINT2
, TIMEXT
) < 0) {
1098 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set error");
1099 return -1; /* (0, 1, 2) */
1101 if (S01T_set(state
, S1T
, S0T
) < 0) {
1102 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1103 return -1; /* (0, 0) */
1105 smrt_info_get(state
, state
->srate
);
1106 if (smrt_set(state
, state
->srate
) < 0) {
1107 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt info get error");
1111 R
= vco_dev_get(state
, state
->srate
);
1113 fOSC_start
= state
->frequency
;
1116 if (state
->frequency
% 2 == 0) {
1117 fOSC_start
= state
->frequency
;
1119 fOSC_start
= state
->frequency
+ 1;
1120 if (fOSC_start
> 2150)
1121 fOSC_start
= state
->frequency
- 1;
1125 ftemp
= fOSC_start
* 1000;
1128 ftemp
= ftemp
+ swp_ofs
;
1132 if (ftemp
> 2150000) {
1136 if ((ftemp
== 2150000) ||
1137 (ftemp
- state
->frequency
* 1000 >= fcp
+ state
->srate
/ 4))
1143 ftemp
= fOSC_start
* 1000;
1146 ftemp
= ftemp
- swp_ofs
;
1150 if (ftemp
< 950000) {
1154 if ((ftemp
== 950000) ||
1155 (state
->frequency
* 1000 - ftemp
>= fcp
+ state
->srate
/ 4))
1160 wait_t
= (8000 + state
->srate
/ 2) / state
->srate
;
1174 swp_info_get(state
, fOSC_start
, state
->srate
,
1175 v
, R
, swp_ofs
, &fOSC
,
1176 &afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1179 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1180 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1184 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1185 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1188 if (srst(state
) < 0) {
1189 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1192 msleep_interruptible(wait_t
);
1194 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1195 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1199 swp_freq
= swp_freq_calcuation(state
, i
, v
, V
, vmax
, vmin
,
1200 SIG1MIN
, fOSC
, afcex_freq
,
1201 swp_ofs
, &SIG1
); /* changed */
1204 for (j
= 0; j
< prev_freq_num
; j
++) {
1205 if ((ABS(prev_swp_freq
[j
] - swp_freq
)) < (swp_ofs
* 3 / 2)) {
1207 dprintk(verbose
, MB86A16_INFO
, 1, "Probably Duplicate Signal, j = %d", j
);
1210 if ((signal_dupl
== 0) && (swp_freq
> 0) && (ABS(swp_freq
- state
->frequency
* 1000) < fcp
+ state
->srate
/ 6)) {
1211 dprintk(verbose
, MB86A16_DEBUG
, 1, "------ Signal detect ------ [swp_freq=[%07d, srate=%05d]]", swp_freq
, state
->srate
);
1212 prev_swp_freq
[prev_freq_num
] = swp_freq
;
1214 swp_info_get2(state
, state
->srate
, R
, swp_freq
,
1216 &AFCEX_L
, &AFCEX_H
);
1218 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1219 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1222 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1223 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1226 signal
= signal_det(state
, state
->srate
, &SIG1
);
1228 dprintk(verbose
, MB86A16_ERROR
, 1, "***** Signal Found *****");
1231 dprintk(verbose
, MB86A16_ERROR
, 1, "!!!!! No signal !!!!!, try again...");
1232 smrt_info_get(state
, state
->srate
);
1233 if (smrt_set(state
, state
->srate
) < 0) {
1234 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1245 if ((i
% 2 == 1) && (vmax_his
== 1))
1247 if ((i
% 2 == 0) && (vmin_his
== 1))
1255 if ((vmax_his
== 1) && (vmin_his
== 1))
1260 dprintk(verbose
, MB86A16_INFO
, 1, " Start Freq Error Check");
1267 if (S01T_set(state
, S1T
, S0T
) < 0) {
1268 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1271 smrt_info_get(state
, state
->srate
);
1272 if (smrt_set(state
, state
->srate
) < 0) {
1273 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1276 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1277 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1280 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1281 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1284 afcex_info_get(state
, afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1285 if (afcofs_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1286 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCOFS data set error");
1289 if (srst(state
) < 0) {
1290 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1294 wait_t
= 200000 / state
->master_clk
+ 200000 / state
->srate
;
1296 afcerr
= afcerr_chk(state
);
1300 swp_freq
= fOSC
* 1000 + afcerr
;
1302 if (state
->srate
>= 1500)
1303 smrt_d
= state
->srate
/ 3;
1305 smrt_d
= state
->srate
/ 2;
1306 smrt_info_get(state
, smrt_d
);
1307 if (smrt_set(state
, smrt_d
) < 0) {
1308 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1311 if (AFCEXEN_set(state
, AFCEXEN
, smrt_d
) < 0) {
1312 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1315 R
= vco_dev_get(state
, smrt_d
);
1316 if (DAGC_data_set(state
, 2, 0) < 0) {
1317 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1320 for (i
= 0; i
< 3; i
++) {
1321 temp_freq
= swp_freq
+ (i
- 1) * state
->srate
/ 8;
1322 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1323 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1324 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1327 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1328 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1331 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1333 dagcm
[i
] = dagcm_val_get(state
);
1335 if ((dagcm
[0] > dagcm
[1]) &&
1336 (dagcm
[0] > dagcm
[2]) &&
1337 (dagcm
[0] - dagcm
[1] > 2 * (dagcm
[2] - dagcm
[1]))) {
1339 temp_freq
= swp_freq
- 2 * state
->srate
/ 8;
1340 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1341 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1342 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1345 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1346 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set");
1349 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1351 dagcm
[3] = dagcm_val_get(state
);
1352 if (dagcm
[3] > dagcm
[1])
1353 delta_freq
= (dagcm
[2] - dagcm
[0] + dagcm
[1] - dagcm
[3]) * state
->srate
/ 300;
1356 } else if ((dagcm
[2] > dagcm
[1]) &&
1357 (dagcm
[2] > dagcm
[0]) &&
1358 (dagcm
[2] - dagcm
[1] > 2 * (dagcm
[0] - dagcm
[1]))) {
1360 temp_freq
= swp_freq
+ 2 * state
->srate
/ 8;
1361 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1362 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1363 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set");
1366 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1367 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set");
1370 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1372 dagcm
[3] = dagcm_val_get(state
);
1373 if (dagcm
[3] > dagcm
[1])
1374 delta_freq
= (dagcm
[2] - dagcm
[0] + dagcm
[3] - dagcm
[1]) * state
->srate
/ 300;
1381 dprintk(verbose
, MB86A16_INFO
, 1, "SWEEP Frequency = %d", swp_freq
);
1382 swp_freq
+= delta_freq
;
1383 dprintk(verbose
, MB86A16_INFO
, 1, "Adjusting .., DELTA Freq = %d, SWEEP Freq=%d", delta_freq
, swp_freq
);
1384 if (ABS(state
->frequency
* 1000 - swp_freq
) > 3800) {
1385 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL !");
1394 if (S01T_set(state
, S1T
, S0T
) < 0) {
1395 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1398 if (DAGC_data_set(state
, 0, 0) < 0) {
1399 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1402 R
= vco_dev_get(state
, state
->srate
);
1403 smrt_info_get(state
, state
->srate
);
1404 if (smrt_set(state
, state
->srate
) < 0) {
1405 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1408 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1409 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1412 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1413 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1416 swp_info_get2(state
, state
->srate
, R
, swp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1417 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1418 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1421 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1422 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1425 if (srst(state
) < 0) {
1426 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1429 wait_t
= 7 + (10000 + state
->srate
/ 2) / state
->srate
;
1432 msleep_interruptible(wait_t
);
1433 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1434 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1439 S2T
= 4; S4T
= 1; S5T
= 6; ETH
= 4; VIA
= 6;
1440 wait_t
= 7 + (917504 + state
->srate
/ 2) / state
->srate
;
1441 } else if (SIG1
> 105) {
1442 S2T
= 4; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1443 wait_t
= 7 + (1048576 + state
->srate
/ 2) / state
->srate
;
1444 } else if (SIG1
> 85) {
1445 S2T
= 5; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1446 wait_t
= 7 + (1310720 + state
->srate
/ 2) / state
->srate
;
1447 } else if (SIG1
> 65) {
1448 S2T
= 6; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1449 wait_t
= 7 + (1572864 + state
->srate
/ 2) / state
->srate
;
1451 S2T
= 7; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1452 wait_t
= 7 + (2097152 + state
->srate
/ 2) / state
->srate
;
1454 wait_t
*= 2; /* FOS */
1455 S2T_set(state
, S2T
);
1456 S45T_set(state
, S4T
, S5T
);
1457 Vi_set(state
, ETH
, VIA
);
1459 msleep_interruptible(wait_t
);
1460 sync
= sync_chk(state
, &VIRM
);
1461 dprintk(verbose
, MB86A16_INFO
, 1, "-------- Viterbi=[%d] SYNC=[%d] ---------", VIRM
, sync
);
1466 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1468 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1469 if (state
->srate
< 5000)
1470 /* FIXME ! , should be a long wait ! */
1471 msleep_interruptible(wait_t
);
1473 msleep_interruptible(wait_t
);
1475 if (sync_chk(state
, &junk
) == 0) {
1476 iq_vt_set(state
, 1);
1480 /* 1/2, 2/3, 3/4, 7/8 */
1482 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1484 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1485 msleep_interruptible(wait_t
);
1488 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SYNC");
1494 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL");
1498 sync
= sync_chk(state
, &junk
);
1500 dprintk(verbose
, MB86A16_INFO
, 1, "******* SYNC *******");
1501 freqerr_chk(state
, state
->frequency
, state
->srate
, 1);
1507 mb86a16_read(state
, 0x15, &agcval
);
1508 mb86a16_read(state
, 0x26, &cnmval
);
1509 dprintk(verbose
, MB86A16_INFO
, 1, "AGC = %02x CNM = %02x", agcval
, cnmval
);
1514 static int mb86a16_send_diseqc_msg(struct dvb_frontend
*fe
,
1515 struct dvb_diseqc_master_cmd
*cmd
)
1517 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1521 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1523 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1525 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1530 if (cmd
->msg_len
> 5 || cmd
->msg_len
< 4)
1533 for (i
= 0; i
< cmd
->msg_len
; i
++) {
1534 if (mb86a16_write(state
, regs
, cmd
->msg
[i
]) < 0)
1541 msleep_interruptible(10);
1543 if (mb86a16_write(state
, MB86A16_DCC1
, i
) < 0)
1545 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1551 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1555 static int mb86a16_send_diseqc_burst(struct dvb_frontend
*fe
,
1556 enum fe_sec_mini_cmd burst
)
1558 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1562 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1564 MB86A16_DCC1_TBO
) < 0)
1566 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1570 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1571 MB86A16_DCC1_TBEN
) < 0)
1573 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1580 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1584 static int mb86a16_set_tone(struct dvb_frontend
*fe
, enum fe_sec_tone_mode tone
)
1586 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1590 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x00) < 0)
1592 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1593 MB86A16_DCC1_CTOE
) < 0)
1596 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1600 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1602 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1604 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1613 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1617 static enum dvbfe_search
mb86a16_search(struct dvb_frontend
*fe
)
1619 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1620 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1622 state
->frequency
= p
->frequency
/ 1000;
1623 state
->srate
= p
->symbol_rate
/ 1000;
1625 if (!mb86a16_set_fe(state
)) {
1626 dprintk(verbose
, MB86A16_ERROR
, 1, "Successfully acquired LOCK");
1627 return DVBFE_ALGO_SEARCH_SUCCESS
;
1630 dprintk(verbose
, MB86A16_ERROR
, 1, "Lock acquisition failed!");
1631 return DVBFE_ALGO_SEARCH_FAILED
;
1634 static void mb86a16_release(struct dvb_frontend
*fe
)
1636 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1640 static int mb86a16_init(struct dvb_frontend
*fe
)
1645 static int mb86a16_sleep(struct dvb_frontend
*fe
)
1650 static int mb86a16_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1652 u8 ber_mon
, ber_tab
, ber_lsb
, ber_mid
, ber_msb
, ber_tim
, ber_rst
;
1655 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1658 if (mb86a16_read(state
, MB86A16_BERMON
, &ber_mon
) != 2)
1660 if (mb86a16_read(state
, MB86A16_BERTAB
, &ber_tab
) != 2)
1662 if (mb86a16_read(state
, MB86A16_BERLSB
, &ber_lsb
) != 2)
1664 if (mb86a16_read(state
, MB86A16_BERMID
, &ber_mid
) != 2)
1666 if (mb86a16_read(state
, MB86A16_BERMSB
, &ber_msb
) != 2)
1668 /* BER monitor invalid when BER_EN = 0 */
1669 if (ber_mon
& 0x04) {
1670 /* coarse, fast calculation */
1671 *ber
= ber_tab
& 0x1f;
1672 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER coarse=[0x%02x]", *ber
);
1673 if (ber_mon
& 0x01) {
1675 * BER_SEL = 1, The monitored BER is the estimated
1676 * value with a Reed-Solomon decoder error amount at
1677 * the deinterleaver output.
1678 * monitored BER is expressed as a 20 bit output in total
1680 ber_rst
= (ber_mon
>> 3) & 0x03;
1681 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1684 else if (ber_rst
== 1)
1686 else if (ber_rst
== 2)
1688 else /* ber_rst == 3 */
1692 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1695 * BER_SEL = 0, The monitored BER is the estimated
1696 * value with a Viterbi decoder error amount at the
1697 * QPSK demodulator output.
1698 * monitored BER is expressed as a 24 bit output in total
1700 ber_tim
= (ber_mon
>> 1) & 0x01;
1701 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1704 else /* ber_tim == 1 */
1708 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1713 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1717 static int mb86a16_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
1720 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1723 if (mb86a16_read(state
, MB86A16_AGCM
, &agcm
) != 2) {
1724 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1728 *strength
= ((0xff - agcm
) * 100) / 256;
1729 dprintk(verbose
, MB86A16_DEBUG
, 1, "Signal strength=[%d %%]", (u8
) *strength
);
1730 *strength
= (0xffff - 0xff) + agcm
;
1740 static const struct cnr cnr_tab
[] = {
1764 static int mb86a16_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1766 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1768 int low_tide
= 2, high_tide
= 30, q_level
;
1772 if (mb86a16_read(state
, 0x26, &cn
) != 2) {
1773 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1777 for (i
= 0; i
< ARRAY_SIZE(cnr_tab
); i
++) {
1778 if (cn
< cnr_tab
[i
].cn_reg
) {
1779 *snr
= cnr_tab
[i
].cn_val
;
1783 q_level
= (*snr
* 100) / (high_tide
- low_tide
);
1784 dprintk(verbose
, MB86A16_ERROR
, 1, "SNR (Quality) = [%d dB], Level=%d %%", *snr
, q_level
);
1785 *snr
= (0xffff - 0xff) + *snr
;
1790 static int mb86a16_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
1793 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1795 if (mb86a16_read(state
, MB86A16_DISTMON
, &dist
) != 2) {
1796 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1804 static enum dvbfe_algo
mb86a16_frontend_algo(struct dvb_frontend
*fe
)
1806 return DVBFE_ALGO_CUSTOM
;
1809 static const struct dvb_frontend_ops mb86a16_ops
= {
1810 .delsys
= { SYS_DVBS
},
1812 .name
= "Fujitsu MB86A16 DVB-S",
1813 .frequency_min
= 950000,
1814 .frequency_max
= 2150000,
1815 .frequency_stepsize
= 3000,
1816 .frequency_tolerance
= 0,
1817 .symbol_rate_min
= 1000000,
1818 .symbol_rate_max
= 45000000,
1819 .symbol_rate_tolerance
= 500,
1820 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
|
1821 FE_CAN_FEC_3_4
| FE_CAN_FEC_5_6
|
1822 FE_CAN_FEC_7_8
| FE_CAN_QPSK
|
1825 .release
= mb86a16_release
,
1827 .get_frontend_algo
= mb86a16_frontend_algo
,
1828 .search
= mb86a16_search
,
1829 .init
= mb86a16_init
,
1830 .sleep
= mb86a16_sleep
,
1831 .read_status
= mb86a16_read_status
,
1833 .read_ber
= mb86a16_read_ber
,
1834 .read_signal_strength
= mb86a16_read_signal_strength
,
1835 .read_snr
= mb86a16_read_snr
,
1836 .read_ucblocks
= mb86a16_read_ucblocks
,
1838 .diseqc_send_master_cmd
= mb86a16_send_diseqc_msg
,
1839 .diseqc_send_burst
= mb86a16_send_diseqc_burst
,
1840 .set_tone
= mb86a16_set_tone
,
1843 struct dvb_frontend
*mb86a16_attach(const struct mb86a16_config
*config
,
1844 struct i2c_adapter
*i2c_adap
)
1847 struct mb86a16_state
*state
= NULL
;
1849 state
= kmalloc(sizeof(struct mb86a16_state
), GFP_KERNEL
);
1853 state
->config
= config
;
1854 state
->i2c_adap
= i2c_adap
;
1856 mb86a16_read(state
, 0x7f, &dev_id
);
1860 memcpy(&state
->frontend
.ops
, &mb86a16_ops
, sizeof(struct dvb_frontend_ops
));
1861 state
->frontend
.demodulator_priv
= state
;
1862 state
->frontend
.ops
.set_voltage
= state
->config
->set_voltage
;
1864 return &state
->frontend
;
1869 EXPORT_SYMBOL(mb86a16_attach
);
1870 MODULE_LICENSE("GPL");
1871 MODULE_AUTHOR("Manu Abraham");