From: Shawn Guo <shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Sean Young <sean-hENCXIMQXOg@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Baoyou Xie <xie.baoyou-i+zz7BTLltu8dxfXipz/DA@public.gmane.org>,
Xin Zhou <zhou.xin8-i+zz7BTLltu8dxfXipz/DA@public.gmane.org>,
Jun Nie <jun.nie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
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 [thread overview]
Message-ID: <1501420993-21977-2-git-send-email-shawnguo@kernel.org> (raw)
In-Reply-To: <1501420993-21977-1-git-send-email-shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
From: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
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 <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
drivers/media/rc/ir-nec-decoder.c | 32 +++-----------------------------
include/media/rc-core.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 29 deletions(-)
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 */
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-07-30 13:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-30 13:23 [PATCH v2 0/3] Add ZTE zx-irdec remote control driver Shawn Guo
[not found] ` <1501420993-21977-1-git-send-email-shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-07-30 13:23 ` Shawn Guo [this message]
2017-07-30 13:23 ` [PATCH v2 2/3] dt-bindings: add bindings document for zx-irdec Shawn Guo
2017-08-03 23:36 ` Rob Herring
2017-07-30 13:23 ` [PATCH v2 3/3] rc: add zx-irdec remote control driver Shawn Guo
[not found] ` <1501420993-21977-4-git-send-email-shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-08-09 13:00 ` Sean Young
[not found] ` <20170809130029.eneyqstlejfkotz2-3XSxi2G4b3iXFJAUJl40Xg@public.gmane.org>
2017-08-09 13:48 ` Shawn Guo
2017-08-09 14:42 ` Sean Young
2017-08-18 12:54 ` [PATCH v2 0/3] Add ZTE " Shawn Guo
2017-08-20 20:09 ` Sean Young
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1501420993-21977-2-git-send-email-shawnguo@kernel.org \
--to=shawnguo-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=jun.nie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=sean-hENCXIMQXOg@public.gmane.org \
--cc=shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=xie.baoyou-i+zz7BTLltu8dxfXipz/DA@public.gmane.org \
--cc=zhou.xin8-i+zz7BTLltu8dxfXipz/DA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).