4 * Copyright (c) 2004 Andreas Monitzer <andy@monitzer.com>
5 * Copyright (c) 2008 Ben Backx <ben@bbackx.com>
6 * Copyright (c) 2008 Henrik Kurelid <henrik@kurelid.se>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
15 #include <ieee1394_transactions.h>
17 #include <asm/byteorder.h>
18 #include <linux/delay.h>
19 #include <linux/crc32.h>
21 #include "firesat-rc.h"
23 #define RESPONSE_REGISTER 0xFFFFF0000D00ULL
24 #define COMMAND_REGISTER 0xFFFFF0000B00ULL
25 #define PCR_BASE_ADDRESS 0xFFFFF0000900ULL
27 static unsigned int avc_comm_debug = 0;
28 module_param(avc_comm_debug, int, 0644);
29 MODULE_PARM_DESC(avc_comm_debug, "debug logging of AV/C communication, default is 0 (no)");
31 static int __AVCRegisterRemoteControl(struct firesat*firesat, int internal);
33 /* Frees an allocated packet */
34 static void avc_free_packet(struct hpsb_packet *packet)
36 hpsb_free_tlabel(packet);
37 hpsb_free_packet(packet);
41 * Goofy routine that basically does a down_timeout function.
44 static int avc_down_timeout(atomic_t *done, int timeout)
48 for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) {
49 set_current_state(TASK_INTERRUPTIBLE);
50 if (schedule_timeout(HZ/10)) /* 100ms */
53 return ((i > 0) ? 0:1);
56 static const char* get_ctype_string(__u8 ctype)
65 return "SPECIFIC_INQUIRY";
69 return "GENERAL_INQUIRY";
74 static const char* get_resp_string(__u8 ctype)
79 return "NOT_IMPLEMENTED";
85 return "IN_TRANSITION";
87 return "IMPLEMENTED_STABLE";
96 static const char* get_subunit_address(__u8 subunit_id, __u8 subunit_type)
98 if (subunit_id == 7 && subunit_type == 0x1F)
100 if (subunit_id == 0 && subunit_type == 0x05)
102 return "Unsupported";
105 static const char* get_opcode_string(__u8 opcode)
112 return "OpenDescriptor";
114 return "ReadDescriptor";
116 return "OutputPlugSignalFormat";
118 return "SubunitInfo";
124 return "DirectSelectInformationType";
126 return "DirectSelectData";
134 static void log_command_frame(const AVCCmdFrm *CmdFrm)
137 printk(KERN_INFO "AV/C Command Frame:\n");
138 printk("CommandType=%s, Address=%s(0x%02X,0x%02X), opcode=%s(0x%02X), "
139 "length=%d\n", get_ctype_string(CmdFrm->ctype),
140 get_subunit_address(CmdFrm->suid, CmdFrm->sutyp),
141 CmdFrm->suid, CmdFrm->sutyp, get_opcode_string(CmdFrm->opcode),
142 CmdFrm->opcode, CmdFrm->length);
143 for(k = 0; k < CmdFrm->length - 3; k++) {
148 printk("operand[%d] = %02X", k, CmdFrm->operand[k]);
153 static void log_response_frame(const AVCRspFrm *RspFrm)
156 printk(KERN_INFO "AV/C Response Frame:\n");
157 printk("Response=%s, Address=%s(0x%02X,0x%02X), opcode=%s(0x%02X), "
158 "length=%d\n", get_resp_string(RspFrm->resp),
159 get_subunit_address(RspFrm->suid, RspFrm->sutyp),
160 RspFrm->suid, RspFrm->sutyp, get_opcode_string(RspFrm->opcode),
161 RspFrm->opcode, RspFrm->length);
162 for(k = 0; k < RspFrm->length - 3; k++) {
167 printk("operand[%d] = %02X", k, RspFrm->operand[k]);
172 static int __AVCWrite(struct firesat *firesat, const AVCCmdFrm *CmdFrm,
174 struct hpsb_packet *packet;
175 struct node_entry *ne;
177 ne = firesat->nodeentry;
179 printk("%s: lost node!\n",__func__);
183 /* need all input data */
184 if(!firesat || !ne || !CmdFrm) {
185 printk("%s: missing input data!\n",__func__);
189 if (avc_comm_debug == 1) {
190 log_command_frame(CmdFrm);
194 atomic_set(&firesat->avc_reply_received, 0);
196 packet=hpsb_make_writepacket(ne->host, ne->nodeid,
200 hpsb_set_packet_complete_task(packet,
201 (void (*)(void*))avc_free_packet,
203 hpsb_node_fill_packet(ne, packet);
205 if (hpsb_send_packet(packet) < 0) {
206 avc_free_packet(packet);
207 atomic_set(&firesat->avc_reply_received, 1);
208 printk("%s: send failed!\n",__func__);
213 // AV/C specs say that answers should be send within
214 // 150 ms so let's time out after 200 ms
215 if(avc_down_timeout(&firesat->avc_reply_received,
217 printk("%s: timeout waiting for avc response\n",
219 atomic_set(&firesat->avc_reply_received, 1);
222 memcpy(RspFrm, firesat->respfrm,
223 firesat->resp_length);
224 RspFrm->length = firesat->resp_length;
225 if (avc_comm_debug == 1) {
226 log_response_frame(RspFrm);
233 int AVCWrite(struct firesat*firesat, const AVCCmdFrm *CmdFrm, AVCRspFrm *RspFrm) {
235 if(down_interruptible(&firesat->avc_sem))
238 ret = __AVCWrite(firesat, CmdFrm, RspFrm);
240 up(&firesat->avc_sem);
244 static void do_schedule_remotecontrol(unsigned long ignored);
245 DECLARE_TASKLET(schedule_remotecontrol, do_schedule_remotecontrol, 0);
247 static void do_schedule_remotecontrol(unsigned long ignored) {
248 struct firesat *firesat;
251 spin_lock_irqsave(&firesat_list_lock, flags);
252 list_for_each_entry(firesat,&firesat_list,list) {
253 if(atomic_read(&firesat->reschedule_remotecontrol) == 1) {
254 if(down_trylock(&firesat->avc_sem))
255 tasklet_schedule(&schedule_remotecontrol);
257 if(__AVCRegisterRemoteControl(firesat, 1) == 0)
258 atomic_set(&firesat->reschedule_remotecontrol, 0);
260 tasklet_schedule(&schedule_remotecontrol);
262 up(&firesat->avc_sem);
266 spin_unlock_irqrestore(&firesat_list_lock, flags);
269 int AVCRecv(struct firesat *firesat, u8 *data, size_t length) {
270 // printk(KERN_INFO "%s\n",__func__);
272 // remote control handling
275 AVCRspFrm *RspFrm = (AVCRspFrm*)data;
277 if(/*RspFrm->length >= 8 && ###*/
278 ((RspFrm->operand[0] == SFE_VENDOR_DE_COMPANYID_0 &&
279 RspFrm->operand[1] == SFE_VENDOR_DE_COMPANYID_1 &&
280 RspFrm->operand[2] == SFE_VENDOR_DE_COMPANYID_2)) &&
281 RspFrm->operand[3] == SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL) {
282 if(RspFrm->resp == CHANGED) {
283 // printk(KERN_INFO "%s: code = %02x %02x\n",__func__,RspFrm->operand[4],RspFrm->operand[5]);
284 firesat_got_remotecontrolcode((((u16)RspFrm->operand[4]) << 8) | ((u16)RspFrm->operand[5]));
287 atomic_set(&firesat->reschedule_remotecontrol, 1);
288 tasklet_schedule(&schedule_remotecontrol);
289 } else if(RspFrm->resp != INTERIM)
290 printk(KERN_INFO "%s: remote control result = %d\n",__func__, RspFrm->resp);
294 if(atomic_read(&firesat->avc_reply_received) == 1) {
295 printk("%s: received out-of-order AVC response, ignored\n",__func__);
298 // AVCRspFrm *resp=(AVCRspFrm *)data;
301 // printk(KERN_INFO "resp=0x%x\n",resp->resp);
302 // printk(KERN_INFO "cts=0x%x\n",resp->cts);
303 // printk(KERN_INFO "suid=0x%x\n",resp->suid);
304 // printk(KERN_INFO "sutyp=0x%x\n",resp->sutyp);
305 // printk(KERN_INFO "opcode=0x%x\n",resp->opcode);
306 // printk(KERN_INFO "length=%d\n",resp->length);
309 // printk(KERN_INFO "operand[%d]=%02x\n",k,resp->operand[k]);
311 memcpy(firesat->respfrm,data,length);
312 firesat->resp_length=length;
314 atomic_set(&firesat->avc_reply_received, 1);
319 // tuning command for setting the relative LNB frequency (not supported by the AVC standard)
320 static void AVCTuner_tuneQPSK(struct firesat *firesat, struct dvb_frontend_parameters *params, AVCCmdFrm *CmdFrm) {
322 memset(CmdFrm, 0, sizeof(AVCCmdFrm));
325 CmdFrm->ctype = CONTROL;
327 CmdFrm->suid = firesat->subunit;
328 CmdFrm->opcode = VENDOR;
330 CmdFrm->operand[0]=SFE_VENDOR_DE_COMPANYID_0;
331 CmdFrm->operand[1]=SFE_VENDOR_DE_COMPANYID_1;
332 CmdFrm->operand[2]=SFE_VENDOR_DE_COMPANYID_2;
333 CmdFrm->operand[3]=SFE_VENDOR_OPCODE_TUNE_QPSK;
335 printk(KERN_INFO "%s: tuning to frequency %u\n",__func__,params->frequency);
337 CmdFrm->operand[4] = (params->frequency >> 24) & 0xFF;
338 CmdFrm->operand[5] = (params->frequency >> 16) & 0xFF;
339 CmdFrm->operand[6] = (params->frequency >> 8) & 0xFF;
340 CmdFrm->operand[7] = params->frequency & 0xFF;
342 printk(KERN_INFO "%s: symbol rate = %uBd\n",__func__,params->u.qpsk.symbol_rate);
344 CmdFrm->operand[8] = ((params->u.qpsk.symbol_rate/1000) >> 8) & 0xFF;
345 CmdFrm->operand[9] = (params->u.qpsk.symbol_rate/1000) & 0xFF;
347 switch(params->u.qpsk.fec_inner) {
349 CmdFrm->operand[10] = 0x1;
352 CmdFrm->operand[10] = 0x2;
355 CmdFrm->operand[10] = 0x3;
358 CmdFrm->operand[10] = 0x4;
361 CmdFrm->operand[10] = 0x5;
367 CmdFrm->operand[10] = 0x0;
370 if(firesat->voltage == 0xff)
371 CmdFrm->operand[11] = 0xff;
373 CmdFrm->operand[11] = (firesat->voltage==SEC_VOLTAGE_18)?0:1; // polarisation
374 if(firesat->tone == 0xff)
375 CmdFrm->operand[12] = 0xff;
377 CmdFrm->operand[12] = (firesat->tone==SEC_TONE_ON)?1:0; // band
379 if (firesat->type == FireSAT_DVB_S2) {
380 CmdFrm->operand[13] = 0x1;
381 CmdFrm->operand[14] = 0xFF;
382 CmdFrm->operand[15] = 0xFF;
388 int AVCTuner_DSD(struct firesat *firesat, struct dvb_frontend_parameters *params, __u8 *status) {
394 // printk(KERN_INFO "%s\n", __func__);
396 if (firesat->type == FireSAT_DVB_S || firesat->type == FireSAT_DVB_S2)
397 AVCTuner_tuneQPSK(firesat, params, &CmdFrm);
399 if(firesat->type == FireSAT_DVB_T) {
400 flags.Bits_T.GuardInterval = (params->u.ofdm.guard_interval != GUARD_INTERVAL_AUTO);
401 flags.Bits_T.CodeRateLPStream = (params->u.ofdm.code_rate_LP != FEC_AUTO);
402 flags.Bits_T.CodeRateHPStream = (params->u.ofdm.code_rate_HP != FEC_AUTO);
403 flags.Bits_T.HierarchyInfo = (params->u.ofdm.hierarchy_information != HIERARCHY_AUTO);
404 flags.Bits_T.Constellation = (params->u.ofdm.constellation != QAM_AUTO);
405 flags.Bits_T.Bandwidth = (params->u.ofdm.bandwidth != BANDWIDTH_AUTO);
406 flags.Bits_T.CenterFrequency = 1;
407 flags.Bits_T.reserved1 = 0;
408 flags.Bits_T.reserved2 = 0;
409 flags.Bits_T.OtherFrequencyFlag = 0;
410 flags.Bits_T.TransmissionMode = (params->u.ofdm.transmission_mode != TRANSMISSION_MODE_AUTO);
411 flags.Bits_T.NetworkId = 0;
413 flags.Bits.Modulation =
414 (params->u.qam.modulation != QAM_AUTO);
415 flags.Bits.FEC_inner =
416 (params->u.qam.fec_inner != FEC_AUTO);
417 flags.Bits.FEC_outer = 0;
418 flags.Bits.Symbol_Rate = 1;
419 flags.Bits.Frequency = 1;
420 flags.Bits.Orbital_Pos = 0;
421 flags.Bits.Polarisation = 0;
422 flags.Bits.reserved_fields = 0;
423 flags.Bits.reserved1 = 0;
424 flags.Bits.Network_ID = 0;
427 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
430 CmdFrm.ctype = CONTROL;
432 CmdFrm.suid = firesat->subunit;
435 CmdFrm.operand[0] = 0; // source plug
436 CmdFrm.operand[1] = 0xD2; // subfunction replace
437 CmdFrm.operand[2] = 0x20; // system id = DVB
438 CmdFrm.operand[3] = 0x00; // antenna number
439 // system_specific_multiplex selection_length
440 CmdFrm.operand[4] = (firesat->type == FireSAT_DVB_T)?0x0c:0x11;
441 CmdFrm.operand[5] = flags.Valid_Word.ByteHi; // valid_flags [0]
442 CmdFrm.operand[6] = flags.Valid_Word.ByteLo; // valid_flags [1]
444 if(firesat->type == FireSAT_DVB_T) {
445 CmdFrm.operand[7] = 0x0;
446 CmdFrm.operand[8] = (params->frequency/10) >> 24;
448 ((params->frequency/10) >> 16) & 0xFF;
450 ((params->frequency/10) >> 8) & 0xFF;
451 CmdFrm.operand[11] = (params->frequency/10) & 0xFF;
452 switch(params->u.ofdm.bandwidth) {
453 case BANDWIDTH_7_MHZ:
454 CmdFrm.operand[12] = 0x20;
456 case BANDWIDTH_8_MHZ:
457 case BANDWIDTH_6_MHZ: // not defined by AVC spec
460 CmdFrm.operand[12] = 0x00;
462 switch(params->u.ofdm.constellation) {
464 CmdFrm.operand[13] = 1 << 6;
467 CmdFrm.operand[13] = 2 << 6;
471 CmdFrm.operand[13] = 0x00;
473 switch(params->u.ofdm.hierarchy_information) {
475 CmdFrm.operand[13] |= 1 << 3;
478 CmdFrm.operand[13] |= 2 << 3;
481 CmdFrm.operand[13] |= 3 << 3;
488 switch(params->u.ofdm.code_rate_HP) {
490 CmdFrm.operand[13] |= 1;
493 CmdFrm.operand[13] |= 2;
496 CmdFrm.operand[13] |= 3;
499 CmdFrm.operand[13] |= 4;
505 switch(params->u.ofdm.code_rate_LP) {
507 CmdFrm.operand[14] = 1 << 5;
510 CmdFrm.operand[14] = 2 << 5;
513 CmdFrm.operand[14] = 3 << 5;
516 CmdFrm.operand[14] = 4 << 5;
520 CmdFrm.operand[14] = 0x00;
523 switch(params->u.ofdm.guard_interval) {
524 case GUARD_INTERVAL_1_16:
525 CmdFrm.operand[14] |= 1 << 3;
527 case GUARD_INTERVAL_1_8:
528 CmdFrm.operand[14] |= 2 << 3;
530 case GUARD_INTERVAL_1_4:
531 CmdFrm.operand[14] |= 3 << 3;
533 case GUARD_INTERVAL_1_32:
534 case GUARD_INTERVAL_AUTO:
538 switch(params->u.ofdm.transmission_mode) {
539 case TRANSMISSION_MODE_8K:
540 CmdFrm.operand[14] |= 1 << 1;
542 case TRANSMISSION_MODE_2K:
543 case TRANSMISSION_MODE_AUTO:
548 CmdFrm.operand[15] = 0x00; // network_ID[0]
549 CmdFrm.operand[16] = 0x00; // network_ID[1]
550 CmdFrm.operand[17] = 0x00; // Nr_of_dsd_sel_specs = 0 - > No PIDs are transmitted
554 CmdFrm.operand[7] = 0x00;
555 CmdFrm.operand[8] = 0x00;
556 CmdFrm.operand[9] = 0x00;
557 CmdFrm.operand[10] = 0x00;
560 (((params->frequency/4000) >> 16) & 0xFF) | (2 << 6);
562 ((params->frequency/4000) >> 8) & 0xFF;
563 CmdFrm.operand[13] = (params->frequency/4000) & 0xFF;
565 ((params->u.qpsk.symbol_rate/1000) >> 12) & 0xFF;
567 ((params->u.qpsk.symbol_rate/1000) >> 4) & 0xFF;
569 ((params->u.qpsk.symbol_rate/1000) << 4) & 0xF0;
570 CmdFrm.operand[17] = 0x00;
571 switch(params->u.qpsk.fec_inner) {
573 CmdFrm.operand[18] = 0x1;
576 CmdFrm.operand[18] = 0x2;
579 CmdFrm.operand[18] = 0x3;
582 CmdFrm.operand[18] = 0x4;
585 CmdFrm.operand[18] = 0x5;
588 CmdFrm.operand[18] = 0x6;
591 CmdFrm.operand[18] = 0x8;
595 CmdFrm.operand[18] = 0x0;
597 switch(params->u.qam.modulation) {
599 CmdFrm.operand[19] = 0x08; // modulation
602 CmdFrm.operand[19] = 0x10; // modulation
605 CmdFrm.operand[19] = 0x18; // modulation
608 CmdFrm.operand[19] = 0x20; // modulation
611 CmdFrm.operand[19] = 0x28; // modulation
615 CmdFrm.operand[19] = 0x00; // modulation
617 CmdFrm.operand[20] = 0x00;
618 CmdFrm.operand[21] = 0x00;
619 CmdFrm.operand[22] = 0x00; // Nr_of_dsd_sel_specs = 0 - > No PIDs are transmitted
623 } // AVCTuner_DSD_direct
625 if((k=AVCWrite(firesat,&CmdFrm,&RspFrm)))
631 *status=RspFrm.operand[2];
635 int AVCTuner_SetPIDs(struct firesat *firesat, unsigned char pidc, u16 pid[])
641 if(pidc > 16 && pidc != 0xFF)
644 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
647 CmdFrm.ctype = CONTROL;
649 CmdFrm.suid = firesat->subunit;
652 CmdFrm.operand[0] = 0; // source plug
653 CmdFrm.operand[1] = 0xD2; // subfunction replace
654 CmdFrm.operand[2] = 0x20; // system id = DVB
655 CmdFrm.operand[3] = 0x00; // antenna number
656 CmdFrm.operand[4] = 0x00; // system_specific_multiplex selection_length
657 CmdFrm.operand[5] = pidc; // Nr_of_dsd_sel_specs
661 for(k=0;k<pidc;k++) {
662 CmdFrm.operand[pos++] = 0x13; // flowfunction relay
663 CmdFrm.operand[pos++] = 0x80; // dsd_sel_spec_valid_flags -> PID
664 CmdFrm.operand[pos++] = (pid[k] >> 8) & 0x1F;
665 CmdFrm.operand[pos++] = pid[k] & 0xFF;
666 CmdFrm.operand[pos++] = 0x00; // tableID
667 CmdFrm.operand[pos++] = 0x00; // filter_length
671 CmdFrm.length = pos+3;
673 CmdFrm.length += 4 - ((pos+3)%4);
675 if((k=AVCWrite(firesat,&CmdFrm,&RspFrm)))
682 int AVCTuner_GetTS(struct firesat *firesat){
687 //printk(KERN_INFO "%s\n", __func__);
689 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
692 CmdFrm.ctype = CONTROL;
694 CmdFrm.suid = firesat->subunit;
695 CmdFrm.opcode = DSIT;
697 CmdFrm.operand[0] = 0; // source plug
698 CmdFrm.operand[1] = 0xD2; // subfunction replace
699 CmdFrm.operand[2] = 0xFF; //status
700 CmdFrm.operand[3] = 0x20; // system id = DVB
701 CmdFrm.operand[4] = 0x00; // antenna number
702 CmdFrm.operand[5] = 0x0; // system_specific_search_flags
703 CmdFrm.operand[6] = (firesat->type == FireSAT_DVB_T)?0x0c:0x11; // system_specific_multiplex selection_length
704 CmdFrm.operand[7] = 0x00; // valid_flags [0]
705 CmdFrm.operand[8] = 0x00; // valid_flags [1]
706 CmdFrm.operand[7 + (firesat->type == FireSAT_DVB_T)?0x0c:0x11] = 0x00; // nr_of_dsit_sel_specs (always 0)
708 CmdFrm.length = (firesat->type == FireSAT_DVB_T)?24:28;
710 if ((k=AVCWrite(firesat, &CmdFrm, &RspFrm)))
717 int AVCIdentifySubunit(struct firesat *firesat, unsigned char *systemId, int *transport) {
721 memset(&CmdFrm,0,sizeof(AVCCmdFrm));
724 CmdFrm.ctype = CONTROL;
725 CmdFrm.sutyp = 0x5; // tuner
726 CmdFrm.suid = firesat->subunit;
727 CmdFrm.opcode = READ_DESCRIPTOR;
729 CmdFrm.operand[0]=DESCRIPTOR_SUBUNIT_IDENTIFIER;
730 CmdFrm.operand[1]=0xff;
731 CmdFrm.operand[2]=0x00;
732 CmdFrm.operand[3]=0x00; // length highbyte
733 CmdFrm.operand[4]=0x08; // length lowbyte
734 CmdFrm.operand[5]=0x00; // offset highbyte
735 CmdFrm.operand[6]=0x0d; // offset lowbyte
739 if(AVCWrite(firesat,&CmdFrm,&RspFrm)<0)
742 if(RspFrm.resp != STABLE && RspFrm.resp != ACCEPTED) {
743 printk("%s: AVCWrite returned error code %d\n",__func__,RspFrm.resp);
746 if(((RspFrm.operand[3] << 8) + RspFrm.operand[4]) != 8) {
747 printk("%s: Invalid response length\n",__func__);
751 *systemId = RspFrm.operand[7];
755 int AVCTunerStatus(struct firesat *firesat, ANTENNA_INPUT_INFO *antenna_input_info) {
760 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
763 CmdFrm.ctype=CONTROL;
764 CmdFrm.sutyp=0x05; // tuner
765 CmdFrm.suid=firesat->subunit;
766 CmdFrm.opcode=READ_DESCRIPTOR;
768 CmdFrm.operand[0]=DESCRIPTOR_TUNER_STATUS;
769 CmdFrm.operand[1]=0xff; //read_result_status
770 CmdFrm.operand[2]=0x00; // reserver
771 CmdFrm.operand[3]=0;//sizeof(ANTENNA_INPUT_INFO) >> 8;
772 CmdFrm.operand[4]=0;//sizeof(ANTENNA_INPUT_INFO) & 0xFF;
773 CmdFrm.operand[5]=0x00;
774 CmdFrm.operand[6]=0x00;
776 if (AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
779 if(RspFrm.resp != STABLE && RspFrm.resp != ACCEPTED) {
780 printk("%s: AVCWrite returned code %d\n",__func__,RspFrm.resp);
784 length = RspFrm.operand[9];
785 if(RspFrm.operand[1] == 0x10 && length == sizeof(ANTENNA_INPUT_INFO))
787 memcpy(antenna_input_info, &RspFrm.operand[10],
788 sizeof(ANTENNA_INPUT_INFO));
791 printk("%s: invalid info returned from AVC\n",__func__);
795 int AVCLNBControl(struct firesat *firesat, char voltage, char burst,
796 char conttone, char nrdiseq,
797 struct dvb_diseqc_master_cmd *diseqcmd)
803 printk(KERN_INFO "%s: voltage = %x, burst = %x, conttone = %x\n",__func__,voltage,burst,conttone);
805 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
808 CmdFrm.ctype=CONTROL;
810 CmdFrm.suid=firesat->subunit;
811 CmdFrm.opcode=VENDOR;
813 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
814 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
815 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
816 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_LNB_CONTROL;
818 CmdFrm.operand[4]=voltage;
819 CmdFrm.operand[5]=nrdiseq;
823 for(j=0;j<nrdiseq;j++) {
825 printk(KERN_INFO "%s: diseq %d len %x\n",__func__,j,diseqcmd[j].msg_len);
826 CmdFrm.operand[i++]=diseqcmd[j].msg_len;
828 for(k=0;k<diseqcmd[j].msg_len;k++) {
829 printk(KERN_INFO "%s: diseq %d msg[%d] = %x\n",__func__,j,k,diseqcmd[j].msg[k]);
830 CmdFrm.operand[i++]=diseqcmd[j].msg[k];
834 CmdFrm.operand[i++]=burst;
835 CmdFrm.operand[i++]=conttone;
839 CmdFrm.length += 4 - ((i+3)%4);
841 /* for(j=0;j<CmdFrm.length;j++)
842 printk(KERN_INFO "%s: CmdFrm.operand[%d]=0x%x\n",__func__,j,CmdFrm.operand[j]);
844 printk(KERN_INFO "%s: cmdfrm.length = %u\n",__func__,CmdFrm.length);
846 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
849 if(RspFrm.resp != ACCEPTED) {
850 printk("%s: AVCWrite returned code %d\n",__func__,RspFrm.resp);
857 int AVCSubUnitInfo(struct firesat *firesat, char *subunitcount)
862 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
865 CmdFrm.ctype = STATUS;
868 CmdFrm.opcode = SUBUNIT_Info;
870 CmdFrm.operand[0] = 0x07;
871 CmdFrm.operand[1] = 0xff;
872 CmdFrm.operand[2] = 0xff;
873 CmdFrm.operand[3] = 0xff;
874 CmdFrm.operand[4] = 0xff;
878 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
881 if(RspFrm.resp != STABLE) {
882 printk("%s: AVCWrite returned code %d\n",__func__,RspFrm.resp);
887 *subunitcount = (RspFrm.operand[1] & 0x7) + 1;
892 static int __AVCRegisterRemoteControl(struct firesat*firesat, int internal)
896 // printk(KERN_INFO "%s\n",__func__);
898 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
901 CmdFrm.ctype = NOTIFY;
904 CmdFrm.opcode = VENDOR;
906 CmdFrm.operand[0] = SFE_VENDOR_DE_COMPANYID_0;
907 CmdFrm.operand[1] = SFE_VENDOR_DE_COMPANYID_1;
908 CmdFrm.operand[2] = SFE_VENDOR_DE_COMPANYID_2;
909 CmdFrm.operand[3] = SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL;
914 if(__AVCWrite(firesat,&CmdFrm,NULL) < 0)
917 if(AVCWrite(firesat,&CmdFrm,NULL) < 0)
923 int AVCRegisterRemoteControl(struct firesat*firesat)
925 return __AVCRegisterRemoteControl(firesat, 0);
928 int AVCTuner_Host2Ca(struct firesat *firesat)
934 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
936 CmdFrm.ctype = CONTROL;
938 CmdFrm.suid = firesat->subunit;
939 CmdFrm.opcode = VENDOR;
941 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
942 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
943 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
944 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_HOST2CA;
945 CmdFrm.operand[4] = 0; // slot
946 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; // ca tag
947 CmdFrm.operand[6] = 0; // more/last
948 CmdFrm.operand[7] = 0; // length
951 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
957 static int get_ca_object_pos(AVCRspFrm *RspFrm)
961 // Check length of length field
962 if (RspFrm->operand[7] & 0x80)
963 length = (RspFrm->operand[7] & 0x7F) + 1;
967 static int get_ca_object_length(AVCRspFrm *RspFrm)
972 if (RspFrm->operand[7] & 0x80) {
973 for (i = 0; i < (RspFrm->operand[7] & 0x7F); i++) {
975 size += RspFrm->operand[8 + i];
978 return RspFrm->operand[7];
981 int avc_ca_app_info(struct firesat *firesat, char *app_info, int *length)
987 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
989 CmdFrm.ctype = STATUS;
991 CmdFrm.suid = firesat->subunit;
992 CmdFrm.opcode = VENDOR;
994 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
995 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
996 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
997 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_CA2HOST;
998 CmdFrm.operand[4] = 0; // slot
999 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; // ca tag
1002 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
1006 pos = get_ca_object_pos(&RspFrm);
1007 app_info[0] = (TAG_APP_INFO >> 16) & 0xFF;
1008 app_info[1] = (TAG_APP_INFO >> 8) & 0xFF;
1009 app_info[2] = (TAG_APP_INFO >> 0) & 0xFF;
1010 app_info[3] = 6 + RspFrm.operand[pos + 4];
1012 memcpy(&app_info[5], &RspFrm.operand[pos], 5 + RspFrm.operand[pos + 4]);
1013 *length = app_info[3] + 4;
1018 int avc_ca_info(struct firesat *firesat, char *app_info, int *length)
1024 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
1026 CmdFrm.ctype = STATUS;
1028 CmdFrm.suid = firesat->subunit;
1029 CmdFrm.opcode = VENDOR;
1031 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
1032 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
1033 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
1034 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_CA2HOST;
1035 CmdFrm.operand[4] = 0; // slot
1036 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; // ca tag
1039 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
1042 pos = get_ca_object_pos(&RspFrm);
1043 app_info[0] = (TAG_CA_INFO >> 16) & 0xFF;
1044 app_info[1] = (TAG_CA_INFO >> 8) & 0xFF;
1045 app_info[2] = (TAG_CA_INFO >> 0) & 0xFF;
1047 app_info[4] = app_info[5];
1048 app_info[5] = app_info[6];
1049 *length = app_info[3] + 4;
1054 int avc_ca_reset(struct firesat *firesat)
1059 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
1061 CmdFrm.ctype = CONTROL;
1063 CmdFrm.suid = firesat->subunit;
1064 CmdFrm.opcode = VENDOR;
1066 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
1067 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
1068 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
1069 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_HOST2CA;
1070 CmdFrm.operand[4] = 0; // slot
1071 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_RESET; // ca tag
1072 CmdFrm.operand[6] = 0; // more/last
1073 CmdFrm.operand[7] = 1; // length
1074 CmdFrm.operand[8] = 0; // force hardware reset
1077 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
1083 int avc_ca_pmt(struct firesat *firesat, char *msg, int length)
1087 int list_management;
1088 int program_info_length;
1095 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
1097 CmdFrm.ctype = CONTROL;
1099 CmdFrm.suid = firesat->subunit;
1100 CmdFrm.opcode = VENDOR;
1102 if (msg[0] != LIST_MANAGEMENT_ONLY) {
1103 printk(KERN_ERR "The only list_manasgement parameter that is "
1104 "supported by the firesat driver is \"only\" (3).");
1107 // We take the cmd_id from the programme level only!
1108 list_management = msg[0];
1109 program_info_length = ((msg[4] & 0x0F) << 8) + msg[5];
1110 if (program_info_length > 0)
1111 program_info_length--; // Remove pmt_cmd_id
1112 pmt_cmd_id = msg[6];
1114 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
1115 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
1116 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
1117 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_HOST2CA;
1118 CmdFrm.operand[4] = 0; // slot
1119 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_PMT; // ca tag
1120 CmdFrm.operand[6] = 0; // more/last
1121 //CmdFrm.operand[7] = XXXprogram_info_length + 17; // length
1122 CmdFrm.operand[8] = list_management;
1123 CmdFrm.operand[9] = 0x01; // pmt_cmd=OK_descramble
1125 // TS program map table
1128 CmdFrm.operand[10] = 0x02;
1129 // Section syntax + length
1130 CmdFrm.operand[11] = 0x80;
1131 //CmdFrm.operand[12] = XXXprogram_info_length + 12;
1133 CmdFrm.operand[13] = msg[1];
1134 CmdFrm.operand[14] = msg[2];
1135 // Version number=0 + current/next=1
1136 CmdFrm.operand[15] = 0x01;
1138 CmdFrm.operand[16] = 0x00;
1139 // Last section number=0
1140 CmdFrm.operand[17] = 0x00;
1142 CmdFrm.operand[18] = 0x1F;
1143 CmdFrm.operand[19] = 0xFF;
1144 // Program info length
1145 CmdFrm.operand[20] = (program_info_length >> 8);
1146 CmdFrm.operand[21] = (program_info_length & 0xFF);
1147 // CA descriptors at programme level
1150 if (program_info_length > 0) {
1151 /* printk(KERN_INFO "Copying descriptors at programme level.\n"); */
1152 pmt_cmd_id = msg[read_pos++];
1153 if (pmt_cmd_id != 1 && pmt_cmd_id !=4) {
1154 printk(KERN_ERR "Invalid pmt_cmd_id=%d.\n",
1157 memcpy(&CmdFrm.operand[write_pos], &msg[read_pos],
1158 program_info_length);
1159 read_pos += program_info_length;
1160 write_pos += program_info_length;
1162 while (read_pos < length) {
1163 /* printk(KERN_INFO "Copying descriptors at stream level for " */
1164 /* "stream type %d.\n", msg[read_pos]); */
1165 CmdFrm.operand[write_pos++] = msg[read_pos++];
1166 CmdFrm.operand[write_pos++] = msg[read_pos++];
1167 CmdFrm.operand[write_pos++] = msg[read_pos++];
1169 ((msg[read_pos] & 0x0F) << 8) + msg[read_pos + 1];
1171 if (es_info_length > 0)
1172 es_info_length--; // Remove pmt_cmd_id
1173 CmdFrm.operand[write_pos++] = es_info_length >> 8;
1174 CmdFrm.operand[write_pos++] = es_info_length & 0xFF;
1175 if (es_info_length > 0) {
1176 pmt_cmd_id = msg[read_pos++];
1177 if (pmt_cmd_id != 1 && pmt_cmd_id !=4) {
1178 printk(KERN_ERR "Invalid pmt_cmd_id=%d at "
1179 "stream level.\n", pmt_cmd_id);
1181 memcpy(&CmdFrm.operand[write_pos], &msg[read_pos],
1183 read_pos += es_info_length;
1184 write_pos += es_info_length;
1189 CmdFrm.operand[write_pos++] = 0x00;
1190 CmdFrm.operand[write_pos++] = 0x00;
1191 CmdFrm.operand[write_pos++] = 0x00;
1192 CmdFrm.operand[write_pos++] = 0x00;
1194 CmdFrm.operand[7] = write_pos - 8;
1195 CmdFrm.operand[12] = write_pos - 13;
1197 crc32_csum = crc32_be(0, &CmdFrm.operand[10],
1198 CmdFrm.operand[12] - 1);
1199 CmdFrm.operand[write_pos - 4] = (crc32_csum >> 24) & 0xFF;
1200 CmdFrm.operand[write_pos - 3] = (crc32_csum >> 16) & 0xFF;
1201 CmdFrm.operand[write_pos - 2] = (crc32_csum >> 8) & 0xFF;
1202 CmdFrm.operand[write_pos - 1] = (crc32_csum >> 0) & 0xFF;
1204 CmdFrm.length = write_pos + 3;
1205 if ((write_pos + 3) % 4)
1206 CmdFrm.length += 4 - ((write_pos + 3) % 4);
1208 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
1211 if (RspFrm.resp != ACCEPTED) {
1212 printk(KERN_ERR "Answer to CA PMT was %d\n", RspFrm.resp);
1220 int avc_ca_get_time_date(struct firesat *firesat, int *interval)
1225 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
1227 CmdFrm.ctype = STATUS;
1229 CmdFrm.suid = firesat->subunit;
1230 CmdFrm.opcode = VENDOR;
1232 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
1233 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
1234 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
1235 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_CA2HOST;
1236 CmdFrm.operand[4] = 0; // slot
1237 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_DATE_TIME; // ca tag
1238 CmdFrm.operand[6] = 0; // more/last
1239 CmdFrm.operand[7] = 0; // length
1242 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
1245 *interval = RspFrm.operand[get_ca_object_pos(&RspFrm)];
1250 int avc_ca_enter_menu(struct firesat *firesat)
1255 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
1257 CmdFrm.ctype = STATUS;
1259 CmdFrm.suid = firesat->subunit;
1260 CmdFrm.opcode = VENDOR;
1262 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
1263 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
1264 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
1265 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_HOST2CA;
1266 CmdFrm.operand[4] = 0; // slot
1267 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_ENTER_MENU;
1268 CmdFrm.operand[6] = 0; // more/last
1269 CmdFrm.operand[7] = 0; // length
1272 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
1278 int avc_ca_get_mmi(struct firesat *firesat, char *mmi_object, int *length)
1283 memset(&CmdFrm, 0, sizeof(AVCCmdFrm));
1285 CmdFrm.ctype = STATUS;
1287 CmdFrm.suid = firesat->subunit;
1288 CmdFrm.opcode = VENDOR;
1290 CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0;
1291 CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1;
1292 CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2;
1293 CmdFrm.operand[3]=SFE_VENDOR_OPCODE_CA2HOST;
1294 CmdFrm.operand[4] = 0; // slot
1295 CmdFrm.operand[5] = SFE_VENDOR_TAG_CA_MMI;
1296 CmdFrm.operand[6] = 0; // more/last
1297 CmdFrm.operand[7] = 0; // length
1300 if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0)
1303 *length = get_ca_object_length(&RspFrm);
1304 memcpy(mmi_object, &RspFrm.operand[get_ca_object_pos(&RspFrm)], *length);