14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/i2c.h>
26 static int buggy_sfn_workaround;
28 MODULE_PARM_DESC(buggy_sfn_workaround,
"Enable work-around for buggy SFNs (default: 0)");
30 #define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB3000MC/P:"); printk(args); printk("\n"); } } while (0)
52 u8 wb[2] = { (reg >> 8) | 0x80, reg & 0xff };
60 dprintk(
"i2c read error on %d\n",reg);
62 return (rb[0] << 8) | rb[1];
68 (reg >> 8) & 0xff, reg & 0xff,
69 (val >> 8) & 0xff, val & 0xff,
72 .addr = state->
i2c_addr >> 1, .flags = 0, .buf =
b, .len = 4
80 if ((value = dib3000mc_read_word(state, 1025)) != 0x01b3) {
81 dprintk(
"-E- DiB3000MC/P: wrong Vendor ID (read=0x%x)\n",value);
85 value = dib3000mc_read_word(state, 1026);
86 if (value != 0x3001 && value != 0x3002) {
87 dprintk(
"-E- DiB3000MC/P: wrong Device ID (%x)\n",value);
101 if (state->
timf == 0) {
111 s16 tim_offs = dib3000mc_read_word(state, 416);
113 if (tim_offs & 0x2000)
120 state->
timf = timf / (bw / 1000);
125 dib3000mc_write_word(state, 23, (
u16) (timf >> 16));
126 dib3000mc_write_word(state, 24, (
u16) (timf ) & 0xffff);
133 u16 reg_51, reg_52 = state->
cfg->agc->setup & 0xfefb;
134 if (state->
cfg->pwm3_inversion) {
135 reg_51 = (2 << 14) | (0 << 10) | (7 << 6) | (2 << 2) | (2 << 0);
138 reg_51 = (2 << 14) | (4 << 10) | (7 << 6) | (2 << 2) | (2 << 0);
141 dib3000mc_write_word(state, 51, reg_51);
142 dib3000mc_write_word(state, 52, reg_52);
144 if (state->
cfg->use_pwm3)
145 dib3000mc_write_word(state, 245, (1 << 3) | (1 << 0));
147 dib3000mc_write_word(state, 245, 0);
149 dib3000mc_write_word(state, 1040, 0x3);
156 u16 fifo_threshold = 1792;
160 u16 smo_reg = dib3000mc_read_word(state, 206) & 0x0010;
162 dprintk(
"-I- Setting output mode for demod %p to %d\n",
163 &state->
demod, mode);
189 fifo_threshold = 512;
197 dprintk(
"Unhandled output_mode passed to be set for demod %p\n",&state->
demod);
202 if ((state->
cfg->output_mpeg2_in_188_bytes))
205 outreg = dib3000mc_read_word(state, 244) & 0x07FF;
206 outreg |= (outmode << 11);
207 ret |= dib3000mc_write_word(state, 244, outreg);
208 ret |= dib3000mc_write_word(state, 206, smo_reg);
209 ret |= dib3000mc_write_word(state, 207, fifo_threshold);
210 ret |= dib3000mc_write_word(state, 1040, elecout);
216 u16 bw_cfg[6] = { 0 };
217 u16 imp_bw_cfg[3] = { 0 };
223 bw_cfg[0] = 0x0019; bw_cfg[1] = 0x5c30; bw_cfg[2] = 0x0054; bw_cfg[3] = 0x88a0; bw_cfg[4] = 0x01a6; bw_cfg[5] = 0xab20;
224 imp_bw_cfg[0] = 0x04db; imp_bw_cfg[1] = 0x00db; imp_bw_cfg[2] = 0x00b7;
228 bw_cfg[0] = 0x001c; bw_cfg[1] = 0xfba5; bw_cfg[2] = 0x0060; bw_cfg[3] = 0x9c25; bw_cfg[4] = 0x01e3; bw_cfg[5] = 0x0cb7;
229 imp_bw_cfg[0] = 0x04c0; imp_bw_cfg[1] = 0x00c0; imp_bw_cfg[2] = 0x00a0;
233 bw_cfg[0] = 0x0021; bw_cfg[1] = 0xd040; bw_cfg[2] = 0x0070; bw_cfg[3] = 0xb62b; bw_cfg[4] = 0x0233; bw_cfg[5] = 0x8ed5;
234 imp_bw_cfg[0] = 0x04a5; imp_bw_cfg[1] = 0x00a5; imp_bw_cfg[2] = 0x0089;
238 bw_cfg[0] = 0x0028; bw_cfg[1] = 0x9380; bw_cfg[2] = 0x0087; bw_cfg[3] = 0x4100; bw_cfg[4] = 0x02a4; bw_cfg[5] = 0x4500;
239 imp_bw_cfg[0] = 0x0489; imp_bw_cfg[1] = 0x0089; imp_bw_cfg[2] = 0x0072;
245 for (reg = 6; reg < 12; reg++)
246 dib3000mc_write_word(state, reg, bw_cfg[reg - 6]);
247 dib3000mc_write_word(state, 12, 0x0000);
248 dib3000mc_write_word(state, 13, 0x03e8);
249 dib3000mc_write_word(state, 14, 0x0000);
250 dib3000mc_write_word(state, 15, 0x03f2);
251 dib3000mc_write_word(state, 16, 0x0001);
252 dib3000mc_write_word(state, 17, 0xb0d0);
254 dib3000mc_write_word(state, 18, 0x0393);
255 dib3000mc_write_word(state, 19, 0x8700);
257 for (reg = 55; reg < 58; reg++)
258 dib3000mc_write_word(state, reg, imp_bw_cfg[reg - 55]);
266 static u16 impulse_noise_val[29] =
269 0x38, 0x6d9, 0x3f28, 0x7a7, 0x3a74, 0x196, 0x32a, 0x48c, 0x3ffe, 0x7f3,
270 0x2d94, 0x76, 0x53d, 0x3ff8, 0x7e3, 0x3320, 0x76, 0x5b3, 0x3feb, 0x7d2,
271 0x365e, 0x76, 0x48c, 0x3ffe, 0x5b3, 0x3feb, 0x76, 0x0000, 0xd
277 for (i = 58; i < 87; i++)
278 dib3000mc_write_word(state, i, impulse_noise_val[i-58]);
281 dib3000mc_write_word(state, 58, 0x3b);
282 dib3000mc_write_word(state, 84, 0x00);
283 dib3000mc_write_word(state, 85, 0x8200);
286 dib3000mc_write_word(state, 34, 0x1294);
287 dib3000mc_write_word(state, 35, 0x1ff8);
289 dib3000mc_write_word(state, 55, dib3000mc_read_word(state, 55) | (1 << 10));
298 dib3000mc_write_word(state, 1027, 0x8000);
299 dib3000mc_write_word(state, 1027, 0x0000);
302 dib3000mc_write_word(state, 140, 0x0000);
303 dib3000mc_write_word(state, 1031, 0);
305 if (state->
cfg->mobile_mode) {
306 dib3000mc_write_word(state, 139, 0x0000);
307 dib3000mc_write_word(state, 141, 0x0000);
308 dib3000mc_write_word(state, 175, 0x0002);
309 dib3000mc_write_word(state, 1032, 0x0000);
311 dib3000mc_write_word(state, 139, 0x0001);
312 dib3000mc_write_word(state, 141, 0x0000);
313 dib3000mc_write_word(state, 175, 0x0000);
314 dib3000mc_write_word(state, 1032, 0x012C);
316 dib3000mc_write_word(state, 1033, 0x0000);
319 dib3000mc_write_word(state, 1037, 0x3130);
324 dib3000mc_write_word(state, 33, (5 << 0));
325 dib3000mc_write_word(state, 88, (1 << 10) | (0x10 << 0));
329 dib3000mc_write_word(state, 99, (1 << 9) | (0x20 << 0));
331 if (state->
cfg->phase_noise_mode == 0)
332 dib3000mc_write_word(state, 111, 0x00);
334 dib3000mc_write_word(state, 111, 0x02);
337 dib3000mc_write_word(state, 50, 0x8000);
340 dib3000mc_setup_pwm_state(state);
343 dib3000mc_write_word(state, 53, 0x87);
345 dib3000mc_write_word(state, 54, 0x87);
348 dib3000mc_write_word(state, 36, state->
cfg->max_time);
349 dib3000mc_write_word(state, 37, (state->
cfg->agc_command1 << 13) | (state->
cfg->agc_command2 << 12) | (0x1d << 0));
350 dib3000mc_write_word(state, 38, state->
cfg->pwm3_value);
351 dib3000mc_write_word(state, 39, state->
cfg->ln_adc_level);
354 dib3000mc_write_word(state, 40, 0x0179);
355 dib3000mc_write_word(state, 41, 0x03f0);
357 dib3000mc_write_word(state, 42, agc->
agc1_max);
358 dib3000mc_write_word(state, 43, agc->
agc1_min);
359 dib3000mc_write_word(state, 44, agc->
agc2_max);
360 dib3000mc_write_word(state, 45, agc->
agc2_min);
368 dib3000mc_write_word(state, 110, 3277);
370 dib3000mc_write_word(state, 26, 0x6680);
372 dib3000mc_write_word(state, 1, 4);
374 dib3000mc_write_word(state, 2, 4);
376 dib3000mc_write_word(state, 3, 0x1000);
378 dib3000mc_write_word(state, 5, 1);
380 dib3000mc_set_bandwidth(state, 8000);
383 dib3000mc_write_word(state, 4, 0x814);
385 dib3000mc_write_word(state, 21, (1 << 9) | 0x164);
386 dib3000mc_write_word(state, 22, 0x463d);
390 dib3000mc_write_word(state, 120, 0x200f);
392 dib3000mc_write_word(state, 134, 0);
395 dib3000mc_write_word(state, 195, 0x10);
398 dib3000mc_write_word(state, 180, 0x2FF0);
407 dib3000mc_write_word(state, 769, (1 << 7) );
416 dib3000mc_write_word(state, 1031, 0xFFFF);
417 dib3000mc_write_word(state, 1032, 0xFFFF);
418 dib3000mc_write_word(state, 1033, 0xFFF0);
428 cfg[0] = 0x099a; cfg[1] = 0x7fae; cfg[2] = 0x0333; cfg[3] = 0x7ff0;
431 cfg[0] = 0x023d; cfg[1] = 0x7fdf; cfg[2] = 0x00a4; cfg[3] = 0x7ff0;
434 cfg[0] = 0x0148; cfg[1] = 0x7ff0; cfg[2] = 0x00a4; cfg[3] = 0x7ff8;
437 for (reg = 129; reg < 133; reg++)
438 dib3000mc_write_word(state, reg, cfg[reg - 129]);
447 dib3000mc_set_bandwidth(state, bw);
453 dib3000mc_write_word(state, 100, (16 << 6) + 9);
455 dib3000mc_write_word(state, 1027, 0x0800);
456 dib3000mc_write_word(state, 1027, 0x0000);
459 dib3000mc_write_word(state, 26, 0x6680);
460 dib3000mc_write_word(state, 29, 0x1273);
461 dib3000mc_write_word(state, 33, 5);
462 dib3000mc_set_adp_cfg(state,
QAM_16);
463 dib3000mc_write_word(state, 133, 15564);
465 dib3000mc_write_word(state, 12 , 0x0);
466 dib3000mc_write_word(state, 13 , 0x3e8);
467 dib3000mc_write_word(state, 14 , 0x0);
468 dib3000mc_write_word(state, 15 , 0x3f2);
470 dib3000mc_write_word(state, 93,0);
471 dib3000mc_write_word(state, 94,0);
472 dib3000mc_write_word(state, 95,0);
473 dib3000mc_write_word(state, 96,0);
474 dib3000mc_write_word(state, 97,0);
475 dib3000mc_write_word(state, 98,0);
493 case QPSK: value |= (0 << 3);
break;
494 case QAM_16: value |= (1 << 3);
break;
496 case QAM_64: value |= (2 << 3);
break;
504 dib3000mc_write_word(state, 0, value);
505 dib3000mc_write_word(state, 5, (1 << 8) | ((seq & 0xf) << 4));
513 case FEC_2_3: value |= (2 << 1);
break;
514 case FEC_3_4: value |= (3 << 1);
break;
515 case FEC_5_6: value |= (5 << 1);
break;
516 case FEC_7_8: value |= (7 << 1);
break;
518 case FEC_1_2: value |= (1 << 1);
break;
520 dib3000mc_write_word(state, 181, value);
526 default: value = 64;
break;
536 value |= dib3000mc_read_word(state, 180) & 0x000f;
537 dib3000mc_write_word(state, 180, value);
540 value = dib3000mc_read_word(state, 0);
541 dib3000mc_write_word(state, 0, value | (1 << 9));
542 dib3000mc_write_word(state, 0, value);
549 static int dib3000mc_autosearch_start(
struct dvb_frontend *demod)
564 schan.modulation =
QAM_64;
569 dib3000mc_set_channel_cfg(state, &schan, 11);
571 reg = dib3000mc_read_word(state, 0);
572 dib3000mc_write_word(state, 0, reg | (1 << 8));
573 dib3000mc_read_word(state, 511);
574 dib3000mc_write_word(state, 0, reg);
579 static int dib3000mc_autosearch_is_irq(
struct dvb_frontend *demod)
582 u16 irq_pending = dib3000mc_read_word(state, 511);
584 if (irq_pending & 0x1)
587 if (irq_pending & 0x2)
599 dib3000mc_set_channel_cfg(state, ch, 0);
603 dprintk(
"SFN workaround is active\n");
604 dib3000mc_write_word(state, 29, 0x1273);
605 dib3000mc_write_word(state, 108, 0x4000);
607 dib3000mc_write_word(state, 29, 0x1073);
608 dib3000mc_write_word(state, 108, 0x0000);
613 dib3000mc_write_word(state, 26, 38528);
614 dib3000mc_write_word(state, 33, 8);
616 dib3000mc_write_word(state, 26, 30336);
617 dib3000mc_write_word(state, 33, 6);
620 if (dib3000mc_read_word(state, 509) & 0x80)
635 static int dib3000mc_get_frontend(
struct dvb_frontend* fe)
639 u16 tps = dib3000mc_read_word(state,458);
645 switch ((tps >> 8) & 0x1) {
657 switch ((tps >> 13) & 0x3) {
668 switch ((tps >> 5) & 0x7) {
678 switch ((tps >> 2) & 0x7) {
690 static int dib3000mc_set_frontend(
struct dvb_frontend *fe)
704 if (fe->
ops.tuner_ops.set_params) {
705 fe->
ops.tuner_ops.set_params(fe);
715 dib3000mc_autosearch_start(fe);
718 found = dib3000mc_autosearch_is_irq(fe);
719 }
while (found == 0 && i--);
721 dprintk(
"autosearch returns: %d\n",found);
722 if (found == 0 || found == 1)
725 dib3000mc_get_frontend(fe);
728 ret = dib3000mc_tune(fe);
738 u16 lock = dib3000mc_read_word(state, 509);
759 *ber = (dib3000mc_read_word(state, 500) << 16) | dib3000mc_read_word(state, 501);
763 static int dib3000mc_read_unc_blocks(
struct dvb_frontend *fe,
u32 *unc)
766 *unc = dib3000mc_read_word(state, 508);
770 static int dib3000mc_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
773 u16 val = dib3000mc_read_word(state, 392);
774 *strength = 65535 -
val;
800 dib3000mc_write_word(state, 212 + index, onoff ? (1 << 13) | pid : 0);
808 u16 tmp = dib3000mc_read_word(state, 206) & ~(1 << 4);
810 return dib3000mc_write_word(state, 206, tmp);
827 static u8 DIB3000MC_I2C_ADDRESS[] = {20,22,24,26};
835 for (k = no_of_demods-1; k >= 0; k--) {
836 dmcst->
cfg = &cfg[
k];
839 new_addr = DIB3000MC_I2C_ADDRESS[
k];
841 if (dib3000mc_identify(dmcst) != 0) {
843 if (dib3000mc_identify(dmcst) != 0) {
844 dprintk(
"-E- DiB3000P/MC #%d: not identified\n", k);
853 dib3000mc_write_word(dmcst, 1024, (new_addr << 3) | 0x1);
857 for (k = 0; k < no_of_demods; k++) {
858 dmcst->
cfg = &cfg[
k];
859 dmcst->
i2c_addr = DIB3000MC_I2C_ADDRESS[
k];
861 dib3000mc_write_word(dmcst, 1024, dmcst->
i2c_addr << 3);
890 if (dib3000mc_identify(st) != 0)
895 dib3000mc_write_word(st, 1037, 0x3130);
908 .name =
"DiBcom 3000MC/P",
909 .frequency_min = 44250000,
910 .frequency_max = 867250000,
911 .frequency_stepsize = 62500,
922 .release = dib3000mc_release,
924 .init = dib3000mc_init,
925 .sleep = dib3000mc_sleep,
927 .set_frontend = dib3000mc_set_frontend,
928 .get_tune_settings = dib3000mc_fe_get_tune_settings,
929 .get_frontend = dib3000mc_get_frontend,
931 .read_status = dib3000mc_read_status,
932 .read_ber = dib3000mc_read_ber,
933 .read_signal_strength = dib3000mc_read_signal_strength,
934 .read_snr = dib3000mc_read_snr,
935 .read_ucblocks = dib3000mc_read_unc_blocks,