Merge branch 'fix/pcm-hwptr' into for-linus
[linux/fpc-iii.git] / drivers / media / dvb / dvb-usb / dw2102.c
blob75de49c0d94370e34e3922b398c5847bf55c7361
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
12 #include "dw2102.h"
13 #include "si21xx.h"
14 #include "stv0299.h"
15 #include "z0194a.h"
16 #include "stv0288.h"
17 #include "stb6000.h"
18 #include "eds1547.h"
19 #include "cx24116.h"
20 #include "tda1002x.h"
22 #ifndef USB_PID_DW2102
23 #define USB_PID_DW2102 0x2102
24 #endif
26 #ifndef USB_PID_DW2104
27 #define USB_PID_DW2104 0x2104
28 #endif
30 #ifndef USB_PID_DW3101
31 #define USB_PID_DW3101 0x3101
32 #endif
34 #ifndef USB_PID_CINERGY_S
35 #define USB_PID_CINERGY_S 0x0064
36 #endif
38 #ifndef USB_PID_TEVII_S650
39 #define USB_PID_TEVII_S650 0xd650
40 #endif
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
48 /* on my own*/
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;
54 int rc_keys_size;
57 /* debug */
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);
63 /* keymaps */
64 static int ir_keymap;
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)
73 int ret;
74 u8 u8buf[len];
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);
87 return ret;
90 /* I2C */
91 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
92 int num)
94 struct dvb_usb_device *d = i2c_get_adapdata(adap);
95 int i = 0, ret = 0;
96 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
97 u16 value;
99 if (!d)
100 return -ENODEV;
101 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
102 return -EAGAIN;
104 switch (num) {
105 case 2:
106 /* read stv0299 register */
107 value = msg[0].buf[0];/* register */
108 for (i = 0; i < msg[1].len; i++) {
109 value = value + i;
110 ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
111 buf6, 2, DW210X_READ_MSG);
112 msg[1].buf[i] = buf6[0];
114 break;
115 case 1:
116 switch (msg[0].addr) {
117 case 0x68:
118 /* write to stv0299 register */
119 buf6[0] = 0x2a;
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);
124 break;
125 case 0x60:
126 if (msg[0].flags == 0) {
127 /* write to tuner pll */
128 buf6[0] = 0x2c;
129 buf6[1] = 5;
130 buf6[2] = 0xc0;
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);
137 } else {
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];
143 break;
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];
149 break;
150 case (DW2102_VOLTAGE_CTRL):
151 buf6[0] = 0x30;
152 buf6[1] = msg[0].buf[0];
153 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
154 buf6, 2, DW210X_WRITE_MSG);
155 break;
158 break;
161 mutex_unlock(&d->i2c_mutex);
162 return num;
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);
169 int ret = 0;
170 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
172 if (!d)
173 return -ENODEV;
174 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
175 return -EAGAIN;
177 switch (num) {
178 case 2:
179 /* read si2109 register by number */
180 buf6[0] = 0xd0;
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);
190 break;
191 case 1:
192 switch (msg[0].addr) {
193 case 0x68:
194 /* write to si2109 register */
195 buf6[0] = 0xd0;
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);
200 break;
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];
206 break;
207 case(DW2102_VOLTAGE_CTRL):
208 buf6[0] = 0x30;
209 buf6[1] = msg[0].buf[0];
210 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
211 buf6, 2, DW210X_WRITE_MSG);
212 break;
214 break;
217 mutex_unlock(&d->i2c_mutex);
218 return num;
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);
224 int ret = 0;
226 if (!d)
227 return -ENODEV;
228 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
229 return -EAGAIN;
231 switch (num) {
232 case 2: {
233 /* read */
234 /* first write first register number */
235 u8 ibuf[msg[1].len + 2], obuf[3];
236 obuf[0] = 0xd0;
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);
246 break;
248 case 1:
249 switch (msg[0].addr) {
250 case 0x68: {
251 /* write to register */
252 u8 obuf[msg[0].len + 2];
253 obuf[0] = 0xd0;
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);
258 break;
260 case 0x61: {
261 /* write to tuner */
262 u8 obuf[msg[0].len + 2];
263 obuf[0] = 0xc2;
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);
268 break;
270 case(DW2102_RC_QUERY): {
271 u8 ibuf[2];
272 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
273 ibuf, 2, DW210X_READ_MSG);
274 memcpy(msg[0].buf, ibuf , 2);
275 break;
277 case(DW2102_VOLTAGE_CTRL): {
278 u8 obuf[2];
279 obuf[0] = 0x30;
280 obuf[1] = msg[0].buf[0];
281 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
282 obuf, 2, DW210X_WRITE_MSG);
283 break;
287 break;
290 mutex_unlock(&d->i2c_mutex);
291 return num;
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);
297 int ret = 0;
298 int len, i;
300 if (!d)
301 return -ENODEV;
302 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
303 return -EAGAIN;
305 switch (num) {
306 case 2: {
307 /* read */
308 /* first write first register number */
309 u8 ibuf[msg[1].len + 2], obuf[3];
310 obuf[0] = 0xaa;
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);
320 break;
322 case 1:
323 switch (msg[0].addr) {
324 case 0x55: {
325 if (msg[0].buf[0] == 0xf7) {
326 /* firmware */
327 /* Write in small blocks */
328 u8 obuf[19];
329 obuf[0] = 0xaa;
330 obuf[1] = 0x11;
331 obuf[2] = 0xf7;
332 len = msg[0].len - 1;
333 i = 1;
334 do {
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);
338 i += 16;
339 len -= 16;
340 } while (len > 0);
341 } else {
342 /* write to register */
343 u8 obuf[msg[0].len + 2];
344 obuf[0] = 0xaa;
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);
350 break;
352 case(DW2102_RC_QUERY): {
353 u8 ibuf[2];
354 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
355 ibuf, 2, DW210X_READ_MSG);
356 memcpy(msg[0].buf, ibuf , 2);
357 break;
359 case(DW2102_VOLTAGE_CTRL): {
360 u8 obuf[2];
361 obuf[0] = 0x30;
362 obuf[1] = msg[0].buf[0];
363 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
364 obuf, 2, DW210X_WRITE_MSG);
365 break;
369 break;
372 mutex_unlock(&d->i2c_mutex);
373 return num;
376 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
377 int num)
379 struct dvb_usb_device *d = i2c_get_adapdata(adap);
380 int ret = 0, i;
382 if (!d)
383 return -ENODEV;
384 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
385 return -EAGAIN;
387 switch (num) {
388 case 2: {
389 /* read */
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);
402 break;
404 case 1:
405 switch (msg[0].addr) {
406 case 0x60:
407 case 0x0c: {
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);
415 break;
417 case(DW2102_RC_QUERY): {
418 u8 ibuf[2];
419 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
420 ibuf, 2, DW210X_READ_MSG);
421 memcpy(msg[0].buf, ibuf , 2);
422 break;
426 break;
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);
436 return num;
439 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
441 return I2C_FUNC_I2C;
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])
471 int i;
472 u8 ibuf[] = {0, 0};
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.");
478 return -1;
479 } else {
480 eepromline[i%16] = ibuf[0];
481 eeprom[i] = 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);
490 return 0;
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);
507 return 0;
510 static struct stv0299_config sharp_z0194a_config = {
511 .demod_address = 0x68,
512 .inittab = sharp_z0194a_inittab,
513 .mclk = 88000000UL,
514 .invert = 1,
515 .skip_reinit = 0,
516 .lock_output = STV0299_LOCKOUTPUT_1,
517 .volt13_op0_op1 = STV0299_VOLT13_OP1,
518 .min_delay_ms = 100,
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,
529 .min_delay_ms = 100,
533 static struct tda10023_config dw3101_tda10023_config = {
534 .demod_address = 0x0c,
535 .invert = 1,
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");
544 return 0;
546 return -EIO;
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,
557 &d->dev->i2c_adap);
558 if (d->fe != NULL) {
559 d->fe->ops.set_voltage = dw210x_set_voltage;
560 info("Attached si21xx!\n");
561 return 0;
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,
567 &d->dev->i2c_adap);
568 if (d->fe != NULL) {
569 d->fe->ops.set_voltage = dw210x_set_voltage;
570 info("Attached stv0288!\n");
571 return 0;
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,
578 &d->dev->i2c_adap);
579 if (d->fe != NULL) {
580 d->fe->ops.set_voltage = dw210x_set_voltage;
581 info("Attached stv0299!\n");
582 return 0;
585 return -EIO;
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);
592 if (d->fe != NULL) {
593 info("Attached tda10023!\n");
594 return 0;
596 return -EIO;
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);
603 return 0;
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);
611 return 0;
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);
619 return 0;
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;
751 u8 key[2];
752 struct i2c_msg msg = {
753 .addr = DW2102_RC_QUERY,
754 .flags = I2C_M_RD,
755 .buf = key,
756 .len = 2
758 int i;
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;
771 break;
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]);
785 return 0;
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)
803 u8 *b, *p;
804 int ret = 0, i;
805 u8 reset;
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) {
810 case 0x2101:
811 ret = request_firmware(&fw, filename, &dev->dev);
812 if (ret != 0) {
813 err("did not find the firmware file. (%s) "
814 "Please see linux/Documentation/dvb/ for more details "
815 "on firmware-problems.", filename);
816 return ret;
818 break;
819 default:
820 fw = frmwr;
821 break;
823 info("start downloading DW210X firmware");
824 p = kmalloc(fw->size, GFP_KERNEL);
825 reset = 1;
826 /*stop the CPU*/
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);
830 if (p != NULL) {
831 memcpy(p, fw->data, fw->size);
832 for (i = 0; i < fw->size; i += 0x40) {
833 b = (u8 *) p + i;
834 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
835 DW210X_WRITE_MSG) != 0x40) {
836 err("error while transferring firmware");
837 ret = -EINVAL;
838 break;
841 /* restart the CPU */
842 reset = 0;
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.");
846 ret = -EINVAL;
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.");
851 ret = -EINVAL;
853 /* init registers */
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);
859 case USB_PID_DW2104:
860 reset = 1;
861 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
862 DW210X_WRITE_MSG);
863 /* break omitted intentionally */
864 case USB_PID_DW3101:
865 reset = 0;
866 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
867 DW210X_WRITE_MSG);
868 break;
869 case USB_PID_CINERGY_S:
870 case USB_PID_DW2102:
871 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
872 DW210X_WRITE_MSG);
873 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
874 DW210X_READ_MSG);
875 /* check STV0299 frontend */
876 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
877 DW210X_READ_MSG);
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;
881 break;
882 } else {
883 /* check STV0288 frontend */
884 reset16[0] = 0xd0;
885 reset16[1] = 1;
886 reset16[2] = 0;
887 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
888 DW210X_WRITE_MSG);
889 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
890 DW210X_READ_MSG);
891 if (reset16[2] == 0x11) {
892 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
893 dw2102_properties.adapter->tuner_attach = &dw2102_earda_tuner_attach;
894 break;
897 case 0x2101:
898 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
899 DW210X_READ_MSG);
900 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
901 DW210X_READ_MSG);
902 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
903 DW210X_READ_MSG);
904 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
905 DW210X_READ_MSG);
906 break;
909 msleep(100);
910 kfree(p);
912 return ret;
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",
919 .no_reconnect = 1,
921 .i2c_algo = &dw2102_serit_i2c_algo,
922 .rc_key_map = dw210x_rc_keys,
923 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
924 .rc_interval = 150,
925 .rc_query = dw2102_rc_query,
927 .generic_bulk_ctrl_endpoint = 0x81,
928 /* parameter for the MPEG2-data transfer */
929 .num_adapters = 1,
930 .download_firmware = dw2102_load_firmware,
931 .read_mac_address = dw210x_read_mac_address,
932 .adapter = {
934 .frontend_attach = dw2102_frontend_attach,
935 .streaming_ctrl = NULL,
936 .tuner_attach = NULL,
937 .stream = {
938 .type = USB_BULK,
939 .count = 8,
940 .endpoint = 0x82,
941 .u = {
942 .bulk = {
943 .buffersize = 4096,
949 .num_device_descs = 3,
950 .devices = {
951 {"DVBWorld DVB-S 2102 USB2.0",
952 {&dw2102_table[0], NULL},
953 {NULL},
955 {"DVBWorld DVB-S 2101 USB2.0",
956 {&dw2102_table[1], NULL},
957 {NULL},
959 {"TerraTec Cinergy S USB",
960 {&dw2102_table[4], NULL},
961 {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",
970 .no_reconnect = 1,
972 .i2c_algo = &dw2104_i2c_algo,
973 .rc_key_map = dw210x_rc_keys,
974 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
975 .rc_interval = 150,
976 .rc_query = dw2102_rc_query,
978 .generic_bulk_ctrl_endpoint = 0x81,
979 /* parameter for the MPEG2-data transfer */
980 .num_adapters = 1,
981 .download_firmware = dw2102_load_firmware,
982 .read_mac_address = dw210x_read_mac_address,
983 .adapter = {
985 .frontend_attach = dw2104_frontend_attach,
986 .streaming_ctrl = NULL,
987 /*.tuner_attach = dw2104_tuner_attach,*/
988 .stream = {
989 .type = USB_BULK,
990 .count = 8,
991 .endpoint = 0x82,
992 .u = {
993 .bulk = {
994 .buffersize = 4096,
1000 .num_device_descs = 2,
1001 .devices = {
1002 { "DVBWorld DW2104 USB2.0",
1003 {&dw2102_table[2], NULL},
1004 {NULL},
1006 { "TeVii S650 USB2.0",
1007 {&dw2102_table[3], NULL},
1008 {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",
1017 .no_reconnect = 1,
1019 .i2c_algo = &dw3101_i2c_algo,
1020 .rc_key_map = dw210x_rc_keys,
1021 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
1022 .rc_interval = 150,
1023 .rc_query = dw2102_rc_query,
1025 .generic_bulk_ctrl_endpoint = 0x81,
1026 /* parameter for the MPEG2-data transfer */
1027 .num_adapters = 1,
1028 .download_firmware = dw2102_load_firmware,
1029 .read_mac_address = dw210x_read_mac_address,
1030 .adapter = {
1032 .frontend_attach = dw3101_frontend_attach,
1033 .streaming_ctrl = NULL,
1034 .tuner_attach = dw3101_tuner_attach,
1035 .stream = {
1036 .type = USB_BULK,
1037 .count = 8,
1038 .endpoint = 0x82,
1039 .u = {
1040 .bulk = {
1041 .buffersize = 4096,
1047 .num_device_descs = 1,
1048 .devices = {
1049 { "DVBWorld DVB-C 3101 USB2.0",
1050 {&dw2102_table[5], NULL},
1051 {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)) {
1065 return 0;
1067 return -ENODEV;
1070 static struct usb_driver dw2102_driver = {
1071 .name = "dw2102",
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);
1080 if (ret)
1081 err("usb_register failed. Error number %d", ret);
1083 return 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");