From patchwork Fri Mar 11 07:37:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafi Rubin X-Patchwork-Id: 627491 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2B7d8tQ008163 for ; Fri, 11 Mar 2011 07:39:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753629Ab1CKHjI (ORCPT ); Fri, 11 Mar 2011 02:39:08 -0500 Received: from fox.seas.upenn.edu ([158.130.68.12]:54066 "EHLO fox.seas.upenn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752687Ab1CKHjH (ORCPT ); Fri, 11 Mar 2011 02:39:07 -0500 Received: from hex.seas.upenn.edu (hex.seas.upenn.edu [158.130.62.166]) by fox.seas.upenn.edu (8.14.3/8.14.3) with ESMTP id p2B7bxpJ028702; Fri, 11 Mar 2011 02:37:59 -0500 From: Rafi Rubin To: jkosina@suse.cz, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, micki@n-trig.com, rydberg@euromail.se, chatty@enac.fr, dmitry.torokhov@gmail.com, Rafi Rubin Subject: [PATCH 1/2] hid-ntrig: sysfs nodes for modes Date: Fri, 11 Mar 2011 02:37:51 -0500 Message-Id: <1299829072-19489-1-git-send-email-rafi@seas.upenn.edu> X-Mailer: git-send-email 1.7.2.3 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15, 1.0.148, 0.0.0000 definitions=2011-03-11_02:2011-03-11, 2011-03-11, 1970-01-01 signatures=0 X-Proofpoint-Spam-Reason: safe Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 11 Mar 2011 07:39:09 +0000 (UTC) diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index fa862c5..24ab6a5 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c @@ -24,6 +24,8 @@ #define NTRIG_DUPLICATE_USAGES 0x001 +static const char *ntrig_modes[4] = { "pen", "touch", "auto", "dual" }; + static unsigned int min_width; module_param(min_width, uint, 0644); MODULE_PARM_DESC(min_width, "Minimum touch contact width to accept."); @@ -430,6 +432,64 @@ static ssize_t set_deactivate_slack(struct device *dev, static DEVICE_ATTR(deactivate_slack, S_IWUSR | S_IRUGO, show_deactivate_slack, set_deactivate_slack); + +static ssize_t show_mode(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int mode = ntrig_get_mode(container_of(dev, struct hid_device, dev)); + int i, ret; + char *s = buf; + + if (mode < 0) + return mode; + + + for (i = 0; i < 4; i++) + s += sprintf(s, "%s%s%s ", (i == mode) ? "[" : "", + ntrig_modes[i], (i == mode) ? "]" : ""); + + if (mode >= 4) + s += sprintf(s, "[%d]\n", mode); + else + *(s - 1) = '\n'; + + ret = s - buf; + + return ret; +} + +static ssize_t store_mode(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int len; + int i; + int mode = -EINVAL; + char *p; + + p = memchr(buf, '\n', count); + len = p ? p - buf : count; + + if (len == 1 && buf[0] >= '0' && buf[0] <= '4') { + mode = buf[0] - '0'; + } else + for (i = 0; i < 4; i++) + if (len == strlen(ntrig_modes[i]) && + !strncmp(buf, ntrig_modes[i], len)) { + mode = i; + break; + } + + if (mode < 0) + return mode; + + ntrig_set_mode(container_of(dev, struct hid_device, dev), mode); + + return count; +} +static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, store_mode); + static struct attribute *sysfs_attrs[] = { &dev_attr_sensor_physical_width.attr, &dev_attr_sensor_physical_height.attr, @@ -441,6 +501,7 @@ static struct attribute *sysfs_attrs[] = { &dev_attr_activation_width.attr, &dev_attr_activation_height.attr, &dev_attr_deactivate_slack.attr, + &dev_attr_mode.attr, NULL };