Path: blob/master/drivers/media/dvb/dvb-usb/cxusb.c
15111 views
/* DVB USB compliant linux driver for Conexant USB reference design.1*2* The Conexant reference design I saw on their website was only for analogue3* capturing (using the cx25842). The box I took to write this driver (reverse4* engineered) is the one labeled Medion MD95700. In addition to the cx258425* for analogue capturing it also has a cx22702 DVB-T demodulator on the main6* board. Besides it has a atiremote (X10) and a USB2.0 hub onboard.7*8* Maybe it is a little bit premature to call this driver cxusb, but I assume9* the USB protocol is identical or at least inherited from the reference10* design, so it can be reused for the "analogue-only" device (if it will11* appear at all).12*13* TODO: Use the cx25840-driver for the analogue part14*15* Copyright (C) 2005 Patrick Boettcher ([email protected])16* Copyright (C) 2006 Michael Krufky ([email protected])17* Copyright (C) 2006, 2007 Chris Pascoe ([email protected])18*19* This program is free software; you can redistribute it and/or modify it20* under the terms of the GNU General Public License as published by the Free21* Software Foundation, version 2.22*23* see Documentation/dvb/README.dvb-usb for more information24*/25#include <media/tuner.h>26#include <linux/vmalloc.h>27#include <linux/slab.h>2829#include "cxusb.h"3031#include "cx22702.h"32#include "lgdt330x.h"33#include "mt352.h"34#include "mt352_priv.h"35#include "zl10353.h"36#include "tuner-xc2028.h"37#include "tuner-simple.h"38#include "mxl5005s.h"39#include "max2165.h"40#include "dib7000p.h"41#include "dib0070.h"42#include "lgs8gxx.h"43#include "atbm8830.h"4445/* debug */46static int dvb_usb_cxusb_debug;47module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);48MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);4950DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);5152#define deb_info(args...) dprintk(dvb_usb_cxusb_debug, 0x03, args)53#define deb_i2c(args...) dprintk(dvb_usb_cxusb_debug, 0x02, args)5455static int cxusb_ctrl_msg(struct dvb_usb_device *d,56u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)57{58int wo = (rbuf == NULL || rlen == 0); /* write-only */59u8 sndbuf[1+wlen];60memset(sndbuf, 0, 1+wlen);6162sndbuf[0] = cmd;63memcpy(&sndbuf[1], wbuf, wlen);64if (wo)65return dvb_usb_generic_write(d, sndbuf, 1+wlen);66else67return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);68}6970/* GPIO */71static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)72{73struct cxusb_state *st = d->priv;74u8 o[2], i;7576if (st->gpio_write_state[GPIO_TUNER] == onoff)77return;7879o[0] = GPIO_TUNER;80o[1] = onoff;81cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);8283if (i != 0x01)84deb_info("gpio_write failed.\n");8586st->gpio_write_state[GPIO_TUNER] = onoff;87}8889static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,90u8 newval)91{92u8 o[2], gpio_state;93int rc;9495o[0] = 0xff & ~changemask; /* mask of bits to keep */96o[1] = newval & changemask; /* new values for bits */9798rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);99if (rc < 0 || (gpio_state & changemask) != (newval & changemask))100deb_info("bluebird_gpio_write failed.\n");101102return rc < 0 ? rc : gpio_state;103}104105static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)106{107cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);108msleep(5);109cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);110}111112static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)113{114cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);115}116117static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,118u8 addr, int onoff)119{120u8 o[2] = {addr, onoff};121u8 i;122int rc;123124rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);125126if (rc < 0)127return rc;128if (i == 0x01)129return 0;130else {131deb_info("gpio_write failed.\n");132return -EIO;133}134}135136/* I2C */137static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],138int num)139{140struct dvb_usb_device *d = i2c_get_adapdata(adap);141int i;142143if (mutex_lock_interruptible(&d->i2c_mutex) < 0)144return -EAGAIN;145146for (i = 0; i < num; i++) {147148if (d->udev->descriptor.idVendor == USB_VID_MEDION)149switch (msg[i].addr) {150case 0x63:151cxusb_gpio_tuner(d, 0);152break;153default:154cxusb_gpio_tuner(d, 1);155break;156}157158if (msg[i].flags & I2C_M_RD) {159/* read only */160u8 obuf[3], ibuf[1+msg[i].len];161obuf[0] = 0;162obuf[1] = msg[i].len;163obuf[2] = msg[i].addr;164if (cxusb_ctrl_msg(d, CMD_I2C_READ,165obuf, 3,166ibuf, 1+msg[i].len) < 0) {167warn("i2c read failed");168break;169}170memcpy(msg[i].buf, &ibuf[1], msg[i].len);171} else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&172msg[i].addr == msg[i+1].addr) {173/* write to then read from same address */174u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];175obuf[0] = msg[i].len;176obuf[1] = msg[i+1].len;177obuf[2] = msg[i].addr;178memcpy(&obuf[3], msg[i].buf, msg[i].len);179180if (cxusb_ctrl_msg(d, CMD_I2C_READ,181obuf, 3+msg[i].len,182ibuf, 1+msg[i+1].len) < 0)183break;184185if (ibuf[0] != 0x08)186deb_i2c("i2c read may have failed\n");187188memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);189190i++;191} else {192/* write only */193u8 obuf[2+msg[i].len], ibuf;194obuf[0] = msg[i].addr;195obuf[1] = msg[i].len;196memcpy(&obuf[2], msg[i].buf, msg[i].len);197198if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,1992+msg[i].len, &ibuf,1) < 0)200break;201if (ibuf != 0x08)202deb_i2c("i2c write may have failed\n");203}204}205206mutex_unlock(&d->i2c_mutex);207return i == num ? num : -EREMOTEIO;208}209210static u32 cxusb_i2c_func(struct i2c_adapter *adapter)211{212return I2C_FUNC_I2C;213}214215static struct i2c_algorithm cxusb_i2c_algo = {216.master_xfer = cxusb_i2c_xfer,217.functionality = cxusb_i2c_func,218};219220static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)221{222u8 b = 0;223if (onoff)224return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);225else226return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);227}228229static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)230{231int ret;232if (!onoff)233return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);234if (d->state == DVB_USB_STATE_INIT &&235usb_set_interface(d->udev, 0, 0) < 0)236err("set interface failed");237do {} while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&238!(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&239!(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);240if (!ret) {241/* FIXME: We don't know why, but we need to configure the242* lgdt3303 with the register settings below on resume */243int i;244u8 buf, bufs[] = {2450x0e, 0x2, 0x00, 0x7f,2460x0e, 0x2, 0x02, 0xfe,2470x0e, 0x2, 0x02, 0x01,2480x0e, 0x2, 0x00, 0x03,2490x0e, 0x2, 0x0d, 0x40,2500x0e, 0x2, 0x0e, 0x87,2510x0e, 0x2, 0x0f, 0x8e,2520x0e, 0x2, 0x10, 0x01,2530x0e, 0x2, 0x14, 0xd7,2540x0e, 0x2, 0x47, 0x88,255};256msleep(20);257for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {258ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,259bufs+i, 4, &buf, 1);260if (ret)261break;262if (buf != 0x8)263return -EREMOTEIO;264}265}266return ret;267}268269static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)270{271u8 b = 0;272if (onoff)273return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);274else275return 0;276}277278static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)279{280int rc = 0;281282rc = cxusb_power_ctrl(d, onoff);283if (!onoff)284cxusb_nano2_led(d, 0);285286return rc;287}288289static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)290{291int ret;292u8 b;293ret = cxusb_power_ctrl(d, onoff);294if (!onoff)295return ret;296297msleep(128);298cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);299msleep(100);300return ret;301}302303static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)304{305u8 buf[2] = { 0x03, 0x00 };306if (onoff)307cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON, buf, 2, NULL, 0);308else309cxusb_ctrl_msg(adap->dev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);310311return 0;312}313314static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)315{316if (onoff)317cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_ON, NULL, 0, NULL, 0);318else319cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,320NULL, 0, NULL, 0);321return 0;322}323324static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)325{326int ep = d->props.generic_bulk_ctrl_endpoint;327const int timeout = 100;328const int junk_len = 32;329u8 *junk;330int rd_count;331332/* Discard remaining data in video pipe */333junk = kmalloc(junk_len, GFP_KERNEL);334if (!junk)335return;336while (1) {337if (usb_bulk_msg(d->udev,338usb_rcvbulkpipe(d->udev, ep),339junk, junk_len, &rd_count, timeout) < 0)340break;341if (!rd_count)342break;343}344kfree(junk);345}346347static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)348{349struct usb_data_stream_properties *p = &d->props.adapter[0].stream;350const int timeout = 100;351const int junk_len = p->u.bulk.buffersize;352u8 *junk;353int rd_count;354355/* Discard remaining data in video pipe */356junk = kmalloc(junk_len, GFP_KERNEL);357if (!junk)358return;359while (1) {360if (usb_bulk_msg(d->udev,361usb_rcvbulkpipe(d->udev, p->endpoint),362junk, junk_len, &rd_count, timeout) < 0)363break;364if (!rd_count)365break;366}367kfree(junk);368}369370static int cxusb_d680_dmb_streaming_ctrl(371struct dvb_usb_adapter *adap, int onoff)372{373if (onoff) {374u8 buf[2] = { 0x03, 0x00 };375cxusb_d680_dmb_drain_video(adap->dev);376return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,377buf, sizeof(buf), NULL, 0);378} else {379int ret = cxusb_ctrl_msg(adap->dev,380CMD_STREAMING_OFF, NULL, 0, NULL, 0);381return ret;382}383}384385static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)386{387struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;388u8 ircode[4];389int i;390391cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);392393*event = 0;394*state = REMOTE_NO_KEY_PRESSED;395396for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {397if (rc5_custom(&keymap[i]) == ircode[2] &&398rc5_data(&keymap[i]) == ircode[3]) {399*event = keymap[i].keycode;400*state = REMOTE_KEY_PRESSED;401402return 0;403}404}405406return 0;407}408409static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,410int *state)411{412struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;413u8 ircode[4];414int i;415struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,416.buf = ircode, .len = 4 };417418*event = 0;419*state = REMOTE_NO_KEY_PRESSED;420421if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)422return 0;423424for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {425if (rc5_custom(&keymap[i]) == ircode[1] &&426rc5_data(&keymap[i]) == ircode[2]) {427*event = keymap[i].keycode;428*state = REMOTE_KEY_PRESSED;429430return 0;431}432}433434return 0;435}436437static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,438int *state)439{440struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;441u8 ircode[2];442int i;443444*event = 0;445*state = REMOTE_NO_KEY_PRESSED;446447if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)448return 0;449450for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {451if (rc5_custom(&keymap[i]) == ircode[0] &&452rc5_data(&keymap[i]) == ircode[1]) {453*event = keymap[i].keycode;454*state = REMOTE_KEY_PRESSED;455456return 0;457}458}459460return 0;461}462463static struct rc_map_table rc_map_dvico_mce_table[] = {464{ 0xfe02, KEY_TV },465{ 0xfe0e, KEY_MP3 },466{ 0xfe1a, KEY_DVD },467{ 0xfe1e, KEY_FAVORITES },468{ 0xfe16, KEY_SETUP },469{ 0xfe46, KEY_POWER2 },470{ 0xfe0a, KEY_EPG },471{ 0xfe49, KEY_BACK },472{ 0xfe4d, KEY_MENU },473{ 0xfe51, KEY_UP },474{ 0xfe5b, KEY_LEFT },475{ 0xfe5f, KEY_RIGHT },476{ 0xfe53, KEY_DOWN },477{ 0xfe5e, KEY_OK },478{ 0xfe59, KEY_INFO },479{ 0xfe55, KEY_TAB },480{ 0xfe0f, KEY_PREVIOUSSONG },/* Replay */481{ 0xfe12, KEY_NEXTSONG }, /* Skip */482{ 0xfe42, KEY_ENTER }, /* Windows/Start */483{ 0xfe15, KEY_VOLUMEUP },484{ 0xfe05, KEY_VOLUMEDOWN },485{ 0xfe11, KEY_CHANNELUP },486{ 0xfe09, KEY_CHANNELDOWN },487{ 0xfe52, KEY_CAMERA },488{ 0xfe5a, KEY_TUNER }, /* Live */489{ 0xfe19, KEY_OPEN },490{ 0xfe0b, KEY_1 },491{ 0xfe17, KEY_2 },492{ 0xfe1b, KEY_3 },493{ 0xfe07, KEY_4 },494{ 0xfe50, KEY_5 },495{ 0xfe54, KEY_6 },496{ 0xfe48, KEY_7 },497{ 0xfe4c, KEY_8 },498{ 0xfe58, KEY_9 },499{ 0xfe13, KEY_ANGLE }, /* Aspect */500{ 0xfe03, KEY_0 },501{ 0xfe1f, KEY_ZOOM },502{ 0xfe43, KEY_REWIND },503{ 0xfe47, KEY_PLAYPAUSE },504{ 0xfe4f, KEY_FASTFORWARD },505{ 0xfe57, KEY_MUTE },506{ 0xfe0d, KEY_STOP },507{ 0xfe01, KEY_RECORD },508{ 0xfe4e, KEY_POWER },509};510511static struct rc_map_table rc_map_dvico_portable_table[] = {512{ 0xfc02, KEY_SETUP }, /* Profile */513{ 0xfc43, KEY_POWER2 },514{ 0xfc06, KEY_EPG },515{ 0xfc5a, KEY_BACK },516{ 0xfc05, KEY_MENU },517{ 0xfc47, KEY_INFO },518{ 0xfc01, KEY_TAB },519{ 0xfc42, KEY_PREVIOUSSONG },/* Replay */520{ 0xfc49, KEY_VOLUMEUP },521{ 0xfc09, KEY_VOLUMEDOWN },522{ 0xfc54, KEY_CHANNELUP },523{ 0xfc0b, KEY_CHANNELDOWN },524{ 0xfc16, KEY_CAMERA },525{ 0xfc40, KEY_TUNER }, /* ATV/DTV */526{ 0xfc45, KEY_OPEN },527{ 0xfc19, KEY_1 },528{ 0xfc18, KEY_2 },529{ 0xfc1b, KEY_3 },530{ 0xfc1a, KEY_4 },531{ 0xfc58, KEY_5 },532{ 0xfc59, KEY_6 },533{ 0xfc15, KEY_7 },534{ 0xfc14, KEY_8 },535{ 0xfc17, KEY_9 },536{ 0xfc44, KEY_ANGLE }, /* Aspect */537{ 0xfc55, KEY_0 },538{ 0xfc07, KEY_ZOOM },539{ 0xfc0a, KEY_REWIND },540{ 0xfc08, KEY_PLAYPAUSE },541{ 0xfc4b, KEY_FASTFORWARD },542{ 0xfc5b, KEY_MUTE },543{ 0xfc04, KEY_STOP },544{ 0xfc56, KEY_RECORD },545{ 0xfc57, KEY_POWER },546{ 0xfc41, KEY_UNKNOWN }, /* INPUT */547{ 0xfc00, KEY_UNKNOWN }, /* HD */548};549550static struct rc_map_table rc_map_d680_dmb_table[] = {551{ 0x0038, KEY_UNKNOWN }, /* TV/AV */552{ 0x080c, KEY_ZOOM },553{ 0x0800, KEY_0 },554{ 0x0001, KEY_1 },555{ 0x0802, KEY_2 },556{ 0x0003, KEY_3 },557{ 0x0804, KEY_4 },558{ 0x0005, KEY_5 },559{ 0x0806, KEY_6 },560{ 0x0007, KEY_7 },561{ 0x0808, KEY_8 },562{ 0x0009, KEY_9 },563{ 0x000a, KEY_MUTE },564{ 0x0829, KEY_BACK },565{ 0x0012, KEY_CHANNELUP },566{ 0x0813, KEY_CHANNELDOWN },567{ 0x002b, KEY_VOLUMEUP },568{ 0x082c, KEY_VOLUMEDOWN },569{ 0x0020, KEY_UP },570{ 0x0821, KEY_DOWN },571{ 0x0011, KEY_LEFT },572{ 0x0810, KEY_RIGHT },573{ 0x000d, KEY_OK },574{ 0x081f, KEY_RECORD },575{ 0x0017, KEY_PLAYPAUSE },576{ 0x0816, KEY_PLAYPAUSE },577{ 0x000b, KEY_STOP },578{ 0x0827, KEY_FASTFORWARD },579{ 0x0026, KEY_REWIND },580{ 0x081e, KEY_UNKNOWN }, /* Time Shift */581{ 0x000e, KEY_UNKNOWN }, /* Snapshot */582{ 0x082d, KEY_UNKNOWN }, /* Mouse Cursor */583{ 0x000f, KEY_UNKNOWN }, /* Minimize/Maximize */584{ 0x0814, KEY_UNKNOWN }, /* Shuffle */585{ 0x0025, KEY_POWER },586};587588static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)589{590static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };591static u8 reset [] = { RESET, 0x80 };592static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };593static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };594static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };595static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };596597mt352_write(fe, clock_config, sizeof(clock_config));598udelay(200);599mt352_write(fe, reset, sizeof(reset));600mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));601602mt352_write(fe, agc_cfg, sizeof(agc_cfg));603mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));604mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));605606return 0;607}608609static int cxusb_mt352_demod_init(struct dvb_frontend* fe)610{ /* used in both lgz201 and th7579 */611static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x29 };612static u8 reset [] = { RESET, 0x80 };613static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };614static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };615static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };616static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };617618mt352_write(fe, clock_config, sizeof(clock_config));619udelay(200);620mt352_write(fe, reset, sizeof(reset));621mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));622623mt352_write(fe, agc_cfg, sizeof(agc_cfg));624mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));625mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));626return 0;627}628629static struct cx22702_config cxusb_cx22702_config = {630.demod_address = 0x63,631.output_mode = CX22702_PARALLEL_OUTPUT,632};633634static struct lgdt330x_config cxusb_lgdt3303_config = {635.demod_address = 0x0e,636.demod_chip = LGDT3303,637};638639static struct lgdt330x_config cxusb_aver_lgdt3303_config = {640.demod_address = 0x0e,641.demod_chip = LGDT3303,642.clock_polarity_flip = 2,643};644645static struct mt352_config cxusb_dee1601_config = {646.demod_address = 0x0f,647.demod_init = cxusb_dee1601_demod_init,648};649650static struct zl10353_config cxusb_zl10353_dee1601_config = {651.demod_address = 0x0f,652.parallel_ts = 1,653};654655static struct mt352_config cxusb_mt352_config = {656/* used in both lgz201 and th7579 */657.demod_address = 0x0f,658.demod_init = cxusb_mt352_demod_init,659};660661static struct zl10353_config cxusb_zl10353_xc3028_config = {662.demod_address = 0x0f,663.if2 = 45600,664.no_tuner = 1,665.parallel_ts = 1,666};667668static struct zl10353_config cxusb_zl10353_xc3028_config_no_i2c_gate = {669.demod_address = 0x0f,670.if2 = 45600,671.no_tuner = 1,672.parallel_ts = 1,673.disable_i2c_gate_ctrl = 1,674};675676static struct mt352_config cxusb_mt352_xc3028_config = {677.demod_address = 0x0f,678.if2 = 4560,679.no_tuner = 1,680.demod_init = cxusb_mt352_demod_init,681};682683/* FIXME: needs tweaking */684static struct mxl5005s_config aver_a868r_tuner = {685.i2c_address = 0x63,686.if_freq = 6000000UL,687.xtal_freq = CRYSTAL_FREQ_16000000HZ,688.agc_mode = MXL_SINGLE_AGC,689.tracking_filter = MXL_TF_C,690.rssi_enable = MXL_RSSI_ENABLE,691.cap_select = MXL_CAP_SEL_ENABLE,692.div_out = MXL_DIV_OUT_4,693.clock_out = MXL_CLOCK_OUT_DISABLE,694.output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,695.top = MXL5005S_TOP_25P2,696.mod_mode = MXL_DIGITAL_MODE,697.if_mode = MXL_ZERO_IF,698.AgcMasterByte = 0x00,699};700701/* FIXME: needs tweaking */702static struct mxl5005s_config d680_dmb_tuner = {703.i2c_address = 0x63,704.if_freq = 36125000UL,705.xtal_freq = CRYSTAL_FREQ_16000000HZ,706.agc_mode = MXL_SINGLE_AGC,707.tracking_filter = MXL_TF_C,708.rssi_enable = MXL_RSSI_ENABLE,709.cap_select = MXL_CAP_SEL_ENABLE,710.div_out = MXL_DIV_OUT_4,711.clock_out = MXL_CLOCK_OUT_DISABLE,712.output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,713.top = MXL5005S_TOP_25P2,714.mod_mode = MXL_DIGITAL_MODE,715.if_mode = MXL_ZERO_IF,716.AgcMasterByte = 0x00,717};718719static struct max2165_config mygica_d689_max2165_cfg = {720.i2c_address = 0x60,721.osc_clk = 20722};723724/* Callbacks for DVB USB */725static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)726{727dvb_attach(simple_tuner_attach, adap->fe,728&adap->dev->i2c_adap, 0x61,729TUNER_PHILIPS_FMD1216ME_MK3);730return 0;731}732733static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)734{735dvb_attach(dvb_pll_attach, adap->fe, 0x61,736NULL, DVB_PLL_THOMSON_DTT7579);737return 0;738}739740static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)741{742dvb_attach(dvb_pll_attach, adap->fe, 0x61, NULL, DVB_PLL_LG_Z201);743return 0;744}745746static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)747{748dvb_attach(dvb_pll_attach, adap->fe, 0x60,749NULL, DVB_PLL_THOMSON_DTT7579);750return 0;751}752753static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)754{755dvb_attach(simple_tuner_attach, adap->fe,756&adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);757return 0;758}759760static int dvico_bluebird_xc2028_callback(void *ptr, int component,761int command, int arg)762{763struct dvb_usb_adapter *adap = ptr;764struct dvb_usb_device *d = adap->dev;765766switch (command) {767case XC2028_TUNER_RESET:768deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);769cxusb_bluebird_gpio_pulse(d, 0x01, 1);770break;771case XC2028_RESET_CLK:772deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);773break;774default:775deb_info("%s: unknown command %d, arg %d\n", __func__,776command, arg);777return -EINVAL;778}779780return 0;781}782783static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)784{785struct dvb_frontend *fe;786struct xc2028_config cfg = {787.i2c_adap = &adap->dev->i2c_adap,788.i2c_addr = 0x61,789};790static struct xc2028_ctrl ctl = {791.fname = XC2028_DEFAULT_FIRMWARE,792.max_len = 64,793.demod = XC3028_FE_ZARLINK456,794};795796/* FIXME: generalize & move to common area */797adap->fe->callback = dvico_bluebird_xc2028_callback;798799fe = dvb_attach(xc2028_attach, adap->fe, &cfg);800if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)801return -EIO;802803fe->ops.tuner_ops.set_config(fe, &ctl);804805return 0;806}807808static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)809{810dvb_attach(mxl5005s_attach, adap->fe,811&adap->dev->i2c_adap, &aver_a868r_tuner);812return 0;813}814815static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)816{817struct dvb_frontend *fe;818fe = dvb_attach(mxl5005s_attach, adap->fe,819&adap->dev->i2c_adap, &d680_dmb_tuner);820return (fe == NULL) ? -EIO : 0;821}822823static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)824{825struct dvb_frontend *fe;826fe = dvb_attach(max2165_attach, adap->fe,827&adap->dev->i2c_adap, &mygica_d689_max2165_cfg);828return (fe == NULL) ? -EIO : 0;829}830831static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)832{833u8 b;834if (usb_set_interface(adap->dev->udev, 0, 6) < 0)835err("set interface failed");836837cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);838839if ((adap->fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,840&adap->dev->i2c_adap)) != NULL)841return 0;842843return -EIO;844}845846static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)847{848if (usb_set_interface(adap->dev->udev, 0, 7) < 0)849err("set interface failed");850851cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);852853if ((adap->fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config,854&adap->dev->i2c_adap)) != NULL)855return 0;856857return -EIO;858}859860static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)861{862adap->fe = dvb_attach(lgdt330x_attach, &cxusb_aver_lgdt3303_config,863&adap->dev->i2c_adap);864if (adap->fe != NULL)865return 0;866867return -EIO;868}869870static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)871{872/* used in both lgz201 and th7579 */873if (usb_set_interface(adap->dev->udev, 0, 0) < 0)874err("set interface failed");875876cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);877878if ((adap->fe = dvb_attach(mt352_attach, &cxusb_mt352_config,879&adap->dev->i2c_adap)) != NULL)880return 0;881882return -EIO;883}884885static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)886{887if (usb_set_interface(adap->dev->udev, 0, 0) < 0)888err("set interface failed");889890cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);891892if (((adap->fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,893&adap->dev->i2c_adap)) != NULL) ||894((adap->fe = dvb_attach(zl10353_attach,895&cxusb_zl10353_dee1601_config,896&adap->dev->i2c_adap)) != NULL))897return 0;898899return -EIO;900}901902static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)903{904u8 ircode[4];905int i;906struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,907.buf = ircode, .len = 4 };908909if (usb_set_interface(adap->dev->udev, 0, 1) < 0)910err("set interface failed");911912cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);913914/* reset the tuner and demodulator */915cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);916cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);917cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);918919if ((adap->fe = dvb_attach(zl10353_attach,920&cxusb_zl10353_xc3028_config_no_i2c_gate,921&adap->dev->i2c_adap)) == NULL)922return -EIO;923924/* try to determine if there is no IR decoder on the I2C bus */925for (i = 0; adap->dev->props.rc.legacy.rc_map_table != NULL && i < 5; i++) {926msleep(20);927if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)928goto no_IR;929if (ircode[0] == 0 && ircode[1] == 0)930continue;931if (ircode[2] + ircode[3] != 0xff) {932no_IR:933adap->dev->props.rc.legacy.rc_map_table = NULL;934info("No IR receiver detected on this device.");935break;936}937}938939return 0;940}941942static struct dibx000_agc_config dib7070_agc_config = {943.band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,944945/*946* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,947* P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,948* P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0949*/950.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |951(0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),952.inv_gain = 600,953.time_stabiliz = 10,954.alpha_level = 0,955.thlock = 118,956.wbd_inv = 0,957.wbd_ref = 3530,958.wbd_sel = 1,959.wbd_alpha = 5,960.agc1_max = 65535,961.agc1_min = 0,962.agc2_max = 65535,963.agc2_min = 0,964.agc1_pt1 = 0,965.agc1_pt2 = 40,966.agc1_pt3 = 183,967.agc1_slope1 = 206,968.agc1_slope2 = 255,969.agc2_pt1 = 72,970.agc2_pt2 = 152,971.agc2_slope1 = 88,972.agc2_slope2 = 90,973.alpha_mant = 17,974.alpha_exp = 27,975.beta_mant = 23,976.beta_exp = 51,977.perform_agc_softsplit = 0,978};979980static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {981.internal = 60000,982.sampling = 15000,983.pll_prediv = 1,984.pll_ratio = 20,985.pll_range = 3,986.pll_reset = 1,987.pll_bypass = 0,988.enable_refdiv = 0,989.bypclk_div = 0,990.IO_CLK_en_core = 1,991.ADClkSrc = 1,992.modulo = 2,993/* refsel, sel, freq_15k */994.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),995.ifreq = (0 << 25) | 0,996.timf = 20452225,997.xtal_hz = 12000000,998};9991000static struct dib7000p_config cxusb_dualdig4_rev2_config = {1001.output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,1002.output_mpeg2_in_188_bytes = 1,10031004.agc_config_count = 1,1005.agc = &dib7070_agc_config,1006.bw = &dib7070_bw_config_12_mhz,1007.tuner_is_baseband = 1,1008.spur_protect = 1,10091010.gpio_dir = 0xfcef,1011.gpio_val = 0x0110,10121013.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,10141015.hostbus_diversity = 1,1016};10171018static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)1019{1020if (usb_set_interface(adap->dev->udev, 0, 1) < 0)1021err("set interface failed");10221023cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);10241025cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);10261027if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,1028&cxusb_dualdig4_rev2_config) < 0) {1029printk(KERN_WARNING "Unable to enumerate dib7000p\n");1030return -ENODEV;1031}10321033adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,1034&cxusb_dualdig4_rev2_config);1035if (adap->fe == NULL)1036return -EIO;10371038return 0;1039}10401041static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)1042{1043return dib7000p_set_gpio(fe, 8, 0, !onoff);1044}10451046static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)1047{1048return 0;1049}10501051static struct dib0070_config dib7070p_dib0070_config = {1052.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,1053.reset = dib7070_tuner_reset,1054.sleep = dib7070_tuner_sleep,1055.clock_khz = 12000,1056};10571058struct dib0700_adapter_state {1059int (*set_param_save) (struct dvb_frontend *,1060struct dvb_frontend_parameters *);1061};10621063static int dib7070_set_param_override(struct dvb_frontend *fe,1064struct dvb_frontend_parameters *fep)1065{1066struct dvb_usb_adapter *adap = fe->dvb->priv;1067struct dib0700_adapter_state *state = adap->priv;10681069u16 offset;1070u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);1071switch (band) {1072case BAND_VHF: offset = 950; break;1073default:1074case BAND_UHF: offset = 550; break;1075}10761077dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));10781079return state->set_param_save(fe, fep);1080}10811082static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)1083{1084struct dib0700_adapter_state *st = adap->priv;1085struct i2c_adapter *tun_i2c =1086dib7000p_get_i2c_master(adap->fe,1087DIBX000_I2C_INTERFACE_TUNER, 1);10881089if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,1090&dib7070p_dib0070_config) == NULL)1091return -ENODEV;10921093st->set_param_save = adap->fe->ops.tuner_ops.set_params;1094adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;1095return 0;1096}10971098static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)1099{1100if (usb_set_interface(adap->dev->udev, 0, 1) < 0)1101err("set interface failed");11021103cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);11041105/* reset the tuner and demodulator */1106cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);1107cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);1108cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);11091110if ((adap->fe = dvb_attach(zl10353_attach,1111&cxusb_zl10353_xc3028_config,1112&adap->dev->i2c_adap)) != NULL)1113return 0;11141115if ((adap->fe = dvb_attach(mt352_attach,1116&cxusb_mt352_xc3028_config,1117&adap->dev->i2c_adap)) != NULL)1118return 0;11191120return -EIO;1121}11221123static struct lgs8gxx_config d680_lgs8gl5_cfg = {1124.prod = LGS8GXX_PROD_LGS8GL5,1125.demod_address = 0x19,1126.serial_ts = 0,1127.ts_clk_pol = 0,1128.ts_clk_gated = 1,1129.if_clk_freq = 30400, /* 30.4 MHz */1130.if_freq = 5725, /* 5.725 MHz */1131.if_neg_center = 0,1132.ext_adc = 0,1133.adc_signed = 0,1134.if_neg_edge = 0,1135};11361137static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)1138{1139struct dvb_usb_device *d = adap->dev;1140int n;11411142/* Select required USB configuration */1143if (usb_set_interface(d->udev, 0, 0) < 0)1144err("set interface failed");11451146/* Unblock all USB pipes */1147usb_clear_halt(d->udev,1148usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));1149usb_clear_halt(d->udev,1150usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));1151usb_clear_halt(d->udev,1152usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));11531154/* Drain USB pipes to avoid hang after reboot */1155for (n = 0; n < 5; n++) {1156cxusb_d680_dmb_drain_message(d);1157cxusb_d680_dmb_drain_video(d);1158msleep(200);1159}11601161/* Reset the tuner */1162if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {1163err("clear tuner gpio failed");1164return -EIO;1165}1166msleep(100);1167if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {1168err("set tuner gpio failed");1169return -EIO;1170}1171msleep(100);11721173/* Attach frontend */1174adap->fe = dvb_attach(lgs8gxx_attach, &d680_lgs8gl5_cfg, &d->i2c_adap);1175if (adap->fe == NULL)1176return -EIO;11771178return 0;1179}11801181static struct atbm8830_config mygica_d689_atbm8830_cfg = {1182.prod = ATBM8830_PROD_8830,1183.demod_address = 0x40,1184.serial_ts = 0,1185.ts_sampling_edge = 1,1186.ts_clk_gated = 0,1187.osc_clk_freq = 30400, /* in kHz */1188.if_freq = 0, /* zero IF */1189.zif_swap_iq = 1,1190.agc_min = 0x2E,1191.agc_max = 0x90,1192.agc_hold_loop = 0,1193};11941195static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)1196{1197struct dvb_usb_device *d = adap->dev;11981199/* Select required USB configuration */1200if (usb_set_interface(d->udev, 0, 0) < 0)1201err("set interface failed");12021203/* Unblock all USB pipes */1204usb_clear_halt(d->udev,1205usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));1206usb_clear_halt(d->udev,1207usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));1208usb_clear_halt(d->udev,1209usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));121012111212/* Reset the tuner */1213if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {1214err("clear tuner gpio failed");1215return -EIO;1216}1217msleep(100);1218if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {1219err("set tuner gpio failed");1220return -EIO;1221}1222msleep(100);12231224/* Attach frontend */1225adap->fe = dvb_attach(atbm8830_attach, &mygica_d689_atbm8830_cfg,1226&d->i2c_adap);1227if (adap->fe == NULL)1228return -EIO;12291230return 0;1231}12321233/*1234* DViCO has shipped two devices with the same USB ID, but only one of them1235* needs a firmware download. Check the device class details to see if they1236* have non-default values to decide whether the device is actually cold or1237* not, and forget a match if it turns out we selected the wrong device.1238*/1239static int bluebird_fx2_identify_state(struct usb_device *udev,1240struct dvb_usb_device_properties *props,1241struct dvb_usb_device_description **desc,1242int *cold)1243{1244int wascold = *cold;12451246*cold = udev->descriptor.bDeviceClass == 0xff &&1247udev->descriptor.bDeviceSubClass == 0xff &&1248udev->descriptor.bDeviceProtocol == 0xff;12491250if (*cold && !wascold)1251*desc = NULL;12521253return 0;1254}12551256/*1257* DViCO bluebird firmware needs the "warm" product ID to be patched into the1258* firmware file before download.1259*/12601261static const int dvico_firmware_id_offsets[] = { 6638, 3204 };1262static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,1263const struct firmware *fw)1264{1265int pos;12661267for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {1268int idoff = dvico_firmware_id_offsets[pos];12691270if (fw->size < idoff + 4)1271continue;12721273if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&1274fw->data[idoff + 1] == USB_VID_DVICO >> 8) {1275struct firmware new_fw;1276u8 *new_fw_data = vmalloc(fw->size);1277int ret;12781279if (!new_fw_data)1280return -ENOMEM;12811282memcpy(new_fw_data, fw->data, fw->size);1283new_fw.size = fw->size;1284new_fw.data = new_fw_data;12851286new_fw_data[idoff + 2] =1287le16_to_cpu(udev->descriptor.idProduct) + 1;1288new_fw_data[idoff + 3] =1289le16_to_cpu(udev->descriptor.idProduct) >> 8;12901291ret = usb_cypress_load_firmware(udev, &new_fw,1292CYPRESS_FX2);1293vfree(new_fw_data);1294return ret;1295}1296}12971298return -EINVAL;1299}13001301/* DVB USB Driver stuff */1302static struct dvb_usb_device_properties cxusb_medion_properties;1303static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;1304static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;1305static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;1306static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;1307static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;1308static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;1309static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;1310static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;1311static struct dvb_usb_device_properties cxusb_aver_a868r_properties;1312static struct dvb_usb_device_properties cxusb_d680_dmb_properties;1313static struct dvb_usb_device_properties cxusb_mygica_d689_properties;13141315static int cxusb_probe(struct usb_interface *intf,1316const struct usb_device_id *id)1317{1318if (0 == dvb_usb_device_init(intf, &cxusb_medion_properties,1319THIS_MODULE, NULL, adapter_nr) ||13200 == dvb_usb_device_init(intf, &cxusb_bluebird_lgh064f_properties,1321THIS_MODULE, NULL, adapter_nr) ||13220 == dvb_usb_device_init(intf, &cxusb_bluebird_dee1601_properties,1323THIS_MODULE, NULL, adapter_nr) ||13240 == dvb_usb_device_init(intf, &cxusb_bluebird_lgz201_properties,1325THIS_MODULE, NULL, adapter_nr) ||13260 == dvb_usb_device_init(intf, &cxusb_bluebird_dtt7579_properties,1327THIS_MODULE, NULL, adapter_nr) ||13280 == dvb_usb_device_init(intf, &cxusb_bluebird_dualdig4_properties,1329THIS_MODULE, NULL, adapter_nr) ||13300 == dvb_usb_device_init(intf, &cxusb_bluebird_nano2_properties,1331THIS_MODULE, NULL, adapter_nr) ||13320 == dvb_usb_device_init(intf,1333&cxusb_bluebird_nano2_needsfirmware_properties,1334THIS_MODULE, NULL, adapter_nr) ||13350 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,1336THIS_MODULE, NULL, adapter_nr) ||13370 == dvb_usb_device_init(intf,1338&cxusb_bluebird_dualdig4_rev2_properties,1339THIS_MODULE, NULL, adapter_nr) ||13400 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,1341THIS_MODULE, NULL, adapter_nr) ||13420 == dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,1343THIS_MODULE, NULL, adapter_nr) ||13440)1345return 0;13461347return -EINVAL;1348}13491350static struct usb_device_id cxusb_table [] = {1351{ USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) },1352{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD) },1353{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) },1354{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD) },1355{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM) },1356{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD) },1357{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM) },1358{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD) },1359{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM) },1360{ USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD) },1361{ USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) },1362{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) },1363{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) },1364{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4) },1365{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) },1366{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },1367{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) },1368{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2) },1369{ USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB) },1370{ USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689) },1371{} /* Terminating entry */1372};1373MODULE_DEVICE_TABLE (usb, cxusb_table);13741375static struct dvb_usb_device_properties cxusb_medion_properties = {1376.caps = DVB_USB_IS_AN_I2C_ADAPTER,13771378.usb_ctrl = CYPRESS_FX2,13791380.size_of_priv = sizeof(struct cxusb_state),13811382.num_adapters = 1,1383.adapter = {1384{1385.streaming_ctrl = cxusb_streaming_ctrl,1386.frontend_attach = cxusb_cx22702_frontend_attach,1387.tuner_attach = cxusb_fmd1216me_tuner_attach,1388/* parameter for the MPEG2-data transfer */1389.stream = {1390.type = USB_BULK,1391.count = 5,1392.endpoint = 0x02,1393.u = {1394.bulk = {1395.buffersize = 8192,1396}1397}1398},13991400},1401},1402.power_ctrl = cxusb_power_ctrl,14031404.i2c_algo = &cxusb_i2c_algo,14051406.generic_bulk_ctrl_endpoint = 0x01,14071408.num_device_descs = 1,1409.devices = {1410{ "Medion MD95700 (MDUSBTV-HYBRID)",1411{ NULL },1412{ &cxusb_table[0], NULL },1413},1414}1415};14161417static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {1418.caps = DVB_USB_IS_AN_I2C_ADAPTER,14191420.usb_ctrl = DEVICE_SPECIFIC,1421.firmware = "dvb-usb-bluebird-01.fw",1422.download_firmware = bluebird_patch_dvico_firmware_download,1423/* use usb alt setting 0 for EP4 transfer (dvb-t),1424use usb alt setting 7 for EP2 transfer (atsc) */14251426.size_of_priv = sizeof(struct cxusb_state),14271428.num_adapters = 1,1429.adapter = {1430{1431.streaming_ctrl = cxusb_streaming_ctrl,1432.frontend_attach = cxusb_lgdt3303_frontend_attach,1433.tuner_attach = cxusb_lgh064f_tuner_attach,14341435/* parameter for the MPEG2-data transfer */1436.stream = {1437.type = USB_BULK,1438.count = 5,1439.endpoint = 0x02,1440.u = {1441.bulk = {1442.buffersize = 8192,1443}1444}1445},1446},1447},14481449.power_ctrl = cxusb_bluebird_power_ctrl,14501451.i2c_algo = &cxusb_i2c_algo,14521453.rc.legacy = {1454.rc_interval = 100,1455.rc_map_table = rc_map_dvico_portable_table,1456.rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),1457.rc_query = cxusb_rc_query,1458},14591460.generic_bulk_ctrl_endpoint = 0x01,14611462.num_device_descs = 1,1463.devices = {1464{ "DViCO FusionHDTV5 USB Gold",1465{ &cxusb_table[1], NULL },1466{ &cxusb_table[2], NULL },1467},1468}1469};14701471static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {1472.caps = DVB_USB_IS_AN_I2C_ADAPTER,14731474.usb_ctrl = DEVICE_SPECIFIC,1475.firmware = "dvb-usb-bluebird-01.fw",1476.download_firmware = bluebird_patch_dvico_firmware_download,1477/* use usb alt setting 0 for EP4 transfer (dvb-t),1478use usb alt setting 7 for EP2 transfer (atsc) */14791480.size_of_priv = sizeof(struct cxusb_state),14811482.num_adapters = 1,1483.adapter = {1484{1485.streaming_ctrl = cxusb_streaming_ctrl,1486.frontend_attach = cxusb_dee1601_frontend_attach,1487.tuner_attach = cxusb_dee1601_tuner_attach,1488/* parameter for the MPEG2-data transfer */1489.stream = {1490.type = USB_BULK,1491.count = 5,1492.endpoint = 0x04,1493.u = {1494.bulk = {1495.buffersize = 8192,1496}1497}1498},1499},1500},15011502.power_ctrl = cxusb_bluebird_power_ctrl,15031504.i2c_algo = &cxusb_i2c_algo,15051506.rc.legacy = {1507.rc_interval = 150,1508.rc_map_table = rc_map_dvico_mce_table,1509.rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),1510.rc_query = cxusb_rc_query,1511},15121513.generic_bulk_ctrl_endpoint = 0x01,15141515.num_device_descs = 3,1516.devices = {1517{ "DViCO FusionHDTV DVB-T Dual USB",1518{ &cxusb_table[3], NULL },1519{ &cxusb_table[4], NULL },1520},1521{ "DigitalNow DVB-T Dual USB",1522{ &cxusb_table[9], NULL },1523{ &cxusb_table[10], NULL },1524},1525{ "DViCO FusionHDTV DVB-T Dual Digital 2",1526{ &cxusb_table[11], NULL },1527{ &cxusb_table[12], NULL },1528},1529}1530};15311532static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {1533.caps = DVB_USB_IS_AN_I2C_ADAPTER,15341535.usb_ctrl = DEVICE_SPECIFIC,1536.firmware = "dvb-usb-bluebird-01.fw",1537.download_firmware = bluebird_patch_dvico_firmware_download,1538/* use usb alt setting 0 for EP4 transfer (dvb-t),1539use usb alt setting 7 for EP2 transfer (atsc) */15401541.size_of_priv = sizeof(struct cxusb_state),15421543.num_adapters = 2,1544.adapter = {1545{1546.streaming_ctrl = cxusb_streaming_ctrl,1547.frontend_attach = cxusb_mt352_frontend_attach,1548.tuner_attach = cxusb_lgz201_tuner_attach,15491550/* parameter for the MPEG2-data transfer */1551.stream = {1552.type = USB_BULK,1553.count = 5,1554.endpoint = 0x04,1555.u = {1556.bulk = {1557.buffersize = 8192,1558}1559}1560},1561},1562},1563.power_ctrl = cxusb_bluebird_power_ctrl,15641565.i2c_algo = &cxusb_i2c_algo,15661567.rc.legacy = {1568.rc_interval = 100,1569.rc_map_table = rc_map_dvico_portable_table,1570.rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),1571.rc_query = cxusb_rc_query,1572},15731574.generic_bulk_ctrl_endpoint = 0x01,1575.num_device_descs = 1,1576.devices = {1577{ "DViCO FusionHDTV DVB-T USB (LGZ201)",1578{ &cxusb_table[5], NULL },1579{ &cxusb_table[6], NULL },1580},1581}1582};15831584static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {1585.caps = DVB_USB_IS_AN_I2C_ADAPTER,15861587.usb_ctrl = DEVICE_SPECIFIC,1588.firmware = "dvb-usb-bluebird-01.fw",1589.download_firmware = bluebird_patch_dvico_firmware_download,1590/* use usb alt setting 0 for EP4 transfer (dvb-t),1591use usb alt setting 7 for EP2 transfer (atsc) */15921593.size_of_priv = sizeof(struct cxusb_state),15941595.num_adapters = 1,1596.adapter = {1597{1598.streaming_ctrl = cxusb_streaming_ctrl,1599.frontend_attach = cxusb_mt352_frontend_attach,1600.tuner_attach = cxusb_dtt7579_tuner_attach,16011602/* parameter for the MPEG2-data transfer */1603.stream = {1604.type = USB_BULK,1605.count = 5,1606.endpoint = 0x04,1607.u = {1608.bulk = {1609.buffersize = 8192,1610}1611}1612},1613},1614},1615.power_ctrl = cxusb_bluebird_power_ctrl,16161617.i2c_algo = &cxusb_i2c_algo,16181619.rc.legacy = {1620.rc_interval = 100,1621.rc_map_table = rc_map_dvico_portable_table,1622.rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),1623.rc_query = cxusb_rc_query,1624},16251626.generic_bulk_ctrl_endpoint = 0x01,16271628.num_device_descs = 1,1629.devices = {1630{ "DViCO FusionHDTV DVB-T USB (TH7579)",1631{ &cxusb_table[7], NULL },1632{ &cxusb_table[8], NULL },1633},1634}1635};16361637static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {1638.caps = DVB_USB_IS_AN_I2C_ADAPTER,16391640.usb_ctrl = CYPRESS_FX2,16411642.size_of_priv = sizeof(struct cxusb_state),16431644.num_adapters = 1,1645.adapter = {1646{1647.streaming_ctrl = cxusb_streaming_ctrl,1648.frontend_attach = cxusb_dualdig4_frontend_attach,1649.tuner_attach = cxusb_dvico_xc3028_tuner_attach,1650/* parameter for the MPEG2-data transfer */1651.stream = {1652.type = USB_BULK,1653.count = 5,1654.endpoint = 0x02,1655.u = {1656.bulk = {1657.buffersize = 8192,1658}1659}1660},1661},1662},16631664.power_ctrl = cxusb_power_ctrl,16651666.i2c_algo = &cxusb_i2c_algo,16671668.generic_bulk_ctrl_endpoint = 0x01,16691670.rc.legacy = {1671.rc_interval = 100,1672.rc_map_table = rc_map_dvico_mce_table,1673.rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),1674.rc_query = cxusb_bluebird2_rc_query,1675},16761677.num_device_descs = 1,1678.devices = {1679{ "DViCO FusionHDTV DVB-T Dual Digital 4",1680{ NULL },1681{ &cxusb_table[13], NULL },1682},1683}1684};16851686static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {1687.caps = DVB_USB_IS_AN_I2C_ADAPTER,16881689.usb_ctrl = CYPRESS_FX2,1690.identify_state = bluebird_fx2_identify_state,16911692.size_of_priv = sizeof(struct cxusb_state),16931694.num_adapters = 1,1695.adapter = {1696{1697.streaming_ctrl = cxusb_streaming_ctrl,1698.frontend_attach = cxusb_nano2_frontend_attach,1699.tuner_attach = cxusb_dvico_xc3028_tuner_attach,1700/* parameter for the MPEG2-data transfer */1701.stream = {1702.type = USB_BULK,1703.count = 5,1704.endpoint = 0x02,1705.u = {1706.bulk = {1707.buffersize = 8192,1708}1709}1710},1711},1712},17131714.power_ctrl = cxusb_nano2_power_ctrl,17151716.i2c_algo = &cxusb_i2c_algo,17171718.generic_bulk_ctrl_endpoint = 0x01,17191720.rc.legacy = {1721.rc_interval = 100,1722.rc_map_table = rc_map_dvico_portable_table,1723.rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),1724.rc_query = cxusb_bluebird2_rc_query,1725},17261727.num_device_descs = 1,1728.devices = {1729{ "DViCO FusionHDTV DVB-T NANO2",1730{ NULL },1731{ &cxusb_table[14], NULL },1732},1733}1734};17351736static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties = {1737.caps = DVB_USB_IS_AN_I2C_ADAPTER,17381739.usb_ctrl = DEVICE_SPECIFIC,1740.firmware = "dvb-usb-bluebird-02.fw",1741.download_firmware = bluebird_patch_dvico_firmware_download,1742.identify_state = bluebird_fx2_identify_state,17431744.size_of_priv = sizeof(struct cxusb_state),17451746.num_adapters = 1,1747.adapter = {1748{1749.streaming_ctrl = cxusb_streaming_ctrl,1750.frontend_attach = cxusb_nano2_frontend_attach,1751.tuner_attach = cxusb_dvico_xc3028_tuner_attach,1752/* parameter for the MPEG2-data transfer */1753.stream = {1754.type = USB_BULK,1755.count = 5,1756.endpoint = 0x02,1757.u = {1758.bulk = {1759.buffersize = 8192,1760}1761}1762},1763},1764},17651766.power_ctrl = cxusb_nano2_power_ctrl,17671768.i2c_algo = &cxusb_i2c_algo,17691770.generic_bulk_ctrl_endpoint = 0x01,17711772.rc.legacy = {1773.rc_interval = 100,1774.rc_map_table = rc_map_dvico_portable_table,1775.rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),1776.rc_query = cxusb_rc_query,1777},17781779.num_device_descs = 1,1780.devices = {1781{ "DViCO FusionHDTV DVB-T NANO2 w/o firmware",1782{ &cxusb_table[14], NULL },1783{ &cxusb_table[15], NULL },1784},1785}1786};17871788static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {1789.caps = DVB_USB_IS_AN_I2C_ADAPTER,17901791.usb_ctrl = CYPRESS_FX2,17921793.size_of_priv = sizeof(struct cxusb_state),17941795.num_adapters = 1,1796.adapter = {1797{1798.streaming_ctrl = cxusb_aver_streaming_ctrl,1799.frontend_attach = cxusb_aver_lgdt3303_frontend_attach,1800.tuner_attach = cxusb_mxl5003s_tuner_attach,1801/* parameter for the MPEG2-data transfer */1802.stream = {1803.type = USB_BULK,1804.count = 5,1805.endpoint = 0x04,1806.u = {1807.bulk = {1808.buffersize = 8192,1809}1810}1811},18121813},1814},1815.power_ctrl = cxusb_aver_power_ctrl,18161817.i2c_algo = &cxusb_i2c_algo,18181819.generic_bulk_ctrl_endpoint = 0x01,18201821.num_device_descs = 1,1822.devices = {1823{ "AVerMedia AVerTVHD Volar (A868R)",1824{ NULL },1825{ &cxusb_table[16], NULL },1826},1827}1828};18291830static1831struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {1832.caps = DVB_USB_IS_AN_I2C_ADAPTER,18331834.usb_ctrl = CYPRESS_FX2,18351836.size_of_priv = sizeof(struct cxusb_state),18371838.num_adapters = 1,1839.adapter = {1840{1841.streaming_ctrl = cxusb_streaming_ctrl,1842.frontend_attach = cxusb_dualdig4_rev2_frontend_attach,1843.tuner_attach = cxusb_dualdig4_rev2_tuner_attach,1844.size_of_priv = sizeof(struct dib0700_adapter_state),1845/* parameter for the MPEG2-data transfer */1846.stream = {1847.type = USB_BULK,1848.count = 7,1849.endpoint = 0x02,1850.u = {1851.bulk = {1852.buffersize = 4096,1853}1854}1855},1856},1857},18581859.power_ctrl = cxusb_bluebird_power_ctrl,18601861.i2c_algo = &cxusb_i2c_algo,18621863.generic_bulk_ctrl_endpoint = 0x01,18641865.rc.legacy = {1866.rc_interval = 100,1867.rc_map_table = rc_map_dvico_mce_table,1868.rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),1869.rc_query = cxusb_rc_query,1870},18711872.num_device_descs = 1,1873.devices = {1874{ "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",1875{ NULL },1876{ &cxusb_table[17], NULL },1877},1878}1879};18801881static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {1882.caps = DVB_USB_IS_AN_I2C_ADAPTER,18831884.usb_ctrl = CYPRESS_FX2,18851886.size_of_priv = sizeof(struct cxusb_state),18871888.num_adapters = 1,1889.adapter = {1890{1891.streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,1892.frontend_attach = cxusb_d680_dmb_frontend_attach,1893.tuner_attach = cxusb_d680_dmb_tuner_attach,18941895/* parameter for the MPEG2-data transfer */1896.stream = {1897.type = USB_BULK,1898.count = 5,1899.endpoint = 0x02,1900.u = {1901.bulk = {1902.buffersize = 8192,1903}1904}1905},1906},1907},19081909.power_ctrl = cxusb_d680_dmb_power_ctrl,19101911.i2c_algo = &cxusb_i2c_algo,19121913.generic_bulk_ctrl_endpoint = 0x01,19141915.rc.legacy = {1916.rc_interval = 100,1917.rc_map_table = rc_map_d680_dmb_table,1918.rc_map_size = ARRAY_SIZE(rc_map_d680_dmb_table),1919.rc_query = cxusb_d680_dmb_rc_query,1920},19211922.num_device_descs = 1,1923.devices = {1924{1925"Conexant DMB-TH Stick",1926{ NULL },1927{ &cxusb_table[18], NULL },1928},1929}1930};19311932static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {1933.caps = DVB_USB_IS_AN_I2C_ADAPTER,19341935.usb_ctrl = CYPRESS_FX2,19361937.size_of_priv = sizeof(struct cxusb_state),19381939.num_adapters = 1,1940.adapter = {1941{1942.streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,1943.frontend_attach = cxusb_mygica_d689_frontend_attach,1944.tuner_attach = cxusb_mygica_d689_tuner_attach,19451946/* parameter for the MPEG2-data transfer */1947.stream = {1948.type = USB_BULK,1949.count = 5,1950.endpoint = 0x02,1951.u = {1952.bulk = {1953.buffersize = 8192,1954}1955}1956},1957},1958},19591960.power_ctrl = cxusb_d680_dmb_power_ctrl,19611962.i2c_algo = &cxusb_i2c_algo,19631964.generic_bulk_ctrl_endpoint = 0x01,19651966.rc.legacy = {1967.rc_interval = 100,1968.rc_map_table = rc_map_d680_dmb_table,1969.rc_map_size = ARRAY_SIZE(rc_map_d680_dmb_table),1970.rc_query = cxusb_d680_dmb_rc_query,1971},19721973.num_device_descs = 1,1974.devices = {1975{1976"Mygica D689 DMB-TH",1977{ NULL },1978{ &cxusb_table[19], NULL },1979},1980}1981};19821983static struct usb_driver cxusb_driver = {1984.name = "dvb_usb_cxusb",1985.probe = cxusb_probe,1986.disconnect = dvb_usb_device_exit,1987.id_table = cxusb_table,1988};19891990/* module stuff */1991static int __init cxusb_module_init(void)1992{1993int result;1994if ((result = usb_register(&cxusb_driver))) {1995err("usb_register failed. Error number %d",result);1996return result;1997}19981999return 0;2000}20012002static void __exit cxusb_module_exit(void)2003{2004/* deregister this driver from the USB subsystem */2005usb_deregister(&cxusb_driver);2006}20072008module_init (cxusb_module_init);2009module_exit (cxusb_module_exit);20102011MODULE_AUTHOR("Patrick Boettcher <[email protected]>");2012MODULE_AUTHOR("Michael Krufky <[email protected]>");2013MODULE_AUTHOR("Chris Pascoe <[email protected]>");2014MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");2015MODULE_VERSION("1.0-alpha");2016MODULE_LICENSE("GPL");201720182019