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 * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
23 int dvb_usb_af9005_debug
;
24 module_param_named(debug
, dvb_usb_af9005_debug
, int, 0644);
25 MODULE_PARM_DESC(debug
,
26 "set debugging level (1=info,xfer=2,rc=4,reg=8,i2c=16,fw=32 (or-able))."
27 DVB_USB_DEBUG_STATUS
);
28 /* enable obnoxious led */
29 bool dvb_usb_af9005_led
= true;
30 module_param_named(led
, dvb_usb_af9005_led
, bool, 0644);
31 MODULE_PARM_DESC(led
, "enable led (default: 1).");
34 static int dvb_usb_af9005_dump_eeprom
;
35 module_param_named(dump_eeprom
, dvb_usb_af9005_dump_eeprom
, int, 0);
36 MODULE_PARM_DESC(dump_eeprom
, "dump contents of the eeprom.");
38 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
40 /* remote control decoder */
41 static int (*rc_decode
) (struct dvb_usb_device
*d
, u8
*data
, int len
,
42 u32
*event
, int *state
);
44 static int *rc_keys_size
;
46 u8 regmask
[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
48 struct af9005_device_state
{
51 unsigned char data
[256];
54 static int af9005_generic_read_write(struct dvb_usb_device
*d
, u16 reg
,
55 int readwrite
, int type
, u8
* values
, int len
)
57 struct af9005_device_state
*st
= d
->priv
;
62 err("generic read/write, less than 1 byte. Makes no sense.");
66 err("generic read/write, more than 8 bytes. Not supported.");
70 mutex_lock(&d
->data_mutex
);
71 st
->data
[0] = 14; /* rest of buffer length low */
72 st
->data
[1] = 0; /* rest of buffer length high */
74 st
->data
[2] = AF9005_REGISTER_RW
; /* register operation */
75 st
->data
[3] = 12; /* rest of buffer length */
77 st
->data
[4] = seq
= st
->sequence
++; /* sequence number */
79 st
->data
[5] = (u8
) (reg
>> 8); /* register address */
80 st
->data
[6] = (u8
) (reg
& 0xff);
82 if (type
== AF9005_OFDM_REG
) {
83 command
= AF9005_CMD_OFDM_REG
;
85 command
= AF9005_CMD_TUNER
;
90 AF9005_CMD_BURST
| AF9005_CMD_AUTOINC
| (len
- 1) << 3;
92 if (readwrite
== AF9005_CMD_WRITE
)
93 for (i
= 0; i
< len
; i
++)
94 st
->data
[8 + i
] = values
[i
];
95 else if (type
== AF9005_TUNER_REG
)
96 /* read command for tuner, the first byte contains the i2c address */
97 st
->data
[8] = values
[0];
98 st
->data
[7] = command
;
100 ret
= dvb_usb_generic_rw(d
, st
->data
, 16, st
->data
, 17, 0);
105 if (st
->data
[2] != AF9005_REGISTER_RW_ACK
) {
106 err("generic read/write, wrong reply code.");
110 if (st
->data
[3] != 0x0d) {
111 err("generic read/write, wrong length in reply.");
115 if (st
->data
[4] != seq
) {
116 err("generic read/write, wrong sequence in reply.");
121 * In thesis, both input and output buffers should have
122 * identical values for st->data[5] to st->data[8].
123 * However, windows driver doesn't check these fields, in fact
124 * sometimes the register in the reply is different that what
127 if (st
->data
[16] != 0x01) {
128 err("generic read/write wrong status code in reply.");
133 if (readwrite
== AF9005_CMD_READ
)
134 for (i
= 0; i
< len
; i
++)
135 values
[i
] = st
->data
[8 + i
];
138 mutex_unlock(&d
->data_mutex
);
143 int af9005_read_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8
* value
)
146 deb_reg("read register %x ", reg
);
147 ret
= af9005_generic_read_write(d
, reg
,
148 AF9005_CMD_READ
, AF9005_OFDM_REG
,
153 deb_reg("value %x\n", *value
);
157 int af9005_read_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
158 u8
* values
, int len
)
161 deb_reg("read %d registers %x ", len
, reg
);
162 ret
= af9005_generic_read_write(d
, reg
,
163 AF9005_CMD_READ
, AF9005_OFDM_REG
,
168 debug_dump(values
, len
, deb_reg
);
172 int af9005_write_ofdm_register(struct dvb_usb_device
*d
, u16 reg
, u8 value
)
176 deb_reg("write register %x value %x ", reg
, value
);
177 ret
= af9005_generic_read_write(d
, reg
,
178 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
187 int af9005_write_ofdm_registers(struct dvb_usb_device
*d
, u16 reg
,
188 u8
* values
, int len
)
191 deb_reg("write %d registers %x values ", len
, reg
);
192 debug_dump(values
, len
, deb_reg
);
194 ret
= af9005_generic_read_write(d
, reg
,
195 AF9005_CMD_WRITE
, AF9005_OFDM_REG
,
204 int af9005_read_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
209 deb_reg("read bits %x %x %x", reg
, pos
, len
);
210 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
212 deb_reg(" failed\n");
215 *value
= (temp
>> pos
) & regmask
[len
- 1];
216 deb_reg(" value %x\n", *value
);
221 int af9005_write_register_bits(struct dvb_usb_device
*d
, u16 reg
, u8 pos
,
226 deb_reg("write bits %x %x %x value %x\n", reg
, pos
, len
, value
);
227 if (pos
== 0 && len
== 8)
228 return af9005_write_ofdm_register(d
, reg
, value
);
229 ret
= af9005_read_ofdm_register(d
, reg
, &temp
);
232 mask
= regmask
[len
- 1] << pos
;
233 temp
= (temp
& ~mask
) | ((value
<< pos
) & mask
);
234 return af9005_write_ofdm_register(d
, reg
, temp
);
238 static int af9005_usb_read_tuner_registers(struct dvb_usb_device
*d
,
239 u16 reg
, u8
* values
, int len
)
241 return af9005_generic_read_write(d
, reg
,
242 AF9005_CMD_READ
, AF9005_TUNER_REG
,
246 static int af9005_usb_write_tuner_registers(struct dvb_usb_device
*d
,
247 u16 reg
, u8
* values
, int len
)
249 return af9005_generic_read_write(d
, reg
,
251 AF9005_TUNER_REG
, values
, len
);
254 int af9005_write_tuner_registers(struct dvb_usb_device
*d
, u16 reg
,
255 u8
* values
, int len
)
257 /* don't let the name of this function mislead you: it's just used
258 as an interface from the firmware to the i2c bus. The actual
259 i2c addresses are contained in the data */
260 int ret
, i
, done
= 0, fail
= 0;
262 ret
= af9005_usb_write_tuner_registers(d
, reg
, values
, len
);
266 /* check if write done (0xa40d bit 1) or fail (0xa40d bit 2) */
267 for (i
= 0; i
< 200; i
++) {
269 af9005_read_ofdm_register(d
,
270 xd_I2C_i2c_m_status_wdat_done
,
274 done
= temp
& (regmask
[i2c_m_status_wdat_done_len
- 1]
275 << i2c_m_status_wdat_done_pos
);
278 fail
= temp
& (regmask
[i2c_m_status_wdat_fail_len
- 1]
279 << i2c_m_status_wdat_fail_pos
);
287 /* clear write fail bit */
288 af9005_write_register_bits(d
,
289 xd_I2C_i2c_m_status_wdat_fail
,
290 i2c_m_status_wdat_fail_pos
,
291 i2c_m_status_wdat_fail_len
,
295 /* clear write done bit */
297 af9005_write_register_bits(d
,
298 xd_I2C_i2c_m_status_wdat_fail
,
299 i2c_m_status_wdat_done_pos
,
300 i2c_m_status_wdat_done_len
, 1);
307 int af9005_read_tuner_registers(struct dvb_usb_device
*d
, u16 reg
, u8 addr
,
308 u8
* values
, int len
)
310 /* don't let the name of this function mislead you: it's just used
311 as an interface from the firmware to the i2c bus. The actual
312 i2c addresses are contained in the data */
316 buf
[0] = addr
; /* tuner i2c address */
317 buf
[1] = values
[0]; /* tuner register */
319 values
[0] = addr
+ 0x01; /* i2c read address */
321 if (reg
== APO_REG_I2C_RW_SILICON_TUNER
) {
322 /* write tuner i2c address to tuner, 0c00c0 undocumented, found by sniffing */
323 ret
= af9005_write_tuner_registers(d
, 0x00c0, buf
, 2);
328 /* send read command to ofsm */
329 ret
= af9005_usb_read_tuner_registers(d
, reg
, values
, 1);
333 /* check if read done */
334 for (i
= 0; i
< 200; i
++) {
335 ret
= af9005_read_ofdm_register(d
, 0xa408, &temp
);
345 /* clear read done bit (by writing 1) */
346 ret
= af9005_write_ofdm_register(d
, xd_I2C_i2c_m_data8
, 1);
350 /* get read data (available from 0xa400) */
351 for (i
= 0; i
< len
; i
++) {
352 ret
= af9005_read_ofdm_register(d
, 0xa400 + i
, &temp
);
360 static int af9005_i2c_write(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
365 deb_i2c("i2c_write i2caddr %x, reg %x, len %d data ", i2caddr
,
367 debug_dump(data
, len
, deb_i2c
);
369 for (i
= 0; i
< len
; i
++) {
371 buf
[1] = reg
+ (u8
) i
;
374 af9005_write_tuner_registers(d
,
375 APO_REG_I2C_RW_SILICON_TUNER
,
378 deb_i2c("i2c_write failed\n");
382 deb_i2c("i2c_write ok\n");
386 static int af9005_i2c_read(struct dvb_usb_device
*d
, u8 i2caddr
, u8 reg
,
391 deb_i2c("i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr
, reg
, len
);
392 for (i
= 0; i
< len
; i
++) {
395 af9005_read_tuner_registers(d
,
396 APO_REG_I2C_RW_SILICON_TUNER
,
399 deb_i2c("i2c_read failed\n");
404 deb_i2c("i2c data read: ");
405 debug_dump(data
, len
, deb_i2c
);
409 static int af9005_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
412 /* only implements what the mt2060 module does, don't know how
413 to make it really generic */
414 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
419 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
423 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
426 /* reads a single register */
430 ret
= af9005_i2c_read(d
, addr
, reg
, value
, 1);
434 /* write one or more registers */
437 value
= &msg
[0].buf
[1];
438 ret
= af9005_i2c_write(d
, addr
, reg
, value
, msg
[0].len
- 1);
443 mutex_unlock(&d
->i2c_mutex
);
447 static u32
af9005_i2c_func(struct i2c_adapter
*adapter
)
452 static struct i2c_algorithm af9005_i2c_algo
= {
453 .master_xfer
= af9005_i2c_xfer
,
454 .functionality
= af9005_i2c_func
,
457 int af9005_send_command(struct dvb_usb_device
*d
, u8 command
, u8
* wbuf
,
458 int wlen
, u8
* rbuf
, int rlen
)
460 struct af9005_device_state
*st
= d
->priv
;
462 int ret
, i
, packet_len
;
466 err("send command, wlen less than 0 bytes. Makes no sense.");
470 err("send command, wlen more than 54 bytes. Not supported.");
474 err("send command, rlen more than 54 bytes. Not supported.");
477 packet_len
= wlen
+ 5;
479 mutex_lock(&d
->data_mutex
);
481 st
->data
[0] = (u8
) (packet_len
& 0xff);
482 st
->data
[1] = (u8
) ((packet_len
& 0xff00) >> 8);
484 st
->data
[2] = 0x26; /* packet type */
485 st
->data
[3] = wlen
+ 3;
486 st
->data
[4] = seq
= st
->sequence
++;
487 st
->data
[5] = command
;
489 for (i
= 0; i
< wlen
; i
++)
490 st
->data
[7 + i
] = wbuf
[i
];
491 ret
= dvb_usb_generic_rw(d
, st
->data
, wlen
+ 7, st
->data
, rlen
+ 7, 0);
492 if (st
->data
[2] != 0x27) {
493 err("send command, wrong reply code.");
495 } else if (st
->data
[4] != seq
) {
496 err("send command, wrong sequence in reply.");
498 } else if (st
->data
[5] != 0x01) {
499 err("send command, wrong status code in reply.");
501 } else if (st
->data
[6] != rlen
) {
502 err("send command, invalid data length in reply.");
506 for (i
= 0; i
< rlen
; i
++)
507 rbuf
[i
] = st
->data
[i
+ 7];
510 mutex_unlock(&d
->data_mutex
);
514 int af9005_read_eeprom(struct dvb_usb_device
*d
, u8 address
, u8
* values
,
517 struct af9005_device_state
*st
= d
->priv
;
521 mutex_lock(&d
->data_mutex
);
523 memset(st
->data
, 0, sizeof(st
->data
));
525 st
->data
[0] = 14; /* length of rest of packet low */
526 st
->data
[1] = 0; /* length of rest of packer high */
528 st
->data
[2] = 0x2a; /* read/write eeprom */
530 st
->data
[3] = 12; /* size */
532 st
->data
[4] = seq
= st
->sequence
++;
534 st
->data
[5] = 0; /* read */
537 st
->data
[7] = address
;
538 ret
= dvb_usb_generic_rw(d
, st
->data
, 16, st
->data
, 14, 0);
539 if (st
->data
[2] != 0x2b) {
540 err("Read eeprom, invalid reply code");
542 } else if (st
->data
[3] != 10) {
543 err("Read eeprom, invalid reply length");
545 } else if (st
->data
[4] != seq
) {
546 err("Read eeprom, wrong sequence in reply ");
548 } else if (st
->data
[5] != 1) {
549 err("Read eeprom, wrong status in reply ");
554 for (i
= 0; i
< len
; i
++)
555 values
[i
] = st
->data
[6 + i
];
557 mutex_unlock(&d
->data_mutex
);
562 static int af9005_boot_packet(struct usb_device
*udev
, int type
, u8
*reply
,
568 memset(buf
, 0, size
);
569 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
570 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 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 */
586 checksum
= buf
[4] + buf
[5];
587 buf
[6] = (u8
) ((checksum
>> 8) & 0xff);
588 buf
[7] = (u8
) (checksum
& 0xff);
593 buf
[4] = 0x00; /* sequence number, original driver doesn't increment it here */
600 for (i
= 4; i
<= 9; i
++)
602 buf
[10] = (u8
) ((checksum
>> 8) & 0xff);
603 buf
[11] = (u8
) (checksum
& 0xff);
606 err("boot packet invalid boot packet type");
610 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
612 ret
= usb_bulk_msg(udev
,
613 usb_sndbulkpipe(udev
, 0x02),
614 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 2000);
616 err("boot packet bulk message failed: %d (%d/%d)", ret
,
617 FW_BULKOUT_SIZE
+ 2, act_len
);
619 ret
= act_len
!= FW_BULKOUT_SIZE
+ 2 ? -1 : 0;
623 ret
= usb_bulk_msg(udev
,
624 usb_rcvbulkpipe(udev
, 0x01), buf
, 9, &act_len
, 2000);
626 err("boot packet recv bulk message failed: %d", ret
);
630 debug_dump(buf
, act_len
, deb_fw
);
634 if (buf
[2] != 0x11) {
635 err("boot bad config header.");
638 if (buf
[3] != 0x05) {
639 err("boot bad config size.");
642 if (buf
[4] != 0x00) {
643 err("boot bad config sequence.");
646 if (buf
[5] != 0x04) {
647 err("boot bad config subtype.");
650 for (i
= 4; i
<= 6; i
++)
652 if (buf
[7] * 256 + buf
[8] != checksum
) {
653 err("boot bad config checksum.");
659 if (buf
[2] != 0x11) {
660 err("boot bad confirm header.");
663 if (buf
[3] != 0x05) {
664 err("boot bad confirm size.");
667 if (buf
[4] != 0x00) {
668 err("boot bad confirm sequence.");
671 if (buf
[5] != 0x02) {
672 err("boot bad confirm subtype.");
675 for (i
= 4; i
<= 6; i
++)
677 if (buf
[7] * 256 + buf
[8] != checksum
) {
678 err("boot bad confirm checksum.");
684 if (buf
[2] != 0x10) {
685 err("boot bad boot header.");
688 if (buf
[3] != 0x05) {
689 err("boot bad boot size.");
692 if (buf
[4] != 0x00) {
693 err("boot bad boot sequence.");
696 if (buf
[5] != 0x01) {
697 err("boot bad boot pattern 01.");
700 if (buf
[6] != 0x10) {
701 err("boot bad boot pattern 10.");
704 for (i
= 4; i
<= 6; i
++)
706 if (buf
[7] * 256 + buf
[8] != checksum
) {
707 err("boot bad boot checksum.");
717 static int af9005_download_firmware(struct usb_device
*udev
, const struct firmware
*fw
)
719 int i
, packets
, ret
, act_len
;
724 buf
= kmalloc(FW_BULKOUT_SIZE
+ 2, GFP_KERNEL
);
728 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
, buf
,
729 FW_BULKOUT_SIZE
+ 2);
733 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply
);
737 packets
= fw
->size
/ FW_BULKOUT_SIZE
;
738 buf
[0] = (u8
) (FW_BULKOUT_SIZE
& 0xff);
739 buf
[1] = (u8
) ((FW_BULKOUT_SIZE
>> 8) & 0xff);
740 for (i
= 0; i
< packets
; i
++) {
741 memcpy(&buf
[2], fw
->data
+ i
* FW_BULKOUT_SIZE
,
744 debug_dump(buf
, FW_BULKOUT_SIZE
+ 2, deb_fw
);
745 ret
= usb_bulk_msg(udev
,
746 usb_sndbulkpipe(udev
, 0x02),
747 buf
, FW_BULKOUT_SIZE
+ 2, &act_len
, 1000);
749 err("firmware download failed at packet %d with code %d", i
, ret
);
753 ret
= af9005_boot_packet(udev
, FW_CONFIRM
, &reply
,
754 buf
, FW_BULKOUT_SIZE
+ 2);
757 if (reply
!= (u8
) (packets
& 0xff)) {
758 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets
& 0xff, reply
);
762 ret
= af9005_boot_packet(udev
, FW_BOOT
, &reply
, buf
,
763 FW_BULKOUT_SIZE
+ 2);
766 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
, buf
,
767 FW_BULKOUT_SIZE
+ 2);
771 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply
);
782 int af9005_led_control(struct dvb_usb_device
*d
, int onoff
)
784 struct af9005_device_state
*st
= d
->priv
;
787 if (onoff
&& dvb_usb_af9005_led
)
791 if (st
->led_state
!= temp
) {
793 af9005_write_register_bits(d
, xd_p_reg_top_locken1
,
795 reg_top_locken1_len
, temp
);
799 af9005_write_register_bits(d
, xd_p_reg_top_lock1
,
801 reg_top_lock1_len
, temp
);
804 st
->led_state
= temp
;
809 static int af9005_frontend_attach(struct dvb_usb_adapter
*adap
)
814 /* without these calls the first commands after downloading
815 the firmware fail. I put these calls here to simulate
816 what it is done in dvb-usb-init.c.
818 struct usb_device
*udev
= adap
->dev
->udev
;
819 usb_clear_halt(udev
, usb_sndbulkpipe(udev
, 2));
820 usb_clear_halt(udev
, usb_rcvbulkpipe(udev
, 1));
821 if (dvb_usb_af9005_dump_eeprom
) {
822 printk("EEPROM DUMP\n");
823 for (i
= 0; i
< 255; i
+= 8) {
824 af9005_read_eeprom(adap
->dev
, i
, buf
, 8);
825 debug_dump(buf
, 8, printk
);
828 adap
->fe_adap
[0].fe
= af9005_fe_attach(adap
->dev
);
832 static int af9005_rc_query(struct dvb_usb_device
*d
, u32
* event
, int *state
)
834 struct af9005_device_state
*st
= d
->priv
;
838 *state
= REMOTE_NO_KEY_PRESSED
;
839 if (rc_decode
== NULL
) {
840 /* it shouldn't never come here */
844 mutex_lock(&d
->data_mutex
);
846 /* deb_info("rc_query\n"); */
847 st
->data
[0] = 3; /* rest of packet length low */
848 st
->data
[1] = 0; /* rest of packet lentgh high */
849 st
->data
[2] = 0x40; /* read remote */
850 st
->data
[3] = 1; /* rest of packet length */
851 st
->data
[4] = seq
= st
->sequence
++; /* sequence number */
852 ret
= dvb_usb_generic_rw(d
, st
->data
, 5, st
->data
, 256, 0);
854 err("rc query failed");
857 if (st
->data
[2] != 0x41) {
858 err("rc query bad header.");
861 } else if (st
->data
[4] != seq
) {
862 err("rc query bad sequence.");
868 err("rc query invalid length");
873 deb_rc("rc data (%d) ", len
);
874 debug_dump((st
->data
+ 6), len
, deb_rc
);
875 ret
= rc_decode(d
, &st
->data
[6], len
, event
, state
);
877 err("rc_decode failed");
880 deb_rc("rc_decode state %x event %x\n", *state
, *event
);
881 if (*state
== REMOTE_KEY_REPEAT
)
882 *event
= d
->last_event
;
887 mutex_unlock(&d
->data_mutex
);
891 static int af9005_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
897 static int af9005_pid_filter_control(struct dvb_usb_adapter
*adap
, int onoff
)
900 deb_info("pid filter control onoff %d\n", onoff
);
903 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
907 af9005_write_register_bits(adap
->dev
,
908 XD_MP2IF_DMX_CTRL
, 1, 1, 1);
912 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 1);
915 af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_DMX_CTRL
, 0);
918 deb_info("pid filter control ok\n");
922 static int af9005_pid_filter(struct dvb_usb_adapter
*adap
, int index
,
925 u8 cmd
= index
& 0x1f;
927 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index
,
930 /* cannot use it as pid_filter_ctrl since it has to be done
931 before setting the first pid */
932 if (adap
->feedcount
== 1) {
933 deb_info("first pid set, enable pid table\n");
934 ret
= af9005_pid_filter_control(adap
, onoff
);
939 af9005_write_ofdm_register(adap
->dev
,
945 af9005_write_ofdm_register(adap
->dev
,
952 if (adap
->feedcount
== 0) {
953 deb_info("last pid unset, disable pid table\n");
954 ret
= af9005_pid_filter_control(adap
, onoff
);
959 ret
= af9005_write_ofdm_register(adap
->dev
, XD_MP2IF_PID_IDX
, cmd
);
962 deb_info("set pid ok\n");
966 static int af9005_identify_state(struct usb_device
*udev
,
967 struct dvb_usb_device_properties
*props
,
968 struct dvb_usb_device_description
**desc
,
974 buf
= kmalloc(FW_BULKOUT_SIZE
+ 2, GFP_KERNEL
);
978 ret
= af9005_boot_packet(udev
, FW_CONFIG
, &reply
,
979 buf
, FW_BULKOUT_SIZE
+ 2);
982 deb_info("result of FW_CONFIG in identify state %d\n", reply
);
985 else if (reply
== 0x02)
989 deb_info("Identify state cold = %d\n", *cold
);
996 static struct dvb_usb_device_properties af9005_properties
;
998 static int af9005_usb_probe(struct usb_interface
*intf
,
999 const struct usb_device_id
*id
)
1001 return dvb_usb_device_init(intf
, &af9005_properties
,
1002 THIS_MODULE
, NULL
, adapter_nr
);
1005 enum af9005_usb_table_entry
{
1011 static struct usb_device_id af9005_usb_table
[] = {
1012 [AFATECH_AF9005
] = {USB_DEVICE(USB_VID_AFATECH
,
1013 USB_PID_AFATECH_AF9005
)},
1014 [TERRATEC_AF9005
] = {USB_DEVICE(USB_VID_TERRATEC
,
1015 USB_PID_TERRATEC_CINERGY_T_USB_XE
)},
1016 [ANSONIC_AF9005
] = {USB_DEVICE(USB_VID_ANSONIC
,
1017 USB_PID_ANSONIC_DVBT_USB
)},
1021 MODULE_DEVICE_TABLE(usb
, af9005_usb_table
);
1023 static struct dvb_usb_device_properties af9005_properties
= {
1024 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
1026 .usb_ctrl
= DEVICE_SPECIFIC
,
1027 .firmware
= "af9005.fw",
1028 .download_firmware
= af9005_download_firmware
,
1031 .size_of_priv
= sizeof(struct af9005_device_state
),
1039 DVB_USB_ADAP_HAS_PID_FILTER
|
1040 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1041 .pid_filter_count
= 32,
1042 .pid_filter
= af9005_pid_filter
,
1043 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1044 .frontend_attach
= af9005_frontend_attach
,
1045 /* .tuner_attach = af9005_tuner_attach, */
1046 /* parameter for the MPEG2-data transfer */
1053 .buffersize
= 4096, /* actual size seen is 3948 */
1060 .power_ctrl
= af9005_power_ctrl
,
1061 .identify_state
= af9005_identify_state
,
1063 .i2c_algo
= &af9005_i2c_algo
,
1067 .rc_map_table
= NULL
,
1069 .rc_query
= af9005_rc_query
,
1072 .generic_bulk_ctrl_endpoint
= 2,
1073 .generic_bulk_ctrl_endpoint_response
= 1,
1075 .num_device_descs
= 3,
1077 {.name
= "Afatech DVB-T USB1.1 stick",
1078 .cold_ids
= {&af9005_usb_table
[AFATECH_AF9005
], NULL
},
1081 {.name
= "TerraTec Cinergy T USB XE",
1082 .cold_ids
= {&af9005_usb_table
[TERRATEC_AF9005
], NULL
},
1085 {.name
= "Ansonic DVB-T USB1.1 stick",
1086 .cold_ids
= {&af9005_usb_table
[ANSONIC_AF9005
], NULL
},
1093 /* usb specific object needed to register this driver with the usb subsystem */
1094 static struct usb_driver af9005_usb_driver
= {
1095 .name
= "dvb_usb_af9005",
1096 .probe
= af9005_usb_probe
,
1097 .disconnect
= dvb_usb_device_exit
,
1098 .id_table
= af9005_usb_table
,
1102 static int __init
af9005_usb_module_init(void)
1105 if ((result
= usb_register(&af9005_usb_driver
))) {
1106 err("usb_register failed. (%d)", result
);
1109 #if IS_MODULE(CONFIG_DVB_USB_AF9005) || defined(CONFIG_DVB_USB_AF9005_REMOTE)
1110 /* FIXME: convert to todays kernel IR infrastructure */
1111 rc_decode
= symbol_request(af9005_rc_decode
);
1112 rc_keys
= symbol_request(rc_map_af9005_table
);
1113 rc_keys_size
= symbol_request(rc_map_af9005_table_size
);
1115 if (rc_decode
== NULL
|| rc_keys
== NULL
|| rc_keys_size
== NULL
) {
1116 err("af9005_rc_decode function not found, disabling remote");
1117 af9005_properties
.rc
.legacy
.rc_query
= NULL
;
1119 af9005_properties
.rc
.legacy
.rc_map_table
= rc_keys
;
1120 af9005_properties
.rc
.legacy
.rc_map_size
= *rc_keys_size
;
1126 static void __exit
af9005_usb_module_exit(void)
1128 /* release rc decode symbols */
1129 if (rc_decode
!= NULL
)
1130 symbol_put(af9005_rc_decode
);
1131 if (rc_keys
!= NULL
)
1132 symbol_put(rc_map_af9005_table
);
1133 if (rc_keys_size
!= NULL
)
1134 symbol_put(rc_map_af9005_table_size
);
1135 /* deregister this driver from the USB subsystem */
1136 usb_deregister(&af9005_usb_driver
);
1139 module_init(af9005_usb_module_init
);
1140 module_exit(af9005_usb_module_exit
);
1142 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1143 MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1144 MODULE_VERSION("1.0");
1145 MODULE_LICENSE("GPL");