Path: blob/master/drivers/media/dvb/dvb-usb/anysee.c
15111 views
/*1* DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver2*3* Copyright (C) 2007 Antti Palosaari <[email protected]>4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18*19* TODO:20* - add smart card reader support for Conditional Access (CA)21*22* Card reader in Anysee is nothing more than ISO 7816 card reader.23* There is no hardware CAM in any Anysee device sold.24* In my understanding it should be implemented by making own module25* for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This26* module registers serial interface that can be used to communicate27* with any ISO 7816 smart card.28*29* Any help according to implement serial smart card reader support30* is highly welcome!31*/3233#include "anysee.h"34#include "tda1002x.h"35#include "mt352.h"36#include "mt352_priv.h"37#include "zl10353.h"38#include "tda18212.h"39#include "cx24116.h"40#include "stv0900.h"41#include "stv6110.h"42#include "isl6423.h"4344/* debug */45static int dvb_usb_anysee_debug;46module_param_named(debug, dvb_usb_anysee_debug, int, 0644);47MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);48static int dvb_usb_anysee_delsys;49module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);50MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");51DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);5253static DEFINE_MUTEX(anysee_usb_mutex);5455static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,56u8 *rbuf, u8 rlen)57{58struct anysee_state *state = d->priv;59int act_len, ret;60u8 buf[64];6162memcpy(&buf[0], sbuf, slen);63buf[60] = state->seq++;6465if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)66return -EAGAIN;6768/* We need receive one message more after dvb_usb_generic_rw due69to weird transaction flow, which is 1 x send + 2 x receive. */70ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);7172if (!ret) {73/* receive 2nd answer */74ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,75d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),76&act_len, 2000);77if (ret)78err("%s: recv bulk message failed: %d", __func__, ret);79else {80deb_xfer("<<< ");81debug_dump(buf, act_len, deb_xfer);82}83}8485/* read request, copy returned data to return buf */86if (!ret && rbuf && rlen)87memcpy(rbuf, buf, rlen);8889mutex_unlock(&anysee_usb_mutex);9091return ret;92}9394static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)95{96u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};97int ret;98ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);99deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);100return ret;101}102103static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)104{105u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};106deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);107return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);108}109110/* write single register with mask */111static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,112u8 mask)113{114int ret;115u8 tmp;116117/* no need for read if whole reg is written */118if (mask != 0xff) {119ret = anysee_read_reg(d, reg, &tmp);120if (ret)121return ret;122123val &= mask;124tmp &= ~mask;125val |= tmp;126}127128return anysee_write_reg(d, reg, val);129}130131static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)132{133u8 buf[] = {CMD_GET_HW_INFO};134return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);135}136137static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)138{139u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};140deb_info("%s: onoff:%02x\n", __func__, onoff);141return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);142}143144static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)145{146u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};147deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);148return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);149}150151static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)152{153u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};154deb_info("%s: onoff:%02x\n", __func__, onoff);155return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);156}157158static int anysee_init(struct dvb_usb_device *d)159{160int ret;161/* LED light */162ret = anysee_led_ctrl(d, 0x01, 0x03);163if (ret)164return ret;165166/* enable IR */167ret = anysee_ir_ctrl(d, 1);168if (ret)169return ret;170171return 0;172}173174/* I2C */175static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,176int num)177{178struct dvb_usb_device *d = i2c_get_adapdata(adap);179int ret = 0, inc, i = 0;180u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */181182if (mutex_lock_interruptible(&d->i2c_mutex) < 0)183return -EAGAIN;184185while (i < num) {186if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {187if (msg[i].len > 2 || msg[i+1].len > 60) {188ret = -EOPNOTSUPP;189break;190}191buf[0] = CMD_I2C_READ;192buf[1] = (msg[i].addr << 1) | 0x01;193buf[2] = msg[i].buf[0];194buf[3] = msg[i].buf[1];195buf[4] = msg[i].len-1;196buf[5] = msg[i+1].len;197ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,198msg[i+1].len);199inc = 2;200} else {201if (msg[i].len > 48) {202ret = -EOPNOTSUPP;203break;204}205buf[0] = CMD_I2C_WRITE;206buf[1] = (msg[i].addr << 1);207buf[2] = msg[i].len;208buf[3] = 0x01;209memcpy(&buf[4], msg[i].buf, msg[i].len);210ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);211inc = 1;212}213if (ret)214break;215216i += inc;217}218219mutex_unlock(&d->i2c_mutex);220221return ret ? ret : i;222}223224static u32 anysee_i2c_func(struct i2c_adapter *adapter)225{226return I2C_FUNC_I2C;227}228229static struct i2c_algorithm anysee_i2c_algo = {230.master_xfer = anysee_master_xfer,231.functionality = anysee_i2c_func,232};233234static int anysee_mt352_demod_init(struct dvb_frontend *fe)235{236static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };237static u8 reset[] = { RESET, 0x80 };238static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };239static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };240static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };241static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };242243mt352_write(fe, clock_config, sizeof(clock_config));244udelay(200);245mt352_write(fe, reset, sizeof(reset));246mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));247248mt352_write(fe, agc_cfg, sizeof(agc_cfg));249mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));250mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));251252return 0;253}254255/* Callbacks for DVB USB */256static struct tda10023_config anysee_tda10023_config = {257.demod_address = (0x1a >> 1),258.invert = 0,259.xtal = 16000000,260.pll_m = 11,261.pll_p = 3,262.pll_n = 1,263.output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,264.deltaf = 0xfeeb,265};266267static struct mt352_config anysee_mt352_config = {268.demod_address = (0x1e >> 1),269.demod_init = anysee_mt352_demod_init,270};271272static struct zl10353_config anysee_zl10353_config = {273.demod_address = (0x1e >> 1),274.parallel_ts = 1,275};276277static struct zl10353_config anysee_zl10353_tda18212_config2 = {278.demod_address = (0x1e >> 1),279.parallel_ts = 1,280.disable_i2c_gate_ctrl = 1,281.no_tuner = 1,282.if2 = 41500,283};284285static struct zl10353_config anysee_zl10353_tda18212_config = {286.demod_address = (0x18 >> 1),287.parallel_ts = 1,288.disable_i2c_gate_ctrl = 1,289.no_tuner = 1,290.if2 = 41500,291};292293static struct tda10023_config anysee_tda10023_tda18212_config = {294.demod_address = (0x1a >> 1),295.xtal = 16000000,296.pll_m = 12,297.pll_p = 3,298.pll_n = 1,299.output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,300.deltaf = 0xba02,301};302303static struct tda18212_config anysee_tda18212_config = {304.i2c_address = (0xc0 >> 1),305.if_dvbt_6 = 4150,306.if_dvbt_7 = 4150,307.if_dvbt_8 = 4150,308.if_dvbc = 5000,309};310311static struct cx24116_config anysee_cx24116_config = {312.demod_address = (0xaa >> 1),313.mpg_clk_pos_pol = 0x00,314.i2c_wr_max = 48,315};316317static struct stv0900_config anysee_stv0900_config = {318.demod_address = (0xd0 >> 1),319.demod_mode = 0,320.xtal = 8000000,321.clkmode = 3,322.diseqc_mode = 2,323.tun1_maddress = 0,324.tun1_adc = 1, /* 1 Vpp */325.path1_mode = 3,326};327328static struct stv6110_config anysee_stv6110_config = {329.i2c_address = (0xc0 >> 1),330.mclk = 16000000,331.clk_div = 1,332};333334static struct isl6423_config anysee_isl6423_config = {335.current_max = SEC_CURRENT_800m,336.curlim = SEC_CURRENT_LIM_OFF,337.mod_extern = 1,338.addr = (0x10 >> 1),339};340341/*342* New USB device strings: Mfr=1, Product=2, SerialNumber=0343* Manufacturer: AMT.CO.KR344*345* E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????346* PCB: ?347* parts: DNOS404ZH102A(MT352, DTT7579(?))348*349* E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????350* PCB: ?351* parts: DNOS404ZH103A(ZL10353, DTT7579(?))352*353* E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"354* PCB: 507CD (rev1.1)355* parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01356* OEA=80 OEB=00 OEC=00 OED=ff OEF=fe357* IOA=4f IOB=ff IOC=00 IOD=06 IOF=01358* IOD[0] ZL10353 1=enabled359* IOA[7] TS 0=enabled360* tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)361*362* E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"363* PCB: 507DC (rev0.2)364* parts: TDA10023, DTOS403IH102B TM, CST56I01365* OEA=80 OEB=00 OEC=00 OED=ff OEF=fe366* IOA=4f IOB=ff IOC=00 IOD=26 IOF=01367* IOD[0] TDA10023 1=enabled368*369* E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"370* PCB: 507SI (rev2.1)371* parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024372* OEA=80 OEB=00 OEC=ff OED=ff OEF=fe373* IOA=4d IOB=ff IOC=00 IOD=26 IOF=01374* IOD[0] CX24116 1=enabled375*376* E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"377* PCB: 507FA (rev0.4)378* parts: TDA10023, DTOS403IH102B TM, TDA8024379* OEA=80 OEB=00 OEC=ff OED=ff OEF=ff380* IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0381* IOD[5] TDA10023 1=enabled382* IOE[0] tuner 1=enabled383*384* E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"385* PCB: 507FA (rev1.1)386* parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024387* OEA=80 OEB=00 OEC=ff OED=ff OEF=ff388* IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0389* DVB-C:390* IOD[5] TDA10023 1=enabled391* IOE[0] tuner 1=enabled392* DVB-T:393* IOD[0] ZL10353 1=enabled394* IOE[0] tuner 0=enabled395* tuner is behind ZL10353 I2C-gate396*397* E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"398* PCB: 508TC (rev0.6)399* parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)400* OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff401* IOA=4d IOB=00 IOC=cc IOD=48 IOF=e4402* IOA[7] TS 1=enabled403* IOE[4] TDA18212 1=enabled404* DVB-C:405* IOD[6] ZL10353 0=disabled406* IOD[5] TDA10023 1=enabled407* IOE[0] IF 1=enabled408* DVB-T:409* IOD[5] TDA10023 0=disabled410* IOD[6] ZL10353 1=enabled411* IOE[0] IF 0=enabled412*413* E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"414* PCB: 508S2 (rev0.7)415* parts: DNBU10512IST(STV0903, STV6110), ISL6423416* OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff417* IOA=4d IOB=00 IOC=c4 IOD=08 IOF=e4418* IOA[7] TS 1=enabled419* IOE[5] STV0903 1=enabled420*421*/422423static int anysee_frontend_attach(struct dvb_usb_adapter *adap)424{425int ret;426struct anysee_state *state = adap->dev->priv;427u8 hw_info[3];428u8 tmp;429struct i2c_msg msg[2] = {430{431.addr = anysee_tda18212_config.i2c_address,432.flags = 0,433.len = 1,434.buf = "\x00",435}, {436.addr = anysee_tda18212_config.i2c_address,437.flags = I2C_M_RD,438.len = 1,439.buf = &tmp,440}441};442443/* Check which hardware we have.444* We must do this call two times to get reliable values (hw bug).445*/446ret = anysee_get_hw_info(adap->dev, hw_info);447if (ret)448goto error;449450ret = anysee_get_hw_info(adap->dev, hw_info);451if (ret)452goto error;453454/* Meaning of these info bytes are guessed. */455info("firmware version:%d.%d hardware id:%d",456hw_info[1], hw_info[2], hw_info[0]);457458state->hw = hw_info[0];459460switch (state->hw) {461case ANYSEE_HW_02: /* 2 */462/* E30 */463464/* attach demod */465adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,466&adap->dev->i2c_adap);467if (adap->fe)468break;469470/* attach demod */471adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,472&adap->dev->i2c_adap);473474break;475case ANYSEE_HW_507CD: /* 6 */476/* E30 Plus */477478/* enable DVB-T demod on IOD[0] */479ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);480if (ret)481goto error;482483/* enable transport stream on IOA[7] */484ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);485if (ret)486goto error;487488/* attach demod */489adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,490&adap->dev->i2c_adap);491492break;493case ANYSEE_HW_507DC: /* 10 */494/* E30 C Plus */495496/* enable DVB-C demod on IOD[0] */497ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);498if (ret)499goto error;500501/* attach demod */502adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,503&adap->dev->i2c_adap, 0x48);504505break;506case ANYSEE_HW_507SI: /* 11 */507/* E30 S2 Plus */508509/* enable DVB-S/S2 demod on IOD[0] */510ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);511if (ret)512goto error;513514/* attach demod */515adap->fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,516&adap->dev->i2c_adap);517518break;519case ANYSEE_HW_507FA: /* 15 */520/* E30 Combo Plus */521/* E30 C Plus */522523/* enable tuner on IOE[4] */524ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);525if (ret)526goto error;527528/* probe TDA18212 */529tmp = 0;530ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);531if (ret == 2 && tmp == 0xc7)532deb_info("%s: TDA18212 found\n", __func__);533else534tmp = 0;535536/* disable tuner on IOE[4] */537ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);538if (ret)539goto error;540541if (dvb_usb_anysee_delsys) {542/* disable DVB-C demod on IOD[5] */543ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),5440x20);545if (ret)546goto error;547548/* enable DVB-T demod on IOD[0] */549ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),5500x01);551if (ret)552goto error;553554/* attach demod */555if (tmp == 0xc7) {556/* TDA18212 config */557adap->fe = dvb_attach(zl10353_attach,558&anysee_zl10353_tda18212_config2,559&adap->dev->i2c_adap);560} else {561/* PLL config */562adap->fe = dvb_attach(zl10353_attach,563&anysee_zl10353_config,564&adap->dev->i2c_adap);565}566} else {567/* disable DVB-T demod on IOD[0] */568ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),5690x01);570if (ret)571goto error;572573/* enable DVB-C demod on IOD[5] */574ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),5750x20);576if (ret)577goto error;578579/* attach demod */580if (tmp == 0xc7) {581/* TDA18212 config */582adap->fe = dvb_attach(tda10023_attach,583&anysee_tda10023_tda18212_config,584&adap->dev->i2c_adap, 0x48);585} else {586/* PLL config */587adap->fe = dvb_attach(tda10023_attach,588&anysee_tda10023_config,589&adap->dev->i2c_adap, 0x48);590}591}592593break;594case ANYSEE_HW_508TC: /* 18 */595/* E7 TC */596597/* enable transport stream on IOA[7] */598ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);599if (ret)600goto error;601602if (dvb_usb_anysee_delsys) {603/* disable DVB-C demod on IOD[5] */604ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),6050x20);606if (ret)607goto error;608609/* enable DVB-T demod on IOD[6] */610ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),6110x40);612if (ret)613goto error;614615/* enable IF route on IOE[0] */616ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),6170x01);618if (ret)619goto error;620621/* attach demod */622adap->fe = dvb_attach(zl10353_attach,623&anysee_zl10353_tda18212_config,624&adap->dev->i2c_adap);625} else {626/* disable DVB-T demod on IOD[6] */627ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),6280x40);629if (ret)630goto error;631632/* enable DVB-C demod on IOD[5] */633ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),6340x20);635if (ret)636goto error;637638/* enable IF route on IOE[0] */639ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),6400x01);641if (ret)642goto error;643644/* attach demod */645adap->fe = dvb_attach(tda10023_attach,646&anysee_tda10023_tda18212_config,647&adap->dev->i2c_adap, 0x48);648}649650break;651case ANYSEE_HW_508S2: /* 19 */652/* E7 S2 */653654/* enable transport stream on IOA[7] */655ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);656if (ret)657goto error;658659/* enable DVB-S/S2 demod on IOE[5] */660ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);661if (ret)662goto error;663664/* attach demod */665adap->fe = dvb_attach(stv0900_attach, &anysee_stv0900_config,666&adap->dev->i2c_adap, 0);667668break;669}670671if (!adap->fe) {672/* we have no frontend :-( */673ret = -ENODEV;674err("Unsupported Anysee version. " \675"Please report the <[email protected]>.");676}677error:678return ret;679}680681static int anysee_tuner_attach(struct dvb_usb_adapter *adap)682{683struct anysee_state *state = adap->dev->priv;684struct dvb_frontend *fe;685int ret;686deb_info("%s:\n", __func__);687688switch (state->hw) {689case ANYSEE_HW_02: /* 2 */690/* E30 */691692/* attach tuner */693fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),694NULL, DVB_PLL_THOMSON_DTT7579);695696break;697case ANYSEE_HW_507CD: /* 6 */698/* E30 Plus */699700/* attach tuner */701fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),702&adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579);703704break;705case ANYSEE_HW_507DC: /* 10 */706/* E30 C Plus */707708/* attach tuner */709fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),710&adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);711712break;713case ANYSEE_HW_507SI: /* 11 */714/* E30 S2 Plus */715716/* attach LNB controller */717fe = dvb_attach(isl6423_attach, adap->fe, &adap->dev->i2c_adap,718&anysee_isl6423_config);719720break;721case ANYSEE_HW_507FA: /* 15 */722/* E30 Combo Plus */723/* E30 C Plus */724725if (dvb_usb_anysee_delsys) {726/* enable DVB-T tuner on IOE[0] */727ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),7280x01);729if (ret)730goto error;731} else {732/* enable DVB-C tuner on IOE[0] */733ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),7340x01);735if (ret)736goto error;737}738739/* Try first attach TDA18212 silicon tuner on IOE[4], if that740* fails attach old simple PLL. */741742/* enable tuner on IOE[4] */743ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);744if (ret)745goto error;746747/* attach tuner */748fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,749&anysee_tda18212_config);750if (fe)751break;752753/* disable tuner on IOE[4] */754ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);755if (ret)756goto error;757758/* attach tuner */759fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),760&adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);761762break;763case ANYSEE_HW_508TC: /* 18 */764/* E7 TC */765766/* enable tuner on IOE[4] */767ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);768if (ret)769goto error;770771/* attach tuner */772fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,773&anysee_tda18212_config);774775break;776case ANYSEE_HW_508S2: /* 19 */777/* E7 S2 */778779/* attach tuner */780fe = dvb_attach(stv6110_attach, adap->fe,781&anysee_stv6110_config, &adap->dev->i2c_adap);782783if (fe) {784/* attach LNB controller */785fe = dvb_attach(isl6423_attach, adap->fe,786&adap->dev->i2c_adap, &anysee_isl6423_config);787}788789break;790default:791fe = NULL;792}793794if (fe)795ret = 0;796else797ret = -ENODEV;798799error:800return ret;801}802803static int anysee_rc_query(struct dvb_usb_device *d)804{805u8 buf[] = {CMD_GET_IR_CODE};806u8 ircode[2];807int ret;808809/* Remote controller is basic NEC using address byte 0x08.810Anysee device RC query returns only two bytes, status and code,811address byte is dropped. Also it does not return any value for812NEC RCs having address byte other than 0x08. Due to that, we813cannot use that device as standard NEC receiver.814It could be possible make hack which reads whole code directly815from device memory... */816817ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));818if (ret)819return ret;820821if (ircode[0]) {822deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);823rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);824}825826return 0;827}828829/* DVB USB Driver stuff */830static struct dvb_usb_device_properties anysee_properties;831832static int anysee_probe(struct usb_interface *intf,833const struct usb_device_id *id)834{835struct dvb_usb_device *d;836struct usb_host_interface *alt;837int ret;838839/* There is one interface with two alternate settings.840Alternate setting 0 is for bulk transfer.841Alternate setting 1 is for isochronous transfer.842We use bulk transfer (alternate setting 0). */843if (intf->num_altsetting < 1)844return -ENODEV;845846/*847* Anysee is always warm (its USB-bridge, Cypress FX2, uploads848* firmware from eeprom). If dvb_usb_device_init() succeeds that849* means d is a valid pointer.850*/851ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,852adapter_nr);853if (ret)854return ret;855856alt = usb_altnum_to_altsetting(intf, 0);857if (alt == NULL) {858deb_info("%s: no alt found!\n", __func__);859return -ENODEV;860}861862ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,863alt->desc.bAlternateSetting);864if (ret)865return ret;866867return anysee_init(d);868}869870static struct usb_device_id anysee_table[] = {871{ USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },872{ USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },873{ } /* Terminating entry */874};875MODULE_DEVICE_TABLE(usb, anysee_table);876877static struct dvb_usb_device_properties anysee_properties = {878.caps = DVB_USB_IS_AN_I2C_ADAPTER,879880.usb_ctrl = DEVICE_SPECIFIC,881882.size_of_priv = sizeof(struct anysee_state),883884.num_adapters = 1,885.adapter = {886{887.streaming_ctrl = anysee_streaming_ctrl,888.frontend_attach = anysee_frontend_attach,889.tuner_attach = anysee_tuner_attach,890.stream = {891.type = USB_BULK,892.count = 8,893.endpoint = 0x82,894.u = {895.bulk = {896.buffersize = (16*512),897}898}899},900}901},902903.rc.core = {904.rc_codes = RC_MAP_ANYSEE,905.protocol = RC_TYPE_OTHER,906.module_name = "anysee",907.rc_query = anysee_rc_query,908.rc_interval = 250, /* windows driver uses 500ms */909},910911.i2c_algo = &anysee_i2c_algo,912913.generic_bulk_ctrl_endpoint = 1,914915.num_device_descs = 1,916.devices = {917{918.name = "Anysee DVB USB2.0",919.cold_ids = {NULL},920.warm_ids = {&anysee_table[0],921&anysee_table[1], NULL},922},923}924};925926static struct usb_driver anysee_driver = {927.name = "dvb_usb_anysee",928.probe = anysee_probe,929.disconnect = dvb_usb_device_exit,930.id_table = anysee_table,931};932933/* module stuff */934static int __init anysee_module_init(void)935{936int ret;937938ret = usb_register(&anysee_driver);939if (ret)940err("%s: usb_register failed. Error number %d", __func__, ret);941942return ret;943}944945static void __exit anysee_module_exit(void)946{947/* deregister this driver from the USB subsystem */948usb_deregister(&anysee_driver);949}950951module_init(anysee_module_init);952module_exit(anysee_module_exit);953954MODULE_AUTHOR("Antti Palosaari <[email protected]>");955MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");956MODULE_LICENSE("GPL");957958959