From patchwork Mon Jan 20 19:39:45 2014 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: 3514291 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 57F259F2D6 for ; Mon, 20 Jan 2014 19:40:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F38C20142 for ; Mon, 20 Jan 2014 19:40:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 668BA2013D for ; Mon, 20 Jan 2014 19:40:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752684AbaATTkM (ORCPT ); Mon, 20 Jan 2014 14:40:12 -0500 Received: from mail-la0-f42.google.com ([209.85.215.42]:51422 "EHLO mail-la0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752209AbaATTkJ (ORCPT ); Mon, 20 Jan 2014 14:40:09 -0500 Received: by mail-la0-f42.google.com with SMTP id hr13so3908551lab.29 for ; Mon, 20 Jan 2014 11:40:08 -0800 (PST) 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=vSa7AP71ATek7kL5ywAYf9E8rM6grUm14kNAS9cOwFU=; b=rH98zvt9fNIIH7KXxNDImoGkcRjj60UysN6YUnYk7cAwTTCo0RbSgSWn6nwMCjT7hc 5LTxeuXrMZkZANoj1EVDKMO4hTs3zI5l+c4Sd5hMJiH/HNB4B437bPNFVhbzXvPilkI+ ctNz41AnNYOoMLGl6iH41PYkNvLFseW96zigGSYScAwjbiwmxRy00q7nvBon8wRm1uSr N/lVvKBPsqg/B83YDc89bNoZ/sEo6I7ooI1pUuKNn8b0/6OhYrS01YoQnneOvkFiJHvB tvT+XTij6VzEshycVIZsBuNOvBwNqDs9oER9Dt9DTFh0sa9zV7qW2KRwvYxflWgRuZHc e56w== X-Received: by 10.112.163.67 with SMTP id yg3mr5963474lbb.17.1390246808286; Mon, 20 Jan 2014 11:40:08 -0800 (PST) Received: from pixie.elisa-laajakaista.fi (a88-114-92-24.elisa-laajakaista.fi. [88.114.92.24]) by mx.google.com with ESMTPSA id np10sm1681402lbb.7.2014.01.20.11.40.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jan 2014 11:40:07 -0800 (PST) From: =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Subject: [RFC PATCH 2/4] rc-core: Add support for reading/writing wakeup scancodes via sysfs Date: Mon, 20 Jan 2014 21:39:45 +0200 Message-Id: <1390246787-15616-3-git-send-email-a.seppala@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390246787-15616-1-git-send-email-a.seppala@gmail.com> References: <20140115173559.7e53239a@samsung.com> <1390246787-15616-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=-7.3 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=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 This patch adds support for /sys/class/rc/rc?/wakeup_scancodes file which can be used to read/write new wakeup scancodes to/from hardware. The contents of the scancode file are simply white space separated bytes. How to read: cat /sys/class/rc/rc?/wakeup_scancodes How to write: echo "0x1 0x2 0x3" > /sys/class/rc/rc?/wakeup_scancodes Signed-off-by: Antti Seppälä --- drivers/media/rc/rc-main.c | 129 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 02e2f38..a2a68f3 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -967,6 +967,119 @@ out: return ret; } +/** + * show_wakeup_scancodes() - shows the current IR wake scancode(s) + * @device: the device descriptor + * @mattr: the device attribute struct (unused) + * @buf: a pointer to the output buffer + * + * This routine is a callback routine for input read the IR wake scancode(s). + * it is trigged by reading /sys/class/rc/rc?/wakeup_scancodes. + * It returns the currently active IR wake scancode or empty buffer if wake + * scancode is not active. + * + * dev->lock is taken to guard against races between device + * registration, store_wakeup_scancodes and show_wakeup_scancodes. + */ +static ssize_t show_wakeup_scancodes(struct device *device, + struct device_attribute *mattr, char *buf) +{ + int ret, pos = 0; + struct rc_wakeup_scancode *scancode, *next; + LIST_HEAD(scancode_list); + struct rc_dev *dev = to_rc_dev(device); + + if (!dev || !dev->s_wakeup_scancodes) + return -ENODEV; + + mutex_lock(&dev->lock); + + ret = dev->s_wakeup_scancodes(dev, &scancode_list, 0); + + list_for_each_entry_safe_reverse(scancode, next, &scancode_list, + list_item) { + pos += scnprintf(buf + pos, PAGE_SIZE - pos, "0x%x ", + scancode->value); + list_del(&scancode->list_item); + kfree(scancode); + } + pos += scnprintf(buf + pos, PAGE_SIZE - pos, "\n"); + + mutex_unlock(&dev->lock); + + if (ret < 0) + return ret; + + return pos; +} + +/** + * store_wakeup_scancodes() - changes the current IR wake scancode(s) + * @device: the device descriptor + * @mattr: the device attribute struct (unused) + * @buf: a pointer to the input buffer + * @len: length of the input buffer + * + * This routine is for changing the IR wake scancode. + * It is trigged by writing to /sys/class/rc/rc?/wakeup_scancodes. + * Writing bytes separated by white space will pass them to the hardware. + * Writing "" (empty) will clear active wake scancode. + * Returns -EINVAL if too many values or invalid values were used + * otherwise @len. + * + * dev->lock is taken to guard against races between device + * registration, store_wakeup_scancodes and show_wakeup_scancodes. + */ +static ssize_t store_wakeup_scancodes(struct device *device, + struct device_attribute *mattr, + const char *data, + size_t len) +{ + int ret = 0, error = 0; + char *tmp; + u8 value; + struct rc_wakeup_scancode *scancode, *next; + LIST_HEAD(scancode_list); + struct rc_dev *dev = to_rc_dev(device); + + if (!dev || !dev->s_wakeup_scancodes) + return -ENODEV; + + mutex_lock(&dev->lock); + + while ((tmp = strsep((char **) &data, " ,\t\n")) != NULL) { + if (!*tmp) + break; + + if (sscanf(tmp, "0x%2hhx", &value) != 1 && + sscanf(tmp, "%2hhx", &value) != 1) { + error = 1; + break; + } else { + scancode = kmalloc(sizeof(struct rc_wakeup_scancode), + GFP_KERNEL); + scancode->value = value; + list_add(&scancode->list_item, &scancode_list); + } + } + + if (error) + IR_dprintk(1, "Error parsing value of %s", tmp); + else + ret = dev->s_wakeup_scancodes(dev, &scancode_list, 1); + + list_for_each_entry_safe(scancode, next, &scancode_list, list_item) { + list_del(&scancode->list_item); + kfree(scancode); + } + + mutex_unlock(&dev->lock); + if (ret < 0) + return ret; + + return error ? -EINVAL : len; +} + static void rc_dev_release(struct device *device) { } @@ -1019,6 +1132,15 @@ static struct device_type rc_dev_type = { .uevent = rc_dev_uevent, }; +static struct device_attribute dev_attr_wakeup_scancodes = { + .attr = { + .name = "wakeup_scancodes", + .mode = S_IRUGO | S_IWUSR, + }, + .show = show_wakeup_scancodes, + .store = store_wakeup_scancodes, +}; + struct rc_dev *rc_allocate_device(void) { struct rc_dev *dev; @@ -1175,6 +1297,13 @@ int rc_register_device(struct rc_dev *dev) dev->enabled_protocols = rc_type; } + /* Create sysfs entry only if device has wake scancode support */ + if (dev->s_wakeup_scancodes) { + rc = device_create_file(&dev->dev, &dev_attr_wakeup_scancodes); + if (rc < 0) + goto out_raw; + } + mutex_unlock(&dev->lock); IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n",