24 #include <linux/kernel.h>
25 #include <linux/module.h>
28 #include <linux/string.h>
29 #include <linux/slab.h>
37 #define DRIVER_VERSION "0.1"
38 #define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator"
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)
55 u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff };
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 },
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];
74 (reg >> 8) & 0xff, reg & 0xff,
75 (val >> 8) & 0xff, val & 0xff,
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);
85 static int dib3000_search_status(
u16 irq,
u16 lock)
92 deb_srch(
"auto search not successful\n");
95 }
else if (irq & 0x01) {
103 static u16 dib3000_seq[2][2][2] =
115 static int dib3000mb_get_frontend(
struct dvb_frontend* fe);
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);
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.");
327 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_high);
337 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_low);
353 while ((search_state =
354 dib3000_search_status(
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);
376 static int dib3000mb_fe_init(
struct dvb_frontend* fe,
int mobile_mode)
380 deb_info(
"dib3000mb is getting up.\n");
395 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[2]);
400 wr_foreach(dib3000mb_reg_agc_gain, dib3000mb_default_agc_gain);
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);
415 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_8mhz);
433 wr_foreach(dib3000mb_reg_filter_coeffs, dib3000mb_filter_coeffs);
453 static int dib3000mb_get_frontend(
struct dvb_frontend* fe)
459 int inv_test1,inv_test2;
467 if (dds_val < threshold)
469 else if (dds_val == threshold)
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)) ?
504 err(
"Unexpected constellation returned by TPS (%d)", tps_val);
531 err(
"Unexpected ALPHA value returned by TPS (%d)", tps_val);
568 err(
"Unexpected FEC returned by TPS (%d)", tps_val);
591 err(
"Unexpected Guard Time returned by TPS (%d)", tps_val);
606 err(
"unexpected transmission mode return by TPS (%d)", tps_val);
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",
655 static int dib3000mb_read_signal_strength(
struct dvb_frontend* fe,
u16 *strength)
669 *snr = (sigpow << 8) / ((icipow > 0) ? icipow : 1);
673 static int dib3000mb_read_unc_blocks(
struct dvb_frontend* fe,
u32 *unc)
684 deb_info(
"dib3000mb is going to bed.\n");
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);
724 deb_xfer(
"%s fifo\n",onoff ?
"enabling" :
"disabling");
733 static int dib3000mb_pid_parse(
struct dvb_frontend *fe,
int onoff)
736 deb_xfer(
"%s pid parsing\n",onoff ?
"enabling" :
"disabling");
741 static int dib3000mb_tuner_pass_ctrl(
struct dvb_frontend *fe,
int onoff,
u8 pll_addr)
780 xfer_ops->
pid_parse = dib3000mb_pid_parse;
781 xfer_ops->
fifo_ctrl = dib3000mb_fifo_control;
782 xfer_ops->
pid_ctrl = dib3000mb_pid_control;
795 .name =
"DiBcom 3000M-B DVB-T",
796 .frequency_min = 44250000,
797 .frequency_max = 867250000,
798 .frequency_stepsize = 62500,
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,