Skip to content

Commit

Permalink
[media] dib0700: NEC scancode cleanup
Browse files Browse the repository at this point in the history
the RC RX packet is defined as:

        struct dib0700_rc_response {
		...
                                u8 not_system;
                                u8 system;
		...
                u8 data;
                u8 not_data;

The NEC protocol transmits in the order:
        system
        not_system
        data
        not_data

Note that the code defines the NEC extended scancode as:

        scancode = be16_to_cpu(poll_reply->system16) << 8 | poll_reply->data;

i.e.

        scancode = poll_reply->not_system << 16 |
                   poll_reply->system     << 8  |
                   poll_reply->data;

Which, if the order *is* reversed, would mean that the scancode that
gets defined is in reality:

        scancode = poll_reply->system     << 16 |
                   poll_reply->not_system << 8  |
                   poll_reply->data;

Which is the same as the order used in drivers/media/rc/ir-nec-decoder.c.

This patch changes the code to match my assumption (the generated scancode
should, however, not change).

[m.chehab@samsung.com: rebased and fixed the decoding error message]
Signed-off-by: David Härdeman <david@hardeman.nu>
CC: Patrick Boettcher <pboettcher@kernellabs.com>
Tested-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
  • Loading branch information
David Härdeman authored and Mauro Carvalho Chehab committed Jul 24, 2014
1 parent 4dd9bb9 commit af3a4a9
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions drivers/media/usb/dvb-usb/dib0700_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,8 @@ int dib0700_change_protocol(struct rc_dev *rc, u64 *rc_type)
struct dib0700_rc_response {
u8 report_id;
u8 data_state;
union {
u16 system16;
struct {
u8 not_system;
u8 system;
};
};
u8 system;
u8 not_system;
u8 data;
u8 not_data;
};
Expand Down Expand Up @@ -710,20 +705,29 @@ static void dib0700_rc_urb_completion(struct urb *purb)
toggle = 0;

/* NEC protocol sends repeat code as 0 0 0 FF */
if ((poll_reply->system == 0x00) && (poll_reply->data == 0x00)
&& (poll_reply->not_data == 0xff)) {
if (poll_reply->system == 0x00 &&
poll_reply->not_system == 0x00 &&
poll_reply->data == 0x00 &&
poll_reply->not_data == 0xff) {
poll_reply->data_state = 2;
break;
}

if ((poll_reply->system ^ poll_reply->not_system) != 0xff) {
if ((poll_reply->data ^ poll_reply->not_data) != 0xff) {
deb_data("NEC32 protocol\n");
keycode = RC_SCANCODE_NEC32(poll_reply->system << 24 |
poll_reply->not_system << 16 |
poll_reply->data << 8 |
poll_reply->not_data);
} else if ((poll_reply->system ^ poll_reply->not_system) != 0xff) {
deb_data("NEC extended protocol\n");
/* NEC extended code - 24 bits */
keycode = be16_to_cpu(poll_reply->system16) << 8 | poll_reply->data;
keycode = RC_SCANCODE_NECX(poll_reply->system << 8 |
poll_reply->not_system,
poll_reply->data);
} else {
deb_data("NEC normal protocol\n");
/* normal NEC code - 16 bits */
keycode = poll_reply->system << 8 | poll_reply->data;
keycode = RC_SCANCODE_NEC(poll_reply->system,
poll_reply->data);
}

break;
Expand All @@ -738,8 +742,8 @@ static void dib0700_rc_urb_completion(struct urb *purb)

if ((poll_reply->data + poll_reply->not_data) != 0xff) {
/* Key failed integrity check */
err("key failed integrity check: %04x %02x %02x",
poll_reply->system,
err("key failed integrity check: %02x %02x %02x %02x",
poll_reply->system, poll_reply->not_system,
poll_reply->data, poll_reply->not_data);
goto resubmit;
}
Expand Down

0 comments on commit af3a4a9

Please sign in to comment.