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/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/string.h>
30 #include <linux/slab.h>
32 #include "dvb_frontend.h"
35 #include "dib3000mb_priv.h"
37 /* Version information */
38 #define DRIVER_VERSION "0.1"
39 #define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator"
40 #define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
42 #ifdef CONFIG_DVB_DIBCOM_DEBUG
44 module_param(debug
, int, 0644);
45 MODULE_PARM_DESC(debug
, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
47 #define deb_info(args...) dprintk(0x01,args)
48 #define deb_i2c(args...) dprintk(0x02,args)
49 #define deb_srch(args...) dprintk(0x04,args)
50 #define deb_info(args...) dprintk(0x01,args)
51 #define deb_xfer(args...) dprintk(0x02,args)
52 #define deb_setf(args...) dprintk(0x04,args)
53 #define deb_getf(args...) dprintk(0x08,args)
55 #ifdef CONFIG_DVB_DIBCOM_DEBUG
57 module_param(debug
, int, 0644);
58 MODULE_PARM_DESC(debug
, "set debugging level (1=info,2=i2c,4=srch (|-able)).");
61 static int dib3000_read_reg(struct dib3000_state
*state
, u16 reg
)
63 u8 wb
[] = { ((reg
>> 8) | 0x80) & 0xff, reg
& 0xff };
65 struct i2c_msg msg
[] = {
66 { .addr
= state
->config
.demod_address
, .flags
= 0, .buf
= wb
, .len
= 2 },
67 { .addr
= state
->config
.demod_address
, .flags
= I2C_M_RD
, .buf
= rb
, .len
= 2 },
70 if (i2c_transfer(state
->i2c
, msg
, 2) != 2)
71 deb_i2c("i2c read error\n");
73 deb_i2c("reading i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg
,reg
,
74 (rb
[0] << 8) | rb
[1],(rb
[0] << 8) | rb
[1]);
76 return (rb
[0] << 8) | rb
[1];
79 static int dib3000_write_reg(struct dib3000_state
*state
, u16 reg
, u16 val
)
82 (reg
>> 8) & 0xff, reg
& 0xff,
83 (val
>> 8) & 0xff, val
& 0xff,
85 struct i2c_msg msg
[] = {
86 { .addr
= state
->config
.demod_address
, .flags
= 0, .buf
= b
, .len
= 4 }
88 deb_i2c("writing i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg
,reg
,val
,val
);
90 return i2c_transfer(state
->i2c
,msg
, 1) != 1 ? -EREMOTEIO
: 0;
93 static int dib3000_search_status(u16 irq
,u16 lock
)
97 deb_srch("auto search succeeded\n");
98 return 1; // auto search succeeded
100 deb_srch("auto search not successful\n");
101 return 0; // auto search failed
103 } else if (irq
& 0x01) {
104 deb_srch("auto search failed\n");
105 return 0; // auto search failed
107 return -1; // try again
110 /* for auto search */
111 static u16 dib3000_seq
[2][2][2] = /* fft,gua, inv */
114 { 0, 1 }, /* 0 0 { 0,1 } */
115 { 3, 9 }, /* 0 1 { 0,1 } */
118 { 2, 5 }, /* 1 0 { 0,1 } */
119 { 6, 11 }, /* 1 1 { 0,1 } */
123 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
124 struct dvb_frontend_parameters
*fep
);
126 static int dib3000mb_set_frontend(struct dvb_frontend
* fe
,
127 struct dvb_frontend_parameters
*fep
, int tuner
)
129 struct dib3000_state
* state
= fe
->demodulator_priv
;
130 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
131 fe_code_rate_t fe_cr
= FEC_NONE
;
132 int search_state
, seq
;
134 if (tuner
&& fe
->ops
.tuner_ops
.set_params
) {
135 fe
->ops
.tuner_ops
.set_params(fe
, fep
);
136 if (fe
->ops
.i2c_gate_ctrl
) fe
->ops
.i2c_gate_ctrl(fe
, 0);
138 deb_setf("bandwidth: ");
139 switch (ofdm
->bandwidth
) {
140 case BANDWIDTH_8_MHZ
:
142 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
143 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
145 case BANDWIDTH_7_MHZ
:
147 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[1]);
148 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_7mhz
);
150 case BANDWIDTH_6_MHZ
:
152 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[0]);
153 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_6mhz
);
158 err("unkown bandwidth value.");
162 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
164 deb_setf("transmission mode: ");
165 switch (ofdm
->transmission_mode
) {
166 case TRANSMISSION_MODE_2K
:
168 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_2K
);
170 case TRANSMISSION_MODE_8K
:
172 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_8K
);
174 case TRANSMISSION_MODE_AUTO
:
182 switch (ofdm
->guard_interval
) {
183 case GUARD_INTERVAL_1_32
:
185 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_32
);
187 case GUARD_INTERVAL_1_16
:
189 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_16
);
191 case GUARD_INTERVAL_1_8
:
193 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_8
);
195 case GUARD_INTERVAL_1_4
:
197 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_4
);
199 case GUARD_INTERVAL_AUTO
:
206 deb_setf("inversion: ");
207 switch (fep
->inversion
) {
210 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_OFF
);
217 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_ON
);
223 deb_setf("constellation: ");
224 switch (ofdm
->constellation
) {
227 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_QPSK
);
231 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_16QAM
);
235 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_64QAM
);
242 deb_setf("hierarchy: ");
243 switch (ofdm
->hierarchy_information
) {
248 deb_setf("alpha=1\n");
249 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_1
);
252 deb_setf("alpha=2\n");
253 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_2
);
256 deb_setf("alpha=4\n");
257 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_4
);
260 deb_setf("alpha=auto\n");
266 deb_setf("hierarchy: ");
267 if (ofdm
->hierarchy_information
== HIERARCHY_NONE
) {
269 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_OFF
);
270 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_HP
);
271 fe_cr
= ofdm
->code_rate_HP
;
272 } else if (ofdm
->hierarchy_information
!= HIERARCHY_AUTO
) {
274 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_ON
);
275 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_LP
);
276 fe_cr
= ofdm
->code_rate_LP
;
282 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_1_2
);
286 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_2_3
);
290 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_3_4
);
294 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_5_6
);
298 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_7_8
);
311 [ofdm
->transmission_mode
== TRANSMISSION_MODE_AUTO
]
312 [ofdm
->guard_interval
== GUARD_INTERVAL_AUTO
]
313 [fep
->inversion
== INVERSION_AUTO
];
315 deb_setf("seq? %d\n", seq
);
317 wr(DIB3000MB_REG_SEQ
, seq
);
319 wr(DIB3000MB_REG_ISI
, seq
? DIB3000MB_ISI_INHIBIT
: DIB3000MB_ISI_ACTIVATE
);
321 if (ofdm
->transmission_mode
== TRANSMISSION_MODE_2K
) {
322 if (ofdm
->guard_interval
== GUARD_INTERVAL_1_8
) {
323 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_2K_1_8
);
325 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_DEFAULT
);
328 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_2K
);
330 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_DEFAULT
);
333 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_OFF
);
334 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
335 wr(DIB3000MB_REG_MOBILE_MODE
, DIB3000MB_MOBILE_MODE_OFF
);
337 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_high
);
339 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_ACTIVATE
);
341 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
+ DIB3000MB_RESTART_CTRL
);
342 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
344 /* wait for AGC lock */
347 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
349 /* something has to be auto searched */
350 if (ofdm
->constellation
== QAM_AUTO
||
351 ofdm
->hierarchy_information
== HIERARCHY_AUTO
||
353 fep
->inversion
== INVERSION_AUTO
) {
356 deb_setf("autosearch enabled.\n");
358 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
360 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AUTO_SEARCH
);
361 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
363 while ((search_state
=
364 dib3000_search_status(
365 rd(DIB3000MB_REG_AS_IRQ_PENDING
),
366 rd(DIB3000MB_REG_LOCK2_VALUE
))) < 0 && as_count
++ < 100)
369 deb_setf("search_state after autosearch %d after %d checks\n",search_state
,as_count
);
371 if (search_state
== 1) {
372 struct dvb_frontend_parameters feps
;
373 if (dib3000mb_get_frontend(fe
, &feps
) == 0) {
374 deb_setf("reading tuning data from frontend succeeded.\n");
375 return dib3000mb_set_frontend(fe
, &feps
, 0);
380 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_CTRL
);
381 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
387 static int dib3000mb_fe_init(struct dvb_frontend
* fe
, int mobile_mode
)
389 struct dib3000_state
* state
= fe
->demodulator_priv
;
391 deb_info("dib3000mb is getting up.\n");
392 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_UP
);
394 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
);
396 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE
);
397 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE_RST
);
399 wr(DIB3000MB_REG_CLOCK
, DIB3000MB_CLOCK_DEFAULT
);
401 wr(DIB3000MB_REG_ELECT_OUT_MODE
, DIB3000MB_ELECT_OUT_MODE_ON
);
403 wr(DIB3000MB_REG_DDS_FREQ_MSB
, DIB3000MB_DDS_FREQ_MSB
);
404 wr(DIB3000MB_REG_DDS_FREQ_LSB
, DIB3000MB_DDS_FREQ_LSB
);
406 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
408 wr_foreach(dib3000mb_reg_impulse_noise
,
409 dib3000mb_impulse_noise_values
[DIB3000MB_IMPNOISE_OFF
]);
411 wr_foreach(dib3000mb_reg_agc_gain
, dib3000mb_default_agc_gain
);
413 wr(DIB3000MB_REG_PHASE_NOISE
, DIB3000MB_PHASE_NOISE_DEFAULT
);
415 wr_foreach(dib3000mb_reg_phase_noise
, dib3000mb_default_noise_phase
);
417 wr_foreach(dib3000mb_reg_lock_duration
, dib3000mb_default_lock_duration
);
419 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
421 wr(DIB3000MB_REG_LOCK0_MASK
, DIB3000MB_LOCK0_DEFAULT
);
422 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
423 wr(DIB3000MB_REG_LOCK2_MASK
, DIB3000MB_LOCK2_DEFAULT
);
424 wr(DIB3000MB_REG_SEQ
, dib3000_seq
[1][1][1]);
426 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
428 wr(DIB3000MB_REG_UNK_68
, DIB3000MB_UNK_68
);
429 wr(DIB3000MB_REG_UNK_69
, DIB3000MB_UNK_69
);
430 wr(DIB3000MB_REG_UNK_71
, DIB3000MB_UNK_71
);
431 wr(DIB3000MB_REG_UNK_77
, DIB3000MB_UNK_77
);
432 wr(DIB3000MB_REG_UNK_78
, DIB3000MB_UNK_78
);
433 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
434 wr(DIB3000MB_REG_UNK_92
, DIB3000MB_UNK_92
);
435 wr(DIB3000MB_REG_UNK_96
, DIB3000MB_UNK_96
);
436 wr(DIB3000MB_REG_UNK_97
, DIB3000MB_UNK_97
);
437 wr(DIB3000MB_REG_UNK_106
, DIB3000MB_UNK_106
);
438 wr(DIB3000MB_REG_UNK_107
, DIB3000MB_UNK_107
);
439 wr(DIB3000MB_REG_UNK_108
, DIB3000MB_UNK_108
);
440 wr(DIB3000MB_REG_UNK_122
, DIB3000MB_UNK_122
);
441 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
442 wr(DIB3000MB_REG_BERLEN
, DIB3000MB_BERLEN_DEFAULT
);
444 wr_foreach(dib3000mb_reg_filter_coeffs
, dib3000mb_filter_coeffs
);
446 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_ON
);
447 wr(DIB3000MB_REG_MULTI_DEMOD_MSB
, DIB3000MB_MULTI_DEMOD_MSB
);
448 wr(DIB3000MB_REG_MULTI_DEMOD_LSB
, DIB3000MB_MULTI_DEMOD_LSB
);
450 wr(DIB3000MB_REG_OUTPUT_MODE
, DIB3000MB_OUTPUT_MODE_SLAVE
);
452 wr(DIB3000MB_REG_FIFO_142
, DIB3000MB_FIFO_142
);
453 wr(DIB3000MB_REG_MPEG2_OUT_MODE
, DIB3000MB_MPEG2_OUT_MODE_188
);
454 wr(DIB3000MB_REG_PID_PARSE
, DIB3000MB_PID_PARSE_ACTIVATE
);
455 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
456 wr(DIB3000MB_REG_FIFO_146
, DIB3000MB_FIFO_146
);
457 wr(DIB3000MB_REG_FIFO_147
, DIB3000MB_FIFO_147
);
459 wr(DIB3000MB_REG_DATA_IN_DIVERSITY
, DIB3000MB_DATA_DIVERSITY_IN_OFF
);
464 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
465 struct dvb_frontend_parameters
*fep
)
467 struct dib3000_state
* state
= fe
->demodulator_priv
;
468 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
471 int inv_test1
,inv_test2
;
472 u32 dds_val
, threshold
= 0x800000;
474 if (!rd(DIB3000MB_REG_TPS_LOCK
))
477 dds_val
= ((rd(DIB3000MB_REG_DDS_VALUE_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB
);
478 deb_getf("DDS_VAL: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_VALUE_MSB
), rd(DIB3000MB_REG_DDS_VALUE_LSB
));
479 if (dds_val
< threshold
)
481 else if (dds_val
== threshold
)
486 dds_val
= ((rd(DIB3000MB_REG_DDS_FREQ_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB
);
487 deb_getf("DDS_FREQ: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_FREQ_MSB
), rd(DIB3000MB_REG_DDS_FREQ_LSB
));
488 if (dds_val
< threshold
)
490 else if (dds_val
== threshold
)
496 ((inv_test2
== 2) && (inv_test1
==1 || inv_test1
==0)) ||
497 ((inv_test2
== 0) && (inv_test1
==1 || inv_test1
==2)) ?
498 INVERSION_ON
: INVERSION_OFF
;
500 deb_getf("inversion %d %d, %d\n", inv_test2
, inv_test1
, fep
->inversion
);
502 switch ((tps_val
= rd(DIB3000MB_REG_TPS_QAM
))) {
503 case DIB3000_CONSTELLATION_QPSK
:
505 ofdm
->constellation
= QPSK
;
507 case DIB3000_CONSTELLATION_16QAM
:
509 ofdm
->constellation
= QAM_16
;
511 case DIB3000_CONSTELLATION_64QAM
:
513 ofdm
->constellation
= QAM_64
;
516 err("Unexpected constellation returned by TPS (%d)", tps_val
);
519 deb_getf("TPS: %d\n", tps_val
);
521 if (rd(DIB3000MB_REG_TPS_HRCH
)) {
522 deb_getf("HRCH ON\n");
523 cr
= &ofdm
->code_rate_LP
;
524 ofdm
->code_rate_HP
= FEC_NONE
;
525 switch ((tps_val
= rd(DIB3000MB_REG_TPS_VIT_ALPHA
))) {
526 case DIB3000_ALPHA_0
:
527 deb_getf("HIERARCHY_NONE ");
528 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
530 case DIB3000_ALPHA_1
:
531 deb_getf("HIERARCHY_1 ");
532 ofdm
->hierarchy_information
= HIERARCHY_1
;
534 case DIB3000_ALPHA_2
:
535 deb_getf("HIERARCHY_2 ");
536 ofdm
->hierarchy_information
= HIERARCHY_2
;
538 case DIB3000_ALPHA_4
:
539 deb_getf("HIERARCHY_4 ");
540 ofdm
->hierarchy_information
= HIERARCHY_4
;
543 err("Unexpected ALPHA value returned by TPS (%d)", tps_val
);
546 deb_getf("TPS: %d\n", tps_val
);
548 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_LP
);
550 deb_getf("HRCH OFF\n");
551 cr
= &ofdm
->code_rate_HP
;
552 ofdm
->code_rate_LP
= FEC_NONE
;
553 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
555 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_HP
);
559 case DIB3000_FEC_1_2
:
560 deb_getf("FEC_1_2 ");
563 case DIB3000_FEC_2_3
:
564 deb_getf("FEC_2_3 ");
567 case DIB3000_FEC_3_4
:
568 deb_getf("FEC_3_4 ");
571 case DIB3000_FEC_5_6
:
572 deb_getf("FEC_5_6 ");
575 case DIB3000_FEC_7_8
:
576 deb_getf("FEC_7_8 ");
580 err("Unexpected FEC returned by TPS (%d)", tps_val
);
583 deb_getf("TPS: %d\n",tps_val
);
585 switch ((tps_val
= rd(DIB3000MB_REG_TPS_GUARD_TIME
))) {
586 case DIB3000_GUARD_TIME_1_32
:
587 deb_getf("GUARD_INTERVAL_1_32 ");
588 ofdm
->guard_interval
= GUARD_INTERVAL_1_32
;
590 case DIB3000_GUARD_TIME_1_16
:
591 deb_getf("GUARD_INTERVAL_1_16 ");
592 ofdm
->guard_interval
= GUARD_INTERVAL_1_16
;
594 case DIB3000_GUARD_TIME_1_8
:
595 deb_getf("GUARD_INTERVAL_1_8 ");
596 ofdm
->guard_interval
= GUARD_INTERVAL_1_8
;
598 case DIB3000_GUARD_TIME_1_4
:
599 deb_getf("GUARD_INTERVAL_1_4 ");
600 ofdm
->guard_interval
= GUARD_INTERVAL_1_4
;
603 err("Unexpected Guard Time returned by TPS (%d)", tps_val
);
606 deb_getf("TPS: %d\n", tps_val
);
608 switch ((tps_val
= rd(DIB3000MB_REG_TPS_FFT
))) {
609 case DIB3000_TRANSMISSION_MODE_2K
:
610 deb_getf("TRANSMISSION_MODE_2K ");
611 ofdm
->transmission_mode
= TRANSMISSION_MODE_2K
;
613 case DIB3000_TRANSMISSION_MODE_8K
:
614 deb_getf("TRANSMISSION_MODE_8K ");
615 ofdm
->transmission_mode
= TRANSMISSION_MODE_8K
;
618 err("unexpected transmission mode return by TPS (%d)", tps_val
);
621 deb_getf("TPS: %d\n", tps_val
);
626 static int dib3000mb_read_status(struct dvb_frontend
* fe
, fe_status_t
*stat
)
628 struct dib3000_state
* state
= fe
->demodulator_priv
;
632 if (rd(DIB3000MB_REG_AGC_LOCK
))
633 *stat
|= FE_HAS_SIGNAL
;
634 if (rd(DIB3000MB_REG_CARRIER_LOCK
))
635 *stat
|= FE_HAS_CARRIER
;
636 if (rd(DIB3000MB_REG_VIT_LCK
))
637 *stat
|= FE_HAS_VITERBI
;
638 if (rd(DIB3000MB_REG_TS_SYNC_LOCK
))
639 *stat
|= (FE_HAS_SYNC
| FE_HAS_LOCK
);
641 deb_getf("actual status is %2x\n",*stat
);
643 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
644 rd(DIB3000MB_REG_TPS_LOCK
),
645 rd(DIB3000MB_REG_TPS_QAM
),
646 rd(DIB3000MB_REG_TPS_HRCH
),
647 rd(DIB3000MB_REG_TPS_VIT_ALPHA
),
648 rd(DIB3000MB_REG_TPS_CODE_RATE_HP
),
649 rd(DIB3000MB_REG_TPS_CODE_RATE_LP
),
650 rd(DIB3000MB_REG_TPS_GUARD_TIME
),
651 rd(DIB3000MB_REG_TPS_FFT
),
652 rd(DIB3000MB_REG_TPS_CELL_ID
));
654 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
658 static int dib3000mb_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
660 struct dib3000_state
* state
= fe
->demodulator_priv
;
662 *ber
= ((rd(DIB3000MB_REG_BER_MSB
) << 16) | rd(DIB3000MB_REG_BER_LSB
));
666 /* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
667 static int dib3000mb_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
669 struct dib3000_state
* state
= fe
->demodulator_priv
;
671 *strength
= rd(DIB3000MB_REG_SIGNAL_POWER
) * 0xffff / 0x170;
675 static int dib3000mb_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
677 struct dib3000_state
* state
= fe
->demodulator_priv
;
678 short sigpow
= rd(DIB3000MB_REG_SIGNAL_POWER
);
679 int icipow
= ((rd(DIB3000MB_REG_NOISE_POWER_MSB
) & 0xff) << 16) |
680 rd(DIB3000MB_REG_NOISE_POWER_LSB
);
681 *snr
= (sigpow
<< 8) / ((icipow
> 0) ? icipow
: 1);
685 static int dib3000mb_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
687 struct dib3000_state
* state
= fe
->demodulator_priv
;
689 *unc
= rd(DIB3000MB_REG_PACKET_ERROR_RATE
);
693 static int dib3000mb_sleep(struct dvb_frontend
* fe
)
695 struct dib3000_state
* state
= fe
->demodulator_priv
;
696 deb_info("dib3000mb is going to bed.\n");
697 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_DOWN
);
701 static int dib3000mb_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
703 tune
->min_delay_ms
= 800;
707 static int dib3000mb_fe_init_nonmobile(struct dvb_frontend
* fe
)
709 return dib3000mb_fe_init(fe
, 0);
712 static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*fep
)
714 return dib3000mb_set_frontend(fe
, fep
, 1);
717 static void dib3000mb_release(struct dvb_frontend
* fe
)
719 struct dib3000_state
*state
= fe
->demodulator_priv
;
723 /* pid filter and transfer stuff */
724 static int dib3000mb_pid_control(struct dvb_frontend
*fe
,int index
, int pid
,int onoff
)
726 struct dib3000_state
*state
= fe
->demodulator_priv
;
727 pid
= (onoff
? pid
| DIB3000_ACTIVATE_PID_FILTERING
: 0);
728 wr(index
+DIB3000MB_REG_FIRST_PID
,pid
);
732 static int dib3000mb_fifo_control(struct dvb_frontend
*fe
, int onoff
)
734 struct dib3000_state
*state
= fe
->demodulator_priv
;
736 deb_xfer("%s fifo\n",onoff
? "enabling" : "disabling");
738 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_ACTIVATE
);
740 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
745 static int dib3000mb_pid_parse(struct dvb_frontend
*fe
, int onoff
)
747 struct dib3000_state
*state
= fe
->demodulator_priv
;
748 deb_xfer("%s pid parsing\n",onoff
? "enabling" : "disabling");
749 wr(DIB3000MB_REG_PID_PARSE
,onoff
);
753 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend
*fe
, int onoff
, u8 pll_addr
)
755 struct dib3000_state
*state
= fe
->demodulator_priv
;
757 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_ENABLE(pll_addr
));
759 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_DISABLE(pll_addr
));
764 static struct dvb_frontend_ops dib3000mb_ops
;
766 struct dvb_frontend
* dib3000mb_attach(const struct dib3000_config
* config
,
767 struct i2c_adapter
* i2c
, struct dib_fe_xfer_ops
*xfer_ops
)
769 struct dib3000_state
* state
= NULL
;
771 /* allocate memory for the internal state */
772 state
= kzalloc(sizeof(struct dib3000_state
), GFP_KERNEL
);
776 /* setup the state */
778 memcpy(&state
->config
,config
,sizeof(struct dib3000_config
));
780 /* check for the correct demod */
781 if (rd(DIB3000_REG_MANUFACTOR_ID
) != DIB3000_I2C_ID_DIBCOM
)
784 if (rd(DIB3000_REG_DEVICE_ID
) != DIB3000MB_DEVICE_ID
)
787 /* create dvb_frontend */
788 memcpy(&state
->frontend
.ops
, &dib3000mb_ops
, sizeof(struct dvb_frontend_ops
));
789 state
->frontend
.demodulator_priv
= state
;
791 /* set the xfer operations */
792 xfer_ops
->pid_parse
= dib3000mb_pid_parse
;
793 xfer_ops
->fifo_ctrl
= dib3000mb_fifo_control
;
794 xfer_ops
->pid_ctrl
= dib3000mb_pid_control
;
795 xfer_ops
->tuner_pass_ctrl
= dib3000mb_tuner_pass_ctrl
;
797 return &state
->frontend
;
804 static struct dvb_frontend_ops dib3000mb_ops
= {
807 .name
= "DiBcom 3000M-B DVB-T",
809 .frequency_min
= 44250000,
810 .frequency_max
= 867250000,
811 .frequency_stepsize
= 62500,
812 .caps
= FE_CAN_INVERSION_AUTO
|
813 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
814 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
815 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
816 FE_CAN_TRANSMISSION_MODE_AUTO
|
817 FE_CAN_GUARD_INTERVAL_AUTO
|
819 FE_CAN_HIERARCHY_AUTO
,
822 .release
= dib3000mb_release
,
824 .init
= dib3000mb_fe_init_nonmobile
,
825 .sleep
= dib3000mb_sleep
,
827 .set_frontend
= dib3000mb_set_frontend_and_tuner
,
828 .get_frontend
= dib3000mb_get_frontend
,
829 .get_tune_settings
= dib3000mb_fe_get_tune_settings
,
831 .read_status
= dib3000mb_read_status
,
832 .read_ber
= dib3000mb_read_ber
,
833 .read_signal_strength
= dib3000mb_read_signal_strength
,
834 .read_snr
= dib3000mb_read_snr
,
835 .read_ucblocks
= dib3000mb_read_unc_blocks
,
838 MODULE_AUTHOR(DRIVER_AUTHOR
);
839 MODULE_DESCRIPTION(DRIVER_DESC
);
840 MODULE_LICENSE("GPL");
842 EXPORT_SYMBOL(dib3000mb_attach
);