From patchwork Sun Jul 30 13:23:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 108951 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp2610718obm; Sun, 30 Jul 2017 06:24:45 -0700 (PDT) X-Received: by 10.99.123.76 with SMTP id k12mr12650395pgn.277.1501421085302; Sun, 30 Jul 2017 06:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501421085; cv=none; d=google.com; s=arc-20160816; b=Y2VeL7s4qQTYnrQ7720p8EeMI6mcCa0sMdI7Yp8fpwgn6Nd10rsHXIXb1qv+xg/YdL 8fc7w/VbBcbiM61PQAXb/VtKXvtPaQlbIe4g8yM0O7PQDmAtfoLzRVfciQvnoxtYoqlu OKn3hHz2hFReZdkKHvSl5cxVboWVBRxqxDjvlaXJV8m/cA3NT1Vm+qvjtD3uM6Jc/wOp RCpYOch3qTfl3/KEwyh9Ujl6L8tV5Ls9DLOLr6bt0gkAtFzaKn3+UZNsOlS/jfSckAsW E3cE2N1vskKHhmj/VEMsrDaf2V8MsIGaJ+/IRS8qtdey2l2dggT6Ksr+AgZglBXKvJgb yIWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:arc-authentication-results; bh=7m0DndrtrHH3afVaWoiUFhOsrLMi3gfrNnTphpvFKLY=; b=UUp2HdLEiqhF6ojVYoADn3dGikQVIYBCu9Wh/5paLBlmTaEEMKFz1Pq+k0eLpRBzTm +90Gk52Z6UghgLroLaT2nyR39n2z780QAu8AMqS7LVv1It1dUfQYFtDM8zOnNdgBueeT LDB4qot1X6EF6XH3Tcd+KJHNFXN+PCqQIBiqHPQuaodyHVvY5Sos7GU7vwTQN0Voaybg X/cVWpJaz9qaG0Jy6WSxlgAxwyJeRz7sKhyemInNy6jK/rKBEbkhcUeBvg+w4fWR7lCC xwQUGBA9j2D5mmpWUupdrYMaG4Ffi5gOei3uuNz7dzRlj/bJBLWrHqM9sdlBhcjRr782 VrCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si9855585pga.905.2017.07.30.06.24.45; Sun, 30 Jul 2017 06:24:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753937AbdG3NYm (ORCPT + 7 others); Sun, 30 Jul 2017 09:24:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:37058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750991AbdG3NYm (ORCPT ); Sun, 30 Jul 2017 09:24:42 -0400 Received: from localhost.localdomain (li411-102.members.linode.com [106.187.91.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CBE8222C86; Sun, 30 Jul 2017 13:24:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBE8222C86 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=shawnguo@kernel.org From: Shawn Guo To: Sean Young , Rob Herring Cc: Baoyou Xie , Xin Zhou , Jun Nie , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Shawn Guo Subject: [PATCH v2 1/3] rc: ir-nec-decoder: move scancode composing code into a shared function Date: Sun, 30 Jul 2017 21:23:11 +0800 Message-Id: <1501420993-21977-2-git-send-email-shawnguo@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501420993-21977-1-git-send-email-shawnguo@kernel.org> References: <1501420993-21977-1-git-send-email-shawnguo@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Shawn Guo The NEC scancode composing and protocol type detection in ir_nec_decode() is generic enough to be a shared function. Let's create an inline function in rc-core.h, so that other remote control drivers can reuse this function to save some code. Signed-off-by: Shawn Guo --- drivers/media/rc/ir-nec-decoder.c | 32 +++----------------------------- include/media/rc-core.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 29 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/rc/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c index 3ce850314dca..b578c1e27c04 100644 --- a/drivers/media/rc/ir-nec-decoder.c +++ b/drivers/media/rc/ir-nec-decoder.c @@ -51,7 +51,6 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev) u32 scancode; enum rc_type rc_type; u8 address, not_address, command, not_command; - bool send_32bits = false; if (!is_timing_event(ev)) { if (ev.reset) @@ -161,34 +160,9 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev) command = bitrev8((data->bits >> 8) & 0xff); not_command = bitrev8((data->bits >> 0) & 0xff); - 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 = not_address << 24 | - address << 16 | - not_command << 8 | - command; - 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; - } + scancode = ir_nec_bytes_to_scancode(address, not_address, + command, not_command, + &rc_type); if (data->is_nec_x) data->necx_repeat = true; diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 78dea39a9b39..204f7785b8e7 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -340,4 +340,35 @@ static inline u32 ir_extract_bits(u32 data, u32 mask) return value; } +/* Get NEC scancode and protocol type from address and command bytes */ +static inline u32 ir_nec_bytes_to_scancode(u8 address, u8 not_address, + u8 command, u8 not_command, + enum rc_type *protocol) +{ + u32 scancode; + + if ((command ^ not_command) != 0xff) { + /* NEC transport, but modified protocol, used by at + * least Apple and TiVo remotes + */ + scancode = not_address << 24 | + address << 16 | + not_command << 8 | + command; + *protocol = RC_TYPE_NEC32; + } else if ((address ^ not_address) != 0xff) { + /* Extended NEC */ + scancode = address << 16 | + not_address << 8 | + command; + *protocol = RC_TYPE_NECX; + } else { + /* Normal NEC */ + scancode = address << 8 | command; + *protocol = RC_TYPE_NEC; + } + + return scancode; +} + #endif /* _RC_CORE */