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/config.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
31 #include "dib3000-common.h"
32 #include "dib3000mb_priv.h"
35 /* Version information */
36 #define DRIVER_VERSION "0.1"
37 #define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator"
38 #define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
40 #ifdef CONFIG_DVB_DIBCOM_DEBUG
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_xfer(args...) dprintk(0x02,args)
47 #define deb_setf(args...) dprintk(0x04,args)
48 #define deb_getf(args...) dprintk(0x08,args)
50 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
51 struct dvb_frontend_parameters
*fep
);
53 static int dib3000mb_set_frontend(struct dvb_frontend
* fe
,
54 struct dvb_frontend_parameters
*fep
, int tuner
)
56 struct dib3000_state
* state
= fe
->demodulator_priv
;
57 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
58 fe_code_rate_t fe_cr
= FEC_NONE
;
59 int search_state
, seq
;
61 if (tuner
&& state
->config
.pll_set
) {
62 state
->config
.pll_set(fe
, fep
);
64 deb_setf("bandwidth: ");
65 switch (ofdm
->bandwidth
) {
68 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
69 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
73 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[1]);
74 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_7mhz
);
78 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[0]);
79 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_6mhz
);
84 err("unkown bandwidth value.");
88 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
90 deb_setf("transmission mode: ");
91 switch (ofdm
->transmission_mode
) {
92 case TRANSMISSION_MODE_2K
:
94 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_2K
);
96 case TRANSMISSION_MODE_8K
:
98 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_8K
);
100 case TRANSMISSION_MODE_AUTO
:
108 switch (ofdm
->guard_interval
) {
109 case GUARD_INTERVAL_1_32
:
111 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_32
);
113 case GUARD_INTERVAL_1_16
:
115 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_16
);
117 case GUARD_INTERVAL_1_8
:
119 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_8
);
121 case GUARD_INTERVAL_1_4
:
123 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_4
);
125 case GUARD_INTERVAL_AUTO
:
132 deb_setf("inversion: ");
133 switch (fep
->inversion
) {
136 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_OFF
);
143 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_ON
);
149 deb_setf("constellation: ");
150 switch (ofdm
->constellation
) {
153 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_QPSK
);
157 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_16QAM
);
161 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_64QAM
);
168 deb_setf("hierachy: ");
169 switch (ofdm
->hierarchy_information
) {
174 deb_setf("alpha=1\n");
175 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_1
);
178 deb_setf("alpha=2\n");
179 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_2
);
182 deb_setf("alpha=4\n");
183 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_4
);
186 deb_setf("alpha=auto\n");
192 deb_setf("hierarchy: ");
193 if (ofdm
->hierarchy_information
== HIERARCHY_NONE
) {
195 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_OFF
);
196 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_HP
);
197 fe_cr
= ofdm
->code_rate_HP
;
198 } else if (ofdm
->hierarchy_information
!= HIERARCHY_AUTO
) {
200 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_ON
);
201 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_LP
);
202 fe_cr
= ofdm
->code_rate_LP
;
208 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_1_2
);
212 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_2_3
);
216 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_3_4
);
220 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_5_6
);
224 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_7_8
);
237 [ofdm
->transmission_mode
== TRANSMISSION_MODE_AUTO
]
238 [ofdm
->guard_interval
== GUARD_INTERVAL_AUTO
]
239 [fep
->inversion
== INVERSION_AUTO
];
241 deb_setf("seq? %d\n", seq
);
243 wr(DIB3000MB_REG_SEQ
, seq
);
245 wr(DIB3000MB_REG_ISI
, seq
? DIB3000MB_ISI_INHIBIT
: DIB3000MB_ISI_ACTIVATE
);
247 if (ofdm
->transmission_mode
== TRANSMISSION_MODE_2K
) {
248 if (ofdm
->guard_interval
== GUARD_INTERVAL_1_8
) {
249 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_2K_1_8
);
251 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_DEFAULT
);
254 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_2K
);
256 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_DEFAULT
);
259 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_OFF
);
260 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
261 wr(DIB3000MB_REG_MOBILE_MODE
, DIB3000MB_MOBILE_MODE_OFF
);
263 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_high
);
265 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_ACTIVATE
);
267 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
+ DIB3000MB_RESTART_CTRL
);
268 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
270 /* wait for AGC lock */
273 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
275 /* something has to be auto searched */
276 if (ofdm
->constellation
== QAM_AUTO
||
277 ofdm
->hierarchy_information
== HIERARCHY_AUTO
||
279 fep
->inversion
== INVERSION_AUTO
) {
282 deb_setf("autosearch enabled.\n");
284 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
286 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AUTO_SEARCH
);
287 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
289 while ((search_state
=
290 dib3000_search_status(
291 rd(DIB3000MB_REG_AS_IRQ_PENDING
),
292 rd(DIB3000MB_REG_LOCK2_VALUE
))) < 0 && as_count
++ < 100)
295 deb_setf("search_state after autosearch %d after %d checks\n",search_state
,as_count
);
297 if (search_state
== 1) {
298 struct dvb_frontend_parameters feps
;
299 if (dib3000mb_get_frontend(fe
, &feps
) == 0) {
300 deb_setf("reading tuning data from frontend succeeded.\n");
301 return dib3000mb_set_frontend(fe
, &feps
, 0);
306 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_CTRL
);
307 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
313 static int dib3000mb_fe_init(struct dvb_frontend
* fe
, int mobile_mode
)
315 struct dib3000_state
* state
= fe
->demodulator_priv
;
317 deb_info("dib3000mb is getting up.\n");
318 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_UP
);
320 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
);
322 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE
);
323 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE_RST
);
325 wr(DIB3000MB_REG_CLOCK
, DIB3000MB_CLOCK_DEFAULT
);
327 wr(DIB3000MB_REG_ELECT_OUT_MODE
, DIB3000MB_ELECT_OUT_MODE_ON
);
329 wr(DIB3000MB_REG_DDS_FREQ_MSB
, DIB3000MB_DDS_FREQ_MSB
);
330 wr(DIB3000MB_REG_DDS_FREQ_LSB
, DIB3000MB_DDS_FREQ_LSB
);
332 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
334 wr_foreach(dib3000mb_reg_impulse_noise
,
335 dib3000mb_impulse_noise_values
[DIB3000MB_IMPNOISE_OFF
]);
337 wr_foreach(dib3000mb_reg_agc_gain
, dib3000mb_default_agc_gain
);
339 wr(DIB3000MB_REG_PHASE_NOISE
, DIB3000MB_PHASE_NOISE_DEFAULT
);
341 wr_foreach(dib3000mb_reg_phase_noise
, dib3000mb_default_noise_phase
);
343 wr_foreach(dib3000mb_reg_lock_duration
, dib3000mb_default_lock_duration
);
345 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
347 wr(DIB3000MB_REG_LOCK0_MASK
, DIB3000MB_LOCK0_DEFAULT
);
348 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
349 wr(DIB3000MB_REG_LOCK2_MASK
, DIB3000MB_LOCK2_DEFAULT
);
350 wr(DIB3000MB_REG_SEQ
, dib3000_seq
[1][1][1]);
352 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
354 wr(DIB3000MB_REG_UNK_68
, DIB3000MB_UNK_68
);
355 wr(DIB3000MB_REG_UNK_69
, DIB3000MB_UNK_69
);
356 wr(DIB3000MB_REG_UNK_71
, DIB3000MB_UNK_71
);
357 wr(DIB3000MB_REG_UNK_77
, DIB3000MB_UNK_77
);
358 wr(DIB3000MB_REG_UNK_78
, DIB3000MB_UNK_78
);
359 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
360 wr(DIB3000MB_REG_UNK_92
, DIB3000MB_UNK_92
);
361 wr(DIB3000MB_REG_UNK_96
, DIB3000MB_UNK_96
);
362 wr(DIB3000MB_REG_UNK_97
, DIB3000MB_UNK_97
);
363 wr(DIB3000MB_REG_UNK_106
, DIB3000MB_UNK_106
);
364 wr(DIB3000MB_REG_UNK_107
, DIB3000MB_UNK_107
);
365 wr(DIB3000MB_REG_UNK_108
, DIB3000MB_UNK_108
);
366 wr(DIB3000MB_REG_UNK_122
, DIB3000MB_UNK_122
);
367 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
368 wr(DIB3000MB_REG_BERLEN
, DIB3000MB_BERLEN_DEFAULT
);
370 wr_foreach(dib3000mb_reg_filter_coeffs
, dib3000mb_filter_coeffs
);
372 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_ON
);
373 wr(DIB3000MB_REG_MULTI_DEMOD_MSB
, DIB3000MB_MULTI_DEMOD_MSB
);
374 wr(DIB3000MB_REG_MULTI_DEMOD_LSB
, DIB3000MB_MULTI_DEMOD_LSB
);
376 wr(DIB3000MB_REG_OUTPUT_MODE
, DIB3000MB_OUTPUT_MODE_SLAVE
);
378 wr(DIB3000MB_REG_FIFO_142
, DIB3000MB_FIFO_142
);
379 wr(DIB3000MB_REG_MPEG2_OUT_MODE
, DIB3000MB_MPEG2_OUT_MODE_188
);
380 wr(DIB3000MB_REG_PID_PARSE
, DIB3000MB_PID_PARSE_ACTIVATE
);
381 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
382 wr(DIB3000MB_REG_FIFO_146
, DIB3000MB_FIFO_146
);
383 wr(DIB3000MB_REG_FIFO_147
, DIB3000MB_FIFO_147
);
385 wr(DIB3000MB_REG_DATA_IN_DIVERSITY
, DIB3000MB_DATA_DIVERSITY_IN_OFF
);
387 if (state
->config
.pll_init
)
388 state
->config
.pll_init(fe
);
393 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
394 struct dvb_frontend_parameters
*fep
)
396 struct dib3000_state
* state
= fe
->demodulator_priv
;
397 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
400 int inv_test1
,inv_test2
;
401 u32 dds_val
, threshold
= 0x800000;
403 if (!rd(DIB3000MB_REG_TPS_LOCK
))
406 dds_val
= ((rd(DIB3000MB_REG_DDS_VALUE_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB
);
407 deb_getf("DDS_VAL: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_VALUE_MSB
), rd(DIB3000MB_REG_DDS_VALUE_LSB
));
408 if (dds_val
< threshold
)
410 else if (dds_val
== threshold
)
415 dds_val
= ((rd(DIB3000MB_REG_DDS_FREQ_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB
);
416 deb_getf("DDS_FREQ: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_FREQ_MSB
), rd(DIB3000MB_REG_DDS_FREQ_LSB
));
417 if (dds_val
< threshold
)
419 else if (dds_val
== threshold
)
425 ((inv_test2
== 2) && (inv_test1
==1 || inv_test1
==0)) ||
426 ((inv_test2
== 0) && (inv_test1
==1 || inv_test1
==2)) ?
427 INVERSION_ON
: INVERSION_OFF
;
429 deb_getf("inversion %d %d, %d\n", inv_test2
, inv_test1
, fep
->inversion
);
431 switch ((tps_val
= rd(DIB3000MB_REG_TPS_QAM
))) {
432 case DIB3000_CONSTELLATION_QPSK
:
434 ofdm
->constellation
= QPSK
;
436 case DIB3000_CONSTELLATION_16QAM
:
438 ofdm
->constellation
= QAM_16
;
440 case DIB3000_CONSTELLATION_64QAM
:
442 ofdm
->constellation
= QAM_64
;
445 err("Unexpected constellation returned by TPS (%d)", tps_val
);
448 deb_getf("TPS: %d\n", tps_val
);
450 if (rd(DIB3000MB_REG_TPS_HRCH
)) {
451 deb_getf("HRCH ON\n");
452 cr
= &ofdm
->code_rate_LP
;
453 ofdm
->code_rate_HP
= FEC_NONE
;
454 switch ((tps_val
= rd(DIB3000MB_REG_TPS_VIT_ALPHA
))) {
455 case DIB3000_ALPHA_0
:
456 deb_getf("HIERARCHY_NONE ");
457 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
459 case DIB3000_ALPHA_1
:
460 deb_getf("HIERARCHY_1 ");
461 ofdm
->hierarchy_information
= HIERARCHY_1
;
463 case DIB3000_ALPHA_2
:
464 deb_getf("HIERARCHY_2 ");
465 ofdm
->hierarchy_information
= HIERARCHY_2
;
467 case DIB3000_ALPHA_4
:
468 deb_getf("HIERARCHY_4 ");
469 ofdm
->hierarchy_information
= HIERARCHY_4
;
472 err("Unexpected ALPHA value returned by TPS (%d)", tps_val
);
475 deb_getf("TPS: %d\n", tps_val
);
477 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_LP
);
479 deb_getf("HRCH OFF\n");
480 cr
= &ofdm
->code_rate_HP
;
481 ofdm
->code_rate_LP
= FEC_NONE
;
482 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
484 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_HP
);
488 case DIB3000_FEC_1_2
:
489 deb_getf("FEC_1_2 ");
492 case DIB3000_FEC_2_3
:
493 deb_getf("FEC_2_3 ");
496 case DIB3000_FEC_3_4
:
497 deb_getf("FEC_3_4 ");
500 case DIB3000_FEC_5_6
:
501 deb_getf("FEC_5_6 ");
504 case DIB3000_FEC_7_8
:
505 deb_getf("FEC_7_8 ");
509 err("Unexpected FEC returned by TPS (%d)", tps_val
);
512 deb_getf("TPS: %d\n",tps_val
);
514 switch ((tps_val
= rd(DIB3000MB_REG_TPS_GUARD_TIME
))) {
515 case DIB3000_GUARD_TIME_1_32
:
516 deb_getf("GUARD_INTERVAL_1_32 ");
517 ofdm
->guard_interval
= GUARD_INTERVAL_1_32
;
519 case DIB3000_GUARD_TIME_1_16
:
520 deb_getf("GUARD_INTERVAL_1_16 ");
521 ofdm
->guard_interval
= GUARD_INTERVAL_1_16
;
523 case DIB3000_GUARD_TIME_1_8
:
524 deb_getf("GUARD_INTERVAL_1_8 ");
525 ofdm
->guard_interval
= GUARD_INTERVAL_1_8
;
527 case DIB3000_GUARD_TIME_1_4
:
528 deb_getf("GUARD_INTERVAL_1_4 ");
529 ofdm
->guard_interval
= GUARD_INTERVAL_1_4
;
532 err("Unexpected Guard Time returned by TPS (%d)", tps_val
);
535 deb_getf("TPS: %d\n", tps_val
);
537 switch ((tps_val
= rd(DIB3000MB_REG_TPS_FFT
))) {
538 case DIB3000_TRANSMISSION_MODE_2K
:
539 deb_getf("TRANSMISSION_MODE_2K ");
540 ofdm
->transmission_mode
= TRANSMISSION_MODE_2K
;
542 case DIB3000_TRANSMISSION_MODE_8K
:
543 deb_getf("TRANSMISSION_MODE_8K ");
544 ofdm
->transmission_mode
= TRANSMISSION_MODE_8K
;
547 err("unexpected transmission mode return by TPS (%d)", tps_val
);
550 deb_getf("TPS: %d\n", tps_val
);
555 static int dib3000mb_read_status(struct dvb_frontend
* fe
, fe_status_t
*stat
)
557 struct dib3000_state
* state
= fe
->demodulator_priv
;
561 if (rd(DIB3000MB_REG_AGC_LOCK
))
562 *stat
|= FE_HAS_SIGNAL
;
563 if (rd(DIB3000MB_REG_CARRIER_LOCK
))
564 *stat
|= FE_HAS_CARRIER
;
565 if (rd(DIB3000MB_REG_VIT_LCK
))
566 *stat
|= FE_HAS_VITERBI
;
567 if (rd(DIB3000MB_REG_TS_SYNC_LOCK
))
568 *stat
|= (FE_HAS_SYNC
| FE_HAS_LOCK
);
570 deb_getf("actual status is %2x\n",*stat
);
572 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
573 rd(DIB3000MB_REG_TPS_LOCK
),
574 rd(DIB3000MB_REG_TPS_QAM
),
575 rd(DIB3000MB_REG_TPS_HRCH
),
576 rd(DIB3000MB_REG_TPS_VIT_ALPHA
),
577 rd(DIB3000MB_REG_TPS_CODE_RATE_HP
),
578 rd(DIB3000MB_REG_TPS_CODE_RATE_LP
),
579 rd(DIB3000MB_REG_TPS_GUARD_TIME
),
580 rd(DIB3000MB_REG_TPS_FFT
),
581 rd(DIB3000MB_REG_TPS_CELL_ID
));
583 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
587 static int dib3000mb_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
589 struct dib3000_state
* state
= fe
->demodulator_priv
;
591 *ber
= ((rd(DIB3000MB_REG_BER_MSB
) << 16) | rd(DIB3000MB_REG_BER_LSB
));
595 /* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
596 static int dib3000mb_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
598 struct dib3000_state
* state
= fe
->demodulator_priv
;
600 *strength
= rd(DIB3000MB_REG_SIGNAL_POWER
) * 0xffff / 0x170;
604 static int dib3000mb_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
606 struct dib3000_state
* state
= fe
->demodulator_priv
;
607 short sigpow
= rd(DIB3000MB_REG_SIGNAL_POWER
);
608 int icipow
= ((rd(DIB3000MB_REG_NOISE_POWER_MSB
) & 0xff) << 16) |
609 rd(DIB3000MB_REG_NOISE_POWER_LSB
);
610 *snr
= (sigpow
<< 8) / ((icipow
> 0) ? icipow
: 1);
614 static int dib3000mb_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
616 struct dib3000_state
* state
= fe
->demodulator_priv
;
618 *unc
= rd(DIB3000MB_REG_PACKET_ERROR_RATE
);
622 static int dib3000mb_sleep(struct dvb_frontend
* fe
)
624 struct dib3000_state
* state
= fe
->demodulator_priv
;
625 deb_info("dib3000mb is going to bed.\n");
626 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_DOWN
);
630 static int dib3000mb_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
632 tune
->min_delay_ms
= 800;
636 static int dib3000mb_fe_init_nonmobile(struct dvb_frontend
* fe
)
638 return dib3000mb_fe_init(fe
, 0);
641 static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*fep
)
643 return dib3000mb_set_frontend(fe
, fep
, 1);
646 static void dib3000mb_release(struct dvb_frontend
* fe
)
648 struct dib3000_state
*state
= fe
->demodulator_priv
;
652 /* pid filter and transfer stuff */
653 static int dib3000mb_pid_control(struct dvb_frontend
*fe
,int index
, int pid
,int onoff
)
655 struct dib3000_state
*state
= fe
->demodulator_priv
;
656 pid
= (onoff
? pid
| DIB3000_ACTIVATE_PID_FILTERING
: 0);
657 wr(index
+DIB3000MB_REG_FIRST_PID
,pid
);
661 static int dib3000mb_fifo_control(struct dvb_frontend
*fe
, int onoff
)
663 struct dib3000_state
*state
= fe
->demodulator_priv
;
665 deb_xfer("%s fifo\n",onoff
? "enabling" : "disabling");
667 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_ACTIVATE
);
669 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
674 static int dib3000mb_pid_parse(struct dvb_frontend
*fe
, int onoff
)
676 struct dib3000_state
*state
= fe
->demodulator_priv
;
677 deb_xfer("%s pid parsing\n",onoff
? "enabling" : "disabling");
678 wr(DIB3000MB_REG_PID_PARSE
,onoff
);
682 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend
*fe
, int onoff
, u8 pll_addr
)
684 struct dib3000_state
*state
= fe
->demodulator_priv
;
686 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_ENABLE(pll_addr
));
688 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_DISABLE(pll_addr
));
693 static struct dvb_frontend_ops dib3000mb_ops
;
695 struct dvb_frontend
* dib3000mb_attach(const struct dib3000_config
* config
,
696 struct i2c_adapter
* i2c
, struct dib_fe_xfer_ops
*xfer_ops
)
698 struct dib3000_state
* state
= NULL
;
700 /* allocate memory for the internal state */
701 state
= kmalloc(sizeof(struct dib3000_state
), GFP_KERNEL
);
704 memset(state
,0,sizeof(struct dib3000_state
));
706 /* setup the state */
708 memcpy(&state
->config
,config
,sizeof(struct dib3000_config
));
709 memcpy(&state
->ops
, &dib3000mb_ops
, sizeof(struct dvb_frontend_ops
));
711 /* check for the correct demod */
712 if (rd(DIB3000_REG_MANUFACTOR_ID
) != DIB3000_I2C_ID_DIBCOM
)
715 if (rd(DIB3000_REG_DEVICE_ID
) != DIB3000MB_DEVICE_ID
)
718 /* create dvb_frontend */
719 state
->frontend
.ops
= &state
->ops
;
720 state
->frontend
.demodulator_priv
= state
;
722 /* set the xfer operations */
723 xfer_ops
->pid_parse
= dib3000mb_pid_parse
;
724 xfer_ops
->fifo_ctrl
= dib3000mb_fifo_control
;
725 xfer_ops
->pid_ctrl
= dib3000mb_pid_control
;
726 xfer_ops
->tuner_pass_ctrl
= dib3000mb_tuner_pass_ctrl
;
728 return &state
->frontend
;
735 static struct dvb_frontend_ops dib3000mb_ops
= {
738 .name
= "DiBcom 3000M-B DVB-T",
740 .frequency_min
= 44250000,
741 .frequency_max
= 867250000,
742 .frequency_stepsize
= 62500,
743 .caps
= FE_CAN_INVERSION_AUTO
|
744 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
745 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
746 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
747 FE_CAN_TRANSMISSION_MODE_AUTO
|
748 FE_CAN_GUARD_INTERVAL_AUTO
|
750 FE_CAN_HIERARCHY_AUTO
,
753 .release
= dib3000mb_release
,
755 .init
= dib3000mb_fe_init_nonmobile
,
756 .sleep
= dib3000mb_sleep
,
758 .set_frontend
= dib3000mb_set_frontend_and_tuner
,
759 .get_frontend
= dib3000mb_get_frontend
,
760 .get_tune_settings
= dib3000mb_fe_get_tune_settings
,
762 .read_status
= dib3000mb_read_status
,
763 .read_ber
= dib3000mb_read_ber
,
764 .read_signal_strength
= dib3000mb_read_signal_strength
,
765 .read_snr
= dib3000mb_read_snr
,
766 .read_ucblocks
= dib3000mb_read_unc_blocks
,
769 MODULE_AUTHOR(DRIVER_AUTHOR
);
770 MODULE_DESCRIPTION(DRIVER_DESC
);
771 MODULE_LICENSE("GPL");
773 EXPORT_SYMBOL(dib3000mb_attach
);