Path: blob/master/drivers/media/dvb/dvb-usb/af9015.c
15111 views
/*1* DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver2*3* Copyright (C) 2007 Antti Palosaari <[email protected]>4*5* Thanks to Afatech who kindly provided information.6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.20*21*/2223#include <linux/hash.h>24#include <linux/slab.h>2526#include "af9015.h"27#include "af9013.h"28#include "mt2060.h"29#include "qt1010.h"30#include "tda18271.h"31#include "mxl5005s.h"32#include "mc44s803.h"33#include "tda18218.h"34#include "mxl5007t.h"3536static int dvb_usb_af9015_debug;37module_param_named(debug, dvb_usb_af9015_debug, int, 0644);38MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);39static int dvb_usb_af9015_remote;40module_param_named(remote, dvb_usb_af9015_remote, int, 0644);41MODULE_PARM_DESC(remote, "select remote");42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);4344static DEFINE_MUTEX(af9015_usb_mutex);4546static struct af9015_config af9015_config;47static struct dvb_usb_device_properties af9015_properties[3];48static int af9015_properties_count = ARRAY_SIZE(af9015_properties);4950static struct af9013_config af9015_af9013_config[] = {51{52.demod_address = AF9015_I2C_DEMOD,53.output_mode = AF9013_OUTPUT_MODE_USB,54.api_version = { 0, 1, 9, 0 },55.gpio[0] = AF9013_GPIO_HI,56.gpio[3] = AF9013_GPIO_TUNER_ON,5758}, {59.output_mode = AF9013_OUTPUT_MODE_SERIAL,60.api_version = { 0, 1, 9, 0 },61.gpio[0] = AF9013_GPIO_TUNER_ON,62.gpio[1] = AF9013_GPIO_LO,63}64};6566static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)67{68#define BUF_LEN 6369#define REQ_HDR_LEN 8 /* send header size */70#define ACK_HDR_LEN 2 /* rece header size */71int act_len, ret;72u8 buf[BUF_LEN];73u8 write = 1;74u8 msg_len = REQ_HDR_LEN;75static u8 seq; /* packet sequence number */7677if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)78return -EAGAIN;7980buf[0] = req->cmd;81buf[1] = seq++;82buf[2] = req->i2c_addr;83buf[3] = req->addr >> 8;84buf[4] = req->addr & 0xff;85buf[5] = req->mbox;86buf[6] = req->addr_len;87buf[7] = req->data_len;8889switch (req->cmd) {90case GET_CONFIG:91case READ_MEMORY:92case RECONNECT_USB:93case GET_IR_CODE:94write = 0;95break;96case READ_I2C:97write = 0;98buf[2] |= 0x01; /* set I2C direction */99case WRITE_I2C:100buf[0] = READ_WRITE_I2C;101break;102case WRITE_MEMORY:103if (((req->addr & 0xff00) == 0xff00) ||104((req->addr & 0xff00) == 0xae00))105buf[0] = WRITE_VIRTUAL_MEMORY;106case WRITE_VIRTUAL_MEMORY:107case COPY_FIRMWARE:108case DOWNLOAD_FIRMWARE:109case BOOT:110break;111default:112err("unknown command:%d", req->cmd);113ret = -1;114goto error_unlock;115}116117/* buffer overflow check */118if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) ||119(!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) {120err("too much data; cmd:%d len:%d", req->cmd, req->data_len);121ret = -EINVAL;122goto error_unlock;123}124125/* write requested */126if (write) {127memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len);128msg_len += req->data_len;129}130131deb_xfer(">>> ");132debug_dump(buf, msg_len, deb_xfer);133134/* send req */135ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len,136&act_len, AF9015_USB_TIMEOUT);137if (ret)138err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len);139else140if (act_len != msg_len)141ret = -1; /* all data is not send */142if (ret)143goto error_unlock;144145/* no ack for those packets */146if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)147goto exit_unlock;148149/* write receives seq + status = 2 bytes150read receives seq + status + data = 2 + N bytes */151msg_len = ACK_HDR_LEN;152if (!write)153msg_len += req->data_len;154155ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,156&act_len, AF9015_USB_TIMEOUT);157if (ret) {158err("recv bulk message failed:%d", ret);159ret = -1;160goto error_unlock;161}162163deb_xfer("<<< ");164debug_dump(buf, act_len, deb_xfer);165166/* remote controller query status is 1 if remote code is not received */167if (req->cmd == GET_IR_CODE && buf[1] == 1) {168buf[1] = 0; /* clear command "error" status */169memset(&buf[2], 0, req->data_len);170buf[3] = 1; /* no remote code received mark */171}172173/* check status */174if (buf[1]) {175err("command failed:%d", buf[1]);176ret = -1;177goto error_unlock;178}179180/* read request, copy returned data to return buf */181if (!write)182memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len);183184error_unlock:185exit_unlock:186mutex_unlock(&af9015_usb_mutex);187188return ret;189}190191static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)192{193return af9015_rw_udev(d->udev, req);194}195196static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val,197u8 len)198{199struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,200val};201return af9015_ctrl_msg(d, &req);202}203204static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)205{206return af9015_write_regs(d, addr, &val, 1);207}208209static int af9015_read_regs(struct dvb_usb_device *d, u16 addr, u8 *val, u8 len)210{211struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,212val};213return af9015_ctrl_msg(d, &req);214}215216static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)217{218return af9015_read_regs(d, addr, val, 1);219}220221static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,222u8 val)223{224struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};225226if (addr == af9015_af9013_config[0].demod_address ||227addr == af9015_af9013_config[1].demod_address)228req.addr_len = 3;229230return af9015_ctrl_msg(d, &req);231}232233static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,234u8 *val)235{236struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};237238if (addr == af9015_af9013_config[0].demod_address ||239addr == af9015_af9013_config[1].demod_address)240req.addr_len = 3;241242return af9015_ctrl_msg(d, &req);243}244245static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],246int num)247{248struct dvb_usb_device *d = i2c_get_adapdata(adap);249int ret = 0, i = 0;250u16 addr;251u8 uninitialized_var(mbox), addr_len;252struct req_t req;253254/* TODO: implement bus lock255256The bus lock is needed because there is two tuners both using same I2C-address.257Due to that the only way to select correct tuner is use demodulator I2C-gate.258259................................................260. AF9015 includes integrated AF9013 demodulator.261. ____________ ____________ . ____________262.| uC | | demod | . | tuner |263.|------------| |------------| . |------------|264.| AF9015 | | AF9013/5 | . | MXL5003 |265.| |--+----I2C-------|-----/ -----|-.-----I2C-------| |266.| | | | addr 0x38 | . | addr 0xc6 |267.|____________| | |____________| . |____________|268.................|..............................269| ____________ ____________270| | demod | | tuner |271| |------------| |------------|272| | AF9013 | | MXL5003 |273+----I2C-------|-----/ -----|-------I2C-------| |274| addr 0x3a | | addr 0xc6 |275|____________| |____________|276*/277if (mutex_lock_interruptible(&d->i2c_mutex) < 0)278return -EAGAIN;279280while (i < num) {281if (msg[i].addr == af9015_af9013_config[0].demod_address ||282msg[i].addr == af9015_af9013_config[1].demod_address) {283addr = msg[i].buf[0] << 8;284addr += msg[i].buf[1];285mbox = msg[i].buf[2];286addr_len = 3;287} else {288addr = msg[i].buf[0];289addr_len = 1;290/* mbox is don't care in that case */291}292293if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {294if (msg[i].addr ==295af9015_af9013_config[0].demod_address)296req.cmd = READ_MEMORY;297else298req.cmd = READ_I2C;299req.i2c_addr = msg[i].addr;300req.addr = addr;301req.mbox = mbox;302req.addr_len = addr_len;303req.data_len = msg[i+1].len;304req.data = &msg[i+1].buf[0];305ret = af9015_ctrl_msg(d, &req);306i += 2;307} else if (msg[i].flags & I2C_M_RD) {308ret = -EINVAL;309if (msg[i].addr ==310af9015_af9013_config[0].demod_address)311goto error;312else313req.cmd = READ_I2C;314req.i2c_addr = msg[i].addr;315req.addr = addr;316req.mbox = mbox;317req.addr_len = addr_len;318req.data_len = msg[i].len;319req.data = &msg[i].buf[0];320ret = af9015_ctrl_msg(d, &req);321i += 1;322} else {323if (msg[i].addr ==324af9015_af9013_config[0].demod_address)325req.cmd = WRITE_MEMORY;326else327req.cmd = WRITE_I2C;328req.i2c_addr = msg[i].addr;329req.addr = addr;330req.mbox = mbox;331req.addr_len = addr_len;332req.data_len = msg[i].len-addr_len;333req.data = &msg[i].buf[addr_len];334ret = af9015_ctrl_msg(d, &req);335i += 1;336}337if (ret)338goto error;339340}341ret = i;342343error:344mutex_unlock(&d->i2c_mutex);345346return ret;347}348349static u32 af9015_i2c_func(struct i2c_adapter *adapter)350{351return I2C_FUNC_I2C;352}353354static struct i2c_algorithm af9015_i2c_algo = {355.master_xfer = af9015_i2c_xfer,356.functionality = af9015_i2c_func,357};358359static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op)360{361int ret;362u8 val, mask = 0x01;363364ret = af9015_read_reg(d, addr, &val);365if (ret)366return ret;367368mask <<= bit;369if (op) {370/* set bit */371val |= mask;372} else {373/* clear bit */374mask ^= 0xff;375val &= mask;376}377378return af9015_write_reg(d, addr, val);379}380381static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)382{383return af9015_do_reg_bit(d, addr, bit, 1);384}385386static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)387{388return af9015_do_reg_bit(d, addr, bit, 0);389}390391static int af9015_init_endpoint(struct dvb_usb_device *d)392{393int ret;394u16 frame_size;395u8 packet_size;396deb_info("%s: USB speed:%d\n", __func__, d->udev->speed);397398/* Windows driver uses packet count 21 for USB1.1 and 348 for USB2.0.399We use smaller - about 1/4 from the original, 5 and 87. */400#define TS_PACKET_SIZE 188401402#define TS_USB20_PACKET_COUNT 87403#define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT)404405#define TS_USB11_PACKET_COUNT 5406#define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT)407408#define TS_USB20_MAX_PACKET_SIZE 512409#define TS_USB11_MAX_PACKET_SIZE 64410411if (d->udev->speed == USB_SPEED_FULL) {412frame_size = TS_USB11_FRAME_SIZE/4;413packet_size = TS_USB11_MAX_PACKET_SIZE/4;414} else {415frame_size = TS_USB20_FRAME_SIZE/4;416packet_size = TS_USB20_MAX_PACKET_SIZE/4;417}418419ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */420if (ret)421goto error;422ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */423if (ret)424goto error;425ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */426if (ret)427goto error;428ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */429if (ret)430goto error;431ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */432if (ret)433goto error;434if (af9015_config.dual_mode) {435ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */436if (ret)437goto error;438}439ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */440if (ret)441goto error;442if (af9015_config.dual_mode) {443ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */444if (ret)445goto error;446}447/* EP4 xfer length */448ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);449if (ret)450goto error;451ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);452if (ret)453goto error;454/* EP5 xfer length */455ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);456if (ret)457goto error;458ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);459if (ret)460goto error;461ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */462if (ret)463goto error;464ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */465if (ret)466goto error;467ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */468if (ret)469goto error;470if (af9015_config.dual_mode) {471ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */472if (ret)473goto error;474}475476/* enable / disable mp2if2 */477if (af9015_config.dual_mode)478ret = af9015_set_reg_bit(d, 0xd50b, 0);479else480ret = af9015_clear_reg_bit(d, 0xd50b, 0);481482error:483if (ret)484err("endpoint init failed:%d", ret);485return ret;486}487488static int af9015_copy_firmware(struct dvb_usb_device *d)489{490int ret;491u8 fw_params[4];492u8 val, i;493struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),494fw_params };495deb_info("%s:\n", __func__);496497fw_params[0] = af9015_config.firmware_size >> 8;498fw_params[1] = af9015_config.firmware_size & 0xff;499fw_params[2] = af9015_config.firmware_checksum >> 8;500fw_params[3] = af9015_config.firmware_checksum & 0xff;501502/* wait 2nd demodulator ready */503msleep(100);504505ret = af9015_read_reg_i2c(d,506af9015_af9013_config[1].demod_address, 0x98be, &val);507if (ret)508goto error;509else510deb_info("%s: firmware status:%02x\n", __func__, val);511512if (val == 0x0c) /* fw is running, no need for download */513goto exit;514515/* set I2C master clock to fast (to speed up firmware copy) */516ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */517if (ret)518goto error;519520msleep(50);521522/* copy firmware */523ret = af9015_ctrl_msg(d, &req);524if (ret)525err("firmware copy cmd failed:%d", ret);526deb_info("%s: firmware copy done\n", __func__);527528/* set I2C master clock back to normal */529ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */530if (ret)531goto error;532533/* request boot firmware */534ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address,5350xe205, 1);536deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);537if (ret)538goto error;539540for (i = 0; i < 15; i++) {541msleep(100);542543/* check firmware status */544ret = af9015_read_reg_i2c(d,545af9015_af9013_config[1].demod_address, 0x98be, &val);546deb_info("%s: firmware status cmd status:%d fw status:%02x\n",547__func__, ret, val);548if (ret)549goto error;550551if (val == 0x0c || val == 0x04) /* success or fail */552break;553}554555if (val == 0x04) {556err("firmware did not run");557ret = -1;558} else if (val != 0x0c) {559err("firmware boot timeout");560ret = -1;561}562563error:564exit:565return ret;566}567568/* hash (and dump) eeprom */569static int af9015_eeprom_hash(struct usb_device *udev)570{571static const unsigned int eeprom_size = 256;572unsigned int reg;573int ret;574u8 val, *eeprom;575struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};576577eeprom = kmalloc(eeprom_size, GFP_KERNEL);578if (eeprom == NULL)579return -ENOMEM;580581for (reg = 0; reg < eeprom_size; reg++) {582req.addr = reg;583ret = af9015_rw_udev(udev, &req);584if (ret)585goto free;586eeprom[reg] = val;587}588589if (dvb_usb_af9015_debug & 0x01)590print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom,591eeprom_size);592593BUG_ON(eeprom_size % 4);594595af9015_config.eeprom_sum = 0;596for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) {597af9015_config.eeprom_sum *= GOLDEN_RATIO_PRIME_32;598af9015_config.eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]);599}600601deb_info("%s: eeprom sum=%.8x\n", __func__, af9015_config.eeprom_sum);602603ret = 0;604free:605kfree(eeprom);606return ret;607}608609static int af9015_init(struct dvb_usb_device *d)610{611int ret;612deb_info("%s:\n", __func__);613614/* init RC canary */615ret = af9015_write_reg(d, 0x98e9, 0xff);616if (ret)617goto error;618619ret = af9015_init_endpoint(d);620if (ret)621goto error;622623error:624return ret;625}626627static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)628{629int ret;630deb_info("%s: onoff:%d\n", __func__, onoff);631632if (onoff)633ret = af9015_set_reg_bit(adap->dev, 0xd503, 0);634else635ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0);636637return ret;638}639640static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,641int onoff)642{643int ret;644u8 idx;645646deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n",647__func__, index, pid, onoff);648649ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff));650if (ret)651goto error;652653ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8));654if (ret)655goto error;656657idx = ((index & 0x1f) | (1 << 5));658ret = af9015_write_reg(adap->dev, 0xd504, idx);659660error:661return ret;662}663664static int af9015_download_firmware(struct usb_device *udev,665const struct firmware *fw)666{667int i, len, remaining, ret;668struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};669u16 checksum = 0;670671deb_info("%s:\n", __func__);672673/* calc checksum */674for (i = 0; i < fw->size; i++)675checksum += fw->data[i];676677af9015_config.firmware_size = fw->size;678af9015_config.firmware_checksum = checksum;679680#define FW_ADDR 0x5100 /* firmware start address */681#define LEN_MAX 55 /* max packet size */682for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {683len = remaining;684if (len > LEN_MAX)685len = LEN_MAX;686687req.data_len = len;688req.data = (u8 *) &fw->data[fw->size - remaining];689req.addr = FW_ADDR + fw->size - remaining;690691ret = af9015_rw_udev(udev, &req);692if (ret) {693err("firmware download failed:%d", ret);694goto error;695}696}697698/* firmware loaded, request boot */699req.cmd = BOOT;700ret = af9015_rw_udev(udev, &req);701if (ret) {702err("firmware boot failed:%d", ret);703goto error;704}705706error:707return ret;708}709710struct af9015_rc_setup {711unsigned int id;712char *rc_codes;713};714715static char *af9015_rc_setup_match(unsigned int id,716const struct af9015_rc_setup *table)717{718for (; table->rc_codes; table++)719if (table->id == id)720return table->rc_codes;721return NULL;722}723724static const struct af9015_rc_setup af9015_rc_setup_modparam[] = {725{ AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M },726{ AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II },727{ AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND },728{ AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE },729{ AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS },730{ }731};732733static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {734{ 0xb8feb708, RC_MAP_MSI_DIGIVOX_II },735{ 0xa3703d00, RC_MAP_ALINK_DTU_M },736{ 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */737{ }738};739740static const struct af9015_rc_setup af9015_rc_setup_usbids[] = {741{ (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_RC,742RC_MAP_TERRATEC_SLIM_2 },743{ (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,744RC_MAP_TERRATEC_SLIM },745{ (USB_VID_VISIONPLUS << 16) + USB_PID_AZUREWAVE_AD_TU700,746RC_MAP_AZUREWAVE_AD_TU700 },747{ (USB_VID_VISIONPLUS << 16) + USB_PID_TINYTWIN,748RC_MAP_AZUREWAVE_AD_TU700 },749{ (USB_VID_MSI_2 << 16) + USB_PID_MSI_DIGI_VOX_MINI_III,750RC_MAP_MSI_DIGIVOX_III },751{ (USB_VID_LEADTEK << 16) + USB_PID_WINFAST_DTV_DONGLE_GOLD,752RC_MAP_LEADTEK_Y04G0051 },753{ (USB_VID_AVERMEDIA << 16) + USB_PID_AVERMEDIA_VOLAR_X,754RC_MAP_AVERMEDIA_M135A },755{ (USB_VID_AFATECH << 16) + USB_PID_TREKSTOR_DVBT,756RC_MAP_TREKSTOR },757{ (USB_VID_KWORLD_2 << 16) + USB_PID_TINYTWIN_2,758RC_MAP_DIGITALNOW_TINYTWIN },759{ (USB_VID_GTEK << 16) + USB_PID_TINYTWIN_3,760RC_MAP_DIGITALNOW_TINYTWIN },761{ }762};763764static void af9015_set_remote_config(struct usb_device *udev,765struct dvb_usb_device_properties *props)766{767u16 vid = le16_to_cpu(udev->descriptor.idVendor);768u16 pid = le16_to_cpu(udev->descriptor.idProduct);769770/* try to load remote based module param */771props->rc.core.rc_codes = af9015_rc_setup_match(772dvb_usb_af9015_remote, af9015_rc_setup_modparam);773774/* try to load remote based eeprom hash */775if (!props->rc.core.rc_codes)776props->rc.core.rc_codes = af9015_rc_setup_match(777af9015_config.eeprom_sum, af9015_rc_setup_hashes);778779/* try to load remote based USB ID */780if (!props->rc.core.rc_codes)781props->rc.core.rc_codes = af9015_rc_setup_match(782(vid << 16) + pid, af9015_rc_setup_usbids);783784/* try to load remote based USB iManufacturer string */785if (!props->rc.core.rc_codes && vid == USB_VID_AFATECH) {786/* Check USB manufacturer and product strings and try787to determine correct remote in case of chip vendor788reference IDs are used.789DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */790char manufacturer[10];791memset(manufacturer, 0, sizeof(manufacturer));792usb_string(udev, udev->descriptor.iManufacturer,793manufacturer, sizeof(manufacturer));794if (!strcmp("MSI", manufacturer)) {795/* iManufacturer 1 MSI796iProduct 2 MSI K-VOX */797props->rc.core.rc_codes = af9015_rc_setup_match(798AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,799af9015_rc_setup_modparam);800}801}802803/* finally load "empty" just for leaving IR receiver enabled */804if (!props->rc.core.rc_codes)805props->rc.core.rc_codes = RC_MAP_EMPTY;806807return;808}809810static int af9015_read_config(struct usb_device *udev)811{812int ret;813u8 val, i, offset = 0;814struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};815816/* IR remote controller */817req.addr = AF9015_EEPROM_IR_MODE;818/* first message will timeout often due to possible hw bug */819for (i = 0; i < 4; i++) {820ret = af9015_rw_udev(udev, &req);821if (!ret)822break;823}824if (ret)825goto error;826827ret = af9015_eeprom_hash(udev);828if (ret)829goto error;830831deb_info("%s: IR mode:%d\n", __func__, val);832for (i = 0; i < af9015_properties_count; i++) {833if (val == AF9015_IR_MODE_DISABLED)834af9015_properties[i].rc.core.rc_codes = NULL;835else836af9015_set_remote_config(udev, &af9015_properties[i]);837}838839/* TS mode - one or two receivers */840req.addr = AF9015_EEPROM_TS_MODE;841ret = af9015_rw_udev(udev, &req);842if (ret)843goto error;844af9015_config.dual_mode = val;845deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode);846847/* Set adapter0 buffer size according to USB port speed, adapter1 buffer848size can be static because it is enabled only USB2.0 */849for (i = 0; i < af9015_properties_count; i++) {850/* USB1.1 set smaller buffersize and disable 2nd adapter */851if (udev->speed == USB_SPEED_FULL) {852af9015_properties[i].adapter[0].stream.u.bulk.buffersize853= TS_USB11_FRAME_SIZE;854/* disable 2nd adapter because we don't have855PID-filters */856af9015_config.dual_mode = 0;857} else {858af9015_properties[i].adapter[0].stream.u.bulk.buffersize859= TS_USB20_FRAME_SIZE;860}861}862863if (af9015_config.dual_mode) {864/* read 2nd demodulator I2C address */865req.addr = AF9015_EEPROM_DEMOD2_I2C;866ret = af9015_rw_udev(udev, &req);867if (ret)868goto error;869af9015_af9013_config[1].demod_address = val;870871/* enable 2nd adapter */872for (i = 0; i < af9015_properties_count; i++)873af9015_properties[i].num_adapters = 2;874875} else {876/* disable 2nd adapter */877for (i = 0; i < af9015_properties_count; i++)878af9015_properties[i].num_adapters = 1;879}880881for (i = 0; i < af9015_properties[0].num_adapters; i++) {882if (i == 1)883offset = AF9015_EEPROM_OFFSET;884/* xtal */885req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset;886ret = af9015_rw_udev(udev, &req);887if (ret)888goto error;889switch (val) {890case 0:891af9015_af9013_config[i].adc_clock = 28800;892break;893case 1:894af9015_af9013_config[i].adc_clock = 20480;895break;896case 2:897af9015_af9013_config[i].adc_clock = 28000;898break;899case 3:900af9015_af9013_config[i].adc_clock = 25000;901break;902};903deb_info("%s: [%d] xtal:%d set adc_clock:%d\n", __func__, i,904val, af9015_af9013_config[i].adc_clock);905906/* tuner IF */907req.addr = AF9015_EEPROM_IF1H + offset;908ret = af9015_rw_udev(udev, &req);909if (ret)910goto error;911af9015_af9013_config[i].tuner_if = val << 8;912req.addr = AF9015_EEPROM_IF1L + offset;913ret = af9015_rw_udev(udev, &req);914if (ret)915goto error;916af9015_af9013_config[i].tuner_if += val;917deb_info("%s: [%d] IF1:%d\n", __func__, i,918af9015_af9013_config[0].tuner_if);919920/* MT2060 IF1 */921req.addr = AF9015_EEPROM_MT2060_IF1H + offset;922ret = af9015_rw_udev(udev, &req);923if (ret)924goto error;925af9015_config.mt2060_if1[i] = val << 8;926req.addr = AF9015_EEPROM_MT2060_IF1L + offset;927ret = af9015_rw_udev(udev, &req);928if (ret)929goto error;930af9015_config.mt2060_if1[i] += val;931deb_info("%s: [%d] MT2060 IF1:%d\n", __func__, i,932af9015_config.mt2060_if1[i]);933934/* tuner */935req.addr = AF9015_EEPROM_TUNER_ID1 + offset;936ret = af9015_rw_udev(udev, &req);937if (ret)938goto error;939switch (val) {940case AF9013_TUNER_ENV77H11D5:941case AF9013_TUNER_MT2060:942case AF9013_TUNER_QT1010:943case AF9013_TUNER_UNKNOWN:944case AF9013_TUNER_MT2060_2:945case AF9013_TUNER_TDA18271:946case AF9013_TUNER_QT1010A:947case AF9013_TUNER_TDA18218:948af9015_af9013_config[i].rf_spec_inv = 1;949break;950case AF9013_TUNER_MXL5003D:951case AF9013_TUNER_MXL5005D:952case AF9013_TUNER_MXL5005R:953case AF9013_TUNER_MXL5007T:954af9015_af9013_config[i].rf_spec_inv = 0;955break;956case AF9013_TUNER_MC44S803:957af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;958af9015_af9013_config[i].rf_spec_inv = 1;959break;960default:961warn("tuner id:%d not supported, please report!", val);962return -ENODEV;963};964965af9015_af9013_config[i].tuner = val;966deb_info("%s: [%d] tuner id:%d\n", __func__, i, val);967}968969error:970if (ret)971err("eeprom read failed:%d", ret);972973/* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM974content :-( Override some wrong values here. Ditto for the975AVerTV Red HD+ (A850T) device. */976if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_AVERMEDIA &&977((le16_to_cpu(udev->descriptor.idProduct) ==978USB_PID_AVERMEDIA_A850) ||979(le16_to_cpu(udev->descriptor.idProduct) ==980USB_PID_AVERMEDIA_A850T))) {981deb_info("%s: AverMedia A850: overriding config\n", __func__);982/* disable dual mode */983af9015_config.dual_mode = 0;984/* disable 2nd adapter */985for (i = 0; i < af9015_properties_count; i++)986af9015_properties[i].num_adapters = 1;987988/* set correct IF */989af9015_af9013_config[0].tuner_if = 4570;990}991992return ret;993}994995static int af9015_identify_state(struct usb_device *udev,996struct dvb_usb_device_properties *props,997struct dvb_usb_device_description **desc,998int *cold)999{1000int ret;1001u8 reply;1002struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};10031004ret = af9015_rw_udev(udev, &req);1005if (ret)1006return ret;10071008deb_info("%s: reply:%02x\n", __func__, reply);1009if (reply == 0x02)1010*cold = 0;1011else1012*cold = 1;10131014return ret;1015}10161017static int af9015_rc_query(struct dvb_usb_device *d)1018{1019struct af9015_state *priv = d->priv;1020int ret;1021u8 buf[17];10221023/* read registers needed to detect remote controller code */1024ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf));1025if (ret)1026goto error;10271028/* If any of these are non-zero, assume invalid data */1029if (buf[1] || buf[2] || buf[3])1030return ret;10311032/* Check for repeat of previous code */1033if ((priv->rc_repeat != buf[6] || buf[0]) &&1034!memcmp(&buf[12], priv->rc_last, 4)) {1035deb_rc("%s: key repeated\n", __func__);1036rc_keydown(d->rc_dev, priv->rc_keycode, 0);1037priv->rc_repeat = buf[6];1038return ret;1039}10401041/* Only process key if canary killed */1042if (buf[16] != 0xff && buf[0] != 0x01) {1043deb_rc("%s: key pressed %02x %02x %02x %02x\n", __func__,1044buf[12], buf[13], buf[14], buf[15]);10451046/* Reset the canary */1047ret = af9015_write_reg(d, 0x98e9, 0xff);1048if (ret)1049goto error;10501051/* Remember this key */1052memcpy(priv->rc_last, &buf[12], 4);1053if (buf[14] == (u8) ~buf[15]) {1054if (buf[12] == (u8) ~buf[13]) {1055/* NEC */1056priv->rc_keycode = buf[12] << 8 | buf[14];1057} else {1058/* NEC extended*/1059priv->rc_keycode = buf[12] << 16 |1060buf[13] << 8 | buf[14];1061}1062} else {1063/* 32 bit NEC */1064priv->rc_keycode = buf[12] << 24 | buf[13] << 16 |1065buf[14] << 8 | buf[15];1066}1067rc_keydown(d->rc_dev, priv->rc_keycode, 0);1068} else {1069deb_rc("%s: no key press\n", __func__);1070/* Invalidate last keypress */1071/* Not really needed, but helps with debug */1072priv->rc_last[2] = priv->rc_last[3];1073}10741075priv->rc_repeat = buf[6];10761077error:1078if (ret)1079err("%s: failed:%d", __func__, ret);10801081return ret;1082}10831084/* init 2nd I2C adapter */1085static int af9015_i2c_init(struct dvb_usb_device *d)1086{1087int ret;1088struct af9015_state *state = d->priv;1089deb_info("%s:\n", __func__);10901091strncpy(state->i2c_adap.name, d->desc->name,1092sizeof(state->i2c_adap.name));1093state->i2c_adap.algo = d->props.i2c_algo;1094state->i2c_adap.algo_data = NULL;1095state->i2c_adap.dev.parent = &d->udev->dev;10961097i2c_set_adapdata(&state->i2c_adap, d);10981099ret = i2c_add_adapter(&state->i2c_adap);1100if (ret < 0)1101err("could not add i2c adapter");11021103return ret;1104}11051106static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)1107{1108int ret;1109struct af9015_state *state = adap->dev->priv;1110struct i2c_adapter *i2c_adap;11111112if (adap->id == 0) {1113/* select I2C adapter */1114i2c_adap = &adap->dev->i2c_adap;11151116deb_info("%s: init I2C\n", __func__);1117ret = af9015_i2c_init(adap->dev);1118} else {1119/* select I2C adapter */1120i2c_adap = &state->i2c_adap;11211122/* copy firmware to 2nd demodulator */1123if (af9015_config.dual_mode) {1124ret = af9015_copy_firmware(adap->dev);1125if (ret) {1126err("firmware copy to 2nd frontend " \1127"failed, will disable it");1128af9015_config.dual_mode = 0;1129return -ENODEV;1130}1131} else {1132return -ENODEV;1133}1134}11351136/* attach demodulator */1137adap->fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id],1138i2c_adap);11391140return adap->fe == NULL ? -ENODEV : 0;1141}11421143static struct mt2060_config af9015_mt2060_config = {1144.i2c_address = 0xc0,1145.clock_out = 0,1146};11471148static struct qt1010_config af9015_qt1010_config = {1149.i2c_address = 0xc4,1150};11511152static struct tda18271_config af9015_tda18271_config = {1153.gate = TDA18271_GATE_DIGITAL,1154.small_i2c = TDA18271_16_BYTE_CHUNK_INIT,1155};11561157static struct mxl5005s_config af9015_mxl5003_config = {1158.i2c_address = 0xc6,1159.if_freq = IF_FREQ_4570000HZ,1160.xtal_freq = CRYSTAL_FREQ_16000000HZ,1161.agc_mode = MXL_SINGLE_AGC,1162.tracking_filter = MXL_TF_DEFAULT,1163.rssi_enable = MXL_RSSI_ENABLE,1164.cap_select = MXL_CAP_SEL_ENABLE,1165.div_out = MXL_DIV_OUT_4,1166.clock_out = MXL_CLOCK_OUT_DISABLE,1167.output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,1168.top = MXL5005S_TOP_25P2,1169.mod_mode = MXL_DIGITAL_MODE,1170.if_mode = MXL_ZERO_IF,1171.AgcMasterByte = 0x00,1172};11731174static struct mxl5005s_config af9015_mxl5005_config = {1175.i2c_address = 0xc6,1176.if_freq = IF_FREQ_4570000HZ,1177.xtal_freq = CRYSTAL_FREQ_16000000HZ,1178.agc_mode = MXL_SINGLE_AGC,1179.tracking_filter = MXL_TF_OFF,1180.rssi_enable = MXL_RSSI_ENABLE,1181.cap_select = MXL_CAP_SEL_ENABLE,1182.div_out = MXL_DIV_OUT_4,1183.clock_out = MXL_CLOCK_OUT_DISABLE,1184.output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,1185.top = MXL5005S_TOP_25P2,1186.mod_mode = MXL_DIGITAL_MODE,1187.if_mode = MXL_ZERO_IF,1188.AgcMasterByte = 0x00,1189};11901191static struct mc44s803_config af9015_mc44s803_config = {1192.i2c_address = 0xc0,1193.dig_out = 1,1194};11951196static struct tda18218_config af9015_tda18218_config = {1197.i2c_address = 0xc0,1198.i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */1199};12001201static struct mxl5007t_config af9015_mxl5007t_config = {1202.xtal_freq_hz = MxL_XTAL_24_MHZ,1203.if_freq_hz = MxL_IF_4_57_MHZ,1204};12051206static int af9015_tuner_attach(struct dvb_usb_adapter *adap)1207{1208struct af9015_state *state = adap->dev->priv;1209struct i2c_adapter *i2c_adap;1210int ret;1211deb_info("%s:\n", __func__);12121213/* select I2C adapter */1214if (adap->id == 0)1215i2c_adap = &adap->dev->i2c_adap;1216else1217i2c_adap = &state->i2c_adap;12181219switch (af9015_af9013_config[adap->id].tuner) {1220case AF9013_TUNER_MT2060:1221case AF9013_TUNER_MT2060_2:1222ret = dvb_attach(mt2060_attach, adap->fe, i2c_adap,1223&af9015_mt2060_config,1224af9015_config.mt2060_if1[adap->id])1225== NULL ? -ENODEV : 0;1226break;1227case AF9013_TUNER_QT1010:1228case AF9013_TUNER_QT1010A:1229ret = dvb_attach(qt1010_attach, adap->fe, i2c_adap,1230&af9015_qt1010_config) == NULL ? -ENODEV : 0;1231break;1232case AF9013_TUNER_TDA18271:1233ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap,1234&af9015_tda18271_config) == NULL ? -ENODEV : 0;1235break;1236case AF9013_TUNER_TDA18218:1237ret = dvb_attach(tda18218_attach, adap->fe, i2c_adap,1238&af9015_tda18218_config) == NULL ? -ENODEV : 0;1239break;1240case AF9013_TUNER_MXL5003D:1241ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,1242&af9015_mxl5003_config) == NULL ? -ENODEV : 0;1243break;1244case AF9013_TUNER_MXL5005D:1245case AF9013_TUNER_MXL5005R:1246ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,1247&af9015_mxl5005_config) == NULL ? -ENODEV : 0;1248break;1249case AF9013_TUNER_ENV77H11D5:1250ret = dvb_attach(dvb_pll_attach, adap->fe, 0xc0, i2c_adap,1251DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;1252break;1253case AF9013_TUNER_MC44S803:1254ret = dvb_attach(mc44s803_attach, adap->fe, i2c_adap,1255&af9015_mc44s803_config) == NULL ? -ENODEV : 0;1256break;1257case AF9013_TUNER_MXL5007T:1258ret = dvb_attach(mxl5007t_attach, adap->fe, i2c_adap,12590xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;1260break;1261case AF9013_TUNER_UNKNOWN:1262default:1263ret = -ENODEV;1264err("Unknown tuner id:%d",1265af9015_af9013_config[adap->id].tuner);1266}1267return ret;1268}12691270static struct usb_device_id af9015_usb_table[] = {1271/* 0 */{USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015)},1272{USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016)},1273{USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD)},1274{USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E)},1275{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U)},1276/* 5 */{USB_DEVICE(USB_VID_VISIONPLUS,1277USB_PID_TINYTWIN)},1278{USB_DEVICE(USB_VID_VISIONPLUS,1279USB_PID_AZUREWAVE_AD_TU700)},1280{USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)},1281{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T)},1282{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)},1283/* 10 */{USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)},1284{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO)},1285{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)},1286{USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2)},1287{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)},1288/* 15 */{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)},1289{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)},1290{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2)},1291{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_3)},1292{USB_DEVICE(USB_VID_AFATECH, USB_PID_TREKSTOR_DVBT)},1293/* 20 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850)},1294{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A805)},1295{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CONCEPTRONIC_CTVDIGRCU)},1296{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_MC810)},1297{USB_DEVICE(USB_VID_KYE, USB_PID_GENIUS_TVGO_DVB_T03)},1298/* 25 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2)},1299{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T)},1300{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20)},1301{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2)},1302{USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)},1303/* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)},1304{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)},1305{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)},1306{USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC)},1307{USB_DEVICE(USB_VID_TERRATEC,1308USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC)},1309/* 35 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T)},1310{USB_DEVICE(USB_VID_GTEK, USB_PID_TINYTWIN_3)},1311{0},1312};1313MODULE_DEVICE_TABLE(usb, af9015_usb_table);13141315#define AF9015_RC_INTERVAL 5001316static struct dvb_usb_device_properties af9015_properties[] = {1317{1318.caps = DVB_USB_IS_AN_I2C_ADAPTER,13191320.usb_ctrl = DEVICE_SPECIFIC,1321.download_firmware = af9015_download_firmware,1322.firmware = "dvb-usb-af9015.fw",1323.no_reconnect = 1,13241325.size_of_priv = sizeof(struct af9015_state),13261327.num_adapters = 2,1328.adapter = {1329{1330.caps = DVB_USB_ADAP_HAS_PID_FILTER |1331DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,13321333.pid_filter_count = 32,1334.pid_filter = af9015_pid_filter,1335.pid_filter_ctrl = af9015_pid_filter_ctrl,13361337.frontend_attach =1338af9015_af9013_frontend_attach,1339.tuner_attach = af9015_tuner_attach,1340.stream = {1341.type = USB_BULK,1342.count = 6,1343.endpoint = 0x84,1344},1345},1346{1347.frontend_attach =1348af9015_af9013_frontend_attach,1349.tuner_attach = af9015_tuner_attach,1350.stream = {1351.type = USB_BULK,1352.count = 6,1353.endpoint = 0x85,1354.u = {1355.bulk = {1356.buffersize =1357TS_USB20_FRAME_SIZE,1358}1359}1360},1361}1362},13631364.identify_state = af9015_identify_state,13651366.rc.core = {1367.protocol = RC_TYPE_NEC,1368.module_name = "af9015",1369.rc_query = af9015_rc_query,1370.rc_interval = AF9015_RC_INTERVAL,1371.allowed_protos = RC_TYPE_NEC,1372},13731374.i2c_algo = &af9015_i2c_algo,13751376.num_device_descs = 12, /* check max from dvb-usb.h */1377.devices = {1378{1379.name = "Afatech AF9015 DVB-T USB2.0 stick",1380.cold_ids = {&af9015_usb_table[0],1381&af9015_usb_table[1], NULL},1382.warm_ids = {NULL},1383},1384{1385.name = "Leadtek WinFast DTV Dongle Gold",1386.cold_ids = {&af9015_usb_table[2], NULL},1387.warm_ids = {NULL},1388},1389{1390.name = "Pinnacle PCTV 71e",1391.cold_ids = {&af9015_usb_table[3], NULL},1392.warm_ids = {NULL},1393},1394{1395.name = "KWorld PlusTV Dual DVB-T Stick " \1396"(DVB-T 399U)",1397.cold_ids = {&af9015_usb_table[4],1398&af9015_usb_table[25], NULL},1399.warm_ids = {NULL},1400},1401{1402.name = "DigitalNow TinyTwin DVB-T Receiver",1403.cold_ids = {&af9015_usb_table[5],1404&af9015_usb_table[28],1405&af9015_usb_table[36], NULL},1406.warm_ids = {NULL},1407},1408{1409.name = "TwinHan AzureWave AD-TU700(704J)",1410.cold_ids = {&af9015_usb_table[6], NULL},1411.warm_ids = {NULL},1412},1413{1414.name = "TerraTec Cinergy T USB XE",1415.cold_ids = {&af9015_usb_table[7], NULL},1416.warm_ids = {NULL},1417},1418{1419.name = "KWorld PlusTV Dual DVB-T PCI " \1420"(DVB-T PC160-2T)",1421.cold_ids = {&af9015_usb_table[8], NULL},1422.warm_ids = {NULL},1423},1424{1425.name = "AVerMedia AVerTV DVB-T Volar X",1426.cold_ids = {&af9015_usb_table[9], NULL},1427.warm_ids = {NULL},1428},1429{1430.name = "TerraTec Cinergy T Stick RC",1431.cold_ids = {&af9015_usb_table[33], NULL},1432.warm_ids = {NULL},1433},1434{1435.name = "TerraTec Cinergy T Stick Dual RC",1436.cold_ids = {&af9015_usb_table[34], NULL},1437.warm_ids = {NULL},1438},1439{1440.name = "AverMedia AVerTV Red HD+ (A850T)",1441.cold_ids = {&af9015_usb_table[35], NULL},1442.warm_ids = {NULL},1443},1444}1445}, {1446.caps = DVB_USB_IS_AN_I2C_ADAPTER,14471448.usb_ctrl = DEVICE_SPECIFIC,1449.download_firmware = af9015_download_firmware,1450.firmware = "dvb-usb-af9015.fw",1451.no_reconnect = 1,14521453.size_of_priv = sizeof(struct af9015_state),14541455.num_adapters = 2,1456.adapter = {1457{1458.caps = DVB_USB_ADAP_HAS_PID_FILTER |1459DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,14601461.pid_filter_count = 32,1462.pid_filter = af9015_pid_filter,1463.pid_filter_ctrl = af9015_pid_filter_ctrl,14641465.frontend_attach =1466af9015_af9013_frontend_attach,1467.tuner_attach = af9015_tuner_attach,1468.stream = {1469.type = USB_BULK,1470.count = 6,1471.endpoint = 0x84,1472},1473},1474{1475.frontend_attach =1476af9015_af9013_frontend_attach,1477.tuner_attach = af9015_tuner_attach,1478.stream = {1479.type = USB_BULK,1480.count = 6,1481.endpoint = 0x85,1482.u = {1483.bulk = {1484.buffersize =1485TS_USB20_FRAME_SIZE,1486}1487}1488},1489}1490},14911492.identify_state = af9015_identify_state,14931494.rc.core = {1495.protocol = RC_TYPE_NEC,1496.module_name = "af9015",1497.rc_query = af9015_rc_query,1498.rc_interval = AF9015_RC_INTERVAL,1499.allowed_protos = RC_TYPE_NEC,1500},15011502.i2c_algo = &af9015_i2c_algo,15031504.num_device_descs = 9, /* check max from dvb-usb.h */1505.devices = {1506{1507.name = "Xtensions XD-380",1508.cold_ids = {&af9015_usb_table[10], NULL},1509.warm_ids = {NULL},1510},1511{1512.name = "MSI DIGIVOX Duo",1513.cold_ids = {&af9015_usb_table[11], NULL},1514.warm_ids = {NULL},1515},1516{1517.name = "Fujitsu-Siemens Slim Mobile USB DVB-T",1518.cold_ids = {&af9015_usb_table[12], NULL},1519.warm_ids = {NULL},1520},1521{1522.name = "Telestar Starstick 2",1523.cold_ids = {&af9015_usb_table[13], NULL},1524.warm_ids = {NULL},1525},1526{1527.name = "AVerMedia A309",1528.cold_ids = {&af9015_usb_table[14], NULL},1529.warm_ids = {NULL},1530},1531{1532.name = "MSI Digi VOX mini III",1533.cold_ids = {&af9015_usb_table[15], NULL},1534.warm_ids = {NULL},1535},1536{1537.name = "KWorld USB DVB-T TV Stick II " \1538"(VS-DVB-T 395U)",1539.cold_ids = {&af9015_usb_table[16],1540&af9015_usb_table[17],1541&af9015_usb_table[18],1542&af9015_usb_table[31], NULL},1543.warm_ids = {NULL},1544},1545{1546.name = "TrekStor DVB-T USB Stick",1547.cold_ids = {&af9015_usb_table[19], NULL},1548.warm_ids = {NULL},1549},1550{1551.name = "AverMedia AVerTV Volar Black HD " \1552"(A850)",1553.cold_ids = {&af9015_usb_table[20], NULL},1554.warm_ids = {NULL},1555},1556}1557}, {1558.caps = DVB_USB_IS_AN_I2C_ADAPTER,15591560.usb_ctrl = DEVICE_SPECIFIC,1561.download_firmware = af9015_download_firmware,1562.firmware = "dvb-usb-af9015.fw",1563.no_reconnect = 1,15641565.size_of_priv = sizeof(struct af9015_state),15661567.num_adapters = 2,1568.adapter = {1569{1570.caps = DVB_USB_ADAP_HAS_PID_FILTER |1571DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,15721573.pid_filter_count = 32,1574.pid_filter = af9015_pid_filter,1575.pid_filter_ctrl = af9015_pid_filter_ctrl,15761577.frontend_attach =1578af9015_af9013_frontend_attach,1579.tuner_attach = af9015_tuner_attach,1580.stream = {1581.type = USB_BULK,1582.count = 6,1583.endpoint = 0x84,1584},1585},1586{1587.frontend_attach =1588af9015_af9013_frontend_attach,1589.tuner_attach = af9015_tuner_attach,1590.stream = {1591.type = USB_BULK,1592.count = 6,1593.endpoint = 0x85,1594.u = {1595.bulk = {1596.buffersize =1597TS_USB20_FRAME_SIZE,1598}1599}1600},1601}1602},16031604.identify_state = af9015_identify_state,16051606.rc.core = {1607.protocol = RC_TYPE_NEC,1608.module_name = "af9015",1609.rc_query = af9015_rc_query,1610.rc_interval = AF9015_RC_INTERVAL,1611.allowed_protos = RC_TYPE_NEC,1612},16131614.i2c_algo = &af9015_i2c_algo,16151616.num_device_descs = 9, /* check max from dvb-usb.h */1617.devices = {1618{1619.name = "AverMedia AVerTV Volar GPS 805 (A805)",1620.cold_ids = {&af9015_usb_table[21], NULL},1621.warm_ids = {NULL},1622},1623{1624.name = "Conceptronic USB2.0 DVB-T CTVDIGRCU " \1625"V3.0",1626.cold_ids = {&af9015_usb_table[22], NULL},1627.warm_ids = {NULL},1628},1629{1630.name = "KWorld Digial MC-810",1631.cold_ids = {&af9015_usb_table[23], NULL},1632.warm_ids = {NULL},1633},1634{1635.name = "Genius TVGo DVB-T03",1636.cold_ids = {&af9015_usb_table[24], NULL},1637.warm_ids = {NULL},1638},1639{1640.name = "KWorld PlusTV DVB-T PCI Pro Card " \1641"(DVB-T PC160-T)",1642.cold_ids = {&af9015_usb_table[26], NULL},1643.warm_ids = {NULL},1644},1645{1646.name = "Sveon STV20 Tuner USB DVB-T HDTV",1647.cold_ids = {&af9015_usb_table[27], NULL},1648.warm_ids = {NULL},1649},1650{1651.name = "Leadtek WinFast DTV2000DS",1652.cold_ids = {&af9015_usb_table[29], NULL},1653.warm_ids = {NULL},1654},1655{1656.name = "KWorld USB DVB-T Stick Mobile " \1657"(UB383-T)",1658.cold_ids = {&af9015_usb_table[30], NULL},1659.warm_ids = {NULL},1660},1661{1662.name = "AverMedia AVerTV Volar M (A815Mac)",1663.cold_ids = {&af9015_usb_table[32], NULL},1664.warm_ids = {NULL},1665},1666}1667},1668};16691670static int af9015_usb_probe(struct usb_interface *intf,1671const struct usb_device_id *id)1672{1673int ret = 0;1674struct dvb_usb_device *d = NULL;1675struct usb_device *udev = interface_to_usbdev(intf);1676u8 i;16771678deb_info("%s: interface:%d\n", __func__,1679intf->cur_altsetting->desc.bInterfaceNumber);16801681/* interface 0 is used by DVB-T receiver and1682interface 1 is for remote controller (HID) */1683if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {1684ret = af9015_read_config(udev);1685if (ret)1686return ret;16871688for (i = 0; i < af9015_properties_count; i++) {1689ret = dvb_usb_device_init(intf, &af9015_properties[i],1690THIS_MODULE, &d, adapter_nr);1691if (!ret)1692break;1693if (ret != -ENODEV)1694return ret;1695}1696if (ret)1697return ret;16981699if (d)1700ret = af9015_init(d);1701}17021703return ret;1704}17051706static void af9015_i2c_exit(struct dvb_usb_device *d)1707{1708struct af9015_state *state = d->priv;1709deb_info("%s:\n", __func__);17101711/* remove 2nd I2C adapter */1712if (d->state & DVB_USB_STATE_I2C)1713i2c_del_adapter(&state->i2c_adap);1714}17151716static void af9015_usb_device_exit(struct usb_interface *intf)1717{1718struct dvb_usb_device *d = usb_get_intfdata(intf);1719deb_info("%s:\n", __func__);17201721/* remove 2nd I2C adapter */1722if (d != NULL && d->desc != NULL)1723af9015_i2c_exit(d);17241725dvb_usb_device_exit(intf);1726}17271728/* usb specific object needed to register this driver with the usb subsystem */1729static struct usb_driver af9015_usb_driver = {1730.name = "dvb_usb_af9015",1731.probe = af9015_usb_probe,1732.disconnect = af9015_usb_device_exit,1733.id_table = af9015_usb_table,1734};17351736/* module stuff */1737static int __init af9015_usb_module_init(void)1738{1739int ret;1740ret = usb_register(&af9015_usb_driver);1741if (ret)1742err("module init failed:%d", ret);17431744return ret;1745}17461747static void __exit af9015_usb_module_exit(void)1748{1749/* deregister this driver from the USB subsystem */1750usb_deregister(&af9015_usb_driver);1751}17521753module_init(af9015_usb_module_init);1754module_exit(af9015_usb_module_exit);17551756MODULE_AUTHOR("Antti Palosaari <[email protected]>");1757MODULE_DESCRIPTION("Driver for Afatech AF9015 DVB-T");1758MODULE_LICENSE("GPL");175917601761