1 // SPDX-License-Identifier: GPL-2.0-only
3 * Frontend driver for mobile DVB-T demodulator DiBcom 3000M-B
4 * DiBcom (http://www.dibcom.fr/)
6 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@posteo.de)
8 * based on GPL code from DibCom, which has
10 * Copyright (C) 2004 Amaury Demol for DiBcom
14 * Amaury Demol from DiBcom for providing specs and driver
15 * sources, on which this driver (and the dvb-dibusb) are based.
17 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
29 #include <media/dvb_frontend.h>
32 #include "dib3000mb_priv.h"
34 /* Version information */
35 #define DRIVER_VERSION "0.1"
36 #define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator"
37 #define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@posteo.de"
40 module_param(debug
, int, 0644);
41 MODULE_PARM_DESC(debug
, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
43 #define deb_info(args...) dprintk(0x01, args)
44 #define deb_i2c(args...) dprintk(0x02, args)
45 #define deb_srch(args...) dprintk(0x04, args)
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 dib3000_read_reg(struct dib3000_state
*state
, u16 reg
)
53 u8 wb
[] = { ((reg
>> 8) | 0x80) & 0xff, reg
& 0xff };
55 struct i2c_msg msg
[] = {
56 { .addr
= state
->config
.demod_address
, .flags
= 0, .buf
= wb
, .len
= 2 },
57 { .addr
= state
->config
.demod_address
, .flags
= I2C_M_RD
, .buf
= rb
, .len
= 2 },
60 if (i2c_transfer(state
->i2c
, msg
, 2) != 2)
61 deb_i2c("i2c read error\n");
63 deb_i2c("reading i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg
,reg
,
64 (rb
[0] << 8) | rb
[1],(rb
[0] << 8) | rb
[1]);
66 return (rb
[0] << 8) | rb
[1];
69 static int dib3000_write_reg(struct dib3000_state
*state
, u16 reg
, u16 val
)
72 (reg
>> 8) & 0xff, reg
& 0xff,
73 (val
>> 8) & 0xff, val
& 0xff,
75 struct i2c_msg msg
[] = {
76 { .addr
= state
->config
.demod_address
, .flags
= 0, .buf
= b
, .len
= 4 }
78 deb_i2c("writing i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg
,reg
,val
,val
);
80 return i2c_transfer(state
->i2c
,msg
, 1) != 1 ? -EREMOTEIO
: 0;
83 static int dib3000_search_status(u16 irq
,u16 lock
)
87 deb_srch("auto search succeeded\n");
88 return 1; // auto search succeeded
90 deb_srch("auto search not successful\n");
91 return 0; // auto search failed
93 } else if (irq
& 0x01) {
94 deb_srch("auto search failed\n");
95 return 0; // auto search failed
97 return -1; // try again
100 /* for auto search */
101 static u16 dib3000_seq
[2][2][2] = /* fft,gua, inv */
104 { 0, 1 }, /* 0 0 { 0,1 } */
105 { 3, 9 }, /* 0 1 { 0,1 } */
108 { 2, 5 }, /* 1 0 { 0,1 } */
109 { 6, 11 }, /* 1 1 { 0,1 } */
113 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
114 struct dtv_frontend_properties
*c
);
116 static int dib3000mb_set_frontend(struct dvb_frontend
*fe
, int tuner
)
118 struct dib3000_state
* state
= fe
->demodulator_priv
;
119 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
120 enum fe_code_rate fe_cr
= FEC_NONE
;
121 int search_state
, seq
;
123 if (tuner
&& fe
->ops
.tuner_ops
.set_params
) {
124 fe
->ops
.tuner_ops
.set_params(fe
);
125 if (fe
->ops
.i2c_gate_ctrl
) fe
->ops
.i2c_gate_ctrl(fe
, 0);
127 switch (c
->bandwidth_hz
) {
129 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
130 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
133 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[1]);
134 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_7mhz
);
137 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[0]);
138 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_6mhz
);
143 pr_err("unknown bandwidth value.\n");
146 deb_setf("bandwidth: %d MHZ\n", c
->bandwidth_hz
/ 1000000);
148 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
150 switch (c
->transmission_mode
) {
151 case TRANSMISSION_MODE_2K
:
152 deb_setf("transmission mode: 2k\n");
153 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_2K
);
155 case TRANSMISSION_MODE_8K
:
156 deb_setf("transmission mode: 8k\n");
157 wr(DIB3000MB_REG_FFT
, DIB3000_TRANSMISSION_MODE_8K
);
159 case TRANSMISSION_MODE_AUTO
:
160 deb_setf("transmission mode: auto\n");
166 switch (c
->guard_interval
) {
167 case GUARD_INTERVAL_1_32
:
168 deb_setf("guard 1_32\n");
169 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_32
);
171 case GUARD_INTERVAL_1_16
:
172 deb_setf("guard 1_16\n");
173 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_16
);
175 case GUARD_INTERVAL_1_8
:
176 deb_setf("guard 1_8\n");
177 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_8
);
179 case GUARD_INTERVAL_1_4
:
180 deb_setf("guard 1_4\n");
181 wr(DIB3000MB_REG_GUARD_TIME
, DIB3000_GUARD_TIME_1_4
);
183 case GUARD_INTERVAL_AUTO
:
184 deb_setf("guard auto\n");
190 switch (c
->inversion
) {
192 deb_setf("inversion off\n");
193 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_OFF
);
196 deb_setf("inversion auto\n");
199 deb_setf("inversion on\n");
200 wr(DIB3000MB_REG_DDS_INV
, DIB3000_DDS_INVERSION_ON
);
206 switch (c
->modulation
) {
208 deb_setf("modulation: qpsk\n");
209 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_QPSK
);
212 deb_setf("modulation: qam16\n");
213 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_16QAM
);
216 deb_setf("modulation: qam64\n");
217 wr(DIB3000MB_REG_QAM
, DIB3000_CONSTELLATION_64QAM
);
224 switch (c
->hierarchy
) {
226 deb_setf("hierarchy: none\n");
229 deb_setf("hierarchy: alpha=1\n");
230 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_1
);
233 deb_setf("hierarchy: alpha=2\n");
234 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_2
);
237 deb_setf("hierarchy: alpha=4\n");
238 wr(DIB3000MB_REG_VIT_ALPHA
, DIB3000_ALPHA_4
);
241 deb_setf("hierarchy: alpha=auto\n");
247 if (c
->hierarchy
== HIERARCHY_NONE
) {
248 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_OFF
);
249 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_HP
);
250 fe_cr
= c
->code_rate_HP
;
251 } else if (c
->hierarchy
!= HIERARCHY_AUTO
) {
252 wr(DIB3000MB_REG_VIT_HRCH
, DIB3000_HRCH_ON
);
253 wr(DIB3000MB_REG_VIT_HP
, DIB3000_SELECT_LP
);
254 fe_cr
= c
->code_rate_LP
;
258 deb_setf("fec: 1_2\n");
259 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_1_2
);
262 deb_setf("fec: 2_3\n");
263 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_2_3
);
266 deb_setf("fec: 3_4\n");
267 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_3_4
);
270 deb_setf("fec: 5_6\n");
271 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_5_6
);
274 deb_setf("fec: 7_8\n");
275 wr(DIB3000MB_REG_VIT_CODE_RATE
, DIB3000_FEC_7_8
);
278 deb_setf("fec: none\n");
281 deb_setf("fec: auto\n");
288 [c
->transmission_mode
== TRANSMISSION_MODE_AUTO
]
289 [c
->guard_interval
== GUARD_INTERVAL_AUTO
]
290 [c
->inversion
== INVERSION_AUTO
];
292 deb_setf("seq? %d\n", seq
);
294 wr(DIB3000MB_REG_SEQ
, seq
);
296 wr(DIB3000MB_REG_ISI
, seq
? DIB3000MB_ISI_INHIBIT
: DIB3000MB_ISI_ACTIVATE
);
298 if (c
->transmission_mode
== TRANSMISSION_MODE_2K
) {
299 if (c
->guard_interval
== GUARD_INTERVAL_1_8
) {
300 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_2K_1_8
);
302 wr(DIB3000MB_REG_SYNC_IMPROVEMENT
, DIB3000MB_SYNC_IMPROVE_DEFAULT
);
305 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_2K
);
307 wr(DIB3000MB_REG_UNK_121
, DIB3000MB_UNK_121_DEFAULT
);
310 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_OFF
);
311 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
312 wr(DIB3000MB_REG_MOBILE_MODE
, DIB3000MB_MOBILE_MODE_OFF
);
314 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_high
);
316 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_ACTIVATE
);
318 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
+ DIB3000MB_RESTART_CTRL
);
319 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
321 /* wait for AGC lock */
324 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
326 /* something has to be auto searched */
327 if (c
->modulation
== QAM_AUTO
||
328 c
->hierarchy
== HIERARCHY_AUTO
||
330 c
->inversion
== INVERSION_AUTO
) {
333 deb_setf("autosearch enabled.\n");
335 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
337 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AUTO_SEARCH
);
338 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
340 while ((search_state
=
341 dib3000_search_status(
342 rd(DIB3000MB_REG_AS_IRQ_PENDING
),
343 rd(DIB3000MB_REG_LOCK2_VALUE
))) < 0 && as_count
++ < 100)
346 deb_setf("search_state after autosearch %d after %d checks\n",
347 search_state
, as_count
);
349 if (search_state
== 1) {
350 if (dib3000mb_get_frontend(fe
, c
) == 0) {
351 deb_setf("reading tuning data from frontend succeeded.\n");
352 return dib3000mb_set_frontend(fe
, 0);
357 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_CTRL
);
358 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_OFF
);
364 static int dib3000mb_fe_init(struct dvb_frontend
* fe
, int mobile_mode
)
366 struct dib3000_state
* state
= fe
->demodulator_priv
;
368 deb_info("dib3000mb is getting up.\n");
369 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_UP
);
371 wr(DIB3000MB_REG_RESTART
, DIB3000MB_RESTART_AGC
);
373 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE
);
374 wr(DIB3000MB_REG_RESET_DEVICE
, DIB3000MB_RESET_DEVICE_RST
);
376 wr(DIB3000MB_REG_CLOCK
, DIB3000MB_CLOCK_DEFAULT
);
378 wr(DIB3000MB_REG_ELECT_OUT_MODE
, DIB3000MB_ELECT_OUT_MODE_ON
);
380 wr(DIB3000MB_REG_DDS_FREQ_MSB
, DIB3000MB_DDS_FREQ_MSB
);
381 wr(DIB3000MB_REG_DDS_FREQ_LSB
, DIB3000MB_DDS_FREQ_LSB
);
383 wr_foreach(dib3000mb_reg_timing_freq
, dib3000mb_timing_freq
[2]);
385 wr_foreach(dib3000mb_reg_impulse_noise
,
386 dib3000mb_impulse_noise_values
[DIB3000MB_IMPNOISE_OFF
]);
388 wr_foreach(dib3000mb_reg_agc_gain
, dib3000mb_default_agc_gain
);
390 wr(DIB3000MB_REG_PHASE_NOISE
, DIB3000MB_PHASE_NOISE_DEFAULT
);
392 wr_foreach(dib3000mb_reg_phase_noise
, dib3000mb_default_noise_phase
);
394 wr_foreach(dib3000mb_reg_lock_duration
, dib3000mb_default_lock_duration
);
396 wr_foreach(dib3000mb_reg_agc_bandwidth
, dib3000mb_agc_bandwidth_low
);
398 wr(DIB3000MB_REG_LOCK0_MASK
, DIB3000MB_LOCK0_DEFAULT
);
399 wr(DIB3000MB_REG_LOCK1_MASK
, DIB3000MB_LOCK1_SEARCH_4
);
400 wr(DIB3000MB_REG_LOCK2_MASK
, DIB3000MB_LOCK2_DEFAULT
);
401 wr(DIB3000MB_REG_SEQ
, dib3000_seq
[1][1][1]);
403 wr_foreach(dib3000mb_reg_bandwidth
, dib3000mb_bandwidth_8mhz
);
405 wr(DIB3000MB_REG_UNK_68
, DIB3000MB_UNK_68
);
406 wr(DIB3000MB_REG_UNK_69
, DIB3000MB_UNK_69
);
407 wr(DIB3000MB_REG_UNK_71
, DIB3000MB_UNK_71
);
408 wr(DIB3000MB_REG_UNK_77
, DIB3000MB_UNK_77
);
409 wr(DIB3000MB_REG_UNK_78
, DIB3000MB_UNK_78
);
410 wr(DIB3000MB_REG_ISI
, DIB3000MB_ISI_INHIBIT
);
411 wr(DIB3000MB_REG_UNK_92
, DIB3000MB_UNK_92
);
412 wr(DIB3000MB_REG_UNK_96
, DIB3000MB_UNK_96
);
413 wr(DIB3000MB_REG_UNK_97
, DIB3000MB_UNK_97
);
414 wr(DIB3000MB_REG_UNK_106
, DIB3000MB_UNK_106
);
415 wr(DIB3000MB_REG_UNK_107
, DIB3000MB_UNK_107
);
416 wr(DIB3000MB_REG_UNK_108
, DIB3000MB_UNK_108
);
417 wr(DIB3000MB_REG_UNK_122
, DIB3000MB_UNK_122
);
418 wr(DIB3000MB_REG_MOBILE_MODE_QAM
, DIB3000MB_MOBILE_MODE_QAM_OFF
);
419 wr(DIB3000MB_REG_BERLEN
, DIB3000MB_BERLEN_DEFAULT
);
421 wr_foreach(dib3000mb_reg_filter_coeffs
, dib3000mb_filter_coeffs
);
423 wr(DIB3000MB_REG_MOBILE_ALGO
, DIB3000MB_MOBILE_ALGO_ON
);
424 wr(DIB3000MB_REG_MULTI_DEMOD_MSB
, DIB3000MB_MULTI_DEMOD_MSB
);
425 wr(DIB3000MB_REG_MULTI_DEMOD_LSB
, DIB3000MB_MULTI_DEMOD_LSB
);
427 wr(DIB3000MB_REG_OUTPUT_MODE
, DIB3000MB_OUTPUT_MODE_SLAVE
);
429 wr(DIB3000MB_REG_FIFO_142
, DIB3000MB_FIFO_142
);
430 wr(DIB3000MB_REG_MPEG2_OUT_MODE
, DIB3000MB_MPEG2_OUT_MODE_188
);
431 wr(DIB3000MB_REG_PID_PARSE
, DIB3000MB_PID_PARSE_ACTIVATE
);
432 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
433 wr(DIB3000MB_REG_FIFO_146
, DIB3000MB_FIFO_146
);
434 wr(DIB3000MB_REG_FIFO_147
, DIB3000MB_FIFO_147
);
436 wr(DIB3000MB_REG_DATA_IN_DIVERSITY
, DIB3000MB_DATA_DIVERSITY_IN_OFF
);
441 static int dib3000mb_get_frontend(struct dvb_frontend
* fe
,
442 struct dtv_frontend_properties
*c
)
444 struct dib3000_state
* state
= fe
->demodulator_priv
;
445 enum fe_code_rate
*cr
;
447 int inv_test1
,inv_test2
;
448 u32 dds_val
, threshold
= 0x800000;
450 if (!rd(DIB3000MB_REG_TPS_LOCK
))
453 dds_val
= ((rd(DIB3000MB_REG_DDS_VALUE_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB
);
454 deb_getf("DDS_VAL: %x %x %x\n", dds_val
, rd(DIB3000MB_REG_DDS_VALUE_MSB
), rd(DIB3000MB_REG_DDS_VALUE_LSB
));
455 if (dds_val
< threshold
)
457 else if (dds_val
== threshold
)
462 dds_val
= ((rd(DIB3000MB_REG_DDS_FREQ_MSB
) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB
);
463 deb_getf("DDS_FREQ: %x %x %x\n", dds_val
, rd(DIB3000MB_REG_DDS_FREQ_MSB
), rd(DIB3000MB_REG_DDS_FREQ_LSB
));
464 if (dds_val
< threshold
)
466 else if (dds_val
== threshold
)
472 ((inv_test2
== 2) && (inv_test1
==1 || inv_test1
==0)) ||
473 ((inv_test2
== 0) && (inv_test1
==1 || inv_test1
==2)) ?
474 INVERSION_ON
: INVERSION_OFF
;
476 deb_getf("inversion %d %d, %d\n", inv_test2
, inv_test1
, c
->inversion
);
478 switch ((tps_val
= rd(DIB3000MB_REG_TPS_QAM
))) {
479 case DIB3000_CONSTELLATION_QPSK
:
481 c
->modulation
= QPSK
;
483 case DIB3000_CONSTELLATION_16QAM
:
485 c
->modulation
= QAM_16
;
487 case DIB3000_CONSTELLATION_64QAM
:
489 c
->modulation
= QAM_64
;
492 pr_err("Unexpected constellation returned by TPS (%d)\n", tps_val
);
495 deb_getf("TPS: %d\n", tps_val
);
497 if (rd(DIB3000MB_REG_TPS_HRCH
)) {
498 deb_getf("HRCH ON\n");
499 cr
= &c
->code_rate_LP
;
500 c
->code_rate_HP
= FEC_NONE
;
501 switch ((tps_val
= rd(DIB3000MB_REG_TPS_VIT_ALPHA
))) {
502 case DIB3000_ALPHA_0
:
503 deb_getf("HIERARCHY_NONE\n");
504 c
->hierarchy
= HIERARCHY_NONE
;
506 case DIB3000_ALPHA_1
:
507 deb_getf("HIERARCHY_1\n");
508 c
->hierarchy
= HIERARCHY_1
;
510 case DIB3000_ALPHA_2
:
511 deb_getf("HIERARCHY_2\n");
512 c
->hierarchy
= HIERARCHY_2
;
514 case DIB3000_ALPHA_4
:
515 deb_getf("HIERARCHY_4\n");
516 c
->hierarchy
= HIERARCHY_4
;
519 pr_err("Unexpected ALPHA value returned by TPS (%d)\n", tps_val
);
522 deb_getf("TPS: %d\n", tps_val
);
524 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_LP
);
526 deb_getf("HRCH OFF\n");
527 cr
= &c
->code_rate_HP
;
528 c
->code_rate_LP
= FEC_NONE
;
529 c
->hierarchy
= HIERARCHY_NONE
;
531 tps_val
= rd(DIB3000MB_REG_TPS_CODE_RATE_HP
);
535 case DIB3000_FEC_1_2
:
536 deb_getf("FEC_1_2\n");
539 case DIB3000_FEC_2_3
:
540 deb_getf("FEC_2_3\n");
543 case DIB3000_FEC_3_4
:
544 deb_getf("FEC_3_4\n");
547 case DIB3000_FEC_5_6
:
548 deb_getf("FEC_5_6\n");
551 case DIB3000_FEC_7_8
:
552 deb_getf("FEC_7_8\n");
556 pr_err("Unexpected FEC returned by TPS (%d)\n", tps_val
);
559 deb_getf("TPS: %d\n",tps_val
);
561 switch ((tps_val
= rd(DIB3000MB_REG_TPS_GUARD_TIME
))) {
562 case DIB3000_GUARD_TIME_1_32
:
563 deb_getf("GUARD_INTERVAL_1_32\n");
564 c
->guard_interval
= GUARD_INTERVAL_1_32
;
566 case DIB3000_GUARD_TIME_1_16
:
567 deb_getf("GUARD_INTERVAL_1_16\n");
568 c
->guard_interval
= GUARD_INTERVAL_1_16
;
570 case DIB3000_GUARD_TIME_1_8
:
571 deb_getf("GUARD_INTERVAL_1_8\n");
572 c
->guard_interval
= GUARD_INTERVAL_1_8
;
574 case DIB3000_GUARD_TIME_1_4
:
575 deb_getf("GUARD_INTERVAL_1_4\n");
576 c
->guard_interval
= GUARD_INTERVAL_1_4
;
579 pr_err("Unexpected Guard Time returned by TPS (%d)\n", tps_val
);
582 deb_getf("TPS: %d\n", tps_val
);
584 switch ((tps_val
= rd(DIB3000MB_REG_TPS_FFT
))) {
585 case DIB3000_TRANSMISSION_MODE_2K
:
586 deb_getf("TRANSMISSION_MODE_2K\n");
587 c
->transmission_mode
= TRANSMISSION_MODE_2K
;
589 case DIB3000_TRANSMISSION_MODE_8K
:
590 deb_getf("TRANSMISSION_MODE_8K\n");
591 c
->transmission_mode
= TRANSMISSION_MODE_8K
;
594 pr_err("unexpected transmission mode return by TPS (%d)\n", tps_val
);
597 deb_getf("TPS: %d\n", tps_val
);
602 static int dib3000mb_read_status(struct dvb_frontend
*fe
,
603 enum fe_status
*stat
)
605 struct dib3000_state
* state
= fe
->demodulator_priv
;
609 if (rd(DIB3000MB_REG_AGC_LOCK
))
610 *stat
|= FE_HAS_SIGNAL
;
611 if (rd(DIB3000MB_REG_CARRIER_LOCK
))
612 *stat
|= FE_HAS_CARRIER
;
613 if (rd(DIB3000MB_REG_VIT_LCK
))
614 *stat
|= FE_HAS_VITERBI
;
615 if (rd(DIB3000MB_REG_TS_SYNC_LOCK
))
616 *stat
|= (FE_HAS_SYNC
| FE_HAS_LOCK
);
618 deb_getf("actual status is %2x\n",*stat
);
620 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
621 rd(DIB3000MB_REG_TPS_LOCK
),
622 rd(DIB3000MB_REG_TPS_QAM
),
623 rd(DIB3000MB_REG_TPS_HRCH
),
624 rd(DIB3000MB_REG_TPS_VIT_ALPHA
),
625 rd(DIB3000MB_REG_TPS_CODE_RATE_HP
),
626 rd(DIB3000MB_REG_TPS_CODE_RATE_LP
),
627 rd(DIB3000MB_REG_TPS_GUARD_TIME
),
628 rd(DIB3000MB_REG_TPS_FFT
),
629 rd(DIB3000MB_REG_TPS_CELL_ID
));
631 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
635 static int dib3000mb_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
637 struct dib3000_state
* state
= fe
->demodulator_priv
;
639 *ber
= ((rd(DIB3000MB_REG_BER_MSB
) << 16) | rd(DIB3000MB_REG_BER_LSB
));
643 /* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
644 static int dib3000mb_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
646 struct dib3000_state
* state
= fe
->demodulator_priv
;
648 *strength
= rd(DIB3000MB_REG_SIGNAL_POWER
) * 0xffff / 0x170;
652 static int dib3000mb_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
654 struct dib3000_state
* state
= fe
->demodulator_priv
;
655 short sigpow
= rd(DIB3000MB_REG_SIGNAL_POWER
);
656 int icipow
= ((rd(DIB3000MB_REG_NOISE_POWER_MSB
) & 0xff) << 16) |
657 rd(DIB3000MB_REG_NOISE_POWER_LSB
);
658 *snr
= (sigpow
<< 8) / ((icipow
> 0) ? icipow
: 1);
662 static int dib3000mb_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
664 struct dib3000_state
* state
= fe
->demodulator_priv
;
666 *unc
= rd(DIB3000MB_REG_PACKET_ERROR_RATE
);
670 static int dib3000mb_sleep(struct dvb_frontend
* fe
)
672 struct dib3000_state
* state
= fe
->demodulator_priv
;
673 deb_info("dib3000mb is going to bed.\n");
674 wr(DIB3000MB_REG_POWER_CONTROL
, DIB3000MB_POWER_DOWN
);
678 static int dib3000mb_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
680 tune
->min_delay_ms
= 800;
684 static int dib3000mb_fe_init_nonmobile(struct dvb_frontend
* fe
)
686 return dib3000mb_fe_init(fe
, 0);
689 static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend
*fe
)
691 return dib3000mb_set_frontend(fe
, 1);
694 static void dib3000mb_release(struct dvb_frontend
* fe
)
696 struct dib3000_state
*state
= fe
->demodulator_priv
;
700 /* pid filter and transfer stuff */
701 static int dib3000mb_pid_control(struct dvb_frontend
*fe
,int index
, int pid
,int onoff
)
703 struct dib3000_state
*state
= fe
->demodulator_priv
;
704 pid
= (onoff
? pid
| DIB3000_ACTIVATE_PID_FILTERING
: 0);
705 wr(index
+DIB3000MB_REG_FIRST_PID
,pid
);
709 static int dib3000mb_fifo_control(struct dvb_frontend
*fe
, int onoff
)
711 struct dib3000_state
*state
= fe
->demodulator_priv
;
713 deb_xfer("%s fifo\n",onoff
? "enabling" : "disabling");
715 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_ACTIVATE
);
717 wr(DIB3000MB_REG_FIFO
, DIB3000MB_FIFO_INHIBIT
);
722 static int dib3000mb_pid_parse(struct dvb_frontend
*fe
, int onoff
)
724 struct dib3000_state
*state
= fe
->demodulator_priv
;
725 deb_xfer("%s pid parsing\n",onoff
? "enabling" : "disabling");
726 wr(DIB3000MB_REG_PID_PARSE
,onoff
);
730 static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend
*fe
, int onoff
, u8 pll_addr
)
732 struct dib3000_state
*state
= fe
->demodulator_priv
;
734 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_ENABLE(pll_addr
));
736 wr(DIB3000MB_REG_TUNER
, DIB3000_TUNER_WRITE_DISABLE(pll_addr
));
741 static const struct dvb_frontend_ops dib3000mb_ops
;
743 struct dvb_frontend
* dib3000mb_attach(const struct dib3000_config
* config
,
744 struct i2c_adapter
* i2c
, struct dib_fe_xfer_ops
*xfer_ops
)
746 struct dib3000_state
* state
= NULL
;
748 /* allocate memory for the internal state */
749 state
= kzalloc(sizeof(struct dib3000_state
), GFP_KERNEL
);
753 /* setup the state */
755 memcpy(&state
->config
,config
,sizeof(struct dib3000_config
));
757 /* check for the correct demod */
758 if (rd(DIB3000_REG_MANUFACTOR_ID
) != DIB3000_I2C_ID_DIBCOM
)
761 if (rd(DIB3000_REG_DEVICE_ID
) != DIB3000MB_DEVICE_ID
)
764 /* create dvb_frontend */
765 memcpy(&state
->frontend
.ops
, &dib3000mb_ops
, sizeof(struct dvb_frontend_ops
));
766 state
->frontend
.demodulator_priv
= state
;
768 /* set the xfer operations */
769 xfer_ops
->pid_parse
= dib3000mb_pid_parse
;
770 xfer_ops
->fifo_ctrl
= dib3000mb_fifo_control
;
771 xfer_ops
->pid_ctrl
= dib3000mb_pid_control
;
772 xfer_ops
->tuner_pass_ctrl
= dib3000mb_tuner_pass_ctrl
;
774 return &state
->frontend
;
781 static const struct dvb_frontend_ops dib3000mb_ops
= {
782 .delsys
= { SYS_DVBT
},
784 .name
= "DiBcom 3000M-B DVB-T",
785 .frequency_min_hz
= 44250 * kHz
,
786 .frequency_max_hz
= 867250 * kHz
,
787 .frequency_stepsize_hz
= 62500,
788 .caps
= FE_CAN_INVERSION_AUTO
|
789 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
790 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
791 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
792 FE_CAN_TRANSMISSION_MODE_AUTO
|
793 FE_CAN_GUARD_INTERVAL_AUTO
|
795 FE_CAN_HIERARCHY_AUTO
,
798 .release
= dib3000mb_release
,
800 .init
= dib3000mb_fe_init_nonmobile
,
801 .sleep
= dib3000mb_sleep
,
803 .set_frontend
= dib3000mb_set_frontend_and_tuner
,
804 .get_frontend
= dib3000mb_get_frontend
,
805 .get_tune_settings
= dib3000mb_fe_get_tune_settings
,
807 .read_status
= dib3000mb_read_status
,
808 .read_ber
= dib3000mb_read_ber
,
809 .read_signal_strength
= dib3000mb_read_signal_strength
,
810 .read_snr
= dib3000mb_read_snr
,
811 .read_ucblocks
= dib3000mb_read_unc_blocks
,
814 MODULE_AUTHOR(DRIVER_AUTHOR
);
815 MODULE_DESCRIPTION(DRIVER_DESC
);
816 MODULE_LICENSE("GPL");
818 EXPORT_SYMBOL(dib3000mb_attach
);