提交 7d53421c 编写于 作者: M Manu Abraham 提交者: Linus Torvalds

[PATCH] dvb: Twinhan DST: frontend fixes

o Make the inversion setting specific, ie, only for the 200103A DVB-S
  This should not be flagged on other cards.
o Make the frequency setting card specific
o Make the bandwidth setting generic such that it supports more DVB-T cards
o Set QAM size for DVB-C cards that do not autodetect QAM size
o Fix a bug that caused the polarization not to be set.
  Set polarization for cards that do not autodetect polarization
o Fix a bogus frontend signal lock, that caused a tuning delay as well.
o Make the Symbolrate setting card specific
Signed-off-by: NManu Abraham <manu@kromtek.com>
Signed-off-by: NJohannes Stezenbach <js@linuxtv.org>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 64221be7
...@@ -258,10 +258,10 @@ int write_dst(struct dst_state *state, u8 *data, u8 len) ...@@ -258,10 +258,10 @@ int write_dst(struct dst_state *state, u8 *data, u8 len)
if (debug && (verbose > 4)) { if (debug && (verbose > 4)) {
u8 i; u8 i;
if (verbose > 4) { if (verbose > 4) {
dprintk("%s writing", __FUNCTION__); dprintk("%s writing [ ", __FUNCTION__);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
dprintk(" %02x", data[i]); dprintk("%02x ", data[i]);
dprintk("\n"); dprintk("]\n");
} }
} }
for (cnt = 0; cnt < 2; cnt++) { for (cnt = 0; cnt < 2; cnt++) {
...@@ -320,10 +320,29 @@ int read_dst(struct dst_state *state, u8 * ret, u8 len) ...@@ -320,10 +320,29 @@ int read_dst(struct dst_state *state, u8 * ret, u8 len)
} }
EXPORT_SYMBOL(read_dst); EXPORT_SYMBOL(read_dst);
static int dst_set_freq(struct dst_state *state, u32 freq) static int dst_set_polarization(struct dst_state *state)
{ {
u8 *val; switch (state->voltage) {
case SEC_VOLTAGE_13: // vertical
printk("%s: Polarization=[Vertical]\n", __FUNCTION__);
state->tx_tuna[8] |= 0x40; //1
break;
case SEC_VOLTAGE_18: // horizontal
printk("%s: Polarization=[Horizontal]\n", __FUNCTION__);
state->tx_tuna[8] =~ 0x40; // 0
break;
case SEC_VOLTAGE_OFF:
break;
}
return 0;
}
static int dst_set_freq(struct dst_state *state, u32 freq)
{
state->frequency = freq; state->frequency = freq;
if (debug > 4) if (debug > 4)
dprintk("%s: set Frequency %u\n", __FUNCTION__, freq); dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
...@@ -332,46 +351,30 @@ static int dst_set_freq(struct dst_state *state, u32 freq) ...@@ -332,46 +351,30 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
freq = freq / 1000; freq = freq / 1000;
if (freq < 950 || freq > 2150) if (freq < 950 || freq > 2150)
return -EINVAL; return -EINVAL;
val = &state->tx_tuna[0];
val[2] = (freq >> 8) & 0x7f; state->tx_tuna[2] = (freq >> 8);
val[3] = (u8) freq; state->tx_tuna[3] = (u8) freq;
val[4] = 1; state->tx_tuna[4] = 0x01;
val[8] &= ~4; state->tx_tuna[8] &= ~0x04;
if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
if (freq < 1531) if (freq < 1531)
val[8] |= 4; state->tx_tuna[8] |= 0x04;
}
} else if (state->dst_type == DST_TYPE_IS_TERR) { } else if (state->dst_type == DST_TYPE_IS_TERR) {
freq = freq / 1000; freq = freq / 1000;
if (freq < 137000 || freq > 858000) if (freq < 137000 || freq > 858000)
return -EINVAL; return -EINVAL;
val = &state->tx_tuna[0];
val[2] = (freq >> 16) & 0xff;
val[3] = (freq >> 8) & 0xff;
val[4] = (u8) freq;
val[5] = 0;
switch (state->bandwidth) {
case BANDWIDTH_6_MHZ:
val[6] = 6;
break;
case BANDWIDTH_7_MHZ: state->tx_tuna[2] = (freq >> 16) & 0xff;
case BANDWIDTH_AUTO: state->tx_tuna[3] = (freq >> 8) & 0xff;
val[6] = 7; state->tx_tuna[4] = (u8) freq;
break;
case BANDWIDTH_8_MHZ:
val[6] = 8;
break;
}
val[7] = 0;
val[8] = 0;
} else if (state->dst_type == DST_TYPE_IS_CABLE) { } else if (state->dst_type == DST_TYPE_IS_CABLE) {
/* guess till will get one */ state->tx_tuna[2] = (freq >> 16) & 0xff;
freq = freq / 1000; state->tx_tuna[3] = (freq >> 8) & 0xff;
val = &state->tx_tuna[0]; state->tx_tuna[4] = (u8) freq;
val[2] = (freq >> 16) & 0xff;
val[3] = (freq >> 8) & 0xff;
val[4] = (u8) freq;
} else } else
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -379,25 +382,37 @@ static int dst_set_freq(struct dst_state *state, u32 freq) ...@@ -379,25 +382,37 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth) static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth)
{ {
u8 *val;
state->bandwidth = bandwidth; state->bandwidth = bandwidth;
if (state->dst_type != DST_TYPE_IS_TERR) if (state->dst_type != DST_TYPE_IS_TERR)
return 0; return 0;
val = &state->tx_tuna[0];
switch (bandwidth) { switch (bandwidth) {
case BANDWIDTH_6_MHZ: case BANDWIDTH_6_MHZ:
val[6] = 6; if (state->dst_hw_cap & DST_TYPE_HAS_CA)
state->tx_tuna[7] = 0x06;
else {
state->tx_tuna[6] = 0x06;
state->tx_tuna[7] = 0x00;
}
break; break;
case BANDWIDTH_7_MHZ: case BANDWIDTH_7_MHZ:
val[6] = 7; if (state->dst_hw_cap & DST_TYPE_HAS_CA)
state->tx_tuna[7] = 0x07;
else {
state->tx_tuna[6] = 0x07;
state->tx_tuna[7] = 0x00;
}
break; break;
case BANDWIDTH_8_MHZ: case BANDWIDTH_8_MHZ:
val[6] = 8; if (state->dst_hw_cap & DST_TYPE_HAS_CA)
state->tx_tuna[7] = 0x08;
else {
state->tx_tuna[6] = 0x08;
state->tx_tuna[7] = 0x00;
}
break; break;
default: default:
...@@ -408,19 +423,14 @@ static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth) ...@@ -408,19 +423,14 @@ static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth)
static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion) static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion)
{ {
u8 *val;
state->inversion = inversion; state->inversion = inversion;
val = &state->tx_tuna[0];
val[8] &= ~0x80;
switch (inversion) { switch (inversion) {
case INVERSION_OFF: case INVERSION_OFF: // Inversion = Normal
state->tx_tuna[8] &= ~0x80;
break; break;
case INVERSION_ON: case INVERSION_ON:
val[8] |= 0x80; state->tx_tuna[8] |= 0x80;
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -478,6 +488,52 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate) ...@@ -478,6 +488,52 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
return 0; return 0;
} }
static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
{
if (state->dst_type != DST_TYPE_IS_CABLE)
return 0;
state->modulation = modulation;
switch (modulation) {
case QAM_16:
state->tx_tuna[8] = 0x10;
break;
case QAM_32:
state->tx_tuna[8] = 0x20;
break;
case QAM_64:
state->tx_tuna[8] = 0x40;
break;
case QAM_128:
state->tx_tuna[8] = 0x80;
break;
case QAM_256:
state->tx_tuna[8] = 0x00;
break;
case QPSK:
case QAM_AUTO:
case VSB_8:
case VSB_16:
default:
return -EINVAL;
}
return 0;
}
static fe_modulation_t dst_get_modulation(struct dst_state *state)
{
return state->modulation;
}
u8 dst_check_sum(u8 * buf, u32 len) u8 dst_check_sum(u8 * buf, u32 len)
{ {
u32 i; u32 i;
...@@ -577,7 +633,7 @@ struct dst_types dst_tlist[] = { ...@@ -577,7 +633,7 @@ struct dst_types dst_tlist[] = {
.device_id = "200103A", .device_id = "200103A",
.offset = 0, .offset = 0,
.dst_type = DST_TYPE_IS_SAT, .dst_type = DST_TYPE_IS_SAT,
.type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1, .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
.dst_feature = 0 .dst_feature = 0
}, /* obsolete */ }, /* obsolete */
...@@ -626,7 +682,7 @@ struct dst_types dst_tlist[] = { ...@@ -626,7 +682,7 @@ struct dst_types dst_tlist[] = {
.device_id = "DSTMCI", .device_id = "DSTMCI",
.offset = 1, .offset = 1,
.dst_type = DST_TYPE_IS_SAT, .dst_type = DST_TYPE_IS_SAT,
.type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
.dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
| DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
}, },
...@@ -872,7 +928,7 @@ static int dst_get_signal(struct dst_state* state) ...@@ -872,7 +928,7 @@ static int dst_get_signal(struct dst_state* state)
{ {
int retval; int retval;
u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
printk("%s: Getting Signal strength and other parameters !!!!!!!!\n", __FUNCTION__);
if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
state->decode_lock = state->decode_strength = state->decode_snr = 0; state->decode_lock = state->decode_strength = state->decode_snr = 0;
return 0; return 0;
...@@ -954,15 +1010,8 @@ static int dst_get_tuna(struct dst_state* state) ...@@ -954,15 +1010,8 @@ static int dst_get_tuna(struct dst_state* state)
state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3]; state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
state->decode_lock = 1; state->decode_lock = 1;
/*
dst->decode_n1 = (dst->rx_tuna[4] << 8) +
(dst->rx_tuna[5]);
dst->decode_n2 = (dst->rx_tuna[8] << 8) +
(dst->rx_tuna[7]);
*/
state->diseq_flags |= HAS_LOCK; state->diseq_flags |= HAS_LOCK;
/* dst->cur_jiff = jiffies; */
return 1; return 1;
} }
...@@ -1145,7 +1194,8 @@ static int dst_init(struct dvb_frontend* fe) ...@@ -1145,7 +1194,8 @@ static int dst_init(struct dvb_frontend* fe)
static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
state->inversion = INVERSION_ON; // state->inversion = INVERSION_ON;
state->inversion = INVERSION_OFF;
state->voltage = SEC_VOLTAGE_13; state->voltage = SEC_VOLTAGE_13;
state->tone = SEC_TONE_OFF; state->tone = SEC_TONE_OFF;
state->symbol_rate = 29473000; state->symbol_rate = 29473000;
...@@ -1174,7 +1224,7 @@ static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status) ...@@ -1174,7 +1224,7 @@ static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
*status = 0; *status = 0;
if (state->diseq_flags & HAS_LOCK) { if (state->diseq_flags & HAS_LOCK) {
dst_get_signal(state); // dst_get_signal(state); // don't require(?) to ask MCU
if (state->decode_lock) if (state->decode_lock)
*status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI; *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
} }
...@@ -1208,20 +1258,25 @@ static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet ...@@ -1208,20 +1258,25 @@ static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
dst_set_freq(state, p->frequency); dst_set_freq(state, p->frequency);
if (verbose > 4) if (verbose > 4)
dprintk("Set Frequency = [%d]\n", p->frequency); dprintk("Set Frequency=[%d]\n", p->frequency);
dst_set_inversion(state, p->inversion); // dst_set_inversion(state, p->inversion);
if (state->dst_type == DST_TYPE_IS_SAT) { if (state->dst_type == DST_TYPE_IS_SAT) {
if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
dst_set_inversion(state, p->inversion);
dst_set_fec(state, p->u.qpsk.fec_inner); dst_set_fec(state, p->u.qpsk.fec_inner);
dst_set_symbolrate(state, p->u.qpsk.symbol_rate); dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
dst_set_polarization(state);
if (verbose > 4) if (verbose > 4)
dprintk("Set Symbolrate = [%d]\n", p->u.qpsk.symbol_rate); dprintk("Set Symbolrate=[%d]\n", p->u.qpsk.symbol_rate);
} else if (state->dst_type == DST_TYPE_IS_TERR) { } else if (state->dst_type == DST_TYPE_IS_TERR) {
dst_set_bandwidth(state, p->u.ofdm.bandwidth); dst_set_bandwidth(state, p->u.ofdm.bandwidth);
} else if (state->dst_type == DST_TYPE_IS_CABLE) { } else if (state->dst_type == DST_TYPE_IS_CABLE) {
dst_set_fec(state, p->u.qam.fec_inner); dst_set_fec(state, p->u.qam.fec_inner);
dst_set_symbolrate(state, p->u.qam.symbol_rate); dst_set_symbolrate(state, p->u.qam.symbol_rate);
dst_set_modulation(state, p->u.qam.modulation);
} }
dst_write_tuna(fe); dst_write_tuna(fe);
...@@ -1233,8 +1288,11 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet ...@@ -1233,8 +1288,11 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
struct dst_state* state = fe->demodulator_priv; struct dst_state* state = fe->demodulator_priv;
p->frequency = state->decode_freq; p->frequency = state->decode_freq;
p->inversion = state->inversion; // p->inversion = state->inversion;
if (state->dst_type == DST_TYPE_IS_SAT) { if (state->dst_type == DST_TYPE_IS_SAT) {
if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
p->inversion = state->inversion;
p->u.qpsk.symbol_rate = state->symbol_rate; p->u.qpsk.symbol_rate = state->symbol_rate;
p->u.qpsk.fec_inner = dst_get_fec(state); p->u.qpsk.fec_inner = dst_get_fec(state);
} else if (state->dst_type == DST_TYPE_IS_TERR) { } else if (state->dst_type == DST_TYPE_IS_TERR) {
...@@ -1242,7 +1300,8 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet ...@@ -1242,7 +1300,8 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
} else if (state->dst_type == DST_TYPE_IS_CABLE) { } else if (state->dst_type == DST_TYPE_IS_CABLE) {
p->u.qam.symbol_rate = state->symbol_rate; p->u.qam.symbol_rate = state->symbol_rate;
p->u.qam.fec_inner = dst_get_fec(state); p->u.qam.fec_inner = dst_get_fec(state);
p->u.qam.modulation = QAM_AUTO; // p->u.qam.modulation = QAM_AUTO;
p->u.qam.modulation = dst_get_modulation(state);
} }
return 0; return 0;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "dst_ca.h" #include "dst_ca.h"
#include "dst_common.h" #include "dst_common.h"
static unsigned int verbose = 1; static unsigned int verbose = 5;
module_param(verbose, int, 0644); module_param(verbose, int, 0644);
MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
...@@ -295,34 +295,28 @@ static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, ...@@ -295,34 +295,28 @@ static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message,
return 0; return 0;
} }
static int handle_en50221_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer) static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)
{ {
if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) { if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */ hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */ hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
} }
else { else {
hw_buffer->msg[0] = (length & 0xff) + 7;
hw_buffer->msg[1] = 0x40;
hw_buffer->msg[2] = 0x03; hw_buffer->msg[2] = 0x03;
hw_buffer->msg[3] = 0x00; hw_buffer->msg[3] = 0x00;
hw_buffer->msg[4] = 0x03;
hw_buffer->msg[5] = length & 0xff;
hw_buffer->msg[6] = 0x00;
} }
return 0; return 0;
} }
static int debug_8820_buffer(struct ca_msg *hw_buffer)
{
unsigned int i;
dprintk("%s:Debug=[", __FUNCTION__);
for (i = 0; i < (hw_buffer->msg[0] + 1); i++)
dprintk(" %02x", hw_buffer->msg[i]);
dprintk("]\n");
return 0;
}
static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 reply) static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)
{ {
if ((dst_put_ci(state, hw_buffer->msg, (hw_buffer->length + 1), hw_buffer->msg, reply)) < 0) { if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {
dprintk("%s: DST-CI Command failed.\n", __FUNCTION__); dprintk("%s: DST-CI Command failed.\n", __FUNCTION__);
dprintk("%s: Resetting DST.\n", __FUNCTION__); dprintk("%s: Resetting DST.\n", __FUNCTION__);
rdc_reset_state(state); rdc_reset_state(state);
...@@ -334,234 +328,141 @@ static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 r ...@@ -334,234 +328,141 @@ static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 r
return 0; return 0;
} }
u32 asn_1_decode(u8 *asn_1_array)
static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
{ {
u32 hw_offset, buf_offset, i, k; u8 length_field = 0, word_count = 0, count = 0;
u32 program_info_length = 0, es_info_length = 0, length = 0, words = 0; u32 length = 0;
u8 found_prog_ca_desc = 0, found_stream_ca_desc = 0, error_condition = 0, hw_buffer_length = 0;
length_field = asn_1_array[0];
if (verbose > 3) dprintk("%s: Length field=[%02x]\n", __FUNCTION__, length_field);
dprintk("%s, p_ca_message length %d (0x%x)\n", __FUNCTION__,p_ca_message->length,p_ca_message->length ); if (length_field < 0x80) {
length = length_field & 0x7f;
handle_en50221_tag(state, p_ca_message, hw_buffer); /* EN50221 tag */ dprintk("%s: Length=[%02x]\n", __FUNCTION__, length);
} else {
/* Handle the length field (variable) */ word_count = length_field & 0x7f;
if (!(p_ca_message->msg[3] & 0x80)) { /* Length = 1 */ for (count = 0; count < word_count; count++) {
length = p_ca_message->msg[3] & 0x7f; length = (length | asn_1_array[count + 1]) << 8;
words = 0; /* domi's suggestion */ dprintk("%s: Length=[%04x]\n", __FUNCTION__, length);
} }
else { /* Length = words */ }
words = p_ca_message->msg[3] & 0x7f; return length;
for (i = 0; i < words; i++) { }
length = length << 8;
length = length | p_ca_message->msg[4 + i];
}
}
if (verbose > 4) {
dprintk("%s:Length=[%d (0x%x)], Words=[%d]\n", __FUNCTION__, length,length, words);
/* Debug Input string */ static int init_buffer(u8 *buffer, u32 length)
{
u32 i;
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
dprintk(" %02x", p_ca_message->msg[i]); buffer[i] = 0;
dprintk("]\n");
}
hw_offset = 7;
buf_offset = words + 4;
/* Program Header */
if (verbose > 4)
dprintk("\n%s:Program Header=[", __FUNCTION__);
for (i = 0; i < 6; i++) {
hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
if (verbose > 4)
dprintk(" %02x", p_ca_message->msg[buf_offset]);
hw_offset++, buf_offset++, hw_buffer_length++;
}
if (verbose > 4)
dprintk("]\n");
program_info_length = 0;
program_info_length = (((program_info_length | p_ca_message->msg[words + 8]) & 0x0f) << 8) | p_ca_message->msg[words + 9];
if (verbose > 4)
dprintk("%s:Program info Length=[%d][%02x], hw_offset=[%d], buf_offset=[%d] \n",
__FUNCTION__, program_info_length, program_info_length, hw_offset, buf_offset);
if (program_info_length && (program_info_length < 256)) { /* If program_info_length */
hw_buffer->msg[11] = hw_buffer->msg[11] & 0x0f; /* req only 4 bits */
hw_buffer->msg[12] = hw_buffer->msg[12] + 1; /* increment! ASIC bug! */
if (p_ca_message->msg[buf_offset + 1] == 0x09) { /* Check CA descriptor */ return 0;
found_prog_ca_desc = 1; }
if (verbose > 4)
dprintk("%s: Found CA descriptor @ Program level\n", __FUNCTION__);
}
if (found_prog_ca_desc) { /* Command only if CA descriptor */
hw_buffer->msg[13] = p_ca_message->msg[buf_offset]; /* CA PMT command ID */
hw_offset++, buf_offset++, hw_buffer_length++;
}
/* Program descriptors */ static int debug_string(u8 *msg, u32 length, u32 offset)
if (verbose > 4) { {
dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset); u32 i;
dprintk("%s:Program descriptors=[", __FUNCTION__);
}
while (program_info_length && !error_condition) { /* Copy prog descriptors */
if (program_info_length > p_ca_message->length) { /* Error situation */
dprintk ("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d]\n",
__FUNCTION__, __LINE__, program_info_length);
dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
error_condition = 1;
break;
}
hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; dprintk(" String=[ ");
dprintk(" %02x", p_ca_message->msg[buf_offset]); for (i = offset; i < length; i++)
hw_offset++, buf_offset++, hw_buffer_length++, program_info_length--; dprintk("%02x ", msg[i]);
}
if (verbose > 4) {
dprintk("]\n"); dprintk("]\n");
dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);
}
if (found_prog_ca_desc) {
if (!reply) {
hw_buffer->msg[13] = 0x01; /* OK descrambling */
if (verbose > 1)
dprintk("CA PMT Command = OK Descrambling\n");
}
else {
hw_buffer->msg[13] = 0x02; /* Ok MMI */
if (verbose > 1)
dprintk("CA PMT Command = Ok MMI\n");
}
if (query) {
hw_buffer->msg[13] = 0x03; /* Query */
if (verbose > 1)
dprintk("CA PMT Command = CA PMT query\n");
}
}
}
else {
hw_buffer->msg[11] = hw_buffer->msg[11] & 0xf0; /* Don't write to ASIC */
hw_buffer->msg[12] = hw_buffer->msg[12] = 0x00;
}
if (verbose > 4)
dprintk("%s:**********>p_ca_message->length=[%d], buf_offset=[%d], hw_offset=[%d]\n",
__FUNCTION__, p_ca_message->length, buf_offset, hw_offset);
while ((buf_offset < p_ca_message->length) && !error_condition) {
/* Bail out in case of an indefinite loop */
if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
dprintk("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d], buf_offset=[%d]\n",
__FUNCTION__, __LINE__, program_info_length, buf_offset);
dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
error_condition = 1;
break;
}
/* Stream Header */
for (k = 0; k < 5; k++) {
hw_buffer->msg[hw_offset + k] = p_ca_message->msg[buf_offset + k];
}
es_info_length = 0;
es_info_length = (es_info_length | (p_ca_message->msg[buf_offset + 3] & 0x0f)) << 8 | p_ca_message->msg[buf_offset + 4];
if (verbose > 4) {
dprintk("\n%s:----->Stream header=[%02x %02x %02x %02x %02x]\n", __FUNCTION__,
p_ca_message->msg[buf_offset + 0], p_ca_message->msg[buf_offset + 1],
p_ca_message->msg[buf_offset + 2], p_ca_message->msg[buf_offset + 3],
p_ca_message->msg[buf_offset + 4]);
dprintk("%s:----->Stream type=[%02x], es length=[%d (0x%x)], Chars=[%02x] [%02x], buf_offset=[%d]\n", __FUNCTION__,
p_ca_message->msg[buf_offset + 0], es_info_length, es_info_length,
p_ca_message->msg[buf_offset + 3], p_ca_message->msg[buf_offset + 4], buf_offset);
}
hw_buffer->msg[hw_offset + 3] &= 0x0f; /* req only 4 bits */
if (found_prog_ca_desc) { return 0;
hw_buffer->msg[hw_offset + 3] = 0x00; }
hw_buffer->msg[hw_offset + 4] = 0x00;
}
hw_offset += 5, buf_offset += 5, hw_buffer_length += 5;
/* Check for CA descriptor */ static int copy_string(u8 *destination, u8 *source, u32 dest_offset, u32 source_offset, u32 length)
if (p_ca_message->msg[buf_offset + 1] == 0x09) { {
if (verbose > 4) u32 i;
dprintk("%s:Found CA descriptor @ Stream level\n", __FUNCTION__); dprintk("%s: Copying [", __FUNCTION__);
found_stream_ca_desc = 1; for (i = 0; i < length; i++) {
destination[i + dest_offset] = source[i + source_offset];
dprintk(" %02x", source[i + source_offset]);
} }
dprintk("]\n");
/* ES descriptors */ return i;
}
if (es_info_length && !error_condition && !found_prog_ca_desc && found_stream_ca_desc) { static int modify_4_bits(u8 *message, u32 pos)
// if (!ca_pmt_done) { {
hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; /* CA PMT cmd(es) */ message[pos] &= 0x0f;
if (verbose > 4)
printk("%s:----->CA PMT Command ID=[%02x]\n", __FUNCTION__, p_ca_message->msg[buf_offset]);
// hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--, ca_pmt_done = 1;
hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
// }
if (verbose > 4)
dprintk("%s:----->ES descriptors=[", __FUNCTION__);
while (es_info_length && !error_condition) { /* ES descriptors */ return 0;
if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) { }
if (verbose > 4) {
dprintk("%s:\"WARNING\" ES Length error, line=[%d], es_info_length=[%d], buf_offset=[%d]\n",
__FUNCTION__, __LINE__, es_info_length, buf_offset);
dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
}
error_condition = 1;
break;
}
hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
if (verbose > 3)
dprintk("%02x ", hw_buffer->msg[hw_offset]);
hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
}
found_stream_ca_desc = 0; /* unset for new streams */
dprintk("]\n");
}
}
/* MCU Magic words */ static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
{
hw_buffer_length += 7; u32 length = 0, count = 0;
hw_buffer->msg[0] = hw_buffer_length; u8 asn_1_words, program_header_length;
hw_buffer->msg[1] = 64; u16 program_info_length = 0, es_info_length = 0;
hw_buffer->msg[4] = 3; u32 hw_offset = 0, buf_offset = 0, i;
hw_buffer->msg[5] = hw_buffer->msg[0] - 7; u8 dst_tag_length;
hw_buffer->msg[6] = 0;
length = asn_1_decode(&p_ca_message->msg[3]);
dprintk("%s: CA Message length=[%d]\n", __FUNCTION__, length);
dprintk("%s: ASN.1 ", __FUNCTION__);
debug_string(&p_ca_message->msg[4], length, 0); // length does not include tag and length
/* Fix length */ init_buffer(hw_buffer->msg, length);
hw_buffer->length = hw_buffer->msg[0]; handle_dst_tag(state, p_ca_message, hw_buffer, length);
put_checksum(&hw_buffer->msg[0], hw_buffer->msg[0]); hw_offset = 7;
/* Do the actual write */ asn_1_words = 1; // just a hack to test, should compute this one
if (verbose > 4) { buf_offset = 3;
dprintk("%s:======================DEBUGGING================================\n", __FUNCTION__); program_header_length = 6;
dprintk("%s: Actual Length=[%d]\n", __FUNCTION__, hw_buffer_length); dst_tag_length = 7;
}
/* Only for debugging! */ // debug_twinhan_ca_params(state, p_ca_message, hw_buffer, reply, query, length, hw_offset, buf_offset);
if (verbose > 2) // dprintk("%s: Program Header(BUF)", __FUNCTION__);
debug_8820_buffer(hw_buffer); // debug_string(&p_ca_message->msg[4], program_header_length, 0);
if (verbose > 3) // dprintk("%s: Copying Program header\n", __FUNCTION__);
dprintk("%s: Reply = [%d]\n", __FUNCTION__, reply); copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + asn_1_words), program_header_length);
write_to_8820(state, hw_buffer, reply); buf_offset += program_header_length, hw_offset += program_header_length;
modify_4_bits(hw_buffer->msg, (hw_offset - 2));
if (state->type_flags & DST_TYPE_HAS_INC_COUNT) { // workaround
dprintk("%s: Probably an ASIC bug !!!\n", __FUNCTION__);
debug_string(hw_buffer->msg, (hw_offset + program_header_length), 0);
hw_buffer->msg[hw_offset - 1] += 1;
}
// dprintk("%s: Program Header(HW), Count=[%d]", __FUNCTION__, count);
// debug_string(hw_buffer->msg, hw_offset, 0);
program_info_length = ((program_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
dprintk("%s: Program info length=[%02x]\n", __FUNCTION__, program_info_length);
if (program_info_length) {
count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + 1), (program_info_length + 1) ); // copy next elem, not current
buf_offset += count, hw_offset += count;
// dprintk("%s: Program level ", __FUNCTION__);
// debug_string(hw_buffer->msg, hw_offset, 0);
}
buf_offset += 1;// hw_offset += 1;
for (i = buf_offset; i < length; i++) {
// dprintk("%s: Stream Header ", __FUNCTION__);
count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, buf_offset, 5);
modify_4_bits(hw_buffer->msg, (hw_offset + 3));
hw_offset += 5, buf_offset += 5, i += 4;
// debug_string(hw_buffer->msg, hw_offset, (hw_offset - 5));
es_info_length = ((es_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
dprintk("%s: ES info length=[%02x]\n", __FUNCTION__, es_info_length);
if (es_info_length) {
// copy descriptors @ STREAM level
dprintk("%s: Descriptors @ STREAM level...!!! \n", __FUNCTION__);
}
}
hw_buffer->msg[length + dst_tag_length] = dst_check_sum(hw_buffer->msg, (length + dst_tag_length));
// dprintk("%s: Total length=[%d], Checksum=[%02x]\n", __FUNCTION__, (length + dst_tag_length), hw_buffer->msg[length + dst_tag_length]);
debug_string(hw_buffer->msg, (length + dst_tag_length + 1), 0); // dst tags also
write_to_8820(state, hw_buffer, (length + dst_tag_length + 1), reply); // checksum
return 0; return 0;
} }
/* Board supports CA PMT reply ? */ /* Board supports CA PMT reply ? */
static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer) static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
{ {
...@@ -605,7 +506,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, ...@@ -605,7 +506,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
struct ca_msg *hw_buffer; struct ca_msg *hw_buffer;
if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
printk("%s: Memory allocation failure\n", __FUNCTION__); dprintk("%s: Memory allocation failure\n", __FUNCTION__);
return -ENOMEM; return -ENOMEM;
} }
if (verbose > 3) if (verbose > 3)
...@@ -630,8 +531,10 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, ...@@ -630,8 +531,10 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
switch (command) { switch (command) {
case CA_PMT: case CA_PMT:
if (verbose > 3) if (verbose > 3)
// dprintk("Command = SEND_CA_PMT\n");
dprintk("Command = SEND_CA_PMT\n"); dprintk("Command = SEND_CA_PMT\n");
if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) {
if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__); dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__);
return -1; return -1;
} }
...@@ -664,7 +567,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, ...@@ -664,7 +567,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
return -1; return -1;
} }
if (verbose > 3) if (verbose > 3)
printk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__); dprintk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__);
break; break;
} }
...@@ -681,17 +584,17 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd ...@@ -681,17 +584,17 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd
struct ca_msg *p_ca_message; struct ca_msg *p_ca_message;
if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
printk("%s: Memory allocation failure\n", __FUNCTION__); dprintk("%s: Memory allocation failure\n", __FUNCTION__);
return -ENOMEM; return -ENOMEM;
} }
if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) { if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
printk("%s: Memory allocation failure\n", __FUNCTION__); dprintk("%s: Memory allocation failure\n", __FUNCTION__);
return -ENOMEM; return -ENOMEM;
} }
if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) { if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
printk("%s: Memory allocation failure\n", __FUNCTION__); dprintk("%s: Memory allocation failure\n", __FUNCTION__);
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
#define DST_TYPE_HAS_FW_2 16 #define DST_TYPE_HAS_FW_2 16
#define DST_TYPE_HAS_FW_3 32 #define DST_TYPE_HAS_FW_3 32
#define DST_TYPE_HAS_FW_BUILD 64 #define DST_TYPE_HAS_FW_BUILD 64
#define DST_TYPE_HAS_OBS_REGS 128
#define DST_TYPE_HAS_INC_COUNT 256
/* Card capability list */ /* Card capability list */
...@@ -110,6 +112,7 @@ struct dst_state { ...@@ -110,6 +112,7 @@ struct dst_state {
u32 dst_hw_cap; u32 dst_hw_cap;
u8 dst_fw_version; u8 dst_fw_version;
fe_sec_mini_cmd_t minicmd; fe_sec_mini_cmd_t minicmd;
fe_modulation_t modulation;
u8 messages[256]; u8 messages[256];
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册