2 * FireDTV driver (formerly known as FireSAT)
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.
14 #include <linux/bug.h>
15 #include <linux/crc32.h>
16 #include <linux/delay.h>
17 #include <linux/device.h>
18 #include <linux/jiffies.h>
19 #include <linux/kernel.h>
20 #include <linux/moduleparam.h>
21 #include <linux/mutex.h>
22 #include <linux/string.h>
23 #include <linux/stringify.h>
24 #include <linux/wait.h>
25 #include <linux/workqueue.h>
29 #define FCP_COMMAND_REGISTER 0xfffff0000b00ULL
31 #define AVC_CTYPE_CONTROL 0x0
32 #define AVC_CTYPE_STATUS 0x1
33 #define AVC_CTYPE_NOTIFY 0x3
35 #define AVC_RESPONSE_ACCEPTED 0x9
36 #define AVC_RESPONSE_STABLE 0xc
37 #define AVC_RESPONSE_CHANGED 0xd
38 #define AVC_RESPONSE_INTERIM 0xf
40 #define AVC_SUBUNIT_TYPE_TUNER (0x05 << 3)
41 #define AVC_SUBUNIT_TYPE_UNIT (0x1f << 3)
43 #define AVC_OPCODE_VENDOR 0x00
44 #define AVC_OPCODE_READ_DESCRIPTOR 0x09
45 #define AVC_OPCODE_DSIT 0xc8
46 #define AVC_OPCODE_DSD 0xcb
48 #define DESCRIPTOR_TUNER_STATUS 0x80
49 #define DESCRIPTOR_SUBUNIT_IDENTIFIER 0x00
51 #define SFE_VENDOR_DE_COMPANYID_0 0x00 /* OUI of Digital Everywhere */
52 #define SFE_VENDOR_DE_COMPANYID_1 0x12
53 #define SFE_VENDOR_DE_COMPANYID_2 0x87
55 #define SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL 0x0a
56 #define SFE_VENDOR_OPCODE_LNB_CONTROL 0x52
57 #define SFE_VENDOR_OPCODE_TUNE_QPSK 0x58 /* for DVB-S */
59 #define SFE_VENDOR_OPCODE_GET_FIRMWARE_VERSION 0x00
60 #define SFE_VENDOR_OPCODE_HOST2CA 0x56
61 #define SFE_VENDOR_OPCODE_CA2HOST 0x57
62 #define SFE_VENDOR_OPCODE_CISTATUS 0x59
63 #define SFE_VENDOR_OPCODE_TUNE_QPSK2 0x60 /* for DVB-S2 */
65 #define SFE_VENDOR_TAG_CA_RESET 0x00
66 #define SFE_VENDOR_TAG_CA_APPLICATION_INFO 0x01
67 #define SFE_VENDOR_TAG_CA_PMT 0x02
68 #define SFE_VENDOR_TAG_CA_DATE_TIME 0x04
69 #define SFE_VENDOR_TAG_CA_MMI 0x05
70 #define SFE_VENDOR_TAG_CA_ENTER_MENU 0x07
72 #define EN50221_LIST_MANAGEMENT_ONLY 0x03
73 #define EN50221_TAG_APP_INFO 0x9f8021
74 #define EN50221_TAG_CA_INFO 0x9f8031
76 struct avc_command_frame
{
84 struct avc_response_frame
{
92 #define AVC_DEBUG_READ_DESCRIPTOR 0x0001
93 #define AVC_DEBUG_DSIT 0x0002
94 #define AVC_DEBUG_DSD 0x0004
95 #define AVC_DEBUG_REGISTER_REMOTE_CONTROL 0x0008
96 #define AVC_DEBUG_LNB_CONTROL 0x0010
97 #define AVC_DEBUG_TUNE_QPSK 0x0020
98 #define AVC_DEBUG_TUNE_QPSK2 0x0040
99 #define AVC_DEBUG_HOST2CA 0x0080
100 #define AVC_DEBUG_CA2HOST 0x0100
101 #define AVC_DEBUG_APPLICATION_PMT 0x4000
102 #define AVC_DEBUG_FCP_PAYLOADS 0x8000
104 static int avc_debug
;
105 module_param_named(debug
, avc_debug
, int, 0644);
106 MODULE_PARM_DESC(debug
, "Verbose logging (none = 0"
108 ": READ DESCRIPTOR = " __stringify(AVC_DEBUG_READ_DESCRIPTOR
)
109 ", DSIT = " __stringify(AVC_DEBUG_DSIT
)
110 ", REGISTER_REMOTE_CONTROL = " __stringify(AVC_DEBUG_REGISTER_REMOTE_CONTROL
)
111 ", LNB CONTROL = " __stringify(AVC_DEBUG_LNB_CONTROL
)
112 ", TUNE QPSK = " __stringify(AVC_DEBUG_TUNE_QPSK
)
113 ", TUNE QPSK2 = " __stringify(AVC_DEBUG_TUNE_QPSK2
)
114 ", HOST2CA = " __stringify(AVC_DEBUG_HOST2CA
)
115 ", CA2HOST = " __stringify(AVC_DEBUG_CA2HOST
)
116 "; Application sent PMT = " __stringify(AVC_DEBUG_APPLICATION_PMT
)
117 ", FCP payloads = " __stringify(AVC_DEBUG_FCP_PAYLOADS
)
118 ", or a combination, or all = -1)");
120 static const char *debug_fcp_ctype(unsigned int ctype
)
122 static const char *ctypes
[] = {
123 [0x0] = "CONTROL", [0x1] = "STATUS",
124 [0x2] = "SPECIFIC INQUIRY", [0x3] = "NOTIFY",
125 [0x4] = "GENERAL INQUIRY", [0x8] = "NOT IMPLEMENTED",
126 [0x9] = "ACCEPTED", [0xa] = "REJECTED",
127 [0xb] = "IN TRANSITION", [0xc] = "IMPLEMENTED/STABLE",
128 [0xd] = "CHANGED", [0xf] = "INTERIM",
130 const char *ret
= ctype
< ARRAY_SIZE(ctypes
) ? ctypes
[ctype
] : NULL
;
132 return ret
? ret
: "?";
135 static const char *debug_fcp_opcode(unsigned int opcode
,
136 const u8
*data
, int length
)
139 case AVC_OPCODE_VENDOR
:
141 case AVC_OPCODE_READ_DESCRIPTOR
:
142 return avc_debug
& AVC_DEBUG_READ_DESCRIPTOR
?
143 "ReadDescriptor" : NULL
;
144 case AVC_OPCODE_DSIT
:
145 return avc_debug
& AVC_DEBUG_DSIT
?
146 "DirectSelectInfo.Type" : NULL
;
148 return avc_debug
& AVC_DEBUG_DSD
? "DirectSelectData" : NULL
;
154 data
[3] != SFE_VENDOR_DE_COMPANYID_0
||
155 data
[4] != SFE_VENDOR_DE_COMPANYID_1
||
156 data
[5] != SFE_VENDOR_DE_COMPANYID_2
)
157 return "Vendor/Unknown";
160 case SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL
:
161 return avc_debug
& AVC_DEBUG_REGISTER_REMOTE_CONTROL
?
163 case SFE_VENDOR_OPCODE_LNB_CONTROL
:
164 return avc_debug
& AVC_DEBUG_LNB_CONTROL
? "LNBControl" : NULL
;
165 case SFE_VENDOR_OPCODE_TUNE_QPSK
:
166 return avc_debug
& AVC_DEBUG_TUNE_QPSK
? "TuneQPSK" : NULL
;
167 case SFE_VENDOR_OPCODE_TUNE_QPSK2
:
168 return avc_debug
& AVC_DEBUG_TUNE_QPSK2
? "TuneQPSK2" : NULL
;
169 case SFE_VENDOR_OPCODE_HOST2CA
:
170 return avc_debug
& AVC_DEBUG_HOST2CA
? "Host2CA" : NULL
;
171 case SFE_VENDOR_OPCODE_CA2HOST
:
172 return avc_debug
& AVC_DEBUG_CA2HOST
? "CA2Host" : NULL
;
174 return "Vendor/Unknown";
177 static void debug_fcp(const u8
*data
, int length
)
179 unsigned int subunit_type
, subunit_id
, opcode
;
180 const char *op
, *prefix
;
182 prefix
= data
[0] > 7 ? "FCP <- " : "FCP -> ";
183 subunit_type
= data
[1] >> 3;
184 subunit_id
= data
[1] & 7;
185 opcode
= subunit_type
== 0x1e || subunit_id
== 5 ? ~0 : data
[2];
186 op
= debug_fcp_opcode(opcode
, data
, length
);
189 printk(KERN_INFO
"%ssu=%x.%x l=%d: %-8s - %s\n",
190 prefix
, subunit_type
, subunit_id
, length
,
191 debug_fcp_ctype(data
[0]), op
);
192 if (avc_debug
& AVC_DEBUG_FCP_PAYLOADS
)
193 print_hex_dump(KERN_INFO
, prefix
, DUMP_PREFIX_NONE
,
194 16, 1, data
, length
, false);
198 static void debug_pmt(char *msg
, int length
)
200 printk(KERN_INFO
"APP PMT -> l=%d\n", length
);
201 print_hex_dump(KERN_INFO
, "APP PMT -> ", DUMP_PREFIX_NONE
,
202 16, 1, msg
, length
, false);
205 static int __avc_write(struct firedtv
*fdtv
,
206 const struct avc_command_frame
*c
, struct avc_response_frame
*r
)
211 fdtv
->avc_reply_received
= false;
213 for (retry
= 0; retry
< 6; retry
++) {
214 if (unlikely(avc_debug
))
215 debug_fcp(&c
->ctype
, c
->length
);
217 err
= fdtv
->backend
->write(fdtv
, FCP_COMMAND_REGISTER
,
218 (void *)&c
->ctype
, c
->length
);
220 fdtv
->avc_reply_received
= true;
221 dev_err(fdtv
->device
, "FCP command write failed\n");
229 * AV/C specs say that answers should be sent within 150 ms.
230 * Time out after 200 ms.
232 if (wait_event_timeout(fdtv
->avc_wait
,
233 fdtv
->avc_reply_received
,
234 msecs_to_jiffies(200)) != 0) {
235 r
->length
= fdtv
->response_length
;
236 memcpy(&r
->response
, fdtv
->response
, r
->length
);
241 dev_err(fdtv
->device
, "FCP response timed out\n");
245 static int avc_write(struct firedtv
*fdtv
,
246 const struct avc_command_frame
*c
, struct avc_response_frame
*r
)
250 if (mutex_lock_interruptible(&fdtv
->avc_mutex
))
253 ret
= __avc_write(fdtv
, c
, r
);
255 mutex_unlock(&fdtv
->avc_mutex
);
259 int avc_recv(struct firedtv
*fdtv
, void *data
, size_t length
)
261 struct avc_response_frame
*r
=
262 data
- offsetof(struct avc_response_frame
, response
);
264 if (unlikely(avc_debug
))
265 debug_fcp(data
, length
);
268 r
->operand
[0] == SFE_VENDOR_DE_COMPANYID_0
&&
269 r
->operand
[1] == SFE_VENDOR_DE_COMPANYID_1
&&
270 r
->operand
[2] == SFE_VENDOR_DE_COMPANYID_2
&&
271 r
->operand
[3] == SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL
) {
272 if (r
->response
== AVC_RESPONSE_CHANGED
) {
274 r
->operand
[4] << 8 | r
->operand
[5]);
275 schedule_work(&fdtv
->remote_ctrl_work
);
276 } else if (r
->response
!= AVC_RESPONSE_INTERIM
) {
277 dev_info(fdtv
->device
,
278 "remote control result = %d\n", r
->response
);
283 if (fdtv
->avc_reply_received
) {
284 dev_err(fdtv
->device
, "out-of-order AVC response, ignored\n");
288 memcpy(fdtv
->response
, data
, length
);
289 fdtv
->response_length
= length
;
291 fdtv
->avc_reply_received
= true;
292 wake_up(&fdtv
->avc_wait
);
297 static int add_pid_filter(struct firedtv
*fdtv
, u8
*operand
)
301 for (i
= 0, n
= 0; i
< 16; i
++) {
302 if (test_bit(i
, &fdtv
->channel_active
)) {
303 operand
[pos
++] = 0x13; /* flowfunction relay */
304 operand
[pos
++] = 0x80; /* dsd_sel_spec_valid_flags -> PID */
305 operand
[pos
++] = (fdtv
->channel_pid
[i
] >> 8) & 0x1f;
306 operand
[pos
++] = fdtv
->channel_pid
[i
] & 0xff;
307 operand
[pos
++] = 0x00; /* tableID */
308 operand
[pos
++] = 0x00; /* filter_length */
318 * tuning command for setting the relative LNB frequency
319 * (not supported by the AVC standard)
321 static void avc_tuner_tuneqpsk(struct firedtv
*fdtv
,
322 struct dvb_frontend_parameters
*params
,
323 struct avc_command_frame
*c
)
325 c
->opcode
= AVC_OPCODE_VENDOR
;
327 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
328 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
329 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
330 if (fdtv
->type
== FIREDTV_DVB_S2
)
331 c
->operand
[3] = SFE_VENDOR_OPCODE_TUNE_QPSK2
;
333 c
->operand
[3] = SFE_VENDOR_OPCODE_TUNE_QPSK
;
335 c
->operand
[4] = (params
->frequency
>> 24) & 0xff;
336 c
->operand
[5] = (params
->frequency
>> 16) & 0xff;
337 c
->operand
[6] = (params
->frequency
>> 8) & 0xff;
338 c
->operand
[7] = params
->frequency
& 0xff;
340 c
->operand
[8] = ((params
->u
.qpsk
.symbol_rate
/ 1000) >> 8) & 0xff;
341 c
->operand
[9] = (params
->u
.qpsk
.symbol_rate
/ 1000) & 0xff;
343 switch (params
->u
.qpsk
.fec_inner
) {
344 case FEC_1_2
: c
->operand
[10] = 0x1; break;
345 case FEC_2_3
: c
->operand
[10] = 0x2; break;
346 case FEC_3_4
: c
->operand
[10] = 0x3; break;
347 case FEC_5_6
: c
->operand
[10] = 0x4; break;
348 case FEC_7_8
: c
->operand
[10] = 0x5; break;
352 default: c
->operand
[10] = 0x0;
355 if (fdtv
->voltage
== 0xff)
356 c
->operand
[11] = 0xff;
357 else if (fdtv
->voltage
== SEC_VOLTAGE_18
) /* polarisation */
362 if (fdtv
->tone
== 0xff)
363 c
->operand
[12] = 0xff;
364 else if (fdtv
->tone
== SEC_TONE_ON
) /* band */
369 if (fdtv
->type
== FIREDTV_DVB_S2
) {
370 c
->operand
[13] = 0x1;
371 c
->operand
[14] = 0xff;
372 c
->operand
[15] = 0xff;
379 static void avc_tuner_dsd_dvb_c(struct firedtv
*fdtv
,
380 struct dvb_frontend_parameters
*params
,
381 struct avc_command_frame
*c
)
383 c
->opcode
= AVC_OPCODE_DSD
;
385 c
->operand
[0] = 0; /* source plug */
386 c
->operand
[1] = 0xd2; /* subfunction replace */
387 c
->operand
[2] = 0x20; /* system id = DVB */
388 c
->operand
[3] = 0x00; /* antenna number */
389 c
->operand
[4] = 0x11; /* system_specific_multiplex selection_length */
391 /* multiplex_valid_flags, high byte */
392 c
->operand
[5] = 0 << 7 /* reserved */
393 | 0 << 6 /* Polarisation */
394 | 0 << 5 /* Orbital_Pos */
395 | 1 << 4 /* Frequency */
396 | 1 << 3 /* Symbol_Rate */
397 | 0 << 2 /* FEC_outer */
398 | (params
->u
.qam
.fec_inner
!= FEC_AUTO
? 1 << 1 : 0)
399 | (params
->u
.qam
.modulation
!= QAM_AUTO
? 1 << 0 : 0);
401 /* multiplex_valid_flags, low byte */
402 c
->operand
[6] = 0 << 7 /* NetworkID */
403 | 0 << 0 /* reserved */ ;
405 c
->operand
[7] = 0x00;
406 c
->operand
[8] = 0x00;
407 c
->operand
[9] = 0x00;
408 c
->operand
[10] = 0x00;
410 c
->operand
[11] = (((params
->frequency
/ 4000) >> 16) & 0xff) | (2 << 6);
411 c
->operand
[12] = ((params
->frequency
/ 4000) >> 8) & 0xff;
412 c
->operand
[13] = (params
->frequency
/ 4000) & 0xff;
413 c
->operand
[14] = ((params
->u
.qpsk
.symbol_rate
/ 1000) >> 12) & 0xff;
414 c
->operand
[15] = ((params
->u
.qpsk
.symbol_rate
/ 1000) >> 4) & 0xff;
415 c
->operand
[16] = ((params
->u
.qpsk
.symbol_rate
/ 1000) << 4) & 0xf0;
416 c
->operand
[17] = 0x00;
418 switch (params
->u
.qpsk
.fec_inner
) {
419 case FEC_1_2
: c
->operand
[18] = 0x1; break;
420 case FEC_2_3
: c
->operand
[18] = 0x2; break;
421 case FEC_3_4
: c
->operand
[18] = 0x3; break;
422 case FEC_5_6
: c
->operand
[18] = 0x4; break;
423 case FEC_7_8
: c
->operand
[18] = 0x5; break;
424 case FEC_8_9
: c
->operand
[18] = 0x6; break;
425 case FEC_4_5
: c
->operand
[18] = 0x8; break;
427 default: c
->operand
[18] = 0x0;
430 switch (params
->u
.qam
.modulation
) {
431 case QAM_16
: c
->operand
[19] = 0x08; break;
432 case QAM_32
: c
->operand
[19] = 0x10; break;
433 case QAM_64
: c
->operand
[19] = 0x18; break;
434 case QAM_128
: c
->operand
[19] = 0x20; break;
435 case QAM_256
: c
->operand
[19] = 0x28; break;
437 default: c
->operand
[19] = 0x00;
440 c
->operand
[20] = 0x00;
441 c
->operand
[21] = 0x00;
443 /* Add PIDs to filter */
444 c
->length
= ALIGN(22 + add_pid_filter(fdtv
, &c
->operand
[22]) + 3, 4);
447 static void avc_tuner_dsd_dvb_t(struct firedtv
*fdtv
,
448 struct dvb_frontend_parameters
*params
,
449 struct avc_command_frame
*c
)
451 struct dvb_ofdm_parameters
*ofdm
= ¶ms
->u
.ofdm
;
453 c
->opcode
= AVC_OPCODE_DSD
;
455 c
->operand
[0] = 0; /* source plug */
456 c
->operand
[1] = 0xd2; /* subfunction replace */
457 c
->operand
[2] = 0x20; /* system id = DVB */
458 c
->operand
[3] = 0x00; /* antenna number */
459 c
->operand
[4] = 0x0c; /* system_specific_multiplex selection_length */
461 /* multiplex_valid_flags, high byte */
463 0 << 7 /* reserved */
464 | 1 << 6 /* CenterFrequency */
465 | (ofdm
->bandwidth
!= BANDWIDTH_AUTO
? 1 << 5 : 0)
466 | (ofdm
->constellation
!= QAM_AUTO
? 1 << 4 : 0)
467 | (ofdm
->hierarchy_information
!= HIERARCHY_AUTO
? 1 << 3 : 0)
468 | (ofdm
->code_rate_HP
!= FEC_AUTO
? 1 << 2 : 0)
469 | (ofdm
->code_rate_LP
!= FEC_AUTO
? 1 << 1 : 0)
470 | (ofdm
->guard_interval
!= GUARD_INTERVAL_AUTO
? 1 << 0 : 0);
472 /* multiplex_valid_flags, low byte */
474 0 << 7 /* NetworkID */
475 | (ofdm
->transmission_mode
!= TRANSMISSION_MODE_AUTO
? 1 << 6 : 0)
476 | 0 << 5 /* OtherFrequencyFlag */
477 | 0 << 0 /* reserved */ ;
480 c
->operand
[8] = (params
->frequency
/ 10) >> 24;
481 c
->operand
[9] = ((params
->frequency
/ 10) >> 16) & 0xff;
482 c
->operand
[10] = ((params
->frequency
/ 10) >> 8) & 0xff;
483 c
->operand
[11] = (params
->frequency
/ 10) & 0xff;
485 switch (ofdm
->bandwidth
) {
486 case BANDWIDTH_7_MHZ
: c
->operand
[12] = 0x20; break;
487 case BANDWIDTH_8_MHZ
:
488 case BANDWIDTH_6_MHZ
: /* not defined by AVC spec */
490 default: c
->operand
[12] = 0x00;
493 switch (ofdm
->constellation
) {
494 case QAM_16
: c
->operand
[13] = 1 << 6; break;
495 case QAM_64
: c
->operand
[13] = 2 << 6; break;
497 default: c
->operand
[13] = 0x00;
500 switch (ofdm
->hierarchy_information
) {
501 case HIERARCHY_1
: c
->operand
[13] |= 1 << 3; break;
502 case HIERARCHY_2
: c
->operand
[13] |= 2 << 3; break;
503 case HIERARCHY_4
: c
->operand
[13] |= 3 << 3; break;
509 switch (ofdm
->code_rate_HP
) {
510 case FEC_2_3
: c
->operand
[13] |= 1; break;
511 case FEC_3_4
: c
->operand
[13] |= 2; break;
512 case FEC_5_6
: c
->operand
[13] |= 3; break;
513 case FEC_7_8
: c
->operand
[13] |= 4; break;
518 switch (ofdm
->code_rate_LP
) {
519 case FEC_2_3
: c
->operand
[14] = 1 << 5; break;
520 case FEC_3_4
: c
->operand
[14] = 2 << 5; break;
521 case FEC_5_6
: c
->operand
[14] = 3 << 5; break;
522 case FEC_7_8
: c
->operand
[14] = 4 << 5; break;
524 default: c
->operand
[14] = 0x00; break;
527 switch (ofdm
->guard_interval
) {
528 case GUARD_INTERVAL_1_16
: c
->operand
[14] |= 1 << 3; break;
529 case GUARD_INTERVAL_1_8
: c
->operand
[14] |= 2 << 3; break;
530 case GUARD_INTERVAL_1_4
: c
->operand
[14] |= 3 << 3; break;
531 case GUARD_INTERVAL_1_32
:
532 case GUARD_INTERVAL_AUTO
:
536 switch (ofdm
->transmission_mode
) {
537 case TRANSMISSION_MODE_8K
: c
->operand
[14] |= 1 << 1; break;
538 case TRANSMISSION_MODE_2K
:
539 case TRANSMISSION_MODE_AUTO
:
543 c
->operand
[15] = 0x00; /* network_ID[0] */
544 c
->operand
[16] = 0x00; /* network_ID[1] */
546 /* Add PIDs to filter */
547 c
->length
= ALIGN(17 + add_pid_filter(fdtv
, &c
->operand
[17]) + 3, 4);
550 int avc_tuner_dsd(struct firedtv
*fdtv
,
551 struct dvb_frontend_parameters
*params
)
553 char buffer
[sizeof(struct avc_command_frame
)];
554 struct avc_command_frame
*c
= (void *)buffer
;
555 struct avc_response_frame
*r
= (void *)buffer
; /* FIXME: unused */
557 memset(c
, 0, sizeof(*c
));
559 c
->ctype
= AVC_CTYPE_CONTROL
;
560 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
562 switch (fdtv
->type
) {
564 case FIREDTV_DVB_S2
: avc_tuner_tuneqpsk(fdtv
, params
, c
); break;
565 case FIREDTV_DVB_C
: avc_tuner_dsd_dvb_c(fdtv
, params
, c
); break;
566 case FIREDTV_DVB_T
: avc_tuner_dsd_dvb_t(fdtv
, params
, c
); break;
571 if (avc_write(fdtv
, c
, r
) < 0)
577 /* u8 *status was an out-parameter of avc_tuner_dsd, unused by caller */
579 *status
= r
->operand
[2];
584 int avc_tuner_set_pids(struct firedtv
*fdtv
, unsigned char pidc
, u16 pid
[])
586 char buffer
[sizeof(struct avc_command_frame
)];
587 struct avc_command_frame
*c
= (void *)buffer
;
588 struct avc_response_frame
*r
= (void *)buffer
; /* FIXME: unused */
591 if (pidc
> 16 && pidc
!= 0xff)
594 memset(c
, 0, sizeof(*c
));
596 c
->ctype
= AVC_CTYPE_CONTROL
;
597 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
598 c
->opcode
= AVC_OPCODE_DSD
;
600 c
->operand
[0] = 0; /* source plug */
601 c
->operand
[1] = 0xd2; /* subfunction replace */
602 c
->operand
[2] = 0x20; /* system id = DVB */
603 c
->operand
[3] = 0x00; /* antenna number */
604 c
->operand
[4] = 0x00; /* system_specific_multiplex selection_length */
605 c
->operand
[5] = pidc
; /* Nr_of_dsd_sel_specs */
609 for (k
= 0; k
< pidc
; k
++) {
610 c
->operand
[pos
++] = 0x13; /* flowfunction relay */
611 c
->operand
[pos
++] = 0x80; /* dsd_sel_spec_valid_flags -> PID */
612 c
->operand
[pos
++] = (pid
[k
] >> 8) & 0x1f;
613 c
->operand
[pos
++] = pid
[k
] & 0xff;
614 c
->operand
[pos
++] = 0x00; /* tableID */
615 c
->operand
[pos
++] = 0x00; /* filter_length */
618 c
->length
= ALIGN(3 + pos
, 4);
620 if (avc_write(fdtv
, c
, r
) < 0)
627 int avc_tuner_get_ts(struct firedtv
*fdtv
)
629 char buffer
[sizeof(struct avc_command_frame
)];
630 struct avc_command_frame
*c
= (void *)buffer
;
631 struct avc_response_frame
*r
= (void *)buffer
; /* FIXME: unused */
634 memset(c
, 0, sizeof(*c
));
636 c
->ctype
= AVC_CTYPE_CONTROL
;
637 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
638 c
->opcode
= AVC_OPCODE_DSIT
;
640 sl
= fdtv
->type
== FIREDTV_DVB_T
? 0x0c : 0x11;
642 c
->operand
[0] = 0; /* source plug */
643 c
->operand
[1] = 0xd2; /* subfunction replace */
644 c
->operand
[2] = 0xff; /* status */
645 c
->operand
[3] = 0x20; /* system id = DVB */
646 c
->operand
[4] = 0x00; /* antenna number */
647 c
->operand
[5] = 0x0; /* system_specific_search_flags */
648 c
->operand
[6] = sl
; /* system_specific_multiplex selection_length */
649 c
->operand
[7] = 0x00; /* valid_flags [0] */
650 c
->operand
[8] = 0x00; /* valid_flags [1] */
651 c
->operand
[7 + sl
] = 0x00; /* nr_of_dsit_sel_specs (always 0) */
653 c
->length
= fdtv
->type
== FIREDTV_DVB_T
? 24 : 28;
655 if (avc_write(fdtv
, c
, r
) < 0)
662 int avc_identify_subunit(struct firedtv
*fdtv
)
664 char buffer
[sizeof(struct avc_command_frame
)];
665 struct avc_command_frame
*c
= (void *)buffer
;
666 struct avc_response_frame
*r
= (void *)buffer
;
668 memset(c
, 0, sizeof(*c
));
670 c
->ctype
= AVC_CTYPE_CONTROL
;
671 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
672 c
->opcode
= AVC_OPCODE_READ_DESCRIPTOR
;
674 c
->operand
[0] = DESCRIPTOR_SUBUNIT_IDENTIFIER
;
675 c
->operand
[1] = 0xff;
676 c
->operand
[2] = 0x00;
677 c
->operand
[3] = 0x00; /* length highbyte */
678 c
->operand
[4] = 0x08; /* length lowbyte */
679 c
->operand
[5] = 0x00; /* offset highbyte */
680 c
->operand
[6] = 0x0d; /* offset lowbyte */
684 if (avc_write(fdtv
, c
, r
) < 0)
687 if ((r
->response
!= AVC_RESPONSE_STABLE
&&
688 r
->response
!= AVC_RESPONSE_ACCEPTED
) ||
689 (r
->operand
[3] << 8) + r
->operand
[4] != 8) {
690 dev_err(fdtv
->device
, "cannot read subunit identifier\n");
696 #define SIZEOF_ANTENNA_INPUT_INFO 22
698 int avc_tuner_status(struct firedtv
*fdtv
, struct firedtv_tuner_status
*stat
)
700 char buffer
[sizeof(struct avc_command_frame
)];
701 struct avc_command_frame
*c
= (void *)buffer
;
702 struct avc_response_frame
*r
= (void *)buffer
;
705 memset(c
, 0, sizeof(*c
));
707 c
->ctype
= AVC_CTYPE_CONTROL
;
708 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
709 c
->opcode
= AVC_OPCODE_READ_DESCRIPTOR
;
711 c
->operand
[0] = DESCRIPTOR_TUNER_STATUS
;
712 c
->operand
[1] = 0xff; /* read_result_status */
713 c
->operand
[2] = 0x00; /* reserved */
714 c
->operand
[3] = 0; /* SIZEOF_ANTENNA_INPUT_INFO >> 8; */
715 c
->operand
[4] = 0; /* SIZEOF_ANTENNA_INPUT_INFO & 0xff; */
716 c
->operand
[5] = 0x00;
717 c
->operand
[6] = 0x00;
721 if (avc_write(fdtv
, c
, r
) < 0)
724 if (r
->response
!= AVC_RESPONSE_STABLE
&&
725 r
->response
!= AVC_RESPONSE_ACCEPTED
) {
726 dev_err(fdtv
->device
, "cannot read tuner status\n");
730 length
= r
->operand
[9];
731 if (r
->operand
[1] != 0x10 || length
!= SIZEOF_ANTENNA_INPUT_INFO
) {
732 dev_err(fdtv
->device
, "got invalid tuner status\n");
736 stat
->active_system
= r
->operand
[10];
737 stat
->searching
= r
->operand
[11] >> 7 & 1;
738 stat
->moving
= r
->operand
[11] >> 6 & 1;
739 stat
->no_rf
= r
->operand
[11] >> 5 & 1;
740 stat
->input
= r
->operand
[12] >> 7 & 1;
741 stat
->selected_antenna
= r
->operand
[12] & 0x7f;
742 stat
->ber
= r
->operand
[13] << 24 |
743 r
->operand
[14] << 16 |
744 r
->operand
[15] << 8 |
746 stat
->signal_strength
= r
->operand
[17];
747 stat
->raster_frequency
= r
->operand
[18] >> 6 & 2;
748 stat
->rf_frequency
= (r
->operand
[18] & 0x3f) << 16 |
749 r
->operand
[19] << 8 |
751 stat
->man_dep_info_length
= r
->operand
[21];
752 stat
->front_end_error
= r
->operand
[22] >> 4 & 1;
753 stat
->antenna_error
= r
->operand
[22] >> 3 & 1;
754 stat
->front_end_power_status
= r
->operand
[22] >> 1 & 1;
755 stat
->power_supply
= r
->operand
[22] & 1;
756 stat
->carrier_noise_ratio
= r
->operand
[23] << 8 |
758 stat
->power_supply_voltage
= r
->operand
[27];
759 stat
->antenna_voltage
= r
->operand
[28];
760 stat
->firewire_bus_voltage
= r
->operand
[29];
761 stat
->ca_mmi
= r
->operand
[30] & 1;
762 stat
->ca_pmt_reply
= r
->operand
[31] >> 7 & 1;
763 stat
->ca_date_time_request
= r
->operand
[31] >> 6 & 1;
764 stat
->ca_application_info
= r
->operand
[31] >> 5 & 1;
765 stat
->ca_module_present_status
= r
->operand
[31] >> 4 & 1;
766 stat
->ca_dvb_flag
= r
->operand
[31] >> 3 & 1;
767 stat
->ca_error_flag
= r
->operand
[31] >> 2 & 1;
768 stat
->ca_initialization_status
= r
->operand
[31] >> 1 & 1;
773 int avc_lnb_control(struct firedtv
*fdtv
, char voltage
, char burst
,
774 char conttone
, char nrdiseq
,
775 struct dvb_diseqc_master_cmd
*diseqcmd
)
777 char buffer
[sizeof(struct avc_command_frame
)];
778 struct avc_command_frame
*c
= (void *)buffer
;
779 struct avc_response_frame
*r
= (void *)buffer
;
782 memset(c
, 0, sizeof(*c
));
784 c
->ctype
= AVC_CTYPE_CONTROL
;
785 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
786 c
->opcode
= AVC_OPCODE_VENDOR
;
788 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
789 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
790 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
791 c
->operand
[3] = SFE_VENDOR_OPCODE_LNB_CONTROL
;
793 c
->operand
[4] = voltage
;
794 c
->operand
[5] = nrdiseq
;
798 for (j
= 0; j
< nrdiseq
; j
++) {
799 c
->operand
[i
++] = diseqcmd
[j
].msg_len
;
801 for (k
= 0; k
< diseqcmd
[j
].msg_len
; k
++)
802 c
->operand
[i
++] = diseqcmd
[j
].msg
[k
];
805 c
->operand
[i
++] = burst
;
806 c
->operand
[i
++] = conttone
;
808 c
->length
= ALIGN(3 + i
, 4);
810 if (avc_write(fdtv
, c
, r
) < 0)
813 if (r
->response
!= AVC_RESPONSE_ACCEPTED
) {
814 dev_err(fdtv
->device
, "LNB control failed\n");
821 int avc_register_remote_control(struct firedtv
*fdtv
)
823 char buffer
[sizeof(struct avc_command_frame
)];
824 struct avc_command_frame
*c
= (void *)buffer
;
826 memset(c
, 0, sizeof(*c
));
828 c
->ctype
= AVC_CTYPE_NOTIFY
;
829 c
->subunit
= AVC_SUBUNIT_TYPE_UNIT
| 7;
830 c
->opcode
= AVC_OPCODE_VENDOR
;
832 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
833 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
834 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
835 c
->operand
[3] = SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL
;
839 return avc_write(fdtv
, c
, NULL
);
842 void avc_remote_ctrl_work(struct work_struct
*work
)
844 struct firedtv
*fdtv
=
845 container_of(work
, struct firedtv
, remote_ctrl_work
);
847 /* Should it be rescheduled in failure cases? */
848 avc_register_remote_control(fdtv
);
851 #if 0 /* FIXME: unused */
852 int avc_tuner_host2ca(struct firedtv
*fdtv
)
854 char buffer
[sizeof(struct avc_command_frame
)];
855 struct avc_command_frame
*c
= (void *)buffer
;
856 struct avc_response_frame
*r
= (void *)buffer
; /* FIXME: unused */
858 memset(c
, 0, sizeof(*c
));
860 c
->ctype
= AVC_CTYPE_CONTROL
;
861 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
862 c
->opcode
= AVC_OPCODE_VENDOR
;
864 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
865 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
866 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
867 c
->operand
[3] = SFE_VENDOR_OPCODE_HOST2CA
;
868 c
->operand
[4] = 0; /* slot */
869 c
->operand
[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO
; /* ca tag */
870 c
->operand
[6] = 0; /* more/last */
871 c
->operand
[7] = 0; /* length */
875 if (avc_write(fdtv
, c
, r
) < 0)
882 static int get_ca_object_pos(struct avc_response_frame
*r
)
886 /* Check length of length field */
887 if (r
->operand
[7] & 0x80)
888 length
= (r
->operand
[7] & 0x7f) + 1;
892 static int get_ca_object_length(struct avc_response_frame
*r
)
894 #if 0 /* FIXME: unused */
898 if (r
->operand
[7] & 0x80)
899 for (i
= 0; i
< (r
->operand
[7] & 0x7f); i
++) {
901 size
+= r
->operand
[8 + i
];
904 return r
->operand
[7];
907 int avc_ca_app_info(struct firedtv
*fdtv
, char *app_info
, unsigned int *len
)
909 char buffer
[sizeof(struct avc_command_frame
)];
910 struct avc_command_frame
*c
= (void *)buffer
;
911 struct avc_response_frame
*r
= (void *)buffer
;
914 memset(c
, 0, sizeof(*c
));
916 c
->ctype
= AVC_CTYPE_STATUS
;
917 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
918 c
->opcode
= AVC_OPCODE_VENDOR
;
920 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
921 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
922 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
923 c
->operand
[3] = SFE_VENDOR_OPCODE_CA2HOST
;
924 c
->operand
[4] = 0; /* slot */
925 c
->operand
[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO
; /* ca tag */
929 if (avc_write(fdtv
, c
, r
) < 0)
932 /* FIXME: check response code and validate response data */
934 pos
= get_ca_object_pos(r
);
935 app_info
[0] = (EN50221_TAG_APP_INFO
>> 16) & 0xff;
936 app_info
[1] = (EN50221_TAG_APP_INFO
>> 8) & 0xff;
937 app_info
[2] = (EN50221_TAG_APP_INFO
>> 0) & 0xff;
938 app_info
[3] = 6 + r
->operand
[pos
+ 4];
940 memcpy(&app_info
[5], &r
->operand
[pos
], 5 + r
->operand
[pos
+ 4]);
941 *len
= app_info
[3] + 4;
946 int avc_ca_info(struct firedtv
*fdtv
, char *app_info
, unsigned int *len
)
948 char buffer
[sizeof(struct avc_command_frame
)];
949 struct avc_command_frame
*c
= (void *)buffer
;
950 struct avc_response_frame
*r
= (void *)buffer
;
953 memset(c
, 0, sizeof(*c
));
955 c
->ctype
= AVC_CTYPE_STATUS
;
956 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
957 c
->opcode
= AVC_OPCODE_VENDOR
;
959 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
960 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
961 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
962 c
->operand
[3] = SFE_VENDOR_OPCODE_CA2HOST
;
963 c
->operand
[4] = 0; /* slot */
964 c
->operand
[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO
; /* ca tag */
968 if (avc_write(fdtv
, c
, r
) < 0)
971 pos
= get_ca_object_pos(r
);
972 app_info
[0] = (EN50221_TAG_CA_INFO
>> 16) & 0xff;
973 app_info
[1] = (EN50221_TAG_CA_INFO
>> 8) & 0xff;
974 app_info
[2] = (EN50221_TAG_CA_INFO
>> 0) & 0xff;
976 app_info
[4] = r
->operand
[pos
+ 0];
977 app_info
[5] = r
->operand
[pos
+ 1];
978 *len
= app_info
[3] + 4;
983 int avc_ca_reset(struct firedtv
*fdtv
)
985 char buffer
[sizeof(struct avc_command_frame
)];
986 struct avc_command_frame
*c
= (void *)buffer
;
987 struct avc_response_frame
*r
= (void *)buffer
; /* FIXME: unused */
989 memset(c
, 0, sizeof(*c
));
991 c
->ctype
= AVC_CTYPE_CONTROL
;
992 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
993 c
->opcode
= AVC_OPCODE_VENDOR
;
995 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
996 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
997 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
998 c
->operand
[3] = SFE_VENDOR_OPCODE_HOST2CA
;
999 c
->operand
[4] = 0; /* slot */
1000 c
->operand
[5] = SFE_VENDOR_TAG_CA_RESET
; /* ca tag */
1001 c
->operand
[6] = 0; /* more/last */
1002 c
->operand
[7] = 1; /* length */
1003 c
->operand
[8] = 0; /* force hardware reset */
1007 if (avc_write(fdtv
, c
, r
) < 0)
1013 int avc_ca_pmt(struct firedtv
*fdtv
, char *msg
, int length
)
1015 char buffer
[sizeof(struct avc_command_frame
)];
1016 struct avc_command_frame
*c
= (void *)buffer
;
1017 struct avc_response_frame
*r
= (void *)buffer
;
1018 int list_management
;
1019 int program_info_length
;
1026 if (unlikely(avc_debug
& AVC_DEBUG_APPLICATION_PMT
))
1027 debug_pmt(msg
, length
);
1029 memset(c
, 0, sizeof(*c
));
1031 c
->ctype
= AVC_CTYPE_CONTROL
;
1032 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
1033 c
->opcode
= AVC_OPCODE_VENDOR
;
1035 if (msg
[0] != EN50221_LIST_MANAGEMENT_ONLY
) {
1036 dev_info(fdtv
->device
, "forcing list_management to ONLY\n");
1037 msg
[0] = EN50221_LIST_MANAGEMENT_ONLY
;
1039 /* We take the cmd_id from the programme level only! */
1040 list_management
= msg
[0];
1041 program_info_length
= ((msg
[4] & 0x0f) << 8) + msg
[5];
1042 if (program_info_length
> 0)
1043 program_info_length
--; /* Remove pmt_cmd_id */
1044 pmt_cmd_id
= msg
[6];
1046 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
1047 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
1048 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
1049 c
->operand
[3] = SFE_VENDOR_OPCODE_HOST2CA
;
1050 c
->operand
[4] = 0; /* slot */
1051 c
->operand
[5] = SFE_VENDOR_TAG_CA_PMT
; /* ca tag */
1052 c
->operand
[6] = 0; /* more/last */
1053 /* c->operand[7] = XXXprogram_info_length + 17; */ /* length */
1054 c
->operand
[8] = list_management
;
1055 c
->operand
[9] = 0x01; /* pmt_cmd=OK_descramble */
1057 /* TS program map table */
1059 c
->operand
[10] = 0x02; /* Table id=2 */
1060 c
->operand
[11] = 0x80; /* Section syntax + length */
1061 /* c->operand[12] = XXXprogram_info_length + 12; */
1062 c
->operand
[13] = msg
[1]; /* Program number */
1063 c
->operand
[14] = msg
[2];
1064 c
->operand
[15] = 0x01; /* Version number=0 + current/next=1 */
1065 c
->operand
[16] = 0x00; /* Section number=0 */
1066 c
->operand
[17] = 0x00; /* Last section number=0 */
1067 c
->operand
[18] = 0x1f; /* PCR_PID=1FFF */
1068 c
->operand
[19] = 0xff;
1069 c
->operand
[20] = (program_info_length
>> 8); /* Program info length */
1070 c
->operand
[21] = (program_info_length
& 0xff);
1072 /* CA descriptors at programme level */
1075 if (program_info_length
> 0) {
1076 pmt_cmd_id
= msg
[read_pos
++];
1077 if (pmt_cmd_id
!= 1 && pmt_cmd_id
!= 4)
1078 dev_err(fdtv
->device
,
1079 "invalid pmt_cmd_id %d\n", pmt_cmd_id
);
1081 memcpy(&c
->operand
[write_pos
], &msg
[read_pos
],
1082 program_info_length
);
1083 read_pos
+= program_info_length
;
1084 write_pos
+= program_info_length
;
1086 while (read_pos
< length
) {
1087 c
->operand
[write_pos
++] = msg
[read_pos
++];
1088 c
->operand
[write_pos
++] = msg
[read_pos
++];
1089 c
->operand
[write_pos
++] = msg
[read_pos
++];
1091 ((msg
[read_pos
] & 0x0f) << 8) + msg
[read_pos
+ 1];
1093 if (es_info_length
> 0)
1094 es_info_length
--; /* Remove pmt_cmd_id */
1095 c
->operand
[write_pos
++] = es_info_length
>> 8;
1096 c
->operand
[write_pos
++] = es_info_length
& 0xff;
1097 if (es_info_length
> 0) {
1098 pmt_cmd_id
= msg
[read_pos
++];
1099 if (pmt_cmd_id
!= 1 && pmt_cmd_id
!= 4)
1100 dev_err(fdtv
->device
, "invalid pmt_cmd_id %d "
1101 "at stream level\n", pmt_cmd_id
);
1103 memcpy(&c
->operand
[write_pos
], &msg
[read_pos
],
1105 read_pos
+= es_info_length
;
1106 write_pos
+= es_info_length
;
1111 c
->operand
[write_pos
++] = 0x00;
1112 c
->operand
[write_pos
++] = 0x00;
1113 c
->operand
[write_pos
++] = 0x00;
1114 c
->operand
[write_pos
++] = 0x00;
1116 c
->operand
[7] = write_pos
- 8;
1117 c
->operand
[12] = write_pos
- 13;
1119 crc32_csum
= crc32_be(0, &c
->operand
[10], c
->operand
[12] - 1);
1120 c
->operand
[write_pos
- 4] = (crc32_csum
>> 24) & 0xff;
1121 c
->operand
[write_pos
- 3] = (crc32_csum
>> 16) & 0xff;
1122 c
->operand
[write_pos
- 2] = (crc32_csum
>> 8) & 0xff;
1123 c
->operand
[write_pos
- 1] = (crc32_csum
>> 0) & 0xff;
1125 c
->length
= ALIGN(3 + write_pos
, 4);
1127 if (avc_write(fdtv
, c
, r
) < 0)
1130 if (r
->response
!= AVC_RESPONSE_ACCEPTED
) {
1131 dev_err(fdtv
->device
,
1132 "CA PMT failed with response 0x%x\n", r
->response
);
1139 int avc_ca_get_time_date(struct firedtv
*fdtv
, int *interval
)
1141 char buffer
[sizeof(struct avc_command_frame
)];
1142 struct avc_command_frame
*c
= (void *)buffer
;
1143 struct avc_response_frame
*r
= (void *)buffer
;
1145 memset(c
, 0, sizeof(*c
));
1147 c
->ctype
= AVC_CTYPE_STATUS
;
1148 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
1149 c
->opcode
= AVC_OPCODE_VENDOR
;
1151 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
1152 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
1153 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
1154 c
->operand
[3] = SFE_VENDOR_OPCODE_CA2HOST
;
1155 c
->operand
[4] = 0; /* slot */
1156 c
->operand
[5] = SFE_VENDOR_TAG_CA_DATE_TIME
; /* ca tag */
1157 c
->operand
[6] = 0; /* more/last */
1158 c
->operand
[7] = 0; /* length */
1162 if (avc_write(fdtv
, c
, r
) < 0)
1165 /* FIXME: check response code and validate response data */
1167 *interval
= r
->operand
[get_ca_object_pos(r
)];
1172 int avc_ca_enter_menu(struct firedtv
*fdtv
)
1174 char buffer
[sizeof(struct avc_command_frame
)];
1175 struct avc_command_frame
*c
= (void *)buffer
;
1176 struct avc_response_frame
*r
= (void *)buffer
; /* FIXME: unused */
1178 memset(c
, 0, sizeof(*c
));
1180 c
->ctype
= AVC_CTYPE_STATUS
;
1181 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
1182 c
->opcode
= AVC_OPCODE_VENDOR
;
1184 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
1185 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
1186 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
1187 c
->operand
[3] = SFE_VENDOR_OPCODE_HOST2CA
;
1188 c
->operand
[4] = 0; /* slot */
1189 c
->operand
[5] = SFE_VENDOR_TAG_CA_ENTER_MENU
;
1190 c
->operand
[6] = 0; /* more/last */
1191 c
->operand
[7] = 0; /* length */
1195 if (avc_write(fdtv
, c
, r
) < 0)
1201 int avc_ca_get_mmi(struct firedtv
*fdtv
, char *mmi_object
, unsigned int *len
)
1203 char buffer
[sizeof(struct avc_command_frame
)];
1204 struct avc_command_frame
*c
= (void *)buffer
;
1205 struct avc_response_frame
*r
= (void *)buffer
;
1207 memset(c
, 0, sizeof(*c
));
1209 c
->ctype
= AVC_CTYPE_STATUS
;
1210 c
->subunit
= AVC_SUBUNIT_TYPE_TUNER
| fdtv
->subunit
;
1211 c
->opcode
= AVC_OPCODE_VENDOR
;
1213 c
->operand
[0] = SFE_VENDOR_DE_COMPANYID_0
;
1214 c
->operand
[1] = SFE_VENDOR_DE_COMPANYID_1
;
1215 c
->operand
[2] = SFE_VENDOR_DE_COMPANYID_2
;
1216 c
->operand
[3] = SFE_VENDOR_OPCODE_CA2HOST
;
1217 c
->operand
[4] = 0; /* slot */
1218 c
->operand
[5] = SFE_VENDOR_TAG_CA_MMI
;
1219 c
->operand
[6] = 0; /* more/last */
1220 c
->operand
[7] = 0; /* length */
1224 if (avc_write(fdtv
, c
, r
) < 0)
1227 /* FIXME: check response code and validate response data */
1229 *len
= get_ca_object_length(r
);
1230 memcpy(mmi_object
, &r
->operand
[get_ca_object_pos(r
)], *len
);
1235 #define CMP_OUTPUT_PLUG_CONTROL_REG_0 0xfffff0000904ULL
1237 static int cmp_read(struct firedtv
*fdtv
, void *buf
, u64 addr
, size_t len
)
1241 if (mutex_lock_interruptible(&fdtv
->avc_mutex
))
1244 ret
= fdtv
->backend
->read(fdtv
, addr
, buf
, len
);
1246 dev_err(fdtv
->device
, "CMP: read I/O error\n");
1248 mutex_unlock(&fdtv
->avc_mutex
);
1252 static int cmp_lock(struct firedtv
*fdtv
, void *data
, u64 addr
, __be32 arg
)
1256 if (mutex_lock_interruptible(&fdtv
->avc_mutex
))
1259 ret
= fdtv
->backend
->lock(fdtv
, addr
, data
, arg
);
1261 dev_err(fdtv
->device
, "CMP: lock I/O error\n");
1263 mutex_unlock(&fdtv
->avc_mutex
);
1267 static inline u32
get_opcr(__be32 opcr
, u32 mask
, u32 shift
)
1269 return (be32_to_cpu(opcr
) >> shift
) & mask
;
1272 static inline void set_opcr(__be32
*opcr
, u32 value
, u32 mask
, u32 shift
)
1274 *opcr
&= ~cpu_to_be32(mask
<< shift
);
1275 *opcr
|= cpu_to_be32((value
& mask
) << shift
);
1278 #define get_opcr_online(v) get_opcr((v), 0x1, 31)
1279 #define get_opcr_p2p_connections(v) get_opcr((v), 0x3f, 24)
1280 #define get_opcr_channel(v) get_opcr((v), 0x3f, 16)
1282 #define set_opcr_p2p_connections(p, v) set_opcr((p), (v), 0x3f, 24)
1283 #define set_opcr_channel(p, v) set_opcr((p), (v), 0x3f, 16)
1284 #define set_opcr_data_rate(p, v) set_opcr((p), (v), 0x3, 14)
1285 #define set_opcr_overhead_id(p, v) set_opcr((p), (v), 0xf, 10)
1287 int cmp_establish_pp_connection(struct firedtv
*fdtv
, int plug
, int channel
)
1289 __be32 old_opcr
, opcr
;
1290 u64 opcr_address
= CMP_OUTPUT_PLUG_CONTROL_REG_0
+ (plug
<< 2);
1294 ret
= cmp_read(fdtv
, &opcr
, opcr_address
, 4);
1299 if (!get_opcr_online(opcr
)) {
1300 dev_err(fdtv
->device
, "CMP: output offline\n");
1306 if (get_opcr_p2p_connections(opcr
)) {
1307 if (get_opcr_channel(opcr
) != channel
) {
1308 dev_err(fdtv
->device
, "CMP: cannot change channel\n");
1311 dev_info(fdtv
->device
, "CMP: overlaying connection\n");
1313 /* We don't allocate isochronous resources. */
1315 set_opcr_channel(&opcr
, channel
);
1316 set_opcr_data_rate(&opcr
, 2); /* S400 */
1318 /* FIXME: this is for the worst case - optimize */
1319 set_opcr_overhead_id(&opcr
, 0);
1322 * FIXME: allocate isochronous channel and bandwidth at IRM
1323 * fdtv->backend->alloc_resources(fdtv, channels_mask, bw);
1327 set_opcr_p2p_connections(&opcr
, get_opcr_p2p_connections(opcr
) + 1);
1329 ret
= cmp_lock(fdtv
, &opcr
, opcr_address
, old_opcr
);
1333 if (old_opcr
!= opcr
) {
1335 * FIXME: if old_opcr.P2P_Connections > 0,
1336 * deallocate isochronous channel and bandwidth at IRM
1338 * fdtv->backend->dealloc_resources(fdtv, channel, bw);
1341 if (++attempts
< 6) /* arbitrary limit */
1349 void cmp_break_pp_connection(struct firedtv
*fdtv
, int plug
, int channel
)
1351 __be32 old_opcr
, opcr
;
1352 u64 opcr_address
= CMP_OUTPUT_PLUG_CONTROL_REG_0
+ (plug
<< 2);
1355 if (cmp_read(fdtv
, &opcr
, opcr_address
, 4) < 0)
1359 if (!get_opcr_online(opcr
) || !get_opcr_p2p_connections(opcr
) ||
1360 get_opcr_channel(opcr
) != channel
) {
1361 dev_err(fdtv
->device
, "CMP: no connection to break\n");
1366 set_opcr_p2p_connections(&opcr
, get_opcr_p2p_connections(opcr
) - 1);
1368 if (cmp_lock(fdtv
, &opcr
, opcr_address
, old_opcr
) < 0)
1371 if (old_opcr
!= opcr
) {
1373 * FIXME: if old_opcr.P2P_Connections == 1, i.e. we were last
1374 * owner, deallocate isochronous channel and bandwidth at IRM
1376 * fdtv->backend->dealloc_resources(fdtv, channel, bw);
1379 if (++attempts
< 6) /* arbitrary limit */