11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
24 #define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000M: "); printk(args); printk("\n"); } } while (0)
77 dprintk(
"could not acquire lock");
86 state->
msg[0].flags = 0;
88 state->
msg[0].len = 2;
92 state->
msg[1].len = 2;
95 dprintk(
"i2c read error on %d",reg);
108 dprintk(
"could not acquire lock");
119 state->
msg[0].flags = 0;
121 state->
msg[0].len = 4;
136 if (state->
reg_offs && (
r >= 112 &&
r <= 331))
140 dib7000m_write_word(state,
r, *n++);
150 u16 outreg, fifo_threshold, smo_mode,
154 fifo_threshold = 1792;
155 smo_mode = (dib7000m_read_word(state, 294 + state->
reg_offs) & 0x0010) | (1 << 1);
157 dprintk(
"setting output mode for demod %p to %d", &state->
demod, mode);
164 outreg = (1 << 10) | (1 << 6);
167 outreg = (1 << 10) | (2 << 6) | (0 << 1);
170 if (state->
cfg.hostbus_diversity)
171 outreg = (1 << 10) | (4 << 6);
176 smo_mode |= (3 << 1);
177 fifo_threshold = 512;
178 outreg = (1 << 10) | (5 << 6);
184 dprintk(
"Unhandled output_mode passed to be set for demod %p",&state->
demod);
188 if (state->
cfg.output_mpeg2_in_188_bytes)
189 smo_mode |= (1 << 5) ;
191 ret |= dib7000m_write_word(state, 294 + state->
reg_offs, smo_mode);
192 ret |= dib7000m_write_word(state, 295 + state->
reg_offs, fifo_threshold);
193 ret |= dib7000m_write_word(state, 1795, outreg);
194 ret |= dib7000m_write_word(state, 1805, sram);
197 u16 clk_cfg1 = dib7000m_read_word(state, 909) & 0xfffd;
199 clk_cfg1 |= (1 << 1);
200 dib7000m_write_word(state, 909, clk_cfg1);
208 u16 reg_903 = 0xffff, reg_904 = 0xffff, reg_905 = 0xffff, reg_906 = 0x3fff;
215 reg_903 = 0x0000; reg_904 = 0x0000; reg_905 = 0x0000; reg_906 = 0x0000;
220 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 2));
224 reg_903 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10));
225 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 2));
226 reg_906 &= ~((1 << 0));
230 reg_903 = 0x0000; reg_904 = 0x801f; reg_905 = 0x0000; reg_906 = 0x0000;
234 reg_903 = 0x0000; reg_904 = 0x8000; reg_905 = 0x010b; reg_906 = 0x0000;
241 if (!state->
cfg.mobile_mode)
242 reg_904 |= (1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) | (1 << 1);
251 dib7000m_write_word(state, 903 + offset, reg_903);
252 dib7000m_write_word(state, 904 + offset, reg_904);
253 dib7000m_write_word(state, 905 + offset, reg_905);
254 dib7000m_write_word(state, 906 + offset, reg_906);
260 u16 reg_913 = dib7000m_read_word(state, 913),
261 reg_914 = dib7000m_read_word(state, 914);
265 reg_914 |= (1 << 1) | (1 << 0);
266 ret |= dib7000m_write_word(state, 914, reg_914);
267 reg_914 &= ~(1 << 1);
271 reg_914 |= (1 << 1) | (1 << 0);
277 dib7000m_write_word(state, 913, 0);
278 dib7000m_write_word(state, 914, reg_914 & 0x3);
280 dib7000m_write_word(state, 913, (1 << 15));
281 dib7000m_write_word(state, 914, reg_914 & 0x3);
289 reg_913 |= (1 << 14) | (1 << 13) | (1 << 12);
290 reg_914 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
294 reg_913 &= ~(1 << 15);
298 reg_913 |= (1 << 15);
306 ret |= dib7000m_write_word(state, 913, reg_913);
307 ret |= dib7000m_write_word(state, 914, reg_914);
322 if (state->
timf == 0) {
323 dprintk(
"using default timf");
326 dprintk(
"using updated timf");
330 timf = timf * (bw / 50) / 160;
332 dib7000m_write_word(state, 23, (
u16) ((timf >> 16) & 0xffff));
333 dib7000m_write_word(state, 24, (
u16) ((timf ) & 0xffff));
343 dprintk(
"diversity combination deactivated - forced by COFDM parameters");
349 dib7000m_write_word(state, 263 + state->
reg_offs, 6);
350 dib7000m_write_word(state, 264 + state->
reg_offs, 6);
351 dib7000m_write_word(state, 266 + state->
reg_offs, (state->
div_sync_wait << 4) | (1 << 2) | (2 << 0));
353 dib7000m_write_word(state, 263 + state->
reg_offs, 1);
354 dib7000m_write_word(state, 264 + state->
reg_offs, 0);
355 dib7000m_write_word(state, 266 + state->
reg_offs, 0);
366 dib7000m_write_word(state, 929, (0 << 1) | (0 << 0));
367 dib7000m_write_word(state, 930, 776);
370 dib7000m_write_word(state, 929, (1 << 0));
371 dib7000m_write_word(state, 929, (0 << 0));
380 dib7000m_write_word(state, 18, (
u16) (((bw->
internal*1000) >> 16) & 0xffff));
381 dib7000m_write_word(state, 19, (
u16) ( (bw->
internal*1000) & 0xffff));
382 dib7000m_write_word(state, 21, (
u16) ( (bw->
ifreq >> 16) & 0xffff));
383 dib7000m_write_word(state, 22, (
u16) ( bw->
ifreq & 0xffff));
385 dib7000m_write_word(state, 928, bw->
sad_cfg);
401 if (!state->
cfg.quartz_direct) {
405 if(state->
cfg.input_clk_is_div_2)
406 reg_907 |= (16 << 9);
414 dib7000m_write_word(state, 910, reg_910);
415 dib7000m_write_word(state, 907, reg_907);
416 dib7000m_write_word(state, 908, 0x0006);
418 dib7000m_reset_pll_common(state, bw);
431 clk_cfg1 = (0 << 14) | (3 << 12) |(0 << 11) |
434 dib7000m_write_word(state, 908, clk_cfg1);
435 clk_cfg1 = (clk_cfg1 & 0xfff7) | (bw->
pll_bypass << 3);
436 dib7000m_write_word(state, 908, clk_cfg1);
439 dib7000m_write_word(state, 910, (1 << 12) | (2 << 10) | (bw->
modulo << 8) | (bw->
ADClkSrc << 7));
441 dib7000m_reset_pll_common(state, bw);
447 dib7000m_write_word(st, 773, st->
cfg.gpio_dir);
448 dib7000m_write_word(st, 774, st->
cfg.gpio_val);
452 dib7000m_write_word(st, 775, st->
cfg.gpio_pwm_pos);
454 dib7000m_write_word(st, 780, st->
cfg.pwm_freq_div);
458 static u16 dib7000m_defaults_common[] =
532 static u16 dib7000m_defaults[] =
537 (1 << 13) - 825 - 117,
538 (1 << 13) - 837 - 117,
539 (1 << 13) - 811 - 117,
540 (1 << 13) - 766 - 117,
541 (1 << 13) - 737 - 117,
542 (1 << 13) - 693 - 117,
543 (1 << 13) - 648 - 117,
544 (1 << 13) - 619 - 117,
545 (1 << 13) - 575 - 117,
546 (1 << 13) - 531 - 117,
547 (1 << 13) - 501 - 117,
567 dib7000m_write_word(state, 898, 0xffff);
568 dib7000m_write_word(state, 899, 0xffff);
569 dib7000m_write_word(state, 900, 0xff0f);
570 dib7000m_write_word(state, 901, 0xfffc);
572 dib7000m_write_word(state, 898, 0);
573 dib7000m_write_word(state, 899, 0);
574 dib7000m_write_word(state, 900, 0);
575 dib7000m_write_word(state, 901, 0);
578 dib7000m_reset_pll(state);
580 dib7000mc_reset_pll(state);
582 if (dib7000m_reset_gpio(state) != 0)
583 dprintk(
"GPIO reset was not successful.");
586 dprintk(
"OUTPUT_MODE could not be reset.");
589 dib7000m_write_word(state, 1794, dib7000m_read_word(state, 1794) & ~(1 << 1) );
591 dib7000m_set_bandwidth(state, 8000);
594 dib7000m_sad_calib(state);
597 if (state->
cfg.dvbt_mode)
598 dib7000m_write_word(state, 1796, 0x0);
600 if (state->
cfg.mobile_mode)
601 dib7000m_write_word(state, 261 + state->
reg_offs, 2);
603 dib7000m_write_word(state, 224 + state->
reg_offs, 1);
606 if(state->
cfg.tuner_is_baseband)
607 dib7000m_write_word(state, 36, 0x0755);
609 dib7000m_write_word(state, 36, 0x1f55);
613 dib7000m_write_word(state, 909, (3 << 10) | (1 << 6));
615 dib7000m_write_word(state, 909, (3 << 4) | 1);
617 dib7000m_write_tab(state, dib7000m_defaults_common);
618 dib7000m_write_tab(state, dib7000m_defaults);
630 dib7000m_write_word(state, 898, 0x0c00);
631 dib7000m_write_word(state, 898, 0x0000);
636 u16 agc,split_offset;
642 agc = dib7000m_read_word(state, 390);
646 else if (agc < state->current_agc->split.max_thres)
653 dprintk(
"AGC split_offset: %d",split_offset);
656 return dib7000m_write_word(state, 103, (dib7000m_read_word(state, 103) & 0xff00) | split_offset);
663 if (state->
cfg.update_lna) {
665 dyn_gain = dib7000m_read_word(state, 390);
667 if (state->
cfg.update_lna(&state->
demod,dyn_gain)) {
668 dib7000m_restart_agc(state);
683 for (i = 0; i < state->
cfg.agc_config_count; i++)
684 if (state->
cfg.agc[i].band_caps & band) {
685 agc = &state->
cfg.agc[
i];
690 dprintk(
"no valid AGC configuration found for band 0x%02x",band);
697 dib7000m_write_word(state, 72 , agc->
setup);
698 dib7000m_write_word(state, 73 , agc->
inv_gain);
706 dprintk(
"WBD: ref: %d, sel: %d, active: %d, alpha: %d",
711 dib7000m_write_word(state, 102, state->
wbd_ref);
713 dib7000m_write_word(state, 102, agc->
wbd_ref);
716 dib7000m_write_word(state, 104, agc->
agc1_max);
717 dib7000m_write_word(state, 105, agc->
agc1_min);
718 dib7000m_write_word(state, 106, agc->
agc2_max);
719 dib7000m_write_word(state, 107, agc->
agc2_min);
726 dib7000m_write_word(state, 71, agc->
agc1_pt3);
729 dib7000m_write_word(state, 929, (dib7000m_read_word(state, 929) & 0xffe3) | (agc->
wbd_inv << 4) | (agc->
wbd_sel << 2));
732 u16 b[9] = { 676, 696, 717, 737, 758, 778, 799, 819, 840 };
733 for (i = 0; i < 9; i++)
734 dib7000m_write_word(state, 88 + i, b[i]);
741 u32 timf = (dib7000m_read_word(state, 436) << 16) | dib7000m_read_word(state, 437);
743 dib7000m_write_word(state, 23, (
u16) (timf >> 16));
744 dib7000m_write_word(state, 24, (
u16) (timf & 0xffff));
748 static int dib7000m_agc_startup(
struct dvb_frontend *demod)
752 u16 cfg_72 = dib7000m_read_word(state, 72);
772 if (state->
cfg.agc_control)
773 state->
cfg.agc_control(&state->
demod, 1);
775 dib7000m_write_word(state, 75, 32768);
778 dib7000m_write_word(state, 103, 1 << 8);
788 dib7000m_restart_agc(state);
792 dib7000m_write_word(state, 72, cfg_72 | (1 << 4));
793 dib7000m_write_word(state, 103, 2 << 9);
799 agc_split = (
u8)dib7000m_read_word(state, 392);
800 dib7000m_write_word(state, 75, dib7000m_read_word(state, 390));
802 dib7000m_write_word(state, 72, cfg_72 & ~(1 << 4));
803 dib7000m_write_word(state, 103, (state->
current_agc->wbd_alpha << 9) | agc_split);
805 dib7000m_restart_agc(state);
807 dprintk(
"SPLIT %p: %hd", demod, agc_split);
817 if (dib7000m_update_lna(state))
825 dib7000m_agc_soft_split(state);
827 if (state->
cfg.agc_control)
828 state->
cfg.agc_control(&state->
demod, 0);
862 case QPSK: value |= (0 << 3);
break;
863 case QAM_16: value |= (1 << 3);
break;
865 case QAM_64: value |= (2 << 3);
break;
873 dib7000m_write_word(state, 0, value);
874 dib7000m_write_word(state, 5, (seq << 4));
885 case FEC_2_3: value |= (2 << 1);
break;
886 case FEC_3_4: value |= (3 << 1);
break;
887 case FEC_5_6: value |= (5 << 1);
break;
888 case FEC_7_8: value |= (7 << 1);
break;
890 case FEC_1_2: value |= (1 << 1);
break;
892 dib7000m_write_word(state, 267 + state->
reg_offs, value);
897 dib7000m_write_word(state, 26, (6 << 12) | (6 << 8) | 0x80);
900 dib7000m_write_word(state, 29, (0 << 14) | (4 << 10) | (1 << 9) | (3 << 5) | (1 << 4) | (0x3));
903 dib7000m_write_word(state, 32, (0 << 4) | 0x3);
906 dib7000m_write_word(state, 33, (0 << 4) | 0x5);
913 default: value = 64;
break;
926 if (1 == 1 || state->
revision > 0x4000)
953 for (value = 0; value < 4; value++)
954 dib7000m_write_word(state, 214 + value + state->
reg_offs, est[value]);
960 static int dib7000m_autosearch_start(
struct dvb_frontend *demod)
977 dib7000m_set_channel(state, &schan, 7);
987 ret |= dib7000m_write_word(state, 6, (
u16) ((value >> 16) & 0xffff));
988 ret |= dib7000m_write_word(state, 7, (
u16) (value & 0xffff));
990 ret |= dib7000m_write_word(state, 8, (
u16) ((value >> 16) & 0xffff));
991 ret |= dib7000m_write_word(state, 9, (
u16) (value & 0xffff));
993 ret |= dib7000m_write_word(state, 10, (
u16) ((value >> 16) & 0xffff));
994 ret |= dib7000m_write_word(state, 11, (
u16) (value & 0xffff));
997 value = dib7000m_read_word(state, 0);
998 ret |= dib7000m_write_word(state, 0, (
u16) (value | (1 << 9)));
1002 dib7000m_write_word(state, 1793, 0);
1004 dib7000m_read_word(state, 537);
1006 ret |= dib7000m_write_word(state, 0, (
u16) value);
1013 u16 irq_pending = dib7000m_read_word(state, reg);
1015 if (irq_pending & 0x1) {
1016 dprintk(
"autosearch failed");
1020 if (irq_pending & 0x2) {
1021 dprintk(
"autosearch succeeded");
1027 static int dib7000m_autosearch_is_irq(
struct dvb_frontend *demod)
1031 return dib7000m_autosearch_irq(state, 1793);
1033 return dib7000m_autosearch_irq(state, 537);
1045 dib7000m_set_channel(state, ch, 0);
1050 ret |= dib7000m_write_word(state, 898, 0x4000);
1051 ret |= dib7000m_write_word(state, 898, 0x0000);
1056 ret |= dib7000m_write_word(state, 29, (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3));
1059 if (state->
timf == 0)
1064 value = (6 << 8) | 0x80;
1071 ret |= dib7000m_write_word(state, 26, value);
1081 ret |= dib7000m_write_word(state, 32, value);
1091 ret |= dib7000m_write_word(state, 33, value);
1094 if ((dib7000m_read_word(state, 535) >> 6) & 0x1)
1095 dib7000m_update_timf(state);
1108 dprintk(
"could not start Slow ADC");
1126 if ((value = dib7000m_read_word(state, 896)) != 0x01b3) {
1127 dprintk(
"wrong Vendor ID (0x%x)",value);
1131 state->
revision = dib7000m_read_word(state, 897);
1136 dprintk(
"wrong Device ID (0x%x)",value);
1141 if (state->
revision == 0x4000 && dib7000m_read_word(state, 769) == 0x4000) {
1142 dprintk(
"this driver does not work with DiB7000PC");
1147 case 0x4000:
dprintk(
"found DiB7000MA/PA/MB/PB");
break;
1157 static int dib7000m_get_frontend(
struct dvb_frontend* fe)
1161 u16 tps = dib7000m_read_word(state,480);
1167 switch ((tps >> 8) & 0x3) {
1173 switch (tps & 0x3) {
1180 switch ((tps >> 14) & 0x3) {
1191 switch ((tps >> 5) & 0x7) {
1201 switch ((tps >> 2) & 0x7) {
1215 static int dib7000m_set_frontend(
struct dvb_frontend *fe)
1225 if (fe->
ops.tuner_ops.set_params)
1226 fe->
ops.tuner_ops.set_params(fe);
1231 time = dib7000m_agc_startup(fe);
1234 }
while (time != -1);
1242 dib7000m_autosearch_start(fe);
1245 found = dib7000m_autosearch_is_irq(fe);
1246 }
while (found == 0 && i--);
1248 dprintk(
"autosearch returns: %d",found);
1249 if (found == 0 || found == 1)
1252 dib7000m_get_frontend(fe);
1255 ret = dib7000m_tune(fe);
1265 u16 lock = dib7000m_read_word(state, 535);
1286 *ber = (dib7000m_read_word(state, 526) << 16) | dib7000m_read_word(state, 527);
1290 static int dib7000m_read_unc_blocks(
struct dvb_frontend *fe,
u32 *unc)
1293 *unc = dib7000m_read_word(state, 534);
1297 static int dib7000m_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
1300 u16 val = dib7000m_read_word(state, 390);
1301 *strength = 65535 -
val;
1317 static void dib7000m_release(
struct dvb_frontend *demod)
1334 u16 val = dib7000m_read_word(state, 294 + state->
reg_offs) & 0xffef;
1335 val |= (onoff & 0x1) << 4;
1336 dprintk(
"PID filter enabled %d", onoff);
1337 return dib7000m_write_word(state, 294 + state->
reg_offs, val);
1344 dprintk(
"PID filter: index %x, PID %d, OnOff %d",
id, pid, onoff);
1345 return dib7000m_write_word(state, 300 + state->
reg_offs +
id,
1346 onoff ? (1 << 13) | pid : 0);
1352 int dib7000m_i2c_enumeration(
struct i2c_adapter *i2c,
int no_of_demods,
1359 for (k = no_of_demods-1; k >= 0; k--) {
1363 new_addr = (0x40 +
k) << 1;
1365 if (dib7000m_identify(&st) != 0) {
1367 if (dib7000m_identify(&st) != 0) {
1368 dprintk(
"DiB7000M #%d: not identified", k);
1376 dib7000m_write_word(&st, 1796, 0x0);
1379 dib7000m_write_word(&st, 1794, (new_addr << 2) | 0x2);
1381 dprintk(
"IC %d initialized (to i2c_address 0x%x)", k, new_addr);
1384 for (k = 0; k < no_of_demods; k++) {
1389 dib7000m_write_word(&st,1794, st.
i2c_addr << 2);
1420 if (dib7000m_identify(st) != 0)
1428 dib7000m_demod_reset(st);
1441 .name =
"DiBcom 7000MA/MB/PA/PB/MC",
1442 .frequency_min = 44250000,
1443 .frequency_max = 867250000,
1444 .frequency_stepsize = 62500,
1455 .release = dib7000m_release,
1457 .init = dib7000m_wakeup,
1458 .sleep = dib7000m_sleep,
1460 .set_frontend = dib7000m_set_frontend,
1461 .get_tune_settings = dib7000m_fe_get_tune_settings,
1462 .get_frontend = dib7000m_get_frontend,
1464 .read_status = dib7000m_read_status,
1465 .read_ber = dib7000m_read_ber,
1466 .read_signal_strength = dib7000m_read_signal_strength,
1467 .read_snr = dib7000m_read_snr,
1468 .read_ucblocks = dib7000m_read_unc_blocks,