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/version.h>
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/init.h>
30 #include <linux/delay.h>
32 #include "dib3000-common.h"
33 #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_xfer(args...) dprintk(0x02,args)
48 #define deb_setf(args...) dprintk(0x04,args)
49 #define deb_getf(args...) dprintk(0x08,args)
51 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend
*fe
, int onoff
, u8 pll_addr
);
53 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
54 struct dvb_frontend_parameters
*fep
);
56 static int dib3000mb_set_frontend(struct dvb_frontend
* fe
,
57 struct dvb_frontend_parameters
*fep
, int tuner
)
59 struct dib3000_state
* state
= fe
->demodulator_priv
;
60 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
61 fe_code_rate_t fe_cr
= FEC_NONE
;
62 int search_state
, seq
;
64 if (tuner
&& state
->config
.pll_addr
&& state
->config
.pll_set
) {
65 dib3000mb_tuner_pass_ctrl(fe
,1,state
->config
.pll_addr(fe
));
66 state
->config
.pll_set(fe
, fep
, NULL
);
67 dib3000mb_tuner_pass_ctrl(fe
,0,state
->config
.pll_addr(fe
));
69 deb_setf("bandwidth: ");
70 switch (ofdm
->bandwidth
) {
73 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
74 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
78 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[1]);
79 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_7mhz
);
83 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[0]);
84 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_6mhz
);
89 err("unkown bandwidth value.");
93 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
95 deb_setf("transmission mode: ");
96 switch (ofdm
->transmission_mode
) {
97 case TRANSMISSION_MODE_2K
:
99 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_2K
);
101 case TRANSMISSION_MODE_8K
:
103 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_8K
);
105 case TRANSMISSION_MODE_AUTO
:
113 switch (ofdm
->guard_interval
) {
114 case GUARD_INTERVAL_1_32
:
116 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_32
);
118 case GUARD_INTERVAL_1_16
:
120 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_16
);
122 case GUARD_INTERVAL_1_8
:
124 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_8
);
126 case GUARD_INTERVAL_1_4
:
128 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_4
);
130 case GUARD_INTERVAL_AUTO
:
137 deb_setf("inversion: ");
138 switch (fep
->inversion
) {
141 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_OFF
);
148 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_ON
);
154 deb_setf("constellation: ");
155 switch (ofdm
->constellation
) {
158 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_QPSK
);
162 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_16QAM
);
166 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_64QAM
);
173 deb_setf("hierachy: ");
174 switch (ofdm
->hierarchy_information
) {
179 deb_setf("alpha=1\n");
180 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_1
);
183 deb_setf("alpha=2\n");
184 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_2
);
187 deb_setf("alpha=4\n");
188 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_4
);
191 deb_setf("alpha=auto\n");
197 deb_setf("hierarchy: ");
198 if (ofdm
->hierarchy_information
== HIERARCHY_NONE
) {
200 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_OFF
);
201 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_HP
);
202 fe_cr
= ofdm
->code_rate_HP
;
203 } else if (ofdm
->hierarchy_information
!= HIERARCHY_AUTO
) {
205 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_ON
);
206 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_LP
);
207 fe_cr
= ofdm
->code_rate_LP
;
213 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_1_2
);
217 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_2_3
);
221 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_3_4
);
225 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_5_6
);
229 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_7_8
);
242 [ofdm
->transmission_mode
== TRANSMISSION_MODE_AUTO
]
243 [ofdm
->guard_interval
== GUARD_INTERVAL_AUTO
]
244 [fep
->inversion
== INVERSION_AUTO
];
246 deb_setf("seq? %d\n", seq
);
248 wr(DIB3000MB_REG_SEQ
, seq
);
250 wr(DIB3000MB_REG_ISI
, seq
? DIB3000MB_ISI_INHIBIT
: DIB3000MB_ISI_ACTIVATE
);
252 if (ofdm
->transmission_mode
== TRANSMISSION_MODE_2K
) {
253 if (ofdm
->guard_interval
== GUARD_INTERVAL_1_8
) {
254 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_2K_1_8
);
256 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_DEFAULT
);
259 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_2K
);
261 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_DEFAULT
);
264 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_OFF
);
265 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
266 wr(DIB3000MB_REG_MOBILE_MODE
, DIB3000MB_MOBILE_MODE_OFF
);
268 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_high
);
270 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_ACTIVATE
);
272 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
+ DIB3000MB_RESTART_CTRL
);
273 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
275 /* wait for AGC lock */
278 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
280 /* something has to be auto searched */
281 if (ofdm
->constellation
== QAM_AUTO
||
282 ofdm
->hierarchy_information
== HIERARCHY_AUTO
||
284 fep
->inversion
== INVERSION_AUTO
) {
287 deb_setf("autosearch enabled.\n");
289 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
291 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AUTO_SEARCH
);
292 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
294 while ((search_state
=
295 dib3000_search_status(
296 rd(DIB3000MB_REG_AS_IRQ_PENDING
),
297 rd(DIB3000MB_REG_LOCK2_VALUE
))) < 0 && as_count
++ < 100)
300 deb_setf("search_state after autosearch %d after %d checks\n",search_state
,as_count
);
302 if (search_state
== 1) {
303 struct dvb_frontend_parameters feps
;
304 if (dib3000mb_get_frontend(fe
, &feps
) == 0) {
305 deb_setf("reading tuning data from frontend succeeded.\n");
306 return dib3000mb_set_frontend(fe
, &feps
, 0);
311 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_CTRL
);
312 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
318 static int dib3000mb_fe_init(struct dvb_frontend
* fe
, int mobile_mode
)
320 struct dib3000_state
* state
= fe
->demodulator_priv
;
322 deb_info("dib3000mb is getting up.\n");
323 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_UP
);
325 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
);
327 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE
);
328 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE_RST
);
330 wr(DIB3000MB_REG_CLOCK
, DIB3000MB_CLOCK_DEFAULT
);
332 wr(DIB3000MB_REG_ELECT_OUT_MODE
, DIB3000MB_ELECT_OUT_MODE_ON
);
334 wr(DIB3000MB_REG_DDS_FREQ_MSB
, DIB3000MB_DDS_FREQ_MSB
);
335 wr(DIB3000MB_REG_DDS_FREQ_LSB
, DIB3000MB_DDS_FREQ_LSB
);
337 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
339 wr_foreach(dib3000mb_reg_impulse_noise
,
340 dib3000mb_impulse_noise_values
[DIB3000MB_IMPNOISE_OFF
]);
342 wr_foreach(dib3000mb_reg_agc_gain
, dib3000mb_default_agc_gain
);
344 wr(DIB3000MB_REG_PHASE_NOISE
, DIB3000MB_PHASE_NOISE_DEFAULT
);
346 wr_foreach(dib3000mb_reg_phase_noise
, dib3000mb_default_noise_phase
);
348 wr_foreach(dib3000mb_reg_lock_duration
, dib3000mb_default_lock_duration
);
350 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
352 wr(DIB3000MB_REG_LOCK0_MASK
, DIB3000MB_LOCK0_DEFAULT
);
353 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
354 wr(DIB3000MB_REG_LOCK2_MASK
, DIB3000MB_LOCK2_DEFAULT
);
355 wr(DIB3000MB_REG_SEQ
, dib3000_seq
[1][1][1]);
357 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
359 wr(DIB3000MB_REG_UNK_68
, DIB3000MB_UNK_68
);
360 wr(DIB3000MB_REG_UNK_69
, DIB3000MB_UNK_69
);
361 wr(DIB3000MB_REG_UNK_71
, DIB3000MB_UNK_71
);
362 wr(DIB3000MB_REG_UNK_77
, DIB3000MB_UNK_77
);
363 wr(DIB3000MB_REG_UNK_78
, DIB3000MB_UNK_78
);
364 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
365 wr(DIB3000MB_REG_UNK_92
, DIB3000MB_UNK_92
);
366 wr(DIB3000MB_REG_UNK_96
, DIB3000MB_UNK_96
);
367 wr(DIB3000MB_REG_UNK_97
, DIB3000MB_UNK_97
);
368 wr(DIB3000MB_REG_UNK_106
, DIB3000MB_UNK_106
);
369 wr(DIB3000MB_REG_UNK_107
, DIB3000MB_UNK_107
);
370 wr(DIB3000MB_REG_UNK_108
, DIB3000MB_UNK_108
);
371 wr(DIB3000MB_REG_UNK_122
, DIB3000MB_UNK_122
);
372 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
373 wr(DIB3000MB_REG_BERLEN
, DIB3000MB_BERLEN_DEFAULT
);
375 wr_foreach(dib3000mb_reg_filter_coeffs
, dib3000mb_filter_coeffs
);
377 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_ON
);
378 wr(DIB3000MB_REG_MULTI_DEMOD_MSB
, DIB3000MB_MULTI_DEMOD_MSB
);
379 wr(DIB3000MB_REG_MULTI_DEMOD_LSB
, DIB3000MB_MULTI_DEMOD_LSB
);
381 wr(DIB3000MB_REG_OUTPUT_MODE
, DIB3000MB_OUTPUT_MODE_SLAVE
);
383 wr(DIB3000MB_REG_FIFO_142
, DIB3000MB_FIFO_142
);
384 wr(DIB3000MB_REG_MPEG2_OUT_MODE
, DIB3000MB_MPEG2_OUT_MODE_188
);
385 wr(DIB3000MB_REG_PID_PARSE
, DIB3000MB_PID_PARSE_ACTIVATE
);
386 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
387 wr(DIB3000MB_REG_FIFO_146
, DIB3000MB_FIFO_146
);
388 wr(DIB3000MB_REG_FIFO_147
, DIB3000MB_FIFO_147
);
390 wr(DIB3000MB_REG_DATA_IN_DIVERSITY
, DIB3000MB_DATA_DIVERSITY_IN_OFF
);
392 if (state
->config
.pll_init
) {
393 dib3000mb_tuner_pass_ctrl(fe
,1,state
->config
.pll_addr(fe
));
394 state
->config
.pll_init(fe
,NULL
);
395 dib3000mb_tuner_pass_ctrl(fe
,0,state
->config
.pll_addr(fe
));
401 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
402 struct dvb_frontend_parameters
*fep
)
404 struct dib3000_state
* state
= fe
->demodulator_priv
;
405 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
408 int inv_test1
,inv_test2
;
409 u32 dds_val
, threshold
= 0x800000;
411 if (!rd(DIB3000MB_REG_TPS_LOCK
))
414 dds_val
= ((rd(DIB3000MB_REG_DDS_VALUE_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB
);
415 deb_getf("DDS_VAL: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_VALUE_MSB
), rd(DIB3000MB_REG_DDS_VALUE_LSB
));
416 if (dds_val
< threshold
)
418 else if (dds_val
== threshold
)
423 dds_val
= ((rd(DIB3000MB_REG_DDS_FREQ_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB
);
424 deb_getf("DDS_FREQ: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_FREQ_MSB
), rd(DIB3000MB_REG_DDS_FREQ_LSB
));
425 if (dds_val
< threshold
)
427 else if (dds_val
== threshold
)
433 ((inv_test2
== 2) && (inv_test1
==1 || inv_test1
==0)) ||
434 ((inv_test2
== 0) && (inv_test1
==1 || inv_test1
==2)) ?
435 INVERSION_ON
: INVERSION_OFF
;
437 deb_getf("inversion %d %d, %d\n", inv_test2
, inv_test1
, fep
->inversion
);
439 switch ((tps_val
= rd(DIB3000MB_REG_TPS_QAM
))) {
440 case DIB3000_CONSTELLATION_QPSK
:
442 ofdm
->constellation
= QPSK
;
444 case DIB3000_CONSTELLATION_16QAM
:
446 ofdm
->constellation
= QAM_16
;
448 case DIB3000_CONSTELLATION_64QAM
:
450 ofdm
->constellation
= QAM_64
;
453 err("Unexpected constellation returned by TPS (%d)", tps_val
);
456 deb_getf("TPS: %d\n", tps_val
);
458 if (rd(DIB3000MB_REG_TPS_HRCH
)) {
459 deb_getf("HRCH ON\n");
460 cr
= &ofdm
->code_rate_LP
;
461 ofdm
->code_rate_HP
= FEC_NONE
;
462 switch ((tps_val
= rd(DIB3000MB_REG_TPS_VIT_ALPHA
))) {
463 case DIB3000_ALPHA_0
:
464 deb_getf("HIERARCHY_NONE ");
465 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
467 case DIB3000_ALPHA_1
:
468 deb_getf("HIERARCHY_1 ");
469 ofdm
->hierarchy_information
= HIERARCHY_1
;
471 case DIB3000_ALPHA_2
:
472 deb_getf("HIERARCHY_2 ");
473 ofdm
->hierarchy_information
= HIERARCHY_2
;
475 case DIB3000_ALPHA_4
:
476 deb_getf("HIERARCHY_4 ");
477 ofdm
->hierarchy_information
= HIERARCHY_4
;
480 err("Unexpected ALPHA value returned by TPS (%d)", tps_val
);
483 deb_getf("TPS: %d\n", tps_val
);
485 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_LP
);
487 deb_getf("HRCH OFF\n");
488 cr
= &ofdm
->code_rate_HP
;
489 ofdm
->code_rate_LP
= FEC_NONE
;
490 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
492 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_HP
);
496 case DIB3000_FEC_1_2
:
497 deb_getf("FEC_1_2 ");
500 case DIB3000_FEC_2_3
:
501 deb_getf("FEC_2_3 ");
504 case DIB3000_FEC_3_4
:
505 deb_getf("FEC_3_4 ");
508 case DIB3000_FEC_5_6
:
509 deb_getf("FEC_5_6 ");
512 case DIB3000_FEC_7_8
:
513 deb_getf("FEC_7_8 ");
517 err("Unexpected FEC returned by TPS (%d)", tps_val
);
520 deb_getf("TPS: %d\n",tps_val
);
522 switch ((tps_val
= rd(DIB3000MB_REG_TPS_GUARD_TIME
))) {
523 case DIB3000_GUARD_TIME_1_32
:
524 deb_getf("GUARD_INTERVAL_1_32 ");
525 ofdm
->guard_interval
= GUARD_INTERVAL_1_32
;
527 case DIB3000_GUARD_TIME_1_16
:
528 deb_getf("GUARD_INTERVAL_1_16 ");
529 ofdm
->guard_interval
= GUARD_INTERVAL_1_16
;
531 case DIB3000_GUARD_TIME_1_8
:
532 deb_getf("GUARD_INTERVAL_1_8 ");
533 ofdm
->guard_interval
= GUARD_INTERVAL_1_8
;
535 case DIB3000_GUARD_TIME_1_4
:
536 deb_getf("GUARD_INTERVAL_1_4 ");
537 ofdm
->guard_interval
= GUARD_INTERVAL_1_4
;
540 err("Unexpected Guard Time returned by TPS (%d)", tps_val
);
543 deb_getf("TPS: %d\n", tps_val
);
545 switch ((tps_val
= rd(DIB3000MB_REG_TPS_FFT
))) {
546 case DIB3000_TRANSMISSION_MODE_2K
:
547 deb_getf("TRANSMISSION_MODE_2K ");
548 ofdm
->transmission_mode
= TRANSMISSION_MODE_2K
;
550 case DIB3000_TRANSMISSION_MODE_8K
:
551 deb_getf("TRANSMISSION_MODE_8K ");
552 ofdm
->transmission_mode
= TRANSMISSION_MODE_8K
;
555 err("unexpected transmission mode return by TPS (%d)", tps_val
);
558 deb_getf("TPS: %d\n", tps_val
);
563 static int dib3000mb_read_status(struct dvb_frontend
* fe
, fe_status_t
*stat
)
565 struct dib3000_state
* state
= fe
->demodulator_priv
;
569 if (rd(DIB3000MB_REG_AGC_LOCK
))
570 *stat
|= FE_HAS_SIGNAL
;
571 if (rd(DIB3000MB_REG_CARRIER_LOCK
))
572 *stat
|= FE_HAS_CARRIER
;
573 if (rd(DIB3000MB_REG_VIT_LCK
))
574 *stat
|= FE_HAS_VITERBI
;
575 if (rd(DIB3000MB_REG_TS_SYNC_LOCK
))
576 *stat
|= (FE_HAS_SYNC
| FE_HAS_LOCK
);
578 deb_getf("actual status is %2x\n",*stat
);
580 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
581 rd(DIB3000MB_REG_TPS_LOCK
),
582 rd(DIB3000MB_REG_TPS_QAM
),
583 rd(DIB3000MB_REG_TPS_HRCH
),
584 rd(DIB3000MB_REG_TPS_VIT_ALPHA
),
585 rd(DIB3000MB_REG_TPS_CODE_RATE_HP
),
586 rd(DIB3000MB_REG_TPS_CODE_RATE_LP
),
587 rd(DIB3000MB_REG_TPS_GUARD_TIME
),
588 rd(DIB3000MB_REG_TPS_FFT
),
589 rd(DIB3000MB_REG_TPS_CELL_ID
));
591 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
595 static int dib3000mb_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
597 struct dib3000_state
* state
= fe
->demodulator_priv
;
599 *ber
= ((rd(DIB3000MB_REG_BER_MSB
) << 16) | rd(DIB3000MB_REG_BER_LSB
));
603 /* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
604 static int dib3000mb_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
606 struct dib3000_state
* state
= fe
->demodulator_priv
;
608 *strength
= rd(DIB3000MB_REG_SIGNAL_POWER
) * 0xffff / 0x170;
612 static int dib3000mb_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
614 struct dib3000_state
* state
= fe
->demodulator_priv
;
615 short sigpow
= rd(DIB3000MB_REG_SIGNAL_POWER
);
616 int icipow
= ((rd(DIB3000MB_REG_NOISE_POWER_MSB
) & 0xff) << 16) |
617 rd(DIB3000MB_REG_NOISE_POWER_LSB
);
618 *snr
= (sigpow
<< 8) / ((icipow
> 0) ? icipow
: 1);
622 static int dib3000mb_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
624 struct dib3000_state
* state
= fe
->demodulator_priv
;
626 *unc
= rd(DIB3000MB_REG_UNC
);
630 static int dib3000mb_sleep(struct dvb_frontend
* fe
)
632 struct dib3000_state
* state
= fe
->demodulator_priv
;
633 deb_info("dib3000mb is going to bed.\n");
634 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_DOWN
);
638 static int dib3000mb_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
640 tune
->min_delay_ms
= 800;
641 tune
->step_size
= 166667;
642 tune
->max_drift
= 166667 * 2;
647 static int dib3000mb_fe_init_nonmobile(struct dvb_frontend
* fe
)
649 return dib3000mb_fe_init(fe
, 0);
652 static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*fep
)
654 return dib3000mb_set_frontend(fe
, fep
, 1);
657 static void dib3000mb_release(struct dvb_frontend
* fe
)
659 struct dib3000_state
*state
= fe
->demodulator_priv
;
663 /* pid filter and transfer stuff */
664 static int dib3000mb_pid_control(struct dvb_frontend
*fe
,int index
, int pid
,int onoff
)
666 struct dib3000_state
*state
= fe
->demodulator_priv
;
667 pid
= (onoff
? pid
| DIB3000_ACTIVATE_PID_FILTERING
: 0);
668 wr(index
+DIB3000MB_REG_FIRST_PID
,pid
);
672 static int dib3000mb_fifo_control(struct dvb_frontend
*fe
, int onoff
)
674 struct dib3000_state
*state
= fe
->demodulator_priv
;
676 deb_xfer("%s fifo\n",onoff
? "enabling" : "disabling");
678 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_ACTIVATE
);
680 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
685 static int dib3000mb_pid_parse(struct dvb_frontend
*fe
, int onoff
)
687 struct dib3000_state
*state
= fe
->demodulator_priv
;
688 deb_xfer("%s pid parsing\n",onoff
? "enabling" : "disabling");
689 wr(DIB3000MB_REG_PID_PARSE
,onoff
);
693 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend
*fe
, int onoff
, u8 pll_addr
)
695 struct dib3000_state
*state
= fe
->demodulator_priv
;
697 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_ENABLE(pll_addr
));
699 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_DISABLE(pll_addr
));
704 static struct dvb_frontend_ops dib3000mb_ops
;
706 struct dvb_frontend
* dib3000mb_attach(const struct dib3000_config
* config
,
707 struct i2c_adapter
* i2c
, struct dib_fe_xfer_ops
*xfer_ops
)
709 struct dib3000_state
* state
= NULL
;
711 /* allocate memory for the internal state */
712 state
= kmalloc(sizeof(struct dib3000_state
), GFP_KERNEL
);
715 memset(state
,0,sizeof(struct dib3000_state
));
717 /* setup the state */
719 memcpy(&state
->config
,config
,sizeof(struct dib3000_config
));
720 memcpy(&state
->ops
, &dib3000mb_ops
, sizeof(struct dvb_frontend_ops
));
722 /* check for the correct demod */
723 if (rd(DIB3000_REG_MANUFACTOR_ID
) != DIB3000_I2C_ID_DIBCOM
)
726 if (rd(DIB3000_REG_DEVICE_ID
) != DIB3000MB_DEVICE_ID
)
729 /* create dvb_frontend */
730 state
->frontend
.ops
= &state
->ops
;
731 state
->frontend
.demodulator_priv
= state
;
733 /* set the xfer operations */
734 xfer_ops
->pid_parse
= dib3000mb_pid_parse
;
735 xfer_ops
->fifo_ctrl
= dib3000mb_fifo_control
;
736 xfer_ops
->pid_ctrl
= dib3000mb_pid_control
;
737 xfer_ops
->tuner_pass_ctrl
= dib3000mb_tuner_pass_ctrl
;
739 return &state
->frontend
;
746 static struct dvb_frontend_ops dib3000mb_ops
= {
749 .name
= "DiBcom 3000M-B DVB-T",
751 .frequency_min
= 44250000,
752 .frequency_max
= 867250000,
753 .frequency_stepsize
= 62500,
754 .caps
= FE_CAN_INVERSION_AUTO
|
755 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
756 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
757 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
758 FE_CAN_TRANSMISSION_MODE_AUTO
|
759 FE_CAN_GUARD_INTERVAL_AUTO
|
761 FE_CAN_HIERARCHY_AUTO
,
764 .release
= dib3000mb_release
,
766 .init
= dib3000mb_fe_init_nonmobile
,
767 .sleep
= dib3000mb_sleep
,
769 .set_frontend
= dib3000mb_set_frontend_and_tuner
,
770 .get_frontend
= dib3000mb_get_frontend
,
771 .get_tune_settings
= dib3000mb_fe_get_tune_settings
,
773 .read_status
= dib3000mb_read_status
,
774 .read_ber
= dib3000mb_read_ber
,
775 .read_signal_strength
= dib3000mb_read_signal_strength
,
776 .read_snr
= dib3000mb_read_snr
,
777 .read_ucblocks
= dib3000mb_read_unc_blocks
,
780 MODULE_AUTHOR(DRIVER_AUTHOR
);
781 MODULE_DESCRIPTION(DRIVER_DESC
);
782 MODULE_LICENSE("GPL");
784 EXPORT_SYMBOL(dib3000mb_attach
);