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 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
46 static 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,
230 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
234 static struct mt352_config anysee_mt352_config = {
235 .demod_address = 0x1e,
236 .demod_init = anysee_mt352_demod_init,
239 static struct zl10353_config anysee_zl10353_config = {
240 .demod_address = 0x1e,
244 static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
247 struct anysee_state *state = adap->dev->priv;
249 u8 io_d; /* IO port D */
251 /* check which hardware we have
252 We must do this call two times to get reliable values (hw bug). */
253 ret = anysee_get_hw_info(adap->dev, hw_info);
256 ret = anysee_get_hw_info(adap->dev, hw_info);
260 /* Meaning of these info bytes are guessed. */
261 info("firmware version:%d.%d.%d hardware id:%d",
262 0, hw_info[1], hw_info[2], hw_info[0]);
264 ret = anysee_read_reg(adap->dev, 0xb0, &io_d); /* IO port D */
267 deb_info("%s: IO port D:%02x\n", __func__, io_d);
269 /* Select demod using trial and error method. */
271 /* Try to attach demodulator in following order:
272 model demod hw firmware
273 1. E30 MT352 02 0.2.1
274 2. E30 ZL10353 02 0.2.1
275 3. E30 Plus ZL10353 06 0.1.0
276 4. E30C Plus TDA10023 0a 0.1.0 rev 0.2
277 4. E30C Plus TDA10023 0f 0.1.2 rev 0.4
280 /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */
281 adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
282 &adap->dev->i2c_adap);
283 if (adap->fe != NULL) {
284 state->tuner = DVB_PLL_THOMSON_DTT7579;
288 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */
289 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
290 &adap->dev->i2c_adap);
291 if (adap->fe != NULL) {
292 state->tuner = DVB_PLL_THOMSON_DTT7579;
296 /* connect demod on IO port D for TDA10023 & ZL10353 */
297 ret = anysee_write_reg(adap->dev, 0xb0, 0x25);
301 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */
302 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
303 &adap->dev->i2c_adap);
304 if (adap->fe != NULL) {
305 state->tuner = DVB_PLL_THOMSON_DTT7579;
309 /* IO port E - E30C rev 0.4 board requires this */
310 ret = anysee_write_reg(adap->dev, 0xb1, 0xa7);
314 /* Philips TDA10023 DVB-C demod */
315 adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
316 &adap->dev->i2c_adap, 0x48);
317 if (adap->fe != NULL) {
318 state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A;
322 /* return IO port D to init value for safe */
323 ret = anysee_write_reg(adap->dev, 0xb0, io_d);
327 err("Unkown Anysee version: %02x %02x %02x. "\
328 "Please report the <linux-dvb@linuxtv.org>.",
329 hw_info[0], hw_info[1], hw_info[2]);
334 static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
336 struct anysee_state *state = adap->dev->priv;
337 deb_info("%s: \n", __func__);
339 switch (state->tuner) {
340 case DVB_PLL_THOMSON_DTT7579:
341 /* Thomson dtt7579 (not sure) PLL inside of:
342 Samsung DNOS404ZH102A NIM
343 Samsung DNOS404ZH103A NIM */
344 dvb_attach(dvb_pll_attach, adap->fe, 0x61,
345 NULL, DVB_PLL_THOMSON_DTT7579);
347 case DVB_PLL_SAMSUNG_DTOS403IH102A:
348 /* Unknown PLL inside of Samsung DTOS403IH102A tuner module */
349 dvb_attach(dvb_pll_attach, adap->fe, 0xc0,
350 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
357 static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
359 u8 buf[] = {CMD_GET_IR_CODE};
360 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
364 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &ircode[0], 2);
369 *state = REMOTE_NO_KEY_PRESSED;
371 for (i = 0; i < d->props.rc_key_map_size; i++) {
372 if (keymap[i].custom == ircode[0] &&
373 keymap[i].data == ircode[1]) {
374 *event = keymap[i].event;
375 *state = REMOTE_KEY_PRESSED;
382 static struct dvb_usb_rc_key anysee_rc_keys[] = {
383 { 0x01, 0x00, KEY_0 },
384 { 0x01, 0x01, KEY_1 },
385 { 0x01, 0x02, KEY_2 },
386 { 0x01, 0x03, KEY_3 },
387 { 0x01, 0x04, KEY_4 },
388 { 0x01, 0x05, KEY_5 },
389 { 0x01, 0x06, KEY_6 },
390 { 0x01, 0x07, KEY_7 },
391 { 0x01, 0x08, KEY_8 },
392 { 0x01, 0x09, KEY_9 },
393 { 0x01, 0x0a, KEY_POWER },
394 { 0x01, 0x0b, KEY_DOCUMENTS }, /* * */
395 { 0x01, 0x19, KEY_FAVORITES },
396 { 0x01, 0x20, KEY_SLEEP },
397 { 0x01, 0x21, KEY_MODE }, /* 4:3 / 16:9 select */
398 { 0x01, 0x22, KEY_ZOOM },
399 { 0x01, 0x47, KEY_TEXT },
400 { 0x01, 0x16, KEY_TV }, /* TV / radio select */
401 { 0x01, 0x1e, KEY_LANGUAGE }, /* Second Audio Program */
402 { 0x01, 0x1a, KEY_SUBTITLE },
403 { 0x01, 0x1b, KEY_CAMERA }, /* screenshot */
404 { 0x01, 0x42, KEY_MUTE },
405 { 0x01, 0x0e, KEY_MENU },
406 { 0x01, 0x0f, KEY_EPG },
407 { 0x01, 0x17, KEY_INFO },
408 { 0x01, 0x10, KEY_EXIT },
409 { 0x01, 0x13, KEY_VOLUMEUP },
410 { 0x01, 0x12, KEY_VOLUMEDOWN },
411 { 0x01, 0x11, KEY_CHANNELUP },
412 { 0x01, 0x14, KEY_CHANNELDOWN },
413 { 0x01, 0x15, KEY_OK },
414 { 0x01, 0x1d, KEY_RED },
415 { 0x01, 0x1f, KEY_GREEN },
416 { 0x01, 0x1c, KEY_YELLOW },
417 { 0x01, 0x44, KEY_BLUE },
418 { 0x01, 0x0c, KEY_SHUFFLE }, /* snapshot */
419 { 0x01, 0x48, KEY_STOP },
420 { 0x01, 0x50, KEY_PLAY },
421 { 0x01, 0x51, KEY_PAUSE },
422 { 0x01, 0x49, KEY_RECORD },
423 { 0x01, 0x18, KEY_PREVIOUS }, /* |<< */
424 { 0x01, 0x0d, KEY_NEXT }, /* >>| */
425 { 0x01, 0x24, KEY_PROG1 }, /* F1 */
426 { 0x01, 0x25, KEY_PROG2 }, /* F2 */
429 /* DVB USB Driver stuff */
430 static struct dvb_usb_device_properties anysee_properties;
432 static int anysee_probe(struct usb_interface *intf,
433 const struct usb_device_id *id)
435 struct dvb_usb_device *d;
436 struct usb_host_interface *alt;
439 mutex_init(&anysee_usb_mutex);
441 /* There is one interface with two alternate settings.
442 Alternate setting 0 is for bulk transfer.
443 Alternate setting 1 is for isochronous transfer.
444 We use bulk transfer (alternate setting 0). */
445 if (intf->num_altsetting < 1)
448 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
453 alt = usb_altnum_to_altsetting(intf, 0);
455 deb_info("%s: no alt found!\n", __func__);
459 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
460 alt->desc.bAlternateSetting);
465 ret = anysee_init(d);
470 static struct usb_device_id anysee_table [] = {
471 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
472 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
473 { } /* Terminating entry */
475 MODULE_DEVICE_TABLE(usb, anysee_table);
477 static struct dvb_usb_device_properties anysee_properties = {
478 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
480 .usb_ctrl = DEVICE_SPECIFIC,
482 .size_of_priv = sizeof(struct anysee_state),
487 .streaming_ctrl = anysee_streaming_ctrl,
488 .frontend_attach = anysee_frontend_attach,
489 .tuner_attach = anysee_tuner_attach,
503 .rc_key_map = anysee_rc_keys,
504 .rc_key_map_size = ARRAY_SIZE(anysee_rc_keys),
505 .rc_query = anysee_rc_query,
506 .rc_interval = 200, /* windows driver uses 500ms */
508 .i2c_algo = &anysee_i2c_algo,
510 .generic_bulk_ctrl_endpoint = 1,
512 .num_device_descs = 1,
515 .name = "Anysee DVB USB2.0",
517 .warm_ids = {&anysee_table[0],
518 &anysee_table[1], NULL},
523 static struct usb_driver anysee_driver = {
524 .name = "dvb_usb_anysee",
525 .probe = anysee_probe,
526 .disconnect = dvb_usb_device_exit,
527 .id_table = anysee_table,
531 static int __init anysee_module_init(void)
535 ret = usb_register(&anysee_driver);
537 err("%s: usb_register failed. Error number %d", __func__, ret);
542 static void __exit anysee_module_exit(void)
544 /* deregister this driver from the USB subsystem */
545 usb_deregister(&anysee_driver);
548 module_init(anysee_module_init);
549 module_exit(anysee_module_exit);
551 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
552 MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
553 MODULE_LICENSE("GPL");