/* Some PLL specifics for tuning */
u32 VCAarg;
u32 VGAarg;
u32 bandselectarg;
u32 pllarg;
u32 FILTune;
struct i2c_adapter tuner_i2c_adapter;
u8 demod_rev;
/* The Demod/Tuner can't easily provide these, we cache them */
u32 currentfreq;
u32 currentsymbolrate;
};
/* Various tuner defaults need to be established for a given symbol rate Sps */ staticstruct cx24123_AGC_val {
u32 symbolrate_low;
u32 symbolrate_high;
u32 VCAprogdata;
u32 VGAprogdata;
u32 FILTune;
} cx24123_AGC_vals[] =
{
{
.symbolrate_low = 1000000,
.symbolrate_high = 4999999, /* the specs recommend other values for VGA offsets,
but tests show they are wrong */
.VGAprogdata = (1 << 19) | (0x180 << 9) | 0x1e0,
.VCAprogdata = (2 << 19) | (0x07 << 9) | 0x07,
.FILTune = 0x27f /* 0.41 V */
},
{
.symbolrate_low = 5000000,
.symbolrate_high = 14999999,
.VGAprogdata = (1 << 19) | (0x180 << 9) | 0x1e0,
.VCAprogdata = (2 << 19) | (0x07 << 9) | 0x1f,
.FILTune = 0x317 /* 0.90 V */
},
{
.symbolrate_low = 15000000,
.symbolrate_high = 45000000,
.VGAprogdata = (1 << 19) | (0x100 << 9) | 0x180,
.VCAprogdata = (2 << 19) | (0x07 << 9) | 0x3f,
.FILTune = 0x145 /* 2.70 V */
},
};
/* * Various tuner defaults need to be established for a given frequency kHz. * fixme: The bounds on the bands do not match the doc in real life. * fixme: Some of them have been moved, other might need adjustment.
*/ staticstruct cx24123_bandselect_val {
u32 freq_low;
u32 freq_high;
u32 VCOdivider;
u32 progdata;
} cx24123_bandselect_vals[] =
{ /* band 1 */
{
.freq_low = 950000,
.freq_high = 1074999,
.VCOdivider = 4,
.progdata = (0 << 19) | (0 << 9) | 0x40,
},
/* Set the soft decision threshold */ if (fec == FEC_1_2)
cx24123_writereg(state, 0x43,
cx24123_readreg(state, 0x43) | 0x01); else
cx24123_writereg(state, 0x43,
cx24123_readreg(state, 0x43) & ~0x01);
switch (fec) { case FEC_1_2:
dprintk("set FEC to 1/2\n");
cx24123_writereg(state, 0x0e, nom_reg | 0x01);
cx24123_writereg(state, 0x0f, 0x02); break; case FEC_2_3:
dprintk("set FEC to 2/3\n");
cx24123_writereg(state, 0x0e, nom_reg | 0x02);
cx24123_writereg(state, 0x0f, 0x04); break; case FEC_3_4:
dprintk("set FEC to 3/4\n");
cx24123_writereg(state, 0x0e, nom_reg | 0x03);
cx24123_writereg(state, 0x0f, 0x08); break; case FEC_4_5:
dprintk("set FEC to 4/5\n");
cx24123_writereg(state, 0x0e, nom_reg | 0x04);
cx24123_writereg(state, 0x0f, 0x10); break; case FEC_5_6:
dprintk("set FEC to 5/6\n");
cx24123_writereg(state, 0x0e, nom_reg | 0x05);
cx24123_writereg(state, 0x0f, 0x20); break; case FEC_6_7:
dprintk("set FEC to 6/7\n");
cx24123_writereg(state, 0x0e, nom_reg | 0x06);
cx24123_writereg(state, 0x0f, 0x40); break; case FEC_7_8:
dprintk("set FEC to 7/8\n");
cx24123_writereg(state, 0x0e, nom_reg | 0x07);
cx24123_writereg(state, 0x0f, 0x80); break; case FEC_AUTO:
dprintk("set FEC to auto\n");
cx24123_writereg(state, 0x0f, 0xfe); break; default: return -EOPNOTSUPP;
}
return 0;
}
staticint cx24123_get_fec(struct cx24123_state *state, enum fe_code_rate *fec)
{ int ret;
ret = cx24123_readreg(state, 0x1b); if (ret < 0) return ret;
ret = ret & 0x07;
switch (ret) { case 1:
*fec = FEC_1_2; break; case 2:
*fec = FEC_2_3; break; case 3:
*fec = FEC_3_4; break; case 4:
*fec = FEC_4_5; break; case 5:
*fec = FEC_5_6; break; case 6:
*fec = FEC_6_7; break; case 7:
*fec = FEC_7_8; break; default: /* this can happen when there's no lock */
*fec = FEC_NONE;
}
return 0;
}
/* Approximation of closest integer of log2(a/b). It actually gives the
lowest integer i such that 2^i >= round(a/b) */ static u32 cx24123_int_log2(u32 a, u32 b)
{
u32 exp, nearest = 0;
u32 div = a / b; if (a % b >= b / 2)
++div; if (div < (1UL << 31)) { for (exp = 1; div > exp; nearest++)
exp += exp;
} return nearest;
}
/* check if symbol rate is within limits */ if ((srate > state->frontend.ops.info.symbol_rate_max) ||
(srate < state->frontend.ops.info.symbol_rate_min)) return -EOPNOTSUPP;
/* choose the sampling rate high enough for the required operation,
while optimizing the power consumed by the demodulator */ if (srate < (XTAL*2)/2)
pll_mult = 2; elseif (srate < (XTAL*3)/2)
pll_mult = 3; elseif (srate < (XTAL*4)/2)
pll_mult = 4; elseif (srate < (XTAL*5)/2)
pll_mult = 5; elseif (srate < (XTAL*6)/2)
pll_mult = 6; elseif (srate < (XTAL*7)/2)
pll_mult = 7; elseif (srate < (XTAL*8)/2)
pll_mult = 8; else
pll_mult = 9;
/* * Based on the required frequency and symbolrate, the tuner AGC has * to be configured and the correct band selected. * Calculate those values.
*/ staticint cx24123_pll_calculate(struct dvb_frontend *fe)
{ struct dtv_frontend_properties *p = &fe->dtv_property_cache; struct cx24123_state *state = fe->demodulator_priv;
u32 ndiv = 0, adiv = 0, vco_div = 0; int i = 0; int pump = 2; int band = 0; int num_bands = ARRAY_SIZE(cx24123_bandselect_vals); struct cx24123_bandselect_val *bsv = NULL; struct cx24123_AGC_val *agcv = NULL;
/* For the given symbol rate, determine the VCA, VGA and
* FILTUNE programming bits */ for (i = 0; i < ARRAY_SIZE(cx24123_AGC_vals); i++) {
agcv = &cx24123_AGC_vals[i]; if ((agcv->symbolrate_low <= p->symbol_rate) &&
(agcv->symbolrate_high >= p->symbol_rate)) {
state->VCAarg = agcv->VCAprogdata;
state->VGAarg = agcv->VGAprogdata;
state->FILTune = agcv->FILTune;
}
}
/* determine the band to use */ if (force_band < 1 || force_band > num_bands) { for (i = 0; i < num_bands; i++) {
bsv = &cx24123_bandselect_vals[i]; if ((bsv->freq_low <= p->frequency) &&
(bsv->freq_high >= p->frequency))
band = i;
}
} else
band = force_band - 1;
/* * Tuner data is 21 bits long, must be left-aligned in data. * Tuner cx24109 is written through a dedicated 3wire interface * on the demod chip.
*/ staticint cx24123_pll_writereg(struct dvb_frontend *fe, u32 data)
{ struct cx24123_state *state = fe->demodulator_priv; unsignedlong timeout;
/* align the 21 bytes into to bit23 boundary */
data = data << 3;
/* Reset the demod pll word length to 0x15 bits */
cx24123_writereg(state, 0x21, 0x15);
/* write the msb 8 bits, wait for the send to be completed */
timeout = jiffies + msecs_to_jiffies(40);
cx24123_writereg(state, 0x22, (data >> 16) & 0xff); while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { if (time_after(jiffies, timeout)) {
err("%s: demodulator is not responding, "\ "possibly hung, aborting.\n", __func__); return -EREMOTEIO;
}
msleep(10);
}
/* send another 8 bytes, wait for the send to be completed */
timeout = jiffies + msecs_to_jiffies(40);
cx24123_writereg(state, 0x22, (data >> 8) & 0xff); while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { if (time_after(jiffies, timeout)) {
err("%s: demodulator is not responding, "\ "possibly hung, aborting.\n", __func__); return -EREMOTEIO;
}
msleep(10);
}
/* send the lower 5 bits of this byte, padded with 3 LBB,
* wait for the send to be completed */
timeout = jiffies + msecs_to_jiffies(40);
cx24123_writereg(state, 0x22, (data) & 0xff); while ((cx24123_readreg(state, 0x20) & 0x80)) { if (time_after(jiffies, timeout)) {
err("%s: demodulator is not responding," \ "possibly hung, aborting.\n", __func__); return -EREMOTEIO;
}
msleep(10);
}
/* Trigger the demod to configure the tuner */
cx24123_writereg(state, 0x20, cx24123_readreg(state, 0x20) | 2);
cx24123_writereg(state, 0x20, cx24123_readreg(state, 0x20) & 0xfd);
/* Write the new VCO/VGA */
cx24123_pll_writereg(fe, state->VCAarg);
cx24123_pll_writereg(fe, state->VGAarg);
/* Write the new bandselect and pll args */
cx24123_pll_writereg(fe, state->bandselectarg);
cx24123_pll_writereg(fe, state->pllarg);
/* set the FILTUNE voltage */
val = cx24123_readreg(state, 0x28) & ~0x3;
cx24123_writereg(state, 0x27, state->FILTune >> 2);
cx24123_writereg(state, 0x28, val | (state->FILTune & 0x3));
/* Configure the demod to a good set of defaults */ for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++)
cx24123_writereg(state, cx24123_regdata[i].reg,
cx24123_regdata[i].data);
/* Set the LNB polarity */ if (state->config->lnb_polarity)
cx24123_writereg(state, 0x32,
cx24123_readreg(state, 0x32) | 0x02);
if (state->config->dont_use_pll)
cx24123_repeater_mode(state, 1, 0);
switch (voltage) { case SEC_VOLTAGE_13:
dprintk("setting voltage 13V\n"); return cx24123_writereg(state, 0x29, val & 0x7f); case SEC_VOLTAGE_18:
dprintk("setting voltage 18V\n"); return cx24123_writereg(state, 0x29, val | 0x80); case SEC_VOLTAGE_OFF: /* already handled in cx88-dvb */ return 0; default: return -EINVAL;
}
return 0;
}
/* wait for diseqc queue to become ready (or timeout) */ staticvoid cx24123_wait_for_diseqc(struct cx24123_state *state)
{ unsignedlong timeout = jiffies + msecs_to_jiffies(200); while (!(cx24123_readreg(state, 0x29) & 0x40)) { if (time_after(jiffies, timeout)) {
err("%s: diseqc queue not ready, " \ "command may be lost.\n", __func__); break;
}
msleep(10);
}
}
staticint cx24123_send_diseqc_msg(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
{ struct cx24123_state *state = fe->demodulator_priv; int i, val, tone;
dprintk("\n");
/* stop continuous tone if enabled */
tone = cx24123_readreg(state, 0x29); if (tone & 0x10)
cx24123_writereg(state, 0x29, tone & ~0x50);
/* wait for diseqc queue ready */
cx24123_wait_for_diseqc(state);
*status = 0; if (state->config->dont_use_pll) {
u32 tun_status = 0; if (fe->ops.tuner_ops.get_status)
fe->ops.tuner_ops.get_status(fe, &tun_status); if (tun_status & TUNER_STATUS_LOCKED)
*status |= FE_HAS_SIGNAL;
} else { int lock = cx24123_readreg(state, 0x20); if (lock & 0x01)
*status |= FE_HAS_SIGNAL;
}
if (sync & 0x02)
*status |= FE_HAS_CARRIER; /* Phase locked */ if (sync & 0x04)
*status |= FE_HAS_VITERBI;
/* Reed-Solomon Status */ if (sync & 0x08)
*status |= FE_HAS_SYNC; if (sync & 0x80)
*status |= FE_HAS_LOCK; /*Full Sync */
return 0;
}
/* * Configured to return the measurement of errors in blocks, * because no UCBLOCKS value is available, so this value doubles up * to satisfy both measurements.
*/ staticint cx24123_read_ber(struct dvb_frontend *fe, u32 *ber)
{ struct cx24123_state *state = fe->demodulator_priv;
/* The true bit error rate is this value divided by
the window size (set as 256 * 255) */
*ber = ((cx24123_readreg(state, 0x1c) & 0x3f) << 16) |
(cx24123_readreg(state, 0x1d) << 8 |
cx24123_readreg(state, 0x1e));
/* Inverted raw Es/N0 count, totally bogus but better than the
BER threshold. */
*snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) |
(u16)cx24123_readreg(state, 0x19));
if (!state->config->dont_use_pll)
cx24123_pll_tune(fe); elseif (fe->ops.tuner_ops.set_params)
fe->ops.tuner_ops.set_params(fe); else
err("it seems I don't have a tuner...");
/* wait for diseqc queue ready */
cx24123_wait_for_diseqc(state);
val = cx24123_readreg(state, 0x29) & ~0x40;
switch (tone) { case SEC_TONE_ON:
dprintk("setting tone on\n"); return cx24123_writereg(state, 0x29, val | 0x10); case SEC_TONE_OFF:
dprintk("setting tone off\n"); return cx24123_writereg(state, 0x29, val & 0xef); default:
err("CASE reached default with tone=%d\n", tone); return -EINVAL;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.