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 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44 /* remote control decoder */
45 int (*rc_decode) (struct dvb_usb_device * d, u8 * data, int len, u32 * event,
50 u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
52 struct af9005_device_state {
57 int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 * wbuf, u16 wlen,
58 u8 * rbuf, u16 rlen, int delay_ms)
60 int actlen, ret = -ENOMEM;
62 if (wbuf == NULL || wlen == 0)
65 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
69 debug_dump(wbuf, wlen, deb_xfer);
71 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
76 err("bulk message failed: %d (%d/%d)", ret, wlen, actlen);
78 ret = actlen != wlen ? -1 : 0;
80 /* an answer is expected, and no error before */
81 if (!ret && rbuf && rlen) {
85 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
90 err("recv bulk message failed: %d", ret);
93 debug_dump(rbuf, actlen, deb_xfer);
97 mutex_unlock(&d->usb_mutex);
101 int af9005_usb_generic_write(struct dvb_usb_device *d, u8 * buf, u16 len)
103 return af9005_usb_generic_rw(d, buf, len, NULL, 0, 0);
106 int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
107 int readwrite, int type, u8 * values, int len)
109 struct af9005_device_state *st = d->priv;
117 err("generic read/write, less than 1 byte. Makes no sense.");
121 err("generic read/write, more than 8 bytes. Not supported.");
125 obuf[0] = 14; /* rest of buffer length low */
126 obuf[1] = 0; /* rest of buffer length high */
128 obuf[2] = AF9005_REGISTER_RW; /* register operation */
129 obuf[3] = 12; /* rest of buffer length */
131 obuf[4] = st->sequence++; /* sequence number */
133 obuf[5] = (u8) (reg >> 8); /* register address */
134 obuf[6] = (u8) (reg & 0xff);
136 if (type == AF9005_OFDM_REG) {
137 command = AF9005_CMD_OFDM_REG;
139 command = AF9005_CMD_TUNER;
144 AF9005_CMD_BURST | AF9005_CMD_AUTOINC | (len - 1) << 3;
145 command |= readwrite;
146 if (readwrite == AF9005_CMD_WRITE)
147 for (i = 0; i < len; i++)
148 obuf[8 + i] = values[i];
149 else if (type == AF9005_TUNER_REG)
150 /* read command for tuner, the first byte contains the i2c address */
154 ret = af9005_usb_generic_rw(d, obuf, 16, ibuf, 17, 0);
159 if (ibuf[2] != AF9005_REGISTER_RW_ACK) {
160 err("generic read/write, wrong reply code.");
163 if (ibuf[3] != 0x0d) {
164 err("generic read/write, wrong length in reply.");
167 if (ibuf[4] != obuf[4]) {
168 err("generic read/write, wrong sequence in reply.");
172 Windows driver doesn't check these fields, in fact sometimes
173 the register in the reply is different that what has been sent
175 if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) {
176 err("generic read/write, wrong register in reply.");
179 if (ibuf[7] != command) {
180 err("generic read/write wrong command in reply.");
184 if (ibuf[16] != 0x01) {
185 err("generic read/write wrong status code in reply.");
188 if (readwrite == AF9005_CMD_READ)
189 for (i = 0; i < len; i++)
190 values[i] = ibuf[8 + i];
196 int af9005_read_ofdm_register(struct dvb_usb_device *d, u16 reg, u8 * value)
199 deb_reg("read register %x ", reg);
200 ret = af9005_generic_read_write(d, reg,
201 AF9005_CMD_READ, AF9005_OFDM_REG,
206 deb_reg("value %x\n", *value);
210 int af9005_read_ofdm_registers(struct dvb_usb_device *d, u16 reg,
211 u8 * values, int len)
214 deb_reg("read %d registers %x ", len, reg);
215 ret = af9005_generic_read_write(d, reg,
216 AF9005_CMD_READ, AF9005_OFDM_REG,
221 debug_dump(values, len, deb_reg);
225 int af9005_write_ofdm_register(struct dvb_usb_device *d, u16 reg, u8 value)
229 deb_reg("write register %x value %x ", reg, value);
230 ret = af9005_generic_read_write(d, reg,
231 AF9005_CMD_WRITE, AF9005_OFDM_REG,
240 int af9005_write_ofdm_registers(struct dvb_usb_device *d, u16 reg,
241 u8 * values, int len)
244 deb_reg("write %d registers %x values ", len, reg);
245 debug_dump(values, len, deb_reg);
247 ret = af9005_generic_read_write(d, reg,
248 AF9005_CMD_WRITE, AF9005_OFDM_REG,
257 int af9005_read_register_bits(struct dvb_usb_device *d, u16 reg, u8 pos,
262 deb_reg("read bits %x %x %x", reg, pos, len);
263 ret = af9005_read_ofdm_register(d, reg, &temp);
265 deb_reg(" failed\n");
268 *value = (temp >> pos) & regmask[len - 1];
269 deb_reg(" value %x\n", *value);
274 int af9005_write_register_bits(struct dvb_usb_device *d, u16 reg, u8 pos,
279 deb_reg("write bits %x %x %x value %x\n", reg, pos, len, value);
280 if (pos == 0 && len == 8)
281 return af9005_write_ofdm_register(d, reg, value);
282 ret = af9005_read_ofdm_register(d, reg, &temp);
285 mask = regmask[len - 1] << pos;
286 temp = (temp & ~mask) | ((value << pos) & mask);
287 return af9005_write_ofdm_register(d, reg, temp);
291 static int af9005_usb_read_tuner_registers(struct dvb_usb_device *d,
292 u16 reg, u8 * values, int len)
294 return af9005_generic_read_write(d, reg,
295 AF9005_CMD_READ, AF9005_TUNER_REG,
299 static int af9005_usb_write_tuner_registers(struct dvb_usb_device *d,
300 u16 reg, u8 * values, int len)
302 return af9005_generic_read_write(d, reg,
304 AF9005_TUNER_REG, values, len);
307 int af9005_write_tuner_registers(struct dvb_usb_device *d, u16 reg,
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 */
313 int ret, i, done = 0, fail = 0;
315 ret = af9005_usb_write_tuner_registers(d, reg, values, len);
319 /* check if write done (0xa40d bit 1) or fail (0xa40d bit 2) */
320 for (i = 0; i < 200; i++) {
322 af9005_read_ofdm_register(d,
323 xd_I2C_i2c_m_status_wdat_done,
327 done = temp & (regmask[i2c_m_status_wdat_done_len - 1]
328 << i2c_m_status_wdat_done_pos);
331 fail = temp & (regmask[i2c_m_status_wdat_fail_len - 1]
332 << i2c_m_status_wdat_fail_pos);
340 /* clear write fail bit */
341 af9005_write_register_bits(d,
342 xd_I2C_i2c_m_status_wdat_fail,
343 i2c_m_status_wdat_fail_pos,
344 i2c_m_status_wdat_fail_len,
348 /* clear write done bit */
350 af9005_write_register_bits(d,
351 xd_I2C_i2c_m_status_wdat_fail,
352 i2c_m_status_wdat_done_pos,
353 i2c_m_status_wdat_done_len, 1);
360 int af9005_read_tuner_registers(struct dvb_usb_device *d, u16 reg, u8 addr,
361 u8 * values, int len)
363 /* don't let the name of this function mislead you: it's just used
364 as an interface from the firmware to the i2c bus. The actual
365 i2c addresses are contained in the data */
369 buf[0] = addr; /* tuner i2c address */
370 buf[1] = values[0]; /* tuner register */
372 values[0] = addr + 0x01; /* i2c read address */
374 if (reg == APO_REG_I2C_RW_SILICON_TUNER) {
375 /* write tuner i2c address to tuner, 0c00c0 undocumented, found by sniffing */
376 ret = af9005_write_tuner_registers(d, 0x00c0, buf, 2);
381 /* send read command to ofsm */
382 ret = af9005_usb_read_tuner_registers(d, reg, values, 1);
386 /* check if read done */
387 for (i = 0; i < 200; i++) {
388 ret = af9005_read_ofdm_register(d, 0xa408, &temp);
398 /* clear read done bit (by writing 1) */
399 ret = af9005_write_ofdm_register(d, xd_I2C_i2c_m_data8, 1);
403 /* get read data (available from 0xa400) */
404 for (i = 0; i < len; i++) {
405 ret = af9005_read_ofdm_register(d, 0xa400 + i, &temp);
413 static int af9005_i2c_write(struct dvb_usb_device *d, u8 i2caddr, u8 reg,
418 deb_i2c("i2c_write i2caddr %x, reg %x, len %d data ", i2caddr,
420 debug_dump(data, len, deb_i2c);
422 for (i = 0; i < len; i++) {
424 buf[1] = reg + (u8) i;
427 af9005_write_tuner_registers(d,
428 APO_REG_I2C_RW_SILICON_TUNER,
431 deb_i2c("i2c_write failed\n");
435 deb_i2c("i2c_write ok\n");
439 static int af9005_i2c_read(struct dvb_usb_device *d, u8 i2caddr, u8 reg,
444 deb_i2c("i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr, reg, len);
445 for (i = 0; i < len; i++) {
448 af9005_read_tuner_registers(d,
449 APO_REG_I2C_RW_SILICON_TUNER,
452 deb_i2c("i2c_read failed\n");
457 deb_i2c("i2c data read: ");
458 debug_dump(data, len, deb_i2c);
462 static int af9005_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
465 /* only implements what the mt2060 module does, don't know how
466 to make it really generic */
467 struct dvb_usb_device *d = i2c_get_adapdata(adap);
472 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
476 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
479 /* reads a single register */
483 ret = af9005_i2c_read(d, addr, reg, value, 1);
487 /* write one or more registers */
490 value = &msg[0].buf[1];
491 ret = af9005_i2c_write(d, addr, reg, value, msg[0].len - 1);
496 mutex_unlock(&d->i2c_mutex);
500 static u32 af9005_i2c_func(struct i2c_adapter *adapter)
505 static struct i2c_algorithm af9005_i2c_algo = {
506 .master_xfer = af9005_i2c_xfer,
507 .functionality = af9005_i2c_func,
510 int af9005_send_command(struct dvb_usb_device *d, u8 command, u8 * wbuf,
511 int wlen, u8 * rbuf, int rlen)
513 struct af9005_device_state *st = d->priv;
515 int ret, i, packet_len;
520 err("send command, wlen less than 0 bytes. Makes no sense.");
524 err("send command, wlen more than 54 bytes. Not supported.");
528 err("send command, rlen more than 54 bytes. Not supported.");
531 packet_len = wlen + 5;
532 buf[0] = (u8) (packet_len & 0xff);
533 buf[1] = (u8) ((packet_len & 0xff00) >> 8);
535 buf[2] = 0x26; /* packet type */
537 buf[4] = st->sequence++;
540 for (i = 0; i < wlen; i++)
541 buf[7 + i] = wbuf[i];
542 ret = af9005_usb_generic_rw(d, buf, wlen + 7, ibuf, rlen + 7, 0);
545 if (ibuf[2] != 0x27) {
546 err("send command, wrong reply code.");
549 if (ibuf[4] != buf[4]) {
550 err("send command, wrong sequence in reply.");
553 if (ibuf[5] != 0x01) {
554 err("send command, wrong status code in reply.");
557 if (ibuf[6] != rlen) {
558 err("send command, invalid data length in reply.");
561 for (i = 0; i < rlen; i++)
562 rbuf[i] = ibuf[i + 7];
566 int af9005_read_eeprom(struct dvb_usb_device *d, u8 address, u8 * values,
569 struct af9005_device_state *st = d->priv;
570 u8 obuf[16], ibuf[14];
573 memset(obuf, 0, sizeof(obuf));
574 memset(ibuf, 0, sizeof(ibuf));
576 obuf[0] = 14; /* length of rest of packet low */
577 obuf[1] = 0; /* length of rest of packer high */
579 obuf[2] = 0x2a; /* read/write eeprom */
581 obuf[3] = 12; /* size */
583 obuf[4] = st->sequence++;
585 obuf[5] = 0; /* read */
589 ret = af9005_usb_generic_rw(d, obuf, 16, ibuf, 14, 0);
592 if (ibuf[2] != 0x2b) {
593 err("Read eeprom, invalid reply code");
597 err("Read eeprom, invalid reply length");
600 if (ibuf[4] != obuf[4]) {
601 err("Read eeprom, wrong sequence in reply ");
605 err("Read eeprom, wrong status in reply ");
608 for (i = 0; i < len; i++) {
609 values[i] = ibuf[6 + i];
614 static int af9005_boot_packet(struct usb_device *udev, int type, u8 * reply)
616 u8 buf[FW_BULKOUT_SIZE + 2];
619 memset(buf, 0, sizeof(buf));
620 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
621 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff);
626 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
628 checksum = buf[4] + buf[5];
629 buf[6] = (u8) ((checksum >> 8) & 0xff);
630 buf[7] = (u8) (checksum & 0xff);
635 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
637 checksum = buf[4] + buf[5];
638 buf[6] = (u8) ((checksum >> 8) & 0xff);
639 buf[7] = (u8) (checksum & 0xff);
644 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
651 for (i = 4; i <= 9; i++)
653 buf[10] = (u8) ((checksum >> 8) & 0xff);
654 buf[11] = (u8) (checksum & 0xff);
657 err("boot packet invalid boot packet type");
661 debug_dump(buf, FW_BULKOUT_SIZE + 2, deb_fw);
663 ret = usb_bulk_msg(udev,
664 usb_sndbulkpipe(udev, 0x02),
665 buf, FW_BULKOUT_SIZE + 2, &act_len, 2000);
667 err("boot packet bulk message failed: %d (%d/%d)", ret,
668 FW_BULKOUT_SIZE + 2, act_len);
670 ret = act_len != FW_BULKOUT_SIZE + 2 ? -1 : 0;
674 ret = usb_bulk_msg(udev,
675 usb_rcvbulkpipe(udev, 0x01), buf, 9, &act_len, 2000);
677 err("boot packet recv bulk message failed: %d", ret);
681 debug_dump(buf, act_len, deb_fw);
685 if (buf[2] != 0x11) {
686 err("boot bad config header.");
689 if (buf[3] != 0x05) {
690 err("boot bad config size.");
693 if (buf[4] != 0x00) {
694 err("boot bad config sequence.");
697 if (buf[5] != 0x04) {
698 err("boot bad config subtype.");
701 for (i = 4; i <= 6; i++)
703 if (buf[7] * 256 + buf[8] != checksum) {
704 err("boot bad config checksum.");
710 if (buf[2] != 0x11) {
711 err("boot bad confirm header.");
714 if (buf[3] != 0x05) {
715 err("boot bad confirm size.");
718 if (buf[4] != 0x00) {
719 err("boot bad confirm sequence.");
722 if (buf[5] != 0x02) {
723 err("boot bad confirm subtype.");
726 for (i = 4; i <= 6; i++)
728 if (buf[7] * 256 + buf[8] != checksum) {
729 err("boot bad confirm checksum.");
735 if (buf[2] != 0x10) {
736 err("boot bad boot header.");
739 if (buf[3] != 0x05) {
740 err("boot bad boot size.");
743 if (buf[4] != 0x00) {
744 err("boot bad boot sequence.");
747 if (buf[5] != 0x01) {
748 err("boot bad boot pattern 01.");
751 if (buf[6] != 0x10) {
752 err("boot bad boot pattern 10.");
755 for (i = 4; i <= 6; i++)
757 if (buf[7] * 256 + buf[8] != checksum) {
758 err("boot bad boot checksum.");
768 int af9005_download_firmware(struct usb_device *udev, const struct firmware *fw)
770 int i, packets, ret, act_len;
772 u8 buf[FW_BULKOUT_SIZE + 2];
775 ret = af9005_boot_packet(udev, FW_CONFIG, &reply);
779 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply);
782 packets = fw->size / FW_BULKOUT_SIZE;
783 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
784 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff);
785 for (i = 0; i < packets; i++) {
786 memcpy(&buf[2], fw->data + i * FW_BULKOUT_SIZE,
789 debug_dump(buf, FW_BULKOUT_SIZE + 2, deb_fw);
790 ret = usb_bulk_msg(udev,
791 usb_sndbulkpipe(udev, 0x02),
792 buf, FW_BULKOUT_SIZE + 2, &act_len, 1000);
794 err("firmware download failed at packet %d with code %d", i, ret);
798 ret = af9005_boot_packet(udev, FW_CONFIRM, &reply);
801 if (reply != (u8) (packets & 0xff)) {
802 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets & 0xff, reply);
805 ret = af9005_boot_packet(udev, FW_BOOT, &reply);
808 ret = af9005_boot_packet(udev, FW_CONFIG, &reply);
812 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply);
820 int af9005_led_control(struct dvb_usb_device *d, int onoff)
822 struct af9005_device_state *st = d->priv;
825 if (onoff && dvb_usb_af9005_led)
829 if (st->led_state != temp) {
831 af9005_write_register_bits(d, xd_p_reg_top_locken1,
833 reg_top_locken1_len, temp);
837 af9005_write_register_bits(d, xd_p_reg_top_lock1,
839 reg_top_lock1_len, temp);
842 st->led_state = temp;
847 static int af9005_frontend_attach(struct dvb_usb_adapter *adap)
852 /* without these calls the first commands after downloading
853 the firmware fail. I put these calls here to simulate
854 what it is done in dvb-usb-init.c.
856 struct usb_device *udev = adap->dev->udev;
857 usb_clear_halt(udev, usb_sndbulkpipe(udev, 2));
858 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 1));
859 if (dvb_usb_af9005_dump_eeprom) {
860 printk("EEPROM DUMP\n");
861 for (i = 0; i < 255; i += 8) {
862 af9005_read_eeprom(adap->dev, i, buf, 8);
863 printk("ADDR %x ", i);
864 debug_dump(buf, 8, printk);
867 adap->fe = af9005_fe_attach(adap->dev);
871 static int af9005_rc_query(struct dvb_usb_device *d, u32 * event, int *state)
873 struct af9005_device_state *st = d->priv;
879 *state = REMOTE_NO_KEY_PRESSED;
880 if (rc_decode == NULL) {
881 /* it shouldn't never come here */
884 /* deb_info("rc_query\n"); */
885 obuf[0] = 3; /* rest of packet length low */
886 obuf[1] = 0; /* rest of packet lentgh high */
887 obuf[2] = 0x40; /* read remote */
888 obuf[3] = 1; /* rest of packet length */
889 obuf[4] = st->sequence++; /* sequence number */
890 ret = af9005_usb_generic_rw(d, obuf, 5, ibuf, 256, 0);
892 err("rc query failed");
895 if (ibuf[2] != 0x41) {
896 err("rc query bad header.");
899 if (ibuf[4] != obuf[4]) {
900 err("rc query bad sequence.");
905 err("rc query invalid length");
909 deb_rc("rc data (%d) ", len);
910 debug_dump((ibuf + 6), len, deb_rc);
911 ret = rc_decode(d, &ibuf[6], len, event, state);
913 err("rc_decode failed");
916 deb_rc("rc_decode state %x event %x\n", *state, *event);
917 if (*state == REMOTE_KEY_REPEAT)
918 *event = d->last_event;
924 static int af9005_power_ctrl(struct dvb_usb_device *d, int onoff)
930 static int af9005_pid_filter_control(struct dvb_usb_adapter *adap, int onoff)
933 deb_info("pid filter control onoff %d\n", onoff);
936 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 1);
940 af9005_write_register_bits(adap->dev,
941 XD_MP2IF_DMX_CTRL, 1, 1, 1);
945 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 1);
948 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 0);
951 deb_info("pid filter control ok\n");
955 static int af9005_pid_filter(struct dvb_usb_adapter *adap, int index,
958 u8 cmd = index & 0x1f;
960 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index,
963 /* cannot use it as pid_filter_ctrl since it has to be done
964 before setting the first pid */
965 if (adap->feedcount == 1) {
966 deb_info("first pid set, enable pid table\n");
967 ret = af9005_pid_filter_control(adap, onoff);
972 af9005_write_ofdm_register(adap->dev,
978 af9005_write_ofdm_register(adap->dev,
985 if (adap->feedcount == 0) {
986 deb_info("last pid unset, disable pid table\n");
987 ret = af9005_pid_filter_control(adap, onoff);
992 ret = af9005_write_ofdm_register(adap->dev, XD_MP2IF_PID_IDX, cmd);
995 deb_info("set pid ok\n");
999 static int af9005_identify_state(struct usb_device *udev,
1000 struct dvb_usb_device_properties *props,
1001 struct dvb_usb_device_description **desc,
1006 ret = af9005_boot_packet(udev, FW_CONFIG, &reply);
1009 deb_info("result of FW_CONFIG in identify state %d\n", reply);
1012 else if (reply == 0x02)
1016 deb_info("Identify state cold = %d\n", *cold);
1020 static struct dvb_usb_device_properties af9005_properties;
1022 static int af9005_usb_probe(struct usb_interface *intf,
1023 const struct usb_device_id *id)
1025 return dvb_usb_device_init(intf, &af9005_properties,
1026 THIS_MODULE, NULL, adapter_nr);
1029 static struct usb_device_id af9005_usb_table[] = {
1030 {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9005)},
1031 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE)},
1032 {USB_DEVICE(USB_VID_ANSONIC, USB_PID_ANSONIC_DVBT_USB)},
1036 MODULE_DEVICE_TABLE(usb, af9005_usb_table);
1038 static struct dvb_usb_device_properties af9005_properties = {
1039 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1041 .usb_ctrl = DEVICE_SPECIFIC,
1042 .firmware = "af9005.fw",
1043 .download_firmware = af9005_download_firmware,
1046 .size_of_priv = sizeof(struct af9005_device_state),
1052 DVB_USB_ADAP_HAS_PID_FILTER |
1053 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1054 .pid_filter_count = 32,
1055 .pid_filter = af9005_pid_filter,
1056 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1057 .frontend_attach = af9005_frontend_attach,
1058 /* .tuner_attach = af9005_tuner_attach, */
1059 /* parameter for the MPEG2-data transfer */
1066 .buffersize = 4096, /* actual size seen is 3948 */
1072 .power_ctrl = af9005_power_ctrl,
1073 .identify_state = af9005_identify_state,
1075 .i2c_algo = &af9005_i2c_algo,
1079 .rc_key_map_size = 0,
1080 .rc_query = af9005_rc_query,
1082 .num_device_descs = 3,
1084 {.name = "Afatech DVB-T USB1.1 stick",
1085 .cold_ids = {&af9005_usb_table[0], NULL},
1088 {.name = "TerraTec Cinergy T USB XE",
1089 .cold_ids = {&af9005_usb_table[1], NULL},
1092 {.name = "Ansonic DVB-T USB1.1 stick",
1093 .cold_ids = {&af9005_usb_table[2], NULL},
1100 /* usb specific object needed to register this driver with the usb subsystem */
1101 static struct usb_driver af9005_usb_driver = {
1102 .name = "dvb_usb_af9005",
1103 .probe = af9005_usb_probe,
1104 .disconnect = dvb_usb_device_exit,
1105 .id_table = af9005_usb_table,
1109 static int __init af9005_usb_module_init(void)
1112 if ((result = usb_register(&af9005_usb_driver))) {
1113 err("usb_register failed. (%d)", result);
1116 rc_decode = symbol_request(af9005_rc_decode);
1117 rc_keys = symbol_request(af9005_rc_keys);
1118 rc_keys_size = symbol_request(af9005_rc_keys_size);
1119 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
1120 err("af9005_rc_decode function not found, disabling remote");
1121 af9005_properties.rc_query = NULL;
1123 af9005_properties.rc_key_map = rc_keys;
1124 af9005_properties.rc_key_map_size = *rc_keys_size;
1130 static void __exit af9005_usb_module_exit(void)
1132 /* release rc decode symbols */
1133 if (rc_decode != NULL)
1134 symbol_put(af9005_rc_decode);
1135 if (rc_keys != NULL)
1136 symbol_put(af9005_rc_keys);
1137 if (rc_keys_size != NULL)
1138 symbol_put(af9005_rc_keys_size);
1139 /* deregister this driver from the USB subsystem */
1140 usb_deregister(&af9005_usb_driver);
1143 module_init(af9005_usb_module_init);
1144 module_exit(af9005_usb_module_exit);
1146 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1147 MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1148 MODULE_VERSION("1.0");
1149 MODULE_LICENSE("GPL");