2 * Frontend driver for mobile DVB-T demodulator DiBcom 3000M-B
3 * DiBcom (http://www.dibcom.fr/)
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
7 * based on GPL code from DibCom, which has
9 * Copyright (C) 2004 Amaury Demol for DiBcom (ademol@dibcom.fr)
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, version 2.
17 * Amaury Demol (ademol@dibcom.fr) from DiBcom for providing specs and driver
18 * sources, on which this driver (and the dvb-dibusb) are based.
20 * see Documentation/dvb/README.dibusb for more information
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/string.h>
29 #include <linux/slab.h>
31 #include "dvb_frontend.h"
34 #include "dib3000mb_priv.h"
36 /* Version information */
37 #define DRIVER_VERSION "0.1"
38 #define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator"
39 #define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
41 #ifdef CONFIG_DVB_DIBCOM_DEBUG
43 module_param(debug, int, 0644);
44 MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
46 #define deb_info(args...) dprintk(0x01,args)
47 #define deb_i2c(args...) dprintk(0x02,args)
48 #define deb_srch(args...) dprintk(0x04,args)
49 #define deb_info(args...) dprintk(0x01,args)
50 #define deb_xfer(args...) dprintk(0x02,args)
51 #define deb_setf(args...) dprintk(0x04,args)
52 #define deb_getf(args...) dprintk(0x08,args)
54 #ifdef CONFIG_DVB_DIBCOM_DEBUG
56 module_param(debug, int, 0644);
57 MODULE_PARM_DESC(debug, "set debugging level (1=info,2=i2c,4=srch (|-able)).");
60 static int dib3000_read_reg(struct dib3000_state *state, u16 reg)
62 u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff };
64 struct i2c_msg msg[] = {
65 { .addr = state->config.demod_address, .flags = 0, .buf = wb, .len = 2 },
66 { .addr = state->config.demod_address, .flags = I2C_M_RD, .buf = rb, .len = 2 },
69 if (i2c_transfer(state->i2c, msg, 2) != 2)
70 deb_i2c("i2c read error\n");
72 deb_i2c("reading i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,
73 (rb[0] << 8) | rb[1],(rb[0] << 8) | rb[1]);
75 return (rb[0] << 8) | rb[1];
78 static int dib3000_write_reg(struct dib3000_state *state, u16 reg, u16 val)
81 (reg >> 8) & 0xff, reg & 0xff,
82 (val >> 8) & 0xff, val & 0xff,
84 struct i2c_msg msg[] = {
85 { .addr = state->config.demod_address, .flags = 0, .buf = b, .len = 4 }
87 deb_i2c("writing i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,val,val);
89 return i2c_transfer(state->i2c,msg, 1) != 1 ? -EREMOTEIO : 0;
92 static int dib3000_search_status(u16 irq,u16 lock)
96 deb_srch("auto search succeeded\n");
97 return 1; // auto search succeeded
99 deb_srch("auto search not successful\n");
100 return 0; // auto search failed
102 } else if (irq & 0x01) {
103 deb_srch("auto search failed\n");
104 return 0; // auto search failed
106 return -1; // try again
109 /* for auto search */
110 static u16 dib3000_seq[2][2][2] = /* fft,gua, inv */
113 { 0, 1 }, /* 0 0 { 0,1 } */
114 { 3, 9 }, /* 0 1 { 0,1 } */
117 { 2, 5 }, /* 1 0 { 0,1 } */
118 { 6, 11 }, /* 1 1 { 0,1 } */
122 static int dib3000mb_get_frontend(struct dvb_frontend* fe,
123 struct dvb_frontend_parameters *fep);
125 static int dib3000mb_set_frontend(struct dvb_frontend* fe,
126 struct dvb_frontend_parameters *fep, int tuner)
128 struct dib3000_state* state = fe->demodulator_priv;
129 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
130 fe_code_rate_t fe_cr = FEC_NONE;
131 int search_state, seq;
133 if (tuner && fe->ops.tuner_ops.set_params) {
134 fe->ops.tuner_ops.set_params(fe, fep);
135 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
137 deb_setf("bandwidth: ");
138 switch (ofdm->bandwidth) {
139 case BANDWIDTH_8_MHZ:
141 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[2]);
142 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_8mhz);
144 case BANDWIDTH_7_MHZ:
146 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[1]);
147 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_7mhz);
149 case BANDWIDTH_6_MHZ:
151 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[0]);
152 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_6mhz);
157 err("unkown bandwidth value.");
161 wr(DIB3000MB_REG_LOCK1_MASK, DIB3000MB_LOCK1_SEARCH_4);
163 deb_setf("transmission mode: ");
164 switch (ofdm->transmission_mode) {
165 case TRANSMISSION_MODE_2K:
167 wr(DIB3000MB_REG_FFT, DIB3000_TRANSMISSION_MODE_2K);
169 case TRANSMISSION_MODE_8K:
171 wr(DIB3000MB_REG_FFT, DIB3000_TRANSMISSION_MODE_8K);
173 case TRANSMISSION_MODE_AUTO:
181 switch (ofdm->guard_interval) {
182 case GUARD_INTERVAL_1_32:
184 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_32);
186 case GUARD_INTERVAL_1_16:
188 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_16);
190 case GUARD_INTERVAL_1_8:
192 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_8);
194 case GUARD_INTERVAL_1_4:
196 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_4);
198 case GUARD_INTERVAL_AUTO:
205 deb_setf("inversion: ");
206 switch (fep->inversion) {
209 wr(DIB3000MB_REG_DDS_INV, DIB3000_DDS_INVERSION_OFF);
216 wr(DIB3000MB_REG_DDS_INV, DIB3000_DDS_INVERSION_ON);
222 deb_setf("constellation: ");
223 switch (ofdm->constellation) {
226 wr(DIB3000MB_REG_QAM, DIB3000_CONSTELLATION_QPSK);
230 wr(DIB3000MB_REG_QAM, DIB3000_CONSTELLATION_16QAM);
234 wr(DIB3000MB_REG_QAM, DIB3000_CONSTELLATION_64QAM);
241 deb_setf("hierarchy: ");
242 switch (ofdm->hierarchy_information) {
247 deb_setf("alpha=1\n");
248 wr(DIB3000MB_REG_VIT_ALPHA, DIB3000_ALPHA_1);
251 deb_setf("alpha=2\n");
252 wr(DIB3000MB_REG_VIT_ALPHA, DIB3000_ALPHA_2);
255 deb_setf("alpha=4\n");
256 wr(DIB3000MB_REG_VIT_ALPHA, DIB3000_ALPHA_4);
259 deb_setf("alpha=auto\n");
265 deb_setf("hierarchy: ");
266 if (ofdm->hierarchy_information == HIERARCHY_NONE) {
268 wr(DIB3000MB_REG_VIT_HRCH, DIB3000_HRCH_OFF);
269 wr(DIB3000MB_REG_VIT_HP, DIB3000_SELECT_HP);
270 fe_cr = ofdm->code_rate_HP;
271 } else if (ofdm->hierarchy_information != HIERARCHY_AUTO) {
273 wr(DIB3000MB_REG_VIT_HRCH, DIB3000_HRCH_ON);
274 wr(DIB3000MB_REG_VIT_HP, DIB3000_SELECT_LP);
275 fe_cr = ofdm->code_rate_LP;
281 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_1_2);
285 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_2_3);
289 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_3_4);
293 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_5_6);
297 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_7_8);
310 [ofdm->transmission_mode == TRANSMISSION_MODE_AUTO]
311 [ofdm->guard_interval == GUARD_INTERVAL_AUTO]
312 [fep->inversion == INVERSION_AUTO];
314 deb_setf("seq? %d\n", seq);
316 wr(DIB3000MB_REG_SEQ, seq);
318 wr(DIB3000MB_REG_ISI, seq ? DIB3000MB_ISI_INHIBIT : DIB3000MB_ISI_ACTIVATE);
320 if (ofdm->transmission_mode == TRANSMISSION_MODE_2K) {
321 if (ofdm->guard_interval == GUARD_INTERVAL_1_8) {
322 wr(DIB3000MB_REG_SYNC_IMPROVEMENT, DIB3000MB_SYNC_IMPROVE_2K_1_8);
324 wr(DIB3000MB_REG_SYNC_IMPROVEMENT, DIB3000MB_SYNC_IMPROVE_DEFAULT);
327 wr(DIB3000MB_REG_UNK_121, DIB3000MB_UNK_121_2K);
329 wr(DIB3000MB_REG_UNK_121, DIB3000MB_UNK_121_DEFAULT);
332 wr(DIB3000MB_REG_MOBILE_ALGO, DIB3000MB_MOBILE_ALGO_OFF);
333 wr(DIB3000MB_REG_MOBILE_MODE_QAM, DIB3000MB_MOBILE_MODE_QAM_OFF);
334 wr(DIB3000MB_REG_MOBILE_MODE, DIB3000MB_MOBILE_MODE_OFF);
336 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_high);
338 wr(DIB3000MB_REG_ISI, DIB3000MB_ISI_ACTIVATE);
340 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_AGC + DIB3000MB_RESTART_CTRL);
341 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_OFF);
343 /* wait for AGC lock */
346 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_low);
348 /* something has to be auto searched */
349 if (ofdm->constellation == QAM_AUTO ||
350 ofdm->hierarchy_information == HIERARCHY_AUTO ||
352 fep->inversion == INVERSION_AUTO) {
355 deb_setf("autosearch enabled.\n");
357 wr(DIB3000MB_REG_ISI, DIB3000MB_ISI_INHIBIT);
359 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_AUTO_SEARCH);
360 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_OFF);
362 while ((search_state =
363 dib3000_search_status(
364 rd(DIB3000MB_REG_AS_IRQ_PENDING),
365 rd(DIB3000MB_REG_LOCK2_VALUE))) < 0 && as_count++ < 100)
368 deb_setf("search_state after autosearch %d after %d checks\n",search_state,as_count);
370 if (search_state == 1) {
371 struct dvb_frontend_parameters feps;
372 if (dib3000mb_get_frontend(fe, &feps) == 0) {
373 deb_setf("reading tuning data from frontend succeeded.\n");
374 return dib3000mb_set_frontend(fe, &feps, 0);
379 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_CTRL);
380 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_OFF);
386 static int dib3000mb_fe_init(struct dvb_frontend* fe, int mobile_mode)
388 struct dib3000_state* state = fe->demodulator_priv;
390 deb_info("dib3000mb is getting up.\n");
391 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_UP);
393 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_AGC);
395 wr(DIB3000MB_REG_RESET_DEVICE, DIB3000MB_RESET_DEVICE);
396 wr(DIB3000MB_REG_RESET_DEVICE, DIB3000MB_RESET_DEVICE_RST);
398 wr(DIB3000MB_REG_CLOCK, DIB3000MB_CLOCK_DEFAULT);
400 wr(DIB3000MB_REG_ELECT_OUT_MODE, DIB3000MB_ELECT_OUT_MODE_ON);
402 wr(DIB3000MB_REG_DDS_FREQ_MSB, DIB3000MB_DDS_FREQ_MSB);
403 wr(DIB3000MB_REG_DDS_FREQ_LSB, DIB3000MB_DDS_FREQ_LSB);
405 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[2]);
407 wr_foreach(dib3000mb_reg_impulse_noise,
408 dib3000mb_impulse_noise_values[DIB3000MB_IMPNOISE_OFF]);
410 wr_foreach(dib3000mb_reg_agc_gain, dib3000mb_default_agc_gain);
412 wr(DIB3000MB_REG_PHASE_NOISE, DIB3000MB_PHASE_NOISE_DEFAULT);
414 wr_foreach(dib3000mb_reg_phase_noise, dib3000mb_default_noise_phase);
416 wr_foreach(dib3000mb_reg_lock_duration, dib3000mb_default_lock_duration);
418 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_low);
420 wr(DIB3000MB_REG_LOCK0_MASK, DIB3000MB_LOCK0_DEFAULT);
421 wr(DIB3000MB_REG_LOCK1_MASK, DIB3000MB_LOCK1_SEARCH_4);
422 wr(DIB3000MB_REG_LOCK2_MASK, DIB3000MB_LOCK2_DEFAULT);
423 wr(DIB3000MB_REG_SEQ, dib3000_seq[1][1][1]);
425 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_8mhz);
427 wr(DIB3000MB_REG_UNK_68, DIB3000MB_UNK_68);
428 wr(DIB3000MB_REG_UNK_69, DIB3000MB_UNK_69);
429 wr(DIB3000MB_REG_UNK_71, DIB3000MB_UNK_71);
430 wr(DIB3000MB_REG_UNK_77, DIB3000MB_UNK_77);
431 wr(DIB3000MB_REG_UNK_78, DIB3000MB_UNK_78);
432 wr(DIB3000MB_REG_ISI, DIB3000MB_ISI_INHIBIT);
433 wr(DIB3000MB_REG_UNK_92, DIB3000MB_UNK_92);
434 wr(DIB3000MB_REG_UNK_96, DIB3000MB_UNK_96);
435 wr(DIB3000MB_REG_UNK_97, DIB3000MB_UNK_97);
436 wr(DIB3000MB_REG_UNK_106, DIB3000MB_UNK_106);
437 wr(DIB3000MB_REG_UNK_107, DIB3000MB_UNK_107);
438 wr(DIB3000MB_REG_UNK_108, DIB3000MB_UNK_108);
439 wr(DIB3000MB_REG_UNK_122, DIB3000MB_UNK_122);
440 wr(DIB3000MB_REG_MOBILE_MODE_QAM, DIB3000MB_MOBILE_MODE_QAM_OFF);
441 wr(DIB3000MB_REG_BERLEN, DIB3000MB_BERLEN_DEFAULT);
443 wr_foreach(dib3000mb_reg_filter_coeffs, dib3000mb_filter_coeffs);
445 wr(DIB3000MB_REG_MOBILE_ALGO, DIB3000MB_MOBILE_ALGO_ON);
446 wr(DIB3000MB_REG_MULTI_DEMOD_MSB, DIB3000MB_MULTI_DEMOD_MSB);
447 wr(DIB3000MB_REG_MULTI_DEMOD_LSB, DIB3000MB_MULTI_DEMOD_LSB);
449 wr(DIB3000MB_REG_OUTPUT_MODE, DIB3000MB_OUTPUT_MODE_SLAVE);
451 wr(DIB3000MB_REG_FIFO_142, DIB3000MB_FIFO_142);
452 wr(DIB3000MB_REG_MPEG2_OUT_MODE, DIB3000MB_MPEG2_OUT_MODE_188);
453 wr(DIB3000MB_REG_PID_PARSE, DIB3000MB_PID_PARSE_ACTIVATE);
454 wr(DIB3000MB_REG_FIFO, DIB3000MB_FIFO_INHIBIT);
455 wr(DIB3000MB_REG_FIFO_146, DIB3000MB_FIFO_146);
456 wr(DIB3000MB_REG_FIFO_147, DIB3000MB_FIFO_147);
458 wr(DIB3000MB_REG_DATA_IN_DIVERSITY, DIB3000MB_DATA_DIVERSITY_IN_OFF);
463 static int dib3000mb_get_frontend(struct dvb_frontend* fe,
464 struct dvb_frontend_parameters *fep)
466 struct dib3000_state* state = fe->demodulator_priv;
467 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
470 int inv_test1,inv_test2;
471 u32 dds_val, threshold = 0x800000;
473 if (!rd(DIB3000MB_REG_TPS_LOCK))
476 dds_val = ((rd(DIB3000MB_REG_DDS_VALUE_MSB) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB);
477 deb_getf("DDS_VAL: %x %x %x",dds_val, rd(DIB3000MB_REG_DDS_VALUE_MSB), rd(DIB3000MB_REG_DDS_VALUE_LSB));
478 if (dds_val < threshold)
480 else if (dds_val == threshold)
485 dds_val = ((rd(DIB3000MB_REG_DDS_FREQ_MSB) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB);
486 deb_getf("DDS_FREQ: %x %x %x",dds_val, rd(DIB3000MB_REG_DDS_FREQ_MSB), rd(DIB3000MB_REG_DDS_FREQ_LSB));
487 if (dds_val < threshold)
489 else if (dds_val == threshold)
495 ((inv_test2 == 2) && (inv_test1==1 || inv_test1==0)) ||
496 ((inv_test2 == 0) && (inv_test1==1 || inv_test1==2)) ?
497 INVERSION_ON : INVERSION_OFF;
499 deb_getf("inversion %d %d, %d\n", inv_test2, inv_test1, fep->inversion);
501 switch ((tps_val = rd(DIB3000MB_REG_TPS_QAM))) {
502 case DIB3000_CONSTELLATION_QPSK:
504 ofdm->constellation = QPSK;
506 case DIB3000_CONSTELLATION_16QAM:
508 ofdm->constellation = QAM_16;
510 case DIB3000_CONSTELLATION_64QAM:
512 ofdm->constellation = QAM_64;
515 err("Unexpected constellation returned by TPS (%d)", tps_val);
518 deb_getf("TPS: %d\n", tps_val);
520 if (rd(DIB3000MB_REG_TPS_HRCH)) {
521 deb_getf("HRCH ON\n");
522 cr = &ofdm->code_rate_LP;
523 ofdm->code_rate_HP = FEC_NONE;
524 switch ((tps_val = rd(DIB3000MB_REG_TPS_VIT_ALPHA))) {
525 case DIB3000_ALPHA_0:
526 deb_getf("HIERARCHY_NONE ");
527 ofdm->hierarchy_information = HIERARCHY_NONE;
529 case DIB3000_ALPHA_1:
530 deb_getf("HIERARCHY_1 ");
531 ofdm->hierarchy_information = HIERARCHY_1;
533 case DIB3000_ALPHA_2:
534 deb_getf("HIERARCHY_2 ");
535 ofdm->hierarchy_information = HIERARCHY_2;
537 case DIB3000_ALPHA_4:
538 deb_getf("HIERARCHY_4 ");
539 ofdm->hierarchy_information = HIERARCHY_4;
542 err("Unexpected ALPHA value returned by TPS (%d)", tps_val);
545 deb_getf("TPS: %d\n", tps_val);
547 tps_val = rd(DIB3000MB_REG_TPS_CODE_RATE_LP);
549 deb_getf("HRCH OFF\n");
550 cr = &ofdm->code_rate_HP;
551 ofdm->code_rate_LP = FEC_NONE;
552 ofdm->hierarchy_information = HIERARCHY_NONE;
554 tps_val = rd(DIB3000MB_REG_TPS_CODE_RATE_HP);
558 case DIB3000_FEC_1_2:
559 deb_getf("FEC_1_2 ");
562 case DIB3000_FEC_2_3:
563 deb_getf("FEC_2_3 ");
566 case DIB3000_FEC_3_4:
567 deb_getf("FEC_3_4 ");
570 case DIB3000_FEC_5_6:
571 deb_getf("FEC_5_6 ");
574 case DIB3000_FEC_7_8:
575 deb_getf("FEC_7_8 ");
579 err("Unexpected FEC returned by TPS (%d)", tps_val);
582 deb_getf("TPS: %d\n",tps_val);
584 switch ((tps_val = rd(DIB3000MB_REG_TPS_GUARD_TIME))) {
585 case DIB3000_GUARD_TIME_1_32:
586 deb_getf("GUARD_INTERVAL_1_32 ");
587 ofdm->guard_interval = GUARD_INTERVAL_1_32;
589 case DIB3000_GUARD_TIME_1_16:
590 deb_getf("GUARD_INTERVAL_1_16 ");
591 ofdm->guard_interval = GUARD_INTERVAL_1_16;
593 case DIB3000_GUARD_TIME_1_8:
594 deb_getf("GUARD_INTERVAL_1_8 ");
595 ofdm->guard_interval = GUARD_INTERVAL_1_8;
597 case DIB3000_GUARD_TIME_1_4:
598 deb_getf("GUARD_INTERVAL_1_4 ");
599 ofdm->guard_interval = GUARD_INTERVAL_1_4;
602 err("Unexpected Guard Time returned by TPS (%d)", tps_val);
605 deb_getf("TPS: %d\n", tps_val);
607 switch ((tps_val = rd(DIB3000MB_REG_TPS_FFT))) {
608 case DIB3000_TRANSMISSION_MODE_2K:
609 deb_getf("TRANSMISSION_MODE_2K ");
610 ofdm->transmission_mode = TRANSMISSION_MODE_2K;
612 case DIB3000_TRANSMISSION_MODE_8K:
613 deb_getf("TRANSMISSION_MODE_8K ");
614 ofdm->transmission_mode = TRANSMISSION_MODE_8K;
617 err("unexpected transmission mode return by TPS (%d)", tps_val);
620 deb_getf("TPS: %d\n", tps_val);
625 static int dib3000mb_read_status(struct dvb_frontend* fe, fe_status_t *stat)
627 struct dib3000_state* state = fe->demodulator_priv;
631 if (rd(DIB3000MB_REG_AGC_LOCK))
632 *stat |= FE_HAS_SIGNAL;
633 if (rd(DIB3000MB_REG_CARRIER_LOCK))
634 *stat |= FE_HAS_CARRIER;
635 if (rd(DIB3000MB_REG_VIT_LCK))
636 *stat |= FE_HAS_VITERBI;
637 if (rd(DIB3000MB_REG_TS_SYNC_LOCK))
638 *stat |= (FE_HAS_SYNC | FE_HAS_LOCK);
640 deb_getf("actual status is %2x\n",*stat);
642 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
643 rd(DIB3000MB_REG_TPS_LOCK),
644 rd(DIB3000MB_REG_TPS_QAM),
645 rd(DIB3000MB_REG_TPS_HRCH),
646 rd(DIB3000MB_REG_TPS_VIT_ALPHA),
647 rd(DIB3000MB_REG_TPS_CODE_RATE_HP),
648 rd(DIB3000MB_REG_TPS_CODE_RATE_LP),
649 rd(DIB3000MB_REG_TPS_GUARD_TIME),
650 rd(DIB3000MB_REG_TPS_FFT),
651 rd(DIB3000MB_REG_TPS_CELL_ID));
653 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
657 static int dib3000mb_read_ber(struct dvb_frontend* fe, u32 *ber)
659 struct dib3000_state* state = fe->demodulator_priv;
661 *ber = ((rd(DIB3000MB_REG_BER_MSB) << 16) | rd(DIB3000MB_REG_BER_LSB));
665 /* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
666 static int dib3000mb_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
668 struct dib3000_state* state = fe->demodulator_priv;
670 *strength = rd(DIB3000MB_REG_SIGNAL_POWER) * 0xffff / 0x170;
674 static int dib3000mb_read_snr(struct dvb_frontend* fe, u16 *snr)
676 struct dib3000_state* state = fe->demodulator_priv;
677 short sigpow = rd(DIB3000MB_REG_SIGNAL_POWER);
678 int icipow = ((rd(DIB3000MB_REG_NOISE_POWER_MSB) & 0xff) << 16) |
679 rd(DIB3000MB_REG_NOISE_POWER_LSB);
680 *snr = (sigpow << 8) / ((icipow > 0) ? icipow : 1);
684 static int dib3000mb_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
686 struct dib3000_state* state = fe->demodulator_priv;
688 *unc = rd(DIB3000MB_REG_PACKET_ERROR_RATE);
692 static int dib3000mb_sleep(struct dvb_frontend* fe)
694 struct dib3000_state* state = fe->demodulator_priv;
695 deb_info("dib3000mb is going to bed.\n");
696 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_DOWN);
700 static int dib3000mb_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
702 tune->min_delay_ms = 800;
706 static int dib3000mb_fe_init_nonmobile(struct dvb_frontend* fe)
708 return dib3000mb_fe_init(fe, 0);
711 static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend* fe, struct dvb_frontend_parameters *fep)
713 return dib3000mb_set_frontend(fe, fep, 1);
716 static void dib3000mb_release(struct dvb_frontend* fe)
718 struct dib3000_state *state = fe->demodulator_priv;
722 /* pid filter and transfer stuff */
723 static int dib3000mb_pid_control(struct dvb_frontend *fe,int index, int pid,int onoff)
725 struct dib3000_state *state = fe->demodulator_priv;
726 pid = (onoff ? pid | DIB3000_ACTIVATE_PID_FILTERING : 0);
727 wr(index+DIB3000MB_REG_FIRST_PID,pid);
731 static int dib3000mb_fifo_control(struct dvb_frontend *fe, int onoff)
733 struct dib3000_state *state = fe->demodulator_priv;
735 deb_xfer("%s fifo\n",onoff ? "enabling" : "disabling");
737 wr(DIB3000MB_REG_FIFO, DIB3000MB_FIFO_ACTIVATE);
739 wr(DIB3000MB_REG_FIFO, DIB3000MB_FIFO_INHIBIT);
744 static int dib3000mb_pid_parse(struct dvb_frontend *fe, int onoff)
746 struct dib3000_state *state = fe->demodulator_priv;
747 deb_xfer("%s pid parsing\n",onoff ? "enabling" : "disabling");
748 wr(DIB3000MB_REG_PID_PARSE,onoff);
752 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr)
754 struct dib3000_state *state = fe->demodulator_priv;
756 wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr));
758 wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_DISABLE(pll_addr));
763 static struct dvb_frontend_ops dib3000mb_ops;
765 struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
766 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
768 struct dib3000_state* state = NULL;
770 /* allocate memory for the internal state */
771 state = kzalloc(sizeof(struct dib3000_state), GFP_KERNEL);
775 /* setup the state */
777 memcpy(&state->config,config,sizeof(struct dib3000_config));
779 /* check for the correct demod */
780 if (rd(DIB3000_REG_MANUFACTOR_ID) != DIB3000_I2C_ID_DIBCOM)
783 if (rd(DIB3000_REG_DEVICE_ID) != DIB3000MB_DEVICE_ID)
786 /* create dvb_frontend */
787 memcpy(&state->frontend.ops, &dib3000mb_ops, sizeof(struct dvb_frontend_ops));
788 state->frontend.demodulator_priv = state;
790 /* set the xfer operations */
791 xfer_ops->pid_parse = dib3000mb_pid_parse;
792 xfer_ops->fifo_ctrl = dib3000mb_fifo_control;
793 xfer_ops->pid_ctrl = dib3000mb_pid_control;
794 xfer_ops->tuner_pass_ctrl = dib3000mb_tuner_pass_ctrl;
796 return &state->frontend;
803 static struct dvb_frontend_ops dib3000mb_ops = {
806 .name = "DiBcom 3000M-B DVB-T",
808 .frequency_min = 44250000,
809 .frequency_max = 867250000,
810 .frequency_stepsize = 62500,
811 .caps = FE_CAN_INVERSION_AUTO |
812 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
813 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
814 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
815 FE_CAN_TRANSMISSION_MODE_AUTO |
816 FE_CAN_GUARD_INTERVAL_AUTO |
818 FE_CAN_HIERARCHY_AUTO,
821 .release = dib3000mb_release,
823 .init = dib3000mb_fe_init_nonmobile,
824 .sleep = dib3000mb_sleep,
826 .set_frontend = dib3000mb_set_frontend_and_tuner,
827 .get_frontend = dib3000mb_get_frontend,
828 .get_tune_settings = dib3000mb_fe_get_tune_settings,
830 .read_status = dib3000mb_read_status,
831 .read_ber = dib3000mb_read_ber,
832 .read_signal_strength = dib3000mb_read_signal_strength,
833 .read_snr = dib3000mb_read_snr,
834 .read_ucblocks = dib3000mb_read_unc_blocks,
837 MODULE_AUTHOR(DRIVER_AUTHOR);
838 MODULE_DESCRIPTION(DRIVER_DESC);
839 MODULE_LICENSE("GPL");
841 EXPORT_SYMBOL(dib3000mb_attach);