From patchwork Fri Mar 14 23:04:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Hogan X-Patchwork-Id: 3835831 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 96F7ABF549 for ; Fri, 14 Mar 2014 23:07:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 97B01202A7 for ; Fri, 14 Mar 2014 23:07:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4ACF82028D for ; Fri, 14 Mar 2014 23:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755192AbaCNXG5 (ORCPT ); Fri, 14 Mar 2014 19:06:57 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:33854 "EHLO mail-wg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754985AbaCNXGz (ORCPT ); Fri, 14 Mar 2014 19:06:55 -0400 Received: by mail-wg0-f49.google.com with SMTP id a1so2744811wgh.20 for ; Fri, 14 Mar 2014 16:06:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=o0w86LFKAUtBVXU9k934q7YomH4t0cEYUQKhD1F6ySw=; b=IwO8cyqWHW5r7PYpdmBUmlhhnDK+dbhebp+em+Q2IOq1D+a2EmMsY0kCJkJZBhcycL wHq1eTvCAiA0eH3MiBpb4z8QjLqVtJGdr7yEY+3fLB86HjkZ4zL12G3wm6HjsTjnsnIO XLVOsskLGvm4fbORwKYl5X7n2Rvz2oGmLVv2bsvbIDiKQB4I5Uqh6cJfgUroG3BEu9/E maPTku+pPbBr+leXmRlvMvVZIn17bnOFSkIzwYoFfdxypWRpUHyByNQvNV0RWOJw2/tz plYm0fofqc9muikKJcH07yOq6S/ikqghq/wI5KQ922H5lk+s9+5rYvMjYFOsby1VLEGR NJLw== X-Gm-Message-State: ALoCoQkpG9eCQ22cE1sqeABkyBIbfu7BiOvsZG6fnhZRnFlBSHzq8YBfkv9BhcBBnQicwu2X2p1T X-Received: by 10.180.11.36 with SMTP id n4mr445629wib.4.1394838414398; Fri, 14 Mar 2014 16:06:54 -0700 (PDT) Received: from localhost.localdomain (jahogan.plus.com. [212.159.75.221]) by mx.google.com with ESMTPSA id dd3sm17220342wjb.9.2014.03.14.16.06.52 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Fri, 14 Mar 2014 16:06:53 -0700 (PDT) From: James Hogan To: Mauro Carvalho Chehab , =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Cc: linux-media@vger.kernel.org, James Hogan , =?UTF-8?q?David=20H=C3=A4rdeman?= Subject: [PATCH v2 1/9] rc: ir-raw: Add scancode encoder callback Date: Fri, 14 Mar 2014 23:04:11 +0000 Message-Id: <1394838259-14260-2-git-send-email-james@albanarts.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1394838259-14260-1-git-send-email-james@albanarts.com> References: <1394838259-14260-1-git-send-email-james@albanarts.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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 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 Cc: Mauro Carvalho Chehab Cc: Antti Seppälä Cc: David Härdeman --- 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/ir-raw.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/media/rc/rc-core-priv.h | 2 ++ include/media/rc-core.h | 3 +++ 3 files changed, 43 insertions(+) diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c index 763c9d1..01adc10 100644 --- a/drivers/media/rc/ir-raw.c +++ b/drivers/media/rc/ir-raw.c @@ -240,6 +240,44 @@ ir_raw_get_allowed_protocols(void) return protocols; } +/** + * 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/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h index da536c9..8afb971 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/include/media/rc-core.h b/include/media/rc-core.h index 0b9f890..8c64f9e 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -275,6 +275,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) {