1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver
5 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
8 * - add smart card reader support for Conditional Access (CA)
10 * Card reader in Anysee is nothing more than ISO 7816 card reader.
11 * There is no hardware CAM in any Anysee device sold.
12 * In my understanding it should be implemented by making own module
13 * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
14 * module registers serial interface that can be used to communicate
15 * with any ISO 7816 smart card.
17 * Any help according to implement serial smart card reader support
25 #include "mt352_priv.h"
34 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
36 static int anysee_ctrl_msg(struct dvb_usb_device
*d
,
37 u8
*sbuf
, u8 slen
, u8
*rbuf
, u8 rlen
)
39 struct anysee_state
*state
= d_to_priv(d
);
42 mutex_lock(&d
->usb_mutex
);
44 memcpy(&state
->buf
[0], sbuf
, slen
);
45 state
->buf
[60] = state
->seq
++;
47 dev_dbg(&d
->udev
->dev
, "%s: >>> %*ph\n", __func__
, slen
, state
->buf
);
49 /* We need receive one message more after dvb_usb_generic_rw due
50 to weird transaction flow, which is 1 x send + 2 x receive. */
51 ret
= dvb_usbv2_generic_rw_locked(d
, state
->buf
, sizeof(state
->buf
),
52 state
->buf
, sizeof(state
->buf
));
56 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
57 * (EPIPE, Broken pipe). Function supports currently msleep() as a
58 * parameter but I would not like to use it, since according to
59 * Documentation/timers/timers-howto.rst it should not be used such
60 * short, under < 20ms, sleeps. Repeating failed message would be
61 * better choice as not to add unwanted delays...
62 * Fixing that correctly is one of those or both;
63 * 1) use repeat if possible
64 * 2) add suitable delay
67 /* get answer, retry few times if error returned */
68 for (i
= 0; i
< 3; i
++) {
69 /* receive 2nd answer */
70 ret
= usb_bulk_msg(d
->udev
, usb_rcvbulkpipe(d
->udev
,
71 d
->props
->generic_bulk_ctrl_endpoint
),
72 state
->buf
, sizeof(state
->buf
), &act_len
, 2000);
74 dev_dbg(&d
->udev
->dev
,
75 "%s: recv bulk message failed=%d\n",
78 dev_dbg(&d
->udev
->dev
, "%s: <<< %*ph\n", __func__
,
81 if (state
->buf
[63] != 0x4f)
82 dev_dbg(&d
->udev
->dev
,
83 "%s: cmd failed\n", __func__
);
89 /* all retries failed, it is fatal */
90 dev_err(&d
->udev
->dev
, "%s: recv bulk message failed=%d\n",
95 /* read request, copy returned data to return buf */
97 memcpy(rbuf
, state
->buf
, rlen
);
100 mutex_unlock(&d
->usb_mutex
);
104 static int anysee_read_reg(struct dvb_usb_device
*d
, u16 reg
, u8
*val
)
106 u8 buf
[] = {CMD_REG_READ
, reg
>> 8, reg
& 0xff, 0x01};
108 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), val
, 1);
109 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, *val
);
113 static int anysee_write_reg(struct dvb_usb_device
*d
, u16 reg
, u8 val
)
115 u8 buf
[] = {CMD_REG_WRITE
, reg
>> 8, reg
& 0xff, 0x01, val
};
116 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, val
);
117 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
120 /* write single register with mask */
121 static int anysee_wr_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8 val
,
127 /* no need for read if whole reg is written */
129 ret
= anysee_read_reg(d
, reg
, &tmp
);
138 return anysee_write_reg(d
, reg
, val
);
141 /* read single register with mask */
142 static int anysee_rd_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8
*val
,
148 ret
= anysee_read_reg(d
, reg
, &tmp
);
154 /* find position of the first bit */
155 for (i
= 0; i
< 8; i
++) {
156 if ((mask
>> i
) & 0x01)
164 static int anysee_get_hw_info(struct dvb_usb_device
*d
, u8
*id
)
166 u8 buf
[] = {CMD_GET_HW_INFO
};
167 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), id
, 3);
170 static int anysee_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
172 u8 buf
[] = {CMD_STREAMING_CTRL
, (u8
)onoff
, 0x00};
173 dev_dbg(&fe_to_d(fe
)->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
174 return anysee_ctrl_msg(fe_to_d(fe
), buf
, sizeof(buf
), NULL
, 0);
177 static int anysee_led_ctrl(struct dvb_usb_device
*d
, u8 mode
, u8 interval
)
179 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x01, mode
, interval
};
180 dev_dbg(&d
->udev
->dev
, "%s: state=%d interval=%d\n", __func__
,
182 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
185 static int anysee_ir_ctrl(struct dvb_usb_device
*d
, u8 onoff
)
187 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x02, onoff
};
188 dev_dbg(&d
->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
189 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
193 static int anysee_master_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msg
,
196 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
197 int ret
= 0, inc
, i
= 0;
198 u8 buf
[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
200 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
204 if (num
> i
+ 1 && (msg
[i
+1].flags
& I2C_M_RD
)) {
205 if (msg
[i
].len
> 2 || msg
[i
+1].len
> 60) {
209 buf
[0] = CMD_I2C_READ
;
210 buf
[1] = (msg
[i
].addr
<< 1) | 0x01;
211 buf
[2] = msg
[i
].buf
[0];
212 buf
[3] = msg
[i
].buf
[1];
213 buf
[4] = msg
[i
].len
-1;
214 buf
[5] = msg
[i
+1].len
;
215 ret
= anysee_ctrl_msg(d
, buf
, 6, msg
[i
+1].buf
,
219 if (msg
[i
].len
> 48) {
223 buf
[0] = CMD_I2C_WRITE
;
224 buf
[1] = (msg
[i
].addr
<< 1);
227 memcpy(&buf
[4], msg
[i
].buf
, msg
[i
].len
);
228 ret
= anysee_ctrl_msg(d
, buf
, 4 + msg
[i
].len
, NULL
, 0);
237 mutex_unlock(&d
->i2c_mutex
);
239 return ret
? ret
: i
;
242 static u32
anysee_i2c_func(struct i2c_adapter
*adapter
)
247 static struct i2c_algorithm anysee_i2c_algo
= {
248 .master_xfer
= anysee_master_xfer
,
249 .functionality
= anysee_i2c_func
,
252 static int anysee_mt352_demod_init(struct dvb_frontend
*fe
)
254 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x28 };
255 static u8 reset
[] = { RESET
, 0x80 };
256 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
257 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0x20 };
258 static u8 gpp_ctl_cfg
[] = { GPP_CTL
, 0x33 };
259 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x32 };
261 mt352_write(fe
, clock_config
, sizeof(clock_config
));
263 mt352_write(fe
, reset
, sizeof(reset
));
264 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
266 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
267 mt352_write(fe
, gpp_ctl_cfg
, sizeof(gpp_ctl_cfg
));
268 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
273 /* Callbacks for DVB USB */
274 static struct tda10023_config anysee_tda10023_config
= {
275 .demod_address
= (0x1a >> 1),
281 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_C
,
285 static struct mt352_config anysee_mt352_config
= {
286 .demod_address
= (0x1e >> 1),
287 .demod_init
= anysee_mt352_demod_init
,
290 static struct zl10353_config anysee_zl10353_config
= {
291 .demod_address
= (0x1e >> 1),
295 static struct zl10353_config anysee_zl10353_tda18212_config2
= {
296 .demod_address
= (0x1e >> 1),
298 .disable_i2c_gate_ctrl
= 1,
303 static struct zl10353_config anysee_zl10353_tda18212_config
= {
304 .demod_address
= (0x18 >> 1),
306 .disable_i2c_gate_ctrl
= 1,
311 static struct tda10023_config anysee_tda10023_tda18212_config
= {
312 .demod_address
= (0x1a >> 1),
317 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_B
,
321 static const struct tda18212_config anysee_tda18212_config
= {
328 static const struct tda18212_config anysee_tda18212_config2
= {
338 static struct cx24116_config anysee_cx24116_config
= {
339 .demod_address
= (0xaa >> 1),
340 .mpg_clk_pos_pol
= 0x00,
344 static struct stv0900_config anysee_stv0900_config
= {
345 .demod_address
= (0xd0 >> 1),
351 .tun1_adc
= 1, /* 1 Vpp */
355 static struct stv6110_config anysee_stv6110_config
= {
356 .i2c_address
= (0xc0 >> 1),
361 static struct isl6423_config anysee_isl6423_config
= {
362 .current_max
= SEC_CURRENT_800m
,
363 .curlim
= SEC_CURRENT_LIM_OFF
,
368 static struct cxd2820r_config anysee_cxd2820r_config
= {
369 .i2c_address
= 0x6d, /* (0xda >> 1) */
374 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
375 * Manufacturer: AMT.CO.KR
377 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
379 * parts: DNOS404ZH102A(MT352, DTT7579(?))
381 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
382 * PCB: PCB 507T (rev1.61)
383 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
384 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
385 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
387 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
388 * PCB: 507CD (rev1.1)
389 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
390 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
391 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
392 * IOD[0] ZL10353 1=enabled
393 * IOA[7] TS 0=enabled
394 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
396 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
397 * PCB: 507DC (rev0.2)
398 * parts: TDA10023, DTOS403IH102B TM, CST56I01
399 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
400 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
401 * IOD[0] TDA10023 1=enabled
403 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
404 * PCB: 507SI (rev2.1)
405 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
406 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
407 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
408 * IOD[0] CX24116 1=enabled
410 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
411 * PCB: 507FA (rev0.4)
412 * parts: TDA10023, DTOS403IH102B TM, TDA8024
413 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
414 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
415 * IOD[5] TDA10023 1=enabled
416 * IOE[0] tuner 1=enabled
418 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
419 * PCB: 507FA (rev1.1)
420 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
421 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
422 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
424 * IOD[5] TDA10023 1=enabled
425 * IOE[0] tuner 1=enabled
427 * IOD[0] ZL10353 1=enabled
428 * IOE[0] tuner 0=enabled
429 * tuner is behind ZL10353 I2C-gate
430 * tuner is behind TDA10023 I2C-gate
432 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
433 * PCB: 508TC (rev0.6)
434 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
435 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
436 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
437 * IOA[7] TS 1=enabled
438 * IOE[4] TDA18212 1=enabled
440 * IOD[6] ZL10353 0=disabled
441 * IOD[5] TDA10023 1=enabled
442 * IOE[0] IF 1=enabled
444 * IOD[5] TDA10023 0=disabled
445 * IOD[6] ZL10353 1=enabled
446 * IOE[0] IF 0=enabled
448 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
449 * PCB: 508S2 (rev0.7)
450 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
451 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
452 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
453 * IOA[7] TS 1=enabled
454 * IOE[5] STV0903 1=enabled
456 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
457 * PCB: 508T2C (rev0.3)
458 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
459 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
460 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
461 * IOA[7] TS 1=enabled
462 * IOE[5] CXD2820R 1=enabled
464 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
465 * PCB: 508PTC (rev0.5)
466 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
467 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
468 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
469 * IOA[7] TS 1=enabled
470 * IOE[4] TDA18212 1=enabled
472 * IOD[6] ZL10353 0=disabled
473 * IOD[5] TDA10023 1=enabled
474 * IOE[0] IF 1=enabled
476 * IOD[5] TDA10023 0=disabled
477 * IOD[6] ZL10353 1=enabled
478 * IOE[0] IF 0=enabled
480 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
481 * PCB: 508PS2 (rev0.4)
482 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
483 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
484 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
485 * IOA[7] TS 1=enabled
486 * IOE[5] STV0903 1=enabled
489 static int anysee_read_config(struct dvb_usb_device
*d
)
491 struct anysee_state
*state
= d_to_priv(d
);
496 * Check which hardware we have.
497 * We must do this call two times to get reliable values (hw/fw bug).
499 ret
= anysee_get_hw_info(d
, hw_info
);
503 ret
= anysee_get_hw_info(d
, hw_info
);
508 * Meaning of these info bytes are guessed.
510 dev_info(&d
->udev
->dev
, "%s: firmware version %d.%d hardware id %d\n",
511 KBUILD_MODNAME
, hw_info
[1], hw_info
[2], hw_info
[0]);
513 state
->hw
= hw_info
[0];
518 /* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
519 static int anysee_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
521 /* enable / disable tuner access on IOE[4] */
522 return anysee_wr_reg_mask(fe_to_d(fe
), REG_IOE
, (enable
<< 4), 0x10);
525 static int anysee_frontend_ctrl(struct dvb_frontend
*fe
, int onoff
)
527 struct anysee_state
*state
= fe_to_priv(fe
);
528 struct dvb_usb_device
*d
= fe_to_d(fe
);
530 dev_dbg(&d
->udev
->dev
, "%s: fe=%d onoff=%d\n", __func__
, fe
->id
, onoff
);
532 /* no frontend sleep control */
537 case ANYSEE_HW_507FA
: /* 15 */
542 /* disable DVB-T demod on IOD[0] */
543 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
547 /* enable DVB-C demod on IOD[5] */
548 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
552 /* enable DVB-C tuner on IOE[0] */
553 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
557 /* disable DVB-C demod on IOD[5] */
558 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
562 /* enable DVB-T demod on IOD[0] */
563 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
567 /* enable DVB-T tuner on IOE[0] */
568 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
574 case ANYSEE_HW_508TC
: /* 18 */
575 case ANYSEE_HW_508PTC
: /* 21 */
580 /* disable DVB-T demod on IOD[6] */
581 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
585 /* enable DVB-C demod on IOD[5] */
586 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
590 /* enable IF route on IOE[0] */
591 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
595 /* disable DVB-C demod on IOD[5] */
596 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
600 /* enable DVB-T demod on IOD[6] */
601 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
605 /* enable IF route on IOE[0] */
606 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
620 static int anysee_add_i2c_dev(struct dvb_usb_device
*d
, const char *type
,
621 u8 addr
, void *platform_data
)
624 struct anysee_state
*state
= d_to_priv(d
);
625 struct i2c_client
*client
;
626 struct i2c_adapter
*adapter
= &d
->i2c_adap
;
627 struct i2c_board_info board_info
= {
629 .platform_data
= platform_data
,
632 strscpy(board_info
.type
, type
, I2C_NAME_SIZE
);
634 /* find first free client */
635 for (num
= 0; num
< ANYSEE_I2C_CLIENT_MAX
; num
++) {
636 if (state
->i2c_client
[num
] == NULL
)
640 dev_dbg(&d
->udev
->dev
, "%s: num=%d\n", __func__
, num
);
642 if (num
== ANYSEE_I2C_CLIENT_MAX
) {
643 dev_err(&d
->udev
->dev
, "%s: I2C client out of index\n",
649 request_module("%s", board_info
.type
);
651 /* register I2C device */
652 client
= i2c_new_client_device(adapter
, &board_info
);
653 if (!i2c_client_has_driver(client
)) {
658 /* increase I2C driver usage count */
659 if (!try_module_get(client
->dev
.driver
->owner
)) {
660 i2c_unregister_device(client
);
665 state
->i2c_client
[num
] = client
;
668 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
672 static void anysee_del_i2c_dev(struct dvb_usb_device
*d
)
675 struct anysee_state
*state
= d_to_priv(d
);
676 struct i2c_client
*client
;
678 /* find last used client */
679 num
= ANYSEE_I2C_CLIENT_MAX
;
681 if (state
->i2c_client
[num
] != NULL
)
685 dev_dbg(&d
->udev
->dev
, "%s: num=%d\n", __func__
, num
);
688 dev_err(&d
->udev
->dev
, "%s: I2C client out of index\n",
693 client
= state
->i2c_client
[num
];
695 /* decrease I2C driver usage count */
696 module_put(client
->dev
.driver
->owner
);
698 /* unregister I2C device */
699 i2c_unregister_device(client
);
701 state
->i2c_client
[num
] = NULL
;
703 dev_dbg(&d
->udev
->dev
, "%s: failed\n", __func__
);
706 static int anysee_frontend_attach(struct dvb_usb_adapter
*adap
)
708 struct anysee_state
*state
= adap_to_priv(adap
);
709 struct dvb_usb_device
*d
= adap_to_d(adap
);
712 struct i2c_msg msg
[2] = {
727 case ANYSEE_HW_507T
: /* 2 */
731 adap
->fe
[0] = dvb_attach(mt352_attach
, &anysee_mt352_config
,
737 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
741 case ANYSEE_HW_507CD
: /* 6 */
744 /* enable DVB-T demod on IOD[0] */
745 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
749 /* enable transport stream on IOA[7] */
750 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
755 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
759 case ANYSEE_HW_507DC
: /* 10 */
762 /* enable DVB-C demod on IOD[0] */
763 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
768 adap
->fe
[0] = dvb_attach(tda10023_attach
,
769 &anysee_tda10023_config
, &d
->i2c_adap
, 0x48);
772 case ANYSEE_HW_507SI
: /* 11 */
775 /* enable DVB-S/S2 demod on IOD[0] */
776 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
781 adap
->fe
[0] = dvb_attach(cx24116_attach
, &anysee_cx24116_config
,
785 case ANYSEE_HW_507FA
: /* 15 */
789 /* enable tuner on IOE[4] */
790 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 4), 0x10);
796 ret
= i2c_transfer(&d
->i2c_adap
, msg
, 2);
797 if (ret
== 2 && tmp
== 0xc7) {
798 dev_dbg(&d
->udev
->dev
, "%s: TDA18212 found\n",
800 state
->has_tda18212
= true;
805 /* disable tuner on IOE[4] */
806 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 4), 0x10);
810 /* disable DVB-T demod on IOD[0] */
811 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
815 /* enable DVB-C demod on IOD[5] */
816 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
822 /* TDA18212 config */
823 adap
->fe
[0] = dvb_attach(tda10023_attach
,
824 &anysee_tda10023_tda18212_config
,
827 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
829 adap
->fe
[0]->ops
.i2c_gate_ctrl
=
830 anysee_i2c_gate_ctrl
;
833 adap
->fe
[0] = dvb_attach(tda10023_attach
,
834 &anysee_tda10023_config
,
838 /* break out if first frontend attaching fails */
842 /* disable DVB-C demod on IOD[5] */
843 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
847 /* enable DVB-T demod on IOD[0] */
848 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
854 /* TDA18212 config */
855 adap
->fe
[1] = dvb_attach(zl10353_attach
,
856 &anysee_zl10353_tda18212_config2
,
859 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
861 adap
->fe
[1]->ops
.i2c_gate_ctrl
=
862 anysee_i2c_gate_ctrl
;
865 adap
->fe
[1] = dvb_attach(zl10353_attach
,
866 &anysee_zl10353_config
,
871 case ANYSEE_HW_508TC
: /* 18 */
872 case ANYSEE_HW_508PTC
: /* 21 */
876 /* disable DVB-T demod on IOD[6] */
877 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
881 /* enable DVB-C demod on IOD[5] */
882 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
887 adap
->fe
[0] = dvb_attach(tda10023_attach
,
888 &anysee_tda10023_tda18212_config
,
891 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
893 adap
->fe
[0]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
895 /* break out if first frontend attaching fails */
899 /* disable DVB-C demod on IOD[5] */
900 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
904 /* enable DVB-T demod on IOD[6] */
905 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
910 adap
->fe
[1] = dvb_attach(zl10353_attach
,
911 &anysee_zl10353_tda18212_config
,
914 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
916 adap
->fe
[1]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
918 state
->has_ci
= true;
921 case ANYSEE_HW_508S2
: /* 19 */
922 case ANYSEE_HW_508PS2
: /* 22 */
926 /* enable DVB-S/S2 demod on IOE[5] */
927 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
932 adap
->fe
[0] = dvb_attach(stv0900_attach
,
933 &anysee_stv0900_config
, &d
->i2c_adap
, 0);
935 state
->has_ci
= true;
938 case ANYSEE_HW_508T2C
: /* 20 */
941 /* enable DVB-T/T2/C demod on IOE[5] */
942 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
947 adap
->fe
[0] = dvb_attach(cxd2820r_attach
,
948 &anysee_cxd2820r_config
, &d
->i2c_adap
, NULL
);
950 state
->has_ci
= true;
956 /* we have no frontend :-( */
958 dev_err(&d
->udev
->dev
,
959 "%s: Unsupported Anysee version. Please report to <linux-media@vger.kernel.org>.\n",
966 static int anysee_tuner_attach(struct dvb_usb_adapter
*adap
)
968 struct anysee_state
*state
= adap_to_priv(adap
);
969 struct dvb_usb_device
*d
= adap_to_d(adap
);
970 struct dvb_frontend
*fe
;
972 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
975 case ANYSEE_HW_507T
: /* 2 */
979 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1), NULL
,
980 DVB_PLL_THOMSON_DTT7579
);
983 case ANYSEE_HW_507CD
: /* 6 */
987 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1),
988 &d
->i2c_adap
, DVB_PLL_THOMSON_DTT7579
);
991 case ANYSEE_HW_507DC
: /* 10 */
995 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc0 >> 1),
996 &d
->i2c_adap
, DVB_PLL_SAMSUNG_DTOS403IH102A
);
999 case ANYSEE_HW_507SI
: /* 11 */
1002 /* attach LNB controller */
1003 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0], &d
->i2c_adap
,
1004 &anysee_isl6423_config
);
1007 case ANYSEE_HW_507FA
: /* 15 */
1008 /* E30 Combo Plus */
1011 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
1012 * fails attach old simple PLL. */
1015 if (state
->has_tda18212
) {
1016 struct tda18212_config tda18212_config
=
1017 anysee_tda18212_config
;
1019 tda18212_config
.fe
= adap
->fe
[0];
1020 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60,
1025 /* copy tuner ops for 2nd FE as tuner is shared */
1027 adap
->fe
[1]->tuner_priv
=
1028 adap
->fe
[0]->tuner_priv
;
1029 memcpy(&adap
->fe
[1]->ops
.tuner_ops
,
1030 &adap
->fe
[0]->ops
.tuner_ops
,
1031 sizeof(struct dvb_tuner_ops
));
1037 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0],
1038 (0xc0 >> 1), &d
->i2c_adap
,
1039 DVB_PLL_SAMSUNG_DTOS403IH102A
);
1041 if (fe
&& adap
->fe
[1]) {
1042 /* attach tuner for 2nd FE */
1043 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[1],
1044 (0xc0 >> 1), &d
->i2c_adap
,
1045 DVB_PLL_SAMSUNG_DTOS403IH102A
);
1050 case ANYSEE_HW_508TC
: /* 18 */
1051 case ANYSEE_HW_508PTC
: /* 21 */
1055 struct tda18212_config tda18212_config
= anysee_tda18212_config
;
1057 tda18212_config
.fe
= adap
->fe
[0];
1058 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60, &tda18212_config
);
1062 /* copy tuner ops for 2nd FE as tuner is shared */
1064 adap
->fe
[1]->tuner_priv
= adap
->fe
[0]->tuner_priv
;
1065 memcpy(&adap
->fe
[1]->ops
.tuner_ops
,
1066 &adap
->fe
[0]->ops
.tuner_ops
,
1067 sizeof(struct dvb_tuner_ops
));
1072 case ANYSEE_HW_508S2
: /* 19 */
1073 case ANYSEE_HW_508PS2
: /* 22 */
1078 fe
= dvb_attach(stv6110_attach
, adap
->fe
[0],
1079 &anysee_stv6110_config
, &d
->i2c_adap
);
1082 /* attach LNB controller */
1083 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0],
1084 &d
->i2c_adap
, &anysee_isl6423_config
);
1089 case ANYSEE_HW_508T2C
: /* 20 */
1092 struct tda18212_config tda18212_config
=
1093 anysee_tda18212_config2
;
1095 tda18212_config
.fe
= adap
->fe
[0];
1096 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60, &tda18212_config
);
1114 #if IS_ENABLED(CONFIG_RC_CORE)
1115 static int anysee_rc_query(struct dvb_usb_device
*d
)
1117 u8 buf
[] = {CMD_GET_IR_CODE
};
1121 /* Remote controller is basic NEC using address byte 0x08.
1122 Anysee device RC query returns only two bytes, status and code,
1123 address byte is dropped. Also it does not return any value for
1124 NEC RCs having address byte other than 0x08. Due to that, we
1125 cannot use that device as standard NEC receiver.
1126 It could be possible make hack which reads whole code directly
1127 from device memory... */
1129 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), ircode
, sizeof(ircode
));
1134 dev_dbg(&d
->udev
->dev
, "%s: key pressed %02x\n", __func__
,
1136 rc_keydown(d
->rc_dev
, RC_PROTO_NEC
,
1137 RC_SCANCODE_NEC(0x08, ircode
[1]), 0);
1143 static int anysee_get_rc_config(struct dvb_usb_device
*d
, struct dvb_usb_rc
*rc
)
1145 rc
->allowed_protos
= RC_PROTO_BIT_NEC
;
1146 rc
->query
= anysee_rc_query
;
1147 rc
->interval
= 250; /* windows driver uses 500ms */
1152 #define anysee_get_rc_config NULL
1155 static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1158 struct dvb_usb_device
*d
= ci
->data
;
1160 u8 buf
[] = {CMD_CI
, 0x02, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1};
1163 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1170 static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1173 struct dvb_usb_device
*d
= ci
->data
;
1175 u8 buf
[] = {CMD_CI
, 0x03, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1, val
};
1177 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1184 static int anysee_ci_read_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1187 struct dvb_usb_device
*d
= ci
->data
;
1189 u8 buf
[] = {CMD_CI
, 0x04, 0x40, addr
, 0x00, 1};
1192 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1199 static int anysee_ci_write_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1202 struct dvb_usb_device
*d
= ci
->data
;
1204 u8 buf
[] = {CMD_CI
, 0x05, 0x40, addr
, 0x00, 1, val
};
1206 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1213 static int anysee_ci_slot_reset(struct dvb_ca_en50221
*ci
, int slot
)
1215 struct dvb_usb_device
*d
= ci
->data
;
1217 struct anysee_state
*state
= d_to_priv(d
);
1219 state
->ci_cam_ready
= jiffies
+ msecs_to_jiffies(1000);
1221 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1227 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1234 static int anysee_ci_slot_shutdown(struct dvb_ca_en50221
*ci
, int slot
)
1236 struct dvb_usb_device
*d
= ci
->data
;
1239 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1245 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1252 static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221
*ci
, int slot
)
1254 struct dvb_usb_device
*d
= ci
->data
;
1257 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 1), 0x02);
1264 static int anysee_ci_poll_slot_status(struct dvb_ca_en50221
*ci
, int slot
,
1267 struct dvb_usb_device
*d
= ci
->data
;
1268 struct anysee_state
*state
= d_to_priv(d
);
1272 ret
= anysee_rd_reg_mask(d
, REG_IOC
, &tmp
, 0x40);
1277 ret
= DVB_CA_EN50221_POLL_CAM_PRESENT
;
1278 if (time_after(jiffies
, state
->ci_cam_ready
))
1279 ret
|= DVB_CA_EN50221_POLL_CAM_READY
;
1285 static int anysee_ci_init(struct dvb_usb_device
*d
)
1287 struct anysee_state
*state
= d_to_priv(d
);
1290 state
->ci
.owner
= THIS_MODULE
;
1291 state
->ci
.read_attribute_mem
= anysee_ci_read_attribute_mem
;
1292 state
->ci
.write_attribute_mem
= anysee_ci_write_attribute_mem
;
1293 state
->ci
.read_cam_control
= anysee_ci_read_cam_control
;
1294 state
->ci
.write_cam_control
= anysee_ci_write_cam_control
;
1295 state
->ci
.slot_reset
= anysee_ci_slot_reset
;
1296 state
->ci
.slot_shutdown
= anysee_ci_slot_shutdown
;
1297 state
->ci
.slot_ts_enable
= anysee_ci_slot_ts_enable
;
1298 state
->ci
.poll_slot_status
= anysee_ci_poll_slot_status
;
1301 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1305 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1309 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1313 ret
= dvb_ca_en50221_init(&d
->adapter
[0].dvb_adap
, &state
->ci
, 0, 1);
1317 state
->ci_attached
= true;
1322 static void anysee_ci_release(struct dvb_usb_device
*d
)
1324 struct anysee_state
*state
= d_to_priv(d
);
1327 if (state
->ci_attached
)
1328 dvb_ca_en50221_release(&state
->ci
);
1333 static int anysee_init(struct dvb_usb_device
*d
)
1335 struct anysee_state
*state
= d_to_priv(d
);
1338 /* There is one interface with two alternate settings.
1339 Alternate setting 0 is for bulk transfer.
1340 Alternate setting 1 is for isochronous transfer.
1341 We use bulk transfer (alternate setting 0). */
1342 ret
= usb_set_interface(d
->udev
, 0, 0);
1347 ret
= anysee_led_ctrl(d
, 0x01, 0x03);
1352 ret
= anysee_ir_ctrl(d
, 1);
1357 if (state
->has_ci
) {
1358 ret
= anysee_ci_init(d
);
1366 static void anysee_exit(struct dvb_usb_device
*d
)
1368 struct anysee_state
*state
= d_to_priv(d
);
1370 if (state
->i2c_client
[0])
1371 anysee_del_i2c_dev(d
);
1373 return anysee_ci_release(d
);
1376 /* DVB USB Driver stuff */
1377 static struct dvb_usb_device_properties anysee_props
= {
1378 .driver_name
= KBUILD_MODNAME
,
1379 .owner
= THIS_MODULE
,
1380 .adapter_nr
= adapter_nr
,
1381 .size_of_priv
= sizeof(struct anysee_state
),
1383 .generic_bulk_ctrl_endpoint
= 0x01,
1384 .generic_bulk_ctrl_endpoint_response
= 0x81,
1386 .i2c_algo
= &anysee_i2c_algo
,
1387 .read_config
= anysee_read_config
,
1388 .frontend_attach
= anysee_frontend_attach
,
1389 .tuner_attach
= anysee_tuner_attach
,
1390 .init
= anysee_init
,
1391 .get_rc_config
= anysee_get_rc_config
,
1392 .frontend_ctrl
= anysee_frontend_ctrl
,
1393 .streaming_ctrl
= anysee_streaming_ctrl
,
1394 .exit
= anysee_exit
,
1399 .stream
= DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
1404 static const struct usb_device_id anysee_id_table
[] = {
1405 { DVB_USB_DEVICE(USB_VID_CYPRESS
, USB_PID_ANYSEE
,
1406 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1407 { DVB_USB_DEVICE(USB_VID_AMT
, USB_PID_ANYSEE
,
1408 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1411 MODULE_DEVICE_TABLE(usb
, anysee_id_table
);
1413 static struct usb_driver anysee_usb_driver
= {
1414 .name
= KBUILD_MODNAME
,
1415 .id_table
= anysee_id_table
,
1416 .probe
= dvb_usbv2_probe
,
1417 .disconnect
= dvb_usbv2_disconnect
,
1418 .suspend
= dvb_usbv2_suspend
,
1419 .resume
= dvb_usbv2_resume
,
1420 .reset_resume
= dvb_usbv2_reset_resume
,
1425 module_usb_driver(anysee_usb_driver
);
1427 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1428 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1429 MODULE_LICENSE("GPL");