From patchwork Fri Feb 28 23:28:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hogan X-Patchwork-Id: 3745141 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4B92C9F35F for ; Fri, 28 Feb 2014 23:34:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 447AD202E6 for ; Fri, 28 Feb 2014 23:34:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3676420265 for ; Fri, 28 Feb 2014 23:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752630AbaB1X36 (ORCPT ); Fri, 28 Feb 2014 18:29:58 -0500 Received: from mail-wi0-f175.google.com ([209.85.212.175]:58004 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752400AbaB1X35 (ORCPT ); Fri, 28 Feb 2014 18:29:57 -0500 Received: by mail-wi0-f175.google.com with SMTP id hm4so1360618wib.8 for ; Fri, 28 Feb 2014 15:29:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dANJ+DPMcK6TscwPB3osqkK/iXen2Bz6pt0ytxcr+uw=; b=YmktGkuDDr7LvzDniR7DQnmwjQyCKBJh8AWfbsrdHwzmyH7wldBEmNMbpWHJUy2FC0 4K0Xm6y5S/Evsgoikh9FU0ZrEa7Jh8O+6jgO6juszR0emFtMoSJk8jXZAsCSh55r56jW INStpQmseEE7uZ6e4Ej6V4lSpjvUueBnrSO0iO/b1eAO29k2TIsUkaKlFxHSAM8Tlvtl Zmv4HX2EBEkMIczAA/wYcTXKOd6HgxFB/odyoGvmbWDbAflNLaiHdNYM/CvhgEZ9GdOE XCOLy3A9cdSZq38MhWZ2iSbxAaX7SOUd7JImQGL+xODg37PxO2QS4EjMmh1kAPI+X8KM GqUA== X-Gm-Message-State: ALoCoQmk1NsMIUbjBo2ARXMm8H8MGmaSdJLNBn02NLwlMUwI91AE9VaK4+n5NyOnFE4ZlsmM/1GX X-Received: by 10.180.188.66 with SMTP id fy2mr4863496wic.45.1393630196165; Fri, 28 Feb 2014 15:29:56 -0800 (PST) Received: from radagast.lan (jahogan.plus.com. [212.159.75.221]) by mx.google.com with ESMTPSA id lz3sm9172173wic.1.2014.02.28.15.29.55 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Fri, 28 Feb 2014 15:29:55 -0800 (PST) From: James Hogan To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: James Hogan Subject: [PATCH v4 09/10] rc: img-ir: add Sharp decoder module Date: Fri, 28 Feb 2014 23:28:59 +0000 Message-Id: <1393630140-31765-10-git-send-email-james.hogan@imgtec.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393630140-31765-1-git-send-email-james.hogan@imgtec.com> References: <1393630140-31765-1-git-send-email-james.hogan@imgtec.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an img-ir module for decoding the Sharp infrared protocol. Signed-off-by: James Hogan Cc: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org --- v2: - Update to new scancode interface (32-bit NEC). - Update to new filtering interface (generic struct rc_scancode_filter). - Remove modularity and dynamic registration/unregistration, adding Sharp directly to the list of decoders in img-ir-hw.c. - Fix typo in logic 1 pulse width comment. - Set tolerance to 20%, which seemed to be needed for the cases I have. --- drivers/media/rc/img-ir/Kconfig | 7 +++ drivers/media/rc/img-ir/Makefile | 1 + drivers/media/rc/img-ir/img-ir-hw.c | 4 ++ drivers/media/rc/img-ir/img-ir-sharp.c | 99 ++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 drivers/media/rc/img-ir/img-ir-sharp.c diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig index ab36577..48627f9 100644 --- a/drivers/media/rc/img-ir/Kconfig +++ b/drivers/media/rc/img-ir/Kconfig @@ -45,3 +45,10 @@ config IR_IMG_SONY help Say Y here to enable support for the Sony protocol in the ImgTec infrared decoder block. + +config IR_IMG_SHARP + bool "Sharp protocol support" + depends on IR_IMG_HW + help + Say Y here to enable support for the Sharp protocol in the ImgTec + infrared decoder block. diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile index 978c0c6..792a3c4 100644 --- a/drivers/media/rc/img-ir/Makefile +++ b/drivers/media/rc/img-ir/Makefile @@ -4,6 +4,7 @@ img-ir-$(CONFIG_IR_IMG_HW) += img-ir-hw.o img-ir-$(CONFIG_IR_IMG_NEC) += img-ir-nec.o img-ir-$(CONFIG_IR_IMG_JVC) += img-ir-jvc.o img-ir-$(CONFIG_IR_IMG_SONY) += img-ir-sony.o +img-ir-$(CONFIG_IR_IMG_SHARP) += img-ir-sharp.o img-ir-objs := $(img-ir-y) obj-$(CONFIG_IR_IMG) += img-ir.o diff --git a/drivers/media/rc/img-ir/img-ir-hw.c b/drivers/media/rc/img-ir/img-ir-hw.c index 0d4f921..9931dfa 100644 --- a/drivers/media/rc/img-ir/img-ir-hw.c +++ b/drivers/media/rc/img-ir/img-ir-hw.c @@ -23,6 +23,7 @@ static DEFINE_SPINLOCK(img_ir_decoders_lock); extern struct img_ir_decoder img_ir_nec; extern struct img_ir_decoder img_ir_jvc; extern struct img_ir_decoder img_ir_sony; +extern struct img_ir_decoder img_ir_sharp; static bool img_ir_decoders_preprocessed; static struct img_ir_decoder *img_ir_decoders[] = { @@ -35,6 +36,9 @@ static struct img_ir_decoder *img_ir_decoders[] = { #ifdef CONFIG_IR_IMG_SONY &img_ir_sony, #endif +#ifdef CONFIG_IR_IMG_SHARP + &img_ir_sharp, +#endif NULL }; diff --git a/drivers/media/rc/img-ir/img-ir-sharp.c b/drivers/media/rc/img-ir/img-ir-sharp.c new file mode 100644 index 0000000..3397cc5 --- /dev/null +++ b/drivers/media/rc/img-ir/img-ir-sharp.c @@ -0,0 +1,99 @@ +/* + * ImgTec IR Decoder setup for Sharp protocol. + * + * Copyright 2012-2014 Imagination Technologies Ltd. + */ + +#include "img-ir-hw.h" + +/* Convert Sharp data to a scancode */ +static int img_ir_sharp_scancode(int len, u64 raw, int *scancode, u64 protocols) +{ + unsigned int addr, cmd, exp, chk; + + if (len != 15) + return -EINVAL; + + addr = (raw >> 0) & 0x1f; + cmd = (raw >> 5) & 0xff; + exp = (raw >> 13) & 0x1; + chk = (raw >> 14) & 0x1; + + /* validate data */ + if (!exp) + return -EINVAL; + if (chk) + /* probably the second half of the message */ + return -EINVAL; + + *scancode = addr << 8 | cmd; + return IMG_IR_SCANCODE; +} + +/* Convert Sharp scancode to Sharp data filter */ +static int img_ir_sharp_filter(const struct rc_scancode_filter *in, + struct img_ir_filter *out, u64 protocols) +{ + unsigned int addr, cmd, exp = 0, chk = 0; + unsigned int addr_m, cmd_m, exp_m = 0, chk_m = 0; + + addr = (in->data >> 8) & 0x1f; + addr_m = (in->mask >> 8) & 0x1f; + cmd = (in->data >> 0) & 0xff; + cmd_m = (in->mask >> 0) & 0xff; + if (cmd_m) { + /* if filtering commands, we can only match the first part */ + exp = 1; + exp_m = 1; + chk = 0; + chk_m = 1; + } + + out->data = addr | + cmd << 5 | + exp << 13 | + chk << 14; + out->mask = addr_m | + cmd_m << 5 | + exp_m << 13 | + chk_m << 14; + + return 0; +} + +/* + * Sharp decoder + * See also http://www.sbprojects.com/knowledge/ir/sharp.php + */ +struct img_ir_decoder img_ir_sharp = { + .type = RC_BIT_SHARP, + .control = { + .decoden = 0, + .decodend2 = 1, + .code_type = IMG_IR_CODETYPE_PULSEDIST, + .d1validsel = 1, + }, + /* main timings */ + .tolerance = 20, /* 20% */ + .timings = { + /* 0 symbol */ + .s10 = { + .pulse = { 320 /* 320 us */ }, + .space = { 680 /* 1 ms period */ }, + }, + /* 1 symbol */ + .s11 = { + .pulse = { 320 /* 320 us */ }, + .space = { 1680 /* 2 ms period */ }, + }, + /* free time */ + .ft = { + .minlen = 15, + .maxlen = 15, + .ft_min = 5000, /* 5 ms */ + }, + }, + /* scancode logic */ + .scancode = img_ir_sharp_scancode, + .filter = img_ir_sharp_filter, +};