Lines Matching full:state

104 static int cx24113_writereg(struct cx24113_state *state, int reg, int data)  in cx24113_writereg()  argument
107 struct i2c_msg msg = { .addr = state->config->i2c_addr, in cx24113_writereg()
109 int err = i2c_transfer(state->i2c, &msg, 1); in cx24113_writereg()
119 static int cx24113_readreg(struct cx24113_state *state, u8 reg) in cx24113_readreg() argument
124 { .addr = state->config->i2c_addr, in cx24113_readreg()
126 { .addr = state->config->i2c_addr, in cx24113_readreg()
130 ret = i2c_transfer(state->i2c, msg, 2); in cx24113_readreg()
141 static void cx24113_set_parameters(struct cx24113_state *state) in cx24113_set_parameters() argument
145 r = cx24113_readreg(state, 0x10) & 0x82; in cx24113_set_parameters()
146 r |= state->icp_mode; in cx24113_set_parameters()
147 r |= state->icp_man << 4; in cx24113_set_parameters()
148 r |= state->icp_dig << 2; in cx24113_set_parameters()
149 r |= state->prescaler_mode << 5; in cx24113_set_parameters()
150 cx24113_writereg(state, 0x10, r); in cx24113_set_parameters()
152 r = (state->icp_auto_low << 0) | (state->icp_auto_mlow << 2) in cx24113_set_parameters()
153 | (state->icp_auto_mhi << 4) | (state->icp_auto_hi << 6); in cx24113_set_parameters()
154 cx24113_writereg(state, 0x11, r); in cx24113_set_parameters()
156 if (state->rev == REV_CX24113) { in cx24113_set_parameters()
157 r = cx24113_readreg(state, 0x20) & 0xec; in cx24113_set_parameters()
158 r |= state->lna_gain; in cx24113_set_parameters()
159 r |= state->rfvga_bias_ctrl << 4; in cx24113_set_parameters()
160 cx24113_writereg(state, 0x20, r); in cx24113_set_parameters()
163 r = cx24113_readreg(state, 0x12) & 0x03; in cx24113_set_parameters()
164 r |= state->acp_on << 2; in cx24113_set_parameters()
165 r |= state->bs_delay << 4; in cx24113_set_parameters()
166 cx24113_writereg(state, 0x12, r); in cx24113_set_parameters()
168 r = cx24113_readreg(state, 0x18) & 0x40; in cx24113_set_parameters()
169 r |= state->vco_shift; in cx24113_set_parameters()
170 if (state->vco_band == VCOBANDSEL_6) in cx24113_set_parameters()
173 r |= (state->vco_band << 1); in cx24113_set_parameters()
174 cx24113_writereg(state, 0x18, r); in cx24113_set_parameters()
176 r = cx24113_readreg(state, 0x14) & 0x20; in cx24113_set_parameters()
177 r |= (state->vco_mode << 6) | ((state->bs_freqcnt >> 8) & 0x1f); in cx24113_set_parameters()
178 cx24113_writereg(state, 0x14, r); in cx24113_set_parameters()
179 cx24113_writereg(state, 0x15, (state->bs_freqcnt & 0xff)); in cx24113_set_parameters()
181 cx24113_writereg(state, 0x16, (state->bs_rdiv >> 4) & 0xff); in cx24113_set_parameters()
182 r = (cx24113_readreg(state, 0x17) & 0x0f) | in cx24113_set_parameters()
183 ((state->bs_rdiv & 0x0f) << 4); in cx24113_set_parameters()
184 cx24113_writereg(state, 0x17, r); in cx24113_set_parameters()
201 static int cx24113_set_gain_settings(struct cx24113_state *state, in cx24113_set_gain_settings() argument
204 u8 ampout = cx24113_readreg(state, 0x1d) & 0xf0, in cx24113_set_gain_settings()
205 vga = cx24113_readreg(state, 0x1f) & 0x3f, in cx24113_set_gain_settings()
206 rfvga = cx24113_readreg(state, 0x20) & 0xf3; in cx24113_set_gain_settings()
207 u8 gain_level = power_estimation >= state->tuner_gain_thres; in cx24113_set_gain_settings()
210 power_estimation, state->tuner_gain_thres, in cx24113_set_gain_settings()
211 state->gain_level, gain_level); in cx24113_set_gain_settings()
213 if (gain_level == state->gain_level) in cx24113_set_gain_settings()
225 state->gain_level = gain_level; in cx24113_set_gain_settings()
227 cx24113_writereg(state, 0x1d, ampout); in cx24113_set_gain_settings()
228 cx24113_writereg(state, 0x1f, vga); in cx24113_set_gain_settings()
229 cx24113_writereg(state, 0x20, rfvga); in cx24113_set_gain_settings()
234 static int cx24113_set_Fref(struct cx24113_state *state, u8 high) in cx24113_set_Fref() argument
236 u8 xtal = cx24113_readreg(state, 0x02); in cx24113_set_Fref()
237 if (state->rev == 0x43 && state->vcodiv == VCODIV4) in cx24113_set_Fref()
243 return cx24113_writereg(state, 0x02, xtal); in cx24113_set_Fref()
246 static int cx24113_enable(struct cx24113_state *state, u8 enable) in cx24113_enable() argument
248 u8 r21 = (cx24113_readreg(state, 0x21) & 0xc0) | enable; in cx24113_enable()
249 if (state->rev == REV_CX24113) in cx24113_enable()
251 return cx24113_writereg(state, 0x21, r21); in cx24113_enable()
254 static int cx24113_set_bandwidth(struct cx24113_state *state, u32 bandwidth_khz) in cx24113_set_bandwidth() argument
276 return cx24113_writereg(state, 0x1e, r); in cx24113_set_bandwidth()
279 static int cx24113_set_clk_inversion(struct cx24113_state *state, u8 on) in cx24113_set_clk_inversion() argument
281 u8 r = (cx24113_readreg(state, 0x10) & 0x7f) | ((on & 0x1) << 7); in cx24113_set_clk_inversion()
282 return cx24113_writereg(state, 0x10, r); in cx24113_set_clk_inversion()
287 struct cx24113_state *state = fe->tuner_priv; in cx24113_get_status() local
288 u8 r = (cx24113_readreg(state, 0x10) & 0x02) >> 1; in cx24113_get_status()
295 static u8 cx24113_set_ref_div(struct cx24113_state *state, u8 refdiv) in cx24113_set_ref_div() argument
297 if (state->rev == 0x43 && state->vcodiv == VCODIV4) in cx24113_set_ref_div()
299 return state->refdiv = refdiv; in cx24113_set_ref_div()
302 static void cx24113_calc_pll_nf(struct cx24113_state *state, u16 *n, s32 *f) in cx24113_calc_pll_nf() argument
310 s32 freq_hz = state->frequency * 1000; in cx24113_calc_pll_nf()
312 if (state->config->xtal_khz < 20000) in cx24113_calc_pll_nf()
317 if (state->rev == REV_CX24113) { in cx24113_calc_pll_nf()
318 if (state->frequency >= 1100000) in cx24113_calc_pll_nf()
323 if (state->frequency >= 1165000) in cx24113_calc_pll_nf()
328 state->vcodiv = vcodiv; in cx24113_calc_pll_nf()
333 R = cx24113_set_ref_div(state, R + 1); in cx24113_calc_pll_nf()
337 N /= (state->config->xtal_khz) * factor * 2; in cx24113_calc_pll_nf()
352 do_div(dividend, state->config->xtal_khz * 1000 * factor * 2); in cx24113_calc_pll_nf()
359 if (state->Fwindow_enabled) { in cx24113_calc_pll_nf()
366 r = cx24113_readreg(state, 0x10); in cx24113_calc_pll_nf()
367 cx24113_writereg(state, 0x10, r | (1 << 6)); in cx24113_calc_pll_nf()
377 static void cx24113_set_nfr(struct cx24113_state *state, u16 n, s32 f, u8 r) in cx24113_set_nfr() argument
380 cx24113_writereg(state, 0x19, (n >> 1) & 0xff); in cx24113_set_nfr()
383 cx24113_writereg(state, 0x1a, reg); in cx24113_set_nfr()
385 cx24113_writereg(state, 0x1b, (f >> 3) & 0xff); in cx24113_set_nfr()
387 reg = cx24113_readreg(state, 0x1c) & 0x1f; in cx24113_set_nfr()
388 cx24113_writereg(state, 0x1c, reg | ((f & 0x7) << 5)); in cx24113_set_nfr()
390 cx24113_set_Fref(state, r - 1); in cx24113_set_nfr()
393 static int cx24113_set_frequency(struct cx24113_state *state, u32 frequency) in cx24113_set_frequency() argument
399 r = cx24113_readreg(state, 0x14); in cx24113_set_frequency()
400 cx24113_writereg(state, 0x14, r & 0x3f); in cx24113_set_frequency()
402 r = cx24113_readreg(state, 0x10); in cx24113_set_frequency()
403 cx24113_writereg(state, 0x10, r & 0xbf); in cx24113_set_frequency()
405 state->frequency = frequency; in cx24113_set_frequency()
409 cx24113_calc_pll_nf(state, &n, &f); in cx24113_set_frequency()
410 cx24113_set_nfr(state, n, f, state->refdiv); in cx24113_set_frequency()
412 r = cx24113_readreg(state, 0x18) & 0xbf; in cx24113_set_frequency()
413 if (state->vcodiv != VCODIV2) in cx24113_set_frequency()
415 cx24113_writereg(state, 0x18, r); in cx24113_set_frequency()
420 r = cx24113_readreg(state, 0x1c) & 0xef; in cx24113_set_frequency()
421 cx24113_writereg(state, 0x1c, r | (1 << 4)); in cx24113_set_frequency()
427 struct cx24113_state *state = fe->tuner_priv; in cx24113_init() local
430 state->tuner_gain_thres = -50; in cx24113_init()
431 state->gain_level = 255; /* to force a gain-setting initialization */ in cx24113_init()
432 state->icp_mode = 0; in cx24113_init()
434 if (state->config->xtal_khz < 11000) { in cx24113_init()
435 state->icp_auto_hi = ICP_LEVEL4; in cx24113_init()
436 state->icp_auto_mhi = ICP_LEVEL4; in cx24113_init()
437 state->icp_auto_mlow = ICP_LEVEL3; in cx24113_init()
438 state->icp_auto_low = ICP_LEVEL3; in cx24113_init()
440 state->icp_auto_hi = ICP_LEVEL4; in cx24113_init()
441 state->icp_auto_mhi = ICP_LEVEL4; in cx24113_init()
442 state->icp_auto_mlow = ICP_LEVEL3; in cx24113_init()
443 state->icp_auto_low = ICP_LEVEL2; in cx24113_init()
446 state->icp_dig = ICP_LEVEL3; in cx24113_init()
447 state->icp_man = ICP_LEVEL1; in cx24113_init()
448 state->acp_on = 1; in cx24113_init()
449 state->vco_mode = 0; in cx24113_init()
450 state->vco_shift = 0; in cx24113_init()
451 state->vco_band = VCOBANDSEL_1; in cx24113_init()
452 state->bs_delay = 8; in cx24113_init()
453 state->bs_freqcnt = 0x0fff; in cx24113_init()
454 state->bs_rdiv = 0x0fff; in cx24113_init()
455 state->prescaler_mode = 0; in cx24113_init()
456 state->lna_gain = LNA_MAX_GAIN; in cx24113_init()
457 state->rfvga_bias_ctrl = 1; in cx24113_init()
458 state->Fwindow_enabled = 1; in cx24113_init()
460 cx24113_set_Fref(state, 0); in cx24113_init()
461 cx24113_enable(state, 0x3d); in cx24113_init()
462 cx24113_set_parameters(state); in cx24113_init()
464 cx24113_set_gain_settings(state, -30); in cx24113_init()
466 cx24113_set_bandwidth(state, 18025); in cx24113_init()
467 cx24113_set_clk_inversion(state, 1); in cx24113_init()
469 if (state->config->xtal_khz >= 40000) in cx24113_init()
470 ret = cx24113_writereg(state, 0x02, in cx24113_init()
471 (cx24113_readreg(state, 0x02) & 0xfb) | (1 << 2)); in cx24113_init()
473 ret = cx24113_writereg(state, 0x02, in cx24113_init()
474 (cx24113_readreg(state, 0x02) & 0xfb) | (0 << 2)); in cx24113_init()
482 struct cx24113_state *state = fe->tuner_priv; in cx24113_set_params() local
491 cx24113_set_bandwidth(state, bw); in cx24113_set_params()
493 cx24113_set_frequency(state, c->frequency); in cx24113_set_params()
505 struct cx24113_state *state = fe->tuner_priv; in cx24113_agc_callback() local
516 if (cx24113_agc_table[state->gain_level][i] > s) in cx24113_agc_callback()
519 } while (cx24113_set_gain_settings(state, s)); in cx24113_agc_callback()
525 struct cx24113_state *state = fe->tuner_priv; in cx24113_get_frequency() local
526 *frequency = state->frequency; in cx24113_get_frequency()
532 struct cx24113_state *state = fe->tuner_priv; in cx24113_release() local
535 kfree(state); in cx24113_release()
559 /* allocate memory for the internal state */ in cx24113_attach()
560 struct cx24113_state *state = in cx24113_attach() local
563 if (state == NULL) { in cx24113_attach()
568 /* setup the state */ in cx24113_attach()
569 state->config = config; in cx24113_attach()
570 state->i2c = i2c; in cx24113_attach()
576 cx24113_readreg(state, 0x00); in cx24113_attach()
578 rc = cx24113_readreg(state, 0x00); in cx24113_attach()
583 state->rev = rc; in cx24113_attach()
593 cx_err("unsupported device id: %x\n", state->rev); in cx24113_attach()
596 state->ver = cx24113_readreg(state, 0x01); in cx24113_attach()
597 cx_info("version: %x\n", state->ver); in cx24113_attach()
602 fe->tuner_priv = state; in cx24113_attach()
606 kfree(state); in cx24113_attach()