25 #include <linux/slab.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
35 static int force_band;
38 "(1-9, default:off).");
44 #define info(args...) do { printk(KERN_INFO "CX24123: " args); } while (0)
45 #define err(args...) do { printk(KERN_ERR "CX24123: " args); } while (0)
47 #define dprintk(args...) \
50 printk(KERN_DEBUG "CX24123: %s: ", __func__); \
78 static struct cx24123_AGC_val {
84 } cx24123_AGC_vals[] =
87 .symbolrate_low = 1000000,
88 .symbolrate_high = 4999999,
91 .VGAprogdata = (1 << 19) | (0x180 << 9) | 0x1e0,
92 .VCAprogdata = (2 << 19) | (0x07 << 9) | 0x07,
96 .symbolrate_low = 5000000,
97 .symbolrate_high = 14999999,
98 .VGAprogdata = (1 << 19) | (0x180 << 9) | 0x1e0,
99 .VCAprogdata = (2 << 19) | (0x07 << 9) | 0x1f,
103 .symbolrate_low = 15000000,
104 .symbolrate_high = 45000000,
105 .VGAprogdata = (1 << 19) | (0x100 << 9) | 0x180,
106 .VCAprogdata = (2 << 19) | (0x07 << 9) | 0x3f,
116 static struct cx24123_bandselect_val {
121 } cx24123_bandselect_vals[] =
126 .freq_high = 1074999,
128 .progdata = (0 << 19) | (0 << 9) | 0x40,
134 .freq_high = 1177999,
136 .progdata = (0 << 19) | (0 << 9) | 0x80,
142 .freq_high = 1295999,
144 .progdata = (0 << 19) | (1 << 9) | 0x01,
150 .freq_high = 1431999,
152 .progdata = (0 << 19) | (1 << 9) | 0x02,
158 .freq_high = 1575999,
160 .progdata = (0 << 19) | (1 << 9) | 0x04,
166 .freq_high = 1717999,
168 .progdata = (0 << 19) | (1 << 9) | 0x08,
174 .freq_high = 1855999,
176 .progdata = (0 << 19) | (1 << 9) | 0x10,
182 .freq_high = 2035999,
184 .progdata = (0 << 19) | (1 << 9) | 0x20,
190 .freq_high = 2150000,
192 .progdata = (0 << 19) | (1 << 9) | 0x40,
199 } cx24123_regdata[] =
249 .addr = i2c_addr, .flags = 0, .buf =
buf, .len = 2
257 printk(
"%s: writereg error(err == %i, reg == 0x%02x,"
258 " data == 0x%02x)\n", __func__, err, reg, data);
270 { .
addr = i2c_addr, .flags = 0, .buf = &
reg, .len = 1 },
271 { .addr = i2c_addr, .flags =
I2C_M_RD, .buf = &
b, .len = 1 }
277 err(
"%s: reg=0x%x (error=%d)\n", __func__, reg, ret);
286 #define cx24123_readreg(state, reg) \
287 cx24123_i2c_readreg(state, state->config->demod_address, reg)
288 #define cx24123_writereg(state, reg, val) \
289 cx24123_i2c_writereg(state, state->config->demod_address, reg, val)
291 static int cx24123_set_inversion(
struct cx24123_state *state,
319 static int cx24123_get_inversion(
struct cx24123_state *state,
327 dprintk(
"read inversion off\n");
330 dprintk(
"read inversion on\n");
446 if (div < (1 << 31)) {
447 for (exp = 1; div >
exp; nearest++)
459 if ((srate > state->
frontend.ops.info.symbol_rate_max) ||
460 (srate < state->frontend.ops.info.symbol_rate_min))
465 if (srate < (
XTAL*2)/2)
467 else if (srate < (
XTAL*3)/2)
469 else if (srate < (
XTAL*4)/2)
471 else if (srate < (
XTAL*5)/2)
473 else if (srate < (
XTAL*6)/2)
475 else if (srate < (
XTAL*7)/2)
477 else if (srate < (
XTAL*8)/2)
483 sample_rate = pll_mult *
XTAL;
495 ratio = tmp / sample_rate;
497 tmp = (tmp % sample_rate) << 6;
498 ratio = (ratio << 6) + (tmp / sample_rate);
500 tmp = (tmp % sample_rate) << 6;
501 ratio = (ratio << 6) + (tmp / sample_rate);
503 tmp = (tmp % sample_rate) << 5;
504 ratio = (ratio << 5) + (tmp / sample_rate);
514 sample_gain = cx24123_int_log2(sample_rate, srate);
518 dprintk(
"srate=%d, ratio=0x%08x, sample_rate=%i sample_gain=%d\n",
519 srate, ratio, sample_rate, sample_gain);
529 static int cx24123_pll_calculate(
struct dvb_frontend *fe)
533 u32 ndiv = 0, adiv = 0, vco_div = 0;
537 int num_bands =
ARRAY_SIZE(cx24123_bandselect_vals);
538 struct cx24123_bandselect_val *bsv =
NULL;
539 struct cx24123_AGC_val *agcv =
NULL;
542 state->
VCAarg = cx24123_AGC_vals[0].VCAprogdata;
543 state->
VGAarg = cx24123_AGC_vals[0].VGAprogdata;
545 vco_div = cx24123_bandselect_vals[0].VCOdivider;
549 for (i = 0; i <
ARRAY_SIZE(cx24123_AGC_vals); i++) {
550 agcv = &cx24123_AGC_vals[
i];
553 state->
VCAarg = agcv->VCAprogdata;
554 state->
VGAarg = agcv->VGAprogdata;
555 state->
FILTune = agcv->FILTune;
560 if (force_band < 1 || force_band > num_bands) {
561 for (i = 0; i < num_bands; i++) {
562 bsv = &cx24123_bandselect_vals[
i];
568 band = force_band - 1;
570 state->
bandselectarg = cx24123_bandselect_vals[band].progdata;
571 vco_div = cx24123_bandselect_vals[band].VCOdivider;
574 if (p->
frequency < (cx24123_bandselect_vals[band].freq_low +
575 cx24123_bandselect_vals[band].freq_high) / 2)
584 (2 * XTAL / 1000)) / 32) & 0x1ff;
586 (2 * XTAL / 1000)) % 32) & 0x1f;
588 if (adiv == 0 && ndiv > 0)
593 state->
pllarg = (3 << 19) | (3 << 17) | (1 << 16) |
594 (pump << 14) | (ndiv << 5) | adiv;
609 dprintk(
"pll writereg called, data=0x%08x\n", data);
622 err(
"%s: demodulator is not responding, "\
623 "possibly hung, aborting.\n", __func__);
634 err(
"%s: demodulator is not responding, "\
635 "possibly hung, aborting.\n", __func__);
647 err(
"%s: demodulator is not responding," \
648 "possibly hung, aborting.\n", __func__);
669 if (cx24123_pll_calculate(fe) != 0) {
670 err(
"%s: cx24123_pll_calcutate failed\n", __func__);
675 cx24123_pll_writereg(fe, state->
VCAarg);
676 cx24123_pll_writereg(fe, state->
VGAarg);
680 cx24123_pll_writereg(fe, state->
pllarg);
707 r |= (1 << 6) | (start << 5);
709 r |= (1 << 7) | (start);
721 for (i = 0; i <
ARRAY_SIZE(cx24123_regdata); i++)
723 cx24123_regdata[i].data);
726 if (state->
config->lnb_polarity)
730 if (state->
config->dont_use_pll)
731 cx24123_repeater_mode(state, 1, 0);
746 dprintk(
"setting voltage 13V\n");
749 dprintk(
"setting voltage 18V\n");
762 static void cx24123_wait_for_diseqc(
struct cx24123_state *state)
767 err(
"%s: diseqc queue not ready, " \
768 "command may be lost.\n", __func__);
775 static int cx24123_send_diseqc_msg(
struct dvb_frontend *fe,
789 cx24123_wait_for_diseqc(state);
794 for (i = 0; i < cmd->
msg_len; i++)
802 cx24123_wait_for_diseqc(state);
811 static int cx24123_diseqc_send_burst(
struct dvb_frontend *fe,
825 cx24123_wait_for_diseqc(state);
838 cx24123_wait_for_diseqc(state);
854 if (state->
config->dont_use_pll) {
856 if (fe->
ops.tuner_ops.get_status)
857 fe->
ops.tuner_ops.get_status(fe, &tun_status);
900 static int cx24123_read_signal_strength(
struct dvb_frontend *fe,
901 u16 *signal_strength)
908 dprintk(
"Signal strength = %d\n", *signal_strength);
922 dprintk(
"read S/N index = %d\n", *snr);
927 static int cx24123_set_frontend(
struct dvb_frontend *fe)
934 if (state->
config->set_ts_params)
935 state->
config->set_ts_params(fe, 0);
940 cx24123_set_inversion(state, p->
inversion);
944 if (!state->
config->dont_use_pll)
945 cx24123_pll_tune(fe);
946 else if (fe->
ops.tuner_ops.set_params)
947 fe->
ops.tuner_ops.set_params(fe);
949 err(
"it seems I don't have a tuner...");
956 if (state->
config->agc_callback)
957 state->
config->agc_callback(fe);
962 static int cx24123_get_frontend(
struct dvb_frontend *fe)
969 if (cx24123_get_inversion(state, &p->
inversion) != 0) {
970 err(
"%s: Failed to get inversion status\n", __func__);
973 if (cx24123_get_fec(state, &p->
fec_inner) != 0) {
974 err(
"%s: Failed to get fec status\n", __func__);
989 cx24123_wait_for_diseqc(state);
1001 err(
"CASE reached default with tone=%d\n", tone);
1010 unsigned int mode_flags,
1011 unsigned int *
delay,
1017 retval = cx24123_set_frontend(fe);
1020 cx24123_read_status(fe, status);
1039 static int cx24123_tuner_i2c_tuner_xfer(
struct i2c_adapter *i2c_adap,
1040 struct i2c_msg msg[],
int num)
1044 cx24123_repeater_mode(state, 1, 1);
1054 .master_xfer = cx24123_tuner_i2c_tuner_xfer,
1055 .functionality = cx24123_tuner_i2c_func,
1076 if (state ==
NULL) {
1077 err(
"Unable to kzalloc\n");
1089 info(
"detected CX24123C\n");
1092 info(
"detected CX24123\n");
1106 cx24123_repeater_mode(state, 1, 0);
1114 err(
"tuner i2c bus could not be initialized\n");
1130 .name =
"Conexant CX24123/CX24109",
1131 .frequency_min = 950000,
1132 .frequency_max = 2150000,
1133 .frequency_stepsize = 1011,
1134 .frequency_tolerance = 5000,
1135 .symbol_rate_min = 1000000,
1136 .symbol_rate_max = 45000000,
1144 .release = cx24123_release,
1146 .init = cx24123_initfe,
1147 .set_frontend = cx24123_set_frontend,
1148 .get_frontend = cx24123_get_frontend,
1149 .read_status = cx24123_read_status,
1150 .read_ber = cx24123_read_ber,
1151 .read_signal_strength = cx24123_read_signal_strength,
1152 .read_snr = cx24123_read_snr,
1153 .diseqc_send_master_cmd = cx24123_send_diseqc_msg,
1154 .diseqc_send_burst = cx24123_diseqc_send_burst,
1155 .set_tone = cx24123_set_tone,
1156 .set_voltage = cx24123_set_voltage,
1157 .tune = cx24123_tune,
1158 .get_frontend_algo = cx24123_get_algo,
1162 "CX24123/CX24109/CX24113 hardware");