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/media/dvb-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 /* write one or more registers */
428 value
= &msg
[0].buf
[1];
429 ret
= af9005_i2c_write(d
, addr
, reg
, value
, msg
[0].len
- 1);
434 mutex_unlock(&d
->i2c_mutex
);
438 static u32
af9005_i2c_func(struct i2c_adapter
*adapter
)
443 static struct i2c_algorithm af9005_i2c_algo
= {
444 .master_xfer
= af9005_i2c_xfer
,
445 .functionality
= af9005_i2c_func
,
448 int af9005_send_command(struct dvb_usb_device
*d
, u8 command
, u8
* wbuf
,
449 int wlen
, u8
* rbuf
, int rlen
)
451 struct af9005_device_state
*st
= d
->priv
;
453 int ret
, i
, packet_len
;
457 err("send command, wlen less than 0 bytes. Makes no sense.");
461 err("send command, wlen more than 54 bytes. Not supported.");
465 err("send command, rlen more than 54 bytes. Not supported.");
468 packet_len
= wlen
+ 5;
470 mutex_lock(&d
->data_mutex
);
472 st
->data
[0] = (u8
) (packet_len
& 0xff);
473 st
->data
[1] = (u8
) ((packet_len
& 0xff00) >> 8);
475 st
->data
[2] = 0x26; /* packet type */
476 st
->data
[3] = wlen
+ 3;
477 st
->data
[4] = seq
= st
->sequence
++;
478 st
->data
[5] = command
;
480 for (i
= 0; i
< wlen
; i
++)
481 st
->data
[7 + i
] = wbuf
[i
];
482 ret
= dvb_usb_generic_rw(d
, st
->data
, wlen
+ 7, st
->data
, rlen
+ 7, 0);
483 if (st
->data
[2] != 0x27) {
484 err("send command, wrong reply code.");
486 } else if (st
->data
[4] != seq
) {
487 err("send command, wrong sequence in reply.");
489 } else if (st
->data
[5] != 0x01) {
490 err("send command, wrong status code in reply.");
492 } else if (st
->data
[6] != rlen
) {
493 err("send command, invalid data length in reply.");
497 for (i
= 0; i
< rlen
; i
++)
498 rbuf
[i
] = st
->data
[i
+ 7];
501 mutex_unlock(&d
->data_mutex
);
505 int af9005_read_eeprom(struct dvb_usb_device
*d
, u8 address
, u8
* values
,
508 struct af9005_device_state
*st
= d
->priv
;
512 mutex_lock(&d
->data_mutex
);
514 memset(st
->data
, 0, sizeof(st
->data
));
516 st
->data
[0] = 14; /* length of rest of packet low */
517 st
->data
[1] = 0; /* length of rest of packer high */
519 st
->data
[2] = 0x2a; /* read/write eeprom */
521 st
->data
[3] = 12; /* size */
523 st
->data
[4] = seq
= st
->sequence
++;
525 st
->data
[5] = 0; /* read */
528 st
->data
[7] = address
;
529 ret
= dvb_usb_generic_rw(d
, st
->data
, 16, st
->data
, 14, 0);
530 if (st
->data
[2] != 0x2b) {
531 err("Read eeprom, invalid reply code");
533 } else if (st
->data
[3] != 10) {
534 err("Read eeprom, invalid reply length");
536 } else if (st
->data
[4] != seq
) {
537 err("Read eeprom, wrong sequence in reply ");
539 } else if (st
->data
[5] != 1) {
540 err("Read eeprom, wrong status in reply ");
545 for (i
= 0; i
< len
; i
++)
546 values
[i
] = st
->data
[6 + i
];
548 mutex_unlock(&d
->data_mutex
);
553 static int af9005_boot_packet(struct usb_device
*udev
, int type
, u8
*reply
,
557 int act_len
= 0, i
, ret
;
559 memset(buf
, 0, size
);
560 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
561 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
566 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
568 checksum
= buf
[4] + buf
[5];
569 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
570 buf
[7] = (u8
) (checksum
& 0xff);
575 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
577 checksum
= buf
[4] + buf
[5];
578 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
579 buf
[7] = (u8
) (checksum
& 0xff);
584 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
591 for (i
= 4; i
<= 9; i
++)
593 buf
[10] = (u8
) ((checksum
>> 8) & 0xff);
594 buf
[11] = (u8
) (checksum
& 0xff);
597 err("boot packet invalid boot packet type");
601 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
603 ret
= usb_bulk_msg(udev
,
604 usb_sndbulkpipe(udev
, 0x02),
605 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 2000);
607 err("boot packet bulk message failed: %d (%d/%d)", ret
,
608 FW_BULKOUT_SIZE
+ 2, act_len
);
610 ret
= act_len
!= FW_BULKOUT_SIZE
+ 2 ? -1 : 0;
614 ret
= usb_bulk_msg(udev
,
615 usb_rcvbulkpipe(udev
, 0x01), buf
, 9, &act_len
, 2000);
617 err("boot packet recv bulk message failed: %d", ret
);
621 debug_dump(buf
, act_len
, deb_fw
);
625 if (buf
[2] != 0x11) {
626 err("boot bad config header.");
629 if (buf
[3] != 0x05) {
630 err("boot bad config size.");
633 if (buf
[4] != 0x00) {
634 err("boot bad config sequence.");
637 if (buf
[5] != 0x04) {
638 err("boot bad config subtype.");
641 for (i
= 4; i
<= 6; i
++)
643 if (buf
[7] * 256 + buf
[8] != checksum
) {
644 err("boot bad config checksum.");
650 if (buf
[2] != 0x11) {
651 err("boot bad confirm header.");
654 if (buf
[3] != 0x05) {
655 err("boot bad confirm size.");
658 if (buf
[4] != 0x00) {
659 err("boot bad confirm sequence.");
662 if (buf
[5] != 0x02) {
663 err("boot bad confirm subtype.");
666 for (i
= 4; i
<= 6; i
++)
668 if (buf
[7] * 256 + buf
[8] != checksum
) {
669 err("boot bad confirm checksum.");
675 if (buf
[2] != 0x10) {
676 err("boot bad boot header.");
679 if (buf
[3] != 0x05) {
680 err("boot bad boot size.");
683 if (buf
[4] != 0x00) {
684 err("boot bad boot sequence.");
687 if (buf
[5] != 0x01) {
688 err("boot bad boot pattern 01.");
691 if (buf
[6] != 0x10) {
692 err("boot bad boot pattern 10.");
695 for (i
= 4; i
<= 6; i
++)
697 if (buf
[7] * 256 + buf
[8] != checksum
) {
698 err("boot bad boot checksum.");
708 static int af9005_download_firmware(struct usb_device
*udev
, const struct firmware
*fw
)
710 int i
, packets
, ret
, act_len
;
715 buf
= kmalloc(FW_BULKOUT_SIZE
+ 2, GFP_KERNEL
);
719 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
, buf
,
720 FW_BULKOUT_SIZE
+ 2);
724 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply
);
728 packets
= fw
->size
/ FW_BULKOUT_SIZE
;
729 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
730 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
731 for (i
= 0; i
< packets
; i
++) {
732 memcpy(&buf
[2], fw
->data
+ i
* FW_BULKOUT_SIZE
,
735 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
736 ret
= usb_bulk_msg(udev
,
737 usb_sndbulkpipe(udev
, 0x02),
738 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 1000);
740 err("firmware download failed at packet %d with code %d", i
, ret
);
744 ret
= af9005_boot_packet(udev
, FW_CONFIRM
, &reply
,
745 buf
, FW_BULKOUT_SIZE
+ 2);
748 if (reply
!= (u8
) (packets
& 0xff)) {
749 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets
& 0xff, reply
);
753 ret
= af9005_boot_packet(udev
, FW_BOOT
, &reply
, buf
,
754 FW_BULKOUT_SIZE
+ 2);
757 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
, buf
,
758 FW_BULKOUT_SIZE
+ 2);
762 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply
);
773 int af9005_led_control(struct dvb_usb_device
*d
, int onoff
)
775 struct af9005_device_state
*st
= d
->priv
;
778 if (onoff
&& dvb_usb_af9005_led
)
782 if (st
->led_state
!= temp
) {
784 af9005_write_register_bits(d
, xd_p_reg_top_locken1
,
786 reg_top_locken1_len
, temp
);
790 af9005_write_register_bits(d
, xd_p_reg_top_lock1
,
792 reg_top_lock1_len
, temp
);
795 st
->led_state
= temp
;
800 static int af9005_frontend_attach(struct dvb_usb_adapter
*adap
)
805 /* without these calls the first commands after downloading
806 the firmware fail. I put these calls here to simulate
807 what it is done in dvb-usb-init.c.
809 struct usb_device
*udev
= adap
->dev
->udev
;
810 usb_clear_halt(udev
, usb_sndbulkpipe(udev
, 2));
811 usb_clear_halt(udev
, usb_rcvbulkpipe(udev
, 1));
812 if (dvb_usb_af9005_dump_eeprom
) {
813 printk("EEPROM DUMP\n");
814 for (i
= 0; i
< 255; i
+= 8) {
815 af9005_read_eeprom(adap
->dev
, i
, buf
, 8);
816 debug_dump(buf
, 8, printk
);
819 adap
->fe_adap
[0].fe
= af9005_fe_attach(adap
->dev
);
823 static int af9005_rc_query(struct dvb_usb_device
*d
, u32
* event
, int *state
)
825 struct af9005_device_state
*st
= d
->priv
;
829 *state
= REMOTE_NO_KEY_PRESSED
;
830 if (rc_decode
== NULL
) {
831 /* it shouldn't never come here */
835 mutex_lock(&d
->data_mutex
);
837 /* deb_info("rc_query\n"); */
838 st
->data
[0] = 3; /* rest of packet length low */
839 st
->data
[1] = 0; /* rest of packet length high */
840 st
->data
[2] = 0x40; /* read remote */
841 st
->data
[3] = 1; /* rest of packet length */
842 st
->data
[4] = seq
= st
->sequence
++; /* sequence number */
843 ret
= dvb_usb_generic_rw(d
, st
->data
, 5, st
->data
, 256, 0);
845 err("rc query failed");
848 if (st
->data
[2] != 0x41) {
849 err("rc query bad header.");
852 } else if (st
->data
[4] != seq
) {
853 err("rc query bad sequence.");
859 err("rc query invalid length");
864 deb_rc("rc data (%d) ", len
);
865 debug_dump((st
->data
+ 6), len
, deb_rc
);
866 ret
= rc_decode(d
, &st
->data
[6], len
, event
, state
);
868 err("rc_decode failed");
871 deb_rc("rc_decode state %x event %x\n", *state
, *event
);
872 if (*state
== REMOTE_KEY_REPEAT
)
873 *event
= d
->last_event
;
878 mutex_unlock(&d
->data_mutex
);
882 static int af9005_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
888 static int af9005_pid_filter_control(struct dvb_usb_adapter
*adap
, int onoff
)
891 deb_info("pid filter control onoff %d\n", onoff
);
894 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
898 af9005_write_register_bits(adap
->dev
,
899 XD_MP2IF_DMX_CTRL
, 1, 1, 1);
903 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
906 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 0);
909 deb_info("pid filter control ok\n");
913 static int af9005_pid_filter(struct dvb_usb_adapter
*adap
, int index
,
916 u8 cmd
= index
& 0x1f;
918 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index
,
921 /* cannot use it as pid_filter_ctrl since it has to be done
922 before setting the first pid */
923 if (adap
->feedcount
== 1) {
924 deb_info("first pid set, enable pid table\n");
925 ret
= af9005_pid_filter_control(adap
, onoff
);
930 af9005_write_ofdm_register(adap
->dev
,
936 af9005_write_ofdm_register(adap
->dev
,
943 if (adap
->feedcount
== 0) {
944 deb_info("last pid unset, disable pid table\n");
945 ret
= af9005_pid_filter_control(adap
, onoff
);
950 ret
= af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_PID_IDX
, cmd
);
953 deb_info("set pid ok\n");
957 static int af9005_identify_state(struct usb_device
*udev
,
958 struct dvb_usb_device_properties
*props
,
959 struct dvb_usb_device_description
**desc
,
965 buf
= kmalloc(FW_BULKOUT_SIZE
+ 2, GFP_KERNEL
);
969 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
,
970 buf
, FW_BULKOUT_SIZE
+ 2);
973 deb_info("result of FW_CONFIG in identify state %d\n", reply
);
976 else if (reply
== 0x02)
981 deb_info("Identify state cold = %d\n", *cold
);
988 static struct dvb_usb_device_properties af9005_properties
;
990 static int af9005_usb_probe(struct usb_interface
*intf
,
991 const struct usb_device_id
*id
)
993 return dvb_usb_device_init(intf
, &af9005_properties
,
994 THIS_MODULE
, NULL
, adapter_nr
);
997 enum af9005_usb_table_entry
{
1003 static struct usb_device_id af9005_usb_table
[] = {
1004 [AFATECH_AF9005
] = {USB_DEVICE(USB_VID_AFATECH
,
1005 USB_PID_AFATECH_AF9005
)},
1006 [TERRATEC_AF9005
] = {USB_DEVICE(USB_VID_TERRATEC
,
1007 USB_PID_TERRATEC_CINERGY_T_USB_XE
)},
1008 [ANSONIC_AF9005
] = {USB_DEVICE(USB_VID_ANSONIC
,
1009 USB_PID_ANSONIC_DVBT_USB
)},
1013 MODULE_DEVICE_TABLE(usb
, af9005_usb_table
);
1015 static struct dvb_usb_device_properties af9005_properties
= {
1016 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
1018 .usb_ctrl
= DEVICE_SPECIFIC
,
1019 .firmware
= "af9005.fw",
1020 .download_firmware
= af9005_download_firmware
,
1023 .size_of_priv
= sizeof(struct af9005_device_state
),
1031 DVB_USB_ADAP_HAS_PID_FILTER
|
1032 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1033 .pid_filter_count
= 32,
1034 .pid_filter
= af9005_pid_filter
,
1035 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1036 .frontend_attach
= af9005_frontend_attach
,
1037 /* .tuner_attach = af9005_tuner_attach, */
1038 /* parameter for the MPEG2-data transfer */
1045 .buffersize
= 4096, /* actual size seen is 3948 */
1052 .power_ctrl
= af9005_power_ctrl
,
1053 .identify_state
= af9005_identify_state
,
1055 .i2c_algo
= &af9005_i2c_algo
,
1059 .rc_map_table
= NULL
,
1061 .rc_query
= af9005_rc_query
,
1064 .generic_bulk_ctrl_endpoint
= 2,
1065 .generic_bulk_ctrl_endpoint_response
= 1,
1067 .num_device_descs
= 3,
1069 {.name
= "Afatech DVB-T USB1.1 stick",
1070 .cold_ids
= {&af9005_usb_table
[AFATECH_AF9005
], NULL
},
1073 {.name
= "TerraTec Cinergy T USB XE",
1074 .cold_ids
= {&af9005_usb_table
[TERRATEC_AF9005
], NULL
},
1077 {.name
= "Ansonic DVB-T USB1.1 stick",
1078 .cold_ids
= {&af9005_usb_table
[ANSONIC_AF9005
], NULL
},
1085 /* usb specific object needed to register this driver with the usb subsystem */
1086 static struct usb_driver af9005_usb_driver
= {
1087 .name
= "dvb_usb_af9005",
1088 .probe
= af9005_usb_probe
,
1089 .disconnect
= dvb_usb_device_exit
,
1090 .id_table
= af9005_usb_table
,
1094 static int __init
af9005_usb_module_init(void)
1097 if ((result
= usb_register(&af9005_usb_driver
))) {
1098 err("usb_register failed. (%d)", result
);
1101 #if IS_MODULE(CONFIG_DVB_USB_AF9005) || defined(CONFIG_DVB_USB_AF9005_REMOTE)
1102 /* FIXME: convert to todays kernel IR infrastructure */
1103 rc_decode
= symbol_request(af9005_rc_decode
);
1104 rc_keys
= symbol_request(rc_map_af9005_table
);
1105 rc_keys_size
= symbol_request(rc_map_af9005_table_size
);
1107 if (rc_decode
== NULL
|| rc_keys
== NULL
|| rc_keys_size
== NULL
) {
1108 err("af9005_rc_decode function not found, disabling remote");
1109 af9005_properties
.rc
.legacy
.rc_query
= NULL
;
1111 af9005_properties
.rc
.legacy
.rc_map_table
= rc_keys
;
1112 af9005_properties
.rc
.legacy
.rc_map_size
= *rc_keys_size
;
1118 static void __exit
af9005_usb_module_exit(void)
1120 /* release rc decode symbols */
1121 if (rc_decode
!= NULL
)
1122 symbol_put(af9005_rc_decode
);
1123 if (rc_keys
!= NULL
)
1124 symbol_put(rc_map_af9005_table
);
1125 if (rc_keys_size
!= NULL
)
1126 symbol_put(rc_map_af9005_table_size
);
1127 /* deregister this driver from the USB subsystem */
1128 usb_deregister(&af9005_usb_driver
);
1131 module_init(af9005_usb_module_init
);
1132 module_exit(af9005_usb_module_exit
);
1134 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1135 MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1136 MODULE_VERSION("1.0");
1137 MODULE_LICENSE("GPL");