w8001
static void scale_touch_coordinates(struct w8001 *w8001,
if (w8001->max_pen_x && w8001->max_touch_x)
*x = *x * w8001->max_pen_x / w8001->max_touch_x;
if (w8001->max_pen_y && w8001->max_touch_y)
*y = *y * w8001->max_pen_y / w8001->max_touch_y;
static void parse_multi_touch(struct w8001 *w8001)
struct input_dev *dev = w8001->touch_dev;
unsigned char *data = w8001->data;
scale_touch_coordinates(w8001, &x, &y);
if (w8001->type != BTN_TOOL_PEN &&
w8001->type != BTN_TOOL_RUBBER) {
w8001->type = count == 1 ? BTN_TOOL_FINGER : KEY_RESERVED;
static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
struct input_dev *dev = w8001->pen_dev;
switch (w8001->type) {
w8001->type = BTN_TOOL_PEN;
w8001->type = coord->f2 ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
input_report_key(dev, w8001->type, coord->rdy);
w8001->type = KEY_RESERVED;
static void report_single_touch(struct w8001 *w8001, struct w8001_coord *coord)
struct input_dev *dev = w8001->touch_dev;
scale_touch_coordinates(w8001, &x, &y);
w8001->type = coord->tsw ? BTN_TOOL_FINGER : KEY_RESERVED;
struct w8001 *w8001 = serio_get_drvdata(serio);
w8001->data[w8001->idx] = data;
switch (w8001->idx++) {
w8001->idx = 0;
tmp = w8001->data[0] & W8001_TOUCH_BYTE;
if (w8001->pktlen == w8001->idx) {
w8001->idx = 0;
if (w8001->type != BTN_TOOL_PEN &&
w8001->type != BTN_TOOL_RUBBER) {
parse_single_touch(w8001->data, &coord);
report_single_touch(w8001, &coord);
tmp = w8001->data[0] & W8001_TAB_MASK;
tmp = w8001->data[0] & W8001_TOUCH_BYTE;
w8001->idx = 0;
parse_pen_data(w8001->data, &coord);
report_pen_events(w8001, &coord);
tmp = w8001->data[0] & W8001_TOUCH_MASK;
w8001->idx = 0;
memcpy(w8001->response, w8001->data, W8001_MAX_LENGTH);
w8001->response_type = W8001_QUERY_PACKET;
complete(&w8001->cmd_done);
w8001->idx = 0;
parse_multi_touch(w8001);
if (!w8001->touch_dev && w8001->idx > W8001_PKTLEN_TPCPEN - 1)
w8001->idx = 0;
static int w8001_command(struct w8001 *w8001, unsigned char command,
w8001->response_type = 0;
init_completion(&w8001->cmd_done);
rc = serio_write(w8001->serio, command);
wait_for_completion_timeout(&w8001->cmd_done, HZ);
if (w8001->response_type != W8001_QUERY_PACKET)
struct w8001 *w8001 = input_get_drvdata(dev);
scoped_guard(mutex_intr, &w8001->mutex) {
if (w8001->open_count == 0) {
err = w8001_command(w8001, W8001_CMD_START, false);
w8001->open_count++;
struct w8001 *w8001 = input_get_drvdata(dev);
guard(mutex)(&w8001->mutex);
if (--w8001->open_count == 0)
w8001_command(w8001, W8001_CMD_STOP, false);
static int w8001_detect(struct w8001 *w8001)
error = w8001_command(w8001, W8001_CMD_STOP, false);
static int w8001_setup_pen(struct w8001 *w8001, char *basename,
struct input_dev *dev = w8001->pen_dev;
error = w8001_command(w8001, W8001_CMD_QUERY, true);
parse_pen_data(w8001->response, &coord);
w8001->max_pen_x = coord.x;
w8001->max_pen_y = coord.y;
w8001->id = 0x90;
static int w8001_setup_touch(struct w8001 *w8001, char *basename,
struct input_dev *dev = w8001->touch_dev;
error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
if (!w8001->response[1])
parse_touchquery(w8001->response, &touch);
w8001->max_touch_x = touch.x;
w8001->max_touch_y = touch.y;
if (w8001->max_pen_x && w8001->max_pen_y) {
touch.x = w8001->max_pen_x;
touch.y = w8001->max_pen_y;
w8001->pktlen = W8001_PKTLEN_TOUCH93;
w8001->id = 0x93;
w8001->pktlen = W8001_PKTLEN_TOUCH9A;
w8001->id = 0x9a;
w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
dev_err(&w8001->serio->dev,
if (w8001->max_pen_x && w8001->max_pen_y)
w8001->id = 0xE3;
w8001->id = 0xE2;
static void w8001_set_devdata(struct input_dev *dev, struct w8001 *w8001,
dev->phys = w8001->phys;
dev->id.product = w8001->id;
input_set_drvdata(dev, w8001);
struct w8001 *w8001 = serio_get_drvdata(serio);
if (w8001->pen_dev)
input_unregister_device(w8001->pen_dev);
if (w8001->touch_dev)
input_unregister_device(w8001->touch_dev);
kfree(w8001);
struct w8001 *w8001;
w8001 = kzalloc_obj(*w8001);
if (!w8001 || !input_dev_pen || !input_dev_touch) {
w8001->serio = serio;
w8001->pen_dev = input_dev_pen;
w8001->touch_dev = input_dev_touch;
mutex_init(&w8001->mutex);
init_completion(&w8001->cmd_done);
snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys);
serio_set_drvdata(serio, w8001);
err = w8001_detect(w8001);
err_pen = w8001_setup_pen(w8001, basename, sizeof(basename));
err_touch = w8001_setup_touch(w8001, basename, sizeof(basename));
snprintf(w8001->pen_name, sizeof(w8001->pen_name),
input_dev_pen->name = w8001->pen_name;
w8001_set_devdata(input_dev_pen, w8001, serio);
err = input_register_device(w8001->pen_dev);
w8001->pen_dev = NULL;
snprintf(w8001->touch_name, sizeof(w8001->touch_name),
input_dev_touch->name = w8001->touch_name;
w8001_set_devdata(input_dev_touch, w8001, serio);
err = input_register_device(w8001->touch_dev);
w8001->touch_dev = NULL;
if (w8001->pen_dev)
input_unregister_device(w8001->pen_dev);
kfree(w8001);