2 * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * - add smart card reader support for Conditional Access (CA)
23 * Card reader in Anysee is nothing more than ISO 7816 card reader.
24 * There is no hardware CAM in any Anysee device sold.
25 * In my understanding it should be implemented by making own module
26 * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
27 * module registers serial interface that can be used to communicate
28 * with any ISO 7816 smart card.
30 * Any help according to implement serial smart card reader support
37 #include "mt352_priv.h"
47 static int dvb_usb_anysee_debug;
48 module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
49 MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
50 static int dvb_usb_anysee_delsys;
51 module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
52 MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
53 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
55 static DEFINE_MUTEX(anysee_usb_mutex);
57 static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
60 struct anysee_state *state = d->priv;
64 memcpy(&buf[0], sbuf, slen);
65 buf[60] = state->seq++;
67 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
71 debug_dump(buf, slen, deb_xfer);
73 /* We need receive one message more after dvb_usb_generic_rw due
74 to weird transaction flow, which is 1 x send + 2 x receive. */
75 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
79 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
80 * (EPIPE, Broken pipe). Function supports currently msleep() as a
81 * parameter but I would not like to use it, since according to
82 * Documentation/timers/timers-howto.txt it should not be used such
83 * short, under < 20ms, sleeps. Repeating failed message would be
84 * better choice as not to add unwanted delays...
85 * Fixing that correctly is one of those or both;
86 * 1) use repeat if possible
87 * 2) add suitable delay
90 /* get answer, retry few times if error returned */
91 for (i = 0; i < 3; i++) {
92 /* receive 2nd answer */
93 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
94 d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),
98 deb_info("%s: recv bulk message failed: %d",
102 debug_dump(buf, rlen, deb_xfer);
105 deb_info("%s: cmd failed\n", __func__);
112 /* all retries failed, it is fatal */
113 err("%s: recv bulk message failed: %d", __func__, ret);
117 /* read request, copy returned data to return buf */
119 memcpy(rbuf, buf, rlen);
122 mutex_unlock(&anysee_usb_mutex);
127 static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
129 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
131 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
132 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
136 static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
138 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
139 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
140 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
143 /* write single register with mask */
144 static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
150 /* no need for read if whole reg is written */
152 ret = anysee_read_reg(d, reg, &tmp);
161 return anysee_write_reg(d, reg, val);
164 /* read single register with mask */
165 static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val,
171 ret = anysee_read_reg(d, reg, &tmp);
177 /* find position of the first bit */
178 for (i = 0; i < 8; i++) {
179 if ((mask >> i) & 0x01)
187 static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
189 u8 buf[] = {CMD_GET_HW_INFO};
190 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
193 static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
195 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
196 deb_info("%s: onoff:%02x\n", __func__, onoff);
197 return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
200 static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
202 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
203 deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
204 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
207 static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
209 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
210 deb_info("%s: onoff:%02x\n", __func__, onoff);
211 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
215 static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
218 struct dvb_usb_device *d = i2c_get_adapdata(adap);
219 int ret = 0, inc, i = 0;
220 u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
222 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
226 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
227 if (msg[i].len > 2 || msg[i+1].len > 60) {
231 buf[0] = CMD_I2C_READ;
232 buf[1] = (msg[i].addr << 1) | 0x01;
233 buf[2] = msg[i].buf[0];
234 buf[3] = msg[i].buf[1];
235 buf[4] = msg[i].len-1;
236 buf[5] = msg[i+1].len;
237 ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
241 if (msg[i].len > 48) {
245 buf[0] = CMD_I2C_WRITE;
246 buf[1] = (msg[i].addr << 1);
249 memcpy(&buf[4], msg[i].buf, msg[i].len);
250 ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
259 mutex_unlock(&d->i2c_mutex);
261 return ret ? ret : i;
264 static u32 anysee_i2c_func(struct i2c_adapter *adapter)
269 static struct i2c_algorithm anysee_i2c_algo = {
270 .master_xfer = anysee_master_xfer,
271 .functionality = anysee_i2c_func,
274 static int anysee_mt352_demod_init(struct dvb_frontend *fe)
276 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
277 static u8 reset[] = { RESET, 0x80 };
278 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
279 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
280 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
281 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
283 mt352_write(fe, clock_config, sizeof(clock_config));
285 mt352_write(fe, reset, sizeof(reset));
286 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
288 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
289 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
290 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
295 /* Callbacks for DVB USB */
296 static struct tda10023_config anysee_tda10023_config = {
297 .demod_address = (0x1a >> 1),
303 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
307 static struct mt352_config anysee_mt352_config = {
308 .demod_address = (0x1e >> 1),
309 .demod_init = anysee_mt352_demod_init,
312 static struct zl10353_config anysee_zl10353_config = {
313 .demod_address = (0x1e >> 1),
317 static struct zl10353_config anysee_zl10353_tda18212_config2 = {
318 .demod_address = (0x1e >> 1),
320 .disable_i2c_gate_ctrl = 1,
325 static struct zl10353_config anysee_zl10353_tda18212_config = {
326 .demod_address = (0x18 >> 1),
328 .disable_i2c_gate_ctrl = 1,
333 static struct tda10023_config anysee_tda10023_tda18212_config = {
334 .demod_address = (0x1a >> 1),
339 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B,
343 static struct tda18212_config anysee_tda18212_config = {
344 .i2c_address = (0xc0 >> 1),
351 static struct tda18212_config anysee_tda18212_config2 = {
352 .i2c_address = 0x60 /* (0xc0 >> 1) */,
362 static struct cx24116_config anysee_cx24116_config = {
363 .demod_address = (0xaa >> 1),
364 .mpg_clk_pos_pol = 0x00,
368 static struct stv0900_config anysee_stv0900_config = {
369 .demod_address = (0xd0 >> 1),
375 .tun1_adc = 1, /* 1 Vpp */
379 static struct stv6110_config anysee_stv6110_config = {
380 .i2c_address = (0xc0 >> 1),
385 static struct isl6423_config anysee_isl6423_config = {
386 .current_max = SEC_CURRENT_800m,
387 .curlim = SEC_CURRENT_LIM_OFF,
392 static struct cxd2820r_config anysee_cxd2820r_config = {
393 .i2c_address = 0x6d, /* (0xda >> 1) */
398 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
399 * Manufacturer: AMT.CO.KR
401 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
403 * parts: DNOS404ZH102A(MT352, DTT7579(?))
405 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
406 * PCB: PCB 507T (rev1.61)
407 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
408 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
409 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
411 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
412 * PCB: 507CD (rev1.1)
413 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
414 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
415 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
416 * IOD[0] ZL10353 1=enabled
417 * IOA[7] TS 0=enabled
418 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
420 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
421 * PCB: 507DC (rev0.2)
422 * parts: TDA10023, DTOS403IH102B TM, CST56I01
423 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
424 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
425 * IOD[0] TDA10023 1=enabled
427 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
428 * PCB: 507SI (rev2.1)
429 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
430 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
431 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
432 * IOD[0] CX24116 1=enabled
434 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
435 * PCB: 507FA (rev0.4)
436 * parts: TDA10023, DTOS403IH102B TM, TDA8024
437 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
438 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
439 * IOD[5] TDA10023 1=enabled
440 * IOE[0] tuner 1=enabled
442 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
443 * PCB: 507FA (rev1.1)
444 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
445 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
446 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
448 * IOD[5] TDA10023 1=enabled
449 * IOE[0] tuner 1=enabled
451 * IOD[0] ZL10353 1=enabled
452 * IOE[0] tuner 0=enabled
453 * tuner is behind ZL10353 I2C-gate
455 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
456 * PCB: 508TC (rev0.6)
457 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
458 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
459 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
460 * IOA[7] TS 1=enabled
461 * IOE[4] TDA18212 1=enabled
463 * IOD[6] ZL10353 0=disabled
464 * IOD[5] TDA10023 1=enabled
465 * IOE[0] IF 1=enabled
467 * IOD[5] TDA10023 0=disabled
468 * IOD[6] ZL10353 1=enabled
469 * IOE[0] IF 0=enabled
471 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
472 * PCB: 508S2 (rev0.7)
473 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
474 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
475 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
476 * IOA[7] TS 1=enabled
477 * IOE[5] STV0903 1=enabled
479 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
480 * PCB: 508T2C (rev0.3)
481 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
482 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
483 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
484 * IOA[7] TS 1=enabled
485 * IOE[5] CXD2820R 1=enabled
487 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
488 * PCB: 508PTC (rev0.5)
489 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
490 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
491 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
492 * IOA[7] TS 1=enabled
493 * IOE[4] TDA18212 1=enabled
495 * IOD[6] ZL10353 0=disabled
496 * IOD[5] TDA10023 1=enabled
497 * IOE[0] IF 1=enabled
499 * IOD[5] TDA10023 0=disabled
500 * IOD[6] ZL10353 1=enabled
501 * IOE[0] IF 0=enabled
503 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
504 * PCB: 508PS2 (rev0.4)
505 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
506 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
507 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
508 * IOA[7] TS 1=enabled
509 * IOE[5] STV0903 1=enabled
513 /* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
514 static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
516 struct dvb_usb_adapter *adap = fe->dvb->priv;
518 /* enable / disable tuner access on IOE[4] */
519 return anysee_wr_reg_mask(adap->dev, REG_IOE, (enable << 4), 0x10);
522 static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
524 struct dvb_usb_adapter *adap = fe->dvb->priv;
525 struct anysee_state *state = adap->dev->priv;
528 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
530 /* no frontend sleep control */
535 case ANYSEE_HW_507FA: /* 15 */
539 if ((fe->id ^ dvb_usb_anysee_delsys) == 0) {
540 /* disable DVB-T demod on IOD[0] */
541 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
546 /* enable DVB-C demod on IOD[5] */
547 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
552 /* enable DVB-C tuner on IOE[0] */
553 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
558 /* disable DVB-C demod on IOD[5] */
559 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
564 /* enable DVB-T demod on IOD[0] */
565 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
570 /* enable DVB-T tuner on IOE[0] */
571 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
578 case ANYSEE_HW_508TC: /* 18 */
579 case ANYSEE_HW_508PTC: /* 21 */
583 if ((fe->id ^ dvb_usb_anysee_delsys) == 0) {
584 /* disable DVB-T demod on IOD[6] */
585 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
590 /* enable DVB-C demod on IOD[5] */
591 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
596 /* enable IF route on IOE[0] */
597 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
602 /* disable DVB-C demod on IOD[5] */
603 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
608 /* enable DVB-T demod on IOD[6] */
609 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
614 /* enable IF route on IOE[0] */
615 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
630 static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
633 struct anysee_state *state = adap->dev->priv;
636 struct i2c_msg msg[2] = {
638 .addr = anysee_tda18212_config.i2c_address,
643 .addr = anysee_tda18212_config.i2c_address,
650 /* detect hardware only once */
651 if (adap->fe_adap[0].fe == NULL) {
652 /* Check which hardware we have.
653 * We must do this call two times to get reliable values
656 ret = anysee_get_hw_info(adap->dev, hw_info);
660 ret = anysee_get_hw_info(adap->dev, hw_info);
664 /* Meaning of these info bytes are guessed. */
665 info("firmware version:%d.%d hardware id:%d",
666 hw_info[1], hw_info[2], hw_info[0]);
668 state->hw = hw_info[0];
671 /* set current frondend ID for devices having two frondends */
672 if (adap->fe_adap[0].fe)
676 case ANYSEE_HW_507T: /* 2 */
683 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
684 &anysee_mt352_config, &adap->dev->i2c_adap);
685 if (adap->fe_adap[0].fe)
689 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
690 &anysee_zl10353_config, &adap->dev->i2c_adap);
693 case ANYSEE_HW_507CD: /* 6 */
699 /* enable DVB-T demod on IOD[0] */
700 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
704 /* enable transport stream on IOA[7] */
705 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);
710 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
711 &anysee_zl10353_config, &adap->dev->i2c_adap);
714 case ANYSEE_HW_507DC: /* 10 */
720 /* enable DVB-C demod on IOD[0] */
721 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
726 adap->fe_adap[0].fe = dvb_attach(tda10023_attach,
727 &anysee_tda10023_config, &adap->dev->i2c_adap, 0x48);
730 case ANYSEE_HW_507SI: /* 11 */
736 /* enable DVB-S/S2 demod on IOD[0] */
737 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
742 adap->fe_adap[0].fe = dvb_attach(cx24116_attach,
743 &anysee_cx24116_config, &adap->dev->i2c_adap);
746 case ANYSEE_HW_507FA: /* 15 */
750 /* enable tuner on IOE[4] */
751 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
757 ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);
758 if (ret == 2 && tmp == 0xc7)
759 deb_info("%s: TDA18212 found\n", __func__);
763 /* disable tuner on IOE[4] */
764 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
768 if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0) {
769 /* disable DVB-T demod on IOD[0] */
770 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
775 /* enable DVB-C demod on IOD[5] */
776 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
783 /* TDA18212 config */
784 adap->fe_adap[state->fe_id].fe = dvb_attach(
786 &anysee_tda10023_tda18212_config,
787 &adap->dev->i2c_adap, 0x48);
790 adap->fe_adap[state->fe_id].fe = dvb_attach(
792 &anysee_tda10023_config,
793 &adap->dev->i2c_adap, 0x48);
796 /* disable DVB-C demod on IOD[5] */
797 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
802 /* enable DVB-T demod on IOD[0] */
803 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
810 /* TDA18212 config */
811 adap->fe_adap[state->fe_id].fe = dvb_attach(
813 &anysee_zl10353_tda18212_config2,
814 &adap->dev->i2c_adap);
817 adap->fe_adap[state->fe_id].fe = dvb_attach(
819 &anysee_zl10353_config,
820 &adap->dev->i2c_adap);
824 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
826 if (adap->fe_adap[state->fe_id].fe)
827 adap->fe_adap[state->fe_id].fe->ops.i2c_gate_ctrl =
828 anysee_i2c_gate_ctrl;
832 case ANYSEE_HW_508TC: /* 18 */
833 case ANYSEE_HW_508PTC: /* 21 */
837 if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0) {
838 /* disable DVB-T demod on IOD[6] */
839 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
844 /* enable DVB-C demod on IOD[5] */
845 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
851 adap->fe_adap[state->fe_id].fe =
852 dvb_attach(tda10023_attach,
853 &anysee_tda10023_tda18212_config,
854 &adap->dev->i2c_adap, 0x48);
856 /* disable DVB-C demod on IOD[5] */
857 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
862 /* enable DVB-T demod on IOD[6] */
863 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
869 adap->fe_adap[state->fe_id].fe =
870 dvb_attach(zl10353_attach,
871 &anysee_zl10353_tda18212_config,
872 &adap->dev->i2c_adap);
875 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
876 if (adap->fe_adap[state->fe_id].fe)
877 adap->fe_adap[state->fe_id].fe->ops.i2c_gate_ctrl =
878 anysee_i2c_gate_ctrl;
880 state->has_ci = true;
883 case ANYSEE_HW_508S2: /* 19 */
884 case ANYSEE_HW_508PS2: /* 22 */
891 /* enable DVB-S/S2 demod on IOE[5] */
892 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
897 adap->fe_adap[0].fe = dvb_attach(stv0900_attach,
898 &anysee_stv0900_config, &adap->dev->i2c_adap, 0);
900 state->has_ci = true;
903 case ANYSEE_HW_508T2C: /* 20 */
909 /* enable DVB-T/T2/C demod on IOE[5] */
910 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
915 adap->fe_adap[state->fe_id].fe = dvb_attach(cxd2820r_attach,
916 &anysee_cxd2820r_config, &adap->dev->i2c_adap);
918 state->has_ci = true;
923 if (!adap->fe_adap[0].fe) {
924 /* we have no frontend :-( */
926 err("Unsupported Anysee version. " \
927 "Please report the <linux-media@vger.kernel.org>.");
933 static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
935 struct anysee_state *state = adap->dev->priv;
936 struct dvb_frontend *fe;
938 deb_info("%s: fe=%d\n", __func__, state->fe_id);
941 case ANYSEE_HW_507T: /* 2 */
945 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe,
946 (0xc2 >> 1), NULL, DVB_PLL_THOMSON_DTT7579);
949 case ANYSEE_HW_507CD: /* 6 */
953 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe,
954 (0xc2 >> 1), &adap->dev->i2c_adap,
955 DVB_PLL_THOMSON_DTT7579);
958 case ANYSEE_HW_507DC: /* 10 */
962 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe,
963 (0xc0 >> 1), &adap->dev->i2c_adap,
964 DVB_PLL_SAMSUNG_DTOS403IH102A);
967 case ANYSEE_HW_507SI: /* 11 */
970 /* attach LNB controller */
971 fe = dvb_attach(isl6423_attach, adap->fe_adap[0].fe,
972 &adap->dev->i2c_adap, &anysee_isl6423_config);
975 case ANYSEE_HW_507FA: /* 15 */
979 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
980 * fails attach old simple PLL. */
983 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
984 &adap->dev->i2c_adap, &anysee_tda18212_config);
989 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[state->fe_id].fe,
990 (0xc0 >> 1), &adap->dev->i2c_adap,
991 DVB_PLL_SAMSUNG_DTOS403IH102A);
994 case ANYSEE_HW_508TC: /* 18 */
995 case ANYSEE_HW_508PTC: /* 21 */
1000 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
1001 &adap->dev->i2c_adap, &anysee_tda18212_config);
1004 case ANYSEE_HW_508S2: /* 19 */
1005 case ANYSEE_HW_508PS2: /* 22 */
1010 fe = dvb_attach(stv6110_attach, adap->fe_adap[0].fe,
1011 &anysee_stv6110_config, &adap->dev->i2c_adap);
1014 /* attach LNB controller */
1015 fe = dvb_attach(isl6423_attach, adap->fe_adap[0].fe,
1016 &adap->dev->i2c_adap, &anysee_isl6423_config);
1021 case ANYSEE_HW_508T2C: /* 20 */
1025 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
1026 &adap->dev->i2c_adap, &anysee_tda18212_config2);
1041 static int anysee_rc_query(struct dvb_usb_device *d)
1043 u8 buf[] = {CMD_GET_IR_CODE};
1047 /* Remote controller is basic NEC using address byte 0x08.
1048 Anysee device RC query returns only two bytes, status and code,
1049 address byte is dropped. Also it does not return any value for
1050 NEC RCs having address byte other than 0x08. Due to that, we
1051 cannot use that device as standard NEC receiver.
1052 It could be possible make hack which reads whole code directly
1053 from device memory... */
1055 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
1060 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
1061 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
1067 static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1070 struct dvb_usb_device *d = ci->data;
1072 u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1};
1075 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1082 static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1085 struct dvb_usb_device *d = ci->data;
1087 u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val};
1089 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1096 static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot,
1099 struct dvb_usb_device *d = ci->data;
1101 u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1};
1104 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1111 static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot,
1114 struct dvb_usb_device *d = ci->data;
1116 u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val};
1118 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1125 static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot)
1127 struct dvb_usb_device *d = ci->data;
1129 struct anysee_state *state = d->priv;
1131 state->ci_cam_ready = jiffies + msecs_to_jiffies(1000);
1133 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1139 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1146 static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot)
1148 struct dvb_usb_device *d = ci->data;
1151 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1157 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1164 static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot)
1166 struct dvb_usb_device *d = ci->data;
1169 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02);
1176 static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot,
1179 struct dvb_usb_device *d = ci->data;
1180 struct anysee_state *state = d->priv;
1184 ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40);
1189 ret = DVB_CA_EN50221_POLL_CAM_PRESENT;
1190 if (time_after(jiffies, state->ci_cam_ready))
1191 ret |= DVB_CA_EN50221_POLL_CAM_READY;
1197 static int anysee_ci_init(struct dvb_usb_device *d)
1199 struct anysee_state *state = d->priv;
1202 state->ci.owner = THIS_MODULE;
1203 state->ci.read_attribute_mem = anysee_ci_read_attribute_mem;
1204 state->ci.write_attribute_mem = anysee_ci_write_attribute_mem;
1205 state->ci.read_cam_control = anysee_ci_read_cam_control;
1206 state->ci.write_cam_control = anysee_ci_write_cam_control;
1207 state->ci.slot_reset = anysee_ci_slot_reset;
1208 state->ci.slot_shutdown = anysee_ci_slot_shutdown;
1209 state->ci.slot_ts_enable = anysee_ci_slot_ts_enable;
1210 state->ci.poll_slot_status = anysee_ci_poll_slot_status;
1213 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1217 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1221 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1225 ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1);
1232 static void anysee_ci_release(struct dvb_usb_device *d)
1234 struct anysee_state *state = d->priv;
1238 dvb_ca_en50221_release(&state->ci);
1243 static int anysee_init(struct dvb_usb_device *d)
1245 struct anysee_state *state = d->priv;
1249 ret = anysee_led_ctrl(d, 0x01, 0x03);
1254 ret = anysee_ir_ctrl(d, 1);
1259 if (state->has_ci) {
1260 ret = anysee_ci_init(d);
1262 state->has_ci = false;
1270 /* DVB USB Driver stuff */
1271 static struct dvb_usb_device_properties anysee_properties;
1273 static int anysee_probe(struct usb_interface *intf,
1274 const struct usb_device_id *id)
1276 struct dvb_usb_device *d;
1277 struct usb_host_interface *alt;
1280 /* There is one interface with two alternate settings.
1281 Alternate setting 0 is for bulk transfer.
1282 Alternate setting 1 is for isochronous transfer.
1283 We use bulk transfer (alternate setting 0). */
1284 if (intf->num_altsetting < 1)
1288 * Anysee is always warm (its USB-bridge, Cypress FX2, uploads
1289 * firmware from eeprom). If dvb_usb_device_init() succeeds that
1290 * means d is a valid pointer.
1292 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
1297 alt = usb_altnum_to_altsetting(intf, 0);
1299 deb_info("%s: no alt found!\n", __func__);
1303 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
1304 alt->desc.bAlternateSetting);
1308 return anysee_init(d);
1311 static void anysee_disconnect(struct usb_interface *intf)
1313 struct dvb_usb_device *d = usb_get_intfdata(intf);
1315 anysee_ci_release(d);
1316 dvb_usb_device_exit(intf);
1321 static struct usb_device_id anysee_table[] = {
1322 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
1323 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
1324 { } /* Terminating entry */
1326 MODULE_DEVICE_TABLE(usb, anysee_table);
1328 static struct dvb_usb_device_properties anysee_properties = {
1329 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1331 .usb_ctrl = DEVICE_SPECIFIC,
1333 .size_of_priv = sizeof(struct anysee_state),
1339 .frontend_ctrl = anysee_frontend_ctrl,
1341 .streaming_ctrl = anysee_streaming_ctrl,
1342 .frontend_attach = anysee_frontend_attach,
1343 .tuner_attach = anysee_tuner_attach,
1350 .buffersize = (16*512),
1355 .streaming_ctrl = anysee_streaming_ctrl,
1356 .frontend_attach = anysee_frontend_attach,
1357 .tuner_attach = anysee_tuner_attach,
1364 .buffersize = (16*512),
1373 .rc_codes = RC_MAP_ANYSEE,
1374 .protocol = RC_TYPE_OTHER,
1375 .module_name = "anysee",
1376 .rc_query = anysee_rc_query,
1377 .rc_interval = 250, /* windows driver uses 500ms */
1380 .i2c_algo = &anysee_i2c_algo,
1382 .generic_bulk_ctrl_endpoint = 1,
1384 .num_device_descs = 1,
1387 .name = "Anysee DVB USB2.0",
1389 .warm_ids = {&anysee_table[0],
1390 &anysee_table[1], NULL},
1395 static struct usb_driver anysee_driver = {
1396 .name = "dvb_usb_anysee",
1397 .probe = anysee_probe,
1398 .disconnect = anysee_disconnect,
1399 .id_table = anysee_table,
1402 module_usb_driver(anysee_driver);
1404 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1405 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1406 MODULE_LICENSE("GPL");