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.
17 * - add smart card reader support for Conditional Access (CA)
19 * Card reader in Anysee is nothing more than ISO 7816 card reader.
20 * There is no hardware CAM in any Anysee device sold.
21 * In my understanding it should be implemented by making own module
22 * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
23 * module registers serial interface that can be used to communicate
24 * with any ISO 7816 smart card.
26 * Any help according to implement serial smart card reader support
34 #include "mt352_priv.h"
43 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
45 static int anysee_ctrl_msg(struct dvb_usb_device
*d
,
46 u8
*sbuf
, u8 slen
, u8
*rbuf
, u8 rlen
)
48 struct anysee_state
*state
= d_to_priv(d
);
51 mutex_lock(&d
->usb_mutex
);
53 memcpy(&state
->buf
[0], sbuf
, slen
);
54 state
->buf
[60] = state
->seq
++;
56 dev_dbg(&d
->udev
->dev
, "%s: >>> %*ph\n", __func__
, slen
, state
->buf
);
58 /* We need receive one message more after dvb_usb_generic_rw due
59 to weird transaction flow, which is 1 x send + 2 x receive. */
60 ret
= dvb_usbv2_generic_rw_locked(d
, state
->buf
, sizeof(state
->buf
),
61 state
->buf
, sizeof(state
->buf
));
65 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
66 * (EPIPE, Broken pipe). Function supports currently msleep() as a
67 * parameter but I would not like to use it, since according to
68 * Documentation/timers/timers-howto.txt it should not be used such
69 * short, under < 20ms, sleeps. Repeating failed message would be
70 * better choice as not to add unwanted delays...
71 * Fixing that correctly is one of those or both;
72 * 1) use repeat if possible
73 * 2) add suitable delay
76 /* get answer, retry few times if error returned */
77 for (i
= 0; i
< 3; i
++) {
78 /* receive 2nd answer */
79 ret
= usb_bulk_msg(d
->udev
, usb_rcvbulkpipe(d
->udev
,
80 d
->props
->generic_bulk_ctrl_endpoint
),
81 state
->buf
, sizeof(state
->buf
), &act_len
, 2000);
83 dev_dbg(&d
->udev
->dev
,
84 "%s: recv bulk message failed=%d\n",
87 dev_dbg(&d
->udev
->dev
, "%s: <<< %*ph\n", __func__
,
90 if (state
->buf
[63] != 0x4f)
91 dev_dbg(&d
->udev
->dev
,
92 "%s: cmd failed\n", __func__
);
98 /* all retries failed, it is fatal */
99 dev_err(&d
->udev
->dev
, "%s: recv bulk message failed=%d\n",
100 KBUILD_MODNAME
, ret
);
104 /* read request, copy returned data to return buf */
106 memcpy(rbuf
, state
->buf
, rlen
);
109 mutex_unlock(&d
->usb_mutex
);
113 static int anysee_read_reg(struct dvb_usb_device
*d
, u16 reg
, u8
*val
)
115 u8 buf
[] = {CMD_REG_READ
, reg
>> 8, reg
& 0xff, 0x01};
117 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), val
, 1);
118 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, *val
);
122 static int anysee_write_reg(struct dvb_usb_device
*d
, u16 reg
, u8 val
)
124 u8 buf
[] = {CMD_REG_WRITE
, reg
>> 8, reg
& 0xff, 0x01, val
};
125 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, val
);
126 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
129 /* write single register with mask */
130 static int anysee_wr_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8 val
,
136 /* no need for read if whole reg is written */
138 ret
= anysee_read_reg(d
, reg
, &tmp
);
147 return anysee_write_reg(d
, reg
, val
);
150 /* read single register with mask */
151 static int anysee_rd_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8
*val
,
157 ret
= anysee_read_reg(d
, reg
, &tmp
);
163 /* find position of the first bit */
164 for (i
= 0; i
< 8; i
++) {
165 if ((mask
>> i
) & 0x01)
173 static int anysee_get_hw_info(struct dvb_usb_device
*d
, u8
*id
)
175 u8 buf
[] = {CMD_GET_HW_INFO
};
176 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), id
, 3);
179 static int anysee_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
181 u8 buf
[] = {CMD_STREAMING_CTRL
, (u8
)onoff
, 0x00};
182 dev_dbg(&fe_to_d(fe
)->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
183 return anysee_ctrl_msg(fe_to_d(fe
), buf
, sizeof(buf
), NULL
, 0);
186 static int anysee_led_ctrl(struct dvb_usb_device
*d
, u8 mode
, u8 interval
)
188 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x01, mode
, interval
};
189 dev_dbg(&d
->udev
->dev
, "%s: state=%d interval=%d\n", __func__
,
191 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
194 static int anysee_ir_ctrl(struct dvb_usb_device
*d
, u8 onoff
)
196 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x02, onoff
};
197 dev_dbg(&d
->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
198 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
202 static int anysee_master_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msg
,
205 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
206 int ret
= 0, inc
, i
= 0;
207 u8 buf
[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
209 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
213 if (num
> i
+ 1 && (msg
[i
+1].flags
& I2C_M_RD
)) {
214 if (msg
[i
].len
> 2 || msg
[i
+1].len
> 60) {
218 buf
[0] = CMD_I2C_READ
;
219 buf
[1] = (msg
[i
].addr
<< 1) | 0x01;
220 buf
[2] = msg
[i
].buf
[0];
221 buf
[3] = msg
[i
].buf
[1];
222 buf
[4] = msg
[i
].len
-1;
223 buf
[5] = msg
[i
+1].len
;
224 ret
= anysee_ctrl_msg(d
, buf
, 6, msg
[i
+1].buf
,
228 if (msg
[i
].len
> 48) {
232 buf
[0] = CMD_I2C_WRITE
;
233 buf
[1] = (msg
[i
].addr
<< 1);
236 memcpy(&buf
[4], msg
[i
].buf
, msg
[i
].len
);
237 ret
= anysee_ctrl_msg(d
, buf
, 4 + msg
[i
].len
, NULL
, 0);
246 mutex_unlock(&d
->i2c_mutex
);
248 return ret
? ret
: i
;
251 static u32
anysee_i2c_func(struct i2c_adapter
*adapter
)
256 static struct i2c_algorithm anysee_i2c_algo
= {
257 .master_xfer
= anysee_master_xfer
,
258 .functionality
= anysee_i2c_func
,
261 static int anysee_mt352_demod_init(struct dvb_frontend
*fe
)
263 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x28 };
264 static u8 reset
[] = { RESET
, 0x80 };
265 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
266 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0x20 };
267 static u8 gpp_ctl_cfg
[] = { GPP_CTL
, 0x33 };
268 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x32 };
270 mt352_write(fe
, clock_config
, sizeof(clock_config
));
272 mt352_write(fe
, reset
, sizeof(reset
));
273 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
275 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
276 mt352_write(fe
, gpp_ctl_cfg
, sizeof(gpp_ctl_cfg
));
277 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
282 /* Callbacks for DVB USB */
283 static struct tda10023_config anysee_tda10023_config
= {
284 .demod_address
= (0x1a >> 1),
290 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_C
,
294 static struct mt352_config anysee_mt352_config
= {
295 .demod_address
= (0x1e >> 1),
296 .demod_init
= anysee_mt352_demod_init
,
299 static struct zl10353_config anysee_zl10353_config
= {
300 .demod_address
= (0x1e >> 1),
304 static struct zl10353_config anysee_zl10353_tda18212_config2
= {
305 .demod_address
= (0x1e >> 1),
307 .disable_i2c_gate_ctrl
= 1,
312 static struct zl10353_config anysee_zl10353_tda18212_config
= {
313 .demod_address
= (0x18 >> 1),
315 .disable_i2c_gate_ctrl
= 1,
320 static struct tda10023_config anysee_tda10023_tda18212_config
= {
321 .demod_address
= (0x1a >> 1),
326 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_B
,
330 static struct tda18212_config anysee_tda18212_config
= {
337 static struct tda18212_config anysee_tda18212_config2
= {
347 static struct cx24116_config anysee_cx24116_config
= {
348 .demod_address
= (0xaa >> 1),
349 .mpg_clk_pos_pol
= 0x00,
353 static struct stv0900_config anysee_stv0900_config
= {
354 .demod_address
= (0xd0 >> 1),
360 .tun1_adc
= 1, /* 1 Vpp */
364 static struct stv6110_config anysee_stv6110_config
= {
365 .i2c_address
= (0xc0 >> 1),
370 static struct isl6423_config anysee_isl6423_config
= {
371 .current_max
= SEC_CURRENT_800m
,
372 .curlim
= SEC_CURRENT_LIM_OFF
,
377 static struct cxd2820r_config anysee_cxd2820r_config
= {
378 .i2c_address
= 0x6d, /* (0xda >> 1) */
383 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
384 * Manufacturer: AMT.CO.KR
386 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
388 * parts: DNOS404ZH102A(MT352, DTT7579(?))
390 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
391 * PCB: PCB 507T (rev1.61)
392 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
393 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
394 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
396 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
397 * PCB: 507CD (rev1.1)
398 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
399 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
400 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
401 * IOD[0] ZL10353 1=enabled
402 * IOA[7] TS 0=enabled
403 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
405 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
406 * PCB: 507DC (rev0.2)
407 * parts: TDA10023, DTOS403IH102B TM, CST56I01
408 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
409 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
410 * IOD[0] TDA10023 1=enabled
412 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
413 * PCB: 507SI (rev2.1)
414 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
415 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
416 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
417 * IOD[0] CX24116 1=enabled
419 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
420 * PCB: 507FA (rev0.4)
421 * parts: TDA10023, DTOS403IH102B TM, TDA8024
422 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
423 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
424 * IOD[5] TDA10023 1=enabled
425 * IOE[0] tuner 1=enabled
427 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
428 * PCB: 507FA (rev1.1)
429 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
430 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
431 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
433 * IOD[5] TDA10023 1=enabled
434 * IOE[0] tuner 1=enabled
436 * IOD[0] ZL10353 1=enabled
437 * IOE[0] tuner 0=enabled
438 * tuner is behind ZL10353 I2C-gate
439 * tuner is behind TDA10023 I2C-gate
441 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
442 * PCB: 508TC (rev0.6)
443 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
444 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
445 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
446 * IOA[7] TS 1=enabled
447 * IOE[4] TDA18212 1=enabled
449 * IOD[6] ZL10353 0=disabled
450 * IOD[5] TDA10023 1=enabled
451 * IOE[0] IF 1=enabled
453 * IOD[5] TDA10023 0=disabled
454 * IOD[6] ZL10353 1=enabled
455 * IOE[0] IF 0=enabled
457 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
458 * PCB: 508S2 (rev0.7)
459 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
460 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
461 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
462 * IOA[7] TS 1=enabled
463 * IOE[5] STV0903 1=enabled
465 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
466 * PCB: 508T2C (rev0.3)
467 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
468 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
469 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
470 * IOA[7] TS 1=enabled
471 * IOE[5] CXD2820R 1=enabled
473 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
474 * PCB: 508PTC (rev0.5)
475 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
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[4] TDA18212 1=enabled
481 * IOD[6] ZL10353 0=disabled
482 * IOD[5] TDA10023 1=enabled
483 * IOE[0] IF 1=enabled
485 * IOD[5] TDA10023 0=disabled
486 * IOD[6] ZL10353 1=enabled
487 * IOE[0] IF 0=enabled
489 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
490 * PCB: 508PS2 (rev0.4)
491 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
492 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
493 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
494 * IOA[7] TS 1=enabled
495 * IOE[5] STV0903 1=enabled
498 static int anysee_read_config(struct dvb_usb_device
*d
)
500 struct anysee_state
*state
= d_to_priv(d
);
505 * Check which hardware we have.
506 * We must do this call two times to get reliable values (hw/fw bug).
508 ret
= anysee_get_hw_info(d
, hw_info
);
512 ret
= anysee_get_hw_info(d
, hw_info
);
517 * Meaning of these info bytes are guessed.
519 dev_info(&d
->udev
->dev
, "%s: firmware version %d.%d hardware id %d\n",
520 KBUILD_MODNAME
, hw_info
[1], hw_info
[2], hw_info
[0]);
522 state
->hw
= hw_info
[0];
527 /* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
528 static int anysee_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
530 /* enable / disable tuner access on IOE[4] */
531 return anysee_wr_reg_mask(fe_to_d(fe
), REG_IOE
, (enable
<< 4), 0x10);
534 static int anysee_frontend_ctrl(struct dvb_frontend
*fe
, int onoff
)
536 struct anysee_state
*state
= fe_to_priv(fe
);
537 struct dvb_usb_device
*d
= fe_to_d(fe
);
539 dev_dbg(&d
->udev
->dev
, "%s: fe=%d onoff=%d\n", __func__
, fe
->id
, onoff
);
541 /* no frontend sleep control */
546 case ANYSEE_HW_507FA
: /* 15 */
551 /* disable DVB-T demod on IOD[0] */
552 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
556 /* enable DVB-C demod on IOD[5] */
557 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
561 /* enable DVB-C tuner on IOE[0] */
562 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
566 /* disable DVB-C demod on IOD[5] */
567 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
571 /* enable DVB-T demod on IOD[0] */
572 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
576 /* enable DVB-T tuner on IOE[0] */
577 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
583 case ANYSEE_HW_508TC
: /* 18 */
584 case ANYSEE_HW_508PTC
: /* 21 */
589 /* disable DVB-T demod on IOD[6] */
590 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
594 /* enable DVB-C demod on IOD[5] */
595 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
599 /* enable IF route on IOE[0] */
600 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
604 /* disable DVB-C demod on IOD[5] */
605 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
609 /* enable DVB-T demod on IOD[6] */
610 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
614 /* enable IF route on IOE[0] */
615 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
629 static int anysee_add_i2c_dev(struct dvb_usb_device
*d
, const char *type
,
630 u8 addr
, void *platform_data
)
633 struct anysee_state
*state
= d_to_priv(d
);
634 struct i2c_client
*client
;
635 struct i2c_adapter
*adapter
= &d
->i2c_adap
;
636 struct i2c_board_info board_info
= {
638 .platform_data
= platform_data
,
641 strlcpy(board_info
.type
, type
, I2C_NAME_SIZE
);
643 /* find first free client */
644 for (num
= 0; num
< ANYSEE_I2C_CLIENT_MAX
; num
++) {
645 if (state
->i2c_client
[num
] == NULL
)
649 dev_dbg(&d
->udev
->dev
, "%s: num=%d\n", __func__
, num
);
651 if (num
== ANYSEE_I2C_CLIENT_MAX
) {
652 dev_err(&d
->udev
->dev
, "%s: I2C client out of index\n",
658 request_module("%s", board_info
.type
);
660 /* register I2C device */
661 client
= i2c_new_device(adapter
, &board_info
);
662 if (client
== NULL
|| client
->dev
.driver
== NULL
) {
667 /* increase I2C driver usage count */
668 if (!try_module_get(client
->dev
.driver
->owner
)) {
669 i2c_unregister_device(client
);
674 state
->i2c_client
[num
] = client
;
677 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
681 static void anysee_del_i2c_dev(struct dvb_usb_device
*d
)
684 struct anysee_state
*state
= d_to_priv(d
);
685 struct i2c_client
*client
;
687 /* find last used client */
688 num
= ANYSEE_I2C_CLIENT_MAX
;
690 if (state
->i2c_client
[num
] != NULL
)
694 dev_dbg(&d
->udev
->dev
, "%s: num=%d\n", __func__
, num
);
697 dev_err(&d
->udev
->dev
, "%s: I2C client out of index\n",
702 client
= state
->i2c_client
[num
];
704 /* decrease I2C driver usage count */
705 module_put(client
->dev
.driver
->owner
);
707 /* unregister I2C device */
708 i2c_unregister_device(client
);
710 state
->i2c_client
[num
] = NULL
;
712 dev_dbg(&d
->udev
->dev
, "%s: failed\n", __func__
);
715 static int anysee_frontend_attach(struct dvb_usb_adapter
*adap
)
717 struct anysee_state
*state
= adap_to_priv(adap
);
718 struct dvb_usb_device
*d
= adap_to_d(adap
);
721 struct i2c_msg msg
[2] = {
736 case ANYSEE_HW_507T
: /* 2 */
740 adap
->fe
[0] = dvb_attach(mt352_attach
, &anysee_mt352_config
,
746 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
750 case ANYSEE_HW_507CD
: /* 6 */
753 /* enable DVB-T demod on IOD[0] */
754 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
758 /* enable transport stream on IOA[7] */
759 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
764 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
768 case ANYSEE_HW_507DC
: /* 10 */
771 /* enable DVB-C demod on IOD[0] */
772 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
777 adap
->fe
[0] = dvb_attach(tda10023_attach
,
778 &anysee_tda10023_config
, &d
->i2c_adap
, 0x48);
781 case ANYSEE_HW_507SI
: /* 11 */
784 /* enable DVB-S/S2 demod on IOD[0] */
785 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
790 adap
->fe
[0] = dvb_attach(cx24116_attach
, &anysee_cx24116_config
,
794 case ANYSEE_HW_507FA
: /* 15 */
798 /* enable tuner on IOE[4] */
799 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 4), 0x10);
805 ret
= i2c_transfer(&d
->i2c_adap
, msg
, 2);
806 if (ret
== 2 && tmp
== 0xc7) {
807 dev_dbg(&d
->udev
->dev
, "%s: TDA18212 found\n",
809 state
->has_tda18212
= true;
814 /* disable tuner on IOE[4] */
815 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 4), 0x10);
819 /* disable DVB-T demod on IOD[0] */
820 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
824 /* enable DVB-C demod on IOD[5] */
825 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
831 /* TDA18212 config */
832 adap
->fe
[0] = dvb_attach(tda10023_attach
,
833 &anysee_tda10023_tda18212_config
,
836 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
838 adap
->fe
[0]->ops
.i2c_gate_ctrl
=
839 anysee_i2c_gate_ctrl
;
842 adap
->fe
[0] = dvb_attach(tda10023_attach
,
843 &anysee_tda10023_config
,
847 /* break out if first frontend attaching fails */
851 /* disable DVB-C demod on IOD[5] */
852 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
856 /* enable DVB-T demod on IOD[0] */
857 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
863 /* TDA18212 config */
864 adap
->fe
[1] = dvb_attach(zl10353_attach
,
865 &anysee_zl10353_tda18212_config2
,
868 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
870 adap
->fe
[1]->ops
.i2c_gate_ctrl
=
871 anysee_i2c_gate_ctrl
;
874 adap
->fe
[1] = dvb_attach(zl10353_attach
,
875 &anysee_zl10353_config
,
880 case ANYSEE_HW_508TC
: /* 18 */
881 case ANYSEE_HW_508PTC
: /* 21 */
885 /* disable DVB-T demod on IOD[6] */
886 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
890 /* enable DVB-C demod on IOD[5] */
891 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
896 adap
->fe
[0] = dvb_attach(tda10023_attach
,
897 &anysee_tda10023_tda18212_config
,
900 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
902 adap
->fe
[0]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
904 /* break out if first frontend attaching fails */
908 /* disable DVB-C demod on IOD[5] */
909 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
913 /* enable DVB-T demod on IOD[6] */
914 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
919 adap
->fe
[1] = dvb_attach(zl10353_attach
,
920 &anysee_zl10353_tda18212_config
,
923 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
925 adap
->fe
[1]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
927 state
->has_ci
= true;
930 case ANYSEE_HW_508S2
: /* 19 */
931 case ANYSEE_HW_508PS2
: /* 22 */
935 /* enable DVB-S/S2 demod on IOE[5] */
936 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
941 adap
->fe
[0] = dvb_attach(stv0900_attach
,
942 &anysee_stv0900_config
, &d
->i2c_adap
, 0);
944 state
->has_ci
= true;
947 case ANYSEE_HW_508T2C
: /* 20 */
950 /* enable DVB-T/T2/C demod on IOE[5] */
951 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
956 adap
->fe
[0] = dvb_attach(cxd2820r_attach
,
957 &anysee_cxd2820r_config
, &d
->i2c_adap
, NULL
);
959 state
->has_ci
= true;
965 /* we have no frontend :-( */
967 dev_err(&d
->udev
->dev
,
968 "%s: Unsupported Anysee version. Please report to <linux-media@vger.kernel.org>.\n",
975 static int anysee_tuner_attach(struct dvb_usb_adapter
*adap
)
977 struct anysee_state
*state
= adap_to_priv(adap
);
978 struct dvb_usb_device
*d
= adap_to_d(adap
);
979 struct dvb_frontend
*fe
;
981 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
984 case ANYSEE_HW_507T
: /* 2 */
988 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1), NULL
,
989 DVB_PLL_THOMSON_DTT7579
);
992 case ANYSEE_HW_507CD
: /* 6 */
996 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1),
997 &d
->i2c_adap
, DVB_PLL_THOMSON_DTT7579
);
1000 case ANYSEE_HW_507DC
: /* 10 */
1004 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc0 >> 1),
1005 &d
->i2c_adap
, DVB_PLL_SAMSUNG_DTOS403IH102A
);
1008 case ANYSEE_HW_507SI
: /* 11 */
1011 /* attach LNB controller */
1012 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0], &d
->i2c_adap
,
1013 &anysee_isl6423_config
);
1016 case ANYSEE_HW_507FA
: /* 15 */
1017 /* E30 Combo Plus */
1020 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
1021 * fails attach old simple PLL. */
1024 if (state
->has_tda18212
) {
1025 struct tda18212_config tda18212_config
=
1026 anysee_tda18212_config
;
1028 tda18212_config
.fe
= adap
->fe
[0];
1029 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60,
1034 /* copy tuner ops for 2nd FE as tuner is shared */
1036 adap
->fe
[1]->tuner_priv
=
1037 adap
->fe
[0]->tuner_priv
;
1038 memcpy(&adap
->fe
[1]->ops
.tuner_ops
,
1039 &adap
->fe
[0]->ops
.tuner_ops
,
1040 sizeof(struct dvb_tuner_ops
));
1046 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0],
1047 (0xc0 >> 1), &d
->i2c_adap
,
1048 DVB_PLL_SAMSUNG_DTOS403IH102A
);
1050 if (fe
&& adap
->fe
[1]) {
1051 /* attach tuner for 2nd FE */
1052 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[1],
1053 (0xc0 >> 1), &d
->i2c_adap
,
1054 DVB_PLL_SAMSUNG_DTOS403IH102A
);
1059 case ANYSEE_HW_508TC
: /* 18 */
1060 case ANYSEE_HW_508PTC
: /* 21 */
1064 struct tda18212_config tda18212_config
= anysee_tda18212_config
;
1066 tda18212_config
.fe
= adap
->fe
[0];
1067 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60, &tda18212_config
);
1071 /* copy tuner ops for 2nd FE as tuner is shared */
1073 adap
->fe
[1]->tuner_priv
= adap
->fe
[0]->tuner_priv
;
1074 memcpy(&adap
->fe
[1]->ops
.tuner_ops
,
1075 &adap
->fe
[0]->ops
.tuner_ops
,
1076 sizeof(struct dvb_tuner_ops
));
1081 case ANYSEE_HW_508S2
: /* 19 */
1082 case ANYSEE_HW_508PS2
: /* 22 */
1087 fe
= dvb_attach(stv6110_attach
, adap
->fe
[0],
1088 &anysee_stv6110_config
, &d
->i2c_adap
);
1091 /* attach LNB controller */
1092 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0],
1093 &d
->i2c_adap
, &anysee_isl6423_config
);
1098 case ANYSEE_HW_508T2C
: /* 20 */
1101 struct tda18212_config tda18212_config
=
1102 anysee_tda18212_config2
;
1104 tda18212_config
.fe
= adap
->fe
[0];
1105 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60, &tda18212_config
);
1123 #if IS_ENABLED(CONFIG_RC_CORE)
1124 static int anysee_rc_query(struct dvb_usb_device
*d
)
1126 u8 buf
[] = {CMD_GET_IR_CODE
};
1130 /* Remote controller is basic NEC using address byte 0x08.
1131 Anysee device RC query returns only two bytes, status and code,
1132 address byte is dropped. Also it does not return any value for
1133 NEC RCs having address byte other than 0x08. Due to that, we
1134 cannot use that device as standard NEC receiver.
1135 It could be possible make hack which reads whole code directly
1136 from device memory... */
1138 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), ircode
, sizeof(ircode
));
1143 dev_dbg(&d
->udev
->dev
, "%s: key pressed %02x\n", __func__
,
1145 rc_keydown(d
->rc_dev
, RC_PROTO_NEC
,
1146 RC_SCANCODE_NEC(0x08, ircode
[1]), 0);
1152 static int anysee_get_rc_config(struct dvb_usb_device
*d
, struct dvb_usb_rc
*rc
)
1154 rc
->allowed_protos
= RC_PROTO_BIT_NEC
;
1155 rc
->query
= anysee_rc_query
;
1156 rc
->interval
= 250; /* windows driver uses 500ms */
1161 #define anysee_get_rc_config NULL
1164 static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1167 struct dvb_usb_device
*d
= ci
->data
;
1169 u8 buf
[] = {CMD_CI
, 0x02, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1};
1172 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1179 static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1182 struct dvb_usb_device
*d
= ci
->data
;
1184 u8 buf
[] = {CMD_CI
, 0x03, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1, val
};
1186 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1193 static int anysee_ci_read_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1196 struct dvb_usb_device
*d
= ci
->data
;
1198 u8 buf
[] = {CMD_CI
, 0x04, 0x40, addr
, 0x00, 1};
1201 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1208 static int anysee_ci_write_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1211 struct dvb_usb_device
*d
= ci
->data
;
1213 u8 buf
[] = {CMD_CI
, 0x05, 0x40, addr
, 0x00, 1, val
};
1215 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1222 static int anysee_ci_slot_reset(struct dvb_ca_en50221
*ci
, int slot
)
1224 struct dvb_usb_device
*d
= ci
->data
;
1226 struct anysee_state
*state
= d_to_priv(d
);
1228 state
->ci_cam_ready
= jiffies
+ msecs_to_jiffies(1000);
1230 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1236 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1243 static int anysee_ci_slot_shutdown(struct dvb_ca_en50221
*ci
, int slot
)
1245 struct dvb_usb_device
*d
= ci
->data
;
1248 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1254 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1261 static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221
*ci
, int slot
)
1263 struct dvb_usb_device
*d
= ci
->data
;
1266 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 1), 0x02);
1273 static int anysee_ci_poll_slot_status(struct dvb_ca_en50221
*ci
, int slot
,
1276 struct dvb_usb_device
*d
= ci
->data
;
1277 struct anysee_state
*state
= d_to_priv(d
);
1281 ret
= anysee_rd_reg_mask(d
, REG_IOC
, &tmp
, 0x40);
1286 ret
= DVB_CA_EN50221_POLL_CAM_PRESENT
;
1287 if (time_after(jiffies
, state
->ci_cam_ready
))
1288 ret
|= DVB_CA_EN50221_POLL_CAM_READY
;
1294 static int anysee_ci_init(struct dvb_usb_device
*d
)
1296 struct anysee_state
*state
= d_to_priv(d
);
1299 state
->ci
.owner
= THIS_MODULE
;
1300 state
->ci
.read_attribute_mem
= anysee_ci_read_attribute_mem
;
1301 state
->ci
.write_attribute_mem
= anysee_ci_write_attribute_mem
;
1302 state
->ci
.read_cam_control
= anysee_ci_read_cam_control
;
1303 state
->ci
.write_cam_control
= anysee_ci_write_cam_control
;
1304 state
->ci
.slot_reset
= anysee_ci_slot_reset
;
1305 state
->ci
.slot_shutdown
= anysee_ci_slot_shutdown
;
1306 state
->ci
.slot_ts_enable
= anysee_ci_slot_ts_enable
;
1307 state
->ci
.poll_slot_status
= anysee_ci_poll_slot_status
;
1310 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1314 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1318 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1322 ret
= dvb_ca_en50221_init(&d
->adapter
[0].dvb_adap
, &state
->ci
, 0, 1);
1326 state
->ci_attached
= true;
1331 static void anysee_ci_release(struct dvb_usb_device
*d
)
1333 struct anysee_state
*state
= d_to_priv(d
);
1336 if (state
->ci_attached
)
1337 dvb_ca_en50221_release(&state
->ci
);
1342 static int anysee_init(struct dvb_usb_device
*d
)
1344 struct anysee_state
*state
= d_to_priv(d
);
1347 /* There is one interface with two alternate settings.
1348 Alternate setting 0 is for bulk transfer.
1349 Alternate setting 1 is for isochronous transfer.
1350 We use bulk transfer (alternate setting 0). */
1351 ret
= usb_set_interface(d
->udev
, 0, 0);
1356 ret
= anysee_led_ctrl(d
, 0x01, 0x03);
1361 ret
= anysee_ir_ctrl(d
, 1);
1366 if (state
->has_ci
) {
1367 ret
= anysee_ci_init(d
);
1375 static void anysee_exit(struct dvb_usb_device
*d
)
1377 struct anysee_state
*state
= d_to_priv(d
);
1379 if (state
->i2c_client
[0])
1380 anysee_del_i2c_dev(d
);
1382 return anysee_ci_release(d
);
1385 /* DVB USB Driver stuff */
1386 static struct dvb_usb_device_properties anysee_props
= {
1387 .driver_name
= KBUILD_MODNAME
,
1388 .owner
= THIS_MODULE
,
1389 .adapter_nr
= adapter_nr
,
1390 .size_of_priv
= sizeof(struct anysee_state
),
1392 .generic_bulk_ctrl_endpoint
= 0x01,
1393 .generic_bulk_ctrl_endpoint_response
= 0x81,
1395 .i2c_algo
= &anysee_i2c_algo
,
1396 .read_config
= anysee_read_config
,
1397 .frontend_attach
= anysee_frontend_attach
,
1398 .tuner_attach
= anysee_tuner_attach
,
1399 .init
= anysee_init
,
1400 .get_rc_config
= anysee_get_rc_config
,
1401 .frontend_ctrl
= anysee_frontend_ctrl
,
1402 .streaming_ctrl
= anysee_streaming_ctrl
,
1403 .exit
= anysee_exit
,
1408 .stream
= DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
1413 static const struct usb_device_id anysee_id_table
[] = {
1414 { DVB_USB_DEVICE(USB_VID_CYPRESS
, USB_PID_ANYSEE
,
1415 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1416 { DVB_USB_DEVICE(USB_VID_AMT
, USB_PID_ANYSEE
,
1417 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1420 MODULE_DEVICE_TABLE(usb
, anysee_id_table
);
1422 static struct usb_driver anysee_usb_driver
= {
1423 .name
= KBUILD_MODNAME
,
1424 .id_table
= anysee_id_table
,
1425 .probe
= dvb_usbv2_probe
,
1426 .disconnect
= dvb_usbv2_disconnect
,
1427 .suspend
= dvb_usbv2_suspend
,
1428 .resume
= dvb_usbv2_resume
,
1429 .reset_resume
= dvb_usbv2_reset_resume
,
1434 module_usb_driver(anysee_usb_driver
);
1436 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1437 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1438 MODULE_LICENSE("GPL");