1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Fujitsu MB86A16 DVB-S/DSS DC Receiver driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/slab.h>
15 #include <media/dvb_frontend.h>
17 #include "mb86a16_priv.h"
19 static unsigned int verbose
= 5;
20 module_param(verbose
, int, 0644);
22 struct mb86a16_state
{
23 struct i2c_adapter
*i2c_adap
;
24 const struct mb86a16_config
*config
;
25 struct dvb_frontend frontend
;
27 /* tuning parameters */
38 #define MB86A16_ERROR 0
39 #define MB86A16_NOTICE 1
40 #define MB86A16_INFO 2
41 #define MB86A16_DEBUG 3
43 #define dprintk(x, y, z, format, arg...) do { \
45 if ((x > MB86A16_ERROR) && (x > y)) \
46 printk(KERN_ERR "%s: " format "\n", __func__, ##arg); \
47 else if ((x > MB86A16_NOTICE) && (x > y)) \
48 printk(KERN_NOTICE "%s: " format "\n", __func__, ##arg); \
49 else if ((x > MB86A16_INFO) && (x > y)) \
50 printk(KERN_INFO "%s: " format "\n", __func__, ##arg); \
51 else if ((x > MB86A16_DEBUG) && (x > y)) \
52 printk(KERN_DEBUG "%s: " format "\n", __func__, ##arg); \
55 printk(format, ##arg); \
59 #define TRACE_IN dprintk(verbose, MB86A16_DEBUG, 1, "-->()")
60 #define TRACE_OUT dprintk(verbose, MB86A16_DEBUG, 1, "()-->")
62 static int mb86a16_write(struct mb86a16_state
*state
, u8 reg
, u8 val
)
65 u8 buf
[] = { reg
, val
};
67 struct i2c_msg msg
= {
68 .addr
= state
->config
->demod_address
,
74 dprintk(verbose
, MB86A16_DEBUG
, 1,
75 "writing to [0x%02x],Reg[0x%02x],Data[0x%02x]",
76 state
->config
->demod_address
, buf
[0], buf
[1]);
78 ret
= i2c_transfer(state
->i2c_adap
, &msg
, 1);
80 return (ret
!= 1) ? -EREMOTEIO
: 0;
83 static int mb86a16_read(struct mb86a16_state
*state
, u8 reg
, u8
*val
)
89 struct i2c_msg msg
[] = {
91 .addr
= state
->config
->demod_address
,
96 .addr
= state
->config
->demod_address
,
102 ret
= i2c_transfer(state
->i2c_adap
, msg
, 2);
104 dprintk(verbose
, MB86A16_ERROR
, 1, "read error(reg=0x%02x, ret=%i)",
116 static int CNTM_set(struct mb86a16_state
*state
,
117 unsigned char timint1
,
118 unsigned char timint2
,
123 val
= (timint1
<< 4) | (timint2
<< 2) | cnext
;
124 if (mb86a16_write(state
, MB86A16_CNTMR
, val
) < 0)
130 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
134 static int smrt_set(struct mb86a16_state
*state
, int rate
)
138 unsigned char STOFS0
, STOFS1
;
140 m
= 1 << state
->deci
;
141 tmp
= (8192 * state
->master_clk
- 2 * m
* rate
* 8192 + state
->master_clk
/ 2) / state
->master_clk
;
143 STOFS0
= tmp
& 0x0ff;
144 STOFS1
= (tmp
& 0xf00) >> 8;
146 if (mb86a16_write(state
, MB86A16_SRATE1
, (state
->deci
<< 2) |
150 if (mb86a16_write(state
, MB86A16_SRATE2
, STOFS0
) < 0)
152 if (mb86a16_write(state
, MB86A16_SRATE3
, STOFS1
) < 0)
157 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
161 static int srst(struct mb86a16_state
*state
)
163 if (mb86a16_write(state
, MB86A16_RESET
, 0x04) < 0)
168 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
173 static int afcex_data_set(struct mb86a16_state
*state
,
174 unsigned char AFCEX_L
,
175 unsigned char AFCEX_H
)
177 if (mb86a16_write(state
, MB86A16_AFCEXL
, AFCEX_L
) < 0)
179 if (mb86a16_write(state
, MB86A16_AFCEXH
, AFCEX_H
) < 0)
184 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
189 static int afcofs_data_set(struct mb86a16_state
*state
,
190 unsigned char AFCEX_L
,
191 unsigned char AFCEX_H
)
193 if (mb86a16_write(state
, 0x58, AFCEX_L
) < 0)
195 if (mb86a16_write(state
, 0x59, AFCEX_H
) < 0)
200 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
204 static int stlp_set(struct mb86a16_state
*state
,
208 if (mb86a16_write(state
, MB86A16_STRFILTCOEF1
, (STRBS
<< 3) | (STRAS
)) < 0)
213 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
217 static int Vi_set(struct mb86a16_state
*state
, unsigned char ETH
, unsigned char VIA
)
219 if (mb86a16_write(state
, MB86A16_VISET2
, 0x04) < 0)
221 if (mb86a16_write(state
, MB86A16_VISET3
, 0xf5) < 0)
226 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
230 static int initial_set(struct mb86a16_state
*state
)
232 if (stlp_set(state
, 5, 7))
236 if (afcex_data_set(state
, 0, 0))
240 if (afcofs_data_set(state
, 0, 0))
244 if (mb86a16_write(state
, MB86A16_CRLFILTCOEF1
, 0x16) < 0)
246 if (mb86a16_write(state
, 0x2f, 0x21) < 0)
248 if (mb86a16_write(state
, MB86A16_VIMAG
, 0x38) < 0)
250 if (mb86a16_write(state
, MB86A16_FAGCS1
, 0x00) < 0)
252 if (mb86a16_write(state
, MB86A16_FAGCS2
, 0x1c) < 0)
254 if (mb86a16_write(state
, MB86A16_FAGCS3
, 0x20) < 0)
256 if (mb86a16_write(state
, MB86A16_FAGCS4
, 0x1e) < 0)
258 if (mb86a16_write(state
, MB86A16_FAGCS5
, 0x23) < 0)
260 if (mb86a16_write(state
, 0x54, 0xff) < 0)
262 if (mb86a16_write(state
, MB86A16_TSOUT
, 0x00) < 0)
268 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
272 static int S01T_set(struct mb86a16_state
*state
,
276 if (mb86a16_write(state
, 0x33, (s1t
<< 3) | s0t
) < 0)
281 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
286 static int EN_set(struct mb86a16_state
*state
,
292 val
= 0x7a | (cren
<< 7) | (afcen
<< 2);
293 if (mb86a16_write(state
, 0x49, val
) < 0)
298 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
302 static int AFCEXEN_set(struct mb86a16_state
*state
,
310 else if (smrt
> 9375)
312 else if (smrt
> 2250)
317 if (mb86a16_write(state
, 0x2a, 0x02 | (afcexen
<< 5) | (AFCA
<< 2)) < 0)
323 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
327 static int DAGC_data_set(struct mb86a16_state
*state
,
331 if (mb86a16_write(state
, 0x2d, (DAGCA
<< 3) | DAGCW
) < 0)
337 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
341 static void smrt_info_get(struct mb86a16_state
*state
, int rate
)
344 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 0;
345 } else if (rate
>= 30001) {
346 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 1;
347 } else if (rate
>= 26251) {
348 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 0;
349 } else if (rate
>= 22501) {
350 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 1;
351 } else if (rate
>= 18751) {
352 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 0;
353 } else if (rate
>= 15001) {
354 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 1;
355 } else if (rate
>= 13126) {
356 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 0;
357 } else if (rate
>= 11251) {
358 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 1;
359 } else if (rate
>= 9376) {
360 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 0;
361 } else if (rate
>= 7501) {
362 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 1;
363 } else if (rate
>= 6563) {
364 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 0;
365 } else if (rate
>= 5626) {
366 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 1;
367 } else if (rate
>= 4688) {
368 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 0;
369 } else if (rate
>= 3751) {
370 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 1;
371 } else if (rate
>= 3282) {
372 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 0;
373 } else if (rate
>= 2814) {
374 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 1;
375 } else if (rate
>= 2344) {
376 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 0;
377 } else if (rate
>= 1876) {
378 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 1;
379 } else if (rate
>= 1641) {
380 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 0;
381 } else if (rate
>= 1407) {
382 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 1;
383 } else if (rate
>= 1172) {
384 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 0;
385 } else if (rate
>= 939) {
386 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 1;
387 } else if (rate
>= 821) {
388 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 0;
390 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 1;
393 if (state
->csel
== 0)
394 state
->master_clk
= 92000;
396 state
->master_clk
= 61333;
400 static int signal_det(struct mb86a16_state
*state
,
410 if (CNTM_set(state
, 2, 1, 2) < 0) {
411 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
415 if (CNTM_set(state
, 3, 1, 2) < 0) {
416 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
420 for (i
= 0; i
< 3; i
++) {
422 smrtd
= smrt
* 98 / 100;
426 smrtd
= smrt
* 102 / 100;
427 smrt_info_get(state
, smrtd
);
428 smrt_set(state
, smrtd
);
430 msleep_interruptible(10);
431 if (mb86a16_read(state
, 0x37, &(S
[i
])) != 2) {
432 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
436 if ((S
[1] > S
[0] * 112 / 100) && (S
[1] > S
[2] * 112 / 100))
443 if (CNTM_set(state
, 0, 1, 2) < 0) {
444 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
451 static int rf_val_set(struct mb86a16_state
*state
,
456 unsigned char C
, F
, B
;
458 unsigned char rf_val
[5];
463 else if (smrt
> 18875)
465 else if (smrt
> 5500)
472 else if (smrt
> 9375)
474 else if (smrt
> 4625)
500 M
= f
* (1 << R
) / 2;
502 rf_val
[0] = 0x01 | (C
<< 3) | (F
<< 1);
503 rf_val
[1] = (R
<< 5) | ((M
& 0x1f000) >> 12);
504 rf_val
[2] = (M
& 0x00ff0) >> 4;
505 rf_val
[3] = ((M
& 0x0000f) << 4) | B
;
508 if (mb86a16_write(state
, 0x21, rf_val
[0]) < 0)
510 if (mb86a16_write(state
, 0x22, rf_val
[1]) < 0)
512 if (mb86a16_write(state
, 0x23, rf_val
[2]) < 0)
514 if (mb86a16_write(state
, 0x24, rf_val
[3]) < 0)
516 if (mb86a16_write(state
, 0x25, 0x01) < 0)
519 dprintk(verbose
, MB86A16_ERROR
, 1, "RF Setup - I2C transfer error");
526 static int afcerr_chk(struct mb86a16_state
*state
)
528 unsigned char AFCM_L
, AFCM_H
;
532 if (mb86a16_read(state
, 0x0e, &AFCM_L
) != 2)
534 if (mb86a16_read(state
, 0x0f, &AFCM_H
) != 2)
537 AFCM
= (AFCM_H
<< 8) + AFCM_L
;
543 afcerr
= afcm
* state
->master_clk
/ 8192;
548 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
552 static int dagcm_val_get(struct mb86a16_state
*state
)
555 unsigned char DAGCM_H
, DAGCM_L
;
557 if (mb86a16_read(state
, 0x45, &DAGCM_L
) != 2)
559 if (mb86a16_read(state
, 0x46, &DAGCM_H
) != 2)
562 DAGCM
= (DAGCM_H
<< 8) + DAGCM_L
;
567 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
571 static int mb86a16_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
574 struct mb86a16_state
*state
= fe
->demodulator_priv
;
578 if (mb86a16_read(state
, MB86A16_SIG1
, &stat
) != 2)
580 if (mb86a16_read(state
, MB86A16_SIG2
, &stat2
) != 2)
582 if ((stat
> 25) && (stat2
> 25))
583 *status
|= FE_HAS_SIGNAL
;
584 if ((stat
> 45) && (stat2
> 45))
585 *status
|= FE_HAS_CARRIER
;
587 if (mb86a16_read(state
, MB86A16_STATUS
, &stat
) != 2)
591 *status
|= FE_HAS_SYNC
;
593 *status
|= FE_HAS_VITERBI
;
595 if (mb86a16_read(state
, MB86A16_FRAMESYNC
, &stat
) != 2)
598 if ((stat
& 0x0f) && (*status
& FE_HAS_VITERBI
))
599 *status
|= FE_HAS_LOCK
;
604 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
608 static int sync_chk(struct mb86a16_state
*state
,
614 if (mb86a16_read(state
, 0x0d, &val
) != 2)
617 dprintk(verbose
, MB86A16_INFO
, 1, "Status = %02x,", val
);
619 *VIRM
= (val
& 0x1c) >> 2;
623 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
629 static int freqerr_chk(struct mb86a16_state
*state
,
634 unsigned char CRM
, AFCML
, AFCMH
;
635 unsigned char temp1
, temp2
, temp3
;
637 int crrerr
, afcerr
; /* kHz */
638 int frqerr
; /* MHz */
639 int afcen
, afcexen
= 0;
640 int R
, M
, fOSC
, fOSC_OFS
;
642 if (mb86a16_read(state
, 0x43, &CRM
) != 2)
650 crrerr
= smrt
* crm
/ 256;
651 if (mb86a16_read(state
, 0x49, &temp1
) != 2)
654 afcen
= (temp1
& 0x04) >> 2;
656 if (mb86a16_read(state
, 0x2a, &temp1
) != 2)
658 afcexen
= (temp1
& 0x20) >> 5;
662 if (mb86a16_read(state
, 0x0e, &AFCML
) != 2)
664 if (mb86a16_read(state
, 0x0f, &AFCMH
) != 2)
666 } else if (afcexen
== 1) {
667 if (mb86a16_read(state
, 0x2b, &AFCML
) != 2)
669 if (mb86a16_read(state
, 0x2c, &AFCMH
) != 2)
672 if ((afcen
== 1) || (afcexen
== 1)) {
673 smrt_info_get(state
, smrt
);
674 AFCM
= ((AFCMH
& 0x01) << 8) + AFCML
;
680 afcerr
= afcm
* state
->master_clk
/ 8192;
684 if (mb86a16_read(state
, 0x22, &temp1
) != 2)
686 if (mb86a16_read(state
, 0x23, &temp2
) != 2)
688 if (mb86a16_read(state
, 0x24, &temp3
) != 2)
691 R
= (temp1
& 0xe0) >> 5;
692 M
= ((temp1
& 0x1f) << 12) + (temp2
<< 4) + (temp3
>> 4);
698 fOSC_OFS
= fOSC
- fTP
;
700 if (unit
== 0) { /* MHz */
701 if (crrerr
+ afcerr
+ fOSC_OFS
* 1000 >= 0)
702 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 + 500) / 1000;
704 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 - 500) / 1000;
706 frqerr
= crrerr
+ afcerr
+ fOSC_OFS
* 1000;
711 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
715 static unsigned char vco_dev_get(struct mb86a16_state
*state
, int smrt
)
727 static void swp_info_get(struct mb86a16_state
*state
,
734 unsigned char *AFCEX_L
,
735 unsigned char *AFCEX_H
)
740 crnt_swp_freq
= fOSC_start
* 1000 + v
* swp_ofs
;
743 *fOSC
= (crnt_swp_freq
+ 1000) / 2000 * 2;
745 *fOSC
= (crnt_swp_freq
+ 500) / 1000;
747 if (*fOSC
>= crnt_swp_freq
)
748 *afcex_freq
= *fOSC
* 1000 - crnt_swp_freq
;
750 *afcex_freq
= crnt_swp_freq
- *fOSC
* 1000;
752 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
753 *AFCEX_L
= AFCEX
& 0x00ff;
754 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
758 static int swp_freq_calcuation(struct mb86a16_state
*state
, int i
, int v
, int *V
, int vmax
, int vmin
,
759 int SIGMIN
, int fOSC
, int afcex_freq
, int swp_ofs
, unsigned char *SIG1
)
763 if ((i
% 2 == 1) && (v
<= vmax
)) {
764 /* positive v (case 1) */
765 if ((v
- 1 == vmin
) &&
766 (*(V
+ 30 + v
) >= 0) &&
767 (*(V
+ 30 + v
- 1) >= 0) &&
768 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
769 (*(V
+ 30 + v
- 1) > SIGMIN
)) {
771 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
772 *SIG1
= *(V
+ 30 + v
- 1);
773 } else if ((v
== vmax
) &&
774 (*(V
+ 30 + v
) >= 0) &&
775 (*(V
+ 30 + v
- 1) >= 0) &&
776 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 1)) &&
777 (*(V
+ 30 + v
) > SIGMIN
)) {
779 swp_freq
= fOSC
* 1000 + afcex_freq
;
780 *SIG1
= *(V
+ 30 + v
);
781 } else if ((*(V
+ 30 + v
) > 0) &&
782 (*(V
+ 30 + v
- 1) > 0) &&
783 (*(V
+ 30 + v
- 2) > 0) &&
784 (*(V
+ 30 + v
- 3) > 0) &&
785 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
786 (*(V
+ 30 + v
- 2) > *(V
+ 30 + v
- 3)) &&
787 ((*(V
+ 30 + v
- 1) > SIGMIN
) ||
788 (*(V
+ 30 + v
- 2) > SIGMIN
))) {
790 if (*(V
+ 30 + v
- 1) >= *(V
+ 30 + v
- 2)) {
791 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
792 *SIG1
= *(V
+ 30 + v
- 1);
794 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
* 2;
795 *SIG1
= *(V
+ 30 + v
- 2);
797 } else if ((v
== vmax
) &&
798 (*(V
+ 30 + v
) >= 0) &&
799 (*(V
+ 30 + v
- 1) >= 0) &&
800 (*(V
+ 30 + v
- 2) >= 0) &&
801 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 2)) &&
802 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
- 2)) &&
803 ((*(V
+ 30 + v
) > SIGMIN
) ||
804 (*(V
+ 30 + v
- 1) > SIGMIN
))) {
806 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
- 1)) {
807 swp_freq
= fOSC
* 1000 + afcex_freq
;
808 *SIG1
= *(V
+ 30 + v
);
810 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
811 *SIG1
= *(V
+ 30 + v
- 1);
816 } else if ((i
% 2 == 0) && (v
>= vmin
)) {
817 /* Negative v (case 1) */
818 if ((*(V
+ 30 + v
) > 0) &&
819 (*(V
+ 30 + v
+ 1) > 0) &&
820 (*(V
+ 30 + v
+ 2) > 0) &&
821 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
822 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
823 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
825 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
826 *SIG1
= *(V
+ 30 + v
+ 1);
827 } else if ((v
+ 1 == vmax
) &&
828 (*(V
+ 30 + v
) >= 0) &&
829 (*(V
+ 30 + v
+ 1) >= 0) &&
830 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
831 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
833 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
834 *SIG1
= *(V
+ 30 + v
);
835 } else if ((v
== vmin
) &&
836 (*(V
+ 30 + v
) > 0) &&
837 (*(V
+ 30 + v
+ 1) > 0) &&
838 (*(V
+ 30 + v
+ 2) > 0) &&
839 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 1)) &&
840 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
841 (*(V
+ 30 + v
) > SIGMIN
)) {
843 swp_freq
= fOSC
* 1000 + afcex_freq
;
844 *SIG1
= *(V
+ 30 + v
);
845 } else if ((*(V
+ 30 + v
) >= 0) &&
846 (*(V
+ 30 + v
+ 1) >= 0) &&
847 (*(V
+ 30 + v
+ 2) >= 0) &&
848 (*(V
+ 30 + v
+ 3) >= 0) &&
849 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
850 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
+ 3)) &&
851 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
852 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
854 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
855 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
856 *SIG1
= *(V
+ 30 + v
+ 1);
858 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
859 *SIG1
= *(V
+ 30 + v
+ 2);
861 } else if ((*(V
+ 30 + v
) >= 0) &&
862 (*(V
+ 30 + v
+ 1) >= 0) &&
863 (*(V
+ 30 + v
+ 2) >= 0) &&
864 (*(V
+ 30 + v
+ 3) >= 0) &&
865 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
866 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
867 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 3)) &&
868 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 3)) &&
869 ((*(V
+ 30 + v
) > SIGMIN
) ||
870 (*(V
+ 30 + v
+ 1) > SIGMIN
))) {
872 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
+ 1)) {
873 swp_freq
= fOSC
* 1000 + afcex_freq
;
874 *SIG1
= *(V
+ 30 + v
);
876 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
877 *SIG1
= *(V
+ 30 + v
+ 1);
879 } else if ((v
+ 2 == vmin
) &&
880 (*(V
+ 30 + v
) >= 0) &&
881 (*(V
+ 30 + v
+ 1) >= 0) &&
882 (*(V
+ 30 + v
+ 2) >= 0) &&
883 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
884 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
)) &&
885 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
886 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
888 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
889 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
890 *SIG1
= *(V
+ 30 + v
+ 1);
892 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
893 *SIG1
= *(V
+ 30 + v
+ 2);
895 } else if ((vmax
== 0) && (vmin
== 0) && (*(V
+ 30 + v
) > SIGMIN
)) {
896 swp_freq
= fOSC
* 1000;
897 *SIG1
= *(V
+ 30 + v
);
906 static void swp_info_get2(struct mb86a16_state
*state
,
912 unsigned char *AFCEX_L
,
913 unsigned char *AFCEX_H
)
918 *fOSC
= (swp_freq
+ 1000) / 2000 * 2;
920 *fOSC
= (swp_freq
+ 500) / 1000;
922 if (*fOSC
>= swp_freq
)
923 *afcex_freq
= *fOSC
* 1000 - swp_freq
;
925 *afcex_freq
= swp_freq
- *fOSC
* 1000;
927 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
928 *AFCEX_L
= AFCEX
& 0x00ff;
929 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
932 static void afcex_info_get(struct mb86a16_state
*state
,
934 unsigned char *AFCEX_L
,
935 unsigned char *AFCEX_H
)
939 AFCEX
= afcex_freq
* 8192 / state
->master_clk
;
940 *AFCEX_L
= AFCEX
& 0x00ff;
941 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
944 static int SEQ_set(struct mb86a16_state
*state
, unsigned char loop
)
947 if (mb86a16_write(state
, 0x32, 0x02 | (loop
<< 2)) < 0) {
948 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
955 static int iq_vt_set(struct mb86a16_state
*state
, unsigned char IQINV
)
957 /* Viterbi Rate, IQ Settings */
958 if (mb86a16_write(state
, 0x06, 0xdf | (IQINV
<< 5)) < 0) {
959 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
966 static int FEC_srst(struct mb86a16_state
*state
)
968 if (mb86a16_write(state
, MB86A16_RESET
, 0x02) < 0) {
969 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
976 static int S2T_set(struct mb86a16_state
*state
, unsigned char S2T
)
978 if (mb86a16_write(state
, 0x34, 0x70 | S2T
) < 0) {
979 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
986 static int S45T_set(struct mb86a16_state
*state
, unsigned char S4T
, unsigned char S5T
)
988 if (mb86a16_write(state
, 0x35, 0x00 | (S5T
<< 4) | S4T
) < 0) {
989 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
997 static int mb86a16_set_fe(struct mb86a16_state
*state
)
1010 unsigned char CREN
, AFCEN
, AFCEXEN
;
1012 unsigned char TIMINT1
, TIMINT2
, TIMEXT
;
1013 unsigned char S0T
, S1T
;
1015 /* unsigned char S2T, S3T; */
1016 unsigned char S4T
, S5T
;
1017 unsigned char AFCEX_L
, AFCEX_H
;
1020 unsigned char ETH
, VIA
;
1026 int vmax_his
, vmin_his
;
1027 int swp_freq
, prev_swp_freq
[20];
1033 int temp_freq
, delta_freq
;
1041 dprintk(verbose
, MB86A16_INFO
, 1, "freq=%d Mhz, symbrt=%d Ksps", state
->frequency
, state
->srate
);
1044 swp_ofs
= state
->srate
/ 4;
1046 for (i
= 0; i
< 60; i
++)
1049 for (i
= 0; i
< 20; i
++)
1050 prev_swp_freq
[i
] = 0;
1054 for (n
= 0; ((n
< 3) && (ret
== -1)); n
++) {
1056 iq_vt_set(state
, 0);
1067 if (initial_set(state
) < 0) {
1068 dprintk(verbose
, MB86A16_ERROR
, 1, "initial set failed");
1071 if (DAGC_data_set(state
, 3, 2) < 0) {
1072 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1075 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1076 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1077 return -1; /* (0, 0) */
1079 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1080 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1081 return -1; /* (1, smrt) = (1, symbolrate) */
1083 if (CNTM_set(state
, TIMINT1
, TIMINT2
, TIMEXT
) < 0) {
1084 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set error");
1085 return -1; /* (0, 1, 2) */
1087 if (S01T_set(state
, S1T
, S0T
) < 0) {
1088 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1089 return -1; /* (0, 0) */
1091 smrt_info_get(state
, state
->srate
);
1092 if (smrt_set(state
, state
->srate
) < 0) {
1093 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt info get error");
1097 R
= vco_dev_get(state
, state
->srate
);
1099 fOSC_start
= state
->frequency
;
1102 if (state
->frequency
% 2 == 0) {
1103 fOSC_start
= state
->frequency
;
1105 fOSC_start
= state
->frequency
+ 1;
1106 if (fOSC_start
> 2150)
1107 fOSC_start
= state
->frequency
- 1;
1111 ftemp
= fOSC_start
* 1000;
1114 ftemp
= ftemp
+ swp_ofs
;
1118 if (ftemp
> 2150000) {
1122 if ((ftemp
== 2150000) ||
1123 (ftemp
- state
->frequency
* 1000 >= fcp
+ state
->srate
/ 4))
1129 ftemp
= fOSC_start
* 1000;
1132 ftemp
= ftemp
- swp_ofs
;
1136 if (ftemp
< 950000) {
1140 if ((ftemp
== 950000) ||
1141 (state
->frequency
* 1000 - ftemp
>= fcp
+ state
->srate
/ 4))
1146 wait_t
= (8000 + state
->srate
/ 2) / state
->srate
;
1160 swp_info_get(state
, fOSC_start
, state
->srate
,
1161 v
, R
, swp_ofs
, &fOSC
,
1162 &afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1165 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1166 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1170 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1171 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1174 if (srst(state
) < 0) {
1175 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1178 msleep_interruptible(wait_t
);
1180 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1181 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1185 swp_freq
= swp_freq_calcuation(state
, i
, v
, V
, vmax
, vmin
,
1186 SIG1MIN
, fOSC
, afcex_freq
,
1187 swp_ofs
, &SIG1
); /* changed */
1190 for (j
= 0; j
< prev_freq_num
; j
++) {
1191 if ((abs(prev_swp_freq
[j
] - swp_freq
)) < (swp_ofs
* 3 / 2)) {
1193 dprintk(verbose
, MB86A16_INFO
, 1, "Probably Duplicate Signal, j = %d", j
);
1196 if ((signal_dupl
== 0) && (swp_freq
> 0) && (abs(swp_freq
- state
->frequency
* 1000) < fcp
+ state
->srate
/ 6)) {
1197 dprintk(verbose
, MB86A16_DEBUG
, 1, "------ Signal detect ------ [swp_freq=[%07d, srate=%05d]]", swp_freq
, state
->srate
);
1198 prev_swp_freq
[prev_freq_num
] = swp_freq
;
1200 swp_info_get2(state
, state
->srate
, R
, swp_freq
,
1202 &AFCEX_L
, &AFCEX_H
);
1204 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1205 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1208 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1209 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1212 signal
= signal_det(state
, state
->srate
, &SIG1
);
1214 dprintk(verbose
, MB86A16_ERROR
, 1, "***** Signal Found *****");
1217 dprintk(verbose
, MB86A16_ERROR
, 1, "!!!!! No signal !!!!!, try again...");
1218 smrt_info_get(state
, state
->srate
);
1219 if (smrt_set(state
, state
->srate
) < 0) {
1220 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1231 if ((i
% 2 == 1) && (vmax_his
== 1))
1233 if ((i
% 2 == 0) && (vmin_his
== 1))
1241 if ((vmax_his
== 1) && (vmin_his
== 1))
1246 dprintk(verbose
, MB86A16_INFO
, 1, " Start Freq Error Check");
1253 if (S01T_set(state
, S1T
, S0T
) < 0) {
1254 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1257 smrt_info_get(state
, state
->srate
);
1258 if (smrt_set(state
, state
->srate
) < 0) {
1259 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1262 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1263 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1266 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1267 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1270 afcex_info_get(state
, afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1271 if (afcofs_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1272 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCOFS data set error");
1275 if (srst(state
) < 0) {
1276 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1280 wait_t
= 200000 / state
->master_clk
+ 200000 / state
->srate
;
1282 afcerr
= afcerr_chk(state
);
1286 swp_freq
= fOSC
* 1000 + afcerr
;
1288 if (state
->srate
>= 1500)
1289 smrt_d
= state
->srate
/ 3;
1291 smrt_d
= state
->srate
/ 2;
1292 smrt_info_get(state
, smrt_d
);
1293 if (smrt_set(state
, smrt_d
) < 0) {
1294 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1297 if (AFCEXEN_set(state
, AFCEXEN
, smrt_d
) < 0) {
1298 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1301 R
= vco_dev_get(state
, smrt_d
);
1302 if (DAGC_data_set(state
, 2, 0) < 0) {
1303 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1306 for (i
= 0; i
< 3; i
++) {
1307 temp_freq
= swp_freq
+ (i
- 1) * state
->srate
/ 8;
1308 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1309 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1310 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1313 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1314 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1317 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1319 dagcm
[i
] = dagcm_val_get(state
);
1321 if ((dagcm
[0] > dagcm
[1]) &&
1322 (dagcm
[0] > dagcm
[2]) &&
1323 (dagcm
[0] - dagcm
[1] > 2 * (dagcm
[2] - dagcm
[1]))) {
1325 temp_freq
= swp_freq
- 2 * state
->srate
/ 8;
1326 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1327 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1328 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1331 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1332 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set");
1335 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1337 dagcm
[3] = dagcm_val_get(state
);
1338 if (dagcm
[3] > dagcm
[1])
1339 delta_freq
= (dagcm
[2] - dagcm
[0] + dagcm
[1] - dagcm
[3]) * state
->srate
/ 300;
1342 } else if ((dagcm
[2] > dagcm
[1]) &&
1343 (dagcm
[2] > dagcm
[0]) &&
1344 (dagcm
[2] - dagcm
[1] > 2 * (dagcm
[0] - dagcm
[1]))) {
1346 temp_freq
= swp_freq
+ 2 * state
->srate
/ 8;
1347 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1348 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1349 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set");
1352 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1353 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set");
1356 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1358 dagcm
[3] = dagcm_val_get(state
);
1359 if (dagcm
[3] > dagcm
[1])
1360 delta_freq
= (dagcm
[2] - dagcm
[0] + dagcm
[3] - dagcm
[1]) * state
->srate
/ 300;
1367 dprintk(verbose
, MB86A16_INFO
, 1, "SWEEP Frequency = %d", swp_freq
);
1368 swp_freq
+= delta_freq
;
1369 dprintk(verbose
, MB86A16_INFO
, 1, "Adjusting .., DELTA Freq = %d, SWEEP Freq=%d", delta_freq
, swp_freq
);
1370 if (abs(state
->frequency
* 1000 - swp_freq
) > 3800) {
1371 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL !");
1380 if (S01T_set(state
, S1T
, S0T
) < 0) {
1381 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1384 if (DAGC_data_set(state
, 0, 0) < 0) {
1385 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1388 R
= vco_dev_get(state
, state
->srate
);
1389 smrt_info_get(state
, state
->srate
);
1390 if (smrt_set(state
, state
->srate
) < 0) {
1391 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1394 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1395 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1398 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1399 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1402 swp_info_get2(state
, state
->srate
, R
, swp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1403 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1404 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1407 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1408 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1411 if (srst(state
) < 0) {
1412 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1415 wait_t
= 7 + (10000 + state
->srate
/ 2) / state
->srate
;
1418 msleep_interruptible(wait_t
);
1419 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1420 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1425 S2T
= 4; S4T
= 1; S5T
= 6; ETH
= 4; VIA
= 6;
1426 wait_t
= 7 + (917504 + state
->srate
/ 2) / state
->srate
;
1427 } else if (SIG1
> 105) {
1428 S2T
= 4; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1429 wait_t
= 7 + (1048576 + state
->srate
/ 2) / state
->srate
;
1430 } else if (SIG1
> 85) {
1431 S2T
= 5; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1432 wait_t
= 7 + (1310720 + state
->srate
/ 2) / state
->srate
;
1433 } else if (SIG1
> 65) {
1434 S2T
= 6; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1435 wait_t
= 7 + (1572864 + state
->srate
/ 2) / state
->srate
;
1437 S2T
= 7; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1438 wait_t
= 7 + (2097152 + state
->srate
/ 2) / state
->srate
;
1440 wait_t
*= 2; /* FOS */
1441 S2T_set(state
, S2T
);
1442 S45T_set(state
, S4T
, S5T
);
1443 Vi_set(state
, ETH
, VIA
);
1445 msleep_interruptible(wait_t
);
1446 sync
= sync_chk(state
, &VIRM
);
1447 dprintk(verbose
, MB86A16_INFO
, 1, "-------- Viterbi=[%d] SYNC=[%d] ---------", VIRM
, sync
);
1452 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1454 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1456 msleep_interruptible(wait_t
);
1458 if (sync_chk(state
, &junk
) == 0) {
1459 iq_vt_set(state
, 1);
1463 /* 1/2, 2/3, 3/4, 7/8 */
1465 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1467 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1468 msleep_interruptible(wait_t
);
1471 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SYNC");
1477 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL");
1481 sync
= sync_chk(state
, &junk
);
1483 dprintk(verbose
, MB86A16_INFO
, 1, "******* SYNC *******");
1484 freqerr_chk(state
, state
->frequency
, state
->srate
, 1);
1490 mb86a16_read(state
, 0x15, &agcval
);
1491 mb86a16_read(state
, 0x26, &cnmval
);
1492 dprintk(verbose
, MB86A16_INFO
, 1, "AGC = %02x CNM = %02x", agcval
, cnmval
);
1497 static int mb86a16_send_diseqc_msg(struct dvb_frontend
*fe
,
1498 struct dvb_diseqc_master_cmd
*cmd
)
1500 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1504 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1506 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1508 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1513 if (cmd
->msg_len
> 5 || cmd
->msg_len
< 4)
1516 for (i
= 0; i
< cmd
->msg_len
; i
++) {
1517 if (mb86a16_write(state
, regs
, cmd
->msg
[i
]) < 0)
1524 msleep_interruptible(10);
1526 if (mb86a16_write(state
, MB86A16_DCC1
, i
) < 0)
1528 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1534 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1538 static int mb86a16_send_diseqc_burst(struct dvb_frontend
*fe
,
1539 enum fe_sec_mini_cmd burst
)
1541 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1545 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1547 MB86A16_DCC1_TBO
) < 0)
1549 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1553 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1554 MB86A16_DCC1_TBEN
) < 0)
1556 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1563 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1567 static int mb86a16_set_tone(struct dvb_frontend
*fe
, enum fe_sec_tone_mode tone
)
1569 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1573 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x00) < 0)
1575 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1576 MB86A16_DCC1_CTOE
) < 0)
1579 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1583 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1585 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1587 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1596 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1600 static enum dvbfe_search
mb86a16_search(struct dvb_frontend
*fe
)
1602 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1603 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1605 state
->frequency
= p
->frequency
/ 1000;
1606 state
->srate
= p
->symbol_rate
/ 1000;
1608 if (!mb86a16_set_fe(state
)) {
1609 dprintk(verbose
, MB86A16_ERROR
, 1, "Successfully acquired LOCK");
1610 return DVBFE_ALGO_SEARCH_SUCCESS
;
1613 dprintk(verbose
, MB86A16_ERROR
, 1, "Lock acquisition failed!");
1614 return DVBFE_ALGO_SEARCH_FAILED
;
1617 static void mb86a16_release(struct dvb_frontend
*fe
)
1619 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1623 static int mb86a16_init(struct dvb_frontend
*fe
)
1628 static int mb86a16_sleep(struct dvb_frontend
*fe
)
1633 static int mb86a16_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1635 u8 ber_mon
, ber_tab
, ber_lsb
, ber_mid
, ber_msb
, ber_tim
, ber_rst
;
1638 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1641 if (mb86a16_read(state
, MB86A16_BERMON
, &ber_mon
) != 2)
1643 if (mb86a16_read(state
, MB86A16_BERTAB
, &ber_tab
) != 2)
1645 if (mb86a16_read(state
, MB86A16_BERLSB
, &ber_lsb
) != 2)
1647 if (mb86a16_read(state
, MB86A16_BERMID
, &ber_mid
) != 2)
1649 if (mb86a16_read(state
, MB86A16_BERMSB
, &ber_msb
) != 2)
1651 /* BER monitor invalid when BER_EN = 0 */
1652 if (ber_mon
& 0x04) {
1653 /* coarse, fast calculation */
1654 *ber
= ber_tab
& 0x1f;
1655 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER coarse=[0x%02x]", *ber
);
1656 if (ber_mon
& 0x01) {
1658 * BER_SEL = 1, The monitored BER is the estimated
1659 * value with a Reed-Solomon decoder error amount at
1660 * the deinterleaver output.
1661 * monitored BER is expressed as a 20 bit output in total
1663 ber_rst
= (ber_mon
>> 3) & 0x03;
1664 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1667 else if (ber_rst
== 1)
1669 else if (ber_rst
== 2)
1671 else /* ber_rst == 3 */
1675 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1678 * BER_SEL = 0, The monitored BER is the estimated
1679 * value with a Viterbi decoder error amount at the
1680 * QPSK demodulator output.
1681 * monitored BER is expressed as a 24 bit output in total
1683 ber_tim
= (ber_mon
>> 1) & 0x01;
1684 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1687 else /* ber_tim == 1 */
1691 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1696 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1700 static int mb86a16_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
1703 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1706 if (mb86a16_read(state
, MB86A16_AGCM
, &agcm
) != 2) {
1707 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1711 *strength
= ((0xff - agcm
) * 100) / 256;
1712 dprintk(verbose
, MB86A16_DEBUG
, 1, "Signal strength=[%d %%]", (u8
) *strength
);
1713 *strength
= (0xffff - 0xff) + agcm
;
1723 static const struct cnr cnr_tab
[] = {
1747 static int mb86a16_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1749 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1751 int low_tide
= 2, high_tide
= 30, q_level
;
1755 if (mb86a16_read(state
, 0x26, &cn
) != 2) {
1756 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1760 for (i
= 0; i
< ARRAY_SIZE(cnr_tab
); i
++) {
1761 if (cn
< cnr_tab
[i
].cn_reg
) {
1762 *snr
= cnr_tab
[i
].cn_val
;
1766 q_level
= (*snr
* 100) / (high_tide
- low_tide
);
1767 dprintk(verbose
, MB86A16_ERROR
, 1, "SNR (Quality) = [%d dB], Level=%d %%", *snr
, q_level
);
1768 *snr
= (0xffff - 0xff) + *snr
;
1773 static int mb86a16_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
1776 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1778 if (mb86a16_read(state
, MB86A16_DISTMON
, &dist
) != 2) {
1779 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1787 static enum dvbfe_algo
mb86a16_frontend_algo(struct dvb_frontend
*fe
)
1789 return DVBFE_ALGO_CUSTOM
;
1792 static const struct dvb_frontend_ops mb86a16_ops
= {
1793 .delsys
= { SYS_DVBS
},
1795 .name
= "Fujitsu MB86A16 DVB-S",
1796 .frequency_min_hz
= 950 * MHz
,
1797 .frequency_max_hz
= 2150 * MHz
,
1798 .frequency_stepsize_hz
= 3 * MHz
,
1799 .symbol_rate_min
= 1000000,
1800 .symbol_rate_max
= 45000000,
1801 .symbol_rate_tolerance
= 500,
1802 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
|
1803 FE_CAN_FEC_3_4
| FE_CAN_FEC_5_6
|
1804 FE_CAN_FEC_7_8
| FE_CAN_QPSK
|
1807 .release
= mb86a16_release
,
1809 .get_frontend_algo
= mb86a16_frontend_algo
,
1810 .search
= mb86a16_search
,
1811 .init
= mb86a16_init
,
1812 .sleep
= mb86a16_sleep
,
1813 .read_status
= mb86a16_read_status
,
1815 .read_ber
= mb86a16_read_ber
,
1816 .read_signal_strength
= mb86a16_read_signal_strength
,
1817 .read_snr
= mb86a16_read_snr
,
1818 .read_ucblocks
= mb86a16_read_ucblocks
,
1820 .diseqc_send_master_cmd
= mb86a16_send_diseqc_msg
,
1821 .diseqc_send_burst
= mb86a16_send_diseqc_burst
,
1822 .set_tone
= mb86a16_set_tone
,
1825 struct dvb_frontend
*mb86a16_attach(const struct mb86a16_config
*config
,
1826 struct i2c_adapter
*i2c_adap
)
1829 struct mb86a16_state
*state
= NULL
;
1831 state
= kmalloc(sizeof(struct mb86a16_state
), GFP_KERNEL
);
1835 state
->config
= config
;
1836 state
->i2c_adap
= i2c_adap
;
1838 mb86a16_read(state
, 0x7f, &dev_id
);
1842 memcpy(&state
->frontend
.ops
, &mb86a16_ops
, sizeof(struct dvb_frontend_ops
));
1843 state
->frontend
.demodulator_priv
= state
;
1844 state
->frontend
.ops
.set_voltage
= state
->config
->set_voltage
;
1846 return &state
->frontend
;
1851 EXPORT_SYMBOL(mb86a16_attach
);
1852 MODULE_LICENSE("GPL");
1853 MODULE_AUTHOR("Manu Abraham");