diff options
author | Devin Heitmueller <devin.heitmueller@gmail.com> | 2008-11-15 05:13:07 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-11-16 20:57:53 -0500 |
commit | 99afb989b05b9fb1c7b3831ce4b7a000b214acdb (patch) | |
tree | 0cf2ed3686af21ab487a19ca2ba70d571b1bc1df | |
parent | deaf53e3c8e717169669ee6c2594b5c33d1af93b (diff) |
V4L/DVB (9639): Make dib0700 remote control support work with firmware v1.20
The format for reading the IR controller changed in firmware 1.20. It now
provides the events on bulk endpoint 1 instead of using a control request.
Support the new format, providing backward compatibility for users who might
be using older firmware.
Thanks to Patrick Boettcher <patrick.boettcher@desy.de> for providing the
required information on how the version 1.20 firmware works.
Signed-off-by: Devin Heitmueller <devin.heitmueller@gmail.com>
Signed-off-by: Patrick Boettcher <pb@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/dvb/dvb-usb/dib0700.h | 5 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/dib0700_core.c | 16 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/dib0700_devices.c | 139 |
3 files changed, 158 insertions, 2 deletions
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h index 739193943c17..8b544fe79b0d 100644 --- a/drivers/media/dvb/dvb-usb/dib0700.h +++ b/drivers/media/dvb/dvb-usb/dib0700.h | |||
@@ -22,7 +22,7 @@ extern int dvb_usb_dib0700_debug; | |||
22 | 22 | ||
23 | #define REQUEST_I2C_READ 0x2 | 23 | #define REQUEST_I2C_READ 0x2 |
24 | #define REQUEST_I2C_WRITE 0x3 | 24 | #define REQUEST_I2C_WRITE 0x3 |
25 | #define REQUEST_POLL_RC 0x4 | 25 | #define REQUEST_POLL_RC 0x4 /* deprecated in firmware v1.20 */ |
26 | #define REQUEST_JUMPRAM 0x8 | 26 | #define REQUEST_JUMPRAM 0x8 |
27 | #define REQUEST_SET_CLOCK 0xB | 27 | #define REQUEST_SET_CLOCK 0xB |
28 | #define REQUEST_SET_GPIO 0xC | 28 | #define REQUEST_SET_GPIO 0xC |
@@ -40,11 +40,14 @@ struct dib0700_state { | |||
40 | u16 mt2060_if1[2]; | 40 | u16 mt2060_if1[2]; |
41 | u8 rc_toggle; | 41 | u8 rc_toggle; |
42 | u8 rc_counter; | 42 | u8 rc_counter; |
43 | u8 rc_func_version; | ||
43 | u8 is_dib7000pc; | 44 | u8 is_dib7000pc; |
44 | u8 fw_use_new_i2c_api; | 45 | u8 fw_use_new_i2c_api; |
45 | u8 disable_streaming_master_mode; | 46 | u8 disable_streaming_master_mode; |
46 | }; | 47 | }; |
47 | 48 | ||
49 | extern int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion, | ||
50 | u32 *romversion, u32 *ramversion, u32 *fwtype); | ||
48 | extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val); | 51 | extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val); |
49 | extern int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3); | 52 | extern int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3); |
50 | extern int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen); | 53 | extern int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen); |
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c index dd53cee3896d..200b215f4d8b 100644 --- a/drivers/media/dvb/dvb-usb/dib0700_core.c +++ b/drivers/media/dvb/dvb-usb/dib0700_core.c | |||
@@ -19,6 +19,22 @@ MODULE_PARM_DESC(dvb_usb_dib0700_ir_proto, "set ir protocol (0=NEC, 1=RC5 (defau | |||
19 | 19 | ||
20 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | 20 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
21 | 21 | ||
22 | |||
23 | int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion, | ||
24 | u32 *romversion, u32 *ramversion, u32 *fwtype) | ||
25 | { | ||
26 | u8 b[16]; | ||
27 | int ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), | ||
28 | REQUEST_GET_VERSION, | ||
29 | USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, | ||
30 | b, sizeof(b), USB_CTRL_GET_TIMEOUT); | ||
31 | *hwversion = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; | ||
32 | *romversion = (b[4] << 24) | (b[5] << 16) | (b[6] << 8) | b[7]; | ||
33 | *ramversion = (b[8] << 24) | (b[9] << 16) | (b[10] << 8) | b[11]; | ||
34 | *fwtype = (b[12] << 24) | (b[13] << 16) | (b[14] << 8) | b[15]; | ||
35 | return ret; | ||
36 | } | ||
37 | |||
22 | /* expecting rx buffer: request data[0] data[1] ... data[2] */ | 38 | /* expecting rx buffer: request data[0] data[1] ... data[2] */ |
23 | static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen) | 39 | static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen) |
24 | { | 40 | { |
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c index 0cfccc24b190..f28d3ae59e04 100644 --- a/drivers/media/dvb/dvb-usb/dib0700_devices.c +++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c | |||
@@ -38,6 +38,7 @@ static struct mt2060_config bristol_mt2060_config[2] = { | |||
38 | } | 38 | } |
39 | }; | 39 | }; |
40 | 40 | ||
41 | |||
41 | static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = { | 42 | static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = { |
42 | .band_caps = BAND_VHF | BAND_UHF, | 43 | .band_caps = BAND_VHF | BAND_UHF, |
43 | .setup = (1 << 8) | (5 << 5) | (0 << 4) | (0 << 3) | (0 << 2) | (2 << 0), | 44 | .setup = (1 << 8) | (5 << 5) | (0 << 4) | (0 << 3) | (0 << 2) | (2 << 0), |
@@ -451,8 +452,13 @@ static u8 rc_request[] = { REQUEST_POLL_RC, 0 }; | |||
451 | 452 | ||
452 | /* Number of keypresses to ignore before start repeating */ | 453 | /* Number of keypresses to ignore before start repeating */ |
453 | #define RC_REPEAT_DELAY 2 | 454 | #define RC_REPEAT_DELAY 2 |
455 | #define RC_REPEAT_DELAY_V1_20 5 | ||
454 | 456 | ||
455 | static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state) | 457 | |
458 | |||
459 | /* Used by firmware versions < 1.20 (deprecated) */ | ||
460 | static int dib0700_rc_query_legacy(struct dvb_usb_device *d, u32 *event, | ||
461 | int *state) | ||
456 | { | 462 | { |
457 | u8 key[4]; | 463 | u8 key[4]; |
458 | int i; | 464 | int i; |
@@ -529,6 +535,137 @@ static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state) | |||
529 | return 0; | 535 | return 0; |
530 | } | 536 | } |
531 | 537 | ||
538 | /* This is the structure of the RC response packet starting in firmware 1.20 */ | ||
539 | struct dib0700_rc_response { | ||
540 | u8 report_id; | ||
541 | u8 data_state; | ||
542 | u8 system_msb; | ||
543 | u8 system_lsb; | ||
544 | u8 data; | ||
545 | u8 not_data; | ||
546 | }; | ||
547 | |||
548 | /* This supports the new IR response format for firmware v1.20 */ | ||
549 | static int dib0700_rc_query_v1_20(struct dvb_usb_device *d, u32 *event, | ||
550 | int *state) | ||
551 | { | ||
552 | struct dvb_usb_rc_key *keymap = d->props.rc_key_map; | ||
553 | struct dib0700_state *st = d->priv; | ||
554 | struct dib0700_rc_response poll_reply; | ||
555 | u8 buf[6]; | ||
556 | int i; | ||
557 | int status; | ||
558 | int actlen; | ||
559 | int found = 0; | ||
560 | |||
561 | /* Set initial results in case we exit the function early */ | ||
562 | *event = 0; | ||
563 | *state = REMOTE_NO_KEY_PRESSED; | ||
564 | |||
565 | /* Firmware v1.20 provides RC data via bulk endpoint 1 */ | ||
566 | status = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, 1), buf, | ||
567 | sizeof(buf), &actlen, 50); | ||
568 | if (status < 0) { | ||
569 | /* No data available (meaning no key press) */ | ||
570 | return 0; | ||
571 | } | ||
572 | |||
573 | if (actlen != sizeof(buf)) { | ||
574 | /* We didn't get back the 6 byte message we expected */ | ||
575 | err("Unexpected RC response size [%d]", actlen); | ||
576 | return -1; | ||
577 | } | ||
578 | |||
579 | poll_reply.report_id = buf[0]; | ||
580 | poll_reply.data_state = buf[1]; | ||
581 | poll_reply.system_msb = buf[2]; | ||
582 | poll_reply.system_lsb = buf[3]; | ||
583 | poll_reply.data = buf[4]; | ||
584 | poll_reply.not_data = buf[5]; | ||
585 | |||
586 | /* | ||
587 | info("rid=%02x ds=%02x sm=%02x sl=%02x d=%02x nd=%02x\n", | ||
588 | poll_reply.report_id, poll_reply.data_state, | ||
589 | poll_reply.system_msb, poll_reply.system_lsb, | ||
590 | poll_reply.data, poll_reply.not_data); | ||
591 | */ | ||
592 | |||
593 | if ((poll_reply.data + poll_reply.not_data) != 0xff) { | ||
594 | /* Key failed integrity check */ | ||
595 | err("key failed integrity check: %02x %02x %02x %02x", | ||
596 | poll_reply.system_msb, poll_reply.system_lsb, | ||
597 | poll_reply.data, poll_reply.not_data); | ||
598 | return -1; | ||
599 | } | ||
600 | |||
601 | /* Find the key in the map */ | ||
602 | for (i = 0; i < d->props.rc_key_map_size; i++) { | ||
603 | if (keymap[i].custom == poll_reply.system_lsb && | ||
604 | keymap[i].data == poll_reply.data) { | ||
605 | *event = keymap[i].event; | ||
606 | found = 1; | ||
607 | break; | ||
608 | } | ||
609 | } | ||
610 | |||
611 | if (found == 0) { | ||
612 | err("Unknown remote controller key: %02x %02x %02x %02x", | ||
613 | poll_reply.system_msb, poll_reply.system_lsb, | ||
614 | poll_reply.data, poll_reply.not_data); | ||
615 | d->last_event = 0; | ||
616 | return 0; | ||
617 | } | ||
618 | |||
619 | if (poll_reply.data_state == 1) { | ||
620 | /* New key hit */ | ||
621 | st->rc_counter = 0; | ||
622 | *event = keymap[i].event; | ||
623 | *state = REMOTE_KEY_PRESSED; | ||
624 | d->last_event = keymap[i].event; | ||
625 | } else if (poll_reply.data_state == 2) { | ||
626 | /* Key repeated */ | ||
627 | st->rc_counter++; | ||
628 | |||
629 | /* prevents unwanted double hits */ | ||
630 | if (st->rc_counter > RC_REPEAT_DELAY_V1_20) { | ||
631 | *event = d->last_event; | ||
632 | *state = REMOTE_KEY_PRESSED; | ||
633 | st->rc_counter = RC_REPEAT_DELAY_V1_20; | ||
634 | } | ||
635 | } else { | ||
636 | err("Unknown data state [%d]", poll_reply.data_state); | ||
637 | } | ||
638 | |||
639 | return 0; | ||
640 | } | ||
641 | |||
642 | static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state) | ||
643 | { | ||
644 | struct dib0700_state *st = d->priv; | ||
645 | |||
646 | /* Because some people may have improperly named firmware files, | ||
647 | let's figure out whether to use the new firmware call or the legacy | ||
648 | call based on the firmware version embedded in the file */ | ||
649 | if (st->rc_func_version == 0) { | ||
650 | u32 hwver, romver, ramver, fwtype; | ||
651 | int ret = dib0700_get_version(d, &hwver, &romver, &ramver, | ||
652 | &fwtype); | ||
653 | if (ret < 0) { | ||
654 | err("Could not determine version info"); | ||
655 | return -1; | ||
656 | } | ||
657 | if (ramver < 0x10200) | ||
658 | st->rc_func_version = 1; | ||
659 | else | ||
660 | st->rc_func_version = 2; | ||
661 | } | ||
662 | |||
663 | if (st->rc_func_version == 2) | ||
664 | return dib0700_rc_query_v1_20(d, event, state); | ||
665 | else | ||
666 | return dib0700_rc_query_legacy(d, event, state); | ||
667 | } | ||
668 | |||
532 | static struct dvb_usb_rc_key dib0700_rc_keys[] = { | 669 | static struct dvb_usb_rc_key dib0700_rc_keys[] = { |
533 | /* Key codes for the tiny Pinnacle remote*/ | 670 | /* Key codes for the tiny Pinnacle remote*/ |
534 | { 0x07, 0x00, KEY_MUTE }, | 671 | { 0x07, 0x00, KEY_MUTE }, |