1 /* DVB USB framework compliant Linux driver for the
2 * DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
3 * TeVii S600, S650 Cards
4 * Copyright (C) 2008,2009 Igor M. Liplianin (liplianin@me.by)
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, version 2.
10 * see Documentation/dvb/README.dvb-usb for more information
22 #ifndef USB_PID_DW2102
23 #define USB_PID_DW2102 0x2102
26 #ifndef USB_PID_DW2104
27 #define USB_PID_DW2104 0x2104
30 #ifndef USB_PID_DW3101
31 #define USB_PID_DW3101 0x3101
34 #ifndef USB_PID_CINERGY_S
35 #define USB_PID_CINERGY_S 0x0064
38 #ifndef USB_PID_TEVII_S650
39 #define USB_PID_TEVII_S650 0xd650
42 #define DW210X_READ_MSG 0
43 #define DW210X_WRITE_MSG 1
45 #define REG_1F_SYMBOLRATE_BYTE0 0x1f
46 #define REG_20_SYMBOLRATE_BYTE1 0x20
47 #define REG_21_SYMBOLRATE_BYTE2 0x21
49 #define DW2102_VOLTAGE_CTRL (0x1800)
50 #define DW2102_RC_QUERY (0x1a00)
52 struct dvb_usb_rc_keys_table {
53 struct dvb_usb_rc_key *rc_keys;
58 static int dvb_usb_dw2102_debug;
59 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
60 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
61 DVB_USB_DEBUG_STATUS);
65 module_param_named(keymap, ir_keymap, int, 0644);
66 MODULE_PARM_DESC(keymap, "set keymap 0=default 1=dvbworld 2=tevii 3=tbs ...");
68 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
70 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
71 u16 index, u8 * data, u16 len, int flags)
76 unsigned int pipe = (flags == DW210X_READ_MSG) ?
77 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
78 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
80 if (flags == DW210X_WRITE_MSG)
81 memcpy(u8buf, data, len);
82 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
83 value, index , u8buf, len, 2000);
85 if (flags == DW210X_READ_MSG)
86 memcpy(data, u8buf, len);
91 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
94 struct dvb_usb_device *d = i2c_get_adapdata(adap);
96 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
101 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
106 /* read stv0299 register */
107 value = msg[0].buf[0];/* register */
108 for (i = 0; i < msg[1].len; i++) {
110 ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
111 buf6, 2, DW210X_READ_MSG);
112 msg[1].buf[i] = buf6[0];
116 switch (msg[0].addr) {
118 /* write to stv0299 register */
120 buf6[1] = msg[0].buf[0];
121 buf6[2] = msg[0].buf[1];
122 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
123 buf6, 3, DW210X_WRITE_MSG);
126 if (msg[0].flags == 0) {
127 /* write to tuner pll */
131 buf6[3] = msg[0].buf[0];
132 buf6[4] = msg[0].buf[1];
133 buf6[5] = msg[0].buf[2];
134 buf6[6] = msg[0].buf[3];
135 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
136 buf6, 7, DW210X_WRITE_MSG);
138 /* read from tuner */
139 ret = dw210x_op_rw(d->udev, 0xb5, 0, 0,
140 buf6, 1, DW210X_READ_MSG);
141 msg[0].buf[0] = buf6[0];
144 case (DW2102_RC_QUERY):
145 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
146 buf6, 2, DW210X_READ_MSG);
147 msg[0].buf[0] = buf6[0];
148 msg[0].buf[1] = buf6[1];
150 case (DW2102_VOLTAGE_CTRL):
152 buf6[1] = msg[0].buf[0];
153 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
154 buf6, 2, DW210X_WRITE_MSG);
161 mutex_unlock(&d->i2c_mutex);
165 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
166 struct i2c_msg msg[], int num)
168 struct dvb_usb_device *d = i2c_get_adapdata(adap);
170 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
174 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
179 /* read si2109 register by number */
181 buf6[1] = msg[0].len;
182 buf6[2] = msg[0].buf[0];
183 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
184 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
185 /* read si2109 register */
186 ret = dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
187 buf6, msg[1].len + 2, DW210X_READ_MSG);
188 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
192 switch (msg[0].addr) {
194 /* write to si2109 register */
196 buf6[1] = msg[0].len;
197 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
198 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
199 msg[0].len + 2, DW210X_WRITE_MSG);
201 case(DW2102_RC_QUERY):
202 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
203 buf6, 2, DW210X_READ_MSG);
204 msg[0].buf[0] = buf6[0];
205 msg[0].buf[1] = buf6[1];
207 case(DW2102_VOLTAGE_CTRL):
209 buf6[1] = msg[0].buf[0];
210 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
211 buf6, 2, DW210X_WRITE_MSG);
217 mutex_unlock(&d->i2c_mutex);
221 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
223 struct dvb_usb_device *d = i2c_get_adapdata(adap);
228 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
234 /* first write first register number */
235 u8 ibuf[msg[1].len + 2], obuf[3];
237 obuf[1] = msg[0].len;
238 obuf[2] = msg[0].buf[0];
239 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
240 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
241 /* second read registers */
242 ret = dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
243 ibuf, msg[1].len + 2, DW210X_READ_MSG);
244 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
249 switch (msg[0].addr) {
251 /* write to register */
252 u8 obuf[msg[0].len + 2];
254 obuf[1] = msg[0].len;
255 memcpy(obuf + 2, msg[0].buf, msg[0].len);
256 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
257 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
262 u8 obuf[msg[0].len + 2];
264 obuf[1] = msg[0].len;
265 memcpy(obuf + 2, msg[0].buf, msg[0].len);
266 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
267 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
270 case(DW2102_RC_QUERY): {
272 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
273 ibuf, 2, DW210X_READ_MSG);
274 memcpy(msg[0].buf, ibuf , 2);
277 case(DW2102_VOLTAGE_CTRL): {
280 obuf[1] = msg[0].buf[0];
281 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
282 obuf, 2, DW210X_WRITE_MSG);
290 mutex_unlock(&d->i2c_mutex);
294 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
296 struct dvb_usb_device *d = i2c_get_adapdata(adap);
302 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
308 /* first write first register number */
309 u8 ibuf[msg[1].len + 2], obuf[3];
311 obuf[1] = msg[0].len;
312 obuf[2] = msg[0].buf[0];
313 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
314 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
315 /* second read registers */
316 ret = dw210x_op_rw(d->udev, 0xc3, 0xab , 0,
317 ibuf, msg[1].len + 2, DW210X_READ_MSG);
318 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
323 switch (msg[0].addr) {
325 if (msg[0].buf[0] == 0xf7) {
327 /* Write in small blocks */
332 len = msg[0].len - 1;
335 memcpy(obuf + 3, msg[0].buf + i, (len > 16 ? 16 : len));
336 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
337 obuf, (len > 16 ? 16 : len) + 3, DW210X_WRITE_MSG);
342 /* write to register */
343 u8 obuf[msg[0].len + 2];
345 obuf[1] = msg[0].len;
346 memcpy(obuf + 2, msg[0].buf, msg[0].len);
347 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
348 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
352 case(DW2102_RC_QUERY): {
354 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
355 ibuf, 2, DW210X_READ_MSG);
356 memcpy(msg[0].buf, ibuf , 2);
359 case(DW2102_VOLTAGE_CTRL): {
362 obuf[1] = msg[0].buf[0];
363 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
364 obuf, 2, DW210X_WRITE_MSG);
372 mutex_unlock(&d->i2c_mutex);
376 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
379 struct dvb_usb_device *d = i2c_get_adapdata(adap);
384 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
390 /* first write first register number */
391 u8 ibuf[msg[1].len + 2], obuf[3];
392 obuf[0] = msg[0].addr << 1;
393 obuf[1] = msg[0].len;
394 obuf[2] = msg[0].buf[0];
395 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
396 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
397 /* second read registers */
398 ret = dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
399 ibuf, msg[1].len + 2, DW210X_READ_MSG);
400 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
405 switch (msg[0].addr) {
408 /* write to register */
409 u8 obuf[msg[0].len + 2];
410 obuf[0] = msg[0].addr << 1;
411 obuf[1] = msg[0].len;
412 memcpy(obuf + 2, msg[0].buf, msg[0].len);
413 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
414 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
417 case(DW2102_RC_QUERY): {
419 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
420 ibuf, 2, DW210X_READ_MSG);
421 memcpy(msg[0].buf, ibuf , 2);
429 for (i = 0; i < num; i++) {
430 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
431 msg[i].flags == 0 ? ">>>" : "<<<");
432 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
435 mutex_unlock(&d->i2c_mutex);
439 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
444 static struct i2c_algorithm dw2102_i2c_algo = {
445 .master_xfer = dw2102_i2c_transfer,
446 .functionality = dw210x_i2c_func,
449 static struct i2c_algorithm dw2102_serit_i2c_algo = {
450 .master_xfer = dw2102_serit_i2c_transfer,
451 .functionality = dw210x_i2c_func,
454 static struct i2c_algorithm dw2102_earda_i2c_algo = {
455 .master_xfer = dw2102_earda_i2c_transfer,
456 .functionality = dw210x_i2c_func,
459 static struct i2c_algorithm dw2104_i2c_algo = {
460 .master_xfer = dw2104_i2c_transfer,
461 .functionality = dw210x_i2c_func,
464 static struct i2c_algorithm dw3101_i2c_algo = {
465 .master_xfer = dw3101_i2c_transfer,
466 .functionality = dw210x_i2c_func,
469 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
473 u8 eeprom[256], eepromline[16];
475 for (i = 0; i < 256; i++) {
476 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
477 err("read eeprom failed.");
480 eepromline[i%16] = ibuf[0];
483 if ((i % 16) == 15) {
484 deb_xfer("%02x: ", i - 15);
485 debug_dump(eepromline, 16, deb_xfer);
489 memcpy(mac, eeprom + 8, 6);
493 static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
495 static u8 command_13v[1] = {0x00};
496 static u8 command_18v[1] = {0x01};
497 struct i2c_msg msg[] = {
498 {.addr = DW2102_VOLTAGE_CTRL, .flags = 0,
499 .buf = command_13v, .len = 1},
502 struct dvb_usb_adapter *udev_adap =
503 (struct dvb_usb_adapter *)(fe->dvb->priv);
504 if (voltage == SEC_VOLTAGE_18)
505 msg[0].buf = command_18v;
506 i2c_transfer(&udev_adap->dev->i2c_adap, msg, 1);
510 static struct stv0299_config sharp_z0194a_config = {
511 .demod_address = 0x68,
512 .inittab = sharp_z0194a_inittab,
516 .lock_output = STV0299_LOCKOUTPUT_1,
517 .volt13_op0_op1 = STV0299_VOLT13_OP1,
519 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
522 static struct cx24116_config dw2104_config = {
523 .demod_address = 0x55,
524 .mpg_clk_pos_pol = 0x01,
527 static struct si21xx_config serit_sp1511lhb_config = {
528 .demod_address = 0x68,
533 static struct tda10023_config dw3101_tda10023_config = {
534 .demod_address = 0x0c,
538 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
540 if ((d->fe = dvb_attach(cx24116_attach, &dw2104_config,
541 &d->dev->i2c_adap)) != NULL) {
542 d->fe->ops.set_voltage = dw210x_set_voltage;
543 info("Attached cx24116!\n");
549 static struct dvb_usb_device_properties dw2102_properties;
550 static struct dvb_usb_device_properties dw2104_properties;
552 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
554 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
555 /*dw2102_properties.adapter->tuner_attach = NULL;*/
556 d->fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
559 d->fe->ops.set_voltage = dw210x_set_voltage;
560 info("Attached si21xx!\n");
564 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
565 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
566 d->fe = dvb_attach(stv0288_attach, &earda_config,
569 d->fe->ops.set_voltage = dw210x_set_voltage;
570 info("Attached stv0288!\n");
575 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
576 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
577 d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
580 d->fe->ops.set_voltage = dw210x_set_voltage;
581 info("Attached stv0299!\n");
588 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
590 d->fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
591 &d->dev->i2c_adap, 0x48);
593 info("Attached tda10023!\n");
599 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
601 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
602 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
606 static int dw2102_earda_tuner_attach(struct dvb_usb_adapter *adap)
608 dvb_attach(stb6000_attach, adap->fe, 0x61,
609 &adap->dev->i2c_adap);
614 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
616 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
617 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
622 static struct dvb_usb_rc_key dw210x_rc_keys[] = {
623 { 0xf8, 0x0a, KEY_Q }, /*power*/
624 { 0xf8, 0x0c, KEY_M }, /*mute*/
625 { 0xf8, 0x11, KEY_1 },
626 { 0xf8, 0x12, KEY_2 },
627 { 0xf8, 0x13, KEY_3 },
628 { 0xf8, 0x14, KEY_4 },
629 { 0xf8, 0x15, KEY_5 },
630 { 0xf8, 0x16, KEY_6 },
631 { 0xf8, 0x17, KEY_7 },
632 { 0xf8, 0x18, KEY_8 },
633 { 0xf8, 0x19, KEY_9 },
634 { 0xf8, 0x10, KEY_0 },
635 { 0xf8, 0x1c, KEY_PAGEUP }, /*ch+*/
636 { 0xf8, 0x0f, KEY_PAGEDOWN }, /*ch-*/
637 { 0xf8, 0x1a, KEY_O }, /*vol+*/
638 { 0xf8, 0x0e, KEY_Z }, /*vol-*/
639 { 0xf8, 0x04, KEY_R }, /*rec*/
640 { 0xf8, 0x09, KEY_D }, /*fav*/
641 { 0xf8, 0x08, KEY_BACKSPACE }, /*rewind*/
642 { 0xf8, 0x07, KEY_A }, /*fast*/
643 { 0xf8, 0x0b, KEY_P }, /*pause*/
644 { 0xf8, 0x02, KEY_ESC }, /*cancel*/
645 { 0xf8, 0x03, KEY_G }, /*tab*/
646 { 0xf8, 0x00, KEY_UP }, /*up*/
647 { 0xf8, 0x1f, KEY_ENTER }, /*ok*/
648 { 0xf8, 0x01, KEY_DOWN }, /*down*/
649 { 0xf8, 0x05, KEY_C }, /*cap*/
650 { 0xf8, 0x06, KEY_S }, /*stop*/
651 { 0xf8, 0x40, KEY_F }, /*full*/
652 { 0xf8, 0x1e, KEY_W }, /*tvmode*/
653 { 0xf8, 0x1b, KEY_B }, /*recall*/
656 static struct dvb_usb_rc_key tevii_rc_keys[] = {
657 { 0xf8, 0x0a, KEY_POWER },
658 { 0xf8, 0x0c, KEY_MUTE },
659 { 0xf8, 0x11, KEY_1 },
660 { 0xf8, 0x12, KEY_2 },
661 { 0xf8, 0x13, KEY_3 },
662 { 0xf8, 0x14, KEY_4 },
663 { 0xf8, 0x15, KEY_5 },
664 { 0xf8, 0x16, KEY_6 },
665 { 0xf8, 0x17, KEY_7 },
666 { 0xf8, 0x18, KEY_8 },
667 { 0xf8, 0x19, KEY_9 },
668 { 0xf8, 0x10, KEY_0 },
669 { 0xf8, 0x1c, KEY_MENU },
670 { 0xf8, 0x0f, KEY_VOLUMEDOWN },
671 { 0xf8, 0x1a, KEY_LAST },
672 { 0xf8, 0x0e, KEY_OPEN },
673 { 0xf8, 0x04, KEY_RECORD },
674 { 0xf8, 0x09, KEY_VOLUMEUP },
675 { 0xf8, 0x08, KEY_CHANNELUP },
676 { 0xf8, 0x07, KEY_PVR },
677 { 0xf8, 0x0b, KEY_TIME },
678 { 0xf8, 0x02, KEY_RIGHT },
679 { 0xf8, 0x03, KEY_LEFT },
680 { 0xf8, 0x00, KEY_UP },
681 { 0xf8, 0x1f, KEY_OK },
682 { 0xf8, 0x01, KEY_DOWN },
683 { 0xf8, 0x05, KEY_TUNER },
684 { 0xf8, 0x06, KEY_CHANNELDOWN },
685 { 0xf8, 0x40, KEY_PLAYPAUSE },
686 { 0xf8, 0x1e, KEY_REWIND },
687 { 0xf8, 0x1b, KEY_FAVORITES },
688 { 0xf8, 0x1d, KEY_BACK },
689 { 0xf8, 0x4d, KEY_FASTFORWARD },
690 { 0xf8, 0x44, KEY_EPG },
691 { 0xf8, 0x4c, KEY_INFO },
692 { 0xf8, 0x41, KEY_AB },
693 { 0xf8, 0x43, KEY_AUDIO },
694 { 0xf8, 0x45, KEY_SUBTITLE },
695 { 0xf8, 0x4a, KEY_LIST },
696 { 0xf8, 0x46, KEY_F1 },
697 { 0xf8, 0x47, KEY_F2 },
698 { 0xf8, 0x5e, KEY_F3 },
699 { 0xf8, 0x5c, KEY_F4 },
700 { 0xf8, 0x52, KEY_F5 },
701 { 0xf8, 0x5a, KEY_F6 },
702 { 0xf8, 0x56, KEY_MODE },
703 { 0xf8, 0x58, KEY_SWITCHVIDEOMODE },
706 static struct dvb_usb_rc_key tbs_rc_keys[] = {
707 { 0xf8, 0x84, KEY_POWER },
708 { 0xf8, 0x94, KEY_MUTE },
709 { 0xf8, 0x87, KEY_1 },
710 { 0xf8, 0x86, KEY_2 },
711 { 0xf8, 0x85, KEY_3 },
712 { 0xf8, 0x8b, KEY_4 },
713 { 0xf8, 0x8a, KEY_5 },
714 { 0xf8, 0x89, KEY_6 },
715 { 0xf8, 0x8f, KEY_7 },
716 { 0xf8, 0x8e, KEY_8 },
717 { 0xf8, 0x8d, KEY_9 },
718 { 0xf8, 0x92, KEY_0 },
719 { 0xf8, 0x96, KEY_CHANNELUP },
720 { 0xf8, 0x91, KEY_CHANNELDOWN },
721 { 0xf8, 0x93, KEY_VOLUMEUP },
722 { 0xf8, 0x8c, KEY_VOLUMEDOWN },
723 { 0xf8, 0x83, KEY_RECORD },
724 { 0xf8, 0x98, KEY_PAUSE },
725 { 0xf8, 0x99, KEY_OK },
726 { 0xf8, 0x9a, KEY_SHUFFLE },
727 { 0xf8, 0x81, KEY_UP },
728 { 0xf8, 0x90, KEY_LEFT },
729 { 0xf8, 0x82, KEY_RIGHT },
730 { 0xf8, 0x88, KEY_DOWN },
731 { 0xf8, 0x95, KEY_FAVORITES },
732 { 0xf8, 0x97, KEY_SUBTITLE },
733 { 0xf8, 0x9d, KEY_ZOOM },
734 { 0xf8, 0x9f, KEY_EXIT },
735 { 0xf8, 0x9e, KEY_MENU },
736 { 0xf8, 0x9c, KEY_EPG },
737 { 0xf8, 0x80, KEY_PREVIOUS },
738 { 0xf8, 0x9b, KEY_MODE }
741 static struct dvb_usb_rc_keys_table keys_tables[] = {
742 { dw210x_rc_keys, ARRAY_SIZE(dw210x_rc_keys) },
743 { tevii_rc_keys, ARRAY_SIZE(tevii_rc_keys) },
744 { tbs_rc_keys, ARRAY_SIZE(tbs_rc_keys) },
747 static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
749 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
750 int keymap_size = d->props.rc_key_map_size;
752 struct i2c_msg msg = {
753 .addr = DW2102_RC_QUERY,
759 /* override keymap */
760 if ((ir_keymap > 0) && (ir_keymap <= ARRAY_SIZE(keys_tables))) {
761 keymap = keys_tables[ir_keymap - 1].rc_keys ;
762 keymap_size = keys_tables[ir_keymap - 1].rc_keys_size;
765 *state = REMOTE_NO_KEY_PRESSED;
766 if (dw2102_i2c_transfer(&d->i2c_adap, &msg, 1) == 1) {
767 for (i = 0; i < keymap_size ; i++) {
768 if (keymap[i].data == msg.buf[0]) {
769 *state = REMOTE_KEY_PRESSED;
770 *event = keymap[i].event;
776 if ((*state) == REMOTE_KEY_PRESSED)
777 deb_rc("%s: found rc key: %x, %x, event: %x\n",
778 __func__, key[0], key[1], (*event));
779 else if (key[0] != 0xff)
780 deb_rc("%s: unknown rc key: %x, %x\n",
781 __func__, key[0], key[1]);
788 static struct usb_device_id dw2102_table[] = {
789 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
790 {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
791 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
792 {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
793 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_CINERGY_S)},
794 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
798 MODULE_DEVICE_TABLE(usb, dw2102_table);
800 static int dw2102_load_firmware(struct usb_device *dev,
801 const struct firmware *frmwr)
806 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
807 const struct firmware *fw;
808 const char *filename = "dvb-usb-dw2101.fw";
809 switch (dev->descriptor.idProduct) {
811 ret = request_firmware(&fw, filename, &dev->dev);
813 err("did not find the firmware file. (%s) "
814 "Please see linux/Documentation/dvb/ for more details "
815 "on firmware-problems.", filename);
823 info("start downloading DW210X firmware");
824 p = kmalloc(fw->size, GFP_KERNEL);
827 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
828 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
831 memcpy(p, fw->data, fw->size);
832 for (i = 0; i < fw->size; i += 0x40) {
834 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
835 DW210X_WRITE_MSG) != 0x40) {
836 err("error while transferring firmware");
841 /* restart the CPU */
843 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
844 DW210X_WRITE_MSG) != 1) {
845 err("could not restart the USB controller CPU.");
848 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
849 DW210X_WRITE_MSG) != 1) {
850 err("could not restart the USB controller CPU.");
854 switch (dev->descriptor.idProduct) {
855 case USB_PID_TEVII_S650:
856 dw2104_properties.rc_key_map = tevii_rc_keys;
857 dw2104_properties.rc_key_map_size =
858 ARRAY_SIZE(tevii_rc_keys);
861 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
863 /* break omitted intentionally */
866 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
869 case USB_PID_CINERGY_S:
871 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
873 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
875 /* check STV0299 frontend */
876 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
878 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
879 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
880 dw2102_properties.adapter->tuner_attach = &dw2102_tuner_attach;
883 /* check STV0288 frontend */
887 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
889 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
891 if (reset16[2] == 0x11) {
892 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
893 dw2102_properties.adapter->tuner_attach = &dw2102_earda_tuner_attach;
898 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
900 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
902 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
904 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
915 static struct dvb_usb_device_properties dw2102_properties = {
916 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
917 .usb_ctrl = DEVICE_SPECIFIC,
918 .firmware = "dvb-usb-dw2102.fw",
921 .i2c_algo = &dw2102_serit_i2c_algo,
922 .rc_key_map = dw210x_rc_keys,
923 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
925 .rc_query = dw2102_rc_query,
927 .generic_bulk_ctrl_endpoint = 0x81,
928 /* parameter for the MPEG2-data transfer */
930 .download_firmware = dw2102_load_firmware,
931 .read_mac_address = dw210x_read_mac_address,
934 .frontend_attach = dw2102_frontend_attach,
935 .streaming_ctrl = NULL,
936 .tuner_attach = NULL,
949 .num_device_descs = 3,
951 {"DVBWorld DVB-S 2102 USB2.0",
952 {&dw2102_table[0], NULL},
955 {"DVBWorld DVB-S 2101 USB2.0",
956 {&dw2102_table[1], NULL},
959 {"TerraTec Cinergy S USB",
960 {&dw2102_table[4], NULL},
966 static struct dvb_usb_device_properties dw2104_properties = {
967 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
968 .usb_ctrl = DEVICE_SPECIFIC,
969 .firmware = "dvb-usb-dw2104.fw",
972 .i2c_algo = &dw2104_i2c_algo,
973 .rc_key_map = dw210x_rc_keys,
974 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
976 .rc_query = dw2102_rc_query,
978 .generic_bulk_ctrl_endpoint = 0x81,
979 /* parameter for the MPEG2-data transfer */
981 .download_firmware = dw2102_load_firmware,
982 .read_mac_address = dw210x_read_mac_address,
985 .frontend_attach = dw2104_frontend_attach,
986 .streaming_ctrl = NULL,
987 /*.tuner_attach = dw2104_tuner_attach,*/
1000 .num_device_descs = 2,
1002 { "DVBWorld DW2104 USB2.0",
1003 {&dw2102_table[2], NULL},
1006 { "TeVii S650 USB2.0",
1007 {&dw2102_table[3], NULL},
1013 static struct dvb_usb_device_properties dw3101_properties = {
1014 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1015 .usb_ctrl = DEVICE_SPECIFIC,
1016 .firmware = "dvb-usb-dw3101.fw",
1019 .i2c_algo = &dw3101_i2c_algo,
1020 .rc_key_map = dw210x_rc_keys,
1021 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
1023 .rc_query = dw2102_rc_query,
1025 .generic_bulk_ctrl_endpoint = 0x81,
1026 /* parameter for the MPEG2-data transfer */
1028 .download_firmware = dw2102_load_firmware,
1029 .read_mac_address = dw210x_read_mac_address,
1032 .frontend_attach = dw3101_frontend_attach,
1033 .streaming_ctrl = NULL,
1034 .tuner_attach = dw3101_tuner_attach,
1047 .num_device_descs = 1,
1049 { "DVBWorld DVB-C 3101 USB2.0",
1050 {&dw2102_table[5], NULL},
1056 static int dw2102_probe(struct usb_interface *intf,
1057 const struct usb_device_id *id)
1059 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
1060 THIS_MODULE, NULL, adapter_nr) ||
1061 0 == dvb_usb_device_init(intf, &dw2104_properties,
1062 THIS_MODULE, NULL, adapter_nr) ||
1063 0 == dvb_usb_device_init(intf, &dw3101_properties,
1064 THIS_MODULE, NULL, adapter_nr)) {
1070 static struct usb_driver dw2102_driver = {
1072 .probe = dw2102_probe,
1073 .disconnect = dvb_usb_device_exit,
1074 .id_table = dw2102_table,
1077 static int __init dw2102_module_init(void)
1079 int ret = usb_register(&dw2102_driver);
1081 err("usb_register failed. Error number %d", ret);
1086 static void __exit dw2102_module_exit(void)
1088 usb_deregister(&dw2102_driver);
1091 module_init(dw2102_module_init);
1092 module_exit(dw2102_module_exit);
1094 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
1095 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
1096 " DVB-C 3101 USB2.0,"
1097 " TeVii S600, S650 USB2.0 devices");
1098 MODULE_VERSION("0.1");
1099 MODULE_LICENSE("GPL");