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.dvb-usb 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"
42 module_param(debug
, int, 0644);
43 MODULE_PARM_DESC(debug
, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
45 #define deb_info(args...) dprintk(0x01,args)
46 #define deb_i2c(args...) dprintk(0x02,args)
47 #define deb_srch(args...) dprintk(0x04,args)
48 #define deb_info(args...) dprintk(0x01,args)
49 #define deb_xfer(args...) dprintk(0x02,args)
50 #define deb_setf(args...) dprintk(0x04,args)
51 #define deb_getf(args...) dprintk(0x08,args)
53 static int dib3000_read_reg(struct dib3000_state
*state
, u16 reg
)
55 u8 wb
[] = { ((reg
>> 8) | 0x80) & 0xff, reg
& 0xff };
57 struct i2c_msg msg
[] = {
58 { .addr
= state
->config
.demod_address
, .flags
= 0, .buf
= wb
, .len
= 2 },
59 { .addr
= state
->config
.demod_address
, .flags
= I2C_M_RD
, .buf
= rb
, .len
= 2 },
62 if (i2c_transfer(state
->i2c
, msg
, 2) != 2)
63 deb_i2c("i2c read error\n");
65 deb_i2c("reading i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg
,reg
,
66 (rb
[0] << 8) | rb
[1],(rb
[0] << 8) | rb
[1]);
68 return (rb
[0] << 8) | rb
[1];
71 static int dib3000_write_reg(struct dib3000_state
*state
, u16 reg
, u16 val
)
74 (reg
>> 8) & 0xff, reg
& 0xff,
75 (val
>> 8) & 0xff, val
& 0xff,
77 struct i2c_msg msg
[] = {
78 { .addr
= state
->config
.demod_address
, .flags
= 0, .buf
= b
, .len
= 4 }
80 deb_i2c("writing i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg
,reg
,val
,val
);
82 return i2c_transfer(state
->i2c
,msg
, 1) != 1 ? -EREMOTEIO
: 0;
85 static int dib3000_search_status(u16 irq
,u16 lock
)
89 deb_srch("auto search succeeded\n");
90 return 1; // auto search succeeded
92 deb_srch("auto search not successful\n");
93 return 0; // auto search failed
95 } else if (irq
& 0x01) {
96 deb_srch("auto search failed\n");
97 return 0; // auto search failed
99 return -1; // try again
102 /* for auto search */
103 static u16 dib3000_seq
[2][2][2] = /* fft,gua, inv */
106 { 0, 1 }, /* 0 0 { 0,1 } */
107 { 3, 9 }, /* 0 1 { 0,1 } */
110 { 2, 5 }, /* 1 0 { 0,1 } */
111 { 6, 11 }, /* 1 1 { 0,1 } */
115 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
);
117 static int dib3000mb_set_frontend(struct dvb_frontend
*fe
, int tuner
)
119 struct dib3000_state
* state
= fe
->demodulator_priv
;
120 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
121 fe_code_rate_t fe_cr
= FEC_NONE
;
122 int search_state
, seq
;
124 if (tuner
&& fe
->ops
.tuner_ops
.set_params
) {
125 fe
->ops
.tuner_ops
.set_params(fe
);
126 if (fe
->ops
.i2c_gate_ctrl
) fe
->ops
.i2c_gate_ctrl(fe
, 0);
128 deb_setf("bandwidth: ");
129 switch (c
->bandwidth_hz
) {
132 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
133 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
137 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[1]);
138 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_7mhz
);
142 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[0]);
143 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_6mhz
);
148 err("unknown bandwidth value.");
152 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
154 deb_setf("transmission mode: ");
155 switch (c
->transmission_mode
) {
156 case TRANSMISSION_MODE_2K
:
158 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_2K
);
160 case TRANSMISSION_MODE_8K
:
162 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_8K
);
164 case TRANSMISSION_MODE_AUTO
:
172 switch (c
->guard_interval
) {
173 case GUARD_INTERVAL_1_32
:
175 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_32
);
177 case GUARD_INTERVAL_1_16
:
179 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_16
);
181 case GUARD_INTERVAL_1_8
:
183 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_8
);
185 case GUARD_INTERVAL_1_4
:
187 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_4
);
189 case GUARD_INTERVAL_AUTO
:
196 deb_setf("inversion: ");
197 switch (c
->inversion
) {
200 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_OFF
);
207 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_ON
);
213 deb_setf("modulation: ");
214 switch (c
->modulation
) {
217 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_QPSK
);
221 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_16QAM
);
225 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_64QAM
);
232 deb_setf("hierarchy: ");
233 switch (c
->hierarchy
) {
238 deb_setf("alpha=1\n");
239 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_1
);
242 deb_setf("alpha=2\n");
243 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_2
);
246 deb_setf("alpha=4\n");
247 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_4
);
250 deb_setf("alpha=auto\n");
256 deb_setf("hierarchy: ");
257 if (c
->hierarchy
== HIERARCHY_NONE
) {
259 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_OFF
);
260 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_HP
);
261 fe_cr
= c
->code_rate_HP
;
262 } else if (c
->hierarchy
!= HIERARCHY_AUTO
) {
264 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_ON
);
265 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_LP
);
266 fe_cr
= c
->code_rate_LP
;
272 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_1_2
);
276 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_2_3
);
280 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_3_4
);
284 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_5_6
);
288 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_7_8
);
301 [c
->transmission_mode
== TRANSMISSION_MODE_AUTO
]
302 [c
->guard_interval
== GUARD_INTERVAL_AUTO
]
303 [c
->inversion
== INVERSION_AUTO
];
305 deb_setf("seq? %d\n", seq
);
307 wr(DIB3000MB_REG_SEQ
, seq
);
309 wr(DIB3000MB_REG_ISI
, seq
? DIB3000MB_ISI_INHIBIT
: DIB3000MB_ISI_ACTIVATE
);
311 if (c
->transmission_mode
== TRANSMISSION_MODE_2K
) {
312 if (c
->guard_interval
== GUARD_INTERVAL_1_8
) {
313 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_2K_1_8
);
315 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_DEFAULT
);
318 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_2K
);
320 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_DEFAULT
);
323 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_OFF
);
324 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
325 wr(DIB3000MB_REG_MOBILE_MODE
, DIB3000MB_MOBILE_MODE_OFF
);
327 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_high
);
329 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_ACTIVATE
);
331 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
+ DIB3000MB_RESTART_CTRL
);
332 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
334 /* wait for AGC lock */
337 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
339 /* something has to be auto searched */
340 if (c
->modulation
== QAM_AUTO
||
341 c
->hierarchy
== HIERARCHY_AUTO
||
343 c
->inversion
== INVERSION_AUTO
) {
346 deb_setf("autosearch enabled.\n");
348 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
350 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AUTO_SEARCH
);
351 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
353 while ((search_state
=
354 dib3000_search_status(
355 rd(DIB3000MB_REG_AS_IRQ_PENDING
),
356 rd(DIB3000MB_REG_LOCK2_VALUE
))) < 0 && as_count
++ < 100)
359 deb_setf("search_state after autosearch %d after %d checks\n",search_state
,as_count
);
361 if (search_state
== 1) {
362 if (dib3000mb_get_frontend(fe
) == 0) {
363 deb_setf("reading tuning data from frontend succeeded.\n");
364 return dib3000mb_set_frontend(fe
, 0);
369 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_CTRL
);
370 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
376 static int dib3000mb_fe_init(struct dvb_frontend
* fe
, int mobile_mode
)
378 struct dib3000_state
* state
= fe
->demodulator_priv
;
380 deb_info("dib3000mb is getting up.\n");
381 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_UP
);
383 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
);
385 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE
);
386 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE_RST
);
388 wr(DIB3000MB_REG_CLOCK
, DIB3000MB_CLOCK_DEFAULT
);
390 wr(DIB3000MB_REG_ELECT_OUT_MODE
, DIB3000MB_ELECT_OUT_MODE_ON
);
392 wr(DIB3000MB_REG_DDS_FREQ_MSB
, DIB3000MB_DDS_FREQ_MSB
);
393 wr(DIB3000MB_REG_DDS_FREQ_LSB
, DIB3000MB_DDS_FREQ_LSB
);
395 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
397 wr_foreach(dib3000mb_reg_impulse_noise
,
398 dib3000mb_impulse_noise_values
[DIB3000MB_IMPNOISE_OFF
]);
400 wr_foreach(dib3000mb_reg_agc_gain
, dib3000mb_default_agc_gain
);
402 wr(DIB3000MB_REG_PHASE_NOISE
, DIB3000MB_PHASE_NOISE_DEFAULT
);
404 wr_foreach(dib3000mb_reg_phase_noise
, dib3000mb_default_noise_phase
);
406 wr_foreach(dib3000mb_reg_lock_duration
, dib3000mb_default_lock_duration
);
408 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
410 wr(DIB3000MB_REG_LOCK0_MASK
, DIB3000MB_LOCK0_DEFAULT
);
411 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
412 wr(DIB3000MB_REG_LOCK2_MASK
, DIB3000MB_LOCK2_DEFAULT
);
413 wr(DIB3000MB_REG_SEQ
, dib3000_seq
[1][1][1]);
415 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
417 wr(DIB3000MB_REG_UNK_68
, DIB3000MB_UNK_68
);
418 wr(DIB3000MB_REG_UNK_69
, DIB3000MB_UNK_69
);
419 wr(DIB3000MB_REG_UNK_71
, DIB3000MB_UNK_71
);
420 wr(DIB3000MB_REG_UNK_77
, DIB3000MB_UNK_77
);
421 wr(DIB3000MB_REG_UNK_78
, DIB3000MB_UNK_78
);
422 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
423 wr(DIB3000MB_REG_UNK_92
, DIB3000MB_UNK_92
);
424 wr(DIB3000MB_REG_UNK_96
, DIB3000MB_UNK_96
);
425 wr(DIB3000MB_REG_UNK_97
, DIB3000MB_UNK_97
);
426 wr(DIB3000MB_REG_UNK_106
, DIB3000MB_UNK_106
);
427 wr(DIB3000MB_REG_UNK_107
, DIB3000MB_UNK_107
);
428 wr(DIB3000MB_REG_UNK_108
, DIB3000MB_UNK_108
);
429 wr(DIB3000MB_REG_UNK_122
, DIB3000MB_UNK_122
);
430 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
431 wr(DIB3000MB_REG_BERLEN
, DIB3000MB_BERLEN_DEFAULT
);
433 wr_foreach(dib3000mb_reg_filter_coeffs
, dib3000mb_filter_coeffs
);
435 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_ON
);
436 wr(DIB3000MB_REG_MULTI_DEMOD_MSB
, DIB3000MB_MULTI_DEMOD_MSB
);
437 wr(DIB3000MB_REG_MULTI_DEMOD_LSB
, DIB3000MB_MULTI_DEMOD_LSB
);
439 wr(DIB3000MB_REG_OUTPUT_MODE
, DIB3000MB_OUTPUT_MODE_SLAVE
);
441 wr(DIB3000MB_REG_FIFO_142
, DIB3000MB_FIFO_142
);
442 wr(DIB3000MB_REG_MPEG2_OUT_MODE
, DIB3000MB_MPEG2_OUT_MODE_188
);
443 wr(DIB3000MB_REG_PID_PARSE
, DIB3000MB_PID_PARSE_ACTIVATE
);
444 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
445 wr(DIB3000MB_REG_FIFO_146
, DIB3000MB_FIFO_146
);
446 wr(DIB3000MB_REG_FIFO_147
, DIB3000MB_FIFO_147
);
448 wr(DIB3000MB_REG_DATA_IN_DIVERSITY
, DIB3000MB_DATA_DIVERSITY_IN_OFF
);
453 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
)
455 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
456 struct dib3000_state
* state
= fe
->demodulator_priv
;
459 int inv_test1
,inv_test2
;
460 u32 dds_val
, threshold
= 0x800000;
462 if (!rd(DIB3000MB_REG_TPS_LOCK
))
465 dds_val
= ((rd(DIB3000MB_REG_DDS_VALUE_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB
);
466 deb_getf("DDS_VAL: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_VALUE_MSB
), rd(DIB3000MB_REG_DDS_VALUE_LSB
));
467 if (dds_val
< threshold
)
469 else if (dds_val
== threshold
)
474 dds_val
= ((rd(DIB3000MB_REG_DDS_FREQ_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB
);
475 deb_getf("DDS_FREQ: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_FREQ_MSB
), rd(DIB3000MB_REG_DDS_FREQ_LSB
));
476 if (dds_val
< threshold
)
478 else if (dds_val
== threshold
)
484 ((inv_test2
== 2) && (inv_test1
==1 || inv_test1
==0)) ||
485 ((inv_test2
== 0) && (inv_test1
==1 || inv_test1
==2)) ?
486 INVERSION_ON
: INVERSION_OFF
;
488 deb_getf("inversion %d %d, %d\n", inv_test2
, inv_test1
, c
->inversion
);
490 switch ((tps_val
= rd(DIB3000MB_REG_TPS_QAM
))) {
491 case DIB3000_CONSTELLATION_QPSK
:
493 c
->modulation
= QPSK
;
495 case DIB3000_CONSTELLATION_16QAM
:
497 c
->modulation
= QAM_16
;
499 case DIB3000_CONSTELLATION_64QAM
:
501 c
->modulation
= QAM_64
;
504 err("Unexpected constellation returned by TPS (%d)", tps_val
);
507 deb_getf("TPS: %d\n", tps_val
);
509 if (rd(DIB3000MB_REG_TPS_HRCH
)) {
510 deb_getf("HRCH ON\n");
511 cr
= &c
->code_rate_LP
;
512 c
->code_rate_HP
= FEC_NONE
;
513 switch ((tps_val
= rd(DIB3000MB_REG_TPS_VIT_ALPHA
))) {
514 case DIB3000_ALPHA_0
:
515 deb_getf("HIERARCHY_NONE ");
516 c
->hierarchy
= HIERARCHY_NONE
;
518 case DIB3000_ALPHA_1
:
519 deb_getf("HIERARCHY_1 ");
520 c
->hierarchy
= HIERARCHY_1
;
522 case DIB3000_ALPHA_2
:
523 deb_getf("HIERARCHY_2 ");
524 c
->hierarchy
= HIERARCHY_2
;
526 case DIB3000_ALPHA_4
:
527 deb_getf("HIERARCHY_4 ");
528 c
->hierarchy
= HIERARCHY_4
;
531 err("Unexpected ALPHA value returned by TPS (%d)", tps_val
);
534 deb_getf("TPS: %d\n", tps_val
);
536 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_LP
);
538 deb_getf("HRCH OFF\n");
539 cr
= &c
->code_rate_HP
;
540 c
->code_rate_LP
= FEC_NONE
;
541 c
->hierarchy
= HIERARCHY_NONE
;
543 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_HP
);
547 case DIB3000_FEC_1_2
:
548 deb_getf("FEC_1_2 ");
551 case DIB3000_FEC_2_3
:
552 deb_getf("FEC_2_3 ");
555 case DIB3000_FEC_3_4
:
556 deb_getf("FEC_3_4 ");
559 case DIB3000_FEC_5_6
:
560 deb_getf("FEC_5_6 ");
563 case DIB3000_FEC_7_8
:
564 deb_getf("FEC_7_8 ");
568 err("Unexpected FEC returned by TPS (%d)", tps_val
);
571 deb_getf("TPS: %d\n",tps_val
);
573 switch ((tps_val
= rd(DIB3000MB_REG_TPS_GUARD_TIME
))) {
574 case DIB3000_GUARD_TIME_1_32
:
575 deb_getf("GUARD_INTERVAL_1_32 ");
576 c
->guard_interval
= GUARD_INTERVAL_1_32
;
578 case DIB3000_GUARD_TIME_1_16
:
579 deb_getf("GUARD_INTERVAL_1_16 ");
580 c
->guard_interval
= GUARD_INTERVAL_1_16
;
582 case DIB3000_GUARD_TIME_1_8
:
583 deb_getf("GUARD_INTERVAL_1_8 ");
584 c
->guard_interval
= GUARD_INTERVAL_1_8
;
586 case DIB3000_GUARD_TIME_1_4
:
587 deb_getf("GUARD_INTERVAL_1_4 ");
588 c
->guard_interval
= GUARD_INTERVAL_1_4
;
591 err("Unexpected Guard Time returned by TPS (%d)", tps_val
);
594 deb_getf("TPS: %d\n", tps_val
);
596 switch ((tps_val
= rd(DIB3000MB_REG_TPS_FFT
))) {
597 case DIB3000_TRANSMISSION_MODE_2K
:
598 deb_getf("TRANSMISSION_MODE_2K ");
599 c
->transmission_mode
= TRANSMISSION_MODE_2K
;
601 case DIB3000_TRANSMISSION_MODE_8K
:
602 deb_getf("TRANSMISSION_MODE_8K ");
603 c
->transmission_mode
= TRANSMISSION_MODE_8K
;
606 err("unexpected transmission mode return by TPS (%d)", tps_val
);
609 deb_getf("TPS: %d\n", tps_val
);
614 static int dib3000mb_read_status(struct dvb_frontend
* fe
, fe_status_t
*stat
)
616 struct dib3000_state
* state
= fe
->demodulator_priv
;
620 if (rd(DIB3000MB_REG_AGC_LOCK
))
621 *stat
|= FE_HAS_SIGNAL
;
622 if (rd(DIB3000MB_REG_CARRIER_LOCK
))
623 *stat
|= FE_HAS_CARRIER
;
624 if (rd(DIB3000MB_REG_VIT_LCK
))
625 *stat
|= FE_HAS_VITERBI
;
626 if (rd(DIB3000MB_REG_TS_SYNC_LOCK
))
627 *stat
|= (FE_HAS_SYNC
| FE_HAS_LOCK
);
629 deb_getf("actual status is %2x\n",*stat
);
631 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
632 rd(DIB3000MB_REG_TPS_LOCK
),
633 rd(DIB3000MB_REG_TPS_QAM
),
634 rd(DIB3000MB_REG_TPS_HRCH
),
635 rd(DIB3000MB_REG_TPS_VIT_ALPHA
),
636 rd(DIB3000MB_REG_TPS_CODE_RATE_HP
),
637 rd(DIB3000MB_REG_TPS_CODE_RATE_LP
),
638 rd(DIB3000MB_REG_TPS_GUARD_TIME
),
639 rd(DIB3000MB_REG_TPS_FFT
),
640 rd(DIB3000MB_REG_TPS_CELL_ID
));
642 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
646 static int dib3000mb_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
648 struct dib3000_state
* state
= fe
->demodulator_priv
;
650 *ber
= ((rd(DIB3000MB_REG_BER_MSB
) << 16) | rd(DIB3000MB_REG_BER_LSB
));
654 /* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
655 static int dib3000mb_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
657 struct dib3000_state
* state
= fe
->demodulator_priv
;
659 *strength
= rd(DIB3000MB_REG_SIGNAL_POWER
) * 0xffff / 0x170;
663 static int dib3000mb_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
665 struct dib3000_state
* state
= fe
->demodulator_priv
;
666 short sigpow
= rd(DIB3000MB_REG_SIGNAL_POWER
);
667 int icipow
= ((rd(DIB3000MB_REG_NOISE_POWER_MSB
) & 0xff) << 16) |
668 rd(DIB3000MB_REG_NOISE_POWER_LSB
);
669 *snr
= (sigpow
<< 8) / ((icipow
> 0) ? icipow
: 1);
673 static int dib3000mb_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
675 struct dib3000_state
* state
= fe
->demodulator_priv
;
677 *unc
= rd(DIB3000MB_REG_PACKET_ERROR_RATE
);
681 static int dib3000mb_sleep(struct dvb_frontend
* fe
)
683 struct dib3000_state
* state
= fe
->demodulator_priv
;
684 deb_info("dib3000mb is going to bed.\n");
685 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_DOWN
);
689 static int dib3000mb_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
691 tune
->min_delay_ms
= 800;
695 static int dib3000mb_fe_init_nonmobile(struct dvb_frontend
* fe
)
697 return dib3000mb_fe_init(fe
, 0);
700 static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend
*fe
)
702 return dib3000mb_set_frontend(fe
, 1);
705 static void dib3000mb_release(struct dvb_frontend
* fe
)
707 struct dib3000_state
*state
= fe
->demodulator_priv
;
711 /* pid filter and transfer stuff */
712 static int dib3000mb_pid_control(struct dvb_frontend
*fe
,int index
, int pid
,int onoff
)
714 struct dib3000_state
*state
= fe
->demodulator_priv
;
715 pid
= (onoff
? pid
| DIB3000_ACTIVATE_PID_FILTERING
: 0);
716 wr(index
+DIB3000MB_REG_FIRST_PID
,pid
);
720 static int dib3000mb_fifo_control(struct dvb_frontend
*fe
, int onoff
)
722 struct dib3000_state
*state
= fe
->demodulator_priv
;
724 deb_xfer("%s fifo\n",onoff
? "enabling" : "disabling");
726 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_ACTIVATE
);
728 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
733 static int dib3000mb_pid_parse(struct dvb_frontend
*fe
, int onoff
)
735 struct dib3000_state
*state
= fe
->demodulator_priv
;
736 deb_xfer("%s pid parsing\n",onoff
? "enabling" : "disabling");
737 wr(DIB3000MB_REG_PID_PARSE
,onoff
);
741 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend
*fe
, int onoff
, u8 pll_addr
)
743 struct dib3000_state
*state
= fe
->demodulator_priv
;
745 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_ENABLE(pll_addr
));
747 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_DISABLE(pll_addr
));
752 static struct dvb_frontend_ops dib3000mb_ops
;
754 struct dvb_frontend
* dib3000mb_attach(const struct dib3000_config
* config
,
755 struct i2c_adapter
* i2c
, struct dib_fe_xfer_ops
*xfer_ops
)
757 struct dib3000_state
* state
= NULL
;
759 /* allocate memory for the internal state */
760 state
= kzalloc(sizeof(struct dib3000_state
), GFP_KERNEL
);
764 /* setup the state */
766 memcpy(&state
->config
,config
,sizeof(struct dib3000_config
));
768 /* check for the correct demod */
769 if (rd(DIB3000_REG_MANUFACTOR_ID
) != DIB3000_I2C_ID_DIBCOM
)
772 if (rd(DIB3000_REG_DEVICE_ID
) != DIB3000MB_DEVICE_ID
)
775 /* create dvb_frontend */
776 memcpy(&state
->frontend
.ops
, &dib3000mb_ops
, sizeof(struct dvb_frontend_ops
));
777 state
->frontend
.demodulator_priv
= state
;
779 /* set the xfer operations */
780 xfer_ops
->pid_parse
= dib3000mb_pid_parse
;
781 xfer_ops
->fifo_ctrl
= dib3000mb_fifo_control
;
782 xfer_ops
->pid_ctrl
= dib3000mb_pid_control
;
783 xfer_ops
->tuner_pass_ctrl
= dib3000mb_tuner_pass_ctrl
;
785 return &state
->frontend
;
792 static struct dvb_frontend_ops dib3000mb_ops
= {
793 .delsys
= { SYS_DVBT
},
795 .name
= "DiBcom 3000M-B DVB-T",
796 .frequency_min
= 44250000,
797 .frequency_max
= 867250000,
798 .frequency_stepsize
= 62500,
799 .caps
= FE_CAN_INVERSION_AUTO
|
800 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
801 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
802 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
803 FE_CAN_TRANSMISSION_MODE_AUTO
|
804 FE_CAN_GUARD_INTERVAL_AUTO
|
806 FE_CAN_HIERARCHY_AUTO
,
809 .release
= dib3000mb_release
,
811 .init
= dib3000mb_fe_init_nonmobile
,
812 .sleep
= dib3000mb_sleep
,
814 .set_frontend
= dib3000mb_set_frontend_and_tuner
,
815 .get_frontend
= dib3000mb_get_frontend
,
816 .get_tune_settings
= dib3000mb_fe_get_tune_settings
,
818 .read_status
= dib3000mb_read_status
,
819 .read_ber
= dib3000mb_read_ber
,
820 .read_signal_strength
= dib3000mb_read_signal_strength
,
821 .read_snr
= dib3000mb_read_snr
,
822 .read_ucblocks
= dib3000mb_read_unc_blocks
,
825 MODULE_AUTHOR(DRIVER_AUTHOR
);
826 MODULE_DESCRIPTION(DRIVER_DESC
);
827 MODULE_LICENSE("GPL");
829 EXPORT_SYMBOL(dib3000mb_attach
);