Lines Matching refs:state

81 static u16 dib0070_read_reg(struct dib0070_state *state, u8 reg)  in dib0070_read_reg()  argument
85 if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) { in dib0070_read_reg()
90 state->i2c_write_buffer[0] = reg; in dib0070_read_reg()
92 memset(state->msg, 0, 2 * sizeof(struct i2c_msg)); in dib0070_read_reg()
93 state->msg[0].addr = state->cfg->i2c_address; in dib0070_read_reg()
94 state->msg[0].flags = 0; in dib0070_read_reg()
95 state->msg[0].buf = state->i2c_write_buffer; in dib0070_read_reg()
96 state->msg[0].len = 1; in dib0070_read_reg()
97 state->msg[1].addr = state->cfg->i2c_address; in dib0070_read_reg()
98 state->msg[1].flags = I2C_M_RD; in dib0070_read_reg()
99 state->msg[1].buf = state->i2c_read_buffer; in dib0070_read_reg()
100 state->msg[1].len = 2; in dib0070_read_reg()
102 if (i2c_transfer(state->i2c, state->msg, 2) != 2) { in dib0070_read_reg()
106 ret = (state->i2c_read_buffer[0] << 8) in dib0070_read_reg()
107 | state->i2c_read_buffer[1]; in dib0070_read_reg()
109 mutex_unlock(&state->i2c_buffer_lock); in dib0070_read_reg()
113 static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val) in dib0070_write_reg() argument
117 if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) { in dib0070_write_reg()
121 state->i2c_write_buffer[0] = reg; in dib0070_write_reg()
122 state->i2c_write_buffer[1] = val >> 8; in dib0070_write_reg()
123 state->i2c_write_buffer[2] = val & 0xff; in dib0070_write_reg()
125 memset(state->msg, 0, sizeof(struct i2c_msg)); in dib0070_write_reg()
126 state->msg[0].addr = state->cfg->i2c_address; in dib0070_write_reg()
127 state->msg[0].flags = 0; in dib0070_write_reg()
128 state->msg[0].buf = state->i2c_write_buffer; in dib0070_write_reg()
129 state->msg[0].len = 3; in dib0070_write_reg()
131 if (i2c_transfer(state->i2c, state->msg, 1) != 1) { in dib0070_write_reg()
137 mutex_unlock(&state->i2c_buffer_lock); in dib0070_write_reg()
141 #define HARD_RESET(state) do { \ argument
142 state->cfg->sleep(state->fe, 0); \
143 if (state->cfg->reset) { \
144 state->cfg->reset(state->fe,1); msleep(10); \
145 state->cfg->reset(state->fe,0); msleep(10); \
151 struct dib0070_state *state = fe->tuner_priv; in dib0070_set_bandwidth() local
152 u16 tmp = dib0070_read_reg(state, 0x02) & 0x3fff; in dib0070_set_bandwidth()
154 if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 7000) in dib0070_set_bandwidth()
156 else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 6000) in dib0070_set_bandwidth()
158 else if (state->fe->dtv_property_cache.bandwidth_hz/1000 > 5000) in dib0070_set_bandwidth()
163 dib0070_write_reg(state, 0x02, tmp); in dib0070_set_bandwidth()
166 if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) { in dib0070_set_bandwidth()
167 u16 value = dib0070_read_reg(state, 0x17); in dib0070_set_bandwidth()
169 dib0070_write_reg(state, 0x17, value & 0xfffc); in dib0070_set_bandwidth()
170 tmp = dib0070_read_reg(state, 0x01) & 0x01ff; in dib0070_set_bandwidth()
171 dib0070_write_reg(state, 0x01, tmp | (60 << 9)); in dib0070_set_bandwidth()
173 dib0070_write_reg(state, 0x17, value); in dib0070_set_bandwidth()
178 static int dib0070_captrim(struct dib0070_state *state, enum frontend_tune_state *tune_state) in dib0070_captrim() argument
185 dib0070_write_reg(state, 0x0f, 0xed10); in dib0070_captrim()
186 dib0070_write_reg(state, 0x17, 0x0034); in dib0070_captrim()
188 dib0070_write_reg(state, 0x18, 0x0032); in dib0070_captrim()
189 state->step = state->captrim = state->fcaptrim = 64; in dib0070_captrim()
190 state->adc_diff = 3000; in dib0070_captrim()
195 state->step /= 2; in dib0070_captrim()
196 dib0070_write_reg(state, 0x14, state->lo4 | state->captrim); in dib0070_captrim()
202 adc = dib0070_read_reg(state, 0x19); in dib0070_captrim()
204 …dprintk("CAPTRIM=%hd; ADC = %hd (ADC) & %dmV\n", state->captrim, adc, (u32) adc*(u32)1800/(u32)102… in dib0070_captrim()
214 if (adc < state->adc_diff) { in dib0070_captrim()
215 dprintk("CAPTRIM=%hd is closer to target (%hd/%hd)\n", state->captrim, adc, state->adc_diff); in dib0070_captrim()
216 state->adc_diff = adc; in dib0070_captrim()
217 state->fcaptrim = state->captrim; in dib0070_captrim()
219 state->captrim += (step_sign * state->step); in dib0070_captrim()
221 if (state->step >= 1) in dib0070_captrim()
227 dib0070_write_reg(state, 0x14, state->lo4 | state->fcaptrim); in dib0070_captrim()
228 dib0070_write_reg(state, 0x18, 0x07ff); in dib0070_captrim()
237 struct dib0070_state *state = fe->tuner_priv; in dib0070_set_ctrl_lo5() local
241 return dib0070_write_reg(state, 0x15, lo5); in dib0070_set_ctrl_lo5()
246 struct dib0070_state *state = fe->tuner_priv; in dib0070_ctrl_agc_filter() local
249 dib0070_write_reg(state, 0x1b, 0xff00); in dib0070_ctrl_agc_filter()
250 dib0070_write_reg(state, 0x1a, 0x0000); in dib0070_ctrl_agc_filter()
252 dib0070_write_reg(state, 0x1b, 0x4112); in dib0070_ctrl_agc_filter()
253 if (state->cfg->vga_filter != 0) { in dib0070_ctrl_agc_filter()
254 dib0070_write_reg(state, 0x1a, state->cfg->vga_filter); in dib0070_ctrl_agc_filter()
255 dprintk("vga filter register is set to %x\n", state->cfg->vga_filter); in dib0070_ctrl_agc_filter()
257 dib0070_write_reg(state, 0x1a, 0x0009); in dib0070_ctrl_agc_filter()
333 struct dib0070_state *state = fe->tuner_priv; in dib0070_tune_digital() local
338 enum frontend_tune_state *tune_state = &state->tune_state; in dib0070_tune_digital()
342 …>dtv_property_cache.frequency/1000 + (band == BAND_VHF ? state->cfg->freq_offset_khz_vhf : state->… in dib0070_tune_digital()
345 …if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.is… in dib0070_tune_digital()
346 if (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) in dib0070_tune_digital()
347 …&& (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb… in dib0070_tune_digital()
348 || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) in dib0070_tune_digital()
349 …&& (state->fe->dtv_property_cache.isdbt_sb_segment_idx == (state->fe->dtv_property_cache.isdbt_sb_… in dib0070_tune_digital()
350 || (((state->fe->dtv_property_cache.isdbt_sb_segment_count % 2) == 0) in dib0070_tune_digital()
351 …&& (state->fe->dtv_property_cache.isdbt_sb_segment_idx == ((state->fe->dtv_property_cache.isdbt_sb… in dib0070_tune_digital()
354 if (state->current_rf != freq) { in dib0070_tune_digital()
356 switch (state->revision) { in dib0070_tune_digital()
363 if (state->cfg->flip_chip) in dib0070_tune_digital()
374 state->current_tune_table_index = tune; in dib0070_tune_digital()
375 state->lna_match = lna_match; in dib0070_tune_digital()
380 if (state->current_rf != freq) { in dib0070_tune_digital()
385 state->current_rf = freq; in dib0070_tune_digital()
386state->lo4 = (state->current_tune_table_index->vco_band << 11) | (state->current_tune_table_index-… in dib0070_tune_digital()
389 dib0070_write_reg(state, 0x17, 0x30); in dib0070_tune_digital()
392 VCOF_kHz = state->current_tune_table_index->vco_multi * freq * 2; in dib0070_tune_digital()
396 REFDIV = (u8) ((state->cfg->clock_khz + 9999) / 10000); in dib0070_tune_digital()
399 REFDIV = (u8) ((state->cfg->clock_khz) / 1000); in dib0070_tune_digital()
402 REFDIV = (u8) (state->cfg->clock_khz / 10000); in dib0070_tune_digital()
405 FREF = state->cfg->clock_khz / REFDIV; in dib0070_tune_digital()
409 switch (state->revision) { in dib0070_tune_digital()
411 FBDiv = (VCOF_kHz / state->current_tune_table_index->presc / FREF); in dib0070_tune_digital()
412 Rest = (VCOF_kHz / state->current_tune_table_index->presc) - FBDiv * FREF; in dib0070_tune_digital()
436 state->lo4 |= (1 << 14) | (1 << 12); in dib0070_tune_digital()
441 dib0070_write_reg(state, 0x11, (u16)FBDiv); in dib0070_tune_digital()
442 dib0070_write_reg(state, 0x12, (Den << 8) | REFDIV); in dib0070_tune_digital()
443 dib0070_write_reg(state, 0x13, (u16) Rest); in dib0070_tune_digital()
445 if (state->revision == DIB0070S_P1A) { in dib0070_tune_digital()
449 dib0070_write_reg(state, 0x1d, 0xFFFF); in dib0070_tune_digital()
454 dib0070_write_reg(state, 0x20, in dib0070_tune_digital()
455 …0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001 | state->current_tune_table_index->tuner_enabl… in dib0070_tune_digital()
459 dprintk("Num: %hd, Den: %hd, SD: %hd\n", (u16) Rest, Den, (state->lo4 >> 12) & 0x1); in dib0070_tune_digital()
460 dprintk("HFDIV code: %hd\n", state->current_tune_table_index->hfdiv); in dib0070_tune_digital()
461 dprintk("VCO = %hd\n", state->current_tune_table_index->vco_band); in dib0070_tune_digital()
462 dprintk("VCOF: ((%hd*%d) << 1))\n", state->current_tune_table_index->vco_multi, freq); in dib0070_tune_digital()
471 ret = dib0070_captrim(state, tune_state); in dib0070_tune_digital()
474 const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; in dib0070_tune_digital()
478 dib0070_write_reg(state, 0x0f, in dib0070_tune_digital()
481 | (state->current_tune_table_index->wbdmux << 0)); in dib0070_tune_digital()
482 state->wbd_gain_current = tmp->wbd_gain_val; in dib0070_tune_digital()
484 dib0070_write_reg(state, 0x0f, in dib0070_tune_digital()
487 | (state->current_tune_table_index->wbdmux << 0)); in dib0070_tune_digital()
488 state->wbd_gain_current = 6; in dib0070_tune_digital()
491 dib0070_write_reg(state, 0x06, 0x3fff); in dib0070_tune_digital()
492 dib0070_write_reg(state, 0x07, in dib0070_tune_digital()
493 …(state->current_tune_table_index->switch_trim << 11) | (7 << 8) | (state->lna_match->lna_band << 3… in dib0070_tune_digital()
494 dib0070_write_reg(state, 0x08, (state->lna_match->lna_band << 10) | (3 << 7) | (127)); in dib0070_tune_digital()
495 dib0070_write_reg(state, 0x0d, 0x0d80); in dib0070_tune_digital()
498 dib0070_write_reg(state, 0x18, 0x07ff); in dib0070_tune_digital()
499 dib0070_write_reg(state, 0x17, 0x0033); in dib0070_tune_digital()
515 struct dib0070_state *state = fe->tuner_priv; in dib0070_tune() local
518 state->tune_state = CT_TUNER_START; in dib0070_tune()
526 } while (state->tune_state != CT_TUNER_STOP); in dib0070_tune()
533 struct dib0070_state *state = fe->tuner_priv; in dib0070_wakeup() local
534 if (state->cfg->sleep) in dib0070_wakeup()
535 state->cfg->sleep(fe, 0); in dib0070_wakeup()
541 struct dib0070_state *state = fe->tuner_priv; in dib0070_sleep() local
542 if (state->cfg->sleep) in dib0070_sleep()
543 state->cfg->sleep(fe, 1); in dib0070_sleep()
549 struct dib0070_state *state = fe->tuner_priv; in dib0070_get_rf_output() local
550 return (dib0070_read_reg(state, 0x07) >> 11) & 0x3; in dib0070_get_rf_output()
556 struct dib0070_state *state = fe->tuner_priv; in dib0070_set_rf_output() local
557 u16 rxrf2 = dib0070_read_reg(state, 0x07) & 0xfe7ff; in dib0070_set_rf_output()
562 return dib0070_write_reg(state, 0x07, rxrf2 | (no << 11)); in dib0070_set_rf_output()
605 static u16 dib0070_read_wbd_offset(struct dib0070_state *state, u8 gain) in dib0070_read_wbd_offset() argument
607 u16 tuner_en = dib0070_read_reg(state, 0x20); in dib0070_read_wbd_offset()
610 dib0070_write_reg(state, 0x18, 0x07ff); in dib0070_read_wbd_offset()
611 …dib0070_write_reg(state, 0x20, 0x0800 | 0x4000 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x00… in dib0070_read_wbd_offset()
612 …dib0070_write_reg(state, 0x0f, (1 << 14) | (2 << 12) | (gain << 9) | (1 << 8) | (1 << 7) | (0 << 0… in dib0070_read_wbd_offset()
614 offset = dib0070_read_reg(state, 0x19); in dib0070_read_wbd_offset()
615 dib0070_write_reg(state, 0x20, tuner_en); in dib0070_read_wbd_offset()
619 static void dib0070_wbd_offset_calibration(struct dib0070_state *state) in dib0070_wbd_offset_calibration() argument
623 state->wbd_offset_3_3[gain - 6] = ((dib0070_read_wbd_offset(state, gain) * 8 * 18 / 33 + 1) / 2); in dib0070_wbd_offset_calibration()
624 dprintk("Gain: %d, WBDOffset (3.3V) = %hd\n", gain, state->wbd_offset_3_3[gain-6]); in dib0070_wbd_offset_calibration()
630 struct dib0070_state *state = fe->tuner_priv; in dib0070_wbd_offset() local
631 const struct dib0070_wbd_gain_cfg *tmp = state->cfg->wbd_gain; in dib0070_wbd_offset()
637 state->wbd_gain_current = tmp->wbd_gain_val; in dib0070_wbd_offset()
639 state->wbd_gain_current = 6; in dib0070_wbd_offset()
641 return state->wbd_offset_3_3[state->wbd_gain_current - 6]; in dib0070_wbd_offset()
648 struct dib0070_state *state = fe->tuner_priv; in dib0070_reset() local
651 HARD_RESET(state); in dib0070_reset()
655 if ((dib0070_read_reg(state, 0x22) >> 9) & 0x1) in dib0070_reset()
656 state->revision = (dib0070_read_reg(state, 0x1f) >> 8) & 0xff; in dib0070_reset()
661 state->revision = DIB0070S_P1A; in dib0070_reset()
664 dprintk("Revision: %x\n", state->revision); in dib0070_reset()
666 if (state->revision == DIB0070_P1D) { in dib0070_reset()
676 dib0070_write_reg(state, (u8)r, pgm_read_word(n++)); in dib0070_reset()
682 if (state->cfg->force_crystal_mode != 0) in dib0070_reset()
683 r = state->cfg->force_crystal_mode; in dib0070_reset()
684 else if (state->cfg->clock_khz >= 24000) in dib0070_reset()
690 r |= state->cfg->osc_buffer_state << 3; in dib0070_reset()
692 dib0070_write_reg(state, 0x10, r); in dib0070_reset()
693 dib0070_write_reg(state, 0x1f, (1 << 8) | ((state->cfg->clock_pad_drive & 0xf) << 5)); in dib0070_reset()
695 if (state->cfg->invert_iq) { in dib0070_reset()
696 r = dib0070_read_reg(state, 0x02) & 0xffdf; in dib0070_reset()
697 dib0070_write_reg(state, 0x02, r | (1 << 5)); in dib0070_reset()
700 if (state->revision == DIB0070S_P1A) in dib0070_reset()
703 dib0070_set_ctrl_lo5(fe, 5, 4, state->cfg->charge_pump, in dib0070_reset()
704 state->cfg->enable_third_order_filter); in dib0070_reset()
706 dib0070_write_reg(state, 0x01, (54 << 9) | 0xc8); in dib0070_reset()
708 dib0070_wbd_offset_calibration(state); in dib0070_reset()
715 struct dib0070_state *state = fe->tuner_priv; in dib0070_get_frequency() local
717 *frequency = 1000 * state->current_rf; in dib0070_get_frequency()
746 struct dib0070_state *state = kzalloc(sizeof(struct dib0070_state), GFP_KERNEL); in dib0070_attach() local
747 if (state == NULL) in dib0070_attach()
750 state->cfg = cfg; in dib0070_attach()
751 state->i2c = i2c; in dib0070_attach()
752 state->fe = fe; in dib0070_attach()
753 mutex_init(&state->i2c_buffer_lock); in dib0070_attach()
754 fe->tuner_priv = state; in dib0070_attach()
762 fe->tuner_priv = state; in dib0070_attach()
766 kfree(state); in dib0070_attach()