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>
26 #include "dvb_frontend.h"
28 #include "mb86a16_priv.h"
30 unsigned int verbose
= 5;
31 module_param(verbose
, int, 0644);
33 #define ABS(x) ((x) < 0 ? (-x) : (x))
35 struct mb86a16_state
{
36 struct i2c_adapter
*i2c_adap
;
37 const struct mb86a16_config
*config
;
38 struct dvb_frontend frontend
;
40 /* tuning parameters */
51 #define MB86A16_ERROR 0
52 #define MB86A16_NOTICE 1
53 #define MB86A16_INFO 2
54 #define MB86A16_DEBUG 3
56 #define dprintk(x, y, z, format, arg...) do { \
58 if ((x > MB86A16_ERROR) && (x > y)) \
59 printk(KERN_ERR "%s: " format "\n", __func__, ##arg); \
60 else if ((x > MB86A16_NOTICE) && (x > y)) \
61 printk(KERN_NOTICE "%s: " format "\n", __func__, ##arg); \
62 else if ((x > MB86A16_INFO) && (x > y)) \
63 printk(KERN_INFO "%s: " format "\n", __func__, ##arg); \
64 else if ((x > MB86A16_DEBUG) && (x > y)) \
65 printk(KERN_DEBUG "%s: " format "\n", __func__, ##arg); \
68 printk(format, ##arg); \
72 #define TRACE_IN dprintk(verbose, MB86A16_DEBUG, 1, "-->()")
73 #define TRACE_OUT dprintk(verbose, MB86A16_DEBUG, 1, "()-->")
75 static int mb86a16_write(struct mb86a16_state
*state
, u8 reg
, u8 val
)
78 u8 buf
[] = { reg
, val
};
80 struct i2c_msg msg
= {
81 .addr
= state
->config
->demod_address
,
87 dprintk(verbose
, MB86A16_DEBUG
, 1,
88 "writing to [0x%02x],Reg[0x%02x],Data[0x%02x]",
89 state
->config
->demod_address
, buf
[0], buf
[1]);
91 ret
= i2c_transfer(state
->i2c_adap
, &msg
, 1);
93 return (ret
!= 1) ? -EREMOTEIO
: 0;
96 static int mb86a16_read(struct mb86a16_state
*state
, u8 reg
, u8
*val
)
102 struct i2c_msg msg
[] = {
104 .addr
= state
->config
->demod_address
,
109 .addr
= state
->config
->demod_address
,
115 ret
= i2c_transfer(state
->i2c_adap
, msg
, 2);
117 dprintk(verbose
, MB86A16_ERROR
, 1, "read error(reg=0x%02x, ret=0x%i)",
127 static int CNTM_set(struct mb86a16_state
*state
,
128 unsigned char timint1
,
129 unsigned char timint2
,
134 val
= (timint1
<< 4) | (timint2
<< 2) | cnext
;
135 if (mb86a16_write(state
, MB86A16_CNTMR
, val
) < 0)
141 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
145 static int smrt_set(struct mb86a16_state
*state
, int rate
)
149 unsigned char STOFS0
, STOFS1
;
151 m
= 1 << state
->deci
;
152 tmp
= (8192 * state
->master_clk
- 2 * m
* rate
* 8192 + state
->master_clk
/ 2) / state
->master_clk
;
154 STOFS0
= tmp
& 0x0ff;
155 STOFS1
= (tmp
& 0xf00) >> 8;
157 if (mb86a16_write(state
, MB86A16_SRATE1
, (state
->deci
<< 2) |
161 if (mb86a16_write(state
, MB86A16_SRATE2
, STOFS0
) < 0)
163 if (mb86a16_write(state
, MB86A16_SRATE3
, STOFS1
) < 0)
168 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
172 static int srst(struct mb86a16_state
*state
)
174 if (mb86a16_write(state
, MB86A16_RESET
, 0x04) < 0)
179 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
184 static int afcex_data_set(struct mb86a16_state
*state
,
185 unsigned char AFCEX_L
,
186 unsigned char AFCEX_H
)
188 if (mb86a16_write(state
, MB86A16_AFCEXL
, AFCEX_L
) < 0)
190 if (mb86a16_write(state
, MB86A16_AFCEXH
, AFCEX_H
) < 0)
195 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
200 static int afcofs_data_set(struct mb86a16_state
*state
,
201 unsigned char AFCEX_L
,
202 unsigned char AFCEX_H
)
204 if (mb86a16_write(state
, 0x58, AFCEX_L
) < 0)
206 if (mb86a16_write(state
, 0x59, AFCEX_H
) < 0)
211 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
215 static int stlp_set(struct mb86a16_state
*state
,
219 if (mb86a16_write(state
, MB86A16_STRFILTCOEF1
, (STRBS
<< 3) | (STRAS
)) < 0)
224 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
228 static int Vi_set(struct mb86a16_state
*state
, unsigned char ETH
, unsigned char VIA
)
230 if (mb86a16_write(state
, MB86A16_VISET2
, 0x04) < 0)
232 if (mb86a16_write(state
, MB86A16_VISET3
, 0xf5) < 0)
237 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
241 static int initial_set(struct mb86a16_state
*state
)
243 if (stlp_set(state
, 5, 7))
247 if (afcex_data_set(state
, 0, 0))
251 if (afcofs_data_set(state
, 0, 0))
255 if (mb86a16_write(state
, MB86A16_CRLFILTCOEF1
, 0x16) < 0)
257 if (mb86a16_write(state
, 0x2f, 0x21) < 0)
259 if (mb86a16_write(state
, MB86A16_VIMAG
, 0x38) < 0)
261 if (mb86a16_write(state
, MB86A16_FAGCS1
, 0x00) < 0)
263 if (mb86a16_write(state
, MB86A16_FAGCS2
, 0x1c) < 0)
265 if (mb86a16_write(state
, MB86A16_FAGCS3
, 0x20) < 0)
267 if (mb86a16_write(state
, MB86A16_FAGCS4
, 0x1e) < 0)
269 if (mb86a16_write(state
, MB86A16_FAGCS5
, 0x23) < 0)
271 if (mb86a16_write(state
, 0x54, 0xff) < 0)
273 if (mb86a16_write(state
, MB86A16_TSOUT
, 0x00) < 0)
279 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
283 static int S01T_set(struct mb86a16_state
*state
,
287 if (mb86a16_write(state
, 0x33, (s1t
<< 3) | s0t
) < 0)
292 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
297 static int EN_set(struct mb86a16_state
*state
,
303 val
= 0x7a | (cren
<< 7) | (afcen
<< 2);
304 if (mb86a16_write(state
, 0x49, val
) < 0)
309 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
313 static int AFCEXEN_set(struct mb86a16_state
*state
,
321 else if (smrt
> 9375)
323 else if (smrt
> 2250)
328 if (mb86a16_write(state
, 0x2a, 0x02 | (afcexen
<< 5) | (AFCA
<< 2)) < 0)
334 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
338 static int DAGC_data_set(struct mb86a16_state
*state
,
342 if (mb86a16_write(state
, 0x2d, (DAGCA
<< 3) | DAGCW
) < 0)
348 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
352 static void smrt_info_get(struct mb86a16_state
*state
, int rate
)
355 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 0;
356 } else if (rate
>= 30001) {
357 state
->deci
= 0; state
->csel
= 0; state
->rsel
= 1;
358 } else if (rate
>= 26251) {
359 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 0;
360 } else if (rate
>= 22501) {
361 state
->deci
= 0; state
->csel
= 1; state
->rsel
= 1;
362 } else if (rate
>= 18751) {
363 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 0;
364 } else if (rate
>= 15001) {
365 state
->deci
= 1; state
->csel
= 0; state
->rsel
= 1;
366 } else if (rate
>= 13126) {
367 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 0;
368 } else if (rate
>= 11251) {
369 state
->deci
= 1; state
->csel
= 1; state
->rsel
= 1;
370 } else if (rate
>= 9376) {
371 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 0;
372 } else if (rate
>= 7501) {
373 state
->deci
= 2; state
->csel
= 0; state
->rsel
= 1;
374 } else if (rate
>= 6563) {
375 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 0;
376 } else if (rate
>= 5626) {
377 state
->deci
= 2; state
->csel
= 1; state
->rsel
= 1;
378 } else if (rate
>= 4688) {
379 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 0;
380 } else if (rate
>= 3751) {
381 state
->deci
= 3; state
->csel
= 0; state
->rsel
= 1;
382 } else if (rate
>= 3282) {
383 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 0;
384 } else if (rate
>= 2814) {
385 state
->deci
= 3; state
->csel
= 1; state
->rsel
= 1;
386 } else if (rate
>= 2344) {
387 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 0;
388 } else if (rate
>= 1876) {
389 state
->deci
= 4; state
->csel
= 0; state
->rsel
= 1;
390 } else if (rate
>= 1641) {
391 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 0;
392 } else if (rate
>= 1407) {
393 state
->deci
= 4; state
->csel
= 1; state
->rsel
= 1;
394 } else if (rate
>= 1172) {
395 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 0;
396 } else if (rate
>= 939) {
397 state
->deci
= 5; state
->csel
= 0; state
->rsel
= 1;
398 } else if (rate
>= 821) {
399 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 0;
401 state
->deci
= 5; state
->csel
= 1; state
->rsel
= 1;
404 if (state
->csel
== 0)
405 state
->master_clk
= 92000;
407 state
->master_clk
= 61333;
411 static int signal_det(struct mb86a16_state
*state
,
425 if (CNTM_set(state
, 2, 1, 2) < 0) {
426 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
431 if (CNTM_set(state
, 3, 1, 2) < 0) {
432 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
437 for (i
= 0; i
< 3; i
++) {
439 smrtd
= smrt
* 98 / 100;
443 smrtd
= smrt
* 102 / 100;
444 smrt_info_get(state
, smrtd
);
445 smrt_set(state
, smrtd
);
447 wait_t
= (wait_sym
+ 99 * smrtd
/ 100) / smrtd
;
450 msleep_interruptible(10);
451 if (mb86a16_read(state
, 0x37, &(S
[i
])) != 2) {
452 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
456 if ((S
[1] > S
[0] * 112 / 100) &&
457 (S
[1] > S
[2] * 112 / 100)) {
465 if (CNTM_set(state
, 0, 1, 2) < 0) {
466 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set Error");
473 static int rf_val_set(struct mb86a16_state
*state
,
478 unsigned char C
, F
, B
;
480 unsigned char rf_val
[5];
485 else if (smrt
> 18875)
487 else if (smrt
> 5500)
494 else if (smrt
> 9375)
496 else if (smrt
> 4625)
522 M
= f
* (1 << R
) / 2;
524 rf_val
[0] = 0x01 | (C
<< 3) | (F
<< 1);
525 rf_val
[1] = (R
<< 5) | ((M
& 0x1f000) >> 12);
526 rf_val
[2] = (M
& 0x00ff0) >> 4;
527 rf_val
[3] = ((M
& 0x0000f) << 4) | B
;
530 if (mb86a16_write(state
, 0x21, rf_val
[0]) < 0)
532 if (mb86a16_write(state
, 0x22, rf_val
[1]) < 0)
534 if (mb86a16_write(state
, 0x23, rf_val
[2]) < 0)
536 if (mb86a16_write(state
, 0x24, rf_val
[3]) < 0)
538 if (mb86a16_write(state
, 0x25, 0x01) < 0)
541 dprintk(verbose
, MB86A16_ERROR
, 1, "RF Setup - I2C transfer error");
548 static int afcerr_chk(struct mb86a16_state
*state
)
550 unsigned char AFCM_L
, AFCM_H
;
554 if (mb86a16_read(state
, 0x0e, &AFCM_L
) != 2)
556 if (mb86a16_read(state
, 0x0f, &AFCM_H
) != 2)
559 AFCM
= (AFCM_H
<< 8) + AFCM_L
;
565 afcerr
= afcm
* state
->master_clk
/ 8192;
570 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
574 static int dagcm_val_get(struct mb86a16_state
*state
)
577 unsigned char DAGCM_H
, DAGCM_L
;
579 if (mb86a16_read(state
, 0x45, &DAGCM_L
) != 2)
581 if (mb86a16_read(state
, 0x46, &DAGCM_H
) != 2)
584 DAGCM
= (DAGCM_H
<< 8) + DAGCM_L
;
589 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
593 static int mb86a16_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
596 struct mb86a16_state
*state
= fe
->demodulator_priv
;
600 if (mb86a16_read(state
, MB86A16_SIG1
, &stat
) != 2)
602 if (mb86a16_read(state
, MB86A16_SIG2
, &stat2
) != 2)
604 if ((stat
> 25) && (stat2
> 25))
605 *status
|= FE_HAS_SIGNAL
;
606 if ((stat
> 45) && (stat2
> 45))
607 *status
|= FE_HAS_CARRIER
;
609 if (mb86a16_read(state
, MB86A16_STATUS
, &stat
) != 2)
613 *status
|= FE_HAS_SYNC
;
615 *status
|= FE_HAS_VITERBI
;
617 if (mb86a16_read(state
, MB86A16_FRAMESYNC
, &stat
) != 2)
620 if ((stat
& 0x0f) && (*status
& FE_HAS_VITERBI
))
621 *status
|= FE_HAS_LOCK
;
626 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
630 static int sync_chk(struct mb86a16_state
*state
,
636 if (mb86a16_read(state
, 0x0d, &val
) != 2)
639 dprintk(verbose
, MB86A16_INFO
, 1, "Status = %02x,", val
);
641 *VIRM
= (val
& 0x1c) >> 2;
645 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
650 static int freqerr_chk(struct mb86a16_state
*state
,
655 unsigned char CRM
, AFCML
, AFCMH
;
656 unsigned char temp1
, temp2
, temp3
;
658 int crrerr
, afcerr
; /* kHz */
659 int frqerr
; /* MHz */
660 int afcen
, afcexen
= 0;
661 int R
, M
, fOSC
, fOSC_OFS
;
663 if (mb86a16_read(state
, 0x43, &CRM
) != 2)
671 crrerr
= smrt
* crm
/ 256;
672 if (mb86a16_read(state
, 0x49, &temp1
) != 2)
675 afcen
= (temp1
& 0x04) >> 2;
677 if (mb86a16_read(state
, 0x2a, &temp1
) != 2)
679 afcexen
= (temp1
& 0x20) >> 5;
683 if (mb86a16_read(state
, 0x0e, &AFCML
) != 2)
685 if (mb86a16_read(state
, 0x0f, &AFCMH
) != 2)
687 } else if (afcexen
== 1) {
688 if (mb86a16_read(state
, 0x2b, &AFCML
) != 2)
690 if (mb86a16_read(state
, 0x2c, &AFCMH
) != 2)
693 if ((afcen
== 1) || (afcexen
== 1)) {
694 smrt_info_get(state
, smrt
);
695 AFCM
= ((AFCMH
& 0x01) << 8) + AFCML
;
701 afcerr
= afcm
* state
->master_clk
/ 8192;
705 if (mb86a16_read(state
, 0x22, &temp1
) != 2)
707 if (mb86a16_read(state
, 0x23, &temp2
) != 2)
709 if (mb86a16_read(state
, 0x24, &temp3
) != 2)
712 R
= (temp1
& 0xe0) >> 5;
713 M
= ((temp1
& 0x1f) << 12) + (temp2
<< 4) + (temp3
>> 4);
719 fOSC_OFS
= fOSC
- fTP
;
721 if (unit
== 0) { /* MHz */
722 if (crrerr
+ afcerr
+ fOSC_OFS
* 1000 >= 0)
723 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 + 500) / 1000;
725 frqerr
= (crrerr
+ afcerr
+ fOSC_OFS
* 1000 - 500) / 1000;
727 frqerr
= crrerr
+ afcerr
+ fOSC_OFS
* 1000;
732 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
736 static unsigned char vco_dev_get(struct mb86a16_state
*state
, int smrt
)
748 static void swp_info_get(struct mb86a16_state
*state
,
755 unsigned char *AFCEX_L
,
756 unsigned char *AFCEX_H
)
761 crnt_swp_freq
= fOSC_start
* 1000 + v
* swp_ofs
;
764 *fOSC
= (crnt_swp_freq
+ 1000) / 2000 * 2;
766 *fOSC
= (crnt_swp_freq
+ 500) / 1000;
768 if (*fOSC
>= crnt_swp_freq
)
769 *afcex_freq
= *fOSC
* 1000 - crnt_swp_freq
;
771 *afcex_freq
= crnt_swp_freq
- *fOSC
* 1000;
773 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
774 *AFCEX_L
= AFCEX
& 0x00ff;
775 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
779 static int swp_freq_calcuation(struct mb86a16_state
*state
, int i
, int v
, int *V
, int vmax
, int vmin
,
780 int SIGMIN
, int fOSC
, int afcex_freq
, int swp_ofs
, unsigned char *SIG1
)
784 if ((i
% 2 == 1) && (v
<= vmax
)) {
785 /* positive v (case 1) */
786 if ((v
- 1 == vmin
) &&
787 (*(V
+ 30 + v
) >= 0) &&
788 (*(V
+ 30 + v
- 1) >= 0) &&
789 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
790 (*(V
+ 30 + v
- 1) > SIGMIN
)) {
792 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
793 *SIG1
= *(V
+ 30 + v
- 1);
794 } else if ((v
== vmax
) &&
795 (*(V
+ 30 + v
) >= 0) &&
796 (*(V
+ 30 + v
- 1) >= 0) &&
797 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 1)) &&
798 (*(V
+ 30 + v
) > SIGMIN
)) {
800 swp_freq
= fOSC
* 1000 + afcex_freq
;
801 *SIG1
= *(V
+ 30 + v
);
802 } else if ((*(V
+ 30 + v
) > 0) &&
803 (*(V
+ 30 + v
- 1) > 0) &&
804 (*(V
+ 30 + v
- 2) > 0) &&
805 (*(V
+ 30 + v
- 3) > 0) &&
806 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
)) &&
807 (*(V
+ 30 + v
- 2) > *(V
+ 30 + v
- 3)) &&
808 ((*(V
+ 30 + v
- 1) > SIGMIN
) ||
809 (*(V
+ 30 + v
- 2) > SIGMIN
))) {
811 if (*(V
+ 30 + v
- 1) >= *(V
+ 30 + v
- 2)) {
812 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
813 *SIG1
= *(V
+ 30 + v
- 1);
815 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
* 2;
816 *SIG1
= *(V
+ 30 + v
- 2);
818 } else if ((v
== vmax
) &&
819 (*(V
+ 30 + v
) >= 0) &&
820 (*(V
+ 30 + v
- 1) >= 0) &&
821 (*(V
+ 30 + v
- 2) >= 0) &&
822 (*(V
+ 30 + v
) > *(V
+ 30 + v
- 2)) &&
823 (*(V
+ 30 + v
- 1) > *(V
+ 30 + v
- 2)) &&
824 ((*(V
+ 30 + v
) > SIGMIN
) ||
825 (*(V
+ 30 + v
- 1) > SIGMIN
))) {
827 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
- 1)) {
828 swp_freq
= fOSC
* 1000 + afcex_freq
;
829 *SIG1
= *(V
+ 30 + v
);
831 swp_freq
= fOSC
* 1000 + afcex_freq
- swp_ofs
;
832 *SIG1
= *(V
+ 30 + v
- 1);
837 } else if ((i
% 2 == 0) && (v
>= vmin
)) {
838 /* Negative v (case 1) */
839 if ((*(V
+ 30 + v
) > 0) &&
840 (*(V
+ 30 + v
+ 1) > 0) &&
841 (*(V
+ 30 + v
+ 2) > 0) &&
842 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
843 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
844 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
846 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
847 *SIG1
= *(V
+ 30 + v
+ 1);
848 } else if ((v
+ 1 == vmax
) &&
849 (*(V
+ 30 + v
) >= 0) &&
850 (*(V
+ 30 + v
+ 1) >= 0) &&
851 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
852 (*(V
+ 30 + v
+ 1) > SIGMIN
)) {
854 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
855 *SIG1
= *(V
+ 30 + v
);
856 } else if ((v
== vmin
) &&
857 (*(V
+ 30 + v
) > 0) &&
858 (*(V
+ 30 + v
+ 1) > 0) &&
859 (*(V
+ 30 + v
+ 2) > 0) &&
860 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 1)) &&
861 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
862 (*(V
+ 30 + v
) > SIGMIN
)) {
864 swp_freq
= fOSC
* 1000 + afcex_freq
;
865 *SIG1
= *(V
+ 30 + v
);
866 } else if ((*(V
+ 30 + v
) >= 0) &&
867 (*(V
+ 30 + v
+ 1) >= 0) &&
868 (*(V
+ 30 + v
+ 2) >= 0) &&
869 (*(V
+ 30 + v
+ 3) >= 0) &&
870 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
871 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
+ 3)) &&
872 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
873 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
875 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
876 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
877 *SIG1
= *(V
+ 30 + v
+ 1);
879 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
880 *SIG1
= *(V
+ 30 + v
+ 2);
882 } else if ((*(V
+ 30 + v
) >= 0) &&
883 (*(V
+ 30 + v
+ 1) >= 0) &&
884 (*(V
+ 30 + v
+ 2) >= 0) &&
885 (*(V
+ 30 + v
+ 3) >= 0) &&
886 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 2)) &&
887 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 2)) &&
888 (*(V
+ 30 + v
) > *(V
+ 30 + v
+ 3)) &&
889 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
+ 3)) &&
890 ((*(V
+ 30 + v
) > SIGMIN
) ||
891 (*(V
+ 30 + v
+ 1) > SIGMIN
))) {
893 if (*(V
+ 30 + v
) >= *(V
+ 30 + v
+ 1)) {
894 swp_freq
= fOSC
* 1000 + afcex_freq
;
895 *SIG1
= *(V
+ 30 + v
);
897 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
898 *SIG1
= *(V
+ 30 + v
+ 1);
900 } else if ((v
+ 2 == vmin
) &&
901 (*(V
+ 30 + v
) >= 0) &&
902 (*(V
+ 30 + v
+ 1) >= 0) &&
903 (*(V
+ 30 + v
+ 2) >= 0) &&
904 (*(V
+ 30 + v
+ 1) > *(V
+ 30 + v
)) &&
905 (*(V
+ 30 + v
+ 2) > *(V
+ 30 + v
)) &&
906 ((*(V
+ 30 + v
+ 1) > SIGMIN
) ||
907 (*(V
+ 30 + v
+ 2) > SIGMIN
))) {
909 if (*(V
+ 30 + v
+ 1) >= *(V
+ 30 + v
+ 2)) {
910 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
;
911 *SIG1
= *(V
+ 30 + v
+ 1);
913 swp_freq
= fOSC
* 1000 + afcex_freq
+ swp_ofs
* 2;
914 *SIG1
= *(V
+ 30 + v
+ 2);
916 } else if ((vmax
== 0) && (vmin
== 0) && (*(V
+ 30 + v
) > SIGMIN
)) {
917 swp_freq
= fOSC
* 1000;
918 *SIG1
= *(V
+ 30 + v
);
927 static void swp_info_get2(struct mb86a16_state
*state
,
933 unsigned char *AFCEX_L
,
934 unsigned char *AFCEX_H
)
939 *fOSC
= (swp_freq
+ 1000) / 2000 * 2;
941 *fOSC
= (swp_freq
+ 500) / 1000;
943 if (*fOSC
>= swp_freq
)
944 *afcex_freq
= *fOSC
* 1000 - swp_freq
;
946 *afcex_freq
= swp_freq
- *fOSC
* 1000;
948 AFCEX
= *afcex_freq
* 8192 / state
->master_clk
;
949 *AFCEX_L
= AFCEX
& 0x00ff;
950 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
953 static void afcex_info_get(struct mb86a16_state
*state
,
955 unsigned char *AFCEX_L
,
956 unsigned char *AFCEX_H
)
960 AFCEX
= afcex_freq
* 8192 / state
->master_clk
;
961 *AFCEX_L
= AFCEX
& 0x00ff;
962 *AFCEX_H
= (AFCEX
& 0x0f00) >> 8;
965 static int SEQ_set(struct mb86a16_state
*state
, unsigned char loop
)
968 if (mb86a16_write(state
, 0x32, 0x02 | (loop
<< 2)) < 0) {
969 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
976 static int iq_vt_set(struct mb86a16_state
*state
, unsigned char IQINV
)
978 /* Viterbi Rate, IQ Settings */
979 if (mb86a16_write(state
, 0x06, 0xdf | (IQINV
<< 5)) < 0) {
980 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
987 static int FEC_srst(struct mb86a16_state
*state
)
989 if (mb86a16_write(state
, MB86A16_RESET
, 0x02) < 0) {
990 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
997 static int S2T_set(struct mb86a16_state
*state
, unsigned char S2T
)
999 if (mb86a16_write(state
, 0x34, 0x70 | S2T
) < 0) {
1000 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1007 static int S45T_set(struct mb86a16_state
*state
, unsigned char S4T
, unsigned char S5T
)
1009 if (mb86a16_write(state
, 0x35, 0x00 | (S5T
<< 4) | S4T
) < 0) {
1010 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1018 static int mb86a16_set_fe(struct mb86a16_state
*state
)
1031 unsigned char CREN
, AFCEN
, AFCEXEN
;
1033 unsigned char TIMINT1
, TIMINT2
, TIMEXT
;
1034 unsigned char S0T
, S1T
;
1036 /* unsigned char S2T, S3T; */
1037 unsigned char S4T
, S5T
;
1038 unsigned char AFCEX_L
, AFCEX_H
;
1041 unsigned char ETH
, VIA
;
1047 int vmax_his
, vmin_his
;
1048 int swp_freq
, prev_swp_freq
[20];
1054 int temp_freq
, delta_freq
;
1062 dprintk(verbose
, MB86A16_INFO
, 1, "freq=%d Mhz, symbrt=%d Ksps", state
->frequency
, state
->srate
);
1065 swp_ofs
= state
->srate
/ 4;
1067 for (i
= 0; i
< 60; i
++)
1070 for (i
= 0; i
< 20; i
++)
1071 prev_swp_freq
[i
] = 0;
1075 for (n
= 0; ((n
< 3) && (ret
== -1)); n
++) {
1077 iq_vt_set(state
, 0);
1088 if (initial_set(state
) < 0) {
1089 dprintk(verbose
, MB86A16_ERROR
, 1, "initial set failed");
1092 if (DAGC_data_set(state
, 3, 2) < 0) {
1093 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1096 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1097 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1098 return -1; /* (0, 0) */
1100 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1101 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1102 return -1; /* (1, smrt) = (1, symbolrate) */
1104 if (CNTM_set(state
, TIMINT1
, TIMINT2
, TIMEXT
) < 0) {
1105 dprintk(verbose
, MB86A16_ERROR
, 1, "CNTM set error");
1106 return -1; /* (0, 1, 2) */
1108 if (S01T_set(state
, S1T
, S0T
) < 0) {
1109 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1110 return -1; /* (0, 0) */
1112 smrt_info_get(state
, state
->srate
);
1113 if (smrt_set(state
, state
->srate
) < 0) {
1114 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt info get error");
1118 R
= vco_dev_get(state
, state
->srate
);
1120 fOSC_start
= state
->frequency
;
1123 if (state
->frequency
% 2 == 0) {
1124 fOSC_start
= state
->frequency
;
1126 fOSC_start
= state
->frequency
+ 1;
1127 if (fOSC_start
> 2150)
1128 fOSC_start
= state
->frequency
- 1;
1132 ftemp
= fOSC_start
* 1000;
1135 ftemp
= ftemp
+ swp_ofs
;
1139 if (ftemp
> 2150000) {
1143 if ((ftemp
== 2150000) ||
1144 (ftemp
- state
->frequency
* 1000 >= fcp
+ state
->srate
/ 4))
1150 ftemp
= fOSC_start
* 1000;
1153 ftemp
= ftemp
- swp_ofs
;
1157 if (ftemp
< 950000) {
1161 if ((ftemp
== 950000) ||
1162 (state
->frequency
* 1000 - ftemp
>= fcp
+ state
->srate
/ 4))
1167 wait_t
= (8000 + state
->srate
/ 2) / state
->srate
;
1181 swp_info_get(state
, fOSC_start
, state
->srate
,
1182 v
, R
, swp_ofs
, &fOSC
,
1183 &afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1186 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1187 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1191 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1192 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1195 if (srst(state
) < 0) {
1196 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1199 msleep_interruptible(wait_t
);
1201 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1202 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1206 swp_freq
= swp_freq_calcuation(state
, i
, v
, V
, vmax
, vmin
,
1207 SIG1MIN
, fOSC
, afcex_freq
,
1208 swp_ofs
, &SIG1
); /* changed */
1211 for (j
= 0; j
< prev_freq_num
; j
++) {
1212 if ((ABS(prev_swp_freq
[j
] - swp_freq
)) < (swp_ofs
* 3 / 2)) {
1214 dprintk(verbose
, MB86A16_INFO
, 1, "Probably Duplicate Signal, j = %d", j
);
1217 if ((signal_dupl
== 0) && (swp_freq
> 0) && (ABS(swp_freq
- state
->frequency
* 1000) < fcp
+ state
->srate
/ 6)) {
1218 dprintk(verbose
, MB86A16_DEBUG
, 1, "------ Signal detect ------ [swp_freq=[%07d, srate=%05d]]", swp_freq
, state
->srate
);
1219 prev_swp_freq
[prev_freq_num
] = swp_freq
;
1221 swp_info_get2(state
, state
->srate
, R
, swp_freq
,
1223 &AFCEX_L
, &AFCEX_H
);
1225 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1226 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1229 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1230 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1233 signal
= signal_det(state
, state
->srate
, &SIG1
);
1235 dprintk(verbose
, MB86A16_ERROR
, 1, "***** Signal Found *****");
1238 dprintk(verbose
, MB86A16_ERROR
, 1, "!!!!! No signal !!!!!, try again...");
1239 smrt_info_get(state
, state
->srate
);
1240 if (smrt_set(state
, state
->srate
) < 0) {
1241 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1252 if ((i
% 2 == 1) && (vmax_his
== 1))
1254 if ((i
% 2 == 0) && (vmin_his
== 1))
1262 if ((vmax_his
== 1) && (vmin_his
== 1))
1267 dprintk(verbose
, MB86A16_INFO
, 1, " Start Freq Error Check");
1274 if (S01T_set(state
, S1T
, S0T
) < 0) {
1275 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1278 smrt_info_get(state
, state
->srate
);
1279 if (smrt_set(state
, state
->srate
) < 0) {
1280 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1283 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1284 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1287 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1288 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1291 afcex_info_get(state
, afcex_freq
, &AFCEX_L
, &AFCEX_H
);
1292 if (afcofs_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1293 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCOFS data set error");
1296 if (srst(state
) < 0) {
1297 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1301 wait_t
= 200000 / state
->master_clk
+ 200000 / state
->srate
;
1303 afcerr
= afcerr_chk(state
);
1307 swp_freq
= fOSC
* 1000 + afcerr
;
1309 if (state
->srate
>= 1500)
1310 smrt_d
= state
->srate
/ 3;
1312 smrt_d
= state
->srate
/ 2;
1313 smrt_info_get(state
, smrt_d
);
1314 if (smrt_set(state
, smrt_d
) < 0) {
1315 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1318 if (AFCEXEN_set(state
, AFCEXEN
, smrt_d
) < 0) {
1319 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1322 R
= vco_dev_get(state
, smrt_d
);
1323 if (DAGC_data_set(state
, 2, 0) < 0) {
1324 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1327 for (i
= 0; i
< 3; i
++) {
1328 temp_freq
= swp_freq
+ (i
- 1) * state
->srate
/ 8;
1329 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1330 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1331 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1334 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1335 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1338 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1340 dagcm
[i
] = dagcm_val_get(state
);
1342 if ((dagcm
[0] > dagcm
[1]) &&
1343 (dagcm
[0] > dagcm
[2]) &&
1344 (dagcm
[0] - dagcm
[1] > 2 * (dagcm
[2] - 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 error");
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
[1] - dagcm
[3]) * state
->srate
/ 300;
1363 } else if ((dagcm
[2] > dagcm
[1]) &&
1364 (dagcm
[2] > dagcm
[0]) &&
1365 (dagcm
[2] - dagcm
[1] > 2 * (dagcm
[0] - dagcm
[1]))) {
1367 temp_freq
= swp_freq
+ 2 * state
->srate
/ 8;
1368 swp_info_get2(state
, smrt_d
, R
, temp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1369 if (rf_val_set(state
, fOSC
, smrt_d
, R
) < 0) {
1370 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set");
1373 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1374 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set");
1377 wait_t
= 200000 / state
->master_clk
+ 40000 / smrt_d
;
1379 dagcm
[3] = dagcm_val_get(state
);
1380 if (dagcm
[3] > dagcm
[1])
1381 delta_freq
= (dagcm
[2] - dagcm
[0] + dagcm
[3] - dagcm
[1]) * state
->srate
/ 300;
1388 dprintk(verbose
, MB86A16_INFO
, 1, "SWEEP Frequency = %d", swp_freq
);
1389 swp_freq
+= delta_freq
;
1390 dprintk(verbose
, MB86A16_INFO
, 1, "Adjusting .., DELTA Freq = %d, SWEEP Freq=%d", delta_freq
, swp_freq
);
1391 if (ABS(state
->frequency
* 1000 - swp_freq
) > 3800) {
1392 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL !");
1401 if (S01T_set(state
, S1T
, S0T
) < 0) {
1402 dprintk(verbose
, MB86A16_ERROR
, 1, "S01T set error");
1405 if (DAGC_data_set(state
, 0, 0) < 0) {
1406 dprintk(verbose
, MB86A16_ERROR
, 1, "DAGC data set error");
1409 R
= vco_dev_get(state
, state
->srate
);
1410 smrt_info_get(state
, state
->srate
);
1411 if (smrt_set(state
, state
->srate
) < 0) {
1412 dprintk(verbose
, MB86A16_ERROR
, 1, "smrt set error");
1415 if (EN_set(state
, CREN
, AFCEN
) < 0) {
1416 dprintk(verbose
, MB86A16_ERROR
, 1, "EN set error");
1419 if (AFCEXEN_set(state
, AFCEXEN
, state
->srate
) < 0) {
1420 dprintk(verbose
, MB86A16_ERROR
, 1, "AFCEXEN set error");
1423 swp_info_get2(state
, state
->srate
, R
, swp_freq
, &afcex_freq
, &fOSC
, &AFCEX_L
, &AFCEX_H
);
1424 if (rf_val_set(state
, fOSC
, state
->srate
, R
) < 0) {
1425 dprintk(verbose
, MB86A16_ERROR
, 1, "rf val set error");
1428 if (afcex_data_set(state
, AFCEX_L
, AFCEX_H
) < 0) {
1429 dprintk(verbose
, MB86A16_ERROR
, 1, "afcex data set error");
1432 if (srst(state
) < 0) {
1433 dprintk(verbose
, MB86A16_ERROR
, 1, "srst error");
1436 wait_t
= 7 + (10000 + state
->srate
/ 2) / state
->srate
;
1439 msleep_interruptible(wait_t
);
1440 if (mb86a16_read(state
, 0x37, &SIG1
) != 2) {
1441 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1446 S2T
= 4; S4T
= 1; S5T
= 6; ETH
= 4; VIA
= 6;
1447 wait_t
= 7 + (917504 + state
->srate
/ 2) / state
->srate
;
1448 } else if (SIG1
> 105) {
1449 S2T
= 4; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1450 wait_t
= 7 + (1048576 + state
->srate
/ 2) / state
->srate
;
1451 } else if (SIG1
> 85) {
1452 S2T
= 5; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1453 wait_t
= 7 + (1310720 + state
->srate
/ 2) / state
->srate
;
1454 } else if (SIG1
> 65) {
1455 S2T
= 6; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1456 wait_t
= 7 + (1572864 + state
->srate
/ 2) / state
->srate
;
1458 S2T
= 7; S4T
= 2; S5T
= 8; ETH
= 7; VIA
= 2;
1459 wait_t
= 7 + (2097152 + state
->srate
/ 2) / state
->srate
;
1461 wait_t
*= 2; /* FOS */
1462 S2T_set(state
, S2T
);
1463 S45T_set(state
, S4T
, S5T
);
1464 Vi_set(state
, ETH
, VIA
);
1466 msleep_interruptible(wait_t
);
1467 sync
= sync_chk(state
, &VIRM
);
1468 dprintk(verbose
, MB86A16_INFO
, 1, "-------- Viterbi=[%d] SYNC=[%d] ---------", VIRM
, sync
);
1473 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1475 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1476 if (state
->srate
< 5000)
1477 /* FIXME ! , should be a long wait ! */
1478 msleep_interruptible(wait_t
);
1480 msleep_interruptible(wait_t
);
1482 if (sync_chk(state
, &junk
) == 0) {
1483 iq_vt_set(state
, 1);
1487 /* 1/2, 2/3, 3/4, 7/8 */
1489 wait_t
= (786432 + state
->srate
/ 2) / state
->srate
;
1491 wait_t
= (1572864 + state
->srate
/ 2) / state
->srate
;
1492 msleep_interruptible(wait_t
);
1495 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SYNC");
1501 dprintk(verbose
, MB86A16_INFO
, 1, "NO -- SIGNAL");
1505 sync
= sync_chk(state
, &junk
);
1507 dprintk(verbose
, MB86A16_INFO
, 1, "******* SYNC *******");
1508 freqerr_chk(state
, state
->frequency
, state
->srate
, 1);
1514 mb86a16_read(state
, 0x15, &agcval
);
1515 mb86a16_read(state
, 0x26, &cnmval
);
1516 dprintk(verbose
, MB86A16_INFO
, 1, "AGC = %02x CNM = %02x", agcval
, cnmval
);
1521 static int mb86a16_send_diseqc_msg(struct dvb_frontend
*fe
,
1522 struct dvb_diseqc_master_cmd
*cmd
)
1524 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1528 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1530 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1532 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1537 if (cmd
->msg_len
> 5 || cmd
->msg_len
< 4)
1540 for (i
= 0; i
< cmd
->msg_len
; i
++) {
1541 if (mb86a16_write(state
, regs
, cmd
->msg
[i
]) < 0)
1548 msleep_interruptible(10);
1550 if (mb86a16_write(state
, MB86A16_DCC1
, i
) < 0)
1552 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1558 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1562 static int mb86a16_send_diseqc_burst(struct dvb_frontend
*fe
, fe_sec_mini_cmd_t burst
)
1564 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1568 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1570 MB86A16_DCC1_TBO
) < 0)
1572 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1576 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1577 MB86A16_DCC1_TBEN
) < 0)
1579 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1586 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1590 static int mb86a16_set_tone(struct dvb_frontend
*fe
, fe_sec_tone_mode_t tone
)
1592 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1596 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x00) < 0)
1598 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
|
1599 MB86A16_DCC1_CTOE
) < 0)
1602 if (mb86a16_write(state
, MB86A16_DCCOUT
, MB86A16_DCCOUT_DISEN
) < 0)
1606 if (mb86a16_write(state
, MB86A16_TONEOUT2
, 0x04) < 0)
1608 if (mb86a16_write(state
, MB86A16_DCC1
, MB86A16_DCC1_DISTA
) < 0)
1610 if (mb86a16_write(state
, MB86A16_DCCOUT
, 0x00) < 0)
1619 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1623 static enum dvbfe_search
mb86a16_search(struct dvb_frontend
*fe
,
1624 struct dvb_frontend_parameters
*p
)
1626 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1628 state
->frequency
= p
->frequency
/ 1000;
1629 state
->srate
= p
->u
.qpsk
.symbol_rate
/ 1000;
1631 if (!mb86a16_set_fe(state
)) {
1632 dprintk(verbose
, MB86A16_ERROR
, 1, "Succesfully acquired LOCK");
1633 return DVBFE_ALGO_SEARCH_SUCCESS
;
1636 dprintk(verbose
, MB86A16_ERROR
, 1, "Lock acquisition failed!");
1637 return DVBFE_ALGO_SEARCH_FAILED
;
1640 static void mb86a16_release(struct dvb_frontend
*fe
)
1642 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1646 static int mb86a16_init(struct dvb_frontend
*fe
)
1651 static int mb86a16_sleep(struct dvb_frontend
*fe
)
1656 static int mb86a16_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1658 u8 ber_mon
, ber_tab
, ber_lsb
, ber_mid
, ber_msb
, ber_tim
, ber_rst
;
1661 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1664 if (mb86a16_read(state
, MB86A16_BERMON
, &ber_mon
) != 2)
1666 if (mb86a16_read(state
, MB86A16_BERTAB
, &ber_tab
) != 2)
1668 if (mb86a16_read(state
, MB86A16_BERLSB
, &ber_lsb
) != 2)
1670 if (mb86a16_read(state
, MB86A16_BERMID
, &ber_mid
) != 2)
1672 if (mb86a16_read(state
, MB86A16_BERMSB
, &ber_msb
) != 2)
1674 /* BER monitor invalid when BER_EN = 0 */
1675 if (ber_mon
& 0x04) {
1676 /* coarse, fast calculation */
1677 *ber
= ber_tab
& 0x1f;
1678 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER coarse=[0x%02x]", *ber
);
1679 if (ber_mon
& 0x01) {
1681 * BER_SEL = 1, The monitored BER is the estimated
1682 * value with a Reed-Solomon decoder error amount at
1683 * the deinterleaver output.
1684 * monitored BER is expressed as a 20 bit output in total
1686 ber_rst
= ber_mon
>> 3;
1687 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1698 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1701 * BER_SEL = 0, The monitored BER is the estimated
1702 * value with a Viterbi decoder error amount at the
1703 * QPSK demodulator output.
1704 * monitored BER is expressed as a 24 bit output in total
1706 ber_tim
= ber_mon
>> 1;
1707 *ber
= (((ber_msb
<< 8) | ber_mid
) << 8) | ber_lsb
;
1714 dprintk(verbose
, MB86A16_DEBUG
, 1, "BER fine=[0x%02x]", *ber
);
1719 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1723 static int mb86a16_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
1726 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1729 if (mb86a16_read(state
, MB86A16_AGCM
, &agcm
) != 2) {
1730 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1734 *strength
= ((0xff - agcm
) * 100) / 256;
1735 dprintk(verbose
, MB86A16_DEBUG
, 1, "Signal strength=[%d %%]", (u8
) *strength
);
1736 *strength
= (0xffff - 0xff) + agcm
;
1746 static const struct cnr cnr_tab
[] = {
1770 static int mb86a16_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1772 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1774 int low_tide
= 2, high_tide
= 30, q_level
;
1778 if (mb86a16_read(state
, 0x26, &cn
) != 2) {
1779 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1783 for (i
= 0; i
< ARRAY_SIZE(cnr_tab
); i
++) {
1784 if (cn
< cnr_tab
[i
].cn_reg
) {
1785 *snr
= cnr_tab
[i
].cn_val
;
1789 q_level
= (*snr
* 100) / (high_tide
- low_tide
);
1790 dprintk(verbose
, MB86A16_ERROR
, 1, "SNR (Quality) = [%d dB], Level=%d %%", *snr
, q_level
);
1791 *snr
= (0xffff - 0xff) + *snr
;
1796 static int mb86a16_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
1799 struct mb86a16_state
*state
= fe
->demodulator_priv
;
1801 if (mb86a16_read(state
, MB86A16_DISTMON
, &dist
) != 2) {
1802 dprintk(verbose
, MB86A16_ERROR
, 1, "I2C transfer error");
1810 static enum dvbfe_algo
mb86a16_frontend_algo(struct dvb_frontend
*fe
)
1812 return DVBFE_ALGO_CUSTOM
;
1815 static struct dvb_frontend_ops mb86a16_ops
= {
1817 .name
= "Fujitsu MB86A16 DVB-S",
1819 .frequency_min
= 950000,
1820 .frequency_max
= 2150000,
1821 .frequency_stepsize
= 3000,
1822 .frequency_tolerance
= 0,
1823 .symbol_rate_min
= 1000000,
1824 .symbol_rate_max
= 45000000,
1825 .symbol_rate_tolerance
= 500,
1826 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
|
1827 FE_CAN_FEC_3_4
| FE_CAN_FEC_5_6
|
1828 FE_CAN_FEC_7_8
| FE_CAN_QPSK
|
1831 .release
= mb86a16_release
,
1833 .get_frontend_algo
= mb86a16_frontend_algo
,
1834 .search
= mb86a16_search
,
1835 .read_status
= mb86a16_read_status
,
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");