2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
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.
24 #include <linux/hash.h>
25 #include <linux/slab.h>
37 static int dvb_usb_af9015_debug;
38 module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
39 MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
40 static int dvb_usb_af9015_remote;
41 module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
42 MODULE_PARM_DESC(remote, "select remote");
43 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
45 static DEFINE_MUTEX(af9015_usb_mutex);
47 static struct af9015_config af9015_config;
48 static struct dvb_usb_device_properties af9015_properties[3];
49 static int af9015_properties_count = ARRAY_SIZE(af9015_properties);
51 static struct af9013_config af9015_af9013_config[] = {
53 .demod_address = AF9015_I2C_DEMOD,
54 .output_mode = AF9013_OUTPUT_MODE_USB,
55 .api_version = { 0, 1, 9, 0 },
56 .gpio[0] = AF9013_GPIO_HI,
57 .gpio[3] = AF9013_GPIO_TUNER_ON,
60 .output_mode = AF9013_OUTPUT_MODE_SERIAL,
61 .api_version = { 0, 1, 9, 0 },
62 .gpio[0] = AF9013_GPIO_TUNER_ON,
63 .gpio[1] = AF9013_GPIO_LO,
67 static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
70 #define REQ_HDR_LEN 8 /* send header size */
71 #define ACK_HDR_LEN 2 /* rece header size */
75 u8 msg_len = REQ_HDR_LEN;
76 static u8 seq; /* packet sequence number */
78 if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)
83 buf[2] = req->i2c_addr;
84 buf[3] = req->addr >> 8;
85 buf[4] = req->addr & 0xff;
87 buf[6] = req->addr_len;
88 buf[7] = req->data_len;
99 buf[2] |= 0x01; /* set I2C direction */
101 buf[0] = READ_WRITE_I2C;
104 if (((req->addr & 0xff00) == 0xff00) ||
105 ((req->addr & 0xff00) == 0xae00))
106 buf[0] = WRITE_VIRTUAL_MEMORY;
107 case WRITE_VIRTUAL_MEMORY:
109 case DOWNLOAD_FIRMWARE:
113 err("unknown command:%d", req->cmd);
118 /* buffer overflow check */
119 if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) ||
120 (!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) {
121 err("too much data; cmd:%d len:%d", req->cmd, req->data_len);
126 /* write requested */
128 memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len);
129 msg_len += req->data_len;
133 debug_dump(buf, msg_len, deb_xfer);
136 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len,
137 &act_len, AF9015_USB_TIMEOUT);
139 err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len);
141 if (act_len != msg_len)
142 ret = -1; /* all data is not send */
146 /* no ack for those packets */
147 if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
150 /* write receives seq + status = 2 bytes
151 read receives seq + status + data = 2 + N bytes */
152 msg_len = ACK_HDR_LEN;
154 msg_len += req->data_len;
156 ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,
157 &act_len, AF9015_USB_TIMEOUT);
159 err("recv bulk message failed:%d", ret);
165 debug_dump(buf, act_len, deb_xfer);
167 /* remote controller query status is 1 if remote code is not received */
168 if (req->cmd == GET_IR_CODE && buf[1] == 1) {
169 buf[1] = 0; /* clear command "error" status */
170 memset(&buf[2], 0, req->data_len);
171 buf[3] = 1; /* no remote code received mark */
176 err("command failed:%d", buf[1]);
181 /* read request, copy returned data to return buf */
183 memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len);
187 mutex_unlock(&af9015_usb_mutex);
192 static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
194 return af9015_rw_udev(d->udev, req);
197 static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val,
200 struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
202 return af9015_ctrl_msg(d, &req);
205 static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)
207 return af9015_write_regs(d, addr, &val, 1);
210 static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)
212 struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, 1, val};
213 return af9015_ctrl_msg(d, &req);
216 static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
219 struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
221 if (addr == af9015_af9013_config[0].demod_address ||
222 addr == af9015_af9013_config[1].demod_address)
225 return af9015_ctrl_msg(d, &req);
228 static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
231 struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
233 if (addr == af9015_af9013_config[0].demod_address ||
234 addr == af9015_af9013_config[1].demod_address)
237 return af9015_ctrl_msg(d, &req);
240 static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
243 struct dvb_usb_device *d = i2c_get_adapdata(adap);
246 u8 uninitialized_var(mbox), addr_len;
249 /* TODO: implement bus lock
251 The bus lock is needed because there is two tuners both using same I2C-address.
252 Due to that the only way to select correct tuner is use demodulator I2C-gate.
254 ................................................
255 . AF9015 includes integrated AF9013 demodulator.
256 . ____________ ____________ . ____________
257 .| uC | | demod | . | tuner |
258 .|------------| |------------| . |------------|
259 .| AF9015 | | AF9013/5 | . | MXL5003 |
260 .| |--+----I2C-------|-----/ -----|-.-----I2C-------| |
261 .| | | | addr 0x38 | . | addr 0xc6 |
262 .|____________| | |____________| . |____________|
263 .................|..............................
264 | ____________ ____________
265 | | demod | | tuner |
266 | |------------| |------------|
267 | | AF9013 | | MXL5003 |
268 +----I2C-------|-----/ -----|-------I2C-------| |
269 | addr 0x3a | | addr 0xc6 |
270 |____________| |____________|
272 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
276 if (msg[i].addr == af9015_af9013_config[0].demod_address ||
277 msg[i].addr == af9015_af9013_config[1].demod_address) {
278 addr = msg[i].buf[0] << 8;
279 addr += msg[i].buf[1];
280 mbox = msg[i].buf[2];
283 addr = msg[i].buf[0];
285 /* mbox is don't care in that case */
288 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
290 af9015_af9013_config[0].demod_address)
291 req.cmd = READ_MEMORY;
294 req.i2c_addr = msg[i].addr;
297 req.addr_len = addr_len;
298 req.data_len = msg[i+1].len;
299 req.data = &msg[i+1].buf[0];
300 ret = af9015_ctrl_msg(d, &req);
302 } else if (msg[i].flags & I2C_M_RD) {
305 af9015_af9013_config[0].demod_address)
309 req.i2c_addr = msg[i].addr;
312 req.addr_len = addr_len;
313 req.data_len = msg[i].len;
314 req.data = &msg[i].buf[0];
315 ret = af9015_ctrl_msg(d, &req);
319 af9015_af9013_config[0].demod_address)
320 req.cmd = WRITE_MEMORY;
323 req.i2c_addr = msg[i].addr;
326 req.addr_len = addr_len;
327 req.data_len = msg[i].len-addr_len;
328 req.data = &msg[i].buf[addr_len];
329 ret = af9015_ctrl_msg(d, &req);
339 mutex_unlock(&d->i2c_mutex);
344 static u32 af9015_i2c_func(struct i2c_adapter *adapter)
349 static struct i2c_algorithm af9015_i2c_algo = {
350 .master_xfer = af9015_i2c_xfer,
351 .functionality = af9015_i2c_func,
354 static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op)
359 ret = af9015_read_reg(d, addr, &val);
373 return af9015_write_reg(d, addr, val);
376 static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
378 return af9015_do_reg_bit(d, addr, bit, 1);
381 static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
383 return af9015_do_reg_bit(d, addr, bit, 0);
386 static int af9015_init_endpoint(struct dvb_usb_device *d)
391 deb_info("%s: USB speed:%d\n", __func__, d->udev->speed);
393 /* Windows driver uses packet count 21 for USB1.1 and 348 for USB2.0.
394 We use smaller - about 1/4 from the original, 5 and 87. */
395 #define TS_PACKET_SIZE 188
397 #define TS_USB20_PACKET_COUNT 87
398 #define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT)
400 #define TS_USB11_PACKET_COUNT 5
401 #define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT)
403 #define TS_USB20_MAX_PACKET_SIZE 512
404 #define TS_USB11_MAX_PACKET_SIZE 64
406 if (d->udev->speed == USB_SPEED_FULL) {
407 frame_size = TS_USB11_FRAME_SIZE/4;
408 packet_size = TS_USB11_MAX_PACKET_SIZE/4;
410 frame_size = TS_USB20_FRAME_SIZE/4;
411 packet_size = TS_USB20_MAX_PACKET_SIZE/4;
414 ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */
417 ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */
420 ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */
423 ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */
426 ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */
429 if (af9015_config.dual_mode) {
430 ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */
434 ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */
437 if (af9015_config.dual_mode) {
438 ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */
442 /* EP4 xfer length */
443 ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);
446 ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);
449 /* EP5 xfer length */
450 ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);
453 ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);
456 ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */
459 ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */
462 ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */
465 if (af9015_config.dual_mode) {
466 ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */
471 /* enable / disable mp2if2 */
472 if (af9015_config.dual_mode)
473 ret = af9015_set_reg_bit(d, 0xd50b, 0);
475 ret = af9015_clear_reg_bit(d, 0xd50b, 0);
478 err("endpoint init failed:%d", ret);
482 static int af9015_copy_firmware(struct dvb_usb_device *d)
487 struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
489 deb_info("%s:\n", __func__);
491 fw_params[0] = af9015_config.firmware_size >> 8;
492 fw_params[1] = af9015_config.firmware_size & 0xff;
493 fw_params[2] = af9015_config.firmware_checksum >> 8;
494 fw_params[3] = af9015_config.firmware_checksum & 0xff;
496 /* wait 2nd demodulator ready */
499 ret = af9015_read_reg_i2c(d,
500 af9015_af9013_config[1].demod_address, 0x98be, &val);
504 deb_info("%s: firmware status:%02x\n", __func__, val);
506 if (val == 0x0c) /* fw is running, no need for download */
509 /* set I2C master clock to fast (to speed up firmware copy) */
510 ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
517 ret = af9015_ctrl_msg(d, &req);
519 err("firmware copy cmd failed:%d", ret);
520 deb_info("%s: firmware copy done\n", __func__);
522 /* set I2C master clock back to normal */
523 ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
527 /* request boot firmware */
528 ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address,
530 deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);
534 for (i = 0; i < 15; i++) {
537 /* check firmware status */
538 ret = af9015_read_reg_i2c(d,
539 af9015_af9013_config[1].demod_address, 0x98be, &val);
540 deb_info("%s: firmware status cmd status:%d fw status:%02x\n",
545 if (val == 0x0c || val == 0x04) /* success or fail */
550 err("firmware did not run");
552 } else if (val != 0x0c) {
553 err("firmware boot timeout");
562 /* hash (and dump) eeprom */
563 static int af9015_eeprom_hash(struct usb_device *udev)
565 static const unsigned int eeprom_size = 256;
569 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
571 eeprom = kmalloc(eeprom_size, GFP_KERNEL);
575 for (reg = 0; reg < eeprom_size; reg++) {
577 ret = af9015_rw_udev(udev, &req);
583 if (dvb_usb_af9015_debug & 0x01)
584 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom,
587 BUG_ON(eeprom_size % 4);
589 af9015_config.eeprom_sum = 0;
590 for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) {
591 af9015_config.eeprom_sum *= GOLDEN_RATIO_PRIME_32;
592 af9015_config.eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]);
595 deb_info("%s: eeprom sum=%.8x\n", __func__, af9015_config.eeprom_sum);
603 static int af9015_init(struct dvb_usb_device *d)
606 deb_info("%s:\n", __func__);
608 ret = af9015_init_endpoint(d);
616 static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
619 deb_info("%s: onoff:%d\n", __func__, onoff);
622 ret = af9015_set_reg_bit(adap->dev, 0xd503, 0);
624 ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0);
629 static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
635 deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n",
636 __func__, index, pid, onoff);
638 ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff));
642 ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8));
646 idx = ((index & 0x1f) | (1 << 5));
647 ret = af9015_write_reg(adap->dev, 0xd504, idx);
653 static int af9015_download_firmware(struct usb_device *udev,
654 const struct firmware *fw)
656 int i, len, packets, remainder, ret;
657 struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
658 u16 addr = 0x5100; /* firmware start address */
661 deb_info("%s:\n", __func__);
664 for (i = 0; i < fw->size; i++)
665 checksum += fw->data[i];
667 af9015_config.firmware_size = fw->size;
668 af9015_config.firmware_checksum = checksum;
670 #define FW_PACKET_MAX_DATA 55
672 packets = fw->size / FW_PACKET_MAX_DATA;
673 remainder = fw->size % FW_PACKET_MAX_DATA;
674 len = FW_PACKET_MAX_DATA;
675 for (i = 0; i <= packets; i++) {
676 if (i == packets) /* set size of the last packet */
680 req.data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA);
682 addr += FW_PACKET_MAX_DATA;
684 ret = af9015_rw_udev(udev, &req);
686 err("firmware download failed at packet %d with " \
692 /* firmware loaded, request boot */
694 ret = af9015_rw_udev(udev, &req);
696 err("firmware boot failed:%d", ret);
704 struct af9015_rc_setup {
709 static char *af9015_rc_setup_match(unsigned int id,
710 const struct af9015_rc_setup *table)
712 for (; table->rc_codes; table++)
714 return table->rc_codes;
718 static const struct af9015_rc_setup af9015_rc_setup_modparam[] = {
719 { AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M },
720 { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II },
721 { AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND },
722 { AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE },
723 { AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS },
727 static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {
728 { 0xb8feb708, RC_MAP_MSI_DIGIVOX_II },
729 { 0xa3703d00, RC_MAP_ALINK_DTU_M },
730 { 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */
734 static const struct af9015_rc_setup af9015_rc_setup_usbids[] = {
735 { (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
736 RC_MAP_TERRATEC_SLIM },
737 { (USB_VID_VISIONPLUS << 16) + USB_PID_AZUREWAVE_AD_TU700,
738 RC_MAP_AZUREWAVE_AD_TU700 },
739 { (USB_VID_VISIONPLUS << 16) + USB_PID_TINYTWIN,
740 RC_MAP_AZUREWAVE_AD_TU700 },
741 { (USB_VID_MSI_2 << 16) + USB_PID_MSI_DIGI_VOX_MINI_III,
742 RC_MAP_MSI_DIGIVOX_III },
743 { (USB_VID_LEADTEK << 16) + USB_PID_WINFAST_DTV_DONGLE_GOLD,
744 RC_MAP_LEADTEK_Y04G0051 },
745 { (USB_VID_AVERMEDIA << 16) + USB_PID_AVERMEDIA_VOLAR_X,
746 RC_MAP_AVERMEDIA_M135A },
747 { (USB_VID_AFATECH << 16) + USB_PID_TREKSTOR_DVBT,
752 static void af9015_set_remote_config(struct usb_device *udev,
753 struct dvb_usb_device_properties *props)
755 u16 vid = le16_to_cpu(udev->descriptor.idVendor);
756 u16 pid = le16_to_cpu(udev->descriptor.idProduct);
758 /* try to load remote based module param */
759 props->rc.core.rc_codes = af9015_rc_setup_match(
760 dvb_usb_af9015_remote, af9015_rc_setup_modparam);
762 /* try to load remote based eeprom hash */
763 if (!props->rc.core.rc_codes)
764 props->rc.core.rc_codes = af9015_rc_setup_match(
765 af9015_config.eeprom_sum, af9015_rc_setup_hashes);
767 /* try to load remote based USB ID */
768 if (!props->rc.core.rc_codes)
769 props->rc.core.rc_codes = af9015_rc_setup_match(
770 (vid << 16) + pid, af9015_rc_setup_usbids);
772 /* try to load remote based USB iManufacturer string */
773 if (!props->rc.core.rc_codes && vid == USB_VID_AFATECH) {
774 /* Check USB manufacturer and product strings and try
775 to determine correct remote in case of chip vendor
776 reference IDs are used.
777 DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */
778 char manufacturer[10];
779 memset(manufacturer, 0, sizeof(manufacturer));
780 usb_string(udev, udev->descriptor.iManufacturer,
781 manufacturer, sizeof(manufacturer));
782 if (!strcmp("MSI", manufacturer)) {
783 /* iManufacturer 1 MSI
784 iProduct 2 MSI K-VOX */
785 props->rc.core.rc_codes = af9015_rc_setup_match(
786 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
787 af9015_rc_setup_modparam);
793 static int af9015_rc_query(struct dvb_usb_device *d);
795 static int af9015_read_config(struct usb_device *udev)
798 u8 val, i, offset = 0;
799 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
801 /* IR remote controller */
802 req.addr = AF9015_EEPROM_IR_MODE;
803 /* first message will timeout often due to possible hw bug */
804 for (i = 0; i < 4; i++) {
805 ret = af9015_rw_udev(udev, &req);
812 ret = af9015_eeprom_hash(udev);
816 deb_info("%s: IR mode:%d\n", __func__, val);
817 for (i = 0; i < af9015_properties_count; i++) {
818 if (val == AF9015_IR_MODE_DISABLED) {
819 af9015_properties[i].rc.core.rc_query = NULL;
821 af9015_properties[i].rc.core.rc_query = af9015_rc_query;
822 af9015_set_remote_config(udev, &af9015_properties[i]);
826 /* TS mode - one or two receivers */
827 req.addr = AF9015_EEPROM_TS_MODE;
828 ret = af9015_rw_udev(udev, &req);
831 af9015_config.dual_mode = val;
832 deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode);
834 /* Set adapter0 buffer size according to USB port speed, adapter1 buffer
835 size can be static because it is enabled only USB2.0 */
836 for (i = 0; i < af9015_properties_count; i++) {
837 /* USB1.1 set smaller buffersize and disable 2nd adapter */
838 if (udev->speed == USB_SPEED_FULL) {
839 af9015_properties[i].adapter[0].stream.u.bulk.buffersize
840 = TS_USB11_FRAME_SIZE;
841 /* disable 2nd adapter because we don't have
843 af9015_config.dual_mode = 0;
845 af9015_properties[i].adapter[0].stream.u.bulk.buffersize
846 = TS_USB20_FRAME_SIZE;
850 if (af9015_config.dual_mode) {
851 /* read 2nd demodulator I2C address */
852 req.addr = AF9015_EEPROM_DEMOD2_I2C;
853 ret = af9015_rw_udev(udev, &req);
856 af9015_af9013_config[1].demod_address = val;
858 /* enable 2nd adapter */
859 for (i = 0; i < af9015_properties_count; i++)
860 af9015_properties[i].num_adapters = 2;
863 /* disable 2nd adapter */
864 for (i = 0; i < af9015_properties_count; i++)
865 af9015_properties[i].num_adapters = 1;
868 for (i = 0; i < af9015_properties[0].num_adapters; i++) {
870 offset = AF9015_EEPROM_OFFSET;
872 req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset;
873 ret = af9015_rw_udev(udev, &req);
878 af9015_af9013_config[i].adc_clock = 28800;
881 af9015_af9013_config[i].adc_clock = 20480;
884 af9015_af9013_config[i].adc_clock = 28000;
887 af9015_af9013_config[i].adc_clock = 25000;
890 deb_info("%s: [%d] xtal:%d set adc_clock:%d\n", __func__, i,
891 val, af9015_af9013_config[i].adc_clock);
894 req.addr = AF9015_EEPROM_IF1H + offset;
895 ret = af9015_rw_udev(udev, &req);
898 af9015_af9013_config[i].tuner_if = val << 8;
899 req.addr = AF9015_EEPROM_IF1L + offset;
900 ret = af9015_rw_udev(udev, &req);
903 af9015_af9013_config[i].tuner_if += val;
904 deb_info("%s: [%d] IF1:%d\n", __func__, i,
905 af9015_af9013_config[0].tuner_if);
908 req.addr = AF9015_EEPROM_MT2060_IF1H + offset;
909 ret = af9015_rw_udev(udev, &req);
912 af9015_config.mt2060_if1[i] = val << 8;
913 req.addr = AF9015_EEPROM_MT2060_IF1L + offset;
914 ret = af9015_rw_udev(udev, &req);
917 af9015_config.mt2060_if1[i] += val;
918 deb_info("%s: [%d] MT2060 IF1:%d\n", __func__, i,
919 af9015_config.mt2060_if1[i]);
922 req.addr = AF9015_EEPROM_TUNER_ID1 + offset;
923 ret = af9015_rw_udev(udev, &req);
927 case AF9013_TUNER_ENV77H11D5:
928 case AF9013_TUNER_MT2060:
929 case AF9013_TUNER_QT1010:
930 case AF9013_TUNER_UNKNOWN:
931 case AF9013_TUNER_MT2060_2:
932 case AF9013_TUNER_TDA18271:
933 case AF9013_TUNER_QT1010A:
934 case AF9013_TUNER_TDA18218:
935 af9015_af9013_config[i].rf_spec_inv = 1;
937 case AF9013_TUNER_MXL5003D:
938 case AF9013_TUNER_MXL5005D:
939 case AF9013_TUNER_MXL5005R:
940 case AF9013_TUNER_MXL5007T:
941 af9015_af9013_config[i].rf_spec_inv = 0;
943 case AF9013_TUNER_MC44S803:
944 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;
945 af9015_af9013_config[i].rf_spec_inv = 1;
948 warn("tuner id:%d not supported, please report!", val);
952 af9015_af9013_config[i].tuner = val;
953 deb_info("%s: [%d] tuner id:%d\n", __func__, i, val);
958 err("eeprom read failed:%d", ret);
960 /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM
961 content :-( Override some wrong values here. Ditto for the
962 AVerTV Red HD+ (A850T) device. */
963 if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_AVERMEDIA &&
964 ((le16_to_cpu(udev->descriptor.idProduct) ==
965 USB_PID_AVERMEDIA_A850) ||
966 (le16_to_cpu(udev->descriptor.idProduct) ==
967 USB_PID_AVERMEDIA_A850T))) {
968 deb_info("%s: AverMedia A850: overriding config\n", __func__);
969 /* disable dual mode */
970 af9015_config.dual_mode = 0;
971 /* disable 2nd adapter */
972 for (i = 0; i < af9015_properties_count; i++)
973 af9015_properties[i].num_adapters = 1;
976 af9015_af9013_config[0].tuner_if = 4570;
982 static int af9015_identify_state(struct usb_device *udev,
983 struct dvb_usb_device_properties *props,
984 struct dvb_usb_device_description **desc,
989 struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};
991 ret = af9015_rw_udev(udev, &req);
995 deb_info("%s: reply:%02x\n", __func__, reply);
1004 static int af9015_rc_query(struct dvb_usb_device *d)
1006 struct af9015_state *priv = d->priv;
1008 u8 repeat, keycode[4];
1010 /* read registers needed to detect remote controller code */
1011 /* TODO: Implement read multiple registers to reduce idle USB traffic.
1012 Currently three reads are needed for one idle rc polling. */
1013 ret = af9015_read_reg(d, 0x98df, &repeat);
1017 ret = af9015_read_reg(d, 0x98e7, &keycode[2]);
1021 ret = af9015_read_reg(d, 0x98e8, &keycode[3]);
1025 if (keycode[2] || keycode[3]) {
1026 /* read 1st address byte */
1027 ret = af9015_read_reg(d, 0x98e5, &keycode[0]);
1031 /* read 2nd address byte */
1032 ret = af9015_read_reg(d, 0x98e6, &keycode[1]);
1036 deb_rc("%s: key pressed ", __func__);
1037 debug_dump(keycode, sizeof(keycode), deb_rc);
1039 /* clean data bytes from mem */
1040 ret = af9015_write_reg(d, 0x98e7, 0);
1044 ret = af9015_write_reg(d, 0x98e8, 0);
1048 if (keycode[2] == (u8) ~keycode[3]) {
1049 if (keycode[0] == (u8) ~keycode[1]) {
1051 priv->rc_keycode = keycode[0] << 8 | keycode[2];
1054 priv->rc_keycode = keycode[0] << 16 |
1055 keycode[1] << 8 | keycode[2];
1057 ir_keydown(d->rc_input_dev, priv->rc_keycode, 0);
1059 priv->rc_keycode = 0; /* clear just for sure */
1061 } else if (priv->rc_repeat != repeat) {
1062 deb_rc("%s: key repeated\n", __func__);
1063 ir_keydown(d->rc_input_dev, priv->rc_keycode, 0);
1065 deb_rc("%s: no key press\n", __func__);
1068 priv->rc_repeat = repeat;
1072 err("%s: failed:%d", __func__, ret);
1077 /* init 2nd I2C adapter */
1078 static int af9015_i2c_init(struct dvb_usb_device *d)
1081 struct af9015_state *state = d->priv;
1082 deb_info("%s:\n", __func__);
1084 strncpy(state->i2c_adap.name, d->desc->name,
1085 sizeof(state->i2c_adap.name));
1086 state->i2c_adap.algo = d->props.i2c_algo;
1087 state->i2c_adap.algo_data = NULL;
1088 state->i2c_adap.dev.parent = &d->udev->dev;
1090 i2c_set_adapdata(&state->i2c_adap, d);
1092 ret = i2c_add_adapter(&state->i2c_adap);
1094 err("could not add i2c adapter");
1099 static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
1102 struct af9015_state *state = adap->dev->priv;
1103 struct i2c_adapter *i2c_adap;
1105 if (adap->id == 0) {
1106 /* select I2C adapter */
1107 i2c_adap = &adap->dev->i2c_adap;
1109 deb_info("%s: init I2C\n", __func__);
1110 ret = af9015_i2c_init(adap->dev);
1112 /* select I2C adapter */
1113 i2c_adap = &state->i2c_adap;
1115 /* copy firmware to 2nd demodulator */
1116 if (af9015_config.dual_mode) {
1117 ret = af9015_copy_firmware(adap->dev);
1119 err("firmware copy to 2nd frontend " \
1120 "failed, will disable it");
1121 af9015_config.dual_mode = 0;
1129 /* attach demodulator */
1130 adap->fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id],
1133 return adap->fe == NULL ? -ENODEV : 0;
1136 static struct mt2060_config af9015_mt2060_config = {
1137 .i2c_address = 0xc0,
1141 static struct qt1010_config af9015_qt1010_config = {
1142 .i2c_address = 0xc4,
1145 static struct tda18271_config af9015_tda18271_config = {
1146 .gate = TDA18271_GATE_DIGITAL,
1150 static struct mxl5005s_config af9015_mxl5003_config = {
1151 .i2c_address = 0xc6,
1152 .if_freq = IF_FREQ_4570000HZ,
1153 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1154 .agc_mode = MXL_SINGLE_AGC,
1155 .tracking_filter = MXL_TF_DEFAULT,
1156 .rssi_enable = MXL_RSSI_ENABLE,
1157 .cap_select = MXL_CAP_SEL_ENABLE,
1158 .div_out = MXL_DIV_OUT_4,
1159 .clock_out = MXL_CLOCK_OUT_DISABLE,
1160 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1161 .top = MXL5005S_TOP_25P2,
1162 .mod_mode = MXL_DIGITAL_MODE,
1163 .if_mode = MXL_ZERO_IF,
1164 .AgcMasterByte = 0x00,
1167 static struct mxl5005s_config af9015_mxl5005_config = {
1168 .i2c_address = 0xc6,
1169 .if_freq = IF_FREQ_4570000HZ,
1170 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1171 .agc_mode = MXL_SINGLE_AGC,
1172 .tracking_filter = MXL_TF_OFF,
1173 .rssi_enable = MXL_RSSI_ENABLE,
1174 .cap_select = MXL_CAP_SEL_ENABLE,
1175 .div_out = MXL_DIV_OUT_4,
1176 .clock_out = MXL_CLOCK_OUT_DISABLE,
1177 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1178 .top = MXL5005S_TOP_25P2,
1179 .mod_mode = MXL_DIGITAL_MODE,
1180 .if_mode = MXL_ZERO_IF,
1181 .AgcMasterByte = 0x00,
1184 static struct mc44s803_config af9015_mc44s803_config = {
1185 .i2c_address = 0xc0,
1189 static struct tda18218_config af9015_tda18218_config = {
1190 .i2c_address = 0xc0,
1191 .i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */
1194 static struct mxl5007t_config af9015_mxl5007t_config = {
1195 .xtal_freq_hz = MxL_XTAL_24_MHZ,
1196 .if_freq_hz = MxL_IF_4_57_MHZ,
1199 static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1201 struct af9015_state *state = adap->dev->priv;
1202 struct i2c_adapter *i2c_adap;
1204 deb_info("%s:\n", __func__);
1206 /* select I2C adapter */
1208 i2c_adap = &adap->dev->i2c_adap;
1210 i2c_adap = &state->i2c_adap;
1212 switch (af9015_af9013_config[adap->id].tuner) {
1213 case AF9013_TUNER_MT2060:
1214 case AF9013_TUNER_MT2060_2:
1215 ret = dvb_attach(mt2060_attach, adap->fe, i2c_adap,
1216 &af9015_mt2060_config,
1217 af9015_config.mt2060_if1[adap->id])
1218 == NULL ? -ENODEV : 0;
1220 case AF9013_TUNER_QT1010:
1221 case AF9013_TUNER_QT1010A:
1222 ret = dvb_attach(qt1010_attach, adap->fe, i2c_adap,
1223 &af9015_qt1010_config) == NULL ? -ENODEV : 0;
1225 case AF9013_TUNER_TDA18271:
1226 ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap,
1227 &af9015_tda18271_config) == NULL ? -ENODEV : 0;
1229 case AF9013_TUNER_TDA18218:
1230 ret = dvb_attach(tda18218_attach, adap->fe, i2c_adap,
1231 &af9015_tda18218_config) == NULL ? -ENODEV : 0;
1233 case AF9013_TUNER_MXL5003D:
1234 ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
1235 &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
1237 case AF9013_TUNER_MXL5005D:
1238 case AF9013_TUNER_MXL5005R:
1239 ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
1240 &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
1242 case AF9013_TUNER_ENV77H11D5:
1243 ret = dvb_attach(dvb_pll_attach, adap->fe, 0xc0, i2c_adap,
1244 DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
1246 case AF9013_TUNER_MC44S803:
1247 ret = dvb_attach(mc44s803_attach, adap->fe, i2c_adap,
1248 &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
1250 case AF9013_TUNER_MXL5007T:
1251 ret = dvb_attach(mxl5007t_attach, adap->fe, i2c_adap,
1252 0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;
1254 case AF9013_TUNER_UNKNOWN:
1257 err("Unknown tuner id:%d",
1258 af9015_af9013_config[adap->id].tuner);
1263 static struct usb_device_id af9015_usb_table[] = {
1264 /* 0 */{USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015)},
1265 {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016)},
1266 {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD)},
1267 {USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E)},
1268 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U)},
1269 /* 5 */{USB_DEVICE(USB_VID_VISIONPLUS,
1271 {USB_DEVICE(USB_VID_VISIONPLUS,
1272 USB_PID_AZUREWAVE_AD_TU700)},
1273 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)},
1274 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T)},
1275 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)},
1276 /* 10 */{USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)},
1277 {USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO)},
1278 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)},
1279 {USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2)},
1280 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)},
1281 /* 15 */{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)},
1282 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)},
1283 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2)},
1284 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_3)},
1285 {USB_DEVICE(USB_VID_AFATECH, USB_PID_TREKSTOR_DVBT)},
1286 /* 20 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850)},
1287 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A805)},
1288 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CONCEPTRONIC_CTVDIGRCU)},
1289 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_MC810)},
1290 {USB_DEVICE(USB_VID_KYE, USB_PID_GENIUS_TVGO_DVB_T03)},
1291 /* 25 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2)},
1292 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T)},
1293 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20)},
1294 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2)},
1295 {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)},
1296 /* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)},
1297 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)},
1298 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)},
1299 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC)},
1300 {USB_DEVICE(USB_VID_TERRATEC,
1301 USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC)},
1302 /* 35 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T)},
1305 MODULE_DEVICE_TABLE(usb, af9015_usb_table);
1307 #define AF9015_RC_INTERVAL 500
1308 static struct dvb_usb_device_properties af9015_properties[] = {
1310 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1312 .usb_ctrl = DEVICE_SPECIFIC,
1313 .download_firmware = af9015_download_firmware,
1314 .firmware = "dvb-usb-af9015.fw",
1317 .size_of_priv = sizeof(struct af9015_state),
1322 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1323 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1325 .pid_filter_count = 32,
1326 .pid_filter = af9015_pid_filter,
1327 .pid_filter_ctrl = af9015_pid_filter_ctrl,
1330 af9015_af9013_frontend_attach,
1331 .tuner_attach = af9015_tuner_attach,
1340 af9015_af9013_frontend_attach,
1341 .tuner_attach = af9015_tuner_attach,
1349 TS_USB20_FRAME_SIZE,
1356 .identify_state = af9015_identify_state,
1359 .protocol = IR_TYPE_NEC,
1360 .module_name = "af9015",
1361 .rc_interval = AF9015_RC_INTERVAL,
1363 .allowed_protos = IR_TYPE_NEC,
1367 .i2c_algo = &af9015_i2c_algo,
1369 .num_device_descs = 12, /* check max from dvb-usb.h */
1372 .name = "Afatech AF9015 DVB-T USB2.0 stick",
1373 .cold_ids = {&af9015_usb_table[0],
1374 &af9015_usb_table[1], NULL},
1378 .name = "Leadtek WinFast DTV Dongle Gold",
1379 .cold_ids = {&af9015_usb_table[2], NULL},
1383 .name = "Pinnacle PCTV 71e",
1384 .cold_ids = {&af9015_usb_table[3], NULL},
1388 .name = "KWorld PlusTV Dual DVB-T Stick " \
1390 .cold_ids = {&af9015_usb_table[4],
1391 &af9015_usb_table[25], NULL},
1395 .name = "DigitalNow TinyTwin DVB-T Receiver",
1396 .cold_ids = {&af9015_usb_table[5],
1397 &af9015_usb_table[28], NULL},
1401 .name = "TwinHan AzureWave AD-TU700(704J)",
1402 .cold_ids = {&af9015_usb_table[6], NULL},
1406 .name = "TerraTec Cinergy T USB XE",
1407 .cold_ids = {&af9015_usb_table[7], NULL},
1411 .name = "KWorld PlusTV Dual DVB-T PCI " \
1413 .cold_ids = {&af9015_usb_table[8], NULL},
1417 .name = "AVerMedia AVerTV DVB-T Volar X",
1418 .cold_ids = {&af9015_usb_table[9], NULL},
1422 .name = "TerraTec Cinergy T Stick RC",
1423 .cold_ids = {&af9015_usb_table[33], NULL},
1427 .name = "TerraTec Cinergy T Stick Dual RC",
1428 .cold_ids = {&af9015_usb_table[34], NULL},
1432 .name = "AverMedia AVerTV Red HD+ (A850T)",
1433 .cold_ids = {&af9015_usb_table[35], NULL},
1438 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1440 .usb_ctrl = DEVICE_SPECIFIC,
1441 .download_firmware = af9015_download_firmware,
1442 .firmware = "dvb-usb-af9015.fw",
1445 .size_of_priv = sizeof(struct af9015_state),
1450 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1451 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1453 .pid_filter_count = 32,
1454 .pid_filter = af9015_pid_filter,
1455 .pid_filter_ctrl = af9015_pid_filter_ctrl,
1458 af9015_af9013_frontend_attach,
1459 .tuner_attach = af9015_tuner_attach,
1468 af9015_af9013_frontend_attach,
1469 .tuner_attach = af9015_tuner_attach,
1477 TS_USB20_FRAME_SIZE,
1484 .identify_state = af9015_identify_state,
1487 .protocol = IR_TYPE_NEC,
1488 .module_name = "af9015",
1489 .rc_interval = AF9015_RC_INTERVAL,
1491 .allowed_protos = IR_TYPE_NEC,
1495 .i2c_algo = &af9015_i2c_algo,
1497 .num_device_descs = 9, /* check max from dvb-usb.h */
1500 .name = "Xtensions XD-380",
1501 .cold_ids = {&af9015_usb_table[10], NULL},
1505 .name = "MSI DIGIVOX Duo",
1506 .cold_ids = {&af9015_usb_table[11], NULL},
1510 .name = "Fujitsu-Siemens Slim Mobile USB DVB-T",
1511 .cold_ids = {&af9015_usb_table[12], NULL},
1515 .name = "Telestar Starstick 2",
1516 .cold_ids = {&af9015_usb_table[13], NULL},
1520 .name = "AVerMedia A309",
1521 .cold_ids = {&af9015_usb_table[14], NULL},
1525 .name = "MSI Digi VOX mini III",
1526 .cold_ids = {&af9015_usb_table[15], NULL},
1530 .name = "KWorld USB DVB-T TV Stick II " \
1532 .cold_ids = {&af9015_usb_table[16],
1533 &af9015_usb_table[17],
1534 &af9015_usb_table[18],
1535 &af9015_usb_table[31], NULL},
1539 .name = "TrekStor DVB-T USB Stick",
1540 .cold_ids = {&af9015_usb_table[19], NULL},
1544 .name = "AverMedia AVerTV Volar Black HD " \
1546 .cold_ids = {&af9015_usb_table[20], NULL},
1551 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1553 .usb_ctrl = DEVICE_SPECIFIC,
1554 .download_firmware = af9015_download_firmware,
1555 .firmware = "dvb-usb-af9015.fw",
1558 .size_of_priv = sizeof(struct af9015_state),
1563 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1564 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1566 .pid_filter_count = 32,
1567 .pid_filter = af9015_pid_filter,
1568 .pid_filter_ctrl = af9015_pid_filter_ctrl,
1571 af9015_af9013_frontend_attach,
1572 .tuner_attach = af9015_tuner_attach,
1581 af9015_af9013_frontend_attach,
1582 .tuner_attach = af9015_tuner_attach,
1590 TS_USB20_FRAME_SIZE,
1597 .identify_state = af9015_identify_state,
1600 .protocol = IR_TYPE_NEC,
1601 .module_name = "af9015",
1602 .rc_interval = AF9015_RC_INTERVAL,
1604 .allowed_protos = IR_TYPE_NEC,
1608 .i2c_algo = &af9015_i2c_algo,
1610 .num_device_descs = 9, /* check max from dvb-usb.h */
1613 .name = "AverMedia AVerTV Volar GPS 805 (A805)",
1614 .cold_ids = {&af9015_usb_table[21], NULL},
1618 .name = "Conceptronic USB2.0 DVB-T CTVDIGRCU " \
1620 .cold_ids = {&af9015_usb_table[22], NULL},
1624 .name = "KWorld Digial MC-810",
1625 .cold_ids = {&af9015_usb_table[23], NULL},
1629 .name = "Genius TVGo DVB-T03",
1630 .cold_ids = {&af9015_usb_table[24], NULL},
1634 .name = "KWorld PlusTV DVB-T PCI Pro Card " \
1636 .cold_ids = {&af9015_usb_table[26], NULL},
1640 .name = "Sveon STV20 Tuner USB DVB-T HDTV",
1641 .cold_ids = {&af9015_usb_table[27], NULL},
1645 .name = "Leadtek WinFast DTV2000DS",
1646 .cold_ids = {&af9015_usb_table[29], NULL},
1650 .name = "KWorld USB DVB-T Stick Mobile " \
1652 .cold_ids = {&af9015_usb_table[30], NULL},
1656 .name = "AverMedia AVerTV Volar M (A815Mac)",
1657 .cold_ids = {&af9015_usb_table[32], NULL},
1664 static int af9015_usb_probe(struct usb_interface *intf,
1665 const struct usb_device_id *id)
1668 struct dvb_usb_device *d = NULL;
1669 struct usb_device *udev = interface_to_usbdev(intf);
1672 deb_info("%s: interface:%d\n", __func__,
1673 intf->cur_altsetting->desc.bInterfaceNumber);
1675 /* interface 0 is used by DVB-T receiver and
1676 interface 1 is for remote controller (HID) */
1677 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
1678 ret = af9015_read_config(udev);
1682 for (i = 0; i < af9015_properties_count; i++) {
1683 ret = dvb_usb_device_init(intf, &af9015_properties[i],
1684 THIS_MODULE, &d, adapter_nr);
1694 ret = af9015_init(d);
1700 static void af9015_i2c_exit(struct dvb_usb_device *d)
1702 struct af9015_state *state = d->priv;
1703 deb_info("%s:\n", __func__);
1705 /* remove 2nd I2C adapter */
1706 if (d->state & DVB_USB_STATE_I2C)
1707 i2c_del_adapter(&state->i2c_adap);
1710 static void af9015_usb_device_exit(struct usb_interface *intf)
1712 struct dvb_usb_device *d = usb_get_intfdata(intf);
1713 deb_info("%s:\n", __func__);
1715 /* remove 2nd I2C adapter */
1716 if (d != NULL && d->desc != NULL)
1719 dvb_usb_device_exit(intf);
1722 /* usb specific object needed to register this driver with the usb subsystem */
1723 static struct usb_driver af9015_usb_driver = {
1724 .name = "dvb_usb_af9015",
1725 .probe = af9015_usb_probe,
1726 .disconnect = af9015_usb_device_exit,
1727 .id_table = af9015_usb_table,
1731 static int __init af9015_usb_module_init(void)
1734 ret = usb_register(&af9015_usb_driver);
1736 err("module init failed:%d", ret);
1741 static void __exit af9015_usb_module_exit(void)
1743 /* deregister this driver from the USB subsystem */
1744 usb_deregister(&af9015_usb_driver);
1747 module_init(af9015_usb_module_init);
1748 module_exit(af9015_usb_module_exit);
1750 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1751 MODULE_DESCRIPTION("Driver for Afatech AF9015 DVB-T");
1752 MODULE_LICENSE("GPL");