From patchwork Sat Apr 29 10:03:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?RGF2aWQgSMODwqRyZGVtYW4=?= X-Patchwork-Id: 9705745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 59860602BE for ; Sat, 29 Apr 2017 10:03:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38F0A2863C for ; Sat, 29 Apr 2017 10:03:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2985B28677; Sat, 29 Apr 2017 10:03:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A81D2863C for ; Sat, 29 Apr 2017 10:03:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S376398AbdD2KDe (ORCPT ); Sat, 29 Apr 2017 06:03:34 -0400 Received: from vader.hardeman.nu ([95.142.160.32]:35733 "EHLO hardeman.nu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1948352AbdD2KDd (ORCPT ); Sat, 29 Apr 2017 06:03:33 -0400 Received: from hardeman.nu (zeus.hardeman.nu [IPv6:fd27:2a41:8fcb:2::a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by vader.hardeman.nu (Postfix) with ESMTPSA id 141183833; Sat, 29 Apr 2017 12:03:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hardeman.nu; s=hardeman-201703; t=1493460210; bh=nu7devMhzm7DeOIqlzXIRylwFglUkmH88I+fKWAGwo4=; h=Subject:From:To:Cc:Date:From; b=pvc/8T4NataC1ORvnVIEvUC0cKien5aXWWiK//n7XRlHwNNPw0heK5hGA9cG3HJH/ fLv2VrZRQs7wUSWLhuXAk32NJbUsmIeDwvxmpAaSPl7nFMGMsxtuU64nZfM6Pmy4or nbzD4spdpOVTN5ErtAZQvAXCb1bfcoPzg1nHwLg/6FSm/hXZlUqpvPwuFSA06FF35H 0PmcHStx2ljbCe5cPya+nPTxfjhCFdUzhRO7aJ+c7XN+k+ABgaVSntvWnXZu+3mZOm 5vogun8VxbUQcfv61TMNvcjCNNEBqCoqsmLqQEDX2IDxqGa4IxDhJ5B00Foq1pyQm0 LNuQ2jttmKfsg== Received: (nullmailer pid 4180 invoked by uid 1000); Sat, 29 Apr 2017 10:03:29 -0000 Subject: [PATCH] rc-core: export the hardware type to sysfs From: David =?utf-8?b?SMOkcmRlbWFu?= To: linux-media@vger.kernel.org Cc: mchehab@s-opensource.com, sean@mess.org Date: Sat, 29 Apr 2017 12:03:29 +0200 Message-ID: <149346020957.4157.4374621534433639100.stgit@zeus.hardeman.nu> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Exporting the hardware type makes it possible for userspace applications to know what to expect from the hardware. This makes it possible to write more user-friendly userspace apps. Note that the size of sysfs_groups[] in struct rc_dev is not changed by this patch because it was already large enough for one more group. Signed-off-by: David Härdeman --- drivers/media/rc/rc-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 85f95441b85b..e0f9b322ab02 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -1294,6 +1294,38 @@ static ssize_t store_protocols(struct device *device, } /** + * show_hwtype() - shows the hardware type in sysfs + * @device: the &struct device descriptor + * @attr: the &struct device_attribute + * @buf: a pointer to the output buffer + * + * This callback function is used to get the hardware type of an rc device. + * It is triggered by reading /sys/class/rc/rc?/hwtype. + * + * Return: the number of bytes read or a negative error code. + */ +static ssize_t show_hwtype(struct device *device, + struct device_attribute *attr, + char *buf) +{ + struct rc_dev *dev = to_rc_dev(device); + + switch (dev->driver_type) { + case RC_DRIVER_SCANCODE: + return sprintf(buf, "scancode\n"); + case RC_DRIVER_IR_RAW_TX: + return sprintf(buf, "ir-tx\n"); + case RC_DRIVER_IR_RAW: + if (dev->tx_ir) + return sprintf(buf, "ir-tx-rx\n"); + else + return sprintf(buf, "ir-rx\n"); + default: + return sprintf(buf, "\n"); + } +} + +/** * show_filter() - shows the current scancode filter value or mask * @device: the device descriptor * @attr: the device attribute struct @@ -1613,6 +1645,7 @@ static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env) * Static device attribute struct with the sysfs attributes for IR's */ static DEVICE_ATTR(protocols, 0644, show_protocols, store_protocols); +static DEVICE_ATTR(hwtype, 0444, show_hwtype, NULL); static DEVICE_ATTR(wakeup_protocols, 0644, show_wakeup_protocols, store_wakeup_protocols); static RC_FILTER_ATTR(filter, S_IRUGO|S_IWUSR, @@ -1633,6 +1666,15 @@ static struct attribute_group rc_dev_protocol_attr_grp = { .attrs = rc_dev_protocol_attrs, }; +static struct attribute *rc_dev_hwtype_attrs[] = { + &dev_attr_hwtype.attr, + NULL, +}; + +static struct attribute_group rc_dev_hwtype_attr_grp = { + .attrs = rc_dev_hwtype_attrs, +}; + static struct attribute *rc_dev_filter_attrs[] = { &dev_attr_filter.attr.attr, &dev_attr_filter_mask.attr.attr, @@ -1863,6 +1905,7 @@ int rc_register_device(struct rc_dev *dev) dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp; if (dev->s_wakeup_filter) dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; + dev->sysfs_groups[attr++] = &rc_dev_hwtype_attr_grp; dev->sysfs_groups[attr++] = NULL; if (dev->driver_type != RC_DRIVER_IR_RAW_TX) {