10 #include <linux/kernel.h>
11 #include <linux/slab.h>
12 #include <linux/i2c.h>
26 #define FE_CALLBACK_TIME_NEVER 0xffffffff
27 #define MAX_NUMBER_OF_FRONTENDS 6
33 #define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB8000: "); printk(args); printk("\n"); } } while (0)
35 #define FE_STATUS_TUNE_FAILED 0
99 {.
addr = i2c->
addr >> 1, .flags = 0, .len = 2},
104 dprintk(
"could not acquire lock");
109 msg[0].
buf[0] = reg >> 8;
110 msg[0].
buf[1] = reg & 0xff;
114 dprintk(
"i2c read error on %d", reg);
116 ret = (msg[1].
buf[0] << 8) | msg[1].
buf[1];
126 dprintk(
"could not acquire lock");
134 state->
msg[0].addr = state->
i2c.addr >> 1;
135 state->
msg[0].flags = 0;
137 state->
msg[0].len = 2;
138 state->
msg[1].addr = state->
i2c.addr >> 1;
141 state->
msg[1].len = 2;
144 dprintk(
"i2c read error on %d", reg);
156 rw[0] = dib8000_read_word(state, reg + 0);
157 rw[1] = dib8000_read_word(state, reg + 1);
159 return ((rw[0] << 16) | (rw[1]));
168 dprintk(
"could not acquire lock");
173 msg.
buf[0] = (reg >> 8) & 0xff;
174 msg.
buf[1] = reg & 0xff;
175 msg.
buf[2] = (val >> 8) & 0xff;
176 msg.
buf[3] = val & 0xff;
189 dprintk(
"could not acquire lock");
199 state->
msg[0].addr = state->
i2c.addr >> 1;
200 state->
msg[0].flags = 0;
202 state->
msg[0].len = 4;
211 static const s16 coeff_2k_sb_1seg_dqpsk[8] = {
212 (769 << 5) | 0x0a, (745 << 5) | 0x03, (595 << 5) | 0x0d, (769 << 5) | 0x0a, (920 << 5) | 0x09, (784 << 5) | 0x02, (519 << 5) | 0x0c,
216 static const s16 coeff_2k_sb_1seg[8] = {
217 (692 << 5) | 0x0b, (683 << 5) | 0x01, (519 << 5) | 0x09, (692 << 5) | 0x0b, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f
220 static const s16 coeff_2k_sb_3seg_0dqpsk_1dqpsk[8] = {
221 (832 << 5) | 0x10, (912 << 5) | 0x05, (900 << 5) | 0x12, (832 << 5) | 0x10, (-931 << 5) | 0x0f, (912 << 5) | 0x04, (807 << 5) | 0x11,
225 static const s16 coeff_2k_sb_3seg_0dqpsk[8] = {
226 (622 << 5) | 0x0c, (941 << 5) | 0x04, (796 << 5) | 0x10, (622 << 5) | 0x0c, (982 << 5) | 0x0c, (519 << 5) | 0x02, (572 << 5) | 0x0e,
230 static const s16 coeff_2k_sb_3seg_1dqpsk[8] = {
231 (699 << 5) | 0x14, (607 << 5) | 0x04, (944 << 5) | 0x13, (699 << 5) | 0x14, (-720 << 5) | 0x0d, (640 << 5) | 0x03, (866 << 5) | 0x12,
235 static const s16 coeff_2k_sb_3seg[8] = {
236 (664 << 5) | 0x0c, (925 << 5) | 0x03, (937 << 5) | 0x10, (664 << 5) | 0x0c, (-610 << 5) | 0x0a, (697 << 5) | 0x01, (836 << 5) | 0x0e,
240 static const s16 coeff_4k_sb_1seg_dqpsk[8] = {
241 (-955 << 5) | 0x0e, (687 << 5) | 0x04, (818 << 5) | 0x10, (-955 << 5) | 0x0e, (-922 << 5) | 0x0d, (750 << 5) | 0x03, (665 << 5) | 0x0f,
245 static const s16 coeff_4k_sb_1seg[8] = {
246 (638 << 5) | 0x0d, (683 << 5) | 0x02, (638 << 5) | 0x0d, (638 << 5) | 0x0d, (-655 << 5) | 0x0a, (517 << 5) | 0x00, (698 << 5) | 0x0d,
250 static const s16 coeff_4k_sb_3seg_0dqpsk_1dqpsk[8] = {
251 (-707 << 5) | 0x14, (910 << 5) | 0x06, (889 << 5) | 0x16, (-707 << 5) | 0x14, (-958 << 5) | 0x13, (993 << 5) | 0x05, (523 << 5) | 0x14,
255 static const s16 coeff_4k_sb_3seg_0dqpsk[8] = {
256 (-723 << 5) | 0x13, (910 << 5) | 0x05, (777 << 5) | 0x14, (-723 << 5) | 0x13, (-568 << 5) | 0x0f, (547 << 5) | 0x03, (696 << 5) | 0x12,
260 static const s16 coeff_4k_sb_3seg_1dqpsk[8] = {
261 (-940 << 5) | 0x15, (607 << 5) | 0x05, (915 << 5) | 0x16, (-940 << 5) | 0x15, (-848 << 5) | 0x13, (683 << 5) | 0x04, (543 << 5) | 0x14,
265 static const s16 coeff_4k_sb_3seg[8] = {
266 (612 << 5) | 0x12, (910 << 5) | 0x04, (864 << 5) | 0x14, (612 << 5) | 0x12, (-869 << 5) | 0x13, (683 << 5) | 0x02, (869 << 5) | 0x12,
270 static const s16 coeff_8k_sb_1seg_dqpsk[8] = {
271 (-835 << 5) | 0x12, (684 << 5) | 0x05, (735 << 5) | 0x14, (-835 << 5) | 0x12, (-598 << 5) | 0x10, (781 << 5) | 0x04, (739 << 5) | 0x13,
275 static const s16 coeff_8k_sb_1seg[8] = {
276 (673 << 5) | 0x0f, (683 << 5) | 0x03, (808 << 5) | 0x12, (673 << 5) | 0x0f, (585 << 5) | 0x0f, (512 << 5) | 0x01, (780 << 5) | 0x0f,
280 static const s16 coeff_8k_sb_3seg_0dqpsk_1dqpsk[8] = {
281 (863 << 5) | 0x17, (930 << 5) | 0x07, (878 << 5) | 0x19, (863 << 5) | 0x17, (0 << 5) | 0x14, (521 << 5) | 0x05, (980 << 5) | 0x18,
285 static const s16 coeff_8k_sb_3seg_0dqpsk[8] = {
286 (-924 << 5) | 0x17, (910 << 5) | 0x06, (774 << 5) | 0x17, (-924 << 5) | 0x17, (-877 << 5) | 0x15, (565 << 5) | 0x04, (553 << 5) | 0x15,
290 static const s16 coeff_8k_sb_3seg_1dqpsk[8] = {
291 (-921 << 5) | 0x19, (607 << 5) | 0x06, (881 << 5) | 0x19, (-921 << 5) | 0x19, (-921 << 5) | 0x14, (713 << 5) | 0x05, (1018 << 5) | 0x18,
295 static const s16 coeff_8k_sb_3seg[8] = {
296 (514 << 5) | 0x14, (910 << 5) | 0x05, (861 << 5) | 0x17, (514 << 5) | 0x14, (690 << 5) | 0x14, (683 << 5) | 0x03, (662 << 5) | 0x15,
300 static const s16 ana_fe_coeff_3seg[24] = {
301 81, 80, 78, 74, 68, 61, 54, 45, 37, 28, 19, 11, 4, 1022, 1017, 1013, 1010, 1008, 1008, 1008, 1008, 1010, 1014, 1017
304 static const s16 ana_fe_coeff_1seg[24] = {
305 249, 226, 164, 82, 5, 981, 970, 988, 1018, 20, 31, 26, 8, 1012, 1000, 1018, 1012, 8, 15, 14, 9, 3, 1017, 1003
308 static const s16 ana_fe_coeff_13seg[24] = {
309 396, 305, 105, -51, -77, -12, 41, 31, -11, -30, -11, 14, 15, -2, -13, -7, 5, 8, 1, -6, -7, -3, 0, 1
315 switch (state->
fe[0]->dtv_property_cache.transmission_mode) {
331 static void dib8000_set_acquisition_mode(
struct dib8000_state *state)
333 u16 nud = dib8000_read_word(state, 298);
334 nud |= (1 << 3) | (1 << 0);
335 dprintk(
"acquisition mode activated");
336 dib8000_write_word(state, 298, nud);
338 static int dib8000_set_output_mode(
struct dvb_frontend *fe,
int mode)
342 u16 outreg, fifo_threshold, smo_mode, sram = 0x0205;
345 fifo_threshold = 1792;
346 smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1);
348 dprintk(
"-I- Setting output mode for demod %p to %d",
349 &state->
fe[0], mode);
356 outreg = (1 << 10) | (1 << 6);
359 outreg = (1 << 10) | (2 << 6) | (0 << 1);
362 if (state->
cfg.hostbus_diversity) {
363 outreg = (1 << 10) | (4 << 6);
369 smo_mode |= (3 << 1);
370 fifo_threshold = 512;
371 outreg = (1 << 10) | (5 << 6);
378 outreg = (1 << 10) | (3 << 6);
379 dib8000_set_acquisition_mode(state);
383 dprintk(
"Unhandled output_mode passed to be set for demod %p",
388 if (state->
cfg.output_mpeg2_in_188_bytes)
389 smo_mode |= (1 << 5);
391 dib8000_write_word(state, 299, smo_mode);
392 dib8000_write_word(state, 300, fifo_threshold);
393 dib8000_write_word(state, 1286, outreg);
394 dib8000_write_word(state, 1291, sram);
402 u16 sync_wait = dib8000_read_word(state, 273) & 0xfff0;
405 dib8000_write_word(state, 272, 1 << 9);
406 dib8000_write_word(state, 273, sync_wait | (1 << 2) | 2);
408 dib8000_write_word(state, 272, 0);
409 dib8000_write_word(state, 273, sync_wait);
415 dib8000_write_word(state, 270, 1);
416 dib8000_write_word(state, 271, 0);
419 dib8000_write_word(state, 270, 6);
420 dib8000_write_word(state, 271, 6);
423 dib8000_write_word(state, 270, 0);
424 dib8000_write_word(state, 271, 1);
433 u16 reg_774 = 0x3fff, reg_775 = 0xffff, reg_776 = 0xffff,
434 reg_900 = (dib8000_read_word(state, 900) & 0xfffc) | 0x3,
438 reg_1280 = (dib8000_read_word(state, 1280) & 0x00ff) | 0xff00;
440 reg_1280 = (dib8000_read_word(state, 1280) & 0x707f) | 0x8f80;
463 dprintk(
"powermode : 774 : %x ; 775 : %x; 776 : %x ; 900 : %x; 1280 : %x", reg_774, reg_775, reg_776, reg_900, reg_1280);
464 dib8000_write_word(state, 774, reg_774);
465 dib8000_write_word(state, 775, reg_775);
466 dib8000_write_word(state, 776, reg_776);
467 dib8000_write_word(state, 900, reg_900);
468 dib8000_write_word(state, 1280, reg_1280);
476 reg = dib8000_read_word(state, 274)&0xfff0;
478 dib8000_write_word(state, 274, reg | 0x7);
480 dib8000_write_word(state, 1803, (7<<2));
482 reg = dib8000_read_word(state, 1280);
484 dib8000_write_word(state, 1280, reg | (1<<2));
487 dib8000_write_word(state, 1280, reg);
495 u16 reg, reg_907 = dib8000_read_word(state, 907);
496 u16 reg_908 = dib8000_read_word(state, 908);
501 reg_908 |= (1 << 1) | (1 << 0);
502 ret |= dib8000_write_word(state, 908, reg_908);
503 reg_908 &= ~(1 << 1);
505 reg = dib8000_read_word(state, 1925);
507 dib8000_write_word(state, 1925, reg |
511 reg = dib8000_read_word(state, 1925);
514 dib8000_write_word(state, 1925, reg & ~(1<<4));
516 reg = dib8000_read_word(state, 921) & ~((0x3 << 14)
520 dib8000_write_word(state, 921, reg | (1 << 14)
527 reg = dib8000_read_word(state, 1925);
529 dib8000_write_word(state, 1925,
530 (reg & ~(1<<2)) | (1<<4));
532 reg_908 |= (1 << 1) | (1 << 0);
541 reg_907 |= (1 << 14) | (1 << 13) | (1 << 12);
542 reg_908 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
546 reg_907 &= ~(1 << 15);
550 reg_907 |= (1 << 15);
557 ret |= dib8000_write_word(state, 907, reg_907);
558 ret |= dib8000_write_word(state, 908, reg_908);
571 if (state->
timf == 0) {
579 dib8000_write_word(state, 29, (
u16) ((timf >> 16) & 0xffff));
580 dib8000_write_word(state, 30, (
u16) ((timf) & 0xffff));
588 dprintk(
"%s: the sad calibration is not needed for the dib8096P",
593 dib8000_write_word(state, 923, (0 << 1) | (0 << 0));
594 dib8000_write_word(state, 924, 776);
597 dib8000_write_word(state, 923, (1 << 0));
598 dib8000_write_word(state, 923, (0 << 0));
610 return dib8000_write_word(state, 106, value);
618 dib8000_write_word(state, 23,
620 dib8000_write_word(state, 24,
623 dib8000_write_word(state, 23, (
u16) (((bw->
internal / 2 * 1000) >> 16) & 0xffff));
624 dib8000_write_word(state, 24,
627 dib8000_write_word(state, 27, (
u16) ((bw->
ifreq >> 16) & 0x01ff));
628 dib8000_write_word(state, 28, (
u16) (bw->
ifreq & 0xffff));
629 dib8000_write_word(state, 26, (
u16) ((bw->
ifreq >> 25) & 0x0003));
632 dib8000_write_word(state, 922, bw->
sad_cfg);
641 dib8000_write_word(state, 901,
649 dib8000_write_word(state, 902, clk_cfg1);
650 clk_cfg1 = (clk_cfg1 & 0xfff7) | (pll->
pll_bypass << 3);
651 dib8000_write_word(state, 902, clk_cfg1);
653 dprintk(
"clk_cfg1: 0x%04x", clk_cfg1);
656 if (state->
cfg.pll->ADClkSrc == 0)
657 dib8000_write_word(state, 904,
658 (0 << 15) | (0 << 12) | (0 << 10) |
661 else if (state->
cfg.refclksel != 0)
662 dib8000_write_word(state, 904, (0 << 15) | (1 << 12) |
663 ((state->
cfg.refclksel & 0x3) << 10) |
667 dib8000_write_word(state, 904, (0 << 15) | (1 << 12) |
668 (3 << 10) | (pll->
modulo << 8) |
671 dib8000_write_word(state, 1856, (!pll->
pll_reset<<13) |
675 reg = dib8000_read_word(state, 1857);
676 dib8000_write_word(state, 1857, reg|(!pll->
pll_bypass<<15));
678 reg = dib8000_read_word(state, 1858);
679 dib8000_write_word(state, 1858, reg | 1);
681 dib8000_write_word(state, 904, (pll->
modulo << 8));
684 dib8000_reset_pll_common(state, pll);
691 u16 reg_1857, reg_1856 = dib8000_read_word(state, 1856);
696 prediv = reg_1856 & 0x3f;
697 loopdiv = (reg_1856 >> 6) & 0x3f;
701 dprintk(
"Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)", prediv, pll->
pll_prediv, loopdiv, pll->
pll_ratio);
703 reg_1857 = dib8000_read_word(state, 1857);
705 dib8000_write_word(state, 1857, reg_1857 & ~(1 << 15));
707 dib8000_write_word(state, 1856, reg_1856 |
712 internal = dib8000_read32(state, 23) / 1000;
713 dprintk(
"Old Internal = %d",
internal);
714 xtal = 2 * (
internal / loopdiv) * prediv;
716 dprintk(
"Xtal = %d , New Fmem = %d New Fdemod = %d, New Fsampling = %d", xtal,
internal/1000,
internal/2000,
internal/8000);
717 dprintk(
"New Internal = %d",
internal);
719 dib8000_write_word(state, 23,
720 (
u16) (((
internal / 2) >> 16) & 0xffff));
721 dib8000_write_word(state, 24, (
u16) ((
internal / 2) & 0xffff));
723 dib8000_write_word(state, 1857, reg_1857 | (1 << 15));
725 while (((dib8000_read_word(state, 1856)>>15)&0x1) != 1)
726 dprintk(
"Waiting for PLL to lock");
729 reg_1856 = dib8000_read_word(state, 1856);
730 dprintk(
"PLL Updated with prediv = %d and loopdiv = %d",
731 reg_1856&0x3f, (reg_1856>>6)&0x3f);
743 dib8000_write_word(st, 1029, st->
cfg.gpio_dir);
744 dib8000_write_word(st, 1030, st->
cfg.gpio_val);
748 dib8000_write_word(st, 1032, st->
cfg.gpio_pwm_pos);
750 dib8000_write_word(st, 1037, st->
cfg.pwm_freq_div);
756 st->
cfg.gpio_dir = dib8000_read_word(st, 1029);
757 st->
cfg.gpio_dir &= ~(1 << num);
758 st->
cfg.gpio_dir |= (dir & 0x1) << num;
759 dib8000_write_word(st, 1029, st->
cfg.gpio_dir);
761 st->
cfg.gpio_val = dib8000_read_word(st, 1030);
762 st->
cfg.gpio_val &= ~(1 << num);
763 st->
cfg.gpio_val |= (val & 0x01) << num;
764 dib8000_write_word(st, 1030, st->
cfg.gpio_val);
766 dprintk(
"gpio dir: %x: gpio val: %x", st->
cfg.gpio_dir, st->
cfg.gpio_val);
774 return dib8000_cfg_gpio(state, num, dir, val);
778 static const u16 dib8000_defaults[] = {
804 (1 << 13) - 825 - 117,
805 (1 << 13) - 837 - 117,
806 (1 << 13) - 811 - 117,
807 (1 << 13) - 766 - 117,
808 (1 << 13) - 737 - 117,
809 (1 << 13) - 693 - 117,
810 (1 << 13) - 648 - 117,
811 (1 << 13) - 619 - 117,
812 (1 << 13) - 575 - 117,
813 (1 << 13) - 531 - 117,
814 (1 << 13) - 501 - 117,
881 value = dib8000_i2c_read16(client, 896);
883 if ((value = dib8000_i2c_read16(client, 896)) != 0x01b3) {
884 dprintk(
"wrong Vendor ID (read=0x%x)", value);
888 value = dib8000_i2c_read16(client, 897);
889 if (value != 0x8000 && value != 0x8001 &&
890 value != 0x8002 && value != 0x8090) {
891 dprintk(
"wrong Device ID (%x)", value);
916 if ((state->
revision = dib8000_identify(&state->
i2c)) == 0)
921 dib8000_write_word(state, 1287, 0x0003);
924 dprintk(
"error : dib8000 MA not supported");
934 dib8000_write_word(state, 770, 0xffff);
935 dib8000_write_word(state, 771, 0xffff);
936 dib8000_write_word(state, 772, 0xfffc);
938 dib8000_write_word(state, 1280, 0x0045);
940 dib8000_write_word(state, 1280, 0x004d);
941 dib8000_write_word(state, 1281, 0x000c);
943 dib8000_write_word(state, 770, 0x0000);
944 dib8000_write_word(state, 771, 0x0000);
945 dib8000_write_word(state, 772, 0x0000);
946 dib8000_write_word(state, 898, 0x0004);
947 dib8000_write_word(state, 1280, 0x0000);
948 dib8000_write_word(state, 1281, 0x0000);
952 if (state->
cfg.drives)
953 dib8000_write_word(state, 906, state->
cfg.drives);
955 dprintk(
"using standard PAD-drive-settings, please adjust settings in config-struct to be optimal.");
957 dib8000_write_word(state, 906, 0x2d98);
961 dib8000_reset_pll(state);
963 dib8000_write_word(state, 898, 0x0004);
965 if (dib8000_reset_gpio(state) != 0)
966 dprintk(
"GPIO reset was not successful.");
970 dprintk(
"OUTPUT_MODE could not be resetted.");
976 if (state->
cfg.pll->ifreq == 0)
977 dib8000_write_word(state, 40, 0x0755);
979 dib8000_write_word(state, 40, 0x1f55);
984 n = dib8000_defaults;
989 dib8000_write_word(state,
r, *n++);
996 dib8000_write_word(state, 903, (0 << 4) | 2);
1000 if (state->
cfg.div_cfg != 0)
1001 dib8000_write_word(state, 903, state->
cfg.div_cfg);
1004 dib8000_write_word(state, 1285, dib8000_read_word(state, 1285) & ~(1 << 1));
1006 dib8000_set_bandwidth(fe, 6000);
1010 dib8000_sad_calib(state);
1019 static void dib8000_restart_agc(
struct dib8000_state *state)
1022 dib8000_write_word(state, 770, 0x0a00);
1023 dib8000_write_word(state, 770, 0x0000);
1030 if (state->
cfg.update_lna) {
1032 dyn_gain = dib8000_read_word(state, 390);
1034 if (state->
cfg.update_lna(state->
fe[0], dyn_gain)) {
1035 dib8000_restart_agc(state);
1042 static int dib8000_set_agc_config(
struct dib8000_state *state,
u8 band)
1052 for (i = 0; i < state->
cfg.agc_config_count; i++)
1053 if (state->
cfg.agc[i].band_caps & band) {
1054 agc = &state->
cfg.agc[
i];
1059 dprintk(
"no valid AGC configuration found for band 0x%02x", band);
1066 dib8000_write_word(state, 76, agc->
setup);
1067 dib8000_write_word(state, 77, agc->
inv_gain);
1075 dprintk(
"WBD: ref: %d, sel: %d, active: %d, alpha: %d",
1080 dib8000_write_word(state, 106, state->
wbd_ref);
1082 dib8000_write_word(state, 106, agc->
wbd_ref);
1085 reg = dib8000_read_word(state, 922) & (0x3 << 2);
1086 dib8000_write_word(state, 922, reg | (agc->
wbd_sel << 2));
1090 dib8000_write_word(state, 108, agc->
agc1_max);
1091 dib8000_write_word(state, 109, agc->
agc1_min);
1092 dib8000_write_word(state, 110, agc->
agc2_max);
1093 dib8000_write_word(state, 111, agc->
agc2_min);
1099 dib8000_write_word(state, 75, agc->
agc1_pt3);
1101 dib8000_write_word(state, 923,
1102 (dib8000_read_word(state, 923) & 0xffe3) |
1116 static int dib8000_agc_soft_split(
struct dib8000_state *state)
1118 u16 agc, split_offset;
1124 agc = dib8000_read_word(state, 390);
1128 else if (agc < state->
current_agc->split.max_thres)
1135 dprintk(
"AGC split_offset: %d", split_offset);
1138 dib8000_write_word(state, 107, (dib8000_read_word(state, 107) & 0xff00) | split_offset);
1142 static int dib8000_agc_startup(
struct dvb_frontend *fe)
1147 u16 reg, upd_demod_gain_period = 0x8000;
1149 switch (*tune_state) {
1158 reg = dib8000_read_word(state, 1947)&0xff00;
1159 dib8000_write_word(state, 1946,
1160 upd_demod_gain_period & 0xFFFF);
1162 dib8000_write_word(state, 1947, reg | (1<<14) |
1163 ((upd_demod_gain_period >> 16) & 0xFF));
1166 reg = dib8000_read_word(state, 1920);
1167 dib8000_write_word(state, 1920, (reg | 0x3) &
1183 if (state->
cfg.agc_control)
1184 state->
cfg.agc_control(fe, 1);
1186 dib8000_restart_agc(state);
1197 if (dib8000_update_lna(state))
1205 dib8000_agc_soft_split(state);
1207 if (state->
cfg.agc_control)
1208 state->
cfg.agc_control(fe, 0);
1213 ret = dib8000_agc_soft_split(state);
1220 static void dib8096p_host_bus_drive(
struct dib8000_state *state,
u8 drive)
1227 reg = dib8000_read_word(state, 1798) &
1228 ~(0x7 | (0x7 << 6) | (0x7 << 12));
1229 reg |= (drive<<12) | (drive<<6) | drive;
1230 dib8000_write_word(state, 1798, reg);
1233 reg = dib8000_read_word(state, 1799) & ~((0x7 << 2) | (0x7 << 8));
1234 reg |= (drive<<8) | (drive<<2);
1235 dib8000_write_word(state, 1799, reg);
1238 reg = dib8000_read_word(state, 1800) &
1239 ~(0x7 | (0x7 << 6) | (0x7 << 12));
1240 reg |= (drive<<12) | (drive<<6) | drive;
1241 dib8000_write_word(state, 1800, reg);
1244 reg = dib8000_read_word(state, 1801) & ~((0x7 << 2) | (0x7 << 8));
1245 reg |= (drive<<8) | (drive<<2);
1246 dib8000_write_word(state, 1801, reg);
1249 reg = dib8000_read_word(state, 1802) &
1250 ~(0x7 | (0x7 << 6) | (0x7 << 12));
1251 reg |= (drive<<12) | (drive<<6) | drive;
1252 dib8000_write_word(state, 1802, reg);
1255 static u32 dib8096p_calcSyncFreq(
u32 P_Kin,
u32 P_Kout,
1256 u32 insertExtSynchro,
u32 syncSize)
1259 u32 nom = (insertExtSynchro * P_Kin+syncSize);
1261 u32 syncFreq = ((nom << quantif) / denom);
1263 if ((syncFreq & ((1 << quantif) - 1)) != 0)
1264 syncFreq = (syncFreq >> quantif) + 1;
1266 syncFreq = (syncFreq >> quantif);
1269 syncFreq = syncFreq - 1;
1275 u32 P_Kout,
u32 insertExtSynchro,
u32 synchroMode,
1276 u32 syncWord,
u32 syncSize)
1278 dprintk(
"Configure DibStream Tx");
1280 dib8000_write_word(state, 1615, 1);
1281 dib8000_write_word(state, 1603, P_Kin);
1282 dib8000_write_word(state, 1605, P_Kout);
1283 dib8000_write_word(state, 1606, insertExtSynchro);
1284 dib8000_write_word(state, 1608, synchroMode);
1285 dib8000_write_word(state, 1609, (syncWord >> 16) & 0xffff);
1286 dib8000_write_word(state, 1610, syncWord & 0xffff);
1287 dib8000_write_word(state, 1612, syncSize);
1288 dib8000_write_word(state, 1615, 0);
1292 u32 P_Kout,
u32 synchroMode,
u32 insertExtSynchro,
1293 u32 syncWord,
u32 syncSize,
u32 dataOutRate)
1297 dprintk(
"Configure DibStream Rx synchroMode = %d", synchroMode);
1299 if ((P_Kin != 0) && (P_Kout != 0)) {
1300 syncFreq = dib8096p_calcSyncFreq(P_Kin, P_Kout,
1301 insertExtSynchro, syncSize);
1302 dib8000_write_word(state, 1542, syncFreq);
1305 dib8000_write_word(state, 1554, 1);
1306 dib8000_write_word(state, 1536, P_Kin);
1307 dib8000_write_word(state, 1537, P_Kout);
1308 dib8000_write_word(state, 1539, synchroMode);
1309 dib8000_write_word(state, 1540, (syncWord >> 16) & 0xffff);
1310 dib8000_write_word(state, 1541, syncWord & 0xffff);
1311 dib8000_write_word(state, 1543, syncSize);
1312 dib8000_write_word(state, 1544, dataOutRate);
1313 dib8000_write_word(state, 1554, 0);
1316 static void dib8096p_enMpegMux(
struct dib8000_state *state,
int onoff)
1320 reg_1287 = dib8000_read_word(state, 1287);
1324 reg_1287 &= ~(1 << 8);
1327 reg_1287 |= (1 << 8);
1331 dib8000_write_word(state, 1287, reg_1287);
1334 static void dib8096p_configMpegMux(
struct dib8000_state *state,
1335 u16 pulseWidth,
u16 enSerialMode,
u16 enSerialClkDiv2)
1341 dib8096p_enMpegMux(state, 0);
1345 enSerialClkDiv2 = 0;
1347 reg_1287 = ((pulseWidth & 0x1f) << 3) |
1348 ((enSerialMode & 0x1) << 2) | (enSerialClkDiv2 & 0x1);
1349 dib8000_write_word(state, 1287, reg_1287);
1351 dib8096p_enMpegMux(state, 1);
1354 static void dib8096p_setDibTxMux(
struct dib8000_state *state,
int mode)
1356 u16 reg_1288 = dib8000_read_word(state, 1288) & ~(0x7 << 7);
1360 dprintk(
"SET MPEG ON DIBSTREAM TX");
1361 dib8096p_cfg_DibTx(state, 8, 5, 0, 0, 0, 0);
1362 reg_1288 |= (1 << 9);
break;
1364 dprintk(
"SET DIV_OUT ON DIBSTREAM TX");
1365 dib8096p_cfg_DibTx(state, 5, 5, 0, 0, 0, 0);
1366 reg_1288 |= (1 << 8);
break;
1368 dprintk(
"SET ADC_OUT ON DIBSTREAM TX");
1369 dib8096p_cfg_DibTx(state, 20, 5, 10, 0, 0, 0);
1370 reg_1288 |= (1 << 7);
break;
1374 dib8000_write_word(state, 1288, reg_1288);
1377 static void dib8096p_setHostBusMux(
struct dib8000_state *state,
int mode)
1379 u16 reg_1288 = dib8000_read_word(state, 1288) & ~(0x7 << 4);
1383 dprintk(
"SET DEM OUT OLD INTERF ON HOST BUS");
1384 dib8096p_enMpegMux(state, 0);
1385 reg_1288 |= (1 << 6);
1388 dprintk(
"SET DIBSTREAM TX ON HOST BUS");
1389 dib8096p_enMpegMux(state, 0);
1390 reg_1288 |= (1 << 5);
1393 dprintk(
"SET MPEG MUX ON HOST BUS");
1394 reg_1288 |= (1 << 4);
1399 dib8000_write_word(state, 1288, reg_1288);
1402 static int dib8096p_set_diversity_in(
struct dvb_frontend *fe,
int onoff)
1409 dprintk(
"%s mode OFF : by default Enable Mpeg INPUT",
1412 dib8096p_cfg_DibRx(state, 8, 5, 0, 0, 0, 8, 0);
1416 reg_1287 = dib8000_read_word(state, 1287);
1418 if ((reg_1287 & 0x1) == 1) {
1421 dib8000_write_word(state, 1287, reg_1287);
1427 dprintk(
"%s ON : Enable diversity INPUT", __func__);
1428 dib8096p_cfg_DibRx(state, 5, 5, 0, 0, 0, 0, 0);
1433 dib8000_set_diversity_in(state->
fe[0], onoff);
1437 static int dib8096p_set_output_mode(
struct dvb_frontend *fe,
int mode)
1440 u16 outreg, smo_mode, fifo_threshold;
1441 u8 prefer_mpeg_mux_use = 1;
1444 dib8096p_host_bus_drive(state, 1);
1446 fifo_threshold = 1792;
1447 smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1);
1448 outreg = dib8000_read_word(state, 1286) &
1449 ~((1 << 10) | (0x7 << 6) | (1 << 1));
1457 if (prefer_mpeg_mux_use) {
1458 dprintk(
"dib8096P setting output mode TS_SERIAL using Mpeg Mux");
1459 dib8096p_configMpegMux(state, 3, 1, 1);
1462 dprintk(
"dib8096P setting output mode TS_SERIAL using Smooth bloc");
1463 dib8096p_setHostBusMux(state,
1465 outreg |= (2 << 6) | (0 << 1);
1470 if (prefer_mpeg_mux_use) {
1471 dprintk(
"dib8096P setting output mode TS_PARALLEL_GATED using Mpeg Mux");
1472 dib8096p_configMpegMux(state, 2, 0, 0);
1475 dprintk(
"dib8096P setting output mode TS_PARALLEL_GATED using Smooth block");
1476 dib8096p_setHostBusMux(state,
1483 dprintk(
"dib8096P setting output mode TS_PARALLEL_CONT using Smooth block");
1491 dprintk(
"dib8096P setting output mode TS_FIFO using Smooth block");
1494 smo_mode |= (3 << 1);
1495 fifo_threshold = 512;
1499 dprintk(
"dib8096P setting output mode MODE_DIVERSITY");
1505 dprintk(
"dib8096P setting output mode MODE_ANALOG_ADC");
1514 dprintk(
"output_mpeg2_in_188_bytes = %d",
1515 state->
cfg.output_mpeg2_in_188_bytes);
1516 if (state->
cfg.output_mpeg2_in_188_bytes)
1517 smo_mode |= (1 << 5);
1519 ret |= dib8000_write_word(state, 299, smo_mode);
1521 ret |= dib8000_write_word(state, 299 + 1, fifo_threshold);
1522 ret |= dib8000_write_word(state, 1286, outreg);
1527 static int map_addr_to_serpar_number(
struct i2c_msg *msg)
1529 if (msg->
buf[0] <= 15)
1531 else if (msg->
buf[0] == 17)
1533 else if (msg->
buf[0] == 16)
1535 else if (msg->
buf[0] == 19)
1537 else if (msg->
buf[0] >= 21 && msg->
buf[0] <= 25)
1539 else if (msg->
buf[0] == 28)
1541 else if (msg->
buf[0] == 99)
1548 static int dib8096p_tuner_write_serpar(
struct i2c_adapter *i2c_adap,
1549 struct i2c_msg msg[],
int num)
1554 u16 serpar_num = msg[0].
buf[0];
1556 while (n_overflow == 1 && i) {
1557 n_overflow = (dib8000_read_word(state, 1984) >> 1) & 0x1;
1560 dprintk(
"Tuner ITF: write busy (overflow)");
1562 dib8000_write_word(state, 1985, (1 << 6) | (serpar_num & 0x3f));
1563 dib8000_write_word(state, 1986, (msg[0].
buf[1] << 8) | msg[0].
buf[2]);
1568 static int dib8096p_tuner_read_serpar(
struct i2c_adapter *i2c_adap,
1569 struct i2c_msg msg[],
int num)
1572 u8 n_overflow = 1, n_empty = 1;
1574 u16 serpar_num = msg[0].
buf[0];
1577 while (n_overflow == 1 && i) {
1578 n_overflow = (dib8000_read_word(state, 1984) >> 1) & 0x1;
1581 dprintk(
"TunerITF: read busy (overflow)");
1583 dib8000_write_word(state, 1985, (0<<6) | (serpar_num&0x3f));
1586 while (n_empty == 1 && i) {
1587 n_empty = dib8000_read_word(state, 1984)&0x1;
1590 dprintk(
"TunerITF: read busy (empty)");
1593 read_word = dib8000_read_word(state, 1987);
1594 msg[1].
buf[0] = (read_word >> 8) & 0xff;
1595 msg[1].
buf[1] = (read_word) & 0xff;
1600 static int dib8096p_tuner_rw_serpar(
struct i2c_adapter *i2c_adap,
1601 struct i2c_msg msg[],
int num)
1603 if (map_addr_to_serpar_number(&msg[0]) == 0) {
1605 return dib8096p_tuner_write_serpar(i2c_adap, msg, 1);
1607 return dib8096p_tuner_read_serpar(i2c_adap, msg, 2);
1612 static int dib8096p_rw_on_apb(
struct i2c_adapter *i2c_adap,
1613 struct i2c_msg msg[],
int num,
u16 apb_address)
1619 dib8000_write_word(state, apb_address,
1620 ((msg[0].
buf[1] << 8) | (msg[0].
buf[2])));
1622 word = dib8000_read_word(state, apb_address);
1623 msg[1].
buf[0] = (word >> 8) & 0xff;
1624 msg[1].
buf[1] = (
word) & 0xff;
1629 static int dib8096p_tuner_xfer(
struct i2c_adapter *i2c_adap,
1630 struct i2c_msg msg[],
int num)
1636 switch (msg[0].
buf[0]) {
1723 i = ((dib8000_read_word(state, 921) >> 12)&0x3);
1724 word = dib8000_read_word(state, 924+i);
1725 msg[1].
buf[0] = (word >> 8) & 0xff;
1726 msg[1].
buf[1] = (
word) & 0xff;
1730 word = (
u16) ((msg[0].buf[1] << 8) |
1734 word = (dib8000_read_word(state, 921) &
1735 ~(3<<12)) | (word<<12);
1737 dib8000_write_word(state, 921, word);
1742 if (apb_address != 0)
1743 return dib8096p_rw_on_apb(i2c_adap, msg, num, apb_address);
1745 return dib8096p_tuner_rw_serpar(i2c_adap, msg, num);
1756 .master_xfer = dib8096p_tuner_xfer,
1757 .functionality = dib8096p_i2c_func,
1772 dprintk(
"sleep dib8096p: %d", onoff);
1774 en_cur_state = dib8000_read_word(state, 1922);
1777 if (en_cur_state > 0xff)
1781 en_cur_state &= 0x00ff;
1787 dib8000_write_word(state, 1922, en_cur_state);
1793 static const s32 lut_1000ln_mant[] =
1795 908, 7003, 7090, 7170, 7244, 7313, 7377, 7438, 7495, 7549, 7600
1801 u32 ix = 0, tmp_val = 0,
exp = 0, mant = 0;
1804 val = dib8000_read32(state, 384);
1807 while (tmp_val >>= 1)
1809 mant = (val * 1000 / (1<<
exp));
1810 ix = (
u8)((mant-1000)/100);
1811 val = (lut_1000ln_mant[ix] + 693*(
exp-20) - 6908);
1812 val = (val*256)/1000;
1825 val = dib8000_read_word(state, 403);
1828 val = dib8000_read_word(state, 404);
1838 static void dib8000_update_timf(
struct dib8000_state *state)
1840 u32 timf = state->
timf = dib8000_read32(state, 435);
1842 dib8000_write_word(state, 29, (
u16) (timf >> 16));
1843 dib8000_write_word(state, 30, (
u16) (timf & 0xffff));
1856 dib8000_update_timf(state);
1861 dib8000_set_bandwidth(state->
fe[0], 6000);
1867 static const u16 adc_target_16dB[11] = {
1868 (1 << 13) - 825 - 117,
1869 (1 << 13) - 837 - 117,
1870 (1 << 13) - 811 - 117,
1871 (1 << 13) - 766 - 117,
1872 (1 << 13) - 737 - 117,
1873 (1 << 13) - 693 - 117,
1874 (1 << 13) - 648 - 117,
1875 (1 << 13) - 619 - 117,
1876 (1 << 13) - 575 - 117,
1877 (1 << 13) - 531 - 117,
1878 (1 << 13) - 501 - 117
1880 static const u8 permu_seg[] = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 };
1882 static void dib8000_set_channel(
struct dib8000_state *state,
u8 seq,
u8 autosearching)
1884 u16 mode, max_constellation, seg_diff_mask = 0, nbseg_diff = 0;
1885 u8 guard, crate, constellation, timeI;
1886 u16 i,
coeff[4], P_cfr_left_edge = 0, P_cfr_right_edge = 0, seg_mask13 = 0x1fff;
1887 const s16 *ncoeff =
NULL, *ana_fe;
1889 u16 coff_pow = 0x2800;
1890 u16 init_prbs = 0xfff;
1894 dib8000_init_sdram(state);
1897 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & 0x60) | state->
ber_monitored_layer);
1899 dib8000_write_word(state, 285, dib8000_read_word(state, 285) & 0x60);
1901 i = dib8000_read_word(state, 26) & 1;
1902 dib8000_write_word(state, 26, state->
fe[0]->dtv_property_cache.inversion^i);
1904 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode) {
1907 state->
fe[0]->dtv_property_cache.isdbt_sb_segment_idx -
1908 (state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) -
1909 (state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2);
1910 int clk = state->
cfg.pll->internal;
1911 u32 segtodds = ((
u32) (430 << 23) / clk) << 3;
1912 int dds_offset = seg_offset * segtodds;
1913 int new_dds, sub_channel;
1914 if ((state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1915 dds_offset -= (
int)(segtodds / 2);
1917 if (state->
cfg.pll->ifreq == 0) {
1918 if ((state->
fe[0]->dtv_property_cache.inversion ^ i) == 0) {
1919 dib8000_write_word(state, 26, dib8000_read_word(state, 26) | 1);
1920 new_dds = dds_offset;
1922 new_dds = dds_offset;
1928 if ((state->
fe[0]->dtv_property_cache.delivery_system ==
SYS_ISDBT)
1929 && (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1)
1930 && (((state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2)
1931 && (state->
fe[0]->dtv_property_cache.isdbt_sb_segment_idx ==
1932 ((state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
1933 || (((state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1934 && (state->
fe[0]->dtv_property_cache.isdbt_sb_segment_idx == (state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2)))
1935 || (((state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1936 && (state->
fe[0]->dtv_property_cache.isdbt_sb_segment_idx ==
1937 ((state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
1939 new_dds -= ((
u32) (850 << 22) / clk) << 4;
1942 if ((state->
fe[0]->dtv_property_cache.inversion ^ i) == 0)
1943 new_dds = state->
cfg.pll->ifreq - dds_offset;
1945 new_dds = state->
cfg.pll->ifreq + dds_offset;
1947 dib8000_write_word(state, 27, (
u16) ((new_dds >> 16) & 0x01ff));
1948 dib8000_write_word(state, 28, (
u16) (new_dds & 0xffff));
1949 if (state->
fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2)
1950 sub_channel = ((state->
fe[0]->dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset) + 1) % 41) / 3;
1952 sub_channel = ((state->
fe[0]->dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset)) % 41) / 3;
1957 dib8000_write_word(state, 219, dib8000_read_word(state, 219) | 0x1);
1958 dib8000_write_word(state, 190, dib8000_read_word(state, 190) | (0x1 << 14));
1960 dib8000_write_word(state, 219, dib8000_read_word(state, 219) & 0xfffe);
1961 dib8000_write_word(state, 190, dib8000_read_word(state, 190) & 0xbfff);
1964 switch (state->
fe[0]->dtv_property_cache.transmission_mode) {
1966 switch (sub_channel) {
2014 switch (sub_channel) {
2063 switch (sub_channel) {
2111 dib8000_write_word(state, 27, (
u16) ((state->
cfg.pll->ifreq >> 16) & 0x01ff));
2112 dib8000_write_word(state, 28, (
u16) (state->
cfg.pll->ifreq & 0xffff));
2113 dib8000_write_word(state, 26, (
u16) ((state->
cfg.pll->ifreq >> 25) & 0x0003));
2116 dib8000_write_word(state, 10, (seq << 4));
2119 switch (state->
fe[0]->dtv_property_cache.guard_interval) {
2135 dib8000_write_word(state, 1, (init_prbs << 2) | (guard & 0x3));
2137 max_constellation =
DQPSK;
2138 for (i = 0; i < 3; i++) {
2139 switch (state->
fe[0]->dtv_property_cache.layer[i].modulation) {
2155 switch (state->
fe[0]->dtv_property_cache.layer[i].fec) {
2174 if ((state->
fe[0]->dtv_property_cache.layer[i].interleaving > 0) &&
2175 ((state->
fe[0]->dtv_property_cache.layer[i].interleaving <= 3) ||
2176 (state->
fe[0]->dtv_property_cache.layer[i].interleaving == 4 && state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1))
2178 timeI = state->
fe[0]->dtv_property_cache.layer[
i].interleaving;
2181 dib8000_write_word(state, 2 + i, (constellation << 10) | ((state->
fe[0]->dtv_property_cache.layer[i].segment_count & 0xf) << 6) |
2182 (crate << 3) | timeI);
2183 if (state->
fe[0]->dtv_property_cache.layer[i].segment_count > 0) {
2184 switch (max_constellation) {
2187 if (state->
fe[0]->dtv_property_cache.layer[i].modulation ==
QAM_16 ||
2188 state->
fe[0]->dtv_property_cache.layer[i].modulation ==
QAM_64)
2189 max_constellation = state->
fe[0]->dtv_property_cache.layer[
i].modulation;
2192 if (state->
fe[0]->dtv_property_cache.layer[i].modulation ==
QAM_64)
2193 max_constellation = state->
fe[0]->dtv_property_cache.layer[
i].modulation;
2199 mode = fft_to_mode(state);
2203 dib8000_write_word(state, 274, (dib8000_read_word(state, 274) & 0xffcf) |
2204 ((state->
fe[0]->dtv_property_cache.isdbt_partial_reception & 1) << 5) | ((state->
fe[0]->dtv_property_cache.
2205 isdbt_sb_mode & 1) << 4));
2207 dprintk(
"mode = %d ; guard = %d", mode, state->
fe[0]->dtv_property_cache.guard_interval);
2211 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception) {
2212 seg_diff_mask = (state->
fe[0]->dtv_property_cache.layer[0].modulation ==
DQPSK) << permu_seg[0];
2213 for (i = 1; i < 3; i++)
2215 (state->
fe[0]->dtv_property_cache.layer[i].modulation ==
DQPSK) * state->
fe[0]->dtv_property_cache.layer[
i].segment_count;
2216 for (i = 0; i < nbseg_diff; i++)
2217 seg_diff_mask |= 1 << permu_seg[i + 1];
2219 for (i = 0; i < 3; i++)
2221 (state->
fe[0]->dtv_property_cache.layer[i].modulation ==
DQPSK) * state->
fe[0]->dtv_property_cache.layer[
i].segment_count;
2222 for (i = 0; i < nbseg_diff; i++)
2223 seg_diff_mask |= 1 << permu_seg[i];
2225 dprintk(
"nbseg_diff = %X (%d)", seg_diff_mask, seg_diff_mask);
2233 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2234 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 1)
2235 seg_mask13 = 0x00E0;
2237 seg_mask13 = 0x0040;
2239 seg_mask13 = 0x1fff;
2242 dib8000_write_word(state, 0, (mode << 13) | seg_diff_mask);
2244 if ((seg_diff_mask) || (state->
fe[0]->dtv_property_cache.isdbt_sb_mode))
2245 dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200);
2247 dib8000_write_word(state, 268, (2 << 9) | 39);
2251 dib8000_write_word(state, 352, seg_diff_mask);
2253 dib8000_write_word(state, 353, seg_mask13);
2258 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2259 switch (state->
fe[0]->dtv_property_cache.transmission_mode) {
2261 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
2262 if (state->
fe[0]->dtv_property_cache.layer[0].modulation ==
DQPSK)
2263 ncoeff = coeff_2k_sb_1seg_dqpsk;
2265 ncoeff = coeff_2k_sb_1seg;
2267 if (state->
fe[0]->dtv_property_cache.layer[0].modulation ==
DQPSK) {
2268 if (state->
fe[0]->dtv_property_cache.layer[1].modulation ==
DQPSK)
2269 ncoeff = coeff_2k_sb_3seg_0dqpsk_1dqpsk;
2271 ncoeff = coeff_2k_sb_3seg_0dqpsk;
2273 if (state->
fe[0]->dtv_property_cache.layer[1].modulation ==
DQPSK)
2274 ncoeff = coeff_2k_sb_3seg_1dqpsk;
2276 ncoeff = coeff_2k_sb_3seg;
2282 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
2283 if (state->
fe[0]->dtv_property_cache.layer[0].modulation ==
DQPSK)
2284 ncoeff = coeff_4k_sb_1seg_dqpsk;
2286 ncoeff = coeff_4k_sb_1seg;
2288 if (state->
fe[0]->dtv_property_cache.layer[0].modulation ==
DQPSK) {
2289 if (state->
fe[0]->dtv_property_cache.layer[1].modulation ==
DQPSK) {
2290 ncoeff = coeff_4k_sb_3seg_0dqpsk_1dqpsk;
2292 ncoeff = coeff_4k_sb_3seg_0dqpsk;
2295 if (state->
fe[0]->dtv_property_cache.layer[1].modulation ==
DQPSK) {
2296 ncoeff = coeff_4k_sb_3seg_1dqpsk;
2298 ncoeff = coeff_4k_sb_3seg;
2306 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
2307 if (state->
fe[0]->dtv_property_cache.layer[0].modulation ==
DQPSK)
2308 ncoeff = coeff_8k_sb_1seg_dqpsk;
2310 ncoeff = coeff_8k_sb_1seg;
2312 if (state->
fe[0]->dtv_property_cache.layer[0].modulation ==
DQPSK) {
2313 if (state->
fe[0]->dtv_property_cache.layer[1].modulation ==
DQPSK) {
2314 ncoeff = coeff_8k_sb_3seg_0dqpsk_1dqpsk;
2316 ncoeff = coeff_8k_sb_3seg_0dqpsk;
2319 if (state->
fe[0]->dtv_property_cache.layer[1].modulation ==
DQPSK) {
2320 ncoeff = coeff_8k_sb_3seg_1dqpsk;
2322 ncoeff = coeff_8k_sb_3seg;
2327 for (i = 0; i < 8; i++)
2328 dib8000_write_word(state, 343 + i, ncoeff[i]);
2332 dib8000_write_word(state, 351,
2333 (state->
fe[0]->dtv_property_cache.isdbt_sb_mode << 9) | (state->
fe[0]->dtv_property_cache.isdbt_sb_mode << 8) | (13 << 4) | 5);
2337 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2341 dib8000_write_word(state, 187,
2342 (4 << 12) | (0 << 11) | (63 << 5) | (0x3 << 3) | ((~state->
fe[0]->dtv_property_cache.isdbt_partial_reception & 1) << 2)
2348 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
2352 dib8000_write_word(state, 180, 0x1fcf | ((mode - 1) << 14));
2354 dib8000_write_word(state, 180, 0x0fcf | ((mode - 1) << 14));
2357 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (5 << 5) | 4);
2359 dib8000_write_word(state, 340, (16 << 6) | (8 << 0));
2361 dib8000_write_word(state, 341, (6 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
2364 dib8000_write_word(state, 181, 300);
2365 dib8000_write_word(state, 182, 150);
2366 dib8000_write_word(state, 183, 80);
2367 dib8000_write_word(state, 184, 300);
2368 dib8000_write_word(state, 185, 150);
2369 dib8000_write_word(state, 186, 80);
2376 dib8000_write_word(state, 180, 0x1fcf | (1 << 14));
2380 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (4 << 5) | 4);
2382 dib8000_write_word(state, 340, (16 << 6) | (8 << 0));
2384 dib8000_write_word(state, 341, (6 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
2387 dib8000_write_word(state, 181, 350);
2388 dib8000_write_word(state, 182, 300);
2389 dib8000_write_word(state, 183, 250);
2390 dib8000_write_word(state, 184, 350);
2391 dib8000_write_word(state, 185, 300);
2392 dib8000_write_word(state, 186, 250);
2396 dib8000_write_word(state, 180, (16 << 6) | 9);
2397 dib8000_write_word(state, 187, (4 << 12) | (8 << 5) | 0x2);
2399 for (i = 0; i < 6; i++)
2400 dib8000_write_word(state, 181 + i, coff_pow);
2404 dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (3 << 5) | 1);
2407 dib8000_write_word(state, 340, (8 << 6) | (6 << 0));
2409 dib8000_write_word(state, 341, (4 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
2412 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1 && state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
2413 dib8000_write_word(state, 178, 64);
2415 dib8000_write_word(state, 178, 32);
2423 dib8000_write_word(state, 189, ~seg_mask13 | seg_diff_mask);
2424 dib8000_write_word(state, 192, ~seg_mask13 | seg_diff_mask);
2425 dib8000_write_word(state, 225, ~seg_mask13 | seg_diff_mask);
2426 if ((!state->
fe[0]->dtv_property_cache.isdbt_sb_mode) && (state->
cfg.pll->ifreq == 0))
2427 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask | 0x40);
2429 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask);
2430 dib8000_write_word(state, 287, ~seg_mask13 | 0x1000);
2433 dib8000_write_word(state, 288, (~seg_mask13 | seg_diff_mask) & 0x1fff);
2435 dib8000_write_word(state, 288, 0x1fff);
2436 dprintk(
"287 = %X (%d)", ~seg_mask13 | 0x1000, ~seg_mask13 | 0x1000);
2438 dib8000_write_word(state, 211, seg_mask13 & (~seg_diff_mask));
2441 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2442 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
2444 dib8000_write_word(state, 32, ((11 - mode) << 12) | (6 << 8) | 0x40);
2448 dib8000_write_word(state, 32, ((10 - mode) << 12) | (6 << 8) | 0x60);
2452 dib8000_write_word(state, 32, ((9 - mode) << 12) | (6 << 8) | 0x80);
2454 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2455 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
2457 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (10 - mode));
2461 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (9 - mode));
2464 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (8 - mode));
2467 switch (state->
fe[0]->dtv_property_cache.transmission_mode) {
2479 if (state->
cfg.diversity_delay == 0)
2480 mode = (mode * (1 << (guard)) * 3) / 2 + 48;
2482 mode = (mode * (1 << (guard)) * 3) / 2 + state->
cfg.diversity_delay;
2484 dib8000_write_word(state, 273, (dib8000_read_word(state, 273) & 0x000f) | mode);
2487 switch (max_constellation) {
2512 for (mode = 0; mode < 4; mode++)
2513 dib8000_write_word(state, 215 + mode, coeff[mode]);
2516 dib8000_write_word(state, 116, ana_gain);
2519 for (i = 0; i < 10; i++)
2520 dib8000_write_word(state, 80 + i, adc_target_16dB[i]);
2522 for (i = 0; i < 10; i++)
2523 dib8000_write_word(state, 80 + i, adc_target_16dB[i] - 355);
2527 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode) {
2528 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 1)
2529 ana_fe = ana_fe_coeff_3seg;
2531 ana_fe = ana_fe_coeff_1seg;
2533 ana_fe = ana_fe_coeff_13seg;
2535 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1 || state->
isdbt_cfg_loaded == 0)
2536 for (mode = 0; mode < 24; mode++)
2537 dib8000_write_word(state, 117 + mode, ana_fe[mode]);
2540 for (i = 0; i < 13; i++) {
2541 if ((((~seg_diff_mask) >> i) & 1) == 1) {
2542 P_cfr_left_edge += (1 <<
i) * ((i == 0) || ((((seg_mask13 & (~seg_diff_mask)) >> (i - 1)) & 1) == 0));
2543 P_cfr_right_edge += (1 <<
i) * ((i == 12) || ((((seg_mask13 & (~seg_diff_mask)) >> (i + 1)) & 1) == 0));
2546 dib8000_write_word(state, 222, P_cfr_left_edge);
2547 dib8000_write_word(state, 223, P_cfr_right_edge);
2551 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2552 dib8000_write_word(state, 228, 1);
2553 dib8000_write_word(state, 205, dib8000_read_word(state, 205) & 0xfff0);
2554 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0
2557 dib8000_write_word(state, 265, 15);
2560 dib8000_write_word(state, 228, 0);
2561 dib8000_write_word(state, 265, 31);
2562 dib8000_write_word(state, 205, 0x200f);
2565 for (i = 0; i < 3; i++)
2567 (((state->
fe[0]->dtv_property_cache.layer[i].modulation ==
DQPSK) * 4 + 1) * state->
fe[0]->dtv_property_cache.layer[i].segment_count);
2570 tmcc_pow *= (1 << (9 - 2));
2572 dib8000_write_word(state, 290, tmcc_pow);
2573 dib8000_write_word(state, 291, tmcc_pow);
2574 dib8000_write_word(state, 292, tmcc_pow);
2579 dib8000_write_word(state, 250, 3285);
2581 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1)
2588 static int dib8000_autosearch_start(
struct dvb_frontend *fe)
2596 state->
fe[0]->dtv_property_cache.inversion = 0;
2597 if (!state->
fe[0]->dtv_property_cache.isdbt_sb_mode)
2598 state->
fe[0]->dtv_property_cache.layer[0].segment_count = 13;
2599 state->
fe[0]->dtv_property_cache.layer[0].modulation =
QAM_64;
2600 state->
fe[0]->dtv_property_cache.layer[0].fec =
FEC_2_3;
2601 state->
fe[0]->dtv_property_cache.layer[0].interleaving = 0;
2604 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode) {
2608 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13));
2613 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13));
2619 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13));
2629 dprintk(
"using list for autosearch : %d", slist);
2630 dib8000_set_channel(state, (
unsigned char)slist, 1);
2636 dib8000_write_word(state, 6, 0x4);
2637 dib8000_write_word(state, 7, 0x8);
2638 dib8000_write_word(state, 8, 0x1000);
2641 value = 50 * state->
cfg.pll->internal * factor;
2642 dib8000_write_word(state, 11, (
u16) ((value >> 16) & 0xffff));
2643 dib8000_write_word(state, 12, (
u16) (value & 0xffff));
2644 value = 100 * state->
cfg.pll->internal * factor;
2645 dib8000_write_word(state, 13, (
u16) ((value >> 16) & 0xffff));
2646 dib8000_write_word(state, 14, (
u16) (value & 0xffff));
2647 value = 1000 * state->
cfg.pll->internal * factor;
2648 dib8000_write_word(state, 15, (
u16) ((value >> 16) & 0xffff));
2649 dib8000_write_word(state, 16, (
u16) (value & 0xffff));
2651 value = dib8000_read_word(state, 0);
2652 dib8000_write_word(state, 0, (
u16) ((1 << 15) | value));
2653 dib8000_read_word(state, 1284);
2654 dib8000_write_word(state, 0, (
u16) value);
2661 static int dib8000_autosearch_irq(
struct dvb_frontend *fe)
2664 u16 irq_pending = dib8000_read_word(state, 1284);
2666 if (irq_pending & 0x1) {
2667 dprintk(
"dib8000_autosearch_irq failed");
2671 if (irq_pending & 0x2) {
2672 dprintk(
"dib8000_autosearch_irq succeeded");
2689 mode = fft_to_mode(state);
2691 dib8000_set_bandwidth(fe, state->
fe[0]->dtv_property_cache.bandwidth_hz / 1000);
2692 dib8000_set_channel(state, 0, 0);
2695 ret |= dib8000_write_word(state, 770, 0x4000);
2696 ret |= dib8000_write_word(state, 770, 0x0000);
2703 if (state->
timf == 0) {
2704 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2705 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
2712 if (state->
fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
2713 if (state->
fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
2716 dib8000_write_word(state, 32, ((13 - mode) << 12) | (6 << 8) | 0x40);
2720 ret |= dib8000_write_word(state, 37, (12 - mode) | ((5 + mode) << 5));
2725 dib8000_write_word(state, 32, ((12 - mode) << 12) | (6 << 8) | 0x60);
2727 ret |= dib8000_write_word(state, 37, (11 - mode) | ((5 + mode) << 5));
2732 dib8000_write_word(state, 32, ((11 - mode) << 12) | (6 << 8) | 0x80);
2734 ret |= dib8000_write_word(state, 37, (10 - mode) | ((5 + mode) << 5));
2740 lock = dib8000_read_word(state, 568);
2742 lock = dib8000_read_word(state, 570);
2743 if ((lock >> 11) & 0x1)
2744 dib8000_update_timf(state);
2747 dib8000_write_word(state, 6, 0x200);
2750 value = dib8000_read_word(state, 903);
2751 dib8000_write_word(state, 903, value & ~(1 << 3));
2753 dib8000_write_word(state, 903, value | (1 << 3));
2768 dprintk(
"could not start Slow ADC");
2771 dib8000_sad_calib(state);
2774 ret = state->
fe[index_frontend]->ops.init(state->
fe[index_frontend]);
2789 ret = state->
fe[index_frontend]->ops.sleep(state->
fe[index_frontend]);
2815 static int dib8000_get_frontend(
struct dvb_frontend *fe)
2820 u8 index_frontend, sub_index_frontend;
2825 state->
fe[index_frontend]->ops.read_status(state->
fe[index_frontend], &stat);
2827 dprintk(
"TMCC lock on the slave%i", index_frontend);
2829 state->
fe[index_frontend]->ops.get_frontend(state->
fe[index_frontend]);
2830 for (sub_index_frontend = 0; (sub_index_frontend <
MAX_NUMBER_OF_FRONTENDS) && (state->
fe[sub_index_frontend] !=
NULL); sub_index_frontend++) {
2831 if (sub_index_frontend != index_frontend) {
2832 state->
fe[sub_index_frontend]->dtv_property_cache.isdbt_sb_mode = state->
fe[index_frontend]->dtv_property_cache.isdbt_sb_mode;
2833 state->
fe[sub_index_frontend]->dtv_property_cache.inversion = state->
fe[index_frontend]->dtv_property_cache.inversion;
2834 state->
fe[sub_index_frontend]->dtv_property_cache.transmission_mode = state->
fe[index_frontend]->dtv_property_cache.transmission_mode;
2835 state->
fe[sub_index_frontend]->dtv_property_cache.guard_interval = state->
fe[index_frontend]->dtv_property_cache.guard_interval;
2836 state->
fe[sub_index_frontend]->dtv_property_cache.isdbt_partial_reception = state->
fe[index_frontend]->dtv_property_cache.isdbt_partial_reception;
2837 for (i = 0; i < 3; i++) {
2838 state->
fe[sub_index_frontend]->dtv_property_cache.layer[
i].segment_count = state->
fe[index_frontend]->dtv_property_cache.layer[
i].segment_count;
2839 state->
fe[sub_index_frontend]->dtv_property_cache.layer[
i].interleaving = state->
fe[index_frontend]->dtv_property_cache.layer[
i].interleaving;
2840 state->
fe[sub_index_frontend]->dtv_property_cache.layer[
i].fec = state->
fe[index_frontend]->dtv_property_cache.layer[
i].fec;
2841 state->
fe[sub_index_frontend]->dtv_property_cache.layer[
i].modulation = state->
fe[index_frontend]->dtv_property_cache.layer[
i].modulation;
2852 val = dib8000_read_word(state, 572);
2854 val = dib8000_read_word(state, 570);
2856 switch ((val & 0x30) >> 4) {
2866 switch (val & 0x3) {
2869 dprintk(
"dib8000_get_frontend GI = 1/32 ");
2873 dprintk(
"dib8000_get_frontend GI = 1/16 ");
2876 dprintk(
"dib8000_get_frontend GI = 1/8 ");
2880 dprintk(
"dib8000_get_frontend GI = 1/4 ");
2885 val = dib8000_read_word(state, 505);
2889 for (i = 0; i < 3; i++) {
2890 val = dib8000_read_word(state, 493 + i);
2894 val = dib8000_read_word(state, 499 + i);
2898 val = dib8000_read_word(state, 481 + i);
2899 switch (val & 0x7) {
2902 dprintk(
"dib8000_get_frontend : Layer %d Code Rate = 1/2 ", i);
2906 dprintk(
"dib8000_get_frontend : Layer %d Code Rate = 2/3 ", i);
2910 dprintk(
"dib8000_get_frontend : Layer %d Code Rate = 3/4 ", i);
2914 dprintk(
"dib8000_get_frontend : Layer %d Code Rate = 5/6 ", i);
2918 dprintk(
"dib8000_get_frontend : Layer %d Code Rate = 7/8 ", i);
2922 val = dib8000_read_word(state, 487 + i);
2923 switch (val & 0x3) {
2925 dprintk(
"dib8000_get_frontend : Layer %d DQPSK ", i);
2930 dprintk(
"dib8000_get_frontend : Layer %d QPSK ", i);
2934 dprintk(
"dib8000_get_frontend : Layer %d QAM16 ", i);
2938 dprintk(
"dib8000_get_frontend : Layer %d QAM64 ", i);
2946 state->
fe[index_frontend]->dtv_property_cache.isdbt_sb_mode = fe->
dtv_property_cache.isdbt_sb_mode;
2948 state->
fe[index_frontend]->dtv_property_cache.transmission_mode = fe->
dtv_property_cache.transmission_mode;
2949 state->
fe[index_frontend]->dtv_property_cache.guard_interval = fe->
dtv_property_cache.guard_interval;
2950 state->
fe[index_frontend]->dtv_property_cache.isdbt_partial_reception = fe->
dtv_property_cache.isdbt_partial_reception;
2951 for (i = 0; i < 3; i++) {
2952 state->
fe[index_frontend]->dtv_property_cache.layer[
i].segment_count = fe->
dtv_property_cache.layer[
i].segment_count;
2953 state->
fe[index_frontend]->dtv_property_cache.layer[
i].interleaving = fe->
dtv_property_cache.layer[
i].interleaving;
2955 state->
fe[index_frontend]->dtv_property_cache.layer[
i].modulation = fe->
dtv_property_cache.layer[
i].modulation;
2961 static int dib8000_set_frontend(
struct dvb_frontend *fe)
2964 u8 nbr_pending, exit_condition, index_frontend;
2965 s8 index_frontend_success = -1;
2969 if (state->
fe[0]->dtv_property_cache.frequency == 0) {
2970 dprintk(
"dib8000: must at least specify frequency ");
2974 if (state->
fe[0]->dtv_property_cache.bandwidth_hz == 0) {
2975 dprintk(
"dib8000: no bandwidth specified, set to default ");
2976 state->
fe[0]->dtv_property_cache.bandwidth_hz = 6000000;
2981 state->
fe[index_frontend]->dtv_property_cache.delivery_system =
SYS_ISDBT;
2985 dib8000_set_output_mode(state->
fe[index_frontend],
2988 dib8096p_set_output_mode(state->
fe[index_frontend],
2990 if (state->
fe[index_frontend]->ops.tuner_ops.set_params)
2991 state->
fe[index_frontend]->ops.tuner_ops.set_params(state->
fe[index_frontend]);
2998 time = dib8000_agc_startup(state->
fe[0]);
3000 time_slave = dib8000_agc_startup(state->
fe[index_frontend]);
3017 }
while (exit_condition == 0);
3022 if ((state->
fe[0]->dtv_property_cache.delivery_system !=
SYS_ISDBT) ||
3026 (((state->
fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 0)) != 0) &&
3027 (state->
fe[0]->dtv_property_cache.layer[0].segment_count != 0xff) &&
3028 (state->
fe[0]->dtv_property_cache.layer[0].segment_count != 0) &&
3029 ((state->
fe[0]->dtv_property_cache.layer[0].modulation ==
QAM_AUTO) ||
3030 (state->
fe[0]->dtv_property_cache.layer[0].fec ==
FEC_AUTO))) ||
3031 (((state->
fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 1)) != 0) &&
3032 (state->
fe[0]->dtv_property_cache.layer[1].segment_count != 0xff) &&
3033 (state->
fe[0]->dtv_property_cache.layer[1].segment_count != 0) &&
3034 ((state->
fe[0]->dtv_property_cache.layer[1].modulation ==
QAM_AUTO) ||
3035 (state->
fe[0]->dtv_property_cache.layer[1].fec ==
FEC_AUTO))) ||
3036 (((state->
fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 2)) != 0) &&
3037 (state->
fe[0]->dtv_property_cache.layer[2].segment_count != 0xff) &&
3038 (state->
fe[0]->dtv_property_cache.layer[2].segment_count != 0) &&
3039 ((state->
fe[0]->dtv_property_cache.layer[2].modulation ==
QAM_AUTO) ||
3040 (state->
fe[0]->dtv_property_cache.layer[2].fec ==
FEC_AUTO))) ||
3041 (((state->
fe[0]->dtv_property_cache.layer[0].segment_count == 0) ||
3042 ((state->
fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 0)) == 0)) &&
3043 ((state->
fe[0]->dtv_property_cache.layer[1].segment_count == 0) ||
3044 ((state->
fe[0]->dtv_property_cache.isdbt_layer_enabled & (2 << 0)) == 0)) &&
3045 ((state->
fe[0]->dtv_property_cache.layer[2].segment_count == 0) || ((state->
fe[0]->dtv_property_cache.isdbt_layer_enabled & (3 << 0)) == 0)))) {
3052 dib8000_autosearch_start(state->
fe[index_frontend]);
3060 if (((tune_failed >> index_frontend) & 0x1) == 0) {
3061 found = dib8000_autosearch_irq(state->
fe[index_frontend]);
3067 dprintk(
"autosearch succeed on the frontend%i", index_frontend);
3069 index_frontend_success = index_frontend;
3072 dprintk(
"unhandled autosearch result");
3074 tune_failed |= (1 << index_frontend);
3075 dprintk(
"autosearch failed for the frontend%i", index_frontend);
3082 if ((nbr_pending == 0) && (exit_condition == 0))
3084 }
while ((exit_condition == 0) && i--);
3086 if (exit_condition == 1) {
3091 dprintk(
"tune success on frontend%i", index_frontend_success);
3093 dib8000_get_frontend(fe);
3096 for (index_frontend = 0, ret = 0; (ret >= 0) && (index_frontend <
MAX_NUMBER_OF_FRONTENDS) && (state->
fe[index_frontend] !=
NULL); index_frontend++)
3097 ret = dib8000_tune(state->
fe[index_frontend]);
3101 dib8000_set_output_mode(state->
fe[0], state->
cfg.output_mode);
3102 for (index_frontend = 1;
3104 (state->
fe[index_frontend] !=
NULL);
3106 dib8000_set_output_mode(state->
fe[index_frontend],
3108 dib8000_set_diversity_in(state->
fe[index_frontend-1], 1);
3112 dib8000_set_diversity_in(state->
fe[index_frontend-1], 0);
3114 dib8096p_set_output_mode(state->
fe[0], state->
cfg.output_mode);
3115 if (state->
cfg.enMpegOutput == 0) {
3119 for (index_frontend = 1;
3121 (state->
fe[index_frontend] !=
NULL);
3123 dib8096p_set_output_mode(state->
fe[index_frontend],
3125 dib8096p_set_diversity_in(state->
fe[index_frontend-1], 1);
3129 dib8096p_set_diversity_in(state->
fe[index_frontend-1], 0);
3140 return dib8000_read_word(state, 570);
3141 return dib8000_read_word(state, 568);
3147 u16 lock_slave = 0, lock;
3151 lock = dib8000_read_word(state, 570);
3153 lock = dib8000_read_word(state, 568);
3156 lock_slave |= dib8000_read_lock(state->
fe[index_frontend]);
3160 if (((lock >> 13) & 1) || ((lock_slave >> 13) & 1))
3163 if (((lock >> 8) & 1) || ((lock_slave >> 8) & 1))
3166 if ((((lock >> 1) & 0xf) == 0xf) || (((lock_slave >> 1) & 0xf) == 0xf))
3169 if ((((lock >> 12) & 1) || ((lock_slave >> 12) & 1)) && ((lock >> 5) & 7))
3172 if (((lock >> 12) & 1) || ((lock_slave >> 12) & 1)) {
3173 lock = dib8000_read_word(state, 554);
3177 lock = dib8000_read_word(state, 555);
3181 lock = dib8000_read_word(state, 556);
3195 *ber = (dib8000_read_word(state, 562) << 16) |
3196 dib8000_read_word(state, 563);
3198 *ber = (dib8000_read_word(state, 560) << 16) |
3199 dib8000_read_word(state, 561);
3203 static int dib8000_read_unc_blocks(
struct dvb_frontend *fe,
u32 * unc)
3209 *unc = dib8000_read_word(state, 567);
3211 *unc = dib8000_read_word(state, 565);
3215 static int dib8000_read_signal_strength(
struct dvb_frontend *fe,
u16 * strength)
3223 state->
fe[index_frontend]->ops.read_signal_strength(state->
fe[index_frontend], &val);
3224 if (val > 65535 - *strength)
3230 val = 65535 - dib8000_read_word(state, 390);
3231 if (val > 65535 - *strength)
3245 val = dib8000_read_word(state, 542);
3247 val = dib8000_read_word(state, 544);
3248 n = (val >> 6) & 0xff;
3250 if ((exp & 0x20) != 0)
3255 val = dib8000_read_word(state, 543);
3257 val = dib8000_read_word(state, 545);
3258 s = (val >> 6) & 0xff;
3260 if ((exp & 0x20) != 0)
3265 u32 t = (s/
n) << 16;
3266 return t + ((s << 16) - n*t) /
n;
3277 snr_master = dib8000_get_snr(fe);
3279 snr_master += dib8000_get_snr(state->
fe[index_frontend]);
3281 if ((snr_master >> 16) != 0) {
3282 snr_master = 10*
intlog10(snr_master>>16);
3283 *snr = snr_master / ((1 << 24) / 10);
3294 u8 index_frontend = 1;
3299 dprintk(
"set slave fe %p to index %i", fe_slave, index_frontend);
3300 state->
fe[index_frontend] = fe_slave;
3304 dprintk(
"too many slave frontend");
3312 u8 index_frontend = 1;
3316 if (index_frontend != 1) {
3317 dprintk(
"remove slave fe %p (index %i)", state->
fe[index_frontend-1], index_frontend-1);
3318 state->
fe[index_frontend] =
NULL;
3322 dprintk(
"no frontend to be removed");
3333 return state->
fe[slave_index];
3339 u8 default_addr,
u8 first_addr,
u8 is_dib8096p)
3347 dprintk(
"%s: not enough memory", __func__);
3352 dprintk(
"%s: not enough memory", __func__);
3354 goto error_memory_read;
3358 dprintk(
"%s: not enough memory", __func__);
3360 goto error_memory_lock;
3364 for (k = no_of_demods - 1; k >= 0; k--) {
3366 new_addr = first_addr + (k << 1);
3368 client.
addr = new_addr;
3370 dib8000_i2c_write16(&client, 1287, 0x0003);
3371 if (dib8000_identify(&client) == 0) {
3374 dib8000_i2c_write16(&client, 1287, 0x0003);
3375 client.
addr = default_addr;
3376 if (dib8000_identify(&client) == 0) {
3377 dprintk(
"#%d: not identified", k);
3384 dib8000_i2c_write16(&client, 1286, (1 << 10) | (4 << 6));
3387 dib8000_i2c_write16(&client, 1285, (new_addr << 2) | 0x2);
3388 client.
addr = new_addr;
3389 dib8000_identify(&client);
3391 dprintk(
"IC %d initialized (to i2c_address 0x%x)", k, new_addr);
3394 for (k = 0; k < no_of_demods; k++) {
3395 new_addr = first_addr | (k << 1);
3396 client.
addr = new_addr;
3399 dib8000_i2c_write16(&client, 1285, new_addr << 2);
3402 dib8000_i2c_write16(&client, 1286, 0);
3449 u16 val = dib8000_read_word(st, 299) & 0xffef;
3450 val |= (onoff & 0x1) << 4;
3452 dprintk(
"pid filter enabled %d", onoff);
3453 return dib8000_write_word(st, 299, val);
3460 dprintk(
"Index %x, PID %d, OnOff %d",
id, pid, onoff);
3461 return dib8000_write_word(st, 305 +
id, onoff ? (1 << 13) | pid : 0);
3468 .name =
"DiBcom 8000 ISDB-T",
3469 .frequency_min = 44250000,
3470 .frequency_max = 867250000,
3471 .frequency_stepsize = 62500,
3479 .release = dib8000_release,
3481 .init = dib8000_wakeup,
3482 .sleep = dib8000_sleep,
3484 .set_frontend = dib8000_set_frontend,
3485 .get_tune_settings = dib8000_fe_get_tune_settings,
3486 .get_frontend = dib8000_get_frontend,
3488 .read_status = dib8000_read_status,
3489 .read_ber = dib8000_read_ber,
3490 .read_signal_strength = dib8000_read_signal_strength,
3491 .read_snr = dib8000_read_snr,
3492 .read_ucblocks = dib8000_read_unc_blocks,
3510 state->
i2c.adap = i2c_adap;
3511 state->
i2c.addr = i2c_addr;
3531 if (dib8000_identify(&state->
i2c) == 0)
3547 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & ~0x60) | (3 << 5));