Lines Matching defs:state

42 #define dprintk(state, fmt, arg...) do {				\
44 dev_printk(KERN_DEBUG, &state->client->dev, fmt, ##arg);\
65 static int i2c_write_demod_bytes(struct lgdt330x_state *state,
73 err = i2c_master_send(state->client, buf, 2);
75 dev_warn(&state->client->dev,
92 static int i2c_read_demod_bytes(struct lgdt330x_state *state,
98 .addr = state->client->addr,
103 .addr = state->client->addr,
111 ret = i2c_transfer(state->client->adapter, msg, 2);
113 dev_warn(&state->client->dev,
115 __func__, state->client->addr, reg, ret);
125 static int lgdt3302_sw_reset(struct lgdt330x_state *state)
137 ret = i2c_write_demod_bytes(state,
142 ret = i2c_write_demod_bytes(state,
148 static int lgdt3303_sw_reset(struct lgdt330x_state *state)
156 ret = i2c_write_demod_bytes(state,
161 ret = i2c_write_demod_bytes(state,
167 static int lgdt330x_sw_reset(struct lgdt330x_state *state)
169 switch (state->config.demod_chip) {
171 return lgdt3302_sw_reset(state);
173 return lgdt3303_sw_reset(state);
181 struct lgdt330x_state *state = fe->demodulator_priv;
254 switch (state->config.demod_chip) {
257 err = i2c_write_demod_bytes(state, lgdt3302_init_data,
262 switch (state->config.clock_polarity_flip) {
264 err = i2c_write_demod_bytes(state,
269 err = i2c_write_demod_bytes(state,
275 err = i2c_write_demod_bytes(state, lgdt3303_init_data,
281 dev_warn(&state->client->dev,
285 dprintk(state, "Initialized the %s chip\n", chip_name);
295 state->last_stats_time = 0;
297 return lgdt330x_sw_reset(state);
302 struct lgdt330x_state *state = fe->demodulator_priv;
304 *ucblocks = state->ucblocks;
312 struct lgdt330x_state *state = fe->demodulator_priv;
346 if (state->current_modulation != p->modulation) {
349 dprintk(state, "VSB_8 MODE\n");
355 if (state->config.pll_rf_set)
356 state->config.pll_rf_set(fe, 1);
358 if (state->config.demod_chip == LGDT3303) {
359 err = i2c_write_demod_bytes(state,
366 dprintk(state, "QAM_64 MODE\n");
372 if (state->config.pll_rf_set)
373 state->config.pll_rf_set(fe, 0);
375 if (state->config.demod_chip == LGDT3303) {
376 err = i2c_write_demod_bytes(state,
383 dprintk(state, "QAM_256 MODE\n");
389 if (state->config.pll_rf_set)
390 state->config.pll_rf_set(fe, 0);
392 if (state->config.demod_chip == LGDT3303) {
393 err = i2c_write_demod_bytes(state,
399 dev_warn(&state->client->dev,
405 dev_warn(&state->client->dev,
414 top_ctrl_cfg[1] |= state->config.serial_mpeg;
417 i2c_write_demod_bytes(state, top_ctrl_cfg,
419 if (state->config.set_ts_params)
420 state->config.set_ts_params(fe, 0);
421 state->current_modulation = p->modulation;
436 state->current_frequency = p->frequency;
438 lgdt330x_sw_reset(state);
445 struct lgdt330x_state *state = fe->demodulator_priv;
447 p->frequency = state->current_frequency;
494 struct lgdt330x_state *state = fe->demodulator_priv;
499 switch (state->current_modulation) {
501 i2c_read_demod_bytes(state, LGDT3302_EQPH_ERR0, buf, 5);
516 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
518 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
522 dev_err(&state->client->dev,
526 state->snr = 0;
531 state->snr = calculate_snr(noise, c);
533 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
534 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
541 struct lgdt330x_state *state = fe->demodulator_priv;
546 switch (state->current_modulation) {
548 i2c_read_demod_bytes(state, LGDT3303_EQPH_ERR0, buf, 5);
563 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
565 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
569 dev_err(&state->client->dev,
572 state->snr = 0;
576 state->snr = calculate_snr(noise, c);
578 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
579 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
586 struct lgdt330x_state *state = fe->demodulator_priv;
588 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */
600 struct lgdt330x_state *state = fe->demodulator_priv;
607 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
609 if (state->snr >= 8960 * 0x10000)
612 *strength = state->snr / 8960;
621 struct lgdt330x_state *state = fe->demodulator_priv;
629 i2c_read_demod_bytes(state, AGC_STATUS, buf, 1);
630 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
646 i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf));
647 dprintk(state,
660 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
661 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
662 switch (state->current_modulation) {
674 dev_warn(&state->client->dev,
686 if (state->last_stats_time &&
687 time_is_after_jiffies(state->last_stats_time))
690 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
695 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
700 err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1,
703 state->ucblocks = (buf[0] << 8) | buf[1];
705 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
707 p->block_error.stat[0].uvalue += state->ucblocks;
724 struct lgdt330x_state *state = fe->demodulator_priv;
732 err = i2c_read_demod_bytes(state, 0x58, buf, 1);
736 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
746 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
747 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
748 switch (state->current_modulation) {
756 i2c_read_demod_bytes(state, 0x8a, buf, 1);
757 dprintk(state, "QAM LOCK = 0x%02x\n", buf[0]);
771 i2c_read_demod_bytes(state, 0x38, buf, 1);
772 dprintk(state, "8-VSB LOCK = 0x%02x\n", buf[0]);
780 dev_warn(&state->client->dev,
792 if (state->last_stats_time &&
793 time_is_after_jiffies(state->last_stats_time))
796 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
801 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
806 err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1,
809 state->ucblocks = (buf[0] << 8) | buf[1];
811 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
813 p->block_error.stat[0].uvalue += state->ucblocks;
840 struct lgdt330x_state *state = fe->demodulator_priv;
841 struct i2c_client *client = state->client;
850 struct lgdt330x_state *state = i2c_get_clientdata(client);
854 return &state->frontend;
863 struct lgdt330x_state *state = NULL;
866 /* Allocate memory for the internal state */
867 state = kzalloc(sizeof(*state), GFP_KERNEL);
868 if (!state)
871 /* Setup the state */
872 memcpy(&state->config, client->dev.platform_data,
873 sizeof(state->config));
874 i2c_set_clientdata(client, state);
875 state->client = client;
878 switch (state->config.demod_chip) {
880 memcpy(&state->frontend.ops, &lgdt3302_ops,
884 memcpy(&state->frontend.ops, &lgdt3303_ops,
890 state->frontend.demodulator_priv = state;
893 state->config.get_dvb_frontend = lgdt330x_get_dvb_frontend;
896 if (i2c_read_demod_bytes(state, 2, buf, 1))
899 state->current_frequency = -1;
900 state->current_modulation = -1;
902 dev_info(&state->client->dev,
904 state->config.demod_chip == LGDT3302 ? "2" : "3");
909 kfree(state);
979 struct lgdt330x_state *state = i2c_get_clientdata(client);
983 kfree(state);