Lines Matching full:state

51 static int stv0297_writereg(struct stv0297_state *state, u8 reg, u8 data)  in stv0297_writereg()  argument
55 struct i2c_msg msg = {.addr = state->config->demod_address,.flags = 0,.buf = buf,.len = 2 }; in stv0297_writereg()
57 ret = i2c_transfer(state->i2c, &msg, 1); in stv0297_writereg()
66 static int stv0297_readreg(struct stv0297_state *state, u8 reg) in stv0297_readreg() argument
71 struct i2c_msg msg[] = { {.addr = state->config->demod_address,.flags = 0,.buf = b0,.len = 1}, in stv0297_readreg()
72 {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = b1,.len = 1} in stv0297_readreg()
76 if (state->config->stop_during_read) { in stv0297_readreg()
77 if ((ret = i2c_transfer(state->i2c, &msg[0], 1)) != 1) { in stv0297_readreg()
81 if ((ret = i2c_transfer(state->i2c, &msg[1], 1)) != 1) { in stv0297_readreg()
86 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) { in stv0297_readreg()
95 static int stv0297_writereg_mask(struct stv0297_state *state, u8 reg, u8 mask, u8 data) in stv0297_writereg_mask() argument
99 val = stv0297_readreg(state, reg); in stv0297_writereg_mask()
102 stv0297_writereg(state, reg, val); in stv0297_writereg_mask()
107 static int stv0297_readregs(struct stv0297_state *state, u8 reg1, u8 * b, u8 len) in stv0297_readregs() argument
110 struct i2c_msg msg[] = { {.addr = state->config->demod_address,.flags = 0,.buf = in stv0297_readregs()
112 {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = b,.len = len} in stv0297_readregs()
116 if (state->config->stop_during_read) { in stv0297_readregs()
117 if ((ret = i2c_transfer(state->i2c, &msg[0], 1)) != 1) { in stv0297_readregs()
121 if ((ret = i2c_transfer(state->i2c, &msg[1], 1)) != 1) { in stv0297_readregs()
126 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) { in stv0297_readregs()
135 static u32 stv0297_get_symbolrate(struct stv0297_state *state) in stv0297_get_symbolrate() argument
139 tmp = stv0297_readreg(state, 0x55); in stv0297_get_symbolrate()
140 tmp |= stv0297_readreg(state, 0x56) << 8; in stv0297_get_symbolrate()
141 tmp |= stv0297_readreg(state, 0x57) << 16; in stv0297_get_symbolrate()
142 tmp |= stv0297_readreg(state, 0x58) << 24; in stv0297_get_symbolrate()
150 static void stv0297_set_symbolrate(struct stv0297_state *state, u32 srate) in stv0297_set_symbolrate() argument
158 stv0297_writereg(state, 0x55, (unsigned char) (tmp & 0xFF)); in stv0297_set_symbolrate()
159 stv0297_writereg(state, 0x56, (unsigned char) (tmp >> 8)); in stv0297_set_symbolrate()
160 stv0297_writereg(state, 0x57, (unsigned char) (tmp >> 16)); in stv0297_set_symbolrate()
161 stv0297_writereg(state, 0x58, (unsigned char) (tmp >> 24)); in stv0297_set_symbolrate()
164 static void stv0297_set_sweeprate(struct stv0297_state *state, short fshift, long symrate) in stv0297_set_sweeprate() argument
180 stv0297_writereg(state, 0x60, tmp & 0xFF); in stv0297_set_sweeprate()
181 stv0297_writereg_mask(state, 0x69, 0xF0, (tmp >> 4) & 0xf0); in stv0297_set_sweeprate()
184 static void stv0297_set_carrieroffset(struct stv0297_state *state, long offset) in stv0297_set_carrieroffset() argument
194 stv0297_writereg(state, 0x66, (unsigned char) (tmp & 0xFF)); in stv0297_set_carrieroffset()
195 stv0297_writereg(state, 0x67, (unsigned char) (tmp >> 8)); in stv0297_set_carrieroffset()
196 stv0297_writereg(state, 0x68, (unsigned char) (tmp >> 16)); in stv0297_set_carrieroffset()
197 stv0297_writereg_mask(state, 0x69, 0x0F, (tmp >> 24) & 0x0f); in stv0297_set_carrieroffset()
201 static long stv0297_get_carrieroffset(struct stv0297_state *state)
205 stv0297_writereg(state, 0x6B, 0x00);
207 tmp = stv0297_readreg(state, 0x66);
208 tmp |= (stv0297_readreg(state, 0x67) << 8);
209 tmp |= (stv0297_readreg(state, 0x68) << 16);
210 tmp |= (stv0297_readreg(state, 0x69) & 0x0F) << 24;
212 tmp *= stv0297_get_symbolrate(state);
219 static void stv0297_set_initialdemodfreq(struct stv0297_state *state, long freq) in stv0297_set_initialdemodfreq() argument
231 stv0297_writereg_mask(state, 0x25, 0x80, 0x80); in stv0297_set_initialdemodfreq()
232 stv0297_writereg(state, 0x21, tmp >> 8); in stv0297_set_initialdemodfreq()
233 stv0297_writereg(state, 0x20, tmp); in stv0297_set_initialdemodfreq()
236 static int stv0297_set_qam(struct stv0297_state *state, fe_modulation_t modulation) in stv0297_set_qam() argument
265 stv0297_writereg_mask(state, 0x00, 0x70, val << 4); in stv0297_set_qam()
270 static int stv0297_set_inversion(struct stv0297_state *state, fe_spectral_inversion_t inversion) in stv0297_set_inversion() argument
287 stv0297_writereg_mask(state, 0x83, 0x08, val << 3); in stv0297_set_inversion()
294 struct stv0297_state *state = fe->demodulator_priv; in stv0297_i2c_gate_ctrl() local
297 stv0297_writereg(state, 0x87, 0x78); in stv0297_i2c_gate_ctrl()
298 stv0297_writereg(state, 0x86, 0xc8); in stv0297_i2c_gate_ctrl()
306 struct stv0297_state *state = fe->demodulator_priv; in stv0297_init() local
310 for (i=0; !(state->config->inittab[i] == 0xff && state->config->inittab[i+1] == 0xff); i+=2) in stv0297_init()
311 stv0297_writereg(state, state->config->inittab[i], state->config->inittab[i+1]); in stv0297_init()
314 state->last_ber = 0; in stv0297_init()
321 struct stv0297_state *state = fe->demodulator_priv; in stv0297_sleep() local
323 stv0297_writereg_mask(state, 0x80, 1, 1); in stv0297_sleep()
330 struct stv0297_state *state = fe->demodulator_priv; in stv0297_read_status() local
332 u8 sync = stv0297_readreg(state, 0xDF); in stv0297_read_status()
343 struct stv0297_state *state = fe->demodulator_priv; in stv0297_read_ber() local
346 stv0297_readregs(state, 0xA0, BER, 3); in stv0297_read_ber()
348 state->last_ber = BER[2] << 8 | BER[1]; in stv0297_read_ber()
349 stv0297_writereg_mask(state, 0xA0, 0x80, 0x80); in stv0297_read_ber()
352 *ber = state->last_ber; in stv0297_read_ber()
360 struct stv0297_state *state = fe->demodulator_priv; in stv0297_read_signal_strength() local
364 stv0297_readregs(state, 0x41, STRENGTH, 3); in stv0297_read_signal_strength()
383 struct stv0297_state *state = fe->demodulator_priv; in stv0297_read_snr() local
386 stv0297_readregs(state, 0x07, SNR, 2); in stv0297_read_snr()
394 struct stv0297_state *state = fe->demodulator_priv; in stv0297_read_ucblocks() local
396 stv0297_writereg_mask(state, 0xDF, 0x03, 0x03); /* freeze the counters */ in stv0297_read_ucblocks()
398 *ucblocks = (stv0297_readreg(state, 0xD5) << 8) in stv0297_read_ucblocks()
399 | stv0297_readreg(state, 0xD4); in stv0297_read_ucblocks()
401 stv0297_writereg_mask(state, 0xDF, 0x03, 0x02); /* clear the counters */ in stv0297_read_ucblocks()
402 stv0297_writereg_mask(state, 0xDF, 0x03, 0x01); /* re-enable the counters */ in stv0297_read_ucblocks()
410 struct stv0297_state *state = fe->demodulator_priv; in stv0297_set_frontend() local
441 if (state->config->invert) in stv0297_set_frontend()
464 stv0297_writereg(state, 0x82, 0x0); in stv0297_set_frontend()
467 stv0297_set_initialdemodfreq(state, 7250); in stv0297_set_frontend()
470 stv0297_writereg_mask(state, 0x43, 0x10, 0x00); in stv0297_set_frontend()
471 stv0297_writereg(state, 0x41, 0x00); in stv0297_set_frontend()
472 stv0297_writereg_mask(state, 0x42, 0x03, 0x01); in stv0297_set_frontend()
473 stv0297_writereg_mask(state, 0x36, 0x60, 0x00); in stv0297_set_frontend()
474 stv0297_writereg_mask(state, 0x36, 0x18, 0x00); in stv0297_set_frontend()
475 stv0297_writereg_mask(state, 0x71, 0x80, 0x80); in stv0297_set_frontend()
476 stv0297_writereg(state, 0x72, 0x00); in stv0297_set_frontend()
477 stv0297_writereg(state, 0x73, 0x00); in stv0297_set_frontend()
478 stv0297_writereg_mask(state, 0x74, 0x0F, 0x00); in stv0297_set_frontend()
479 stv0297_writereg_mask(state, 0x43, 0x08, 0x00); in stv0297_set_frontend()
480 stv0297_writereg_mask(state, 0x71, 0x80, 0x00); in stv0297_set_frontend()
483 stv0297_writereg_mask(state, 0x5a, 0x20, 0x20); in stv0297_set_frontend()
484 stv0297_writereg_mask(state, 0x5b, 0x02, 0x02); in stv0297_set_frontend()
485 stv0297_writereg_mask(state, 0x5b, 0x02, 0x00); in stv0297_set_frontend()
486 stv0297_writereg_mask(state, 0x5b, 0x01, 0x00); in stv0297_set_frontend()
487 stv0297_writereg_mask(state, 0x5a, 0x40, 0x40); in stv0297_set_frontend()
490 stv0297_writereg_mask(state, 0x6a, 0x01, 0x00); in stv0297_set_frontend()
493 stv0297_writereg_mask(state, 0x81, 0x01, 0x01); in stv0297_set_frontend()
494 stv0297_writereg_mask(state, 0x81, 0x01, 0x00); in stv0297_set_frontend()
497 stv0297_writereg_mask(state, 0x83, 0x20, 0x20); in stv0297_set_frontend()
498 stv0297_writereg_mask(state, 0x83, 0x20, 0x00); in stv0297_set_frontend()
501 u_threshold = stv0297_readreg(state, 0x00) & 0xf; in stv0297_set_frontend()
502 initial_u = stv0297_readreg(state, 0x01) >> 4; in stv0297_set_frontend()
503 blind_u = stv0297_readreg(state, 0x01) & 0xf; in stv0297_set_frontend()
504 stv0297_writereg_mask(state, 0x84, 0x01, 0x01); in stv0297_set_frontend()
505 stv0297_writereg_mask(state, 0x84, 0x01, 0x00); in stv0297_set_frontend()
506 stv0297_writereg_mask(state, 0x00, 0x0f, u_threshold); in stv0297_set_frontend()
507 stv0297_writereg_mask(state, 0x01, 0xf0, initial_u << 4); in stv0297_set_frontend()
508 stv0297_writereg_mask(state, 0x01, 0x0f, blind_u); in stv0297_set_frontend()
511 stv0297_writereg_mask(state, 0x87, 0x80, 0x00); in stv0297_set_frontend()
514 stv0297_writereg(state, 0x63, 0x00); in stv0297_set_frontend()
515 stv0297_writereg(state, 0x64, 0x00); in stv0297_set_frontend()
516 stv0297_writereg(state, 0x65, 0x00); in stv0297_set_frontend()
517 stv0297_writereg(state, 0x66, 0x00); in stv0297_set_frontend()
518 stv0297_writereg(state, 0x67, 0x00); in stv0297_set_frontend()
519 stv0297_writereg(state, 0x68, 0x00); in stv0297_set_frontend()
520 stv0297_writereg_mask(state, 0x69, 0x0f, 0x00); in stv0297_set_frontend()
523 stv0297_set_qam(state, p->modulation); in stv0297_set_frontend()
524 stv0297_set_symbolrate(state, p->symbol_rate / 1000); in stv0297_set_frontend()
525 stv0297_set_sweeprate(state, sweeprate, p->symbol_rate / 1000); in stv0297_set_frontend()
526 stv0297_set_carrieroffset(state, carrieroffset); in stv0297_set_frontend()
527 stv0297_set_inversion(state, inversion); in stv0297_set_frontend()
533 stv0297_writereg_mask(state, 0x88, 0x08, 0x00); in stv0297_set_frontend()
535 stv0297_writereg_mask(state, 0x88, 0x08, 0x08); in stv0297_set_frontend()
537 stv0297_writereg_mask(state, 0x5a, 0x20, 0x00); in stv0297_set_frontend()
538 stv0297_writereg_mask(state, 0x6a, 0x01, 0x01); in stv0297_set_frontend()
539 stv0297_writereg_mask(state, 0x43, 0x40, 0x40); in stv0297_set_frontend()
540 stv0297_writereg_mask(state, 0x5b, 0x30, 0x00); in stv0297_set_frontend()
541 stv0297_writereg_mask(state, 0x03, 0x0c, 0x0c); in stv0297_set_frontend()
542 stv0297_writereg_mask(state, 0x03, 0x03, 0x03); in stv0297_set_frontend()
543 stv0297_writereg_mask(state, 0x43, 0x10, 0x10); in stv0297_set_frontend()
550 if (stv0297_readreg(state, 0x43) & 0x08) in stv0297_set_frontend()
563 if (stv0297_readreg(state, 0x82) & 0x04) { in stv0297_set_frontend()
576 if (stv0297_readreg(state, 0x82) & 0x08) { in stv0297_set_frontend()
585 stv0297_writereg_mask(state, 0x6a, 1, 0); in stv0297_set_frontend()
586 stv0297_writereg_mask(state, 0x88, 8, 0); in stv0297_set_frontend()
593 if (stv0297_readreg(state, 0xDF) & 0x80) { in stv0297_set_frontend()
603 if (!(stv0297_readreg(state, 0xDF) & 0x80)) { in stv0297_set_frontend()
608 stv0297_writereg_mask(state, 0x5a, 0x40, 0x00); in stv0297_set_frontend()
609 state->base_freq = p->frequency; in stv0297_set_frontend()
613 stv0297_writereg_mask(state, 0x6a, 0x01, 0x00); in stv0297_set_frontend()
620 struct stv0297_state *state = fe->demodulator_priv; in stv0297_get_frontend() local
623 reg_00 = stv0297_readreg(state, 0x00); in stv0297_get_frontend()
624 reg_83 = stv0297_readreg(state, 0x83); in stv0297_get_frontend()
626 p->frequency = state->base_freq; in stv0297_get_frontend()
628 if (state->config->invert) in stv0297_get_frontend()
630 p->symbol_rate = stv0297_get_symbolrate(state) * 1000; in stv0297_get_frontend()
656 struct stv0297_state *state = fe->demodulator_priv; in stv0297_release() local
657 kfree(state); in stv0297_release()
665 struct stv0297_state *state = NULL; in stv0297_attach() local
667 /* allocate memory for the internal state */ in stv0297_attach()
668 state = kzalloc(sizeof(struct stv0297_state), GFP_KERNEL); in stv0297_attach()
669 if (state == NULL) in stv0297_attach()
672 /* setup the state */ in stv0297_attach()
673 state->config = config; in stv0297_attach()
674 state->i2c = i2c; in stv0297_attach()
675 state->last_ber = 0; in stv0297_attach()
676 state->base_freq = 0; in stv0297_attach()
679 if ((stv0297_readreg(state, 0x80) & 0x70) != 0x20) in stv0297_attach()
683 memcpy(&state->frontend.ops, &stv0297_ops, sizeof(struct dvb_frontend_ops)); in stv0297_attach()
684 state->frontend.demodulator_priv = state; in stv0297_attach()
685 return &state->frontend; in stv0297_attach()
688 kfree(state); in stv0297_attach()