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_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 static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
102 int readwrite, int type, u8 * values, int len)
104 struct af9005_device_state *st = d->priv;
112 err("generic read/write, less than 1 byte. Makes no sense.");
116 err("generic read/write, more than 8 bytes. Not supported.");
120 obuf[0] = 14; /* rest of buffer length low */
121 obuf[1] = 0; /* rest of buffer length high */
123 obuf[2] = AF9005_REGISTER_RW; /* register operation */
124 obuf[3] = 12; /* rest of buffer length */
126 obuf[4] = st->sequence++; /* sequence number */
128 obuf[5] = (u8) (reg >> 8); /* register address */
129 obuf[6] = (u8) (reg & 0xff);
131 if (type == AF9005_OFDM_REG) {
132 command = AF9005_CMD_OFDM_REG;
134 command = AF9005_CMD_TUNER;
139 AF9005_CMD_BURST | AF9005_CMD_AUTOINC | (len - 1) << 3;
140 command |= readwrite;
141 if (readwrite == AF9005_CMD_WRITE)
142 for (i = 0; i < len; i++)
143 obuf[8 + i] = values[i];
144 else if (type == AF9005_TUNER_REG)
145 /* read command for tuner, the first byte contains the i2c address */
149 ret = af9005_usb_generic_rw(d, obuf, 16, ibuf, 17, 0);
154 if (ibuf[2] != AF9005_REGISTER_RW_ACK) {
155 err("generic read/write, wrong reply code.");
158 if (ibuf[3] != 0x0d) {
159 err("generic read/write, wrong length in reply.");
162 if (ibuf[4] != obuf[4]) {
163 err("generic read/write, wrong sequence in reply.");
167 Windows driver doesn't check these fields, in fact sometimes
168 the register in the reply is different that what has been sent
170 if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) {
171 err("generic read/write, wrong register in reply.");
174 if (ibuf[7] != command) {
175 err("generic read/write wrong command in reply.");
179 if (ibuf[16] != 0x01) {
180 err("generic read/write wrong status code in reply.");
183 if (readwrite == AF9005_CMD_READ)
184 for (i = 0; i < len; i++)
185 values[i] = ibuf[8 + i];
191 int af9005_read_ofdm_register(struct dvb_usb_device *d, u16 reg, u8 * value)
194 deb_reg("read register %x ", reg);
195 ret = af9005_generic_read_write(d, reg,
196 AF9005_CMD_READ, AF9005_OFDM_REG,
201 deb_reg("value %x\n", *value);
205 int af9005_read_ofdm_registers(struct dvb_usb_device *d, u16 reg,
206 u8 * values, int len)
209 deb_reg("read %d registers %x ", len, reg);
210 ret = af9005_generic_read_write(d, reg,
211 AF9005_CMD_READ, AF9005_OFDM_REG,
216 debug_dump(values, len, deb_reg);
220 int af9005_write_ofdm_register(struct dvb_usb_device *d, u16 reg, u8 value)
224 deb_reg("write register %x value %x ", reg, value);
225 ret = af9005_generic_read_write(d, reg,
226 AF9005_CMD_WRITE, AF9005_OFDM_REG,
235 int af9005_write_ofdm_registers(struct dvb_usb_device *d, u16 reg,
236 u8 * values, int len)
239 deb_reg("write %d registers %x values ", len, reg);
240 debug_dump(values, len, deb_reg);
242 ret = af9005_generic_read_write(d, reg,
243 AF9005_CMD_WRITE, AF9005_OFDM_REG,
252 int af9005_read_register_bits(struct dvb_usb_device *d, u16 reg, u8 pos,
257 deb_reg("read bits %x %x %x", reg, pos, len);
258 ret = af9005_read_ofdm_register(d, reg, &temp);
260 deb_reg(" failed\n");
263 *value = (temp >> pos) & regmask[len - 1];
264 deb_reg(" value %x\n", *value);
269 int af9005_write_register_bits(struct dvb_usb_device *d, u16 reg, u8 pos,
274 deb_reg("write bits %x %x %x value %x\n", reg, pos, len, value);
275 if (pos == 0 && len == 8)
276 return af9005_write_ofdm_register(d, reg, value);
277 ret = af9005_read_ofdm_register(d, reg, &temp);
280 mask = regmask[len - 1] << pos;
281 temp = (temp & ~mask) | ((value << pos) & mask);
282 return af9005_write_ofdm_register(d, reg, temp);
286 static int af9005_usb_read_tuner_registers(struct dvb_usb_device *d,
287 u16 reg, u8 * values, int len)
289 return af9005_generic_read_write(d, reg,
290 AF9005_CMD_READ, AF9005_TUNER_REG,
294 static int af9005_usb_write_tuner_registers(struct dvb_usb_device *d,
295 u16 reg, u8 * values, int len)
297 return af9005_generic_read_write(d, reg,
299 AF9005_TUNER_REG, values, len);
302 int af9005_write_tuner_registers(struct dvb_usb_device *d, u16 reg,
303 u8 * values, int len)
305 /* don't let the name of this function mislead you: it's just used
306 as an interface from the firmware to the i2c bus. The actual
307 i2c addresses are contained in the data */
308 int ret, i, done = 0, fail = 0;
310 ret = af9005_usb_write_tuner_registers(d, reg, values, len);
314 /* check if write done (0xa40d bit 1) or fail (0xa40d bit 2) */
315 for (i = 0; i < 200; i++) {
317 af9005_read_ofdm_register(d,
318 xd_I2C_i2c_m_status_wdat_done,
322 done = temp & (regmask[i2c_m_status_wdat_done_len - 1]
323 << i2c_m_status_wdat_done_pos);
326 fail = temp & (regmask[i2c_m_status_wdat_fail_len - 1]
327 << i2c_m_status_wdat_fail_pos);
335 /* clear write fail bit */
336 af9005_write_register_bits(d,
337 xd_I2C_i2c_m_status_wdat_fail,
338 i2c_m_status_wdat_fail_pos,
339 i2c_m_status_wdat_fail_len,
343 /* clear write done bit */
345 af9005_write_register_bits(d,
346 xd_I2C_i2c_m_status_wdat_fail,
347 i2c_m_status_wdat_done_pos,
348 i2c_m_status_wdat_done_len, 1);
355 int af9005_read_tuner_registers(struct dvb_usb_device *d, u16 reg, u8 addr,
356 u8 * values, int len)
358 /* don't let the name of this function mislead you: it's just used
359 as an interface from the firmware to the i2c bus. The actual
360 i2c addresses are contained in the data */
364 buf[0] = addr; /* tuner i2c address */
365 buf[1] = values[0]; /* tuner register */
367 values[0] = addr + 0x01; /* i2c read address */
369 if (reg == APO_REG_I2C_RW_SILICON_TUNER) {
370 /* write tuner i2c address to tuner, 0c00c0 undocumented, found by sniffing */
371 ret = af9005_write_tuner_registers(d, 0x00c0, buf, 2);
376 /* send read command to ofsm */
377 ret = af9005_usb_read_tuner_registers(d, reg, values, 1);
381 /* check if read done */
382 for (i = 0; i < 200; i++) {
383 ret = af9005_read_ofdm_register(d, 0xa408, &temp);
393 /* clear read done bit (by writing 1) */
394 ret = af9005_write_ofdm_register(d, xd_I2C_i2c_m_data8, 1);
398 /* get read data (available from 0xa400) */
399 for (i = 0; i < len; i++) {
400 ret = af9005_read_ofdm_register(d, 0xa400 + i, &temp);
408 static int af9005_i2c_write(struct dvb_usb_device *d, u8 i2caddr, u8 reg,
413 deb_i2c("i2c_write i2caddr %x, reg %x, len %d data ", i2caddr,
415 debug_dump(data, len, deb_i2c);
417 for (i = 0; i < len; i++) {
419 buf[1] = reg + (u8) i;
422 af9005_write_tuner_registers(d,
423 APO_REG_I2C_RW_SILICON_TUNER,
426 deb_i2c("i2c_write failed\n");
430 deb_i2c("i2c_write ok\n");
434 static int af9005_i2c_read(struct dvb_usb_device *d, u8 i2caddr, u8 reg,
439 deb_i2c("i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr, reg, len);
440 for (i = 0; i < len; i++) {
443 af9005_read_tuner_registers(d,
444 APO_REG_I2C_RW_SILICON_TUNER,
447 deb_i2c("i2c_read failed\n");
452 deb_i2c("i2c data read: ");
453 debug_dump(data, len, deb_i2c);
457 static int af9005_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
460 /* only implements what the mt2060 module does, don't know how
461 to make it really generic */
462 struct dvb_usb_device *d = i2c_get_adapdata(adap);
467 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
471 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
474 /* reads a single register */
478 ret = af9005_i2c_read(d, addr, reg, value, 1);
482 /* write one or more registers */
485 value = &msg[0].buf[1];
486 ret = af9005_i2c_write(d, addr, reg, value, msg[0].len - 1);
491 mutex_unlock(&d->i2c_mutex);
495 static u32 af9005_i2c_func(struct i2c_adapter *adapter)
500 static struct i2c_algorithm af9005_i2c_algo = {
501 .master_xfer = af9005_i2c_xfer,
502 .functionality = af9005_i2c_func,
505 int af9005_send_command(struct dvb_usb_device *d, u8 command, u8 * wbuf,
506 int wlen, u8 * rbuf, int rlen)
508 struct af9005_device_state *st = d->priv;
510 int ret, i, packet_len;
515 err("send command, wlen less than 0 bytes. Makes no sense.");
519 err("send command, wlen more than 54 bytes. Not supported.");
523 err("send command, rlen more than 54 bytes. Not supported.");
526 packet_len = wlen + 5;
527 buf[0] = (u8) (packet_len & 0xff);
528 buf[1] = (u8) ((packet_len & 0xff00) >> 8);
530 buf[2] = 0x26; /* packet type */
532 buf[4] = st->sequence++;
535 for (i = 0; i < wlen; i++)
536 buf[7 + i] = wbuf[i];
537 ret = af9005_usb_generic_rw(d, buf, wlen + 7, ibuf, rlen + 7, 0);
540 if (ibuf[2] != 0x27) {
541 err("send command, wrong reply code.");
544 if (ibuf[4] != buf[4]) {
545 err("send command, wrong sequence in reply.");
548 if (ibuf[5] != 0x01) {
549 err("send command, wrong status code in reply.");
552 if (ibuf[6] != rlen) {
553 err("send command, invalid data length in reply.");
556 for (i = 0; i < rlen; i++)
557 rbuf[i] = ibuf[i + 7];
561 int af9005_read_eeprom(struct dvb_usb_device *d, u8 address, u8 * values,
564 struct af9005_device_state *st = d->priv;
565 u8 obuf[16], ibuf[14];
568 memset(obuf, 0, sizeof(obuf));
569 memset(ibuf, 0, sizeof(ibuf));
571 obuf[0] = 14; /* length of rest of packet low */
572 obuf[1] = 0; /* length of rest of packer high */
574 obuf[2] = 0x2a; /* read/write eeprom */
576 obuf[3] = 12; /* size */
578 obuf[4] = st->sequence++;
580 obuf[5] = 0; /* read */
584 ret = af9005_usb_generic_rw(d, obuf, 16, ibuf, 14, 0);
587 if (ibuf[2] != 0x2b) {
588 err("Read eeprom, invalid reply code");
592 err("Read eeprom, invalid reply length");
595 if (ibuf[4] != obuf[4]) {
596 err("Read eeprom, wrong sequence in reply ");
600 err("Read eeprom, wrong status in reply ");
603 for (i = 0; i < len; i++) {
604 values[i] = ibuf[6 + i];
609 static int af9005_boot_packet(struct usb_device *udev, int type, u8 * reply)
611 u8 buf[FW_BULKOUT_SIZE + 2];
614 memset(buf, 0, sizeof(buf));
615 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
616 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff);
621 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
623 checksum = buf[4] + buf[5];
624 buf[6] = (u8) ((checksum >> 8) & 0xff);
625 buf[7] = (u8) (checksum & 0xff);
630 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
632 checksum = buf[4] + buf[5];
633 buf[6] = (u8) ((checksum >> 8) & 0xff);
634 buf[7] = (u8) (checksum & 0xff);
639 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
646 for (i = 4; i <= 9; i++)
648 buf[10] = (u8) ((checksum >> 8) & 0xff);
649 buf[11] = (u8) (checksum & 0xff);
652 err("boot packet invalid boot packet type");
656 debug_dump(buf, FW_BULKOUT_SIZE + 2, deb_fw);
658 ret = usb_bulk_msg(udev,
659 usb_sndbulkpipe(udev, 0x02),
660 buf, FW_BULKOUT_SIZE + 2, &act_len, 2000);
662 err("boot packet bulk message failed: %d (%d/%d)", ret,
663 FW_BULKOUT_SIZE + 2, act_len);
665 ret = act_len != FW_BULKOUT_SIZE + 2 ? -1 : 0;
669 ret = usb_bulk_msg(udev,
670 usb_rcvbulkpipe(udev, 0x01), buf, 9, &act_len, 2000);
672 err("boot packet recv bulk message failed: %d", ret);
676 debug_dump(buf, act_len, deb_fw);
680 if (buf[2] != 0x11) {
681 err("boot bad config header.");
684 if (buf[3] != 0x05) {
685 err("boot bad config size.");
688 if (buf[4] != 0x00) {
689 err("boot bad config sequence.");
692 if (buf[5] != 0x04) {
693 err("boot bad config subtype.");
696 for (i = 4; i <= 6; i++)
698 if (buf[7] * 256 + buf[8] != checksum) {
699 err("boot bad config checksum.");
705 if (buf[2] != 0x11) {
706 err("boot bad confirm header.");
709 if (buf[3] != 0x05) {
710 err("boot bad confirm size.");
713 if (buf[4] != 0x00) {
714 err("boot bad confirm sequence.");
717 if (buf[5] != 0x02) {
718 err("boot bad confirm subtype.");
721 for (i = 4; i <= 6; i++)
723 if (buf[7] * 256 + buf[8] != checksum) {
724 err("boot bad confirm checksum.");
730 if (buf[2] != 0x10) {
731 err("boot bad boot header.");
734 if (buf[3] != 0x05) {
735 err("boot bad boot size.");
738 if (buf[4] != 0x00) {
739 err("boot bad boot sequence.");
742 if (buf[5] != 0x01) {
743 err("boot bad boot pattern 01.");
746 if (buf[6] != 0x10) {
747 err("boot bad boot pattern 10.");
750 for (i = 4; i <= 6; i++)
752 if (buf[7] * 256 + buf[8] != checksum) {
753 err("boot bad boot checksum.");
763 static int af9005_download_firmware(struct usb_device *udev, const struct firmware *fw)
765 int i, packets, ret, act_len;
767 u8 buf[FW_BULKOUT_SIZE + 2];
770 ret = af9005_boot_packet(udev, FW_CONFIG, &reply);
774 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply);
777 packets = fw->size / FW_BULKOUT_SIZE;
778 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
779 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff);
780 for (i = 0; i < packets; i++) {
781 memcpy(&buf[2], fw->data + i * FW_BULKOUT_SIZE,
784 debug_dump(buf, FW_BULKOUT_SIZE + 2, deb_fw);
785 ret = usb_bulk_msg(udev,
786 usb_sndbulkpipe(udev, 0x02),
787 buf, FW_BULKOUT_SIZE + 2, &act_len, 1000);
789 err("firmware download failed at packet %d with code %d", i, ret);
793 ret = af9005_boot_packet(udev, FW_CONFIRM, &reply);
796 if (reply != (u8) (packets & 0xff)) {
797 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets & 0xff, reply);
800 ret = af9005_boot_packet(udev, FW_BOOT, &reply);
803 ret = af9005_boot_packet(udev, FW_CONFIG, &reply);
807 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply);
815 int af9005_led_control(struct dvb_usb_device *d, int onoff)
817 struct af9005_device_state *st = d->priv;
820 if (onoff && dvb_usb_af9005_led)
824 if (st->led_state != temp) {
826 af9005_write_register_bits(d, xd_p_reg_top_locken1,
828 reg_top_locken1_len, temp);
832 af9005_write_register_bits(d, xd_p_reg_top_lock1,
834 reg_top_lock1_len, temp);
837 st->led_state = temp;
842 static int af9005_frontend_attach(struct dvb_usb_adapter *adap)
847 /* without these calls the first commands after downloading
848 the firmware fail. I put these calls here to simulate
849 what it is done in dvb-usb-init.c.
851 struct usb_device *udev = adap->dev->udev;
852 usb_clear_halt(udev, usb_sndbulkpipe(udev, 2));
853 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 1));
854 if (dvb_usb_af9005_dump_eeprom) {
855 printk("EEPROM DUMP\n");
856 for (i = 0; i < 255; i += 8) {
857 af9005_read_eeprom(adap->dev, i, buf, 8);
858 printk("ADDR %x ", i);
859 debug_dump(buf, 8, printk);
862 adap->fe = af9005_fe_attach(adap->dev);
866 static int af9005_rc_query(struct dvb_usb_device *d, u32 * event, int *state)
868 struct af9005_device_state *st = d->priv;
874 *state = REMOTE_NO_KEY_PRESSED;
875 if (rc_decode == NULL) {
876 /* it shouldn't never come here */
879 /* deb_info("rc_query\n"); */
880 obuf[0] = 3; /* rest of packet length low */
881 obuf[1] = 0; /* rest of packet lentgh high */
882 obuf[2] = 0x40; /* read remote */
883 obuf[3] = 1; /* rest of packet length */
884 obuf[4] = st->sequence++; /* sequence number */
885 ret = af9005_usb_generic_rw(d, obuf, 5, ibuf, 256, 0);
887 err("rc query failed");
890 if (ibuf[2] != 0x41) {
891 err("rc query bad header.");
894 if (ibuf[4] != obuf[4]) {
895 err("rc query bad sequence.");
900 err("rc query invalid length");
904 deb_rc("rc data (%d) ", len);
905 debug_dump((ibuf + 6), len, deb_rc);
906 ret = rc_decode(d, &ibuf[6], len, event, state);
908 err("rc_decode failed");
911 deb_rc("rc_decode state %x event %x\n", *state, *event);
912 if (*state == REMOTE_KEY_REPEAT)
913 *event = d->last_event;
919 static int af9005_power_ctrl(struct dvb_usb_device *d, int onoff)
925 static int af9005_pid_filter_control(struct dvb_usb_adapter *adap, int onoff)
928 deb_info("pid filter control onoff %d\n", onoff);
931 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 1);
935 af9005_write_register_bits(adap->dev,
936 XD_MP2IF_DMX_CTRL, 1, 1, 1);
940 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 1);
943 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 0);
946 deb_info("pid filter control ok\n");
950 static int af9005_pid_filter(struct dvb_usb_adapter *adap, int index,
953 u8 cmd = index & 0x1f;
955 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index,
958 /* cannot use it as pid_filter_ctrl since it has to be done
959 before setting the first pid */
960 if (adap->feedcount == 1) {
961 deb_info("first pid set, enable pid table\n");
962 ret = af9005_pid_filter_control(adap, onoff);
967 af9005_write_ofdm_register(adap->dev,
973 af9005_write_ofdm_register(adap->dev,
980 if (adap->feedcount == 0) {
981 deb_info("last pid unset, disable pid table\n");
982 ret = af9005_pid_filter_control(adap, onoff);
987 ret = af9005_write_ofdm_register(adap->dev, XD_MP2IF_PID_IDX, cmd);
990 deb_info("set pid ok\n");
994 static int af9005_identify_state(struct usb_device *udev,
995 struct dvb_usb_device_properties *props,
996 struct dvb_usb_device_description **desc,
1001 ret = af9005_boot_packet(udev, FW_CONFIG, &reply);
1004 deb_info("result of FW_CONFIG in identify state %d\n", reply);
1007 else if (reply == 0x02)
1011 deb_info("Identify state cold = %d\n", *cold);
1015 static struct dvb_usb_device_properties af9005_properties;
1017 static int af9005_usb_probe(struct usb_interface *intf,
1018 const struct usb_device_id *id)
1020 return dvb_usb_device_init(intf, &af9005_properties,
1021 THIS_MODULE, NULL, adapter_nr);
1024 static struct usb_device_id af9005_usb_table[] = {
1025 {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9005)},
1026 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE)},
1027 {USB_DEVICE(USB_VID_ANSONIC, USB_PID_ANSONIC_DVBT_USB)},
1031 MODULE_DEVICE_TABLE(usb, af9005_usb_table);
1033 static struct dvb_usb_device_properties af9005_properties = {
1034 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1036 .usb_ctrl = DEVICE_SPECIFIC,
1037 .firmware = "af9005.fw",
1038 .download_firmware = af9005_download_firmware,
1041 .size_of_priv = sizeof(struct af9005_device_state),
1047 DVB_USB_ADAP_HAS_PID_FILTER |
1048 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1049 .pid_filter_count = 32,
1050 .pid_filter = af9005_pid_filter,
1051 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1052 .frontend_attach = af9005_frontend_attach,
1053 /* .tuner_attach = af9005_tuner_attach, */
1054 /* parameter for the MPEG2-data transfer */
1061 .buffersize = 4096, /* actual size seen is 3948 */
1067 .power_ctrl = af9005_power_ctrl,
1068 .identify_state = af9005_identify_state,
1070 .i2c_algo = &af9005_i2c_algo,
1074 .rc_key_map_size = 0,
1075 .rc_query = af9005_rc_query,
1077 .num_device_descs = 3,
1079 {.name = "Afatech DVB-T USB1.1 stick",
1080 .cold_ids = {&af9005_usb_table[0], NULL},
1083 {.name = "TerraTec Cinergy T USB XE",
1084 .cold_ids = {&af9005_usb_table[1], NULL},
1087 {.name = "Ansonic DVB-T USB1.1 stick",
1088 .cold_ids = {&af9005_usb_table[2], NULL},
1095 /* usb specific object needed to register this driver with the usb subsystem */
1096 static struct usb_driver af9005_usb_driver = {
1097 .name = "dvb_usb_af9005",
1098 .probe = af9005_usb_probe,
1099 .disconnect = dvb_usb_device_exit,
1100 .id_table = af9005_usb_table,
1104 static int __init af9005_usb_module_init(void)
1107 if ((result = usb_register(&af9005_usb_driver))) {
1108 err("usb_register failed. (%d)", result);
1111 rc_decode = symbol_request(af9005_rc_decode);
1112 rc_keys = symbol_request(af9005_rc_keys);
1113 rc_keys_size = symbol_request(af9005_rc_keys_size);
1114 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
1115 err("af9005_rc_decode function not found, disabling remote");
1116 af9005_properties.rc_query = NULL;
1118 af9005_properties.rc_key_map = rc_keys;
1119 af9005_properties.rc_key_map_size = *rc_keys_size;
1125 static void __exit af9005_usb_module_exit(void)
1127 /* release rc decode symbols */
1128 if (rc_decode != NULL)
1129 symbol_put(af9005_rc_decode);
1130 if (rc_keys != NULL)
1131 symbol_put(af9005_rc_keys);
1132 if (rc_keys_size != NULL)
1133 symbol_put(af9005_rc_keys_size);
1134 /* deregister this driver from the USB subsystem */
1135 usb_deregister(&af9005_usb_driver);
1138 module_init(af9005_usb_module_init);
1139 module_exit(af9005_usb_module_exit);
1141 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1142 MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1143 MODULE_VERSION("1.0");
1144 MODULE_LICENSE("GPL");