diff -drupN a/drivers/media/rc/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c --- a/drivers/media/rc/ir-nec-decoder.c 2018-08-06 17:23:04.000000000 +0300 +++ b/drivers/media/rc/ir-nec-decoder.c 2022-06-12 05:28:14.000000000 +0300 @@ -1,6 +1,6 @@ /* ir-nec-decoder.c - handle NEC IR Pulse/Space protocol * - * Copyright (C) 2010 by Mauro Carvalho Chehab + * Copyright (C) 2010 by Mauro Carvalho Chehab * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,9 +49,12 @@ static int ir_nec_decode(struct rc_dev * { struct nec_dec *data = &dev->raw->nec; u32 scancode; - enum rc_type rc_type; u8 address, not_address, command, not_command; bool send_32bits = false; + bool extended_nec = false; + + if (!(dev->enabled_protocols & RC_BIT_NEC)) + return 0; if (!is_timing_event(ev)) { if (ev.reset) @@ -91,8 +94,9 @@ static int ir_nec_decode(struct rc_dev * if (!dev->keypressed) { IR_dprintk(1, "Discarding last key repeat: event after key up\n"); } else { - rc_repeat(dev); - IR_dprintk(1, "Repeat last key\n"); + //IR_dprintk(1, "Repeat last key\n"); + //rc_repeat(dev); + data->necx_repeat = true; data->state = STATE_TRAILER_PULSE; } return 0; @@ -118,10 +122,10 @@ static int ir_nec_decode(struct rc_dev * geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2)) { IR_dprintk(1, "Repeat last key\n"); - rc_repeat(dev); + //rc_repeat(dev); + data->necx_repeat = true; data->state = STATE_INACTIVE; return 0; - } else if (data->count > NECX_REPEAT_BITS) data->necx_repeat = false; @@ -156,53 +160,71 @@ static int ir_nec_decode(struct rc_dev * if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2)) break; - address = bitrev8((data->bits >> 24) & 0xff); - not_address = bitrev8((data->bits >> 16) & 0xff); - command = bitrev8((data->bits >> 8) & 0xff); - not_command = bitrev8((data->bits >> 0) & 0xff); + if (data->necx_repeat) { + IR_dprintk(1, "Repeat last key\n"); + rc_repeat(dev); + } else { + address = bitrev8((data->bits >> 24) & 0xff); + not_address = bitrev8((data->bits >> 16) & 0xff); + command = bitrev8((data->bits >> 8) & 0xff); + not_command = bitrev8((data->bits >> 0) & 0xff); + IR_dprintk(1, "current comand: %02x\n", command); - if ((command ^ not_command) != 0xff) { - IR_dprintk(1, "NEC checksum error: received 0x%08x\n", - data->bits); - send_32bits = true; - } + if ((command ^ not_command) != 0xff) { + IR_dprintk(1, "NEC checksum error: received 0x%08x\n", + data->bits); + send_32bits = true; + } - if (send_32bits) { - /* NEC transport, but modified protocol, used by at - * least Apple and TiVo remotes */ - scancode = data->bits; - IR_dprintk(1, "NEC (modified) scancode 0x%08x\n", scancode); - rc_type = RC_TYPE_NEC32; - } else if ((address ^ not_address) != 0xff) { - /* Extended NEC */ - scancode = address << 16 | - not_address << 8 | - command; - IR_dprintk(1, "NEC (Ext) scancode 0x%06x\n", scancode); - rc_type = RC_TYPE_NECX; - } else { - /* Normal NEC */ - scancode = address << 8 | command; - IR_dprintk(1, "NEC scancode 0x%04x\n", scancode); - rc_type = RC_TYPE_NEC; - } + if ((address ^ not_address) != 0xff) { + IR_dprintk(1, "NEC checksum error: received 0x%08x\n", + data->bits); + extended_nec = true; + } - if (data->is_nec_x) - data->necx_repeat = true; + if (send_32bits) { + /* NEC transport, but modified protocol, used by at + * least Apple and TiVo remotes */ + scancode = data->bits; + IR_dprintk(2, "NEC (modified) scancode 0x%08x\n", scancode); + } else { + if (extended_nec) { + /* Extended NEC */ + scancode = address << 8 | + not_address << 16 | + command; + IR_dprintk(2, "Extended NEC scancode 0x%06x\n", scancode); + } else { + /* Normal NEC */ + scancode = address << 24 | + not_address << 16 | + command << 8 | + not_command; + IR_dprintk(2, "Normal NEC scancode 0x%08x\n", scancode); + } + } + + if (data->is_nec_x) + data->necx_repeat = true; + + rc_keydown(dev, RC_TYPE_NEC, scancode, 0); + } - rc_keydown(dev, rc_type, scancode, 0); data->state = STATE_INACTIVE; + data->count = 0; return 0; } IR_dprintk(1, "NEC decode failed at count %d state %d (%uus %s)\n", data->count, data->state, TO_US(ev.duration), TO_STR(ev.pulse)); + data->state = STATE_INACTIVE; + data->count = 0; return -EINVAL; } static struct ir_raw_handler nec_handler = { - .protocols = RC_BIT_NEC | RC_BIT_NECX | RC_BIT_NEC32, + .protocols = RC_BIT_NEC, .decode = ir_nec_decode, }; @@ -223,6 +245,6 @@ module_init(ir_nec_decode_init); module_exit(ir_nec_decode_exit); MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Mauro Carvalho Chehab"); +MODULE_AUTHOR("Mauro Carvalho Chehab "); MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); MODULE_DESCRIPTION("NEC IR protocol decoder");