Lines Matching +full:default +full:- +full:state

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Conexant cx24123/cx24109 - DVB QPSK Satellite demod/tuner driver
7 * Support for KWorld DVB-S 100 by Vadim Catana <skystar@moldova.cc>
9 * Support for CX24123/CX24113-NIM by Patrick Boettcher <pb@linuxtv.org>
26 "(1-9, default:off).");
30 MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
191 {0x03, 0x07}, /* QPSK, DVB, Auto Acquisition (default) */
194 {0x06, 0x31}, /* MPEG (default) */
195 {0x0b, 0x00}, /* Freq search start point (default) */
196 {0x0c, 0x00}, /* Demodulator sample gain (default) */
197 {0x0d, 0x7f}, /* Force driver to shift until the maximum (+-10 MHz) */
198 {0x0e, 0x03}, /* Default non-inverted, FEC 3/4 (default) */
200 {0x10, 0x01}, /* Default search inversion, no repeat (default) */
208 {0x2a, 0xb0}, /* DiSEqC Parameters (default) */
209 {0x2b, 0x73}, /* DiSEqC Tone Frequency (default) */
210 {0x2c, 0x00}, /* DiSEqC Message (0x2c - 0x31) */
216 {0x32, 0x8c}, /* DiSEqC Parameters (default) */
217 {0x33, 0x00}, /* Interrupts off (0x33 - 0x34) */
219 {0x35, 0x03}, /* DiSEqC Tone Amplitude (default) */
220 {0x36, 0x02}, /* DiSEqC Parameters (default) */
221 {0x37, 0x3a}, /* DiSEqC Parameters (default) */
223 {0x44, 0x00}, /* Constellation (default) */
224 {0x45, 0x00}, /* Symbol count (default) */
225 {0x46, 0x0d}, /* Symbol rate estimator on (default) */
227 {0x57, 0xff}, /* Error Counter Window (default) */
228 {0x5c, 0x20}, /* Acquisition AFC Expiration window (default is 0x10) */
229 {0x67, 0x83}, /* Non-DCII symbol clock */
232 static int cx24123_i2c_writereg(struct cx24123_state *state, in cx24123_i2c_writereg() argument
243 err = i2c_transfer(state->i2c, &msg, 1); in cx24123_i2c_writereg()
253 static int cx24123_i2c_readreg(struct cx24123_state *state, u8 i2c_addr, u8 reg) in cx24123_i2c_readreg() argument
262 ret = i2c_transfer(state->i2c, msg, 2); in cx24123_i2c_readreg()
274 #define cx24123_readreg(state, reg) \ argument
275 cx24123_i2c_readreg(state, state->config->demod_address, reg)
276 #define cx24123_writereg(state, reg, val) \ argument
277 cx24123_i2c_writereg(state, state->config->demod_address, reg, val)
279 static int cx24123_set_inversion(struct cx24123_state *state, in cx24123_set_inversion() argument
282 u8 nom_reg = cx24123_readreg(state, 0x0e); in cx24123_set_inversion()
283 u8 auto_reg = cx24123_readreg(state, 0x10); in cx24123_set_inversion()
288 cx24123_writereg(state, 0x0e, nom_reg & ~0x80); in cx24123_set_inversion()
289 cx24123_writereg(state, 0x10, auto_reg | 0x80); in cx24123_set_inversion()
293 cx24123_writereg(state, 0x0e, nom_reg | 0x80); in cx24123_set_inversion()
294 cx24123_writereg(state, 0x10, auto_reg | 0x80); in cx24123_set_inversion()
298 cx24123_writereg(state, 0x10, auto_reg & ~0x80); in cx24123_set_inversion()
300 default: in cx24123_set_inversion()
301 return -EINVAL; in cx24123_set_inversion()
307 static int cx24123_get_inversion(struct cx24123_state *state, in cx24123_get_inversion() argument
312 val = cx24123_readreg(state, 0x1b) >> 7; in cx24123_get_inversion()
325 static int cx24123_set_fec(struct cx24123_state *state, enum fe_code_rate fec) in cx24123_set_fec() argument
327 u8 nom_reg = cx24123_readreg(state, 0x0e) & ~0x07; in cx24123_set_fec()
334 cx24123_writereg(state, 0x43, in cx24123_set_fec()
335 cx24123_readreg(state, 0x43) | 0x01); in cx24123_set_fec()
337 cx24123_writereg(state, 0x43, in cx24123_set_fec()
338 cx24123_readreg(state, 0x43) & ~0x01); in cx24123_set_fec()
343 cx24123_writereg(state, 0x0e, nom_reg | 0x01); in cx24123_set_fec()
344 cx24123_writereg(state, 0x0f, 0x02); in cx24123_set_fec()
348 cx24123_writereg(state, 0x0e, nom_reg | 0x02); in cx24123_set_fec()
349 cx24123_writereg(state, 0x0f, 0x04); in cx24123_set_fec()
353 cx24123_writereg(state, 0x0e, nom_reg | 0x03); in cx24123_set_fec()
354 cx24123_writereg(state, 0x0f, 0x08); in cx24123_set_fec()
358 cx24123_writereg(state, 0x0e, nom_reg | 0x04); in cx24123_set_fec()
359 cx24123_writereg(state, 0x0f, 0x10); in cx24123_set_fec()
363 cx24123_writereg(state, 0x0e, nom_reg | 0x05); in cx24123_set_fec()
364 cx24123_writereg(state, 0x0f, 0x20); in cx24123_set_fec()
368 cx24123_writereg(state, 0x0e, nom_reg | 0x06); in cx24123_set_fec()
369 cx24123_writereg(state, 0x0f, 0x40); in cx24123_set_fec()
373 cx24123_writereg(state, 0x0e, nom_reg | 0x07); in cx24123_set_fec()
374 cx24123_writereg(state, 0x0f, 0x80); in cx24123_set_fec()
378 cx24123_writereg(state, 0x0f, 0xfe); in cx24123_set_fec()
380 default: in cx24123_set_fec()
381 return -EOPNOTSUPP; in cx24123_set_fec()
387 static int cx24123_get_fec(struct cx24123_state *state, enum fe_code_rate *fec) in cx24123_get_fec() argument
391 ret = cx24123_readreg(state, 0x1b); in cx24123_get_fec()
418 default: in cx24123_get_fec()
441 static int cx24123_set_symbolrate(struct cx24123_state *state, u32 srate) in cx24123_set_symbolrate() argument
448 if ((srate > state->frontend.ops.info.symbol_rate_max) || in cx24123_set_symbolrate()
449 (srate < state->frontend.ops.info.symbol_rate_min)) in cx24123_set_symbolrate()
450 return -EOPNOTSUPP; in cx24123_set_symbolrate()
480 cx24123_writereg(state, 0x01, pll_mult * 6); in cx24123_set_symbolrate()
482 cx24123_writereg(state, 0x08, (ratio >> 16) & 0x3f); in cx24123_set_symbolrate()
483 cx24123_writereg(state, 0x09, (ratio >> 8) & 0xff); in cx24123_set_symbolrate()
484 cx24123_writereg(state, 0x0a, ratio & 0xff); in cx24123_set_symbolrate()
488 tmp = cx24123_readreg(state, 0x0c) & ~0xe0; in cx24123_set_symbolrate()
489 cx24123_writereg(state, 0x0c, tmp | sample_gain << 5); in cx24123_set_symbolrate()
504 struct dtv_frontend_properties *p = &fe->dtv_property_cache; in cx24123_pll_calculate()
505 struct cx24123_state *state = fe->demodulator_priv; in cx24123_pll_calculate() local
515 state->VCAarg = cx24123_AGC_vals[0].VCAprogdata; in cx24123_pll_calculate()
516 state->VGAarg = cx24123_AGC_vals[0].VGAprogdata; in cx24123_pll_calculate()
517 state->bandselectarg = cx24123_bandselect_vals[0].progdata; in cx24123_pll_calculate()
524 if ((agcv->symbolrate_low <= p->symbol_rate) && in cx24123_pll_calculate()
525 (agcv->symbolrate_high >= p->symbol_rate)) { in cx24123_pll_calculate()
526 state->VCAarg = agcv->VCAprogdata; in cx24123_pll_calculate()
527 state->VGAarg = agcv->VGAprogdata; in cx24123_pll_calculate()
528 state->FILTune = agcv->FILTune; in cx24123_pll_calculate()
536 if ((bsv->freq_low <= p->frequency) && in cx24123_pll_calculate()
537 (bsv->freq_high >= p->frequency)) in cx24123_pll_calculate()
541 band = force_band - 1; in cx24123_pll_calculate()
543 state->bandselectarg = cx24123_bandselect_vals[band].progdata; in cx24123_pll_calculate()
547 if (p->frequency < (cx24123_bandselect_vals[band].freq_low + in cx24123_pll_calculate()
556 ndiv = (((p->frequency * vco_div * 10) / in cx24123_pll_calculate()
558 adiv = (((p->frequency * vco_div * 10) / in cx24123_pll_calculate()
562 ndiv--; in cx24123_pll_calculate()
566 state->pllarg = (3 << 19) | (3 << 17) | (1 << 16) | in cx24123_pll_calculate()
573 * Tuner data is 21 bits long, must be left-aligned in data.
579 struct cx24123_state *state = fe->demodulator_priv; in cx24123_pll_writereg() local
588 cx24123_writereg(state, 0x21, 0x15); in cx24123_pll_writereg()
592 cx24123_writereg(state, 0x22, (data >> 16) & 0xff); in cx24123_pll_writereg()
593 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { in cx24123_pll_writereg()
597 return -EREMOTEIO; in cx24123_pll_writereg()
604 cx24123_writereg(state, 0x22, (data >> 8) & 0xff); in cx24123_pll_writereg()
605 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { in cx24123_pll_writereg()
609 return -EREMOTEIO; in cx24123_pll_writereg()
617 cx24123_writereg(state, 0x22, (data) & 0xff); in cx24123_pll_writereg()
618 while ((cx24123_readreg(state, 0x20) & 0x80)) { in cx24123_pll_writereg()
622 return -EREMOTEIO; in cx24123_pll_writereg()
628 cx24123_writereg(state, 0x20, cx24123_readreg(state, 0x20) | 2); in cx24123_pll_writereg()
629 cx24123_writereg(state, 0x20, cx24123_readreg(state, 0x20) & 0xfd); in cx24123_pll_writereg()
636 struct dtv_frontend_properties *p = &fe->dtv_property_cache; in cx24123_pll_tune()
637 struct cx24123_state *state = fe->demodulator_priv; in cx24123_pll_tune() local
640 dprintk("frequency=%i\n", p->frequency); in cx24123_pll_tune()
644 return -EINVAL; in cx24123_pll_tune()
648 cx24123_pll_writereg(fe, state->VCAarg); in cx24123_pll_tune()
649 cx24123_pll_writereg(fe, state->VGAarg); in cx24123_pll_tune()
652 cx24123_pll_writereg(fe, state->bandselectarg); in cx24123_pll_tune()
653 cx24123_pll_writereg(fe, state->pllarg); in cx24123_pll_tune()
656 val = cx24123_readreg(state, 0x28) & ~0x3; in cx24123_pll_tune()
657 cx24123_writereg(state, 0x27, state->FILTune >> 2); in cx24123_pll_tune()
658 cx24123_writereg(state, 0x28, val | (state->FILTune & 0x3)); in cx24123_pll_tune()
660 dprintk("pll tune VCA=%d, band=%d, pll=%d\n", state->VCAarg, in cx24123_pll_tune()
661 state->bandselectarg, state->pllarg); in cx24123_pll_tune()
675 /* mode == 1 -> i2c-repeater, 0 -> bti */
676 static int cx24123_repeater_mode(struct cx24123_state *state, u8 mode, u8 start) in cx24123_repeater_mode() argument
678 u8 r = cx24123_readreg(state, 0x23) & 0x1e; in cx24123_repeater_mode()
683 return cx24123_writereg(state, 0x23, r); in cx24123_repeater_mode()
688 struct cx24123_state *state = fe->demodulator_priv; in cx24123_initfe() local
695 cx24123_writereg(state, cx24123_regdata[i].reg, in cx24123_initfe()
699 if (state->config->lnb_polarity) in cx24123_initfe()
700 cx24123_writereg(state, 0x32, in cx24123_initfe()
701 cx24123_readreg(state, 0x32) | 0x02); in cx24123_initfe()
703 if (state->config->dont_use_pll) in cx24123_initfe()
704 cx24123_repeater_mode(state, 1, 0); in cx24123_initfe()
712 struct cx24123_state *state = fe->demodulator_priv; in cx24123_set_voltage() local
715 val = cx24123_readreg(state, 0x29) & ~0x40; in cx24123_set_voltage()
720 return cx24123_writereg(state, 0x29, val & 0x7f); in cx24123_set_voltage()
723 return cx24123_writereg(state, 0x29, val | 0x80); in cx24123_set_voltage()
725 /* already handled in cx88-dvb */ in cx24123_set_voltage()
727 default: in cx24123_set_voltage()
728 return -EINVAL; in cx24123_set_voltage()
735 static void cx24123_wait_for_diseqc(struct cx24123_state *state) in cx24123_wait_for_diseqc() argument
738 while (!(cx24123_readreg(state, 0x29) & 0x40)) { in cx24123_wait_for_diseqc()
751 struct cx24123_state *state = fe->demodulator_priv; in cx24123_send_diseqc_msg() local
757 tone = cx24123_readreg(state, 0x29); in cx24123_send_diseqc_msg()
759 cx24123_writereg(state, 0x29, tone & ~0x50); in cx24123_send_diseqc_msg()
762 cx24123_wait_for_diseqc(state); in cx24123_send_diseqc_msg()
765 cx24123_writereg(state, 0x2a, cx24123_readreg(state, 0x2a) & 0xfb); in cx24123_send_diseqc_msg()
767 for (i = 0; i < cmd->msg_len; i++) in cx24123_send_diseqc_msg()
768 cx24123_writereg(state, 0x2C + i, cmd->msg[i]); in cx24123_send_diseqc_msg()
770 val = cx24123_readreg(state, 0x29); in cx24123_send_diseqc_msg()
771 cx24123_writereg(state, 0x29, ((val & 0x90) | 0x40) | in cx24123_send_diseqc_msg()
772 ((cmd->msg_len-3) & 3)); in cx24123_send_diseqc_msg()
775 cx24123_wait_for_diseqc(state); in cx24123_send_diseqc_msg()
779 cx24123_writereg(state, 0x29, tone & ~0x40); in cx24123_send_diseqc_msg()
787 struct cx24123_state *state = fe->demodulator_priv; in cx24123_diseqc_send_burst() local
793 tone = cx24123_readreg(state, 0x29); in cx24123_diseqc_send_burst()
795 cx24123_writereg(state, 0x29, tone & ~0x50); in cx24123_diseqc_send_burst()
798 cx24123_wait_for_diseqc(state); in cx24123_diseqc_send_burst()
801 cx24123_writereg(state, 0x2a, cx24123_readreg(state, 0x2a) | 0x4); in cx24123_diseqc_send_burst()
803 val = cx24123_readreg(state, 0x29); in cx24123_diseqc_send_burst()
805 cx24123_writereg(state, 0x29, ((val & 0x90) | 0x40 | 0x00)); in cx24123_diseqc_send_burst()
807 cx24123_writereg(state, 0x29, ((val & 0x90) | 0x40 | 0x08)); in cx24123_diseqc_send_burst()
809 return -EINVAL; in cx24123_diseqc_send_burst()
811 cx24123_wait_for_diseqc(state); in cx24123_diseqc_send_burst()
812 cx24123_writereg(state, 0x2a, cx24123_readreg(state, 0x2a) & 0xfb); in cx24123_diseqc_send_burst()
816 cx24123_writereg(state, 0x29, tone & ~0x40); in cx24123_diseqc_send_burst()
823 struct cx24123_state *state = fe->demodulator_priv; in cx24123_read_status() local
824 int sync = cx24123_readreg(state, 0x14); in cx24123_read_status()
827 if (state->config->dont_use_pll) { in cx24123_read_status()
829 if (fe->ops.tuner_ops.get_status) in cx24123_read_status()
830 fe->ops.tuner_ops.get_status(fe, &tun_status); in cx24123_read_status()
834 int lock = cx24123_readreg(state, 0x20); in cx24123_read_status()
844 /* Reed-Solomon Status */ in cx24123_read_status()
860 struct cx24123_state *state = fe->demodulator_priv; in cx24123_read_ber() local
864 *ber = ((cx24123_readreg(state, 0x1c) & 0x3f) << 16) | in cx24123_read_ber()
865 (cx24123_readreg(state, 0x1d) << 8 | in cx24123_read_ber()
866 cx24123_readreg(state, 0x1e)); in cx24123_read_ber()
876 struct cx24123_state *state = fe->demodulator_priv; in cx24123_read_signal_strength() local
879 *signal_strength = cx24123_readreg(state, 0x3b) << 8; in cx24123_read_signal_strength()
888 struct cx24123_state *state = fe->demodulator_priv; in cx24123_read_snr() local
892 *snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) | in cx24123_read_snr()
893 (u16)cx24123_readreg(state, 0x19)); in cx24123_read_snr()
902 struct cx24123_state *state = fe->demodulator_priv; in cx24123_set_frontend() local
903 struct dtv_frontend_properties *p = &fe->dtv_property_cache; in cx24123_set_frontend()
907 if (state->config->set_ts_params) in cx24123_set_frontend()
908 state->config->set_ts_params(fe, 0); in cx24123_set_frontend()
910 state->currentfreq = p->frequency; in cx24123_set_frontend()
911 state->currentsymbolrate = p->symbol_rate; in cx24123_set_frontend()
913 cx24123_set_inversion(state, p->inversion); in cx24123_set_frontend()
914 cx24123_set_fec(state, p->fec_inner); in cx24123_set_frontend()
915 cx24123_set_symbolrate(state, p->symbol_rate); in cx24123_set_frontend()
917 if (!state->config->dont_use_pll) in cx24123_set_frontend()
919 else if (fe->ops.tuner_ops.set_params) in cx24123_set_frontend()
920 fe->ops.tuner_ops.set_params(fe); in cx24123_set_frontend()
925 cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07)); in cx24123_set_frontend()
926 cx24123_writereg(state, 0x00, 0x10); in cx24123_set_frontend()
927 cx24123_writereg(state, 0x00, 0); in cx24123_set_frontend()
929 if (state->config->agc_callback) in cx24123_set_frontend()
930 state->config->agc_callback(fe); in cx24123_set_frontend()
938 struct cx24123_state *state = fe->demodulator_priv; in cx24123_get_frontend() local
942 if (cx24123_get_inversion(state, &p->inversion) != 0) { in cx24123_get_frontend()
944 return -EREMOTEIO; in cx24123_get_frontend()
946 if (cx24123_get_fec(state, &p->fec_inner) != 0) { in cx24123_get_frontend()
948 return -EREMOTEIO; in cx24123_get_frontend()
950 p->frequency = state->currentfreq; in cx24123_get_frontend()
951 p->symbol_rate = state->currentsymbolrate; in cx24123_get_frontend()
958 struct cx24123_state *state = fe->demodulator_priv; in cx24123_set_tone() local
962 cx24123_wait_for_diseqc(state); in cx24123_set_tone()
964 val = cx24123_readreg(state, 0x29) & ~0x40; in cx24123_set_tone()
969 return cx24123_writereg(state, 0x29, val | 0x10); in cx24123_set_tone()
972 return cx24123_writereg(state, 0x29, val & 0xef); in cx24123_set_tone()
973 default: in cx24123_set_tone()
974 err("CASE reached default with tone=%d\n", tone); in cx24123_set_tone()
975 return -EINVAL; in cx24123_set_tone()
1006 struct cx24123_state *state = fe->demodulator_priv; in cx24123_release() local
1008 i2c_del_adapter(&state->tuner_i2c_adapter); in cx24123_release()
1009 kfree(state); in cx24123_release()
1015 struct cx24123_state *state = i2c_get_adapdata(i2c_adap); in cx24123_tuner_i2c_tuner_xfer() local
1017 cx24123_repeater_mode(state, 1, 1); in cx24123_tuner_i2c_tuner_xfer()
1018 return i2c_transfer(state->i2c, msg, num); in cx24123_tuner_i2c_tuner_xfer()
1034 struct cx24123_state *state = fe->demodulator_priv; in cx24123_get_tuner_i2c_adapter() local
1035 return &state->tuner_i2c_adapter; in cx24123_get_tuner_i2c_adapter()
1044 /* allocate memory for the internal state */ in cx24123_attach()
1045 struct cx24123_state *state = in cx24123_attach() local
1049 if (state == NULL) { in cx24123_attach()
1054 /* setup the state */ in cx24123_attach()
1055 state->config = config; in cx24123_attach()
1056 state->i2c = i2c; in cx24123_attach()
1059 state->demod_rev = cx24123_readreg(state, 0x00); in cx24123_attach()
1060 switch (state->demod_rev) { in cx24123_attach()
1067 default: in cx24123_attach()
1068 err("wrong demod revision: %x\n", state->demod_rev); in cx24123_attach()
1073 memcpy(&state->frontend.ops, &cx24123_ops, in cx24123_attach()
1075 state->frontend.demodulator_priv = state; in cx24123_attach()
1078 if (config->dont_use_pll) in cx24123_attach()
1079 cx24123_repeater_mode(state, 1, 0); in cx24123_attach()
1081 strscpy(state->tuner_i2c_adapter.name, "CX24123 tuner I2C bus", in cx24123_attach()
1082 sizeof(state->tuner_i2c_adapter.name)); in cx24123_attach()
1083 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo; in cx24123_attach()
1084 state->tuner_i2c_adapter.algo_data = NULL; in cx24123_attach()
1085 state->tuner_i2c_adapter.dev.parent = i2c->dev.parent; in cx24123_attach()
1086 i2c_set_adapdata(&state->tuner_i2c_adapter, state); in cx24123_attach()
1087 if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) { in cx24123_attach()
1092 return &state->frontend; in cx24123_attach()
1095 kfree(state); in cx24123_attach()