Lines Matching +full:auto +full:- +full:retry
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for OR51132 (pcHDTV HD-3000) - VSB/QAM
15 * "dvb-fe-or51132-vsb.fw" and "dvb-fe-or51132-qam.fw" to
19 #define OR51132_VSB_FIRMWARE "dvb-fe-or51132-vsb.fw"
20 #define OR51132_QAM_FIRMWARE "dvb-fe-or51132-qam.fw"
63 struct i2c_msg msg = { .addr = state->config->demod_address, in or51132_writebuf()
67 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { in or51132_writebuf()
70 return -EREMOTEIO; in or51132_writebuf()
86 struct i2c_msg msg = { .addr = state->config->demod_address, in or51132_readbuf()
90 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { in or51132_readbuf()
93 return -EREMOTEIO; in or51132_readbuf()
98 /* Reads a 16-bit demod register. Returns <0 on error. */
103 {.addr = state->config->demod_address, .flags = 0, in or51132_readreg()
105 {.addr = state->config->demod_address, .flags = I2C_M_RD, in or51132_readreg()
109 if ((err = i2c_transfer(state->i2c, msg, 2)) != 2) { in or51132_readreg()
112 return -EREMOTEIO; in or51132_readreg()
119 struct or51132_state* state = fe->demodulator_priv; in or51132_load_firmware()
125 dprintk("Firmware is %zd bytes\n",fw->size); in or51132_load_firmware()
128 firmwareAsize = le32_to_cpu(*((__le32*)fw->data)); in or51132_load_firmware()
130 firmwareBsize = le32_to_cpu(*((__le32*)(fw->data+4))); in or51132_load_firmware()
134 if ((ret = or51132_writebuf(state, &fw->data[8], firmwareAsize))) { in or51132_load_firmware()
138 if ((ret = or51132_writebuf(state, &fw->data[8+firmwareAsize], in or51132_load_firmware()
178 "or51132: load_firmware error d - %d\n",i); in or51132_load_firmware()
184 "or51132: Version: %02X%02X%02X%02X-%02X%02X%02X%02X (%02X%01X-%01X-%02X%01X-%01X)\n", in or51132_load_firmware()
221 struct or51132_state* state = fe->demodulator_priv; in or51132_setmode()
225 dprintk("setmode %d\n",(int)state->current_modulation); in or51132_setmode()
227 switch (state->current_modulation) { in or51132_setmode()
229 /* Auto CH, Auto NTSC rej, MPEGser, MPEG2tr, phase noise-high */ in or51132_setmode()
237 Auto-deinterleave; MPEGser, MPEG2tr, phase noise-high in or51132_setmode()
240 /* Channel MODE Auto QAM64/256 */ in or51132_setmode()
254 state->current_modulation); in or51132_setmode()
255 return -EINVAL; in or51132_setmode()
261 return -EREMOTEIO; in or51132_setmode()
268 return -EREMOTEIO; in or51132_setmode()
296 struct dtv_frontend_properties *p = &fe->dtv_property_cache; in or51132_set_parameters()
298 struct or51132_state* state = fe->demodulator_priv; in or51132_set_parameters()
304 if (modulation_fw_class(state->current_modulation) != in or51132_set_parameters()
305 modulation_fw_class(p->modulation)) { in or51132_set_parameters()
306 switch (modulation_fw_class(p->modulation)) { in or51132_set_parameters()
311 /* Set non-punctured clock for VSB */ in or51132_set_parameters()
323 p->modulation); in or51132_set_parameters()
324 return -1; in or51132_set_parameters()
328 ret = request_firmware(&fw, fwname, state->i2c->dev.parent); in or51132_set_parameters()
340 state->config->set_ts_params(fe, clock_mode); in or51132_set_parameters()
343 if (state->current_modulation != p->modulation) { in or51132_set_parameters()
344 state->current_modulation = p->modulation; in or51132_set_parameters()
348 if (fe->ops.tuner_ops.set_params) { in or51132_set_parameters()
349 fe->ops.tuner_ops.set_params(fe); in or51132_set_parameters()
350 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); in or51132_set_parameters()
357 state->current_frequency = p->frequency; in or51132_set_parameters()
364 struct or51132_state* state = fe->demodulator_priv; in or51132_get_parameters()
366 int retry = 1; in or51132_get_parameters() local
372 return -EREMOTEIO; in or51132_get_parameters()
376 p->modulation = VSB_8; in or51132_get_parameters()
379 p->modulation = QAM_64; in or51132_get_parameters()
382 p->modulation = QAM_256; in or51132_get_parameters()
385 if (retry--) in or51132_get_parameters()
389 return -EREMOTEIO; in or51132_get_parameters()
393 p->frequency = state->current_frequency; in or51132_get_parameters()
396 p->inversion = INVERSION_AUTO; in or51132_get_parameters()
403 struct or51132_state* state = fe->demodulator_priv; in or51132_read_status()
410 return -EREMOTEIO; in or51132_read_status()
424 8-VSB SNR and QAM equations from Oren datasheets
426 For 8-VSB:
427 SNR[dB] = 10 * log10(897152044.8282 / MSE^2 ) - K
438 We re-write the snr equation as:
439 SNR * 2^24 = 10*(c - 2*intlog10(MSE))
441 and for 8-VSB and QAM64, c = log10(897152044.8282) * 2^24 */
455 return 10*(c - mse); in calculate_snr()
460 struct or51132_state* state = fe->demodulator_priv; in or51132_read_snr()
463 int retry = 1; in or51132_read_snr() local
470 return -EREMOTEIO; in or51132_read_snr()
479 return -EREMOTEIO; in or51132_read_snr()
494 if (retry--) goto start; in or51132_read_snr()
495 return -EREMOTEIO; in or51132_read_snr()
501 state->snr = calculate_snr(noise, c) - usK; in or51132_read_snr()
502 *snr = (state->snr) >> 16; in or51132_read_snr()
505 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); in or51132_read_snr()
515 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; in or51132_read_signal_strength()
519 ret = fe->ops.read_snr(fe, &snr); in or51132_read_signal_strength()
522 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */ in or51132_read_signal_strength()
523 /* scale the range 0 - 35*2^24 into 0 - 65535 */ in or51132_read_signal_strength()
524 if (state->snr >= 8960 * 0x10000) in or51132_read_signal_strength()
527 *strength = state->snr / 8960; in or51132_read_signal_strength()
534 fe_tune_settings->min_delay_ms = 500; in or51132_get_tune_settings()
535 fe_tune_settings->step_size = 0; in or51132_get_tune_settings()
536 fe_tune_settings->max_drift = 0; in or51132_get_tune_settings()
543 struct or51132_state* state = fe->demodulator_priv; in or51132_release()
560 state->config = config; in or51132_attach()
561 state->i2c = i2c; in or51132_attach()
562 state->current_frequency = -1; in or51132_attach()
563 state->current_modulation = -1; in or51132_attach()
566 memcpy(&state->frontend.ops, &or51132_ops, sizeof(struct dvb_frontend_ops)); in or51132_attach()
567 state->frontend.demodulator_priv = state; in or51132_attach()
568 return &state->frontend; in or51132_attach()
603 MODULE_DESCRIPTION("OR51132 ATSC [pcHDTV HD-3000] (8VSB & ITU J83 AnnexB FEC QAM64/256) Demodulator…