Lines Matching +full:default +full:- +full:state
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Zarlink DVB-T MT352 demodulator
8 * AVerMedia AVerTV DVB-T 771 support by
15 * DVICO FusionHDTV DVB-T1 and DVICO FusionHDTV DVB-T Lite support by
46 struct mt352_state* state = fe->demodulator_priv; in mt352_single_write() local
48 struct i2c_msg msg = { .addr = state->config.demod_address, .flags = 0, in mt352_single_write()
50 int err = i2c_transfer(state->i2c, &msg, 1); in mt352_single_write()
61 for (i=0; i < ilen-1; i++) in _mt352_write()
68 static int mt352_read_register(struct mt352_state* state, u8 reg) in mt352_read_register() argument
73 struct i2c_msg msg [] = { { .addr = state->config.demod_address, in mt352_read_register()
76 { .addr = state->config.demod_address, in mt352_read_register()
80 ret = i2c_transfer(state->i2c, msg, 2); in mt352_read_register()
99 static void mt352_calc_nominal_rate(struct mt352_state* state, in mt352_calc_nominal_rate() argument
114 default: in mt352_calc_nominal_rate()
118 if (state->config.adc_clock) in mt352_calc_nominal_rate()
119 adc_clock = state->config.adc_clock; in mt352_calc_nominal_rate()
129 static void mt352_calc_input_freq(struct mt352_state* state, in mt352_calc_input_freq() argument
136 if (state->config.adc_clock) in mt352_calc_input_freq()
137 adc_clock = state->config.adc_clock; in mt352_calc_input_freq()
138 if (state->config.if2) in mt352_calc_input_freq()
139 if2 = state->config.if2; in mt352_calc_input_freq()
144 ife = adc_clock - (if2 % adc_clock); in mt352_calc_input_freq()
146 ife = adc_clock - ife; in mt352_calc_input_freq()
148 value = -16374 * ife / adc_clock; in mt352_calc_input_freq()
157 struct dtv_frontend_properties *op = &fe->dtv_property_cache; in mt352_set_parameters()
158 struct mt352_state* state = fe->demodulator_priv; in mt352_set_parameters() local
164 switch (op->code_rate_HP) { in mt352_set_parameters()
180 default: in mt352_set_parameters()
181 return -EINVAL; in mt352_set_parameters()
184 switch (op->code_rate_LP) { in mt352_set_parameters()
201 if (op->hierarchy == HIERARCHY_AUTO || in mt352_set_parameters()
202 op->hierarchy == HIERARCHY_NONE) in mt352_set_parameters()
205 default: in mt352_set_parameters()
206 return -EINVAL; in mt352_set_parameters()
209 switch (op->modulation) { in mt352_set_parameters()
219 default: in mt352_set_parameters()
220 return -EINVAL; in mt352_set_parameters()
223 switch (op->transmission_mode) { in mt352_set_parameters()
230 default: in mt352_set_parameters()
231 return -EINVAL; in mt352_set_parameters()
234 switch (op->guard_interval) { in mt352_set_parameters()
247 default: in mt352_set_parameters()
248 return -EINVAL; in mt352_set_parameters()
251 switch (op->hierarchy) { in mt352_set_parameters()
264 default: in mt352_set_parameters()
265 return -EINVAL; in mt352_set_parameters()
277 mt352_calc_nominal_rate(state, op->bandwidth_hz, buf+4); in mt352_set_parameters()
278 mt352_calc_input_freq(state, buf+6); in mt352_set_parameters()
280 if (state->config.no_tuner) { in mt352_set_parameters()
281 if (fe->ops.tuner_ops.set_params) { in mt352_set_parameters()
282 fe->ops.tuner_ops.set_params(fe); in mt352_set_parameters()
283 if (fe->ops.i2c_gate_ctrl) in mt352_set_parameters()
284 fe->ops.i2c_gate_ctrl(fe, 0); in mt352_set_parameters()
290 if (fe->ops.tuner_ops.calc_regs) { in mt352_set_parameters()
291 fe->ops.tuner_ops.calc_regs(fe, buf+8, 5); in mt352_set_parameters()
304 struct mt352_state* state = fe->demodulator_priv; in mt352_get_parameters() local
320 if ( (mt352_read_register(state,0x00) & 0xC0) != 0xC0 ) in mt352_get_parameters()
321 return -EINVAL; in mt352_get_parameters()
323 /* Use TPS_RECEIVED-registers, not the TPS_CURRENT-registers because in mt352_get_parameters()
326 …tps = (mt352_read_register(state, TPS_RECEIVED_1) << 8) | mt352_read_register(state, TPS_RECEIVED_… in mt352_get_parameters()
327 div = (mt352_read_register(state, CHAN_START_1) << 8) | mt352_read_register(state, CHAN_START_0); in mt352_get_parameters()
328 trl = mt352_read_register(state, TRL_NOMINAL_RATE_1); in mt352_get_parameters()
330 op->code_rate_HP = tps_fec_to_api[(tps >> 7) & 7]; in mt352_get_parameters()
331 op->code_rate_LP = tps_fec_to_api[(tps >> 4) & 7]; in mt352_get_parameters()
336 op->modulation = QPSK; in mt352_get_parameters()
339 op->modulation = QAM_16; in mt352_get_parameters()
342 op->modulation = QAM_64; in mt352_get_parameters()
344 default: in mt352_get_parameters()
345 op->modulation = QAM_AUTO; in mt352_get_parameters()
349 op->transmission_mode = (tps & 0x01) ? TRANSMISSION_MODE_8K : TRANSMISSION_MODE_2K; in mt352_get_parameters()
354 op->guard_interval = GUARD_INTERVAL_1_32; in mt352_get_parameters()
357 op->guard_interval = GUARD_INTERVAL_1_16; in mt352_get_parameters()
360 op->guard_interval = GUARD_INTERVAL_1_8; in mt352_get_parameters()
363 op->guard_interval = GUARD_INTERVAL_1_4; in mt352_get_parameters()
365 default: in mt352_get_parameters()
366 op->guard_interval = GUARD_INTERVAL_AUTO; in mt352_get_parameters()
373 op->hierarchy = HIERARCHY_NONE; in mt352_get_parameters()
376 op->hierarchy = HIERARCHY_1; in mt352_get_parameters()
379 op->hierarchy = HIERARCHY_2; in mt352_get_parameters()
382 op->hierarchy = HIERARCHY_4; in mt352_get_parameters()
384 default: in mt352_get_parameters()
385 op->hierarchy = HIERARCHY_AUTO; in mt352_get_parameters()
389 op->frequency = (500 * (div - IF_FREQUENCYx6)) / 3 * 1000; in mt352_get_parameters()
392 op->bandwidth_hz = 8000000; in mt352_get_parameters()
394 op->bandwidth_hz = 7000000; in mt352_get_parameters()
396 op->bandwidth_hz = 6000000; in mt352_get_parameters()
399 if (mt352_read_register(state, STATUS_2) & 0x02) in mt352_get_parameters()
400 op->inversion = INVERSION_OFF; in mt352_get_parameters()
402 op->inversion = INVERSION_ON; in mt352_get_parameters()
409 struct mt352_state* state = fe->demodulator_priv; in mt352_read_status() local
414 * The MT352 design manual from Zarlink states (page 46-47): in mt352_read_status()
418 * If the Read_Tuner_Byte (bit-1) is activated, then the tuner status in mt352_read_status()
420 * completion of the read operation is indicated by bit-5 of the in mt352_read_status()
424 if ((s0 = mt352_read_register(state, STATUS_0)) < 0) in mt352_read_status()
425 return -EREMOTEIO; in mt352_read_status()
426 if ((s1 = mt352_read_register(state, STATUS_1)) < 0) in mt352_read_status()
427 return -EREMOTEIO; in mt352_read_status()
428 if ((s3 = mt352_read_register(state, STATUS_3)) < 0) in mt352_read_status()
429 return -EREMOTEIO; in mt352_read_status()
452 struct mt352_state* state = fe->demodulator_priv; in mt352_read_ber() local
454 *ber = (mt352_read_register (state, RS_ERR_CNT_2) << 16) | in mt352_read_ber()
455 (mt352_read_register (state, RS_ERR_CNT_1) << 8) | in mt352_read_ber()
456 (mt352_read_register (state, RS_ERR_CNT_0)); in mt352_read_ber()
463 struct mt352_state* state = fe->demodulator_priv; in mt352_read_signal_strength() local
466 u16 signal = ((mt352_read_register(state, AGC_GAIN_1) & 0x0f) << 12) | in mt352_read_signal_strength()
467 (mt352_read_register(state, AGC_GAIN_0) << 4); in mt352_read_signal_strength()
476 struct mt352_state* state = fe->demodulator_priv; in mt352_read_snr() local
478 u8 _snr = mt352_read_register (state, SNR); in mt352_read_snr()
486 struct mt352_state* state = fe->demodulator_priv; in mt352_read_ucblocks() local
488 *ucblocks = (mt352_read_register (state, RS_UBC_1) << 8) | in mt352_read_ucblocks()
489 (mt352_read_register (state, RS_UBC_0)); in mt352_read_ucblocks()
496 fe_tune_settings->min_delay_ms = 800; in mt352_get_tune_settings()
497 fe_tune_settings->step_size = 0; in mt352_get_tune_settings()
498 fe_tune_settings->max_drift = 0; in mt352_get_tune_settings()
505 struct mt352_state* state = fe->demodulator_priv; in mt352_init() local
511 if ((mt352_read_register(state, CLOCK_CTL) & 0x10) == 0 || in mt352_init()
512 (mt352_read_register(state, CONFIG) & 0x20) == 0) { in mt352_init()
516 return state->config.demod_init(fe); in mt352_init()
524 struct mt352_state* state = fe->demodulator_priv; in mt352_release() local
525 kfree(state); in mt352_release()
533 struct mt352_state* state = NULL; in mt352_attach() local
535 /* allocate memory for the internal state */ in mt352_attach()
536 state = kzalloc(sizeof(struct mt352_state), GFP_KERNEL); in mt352_attach()
537 if (state == NULL) goto error; in mt352_attach()
539 /* setup the state */ in mt352_attach()
540 state->i2c = i2c; in mt352_attach()
541 memcpy(&state->config,config,sizeof(struct mt352_config)); in mt352_attach()
544 if (mt352_read_register(state, CHIP_ID) != ID_MT352) goto error; in mt352_attach()
547 memcpy(&state->frontend.ops, &mt352_ops, sizeof(struct dvb_frontend_ops)); in mt352_attach()
548 state->frontend.demodulator_priv = state; in mt352_attach()
549 return &state->frontend; in mt352_attach()
552 kfree(state); in mt352_attach()
559 .name = "Zarlink MT352 DVB-T",
590 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
592 MODULE_DESCRIPTION("Zarlink MT352 DVB-T Demodulator driver");