27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/i2c.h>
41 #define dprintk(args...) do { \
43 printk(KERN_DEBUG "DiB0070: "); \
49 #define DIB0070_P1D 0x00
50 #define DIB0070_P1F 0x01
51 #define DIB0070_P1G 0x03
52 #define DIB0070S_P1A 0x02
90 dprintk(
"could not acquire lock");
97 state->
msg[0].addr = state->
cfg->i2c_address;
98 state->
msg[0].flags = 0;
100 state->
msg[0].len = 1;
101 state->
msg[1].addr = state->
cfg->i2c_address;
104 state->
msg[1].len = 2;
122 dprintk(
"could not acquire lock");
130 state->
msg[0].addr = state->
cfg->i2c_address;
131 state->
msg[0].flags = 0;
133 state->
msg[0].len = 3;
145 #define HARD_RESET(state) do { \
146 state->cfg->sleep(state->fe, 0); \
147 if (state->cfg->reset) { \
148 state->cfg->reset(state->fe,1); msleep(10); \
149 state->cfg->reset(state->fe,0); msleep(10); \
153 static int dib0070_set_bandwidth(
struct dvb_frontend *fe)
156 u16 tmp = dib0070_read_reg(state, 0x02) & 0x3fff;
158 if (state->
fe->dtv_property_cache.bandwidth_hz/1000 > 7000)
160 else if (state->
fe->dtv_property_cache.bandwidth_hz/1000 > 6000)
162 else if (state->
fe->dtv_property_cache.bandwidth_hz/1000 > 5000)
167 dib0070_write_reg(state, 0x02, tmp);
170 if (state->
fe->dtv_property_cache.delivery_system ==
SYS_ISDBT) {
171 u16 value = dib0070_read_reg(state, 0x17);
173 dib0070_write_reg(state, 0x17, value & 0xfffc);
174 tmp = dib0070_read_reg(state, 0x01) & 0x01ff;
175 dib0070_write_reg(state, 0x01, tmp | (60 << 9));
177 dib0070_write_reg(state, 0x17, value);
190 dib0070_write_reg(state, 0x0f, 0xed10);
191 dib0070_write_reg(state, 0x17, 0x0034);
193 dib0070_write_reg(state, 0x18, 0x0032);
201 dib0070_write_reg(state, 0x14, state->
lo4 | state->
captrim);
207 adc = dib0070_read_reg(state, 0x19);
229 if (state->
step >= 1)
235 dib0070_write_reg(state, 0x14, state->
lo4 | state->
fcaptrim);
236 dib0070_write_reg(state, 0x18, 0x07ff);
243 static int dib0070_set_ctrl_lo5(
struct dvb_frontend *
fe,
u8 vco_bias_trim,
u8 hf_div_trim,
u8 cp_current,
u8 third_order_filt)
246 u16 lo5 = (third_order_filt << 14) | (0 << 13) | (1 << 12) | (3 << 9) | (cp_current << 6) | (hf_div_trim << 3) | (vco_bias_trim << 0);
247 dprintk(
"CTRL_LO5: 0x%x", lo5);
248 return dib0070_write_reg(state, 0x15, lo5);
256 dib0070_write_reg(state, 0x1b, 0xff00);
257 dib0070_write_reg(state, 0x1a, 0x0000);
259 dib0070_write_reg(state, 0x1b, 0x4112);
260 if (state->
cfg->vga_filter != 0) {
261 dib0070_write_reg(state, 0x1a, state->
cfg->vga_filter);
262 dprintk(
"vga filter register is set to %x", state->
cfg->vga_filter);
264 dib0070_write_reg(state, 0x1a, 0x0009);
286 { 570000, 2, 1, 3, 6, 6, 2, 0x4000 | 0x0800 },
287 { 700000, 2, 0, 2, 4, 2, 2, 0x4000 | 0x0800 },
288 { 863999, 2, 1, 2, 4, 2, 2, 0x4000 | 0x0800 },
289 { 1500000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 },
290 { 1600000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 },
291 { 2000000, 0, 1, 1, 2, 2, 4, 0x2000 | 0x0400 },
292 { 0xffffffff, 0, 0, 8, 1, 2, 1, 0x8000 | 0x1000 },
296 { 115000, 1, 0, 7, 24, 2, 1, 0x8000 | 0x1000 },
297 { 179500, 1, 0, 3, 16, 2, 1, 0x8000 | 0x1000 },
298 { 189999, 1, 1, 3, 16, 2, 1, 0x8000 | 0x1000 },
299 { 250000, 1, 0, 6, 12, 2, 1, 0x8000 | 0x1000 },
300 { 569999, 2, 1, 5, 6, 2, 2, 0x4000 | 0x0800 },
301 { 699999, 2, 0, 1, 4, 2, 2, 0x4000 | 0x0800 },
302 { 863999, 2, 1, 1, 4, 2, 2, 0x4000 | 0x0800 },
303 { 0xffffffff, 0, 1, 0, 2, 2, 4, 0x2000 | 0x0400 },
338 static int dib0070_tune_digital(
struct dvb_frontend *fe)
351 #ifdef CONFIG_SYS_ISDBT
352 if (state->
fe->dtv_property_cache.delivery_system ==
SYS_ISDBT && state->
fe->dtv_property_cache.isdbt_sb_mode == 1)
353 if (((state->
fe->dtv_property_cache.isdbt_sb_segment_count % 2)
354 && (state->
fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->
fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
355 || (((state->
fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
356 && (state->
fe->dtv_property_cache.isdbt_sb_segment_idx == (state->
fe->dtv_property_cache.isdbt_sb_segment_count / 2)))
357 || (((state->
fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
358 && (state->
fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->
fe->dtv_property_cache.isdbt_sb_segment_count / 2) + 1))))
365 tune = dib0070s_tuning_table;
366 lna_match = dib0070_lna;
369 tune = dib0070_tuning_table;
370 if (state->
cfg->flip_chip)
371 lna_match = dib0070_lna_flip_chip;
373 lna_match = dib0070_lna;
386 dprintk(
"Tuning for Band: %hd (%d kHz)", band, freq);
389 u32 FBDiv, Rest,
FREF, VCOF_kHz;
396 dib0070_write_reg(state, 0x17, 0x30);
403 REFDIV = (
u8) ((state->
cfg->clock_khz + 9999) / 10000);
406 REFDIV = (
u8) ((state->
cfg->clock_khz) / 1000);
409 REFDIV = (
u8) (state->
cfg->clock_khz / 10000);
412 FREF = state->
cfg->clock_khz / REFDIV;
425 FBDiv = (freq / (FREF / 2));
426 Rest = 2 * freq - FBDiv *
FREF;
432 else if (Rest < 2 *
LPF)
434 else if (Rest > (FREF -
LPF)) {
437 }
else if (Rest > (FREF - 2 *
LPF))
438 Rest = FREF - 2 *
LPF;
439 Rest = (Rest * 6528) / (FREF / 10);
443 state->
lo4 |= (1 << 14) | (1 << 12);
448 dib0070_write_reg(state, 0x11, (
u16)FBDiv);
449 dib0070_write_reg(state, 0x12, (Den << 8) | REFDIV);
450 dib0070_write_reg(state, 0x13, (
u16) Rest);
455 dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0);
456 dib0070_write_reg(state, 0x1d, 0xFFFF);
458 dib0070_set_ctrl_lo5(fe, 5, 4, 3, 1);
461 dib0070_write_reg(state, 0x20,
464 dprintk(
"REFDIV: %hd, FREF: %d", REFDIV, FREF);
465 dprintk(
"FBDIV: %d, Rest: %d", FBDiv, Rest);
466 dprintk(
"Num: %hd, Den: %hd, SD: %hd", (
u16) Rest, Den, (state->
lo4 >> 12) & 0x1);
478 ret = dib0070_captrim(state, tune_state);
483 while (freq/1000 > tmp->
freq)
485 dib0070_write_reg(state, 0x0f,
486 (0 << 15) | (1 << 14) | (3 << 12)
491 dib0070_write_reg(state, 0x0f,
497 dib0070_write_reg(state, 0x06, 0x3fff);
498 dib0070_write_reg(state, 0x07,
500 dib0070_write_reg(state, 0x08, (state->
lna_match->lna_band << 10) | (3 << 7) | (127));
501 dib0070_write_reg(state, 0x0d, 0x0d80);
504 dib0070_write_reg(state, 0x18, 0x07ff);
505 dib0070_write_reg(state, 0x17, 0x0033);
510 dib0070_set_bandwidth(fe);
527 ret = dib0070_tune_digital(fe);
540 if (state->
cfg->sleep)
541 state->
cfg->sleep(fe, 0);
548 if (state->
cfg->sleep)
549 state->
cfg->sleep(fe, 1);
556 return (dib0070_read_reg(state, 0x07) >> 11) & 0x3;
563 u16 rxrf2 = dib0070_read_reg(state, 0x07) & 0xfe7ff;
568 return dib0070_write_reg(state, 0x07, rxrf2 | (no << 11));
572 static const u16 dib0070_p1f_defaults[] =
606 0x4000 | 0x0800 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001,
613 u16 tuner_en = dib0070_read_reg(state, 0x20);
616 dib0070_write_reg(state, 0x18, 0x07ff);
617 dib0070_write_reg(state, 0x20, 0x0800 | 0x4000 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001);
618 dib0070_write_reg(state, 0x0f, (1 << 14) | (2 << 12) | (gain << 9) | (1 << 8) | (1 << 7) | (0 << 0));
620 offset = dib0070_read_reg(state, 0x19);
621 dib0070_write_reg(state, 0x20, tuner_en);
625 static void dib0070_wbd_offset_calibration(
struct dib0070_state *state)
628 for (gain = 6; gain < 8; gain++) {
629 state->
wbd_offset_3_3[gain - 6] = ((dib0070_read_wbd_offset(state, gain) * 8 * 18 / 33 + 1) / 2);
641 while (freq/1000 > tmp->
freq)
651 #define pgm_read_word(w) (*w)
660 #ifndef FORCE_SBAND_TUNER
661 if ((dib0070_read_reg(state, 0x22) >> 9) & 0x1)
662 state->
revision = (dib0070_read_reg(state, 0x1f) >> 8) & 0xff;
665 #warning forcing SBAND
673 dprintk(
"Error: this driver is not to be used meant for P1D or earlier");
677 n = (
u16 *) dib0070_p1f_defaults;
688 if (state->
cfg->force_crystal_mode != 0)
689 r = state->
cfg->force_crystal_mode;
690 else if (state->
cfg->clock_khz >= 24000)
696 r |= state->
cfg->osc_buffer_state << 3;
698 dib0070_write_reg(state, 0x10, r);
699 dib0070_write_reg(state, 0x1f, (1 << 8) | ((state->
cfg->clock_pad_drive & 0xf) << 5));
701 if (state->
cfg->invert_iq) {
702 r = dib0070_read_reg(state, 0x02) & 0xffdf;
703 dib0070_write_reg(state, 0x02, r | (1 << 5));
707 dib0070_set_ctrl_lo5(fe, 2, 4, 3, 0);
709 dib0070_set_ctrl_lo5(fe, 5, 4, state->
cfg->charge_pump, state->
cfg->enable_third_order_filter);
711 dib0070_write_reg(state, 0x01, (54 << 9) | 0xc8);
713 dib0070_wbd_offset_calibration(state);
735 .name =
"DiBcom DiB0070",
736 .frequency_min = 45000000,
737 .frequency_max = 860000000,
738 .frequency_step = 1000,
740 .release = dib0070_release,
742 .init = dib0070_wakeup,
743 .sleep = dib0070_sleep,
744 .set_params = dib0070_tune,
746 .get_frequency = dib0070_get_frequency,
762 if (dib0070_reset(fe) != 0)