1 /* DVB USB compliant Linux driver for the Afatech 9005
2 * USB1.1 DVB-T receiver.
4 * Copyright (C) 2007 Luca Olivetti (luca@ventoso.org)
6 * Thanks to Afatech who kindly provided information.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * see Documentation/dvb/REDME.dvb-usb for more information
27 int dvb_usb_af9005_debug
;
28 module_param_named(debug
, dvb_usb_af9005_debug
, int, 0644);
29 MODULE_PARM_DESC(debug
,
30 "set debugging level (1=info,xfer=2,rc=4,reg=8,i2c=16,fw=32 (or-able))."
31 DVB_USB_DEBUG_STATUS
);
32 /* enable obnoxious led */
33 int dvb_usb_af9005_led
= 1;
34 module_param_named(led
, dvb_usb_af9005_led
, bool, 0644);
35 MODULE_PARM_DESC(led
, "enable led (default: 1).");
38 static int dvb_usb_af9005_dump_eeprom
;
39 module_param_named(dump_eeprom
, dvb_usb_af9005_dump_eeprom
, int, 0);
40 MODULE_PARM_DESC(dump_eeprom
, "dump contents of the eeprom.");
42 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
44 /* remote control decoder */
45 static int (*rc_decode
) (struct dvb_usb_device
*d
, u8
*data
, int len
,
46 u32
*event
, int *state
);
48 static int *rc_keys_size
;
50 u8 regmask
[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
52 struct af9005_device_state
{
57 static int af9005_generic_read_write(struct dvb_usb_device
*d
, u16 reg
,
58 int readwrite
, int type
, u8
* values
, int len
)
60 struct af9005_device_state
*st
= d
->priv
;
68 err("generic read/write, less than 1 byte. Makes no sense.");
72 err("generic read/write, more than 8 bytes. Not supported.");
76 obuf
[0] = 14; /* rest of buffer length low */
77 obuf
[1] = 0; /* rest of buffer length high */
79 obuf
[2] = AF9005_REGISTER_RW
; /* register operation */
80 obuf
[3] = 12; /* rest of buffer length */
82 obuf
[4] = st
->sequence
++; /* sequence number */
84 obuf
[5] = (u8
) (reg
>> 8); /* register address */
85 obuf
[6] = (u8
) (reg
& 0xff);
87 if (type
== AF9005_OFDM_REG
) {
88 command
= AF9005_CMD_OFDM_REG
;
90 command
= AF9005_CMD_TUNER
;
95 AF9005_CMD_BURST
| AF9005_CMD_AUTOINC
| (len
- 1) << 3;
97 if (readwrite
== AF9005_CMD_WRITE
)
98 for (i
= 0; i
< len
; i
++)
99 obuf
[8 + i
] = values
[i
];
100 else if (type
== AF9005_TUNER_REG
)
101 /* read command for tuner, the first byte contains the i2c address */
105 ret
= dvb_usb_generic_rw(d
, obuf
, 16, ibuf
, 17, 0);
110 if (ibuf
[2] != AF9005_REGISTER_RW_ACK
) {
111 err("generic read/write, wrong reply code.");
114 if (ibuf
[3] != 0x0d) {
115 err("generic read/write, wrong length in reply.");
118 if (ibuf
[4] != obuf
[4]) {
119 err("generic read/write, wrong sequence in reply.");
123 Windows driver doesn't check these fields, in fact sometimes
124 the register in the reply is different that what has been sent
126 if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) {
127 err("generic read/write, wrong register in reply.");
130 if (ibuf[7] != command) {
131 err("generic read/write wrong command in reply.");
135 if (ibuf
[16] != 0x01) {
136 err("generic read/write wrong status code in reply.");
139 if (readwrite
== AF9005_CMD_READ
)
140 for (i
= 0; i
< len
; i
++)
141 values
[i
] = ibuf
[8 + i
];
147 int af9005_read_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8
* value
)
150 deb_reg("read register %x ", reg
);
151 ret
= af9005_generic_read_write(d
, reg
,
152 AF9005_CMD_READ
, AF9005_OFDM_REG
,
157 deb_reg("value %x\n", *value
);
161 int af9005_read_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
162 u8
* values
, int len
)
165 deb_reg("read %d registers %x ", len
, reg
);
166 ret
= af9005_generic_read_write(d
, reg
,
167 AF9005_CMD_READ
, AF9005_OFDM_REG
,
172 debug_dump(values
, len
, deb_reg
);
176 int af9005_write_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8 value
)
180 deb_reg("write register %x value %x ", reg
, value
);
181 ret
= af9005_generic_read_write(d
, reg
,
182 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
191 int af9005_write_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
192 u8
* values
, int len
)
195 deb_reg("write %d registers %x values ", len
, reg
);
196 debug_dump(values
, len
, deb_reg
);
198 ret
= af9005_generic_read_write(d
, reg
,
199 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
208 int af9005_read_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
213 deb_reg("read bits %x %x %x", reg
, pos
, len
);
214 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
216 deb_reg(" failed\n");
219 *value
= (temp
>> pos
) & regmask
[len
- 1];
220 deb_reg(" value %x\n", *value
);
225 int af9005_write_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
230 deb_reg("write bits %x %x %x value %x\n", reg
, pos
, len
, value
);
231 if (pos
== 0 && len
== 8)
232 return af9005_write_ofdm_register(d
, reg
, value
);
233 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
236 mask
= regmask
[len
- 1] << pos
;
237 temp
= (temp
& ~mask
) | ((value
<< pos
) & mask
);
238 return af9005_write_ofdm_register(d
, reg
, temp
);
242 static int af9005_usb_read_tuner_registers(struct dvb_usb_device
*d
,
243 u16 reg
, u8
* values
, int len
)
245 return af9005_generic_read_write(d
, reg
,
246 AF9005_CMD_READ
, AF9005_TUNER_REG
,
250 static int af9005_usb_write_tuner_registers(struct dvb_usb_device
*d
,
251 u16 reg
, u8
* values
, int len
)
253 return af9005_generic_read_write(d
, reg
,
255 AF9005_TUNER_REG
, values
, len
);
258 int af9005_write_tuner_registers(struct dvb_usb_device
*d
, u16 reg
,
259 u8
* values
, int len
)
261 /* don't let the name of this function mislead you: it's just used
262 as an interface from the firmware to the i2c bus. The actual
263 i2c addresses are contained in the data */
264 int ret
, i
, done
= 0, fail
= 0;
266 ret
= af9005_usb_write_tuner_registers(d
, reg
, values
, len
);
270 /* check if write done (0xa40d bit 1) or fail (0xa40d bit 2) */
271 for (i
= 0; i
< 200; i
++) {
273 af9005_read_ofdm_register(d
,
274 xd_I2C_i2c_m_status_wdat_done
,
278 done
= temp
& (regmask
[i2c_m_status_wdat_done_len
- 1]
279 << i2c_m_status_wdat_done_pos
);
282 fail
= temp
& (regmask
[i2c_m_status_wdat_fail_len
- 1]
283 << i2c_m_status_wdat_fail_pos
);
291 /* clear write fail bit */
292 af9005_write_register_bits(d
,
293 xd_I2C_i2c_m_status_wdat_fail
,
294 i2c_m_status_wdat_fail_pos
,
295 i2c_m_status_wdat_fail_len
,
299 /* clear write done bit */
301 af9005_write_register_bits(d
,
302 xd_I2C_i2c_m_status_wdat_fail
,
303 i2c_m_status_wdat_done_pos
,
304 i2c_m_status_wdat_done_len
, 1);
311 int af9005_read_tuner_registers(struct dvb_usb_device
*d
, u16 reg
, u8 addr
,
312 u8
* values
, int len
)
314 /* don't let the name of this function mislead you: it's just used
315 as an interface from the firmware to the i2c bus. The actual
316 i2c addresses are contained in the data */
320 buf
[0] = addr
; /* tuner i2c address */
321 buf
[1] = values
[0]; /* tuner register */
323 values
[0] = addr
+ 0x01; /* i2c read address */
325 if (reg
== APO_REG_I2C_RW_SILICON_TUNER
) {
326 /* write tuner i2c address to tuner, 0c00c0 undocumented, found by sniffing */
327 ret
= af9005_write_tuner_registers(d
, 0x00c0, buf
, 2);
332 /* send read command to ofsm */
333 ret
= af9005_usb_read_tuner_registers(d
, reg
, values
, 1);
337 /* check if read done */
338 for (i
= 0; i
< 200; i
++) {
339 ret
= af9005_read_ofdm_register(d
, 0xa408, &temp
);
349 /* clear read done bit (by writing 1) */
350 ret
= af9005_write_ofdm_register(d
, xd_I2C_i2c_m_data8
, 1);
354 /* get read data (available from 0xa400) */
355 for (i
= 0; i
< len
; i
++) {
356 ret
= af9005_read_ofdm_register(d
, 0xa400 + i
, &temp
);
364 static int af9005_i2c_write(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
369 deb_i2c("i2c_write i2caddr %x, reg %x, len %d data ", i2caddr
,
371 debug_dump(data
, len
, deb_i2c
);
373 for (i
= 0; i
< len
; i
++) {
375 buf
[1] = reg
+ (u8
) i
;
378 af9005_write_tuner_registers(d
,
379 APO_REG_I2C_RW_SILICON_TUNER
,
382 deb_i2c("i2c_write failed\n");
386 deb_i2c("i2c_write ok\n");
390 static int af9005_i2c_read(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
395 deb_i2c("i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr
, reg
, len
);
396 for (i
= 0; i
< len
; i
++) {
399 af9005_read_tuner_registers(d
,
400 APO_REG_I2C_RW_SILICON_TUNER
,
403 deb_i2c("i2c_read failed\n");
408 deb_i2c("i2c data read: ");
409 debug_dump(data
, len
, deb_i2c
);
413 static int af9005_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
416 /* only implements what the mt2060 module does, don't know how
417 to make it really generic */
418 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
423 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
427 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
430 /* reads a single register */
434 ret
= af9005_i2c_read(d
, addr
, reg
, value
, 1);
438 /* write one or more registers */
441 value
= &msg
[0].buf
[1];
442 ret
= af9005_i2c_write(d
, addr
, reg
, value
, msg
[0].len
- 1);
447 mutex_unlock(&d
->i2c_mutex
);
451 static u32
af9005_i2c_func(struct i2c_adapter
*adapter
)
456 static struct i2c_algorithm af9005_i2c_algo
= {
457 .master_xfer
= af9005_i2c_xfer
,
458 .functionality
= af9005_i2c_func
,
461 int af9005_send_command(struct dvb_usb_device
*d
, u8 command
, u8
* wbuf
,
462 int wlen
, u8
* rbuf
, int rlen
)
464 struct af9005_device_state
*st
= d
->priv
;
466 int ret
, i
, packet_len
;
471 err("send command, wlen less than 0 bytes. Makes no sense.");
475 err("send command, wlen more than 54 bytes. Not supported.");
479 err("send command, rlen more than 54 bytes. Not supported.");
482 packet_len
= wlen
+ 5;
483 buf
[0] = (u8
) (packet_len
& 0xff);
484 buf
[1] = (u8
) ((packet_len
& 0xff00) >> 8);
486 buf
[2] = 0x26; /* packet type */
488 buf
[4] = st
->sequence
++;
491 for (i
= 0; i
< wlen
; i
++)
492 buf
[7 + i
] = wbuf
[i
];
493 ret
= dvb_usb_generic_rw(d
, buf
, wlen
+ 7, ibuf
, rlen
+ 7, 0);
496 if (ibuf
[2] != 0x27) {
497 err("send command, wrong reply code.");
500 if (ibuf
[4] != buf
[4]) {
501 err("send command, wrong sequence in reply.");
504 if (ibuf
[5] != 0x01) {
505 err("send command, wrong status code in reply.");
508 if (ibuf
[6] != rlen
) {
509 err("send command, invalid data length in reply.");
512 for (i
= 0; i
< rlen
; i
++)
513 rbuf
[i
] = ibuf
[i
+ 7];
517 int af9005_read_eeprom(struct dvb_usb_device
*d
, u8 address
, u8
* values
,
520 struct af9005_device_state
*st
= d
->priv
;
521 u8 obuf
[16], ibuf
[14];
524 memset(obuf
, 0, sizeof(obuf
));
525 memset(ibuf
, 0, sizeof(ibuf
));
527 obuf
[0] = 14; /* length of rest of packet low */
528 obuf
[1] = 0; /* length of rest of packer high */
530 obuf
[2] = 0x2a; /* read/write eeprom */
532 obuf
[3] = 12; /* size */
534 obuf
[4] = st
->sequence
++;
536 obuf
[5] = 0; /* read */
540 ret
= dvb_usb_generic_rw(d
, obuf
, 16, ibuf
, 14, 0);
543 if (ibuf
[2] != 0x2b) {
544 err("Read eeprom, invalid reply code");
548 err("Read eeprom, invalid reply length");
551 if (ibuf
[4] != obuf
[4]) {
552 err("Read eeprom, wrong sequence in reply ");
556 err("Read eeprom, wrong status in reply ");
559 for (i
= 0; i
< len
; i
++) {
560 values
[i
] = ibuf
[6 + i
];
565 static int af9005_boot_packet(struct usb_device
*udev
, int type
, u8
* reply
)
567 u8 buf
[FW_BULKOUT_SIZE
+ 2];
570 memset(buf
, 0, sizeof(buf
));
571 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
572 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
577 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
579 checksum
= buf
[4] + buf
[5];
580 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
581 buf
[7] = (u8
) (checksum
& 0xff);
586 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
588 checksum
= buf
[4] + buf
[5];
589 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
590 buf
[7] = (u8
) (checksum
& 0xff);
595 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
602 for (i
= 4; i
<= 9; i
++)
604 buf
[10] = (u8
) ((checksum
>> 8) & 0xff);
605 buf
[11] = (u8
) (checksum
& 0xff);
608 err("boot packet invalid boot packet type");
612 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
614 ret
= usb_bulk_msg(udev
,
615 usb_sndbulkpipe(udev
, 0x02),
616 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 2000);
618 err("boot packet bulk message failed: %d (%d/%d)", ret
,
619 FW_BULKOUT_SIZE
+ 2, act_len
);
621 ret
= act_len
!= FW_BULKOUT_SIZE
+ 2 ? -1 : 0;
625 ret
= usb_bulk_msg(udev
,
626 usb_rcvbulkpipe(udev
, 0x01), buf
, 9, &act_len
, 2000);
628 err("boot packet recv bulk message failed: %d", ret
);
632 debug_dump(buf
, act_len
, deb_fw
);
636 if (buf
[2] != 0x11) {
637 err("boot bad config header.");
640 if (buf
[3] != 0x05) {
641 err("boot bad config size.");
644 if (buf
[4] != 0x00) {
645 err("boot bad config sequence.");
648 if (buf
[5] != 0x04) {
649 err("boot bad config subtype.");
652 for (i
= 4; i
<= 6; i
++)
654 if (buf
[7] * 256 + buf
[8] != checksum
) {
655 err("boot bad config checksum.");
661 if (buf
[2] != 0x11) {
662 err("boot bad confirm header.");
665 if (buf
[3] != 0x05) {
666 err("boot bad confirm size.");
669 if (buf
[4] != 0x00) {
670 err("boot bad confirm sequence.");
673 if (buf
[5] != 0x02) {
674 err("boot bad confirm subtype.");
677 for (i
= 4; i
<= 6; i
++)
679 if (buf
[7] * 256 + buf
[8] != checksum
) {
680 err("boot bad confirm checksum.");
686 if (buf
[2] != 0x10) {
687 err("boot bad boot header.");
690 if (buf
[3] != 0x05) {
691 err("boot bad boot size.");
694 if (buf
[4] != 0x00) {
695 err("boot bad boot sequence.");
698 if (buf
[5] != 0x01) {
699 err("boot bad boot pattern 01.");
702 if (buf
[6] != 0x10) {
703 err("boot bad boot pattern 10.");
706 for (i
= 4; i
<= 6; i
++)
708 if (buf
[7] * 256 + buf
[8] != checksum
) {
709 err("boot bad boot checksum.");
719 static int af9005_download_firmware(struct usb_device
*udev
, const struct firmware
*fw
)
721 int i
, packets
, ret
, act_len
;
723 u8 buf
[FW_BULKOUT_SIZE
+ 2];
726 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
);
730 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
);
752 if (reply
!= (u8
) (packets
& 0xff)) {
753 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets
& 0xff, reply
);
756 ret
= af9005_boot_packet(udev
, FW_BOOT
, &reply
);
759 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
);
763 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply
);
771 int af9005_led_control(struct dvb_usb_device
*d
, int onoff
)
773 struct af9005_device_state
*st
= d
->priv
;
776 if (onoff
&& dvb_usb_af9005_led
)
780 if (st
->led_state
!= temp
) {
782 af9005_write_register_bits(d
, xd_p_reg_top_locken1
,
784 reg_top_locken1_len
, temp
);
788 af9005_write_register_bits(d
, xd_p_reg_top_lock1
,
790 reg_top_lock1_len
, temp
);
793 st
->led_state
= temp
;
798 static int af9005_frontend_attach(struct dvb_usb_adapter
*adap
)
803 /* without these calls the first commands after downloading
804 the firmware fail. I put these calls here to simulate
805 what it is done in dvb-usb-init.c.
807 struct usb_device
*udev
= adap
->dev
->udev
;
808 usb_clear_halt(udev
, usb_sndbulkpipe(udev
, 2));
809 usb_clear_halt(udev
, usb_rcvbulkpipe(udev
, 1));
810 if (dvb_usb_af9005_dump_eeprom
) {
811 printk("EEPROM DUMP\n");
812 for (i
= 0; i
< 255; i
+= 8) {
813 af9005_read_eeprom(adap
->dev
, i
, buf
, 8);
814 printk("ADDR %x ", i
);
815 debug_dump(buf
, 8, printk
);
818 adap
->fe
= af9005_fe_attach(adap
->dev
);
822 static int af9005_rc_query(struct dvb_usb_device
*d
, u32
* event
, int *state
)
824 struct af9005_device_state
*st
= d
->priv
;
830 *state
= REMOTE_NO_KEY_PRESSED
;
831 if (rc_decode
== NULL
) {
832 /* it shouldn't never come here */
835 /* deb_info("rc_query\n"); */
836 obuf
[0] = 3; /* rest of packet length low */
837 obuf
[1] = 0; /* rest of packet lentgh high */
838 obuf
[2] = 0x40; /* read remote */
839 obuf
[3] = 1; /* rest of packet length */
840 obuf
[4] = st
->sequence
++; /* sequence number */
841 ret
= dvb_usb_generic_rw(d
, obuf
, 5, ibuf
, 256, 0);
843 err("rc query failed");
846 if (ibuf
[2] != 0x41) {
847 err("rc query bad header.");
850 if (ibuf
[4] != obuf
[4]) {
851 err("rc query bad sequence.");
856 err("rc query invalid length");
860 deb_rc("rc data (%d) ", len
);
861 debug_dump((ibuf
+ 6), len
, deb_rc
);
862 ret
= rc_decode(d
, &ibuf
[6], len
, event
, state
);
864 err("rc_decode failed");
867 deb_rc("rc_decode state %x event %x\n", *state
, *event
);
868 if (*state
== REMOTE_KEY_REPEAT
)
869 *event
= d
->last_event
;
875 static int af9005_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
881 static int af9005_pid_filter_control(struct dvb_usb_adapter
*adap
, int onoff
)
884 deb_info("pid filter control onoff %d\n", onoff
);
887 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
891 af9005_write_register_bits(adap
->dev
,
892 XD_MP2IF_DMX_CTRL
, 1, 1, 1);
896 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
899 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 0);
902 deb_info("pid filter control ok\n");
906 static int af9005_pid_filter(struct dvb_usb_adapter
*adap
, int index
,
909 u8 cmd
= index
& 0x1f;
911 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index
,
914 /* cannot use it as pid_filter_ctrl since it has to be done
915 before setting the first pid */
916 if (adap
->feedcount
== 1) {
917 deb_info("first pid set, enable pid table\n");
918 ret
= af9005_pid_filter_control(adap
, onoff
);
923 af9005_write_ofdm_register(adap
->dev
,
929 af9005_write_ofdm_register(adap
->dev
,
936 if (adap
->feedcount
== 0) {
937 deb_info("last pid unset, disable pid table\n");
938 ret
= af9005_pid_filter_control(adap
, onoff
);
943 ret
= af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_PID_IDX
, cmd
);
946 deb_info("set pid ok\n");
950 static int af9005_identify_state(struct usb_device
*udev
,
951 struct dvb_usb_device_properties
*props
,
952 struct dvb_usb_device_description
**desc
,
957 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
);
960 deb_info("result of FW_CONFIG in identify state %d\n", reply
);
963 else if (reply
== 0x02)
967 deb_info("Identify state cold = %d\n", *cold
);
971 static struct dvb_usb_device_properties af9005_properties
;
973 static int af9005_usb_probe(struct usb_interface
*intf
,
974 const struct usb_device_id
*id
)
976 return dvb_usb_device_init(intf
, &af9005_properties
,
977 THIS_MODULE
, NULL
, adapter_nr
);
980 static struct usb_device_id af9005_usb_table
[] = {
981 {USB_DEVICE(USB_VID_AFATECH
, USB_PID_AFATECH_AF9005
)},
982 {USB_DEVICE(USB_VID_TERRATEC
, USB_PID_TERRATEC_CINERGY_T_USB_XE
)},
983 {USB_DEVICE(USB_VID_ANSONIC
, USB_PID_ANSONIC_DVBT_USB
)},
987 MODULE_DEVICE_TABLE(usb
, af9005_usb_table
);
989 static struct dvb_usb_device_properties af9005_properties
= {
990 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
992 .usb_ctrl
= DEVICE_SPECIFIC
,
993 .firmware
= "af9005.fw",
994 .download_firmware
= af9005_download_firmware
,
997 .size_of_priv
= sizeof(struct af9005_device_state
),
1003 DVB_USB_ADAP_HAS_PID_FILTER
|
1004 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1005 .pid_filter_count
= 32,
1006 .pid_filter
= af9005_pid_filter
,
1007 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1008 .frontend_attach
= af9005_frontend_attach
,
1009 /* .tuner_attach = af9005_tuner_attach, */
1010 /* parameter for the MPEG2-data transfer */
1017 .buffersize
= 4096, /* actual size seen is 3948 */
1023 .power_ctrl
= af9005_power_ctrl
,
1024 .identify_state
= af9005_identify_state
,
1026 .i2c_algo
= &af9005_i2c_algo
,
1030 .rc_map_table
= NULL
,
1032 .rc_query
= af9005_rc_query
,
1035 .generic_bulk_ctrl_endpoint
= 2,
1036 .generic_bulk_ctrl_endpoint_response
= 1,
1038 .num_device_descs
= 3,
1040 {.name
= "Afatech DVB-T USB1.1 stick",
1041 .cold_ids
= {&af9005_usb_table
[0], NULL
},
1044 {.name
= "TerraTec Cinergy T USB XE",
1045 .cold_ids
= {&af9005_usb_table
[1], NULL
},
1048 {.name
= "Ansonic DVB-T USB1.1 stick",
1049 .cold_ids
= {&af9005_usb_table
[2], NULL
},
1056 /* usb specific object needed to register this driver with the usb subsystem */
1057 static struct usb_driver af9005_usb_driver
= {
1058 .name
= "dvb_usb_af9005",
1059 .probe
= af9005_usb_probe
,
1060 .disconnect
= dvb_usb_device_exit
,
1061 .id_table
= af9005_usb_table
,
1065 static int __init
af9005_usb_module_init(void)
1068 if ((result
= usb_register(&af9005_usb_driver
))) {
1069 err("usb_register failed. (%d)", result
);
1072 rc_decode
= symbol_request(af9005_rc_decode
);
1073 rc_keys
= symbol_request(rc_map_af9005_table
);
1074 rc_keys_size
= symbol_request(rc_map_af9005_table_size
);
1075 if (rc_decode
== NULL
|| rc_keys
== NULL
|| rc_keys_size
== NULL
) {
1076 err("af9005_rc_decode function not found, disabling remote");
1077 af9005_properties
.rc
.legacy
.rc_query
= NULL
;
1079 af9005_properties
.rc
.legacy
.rc_map_table
= rc_keys
;
1080 af9005_properties
.rc
.legacy
.rc_map_size
= *rc_keys_size
;
1086 static void __exit
af9005_usb_module_exit(void)
1088 /* release rc decode symbols */
1089 if (rc_decode
!= NULL
)
1090 symbol_put(af9005_rc_decode
);
1091 if (rc_keys
!= NULL
)
1092 symbol_put(rc_map_af9005_table
);
1093 if (rc_keys_size
!= NULL
)
1094 symbol_put(rc_map_af9005_table_size
);
1095 /* deregister this driver from the USB subsystem */
1096 usb_deregister(&af9005_usb_driver
);
1099 module_init(af9005_usb_module_init
);
1100 module_exit(af9005_usb_module_exit
);
1102 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1103 MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1104 MODULE_VERSION("1.0");
1105 MODULE_LICENSE("GPL");