Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  HID driver for N-Trig touchscreens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Copyright (c) 2008-2010 Rafi Rubin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  Copyright (c) 2009-2010 Stephane Chatty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include "usbhid/usbhid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #define NTRIG_DUPLICATE_USAGES	0x001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) static unsigned int min_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) module_param(min_width, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) MODULE_PARM_DESC(min_width, "Minimum touch contact width to accept.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) static unsigned int min_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) module_param(min_height, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) MODULE_PARM_DESC(min_height, "Minimum touch contact height to accept.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) static unsigned int activate_slack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) module_param(activate_slack, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) MODULE_PARM_DESC(activate_slack, "Number of touch frames to ignore at "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 		 "the start of touch input.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) static unsigned int deactivate_slack = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) module_param(deactivate_slack, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) MODULE_PARM_DESC(deactivate_slack, "Number of empty frames to ignore before "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 		 "deactivating touch.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) static unsigned int activation_width = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) module_param(activation_width, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) MODULE_PARM_DESC(activation_width, "Width threshold to immediately start "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 		 "processing touch events.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) static unsigned int activation_height = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) module_param(activation_height, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) MODULE_PARM_DESC(activation_height, "Height threshold to immediately start "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 		 "processing touch events.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) struct ntrig_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	/* Incoming raw values for a single contact */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	__u16 x, y, w, h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	__u16 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	bool tipswitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	bool confidence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	bool first_contact_touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	bool reading_mt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	__u8 mt_footer[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	__u8 mt_foot_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	/* The current activation state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	__s8 act_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	/* Empty frames to ignore before recognizing the end of activity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	__s8 deactivate_slack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	/* Frames to ignore before acknowledging the start of activity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	__s8 activate_slack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	/* Minimum size contact to accept */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	__u16 min_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	__u16 min_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	/* Threshold to override activation slack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	__u16 activation_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	__u16 activation_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	__u16 sensor_logical_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	__u16 sensor_logical_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	__u16 sensor_physical_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	__u16 sensor_physical_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  * This function converts the 4 byte raw firmware code into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * a string containing 5 comma separated numbers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static int ntrig_version_string(unsigned char *raw, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	__u8 a =  (raw[1] & 0x0e) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	__u8 b =  (raw[0] & 0x3c) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	__u8 c = ((raw[0] & 0x03) << 3) | ((raw[3] & 0xe0) >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	__u8 d = ((raw[3] & 0x07) << 3) | ((raw[2] & 0xe0) >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	__u8 e =   raw[2] & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	 * As yet unmapped bits:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	 * 0b11000000 0b11110001 0b00011000 0b00011000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	return sprintf(buf, "%u.%u.%u.%u.%u", a, b, c, d, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static inline int ntrig_get_mode(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 				    report_id_hash[0x0d];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	if (!report || report->maxfield < 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	    report->field[0]->report_count < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	hid_hw_wait(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	return (int)report->field[0]->value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) static inline void ntrig_set_mode(struct hid_device *hdev, const int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	__u8 mode_commands[4] = { 0xe, 0xf, 0x1b, 0x10 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	if (mode < 0 || mode > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	report = hdev->report_enum[HID_FEATURE_REPORT].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		 report_id_hash[mode_commands[mode]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	if (!report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static void ntrig_report_version(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	char buf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	struct usb_device *usb_dev = hid_to_usb_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	unsigned char *data = kmalloc(8, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 			      USB_REQ_CLEAR_FEATURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 			      USB_TYPE_CLASS | USB_RECIP_INTERFACE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 			      USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 			      0x30c, 1, data, 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 			      USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	if (ret == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		ret = ntrig_version_string(&data[2], buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 		hid_info(hdev, "Firmware version: %s (%02x%02x %02x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 			 buf, data[2], data[3], data[4], data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) static ssize_t show_phys_width(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 			       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 			       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	return sprintf(buf, "%d\n", nd->sensor_physical_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) static DEVICE_ATTR(sensor_physical_width, S_IRUGO, show_phys_width, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static ssize_t show_phys_height(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 				char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	return sprintf(buf, "%d\n", nd->sensor_physical_height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) static DEVICE_ATTR(sensor_physical_height, S_IRUGO, show_phys_height, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) static ssize_t show_log_width(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 			      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 			      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	return sprintf(buf, "%d\n", nd->sensor_logical_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) static DEVICE_ATTR(sensor_logical_width, S_IRUGO, show_log_width, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) static ssize_t show_log_height(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 			       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 			       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	return sprintf(buf, "%d\n", nd->sensor_logical_height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) static DEVICE_ATTR(sensor_logical_height, S_IRUGO, show_log_height, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) static ssize_t show_min_width(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 			      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 			      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	return sprintf(buf, "%d\n", nd->min_width *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 				    nd->sensor_physical_width /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 				    nd->sensor_logical_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) static ssize_t set_min_width(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 			     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	if (kstrtoul(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	if (val > nd->sensor_physical_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	nd->min_width = val * nd->sensor_logical_width /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 			      nd->sensor_physical_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) static DEVICE_ATTR(min_width, S_IWUSR | S_IRUGO, show_min_width, set_min_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) static ssize_t show_min_height(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 			       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 			       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	return sprintf(buf, "%d\n", nd->min_height *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 				    nd->sensor_physical_height /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 				    nd->sensor_logical_height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) static ssize_t set_min_height(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 			      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	if (kstrtoul(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	if (val > nd->sensor_physical_height)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	nd->min_height = val * nd->sensor_logical_height /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 			       nd->sensor_physical_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) static DEVICE_ATTR(min_height, S_IWUSR | S_IRUGO, show_min_height,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		   set_min_height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) static ssize_t show_activate_slack(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 				   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 				   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	return sprintf(buf, "%d\n", nd->activate_slack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) static ssize_t set_activate_slack(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 				  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 				  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	if (kstrtoul(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (val > 0x7f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	nd->activate_slack = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) static DEVICE_ATTR(activate_slack, S_IWUSR | S_IRUGO, show_activate_slack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		   set_activate_slack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) static ssize_t show_activation_width(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 				     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	return sprintf(buf, "%d\n", nd->activation_width *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 				    nd->sensor_physical_width /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 				    nd->sensor_logical_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) static ssize_t set_activation_width(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	if (kstrtoul(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (val > nd->sensor_physical_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	nd->activation_width = val * nd->sensor_logical_width /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 				     nd->sensor_physical_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) static DEVICE_ATTR(activation_width, S_IWUSR | S_IRUGO, show_activation_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		   set_activation_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) static ssize_t show_activation_height(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 				      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 				      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	return sprintf(buf, "%d\n", nd->activation_height *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 				    nd->sensor_physical_height /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 				    nd->sensor_logical_height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) static ssize_t set_activation_height(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 				     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	if (kstrtoul(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	if (val > nd->sensor_physical_height)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	nd->activation_height = val * nd->sensor_logical_height /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 				      nd->sensor_physical_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) static DEVICE_ATTR(activation_height, S_IWUSR | S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		   show_activation_height, set_activation_height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) static ssize_t show_deactivate_slack(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 				     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	return sprintf(buf, "%d\n", -nd->deactivate_slack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) static ssize_t set_deactivate_slack(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	if (kstrtoul(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	 * No more than 8 terminal frames have been observed so far
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	 * and higher slack is highly likely to leave the single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	 * touch emulation stuck down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	if (val > 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	nd->deactivate_slack = -val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) static DEVICE_ATTR(deactivate_slack, S_IWUSR | S_IRUGO, show_deactivate_slack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		   set_deactivate_slack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) static struct attribute *sysfs_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	&dev_attr_sensor_physical_width.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	&dev_attr_sensor_physical_height.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	&dev_attr_sensor_logical_width.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	&dev_attr_sensor_logical_height.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	&dev_attr_min_height.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	&dev_attr_min_width.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	&dev_attr_activate_slack.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	&dev_attr_activation_width.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	&dev_attr_activation_height.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	&dev_attr_deactivate_slack.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) static const struct attribute_group ntrig_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	.attrs = sysfs_attrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449)  * this driver is aimed at two firmware versions in circulation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)  *  - dual pen/finger single touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  *  - finger multitouch, pen not working
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			       struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			       unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	struct ntrig_data *nd = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	/* No special mappings needed for the pen and single touch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	if (field->physical)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	switch (usage->hid & HID_USAGE_PAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	case HID_UP_GENDESK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		switch (usage->hid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		case HID_GD_X:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 			hid_map_usage(hi, usage, bit, max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 					EV_ABS, ABS_MT_POSITION_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 			input_set_abs_params(hi->input, ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 					field->logical_minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 					field->logical_maximum, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			if (!nd->sensor_logical_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 				nd->sensor_logical_width =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 					field->logical_maximum -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 					field->logical_minimum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 				nd->sensor_physical_width =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 					field->physical_maximum -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 					field->physical_minimum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 				nd->activation_width = activation_width *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 					nd->sensor_logical_width /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 					nd->sensor_physical_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 				nd->min_width = min_width *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 					nd->sensor_logical_width /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 					nd->sensor_physical_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		case HID_GD_Y:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			hid_map_usage(hi, usage, bit, max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 					EV_ABS, ABS_MT_POSITION_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			input_set_abs_params(hi->input, ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 					field->logical_minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 					field->logical_maximum, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			if (!nd->sensor_logical_height) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 				nd->sensor_logical_height =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 					field->logical_maximum -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 					field->logical_minimum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 				nd->sensor_physical_height =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 					field->physical_maximum -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 					field->physical_minimum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 				nd->activation_height = activation_height *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 					nd->sensor_logical_height /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 					nd->sensor_physical_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 				nd->min_height = min_height *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 					nd->sensor_logical_height /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 					nd->sensor_physical_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	case HID_UP_DIGITIZER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		switch (usage->hid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		/* we do not want to map these for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		case HID_DG_CONTACTID: /* Not trustworthy, squelch for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		case HID_DG_INPUTMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		case HID_DG_DEVICEINDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		case HID_DG_CONTACTMAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		/* width/height mapped on TouchMajor/TouchMinor/Orientation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		case HID_DG_WIDTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			hid_map_usage(hi, usage, bit, max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 				      EV_ABS, ABS_MT_TOUCH_MAJOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		case HID_DG_HEIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			hid_map_usage(hi, usage, bit, max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 				      EV_ABS, ABS_MT_TOUCH_MINOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 					     0, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	case 0xff000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		/* we do not want to map these: no input-oriented meaning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) static int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			      struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			      unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	/* No special mappings needed for the pen and single touch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	if (field->physical)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	if (usage->type == EV_KEY || usage->type == EV_REL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 			|| usage->type == EV_ABS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		clear_bit(usage->code, *bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  * this function is called upon all reports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  * so that we can filter contact point information,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  * decide whether we are in multi or single touch mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  * and call input_mt_sync after each point if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) static int ntrig_event (struct hid_device *hid, struct hid_field *field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 			struct hid_usage *usage, __s32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	struct ntrig_data *nd = hid_get_drvdata(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	/* Skip processing if not a claimed input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	if (!(hid->claimed & HID_CLAIMED_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		goto not_claimed_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	/* This function is being called before the structures are fully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	 * initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	if(!(field->hidinput && field->hidinput->input))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	input = field->hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	/* No special handling needed for the pen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	if (field->application == HID_DG_PEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	switch (usage->hid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	case 0xff000001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		/* Tag indicating the start of a multitouch group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		nd->reading_mt = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		nd->first_contact_touch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	case HID_DG_TIPSWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		nd->tipswitch = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		/* Prevent emission of touch until validated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	case HID_DG_CONFIDENCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		nd->confidence = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	case HID_GD_X:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		nd->x = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		/* Clear the contact footer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		nd->mt_foot_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	case HID_GD_Y:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		nd->y = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	case HID_DG_CONTACTID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		nd->id = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	case HID_DG_WIDTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		nd->w = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	case HID_DG_HEIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		nd->h = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		 * when in single touch mode, this is the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		 * report received in a finger event. We want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		 * to emit a normal (X, Y) position
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		if (!nd->reading_mt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 			 * TipSwitch indicates the presence of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 			 * finger in single touch mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 			input_report_key(input, BTN_TOUCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 					 nd->tipswitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 			input_report_key(input, BTN_TOOL_DOUBLETAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 					 nd->tipswitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 			input_event(input, EV_ABS, ABS_X, nd->x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 			input_event(input, EV_ABS, ABS_Y, nd->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	case 0xff000002:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		 * we receive this when the device is in multitouch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		 * mode. The first of the three values tagged with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		 * this usage tells if the contact point is real
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		 * or a placeholder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		/* Shouldn't get more than 4 footer packets, so skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		if (nd->mt_foot_count >= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		nd->mt_footer[nd->mt_foot_count++] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		/* if the footer isn't complete break */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		if (nd->mt_foot_count != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		/* Pen activity signal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		if (nd->mt_footer[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 			 * When the pen deactivates touch, we see a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 			 * bogus frame with ContactCount > 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 			 * We can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 			 * save a bit of work by ensuring act_state < 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			 * even if deactivation slack is turned off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 			nd->act_state = deactivate_slack - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			nd->confidence = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		 * The first footer value indicates the presence of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		 * finger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		if (nd->mt_footer[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			 * We do not want to process contacts under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 			 * the size threshold, but do not want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			 * ignore them for activation state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 			if (nd->w < nd->min_width ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			    nd->h < nd->min_height)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 				nd->confidence = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		if (nd->act_state > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 			 * Contact meets the activation size threshold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 			if (nd->w >= nd->activation_width &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 			    nd->h >= nd->activation_height) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 				if (nd->id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 					 * first contact, activate now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 					nd->act_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 				else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 					 * avoid corrupting this frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 					 * but ensure next frame will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 					 * be active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 					nd->act_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 				 * Defer adjusting the activation state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 				 * until the end of the frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		/* Discarding this contact */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		if (!nd->confidence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		/* emit a normal (X, Y) for the first point only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		if (nd->id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			 * TipSwitch is superfluous in multitouch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 			 * mode.  The footer events tell us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			 * if there is a finger on the screen or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			 * not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 			nd->first_contact_touch = nd->confidence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 			input_event(input, EV_ABS, ABS_X, nd->x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			input_event(input, EV_ABS, ABS_Y, nd->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		/* Emit MT events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		input_event(input, EV_ABS, ABS_MT_POSITION_X, nd->x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		input_event(input, EV_ABS, ABS_MT_POSITION_Y, nd->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		 * Translate from height and width to size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		 * and orientation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		if (nd->w > nd->h) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 			input_event(input, EV_ABS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 					ABS_MT_ORIENTATION, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			input_event(input, EV_ABS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 					ABS_MT_TOUCH_MAJOR, nd->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			input_event(input, EV_ABS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 					ABS_MT_TOUCH_MINOR, nd->h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			input_event(input, EV_ABS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 					ABS_MT_ORIENTATION, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			input_event(input, EV_ABS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 					ABS_MT_TOUCH_MAJOR, nd->h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			input_event(input, EV_ABS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 					ABS_MT_TOUCH_MINOR, nd->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		input_mt_sync(field->hidinput->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	case HID_DG_CONTACTCOUNT: /* End of a multitouch group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		if (!nd->reading_mt) /* Just to be sure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		nd->reading_mt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		 * Activation state machine logic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		 * Fundamental states:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		 *	state >  0: Inactive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		 *	state <= 0: Active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		 *	state <  -deactivate_slack:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		 *		 Pen termination of touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		 * Specific values of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		 *	state == activate_slack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		 *		 no valid input since the last reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		 *	state == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		 *		 general operational state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		 *	state == -deactivate_slack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		 *		 read sufficient empty frames to accept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		 *		 the end of input and reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		if (nd->act_state > 0) { /* Currently inactive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 				 * Consider each live contact as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 				 * evidence of intentional activity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 				nd->act_state = (nd->act_state > value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 						? nd->act_state - value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 						: 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 				 * Empty frame before we hit the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 				 * activity threshold, reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 				nd->act_state = nd->activate_slack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			 * Entered this block inactive and no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			 * coordinates sent this frame, so hold off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			 * on button state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		} else { /* Currently active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			if (value && nd->act_state >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 				     nd->deactivate_slack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 				 * Live point: clear accumulated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 				 * deactivation count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 				nd->act_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 			else if (nd->act_state <= nd->deactivate_slack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 				 * We've consumed the deactivation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 				 * slack, time to deactivate and reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 				nd->act_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 					nd->activate_slack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			else { /* Move towards deactivation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 				nd->act_state--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		if (nd->first_contact_touch && nd->act_state <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			 * Check to see if we're ready to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			 * emitting touch events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			 * Note: activation slack will decrease over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 			 * the course of the frame, and it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 			 * inconsistent from the start to the end of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			 * the frame.  However if the frame starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			 * with slack, first_contact_touch will still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			 * be 0 and we will not get to this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			input_report_key(input, BTN_TOOL_DOUBLETAP, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			input_report_key(input, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			input_report_key(input, BTN_TOOL_DOUBLETAP, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 			input_report_key(input, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		/* fall-back to the generic hidinput handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) not_claimed_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	/* we have handled the hidinput part, now remains hiddev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		hid->hiddev_hid_event(hid, field, usage, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) static int ntrig_input_configured(struct hid_device *hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		struct hid_input *hidinput)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	struct input_dev *input = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	if (hidinput->report->maxfield < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	switch (hidinput->report->field[0]->application) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	case HID_DG_PEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		input->name = "N-Trig Pen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	case HID_DG_TOUCHSCREEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		/* These keys are redundant for fingers, clear them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		 * to prevent incorrect identification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		__clear_bit(BTN_TOOL_PEN, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		__clear_bit(BTN_TOOL_FINGER, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		__clear_bit(BTN_0, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		__set_bit(BTN_TOOL_DOUBLETAP, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		 * The physical touchscreen (single touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		 * input has a value for physical, whereas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		 * the multitouch only has logical input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		 * fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		input->name = (hidinput->report->field[0]->physical) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 							"N-Trig Touchscreen" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 							"N-Trig MultiTouch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	struct ntrig_data *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	if (id->driver_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		hdev->quirks |= HID_QUIRK_MULTI_INPUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 				| HID_QUIRK_NO_INIT_REPORTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (!nd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		hid_err(hdev, "cannot allocate N-Trig data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	nd->reading_mt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	nd->min_width = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	nd->min_height = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	nd->activate_slack = activate_slack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	nd->act_state = activate_slack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	nd->deactivate_slack = -deactivate_slack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	nd->sensor_logical_width = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	nd->sensor_logical_height = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	nd->sensor_physical_width = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	nd->sensor_physical_height = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	hid_set_drvdata(hdev, nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	/* This is needed for devices with more recent firmware versions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0x0a];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (report) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		/* Let the device settle to ensure the wakeup message gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		 * through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		hid_hw_wait(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		 * Sanity check: if the current mode is invalid reset it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		 * something reasonable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		if (ntrig_get_mode(hdev) >= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			ntrig_set_mode(hdev, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	ntrig_report_version(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	ret = sysfs_create_group(&hdev->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			&ntrig_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		hid_err(hdev, "cannot create sysfs group\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	kfree(nd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) static void ntrig_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	sysfs_remove_group(&hdev->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 			   &ntrig_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	kfree(hid_get_drvdata(hdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) static const struct hid_device_id ntrig_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		.driver_data = NTRIG_DUPLICATE_USAGES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) MODULE_DEVICE_TABLE(hid, ntrig_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static const struct hid_usage_id ntrig_grabbed_usages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	{ HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	{ HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) static struct hid_driver ntrig_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	.name = "ntrig",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	.id_table = ntrig_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	.probe = ntrig_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	.remove = ntrig_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	.input_mapping = ntrig_input_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	.input_mapped = ntrig_input_mapped,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	.input_configured = ntrig_input_configured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	.usage_table = ntrig_grabbed_usages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	.event = ntrig_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) module_hid_driver(ntrig_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) MODULE_LICENSE("GPL");