18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  HID driver for N-Trig touchscreens
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2008-2010 Rafi Rubin
68c2ecf20Sopenharmony_ci *  Copyright (c) 2009-2010 Stephane Chatty
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/device.h>
138c2ecf20Sopenharmony_ci#include <linux/hid.h>
148c2ecf20Sopenharmony_ci#include <linux/usb.h>
158c2ecf20Sopenharmony_ci#include "usbhid/usbhid.h"
168c2ecf20Sopenharmony_ci#include <linux/module.h>
178c2ecf20Sopenharmony_ci#include <linux/slab.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "hid-ids.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define NTRIG_DUPLICATE_USAGES	0x001
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic unsigned int min_width;
248c2ecf20Sopenharmony_cimodule_param(min_width, uint, 0644);
258c2ecf20Sopenharmony_ciMODULE_PARM_DESC(min_width, "Minimum touch contact width to accept.");
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic unsigned int min_height;
288c2ecf20Sopenharmony_cimodule_param(min_height, uint, 0644);
298c2ecf20Sopenharmony_ciMODULE_PARM_DESC(min_height, "Minimum touch contact height to accept.");
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic unsigned int activate_slack = 1;
328c2ecf20Sopenharmony_cimodule_param(activate_slack, uint, 0644);
338c2ecf20Sopenharmony_ciMODULE_PARM_DESC(activate_slack, "Number of touch frames to ignore at "
348c2ecf20Sopenharmony_ci		 "the start of touch input.");
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic unsigned int deactivate_slack = 4;
378c2ecf20Sopenharmony_cimodule_param(deactivate_slack, uint, 0644);
388c2ecf20Sopenharmony_ciMODULE_PARM_DESC(deactivate_slack, "Number of empty frames to ignore before "
398c2ecf20Sopenharmony_ci		 "deactivating touch.");
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic unsigned int activation_width = 64;
428c2ecf20Sopenharmony_cimodule_param(activation_width, uint, 0644);
438c2ecf20Sopenharmony_ciMODULE_PARM_DESC(activation_width, "Width threshold to immediately start "
448c2ecf20Sopenharmony_ci		 "processing touch events.");
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic unsigned int activation_height = 32;
478c2ecf20Sopenharmony_cimodule_param(activation_height, uint, 0644);
488c2ecf20Sopenharmony_ciMODULE_PARM_DESC(activation_height, "Height threshold to immediately start "
498c2ecf20Sopenharmony_ci		 "processing touch events.");
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct ntrig_data {
528c2ecf20Sopenharmony_ci	/* Incoming raw values for a single contact */
538c2ecf20Sopenharmony_ci	__u16 x, y, w, h;
548c2ecf20Sopenharmony_ci	__u16 id;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	bool tipswitch;
578c2ecf20Sopenharmony_ci	bool confidence;
588c2ecf20Sopenharmony_ci	bool first_contact_touch;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	bool reading_mt;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	__u8 mt_footer[4];
638c2ecf20Sopenharmony_ci	__u8 mt_foot_count;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	/* The current activation state. */
668c2ecf20Sopenharmony_ci	__s8 act_state;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	/* Empty frames to ignore before recognizing the end of activity */
698c2ecf20Sopenharmony_ci	__s8 deactivate_slack;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	/* Frames to ignore before acknowledging the start of activity */
728c2ecf20Sopenharmony_ci	__s8 activate_slack;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	/* Minimum size contact to accept */
758c2ecf20Sopenharmony_ci	__u16 min_width;
768c2ecf20Sopenharmony_ci	__u16 min_height;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	/* Threshold to override activation slack */
798c2ecf20Sopenharmony_ci	__u16 activation_width;
808c2ecf20Sopenharmony_ci	__u16 activation_height;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	__u16 sensor_logical_width;
838c2ecf20Sopenharmony_ci	__u16 sensor_logical_height;
848c2ecf20Sopenharmony_ci	__u16 sensor_physical_width;
858c2ecf20Sopenharmony_ci	__u16 sensor_physical_height;
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/*
908c2ecf20Sopenharmony_ci * This function converts the 4 byte raw firmware code into
918c2ecf20Sopenharmony_ci * a string containing 5 comma separated numbers.
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_cistatic int ntrig_version_string(unsigned char *raw, char *buf)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	__u8 a =  (raw[1] & 0x0e) >> 1;
968c2ecf20Sopenharmony_ci	__u8 b =  (raw[0] & 0x3c) >> 2;
978c2ecf20Sopenharmony_ci	__u8 c = ((raw[0] & 0x03) << 3) | ((raw[3] & 0xe0) >> 5);
988c2ecf20Sopenharmony_ci	__u8 d = ((raw[3] & 0x07) << 3) | ((raw[2] & 0xe0) >> 5);
998c2ecf20Sopenharmony_ci	__u8 e =   raw[2] & 0x07;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/*
1028c2ecf20Sopenharmony_ci	 * As yet unmapped bits:
1038c2ecf20Sopenharmony_ci	 * 0b11000000 0b11110001 0b00011000 0b00011000
1048c2ecf20Sopenharmony_ci	 */
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	return sprintf(buf, "%u.%u.%u.%u.%u", a, b, c, d, e);
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic inline int ntrig_get_mode(struct hid_device *hdev)
1108c2ecf20Sopenharmony_ci{
1118c2ecf20Sopenharmony_ci	struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
1128c2ecf20Sopenharmony_ci				    report_id_hash[0x0d];
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	if (!report || report->maxfield < 1 ||
1158c2ecf20Sopenharmony_ci	    report->field[0]->report_count < 1)
1168c2ecf20Sopenharmony_ci		return -EINVAL;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
1198c2ecf20Sopenharmony_ci	hid_hw_wait(hdev);
1208c2ecf20Sopenharmony_ci	return (int)report->field[0]->value[0];
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic inline void ntrig_set_mode(struct hid_device *hdev, const int mode)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	struct hid_report *report;
1268c2ecf20Sopenharmony_ci	__u8 mode_commands[4] = { 0xe, 0xf, 0x1b, 0x10 };
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	if (mode < 0 || mode > 3)
1298c2ecf20Sopenharmony_ci		return;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	report = hdev->report_enum[HID_FEATURE_REPORT].
1328c2ecf20Sopenharmony_ci		 report_id_hash[mode_commands[mode]];
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	if (!report)
1358c2ecf20Sopenharmony_ci		return;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic void ntrig_report_version(struct hid_device *hdev)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	int ret;
1438c2ecf20Sopenharmony_ci	char buf[20];
1448c2ecf20Sopenharmony_ci	struct usb_device *usb_dev = hid_to_usb_dev(hdev);
1458c2ecf20Sopenharmony_ci	unsigned char *data = kmalloc(8, GFP_KERNEL);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	if (!data)
1488c2ecf20Sopenharmony_ci		goto err_free;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
1518c2ecf20Sopenharmony_ci			      USB_REQ_CLEAR_FEATURE,
1528c2ecf20Sopenharmony_ci			      USB_TYPE_CLASS | USB_RECIP_INTERFACE |
1538c2ecf20Sopenharmony_ci			      USB_DIR_IN,
1548c2ecf20Sopenharmony_ci			      0x30c, 1, data, 8,
1558c2ecf20Sopenharmony_ci			      USB_CTRL_SET_TIMEOUT);
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	if (ret == 8) {
1588c2ecf20Sopenharmony_ci		ret = ntrig_version_string(&data[2], buf);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci		hid_info(hdev, "Firmware version: %s (%02x%02x %02x%02x)\n",
1618c2ecf20Sopenharmony_ci			 buf, data[2], data[3], data[4], data[5]);
1628c2ecf20Sopenharmony_ci	}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cierr_free:
1658c2ecf20Sopenharmony_ci	kfree(data);
1668c2ecf20Sopenharmony_ci}
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cistatic ssize_t show_phys_width(struct device *dev,
1698c2ecf20Sopenharmony_ci			       struct device_attribute *attr,
1708c2ecf20Sopenharmony_ci			       char *buf)
1718c2ecf20Sopenharmony_ci{
1728c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
1738c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->sensor_physical_width);
1768c2ecf20Sopenharmony_ci}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistatic DEVICE_ATTR(sensor_physical_width, S_IRUGO, show_phys_width, NULL);
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic ssize_t show_phys_height(struct device *dev,
1818c2ecf20Sopenharmony_ci				struct device_attribute *attr,
1828c2ecf20Sopenharmony_ci				char *buf)
1838c2ecf20Sopenharmony_ci{
1848c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
1858c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->sensor_physical_height);
1888c2ecf20Sopenharmony_ci}
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistatic DEVICE_ATTR(sensor_physical_height, S_IRUGO, show_phys_height, NULL);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cistatic ssize_t show_log_width(struct device *dev,
1938c2ecf20Sopenharmony_ci			      struct device_attribute *attr,
1948c2ecf20Sopenharmony_ci			      char *buf)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
1978c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->sensor_logical_width);
2008c2ecf20Sopenharmony_ci}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistatic DEVICE_ATTR(sensor_logical_width, S_IRUGO, show_log_width, NULL);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistatic ssize_t show_log_height(struct device *dev,
2058c2ecf20Sopenharmony_ci			       struct device_attribute *attr,
2068c2ecf20Sopenharmony_ci			       char *buf)
2078c2ecf20Sopenharmony_ci{
2088c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
2098c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->sensor_logical_height);
2128c2ecf20Sopenharmony_ci}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic DEVICE_ATTR(sensor_logical_height, S_IRUGO, show_log_height, NULL);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_cistatic ssize_t show_min_width(struct device *dev,
2178c2ecf20Sopenharmony_ci			      struct device_attribute *attr,
2188c2ecf20Sopenharmony_ci			      char *buf)
2198c2ecf20Sopenharmony_ci{
2208c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
2218c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->min_width *
2248c2ecf20Sopenharmony_ci				    nd->sensor_physical_width /
2258c2ecf20Sopenharmony_ci				    nd->sensor_logical_width);
2268c2ecf20Sopenharmony_ci}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic ssize_t set_min_width(struct device *dev,
2298c2ecf20Sopenharmony_ci			     struct device_attribute *attr,
2308c2ecf20Sopenharmony_ci			     const char *buf, size_t count)
2318c2ecf20Sopenharmony_ci{
2328c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
2338c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	unsigned long val;
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	if (kstrtoul(buf, 0, &val))
2388c2ecf20Sopenharmony_ci		return -EINVAL;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	if (val > nd->sensor_physical_width)
2418c2ecf20Sopenharmony_ci		return -EINVAL;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	nd->min_width = val * nd->sensor_logical_width /
2448c2ecf20Sopenharmony_ci			      nd->sensor_physical_width;
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	return count;
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic DEVICE_ATTR(min_width, S_IWUSR | S_IRUGO, show_min_width, set_min_width);
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cistatic ssize_t show_min_height(struct device *dev,
2528c2ecf20Sopenharmony_ci			       struct device_attribute *attr,
2538c2ecf20Sopenharmony_ci			       char *buf)
2548c2ecf20Sopenharmony_ci{
2558c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
2568c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->min_height *
2598c2ecf20Sopenharmony_ci				    nd->sensor_physical_height /
2608c2ecf20Sopenharmony_ci				    nd->sensor_logical_height);
2618c2ecf20Sopenharmony_ci}
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_cistatic ssize_t set_min_height(struct device *dev,
2648c2ecf20Sopenharmony_ci			      struct device_attribute *attr,
2658c2ecf20Sopenharmony_ci			      const char *buf, size_t count)
2668c2ecf20Sopenharmony_ci{
2678c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
2688c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	unsigned long val;
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	if (kstrtoul(buf, 0, &val))
2738c2ecf20Sopenharmony_ci		return -EINVAL;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	if (val > nd->sensor_physical_height)
2768c2ecf20Sopenharmony_ci		return -EINVAL;
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	nd->min_height = val * nd->sensor_logical_height /
2798c2ecf20Sopenharmony_ci			       nd->sensor_physical_height;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	return count;
2828c2ecf20Sopenharmony_ci}
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistatic DEVICE_ATTR(min_height, S_IWUSR | S_IRUGO, show_min_height,
2858c2ecf20Sopenharmony_ci		   set_min_height);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_cistatic ssize_t show_activate_slack(struct device *dev,
2888c2ecf20Sopenharmony_ci				   struct device_attribute *attr,
2898c2ecf20Sopenharmony_ci				   char *buf)
2908c2ecf20Sopenharmony_ci{
2918c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
2928c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->activate_slack);
2958c2ecf20Sopenharmony_ci}
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cistatic ssize_t set_activate_slack(struct device *dev,
2988c2ecf20Sopenharmony_ci				  struct device_attribute *attr,
2998c2ecf20Sopenharmony_ci				  const char *buf, size_t count)
3008c2ecf20Sopenharmony_ci{
3018c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
3028c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	unsigned long val;
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	if (kstrtoul(buf, 0, &val))
3078c2ecf20Sopenharmony_ci		return -EINVAL;
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci	if (val > 0x7f)
3108c2ecf20Sopenharmony_ci		return -EINVAL;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	nd->activate_slack = val;
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	return count;
3158c2ecf20Sopenharmony_ci}
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_cistatic DEVICE_ATTR(activate_slack, S_IWUSR | S_IRUGO, show_activate_slack,
3188c2ecf20Sopenharmony_ci		   set_activate_slack);
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic ssize_t show_activation_width(struct device *dev,
3218c2ecf20Sopenharmony_ci				     struct device_attribute *attr,
3228c2ecf20Sopenharmony_ci				     char *buf)
3238c2ecf20Sopenharmony_ci{
3248c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
3258c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->activation_width *
3288c2ecf20Sopenharmony_ci				    nd->sensor_physical_width /
3298c2ecf20Sopenharmony_ci				    nd->sensor_logical_width);
3308c2ecf20Sopenharmony_ci}
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_cistatic ssize_t set_activation_width(struct device *dev,
3338c2ecf20Sopenharmony_ci				    struct device_attribute *attr,
3348c2ecf20Sopenharmony_ci				    const char *buf, size_t count)
3358c2ecf20Sopenharmony_ci{
3368c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
3378c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	unsigned long val;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	if (kstrtoul(buf, 0, &val))
3428c2ecf20Sopenharmony_ci		return -EINVAL;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	if (val > nd->sensor_physical_width)
3458c2ecf20Sopenharmony_ci		return -EINVAL;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	nd->activation_width = val * nd->sensor_logical_width /
3488c2ecf20Sopenharmony_ci				     nd->sensor_physical_width;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	return count;
3518c2ecf20Sopenharmony_ci}
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_cistatic DEVICE_ATTR(activation_width, S_IWUSR | S_IRUGO, show_activation_width,
3548c2ecf20Sopenharmony_ci		   set_activation_width);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cistatic ssize_t show_activation_height(struct device *dev,
3578c2ecf20Sopenharmony_ci				      struct device_attribute *attr,
3588c2ecf20Sopenharmony_ci				      char *buf)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
3618c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", nd->activation_height *
3648c2ecf20Sopenharmony_ci				    nd->sensor_physical_height /
3658c2ecf20Sopenharmony_ci				    nd->sensor_logical_height);
3668c2ecf20Sopenharmony_ci}
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_cistatic ssize_t set_activation_height(struct device *dev,
3698c2ecf20Sopenharmony_ci				     struct device_attribute *attr,
3708c2ecf20Sopenharmony_ci				     const char *buf, size_t count)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
3738c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	unsigned long val;
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	if (kstrtoul(buf, 0, &val))
3788c2ecf20Sopenharmony_ci		return -EINVAL;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	if (val > nd->sensor_physical_height)
3818c2ecf20Sopenharmony_ci		return -EINVAL;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	nd->activation_height = val * nd->sensor_logical_height /
3848c2ecf20Sopenharmony_ci				      nd->sensor_physical_height;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	return count;
3878c2ecf20Sopenharmony_ci}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_cistatic DEVICE_ATTR(activation_height, S_IWUSR | S_IRUGO,
3908c2ecf20Sopenharmony_ci		   show_activation_height, set_activation_height);
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_cistatic ssize_t show_deactivate_slack(struct device *dev,
3938c2ecf20Sopenharmony_ci				     struct device_attribute *attr,
3948c2ecf20Sopenharmony_ci				     char *buf)
3958c2ecf20Sopenharmony_ci{
3968c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
3978c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	return sprintf(buf, "%d\n", -nd->deactivate_slack);
4008c2ecf20Sopenharmony_ci}
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_cistatic ssize_t set_deactivate_slack(struct device *dev,
4038c2ecf20Sopenharmony_ci				    struct device_attribute *attr,
4048c2ecf20Sopenharmony_ci				    const char *buf, size_t count)
4058c2ecf20Sopenharmony_ci{
4068c2ecf20Sopenharmony_ci	struct hid_device *hdev = to_hid_device(dev);
4078c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	unsigned long val;
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	if (kstrtoul(buf, 0, &val))
4128c2ecf20Sopenharmony_ci		return -EINVAL;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	/*
4158c2ecf20Sopenharmony_ci	 * No more than 8 terminal frames have been observed so far
4168c2ecf20Sopenharmony_ci	 * and higher slack is highly likely to leave the single
4178c2ecf20Sopenharmony_ci	 * touch emulation stuck down.
4188c2ecf20Sopenharmony_ci	 */
4198c2ecf20Sopenharmony_ci	if (val > 7)
4208c2ecf20Sopenharmony_ci		return -EINVAL;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	nd->deactivate_slack = -val;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	return count;
4258c2ecf20Sopenharmony_ci}
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_cistatic DEVICE_ATTR(deactivate_slack, S_IWUSR | S_IRUGO, show_deactivate_slack,
4288c2ecf20Sopenharmony_ci		   set_deactivate_slack);
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_cistatic struct attribute *sysfs_attrs[] = {
4318c2ecf20Sopenharmony_ci	&dev_attr_sensor_physical_width.attr,
4328c2ecf20Sopenharmony_ci	&dev_attr_sensor_physical_height.attr,
4338c2ecf20Sopenharmony_ci	&dev_attr_sensor_logical_width.attr,
4348c2ecf20Sopenharmony_ci	&dev_attr_sensor_logical_height.attr,
4358c2ecf20Sopenharmony_ci	&dev_attr_min_height.attr,
4368c2ecf20Sopenharmony_ci	&dev_attr_min_width.attr,
4378c2ecf20Sopenharmony_ci	&dev_attr_activate_slack.attr,
4388c2ecf20Sopenharmony_ci	&dev_attr_activation_width.attr,
4398c2ecf20Sopenharmony_ci	&dev_attr_activation_height.attr,
4408c2ecf20Sopenharmony_ci	&dev_attr_deactivate_slack.attr,
4418c2ecf20Sopenharmony_ci	NULL
4428c2ecf20Sopenharmony_ci};
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_cistatic const struct attribute_group ntrig_attribute_group = {
4458c2ecf20Sopenharmony_ci	.attrs = sysfs_attrs
4468c2ecf20Sopenharmony_ci};
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci/*
4498c2ecf20Sopenharmony_ci * this driver is aimed at two firmware versions in circulation:
4508c2ecf20Sopenharmony_ci *  - dual pen/finger single touch
4518c2ecf20Sopenharmony_ci *  - finger multitouch, pen not working
4528c2ecf20Sopenharmony_ci */
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_cistatic int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi,
4558c2ecf20Sopenharmony_ci			       struct hid_field *field, struct hid_usage *usage,
4568c2ecf20Sopenharmony_ci			       unsigned long **bit, int *max)
4578c2ecf20Sopenharmony_ci{
4588c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hdev);
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	/* No special mappings needed for the pen and single touch */
4618c2ecf20Sopenharmony_ci	if (field->physical)
4628c2ecf20Sopenharmony_ci		return 0;
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	switch (usage->hid & HID_USAGE_PAGE) {
4658c2ecf20Sopenharmony_ci	case HID_UP_GENDESK:
4668c2ecf20Sopenharmony_ci		switch (usage->hid) {
4678c2ecf20Sopenharmony_ci		case HID_GD_X:
4688c2ecf20Sopenharmony_ci			hid_map_usage(hi, usage, bit, max,
4698c2ecf20Sopenharmony_ci					EV_ABS, ABS_MT_POSITION_X);
4708c2ecf20Sopenharmony_ci			input_set_abs_params(hi->input, ABS_X,
4718c2ecf20Sopenharmony_ci					field->logical_minimum,
4728c2ecf20Sopenharmony_ci					field->logical_maximum, 0, 0);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci			if (!nd->sensor_logical_width) {
4758c2ecf20Sopenharmony_ci				nd->sensor_logical_width =
4768c2ecf20Sopenharmony_ci					field->logical_maximum -
4778c2ecf20Sopenharmony_ci					field->logical_minimum;
4788c2ecf20Sopenharmony_ci				nd->sensor_physical_width =
4798c2ecf20Sopenharmony_ci					field->physical_maximum -
4808c2ecf20Sopenharmony_ci					field->physical_minimum;
4818c2ecf20Sopenharmony_ci				nd->activation_width = activation_width *
4828c2ecf20Sopenharmony_ci					nd->sensor_logical_width /
4838c2ecf20Sopenharmony_ci					nd->sensor_physical_width;
4848c2ecf20Sopenharmony_ci				nd->min_width = min_width *
4858c2ecf20Sopenharmony_ci					nd->sensor_logical_width /
4868c2ecf20Sopenharmony_ci					nd->sensor_physical_width;
4878c2ecf20Sopenharmony_ci			}
4888c2ecf20Sopenharmony_ci			return 1;
4898c2ecf20Sopenharmony_ci		case HID_GD_Y:
4908c2ecf20Sopenharmony_ci			hid_map_usage(hi, usage, bit, max,
4918c2ecf20Sopenharmony_ci					EV_ABS, ABS_MT_POSITION_Y);
4928c2ecf20Sopenharmony_ci			input_set_abs_params(hi->input, ABS_Y,
4938c2ecf20Sopenharmony_ci					field->logical_minimum,
4948c2ecf20Sopenharmony_ci					field->logical_maximum, 0, 0);
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci			if (!nd->sensor_logical_height) {
4978c2ecf20Sopenharmony_ci				nd->sensor_logical_height =
4988c2ecf20Sopenharmony_ci					field->logical_maximum -
4998c2ecf20Sopenharmony_ci					field->logical_minimum;
5008c2ecf20Sopenharmony_ci				nd->sensor_physical_height =
5018c2ecf20Sopenharmony_ci					field->physical_maximum -
5028c2ecf20Sopenharmony_ci					field->physical_minimum;
5038c2ecf20Sopenharmony_ci				nd->activation_height = activation_height *
5048c2ecf20Sopenharmony_ci					nd->sensor_logical_height /
5058c2ecf20Sopenharmony_ci					nd->sensor_physical_height;
5068c2ecf20Sopenharmony_ci				nd->min_height = min_height *
5078c2ecf20Sopenharmony_ci					nd->sensor_logical_height /
5088c2ecf20Sopenharmony_ci					nd->sensor_physical_height;
5098c2ecf20Sopenharmony_ci			}
5108c2ecf20Sopenharmony_ci			return 1;
5118c2ecf20Sopenharmony_ci		}
5128c2ecf20Sopenharmony_ci		return 0;
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	case HID_UP_DIGITIZER:
5158c2ecf20Sopenharmony_ci		switch (usage->hid) {
5168c2ecf20Sopenharmony_ci		/* we do not want to map these for now */
5178c2ecf20Sopenharmony_ci		case HID_DG_CONTACTID: /* Not trustworthy, squelch for now */
5188c2ecf20Sopenharmony_ci		case HID_DG_INPUTMODE:
5198c2ecf20Sopenharmony_ci		case HID_DG_DEVICEINDEX:
5208c2ecf20Sopenharmony_ci		case HID_DG_CONTACTMAX:
5218c2ecf20Sopenharmony_ci			return -1;
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci		/* width/height mapped on TouchMajor/TouchMinor/Orientation */
5248c2ecf20Sopenharmony_ci		case HID_DG_WIDTH:
5258c2ecf20Sopenharmony_ci			hid_map_usage(hi, usage, bit, max,
5268c2ecf20Sopenharmony_ci				      EV_ABS, ABS_MT_TOUCH_MAJOR);
5278c2ecf20Sopenharmony_ci			return 1;
5288c2ecf20Sopenharmony_ci		case HID_DG_HEIGHT:
5298c2ecf20Sopenharmony_ci			hid_map_usage(hi, usage, bit, max,
5308c2ecf20Sopenharmony_ci				      EV_ABS, ABS_MT_TOUCH_MINOR);
5318c2ecf20Sopenharmony_ci			input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
5328c2ecf20Sopenharmony_ci					     0, 1, 0, 0);
5338c2ecf20Sopenharmony_ci			return 1;
5348c2ecf20Sopenharmony_ci		}
5358c2ecf20Sopenharmony_ci		return 0;
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	case 0xff000000:
5388c2ecf20Sopenharmony_ci		/* we do not want to map these: no input-oriented meaning */
5398c2ecf20Sopenharmony_ci		return -1;
5408c2ecf20Sopenharmony_ci	}
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci	return 0;
5438c2ecf20Sopenharmony_ci}
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_cistatic int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi,
5468c2ecf20Sopenharmony_ci			      struct hid_field *field, struct hid_usage *usage,
5478c2ecf20Sopenharmony_ci			      unsigned long **bit, int *max)
5488c2ecf20Sopenharmony_ci{
5498c2ecf20Sopenharmony_ci	/* No special mappings needed for the pen and single touch */
5508c2ecf20Sopenharmony_ci	if (field->physical)
5518c2ecf20Sopenharmony_ci		return 0;
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci	if (usage->type == EV_KEY || usage->type == EV_REL
5548c2ecf20Sopenharmony_ci			|| usage->type == EV_ABS)
5558c2ecf20Sopenharmony_ci		clear_bit(usage->code, *bit);
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	return 0;
5588c2ecf20Sopenharmony_ci}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci/*
5618c2ecf20Sopenharmony_ci * this function is called upon all reports
5628c2ecf20Sopenharmony_ci * so that we can filter contact point information,
5638c2ecf20Sopenharmony_ci * decide whether we are in multi or single touch mode
5648c2ecf20Sopenharmony_ci * and call input_mt_sync after each point if necessary
5658c2ecf20Sopenharmony_ci */
5668c2ecf20Sopenharmony_cistatic int ntrig_event (struct hid_device *hid, struct hid_field *field,
5678c2ecf20Sopenharmony_ci			struct hid_usage *usage, __s32 value)
5688c2ecf20Sopenharmony_ci{
5698c2ecf20Sopenharmony_ci	struct ntrig_data *nd = hid_get_drvdata(hid);
5708c2ecf20Sopenharmony_ci	struct input_dev *input;
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci	/* Skip processing if not a claimed input */
5738c2ecf20Sopenharmony_ci	if (!(hid->claimed & HID_CLAIMED_INPUT))
5748c2ecf20Sopenharmony_ci		goto not_claimed_input;
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci	/* This function is being called before the structures are fully
5778c2ecf20Sopenharmony_ci	 * initialized */
5788c2ecf20Sopenharmony_ci	if(!(field->hidinput && field->hidinput->input))
5798c2ecf20Sopenharmony_ci		return -EINVAL;
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci	input = field->hidinput->input;
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	/* No special handling needed for the pen */
5848c2ecf20Sopenharmony_ci	if (field->application == HID_DG_PEN)
5858c2ecf20Sopenharmony_ci		return 0;
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	switch (usage->hid) {
5888c2ecf20Sopenharmony_ci	case 0xff000001:
5898c2ecf20Sopenharmony_ci		/* Tag indicating the start of a multitouch group */
5908c2ecf20Sopenharmony_ci		nd->reading_mt = true;
5918c2ecf20Sopenharmony_ci		nd->first_contact_touch = false;
5928c2ecf20Sopenharmony_ci		break;
5938c2ecf20Sopenharmony_ci	case HID_DG_TIPSWITCH:
5948c2ecf20Sopenharmony_ci		nd->tipswitch = value;
5958c2ecf20Sopenharmony_ci		/* Prevent emission of touch until validated */
5968c2ecf20Sopenharmony_ci		return 1;
5978c2ecf20Sopenharmony_ci	case HID_DG_CONFIDENCE:
5988c2ecf20Sopenharmony_ci		nd->confidence = value;
5998c2ecf20Sopenharmony_ci		break;
6008c2ecf20Sopenharmony_ci	case HID_GD_X:
6018c2ecf20Sopenharmony_ci		nd->x = value;
6028c2ecf20Sopenharmony_ci		/* Clear the contact footer */
6038c2ecf20Sopenharmony_ci		nd->mt_foot_count = 0;
6048c2ecf20Sopenharmony_ci		break;
6058c2ecf20Sopenharmony_ci	case HID_GD_Y:
6068c2ecf20Sopenharmony_ci		nd->y = value;
6078c2ecf20Sopenharmony_ci		break;
6088c2ecf20Sopenharmony_ci	case HID_DG_CONTACTID:
6098c2ecf20Sopenharmony_ci		nd->id = value;
6108c2ecf20Sopenharmony_ci		break;
6118c2ecf20Sopenharmony_ci	case HID_DG_WIDTH:
6128c2ecf20Sopenharmony_ci		nd->w = value;
6138c2ecf20Sopenharmony_ci		break;
6148c2ecf20Sopenharmony_ci	case HID_DG_HEIGHT:
6158c2ecf20Sopenharmony_ci		nd->h = value;
6168c2ecf20Sopenharmony_ci		/*
6178c2ecf20Sopenharmony_ci		 * when in single touch mode, this is the last
6188c2ecf20Sopenharmony_ci		 * report received in a finger event. We want
6198c2ecf20Sopenharmony_ci		 * to emit a normal (X, Y) position
6208c2ecf20Sopenharmony_ci		 */
6218c2ecf20Sopenharmony_ci		if (!nd->reading_mt) {
6228c2ecf20Sopenharmony_ci			/*
6238c2ecf20Sopenharmony_ci			 * TipSwitch indicates the presence of a
6248c2ecf20Sopenharmony_ci			 * finger in single touch mode.
6258c2ecf20Sopenharmony_ci			 */
6268c2ecf20Sopenharmony_ci			input_report_key(input, BTN_TOUCH,
6278c2ecf20Sopenharmony_ci					 nd->tipswitch);
6288c2ecf20Sopenharmony_ci			input_report_key(input, BTN_TOOL_DOUBLETAP,
6298c2ecf20Sopenharmony_ci					 nd->tipswitch);
6308c2ecf20Sopenharmony_ci			input_event(input, EV_ABS, ABS_X, nd->x);
6318c2ecf20Sopenharmony_ci			input_event(input, EV_ABS, ABS_Y, nd->y);
6328c2ecf20Sopenharmony_ci		}
6338c2ecf20Sopenharmony_ci		break;
6348c2ecf20Sopenharmony_ci	case 0xff000002:
6358c2ecf20Sopenharmony_ci		/*
6368c2ecf20Sopenharmony_ci		 * we receive this when the device is in multitouch
6378c2ecf20Sopenharmony_ci		 * mode. The first of the three values tagged with
6388c2ecf20Sopenharmony_ci		 * this usage tells if the contact point is real
6398c2ecf20Sopenharmony_ci		 * or a placeholder
6408c2ecf20Sopenharmony_ci		 */
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci		/* Shouldn't get more than 4 footer packets, so skip */
6438c2ecf20Sopenharmony_ci		if (nd->mt_foot_count >= 4)
6448c2ecf20Sopenharmony_ci			break;
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci		nd->mt_footer[nd->mt_foot_count++] = value;
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_ci		/* if the footer isn't complete break */
6498c2ecf20Sopenharmony_ci		if (nd->mt_foot_count != 4)
6508c2ecf20Sopenharmony_ci			break;
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci		/* Pen activity signal. */
6538c2ecf20Sopenharmony_ci		if (nd->mt_footer[2]) {
6548c2ecf20Sopenharmony_ci			/*
6558c2ecf20Sopenharmony_ci			 * When the pen deactivates touch, we see a
6568c2ecf20Sopenharmony_ci			 * bogus frame with ContactCount > 0.
6578c2ecf20Sopenharmony_ci			 * We can
6588c2ecf20Sopenharmony_ci			 * save a bit of work by ensuring act_state < 0
6598c2ecf20Sopenharmony_ci			 * even if deactivation slack is turned off.
6608c2ecf20Sopenharmony_ci			 */
6618c2ecf20Sopenharmony_ci			nd->act_state = deactivate_slack - 1;
6628c2ecf20Sopenharmony_ci			nd->confidence = false;
6638c2ecf20Sopenharmony_ci			break;
6648c2ecf20Sopenharmony_ci		}
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci		/*
6678c2ecf20Sopenharmony_ci		 * The first footer value indicates the presence of a
6688c2ecf20Sopenharmony_ci		 * finger.
6698c2ecf20Sopenharmony_ci		 */
6708c2ecf20Sopenharmony_ci		if (nd->mt_footer[0]) {
6718c2ecf20Sopenharmony_ci			/*
6728c2ecf20Sopenharmony_ci			 * We do not want to process contacts under
6738c2ecf20Sopenharmony_ci			 * the size threshold, but do not want to
6748c2ecf20Sopenharmony_ci			 * ignore them for activation state
6758c2ecf20Sopenharmony_ci			 */
6768c2ecf20Sopenharmony_ci			if (nd->w < nd->min_width ||
6778c2ecf20Sopenharmony_ci			    nd->h < nd->min_height)
6788c2ecf20Sopenharmony_ci				nd->confidence = false;
6798c2ecf20Sopenharmony_ci		} else
6808c2ecf20Sopenharmony_ci			break;
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci		if (nd->act_state > 0) {
6838c2ecf20Sopenharmony_ci			/*
6848c2ecf20Sopenharmony_ci			 * Contact meets the activation size threshold
6858c2ecf20Sopenharmony_ci			 */
6868c2ecf20Sopenharmony_ci			if (nd->w >= nd->activation_width &&
6878c2ecf20Sopenharmony_ci			    nd->h >= nd->activation_height) {
6888c2ecf20Sopenharmony_ci				if (nd->id)
6898c2ecf20Sopenharmony_ci					/*
6908c2ecf20Sopenharmony_ci					 * first contact, activate now
6918c2ecf20Sopenharmony_ci					 */
6928c2ecf20Sopenharmony_ci					nd->act_state = 0;
6938c2ecf20Sopenharmony_ci				else {
6948c2ecf20Sopenharmony_ci					/*
6958c2ecf20Sopenharmony_ci					 * avoid corrupting this frame
6968c2ecf20Sopenharmony_ci					 * but ensure next frame will
6978c2ecf20Sopenharmony_ci					 * be active
6988c2ecf20Sopenharmony_ci					 */
6998c2ecf20Sopenharmony_ci					nd->act_state = 1;
7008c2ecf20Sopenharmony_ci					break;
7018c2ecf20Sopenharmony_ci				}
7028c2ecf20Sopenharmony_ci			} else
7038c2ecf20Sopenharmony_ci				/*
7048c2ecf20Sopenharmony_ci				 * Defer adjusting the activation state
7058c2ecf20Sopenharmony_ci				 * until the end of the frame.
7068c2ecf20Sopenharmony_ci				 */
7078c2ecf20Sopenharmony_ci				break;
7088c2ecf20Sopenharmony_ci		}
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci		/* Discarding this contact */
7118c2ecf20Sopenharmony_ci		if (!nd->confidence)
7128c2ecf20Sopenharmony_ci			break;
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci		/* emit a normal (X, Y) for the first point only */
7158c2ecf20Sopenharmony_ci		if (nd->id == 0) {
7168c2ecf20Sopenharmony_ci			/*
7178c2ecf20Sopenharmony_ci			 * TipSwitch is superfluous in multitouch
7188c2ecf20Sopenharmony_ci			 * mode.  The footer events tell us
7198c2ecf20Sopenharmony_ci			 * if there is a finger on the screen or
7208c2ecf20Sopenharmony_ci			 * not.
7218c2ecf20Sopenharmony_ci			 */
7228c2ecf20Sopenharmony_ci			nd->first_contact_touch = nd->confidence;
7238c2ecf20Sopenharmony_ci			input_event(input, EV_ABS, ABS_X, nd->x);
7248c2ecf20Sopenharmony_ci			input_event(input, EV_ABS, ABS_Y, nd->y);
7258c2ecf20Sopenharmony_ci		}
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci		/* Emit MT events */
7288c2ecf20Sopenharmony_ci		input_event(input, EV_ABS, ABS_MT_POSITION_X, nd->x);
7298c2ecf20Sopenharmony_ci		input_event(input, EV_ABS, ABS_MT_POSITION_Y, nd->y);
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_ci		/*
7328c2ecf20Sopenharmony_ci		 * Translate from height and width to size
7338c2ecf20Sopenharmony_ci		 * and orientation.
7348c2ecf20Sopenharmony_ci		 */
7358c2ecf20Sopenharmony_ci		if (nd->w > nd->h) {
7368c2ecf20Sopenharmony_ci			input_event(input, EV_ABS,
7378c2ecf20Sopenharmony_ci					ABS_MT_ORIENTATION, 1);
7388c2ecf20Sopenharmony_ci			input_event(input, EV_ABS,
7398c2ecf20Sopenharmony_ci					ABS_MT_TOUCH_MAJOR, nd->w);
7408c2ecf20Sopenharmony_ci			input_event(input, EV_ABS,
7418c2ecf20Sopenharmony_ci					ABS_MT_TOUCH_MINOR, nd->h);
7428c2ecf20Sopenharmony_ci		} else {
7438c2ecf20Sopenharmony_ci			input_event(input, EV_ABS,
7448c2ecf20Sopenharmony_ci					ABS_MT_ORIENTATION, 0);
7458c2ecf20Sopenharmony_ci			input_event(input, EV_ABS,
7468c2ecf20Sopenharmony_ci					ABS_MT_TOUCH_MAJOR, nd->h);
7478c2ecf20Sopenharmony_ci			input_event(input, EV_ABS,
7488c2ecf20Sopenharmony_ci					ABS_MT_TOUCH_MINOR, nd->w);
7498c2ecf20Sopenharmony_ci		}
7508c2ecf20Sopenharmony_ci		input_mt_sync(field->hidinput->input);
7518c2ecf20Sopenharmony_ci		break;
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci	case HID_DG_CONTACTCOUNT: /* End of a multitouch group */
7548c2ecf20Sopenharmony_ci		if (!nd->reading_mt) /* Just to be sure */
7558c2ecf20Sopenharmony_ci			break;
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci		nd->reading_mt = false;
7588c2ecf20Sopenharmony_ci
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci		/*
7618c2ecf20Sopenharmony_ci		 * Activation state machine logic:
7628c2ecf20Sopenharmony_ci		 *
7638c2ecf20Sopenharmony_ci		 * Fundamental states:
7648c2ecf20Sopenharmony_ci		 *	state >  0: Inactive
7658c2ecf20Sopenharmony_ci		 *	state <= 0: Active
7668c2ecf20Sopenharmony_ci		 *	state <  -deactivate_slack:
7678c2ecf20Sopenharmony_ci		 *		 Pen termination of touch
7688c2ecf20Sopenharmony_ci		 *
7698c2ecf20Sopenharmony_ci		 * Specific values of interest
7708c2ecf20Sopenharmony_ci		 *	state == activate_slack
7718c2ecf20Sopenharmony_ci		 *		 no valid input since the last reset
7728c2ecf20Sopenharmony_ci		 *
7738c2ecf20Sopenharmony_ci		 *	state == 0
7748c2ecf20Sopenharmony_ci		 *		 general operational state
7758c2ecf20Sopenharmony_ci		 *
7768c2ecf20Sopenharmony_ci		 *	state == -deactivate_slack
7778c2ecf20Sopenharmony_ci		 *		 read sufficient empty frames to accept
7788c2ecf20Sopenharmony_ci		 *		 the end of input and reset
7798c2ecf20Sopenharmony_ci		 */
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci		if (nd->act_state > 0) { /* Currently inactive */
7828c2ecf20Sopenharmony_ci			if (value)
7838c2ecf20Sopenharmony_ci				/*
7848c2ecf20Sopenharmony_ci				 * Consider each live contact as
7858c2ecf20Sopenharmony_ci				 * evidence of intentional activity.
7868c2ecf20Sopenharmony_ci				 */
7878c2ecf20Sopenharmony_ci				nd->act_state = (nd->act_state > value)
7888c2ecf20Sopenharmony_ci						? nd->act_state - value
7898c2ecf20Sopenharmony_ci						: 0;
7908c2ecf20Sopenharmony_ci			else
7918c2ecf20Sopenharmony_ci				/*
7928c2ecf20Sopenharmony_ci				 * Empty frame before we hit the
7938c2ecf20Sopenharmony_ci				 * activity threshold, reset.
7948c2ecf20Sopenharmony_ci				 */
7958c2ecf20Sopenharmony_ci				nd->act_state = nd->activate_slack;
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci			/*
7988c2ecf20Sopenharmony_ci			 * Entered this block inactive and no
7998c2ecf20Sopenharmony_ci			 * coordinates sent this frame, so hold off
8008c2ecf20Sopenharmony_ci			 * on button state.
8018c2ecf20Sopenharmony_ci			 */
8028c2ecf20Sopenharmony_ci			break;
8038c2ecf20Sopenharmony_ci		} else { /* Currently active */
8048c2ecf20Sopenharmony_ci			if (value && nd->act_state >=
8058c2ecf20Sopenharmony_ci				     nd->deactivate_slack)
8068c2ecf20Sopenharmony_ci				/*
8078c2ecf20Sopenharmony_ci				 * Live point: clear accumulated
8088c2ecf20Sopenharmony_ci				 * deactivation count.
8098c2ecf20Sopenharmony_ci				 */
8108c2ecf20Sopenharmony_ci				nd->act_state = 0;
8118c2ecf20Sopenharmony_ci			else if (nd->act_state <= nd->deactivate_slack)
8128c2ecf20Sopenharmony_ci				/*
8138c2ecf20Sopenharmony_ci				 * We've consumed the deactivation
8148c2ecf20Sopenharmony_ci				 * slack, time to deactivate and reset.
8158c2ecf20Sopenharmony_ci				 */
8168c2ecf20Sopenharmony_ci				nd->act_state =
8178c2ecf20Sopenharmony_ci					nd->activate_slack;
8188c2ecf20Sopenharmony_ci			else { /* Move towards deactivation */
8198c2ecf20Sopenharmony_ci				nd->act_state--;
8208c2ecf20Sopenharmony_ci				break;
8218c2ecf20Sopenharmony_ci			}
8228c2ecf20Sopenharmony_ci		}
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci		if (nd->first_contact_touch && nd->act_state <= 0) {
8258c2ecf20Sopenharmony_ci			/*
8268c2ecf20Sopenharmony_ci			 * Check to see if we're ready to start
8278c2ecf20Sopenharmony_ci			 * emitting touch events.
8288c2ecf20Sopenharmony_ci			 *
8298c2ecf20Sopenharmony_ci			 * Note: activation slack will decrease over
8308c2ecf20Sopenharmony_ci			 * the course of the frame, and it will be
8318c2ecf20Sopenharmony_ci			 * inconsistent from the start to the end of
8328c2ecf20Sopenharmony_ci			 * the frame.  However if the frame starts
8338c2ecf20Sopenharmony_ci			 * with slack, first_contact_touch will still
8348c2ecf20Sopenharmony_ci			 * be 0 and we will not get to this point.
8358c2ecf20Sopenharmony_ci			 */
8368c2ecf20Sopenharmony_ci			input_report_key(input, BTN_TOOL_DOUBLETAP, 1);
8378c2ecf20Sopenharmony_ci			input_report_key(input, BTN_TOUCH, 1);
8388c2ecf20Sopenharmony_ci		} else {
8398c2ecf20Sopenharmony_ci			input_report_key(input, BTN_TOOL_DOUBLETAP, 0);
8408c2ecf20Sopenharmony_ci			input_report_key(input, BTN_TOUCH, 0);
8418c2ecf20Sopenharmony_ci		}
8428c2ecf20Sopenharmony_ci		break;
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	default:
8458c2ecf20Sopenharmony_ci		/* fall-back to the generic hidinput handling */
8468c2ecf20Sopenharmony_ci		return 0;
8478c2ecf20Sopenharmony_ci	}
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_cinot_claimed_input:
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_ci	/* we have handled the hidinput part, now remains hiddev */
8528c2ecf20Sopenharmony_ci	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event)
8538c2ecf20Sopenharmony_ci		hid->hiddev_hid_event(hid, field, usage, value);
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	return 1;
8568c2ecf20Sopenharmony_ci}
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_cistatic int ntrig_input_configured(struct hid_device *hid,
8598c2ecf20Sopenharmony_ci		struct hid_input *hidinput)
8608c2ecf20Sopenharmony_ci
8618c2ecf20Sopenharmony_ci{
8628c2ecf20Sopenharmony_ci	struct input_dev *input = hidinput->input;
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci	if (hidinput->report->maxfield < 1)
8658c2ecf20Sopenharmony_ci		return 0;
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_ci	switch (hidinput->report->field[0]->application) {
8688c2ecf20Sopenharmony_ci	case HID_DG_PEN:
8698c2ecf20Sopenharmony_ci		input->name = "N-Trig Pen";
8708c2ecf20Sopenharmony_ci		break;
8718c2ecf20Sopenharmony_ci	case HID_DG_TOUCHSCREEN:
8728c2ecf20Sopenharmony_ci		/* These keys are redundant for fingers, clear them
8738c2ecf20Sopenharmony_ci		 * to prevent incorrect identification */
8748c2ecf20Sopenharmony_ci		__clear_bit(BTN_TOOL_PEN, input->keybit);
8758c2ecf20Sopenharmony_ci		__clear_bit(BTN_TOOL_FINGER, input->keybit);
8768c2ecf20Sopenharmony_ci		__clear_bit(BTN_0, input->keybit);
8778c2ecf20Sopenharmony_ci		__set_bit(BTN_TOOL_DOUBLETAP, input->keybit);
8788c2ecf20Sopenharmony_ci		/*
8798c2ecf20Sopenharmony_ci		 * The physical touchscreen (single touch)
8808c2ecf20Sopenharmony_ci		 * input has a value for physical, whereas
8818c2ecf20Sopenharmony_ci		 * the multitouch only has logical input
8828c2ecf20Sopenharmony_ci		 * fields.
8838c2ecf20Sopenharmony_ci		 */
8848c2ecf20Sopenharmony_ci		input->name = (hidinput->report->field[0]->physical) ?
8858c2ecf20Sopenharmony_ci							"N-Trig Touchscreen" :
8868c2ecf20Sopenharmony_ci							"N-Trig MultiTouch";
8878c2ecf20Sopenharmony_ci		break;
8888c2ecf20Sopenharmony_ci	}
8898c2ecf20Sopenharmony_ci
8908c2ecf20Sopenharmony_ci	return 0;
8918c2ecf20Sopenharmony_ci}
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_cistatic int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
8948c2ecf20Sopenharmony_ci{
8958c2ecf20Sopenharmony_ci	int ret;
8968c2ecf20Sopenharmony_ci	struct ntrig_data *nd;
8978c2ecf20Sopenharmony_ci	struct hid_report *report;
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	if (id->driver_data)
9008c2ecf20Sopenharmony_ci		hdev->quirks |= HID_QUIRK_MULTI_INPUT
9018c2ecf20Sopenharmony_ci				| HID_QUIRK_NO_INIT_REPORTS;
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci	nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL);
9048c2ecf20Sopenharmony_ci	if (!nd) {
9058c2ecf20Sopenharmony_ci		hid_err(hdev, "cannot allocate N-Trig data\n");
9068c2ecf20Sopenharmony_ci		return -ENOMEM;
9078c2ecf20Sopenharmony_ci	}
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci	nd->reading_mt = false;
9108c2ecf20Sopenharmony_ci	nd->min_width = 0;
9118c2ecf20Sopenharmony_ci	nd->min_height = 0;
9128c2ecf20Sopenharmony_ci	nd->activate_slack = activate_slack;
9138c2ecf20Sopenharmony_ci	nd->act_state = activate_slack;
9148c2ecf20Sopenharmony_ci	nd->deactivate_slack = -deactivate_slack;
9158c2ecf20Sopenharmony_ci	nd->sensor_logical_width = 1;
9168c2ecf20Sopenharmony_ci	nd->sensor_logical_height = 1;
9178c2ecf20Sopenharmony_ci	nd->sensor_physical_width = 1;
9188c2ecf20Sopenharmony_ci	nd->sensor_physical_height = 1;
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_ci	hid_set_drvdata(hdev, nd);
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci	ret = hid_parse(hdev);
9238c2ecf20Sopenharmony_ci	if (ret) {
9248c2ecf20Sopenharmony_ci		hid_err(hdev, "parse failed\n");
9258c2ecf20Sopenharmony_ci		goto err_free;
9268c2ecf20Sopenharmony_ci	}
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
9298c2ecf20Sopenharmony_ci	if (ret) {
9308c2ecf20Sopenharmony_ci		hid_err(hdev, "hw start failed\n");
9318c2ecf20Sopenharmony_ci		goto err_free;
9328c2ecf20Sopenharmony_ci	}
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_ci	/* This is needed for devices with more recent firmware versions */
9358c2ecf20Sopenharmony_ci	report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0x0a];
9368c2ecf20Sopenharmony_ci	if (report) {
9378c2ecf20Sopenharmony_ci		/* Let the device settle to ensure the wakeup message gets
9388c2ecf20Sopenharmony_ci		 * through */
9398c2ecf20Sopenharmony_ci		hid_hw_wait(hdev);
9408c2ecf20Sopenharmony_ci		hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
9418c2ecf20Sopenharmony_ci
9428c2ecf20Sopenharmony_ci		/*
9438c2ecf20Sopenharmony_ci		 * Sanity check: if the current mode is invalid reset it to
9448c2ecf20Sopenharmony_ci		 * something reasonable.
9458c2ecf20Sopenharmony_ci		 */
9468c2ecf20Sopenharmony_ci		if (ntrig_get_mode(hdev) >= 4)
9478c2ecf20Sopenharmony_ci			ntrig_set_mode(hdev, 3);
9488c2ecf20Sopenharmony_ci	}
9498c2ecf20Sopenharmony_ci
9508c2ecf20Sopenharmony_ci	ntrig_report_version(hdev);
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci	ret = sysfs_create_group(&hdev->dev.kobj,
9538c2ecf20Sopenharmony_ci			&ntrig_attribute_group);
9548c2ecf20Sopenharmony_ci	if (ret)
9558c2ecf20Sopenharmony_ci		hid_err(hdev, "cannot create sysfs group\n");
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	return 0;
9588c2ecf20Sopenharmony_cierr_free:
9598c2ecf20Sopenharmony_ci	kfree(nd);
9608c2ecf20Sopenharmony_ci	return ret;
9618c2ecf20Sopenharmony_ci}
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_cistatic void ntrig_remove(struct hid_device *hdev)
9648c2ecf20Sopenharmony_ci{
9658c2ecf20Sopenharmony_ci	sysfs_remove_group(&hdev->dev.kobj,
9668c2ecf20Sopenharmony_ci			   &ntrig_attribute_group);
9678c2ecf20Sopenharmony_ci	hid_hw_stop(hdev);
9688c2ecf20Sopenharmony_ci	kfree(hid_get_drvdata(hdev));
9698c2ecf20Sopenharmony_ci}
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_cistatic const struct hid_device_id ntrig_devices[] = {
9728c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN),
9738c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9748c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1),
9758c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9768c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2),
9778c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9788c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3),
9798c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9808c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4),
9818c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9828c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5),
9838c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9848c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6),
9858c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9868c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7),
9878c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9888c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8),
9898c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9908c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9),
9918c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9928c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10),
9938c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9948c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11),
9958c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9968c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12),
9978c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
9988c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13),
9998c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
10008c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14),
10018c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
10028c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15),
10038c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
10048c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16),
10058c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
10068c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17),
10078c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
10088c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18),
10098c2ecf20Sopenharmony_ci		.driver_data = NTRIG_DUPLICATE_USAGES },
10108c2ecf20Sopenharmony_ci	{ }
10118c2ecf20Sopenharmony_ci};
10128c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(hid, ntrig_devices);
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_cistatic const struct hid_usage_id ntrig_grabbed_usages[] = {
10158c2ecf20Sopenharmony_ci	{ HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
10168c2ecf20Sopenharmony_ci	{ HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
10178c2ecf20Sopenharmony_ci};
10188c2ecf20Sopenharmony_ci
10198c2ecf20Sopenharmony_cistatic struct hid_driver ntrig_driver = {
10208c2ecf20Sopenharmony_ci	.name = "ntrig",
10218c2ecf20Sopenharmony_ci	.id_table = ntrig_devices,
10228c2ecf20Sopenharmony_ci	.probe = ntrig_probe,
10238c2ecf20Sopenharmony_ci	.remove = ntrig_remove,
10248c2ecf20Sopenharmony_ci	.input_mapping = ntrig_input_mapping,
10258c2ecf20Sopenharmony_ci	.input_mapped = ntrig_input_mapped,
10268c2ecf20Sopenharmony_ci	.input_configured = ntrig_input_configured,
10278c2ecf20Sopenharmony_ci	.usage_table = ntrig_grabbed_usages,
10288c2ecf20Sopenharmony_ci	.event = ntrig_event,
10298c2ecf20Sopenharmony_ci};
10308c2ecf20Sopenharmony_cimodule_hid_driver(ntrig_driver);
10318c2ecf20Sopenharmony_ci
10328c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1033