2 * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * - add smart card reader support for Conditional Access (CA)
23 * Card reader in Anysee is nothing more than ISO 7816 card reader.
24 * There is no hardware CAM in any Anysee device sold.
25 * In my understanding it should be implemented by making own module
26 * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
27 * module registers serial interface that can be used to communicate
28 * with any ISO 7816 smart card.
30 * Any help according to implement serial smart card reader support
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 static int dvb_usb_anysee_delsys;
45 module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
46 MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
47 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
49 static DEFINE_MUTEX(anysee_usb_mutex);
51 static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
54 struct anysee_state *state = d->priv;
58 if (slen > sizeof(buf))
60 memcpy(&buf[0], sbuf, slen);
61 buf[60] = state->seq++;
63 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
66 /* We need receive one message more after dvb_usb_generic_rw due
67 to weird transaction flow, which is 1 x send + 2 x receive. */
68 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
71 /* receive 2nd answer */
72 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
73 d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),
76 err("%s: recv bulk message failed: %d", __func__, ret);
79 debug_dump(buf, act_len, deb_xfer);
83 /* read request, copy returned data to return buf */
84 if (!ret && rbuf && rlen)
85 memcpy(rbuf, buf, rlen);
87 mutex_unlock(&anysee_usb_mutex);
92 static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
94 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
96 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
97 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
101 static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
103 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
104 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
105 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
108 static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
110 u8 buf[] = {CMD_GET_HW_INFO};
111 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
114 static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
116 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
117 deb_info("%s: onoff:%02x\n", __func__, onoff);
118 return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
121 static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
123 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
124 deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
125 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
128 static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
130 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
131 deb_info("%s: onoff:%02x\n", __func__, onoff);
132 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
135 static int anysee_init(struct dvb_usb_device *d)
139 ret = anysee_led_ctrl(d, 0x01, 0x03);
144 ret = anysee_ir_ctrl(d, 1);
152 static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
155 struct dvb_usb_device *d = i2c_get_adapdata(adap);
156 int ret = 0, inc, i = 0;
158 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
162 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
164 buf[0] = CMD_I2C_READ;
165 buf[1] = msg[i].addr + 1;
166 buf[2] = msg[i].buf[0];
170 ret = anysee_ctrl_msg(d, buf, sizeof(buf), msg[i+1].buf,
174 u8 buf[4+msg[i].len];
175 buf[0] = CMD_I2C_WRITE;
176 buf[1] = msg[i].addr;
179 memcpy(&buf[4], msg[i].buf, msg[i].len);
180 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
189 mutex_unlock(&d->i2c_mutex);
191 return ret ? ret : i;
194 static u32 anysee_i2c_func(struct i2c_adapter *adapter)
199 static struct i2c_algorithm anysee_i2c_algo = {
200 .master_xfer = anysee_master_xfer,
201 .functionality = anysee_i2c_func,
204 static int anysee_mt352_demod_init(struct dvb_frontend *fe)
206 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };
207 static u8 reset [] = { RESET, 0x80 };
208 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
209 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
210 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
211 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
213 mt352_write(fe, clock_config, sizeof(clock_config));
215 mt352_write(fe, reset, sizeof(reset));
216 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
218 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
219 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
220 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
225 /* Callbacks for DVB USB */
226 static struct tda10023_config anysee_tda10023_config = {
227 .demod_address = 0x1a,
233 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
237 static struct mt352_config anysee_mt352_config = {
238 .demod_address = 0x1e,
239 .demod_init = anysee_mt352_demod_init,
242 static struct zl10353_config anysee_zl10353_config = {
243 .demod_address = 0x1e,
247 static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
250 struct anysee_state *state = adap->dev->priv;
252 u8 io_d; /* IO port D */
254 /* check which hardware we have
255 We must do this call two times to get reliable values (hw bug). */
256 ret = anysee_get_hw_info(adap->dev, hw_info);
259 ret = anysee_get_hw_info(adap->dev, hw_info);
263 /* Meaning of these info bytes are guessed. */
264 info("firmware version:%d.%d.%d hardware id:%d",
265 0, hw_info[1], hw_info[2], hw_info[0]);
267 ret = anysee_read_reg(adap->dev, 0xb0, &io_d); /* IO port D */
270 deb_info("%s: IO port D:%02x\n", __func__, io_d);
272 /* Select demod using trial and error method. */
274 /* Try to attach demodulator in following order:
275 model demod hw firmware
276 1. E30 MT352 02 0.2.1
277 2. E30 ZL10353 02 0.2.1
278 3. E30 Combo ZL10353 0f 0.1.2 DVB-T/C combo
279 4. E30 Plus ZL10353 06 0.1.0
280 5. E30C Plus TDA10023 0a 0.1.0 rev 0.2
281 E30C Plus TDA10023 0f 0.1.2 rev 0.4
282 E30 Combo TDA10023 0f 0.1.2 DVB-T/C combo
285 /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */
286 adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
287 &adap->dev->i2c_adap);
288 if (adap->fe != NULL) {
289 state->tuner = DVB_PLL_THOMSON_DTT7579;
293 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */
294 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
295 &adap->dev->i2c_adap);
296 if (adap->fe != NULL) {
297 state->tuner = DVB_PLL_THOMSON_DTT7579;
301 /* for E30 Combo Plus DVB-T demodulator */
302 if (dvb_usb_anysee_delsys) {
303 ret = anysee_write_reg(adap->dev, 0xb0, 0x01);
307 /* Zarlink ZL10353 DVB-T demod */
308 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
309 &adap->dev->i2c_adap);
310 if (adap->fe != NULL) {
311 state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A;
316 /* connect demod on IO port D for TDA10023 & ZL10353 */
317 ret = anysee_write_reg(adap->dev, 0xb0, 0x25);
321 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */
322 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
323 &adap->dev->i2c_adap);
324 if (adap->fe != NULL) {
325 state->tuner = DVB_PLL_THOMSON_DTT7579;
329 /* IO port E - E30C rev 0.4 board requires this */
330 ret = anysee_write_reg(adap->dev, 0xb1, 0xa7);
334 /* Philips TDA10023 DVB-C demod */
335 adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
336 &adap->dev->i2c_adap, 0x48);
337 if (adap->fe != NULL) {
338 state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A;
342 /* return IO port D to init value for safe */
343 ret = anysee_write_reg(adap->dev, 0xb0, io_d);
347 err("Unkown Anysee version: %02x %02x %02x. "\
348 "Please report the <linux-dvb@linuxtv.org>.",
349 hw_info[0], hw_info[1], hw_info[2]);
354 static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
356 struct anysee_state *state = adap->dev->priv;
357 deb_info("%s: \n", __func__);
359 switch (state->tuner) {
360 case DVB_PLL_THOMSON_DTT7579:
361 /* Thomson dtt7579 (not sure) PLL inside of:
362 Samsung DNOS404ZH102A NIM
363 Samsung DNOS404ZH103A NIM */
364 dvb_attach(dvb_pll_attach, adap->fe, 0x61,
365 NULL, DVB_PLL_THOMSON_DTT7579);
367 case DVB_PLL_SAMSUNG_DTOS403IH102A:
368 /* Unknown PLL inside of Samsung DTOS403IH102A tuner module */
369 dvb_attach(dvb_pll_attach, adap->fe, 0xc0,
370 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
377 static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
379 u8 buf[] = {CMD_GET_IR_CODE};
380 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
384 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &ircode[0], 2);
389 *state = REMOTE_NO_KEY_PRESSED;
391 for (i = 0; i < d->props.rc_key_map_size; i++) {
392 if (keymap[i].custom == ircode[0] &&
393 keymap[i].data == ircode[1]) {
394 *event = keymap[i].event;
395 *state = REMOTE_KEY_PRESSED;
402 static struct dvb_usb_rc_key anysee_rc_keys[] = {
403 { 0x01, 0x00, KEY_0 },
404 { 0x01, 0x01, KEY_1 },
405 { 0x01, 0x02, KEY_2 },
406 { 0x01, 0x03, KEY_3 },
407 { 0x01, 0x04, KEY_4 },
408 { 0x01, 0x05, KEY_5 },
409 { 0x01, 0x06, KEY_6 },
410 { 0x01, 0x07, KEY_7 },
411 { 0x01, 0x08, KEY_8 },
412 { 0x01, 0x09, KEY_9 },
413 { 0x01, 0x0a, KEY_POWER },
414 { 0x01, 0x0b, KEY_DOCUMENTS }, /* * */
415 { 0x01, 0x19, KEY_FAVORITES },
416 { 0x01, 0x20, KEY_SLEEP },
417 { 0x01, 0x21, KEY_MODE }, /* 4:3 / 16:9 select */
418 { 0x01, 0x22, KEY_ZOOM },
419 { 0x01, 0x47, KEY_TEXT },
420 { 0x01, 0x16, KEY_TV }, /* TV / radio select */
421 { 0x01, 0x1e, KEY_LANGUAGE }, /* Second Audio Program */
422 { 0x01, 0x1a, KEY_SUBTITLE },
423 { 0x01, 0x1b, KEY_CAMERA }, /* screenshot */
424 { 0x01, 0x42, KEY_MUTE },
425 { 0x01, 0x0e, KEY_MENU },
426 { 0x01, 0x0f, KEY_EPG },
427 { 0x01, 0x17, KEY_INFO },
428 { 0x01, 0x10, KEY_EXIT },
429 { 0x01, 0x13, KEY_VOLUMEUP },
430 { 0x01, 0x12, KEY_VOLUMEDOWN },
431 { 0x01, 0x11, KEY_CHANNELUP },
432 { 0x01, 0x14, KEY_CHANNELDOWN },
433 { 0x01, 0x15, KEY_OK },
434 { 0x01, 0x1d, KEY_RED },
435 { 0x01, 0x1f, KEY_GREEN },
436 { 0x01, 0x1c, KEY_YELLOW },
437 { 0x01, 0x44, KEY_BLUE },
438 { 0x01, 0x0c, KEY_SHUFFLE }, /* snapshot */
439 { 0x01, 0x48, KEY_STOP },
440 { 0x01, 0x50, KEY_PLAY },
441 { 0x01, 0x51, KEY_PAUSE },
442 { 0x01, 0x49, KEY_RECORD },
443 { 0x01, 0x18, KEY_PREVIOUS }, /* |<< */
444 { 0x01, 0x0d, KEY_NEXT }, /* >>| */
445 { 0x01, 0x24, KEY_PROG1 }, /* F1 */
446 { 0x01, 0x25, KEY_PROG2 }, /* F2 */
449 /* DVB USB Driver stuff */
450 static struct dvb_usb_device_properties anysee_properties;
452 static int anysee_probe(struct usb_interface *intf,
453 const struct usb_device_id *id)
455 struct dvb_usb_device *d;
456 struct usb_host_interface *alt;
459 /* There is one interface with two alternate settings.
460 Alternate setting 0 is for bulk transfer.
461 Alternate setting 1 is for isochronous transfer.
462 We use bulk transfer (alternate setting 0). */
463 if (intf->num_altsetting < 1)
466 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
471 alt = usb_altnum_to_altsetting(intf, 0);
473 deb_info("%s: no alt found!\n", __func__);
477 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
478 alt->desc.bAlternateSetting);
483 ret = anysee_init(d);
488 static struct usb_device_id anysee_table [] = {
489 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
490 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
491 { } /* Terminating entry */
493 MODULE_DEVICE_TABLE(usb, anysee_table);
495 static struct dvb_usb_device_properties anysee_properties = {
496 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
498 .usb_ctrl = DEVICE_SPECIFIC,
500 .size_of_priv = sizeof(struct anysee_state),
505 .streaming_ctrl = anysee_streaming_ctrl,
506 .frontend_attach = anysee_frontend_attach,
507 .tuner_attach = anysee_tuner_attach,
521 .rc_key_map = anysee_rc_keys,
522 .rc_key_map_size = ARRAY_SIZE(anysee_rc_keys),
523 .rc_query = anysee_rc_query,
524 .rc_interval = 200, /* windows driver uses 500ms */
526 .i2c_algo = &anysee_i2c_algo,
528 .generic_bulk_ctrl_endpoint = 1,
530 .num_device_descs = 1,
533 .name = "Anysee DVB USB2.0",
535 .warm_ids = {&anysee_table[0],
536 &anysee_table[1], NULL},
541 static struct usb_driver anysee_driver = {
542 .name = "dvb_usb_anysee",
543 .probe = anysee_probe,
544 .disconnect = dvb_usb_device_exit,
545 .id_table = anysee_table,
549 static int __init anysee_module_init(void)
553 ret = usb_register(&anysee_driver);
555 err("%s: usb_register failed. Error number %d", __func__, ret);
560 static void __exit anysee_module_exit(void)
562 /* deregister this driver from the USB subsystem */
563 usb_deregister(&anysee_driver);
566 module_init(anysee_module_init);
567 module_exit(anysee_module_exit);
569 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
570 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
571 MODULE_LICENSE("GPL");