Lines Matching refs:state

90 static int cx24113_writereg(struct cx24113_state *state, int reg, int data)  in cx24113_writereg()  argument
93 struct i2c_msg msg = { .addr = state->config->i2c_addr, in cx24113_writereg()
95 int err = i2c_transfer(state->i2c, &msg, 1); in cx24113_writereg()
105 static int cx24113_readreg(struct cx24113_state *state, u8 reg) in cx24113_readreg() argument
110 { .addr = state->config->i2c_addr, in cx24113_readreg()
112 { .addr = state->config->i2c_addr, in cx24113_readreg()
116 ret = i2c_transfer(state->i2c, msg, 2); in cx24113_readreg()
127 static void cx24113_set_parameters(struct cx24113_state *state) in cx24113_set_parameters() argument
131 r = cx24113_readreg(state, 0x10) & 0x82; in cx24113_set_parameters()
132 r |= state->icp_mode; in cx24113_set_parameters()
133 r |= state->icp_man << 4; in cx24113_set_parameters()
134 r |= state->icp_dig << 2; in cx24113_set_parameters()
135 r |= state->prescaler_mode << 5; in cx24113_set_parameters()
136 cx24113_writereg(state, 0x10, r); in cx24113_set_parameters()
138 r = (state->icp_auto_low << 0) | (state->icp_auto_mlow << 2) in cx24113_set_parameters()
139 | (state->icp_auto_mhi << 4) | (state->icp_auto_hi << 6); in cx24113_set_parameters()
140 cx24113_writereg(state, 0x11, r); in cx24113_set_parameters()
142 if (state->rev == REV_CX24113) { in cx24113_set_parameters()
143 r = cx24113_readreg(state, 0x20) & 0xec; in cx24113_set_parameters()
144 r |= state->lna_gain; in cx24113_set_parameters()
145 r |= state->rfvga_bias_ctrl << 4; in cx24113_set_parameters()
146 cx24113_writereg(state, 0x20, r); in cx24113_set_parameters()
149 r = cx24113_readreg(state, 0x12) & 0x03; in cx24113_set_parameters()
150 r |= state->acp_on << 2; in cx24113_set_parameters()
151 r |= state->bs_delay << 4; in cx24113_set_parameters()
152 cx24113_writereg(state, 0x12, r); in cx24113_set_parameters()
154 r = cx24113_readreg(state, 0x18) & 0x40; in cx24113_set_parameters()
155 r |= state->vco_shift; in cx24113_set_parameters()
156 if (state->vco_band == VCOBANDSEL_6) in cx24113_set_parameters()
159 r |= (state->vco_band << 1); in cx24113_set_parameters()
160 cx24113_writereg(state, 0x18, r); in cx24113_set_parameters()
162 r = cx24113_readreg(state, 0x14) & 0x20; in cx24113_set_parameters()
163 r |= (state->vco_mode << 6) | ((state->bs_freqcnt >> 8) & 0x1f); in cx24113_set_parameters()
164 cx24113_writereg(state, 0x14, r); in cx24113_set_parameters()
165 cx24113_writereg(state, 0x15, (state->bs_freqcnt & 0xff)); in cx24113_set_parameters()
167 cx24113_writereg(state, 0x16, (state->bs_rdiv >> 4) & 0xff); in cx24113_set_parameters()
168 r = (cx24113_readreg(state, 0x17) & 0x0f) | in cx24113_set_parameters()
169 ((state->bs_rdiv & 0x0f) << 4); in cx24113_set_parameters()
170 cx24113_writereg(state, 0x17, r); in cx24113_set_parameters()
187 static int cx24113_set_gain_settings(struct cx24113_state *state, in cx24113_set_gain_settings() argument
190 u8 ampout = cx24113_readreg(state, 0x1d) & 0xf0, in cx24113_set_gain_settings()
191 vga = cx24113_readreg(state, 0x1f) & 0x3f, in cx24113_set_gain_settings()
192 rfvga = cx24113_readreg(state, 0x20) & 0xf3; in cx24113_set_gain_settings()
193 u8 gain_level = power_estimation >= state->tuner_gain_thres; in cx24113_set_gain_settings()
196 power_estimation, state->tuner_gain_thres, in cx24113_set_gain_settings()
197 state->gain_level, gain_level); in cx24113_set_gain_settings()
199 if (gain_level == state->gain_level) in cx24113_set_gain_settings()
211 state->gain_level = gain_level; in cx24113_set_gain_settings()
213 cx24113_writereg(state, 0x1d, ampout); in cx24113_set_gain_settings()
214 cx24113_writereg(state, 0x1f, vga); in cx24113_set_gain_settings()
215 cx24113_writereg(state, 0x20, rfvga); in cx24113_set_gain_settings()
220 static int cx24113_set_Fref(struct cx24113_state *state, u8 high) in cx24113_set_Fref() argument
222 u8 xtal = cx24113_readreg(state, 0x02); in cx24113_set_Fref()
223 if (state->rev == 0x43 && state->vcodiv == VCODIV4) in cx24113_set_Fref()
229 return cx24113_writereg(state, 0x02, xtal); in cx24113_set_Fref()
232 static int cx24113_enable(struct cx24113_state *state, u8 enable) in cx24113_enable() argument
234 u8 r21 = (cx24113_readreg(state, 0x21) & 0xc0) | enable; in cx24113_enable()
235 if (state->rev == REV_CX24113) in cx24113_enable()
237 return cx24113_writereg(state, 0x21, r21); in cx24113_enable()
240 static int cx24113_set_bandwidth(struct cx24113_state *state, u32 bandwidth_khz) in cx24113_set_bandwidth() argument
262 return cx24113_writereg(state, 0x1e, r); in cx24113_set_bandwidth()
265 static int cx24113_set_clk_inversion(struct cx24113_state *state, u8 on) in cx24113_set_clk_inversion() argument
267 u8 r = (cx24113_readreg(state, 0x10) & 0x7f) | ((on & 0x1) << 7); in cx24113_set_clk_inversion()
268 return cx24113_writereg(state, 0x10, r); in cx24113_set_clk_inversion()
273 struct cx24113_state *state = fe->tuner_priv; in cx24113_get_status() local
274 u8 r = (cx24113_readreg(state, 0x10) & 0x02) >> 1; in cx24113_get_status()
281 static u8 cx24113_set_ref_div(struct cx24113_state *state, u8 refdiv) in cx24113_set_ref_div() argument
283 if (state->rev == 0x43 && state->vcodiv == VCODIV4) in cx24113_set_ref_div()
285 return state->refdiv = refdiv; in cx24113_set_ref_div()
288 static void cx24113_calc_pll_nf(struct cx24113_state *state, u16 *n, s32 *f) in cx24113_calc_pll_nf() argument
296 s32 freq_hz = state->frequency * 1000; in cx24113_calc_pll_nf()
298 if (state->config->xtal_khz < 20000) in cx24113_calc_pll_nf()
303 if (state->rev == REV_CX24113) { in cx24113_calc_pll_nf()
304 if (state->frequency >= 1100000) in cx24113_calc_pll_nf()
309 if (state->frequency >= 1165000) in cx24113_calc_pll_nf()
314 state->vcodiv = vcodiv; in cx24113_calc_pll_nf()
319 R = cx24113_set_ref_div(state, R + 1); in cx24113_calc_pll_nf()
323 N /= (state->config->xtal_khz) * factor * 2; in cx24113_calc_pll_nf()
338 do_div(dividend, state->config->xtal_khz * 1000 * factor * 2); in cx24113_calc_pll_nf()
345 if (state->Fwindow_enabled) { in cx24113_calc_pll_nf()
352 r = cx24113_readreg(state, 0x10); in cx24113_calc_pll_nf()
353 cx24113_writereg(state, 0x10, r | (1 << 6)); in cx24113_calc_pll_nf()
363 static void cx24113_set_nfr(struct cx24113_state *state, u16 n, s32 f, u8 r) in cx24113_set_nfr() argument
366 cx24113_writereg(state, 0x19, (n >> 1) & 0xff); in cx24113_set_nfr()
369 cx24113_writereg(state, 0x1a, reg); in cx24113_set_nfr()
371 cx24113_writereg(state, 0x1b, (f >> 3) & 0xff); in cx24113_set_nfr()
373 reg = cx24113_readreg(state, 0x1c) & 0x1f; in cx24113_set_nfr()
374 cx24113_writereg(state, 0x1c, reg | ((f & 0x7) << 5)); in cx24113_set_nfr()
376 cx24113_set_Fref(state, r - 1); in cx24113_set_nfr()
379 static int cx24113_set_frequency(struct cx24113_state *state, u32 frequency) in cx24113_set_frequency() argument
385 r = cx24113_readreg(state, 0x14); in cx24113_set_frequency()
386 cx24113_writereg(state, 0x14, r & 0x3f); in cx24113_set_frequency()
388 r = cx24113_readreg(state, 0x10); in cx24113_set_frequency()
389 cx24113_writereg(state, 0x10, r & 0xbf); in cx24113_set_frequency()
391 state->frequency = frequency; in cx24113_set_frequency()
395 cx24113_calc_pll_nf(state, &n, &f); in cx24113_set_frequency()
396 cx24113_set_nfr(state, n, f, state->refdiv); in cx24113_set_frequency()
398 r = cx24113_readreg(state, 0x18) & 0xbf; in cx24113_set_frequency()
399 if (state->vcodiv != VCODIV2) in cx24113_set_frequency()
401 cx24113_writereg(state, 0x18, r); in cx24113_set_frequency()
406 r = cx24113_readreg(state, 0x1c) & 0xef; in cx24113_set_frequency()
407 cx24113_writereg(state, 0x1c, r | (1 << 4)); in cx24113_set_frequency()
413 struct cx24113_state *state = fe->tuner_priv; in cx24113_init() local
416 state->tuner_gain_thres = -50; in cx24113_init()
417 state->gain_level = 255; /* to force a gain-setting initialization */ in cx24113_init()
418 state->icp_mode = 0; in cx24113_init()
420 if (state->config->xtal_khz < 11000) { in cx24113_init()
421 state->icp_auto_hi = ICP_LEVEL4; in cx24113_init()
422 state->icp_auto_mhi = ICP_LEVEL4; in cx24113_init()
423 state->icp_auto_mlow = ICP_LEVEL3; in cx24113_init()
424 state->icp_auto_low = ICP_LEVEL3; in cx24113_init()
426 state->icp_auto_hi = ICP_LEVEL4; in cx24113_init()
427 state->icp_auto_mhi = ICP_LEVEL4; in cx24113_init()
428 state->icp_auto_mlow = ICP_LEVEL3; in cx24113_init()
429 state->icp_auto_low = ICP_LEVEL2; in cx24113_init()
432 state->icp_dig = ICP_LEVEL3; in cx24113_init()
433 state->icp_man = ICP_LEVEL1; in cx24113_init()
434 state->acp_on = 1; in cx24113_init()
435 state->vco_mode = 0; in cx24113_init()
436 state->vco_shift = 0; in cx24113_init()
437 state->vco_band = VCOBANDSEL_1; in cx24113_init()
438 state->bs_delay = 8; in cx24113_init()
439 state->bs_freqcnt = 0x0fff; in cx24113_init()
440 state->bs_rdiv = 0x0fff; in cx24113_init()
441 state->prescaler_mode = 0; in cx24113_init()
442 state->lna_gain = LNA_MAX_GAIN; in cx24113_init()
443 state->rfvga_bias_ctrl = 1; in cx24113_init()
444 state->Fwindow_enabled = 1; in cx24113_init()
446 cx24113_set_Fref(state, 0); in cx24113_init()
447 cx24113_enable(state, 0x3d); in cx24113_init()
448 cx24113_set_parameters(state); in cx24113_init()
450 cx24113_set_gain_settings(state, -30); in cx24113_init()
452 cx24113_set_bandwidth(state, 18025); in cx24113_init()
453 cx24113_set_clk_inversion(state, 1); in cx24113_init()
455 if (state->config->xtal_khz >= 40000) in cx24113_init()
456 ret = cx24113_writereg(state, 0x02, in cx24113_init()
457 (cx24113_readreg(state, 0x02) & 0xfb) | (1 << 2)); in cx24113_init()
459 ret = cx24113_writereg(state, 0x02, in cx24113_init()
460 (cx24113_readreg(state, 0x02) & 0xfb) | (0 << 2)); in cx24113_init()
468 struct cx24113_state *state = fe->tuner_priv; in cx24113_set_params() local
477 cx24113_set_bandwidth(state, bw); in cx24113_set_params()
479 cx24113_set_frequency(state, c->frequency); in cx24113_set_params()
491 struct cx24113_state *state = fe->tuner_priv; in cx24113_agc_callback() local
502 if (cx24113_agc_table[state->gain_level][i] > s) in cx24113_agc_callback()
505 } while (cx24113_set_gain_settings(state, s)); in cx24113_agc_callback()
511 struct cx24113_state *state = fe->tuner_priv; in cx24113_get_frequency() local
512 *frequency = state->frequency; in cx24113_get_frequency()
518 struct cx24113_state *state = fe->tuner_priv; in cx24113_release() local
521 kfree(state); in cx24113_release()
545 struct cx24113_state *state = kzalloc(sizeof(*state), GFP_KERNEL); in cx24113_attach() local
548 if (!state) in cx24113_attach()
552 state->config = config; in cx24113_attach()
553 state->i2c = i2c; in cx24113_attach()
559 cx24113_readreg(state, 0x00); in cx24113_attach()
561 rc = cx24113_readreg(state, 0x00); in cx24113_attach()
566 state->rev = rc; in cx24113_attach()
576 cx_err("unsupported device id: %x\n", state->rev); in cx24113_attach()
579 state->ver = cx24113_readreg(state, 0x01); in cx24113_attach()
580 cx_info("version: %x\n", state->ver); in cx24113_attach()
585 fe->tuner_priv = state; in cx24113_attach()
589 kfree(state); in cx24113_attach()