@@ -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
};