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
38 #include "mt352_priv.h"
47 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
48 static DEFINE_MUTEX(anysee_usb_mutex
);
50 static int anysee_ctrl_msg(struct dvb_usb_device
*d
, u8
*sbuf
, u8 slen
,
53 struct anysee_state
*state
= d_to_priv(d
);
57 memcpy(&buf
[0], sbuf
, slen
);
58 buf
[60] = state
->seq
++;
60 mutex_lock(&anysee_usb_mutex
);
62 dev_dbg(&d
->udev
->dev
, "%s: >>> %*ph\n", __func__
, slen
, buf
);
64 /* We need receive one message more after dvb_usb_generic_rw due
65 to weird transaction flow, which is 1 x send + 2 x receive. */
66 ret
= dvb_usbv2_generic_rw(d
, buf
, sizeof(buf
), buf
, sizeof(buf
));
70 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
71 * (EPIPE, Broken pipe). Function supports currently msleep() as a
72 * parameter but I would not like to use it, since according to
73 * Documentation/timers/timers-howto.txt it should not be used such
74 * short, under < 20ms, sleeps. Repeating failed message would be
75 * better choice as not to add unwanted delays...
76 * Fixing that correctly is one of those or both;
77 * 1) use repeat if possible
78 * 2) add suitable delay
81 /* get answer, retry few times if error returned */
82 for (i
= 0; i
< 3; i
++) {
83 /* receive 2nd answer */
84 ret
= usb_bulk_msg(d
->udev
, usb_rcvbulkpipe(d
->udev
,
85 d
->props
->generic_bulk_ctrl_endpoint
), buf
, sizeof(buf
),
89 dev_dbg(&d
->udev
->dev
, "%s: recv bulk message " \
90 "failed=%d\n", __func__
, ret
);
92 dev_dbg(&d
->udev
->dev
, "%s: <<< %*ph\n", __func__
,
96 dev_dbg(&d
->udev
->dev
, "%s: cmd failed\n",
104 /* all retries failed, it is fatal */
105 dev_err(&d
->udev
->dev
, "%s: recv bulk message failed=%d\n",
106 KBUILD_MODNAME
, ret
);
110 /* read request, copy returned data to return buf */
112 memcpy(rbuf
, buf
, rlen
);
115 mutex_unlock(&anysee_usb_mutex
);
120 static int anysee_read_reg(struct dvb_usb_device
*d
, u16 reg
, u8
*val
)
122 u8 buf
[] = {CMD_REG_READ
, reg
>> 8, reg
& 0xff, 0x01};
124 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), val
, 1);
125 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, *val
);
129 static int anysee_write_reg(struct dvb_usb_device
*d
, u16 reg
, u8 val
)
131 u8 buf
[] = {CMD_REG_WRITE
, reg
>> 8, reg
& 0xff, 0x01, val
};
132 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, val
);
133 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
136 /* write single register with mask */
137 static int anysee_wr_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8 val
,
143 /* no need for read if whole reg is written */
145 ret
= anysee_read_reg(d
, reg
, &tmp
);
154 return anysee_write_reg(d
, reg
, val
);
157 /* read single register with mask */
158 static int anysee_rd_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8
*val
,
164 ret
= anysee_read_reg(d
, reg
, &tmp
);
170 /* find position of the first bit */
171 for (i
= 0; i
< 8; i
++) {
172 if ((mask
>> i
) & 0x01)
180 static int anysee_get_hw_info(struct dvb_usb_device
*d
, u8
*id
)
182 u8 buf
[] = {CMD_GET_HW_INFO
};
183 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), id
, 3);
186 static int anysee_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
188 u8 buf
[] = {CMD_STREAMING_CTRL
, (u8
)onoff
, 0x00};
189 dev_dbg(&fe_to_d(fe
)->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
190 return anysee_ctrl_msg(fe_to_d(fe
), buf
, sizeof(buf
), NULL
, 0);
193 static int anysee_led_ctrl(struct dvb_usb_device
*d
, u8 mode
, u8 interval
)
195 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x01, mode
, interval
};
196 dev_dbg(&d
->udev
->dev
, "%s: state=%d interval=%d\n", __func__
,
198 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
201 static int anysee_ir_ctrl(struct dvb_usb_device
*d
, u8 onoff
)
203 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x02, onoff
};
204 dev_dbg(&d
->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
205 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
209 static int anysee_master_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msg
,
212 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
213 int ret
= 0, inc
, i
= 0;
214 u8 buf
[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
216 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
220 if (num
> i
+ 1 && (msg
[i
+1].flags
& I2C_M_RD
)) {
221 if (msg
[i
].len
> 2 || msg
[i
+1].len
> 60) {
225 buf
[0] = CMD_I2C_READ
;
226 buf
[1] = (msg
[i
].addr
<< 1) | 0x01;
227 buf
[2] = msg
[i
].buf
[0];
228 buf
[3] = msg
[i
].buf
[1];
229 buf
[4] = msg
[i
].len
-1;
230 buf
[5] = msg
[i
+1].len
;
231 ret
= anysee_ctrl_msg(d
, buf
, 6, msg
[i
+1].buf
,
235 if (msg
[i
].len
> 48) {
239 buf
[0] = CMD_I2C_WRITE
;
240 buf
[1] = (msg
[i
].addr
<< 1);
243 memcpy(&buf
[4], msg
[i
].buf
, msg
[i
].len
);
244 ret
= anysee_ctrl_msg(d
, buf
, 4 + msg
[i
].len
, NULL
, 0);
253 mutex_unlock(&d
->i2c_mutex
);
255 return ret
? ret
: i
;
258 static u32
anysee_i2c_func(struct i2c_adapter
*adapter
)
263 static struct i2c_algorithm anysee_i2c_algo
= {
264 .master_xfer
= anysee_master_xfer
,
265 .functionality
= anysee_i2c_func
,
268 static int anysee_mt352_demod_init(struct dvb_frontend
*fe
)
270 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x28 };
271 static u8 reset
[] = { RESET
, 0x80 };
272 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
273 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0x20 };
274 static u8 gpp_ctl_cfg
[] = { GPP_CTL
, 0x33 };
275 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x32 };
277 mt352_write(fe
, clock_config
, sizeof(clock_config
));
279 mt352_write(fe
, reset
, sizeof(reset
));
280 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
282 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
283 mt352_write(fe
, gpp_ctl_cfg
, sizeof(gpp_ctl_cfg
));
284 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
289 /* Callbacks for DVB USB */
290 static struct tda10023_config anysee_tda10023_config
= {
291 .demod_address
= (0x1a >> 1),
297 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_C
,
301 static struct mt352_config anysee_mt352_config
= {
302 .demod_address
= (0x1e >> 1),
303 .demod_init
= anysee_mt352_demod_init
,
306 static struct zl10353_config anysee_zl10353_config
= {
307 .demod_address
= (0x1e >> 1),
311 static struct zl10353_config anysee_zl10353_tda18212_config2
= {
312 .demod_address
= (0x1e >> 1),
314 .disable_i2c_gate_ctrl
= 1,
319 static struct zl10353_config anysee_zl10353_tda18212_config
= {
320 .demod_address
= (0x18 >> 1),
322 .disable_i2c_gate_ctrl
= 1,
327 static struct tda10023_config anysee_tda10023_tda18212_config
= {
328 .demod_address
= (0x1a >> 1),
333 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_B
,
337 static struct tda18212_config anysee_tda18212_config
= {
338 .i2c_address
= (0xc0 >> 1),
345 static struct tda18212_config anysee_tda18212_config2
= {
346 .i2c_address
= 0x60 /* (0xc0 >> 1) */,
356 static struct cx24116_config anysee_cx24116_config
= {
357 .demod_address
= (0xaa >> 1),
358 .mpg_clk_pos_pol
= 0x00,
362 static struct stv0900_config anysee_stv0900_config
= {
363 .demod_address
= (0xd0 >> 1),
369 .tun1_adc
= 1, /* 1 Vpp */
373 static struct stv6110_config anysee_stv6110_config
= {
374 .i2c_address
= (0xc0 >> 1),
379 static struct isl6423_config anysee_isl6423_config
= {
380 .current_max
= SEC_CURRENT_800m
,
381 .curlim
= SEC_CURRENT_LIM_OFF
,
386 static struct cxd2820r_config anysee_cxd2820r_config
= {
387 .i2c_address
= 0x6d, /* (0xda >> 1) */
392 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
393 * Manufacturer: AMT.CO.KR
395 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
397 * parts: DNOS404ZH102A(MT352, DTT7579(?))
399 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
400 * PCB: PCB 507T (rev1.61)
401 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
402 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
403 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
405 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
406 * PCB: 507CD (rev1.1)
407 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
408 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
409 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
410 * IOD[0] ZL10353 1=enabled
411 * IOA[7] TS 0=enabled
412 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
414 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
415 * PCB: 507DC (rev0.2)
416 * parts: TDA10023, DTOS403IH102B TM, CST56I01
417 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
418 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
419 * IOD[0] TDA10023 1=enabled
421 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
422 * PCB: 507SI (rev2.1)
423 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
424 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
425 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
426 * IOD[0] CX24116 1=enabled
428 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
429 * PCB: 507FA (rev0.4)
430 * parts: TDA10023, DTOS403IH102B TM, TDA8024
431 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
432 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
433 * IOD[5] TDA10023 1=enabled
434 * IOE[0] tuner 1=enabled
436 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
437 * PCB: 507FA (rev1.1)
438 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
439 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
440 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
442 * IOD[5] TDA10023 1=enabled
443 * IOE[0] tuner 1=enabled
445 * IOD[0] ZL10353 1=enabled
446 * IOE[0] tuner 0=enabled
447 * tuner is behind ZL10353 I2C-gate
449 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
450 * PCB: 508TC (rev0.6)
451 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
452 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
453 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
454 * IOA[7] TS 1=enabled
455 * IOE[4] TDA18212 1=enabled
457 * IOD[6] ZL10353 0=disabled
458 * IOD[5] TDA10023 1=enabled
459 * IOE[0] IF 1=enabled
461 * IOD[5] TDA10023 0=disabled
462 * IOD[6] ZL10353 1=enabled
463 * IOE[0] IF 0=enabled
465 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
466 * PCB: 508S2 (rev0.7)
467 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
468 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
469 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
470 * IOA[7] TS 1=enabled
471 * IOE[5] STV0903 1=enabled
473 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
474 * PCB: 508T2C (rev0.3)
475 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
476 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
477 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
478 * IOA[7] TS 1=enabled
479 * IOE[5] CXD2820R 1=enabled
481 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
482 * PCB: 508PTC (rev0.5)
483 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
484 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
485 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
486 * IOA[7] TS 1=enabled
487 * IOE[4] TDA18212 1=enabled
489 * IOD[6] ZL10353 0=disabled
490 * IOD[5] TDA10023 1=enabled
491 * IOE[0] IF 1=enabled
493 * IOD[5] TDA10023 0=disabled
494 * IOD[6] ZL10353 1=enabled
495 * IOE[0] IF 0=enabled
497 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
498 * PCB: 508PS2 (rev0.4)
499 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
500 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
501 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
502 * IOA[7] TS 1=enabled
503 * IOE[5] STV0903 1=enabled
506 static int anysee_read_config(struct dvb_usb_device
*d
)
508 struct anysee_state
*state
= d_to_priv(d
);
513 * Check which hardware we have.
514 * We must do this call two times to get reliable values (hw/fw bug).
516 ret
= anysee_get_hw_info(d
, hw_info
);
520 ret
= anysee_get_hw_info(d
, hw_info
);
525 * Meaning of these info bytes are guessed.
527 dev_info(&d
->udev
->dev
, "%s: firmware version %d.%d hardware id %d\n",
528 KBUILD_MODNAME
, hw_info
[1], hw_info
[2], hw_info
[0]);
530 state
->hw
= hw_info
[0];
535 /* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
536 static int anysee_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
538 /* enable / disable tuner access on IOE[4] */
539 return anysee_wr_reg_mask(fe_to_d(fe
), REG_IOE
, (enable
<< 4), 0x10);
542 static int anysee_frontend_ctrl(struct dvb_frontend
*fe
, int onoff
)
544 struct anysee_state
*state
= fe_to_priv(fe
);
545 struct dvb_usb_device
*d
= fe_to_d(fe
);
547 dev_dbg(&d
->udev
->dev
, "%s: fe=%d onoff=%d\n", __func__
, fe
->id
, onoff
);
549 /* no frontend sleep control */
554 case ANYSEE_HW_507FA
: /* 15 */
559 /* disable DVB-T demod on IOD[0] */
560 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
564 /* enable DVB-C demod on IOD[5] */
565 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
569 /* enable DVB-C tuner on IOE[0] */
570 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
574 /* disable DVB-C demod on IOD[5] */
575 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
579 /* enable DVB-T demod on IOD[0] */
580 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
584 /* enable DVB-T tuner on IOE[0] */
585 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
591 case ANYSEE_HW_508TC
: /* 18 */
592 case ANYSEE_HW_508PTC
: /* 21 */
597 /* disable DVB-T demod on IOD[6] */
598 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
602 /* enable DVB-C demod on IOD[5] */
603 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
607 /* enable IF route on IOE[0] */
608 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
612 /* disable DVB-C demod on IOD[5] */
613 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
617 /* enable DVB-T demod on IOD[6] */
618 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
622 /* enable IF route on IOE[0] */
623 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
637 static int anysee_frontend_attach(struct dvb_usb_adapter
*adap
)
639 struct anysee_state
*state
= adap_to_priv(adap
);
640 struct dvb_usb_device
*d
= adap_to_d(adap
);
643 struct i2c_msg msg
[2] = {
645 .addr
= anysee_tda18212_config
.i2c_address
,
650 .addr
= anysee_tda18212_config
.i2c_address
,
658 case ANYSEE_HW_507T
: /* 2 */
662 adap
->fe
[0] = dvb_attach(mt352_attach
, &anysee_mt352_config
,
668 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
672 case ANYSEE_HW_507CD
: /* 6 */
675 /* enable DVB-T demod on IOD[0] */
676 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
680 /* enable transport stream on IOA[7] */
681 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
686 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
690 case ANYSEE_HW_507DC
: /* 10 */
693 /* enable DVB-C demod on IOD[0] */
694 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
699 adap
->fe
[0] = dvb_attach(tda10023_attach
,
700 &anysee_tda10023_config
, &d
->i2c_adap
, 0x48);
703 case ANYSEE_HW_507SI
: /* 11 */
706 /* enable DVB-S/S2 demod on IOD[0] */
707 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
712 adap
->fe
[0] = dvb_attach(cx24116_attach
, &anysee_cx24116_config
,
716 case ANYSEE_HW_507FA
: /* 15 */
720 /* enable tuner on IOE[4] */
721 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 4), 0x10);
727 ret
= i2c_transfer(&d
->i2c_adap
, msg
, 2);
728 if (ret
== 2 && tmp
== 0xc7)
729 dev_dbg(&d
->udev
->dev
, "%s: TDA18212 found\n",
734 /* disable tuner on IOE[4] */
735 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 4), 0x10);
739 /* disable DVB-T demod on IOD[0] */
740 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
744 /* enable DVB-C demod on IOD[5] */
745 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
751 /* TDA18212 config */
752 adap
->fe
[0] = dvb_attach(tda10023_attach
,
753 &anysee_tda10023_tda18212_config
,
756 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
758 adap
->fe
[0]->ops
.i2c_gate_ctrl
=
759 anysee_i2c_gate_ctrl
;
762 adap
->fe
[0] = dvb_attach(tda10023_attach
,
763 &anysee_tda10023_config
,
767 /* break out if first frontend attaching fails */
771 /* disable DVB-C demod on IOD[5] */
772 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
776 /* enable DVB-T demod on IOD[0] */
777 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
783 /* TDA18212 config */
784 adap
->fe
[1] = dvb_attach(zl10353_attach
,
785 &anysee_zl10353_tda18212_config2
,
788 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
790 adap
->fe
[1]->ops
.i2c_gate_ctrl
=
791 anysee_i2c_gate_ctrl
;
794 adap
->fe
[1] = dvb_attach(zl10353_attach
,
795 &anysee_zl10353_config
,
800 case ANYSEE_HW_508TC
: /* 18 */
801 case ANYSEE_HW_508PTC
: /* 21 */
805 /* disable DVB-T demod on IOD[6] */
806 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
810 /* enable DVB-C demod on IOD[5] */
811 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
816 adap
->fe
[0] = dvb_attach(tda10023_attach
,
817 &anysee_tda10023_tda18212_config
,
820 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
822 adap
->fe
[0]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
824 /* break out if first frontend attaching fails */
828 /* disable DVB-C demod on IOD[5] */
829 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
833 /* enable DVB-T demod on IOD[6] */
834 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
839 adap
->fe
[1] = dvb_attach(zl10353_attach
,
840 &anysee_zl10353_tda18212_config
,
843 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
845 adap
->fe
[1]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
847 state
->has_ci
= true;
850 case ANYSEE_HW_508S2
: /* 19 */
851 case ANYSEE_HW_508PS2
: /* 22 */
855 /* enable DVB-S/S2 demod on IOE[5] */
856 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
861 adap
->fe
[0] = dvb_attach(stv0900_attach
,
862 &anysee_stv0900_config
, &d
->i2c_adap
, 0);
864 state
->has_ci
= true;
867 case ANYSEE_HW_508T2C
: /* 20 */
870 /* enable DVB-T/T2/C demod on IOE[5] */
871 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
876 adap
->fe
[0] = dvb_attach(cxd2820r_attach
,
877 &anysee_cxd2820r_config
, &d
->i2c_adap
, NULL
);
879 state
->has_ci
= true;
885 /* we have no frontend :-( */
887 dev_err(&d
->udev
->dev
, "%s: Unsupported Anysee version. " \
888 "Please report the " \
889 "<linux-media@vger.kernel.org>.\n",
896 static int anysee_tuner_attach(struct dvb_usb_adapter
*adap
)
898 struct anysee_state
*state
= adap_to_priv(adap
);
899 struct dvb_usb_device
*d
= adap_to_d(adap
);
900 struct dvb_frontend
*fe
;
902 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
905 case ANYSEE_HW_507T
: /* 2 */
909 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1), NULL
,
910 DVB_PLL_THOMSON_DTT7579
);
913 case ANYSEE_HW_507CD
: /* 6 */
917 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1),
918 &d
->i2c_adap
, DVB_PLL_THOMSON_DTT7579
);
921 case ANYSEE_HW_507DC
: /* 10 */
925 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc0 >> 1),
926 &d
->i2c_adap
, DVB_PLL_SAMSUNG_DTOS403IH102A
);
929 case ANYSEE_HW_507SI
: /* 11 */
932 /* attach LNB controller */
933 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0], &d
->i2c_adap
,
934 &anysee_isl6423_config
);
937 case ANYSEE_HW_507FA
: /* 15 */
941 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
942 * fails attach old simple PLL. */
945 fe
= dvb_attach(tda18212_attach
, adap
->fe
[0], &d
->i2c_adap
,
946 &anysee_tda18212_config
);
948 if (fe
&& adap
->fe
[1]) {
949 /* attach tuner for 2nd FE */
950 fe
= dvb_attach(tda18212_attach
, adap
->fe
[1],
951 &d
->i2c_adap
, &anysee_tda18212_config
);
958 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc0 >> 1),
959 &d
->i2c_adap
, DVB_PLL_SAMSUNG_DTOS403IH102A
);
961 if (fe
&& adap
->fe
[1]) {
962 /* attach tuner for 2nd FE */
963 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0],
964 (0xc0 >> 1), &d
->i2c_adap
,
965 DVB_PLL_SAMSUNG_DTOS403IH102A
);
969 case ANYSEE_HW_508TC
: /* 18 */
970 case ANYSEE_HW_508PTC
: /* 21 */
975 fe
= dvb_attach(tda18212_attach
, adap
->fe
[0], &d
->i2c_adap
,
976 &anysee_tda18212_config
);
979 /* attach tuner for 2nd FE */
980 fe
= dvb_attach(tda18212_attach
, adap
->fe
[1],
981 &d
->i2c_adap
, &anysee_tda18212_config
);
985 case ANYSEE_HW_508S2
: /* 19 */
986 case ANYSEE_HW_508PS2
: /* 22 */
991 fe
= dvb_attach(stv6110_attach
, adap
->fe
[0],
992 &anysee_stv6110_config
, &d
->i2c_adap
);
995 /* attach LNB controller */
996 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0],
997 &d
->i2c_adap
, &anysee_isl6423_config
);
1002 case ANYSEE_HW_508T2C
: /* 20 */
1006 fe
= dvb_attach(tda18212_attach
, adap
->fe
[0], &d
->i2c_adap
,
1007 &anysee_tda18212_config2
);
1022 static int anysee_rc_query(struct dvb_usb_device
*d
)
1024 u8 buf
[] = {CMD_GET_IR_CODE
};
1028 /* Remote controller is basic NEC using address byte 0x08.
1029 Anysee device RC query returns only two bytes, status and code,
1030 address byte is dropped. Also it does not return any value for
1031 NEC RCs having address byte other than 0x08. Due to that, we
1032 cannot use that device as standard NEC receiver.
1033 It could be possible make hack which reads whole code directly
1034 from device memory... */
1036 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), ircode
, sizeof(ircode
));
1041 dev_dbg(&d
->udev
->dev
, "%s: key pressed %02x\n", __func__
,
1043 rc_keydown(d
->rc_dev
, 0x08 << 8 | ircode
[1], 0);
1049 static int anysee_get_rc_config(struct dvb_usb_device
*d
, struct dvb_usb_rc
*rc
)
1051 rc
->allowed_protos
= RC_BIT_NEC
;
1052 rc
->query
= anysee_rc_query
;
1053 rc
->interval
= 250; /* windows driver uses 500ms */
1058 static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1061 struct dvb_usb_device
*d
= ci
->data
;
1063 u8 buf
[] = {CMD_CI
, 0x02, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1};
1066 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1073 static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1076 struct dvb_usb_device
*d
= ci
->data
;
1078 u8 buf
[] = {CMD_CI
, 0x03, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1, val
};
1080 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1087 static int anysee_ci_read_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1090 struct dvb_usb_device
*d
= ci
->data
;
1092 u8 buf
[] = {CMD_CI
, 0x04, 0x40, addr
, 0x00, 1};
1095 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1102 static int anysee_ci_write_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1105 struct dvb_usb_device
*d
= ci
->data
;
1107 u8 buf
[] = {CMD_CI
, 0x05, 0x40, addr
, 0x00, 1, val
};
1109 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1116 static int anysee_ci_slot_reset(struct dvb_ca_en50221
*ci
, int slot
)
1118 struct dvb_usb_device
*d
= ci
->data
;
1120 struct anysee_state
*state
= d_to_priv(d
);
1122 state
->ci_cam_ready
= jiffies
+ msecs_to_jiffies(1000);
1124 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1130 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1137 static int anysee_ci_slot_shutdown(struct dvb_ca_en50221
*ci
, int slot
)
1139 struct dvb_usb_device
*d
= ci
->data
;
1142 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1148 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1155 static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221
*ci
, int slot
)
1157 struct dvb_usb_device
*d
= ci
->data
;
1160 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 1), 0x02);
1167 static int anysee_ci_poll_slot_status(struct dvb_ca_en50221
*ci
, int slot
,
1170 struct dvb_usb_device
*d
= ci
->data
;
1171 struct anysee_state
*state
= d_to_priv(d
);
1175 ret
= anysee_rd_reg_mask(d
, REG_IOC
, &tmp
, 0x40);
1180 ret
= DVB_CA_EN50221_POLL_CAM_PRESENT
;
1181 if (time_after(jiffies
, state
->ci_cam_ready
))
1182 ret
|= DVB_CA_EN50221_POLL_CAM_READY
;
1188 static int anysee_ci_init(struct dvb_usb_device
*d
)
1190 struct anysee_state
*state
= d_to_priv(d
);
1193 state
->ci
.owner
= THIS_MODULE
;
1194 state
->ci
.read_attribute_mem
= anysee_ci_read_attribute_mem
;
1195 state
->ci
.write_attribute_mem
= anysee_ci_write_attribute_mem
;
1196 state
->ci
.read_cam_control
= anysee_ci_read_cam_control
;
1197 state
->ci
.write_cam_control
= anysee_ci_write_cam_control
;
1198 state
->ci
.slot_reset
= anysee_ci_slot_reset
;
1199 state
->ci
.slot_shutdown
= anysee_ci_slot_shutdown
;
1200 state
->ci
.slot_ts_enable
= anysee_ci_slot_ts_enable
;
1201 state
->ci
.poll_slot_status
= anysee_ci_poll_slot_status
;
1204 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1208 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1212 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1216 ret
= dvb_ca_en50221_init(&d
->adapter
[0].dvb_adap
, &state
->ci
, 0, 1);
1220 state
->ci_attached
= true;
1225 static void anysee_ci_release(struct dvb_usb_device
*d
)
1227 struct anysee_state
*state
= d_to_priv(d
);
1230 if (state
->ci_attached
)
1231 dvb_ca_en50221_release(&state
->ci
);
1236 static int anysee_init(struct dvb_usb_device
*d
)
1238 struct anysee_state
*state
= d_to_priv(d
);
1241 /* There is one interface with two alternate settings.
1242 Alternate setting 0 is for bulk transfer.
1243 Alternate setting 1 is for isochronous transfer.
1244 We use bulk transfer (alternate setting 0). */
1245 ret
= usb_set_interface(d
->udev
, 0, 0);
1250 ret
= anysee_led_ctrl(d
, 0x01, 0x03);
1255 ret
= anysee_ir_ctrl(d
, 1);
1260 if (state
->has_ci
) {
1261 ret
= anysee_ci_init(d
);
1269 static void anysee_exit(struct dvb_usb_device
*d
)
1271 return anysee_ci_release(d
);
1274 /* DVB USB Driver stuff */
1275 static struct dvb_usb_device_properties anysee_props
= {
1276 .driver_name
= KBUILD_MODNAME
,
1277 .owner
= THIS_MODULE
,
1278 .adapter_nr
= adapter_nr
,
1279 .size_of_priv
= sizeof(struct anysee_state
),
1281 .generic_bulk_ctrl_endpoint
= 0x01,
1282 .generic_bulk_ctrl_endpoint_response
= 0x81,
1284 .i2c_algo
= &anysee_i2c_algo
,
1285 .read_config
= anysee_read_config
,
1286 .frontend_attach
= anysee_frontend_attach
,
1287 .tuner_attach
= anysee_tuner_attach
,
1288 .init
= anysee_init
,
1289 .get_rc_config
= anysee_get_rc_config
,
1290 .frontend_ctrl
= anysee_frontend_ctrl
,
1291 .streaming_ctrl
= anysee_streaming_ctrl
,
1292 .exit
= anysee_exit
,
1297 .stream
= DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
1302 static const struct usb_device_id anysee_id_table
[] = {
1303 { DVB_USB_DEVICE(USB_VID_CYPRESS
, USB_PID_ANYSEE
,
1304 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1305 { DVB_USB_DEVICE(USB_VID_AMT
, USB_PID_ANYSEE
,
1306 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1309 MODULE_DEVICE_TABLE(usb
, anysee_id_table
);
1311 static struct usb_driver anysee_usb_driver
= {
1312 .name
= KBUILD_MODNAME
,
1313 .id_table
= anysee_id_table
,
1314 .probe
= dvb_usbv2_probe
,
1315 .disconnect
= dvb_usbv2_disconnect
,
1316 .suspend
= dvb_usbv2_suspend
,
1317 .resume
= dvb_usbv2_resume
,
1318 .reset_resume
= dvb_usbv2_reset_resume
,
1323 module_usb_driver(anysee_usb_driver
);
1325 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1326 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1327 MODULE_LICENSE("GPL");