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 implented. This
27 * module registers serial interface that can be used to comminicate
28 * with any ISO 7816 smart card.
30 * Any help according to implement serial smart card reader support
37 #include "mt352_priv.h"
41 static int dvb_usb_anysee_debug;
42 module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
43 MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
44 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
46 struct mutex anysee_usb_mutex;
48 static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
51 struct anysee_state *state = d->priv;
55 if (slen > sizeof(buf))
57 memcpy(&buf[0], sbuf, slen);
58 buf[60] = state->seq++;
60 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
63 /* We need receive one message more after dvb_usb_generic_rw due
64 to weird transaction flow, which is 1 x send + 2 x receive. */
65 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
68 /* receive 2nd answer */
69 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
70 d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),
73 err("%s: recv bulk message failed: %d", __func__, ret);
76 debug_dump(buf, act_len, deb_xfer);
80 /* read request, copy returned data to return buf */
81 if (!ret && rbuf && rlen)
82 memcpy(rbuf, buf, rlen);
84 mutex_unlock(&anysee_usb_mutex);
89 static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
91 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
93 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
94 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
98 static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
100 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
101 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
102 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
105 static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
107 u8 buf[] = {CMD_GET_HW_INFO};
108 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
111 static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
113 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
114 deb_info("%s: onoff:%02x\n", __func__, onoff);
115 return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
118 static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
120 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
121 deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
122 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
125 static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
127 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
128 deb_info("%s: onoff:%02x\n", __func__, onoff);
129 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
132 static int anysee_init(struct dvb_usb_device *d)
136 ret = anysee_led_ctrl(d, 0x01, 0x03);
141 ret = anysee_ir_ctrl(d, 1);
149 static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
152 struct dvb_usb_device *d = i2c_get_adapdata(adap);
155 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
159 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
161 buf[0] = CMD_I2C_READ;
162 buf[1] = msg[i].addr + 1;
163 buf[2] = msg[i].buf[0];
167 ret = anysee_ctrl_msg(d, buf, sizeof(buf), msg[i+1].buf,
171 u8 buf[4+msg[i].len];
172 buf[0] = CMD_I2C_WRITE;
173 buf[1] = msg[i].addr;
176 memcpy(&buf[4], msg[i].buf, msg[i].len);
177 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
186 mutex_unlock(&d->i2c_mutex);
191 static u32 anysee_i2c_func(struct i2c_adapter *adapter)
196 static struct i2c_algorithm anysee_i2c_algo = {
197 .master_xfer = anysee_master_xfer,
198 .functionality = anysee_i2c_func,
201 static int anysee_mt352_demod_init(struct dvb_frontend *fe)
203 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };
204 static u8 reset [] = { RESET, 0x80 };
205 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
206 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
207 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
208 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
210 mt352_write(fe, clock_config, sizeof(clock_config));
212 mt352_write(fe, reset, sizeof(reset));
213 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
215 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
216 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
217 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
222 /* Callbacks for DVB USB */
223 static struct tda10023_config anysee_tda10023_config = {
224 .demod_address = 0x1a,
233 static struct mt352_config anysee_mt352_config = {
234 .demod_address = 0x1e,
235 .demod_init = anysee_mt352_demod_init,
238 static struct zl10353_config anysee_zl10353_config = {
239 .demod_address = 0x1e,
243 static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
246 struct anysee_state *state = adap->dev->priv;
248 u8 io_d; /* IO port D */
250 /* check which hardware we have
251 We must do this call two times to get reliable values (hw bug). */
252 ret = anysee_get_hw_info(adap->dev, hw_info);
255 ret = anysee_get_hw_info(adap->dev, hw_info);
259 /* Meaning of these info bytes are guessed. */
260 info("firmware version:%d.%d.%d hardware id:%d",
261 0, hw_info[1], hw_info[2], hw_info[0]);
263 ret = anysee_read_reg(adap->dev, 0xb0, &io_d); /* IO port D */
266 deb_info("%s: IO port D:%02x\n", __func__, io_d);
268 /* Select demod using trial and error method. */
270 /* Try to attach demodulator in following order:
271 model demod hw firmware
272 1. E30 MT352 02 0.2.1
273 2. E30 ZL10353 02 0.2.1
274 3. E30 Plus ZL10353 06 0.1.0
275 4. E30C Plus TDA10023 0a 0.1.0
276 E30C Plus TDA10023 0f 0.1.2 (not working)
279 /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */
280 adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
281 &adap->dev->i2c_adap);
282 if (adap->fe != NULL) {
283 state->tuner = DVB_PLL_THOMSON_DTT7579;
287 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */
288 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
289 &adap->dev->i2c_adap);
290 if (adap->fe != NULL) {
291 state->tuner = DVB_PLL_THOMSON_DTT7579;
295 /* connect demod on IO port D for TDA10023 & ZL10353 */
296 ret = anysee_write_reg(adap->dev, 0xb0, 0x25);
300 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */
301 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
302 &adap->dev->i2c_adap);
303 if (adap->fe != NULL) {
304 state->tuner = DVB_PLL_THOMSON_DTT7579;
308 /* known not working (E30C Plus v0.1.2) */
309 if (hw_info[0] == 0x0f) {
310 info("this version of Anysee is not supported yet");
311 /* return IO port D to init value for safe */
312 ret = anysee_write_reg(adap->dev, 0xb0, io_d);
316 /* Philips TDA10023 DVB-C demod */
317 adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
318 &adap->dev->i2c_adap, 0x48);
319 if (adap->fe != NULL) {
320 state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A;
324 /* return IO port D to init value for safe */
325 ret = anysee_write_reg(adap->dev, 0xb0, io_d);
329 err("Unkown Anysee version: %02x %02x %02x. "\
330 "Please report the <linux-dvb@linuxtv.org>.",
331 hw_info[0], hw_info[1], hw_info[2]);
336 static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
338 struct anysee_state *state = adap->dev->priv;
339 deb_info("%s: \n", __func__);
341 switch (state->tuner) {
342 case DVB_PLL_THOMSON_DTT7579:
343 /* Thomson dtt7579 (not sure) PLL inside of:
344 Samsung DNOS404ZH102A NIM
345 Samsung DNOS404ZH103A NIM */
346 dvb_attach(dvb_pll_attach, adap->fe, 0x61,
347 NULL, DVB_PLL_THOMSON_DTT7579);
349 case DVB_PLL_SAMSUNG_DTOS403IH102A:
350 /* Unknown PLL inside of Samsung DTOS403IH102A tuner module */
351 dvb_attach(dvb_pll_attach, adap->fe, 0xc0,
352 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
359 static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
361 u8 buf[] = {CMD_GET_IR_CODE};
362 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
366 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &ircode[0], 2);
371 *state = REMOTE_NO_KEY_PRESSED;
373 for (i = 0; i < d->props.rc_key_map_size; i++) {
374 if (keymap[i].custom == ircode[0] &&
375 keymap[i].data == ircode[1]) {
376 *event = keymap[i].event;
377 *state = REMOTE_KEY_PRESSED;
384 static struct dvb_usb_rc_key anysee_rc_keys[] = {
385 { 0x01, 0x00, KEY_0 },
386 { 0x01, 0x01, KEY_1 },
387 { 0x01, 0x02, KEY_2 },
388 { 0x01, 0x03, KEY_3 },
389 { 0x01, 0x04, KEY_4 },
390 { 0x01, 0x05, KEY_5 },
391 { 0x01, 0x06, KEY_6 },
392 { 0x01, 0x07, KEY_7 },
393 { 0x01, 0x08, KEY_8 },
394 { 0x01, 0x09, KEY_9 },
395 { 0x01, 0x0a, KEY_POWER },
396 { 0x01, 0x0b, KEY_DOCUMENTS }, /* * */
397 { 0x01, 0x19, KEY_FAVORITES },
398 { 0x01, 0x20, KEY_SLEEP },
399 { 0x01, 0x21, KEY_MODE }, /* 4:3 / 16:9 select */
400 { 0x01, 0x22, KEY_ZOOM },
401 { 0x01, 0x47, KEY_TEXT },
402 { 0x01, 0x16, KEY_TV }, /* TV / radio select */
403 { 0x01, 0x1e, KEY_LANGUAGE }, /* Second Audio Program */
404 { 0x01, 0x1a, KEY_SUBTITLE },
405 { 0x01, 0x1b, KEY_CAMERA }, /* screenshot */
406 { 0x01, 0x42, KEY_MUTE },
407 { 0x01, 0x0e, KEY_MENU },
408 { 0x01, 0x0f, KEY_EPG },
409 { 0x01, 0x17, KEY_INFO },
410 { 0x01, 0x10, KEY_EXIT },
411 { 0x01, 0x13, KEY_VOLUMEUP },
412 { 0x01, 0x12, KEY_VOLUMEDOWN },
413 { 0x01, 0x11, KEY_CHANNELUP },
414 { 0x01, 0x14, KEY_CHANNELDOWN },
415 { 0x01, 0x15, KEY_OK },
416 { 0x01, 0x1d, KEY_RED },
417 { 0x01, 0x1f, KEY_GREEN },
418 { 0x01, 0x1c, KEY_YELLOW },
419 { 0x01, 0x44, KEY_BLUE },
420 { 0x01, 0x0c, KEY_SHUFFLE }, /* snapshot */
421 { 0x01, 0x48, KEY_STOP },
422 { 0x01, 0x50, KEY_PLAY },
423 { 0x01, 0x51, KEY_PAUSE },
424 { 0x01, 0x49, KEY_RECORD },
425 { 0x01, 0x18, KEY_PREVIOUS }, /* |<< */
426 { 0x01, 0x0d, KEY_NEXT }, /* >>| */
427 { 0x01, 0x24, KEY_PROG1 }, /* F1 */
428 { 0x01, 0x25, KEY_PROG2 }, /* F2 */
431 /* DVB USB Driver stuff */
432 static struct dvb_usb_device_properties anysee_properties;
434 static int anysee_probe(struct usb_interface *intf,
435 const struct usb_device_id *id)
437 struct dvb_usb_device *d;
438 struct usb_host_interface *alt;
441 mutex_init(&anysee_usb_mutex);
443 /* There is one interface with two alternate settings.
444 Alternate setting 0 is for bulk transfer.
445 Alternate setting 1 is for isochronous transfer.
446 We use bulk transfer (alternate setting 0). */
447 if (intf->num_altsetting < 1)
450 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
455 alt = usb_altnum_to_altsetting(intf, 0);
457 deb_info("%s: no alt found!\n", __func__);
461 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
462 alt->desc.bAlternateSetting);
467 ret = anysee_init(d);
472 static struct usb_device_id anysee_table [] = {
473 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
474 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
475 { } /* Terminating entry */
477 MODULE_DEVICE_TABLE(usb, anysee_table);
479 static struct dvb_usb_device_properties anysee_properties = {
480 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
482 .usb_ctrl = DEVICE_SPECIFIC,
484 .size_of_priv = sizeof(struct anysee_state),
489 .streaming_ctrl = anysee_streaming_ctrl,
490 .frontend_attach = anysee_frontend_attach,
491 .tuner_attach = anysee_tuner_attach,
505 .rc_key_map = anysee_rc_keys,
506 .rc_key_map_size = ARRAY_SIZE(anysee_rc_keys),
507 .rc_query = anysee_rc_query,
508 .rc_interval = 200, /* windows driver uses 500ms */
510 .i2c_algo = &anysee_i2c_algo,
512 .generic_bulk_ctrl_endpoint = 1,
514 .num_device_descs = 1,
517 .name = "Anysee DVB USB2.0",
519 .warm_ids = {&anysee_table[0],
520 &anysee_table[1], NULL},
525 static struct usb_driver anysee_driver = {
526 .name = "dvb_usb_anysee",
527 .probe = anysee_probe,
528 .disconnect = dvb_usb_device_exit,
529 .id_table = anysee_table,
533 static int __init anysee_module_init(void)
537 ret = usb_register(&anysee_driver);
539 err("%s: usb_register failed. Error number %d", __func__, ret);
544 static void __exit anysee_module_exit(void)
546 /* deregister this driver from the USB subsystem */
547 usb_deregister(&anysee_driver);
550 module_init(anysee_module_init);
551 module_exit(anysee_module_exit);
553 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
554 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
555 MODULE_LICENSE("GPL");