aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManu Abraham <manu@kromtek.com>2005-07-07 20:57:50 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-07 21:23:56 -0400
commit7d53421c6adce47d067b834c605daeafe1ff9356 (patch)
tree1eb9e34d36f79bb9cd41676b8636445c56a0e2e8
parent64221be7b9006338e4a45228f013e467ee4bf045 (diff)
[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: Manu Abraham <manu@kromtek.com> Signed-off-by: Johannes Stezenbach <js@linuxtv.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/media/dvb/bt8xx/dst.c227
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c349
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h3
3 files changed, 272 insertions, 307 deletions
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 1339912c308b..1f97c37fe9a6 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -258,10 +258,10 @@ int write_dst(struct dst_state *state, u8 *data, u8 len)
258 if (debug && (verbose > 4)) { 258 if (debug && (verbose > 4)) {
259 u8 i; 259 u8 i;
260 if (verbose > 4) { 260 if (verbose > 4) {
261 dprintk("%s writing", __FUNCTION__); 261 dprintk("%s writing [ ", __FUNCTION__);
262 for (i = 0; i < len; i++) 262 for (i = 0; i < len; i++)
263 dprintk(" %02x", data[i]); 263 dprintk("%02x ", data[i]);
264 dprintk("\n"); 264 dprintk("]\n");
265 } 265 }
266 } 266 }
267 for (cnt = 0; cnt < 2; cnt++) { 267 for (cnt = 0; cnt < 2; cnt++) {
@@ -320,10 +320,29 @@ int read_dst(struct dst_state *state, u8 * ret, u8 len)
320} 320}
321EXPORT_SYMBOL(read_dst); 321EXPORT_SYMBOL(read_dst);
322 322
323static int dst_set_freq(struct dst_state *state, u32 freq) 323static int dst_set_polarization(struct dst_state *state)
324{ 324{
325 u8 *val; 325 switch (state->voltage) {
326 case SEC_VOLTAGE_13: // vertical
327 printk("%s: Polarization=[Vertical]\n", __FUNCTION__);
328 state->tx_tuna[8] |= 0x40; //1
329 break;
330
331 case SEC_VOLTAGE_18: // horizontal
332 printk("%s: Polarization=[Horizontal]\n", __FUNCTION__);
333 state->tx_tuna[8] =~ 0x40; // 0
334 break;
326 335
336 case SEC_VOLTAGE_OFF:
337
338 break;
339 }
340
341 return 0;
342}
343
344static int dst_set_freq(struct dst_state *state, u32 freq)
345{
327 state->frequency = freq; 346 state->frequency = freq;
328 if (debug > 4) 347 if (debug > 4)
329 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq); 348 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
@@ -332,46 +351,30 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
332 freq = freq / 1000; 351 freq = freq / 1000;
333 if (freq < 950 || freq > 2150) 352 if (freq < 950 || freq > 2150)
334 return -EINVAL; 353 return -EINVAL;
335 val = &state->tx_tuna[0]; 354
336 val[2] = (freq >> 8) & 0x7f; 355 state->tx_tuna[2] = (freq >> 8);
337 val[3] = (u8) freq; 356 state->tx_tuna[3] = (u8) freq;
338 val[4] = 1; 357 state->tx_tuna[4] = 0x01;
339 val[8] &= ~4; 358 state->tx_tuna[8] &= ~0x04;
340 if (freq < 1531) 359 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
341 val[8] |= 4; 360 if (freq < 1531)
361 state->tx_tuna[8] |= 0x04;
362 }
363
342 } else if (state->dst_type == DST_TYPE_IS_TERR) { 364 } else if (state->dst_type == DST_TYPE_IS_TERR) {
343 freq = freq / 1000; 365 freq = freq / 1000;
344 if (freq < 137000 || freq > 858000) 366 if (freq < 137000 || freq > 858000)
345 return -EINVAL; 367 return -EINVAL;
346 val = &state->tx_tuna[0];
347 val[2] = (freq >> 16) & 0xff;
348 val[3] = (freq >> 8) & 0xff;
349 val[4] = (u8) freq;
350 val[5] = 0;
351 switch (state->bandwidth) {
352 case BANDWIDTH_6_MHZ:
353 val[6] = 6;
354 break;
355
356 case BANDWIDTH_7_MHZ:
357 case BANDWIDTH_AUTO:
358 val[6] = 7;
359 break;
360 368
361 case BANDWIDTH_8_MHZ: 369 state->tx_tuna[2] = (freq >> 16) & 0xff;
362 val[6] = 8; 370 state->tx_tuna[3] = (freq >> 8) & 0xff;
363 break; 371 state->tx_tuna[4] = (u8) freq;
364 }
365 372
366 val[7] = 0;
367 val[8] = 0;
368 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 373 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
369 /* guess till will get one */ 374 state->tx_tuna[2] = (freq >> 16) & 0xff;
370 freq = freq / 1000; 375 state->tx_tuna[3] = (freq >> 8) & 0xff;
371 val = &state->tx_tuna[0]; 376 state->tx_tuna[4] = (u8) freq;
372 val[2] = (freq >> 16) & 0xff; 377
373 val[3] = (freq >> 8) & 0xff;
374 val[4] = (u8) freq;
375 } else 378 } else
376 return -EINVAL; 379 return -EINVAL;
377 return 0; 380 return 0;
@@ -379,51 +382,58 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
379 382
380static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth) 383static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth)
381{ 384{
382 u8 *val;
383
384 state->bandwidth = bandwidth; 385 state->bandwidth = bandwidth;
385 386
386 if (state->dst_type != DST_TYPE_IS_TERR) 387 if (state->dst_type != DST_TYPE_IS_TERR)
387 return 0; 388 return 0;
388 389
389 val = &state->tx_tuna[0];
390 switch (bandwidth) { 390 switch (bandwidth) {
391 case BANDWIDTH_6_MHZ: 391 case BANDWIDTH_6_MHZ:
392 val[6] = 6; 392 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
393 break; 393 state->tx_tuna[7] = 0x06;
394 else {
395 state->tx_tuna[6] = 0x06;
396 state->tx_tuna[7] = 0x00;
397 }
398 break;
394 399
395 case BANDWIDTH_7_MHZ: 400 case BANDWIDTH_7_MHZ:
396 val[6] = 7; 401 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
397 break; 402 state->tx_tuna[7] = 0x07;
403 else {
404 state->tx_tuna[6] = 0x07;
405 state->tx_tuna[7] = 0x00;
406 }
407 break;
398 408
399 case BANDWIDTH_8_MHZ: 409 case BANDWIDTH_8_MHZ:
400 val[6] = 8; 410 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
401 break; 411 state->tx_tuna[7] = 0x08;
412 else {
413 state->tx_tuna[6] = 0x08;
414 state->tx_tuna[7] = 0x00;
415 }
416 break;
402 417
403 default: 418 default:
404 return -EINVAL; 419 return -EINVAL;
405 } 420 }
406 return 0; 421 return 0;
407} 422}
408 423
409static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion) 424static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion)
410{ 425{
411 u8 *val;
412
413 state->inversion = inversion; 426 state->inversion = inversion;
414
415 val = &state->tx_tuna[0];
416
417 val[8] &= ~0x80;
418
419 switch (inversion) { 427 switch (inversion) {
420 case INVERSION_OFF: 428 case INVERSION_OFF: // Inversion = Normal
421 break; 429 state->tx_tuna[8] &= ~0x80;
422 case INVERSION_ON: 430 break;
423 val[8] |= 0x80; 431
424 break; 432 case INVERSION_ON:
425 default: 433 state->tx_tuna[8] |= 0x80;
426 return -EINVAL; 434 break;
435 default:
436 return -EINVAL;
427 } 437 }
428 return 0; 438 return 0;
429} 439}
@@ -478,6 +488,52 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
478 return 0; 488 return 0;
479} 489}
480 490
491
492static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
493{
494 if (state->dst_type != DST_TYPE_IS_CABLE)
495 return 0;
496
497 state->modulation = modulation;
498 switch (modulation) {
499 case QAM_16:
500 state->tx_tuna[8] = 0x10;
501 break;
502
503 case QAM_32:
504 state->tx_tuna[8] = 0x20;
505 break;
506
507 case QAM_64:
508 state->tx_tuna[8] = 0x40;
509 break;
510
511 case QAM_128:
512 state->tx_tuna[8] = 0x80;
513 break;
514
515 case QAM_256:
516 state->tx_tuna[8] = 0x00;
517 break;
518
519 case QPSK:
520 case QAM_AUTO:
521 case VSB_8:
522 case VSB_16:
523 default:
524 return -EINVAL;
525
526 }
527
528 return 0;
529}
530
531static fe_modulation_t dst_get_modulation(struct dst_state *state)
532{
533 return state->modulation;
534}
535
536
481u8 dst_check_sum(u8 * buf, u32 len) 537u8 dst_check_sum(u8 * buf, u32 len)
482{ 538{
483 u32 i; 539 u32 i;
@@ -577,7 +633,7 @@ struct dst_types dst_tlist[] = {
577 .device_id = "200103A", 633 .device_id = "200103A",
578 .offset = 0, 634 .offset = 0,
579 .dst_type = DST_TYPE_IS_SAT, 635 .dst_type = DST_TYPE_IS_SAT,
580 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1, 636 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
581 .dst_feature = 0 637 .dst_feature = 0
582 }, /* obsolete */ 638 }, /* obsolete */
583 639
@@ -626,7 +682,7 @@ struct dst_types dst_tlist[] = {
626 .device_id = "DSTMCI", 682 .device_id = "DSTMCI",
627 .offset = 1, 683 .offset = 1,
628 .dst_type = DST_TYPE_IS_SAT, 684 .dst_type = DST_TYPE_IS_SAT,
629 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, 685 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
630 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 686 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
631 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC 687 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
632 }, 688 },
@@ -872,7 +928,7 @@ static int dst_get_signal(struct dst_state* state)
872{ 928{
873 int retval; 929 int retval;
874 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; 930 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
875 931 printk("%s: Getting Signal strength and other parameters !!!!!!!!\n", __FUNCTION__);
876 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { 932 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
877 state->decode_lock = state->decode_strength = state->decode_snr = 0; 933 state->decode_lock = state->decode_strength = state->decode_snr = 0;
878 return 0; 934 return 0;
@@ -954,15 +1010,8 @@ static int dst_get_tuna(struct dst_state* state)
954 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3]; 1010 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
955 1011
956 state->decode_lock = 1; 1012 state->decode_lock = 1;
957 /*
958 dst->decode_n1 = (dst->rx_tuna[4] << 8) +
959 (dst->rx_tuna[5]);
960
961 dst->decode_n2 = (dst->rx_tuna[8] << 8) +
962 (dst->rx_tuna[7]);
963 */
964 state->diseq_flags |= HAS_LOCK; 1013 state->diseq_flags |= HAS_LOCK;
965 /* dst->cur_jiff = jiffies; */ 1014
966 return 1; 1015 return 1;
967} 1016}
968 1017
@@ -1145,7 +1194,8 @@ static int dst_init(struct dvb_frontend* fe)
1145 static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1194 static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1146 static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1195 static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1147 static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1196 static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1148 state->inversion = INVERSION_ON; 1197// state->inversion = INVERSION_ON;
1198 state->inversion = INVERSION_OFF;
1149 state->voltage = SEC_VOLTAGE_13; 1199 state->voltage = SEC_VOLTAGE_13;
1150 state->tone = SEC_TONE_OFF; 1200 state->tone = SEC_TONE_OFF;
1151 state->symbol_rate = 29473000; 1201 state->symbol_rate = 29473000;
@@ -1174,7 +1224,7 @@ static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
1174 1224
1175 *status = 0; 1225 *status = 0;
1176 if (state->diseq_flags & HAS_LOCK) { 1226 if (state->diseq_flags & HAS_LOCK) {
1177 dst_get_signal(state); 1227// dst_get_signal(state); // don't require(?) to ask MCU
1178 if (state->decode_lock) 1228 if (state->decode_lock)
1179 *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI; 1229 *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
1180 } 1230 }
@@ -1208,20 +1258,25 @@ static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
1208 1258
1209 dst_set_freq(state, p->frequency); 1259 dst_set_freq(state, p->frequency);
1210 if (verbose > 4) 1260 if (verbose > 4)
1211 dprintk("Set Frequency = [%d]\n", p->frequency); 1261 dprintk("Set Frequency=[%d]\n", p->frequency);
1212 1262
1213 dst_set_inversion(state, p->inversion); 1263// dst_set_inversion(state, p->inversion);
1214 if (state->dst_type == DST_TYPE_IS_SAT) { 1264 if (state->dst_type == DST_TYPE_IS_SAT) {
1265 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1266 dst_set_inversion(state, p->inversion);
1267
1215 dst_set_fec(state, p->u.qpsk.fec_inner); 1268 dst_set_fec(state, p->u.qpsk.fec_inner);
1216 dst_set_symbolrate(state, p->u.qpsk.symbol_rate); 1269 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
1270 dst_set_polarization(state);
1217 if (verbose > 4) 1271 if (verbose > 4)
1218 dprintk("Set Symbolrate = [%d]\n", p->u.qpsk.symbol_rate); 1272 dprintk("Set Symbolrate=[%d]\n", p->u.qpsk.symbol_rate);
1219 1273
1220 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1274 } else if (state->dst_type == DST_TYPE_IS_TERR) {
1221 dst_set_bandwidth(state, p->u.ofdm.bandwidth); 1275 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
1222 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1276 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1223 dst_set_fec(state, p->u.qam.fec_inner); 1277 dst_set_fec(state, p->u.qam.fec_inner);
1224 dst_set_symbolrate(state, p->u.qam.symbol_rate); 1278 dst_set_symbolrate(state, p->u.qam.symbol_rate);
1279 dst_set_modulation(state, p->u.qam.modulation);
1225 } 1280 }
1226 dst_write_tuna(fe); 1281 dst_write_tuna(fe);
1227 1282
@@ -1233,8 +1288,11 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
1233 struct dst_state* state = fe->demodulator_priv; 1288 struct dst_state* state = fe->demodulator_priv;
1234 1289
1235 p->frequency = state->decode_freq; 1290 p->frequency = state->decode_freq;
1236 p->inversion = state->inversion; 1291// p->inversion = state->inversion;
1237 if (state->dst_type == DST_TYPE_IS_SAT) { 1292 if (state->dst_type == DST_TYPE_IS_SAT) {
1293 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1294 p->inversion = state->inversion;
1295
1238 p->u.qpsk.symbol_rate = state->symbol_rate; 1296 p->u.qpsk.symbol_rate = state->symbol_rate;
1239 p->u.qpsk.fec_inner = dst_get_fec(state); 1297 p->u.qpsk.fec_inner = dst_get_fec(state);
1240 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1298 } 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 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1300 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1243 p->u.qam.symbol_rate = state->symbol_rate; 1301 p->u.qam.symbol_rate = state->symbol_rate;
1244 p->u.qam.fec_inner = dst_get_fec(state); 1302 p->u.qam.fec_inner = dst_get_fec(state);
1245 p->u.qam.modulation = QAM_AUTO; 1303// p->u.qam.modulation = QAM_AUTO;
1304 p->u.qam.modulation = dst_get_modulation(state);
1246 } 1305 }
1247 1306
1248 return 0; 1307 return 0;
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index d781504cc2fa..bfaacd5fc20f 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -32,7 +32,7 @@
32#include "dst_ca.h" 32#include "dst_ca.h"
33#include "dst_common.h" 33#include "dst_common.h"
34 34
35static unsigned int verbose = 1; 35static unsigned int verbose = 5;
36module_param(verbose, int, 0644); 36module_param(verbose, int, 0644);
37MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 37MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
38 38
@@ -295,34 +295,28 @@ static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message,
295 return 0; 295 return 0;
296} 296}
297 297
298static int handle_en50221_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer) 298static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)
299{ 299{
300 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) { 300 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
301 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */ 301 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
302 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */ 302 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
303 } 303 }
304 else { 304 else {
305 hw_buffer->msg[0] = (length & 0xff) + 7;
306 hw_buffer->msg[1] = 0x40;
305 hw_buffer->msg[2] = 0x03; 307 hw_buffer->msg[2] = 0x03;
306 hw_buffer->msg[3] = 0x00; 308 hw_buffer->msg[3] = 0x00;
309 hw_buffer->msg[4] = 0x03;
310 hw_buffer->msg[5] = length & 0xff;
311 hw_buffer->msg[6] = 0x00;
307 } 312 }
308 return 0; 313 return 0;
309} 314}
310 315
311static int debug_8820_buffer(struct ca_msg *hw_buffer)
312{
313 unsigned int i;
314
315 dprintk("%s:Debug=[", __FUNCTION__);
316 for (i = 0; i < (hw_buffer->msg[0] + 1); i++)
317 dprintk(" %02x", hw_buffer->msg[i]);
318 dprintk("]\n");
319
320 return 0;
321}
322 316
323static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 reply) 317static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)
324{ 318{
325 if ((dst_put_ci(state, hw_buffer->msg, (hw_buffer->length + 1), hw_buffer->msg, reply)) < 0) { 319 if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {
326 dprintk("%s: DST-CI Command failed.\n", __FUNCTION__); 320 dprintk("%s: DST-CI Command failed.\n", __FUNCTION__);
327 dprintk("%s: Resetting DST.\n", __FUNCTION__); 321 dprintk("%s: Resetting DST.\n", __FUNCTION__);
328 rdc_reset_state(state); 322 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 return 0; 328 return 0;
335} 329}
336 330
337 331u32 asn_1_decode(u8 *asn_1_array)
338static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
339{ 332{
340 u32 hw_offset, buf_offset, i, k; 333 u8 length_field = 0, word_count = 0, count = 0;
341 u32 program_info_length = 0, es_info_length = 0, length = 0, words = 0; 334 u32 length = 0;
342 u8 found_prog_ca_desc = 0, found_stream_ca_desc = 0, error_condition = 0, hw_buffer_length = 0; 335
343 336 length_field = asn_1_array[0];
344 if (verbose > 3) 337 dprintk("%s: Length field=[%02x]\n", __FUNCTION__, length_field);
345 dprintk("%s, p_ca_message length %d (0x%x)\n", __FUNCTION__,p_ca_message->length,p_ca_message->length ); 338 if (length_field < 0x80) {
346 339 length = length_field & 0x7f;
347 handle_en50221_tag(state, p_ca_message, hw_buffer); /* EN50221 tag */ 340 dprintk("%s: Length=[%02x]\n", __FUNCTION__, length);
348 341 } else {
349 /* Handle the length field (variable) */ 342 word_count = length_field & 0x7f;
350 if (!(p_ca_message->msg[3] & 0x80)) { /* Length = 1 */ 343 for (count = 0; count < word_count; count++) {
351 length = p_ca_message->msg[3] & 0x7f; 344 length = (length | asn_1_array[count + 1]) << 8;
352 words = 0; /* domi's suggestion */ 345 dprintk("%s: Length=[%04x]\n", __FUNCTION__, length);
353 }
354 else { /* Length = words */
355 words = p_ca_message->msg[3] & 0x7f;
356 for (i = 0; i < words; i++) {
357 length = length << 8;
358 length = length | p_ca_message->msg[4 + i];
359 } 346 }
360 } 347 }
361 if (verbose > 4) { 348 return length;
362 dprintk("%s:Length=[%d (0x%x)], Words=[%d]\n", __FUNCTION__, length,length, words); 349}
363
364 /* Debug Input string */
365 for (i = 0; i < length; i++)
366 dprintk(" %02x", p_ca_message->msg[i]);
367 dprintk("]\n");
368 }
369
370 hw_offset = 7;
371 buf_offset = words + 4;
372
373 /* Program Header */
374 if (verbose > 4)
375 dprintk("\n%s:Program Header=[", __FUNCTION__);
376 for (i = 0; i < 6; i++) {
377 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
378 if (verbose > 4)
379 dprintk(" %02x", p_ca_message->msg[buf_offset]);
380 hw_offset++, buf_offset++, hw_buffer_length++;
381 }
382 if (verbose > 4)
383 dprintk("]\n");
384 350
385 program_info_length = 0; 351static int init_buffer(u8 *buffer, u32 length)
386 program_info_length = (((program_info_length | p_ca_message->msg[words + 8]) & 0x0f) << 8) | p_ca_message->msg[words + 9]; 352{
387 if (verbose > 4) 353 u32 i;
388 dprintk("%s:Program info Length=[%d][%02x], hw_offset=[%d], buf_offset=[%d] \n", 354 for (i = 0; i < length; i++)
389 __FUNCTION__, program_info_length, program_info_length, hw_offset, buf_offset); 355 buffer[i] = 0;
390 356
391 if (program_info_length && (program_info_length < 256)) { /* If program_info_length */ 357 return 0;
392 hw_buffer->msg[11] = hw_buffer->msg[11] & 0x0f; /* req only 4 bits */ 358}
393 hw_buffer->msg[12] = hw_buffer->msg[12] + 1; /* increment! ASIC bug! */
394 359
395 if (p_ca_message->msg[buf_offset + 1] == 0x09) { /* Check CA descriptor */ 360static int debug_string(u8 *msg, u32 length, u32 offset)
396 found_prog_ca_desc = 1; 361{
397 if (verbose > 4) 362 u32 i;
398 dprintk("%s: Found CA descriptor @ Program level\n", __FUNCTION__);
399 }
400 363
401 if (found_prog_ca_desc) { /* Command only if CA descriptor */ 364 dprintk(" String=[ ");
402 hw_buffer->msg[13] = p_ca_message->msg[buf_offset]; /* CA PMT command ID */ 365 for (i = offset; i < length; i++)
403 hw_offset++, buf_offset++, hw_buffer_length++; 366 dprintk("%02x ", msg[i]);
404 } 367 dprintk("]\n");
405 368
406 /* Program descriptors */ 369 return 0;
407 if (verbose > 4) { 370}
408 dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);
409 dprintk("%s:Program descriptors=[", __FUNCTION__);
410 }
411 while (program_info_length && !error_condition) { /* Copy prog descriptors */
412 if (program_info_length > p_ca_message->length) { /* Error situation */
413 dprintk ("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d]\n",
414 __FUNCTION__, __LINE__, program_info_length);
415 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
416 error_condition = 1;
417 break;
418 }
419 371
420 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; 372static int copy_string(u8 *destination, u8 *source, u32 dest_offset, u32 source_offset, u32 length)
421 dprintk(" %02x", p_ca_message->msg[buf_offset]); 373{
422 hw_offset++, buf_offset++, hw_buffer_length++, program_info_length--; 374 u32 i;
423 } 375 dprintk("%s: Copying [", __FUNCTION__);
424 if (verbose > 4) { 376 for (i = 0; i < length; i++) {
425 dprintk("]\n"); 377 destination[i + dest_offset] = source[i + source_offset];
426 dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset); 378 dprintk(" %02x", source[i + source_offset]);
427 }
428 if (found_prog_ca_desc) {
429 if (!reply) {
430 hw_buffer->msg[13] = 0x01; /* OK descrambling */
431 if (verbose > 1)
432 dprintk("CA PMT Command = OK Descrambling\n");
433 }
434 else {
435 hw_buffer->msg[13] = 0x02; /* Ok MMI */
436 if (verbose > 1)
437 dprintk("CA PMT Command = Ok MMI\n");
438 }
439 if (query) {
440 hw_buffer->msg[13] = 0x03; /* Query */
441 if (verbose > 1)
442 dprintk("CA PMT Command = CA PMT query\n");
443 }
444 }
445 }
446 else {
447 hw_buffer->msg[11] = hw_buffer->msg[11] & 0xf0; /* Don't write to ASIC */
448 hw_buffer->msg[12] = hw_buffer->msg[12] = 0x00;
449 } 379 }
450 if (verbose > 4) 380 dprintk("]\n");
451 dprintk("%s:**********>p_ca_message->length=[%d], buf_offset=[%d], hw_offset=[%d]\n",
452 __FUNCTION__, p_ca_message->length, buf_offset, hw_offset);
453
454 while ((buf_offset < p_ca_message->length) && !error_condition) {
455 /* Bail out in case of an indefinite loop */
456 if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
457 dprintk("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d], buf_offset=[%d]\n",
458 __FUNCTION__, __LINE__, program_info_length, buf_offset);
459
460 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
461 error_condition = 1;
462 break;
463 }
464
465 /* Stream Header */
466
467 for (k = 0; k < 5; k++) {
468 hw_buffer->msg[hw_offset + k] = p_ca_message->msg[buf_offset + k];
469 }
470 381
471 es_info_length = 0; 382 return i;
472 es_info_length = (es_info_length | (p_ca_message->msg[buf_offset + 3] & 0x0f)) << 8 | p_ca_message->msg[buf_offset + 4]; 383}
473 384
474 if (verbose > 4) { 385static int modify_4_bits(u8 *message, u32 pos)
475 dprintk("\n%s:----->Stream header=[%02x %02x %02x %02x %02x]\n", __FUNCTION__, 386{
476 p_ca_message->msg[buf_offset + 0], p_ca_message->msg[buf_offset + 1], 387 message[pos] &= 0x0f;
477 p_ca_message->msg[buf_offset + 2], p_ca_message->msg[buf_offset + 3],
478 p_ca_message->msg[buf_offset + 4]);
479 388
480 dprintk("%s:----->Stream type=[%02x], es length=[%d (0x%x)], Chars=[%02x] [%02x], buf_offset=[%d]\n", __FUNCTION__, 389 return 0;
481 p_ca_message->msg[buf_offset + 0], es_info_length, es_info_length, 390}
482 p_ca_message->msg[buf_offset + 3], p_ca_message->msg[buf_offset + 4], buf_offset);
483 }
484 391
485 hw_buffer->msg[hw_offset + 3] &= 0x0f; /* req only 4 bits */
486 392
487 if (found_prog_ca_desc) {
488 hw_buffer->msg[hw_offset + 3] = 0x00;
489 hw_buffer->msg[hw_offset + 4] = 0x00;
490 }
491 393
492 hw_offset += 5, buf_offset += 5, hw_buffer_length += 5; 394static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
395{
396 u32 length = 0, count = 0;
397 u8 asn_1_words, program_header_length;
398 u16 program_info_length = 0, es_info_length = 0;
399 u32 hw_offset = 0, buf_offset = 0, i;
400 u8 dst_tag_length;
493 401
494 /* Check for CA descriptor */ 402 length = asn_1_decode(&p_ca_message->msg[3]);
495 if (p_ca_message->msg[buf_offset + 1] == 0x09) { 403 dprintk("%s: CA Message length=[%d]\n", __FUNCTION__, length);
496 if (verbose > 4) 404 dprintk("%s: ASN.1 ", __FUNCTION__);
497 dprintk("%s:Found CA descriptor @ Stream level\n", __FUNCTION__); 405 debug_string(&p_ca_message->msg[4], length, 0); // length does not include tag and length
498 found_stream_ca_desc = 1;
499 }
500 406
501 /* ES descriptors */ 407 init_buffer(hw_buffer->msg, length);
502 408 handle_dst_tag(state, p_ca_message, hw_buffer, length);
503 if (es_info_length && !error_condition && !found_prog_ca_desc && found_stream_ca_desc) {
504// if (!ca_pmt_done) {
505 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; /* CA PMT cmd(es) */
506 if (verbose > 4)
507 printk("%s:----->CA PMT Command ID=[%02x]\n", __FUNCTION__, p_ca_message->msg[buf_offset]);
508// hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--, ca_pmt_done = 1;
509 hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
510// }
511 if (verbose > 4)
512 dprintk("%s:----->ES descriptors=[", __FUNCTION__);
513
514 while (es_info_length && !error_condition) { /* ES descriptors */
515 if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
516 if (verbose > 4) {
517 dprintk("%s:\"WARNING\" ES Length error, line=[%d], es_info_length=[%d], buf_offset=[%d]\n",
518 __FUNCTION__, __LINE__, es_info_length, buf_offset);
519
520 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
521 }
522 error_condition = 1;
523 break;
524 }
525 409
526 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; 410 hw_offset = 7;
527 if (verbose > 3) 411 asn_1_words = 1; // just a hack to test, should compute this one
528 dprintk("%02x ", hw_buffer->msg[hw_offset]); 412 buf_offset = 3;
529 hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--; 413 program_header_length = 6;
530 } 414 dst_tag_length = 7;
531 found_stream_ca_desc = 0; /* unset for new streams */ 415
532 dprintk("]\n"); 416// debug_twinhan_ca_params(state, p_ca_message, hw_buffer, reply, query, length, hw_offset, buf_offset);
417// dprintk("%s: Program Header(BUF)", __FUNCTION__);
418// debug_string(&p_ca_message->msg[4], program_header_length, 0);
419// dprintk("%s: Copying Program header\n", __FUNCTION__);
420 copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + asn_1_words), program_header_length);
421 buf_offset += program_header_length, hw_offset += program_header_length;
422 modify_4_bits(hw_buffer->msg, (hw_offset - 2));
423 if (state->type_flags & DST_TYPE_HAS_INC_COUNT) { // workaround
424 dprintk("%s: Probably an ASIC bug !!!\n", __FUNCTION__);
425 debug_string(hw_buffer->msg, (hw_offset + program_header_length), 0);
426 hw_buffer->msg[hw_offset - 1] += 1;
427 }
428
429// dprintk("%s: Program Header(HW), Count=[%d]", __FUNCTION__, count);
430// debug_string(hw_buffer->msg, hw_offset, 0);
431
432 program_info_length = ((program_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
433 dprintk("%s: Program info length=[%02x]\n", __FUNCTION__, program_info_length);
434 if (program_info_length) {
435 count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + 1), (program_info_length + 1) ); // copy next elem, not current
436 buf_offset += count, hw_offset += count;
437// dprintk("%s: Program level ", __FUNCTION__);
438// debug_string(hw_buffer->msg, hw_offset, 0);
439 }
440
441 buf_offset += 1;// hw_offset += 1;
442 for (i = buf_offset; i < length; i++) {
443// dprintk("%s: Stream Header ", __FUNCTION__);
444 count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, buf_offset, 5);
445 modify_4_bits(hw_buffer->msg, (hw_offset + 3));
446
447 hw_offset += 5, buf_offset += 5, i += 4;
448// debug_string(hw_buffer->msg, hw_offset, (hw_offset - 5));
449 es_info_length = ((es_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
450 dprintk("%s: ES info length=[%02x]\n", __FUNCTION__, es_info_length);
451 if (es_info_length) {
452 // copy descriptors @ STREAM level
453 dprintk("%s: Descriptors @ STREAM level...!!! \n", __FUNCTION__);
533 } 454 }
534 }
535
536 /* MCU Magic words */
537
538 hw_buffer_length += 7;
539 hw_buffer->msg[0] = hw_buffer_length;
540 hw_buffer->msg[1] = 64;
541 hw_buffer->msg[4] = 3;
542 hw_buffer->msg[5] = hw_buffer->msg[0] - 7;
543 hw_buffer->msg[6] = 0;
544
545 455
546 /* Fix length */
547 hw_buffer->length = hw_buffer->msg[0];
548
549 put_checksum(&hw_buffer->msg[0], hw_buffer->msg[0]);
550 /* Do the actual write */
551 if (verbose > 4) {
552 dprintk("%s:======================DEBUGGING================================\n", __FUNCTION__);
553 dprintk("%s: Actual Length=[%d]\n", __FUNCTION__, hw_buffer_length);
554 } 456 }
555 /* Only for debugging! */ 457 hw_buffer->msg[length + dst_tag_length] = dst_check_sum(hw_buffer->msg, (length + dst_tag_length));
556 if (verbose > 2) 458// dprintk("%s: Total length=[%d], Checksum=[%02x]\n", __FUNCTION__, (length + dst_tag_length), hw_buffer->msg[length + dst_tag_length]);
557 debug_8820_buffer(hw_buffer); 459 debug_string(hw_buffer->msg, (length + dst_tag_length + 1), 0); // dst tags also
558 if (verbose > 3) 460 write_to_8820(state, hw_buffer, (length + dst_tag_length + 1), reply); // checksum
559 dprintk("%s: Reply = [%d]\n", __FUNCTION__, reply);
560 write_to_8820(state, hw_buffer, reply);
561 461
562 return 0; 462 return 0;
563} 463}
564 464
465
565/* Board supports CA PMT reply ? */ 466/* Board supports CA PMT reply ? */
566static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer) 467static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
567{ 468{
@@ -605,7 +506,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
605 struct ca_msg *hw_buffer; 506 struct ca_msg *hw_buffer;
606 507
607 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { 508 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
608 printk("%s: Memory allocation failure\n", __FUNCTION__); 509 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
609 return -ENOMEM; 510 return -ENOMEM;
610 } 511 }
611 if (verbose > 3) 512 if (verbose > 3)
@@ -630,8 +531,10 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
630 switch (command) { 531 switch (command) {
631 case CA_PMT: 532 case CA_PMT:
632 if (verbose > 3) 533 if (verbose > 3)
534// dprintk("Command = SEND_CA_PMT\n");
633 dprintk("Command = SEND_CA_PMT\n"); 535 dprintk("Command = SEND_CA_PMT\n");
634 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { 536// if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) {
537 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
635 dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__); 538 dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__);
636 return -1; 539 return -1;
637 } 540 }
@@ -664,7 +567,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
664 return -1; 567 return -1;
665 } 568 }
666 if (verbose > 3) 569 if (verbose > 3)
667 printk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__); 570 dprintk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__);
668 571
669 break; 572 break;
670 } 573 }
@@ -681,17 +584,17 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd
681 struct ca_msg *p_ca_message; 584 struct ca_msg *p_ca_message;
682 585
683 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { 586 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
684 printk("%s: Memory allocation failure\n", __FUNCTION__); 587 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
685 return -ENOMEM; 588 return -ENOMEM;
686 } 589 }
687 590
688 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) { 591 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
689 printk("%s: Memory allocation failure\n", __FUNCTION__); 592 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
690 return -ENOMEM; 593 return -ENOMEM;
691 } 594 }
692 595
693 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) { 596 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
694 printk("%s: Memory allocation failure\n", __FUNCTION__); 597 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
695 return -ENOMEM; 598 return -ENOMEM;
696 } 599 }
697 600
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
index 0b3da29245fb..ef532a6aceaa 100644
--- a/drivers/media/dvb/bt8xx/dst_common.h
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -47,6 +47,8 @@
47#define DST_TYPE_HAS_FW_2 16 47#define DST_TYPE_HAS_FW_2 16
48#define DST_TYPE_HAS_FW_3 32 48#define DST_TYPE_HAS_FW_3 32
49#define DST_TYPE_HAS_FW_BUILD 64 49#define DST_TYPE_HAS_FW_BUILD 64
50#define DST_TYPE_HAS_OBS_REGS 128
51#define DST_TYPE_HAS_INC_COUNT 256
50 52
51/* Card capability list */ 53/* Card capability list */
52 54
@@ -110,6 +112,7 @@ struct dst_state {
110 u32 dst_hw_cap; 112 u32 dst_hw_cap;
111 u8 dst_fw_version; 113 u8 dst_fw_version;
112 fe_sec_mini_cmd_t minicmd; 114 fe_sec_mini_cmd_t minicmd;
115 fe_modulation_t modulation;
113 u8 messages[256]; 116 u8 messages[256];
114}; 117};
115 118