From patchwork Sun Feb 7 20:13:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 8245161 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 7E7E29F6DA for ; Sun, 7 Feb 2016 20:14:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 99D17201C7 for ; Sun, 7 Feb 2016 20:14:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C648201C8 for ; Sun, 7 Feb 2016 20:14:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754804AbcBGUOX (ORCPT ); Sun, 7 Feb 2016 15:14:23 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33366 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754121AbcBGUOW (ORCPT ); Sun, 7 Feb 2016 15:14:22 -0500 Received: by mail-wm0-f66.google.com with SMTP id r129so12481356wmr.0 for ; Sun, 07 Feb 2016 12:14:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=NqWR5C38juJnsFPn7qU23s7ItDWLcAT67eCIX+dMyiU=; b=Eg97V7hgKa/3u6DARQaom1CHX5OQwyKQSo7l4eznTsgYmK5XVDCttzQ0b3ViaG5cC+ BBHkopUYQhQT2JfbG+IFNWKbCpLZ01mSDyMYW165519xOPKqAXCMcZifIif6z0q9+apD FtKUzFXKcSRKDaNxWT2clGt91XDwB/aILtCP4EScS4twb+Vzpw3H+cHDx8gr+royF7/9 iuQY9/Ki5kCmJitnpEgLc1VlJIL9k95VEjXsZj481xgul5kMHfOeA6SHNDYYwlED2Ima 5gV1iN7mDKKCviijhF3r/vyx7Iet0wEki2O1rCe8Yt1kmh0VfESkhex16GaXW35z4ajM 6kkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-type:content-transfer-encoding; bh=NqWR5C38juJnsFPn7qU23s7ItDWLcAT67eCIX+dMyiU=; b=IJj9G/whuVu3rZxBtzAsLnyULa9tL8M0PQsGLbl6yvj2o29Sjo1ewbb8WlU02qJ67m 3MpE1kTPRVDYmFHQOhxU9+OsdQToy2fy7SifIueNLAd24enEZIxwEzrNxbkAq2L/aKF4 0INFbd4Fx9elt/f049m7cGD16rkNt5BG0+bg37m5CKb/8g7WxMWEX35k1LpYZK8zZFZ6 qAFQ4Y+zyymoP+RQwkU0UQ9v9uTpH+edVuzaWtuDFZ6Iwm268bZZsu6G7Uv4C5J8/GJV IS36SLk7czA+By8kDU7l6cKGLxMiZPTsxLFrcTRo4IlfIo+QGTlxG4jGEU8tbtPHoAD6 ghNQ== X-Gm-Message-State: AG10YOR4h+EzufkZjED8qJxzO4akTl5HG9oSQriIbov2nl0Tpbnvuu7Jih8A+7bSiswTRw== X-Received: by 10.28.89.195 with SMTP id n186mr27622832wmb.49.1454876061379; Sun, 07 Feb 2016 12:14:21 -0800 (PST) Received: from ?IPv6:2003:62:5f55:ba00:c96c:24f6:430b:17c6? (p200300625F55BA00C96C24F6430B17C6.dip0.t-ipconnect.de. [2003:62:5f55:ba00:c96c:24f6:430b:17c6]) by smtp.googlemail.com with ESMTPSA id i5sm26320365wja.23.2016.02.07.12.14.20 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Feb 2016 12:14:20 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 1/3] media: rc: add core functionality to store the most recent raw data To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Message-ID: <56B7A57C.1070506@gmail.com> Date: Sun, 7 Feb 2016 21:13:48 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 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=-7.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Add functionality to the core to store the most recent raw packet. It's used to expose this data via sysfs. To use this functionality a driver has to set enable_sysfs_lrp in struct rc_dev and add a call to ir_raw_store_sysfs_lrp for storing a raw byte into the buffer. Signed-off-by: Heiner Kallweit --- drivers/media/rc/rc-core-priv.h | 6 ++++++ drivers/media/rc/rc-ir-raw.c | 34 ++++++++++++++++++++++++++++++++++ include/media/rc-core.h | 3 +++ 3 files changed, 43 insertions(+) diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h index 585d5e5..6193883 100644 --- a/drivers/media/rc/rc-core-priv.h +++ b/drivers/media/rc/rc-core-priv.h @@ -19,6 +19,8 @@ /* Define the max number of pulse/space transitions to buffer */ #define MAX_IR_EVENT_SIZE 512 +#define BUF_SYSFS_LRP_SZ 128 + #include #include #include @@ -43,6 +45,10 @@ struct ir_raw_event_ctrl { ktime_t last_event; /* when last event occurred */ enum raw_event_type last_type; /* last event type */ struct rc_dev *dev; /* pointer to the parent rc_dev */ + /* used for exposing the last raw packets via sysfs */ + u8 buf_sysfs_lrp[BUF_SYSFS_LRP_SZ]; + unsigned buf_sysfs_lrp_cnt; + ktime_t buf_sysfs_lrp_last; /* raw decoder state follows */ struct ir_raw_event prev_ev; diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c index 144304c..6bf2b56 100644 --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -20,6 +20,8 @@ #include #include "rc-core-priv.h" +#define RESTART_SYSFS_LRP_MS 1000 + /* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */ static LIST_HEAD(ir_raw_client_list); @@ -66,6 +68,38 @@ static int ir_raw_event_thread(void *data) } /** + * ir_raw_store_sysfs_lrp() - pass a raw byte to sysfs buffer + * @dev: the struct rc_dev device descriptor + * @val: the raw value to store + * + * This routine (which may be called from interrupt context) stores a + * raw byte in the sysfs buffer. It only needs to be called if the most + * recent series of raw bytes should be available via sysfs. + */ +void ir_raw_store_sysfs_lrp(struct rc_dev *dev, u8 val) +{ + ktime_t now; + struct ir_raw_event_ctrl *raw = dev->raw; + + if (!raw || !dev->enable_sysfs_lrp) + return; + + now = ktime_get(); + spin_lock(&raw->lock); + + if (ktime_ms_delta(now, raw->buf_sysfs_lrp_last) > + RESTART_SYSFS_LRP_MS) + raw->buf_sysfs_lrp_cnt = 0; + raw->buf_sysfs_lrp_last = now; + + if (raw->buf_sysfs_lrp_cnt < BUF_SYSFS_LRP_SZ) + raw->buf_sysfs_lrp[raw->buf_sysfs_lrp_cnt++] = val; + + spin_unlock(&raw->lock); +} +EXPORT_SYMBOL_GPL(ir_raw_store_sysfs_lrp); + +/** * ir_raw_event_store() - pass a pulse/space duration to the raw ir decoders * @dev: the struct rc_dev device descriptor * @ev: the struct ir_raw_event descriptor of the pulse/space diff --git a/include/media/rc-core.h b/include/media/rc-core.h index f649470..9542891 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -71,6 +71,7 @@ enum rc_filter_type { * anyone can call show_protocols or store_protocols * @minor: unique minor remote control device number * @raw: additional data for raw pulse/space devices + * @enable_sysfs_lrp: expose last raw packets via sysfs * @input_dev: the input child device used to communicate events to userspace * @driver_type: specifies if protocol decoding is done in hardware or software * @idle: used to keep track of RX state @@ -131,6 +132,7 @@ struct rc_dev { struct mutex lock; unsigned int minor; struct ir_raw_event_ctrl *raw; + bool enable_sysfs_lrp; struct input_dev *input_dev; enum rc_driver_type driver_type; bool idle; @@ -246,6 +248,7 @@ static inline void init_ir_raw_event(struct ir_raw_event *ev) #define MS_TO_NS(msec) ((msec) * 1000 * 1000) void ir_raw_event_handle(struct rc_dev *dev); +void ir_raw_store_sysfs_lrp(struct rc_dev *dev, u8 val); int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev); 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,