[media] zl10353: convert set_fontend to use DVBv5 parameters

Instead of using dvb_frontend_parameters struct, that were
designed for a subset of the supported standards, use the DVBv5
cache information.

Also, fill the supported delivery systems at dvb_frontend_ops
struct.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Mauro Carvalho Chehab 2011-12-22 21:12:28 -03:00
parent f20b12ecb4
commit 4e4d2bcf48
1 changed files with 50 additions and 63 deletions

View File

@ -37,9 +37,9 @@ struct zl10353_state {
struct zl10353_config config; struct zl10353_config config;
enum fe_bandwidth bandwidth; u32 bandwidth;
u32 ucblocks; u32 ucblocks;
u32 frequency; u32 frequency;
}; };
static int debug; static int debug;
@ -122,30 +122,17 @@ static void zl10353_dump_regs(struct dvb_frontend *fe)
} }
static void zl10353_calc_nominal_rate(struct dvb_frontend *fe, static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
enum fe_bandwidth bandwidth, u32 bandwidth,
u16 *nominal_rate) u16 *nominal_rate)
{ {
struct zl10353_state *state = fe->demodulator_priv; struct zl10353_state *state = fe->demodulator_priv;
u32 adc_clock = 450560; /* 45.056 MHz */ u32 adc_clock = 450560; /* 45.056 MHz */
u64 value; u64 value;
u8 bw; u8 bw = bandwidth / 1000000;
if (state->config.adc_clock) if (state->config.adc_clock)
adc_clock = state->config.adc_clock; adc_clock = state->config.adc_clock;
switch (bandwidth) {
case BANDWIDTH_6_MHZ:
bw = 6;
break;
case BANDWIDTH_7_MHZ:
bw = 7;
break;
case BANDWIDTH_8_MHZ:
default:
bw = 8;
break;
}
value = (u64)10 * (1 << 23) / 7 * 125; value = (u64)10 * (1 << 23) / 7 * 125;
value = (bw * value) + adc_clock / 2; value = (bw * value) + adc_clock / 2;
do_div(value, adc_clock); do_div(value, adc_clock);
@ -192,16 +179,15 @@ static int zl10353_sleep(struct dvb_frontend *fe)
return 0; return 0;
} }
static int zl10353_set_parameters(struct dvb_frontend *fe, static int zl10353_set_parameters(struct dvb_frontend *fe)
struct dvb_frontend_parameters *param)
{ {
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
struct zl10353_state *state = fe->demodulator_priv; struct zl10353_state *state = fe->demodulator_priv;
u16 nominal_rate, input_freq; u16 nominal_rate, input_freq;
u8 pllbuf[6] = { 0x67 }, acq_ctl = 0; u8 pllbuf[6] = { 0x67 }, acq_ctl = 0;
u16 tps = 0; u16 tps = 0;
struct dvb_ofdm_parameters *op = &param->u.ofdm;
state->frequency = param->frequency; state->frequency = c->frequency;
zl10353_single_write(fe, RESET, 0x80); zl10353_single_write(fe, RESET, 0x80);
udelay(200); udelay(200);
@ -211,42 +197,44 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
zl10353_single_write(fe, AGC_TARGET, 0x28); zl10353_single_write(fe, AGC_TARGET, 0x28);
if (op->transmission_mode != TRANSMISSION_MODE_AUTO) if (c->transmission_mode != TRANSMISSION_MODE_AUTO)
acq_ctl |= (1 << 0); acq_ctl |= (1 << 0);
if (op->guard_interval != GUARD_INTERVAL_AUTO) if (c->guard_interval != GUARD_INTERVAL_AUTO)
acq_ctl |= (1 << 1); acq_ctl |= (1 << 1);
zl10353_single_write(fe, ACQ_CTL, acq_ctl); zl10353_single_write(fe, ACQ_CTL, acq_ctl);
switch (op->bandwidth) { switch (c->bandwidth_hz) {
case BANDWIDTH_6_MHZ: case 6000000:
/* These are extrapolated from the 7 and 8MHz values */ /* These are extrapolated from the 7 and 8MHz values */
zl10353_single_write(fe, MCLK_RATIO, 0x97); zl10353_single_write(fe, MCLK_RATIO, 0x97);
zl10353_single_write(fe, 0x64, 0x34); zl10353_single_write(fe, 0x64, 0x34);
zl10353_single_write(fe, 0xcc, 0xdd); zl10353_single_write(fe, 0xcc, 0xdd);
break; break;
case BANDWIDTH_7_MHZ: case 7000000:
zl10353_single_write(fe, MCLK_RATIO, 0x86); zl10353_single_write(fe, MCLK_RATIO, 0x86);
zl10353_single_write(fe, 0x64, 0x35); zl10353_single_write(fe, 0x64, 0x35);
zl10353_single_write(fe, 0xcc, 0x73); zl10353_single_write(fe, 0xcc, 0x73);
break; break;
case BANDWIDTH_8_MHZ:
default: default:
c->bandwidth_hz = 8000000;
/* fall though */
case 8000000:
zl10353_single_write(fe, MCLK_RATIO, 0x75); zl10353_single_write(fe, MCLK_RATIO, 0x75);
zl10353_single_write(fe, 0x64, 0x36); zl10353_single_write(fe, 0x64, 0x36);
zl10353_single_write(fe, 0xcc, 0x73); zl10353_single_write(fe, 0xcc, 0x73);
} }
zl10353_calc_nominal_rate(fe, op->bandwidth, &nominal_rate); zl10353_calc_nominal_rate(fe, c->bandwidth_hz, &nominal_rate);
zl10353_single_write(fe, TRL_NOMINAL_RATE_1, msb(nominal_rate)); zl10353_single_write(fe, TRL_NOMINAL_RATE_1, msb(nominal_rate));
zl10353_single_write(fe, TRL_NOMINAL_RATE_0, lsb(nominal_rate)); zl10353_single_write(fe, TRL_NOMINAL_RATE_0, lsb(nominal_rate));
state->bandwidth = op->bandwidth; state->bandwidth = c->bandwidth_hz;
zl10353_calc_input_freq(fe, &input_freq); zl10353_calc_input_freq(fe, &input_freq);
zl10353_single_write(fe, INPUT_FREQ_1, msb(input_freq)); zl10353_single_write(fe, INPUT_FREQ_1, msb(input_freq));
zl10353_single_write(fe, INPUT_FREQ_0, lsb(input_freq)); zl10353_single_write(fe, INPUT_FREQ_0, lsb(input_freq));
/* Hint at TPS settings */ /* Hint at TPS settings */
switch (op->code_rate_HP) { switch (c->code_rate_HP) {
case FEC_2_3: case FEC_2_3:
tps |= (1 << 7); tps |= (1 << 7);
break; break;
@ -266,7 +254,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
return -EINVAL; return -EINVAL;
} }
switch (op->code_rate_LP) { switch (c->code_rate_LP) {
case FEC_2_3: case FEC_2_3:
tps |= (1 << 4); tps |= (1 << 4);
break; break;
@ -283,14 +271,14 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
case FEC_AUTO: case FEC_AUTO:
break; break;
case FEC_NONE: case FEC_NONE:
if (op->hierarchy_information == HIERARCHY_AUTO || if (c->hierarchy == HIERARCHY_AUTO ||
op->hierarchy_information == HIERARCHY_NONE) c->hierarchy == HIERARCHY_NONE)
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
switch (op->constellation) { switch (c->modulation) {
case QPSK: case QPSK:
break; break;
case QAM_AUTO: case QAM_AUTO:
@ -304,7 +292,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
return -EINVAL; return -EINVAL;
} }
switch (op->transmission_mode) { switch (c->transmission_mode) {
case TRANSMISSION_MODE_2K: case TRANSMISSION_MODE_2K:
case TRANSMISSION_MODE_AUTO: case TRANSMISSION_MODE_AUTO:
break; break;
@ -315,7 +303,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
return -EINVAL; return -EINVAL;
} }
switch (op->guard_interval) { switch (c->guard_interval) {
case GUARD_INTERVAL_1_32: case GUARD_INTERVAL_1_32:
case GUARD_INTERVAL_AUTO: case GUARD_INTERVAL_AUTO:
break; break;
@ -332,7 +320,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
return -EINVAL; return -EINVAL;
} }
switch (op->hierarchy_information) { switch (c->hierarchy) {
case HIERARCHY_AUTO: case HIERARCHY_AUTO:
case HIERARCHY_NONE: case HIERARCHY_NONE:
break; break;
@ -384,10 +372,9 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
} }
static int zl10353_get_parameters(struct dvb_frontend *fe, static int zl10353_get_parameters(struct dvb_frontend *fe,
struct dvb_frontend_parameters *param) struct dtv_frontend_properties *c)
{ {
struct zl10353_state *state = fe->demodulator_priv; struct zl10353_state *state = fe->demodulator_priv;
struct dvb_ofdm_parameters *op = &param->u.ofdm;
int s6, s9; int s6, s9;
u16 tps; u16 tps;
static const u8 tps_fec_to_api[8] = { static const u8 tps_fec_to_api[8] = {
@ -411,66 +398,66 @@ static int zl10353_get_parameters(struct dvb_frontend *fe,
tps = zl10353_read_register(state, TPS_RECEIVED_1) << 8 | tps = zl10353_read_register(state, TPS_RECEIVED_1) << 8 |
zl10353_read_register(state, TPS_RECEIVED_0); zl10353_read_register(state, TPS_RECEIVED_0);
op->code_rate_HP = tps_fec_to_api[(tps >> 7) & 7]; c->code_rate_HP = tps_fec_to_api[(tps >> 7) & 7];
op->code_rate_LP = tps_fec_to_api[(tps >> 4) & 7]; c->code_rate_LP = tps_fec_to_api[(tps >> 4) & 7];
switch ((tps >> 13) & 3) { switch ((tps >> 13) & 3) {
case 0: case 0:
op->constellation = QPSK; c->modulation = QPSK;
break; break;
case 1: case 1:
op->constellation = QAM_16; c->modulation = QAM_16;
break; break;
case 2: case 2:
op->constellation = QAM_64; c->modulation = QAM_64;
break; break;
default: default:
op->constellation = QAM_AUTO; c->modulation = QAM_AUTO;
break; break;
} }
op->transmission_mode = (tps & 0x01) ? TRANSMISSION_MODE_8K : c->transmission_mode = (tps & 0x01) ? TRANSMISSION_MODE_8K :
TRANSMISSION_MODE_2K; TRANSMISSION_MODE_2K;
switch ((tps >> 2) & 3) { switch ((tps >> 2) & 3) {
case 0: case 0:
op->guard_interval = GUARD_INTERVAL_1_32; c->guard_interval = GUARD_INTERVAL_1_32;
break; break;
case 1: case 1:
op->guard_interval = GUARD_INTERVAL_1_16; c->guard_interval = GUARD_INTERVAL_1_16;
break; break;
case 2: case 2:
op->guard_interval = GUARD_INTERVAL_1_8; c->guard_interval = GUARD_INTERVAL_1_8;
break; break;
case 3: case 3:
op->guard_interval = GUARD_INTERVAL_1_4; c->guard_interval = GUARD_INTERVAL_1_4;
break; break;
default: default:
op->guard_interval = GUARD_INTERVAL_AUTO; c->guard_interval = GUARD_INTERVAL_AUTO;
break; break;
} }
switch ((tps >> 10) & 7) { switch ((tps >> 10) & 7) {
case 0: case 0:
op->hierarchy_information = HIERARCHY_NONE; c->hierarchy = HIERARCHY_NONE;
break; break;
case 1: case 1:
op->hierarchy_information = HIERARCHY_1; c->hierarchy = HIERARCHY_1;
break; break;
case 2: case 2:
op->hierarchy_information = HIERARCHY_2; c->hierarchy = HIERARCHY_2;
break; break;
case 3: case 3:
op->hierarchy_information = HIERARCHY_4; c->hierarchy = HIERARCHY_4;
break; break;
default: default:
op->hierarchy_information = HIERARCHY_AUTO; c->hierarchy = HIERARCHY_AUTO;
break; break;
} }
param->frequency = state->frequency; c->frequency = state->frequency;
op->bandwidth = state->bandwidth; c->bandwidth_hz = state->bandwidth;
param->inversion = INVERSION_AUTO; c->inversion = INVERSION_AUTO;
return 0; return 0;
} }
@ -651,7 +638,7 @@ struct dvb_frontend *zl10353_attach(const struct zl10353_config *config,
} }
static struct dvb_frontend_ops zl10353_ops = { static struct dvb_frontend_ops zl10353_ops = {
.delsys = { SYS_DVBT },
.info = { .info = {
.name = "Zarlink ZL10353 DVB-T", .name = "Zarlink ZL10353 DVB-T",
.type = FE_OFDM, .type = FE_OFDM,
@ -675,8 +662,8 @@ static struct dvb_frontend_ops zl10353_ops = {
.i2c_gate_ctrl = zl10353_i2c_gate_ctrl, .i2c_gate_ctrl = zl10353_i2c_gate_ctrl,
.write = zl10353_write, .write = zl10353_write,
.set_frontend_legacy = zl10353_set_parameters, .set_frontend = zl10353_set_parameters,
.get_frontend_legacy = zl10353_get_parameters, .get_frontend = zl10353_get_parameters,
.get_tune_settings = zl10353_get_tune_settings, .get_tune_settings = zl10353_get_tune_settings,
.read_status = zl10353_read_status, .read_status = zl10353_read_status,