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
);
50 * We need receive one message more after dvb_usbv2_generic_rw_locked()
51 * due to weird transaction flow, which is 1 x send + 2 x receive.
53 ret
= dvb_usbv2_generic_rw_locked(d
, state
->buf
, sizeof(state
->buf
),
54 state
->buf
, sizeof(state
->buf
));
58 /* get answer, retry few times if error returned */
59 for (i
= 0; i
< 3; i
++) {
60 /* receive 2nd answer */
61 ret
= usb_bulk_msg(d
->udev
, usb_rcvbulkpipe(d
->udev
,
62 d
->props
->generic_bulk_ctrl_endpoint
),
63 state
->buf
, sizeof(state
->buf
), &act_len
, 2000);
65 dev_dbg(&d
->udev
->dev
,
66 "%s: recv bulk message failed=%d\n",
69 dev_dbg(&d
->udev
->dev
, "%s: <<< %*ph\n", __func__
,
72 if (state
->buf
[63] != 0x4f)
73 dev_dbg(&d
->udev
->dev
,
74 "%s: cmd failed\n", __func__
);
80 /* all retries failed, it is fatal */
81 dev_err(&d
->udev
->dev
, "%s: recv bulk message failed=%d\n",
86 /* read request, copy returned data to return buf */
88 memcpy(rbuf
, state
->buf
, rlen
);
91 mutex_unlock(&d
->usb_mutex
);
95 static int anysee_read_reg(struct dvb_usb_device
*d
, u16 reg
, u8
*val
)
97 u8 buf
[] = {CMD_REG_READ
, reg
>> 8, reg
& 0xff, 0x01};
99 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), val
, 1);
100 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, *val
);
104 static int anysee_write_reg(struct dvb_usb_device
*d
, u16 reg
, u8 val
)
106 u8 buf
[] = {CMD_REG_WRITE
, reg
>> 8, reg
& 0xff, 0x01, val
};
107 dev_dbg(&d
->udev
->dev
, "%s: reg=%04x val=%02x\n", __func__
, reg
, val
);
108 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
111 /* write single register with mask */
112 static int anysee_wr_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8 val
,
118 /* no need for read if whole reg is written */
120 ret
= anysee_read_reg(d
, reg
, &tmp
);
129 return anysee_write_reg(d
, reg
, val
);
132 /* read single register with mask */
133 static int anysee_rd_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8
*val
,
139 ret
= anysee_read_reg(d
, reg
, &tmp
);
145 /* find position of the first bit */
146 for (i
= 0; i
< 8; i
++) {
147 if ((mask
>> i
) & 0x01)
155 static int anysee_get_hw_info(struct dvb_usb_device
*d
, u8
*id
)
157 u8 buf
[] = {CMD_GET_HW_INFO
};
158 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), id
, 3);
161 static int anysee_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
163 u8 buf
[] = {CMD_STREAMING_CTRL
, (u8
)onoff
, 0x00};
164 dev_dbg(&fe_to_d(fe
)->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
165 return anysee_ctrl_msg(fe_to_d(fe
), buf
, sizeof(buf
), NULL
, 0);
168 static int anysee_led_ctrl(struct dvb_usb_device
*d
, u8 mode
, u8 interval
)
170 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x01, mode
, interval
};
171 dev_dbg(&d
->udev
->dev
, "%s: state=%d interval=%d\n", __func__
,
173 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
176 static int anysee_ir_ctrl(struct dvb_usb_device
*d
, u8 onoff
)
178 u8 buf
[] = {CMD_LED_AND_IR_CTRL
, 0x02, onoff
};
179 dev_dbg(&d
->udev
->dev
, "%s: onoff=%d\n", __func__
, onoff
);
180 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
184 static int anysee_master_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msg
,
187 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
188 int ret
= 0, inc
, i
= 0;
189 u8 buf
[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
191 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
195 if (num
> i
+ 1 && (msg
[i
+1].flags
& I2C_M_RD
)) {
196 if (msg
[i
].len
< 1 || msg
[i
].len
> 2 || msg
[i
+ 1].len
> 60) {
200 buf
[0] = CMD_I2C_READ
;
201 buf
[1] = (msg
[i
].addr
<< 1) | 0x01;
202 buf
[2] = msg
[i
].buf
[0];
203 buf
[3] = (msg
[i
].len
< 2) ? 0 : msg
[i
].buf
[1];
204 buf
[4] = msg
[i
].len
-1;
205 buf
[5] = msg
[i
+1].len
;
206 ret
= anysee_ctrl_msg(d
, buf
, 6, msg
[i
+1].buf
,
210 if (msg
[i
].len
> 48) {
214 buf
[0] = CMD_I2C_WRITE
;
215 buf
[1] = (msg
[i
].addr
<< 1);
218 memcpy(&buf
[4], msg
[i
].buf
, msg
[i
].len
);
219 ret
= anysee_ctrl_msg(d
, buf
, 4 + msg
[i
].len
, NULL
, 0);
228 mutex_unlock(&d
->i2c_mutex
);
230 return ret
? ret
: i
;
233 static u32
anysee_i2c_func(struct i2c_adapter
*adapter
)
238 static struct i2c_algorithm anysee_i2c_algo
= {
239 .master_xfer
= anysee_master_xfer
,
240 .functionality
= anysee_i2c_func
,
243 static int anysee_mt352_demod_init(struct dvb_frontend
*fe
)
245 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x28 };
246 static u8 reset
[] = { RESET
, 0x80 };
247 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
248 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0x20 };
249 static u8 gpp_ctl_cfg
[] = { GPP_CTL
, 0x33 };
250 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x32 };
252 mt352_write(fe
, clock_config
, sizeof(clock_config
));
254 mt352_write(fe
, reset
, sizeof(reset
));
255 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
257 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
258 mt352_write(fe
, gpp_ctl_cfg
, sizeof(gpp_ctl_cfg
));
259 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
264 /* Callbacks for DVB USB */
265 static struct tda10023_config anysee_tda10023_config
= {
266 .demod_address
= (0x1a >> 1),
272 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_C
,
276 static struct mt352_config anysee_mt352_config
= {
277 .demod_address
= (0x1e >> 1),
278 .demod_init
= anysee_mt352_demod_init
,
281 static struct zl10353_config anysee_zl10353_config
= {
282 .demod_address
= (0x1e >> 1),
286 static struct zl10353_config anysee_zl10353_tda18212_config2
= {
287 .demod_address
= (0x1e >> 1),
289 .disable_i2c_gate_ctrl
= 1,
294 static struct zl10353_config anysee_zl10353_tda18212_config
= {
295 .demod_address
= (0x18 >> 1),
297 .disable_i2c_gate_ctrl
= 1,
302 static struct tda10023_config anysee_tda10023_tda18212_config
= {
303 .demod_address
= (0x1a >> 1),
308 .output_mode
= TDA10023_OUTPUT_MODE_PARALLEL_B
,
312 static const struct tda18212_config anysee_tda18212_config
= {
319 static const struct tda18212_config anysee_tda18212_config2
= {
329 static struct cx24116_config anysee_cx24116_config
= {
330 .demod_address
= (0xaa >> 1),
331 .mpg_clk_pos_pol
= 0x00,
335 static struct stv0900_config anysee_stv0900_config
= {
336 .demod_address
= (0xd0 >> 1),
342 .tun1_adc
= 1, /* 1 Vpp */
346 static struct stv6110_config anysee_stv6110_config
= {
347 .i2c_address
= (0xc0 >> 1),
352 static struct isl6423_config anysee_isl6423_config
= {
353 .current_max
= SEC_CURRENT_800m
,
354 .curlim
= SEC_CURRENT_LIM_OFF
,
359 static struct cxd2820r_config anysee_cxd2820r_config
= {
360 .i2c_address
= 0x6d, /* (0xda >> 1) */
365 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
366 * Manufacturer: AMT.CO.KR
368 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
370 * parts: DNOS404ZH102A(MT352, DTT7579(?))
372 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
373 * PCB: PCB 507T (rev1.61)
374 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
375 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
376 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
378 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
379 * PCB: 507CD (rev1.1)
380 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
381 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
382 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
383 * IOD[0] ZL10353 1=enabled
384 * IOA[7] TS 0=enabled
385 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
387 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
388 * PCB: 507DC (rev0.2)
389 * parts: TDA10023, DTOS403IH102B TM, CST56I01
390 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
391 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
392 * IOD[0] TDA10023 1=enabled
394 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
395 * PCB: 507SI (rev2.1)
396 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
397 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
398 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
399 * IOD[0] CX24116 1=enabled
401 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
402 * PCB: 507FA (rev0.4)
403 * parts: TDA10023, DTOS403IH102B TM, TDA8024
404 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
405 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
406 * IOD[5] TDA10023 1=enabled
407 * IOE[0] tuner 1=enabled
409 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
410 * PCB: 507FA (rev1.1)
411 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
412 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
413 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
415 * IOD[5] TDA10023 1=enabled
416 * IOE[0] tuner 1=enabled
418 * IOD[0] ZL10353 1=enabled
419 * IOE[0] tuner 0=enabled
420 * tuner is behind ZL10353 I2C-gate
421 * tuner is behind TDA10023 I2C-gate
423 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
424 * PCB: 508TC (rev0.6)
425 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
426 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
427 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
428 * IOA[7] TS 1=enabled
429 * IOE[4] TDA18212 1=enabled
431 * IOD[6] ZL10353 0=disabled
432 * IOD[5] TDA10023 1=enabled
433 * IOE[0] IF 1=enabled
435 * IOD[5] TDA10023 0=disabled
436 * IOD[6] ZL10353 1=enabled
437 * IOE[0] IF 0=enabled
439 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
440 * PCB: 508S2 (rev0.7)
441 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
442 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
443 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
444 * IOA[7] TS 1=enabled
445 * IOE[5] STV0903 1=enabled
447 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
448 * PCB: 508T2C (rev0.3)
449 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
450 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
451 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
452 * IOA[7] TS 1=enabled
453 * IOE[5] CXD2820R 1=enabled
455 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
456 * PCB: 508PTC (rev0.5)
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 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
472 * PCB: 508PS2 (rev0.4)
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
480 static int anysee_read_config(struct dvb_usb_device
*d
)
482 struct anysee_state
*state
= d_to_priv(d
);
487 * Check which hardware we have.
488 * We must do this call two times to get reliable values (hw/fw bug).
490 ret
= anysee_get_hw_info(d
, hw_info
);
494 ret
= anysee_get_hw_info(d
, hw_info
);
499 * Meaning of these info bytes are guessed.
501 dev_info(&d
->udev
->dev
, "%s: firmware version %d.%d hardware id %d\n",
502 KBUILD_MODNAME
, hw_info
[1], hw_info
[2], hw_info
[0]);
504 state
->hw
= hw_info
[0];
509 /* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
510 static int anysee_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
512 /* enable / disable tuner access on IOE[4] */
513 return anysee_wr_reg_mask(fe_to_d(fe
), REG_IOE
, (enable
<< 4), 0x10);
516 static int anysee_frontend_ctrl(struct dvb_frontend
*fe
, int onoff
)
518 struct anysee_state
*state
= fe_to_priv(fe
);
519 struct dvb_usb_device
*d
= fe_to_d(fe
);
521 dev_dbg(&d
->udev
->dev
, "%s: fe=%d onoff=%d\n", __func__
, fe
->id
, onoff
);
523 /* no frontend sleep control */
528 case ANYSEE_HW_507FA
: /* 15 */
533 /* disable DVB-T demod on IOD[0] */
534 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
538 /* enable DVB-C demod on IOD[5] */
539 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
543 /* enable DVB-C tuner on IOE[0] */
544 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
548 /* disable DVB-C demod on IOD[5] */
549 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
553 /* enable DVB-T demod on IOD[0] */
554 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
558 /* enable DVB-T tuner on IOE[0] */
559 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
565 case ANYSEE_HW_508TC
: /* 18 */
566 case ANYSEE_HW_508PTC
: /* 21 */
571 /* disable DVB-T demod on IOD[6] */
572 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
576 /* enable DVB-C demod on IOD[5] */
577 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
581 /* enable IF route on IOE[0] */
582 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 0), 0x01);
586 /* disable DVB-C demod on IOD[5] */
587 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
591 /* enable DVB-T demod on IOD[6] */
592 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
596 /* enable IF route on IOE[0] */
597 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 0), 0x01);
611 static int anysee_add_i2c_dev(struct dvb_usb_device
*d
, const char *type
,
612 u8 addr
, void *platform_data
)
615 struct anysee_state
*state
= d_to_priv(d
);
616 struct i2c_client
*client
;
617 struct i2c_adapter
*adapter
= &d
->i2c_adap
;
618 struct i2c_board_info board_info
= {
620 .platform_data
= platform_data
,
623 strscpy(board_info
.type
, type
, I2C_NAME_SIZE
);
625 /* find first free client */
626 for (num
= 0; num
< ANYSEE_I2C_CLIENT_MAX
; num
++) {
627 if (state
->i2c_client
[num
] == NULL
)
631 dev_dbg(&d
->udev
->dev
, "%s: num=%d\n", __func__
, num
);
633 if (num
== ANYSEE_I2C_CLIENT_MAX
) {
634 dev_err(&d
->udev
->dev
, "%s: I2C client out of index\n",
640 request_module("%s", board_info
.type
);
642 /* register I2C device */
643 client
= i2c_new_client_device(adapter
, &board_info
);
644 if (!i2c_client_has_driver(client
)) {
649 /* increase I2C driver usage count */
650 if (!try_module_get(client
->dev
.driver
->owner
)) {
651 i2c_unregister_device(client
);
656 state
->i2c_client
[num
] = client
;
659 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
663 static void anysee_del_i2c_dev(struct dvb_usb_device
*d
)
666 struct anysee_state
*state
= d_to_priv(d
);
667 struct i2c_client
*client
;
669 /* find last used client */
670 num
= ANYSEE_I2C_CLIENT_MAX
;
672 if (state
->i2c_client
[num
] != NULL
)
676 dev_dbg(&d
->udev
->dev
, "%s: num=%d\n", __func__
, num
);
679 dev_err(&d
->udev
->dev
, "%s: I2C client out of index\n",
684 client
= state
->i2c_client
[num
];
686 /* decrease I2C driver usage count */
687 module_put(client
->dev
.driver
->owner
);
689 /* unregister I2C device */
690 i2c_unregister_device(client
);
692 state
->i2c_client
[num
] = NULL
;
694 dev_dbg(&d
->udev
->dev
, "%s: failed\n", __func__
);
697 static int anysee_frontend_attach(struct dvb_usb_adapter
*adap
)
699 struct anysee_state
*state
= adap_to_priv(adap
);
700 struct dvb_usb_device
*d
= adap_to_d(adap
);
703 struct i2c_msg msg
[2] = {
718 case ANYSEE_HW_507T
: /* 2 */
722 adap
->fe
[0] = dvb_attach(mt352_attach
, &anysee_mt352_config
,
728 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
732 case ANYSEE_HW_507CD
: /* 6 */
735 /* enable DVB-T demod on IOD[0] */
736 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
740 /* enable transport stream on IOA[7] */
741 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
746 adap
->fe
[0] = dvb_attach(zl10353_attach
, &anysee_zl10353_config
,
750 case ANYSEE_HW_507DC
: /* 10 */
753 /* enable DVB-C demod on IOD[0] */
754 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
759 adap
->fe
[0] = dvb_attach(tda10023_attach
,
760 &anysee_tda10023_config
, &d
->i2c_adap
, 0x48);
763 case ANYSEE_HW_507SI
: /* 11 */
766 /* enable DVB-S/S2 demod on IOD[0] */
767 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
772 adap
->fe
[0] = dvb_attach(cx24116_attach
, &anysee_cx24116_config
,
776 case ANYSEE_HW_507FA
: /* 15 */
780 /* enable tuner on IOE[4] */
781 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 4), 0x10);
787 ret
= i2c_transfer(&d
->i2c_adap
, msg
, 2);
788 if (ret
== 2 && tmp
== 0xc7) {
789 dev_dbg(&d
->udev
->dev
, "%s: TDA18212 found\n",
791 state
->has_tda18212
= true;
796 /* disable tuner on IOE[4] */
797 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (0 << 4), 0x10);
801 /* disable DVB-T demod on IOD[0] */
802 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 0), 0x01);
806 /* enable DVB-C demod on IOD[5] */
807 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
813 /* TDA18212 config */
814 adap
->fe
[0] = dvb_attach(tda10023_attach
,
815 &anysee_tda10023_tda18212_config
,
818 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
820 adap
->fe
[0]->ops
.i2c_gate_ctrl
=
821 anysee_i2c_gate_ctrl
;
824 adap
->fe
[0] = dvb_attach(tda10023_attach
,
825 &anysee_tda10023_config
,
829 /* break out if first frontend attaching fails */
833 /* disable DVB-C demod on IOD[5] */
834 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
838 /* enable DVB-T demod on IOD[0] */
839 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 0), 0x01);
845 /* TDA18212 config */
846 adap
->fe
[1] = dvb_attach(zl10353_attach
,
847 &anysee_zl10353_tda18212_config2
,
850 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
852 adap
->fe
[1]->ops
.i2c_gate_ctrl
=
853 anysee_i2c_gate_ctrl
;
856 adap
->fe
[1] = dvb_attach(zl10353_attach
,
857 &anysee_zl10353_config
,
862 case ANYSEE_HW_508TC
: /* 18 */
863 case ANYSEE_HW_508PTC
: /* 21 */
867 /* disable DVB-T demod on IOD[6] */
868 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 6), 0x40);
872 /* enable DVB-C demod on IOD[5] */
873 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 5), 0x20);
878 adap
->fe
[0] = dvb_attach(tda10023_attach
,
879 &anysee_tda10023_tda18212_config
,
882 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
884 adap
->fe
[0]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
886 /* break out if first frontend attaching fails */
890 /* disable DVB-C demod on IOD[5] */
891 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 5), 0x20);
895 /* enable DVB-T demod on IOD[6] */
896 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 6), 0x40);
901 adap
->fe
[1] = dvb_attach(zl10353_attach
,
902 &anysee_zl10353_tda18212_config
,
905 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
907 adap
->fe
[1]->ops
.i2c_gate_ctrl
= anysee_i2c_gate_ctrl
;
909 state
->has_ci
= true;
912 case ANYSEE_HW_508S2
: /* 19 */
913 case ANYSEE_HW_508PS2
: /* 22 */
917 /* enable DVB-S/S2 demod on IOE[5] */
918 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
923 adap
->fe
[0] = dvb_attach(stv0900_attach
,
924 &anysee_stv0900_config
, &d
->i2c_adap
, 0);
926 state
->has_ci
= true;
929 case ANYSEE_HW_508T2C
: /* 20 */
932 /* enable DVB-T/T2/C demod on IOE[5] */
933 ret
= anysee_wr_reg_mask(d
, REG_IOE
, (1 << 5), 0x20);
938 adap
->fe
[0] = dvb_attach(cxd2820r_attach
,
939 &anysee_cxd2820r_config
, &d
->i2c_adap
, NULL
);
941 state
->has_ci
= true;
947 /* we have no frontend :-( */
949 dev_err(&d
->udev
->dev
,
950 "%s: Unsupported Anysee version. Please report to <linux-media@vger.kernel.org>.\n",
957 static int anysee_tuner_attach(struct dvb_usb_adapter
*adap
)
959 struct anysee_state
*state
= adap_to_priv(adap
);
960 struct dvb_usb_device
*d
= adap_to_d(adap
);
961 struct dvb_frontend
*fe
;
963 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
966 case ANYSEE_HW_507T
: /* 2 */
970 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1), NULL
,
971 DVB_PLL_THOMSON_DTT7579
);
974 case ANYSEE_HW_507CD
: /* 6 */
978 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc2 >> 1),
979 &d
->i2c_adap
, DVB_PLL_THOMSON_DTT7579
);
982 case ANYSEE_HW_507DC
: /* 10 */
986 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0], (0xc0 >> 1),
987 &d
->i2c_adap
, DVB_PLL_SAMSUNG_DTOS403IH102A
);
990 case ANYSEE_HW_507SI
: /* 11 */
993 /* attach LNB controller */
994 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0], &d
->i2c_adap
,
995 &anysee_isl6423_config
);
998 case ANYSEE_HW_507FA
: /* 15 */
1002 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
1003 * fails attach old simple PLL. */
1006 if (state
->has_tda18212
) {
1007 struct tda18212_config tda18212_config
=
1008 anysee_tda18212_config
;
1010 tda18212_config
.fe
= adap
->fe
[0];
1011 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60,
1016 /* copy tuner ops for 2nd FE as tuner is shared */
1018 adap
->fe
[1]->tuner_priv
=
1019 adap
->fe
[0]->tuner_priv
;
1020 memcpy(&adap
->fe
[1]->ops
.tuner_ops
,
1021 &adap
->fe
[0]->ops
.tuner_ops
,
1022 sizeof(struct dvb_tuner_ops
));
1028 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[0],
1029 (0xc0 >> 1), &d
->i2c_adap
,
1030 DVB_PLL_SAMSUNG_DTOS403IH102A
);
1032 if (fe
&& adap
->fe
[1]) {
1033 /* attach tuner for 2nd FE */
1034 fe
= dvb_attach(dvb_pll_attach
, adap
->fe
[1],
1035 (0xc0 >> 1), &d
->i2c_adap
,
1036 DVB_PLL_SAMSUNG_DTOS403IH102A
);
1041 case ANYSEE_HW_508TC
: /* 18 */
1042 case ANYSEE_HW_508PTC
: /* 21 */
1046 struct tda18212_config tda18212_config
= anysee_tda18212_config
;
1048 tda18212_config
.fe
= adap
->fe
[0];
1049 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60, &tda18212_config
);
1053 /* copy tuner ops for 2nd FE as tuner is shared */
1055 adap
->fe
[1]->tuner_priv
= adap
->fe
[0]->tuner_priv
;
1056 memcpy(&adap
->fe
[1]->ops
.tuner_ops
,
1057 &adap
->fe
[0]->ops
.tuner_ops
,
1058 sizeof(struct dvb_tuner_ops
));
1063 case ANYSEE_HW_508S2
: /* 19 */
1064 case ANYSEE_HW_508PS2
: /* 22 */
1069 fe
= dvb_attach(stv6110_attach
, adap
->fe
[0],
1070 &anysee_stv6110_config
, &d
->i2c_adap
);
1073 /* attach LNB controller */
1074 fe
= dvb_attach(isl6423_attach
, adap
->fe
[0],
1075 &d
->i2c_adap
, &anysee_isl6423_config
);
1080 case ANYSEE_HW_508T2C
: /* 20 */
1083 struct tda18212_config tda18212_config
=
1084 anysee_tda18212_config2
;
1086 tda18212_config
.fe
= adap
->fe
[0];
1087 ret
= anysee_add_i2c_dev(d
, "tda18212", 0x60, &tda18212_config
);
1105 #if IS_ENABLED(CONFIG_RC_CORE)
1106 static int anysee_rc_query(struct dvb_usb_device
*d
)
1108 u8 buf
[] = {CMD_GET_IR_CODE
};
1112 /* Remote controller is basic NEC using address byte 0x08.
1113 Anysee device RC query returns only two bytes, status and code,
1114 address byte is dropped. Also it does not return any value for
1115 NEC RCs having address byte other than 0x08. Due to that, we
1116 cannot use that device as standard NEC receiver.
1117 It could be possible make hack which reads whole code directly
1118 from device memory... */
1120 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), ircode
, sizeof(ircode
));
1125 dev_dbg(&d
->udev
->dev
, "%s: key pressed %02x\n", __func__
,
1127 rc_keydown(d
->rc_dev
, RC_PROTO_NEC
,
1128 RC_SCANCODE_NEC(0x08, ircode
[1]), 0);
1134 static int anysee_get_rc_config(struct dvb_usb_device
*d
, struct dvb_usb_rc
*rc
)
1136 rc
->allowed_protos
= RC_PROTO_BIT_NEC
;
1137 rc
->query
= anysee_rc_query
;
1138 rc
->interval
= 250; /* windows driver uses 500ms */
1143 #define anysee_get_rc_config NULL
1146 static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1149 struct dvb_usb_device
*d
= ci
->data
;
1151 u8 buf
[] = {CMD_CI
, 0x02, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1};
1154 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1161 static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221
*ci
, int slot
,
1164 struct dvb_usb_device
*d
= ci
->data
;
1165 u8 buf
[] = {CMD_CI
, 0x03, 0x40 | addr
>> 8, addr
& 0xff, 0x00, 1, val
};
1167 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1170 static int anysee_ci_read_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1173 struct dvb_usb_device
*d
= ci
->data
;
1175 u8 buf
[] = {CMD_CI
, 0x04, 0x40, addr
, 0x00, 1};
1178 ret
= anysee_ctrl_msg(d
, buf
, sizeof(buf
), &val
, 1);
1185 static int anysee_ci_write_cam_control(struct dvb_ca_en50221
*ci
, int slot
,
1188 struct dvb_usb_device
*d
= ci
->data
;
1189 u8 buf
[] = {CMD_CI
, 0x05, 0x40, addr
, 0x00, 1, val
};
1191 return anysee_ctrl_msg(d
, buf
, sizeof(buf
), NULL
, 0);
1194 static int anysee_ci_slot_reset(struct dvb_ca_en50221
*ci
, int slot
)
1196 struct dvb_usb_device
*d
= ci
->data
;
1198 struct anysee_state
*state
= d_to_priv(d
);
1200 state
->ci_cam_ready
= jiffies
+ msecs_to_jiffies(1000);
1202 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1208 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1215 static int anysee_ci_slot_shutdown(struct dvb_ca_en50221
*ci
, int slot
)
1217 struct dvb_usb_device
*d
= ci
->data
;
1220 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (0 << 7), 0x80);
1226 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1233 static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221
*ci
, int slot
)
1235 struct dvb_usb_device
*d
= ci
->data
;
1237 return anysee_wr_reg_mask(d
, REG_IOD
, (0 << 1), 0x02);
1240 static int anysee_ci_poll_slot_status(struct dvb_ca_en50221
*ci
, int slot
,
1243 struct dvb_usb_device
*d
= ci
->data
;
1244 struct anysee_state
*state
= d_to_priv(d
);
1248 ret
= anysee_rd_reg_mask(d
, REG_IOC
, &tmp
, 0x40);
1253 ret
= DVB_CA_EN50221_POLL_CAM_PRESENT
;
1254 if (time_after(jiffies
, state
->ci_cam_ready
))
1255 ret
|= DVB_CA_EN50221_POLL_CAM_READY
;
1261 static int anysee_ci_init(struct dvb_usb_device
*d
)
1263 struct anysee_state
*state
= d_to_priv(d
);
1266 state
->ci
.owner
= THIS_MODULE
;
1267 state
->ci
.read_attribute_mem
= anysee_ci_read_attribute_mem
;
1268 state
->ci
.write_attribute_mem
= anysee_ci_write_attribute_mem
;
1269 state
->ci
.read_cam_control
= anysee_ci_read_cam_control
;
1270 state
->ci
.write_cam_control
= anysee_ci_write_cam_control
;
1271 state
->ci
.slot_reset
= anysee_ci_slot_reset
;
1272 state
->ci
.slot_shutdown
= anysee_ci_slot_shutdown
;
1273 state
->ci
.slot_ts_enable
= anysee_ci_slot_ts_enable
;
1274 state
->ci
.poll_slot_status
= anysee_ci_poll_slot_status
;
1277 ret
= anysee_wr_reg_mask(d
, REG_IOA
, (1 << 7), 0x80);
1281 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1285 ret
= anysee_wr_reg_mask(d
, REG_IOD
, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1289 ret
= dvb_ca_en50221_init(&d
->adapter
[0].dvb_adap
, &state
->ci
, 0, 1);
1293 state
->ci_attached
= true;
1298 static void anysee_ci_release(struct dvb_usb_device
*d
)
1300 struct anysee_state
*state
= d_to_priv(d
);
1303 if (state
->ci_attached
)
1304 dvb_ca_en50221_release(&state
->ci
);
1309 static int anysee_init(struct dvb_usb_device
*d
)
1311 struct anysee_state
*state
= d_to_priv(d
);
1314 /* There is one interface with two alternate settings.
1315 Alternate setting 0 is for bulk transfer.
1316 Alternate setting 1 is for isochronous transfer.
1317 We use bulk transfer (alternate setting 0). */
1318 ret
= usb_set_interface(d
->udev
, 0, 0);
1323 ret
= anysee_led_ctrl(d
, 0x01, 0x03);
1328 ret
= anysee_ir_ctrl(d
, 1);
1333 if (state
->has_ci
) {
1334 ret
= anysee_ci_init(d
);
1342 static void anysee_exit(struct dvb_usb_device
*d
)
1344 struct anysee_state
*state
= d_to_priv(d
);
1346 if (state
->i2c_client
[0])
1347 anysee_del_i2c_dev(d
);
1349 return anysee_ci_release(d
);
1352 /* DVB USB Driver stuff */
1353 static struct dvb_usb_device_properties anysee_props
= {
1354 .driver_name
= KBUILD_MODNAME
,
1355 .owner
= THIS_MODULE
,
1356 .adapter_nr
= adapter_nr
,
1357 .size_of_priv
= sizeof(struct anysee_state
),
1359 .generic_bulk_ctrl_endpoint
= 0x01,
1360 .generic_bulk_ctrl_endpoint_response
= 0x81,
1362 .i2c_algo
= &anysee_i2c_algo
,
1363 .read_config
= anysee_read_config
,
1364 .frontend_attach
= anysee_frontend_attach
,
1365 .tuner_attach
= anysee_tuner_attach
,
1366 .init
= anysee_init
,
1367 .get_rc_config
= anysee_get_rc_config
,
1368 .frontend_ctrl
= anysee_frontend_ctrl
,
1369 .streaming_ctrl
= anysee_streaming_ctrl
,
1370 .exit
= anysee_exit
,
1375 .stream
= DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
1380 static const struct usb_device_id anysee_id_table
[] = {
1381 { DVB_USB_DEVICE(USB_VID_CYPRESS
, USB_PID_ANYSEE
,
1382 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1383 { DVB_USB_DEVICE(USB_VID_AMT
, USB_PID_ANYSEE
,
1384 &anysee_props
, "Anysee", RC_MAP_ANYSEE
) },
1387 MODULE_DEVICE_TABLE(usb
, anysee_id_table
);
1389 static struct usb_driver anysee_usb_driver
= {
1390 .name
= KBUILD_MODNAME
,
1391 .id_table
= anysee_id_table
,
1392 .probe
= dvb_usbv2_probe
,
1393 .disconnect
= dvb_usbv2_disconnect
,
1394 .suspend
= dvb_usbv2_suspend
,
1395 .resume
= dvb_usbv2_resume
,
1396 .reset_resume
= dvb_usbv2_reset_resume
,
1401 module_usb_driver(anysee_usb_driver
);
1403 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1404 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1405 MODULE_LICENSE("GPL");