From patchwork Tue Mar 31 17:48:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QW50dGkgU2VwcMOkbMOk?= X-Patchwork-Id: 6133171 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6F8C79F349 for ; Tue, 31 Mar 2015 17:49:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C065201C8 for ; Tue, 31 Mar 2015 17:48:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FFA8201C0 for ; Tue, 31 Mar 2015 17:48:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752536AbbCaRsz (ORCPT ); Tue, 31 Mar 2015 13:48:55 -0400 Received: from mail-la0-f49.google.com ([209.85.215.49]:35544 "EHLO mail-la0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752285AbbCaRsy (ORCPT ); Tue, 31 Mar 2015 13:48:54 -0400 Received: by lahf3 with SMTP id f3so18153721lah.2 for ; Tue, 31 Mar 2015 10:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=7pyV92hk7AYpqMkItoYNCF+Oh4uME8DzHfE1anHtGDg=; b=BBlgIo8hPGFIFvIj2LtwBbri5KAmPs8Qjn6Y2vQU11X6Z0Gr/Ek/3edLcrezprd/it dM2Ua8EMiy6VpVs4f7x1dPy8DAqovs5O9zcJWO6brBJLsz8NeihDNK/YTn7YBin/esiv Qs8W+7ZsbydzFP1fUj4ckgADMfgjNUQmxumaH5/ySvGx0/FoXuBEs562xW+WFmtImkse Q1ZrUA5E35822m3yxAeBisPH7dh1hwtAijlx0jfQFP2hBVRU8JHF0cBOBrb1qT7JWOxv KtO5zmsB8LCzC5liM60K0lHTGCUpG3/6c7HWfIzNJYOPPVL3bnRFTBGBOZshvGH8rYzX oP3A== X-Received: by 10.112.29.36 with SMTP id g4mr23908490lbh.56.1427824132915; Tue, 31 Mar 2015 10:48:52 -0700 (PDT) Received: from pixie.elisa-laajakaista.fi (a91-154-178-36.elisa-laajakaista.fi. [91.154.178.36]) by mx.google.com with ESMTPSA id qw1sm2771382lbb.21.2015.03.31.10.48.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Mar 2015 10:48:51 -0700 (PDT) From: =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= To: linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= , James Hogan , =?UTF-8?q?David=20H=C3=A4rdeman?= Subject: [PATCH v3 1/7] rc: rc-ir-raw: Add scancode encoder callback Date: Tue, 31 Mar 2015 20:48:06 +0300 Message-Id: <1427824092-23163-2-git-send-email-a.seppala@gmail.com> X-Mailer: git-send-email 2.0.5 In-Reply-To: <1427824092-23163-1-git-send-email-a.seppala@gmail.com> References: <1427824092-23163-1-git-send-email-a.seppala@gmail.com> MIME-Version: 1.0 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: James Hogan Add a callback to raw ir handlers for encoding and modulating a scancode to a set of raw events. This could be used for transmit, or for converting a wakeup scancode filter to a form that is more suitable for raw hardware wake up filters. Signed-off-by: James Hogan Signed-off-by: Antti Seppälä Cc: David Härdeman --- Notes: Changes in v3: - Ported to apply against latest media-tree Changes in v2: - Alter encode API to return -ENOBUFS when there isn't enough buffer space. When this occurs all buffer contents must have been written with the partial encoding of the scancode. This is to allow drivers such as nuvoton-cir to provide a shorter buffer and still get a useful partial encoding for the wakeup pattern. drivers/media/rc/rc-core-priv.h | 2 ++ drivers/media/rc/rc-ir-raw.c | 37 +++++++++++++++++++++++++++++++++++++ include/media/rc-core.h | 3 +++ 3 files changed, 42 insertions(+) diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h index b68d4f76..122c25f 100644 --- a/drivers/media/rc/rc-core-priv.h +++ b/drivers/media/rc/rc-core-priv.h @@ -25,6 +25,8 @@ struct ir_raw_handler { u64 protocols; /* which are handled by this handler */ int (*decode)(struct rc_dev *dev, struct ir_raw_event event); + int (*encode)(u64 protocols, const struct rc_scancode_filter *scancode, + struct ir_raw_event *events, unsigned int max); /* These two should only be used by the lirc decoder */ int (*raw_register)(struct rc_dev *dev); diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c index b732ac6..dd47fe5 100644 --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -246,6 +246,43 @@ static int change_protocol(struct rc_dev *dev, u64 *rc_type) return 0; } +/** + * ir_raw_encode_scancode() - Encode a scancode as raw events + * + * @protocols: permitted protocols + * @scancode: scancode filter describing a single scancode + * @events: array of raw events to write into + * @max: max number of raw events + * + * Attempts to encode the scancode as raw events. + * + * Returns: The number of events written. + * -ENOBUFS if there isn't enough space in the array to fit the + * encoding. In this case all @max events will have been written. + * -EINVAL if the scancode is ambiguous or invalid, or if no + * compatible encoder was found. + */ +int ir_raw_encode_scancode(u64 protocols, + const struct rc_scancode_filter *scancode, + struct ir_raw_event *events, unsigned int max) +{ + struct ir_raw_handler *handler; + int ret = -EINVAL; + + mutex_lock(&ir_raw_handler_lock); + list_for_each_entry(handler, &ir_raw_handler_list, list) { + if (handler->protocols & protocols && handler->encode) { + ret = handler->encode(protocols, scancode, events, max); + if (ret >= 0 || ret == -ENOBUFS) + break; + } + } + mutex_unlock(&ir_raw_handler_lock); + + return ret; +} +EXPORT_SYMBOL(ir_raw_encode_scancode); + /* * Used to (un)register raw event clients */ diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 2c7fbca..5703c08 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -250,6 +250,9 @@ int ir_raw_event_store_edge(struct rc_dev *dev, enum raw_event_type type); int ir_raw_event_store_with_filter(struct rc_dev *dev, struct ir_raw_event *ev); void ir_raw_event_set_idle(struct rc_dev *dev, bool idle); +int ir_raw_encode_scancode(u64 protocols, + const struct rc_scancode_filter *scancode, + struct ir_raw_event *events, unsigned int max); static inline void ir_raw_event_reset(struct rc_dev *dev) {