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"
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
,
116 struct dvb_frontend_parameters
*fep
);
118 static int dib3000mb_set_frontend(struct dvb_frontend
* fe
,
119 struct dvb_frontend_parameters
*fep
, int tuner
)
121 struct dib3000_state
* state
= fe
->demodulator_priv
;
122 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
123 fe_code_rate_t fe_cr
= FEC_NONE
;
124 int search_state
, seq
;
126 if (tuner
&& fe
->ops
.tuner_ops
.set_params
) {
127 fe
->ops
.tuner_ops
.set_params(fe
, fep
);
128 if (fe
->ops
.i2c_gate_ctrl
) fe
->ops
.i2c_gate_ctrl(fe
, 0);
130 deb_setf("bandwidth: ");
131 switch (ofdm
->bandwidth
) {
132 case BANDWIDTH_8_MHZ
:
134 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
135 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
137 case BANDWIDTH_7_MHZ
:
139 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[1]);
140 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_7mhz
);
142 case BANDWIDTH_6_MHZ
:
144 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[0]);
145 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_6mhz
);
150 err("unknown bandwidth value.");
154 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
156 deb_setf("transmission mode: ");
157 switch (ofdm
->transmission_mode
) {
158 case TRANSMISSION_MODE_2K
:
160 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_2K
);
162 case TRANSMISSION_MODE_8K
:
164 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_8K
);
166 case TRANSMISSION_MODE_AUTO
:
174 switch (ofdm
->guard_interval
) {
175 case GUARD_INTERVAL_1_32
:
177 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_32
);
179 case GUARD_INTERVAL_1_16
:
181 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_16
);
183 case GUARD_INTERVAL_1_8
:
185 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_8
);
187 case GUARD_INTERVAL_1_4
:
189 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_4
);
191 case GUARD_INTERVAL_AUTO
:
198 deb_setf("inversion: ");
199 switch (fep
->inversion
) {
202 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_OFF
);
209 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_ON
);
215 deb_setf("constellation: ");
216 switch (ofdm
->constellation
) {
219 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_QPSK
);
223 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_16QAM
);
227 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_64QAM
);
234 deb_setf("hierarchy: ");
235 switch (ofdm
->hierarchy_information
) {
240 deb_setf("alpha=1\n");
241 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_1
);
244 deb_setf("alpha=2\n");
245 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_2
);
248 deb_setf("alpha=4\n");
249 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_4
);
252 deb_setf("alpha=auto\n");
258 deb_setf("hierarchy: ");
259 if (ofdm
->hierarchy_information
== HIERARCHY_NONE
) {
261 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_OFF
);
262 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_HP
);
263 fe_cr
= ofdm
->code_rate_HP
;
264 } else if (ofdm
->hierarchy_information
!= HIERARCHY_AUTO
) {
266 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_ON
);
267 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_LP
);
268 fe_cr
= ofdm
->code_rate_LP
;
274 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_1_2
);
278 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_2_3
);
282 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_3_4
);
286 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_5_6
);
290 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_7_8
);
303 [ofdm
->transmission_mode
== TRANSMISSION_MODE_AUTO
]
304 [ofdm
->guard_interval
== GUARD_INTERVAL_AUTO
]
305 [fep
->inversion
== INVERSION_AUTO
];
307 deb_setf("seq? %d\n", seq
);
309 wr(DIB3000MB_REG_SEQ
, seq
);
311 wr(DIB3000MB_REG_ISI
, seq
? DIB3000MB_ISI_INHIBIT
: DIB3000MB_ISI_ACTIVATE
);
313 if (ofdm
->transmission_mode
== TRANSMISSION_MODE_2K
) {
314 if (ofdm
->guard_interval
== GUARD_INTERVAL_1_8
) {
315 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_2K_1_8
);
317 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_DEFAULT
);
320 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_2K
);
322 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_DEFAULT
);
325 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_OFF
);
326 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
327 wr(DIB3000MB_REG_MOBILE_MODE
, DIB3000MB_MOBILE_MODE_OFF
);
329 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_high
);
331 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_ACTIVATE
);
333 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
+ DIB3000MB_RESTART_CTRL
);
334 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
336 /* wait for AGC lock */
339 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
341 /* something has to be auto searched */
342 if (ofdm
->constellation
== QAM_AUTO
||
343 ofdm
->hierarchy_information
== HIERARCHY_AUTO
||
345 fep
->inversion
== INVERSION_AUTO
) {
348 deb_setf("autosearch enabled.\n");
350 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
352 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AUTO_SEARCH
);
353 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
355 while ((search_state
=
356 dib3000_search_status(
357 rd(DIB3000MB_REG_AS_IRQ_PENDING
),
358 rd(DIB3000MB_REG_LOCK2_VALUE
))) < 0 && as_count
++ < 100)
361 deb_setf("search_state after autosearch %d after %d checks\n",search_state
,as_count
);
363 if (search_state
== 1) {
364 struct dvb_frontend_parameters feps
;
365 if (dib3000mb_get_frontend(fe
, &feps
) == 0) {
366 deb_setf("reading tuning data from frontend succeeded.\n");
367 return dib3000mb_set_frontend(fe
, &feps
, 0);
372 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_CTRL
);
373 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
379 static int dib3000mb_fe_init(struct dvb_frontend
* fe
, int mobile_mode
)
381 struct dib3000_state
* state
= fe
->demodulator_priv
;
383 deb_info("dib3000mb is getting up.\n");
384 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_UP
);
386 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
);
388 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE
);
389 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE_RST
);
391 wr(DIB3000MB_REG_CLOCK
, DIB3000MB_CLOCK_DEFAULT
);
393 wr(DIB3000MB_REG_ELECT_OUT_MODE
, DIB3000MB_ELECT_OUT_MODE_ON
);
395 wr(DIB3000MB_REG_DDS_FREQ_MSB
, DIB3000MB_DDS_FREQ_MSB
);
396 wr(DIB3000MB_REG_DDS_FREQ_LSB
, DIB3000MB_DDS_FREQ_LSB
);
398 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
400 wr_foreach(dib3000mb_reg_impulse_noise
,
401 dib3000mb_impulse_noise_values
[DIB3000MB_IMPNOISE_OFF
]);
403 wr_foreach(dib3000mb_reg_agc_gain
, dib3000mb_default_agc_gain
);
405 wr(DIB3000MB_REG_PHASE_NOISE
, DIB3000MB_PHASE_NOISE_DEFAULT
);
407 wr_foreach(dib3000mb_reg_phase_noise
, dib3000mb_default_noise_phase
);
409 wr_foreach(dib3000mb_reg_lock_duration
, dib3000mb_default_lock_duration
);
411 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
413 wr(DIB3000MB_REG_LOCK0_MASK
, DIB3000MB_LOCK0_DEFAULT
);
414 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
415 wr(DIB3000MB_REG_LOCK2_MASK
, DIB3000MB_LOCK2_DEFAULT
);
416 wr(DIB3000MB_REG_SEQ
, dib3000_seq
[1][1][1]);
418 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
420 wr(DIB3000MB_REG_UNK_68
, DIB3000MB_UNK_68
);
421 wr(DIB3000MB_REG_UNK_69
, DIB3000MB_UNK_69
);
422 wr(DIB3000MB_REG_UNK_71
, DIB3000MB_UNK_71
);
423 wr(DIB3000MB_REG_UNK_77
, DIB3000MB_UNK_77
);
424 wr(DIB3000MB_REG_UNK_78
, DIB3000MB_UNK_78
);
425 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
426 wr(DIB3000MB_REG_UNK_92
, DIB3000MB_UNK_92
);
427 wr(DIB3000MB_REG_UNK_96
, DIB3000MB_UNK_96
);
428 wr(DIB3000MB_REG_UNK_97
, DIB3000MB_UNK_97
);
429 wr(DIB3000MB_REG_UNK_106
, DIB3000MB_UNK_106
);
430 wr(DIB3000MB_REG_UNK_107
, DIB3000MB_UNK_107
);
431 wr(DIB3000MB_REG_UNK_108
, DIB3000MB_UNK_108
);
432 wr(DIB3000MB_REG_UNK_122
, DIB3000MB_UNK_122
);
433 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
434 wr(DIB3000MB_REG_BERLEN
, DIB3000MB_BERLEN_DEFAULT
);
436 wr_foreach(dib3000mb_reg_filter_coeffs
, dib3000mb_filter_coeffs
);
438 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_ON
);
439 wr(DIB3000MB_REG_MULTI_DEMOD_MSB
, DIB3000MB_MULTI_DEMOD_MSB
);
440 wr(DIB3000MB_REG_MULTI_DEMOD_LSB
, DIB3000MB_MULTI_DEMOD_LSB
);
442 wr(DIB3000MB_REG_OUTPUT_MODE
, DIB3000MB_OUTPUT_MODE_SLAVE
);
444 wr(DIB3000MB_REG_FIFO_142
, DIB3000MB_FIFO_142
);
445 wr(DIB3000MB_REG_MPEG2_OUT_MODE
, DIB3000MB_MPEG2_OUT_MODE_188
);
446 wr(DIB3000MB_REG_PID_PARSE
, DIB3000MB_PID_PARSE_ACTIVATE
);
447 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
448 wr(DIB3000MB_REG_FIFO_146
, DIB3000MB_FIFO_146
);
449 wr(DIB3000MB_REG_FIFO_147
, DIB3000MB_FIFO_147
);
451 wr(DIB3000MB_REG_DATA_IN_DIVERSITY
, DIB3000MB_DATA_DIVERSITY_IN_OFF
);
456 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
457 struct dvb_frontend_parameters
*fep
)
459 struct dib3000_state
* state
= fe
->demodulator_priv
;
460 struct dvb_ofdm_parameters
*ofdm
= &fep
->u
.ofdm
;
463 int inv_test1
,inv_test2
;
464 u32 dds_val
, threshold
= 0x800000;
466 if (!rd(DIB3000MB_REG_TPS_LOCK
))
469 dds_val
= ((rd(DIB3000MB_REG_DDS_VALUE_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB
);
470 deb_getf("DDS_VAL: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_VALUE_MSB
), rd(DIB3000MB_REG_DDS_VALUE_LSB
));
471 if (dds_val
< threshold
)
473 else if (dds_val
== threshold
)
478 dds_val
= ((rd(DIB3000MB_REG_DDS_FREQ_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB
);
479 deb_getf("DDS_FREQ: %x %x %x",dds_val
, rd(DIB3000MB_REG_DDS_FREQ_MSB
), rd(DIB3000MB_REG_DDS_FREQ_LSB
));
480 if (dds_val
< threshold
)
482 else if (dds_val
== threshold
)
488 ((inv_test2
== 2) && (inv_test1
==1 || inv_test1
==0)) ||
489 ((inv_test2
== 0) && (inv_test1
==1 || inv_test1
==2)) ?
490 INVERSION_ON
: INVERSION_OFF
;
492 deb_getf("inversion %d %d, %d\n", inv_test2
, inv_test1
, fep
->inversion
);
494 switch ((tps_val
= rd(DIB3000MB_REG_TPS_QAM
))) {
495 case DIB3000_CONSTELLATION_QPSK
:
497 ofdm
->constellation
= QPSK
;
499 case DIB3000_CONSTELLATION_16QAM
:
501 ofdm
->constellation
= QAM_16
;
503 case DIB3000_CONSTELLATION_64QAM
:
505 ofdm
->constellation
= QAM_64
;
508 err("Unexpected constellation returned by TPS (%d)", tps_val
);
511 deb_getf("TPS: %d\n", tps_val
);
513 if (rd(DIB3000MB_REG_TPS_HRCH
)) {
514 deb_getf("HRCH ON\n");
515 cr
= &ofdm
->code_rate_LP
;
516 ofdm
->code_rate_HP
= FEC_NONE
;
517 switch ((tps_val
= rd(DIB3000MB_REG_TPS_VIT_ALPHA
))) {
518 case DIB3000_ALPHA_0
:
519 deb_getf("HIERARCHY_NONE ");
520 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
522 case DIB3000_ALPHA_1
:
523 deb_getf("HIERARCHY_1 ");
524 ofdm
->hierarchy_information
= HIERARCHY_1
;
526 case DIB3000_ALPHA_2
:
527 deb_getf("HIERARCHY_2 ");
528 ofdm
->hierarchy_information
= HIERARCHY_2
;
530 case DIB3000_ALPHA_4
:
531 deb_getf("HIERARCHY_4 ");
532 ofdm
->hierarchy_information
= HIERARCHY_4
;
535 err("Unexpected ALPHA value returned by TPS (%d)", tps_val
);
538 deb_getf("TPS: %d\n", tps_val
);
540 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_LP
);
542 deb_getf("HRCH OFF\n");
543 cr
= &ofdm
->code_rate_HP
;
544 ofdm
->code_rate_LP
= FEC_NONE
;
545 ofdm
->hierarchy_information
= HIERARCHY_NONE
;
547 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_HP
);
551 case DIB3000_FEC_1_2
:
552 deb_getf("FEC_1_2 ");
555 case DIB3000_FEC_2_3
:
556 deb_getf("FEC_2_3 ");
559 case DIB3000_FEC_3_4
:
560 deb_getf("FEC_3_4 ");
563 case DIB3000_FEC_5_6
:
564 deb_getf("FEC_5_6 ");
567 case DIB3000_FEC_7_8
:
568 deb_getf("FEC_7_8 ");
572 err("Unexpected FEC returned by TPS (%d)", tps_val
);
575 deb_getf("TPS: %d\n",tps_val
);
577 switch ((tps_val
= rd(DIB3000MB_REG_TPS_GUARD_TIME
))) {
578 case DIB3000_GUARD_TIME_1_32
:
579 deb_getf("GUARD_INTERVAL_1_32 ");
580 ofdm
->guard_interval
= GUARD_INTERVAL_1_32
;
582 case DIB3000_GUARD_TIME_1_16
:
583 deb_getf("GUARD_INTERVAL_1_16 ");
584 ofdm
->guard_interval
= GUARD_INTERVAL_1_16
;
586 case DIB3000_GUARD_TIME_1_8
:
587 deb_getf("GUARD_INTERVAL_1_8 ");
588 ofdm
->guard_interval
= GUARD_INTERVAL_1_8
;
590 case DIB3000_GUARD_TIME_1_4
:
591 deb_getf("GUARD_INTERVAL_1_4 ");
592 ofdm
->guard_interval
= GUARD_INTERVAL_1_4
;
595 err("Unexpected Guard Time returned by TPS (%d)", tps_val
);
598 deb_getf("TPS: %d\n", tps_val
);
600 switch ((tps_val
= rd(DIB3000MB_REG_TPS_FFT
))) {
601 case DIB3000_TRANSMISSION_MODE_2K
:
602 deb_getf("TRANSMISSION_MODE_2K ");
603 ofdm
->transmission_mode
= TRANSMISSION_MODE_2K
;
605 case DIB3000_TRANSMISSION_MODE_8K
:
606 deb_getf("TRANSMISSION_MODE_8K ");
607 ofdm
->transmission_mode
= TRANSMISSION_MODE_8K
;
610 err("unexpected transmission mode return by TPS (%d)", tps_val
);
613 deb_getf("TPS: %d\n", tps_val
);
618 static int dib3000mb_read_status(struct dvb_frontend
* fe
, fe_status_t
*stat
)
620 struct dib3000_state
* state
= fe
->demodulator_priv
;
624 if (rd(DIB3000MB_REG_AGC_LOCK
))
625 *stat
|= FE_HAS_SIGNAL
;
626 if (rd(DIB3000MB_REG_CARRIER_LOCK
))
627 *stat
|= FE_HAS_CARRIER
;
628 if (rd(DIB3000MB_REG_VIT_LCK
))
629 *stat
|= FE_HAS_VITERBI
;
630 if (rd(DIB3000MB_REG_TS_SYNC_LOCK
))
631 *stat
|= (FE_HAS_SYNC
| FE_HAS_LOCK
);
633 deb_getf("actual status is %2x\n",*stat
);
635 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
636 rd(DIB3000MB_REG_TPS_LOCK
),
637 rd(DIB3000MB_REG_TPS_QAM
),
638 rd(DIB3000MB_REG_TPS_HRCH
),
639 rd(DIB3000MB_REG_TPS_VIT_ALPHA
),
640 rd(DIB3000MB_REG_TPS_CODE_RATE_HP
),
641 rd(DIB3000MB_REG_TPS_CODE_RATE_LP
),
642 rd(DIB3000MB_REG_TPS_GUARD_TIME
),
643 rd(DIB3000MB_REG_TPS_FFT
),
644 rd(DIB3000MB_REG_TPS_CELL_ID
));
646 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
650 static int dib3000mb_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
652 struct dib3000_state
* state
= fe
->demodulator_priv
;
654 *ber
= ((rd(DIB3000MB_REG_BER_MSB
) << 16) | rd(DIB3000MB_REG_BER_LSB
));
658 /* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
659 static int dib3000mb_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
661 struct dib3000_state
* state
= fe
->demodulator_priv
;
663 *strength
= rd(DIB3000MB_REG_SIGNAL_POWER
) * 0xffff / 0x170;
667 static int dib3000mb_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
669 struct dib3000_state
* state
= fe
->demodulator_priv
;
670 short sigpow
= rd(DIB3000MB_REG_SIGNAL_POWER
);
671 int icipow
= ((rd(DIB3000MB_REG_NOISE_POWER_MSB
) & 0xff) << 16) |
672 rd(DIB3000MB_REG_NOISE_POWER_LSB
);
673 *snr
= (sigpow
<< 8) / ((icipow
> 0) ? icipow
: 1);
677 static int dib3000mb_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
679 struct dib3000_state
* state
= fe
->demodulator_priv
;
681 *unc
= rd(DIB3000MB_REG_PACKET_ERROR_RATE
);
685 static int dib3000mb_sleep(struct dvb_frontend
* fe
)
687 struct dib3000_state
* state
= fe
->demodulator_priv
;
688 deb_info("dib3000mb is going to bed.\n");
689 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_DOWN
);
693 static int dib3000mb_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
695 tune
->min_delay_ms
= 800;
699 static int dib3000mb_fe_init_nonmobile(struct dvb_frontend
* fe
)
701 return dib3000mb_fe_init(fe
, 0);
704 static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*fep
)
706 return dib3000mb_set_frontend(fe
, fep
, 1);
709 static void dib3000mb_release(struct dvb_frontend
* fe
)
711 struct dib3000_state
*state
= fe
->demodulator_priv
;
715 /* pid filter and transfer stuff */
716 static int dib3000mb_pid_control(struct dvb_frontend
*fe
,int index
, int pid
,int onoff
)
718 struct dib3000_state
*state
= fe
->demodulator_priv
;
719 pid
= (onoff
? pid
| DIB3000_ACTIVATE_PID_FILTERING
: 0);
720 wr(index
+DIB3000MB_REG_FIRST_PID
,pid
);
724 static int dib3000mb_fifo_control(struct dvb_frontend
*fe
, int onoff
)
726 struct dib3000_state
*state
= fe
->demodulator_priv
;
728 deb_xfer("%s fifo\n",onoff
? "enabling" : "disabling");
730 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_ACTIVATE
);
732 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
737 static int dib3000mb_pid_parse(struct dvb_frontend
*fe
, int onoff
)
739 struct dib3000_state
*state
= fe
->demodulator_priv
;
740 deb_xfer("%s pid parsing\n",onoff
? "enabling" : "disabling");
741 wr(DIB3000MB_REG_PID_PARSE
,onoff
);
745 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend
*fe
, int onoff
, u8 pll_addr
)
747 struct dib3000_state
*state
= fe
->demodulator_priv
;
749 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_ENABLE(pll_addr
));
751 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_DISABLE(pll_addr
));
756 static struct dvb_frontend_ops dib3000mb_ops
;
758 struct dvb_frontend
* dib3000mb_attach(const struct dib3000_config
* config
,
759 struct i2c_adapter
* i2c
, struct dib_fe_xfer_ops
*xfer_ops
)
761 struct dib3000_state
* state
= NULL
;
763 /* allocate memory for the internal state */
764 state
= kzalloc(sizeof(struct dib3000_state
), GFP_KERNEL
);
768 /* setup the state */
770 memcpy(&state
->config
,config
,sizeof(struct dib3000_config
));
772 /* check for the correct demod */
773 if (rd(DIB3000_REG_MANUFACTOR_ID
) != DIB3000_I2C_ID_DIBCOM
)
776 if (rd(DIB3000_REG_DEVICE_ID
) != DIB3000MB_DEVICE_ID
)
779 /* create dvb_frontend */
780 memcpy(&state
->frontend
.ops
, &dib3000mb_ops
, sizeof(struct dvb_frontend_ops
));
781 state
->frontend
.demodulator_priv
= state
;
783 /* set the xfer operations */
784 xfer_ops
->pid_parse
= dib3000mb_pid_parse
;
785 xfer_ops
->fifo_ctrl
= dib3000mb_fifo_control
;
786 xfer_ops
->pid_ctrl
= dib3000mb_pid_control
;
787 xfer_ops
->tuner_pass_ctrl
= dib3000mb_tuner_pass_ctrl
;
789 return &state
->frontend
;
796 static struct dvb_frontend_ops dib3000mb_ops
= {
799 .name
= "DiBcom 3000M-B DVB-T",
801 .frequency_min
= 44250000,
802 .frequency_max
= 867250000,
803 .frequency_stepsize
= 62500,
804 .caps
= FE_CAN_INVERSION_AUTO
|
805 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
806 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
807 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
808 FE_CAN_TRANSMISSION_MODE_AUTO
|
809 FE_CAN_GUARD_INTERVAL_AUTO
|
811 FE_CAN_HIERARCHY_AUTO
,
814 .release
= dib3000mb_release
,
816 .init
= dib3000mb_fe_init_nonmobile
,
817 .sleep
= dib3000mb_sleep
,
819 .set_frontend
= dib3000mb_set_frontend_and_tuner
,
820 .get_frontend
= dib3000mb_get_frontend
,
821 .get_tune_settings
= dib3000mb_fe_get_tune_settings
,
823 .read_status
= dib3000mb_read_status
,
824 .read_ber
= dib3000mb_read_ber
,
825 .read_signal_strength
= dib3000mb_read_signal_strength
,
826 .read_snr
= dib3000mb_read_snr
,
827 .read_ucblocks
= dib3000mb_read_unc_blocks
,
830 MODULE_AUTHOR(DRIVER_AUTHOR
);
831 MODULE_DESCRIPTION(DRIVER_DESC
);
832 MODULE_LICENSE("GPL");
834 EXPORT_SYMBOL(dib3000mb_attach
);