Lines Matching defs:w8001
84 struct w8001 {
138 static void scale_touch_coordinates(struct w8001 *w8001,
141 if (w8001->max_pen_x && w8001->max_touch_x)
142 *x = *x * w8001->max_pen_x / w8001->max_touch_x;
144 if (w8001->max_pen_y && w8001->max_touch_y)
145 *y = *y * w8001->max_pen_y / w8001->max_touch_y;
148 static void parse_multi_touch(struct w8001 *w8001)
150 struct input_dev *dev = w8001->touch_dev;
151 unsigned char *data = w8001->data;
167 scale_touch_coordinates(w8001, &x, &y);
179 if (w8001->type != BTN_TOOL_PEN &&
180 w8001->type != BTN_TOOL_RUBBER) {
181 w8001->type = count == 1 ? BTN_TOOL_FINGER : KEY_RESERVED;
214 static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
216 struct input_dev *dev = w8001->pen_dev;
228 switch (w8001->type) {
237 w8001->type = BTN_TOOL_PEN;
243 w8001->type = coord->f2 ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
256 input_report_key(dev, w8001->type, coord->rdy);
260 w8001->type = KEY_RESERVED;
263 static void report_single_touch(struct w8001 *w8001, struct w8001_coord *coord)
265 struct input_dev *dev = w8001->touch_dev;
270 scale_touch_coordinates(w8001, &x, &y);
278 w8001->type = coord->tsw ? BTN_TOOL_FINGER : KEY_RESERVED;
284 struct w8001 *w8001 = serio_get_drvdata(serio);
288 w8001->data[w8001->idx] = data;
289 switch (w8001->idx++) {
292 pr_debug("w8001: unsynchronized data: 0x%02x\n", data);
293 w8001->idx = 0;
299 tmp = w8001->data[0] & W8001_TOUCH_BYTE;
303 if (w8001->pktlen == w8001->idx) {
304 w8001->idx = 0;
305 if (w8001->type != BTN_TOOL_PEN &&
306 w8001->type != BTN_TOOL_RUBBER) {
307 parse_single_touch(w8001->data, &coord);
308 report_single_touch(w8001, &coord);
315 tmp = w8001->data[0] & W8001_TAB_MASK;
319 tmp = w8001->data[0] & W8001_TOUCH_BYTE;
323 w8001->idx = 0;
324 parse_pen_data(w8001->data, &coord);
325 report_pen_events(w8001, &coord);
330 tmp = w8001->data[0] & W8001_TOUCH_MASK;
334 w8001->idx = 0;
335 memcpy(w8001->response, w8001->data, W8001_MAX_LENGTH);
336 w8001->response_type = W8001_QUERY_PACKET;
337 complete(&w8001->cmd_done);
342 w8001->idx = 0;
343 parse_multi_touch(w8001);
352 if (!w8001->touch_dev && w8001->idx > W8001_PKTLEN_TPCPEN - 1)
353 w8001->idx = 0;
359 static int w8001_command(struct w8001 *w8001, unsigned char command,
364 w8001->response_type = 0;
365 init_completion(&w8001->cmd_done);
367 rc = serio_write(w8001->serio, command);
370 wait_for_completion_timeout(&w8001->cmd_done, HZ);
371 if (w8001->response_type != W8001_QUERY_PACKET)
380 struct w8001 *w8001 = input_get_drvdata(dev);
383 err = mutex_lock_interruptible(&w8001->mutex);
387 if (w8001->open_count++ == 0) {
388 err = w8001_command(w8001, W8001_CMD_START, false);
390 w8001->open_count--;
393 mutex_unlock(&w8001->mutex);
399 struct w8001 *w8001 = input_get_drvdata(dev);
401 mutex_lock(&w8001->mutex);
403 if (--w8001->open_count == 0)
404 w8001_command(w8001, W8001_CMD_STOP, false);
406 mutex_unlock(&w8001->mutex);
409 static int w8001_detect(struct w8001 *w8001)
413 error = w8001_command(w8001, W8001_CMD_STOP, false);
422 static int w8001_setup_pen(struct w8001 *w8001, char *basename,
425 struct input_dev *dev = w8001->pen_dev;
430 error = w8001_command(w8001, W8001_CMD_QUERY, true);
443 parse_pen_data(w8001->response, &coord);
444 w8001->max_pen_x = coord.x;
445 w8001->max_pen_y = coord.y;
457 w8001->id = 0x90;
463 static int w8001_setup_touch(struct w8001 *w8001, char *basename,
466 struct input_dev *dev = w8001->touch_dev;
472 error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
479 if (!w8001->response[1])
487 parse_touchquery(w8001->response, &touch);
488 w8001->max_touch_x = touch.x;
489 w8001->max_touch_y = touch.y;
491 if (w8001->max_pen_x && w8001->max_pen_y) {
493 touch.x = w8001->max_pen_x;
494 touch.y = w8001->max_pen_y;
506 w8001->pktlen = W8001_PKTLEN_TOUCH93;
507 w8001->id = 0x93;
514 w8001->pktlen = W8001_PKTLEN_TOUCH9A;
516 w8001->id = 0x9a;
520 w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
525 dev_err(&w8001->serio->dev,
540 if (w8001->max_pen_x && w8001->max_pen_y)
541 w8001->id = 0xE3;
543 w8001->id = 0xE2;
552 static void w8001_set_devdata(struct input_dev *dev, struct w8001 *w8001,
555 dev->phys = w8001->phys;
557 dev->id.product = w8001->id;
565 input_set_drvdata(dev, w8001);
574 struct w8001 *w8001 = serio_get_drvdata(serio);
578 if (w8001->pen_dev)
579 input_unregister_device(w8001->pen_dev);
580 if (w8001->touch_dev)
581 input_unregister_device(w8001->touch_dev);
582 kfree(w8001);
589 * new serio device that supports the w8001 protocol and registers it as
595 struct w8001 *w8001;
601 w8001 = kzalloc(sizeof(struct w8001), GFP_KERNEL);
604 if (!w8001 || !input_dev_pen || !input_dev_touch) {
609 w8001->serio = serio;
610 w8001->pen_dev = input_dev_pen;
611 w8001->touch_dev = input_dev_touch;
612 mutex_init(&w8001->mutex);
613 init_completion(&w8001->cmd_done);
614 snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys);
616 serio_set_drvdata(serio, w8001);
621 err = w8001_detect(w8001);
630 err_pen = w8001_setup_pen(w8001, basename, sizeof(basename));
631 err_touch = w8001_setup_touch(w8001, basename, sizeof(basename));
638 strlcpy(w8001->pen_name, basename, sizeof(w8001->pen_name));
639 strlcat(w8001->pen_name, " Pen", sizeof(w8001->pen_name));
640 input_dev_pen->name = w8001->pen_name;
642 w8001_set_devdata(input_dev_pen, w8001, serio);
644 err = input_register_device(w8001->pen_dev);
650 w8001->pen_dev = NULL;
654 strlcpy(w8001->touch_name, basename, sizeof(w8001->touch_name));
655 strlcat(w8001->touch_name, " Finger",
656 sizeof(w8001->touch_name));
657 input_dev_touch->name = w8001->touch_name;
659 w8001_set_devdata(input_dev_touch, w8001, serio);
661 err = input_register_device(w8001->touch_dev);
667 w8001->touch_dev = NULL;
673 if (w8001->pen_dev)
674 input_unregister_device(w8001->pen_dev);
682 kfree(w8001);
700 .name = "w8001",