From patchwork Sun Feb 7 20:14:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 8245171 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9152EBEEE5 for ; Sun, 7 Feb 2016 20:14:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 972A1201ED for ; Sun, 7 Feb 2016 20:14:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97DE2201C7 for ; Sun, 7 Feb 2016 20:14:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754813AbcBGUOZ (ORCPT ); Sun, 7 Feb 2016 15:14:25 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33380 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754797AbcBGUOY (ORCPT ); Sun, 7 Feb 2016 15:14:24 -0500 Received: by mail-wm0-f66.google.com with SMTP id r129so12481421wmr.0 for ; Sun, 07 Feb 2016 12:14:23 -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=ab5XrbQA8jTsCFfZ4/R50nZjqQ52sR/0mhw0FA1uZ94=; b=Ee9YvEfFks65n+j8h8MGMCW7I6q3zjBi/Chrg6AHli1pAygns7zHGmS0AqeVm8qVjw 88MsJZAytz6Qi8hLGUqiWahlSgqOtuAo76DxnJAwiBIJOcs3rIVA1kZJXHMz+h2CODta udUJR+sWmMkpRL/4o6N7vlMkIflPXeMaEksBj9dRqtiQoFYrYGaZVlbHldXZebnG8l5S 6vnuAro3pw6gAgD1fUWGkAWqB48ecG0DJgFzGMJDttJ0bKjzFhlzWElrjfxYf3Pg0KTp 5l0IDtb6p6FvVgolLUEdIOtUcznB1M4ereJY3+Y5YkIyEh4bC6DqYN00SNfcRDLv9/pZ GZeg== 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=ab5XrbQA8jTsCFfZ4/R50nZjqQ52sR/0mhw0FA1uZ94=; b=LLMfe0ARKQW85lCZ4A9gsYnuRH1ZfruaodPkyWN6Ux20M0vp8px3+Ds3m9w5vf0600 UKn4ChcNf3nRpTUTf0lUgppZ8q9xWQVnv7A5rVfz5OEEnsJnRoisNSnrbPWONSzwYIO+ ueWWLsXtg9RafrWApq2F6zK1wawaAjHHQKwk7+Yfv4rzNn2QmgSr5WNJFAEAgGUY3wu3 WQgvP8Gh8e+653e5AIYzLfoLAUI2FbyqQXnaAkNighWt+x8nVEgsRJEgBVFHuovxnaU3 9+e1dT9vQMdqNbieH9ksWOu3gJvQBNEcdBRA0Xxd16gDCnLgIwwAZc/u7eJul5HqlSXP AEAA== X-Gm-Message-State: AG10YOT5OqTgKk1NlUi4R6feCtWuwFDnGZVsGJzxIa1I4aMlunvgLVmuatCbN7Ycns6TRg== X-Received: by 10.28.173.208 with SMTP id w199mr25283125wme.45.1454876062852; Sun, 07 Feb 2016 12:14:22 -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 m63sm9283235wmc.3.2016.02.07.12.14.21 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Feb 2016 12:14:22 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 2/3] media: rc: expose most recent raw packet via sysfs To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Message-ID: <56B7A592.9060700@gmail.com> Date: Sun, 7 Feb 2016 21:14:10 +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 This patch introduces a binary read-only sysfs attribute last_raw_packet to expose the most recent raw packet to userspace. Signed-off-by: Heiner Kallweit --- drivers/media/rc/rc-main.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ include/media/rc-core.h | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 1042fa3..1b1ae6d 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -1246,6 +1246,47 @@ unlock: return (ret < 0) ? ret : len; } +/** + * last_raw_packet_read() - shows the most recent packet of raw bytes + * This is a binary attribute. + * + * This routine is a callback routine to read the most recent packet of + * raw bytes received. + * It is triggered by reading /sys/class/rc/rc?/last_raw_packet. + * Most recent means up to BUF_SYSFS_LRP_SZ bytes after the last break + * of at least RESTART_SYSFS_LRP_MS milliseconds. + * + * Primary use is assembling a wakeup sequence for chips supporting this + * feature (e.g. nuvoton-cir). Apart from that it can be used for + * debugging purposes. + */ +static ssize_t last_raw_packet_read(struct file *fp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t off, size_t count) +{ + struct device *dev = kobj_to_dev(kobj); + struct rc_dev *rc_dev = to_rc_dev(dev); + unsigned long flags; + size_t cnt; + + if (!rc_dev->raw) + return 0; + + spin_lock_irqsave(&rc_dev->raw->lock, flags); + + if (off >= rc_dev->raw->buf_sysfs_lrp_cnt) { + spin_unlock_irqrestore(&rc_dev->raw->lock, flags); + return 0; + } + + cnt = min_t(size_t, count, rc_dev->raw->buf_sysfs_lrp_cnt - off); + memcpy(buf, rc_dev->raw->buf_sysfs_lrp + off, cnt); + + spin_unlock_irqrestore(&rc_dev->raw->lock, flags); + + return cnt; +} + static void rc_dev_release(struct device *device) { } @@ -1284,6 +1325,7 @@ static RC_FILTER_ATTR(wakeup_filter, S_IRUGO|S_IWUSR, show_filter, store_filter, RC_FILTER_WAKEUP, false); static RC_FILTER_ATTR(wakeup_filter_mask, S_IRUGO|S_IWUSR, show_filter, store_filter, RC_FILTER_WAKEUP, true); +static BIN_ATTR_RO(last_raw_packet, BUF_SYSFS_LRP_SZ); static struct attribute *rc_dev_protocol_attrs[] = { &dev_attr_protocols.attr.attr, @@ -1323,6 +1365,15 @@ static struct attribute_group rc_dev_wakeup_filter_attr_grp = { .attrs = rc_dev_wakeup_filter_attrs, }; +static struct bin_attribute *rc_dev_raw_lrp_attrs[] = { + &bin_attr_last_raw_packet, + NULL, +}; + +static struct attribute_group rc_dev_raw_lrp_attr_grp = { + .bin_attrs = rc_dev_raw_lrp_attrs, +}; + static struct device_type rc_dev_type = { .release = rc_dev_release, .uevent = rc_dev_uevent, @@ -1417,6 +1468,8 @@ int rc_register_device(struct rc_dev *dev) dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; if (dev->change_wakeup_protocol) dev->sysfs_groups[attr++] = &rc_dev_wakeup_protocol_attr_grp; + if (dev->enable_sysfs_lrp) + dev->sysfs_groups[attr++] = &rc_dev_raw_lrp_attr_grp; dev->sysfs_groups[attr++] = NULL; /* diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 9542891..e2d89ea 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -122,7 +122,7 @@ enum rc_filter_type { */ struct rc_dev { struct device dev; - const struct attribute_group *sysfs_groups[5]; + const struct attribute_group *sysfs_groups[6]; const char *input_name; const char *input_phys; struct input_id input_id;