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 int dvb_usb_af9005_dump_eeprom
= 0;
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 /* remote control decoder */
43 int (*rc_decode
) (struct dvb_usb_device
* d
, u8
* data
, int len
, u32
* event
,
48 u8 regmask
[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
50 struct af9005_device_state
{
55 int af9005_usb_generic_rw(struct dvb_usb_device
*d
, u8
* wbuf
, u16 wlen
,
56 u8
* rbuf
, u16 rlen
, int delay_ms
)
58 int actlen
, ret
= -ENOMEM
;
60 if (wbuf
== NULL
|| wlen
== 0)
63 if ((ret
= mutex_lock_interruptible(&d
->usb_mutex
)))
67 debug_dump(wbuf
, wlen
, deb_xfer
);
69 ret
= usb_bulk_msg(d
->udev
, usb_sndbulkpipe(d
->udev
,
74 err("bulk message failed: %d (%d/%d)", ret
, wlen
, actlen
);
76 ret
= actlen
!= wlen
? -1 : 0;
78 /* an answer is expected, and no error before */
79 if (!ret
&& rbuf
&& rlen
) {
83 ret
= usb_bulk_msg(d
->udev
, usb_rcvbulkpipe(d
->udev
,
88 err("recv bulk message failed: %d", ret
);
91 debug_dump(rbuf
, actlen
, deb_xfer
);
95 mutex_unlock(&d
->usb_mutex
);
99 int af9005_usb_generic_write(struct dvb_usb_device
*d
, u8
* buf
, u16 len
)
101 return af9005_usb_generic_rw(d
, buf
, len
, NULL
, 0, 0);
104 int af9005_generic_read_write(struct dvb_usb_device
*d
, u16 reg
,
105 int readwrite
, int type
, u8
* values
, int len
)
107 struct af9005_device_state
*st
= d
->priv
;
115 err("generic read/write, less than 1 byte. Makes no sense.");
119 err("generic read/write, more than 8 bytes. Not supported.");
123 obuf
[0] = 14; /* rest of buffer length low */
124 obuf
[1] = 0; /* rest of buffer length high */
126 obuf
[2] = AF9005_REGISTER_RW
; /* register operation */
127 obuf
[3] = 12; /* rest of buffer length */
129 obuf
[4] = st
->sequence
++; /* sequence number */
131 obuf
[5] = (u8
) (reg
>> 8); /* register address */
132 obuf
[6] = (u8
) (reg
& 0xff);
134 if (type
== AF9005_OFDM_REG
) {
135 command
= AF9005_CMD_OFDM_REG
;
137 command
= AF9005_CMD_TUNER
;
142 AF9005_CMD_BURST
| AF9005_CMD_AUTOINC
| (len
- 1) << 3;
143 command
|= readwrite
;
144 if (readwrite
== AF9005_CMD_WRITE
)
145 for (i
= 0; i
< len
; i
++)
146 obuf
[8 + i
] = values
[i
];
147 else if (type
== AF9005_TUNER_REG
)
148 /* read command for tuner, the first byte contains the i2c address */
152 ret
= af9005_usb_generic_rw(d
, obuf
, 16, ibuf
, 17, 0);
157 if (ibuf
[2] != AF9005_REGISTER_RW_ACK
) {
158 err("generic read/write, wrong reply code.");
161 if (ibuf
[3] != 0x0d) {
162 err("generic read/write, wrong length in reply.");
165 if (ibuf
[4] != obuf
[4]) {
166 err("generic read/write, wrong sequence in reply.");
170 Windows driver doesn't check these fields, in fact sometimes
171 the register in the reply is different that what has been sent
173 if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) {
174 err("generic read/write, wrong register in reply.");
177 if (ibuf[7] != command) {
178 err("generic read/write wrong command in reply.");
182 if (ibuf
[16] != 0x01) {
183 err("generic read/write wrong status code in reply.");
186 if (readwrite
== AF9005_CMD_READ
)
187 for (i
= 0; i
< len
; i
++)
188 values
[i
] = ibuf
[8 + i
];
194 int af9005_read_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8
* value
)
197 deb_reg("read register %x ", reg
);
198 ret
= af9005_generic_read_write(d
, reg
,
199 AF9005_CMD_READ
, AF9005_OFDM_REG
,
204 deb_reg("value %x\n", *value
);
208 int af9005_read_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
209 u8
* values
, int len
)
212 deb_reg("read %d registers %x ", len
, reg
);
213 ret
= af9005_generic_read_write(d
, reg
,
214 AF9005_CMD_READ
, AF9005_OFDM_REG
,
219 debug_dump(values
, len
, deb_reg
);
223 int af9005_write_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8 value
)
227 deb_reg("write register %x value %x ", reg
, value
);
228 ret
= af9005_generic_read_write(d
, reg
,
229 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
238 int af9005_write_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
239 u8
* values
, int len
)
242 deb_reg("write %d registers %x values ", len
, reg
);
243 debug_dump(values
, len
, deb_reg
);
245 ret
= af9005_generic_read_write(d
, reg
,
246 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
255 int af9005_read_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
260 deb_reg("read bits %x %x %x", reg
, pos
, len
);
261 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
263 deb_reg(" failed\n");
266 *value
= (temp
>> pos
) & regmask
[len
- 1];
267 deb_reg(" value %x\n", *value
);
272 int af9005_write_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
277 deb_reg("write bits %x %x %x value %x\n", reg
, pos
, len
, value
);
278 if (pos
== 0 && len
== 8)
279 return af9005_write_ofdm_register(d
, reg
, value
);
280 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
283 mask
= regmask
[len
- 1] << pos
;
284 temp
= (temp
& ~mask
) | ((value
<< pos
) & mask
);
285 return af9005_write_ofdm_register(d
, reg
, temp
);
289 static int af9005_usb_read_tuner_registers(struct dvb_usb_device
*d
,
290 u16 reg
, u8
* values
, int len
)
292 return af9005_generic_read_write(d
, reg
,
293 AF9005_CMD_READ
, AF9005_TUNER_REG
,
297 static int af9005_usb_write_tuner_registers(struct dvb_usb_device
*d
,
298 u16 reg
, u8
* values
, int len
)
300 return af9005_generic_read_write(d
, reg
,
302 AF9005_TUNER_REG
, values
, len
);
305 int af9005_write_tuner_registers(struct dvb_usb_device
*d
, u16 reg
,
306 u8
* values
, int len
)
308 /* don't let the name of this function mislead you: it's just used
309 as an interface from the firmware to the i2c bus. The actual
310 i2c addresses are contained in the data */
311 int ret
, i
, done
= 0, fail
= 0;
313 ret
= af9005_usb_write_tuner_registers(d
, reg
, values
, len
);
317 /* check if write done (0xa40d bit 1) or fail (0xa40d bit 2) */
318 for (i
= 0; i
< 200; i
++) {
320 af9005_read_ofdm_register(d
,
321 xd_I2C_i2c_m_status_wdat_done
,
325 done
= temp
& (regmask
[i2c_m_status_wdat_done_len
- 1]
326 << i2c_m_status_wdat_done_pos
);
329 fail
= temp
& (regmask
[i2c_m_status_wdat_fail_len
- 1]
330 << i2c_m_status_wdat_fail_pos
);
338 /* clear write fail bit */
339 af9005_write_register_bits(d
,
340 xd_I2C_i2c_m_status_wdat_fail
,
341 i2c_m_status_wdat_fail_pos
,
342 i2c_m_status_wdat_fail_len
,
346 /* clear write done bit */
348 af9005_write_register_bits(d
,
349 xd_I2C_i2c_m_status_wdat_fail
,
350 i2c_m_status_wdat_done_pos
,
351 i2c_m_status_wdat_done_len
, 1);
358 int af9005_read_tuner_registers(struct dvb_usb_device
*d
, u16 reg
, u8 addr
,
359 u8
* values
, int len
)
361 /* don't let the name of this function mislead you: it's just used
362 as an interface from the firmware to the i2c bus. The actual
363 i2c addresses are contained in the data */
367 buf
[0] = addr
; /* tuner i2c address */
368 buf
[1] = values
[0]; /* tuner register */
370 values
[0] = addr
+ 0x01; /* i2c read address */
372 if (reg
== APO_REG_I2C_RW_SILICON_TUNER
) {
373 /* write tuner i2c address to tuner, 0c00c0 undocumented, found by sniffing */
374 ret
= af9005_write_tuner_registers(d
, 0x00c0, buf
, 2);
379 /* send read command to ofsm */
380 ret
= af9005_usb_read_tuner_registers(d
, reg
, values
, 1);
384 /* check if read done */
385 for (i
= 0; i
< 200; i
++) {
386 ret
= af9005_read_ofdm_register(d
, 0xa408, &temp
);
396 /* clear read done bit (by writing 1) */
397 ret
= af9005_write_ofdm_register(d
, xd_I2C_i2c_m_data8
, 1);
401 /* get read data (available from 0xa400) */
402 for (i
= 0; i
< len
; i
++) {
403 ret
= af9005_read_ofdm_register(d
, 0xa400 + i
, &temp
);
411 static int af9005_i2c_write(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
416 deb_i2c("i2c_write i2caddr %x, reg %x, len %d data ", i2caddr
,
418 debug_dump(data
, len
, deb_i2c
);
420 for (i
= 0; i
< len
; i
++) {
422 buf
[1] = reg
+ (u8
) i
;
425 af9005_write_tuner_registers(d
,
426 APO_REG_I2C_RW_SILICON_TUNER
,
429 deb_i2c("i2c_write failed\n");
433 deb_i2c("i2c_write ok\n");
437 static int af9005_i2c_read(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
442 deb_i2c("i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr
, reg
, len
);
443 for (i
= 0; i
< len
; i
++) {
446 af9005_read_tuner_registers(d
,
447 APO_REG_I2C_RW_SILICON_TUNER
,
450 deb_i2c("i2c_read failed\n");
455 deb_i2c("i2c data read: ");
456 debug_dump(data
, len
, deb_i2c
);
460 static int af9005_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
463 /* only implements what the mt2060 module does, don't know how
464 to make it really generic */
465 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
470 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
474 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
477 /* reads a single register */
481 ret
= af9005_i2c_read(d
, addr
, reg
, value
, 1);
485 /* write one or more registers */
488 value
= &msg
[0].buf
[1];
489 ret
= af9005_i2c_write(d
, addr
, reg
, value
, msg
[0].len
- 1);
494 mutex_unlock(&d
->i2c_mutex
);
498 static u32
af9005_i2c_func(struct i2c_adapter
*adapter
)
503 static struct i2c_algorithm af9005_i2c_algo
= {
504 .master_xfer
= af9005_i2c_xfer
,
505 .functionality
= af9005_i2c_func
,
508 int af9005_send_command(struct dvb_usb_device
*d
, u8 command
, u8
* wbuf
,
509 int wlen
, u8
* rbuf
, int rlen
)
511 struct af9005_device_state
*st
= d
->priv
;
513 int ret
, i
, packet_len
;
518 err("send command, wlen less than 0 bytes. Makes no sense.");
522 err("send command, wlen more than 54 bytes. Not supported.");
526 err("send command, rlen more than 54 bytes. Not supported.");
529 packet_len
= wlen
+ 5;
530 buf
[0] = (u8
) (packet_len
& 0xff);
531 buf
[1] = (u8
) ((packet_len
& 0xff00) >> 8);
533 buf
[2] = 0x26; /* packet type */
535 buf
[4] = st
->sequence
++;
538 for (i
= 0; i
< wlen
; i
++)
539 buf
[7 + i
] = wbuf
[i
];
540 ret
= af9005_usb_generic_rw(d
, buf
, wlen
+ 7, ibuf
, rlen
+ 7, 0);
543 if (ibuf
[2] != 0x27) {
544 err("send command, wrong reply code.");
547 if (ibuf
[4] != buf
[4]) {
548 err("send command, wrong sequence in reply.");
551 if (ibuf
[5] != 0x01) {
552 err("send command, wrong status code in reply.");
555 if (ibuf
[6] != rlen
) {
556 err("send command, invalid data length in reply.");
559 for (i
= 0; i
< rlen
; i
++)
560 rbuf
[i
] = ibuf
[i
+ 7];
564 int af9005_read_eeprom(struct dvb_usb_device
*d
, u8 address
, u8
* values
,
567 struct af9005_device_state
*st
= d
->priv
;
568 u8 obuf
[16], ibuf
[14];
571 memset(obuf
, 0, sizeof(obuf
));
572 memset(ibuf
, 0, sizeof(ibuf
));
574 obuf
[0] = 14; /* length of rest of packet low */
575 obuf
[1] = 0; /* length of rest of packer high */
577 obuf
[2] = 0x2a; /* read/write eeprom */
579 obuf
[3] = 12; /* size */
581 obuf
[4] = st
->sequence
++;
583 obuf
[5] = 0; /* read */
587 ret
= af9005_usb_generic_rw(d
, obuf
, 16, ibuf
, 14, 0);
590 if (ibuf
[2] != 0x2b) {
591 err("Read eeprom, invalid reply code");
595 err("Read eeprom, invalid reply length");
598 if (ibuf
[4] != obuf
[4]) {
599 err("Read eeprom, wrong sequence in reply ");
603 err("Read eeprom, wrong status in reply ");
606 for (i
= 0; i
< len
; i
++) {
607 values
[i
] = ibuf
[6 + i
];
612 static int af9005_boot_packet(struct usb_device
*udev
, int type
, u8
* reply
)
614 u8 buf
[FW_BULKOUT_SIZE
+ 2];
617 memset(buf
, 0, sizeof(buf
));
618 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
619 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
624 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
626 checksum
= buf
[4] + buf
[5];
627 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
628 buf
[7] = (u8
) (checksum
& 0xff);
633 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
635 checksum
= buf
[4] + buf
[5];
636 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
637 buf
[7] = (u8
) (checksum
& 0xff);
642 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
649 for (i
= 4; i
<= 9; i
++)
651 buf
[10] = (u8
) ((checksum
>> 8) & 0xff);
652 buf
[11] = (u8
) (checksum
& 0xff);
655 err("boot packet invalid boot packet type");
659 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
661 ret
= usb_bulk_msg(udev
,
662 usb_sndbulkpipe(udev
, 0x02),
663 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 2000);
665 err("boot packet bulk message failed: %d (%d/%d)", ret
,
666 FW_BULKOUT_SIZE
+ 2, act_len
);
668 ret
= act_len
!= FW_BULKOUT_SIZE
+ 2 ? -1 : 0;
672 ret
= usb_bulk_msg(udev
,
673 usb_rcvbulkpipe(udev
, 0x01), buf
, 9, &act_len
, 2000);
675 err("boot packet recv bulk message failed: %d", ret
);
679 debug_dump(buf
, act_len
, deb_fw
);
683 if (buf
[2] != 0x11) {
684 err("boot bad config header.");
687 if (buf
[3] != 0x05) {
688 err("boot bad config size.");
691 if (buf
[4] != 0x00) {
692 err("boot bad config sequence.");
695 if (buf
[5] != 0x04) {
696 err("boot bad config subtype.");
699 for (i
= 4; i
<= 6; i
++)
701 if (buf
[7] * 256 + buf
[8] != checksum
) {
702 err("boot bad config checksum.");
708 if (buf
[2] != 0x11) {
709 err("boot bad confirm header.");
712 if (buf
[3] != 0x05) {
713 err("boot bad confirm size.");
716 if (buf
[4] != 0x00) {
717 err("boot bad confirm sequence.");
720 if (buf
[5] != 0x02) {
721 err("boot bad confirm subtype.");
724 for (i
= 4; i
<= 6; i
++)
726 if (buf
[7] * 256 + buf
[8] != checksum
) {
727 err("boot bad confirm checksum.");
733 if (buf
[2] != 0x10) {
734 err("boot bad boot header.");
737 if (buf
[3] != 0x05) {
738 err("boot bad boot size.");
741 if (buf
[4] != 0x00) {
742 err("boot bad boot sequence.");
745 if (buf
[5] != 0x01) {
746 err("boot bad boot pattern 01.");
749 if (buf
[6] != 0x10) {
750 err("boot bad boot pattern 10.");
753 for (i
= 4; i
<= 6; i
++)
755 if (buf
[7] * 256 + buf
[8] != checksum
) {
756 err("boot bad boot checksum.");
766 int af9005_download_firmware(struct usb_device
*udev
, const struct firmware
*fw
)
768 int i
, packets
, ret
, act_len
;
770 u8 buf
[FW_BULKOUT_SIZE
+ 2];
773 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
);
777 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply
);
780 packets
= fw
->size
/ FW_BULKOUT_SIZE
;
781 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
782 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
783 for (i
= 0; i
< packets
; i
++) {
784 memcpy(&buf
[2], fw
->data
+ i
* FW_BULKOUT_SIZE
,
787 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
788 ret
= usb_bulk_msg(udev
,
789 usb_sndbulkpipe(udev
, 0x02),
790 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 1000);
792 err("firmware download failed at packet %d with code %d", i
, ret
);
796 ret
= af9005_boot_packet(udev
, FW_CONFIRM
, &reply
);
799 if (reply
!= (u8
) (packets
& 0xff)) {
800 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets
& 0xff, reply
);
803 ret
= af9005_boot_packet(udev
, FW_BOOT
, &reply
);
806 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
);
810 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply
);
818 int af9005_led_control(struct dvb_usb_device
*d
, int onoff
)
820 struct af9005_device_state
*st
= d
->priv
;
823 if (onoff
&& dvb_usb_af9005_led
)
827 if (st
->led_state
!= temp
) {
829 af9005_write_register_bits(d
, xd_p_reg_top_locken1
,
831 reg_top_locken1_len
, temp
);
835 af9005_write_register_bits(d
, xd_p_reg_top_lock1
,
837 reg_top_lock1_len
, temp
);
840 st
->led_state
= temp
;
845 static int af9005_frontend_attach(struct dvb_usb_adapter
*adap
)
850 /* without these calls the first commands after downloading
851 the firmware fail. I put these calls here to simulate
852 what it is done in dvb-usb-init.c.
854 struct usb_device
*udev
= adap
->dev
->udev
;
855 usb_clear_halt(udev
, usb_sndbulkpipe(udev
, 2));
856 usb_clear_halt(udev
, usb_rcvbulkpipe(udev
, 1));
857 if (dvb_usb_af9005_dump_eeprom
) {
858 printk("EEPROM DUMP\n");
859 for (i
= 0; i
< 255; i
+= 8) {
860 af9005_read_eeprom(adap
->dev
, i
, buf
, 8);
861 printk("ADDR %x ", i
);
862 debug_dump(buf
, 8, printk
);
865 adap
->fe
= af9005_fe_attach(adap
->dev
);
869 static int af9005_rc_query(struct dvb_usb_device
*d
, u32
* event
, int *state
)
871 struct af9005_device_state
*st
= d
->priv
;
877 *state
= REMOTE_NO_KEY_PRESSED
;
878 if (rc_decode
== NULL
) {
879 /* it shouldn't never come here */
882 /* deb_info("rc_query\n"); */
883 obuf
[0] = 3; /* rest of packet length low */
884 obuf
[1] = 0; /* rest of packet lentgh high */
885 obuf
[2] = 0x40; /* read remote */
886 obuf
[3] = 1; /* rest of packet length */
887 obuf
[4] = st
->sequence
++; /* sequence number */
888 ret
= af9005_usb_generic_rw(d
, obuf
, 5, ibuf
, 256, 0);
890 err("rc query failed");
893 if (ibuf
[2] != 0x41) {
894 err("rc query bad header.");
897 if (ibuf
[4] != obuf
[4]) {
898 err("rc query bad sequence.");
903 err("rc query invalid length");
907 deb_rc("rc data (%d) ", len
);
908 debug_dump((ibuf
+ 6), len
, deb_rc
);
909 ret
= rc_decode(d
, &ibuf
[6], len
, event
, state
);
911 err("rc_decode failed");
914 deb_rc("rc_decode state %x event %x\n", *state
, *event
);
915 if (*state
== REMOTE_KEY_REPEAT
)
916 *event
= d
->last_event
;
922 static int af9005_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
928 static int af9005_pid_filter_control(struct dvb_usb_adapter
*adap
, int onoff
)
931 deb_info("pid filter control onoff %d\n", onoff
);
934 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
938 af9005_write_register_bits(adap
->dev
,
939 XD_MP2IF_DMX_CTRL
, 1, 1, 1);
943 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
946 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 0);
949 deb_info("pid filter control ok\n");
953 static int af9005_pid_filter(struct dvb_usb_adapter
*adap
, int index
,
956 u8 cmd
= index
& 0x1f;
958 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index
,
961 /* cannot use it as pid_filter_ctrl since it has to be done
962 before setting the first pid */
963 if (adap
->feedcount
== 1) {
964 deb_info("first pid set, enable pid table\n");
965 ret
= af9005_pid_filter_control(adap
, onoff
);
970 af9005_write_ofdm_register(adap
->dev
,
976 af9005_write_ofdm_register(adap
->dev
,
983 if (adap
->feedcount
== 0) {
984 deb_info("last pid unset, disable pid table\n");
985 ret
= af9005_pid_filter_control(adap
, onoff
);
990 ret
= af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_PID_IDX
, cmd
);
993 deb_info("set pid ok\n");
997 static int af9005_identify_state(struct usb_device
*udev
,
998 struct dvb_usb_device_properties
*props
,
999 struct dvb_usb_device_description
**desc
,
1004 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
);
1007 deb_info("result of FW_CONFIG in identify state %d\n", reply
);
1010 else if (reply
== 0x02)
1014 deb_info("Identify state cold = %d\n", *cold
);
1018 static struct dvb_usb_device_properties af9005_properties
;
1020 static int af9005_usb_probe(struct usb_interface
*intf
,
1021 const struct usb_device_id
*id
)
1023 return dvb_usb_device_init(intf
, &af9005_properties
, THIS_MODULE
, NULL
);
1026 static struct usb_device_id af9005_usb_table
[] = {
1027 {USB_DEVICE(USB_VID_AFATECH
, USB_PID_AFATECH_AF9005
)},
1028 {USB_DEVICE(USB_VID_TERRATEC
, USB_PID_TERRATEC_CINERGY_T_USB_XE
)},
1032 MODULE_DEVICE_TABLE(usb
, af9005_usb_table
);
1034 static struct dvb_usb_device_properties af9005_properties
= {
1035 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
1037 .usb_ctrl
= DEVICE_SPECIFIC
,
1038 .firmware
= "af9005.fw",
1039 .download_firmware
= af9005_download_firmware
,
1042 .size_of_priv
= sizeof(struct af9005_device_state
),
1048 DVB_USB_ADAP_HAS_PID_FILTER
|
1049 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1050 .pid_filter_count
= 32,
1051 .pid_filter
= af9005_pid_filter
,
1052 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1053 .frontend_attach
= af9005_frontend_attach
,
1054 /* .tuner_attach = af9005_tuner_attach, */
1055 /* parameter for the MPEG2-data transfer */
1062 .buffersize
= 4096, /* actual size seen is 3948 */
1068 .power_ctrl
= af9005_power_ctrl
,
1069 .identify_state
= af9005_identify_state
,
1071 .i2c_algo
= &af9005_i2c_algo
,
1075 .rc_key_map_size
= 0,
1076 .rc_query
= af9005_rc_query
,
1078 .num_device_descs
= 2,
1080 {.name
= "Afatech DVB-T USB1.1 stick",
1081 .cold_ids
= {&af9005_usb_table
[0], NULL
},
1084 {.name
= "TerraTec Cinergy T USB XE",
1085 .cold_ids
= {&af9005_usb_table
[1], NULL
},
1092 /* usb specific object needed to register this driver with the usb subsystem */
1093 static struct usb_driver af9005_usb_driver
= {
1094 .name
= "dvb_usb_af9005",
1095 .probe
= af9005_usb_probe
,
1096 .disconnect
= dvb_usb_device_exit
,
1097 .id_table
= af9005_usb_table
,
1101 static int __init
af9005_usb_module_init(void)
1104 if ((result
= usb_register(&af9005_usb_driver
))) {
1105 err("usb_register failed. (%d)", result
);
1108 rc_decode
= symbol_request(af9005_rc_decode
);
1109 rc_keys
= symbol_request(af9005_rc_keys
);
1110 rc_keys_size
= symbol_request(af9005_rc_keys_size
);
1111 if (rc_decode
== NULL
|| rc_keys
== NULL
|| rc_keys_size
== NULL
) {
1112 err("af9005_rc_decode function not found, disabling remote");
1113 af9005_properties
.rc_query
= NULL
;
1115 af9005_properties
.rc_key_map
= rc_keys
;
1116 af9005_properties
.rc_key_map_size
= *rc_keys_size
;
1122 static void __exit
af9005_usb_module_exit(void)
1124 /* release rc decode symbols */
1125 if (rc_decode
!= NULL
)
1126 symbol_put(af9005_rc_decode
);
1127 if (rc_keys
!= NULL
)
1128 symbol_put(af9005_rc_keys
);
1129 if (rc_keys_size
!= NULL
)
1130 symbol_put(af9005_rc_keys_size
);
1131 /* deregister this driver from the USB subsystem */
1132 usb_deregister(&af9005_usb_driver
);
1135 module_init(af9005_usb_module_init
);
1136 module_exit(af9005_usb_module_exit
);
1138 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1139 MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1140 MODULE_VERSION("1.0");
1141 MODULE_LICENSE("GPL");