22 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/slab.h>
34 #define ABS(x) ((x) < 0 ? (-x) : (x))
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, "()-->")
89 "writing to [0x%02x],Reg[0x%02x],Data[0x%02x]",
90 state->
config->demod_address, buf[0], buf[1]);
105 .addr = state->
config->demod_address,
110 .addr = state->
config->demod_address,
129 unsigned char timint1,
130 unsigned char timint2,
135 val = (timint1 << 4) | (timint2 << 2) | cnext;
150 unsigned char STOFS0, STOFS1;
152 m = 1 << state->
deci;
155 STOFS0 = tmp & 0x0ff;
156 STOFS1 = (tmp & 0xf00) >> 8;
186 unsigned char AFCEX_L,
187 unsigned char AFCEX_H)
202 unsigned char AFCEX_L,
203 unsigned char AFCEX_H)
205 if (mb86a16_write(state, 0x58, AFCEX_L) < 0)
207 if (mb86a16_write(state, 0x59, AFCEX_H) < 0)
229 static int Vi_set(
struct mb86a16_state *state,
unsigned char ETH,
unsigned char VIA)
244 if (stlp_set(state, 5, 7))
248 if (afcex_data_set(state, 0, 0))
252 if (afcofs_data_set(state, 0, 0))
258 if (mb86a16_write(state, 0x2f, 0x21) < 0)
272 if (mb86a16_write(state, 0x54, 0xff) < 0)
288 if (mb86a16_write(state, 0x33, (s1t << 3) | s0t) < 0)
304 val = 0x7a | (cren << 7) | (afcen << 2);
305 if (mb86a16_write(state, 0x49, val) < 0)
322 else if (smrt > 9375)
324 else if (smrt > 2250)
329 if (mb86a16_write(state, 0x2a, 0x02 | (afcexen << 5) | (AFCA << 2)) < 0)
343 if (mb86a16_write(state, 0x2d, (DAGCA << 3) | DAGCW) < 0)
353 static void smrt_info_get(
struct mb86a16_state *state,
int rate)
357 }
else if (rate >= 30001) {
359 }
else if (rate >= 26251) {
361 }
else if (rate >= 22501) {
363 }
else if (rate >= 18751) {
365 }
else if (rate >= 15001) {
367 }
else if (rate >= 13126) {
369 }
else if (rate >= 11251) {
371 }
else if (rate >= 9376) {
373 }
else if (rate >= 7501) {
375 }
else if (rate >= 6563) {
377 }
else if (rate >= 5626) {
379 }
else if (rate >= 4688) {
381 }
else if (rate >= 3751) {
383 }
else if (rate >= 3282) {
385 }
else if (rate >= 2814) {
387 }
else if (rate >= 2344) {
389 }
else if (rate >= 1876) {
391 }
else if (rate >= 1641) {
393 }
else if (rate >= 1407) {
395 }
else if (rate >= 1172) {
397 }
else if (rate >= 939) {
399 }
else if (rate >= 821) {
405 if (state->
csel == 0)
426 if (CNTM_set(state, 2, 1, 2) < 0) {
432 if (CNTM_set(state, 3, 1, 2) < 0) {
438 for (i = 0; i < 3; i++) {
440 smrtd = smrt * 98 / 100;
444 smrtd = smrt * 102 / 100;
445 smrt_info_get(state, smrtd);
446 smrt_set(state, smrtd);
448 wait_t = (wait_sym + 99 * smrtd / 100) / smrtd;
452 if (mb86a16_read(state, 0x37, &(S[i])) != 2) {
457 if ((S[1] > S[0] * 112 / 100) &&
458 (S[1] > S[2] * 112 / 100)) {
466 if (CNTM_set(state, 0, 1, 2) < 0) {
479 unsigned char C,
F,
B;
481 unsigned char rf_val[5];
486 else if (smrt > 18875)
488 else if (smrt > 5500)
495 else if (smrt > 9375)
497 else if (smrt > 4625)
523 M = f * (1 <<
R) / 2;
525 rf_val[0] = 0x01 | (C << 3) | (F << 1);
526 rf_val[1] = (R << 5) | ((M & 0x1f000) >> 12);
527 rf_val[2] = (M & 0x00ff0) >> 4;
528 rf_val[3] = ((M & 0x0000f) << 4) |
B;
531 if (mb86a16_write(state, 0x21, rf_val[0]) < 0)
533 if (mb86a16_write(state, 0x22, rf_val[1]) < 0)
535 if (mb86a16_write(state, 0x23, rf_val[2]) < 0)
537 if (mb86a16_write(state, 0x24, rf_val[3]) < 0)
539 if (mb86a16_write(state, 0x25, 0x01) < 0)
551 unsigned char AFCM_L, AFCM_H ;
555 if (mb86a16_read(state, 0x0e, &AFCM_L) != 2)
557 if (mb86a16_read(state, 0x0f, &AFCM_H) != 2)
560 AFCM = (AFCM_H << 8) + AFCM_L;
578 unsigned char DAGCM_H, DAGCM_L;
580 if (mb86a16_read(state, 0x45, &DAGCM_L) != 2)
582 if (mb86a16_read(state, 0x46, &DAGCM_H) != 2)
585 DAGCM = (DAGCM_H << 8) + DAGCM_L;
605 if ((stat > 25) && (stat2 > 25))
607 if ((stat > 45) && (stat2 > 45))
637 if (mb86a16_read(state, 0x0d, &val) != 2)
642 *VIRM = (val & 0x1c) >> 2;
656 unsigned char CRM, AFCML, AFCMH;
661 int afcen, afcexen = 0;
662 int R,
M, fOSC, fOSC_OFS;
664 if (mb86a16_read(state, 0x43, &CRM) != 2)
672 crrerr = smrt * crm / 256;
673 if (mb86a16_read(state, 0x49, &temp1) != 2)
676 afcen = (temp1 & 0x04) >> 2;
678 if (mb86a16_read(state, 0x2a, &temp1) != 2)
680 afcexen = (temp1 & 0x20) >> 5;
684 if (mb86a16_read(state, 0x0e, &AFCML) != 2)
686 if (mb86a16_read(state, 0x0f, &AFCMH) != 2)
688 }
else if (afcexen == 1) {
689 if (mb86a16_read(state, 0x2b, &AFCML) != 2)
691 if (mb86a16_read(state, 0x2c, &AFCMH) != 2)
694 if ((afcen == 1) || (afcexen == 1)) {
695 smrt_info_get(state, smrt);
696 AFCM = ((AFCMH & 0x01) << 8) + AFCML;
706 if (mb86a16_read(state, 0x22, &temp1) != 2)
708 if (mb86a16_read(state, 0x23, &temp2) != 2)
710 if (mb86a16_read(state, 0x24, &temp3) != 2)
713 R = (temp1 & 0xe0) >> 5;
714 M = ((temp1 & 0x1f) << 12) + (temp2 << 4) + (temp3 >> 4);
720 fOSC_OFS = fOSC - fTP;
723 if (crrerr + afcerr + fOSC_OFS * 1000 >= 0)
724 frqerr = (crrerr + afcerr + fOSC_OFS * 1000 + 500) / 1000;
726 frqerr = (crrerr + afcerr + fOSC_OFS * 1000 - 500) / 1000;
728 frqerr = crrerr + afcerr + fOSC_OFS * 1000;
737 static unsigned char vco_dev_get(
struct mb86a16_state *state,
int smrt)
756 unsigned char *AFCEX_L,
757 unsigned char *AFCEX_H)
762 crnt_swp_freq = fOSC_start * 1000 + v * swp_ofs;
765 *fOSC = (crnt_swp_freq + 1000) / 2000 * 2;
767 *fOSC = (crnt_swp_freq + 500) / 1000;
769 if (*fOSC >= crnt_swp_freq)
770 *afcex_freq = *fOSC * 1000 - crnt_swp_freq;
772 *afcex_freq = crnt_swp_freq - *fOSC * 1000;
774 AFCEX = *afcex_freq * 8192 / state->
master_clk;
775 *AFCEX_L = AFCEX & 0x00ff;
776 *AFCEX_H = (AFCEX & 0x0f00) >> 8;
780 static int swp_freq_calcuation(
struct mb86a16_state *state,
int i,
int v,
int *
V,
int vmax,
int vmin,
781 int SIGMIN,
int fOSC,
int afcex_freq,
int swp_ofs,
unsigned char *
SIG1)
785 if ((i % 2 == 1) && (v <= vmax)) {
787 if ((v - 1 == vmin) &&
788 (*(V + 30 + v) >= 0) &&
789 (*(V + 30 + v - 1) >= 0) &&
790 (*(V + 30 + v - 1) > *(V + 30 + v)) &&
791 (*(V + 30 + v - 1) > SIGMIN)) {
793 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs;
794 *SIG1 = *(V + 30 + v - 1);
795 }
else if ((v == vmax) &&
796 (*(V + 30 +
v) >= 0) &&
797 (*(V + 30 + v - 1) >= 0) &&
798 (*(V + 30 +
v) > *(V + 30 + v - 1)) &&
799 (*(V + 30 + v) > SIGMIN)) {
801 swp_freq = fOSC * 1000 + afcex_freq;
802 *SIG1 = *(V + 30 +
v);
803 }
else if ((*(V + 30 + v) > 0) &&
804 (*(V + 30 + v - 1) > 0) &&
805 (*(V + 30 + v - 2) > 0) &&
806 (*(V + 30 + v - 3) > 0) &&
807 (*(V + 30 + v - 1) > *(V + 30 +
v)) &&
808 (*(V + 30 + v - 2) > *(V + 30 + v - 3)) &&
809 ((*(V + 30 + v - 1) > SIGMIN) ||
810 (*(V + 30 + v - 2) > SIGMIN))) {
812 if (*(V + 30 + v - 1) >= *(V + 30 + v - 2)) {
813 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs;
814 *SIG1 = *(V + 30 + v - 1);
816 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs * 2;
817 *SIG1 = *(V + 30 + v - 2);
819 }
else if ((v == vmax) &&
820 (*(V + 30 +
v) >= 0) &&
821 (*(V + 30 + v - 1) >= 0) &&
822 (*(V + 30 + v - 2) >= 0) &&
823 (*(V + 30 +
v) > *(V + 30 + v - 2)) &&
824 (*(V + 30 + v - 1) > *(V + 30 + v - 2)) &&
825 ((*(V + 30 +
v) > SIGMIN) ||
826 (*(V + 30 + v - 1) > SIGMIN))) {
828 if (*(V + 30 + v) >= *(V + 30 + v - 1)) {
829 swp_freq = fOSC * 1000 + afcex_freq;
830 *SIG1 = *(V + 30 +
v);
832 swp_freq = fOSC * 1000 + afcex_freq - swp_ofs;
833 *SIG1 = *(V + 30 + v - 1);
838 }
else if ((i % 2 == 0) && (v >= vmin)) {
840 if ((*(V + 30 + v) > 0) &&
841 (*(V + 30 + v + 1) > 0) &&
842 (*(V + 30 + v + 2) > 0) &&
843 (*(V + 30 + v + 1) > *(V + 30 +
v)) &&
844 (*(V + 30 + v + 1) > *(V + 30 + v + 2)) &&
845 (*(V + 30 + v + 1) > SIGMIN)) {
847 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
848 *SIG1 = *(V + 30 + v + 1);
849 }
else if ((v + 1 == vmax) &&
850 (*(V + 30 +
v) >= 0) &&
851 (*(V + 30 + v + 1) >= 0) &&
852 (*(V + 30 + v + 1) > *(V + 30 + v)) &&
853 (*(V + 30 + v + 1) > SIGMIN)) {
855 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
856 *SIG1 = *(V + 30 +
v);
857 }
else if ((v == vmin) &&
858 (*(V + 30 +
v) > 0) &&
859 (*(V + 30 + v + 1) > 0) &&
860 (*(V + 30 + v + 2) > 0) &&
861 (*(V + 30 +
v) > *(V + 30 + v + 1)) &&
862 (*(V + 30 + v) > *(V + 30 + v + 2)) &&
863 (*(V + 30 +
v) > SIGMIN)) {
865 swp_freq = fOSC * 1000 + afcex_freq;
866 *SIG1 = *(V + 30 +
v);
867 }
else if ((*(V + 30 + v) >= 0) &&
868 (*(V + 30 + v + 1) >= 0) &&
869 (*(V + 30 + v + 2) >= 0) &&
870 (*(V + 30 + v + 3) >= 0) &&
871 (*(V + 30 + v + 1) > *(V + 30 +
v)) &&
872 (*(V + 30 + v + 2) > *(V + 30 + v + 3)) &&
873 ((*(V + 30 + v + 1) > SIGMIN) ||
874 (*(V + 30 + v + 2) > SIGMIN))) {
876 if (*(V + 30 + v + 1) >= *(V + 30 + v + 2)) {
877 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
878 *SIG1 = *(V + 30 + v + 1);
880 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs * 2;
881 *SIG1 = *(V + 30 + v + 2);
883 }
else if ((*(V + 30 + v) >= 0) &&
884 (*(V + 30 + v + 1) >= 0) &&
885 (*(V + 30 + v + 2) >= 0) &&
886 (*(V + 30 + v + 3) >= 0) &&
887 (*(V + 30 + v) > *(V + 30 + v + 2)) &&
888 (*(V + 30 + v + 1) > *(V + 30 + v + 2)) &&
889 (*(V + 30 + v) > *(V + 30 + v + 3)) &&
890 (*(V + 30 + v + 1) > *(V + 30 + v + 3)) &&
891 ((*(V + 30 + v) > SIGMIN) ||
892 (*(V + 30 + v + 1) > SIGMIN))) {
894 if (*(V + 30 + v) >= *(V + 30 + v + 1)) {
895 swp_freq = fOSC * 1000 + afcex_freq;
896 *SIG1 = *(V + 30 +
v);
898 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
899 *SIG1 = *(V + 30 + v + 1);
901 }
else if ((v + 2 == vmin) &&
902 (*(V + 30 +
v) >= 0) &&
903 (*(V + 30 + v + 1) >= 0) &&
904 (*(V + 30 + v + 2) >= 0) &&
905 (*(V + 30 + v + 1) > *(V + 30 + v)) &&
906 (*(V + 30 + v + 2) > *(V + 30 +
v)) &&
907 ((*(V + 30 + v + 1) > SIGMIN) ||
908 (*(V + 30 + v + 2) > SIGMIN))) {
910 if (*(V + 30 + v + 1) >= *(V + 30 + v + 2)) {
911 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs;
912 *SIG1 = *(V + 30 + v + 1);
914 swp_freq = fOSC * 1000 + afcex_freq + swp_ofs * 2;
915 *SIG1 = *(V + 30 + v + 2);
917 }
else if ((vmax == 0) && (vmin == 0) && (*(V + 30 + v) > SIGMIN)) {
918 swp_freq = fOSC * 1000;
919 *SIG1 = *(V + 30 +
v);
934 unsigned char *AFCEX_L,
935 unsigned char *AFCEX_H)
940 *fOSC = (swp_freq + 1000) / 2000 * 2;
942 *fOSC = (swp_freq + 500) / 1000;
944 if (*fOSC >= swp_freq)
945 *afcex_freq = *fOSC * 1000 - swp_freq;
947 *afcex_freq = swp_freq - *fOSC * 1000;
949 AFCEX = *afcex_freq * 8192 / state->
master_clk;
950 *AFCEX_L = AFCEX & 0x00ff;
951 *AFCEX_H = (AFCEX & 0x0f00) >> 8;
956 unsigned char *AFCEX_L,
957 unsigned char *AFCEX_H)
961 AFCEX = afcex_freq * 8192 / state->
master_clk;
962 *AFCEX_L = AFCEX & 0x00ff;
963 *AFCEX_H = (AFCEX & 0x0f00) >> 8;
966 static int SEQ_set(
struct mb86a16_state *state,
unsigned char loop)
969 if (mb86a16_write(state, 0x32, 0x02 | (loop << 2)) < 0) {
980 if (mb86a16_write(state, 0x06, 0xdf | (IQINV << 5)) < 0) {
998 static int S2T_set(
struct mb86a16_state *state,
unsigned char S2T)
1000 if (mb86a16_write(state, 0x34, 0x70 | S2T) < 0) {
1008 static int S45T_set(
struct mb86a16_state *state,
unsigned char S4T,
unsigned char S5T)
1010 if (mb86a16_write(state, 0x35, 0x00 | (S5T << 4) | S4T) < 0) {
1032 unsigned char CREN, AFCEN, AFCEXEN;
1034 unsigned char TIMINT1, TIMINT2, TIMEXT;
1035 unsigned char S0T, S1T;
1038 unsigned char S4T, S5T;
1039 unsigned char AFCEX_L, AFCEX_H;
1042 unsigned char ETH, VIA;
1048 int vmax_his, vmin_his;
1049 int swp_freq, prev_swp_freq[20];
1055 int temp_freq, delta_freq;
1066 swp_ofs = state->
srate / 4;
1068 for (i = 0; i < 60; i++)
1071 for (i = 0; i < 20; i++)
1072 prev_swp_freq[i] = 0;
1076 for (n = 0; ((n < 3) && (ret == -1)); n++) {
1078 iq_vt_set(state, 0);
1089 if (initial_set(state) < 0) {
1093 if (DAGC_data_set(state, 3, 2) < 0) {
1097 if (EN_set(state, CREN, AFCEN) < 0) {
1101 if (AFCEXEN_set(state, AFCEXEN, state->
srate) < 0) {
1105 if (CNTM_set(state, TIMINT1, TIMINT2, TIMEXT) < 0) {
1109 if (S01T_set(state, S1T, S0T) < 0) {
1113 smrt_info_get(state, state->
srate);
1114 if (smrt_set(state, state->
srate) < 0) {
1119 R = vco_dev_get(state, state->
srate);
1128 if (fOSC_start > 2150)
1133 ftemp = fOSC_start * 1000;
1136 ftemp = ftemp + swp_ofs;
1140 if (ftemp > 2150000) {
1144 if ((ftemp == 2150000) ||
1151 ftemp = fOSC_start * 1000;
1154 ftemp = ftemp - swp_ofs;
1158 if (ftemp < 950000) {
1162 if ((ftemp == 950000) ||
1168 wait_t = (8000 + state->
srate / 2) / state->
srate;
1182 swp_info_get(state, fOSC_start, state->
srate,
1183 v, R, swp_ofs, &fOSC,
1184 &afcex_freq, &AFCEX_L, &AFCEX_H);
1187 if (rf_val_set(state, fOSC, state->
srate, R) < 0) {
1192 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1196 if (srst(state) < 0) {
1202 if (mb86a16_read(state, 0x37, &SIG1) != 2) {
1207 swp_freq = swp_freq_calcuation(state, i, v, V, vmax, vmin,
1208 SIG1MIN, fOSC, afcex_freq,
1212 for (j = 0; j < prev_freq_num; j++) {
1213 if ((
ABS(prev_swp_freq[j] - swp_freq)) < (swp_ofs * 3 / 2)) {
1218 if ((signal_dupl == 0) && (swp_freq > 0) && (
ABS(swp_freq - state->
frequency * 1000) < fcp + state->
srate / 6)) {
1220 prev_swp_freq[prev_freq_num] = swp_freq;
1222 swp_info_get2(state, state->
srate, R, swp_freq,
1224 &AFCEX_L, &AFCEX_H);
1226 if (rf_val_set(state, fOSC, state->
srate, R) < 0) {
1230 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1234 signal = signal_det(state, state->
srate, &SIG1);
1240 smrt_info_get(state, state->
srate);
1241 if (smrt_set(state, state->
srate) < 0) {
1253 if ((i % 2 == 1) && (vmax_his == 1))
1255 if ((i % 2 == 0) && (vmin_his == 1))
1263 if ((vmax_his == 1) && (vmin_his == 1))
1275 if (S01T_set(state, S1T, S0T) < 0) {
1279 smrt_info_get(state, state->
srate);
1280 if (smrt_set(state, state->
srate) < 0) {
1284 if (EN_set(state, CREN, AFCEN) < 0) {
1288 if (AFCEXEN_set(state, AFCEXEN, state->
srate) < 0) {
1292 afcex_info_get(state, afcex_freq, &AFCEX_L, &AFCEX_H);
1293 if (afcofs_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1297 if (srst(state) < 0) {
1304 afcerr = afcerr_chk(state);
1308 swp_freq = fOSC * 1000 + afcerr ;
1310 if (state->
srate >= 1500)
1311 smrt_d = state->
srate / 3;
1313 smrt_d = state->
srate / 2;
1314 smrt_info_get(state, smrt_d);
1315 if (smrt_set(state, smrt_d) < 0) {
1319 if (AFCEXEN_set(state, AFCEXEN, smrt_d) < 0) {
1323 R = vco_dev_get(state, smrt_d);
1324 if (DAGC_data_set(state, 2, 0) < 0) {
1328 for (i = 0; i < 3; i++) {
1329 temp_freq = swp_freq + (i - 1) * state->
srate / 8;
1330 swp_info_get2(state, smrt_d, R, temp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1331 if (rf_val_set(state, fOSC, smrt_d, R) < 0) {
1335 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1339 wait_t = 200000 / state->
master_clk + 40000 / smrt_d;
1341 dagcm[
i] = dagcm_val_get(state);
1343 if ((dagcm[0] > dagcm[1]) &&
1344 (dagcm[0] > dagcm[2]) &&
1345 (dagcm[0] - dagcm[1] > 2 * (dagcm[2] - dagcm[1]))) {
1347 temp_freq = swp_freq - 2 * state->
srate / 8;
1348 swp_info_get2(state, smrt_d, R, temp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1349 if (rf_val_set(state, fOSC, smrt_d, R) < 0) {
1353 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1357 wait_t = 200000 / state->
master_clk + 40000 / smrt_d;
1359 dagcm[3] = dagcm_val_get(state);
1360 if (dagcm[3] > dagcm[1])
1361 delta_freq = (dagcm[2] - dagcm[0] + dagcm[1] - dagcm[3]) * state->
srate / 300;
1364 }
else if ((dagcm[2] > dagcm[1]) &&
1365 (dagcm[2] > dagcm[0]) &&
1366 (dagcm[2] - dagcm[1] > 2 * (dagcm[0] - dagcm[1]))) {
1368 temp_freq = swp_freq + 2 * state->
srate / 8;
1369 swp_info_get2(state, smrt_d, R, temp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1370 if (rf_val_set(state, fOSC, smrt_d, R) < 0) {
1374 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1378 wait_t = 200000 / state->
master_clk + 40000 / smrt_d;
1380 dagcm[3] = dagcm_val_get(state);
1381 if (dagcm[3] > dagcm[1])
1382 delta_freq = (dagcm[2] - dagcm[0] + dagcm[3] - dagcm[1]) * state->
srate / 300;
1390 swp_freq += delta_freq;
1402 if (S01T_set(state, S1T, S0T) < 0) {
1406 if (DAGC_data_set(state, 0, 0) < 0) {
1410 R = vco_dev_get(state, state->
srate);
1411 smrt_info_get(state, state->
srate);
1412 if (smrt_set(state, state->
srate) < 0) {
1416 if (EN_set(state, CREN, AFCEN) < 0) {
1420 if (AFCEXEN_set(state, AFCEXEN, state->
srate) < 0) {
1424 swp_info_get2(state, state->
srate, R, swp_freq, &afcex_freq, &fOSC, &AFCEX_L, &AFCEX_H);
1425 if (rf_val_set(state, fOSC, state->
srate, R) < 0) {
1429 if (afcex_data_set(state, AFCEX_L, AFCEX_H) < 0) {
1433 if (srst(state) < 0) {
1437 wait_t = 7 + (10000 + state->
srate / 2) / state->
srate;
1441 if (mb86a16_read(state, 0x37, &SIG1) != 2) {
1447 S2T = 4; S4T = 1; S5T = 6; ETH = 4; VIA = 6;
1448 wait_t = 7 + (917504 + state->
srate / 2) / state->
srate;
1449 }
else if (SIG1 > 105) {
1450 S2T = 4; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1451 wait_t = 7 + (1048576 + state->
srate / 2) / state->
srate;
1452 }
else if (SIG1 > 85) {
1453 S2T = 5; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1454 wait_t = 7 + (1310720 + state->
srate / 2) / state->
srate;
1455 }
else if (SIG1 > 65) {
1456 S2T = 6; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1457 wait_t = 7 + (1572864 + state->
srate / 2) / state->
srate;
1459 S2T = 7; S4T = 2; S5T = 8; ETH = 7; VIA = 2;
1460 wait_t = 7 + (2097152 + state->
srate / 2) / state->
srate;
1463 S2T_set(state, S2T);
1464 S45T_set(state, S4T, S5T);
1465 Vi_set(state, ETH, VIA);
1468 sync = sync_chk(state, &VIRM);
1474 wait_t = (786432 + state->
srate / 2) / state->
srate;
1476 wait_t = (1572864 + state->
srate / 2) / state->
srate;
1477 if (state->
srate < 5000)
1483 if (sync_chk(state, &junk) == 0) {
1484 iq_vt_set(state, 1);
1490 wait_t = (786432 + state->
srate / 2) / state->
srate;
1492 wait_t = (1572864 + state->
srate / 2) / state->
srate;
1506 sync = sync_chk(state, &junk);
1515 mb86a16_read(state, 0x15, &agcval);
1516 mb86a16_read(state, 0x26, &cnmval);
1522 static int mb86a16_send_diseqc_msg(
struct dvb_frontend *fe,
1541 for (i = 0; i < cmd->
msg_len; i++) {
1542 if (mb86a16_write(state, regs, cmd->
msg[i]) < 0)
1632 if (!mb86a16_set_fe(state)) {
1659 u8 ber_mon, ber_tab, ber_lsb, ber_mid, ber_msb, ber_tim, ber_rst;
1676 if (ber_mon & 0x04) {
1678 *ber = ber_tab & 0x1f;
1680 if (ber_mon & 0x01) {
1687 ber_rst = ber_mon >> 3;
1688 *ber = (((ber_msb << 8) | ber_mid) << 8) | ber_lsb;
1707 ber_tim = ber_mon >> 1;
1708 *ber = (((ber_msb << 8) | ber_mid) << 8) | ber_lsb;
1724 static int mb86a16_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
1735 *strength = ((0xff - agcm) * 100) / 256;
1737 *strength = (0xffff - 0xff) + agcm;
1747 static const struct cnr cnr_tab[] = {
1775 int low_tide = 2, high_tide = 30, q_level;
1779 if (mb86a16_read(state, 0x26, &cn) != 2) {
1785 if (cn < cnr_tab[i].cn_reg) {
1790 q_level = (*snr * 100) / (high_tide - low_tide);
1792 *snr = (0xffff - 0xff) + *snr;
1797 static int mb86a16_read_ucblocks(
struct dvb_frontend *fe,
u32 *ucblocks)
1819 .name =
"Fujitsu MB86A16 DVB-S",
1820 .frequency_min = 950000,
1821 .frequency_max = 2150000,
1822 .frequency_stepsize = 3000,
1823 .frequency_tolerance = 0,
1824 .symbol_rate_min = 1000000,
1825 .symbol_rate_max = 45000000,
1826 .symbol_rate_tolerance = 500,
1832 .release = mb86a16_release,
1834 .get_frontend_algo = mb86a16_frontend_algo,
1835 .search = mb86a16_search,
1836 .init = mb86a16_init,
1837 .sleep = mb86a16_sleep,
1838 .read_status = mb86a16_read_status,
1840 .read_ber = mb86a16_read_ber,
1841 .read_signal_strength = mb86a16_read_signal_strength,
1842 .read_snr = mb86a16_read_snr,
1843 .read_ucblocks = mb86a16_read_ucblocks,
1845 .diseqc_send_master_cmd = mb86a16_send_diseqc_msg,
1846 .diseqc_send_burst = mb86a16_send_diseqc_burst,
1847 .set_tone = mb86a16_set_tone,
1863 mb86a16_read(state, 0x7f, &dev_id);