1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* DVB USB compliant Linux driver for the Afatech 9005
3 * USB1.1 DVB-T receiver.
5 * Copyright (C) 2007 Luca Olivetti (luca@ventoso.org)
7 * Thanks to Afatech who kindly provided information.
9 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
14 int dvb_usb_af9005_debug
;
15 module_param_named(debug
, dvb_usb_af9005_debug
, int, 0644);
16 MODULE_PARM_DESC(debug
,
17 "set debugging level (1=info,xfer=2,rc=4,reg=8,i2c=16,fw=32 (or-able))."
18 DVB_USB_DEBUG_STATUS
);
19 /* enable obnoxious led */
20 bool dvb_usb_af9005_led
= true;
21 module_param_named(led
, dvb_usb_af9005_led
, bool, 0644);
22 MODULE_PARM_DESC(led
, "enable led (default: 1).");
25 static int dvb_usb_af9005_dump_eeprom
;
26 module_param_named(dump_eeprom
, dvb_usb_af9005_dump_eeprom
, int, 0);
27 MODULE_PARM_DESC(dump_eeprom
, "dump contents of the eeprom.");
29 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
31 /* remote control decoder */
32 static int (*rc_decode
) (struct dvb_usb_device
*d
, u8
*data
, int len
,
33 u32
*event
, int *state
);
35 static int *rc_keys_size
;
37 u8 regmask
[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
39 struct af9005_device_state
{
42 unsigned char data
[256];
45 static int af9005_generic_read_write(struct dvb_usb_device
*d
, u16 reg
,
46 int readwrite
, int type
, u8
* values
, int len
)
48 struct af9005_device_state
*st
= d
->priv
;
53 err("generic read/write, less than 1 byte. Makes no sense.");
57 err("generic read/write, more than 8 bytes. Not supported.");
61 mutex_lock(&d
->data_mutex
);
62 st
->data
[0] = 14; /* rest of buffer length low */
63 st
->data
[1] = 0; /* rest of buffer length high */
65 st
->data
[2] = AF9005_REGISTER_RW
; /* register operation */
66 st
->data
[3] = 12; /* rest of buffer length */
68 st
->data
[4] = seq
= st
->sequence
++; /* sequence number */
70 st
->data
[5] = (u8
) (reg
>> 8); /* register address */
71 st
->data
[6] = (u8
) (reg
& 0xff);
73 if (type
== AF9005_OFDM_REG
) {
74 command
= AF9005_CMD_OFDM_REG
;
76 command
= AF9005_CMD_TUNER
;
81 AF9005_CMD_BURST
| AF9005_CMD_AUTOINC
| (len
- 1) << 3;
83 if (readwrite
== AF9005_CMD_WRITE
)
84 for (i
= 0; i
< len
; i
++)
85 st
->data
[8 + i
] = values
[i
];
86 else if (type
== AF9005_TUNER_REG
)
87 /* read command for tuner, the first byte contains the i2c address */
88 st
->data
[8] = values
[0];
89 st
->data
[7] = command
;
91 ret
= dvb_usb_generic_rw(d
, st
->data
, 16, st
->data
, 17, 0);
96 if (st
->data
[2] != AF9005_REGISTER_RW_ACK
) {
97 err("generic read/write, wrong reply code.");
101 if (st
->data
[3] != 0x0d) {
102 err("generic read/write, wrong length in reply.");
106 if (st
->data
[4] != seq
) {
107 err("generic read/write, wrong sequence in reply.");
112 * In thesis, both input and output buffers should have
113 * identical values for st->data[5] to st->data[8].
114 * However, windows driver doesn't check these fields, in fact
115 * sometimes the register in the reply is different that what
118 if (st
->data
[16] != 0x01) {
119 err("generic read/write wrong status code in reply.");
124 if (readwrite
== AF9005_CMD_READ
)
125 for (i
= 0; i
< len
; i
++)
126 values
[i
] = st
->data
[8 + i
];
129 mutex_unlock(&d
->data_mutex
);
134 int af9005_read_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8
* value
)
137 deb_reg("read register %x ", reg
);
138 ret
= af9005_generic_read_write(d
, reg
,
139 AF9005_CMD_READ
, AF9005_OFDM_REG
,
144 deb_reg("value %x\n", *value
);
148 int af9005_read_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
149 u8
* values
, int len
)
152 deb_reg("read %d registers %x ", len
, reg
);
153 ret
= af9005_generic_read_write(d
, reg
,
154 AF9005_CMD_READ
, AF9005_OFDM_REG
,
159 debug_dump(values
, len
, deb_reg
);
163 int af9005_write_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8 value
)
167 deb_reg("write register %x value %x ", reg
, value
);
168 ret
= af9005_generic_read_write(d
, reg
,
169 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
178 int af9005_write_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
179 u8
* values
, int len
)
182 deb_reg("write %d registers %x values ", len
, reg
);
183 debug_dump(values
, len
, deb_reg
);
185 ret
= af9005_generic_read_write(d
, reg
,
186 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
195 int af9005_read_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
200 deb_reg("read bits %x %x %x", reg
, pos
, len
);
201 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
203 deb_reg(" failed\n");
206 *value
= (temp
>> pos
) & regmask
[len
- 1];
207 deb_reg(" value %x\n", *value
);
212 int af9005_write_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
217 deb_reg("write bits %x %x %x value %x\n", reg
, pos
, len
, value
);
218 if (pos
== 0 && len
== 8)
219 return af9005_write_ofdm_register(d
, reg
, value
);
220 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
223 mask
= regmask
[len
- 1] << pos
;
224 temp
= (temp
& ~mask
) | ((value
<< pos
) & mask
);
225 return af9005_write_ofdm_register(d
, reg
, temp
);
229 static int af9005_usb_read_tuner_registers(struct dvb_usb_device
*d
,
230 u16 reg
, u8
* values
, int len
)
232 return af9005_generic_read_write(d
, reg
,
233 AF9005_CMD_READ
, AF9005_TUNER_REG
,
237 static int af9005_usb_write_tuner_registers(struct dvb_usb_device
*d
,
238 u16 reg
, u8
* values
, int len
)
240 return af9005_generic_read_write(d
, reg
,
242 AF9005_TUNER_REG
, values
, len
);
245 int af9005_write_tuner_registers(struct dvb_usb_device
*d
, u16 reg
,
246 u8
* values
, int len
)
248 /* don't let the name of this function mislead you: it's just used
249 as an interface from the firmware to the i2c bus. The actual
250 i2c addresses are contained in the data */
251 int ret
, i
, done
= 0, fail
= 0;
253 ret
= af9005_usb_write_tuner_registers(d
, reg
, values
, len
);
257 /* check if write done (0xa40d bit 1) or fail (0xa40d bit 2) */
258 for (i
= 0; i
< 200; i
++) {
260 af9005_read_ofdm_register(d
,
261 xd_I2C_i2c_m_status_wdat_done
,
265 done
= temp
& (regmask
[i2c_m_status_wdat_done_len
- 1]
266 << i2c_m_status_wdat_done_pos
);
269 fail
= temp
& (regmask
[i2c_m_status_wdat_fail_len
- 1]
270 << i2c_m_status_wdat_fail_pos
);
278 /* clear write fail bit */
279 af9005_write_register_bits(d
,
280 xd_I2C_i2c_m_status_wdat_fail
,
281 i2c_m_status_wdat_fail_pos
,
282 i2c_m_status_wdat_fail_len
,
286 /* clear write done bit */
288 af9005_write_register_bits(d
,
289 xd_I2C_i2c_m_status_wdat_fail
,
290 i2c_m_status_wdat_done_pos
,
291 i2c_m_status_wdat_done_len
, 1);
298 int af9005_read_tuner_registers(struct dvb_usb_device
*d
, u16 reg
, u8 addr
,
299 u8
* values
, int len
)
301 /* don't let the name of this function mislead you: it's just used
302 as an interface from the firmware to the i2c bus. The actual
303 i2c addresses are contained in the data */
307 buf
[0] = addr
; /* tuner i2c address */
308 buf
[1] = values
[0]; /* tuner register */
310 values
[0] = addr
+ 0x01; /* i2c read address */
312 if (reg
== APO_REG_I2C_RW_SILICON_TUNER
) {
313 /* write tuner i2c address to tuner, 0c00c0 undocumented, found by sniffing */
314 ret
= af9005_write_tuner_registers(d
, 0x00c0, buf
, 2);
319 /* send read command to ofsm */
320 ret
= af9005_usb_read_tuner_registers(d
, reg
, values
, 1);
324 /* check if read done */
325 for (i
= 0; i
< 200; i
++) {
326 ret
= af9005_read_ofdm_register(d
, 0xa408, &temp
);
336 /* clear read done bit (by writing 1) */
337 ret
= af9005_write_ofdm_register(d
, xd_I2C_i2c_m_data8
, 1);
341 /* get read data (available from 0xa400) */
342 for (i
= 0; i
< len
; i
++) {
343 ret
= af9005_read_ofdm_register(d
, 0xa400 + i
, &temp
);
351 static int af9005_i2c_write(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
356 deb_i2c("i2c_write i2caddr %x, reg %x, len %d data ", i2caddr
,
358 debug_dump(data
, len
, deb_i2c
);
360 for (i
= 0; i
< len
; i
++) {
362 buf
[1] = reg
+ (u8
) i
;
365 af9005_write_tuner_registers(d
,
366 APO_REG_I2C_RW_SILICON_TUNER
,
369 deb_i2c("i2c_write failed\n");
373 deb_i2c("i2c_write ok\n");
377 static int af9005_i2c_read(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
382 deb_i2c("i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr
, reg
, len
);
383 for (i
= 0; i
< len
; i
++) {
386 af9005_read_tuner_registers(d
,
387 APO_REG_I2C_RW_SILICON_TUNER
,
390 deb_i2c("i2c_read failed\n");
395 deb_i2c("i2c data read: ");
396 debug_dump(data
, len
, deb_i2c
);
400 static int af9005_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
403 /* only implements what the mt2060 module does, don't know how
404 to make it really generic */
405 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
410 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
414 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
417 /* reads a single register */
421 ret
= af9005_i2c_read(d
, addr
, reg
, value
, 1);
425 if (msg
[0].len
< 2) {
429 /* write one or more registers */
432 value
= &msg
[0].buf
[1];
433 ret
= af9005_i2c_write(d
, addr
, reg
, value
, msg
[0].len
- 1);
439 mutex_unlock(&d
->i2c_mutex
);
443 static u32
af9005_i2c_func(struct i2c_adapter
*adapter
)
448 static struct i2c_algorithm af9005_i2c_algo
= {
449 .master_xfer
= af9005_i2c_xfer
,
450 .functionality
= af9005_i2c_func
,
453 int af9005_send_command(struct dvb_usb_device
*d
, u8 command
, u8
* wbuf
,
454 int wlen
, u8
* rbuf
, int rlen
)
456 struct af9005_device_state
*st
= d
->priv
;
458 int ret
, i
, packet_len
;
462 err("send command, wlen less than 0 bytes. Makes no sense.");
466 err("send command, wlen more than 54 bytes. Not supported.");
470 err("send command, rlen more than 54 bytes. Not supported.");
473 packet_len
= wlen
+ 5;
475 mutex_lock(&d
->data_mutex
);
477 st
->data
[0] = (u8
) (packet_len
& 0xff);
478 st
->data
[1] = (u8
) ((packet_len
& 0xff00) >> 8);
480 st
->data
[2] = 0x26; /* packet type */
481 st
->data
[3] = wlen
+ 3;
482 st
->data
[4] = seq
= st
->sequence
++;
483 st
->data
[5] = command
;
485 for (i
= 0; i
< wlen
; i
++)
486 st
->data
[7 + i
] = wbuf
[i
];
487 ret
= dvb_usb_generic_rw(d
, st
->data
, wlen
+ 7, st
->data
, rlen
+ 7, 0);
488 if (st
->data
[2] != 0x27) {
489 err("send command, wrong reply code.");
491 } else if (st
->data
[4] != seq
) {
492 err("send command, wrong sequence in reply.");
494 } else if (st
->data
[5] != 0x01) {
495 err("send command, wrong status code in reply.");
497 } else if (st
->data
[6] != rlen
) {
498 err("send command, invalid data length in reply.");
502 for (i
= 0; i
< rlen
; i
++)
503 rbuf
[i
] = st
->data
[i
+ 7];
506 mutex_unlock(&d
->data_mutex
);
510 int af9005_read_eeprom(struct dvb_usb_device
*d
, u8 address
, u8
* values
,
513 struct af9005_device_state
*st
= d
->priv
;
517 mutex_lock(&d
->data_mutex
);
519 memset(st
->data
, 0, sizeof(st
->data
));
521 st
->data
[0] = 14; /* length of rest of packet low */
522 st
->data
[1] = 0; /* length of rest of packer high */
524 st
->data
[2] = 0x2a; /* read/write eeprom */
526 st
->data
[3] = 12; /* size */
528 st
->data
[4] = seq
= st
->sequence
++;
530 st
->data
[5] = 0; /* read */
533 st
->data
[7] = address
;
534 ret
= dvb_usb_generic_rw(d
, st
->data
, 16, st
->data
, 14, 0);
535 if (st
->data
[2] != 0x2b) {
536 err("Read eeprom, invalid reply code");
538 } else if (st
->data
[3] != 10) {
539 err("Read eeprom, invalid reply length");
541 } else if (st
->data
[4] != seq
) {
542 err("Read eeprom, wrong sequence in reply ");
544 } else if (st
->data
[5] != 1) {
545 err("Read eeprom, wrong status in reply ");
550 for (i
= 0; i
< len
; i
++)
551 values
[i
] = st
->data
[6 + i
];
553 mutex_unlock(&d
->data_mutex
);
558 static int af9005_boot_packet(struct usb_device
*udev
, int type
, u8
*reply
,
562 int act_len
= 0, i
, ret
;
564 memset(buf
, 0, size
);
565 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
566 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
571 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
573 checksum
= buf
[4] + buf
[5];
574 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
575 buf
[7] = (u8
) (checksum
& 0xff);
580 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
582 checksum
= buf
[4] + buf
[5];
583 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
584 buf
[7] = (u8
) (checksum
& 0xff);
589 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
596 for (i
= 4; i
<= 9; i
++)
598 buf
[10] = (u8
) ((checksum
>> 8) & 0xff);
599 buf
[11] = (u8
) (checksum
& 0xff);
602 err("boot packet invalid boot packet type");
606 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
608 ret
= usb_bulk_msg(udev
,
609 usb_sndbulkpipe(udev
, 0x02),
610 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 2000);
612 err("boot packet bulk message failed: %d (%d/%d)", ret
,
613 FW_BULKOUT_SIZE
+ 2, act_len
);
615 ret
= act_len
!= FW_BULKOUT_SIZE
+ 2 ? -1 : 0;
619 ret
= usb_bulk_msg(udev
,
620 usb_rcvbulkpipe(udev
, 0x01), buf
, 9, &act_len
, 2000);
622 err("boot packet recv bulk message failed: %d", ret
);
626 debug_dump(buf
, act_len
, deb_fw
);
630 if (buf
[2] != 0x11) {
631 err("boot bad config header.");
634 if (buf
[3] != 0x05) {
635 err("boot bad config size.");
638 if (buf
[4] != 0x00) {
639 err("boot bad config sequence.");
642 if (buf
[5] != 0x04) {
643 err("boot bad config subtype.");
646 for (i
= 4; i
<= 6; i
++)
648 if (buf
[7] * 256 + buf
[8] != checksum
) {
649 err("boot bad config checksum.");
655 if (buf
[2] != 0x11) {
656 err("boot bad confirm header.");
659 if (buf
[3] != 0x05) {
660 err("boot bad confirm size.");
663 if (buf
[4] != 0x00) {
664 err("boot bad confirm sequence.");
667 if (buf
[5] != 0x02) {
668 err("boot bad confirm subtype.");
671 for (i
= 4; i
<= 6; i
++)
673 if (buf
[7] * 256 + buf
[8] != checksum
) {
674 err("boot bad confirm checksum.");
680 if (buf
[2] != 0x10) {
681 err("boot bad boot header.");
684 if (buf
[3] != 0x05) {
685 err("boot bad boot size.");
688 if (buf
[4] != 0x00) {
689 err("boot bad boot sequence.");
692 if (buf
[5] != 0x01) {
693 err("boot bad boot pattern 01.");
696 if (buf
[6] != 0x10) {
697 err("boot bad boot pattern 10.");
700 for (i
= 4; i
<= 6; i
++)
702 if (buf
[7] * 256 + buf
[8] != checksum
) {
703 err("boot bad boot checksum.");
713 static int af9005_download_firmware(struct usb_device
*udev
, const struct firmware
*fw
)
715 int i
, packets
, ret
, act_len
;
720 buf
= kmalloc(FW_BULKOUT_SIZE
+ 2, GFP_KERNEL
);
724 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
, buf
,
725 FW_BULKOUT_SIZE
+ 2);
729 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply
);
733 packets
= fw
->size
/ FW_BULKOUT_SIZE
;
734 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
735 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
736 for (i
= 0; i
< packets
; i
++) {
737 memcpy(&buf
[2], fw
->data
+ i
* FW_BULKOUT_SIZE
,
740 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
741 ret
= usb_bulk_msg(udev
,
742 usb_sndbulkpipe(udev
, 0x02),
743 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 1000);
745 err("firmware download failed at packet %d with code %d", i
, ret
);
749 ret
= af9005_boot_packet(udev
, FW_CONFIRM
, &reply
,
750 buf
, FW_BULKOUT_SIZE
+ 2);
753 if (reply
!= (u8
) (packets
& 0xff)) {
754 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets
& 0xff, reply
);
758 ret
= af9005_boot_packet(udev
, FW_BOOT
, &reply
, buf
,
759 FW_BULKOUT_SIZE
+ 2);
762 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
, buf
,
763 FW_BULKOUT_SIZE
+ 2);
767 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply
);
778 int af9005_led_control(struct dvb_usb_device
*d
, int onoff
)
780 struct af9005_device_state
*st
= d
->priv
;
783 if (onoff
&& dvb_usb_af9005_led
)
787 if (st
->led_state
!= temp
) {
789 af9005_write_register_bits(d
, xd_p_reg_top_locken1
,
791 reg_top_locken1_len
, temp
);
795 af9005_write_register_bits(d
, xd_p_reg_top_lock1
,
797 reg_top_lock1_len
, temp
);
800 st
->led_state
= temp
;
805 static int af9005_frontend_attach(struct dvb_usb_adapter
*adap
)
810 /* without these calls the first commands after downloading
811 the firmware fail. I put these calls here to simulate
812 what it is done in dvb-usb-init.c.
814 struct usb_device
*udev
= adap
->dev
->udev
;
815 usb_clear_halt(udev
, usb_sndbulkpipe(udev
, 2));
816 usb_clear_halt(udev
, usb_rcvbulkpipe(udev
, 1));
817 if (dvb_usb_af9005_dump_eeprom
) {
818 printk("EEPROM DUMP\n");
819 for (i
= 0; i
< 255; i
+= 8) {
820 af9005_read_eeprom(adap
->dev
, i
, buf
, 8);
821 debug_dump(buf
, 8, printk
);
824 adap
->fe_adap
[0].fe
= af9005_fe_attach(adap
->dev
);
828 static int af9005_rc_query(struct dvb_usb_device
*d
, u32
* event
, int *state
)
830 struct af9005_device_state
*st
= d
->priv
;
834 *state
= REMOTE_NO_KEY_PRESSED
;
835 if (rc_decode
== NULL
) {
836 /* it shouldn't never come here */
840 mutex_lock(&d
->data_mutex
);
842 /* deb_info("rc_query\n"); */
843 st
->data
[0] = 3; /* rest of packet length low */
844 st
->data
[1] = 0; /* rest of packet length high */
845 st
->data
[2] = 0x40; /* read remote */
846 st
->data
[3] = 1; /* rest of packet length */
847 st
->data
[4] = seq
= st
->sequence
++; /* sequence number */
848 ret
= dvb_usb_generic_rw(d
, st
->data
, 5, st
->data
, 256, 0);
850 err("rc query failed");
853 if (st
->data
[2] != 0x41) {
854 err("rc query bad header.");
857 } else if (st
->data
[4] != seq
) {
858 err("rc query bad sequence.");
864 err("rc query invalid length");
869 deb_rc("rc data (%d) ", len
);
870 debug_dump((st
->data
+ 6), len
, deb_rc
);
871 ret
= rc_decode(d
, &st
->data
[6], len
, event
, state
);
873 err("rc_decode failed");
876 deb_rc("rc_decode state %x event %x\n", *state
, *event
);
877 if (*state
== REMOTE_KEY_REPEAT
)
878 *event
= d
->last_event
;
883 mutex_unlock(&d
->data_mutex
);
887 static int af9005_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
893 static int af9005_pid_filter_control(struct dvb_usb_adapter
*adap
, int onoff
)
896 deb_info("pid filter control onoff %d\n", onoff
);
899 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
903 af9005_write_register_bits(adap
->dev
,
904 XD_MP2IF_DMX_CTRL
, 1, 1, 1);
908 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
911 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 0);
914 deb_info("pid filter control ok\n");
918 static int af9005_pid_filter(struct dvb_usb_adapter
*adap
, int index
,
921 u8 cmd
= index
& 0x1f;
923 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index
,
926 /* cannot use it as pid_filter_ctrl since it has to be done
927 before setting the first pid */
928 if (adap
->feedcount
== 1) {
929 deb_info("first pid set, enable pid table\n");
930 ret
= af9005_pid_filter_control(adap
, onoff
);
935 af9005_write_ofdm_register(adap
->dev
,
941 af9005_write_ofdm_register(adap
->dev
,
948 if (adap
->feedcount
== 0) {
949 deb_info("last pid unset, disable pid table\n");
950 ret
= af9005_pid_filter_control(adap
, onoff
);
955 ret
= af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_PID_IDX
, cmd
);
958 deb_info("set pid ok\n");
962 static int af9005_identify_state(struct usb_device
*udev
,
963 const struct dvb_usb_device_properties
*props
,
964 const struct dvb_usb_device_description
**desc
,
970 buf
= kmalloc(FW_BULKOUT_SIZE
+ 2, GFP_KERNEL
);
974 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
,
975 buf
, FW_BULKOUT_SIZE
+ 2);
978 deb_info("result of FW_CONFIG in identify state %d\n", reply
);
981 else if (reply
== 0x02)
986 deb_info("Identify state cold = %d\n", *cold
);
993 static struct dvb_usb_device_properties af9005_properties
;
995 static int af9005_usb_probe(struct usb_interface
*intf
,
996 const struct usb_device_id
*id
)
998 return dvb_usb_device_init(intf
, &af9005_properties
,
999 THIS_MODULE
, NULL
, adapter_nr
);
1004 TERRATEC_CINERGY_T_USB_XE
,
1008 static struct usb_device_id af9005_usb_table
[] = {
1009 DVB_USB_DEV(AFATECH
, AFATECH_AF9005
),
1010 DVB_USB_DEV(TERRATEC
, TERRATEC_CINERGY_T_USB_XE
),
1011 DVB_USB_DEV(ANSONIC
, ANSONIC_DVBT_USB
),
1015 MODULE_DEVICE_TABLE(usb
, af9005_usb_table
);
1017 static struct dvb_usb_device_properties af9005_properties
= {
1018 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
1020 .usb_ctrl
= DEVICE_SPECIFIC
,
1021 .firmware
= "af9005.fw",
1022 .download_firmware
= af9005_download_firmware
,
1025 .size_of_priv
= sizeof(struct af9005_device_state
),
1033 DVB_USB_ADAP_HAS_PID_FILTER
|
1034 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1035 .pid_filter_count
= 32,
1036 .pid_filter
= af9005_pid_filter
,
1037 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1038 .frontend_attach
= af9005_frontend_attach
,
1039 /* .tuner_attach = af9005_tuner_attach, */
1040 /* parameter for the MPEG2-data transfer */
1047 .buffersize
= 4096, /* actual size seen is 3948 */
1054 .power_ctrl
= af9005_power_ctrl
,
1055 .identify_state
= af9005_identify_state
,
1057 .i2c_algo
= &af9005_i2c_algo
,
1061 .rc_map_table
= NULL
,
1063 .rc_query
= af9005_rc_query
,
1066 .generic_bulk_ctrl_endpoint
= 2,
1067 .generic_bulk_ctrl_endpoint_response
= 1,
1069 .num_device_descs
= 3,
1071 {.name
= "Afatech DVB-T USB1.1 stick",
1072 .cold_ids
= {&af9005_usb_table
[AFATECH_AF9005
], NULL
},
1075 {.name
= "TerraTec Cinergy T USB XE",
1076 .cold_ids
= {&af9005_usb_table
[TERRATEC_CINERGY_T_USB_XE
], NULL
},
1079 {.name
= "Ansonic DVB-T USB1.1 stick",
1080 .cold_ids
= {&af9005_usb_table
[ANSONIC_DVBT_USB
], NULL
},
1087 /* usb specific object needed to register this driver with the usb subsystem */
1088 static struct usb_driver af9005_usb_driver
= {
1089 .name
= "dvb_usb_af9005",
1090 .probe
= af9005_usb_probe
,
1091 .disconnect
= dvb_usb_device_exit
,
1092 .id_table
= af9005_usb_table
,
1096 static int __init
af9005_usb_module_init(void)
1099 if ((result
= usb_register(&af9005_usb_driver
))) {
1100 err("usb_register failed. (%d)", result
);
1103 #if IS_MODULE(CONFIG_DVB_USB_AF9005) || defined(CONFIG_DVB_USB_AF9005_REMOTE)
1104 /* FIXME: convert to todays kernel IR infrastructure */
1105 rc_decode
= symbol_request(af9005_rc_decode
);
1106 rc_keys
= symbol_request(rc_map_af9005_table
);
1107 rc_keys_size
= symbol_request(rc_map_af9005_table_size
);
1109 if (rc_decode
== NULL
|| rc_keys
== NULL
|| rc_keys_size
== NULL
) {
1110 err("af9005_rc_decode function not found, disabling remote");
1111 af9005_properties
.rc
.legacy
.rc_query
= NULL
;
1113 af9005_properties
.rc
.legacy
.rc_map_table
= rc_keys
;
1114 af9005_properties
.rc
.legacy
.rc_map_size
= *rc_keys_size
;
1120 static void __exit
af9005_usb_module_exit(void)
1122 /* release rc decode symbols */
1123 if (rc_decode
!= NULL
)
1124 symbol_put(af9005_rc_decode
);
1125 if (rc_keys
!= NULL
)
1126 symbol_put(rc_map_af9005_table
);
1127 if (rc_keys_size
!= NULL
)
1128 symbol_put(rc_map_af9005_table_size
);
1129 /* deregister this driver from the USB subsystem */
1130 usb_deregister(&af9005_usb_driver
);
1133 module_init(af9005_usb_module_init
);
1134 module_exit(af9005_usb_module_exit
);
1136 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1137 MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1138 MODULE_VERSION("1.0");
1139 MODULE_LICENSE("GPL");