/*
* HID driver for N-Trig touchscreens
*
* Copyright (c) 2008-2010 Rafi Rubin
* Copyright (c) 2009-2010 Stephane Chatty
*
*/
/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*/
#include <linux/device.h>
#include <linux/hid.h>
#include <linux/usb.h>
#include "usbhid/usbhid.h"
#include <linux/module.h>
#include <linux/slab.h>
#include "hid-ids.h"
#define NTRIG_DUPLICATE_USAGES 0x001
static unsigned int min_width;
module_param(min_width, uint, 0644);
MODULE_PARM_DESC(min_width, "Minimum touch contact width to accept.");
static unsigned int min_height;
module_param(min_height, uint, 0644);
MODULE_PARM_DESC(min_height, "Minimum touch contact height to accept.");
static unsigned int activate_slack = 1;
module_param(activate_slack, uint, 0644);
MODULE_PARM_DESC(activate_slack, "Number of touch frames to ignore at "
"the start of touch input.");
static unsigned int deactivate_slack = 4;
module_param(deactivate_slack, uint, 0644);
MODULE_PARM_DESC(deactivate_slack, "Number of empty frames to ignore before "
"deactivating touch.");
static unsigned int activation_width = 64;
module_param(activation_width, uint, 0644);
MODULE_PARM_DESC(activation_width, "Width threshold to immediately start "
"processing touch events.");
static unsigned int activation_height = 32;
module_param(activation_height, uint, 0644);
MODULE_PARM_DESC(activation_height, "Height threshold to immediately start "
"processing touch events.");
struct ntrig_data {
/* Incoming raw values for a single contact */
__u16 x, y, w, h;
__u16 id;
bool tipswitch;
bool confidence;
bool first_contact_touch;
bool reading_mt;
__u8 mt_footer[4];
__u8 mt_foot_count;
/* The current activation state. */
__s8 act_state;
/* Empty frames to ignore before recognizing the end of activity */
__s8 deactivate_slack;
/* Frames to ignore before acknowledging the start of activity */
__s8 activate_slack;
/* Minimum size contact to accept */
__u16 min_width;
__u16 min_height;
/* Threshold to override activation slack */
__u16 activation_width;
__u16 activation_height;
__u16 sensor_logical_width;
__u16 sensor_logical_height;
__u16 sensor_physical_width;
__u16 sensor_physical_height;
};
/*
* This function converts the 4 byte raw firmware code into
* a string containing 5 comma separated numbers.
*/
static int ntrig_version_string(unsigned char *raw, char *buf)
{
__u8 a = (raw[1] & 0x0e) >> 1;
__u8 b = (raw[0] & 0x3c) >> 2;
__u8 c = ((raw[0] & 0x03) << 3) | ((raw[3] & 0xe0) >> 5);
__u8 d = ((raw[3] & 0x07) << 3) | ((raw[2] & 0xe0) >> 5);
__u8 e = raw[2] & 0x07;
/*
* As yet unmapped bits:
* 0b11000000 0b11110001 0b00011000 0b00011000
*/
return sprintf(buf, "%u.%u.%u.%u.%u", a, b, c, d, e);
}
static void ntrig_report_version(struct hid_device *hdev)
{
int ret;
char buf[20];
struct usb_device *usb_dev = hid_to_usb_dev(hdev);
unsigned char *data = kmalloc(8, GFP_KERNEL);
if (!data)
goto err_free;
ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
USB_REQ_CLEAR_FEATURE,
USB_TYPE_CLASS | USB_RECIP_INTERFACE |
USB_DIR_IN,
0x30c, 1, data, 8,
USB_CTRL_SET_TIMEOUT);
if (ret == 8) {
ret = ntrig_version_string(&data[2], buf);
dev_info(&hdev->dev,
"Firmware version: %s (%02x%02x %02x%02x)\n",
buf, data[2], data[3], data[4], data[5]);
}
err_free:
kfree(data);
}
static ssize_t show_phys_width(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct ntrig_data *nd = hid_get_drvdata(hdev);
return sprintf(buf, "%d\n", nd->sensor_physical_width);
}
static DEVICE_ATTR(sensor_physical_width, S_IRUGO, show_phys_width, NULL);
static ssize_t show_phys_height(struct device *dev,
struct device_attribute *