Skip to content

Commit 5d0a4fe

Browse files
whotdtor
authored andcommitted
Input: wacom_w8001 - split pen and touch initialization up
This is preparation work for splitting it up for two event nodes. Signed-off-by: Peter Hutterer <[email protected]> Acked-by: Benjamin Tissoires <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent e171735 commit 5d0a4fe

File tree

1 file changed

+111
-83
lines changed

1 file changed

+111
-83
lines changed

drivers/input/touchscreen/wacom_w8001.c

Lines changed: 111 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,10 @@ static void w8001_close(struct input_dev *dev)
380380
w8001_command(w8001, W8001_CMD_STOP, false);
381381
}
382382

383-
static int w8001_setup(struct w8001 *w8001)
383+
static int w8001_detect(struct w8001 *w8001)
384384
{
385385
struct input_dev *dev = w8001->dev;
386-
struct w8001_coord coord;
387-
struct w8001_touch_query touch;
388-
int error, err_pen, err_touch;
386+
int error;
389387

390388
error = w8001_command(w8001, W8001_CMD_STOP, false);
391389
if (error)
@@ -399,98 +397,121 @@ static int w8001_setup(struct w8001 *w8001)
399397

400398
__set_bit(INPUT_PROP_DIRECT, dev->propbit);
401399

400+
return 0;
401+
}
402+
403+
static int w8001_setup_pen(struct w8001 *w8001)
404+
{
405+
struct input_dev *dev = w8001->dev;
406+
struct w8001_coord coord;
407+
int error;
408+
402409
/* penabled? */
403-
err_pen = w8001_command(w8001, W8001_CMD_QUERY, true);
404-
if (!err_pen) {
405-
__set_bit(BTN_TOUCH, dev->keybit);
406-
__set_bit(BTN_TOOL_PEN, dev->keybit);
407-
__set_bit(BTN_TOOL_RUBBER, dev->keybit);
408-
__set_bit(BTN_STYLUS, dev->keybit);
409-
__set_bit(BTN_STYLUS2, dev->keybit);
410-
411-
parse_pen_data(w8001->response, &coord);
412-
w8001->max_pen_x = coord.x;
413-
w8001->max_pen_y = coord.y;
414-
415-
input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
416-
input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
417-
input_abs_set_res(dev, ABS_X, W8001_PEN_RESOLUTION);
418-
input_abs_set_res(dev, ABS_Y, W8001_PEN_RESOLUTION);
419-
input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
420-
if (coord.tilt_x && coord.tilt_y) {
421-
input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
422-
input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
423-
}
424-
w8001->id = 0x90;
425-
strlcat(w8001->name, " Penabled", sizeof(w8001->name));
410+
error = w8001_command(w8001, W8001_CMD_QUERY, true);
411+
if (error)
412+
return error;
413+
414+
__set_bit(BTN_TOUCH, dev->keybit);
415+
__set_bit(BTN_TOOL_PEN, dev->keybit);
416+
__set_bit(BTN_TOOL_RUBBER, dev->keybit);
417+
__set_bit(BTN_STYLUS, dev->keybit);
418+
__set_bit(BTN_STYLUS2, dev->keybit);
419+
420+
parse_pen_data(w8001->response, &coord);
421+
w8001->max_pen_x = coord.x;
422+
w8001->max_pen_y = coord.y;
423+
424+
input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
425+
input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
426+
input_abs_set_res(dev, ABS_X, W8001_PEN_RESOLUTION);
427+
input_abs_set_res(dev, ABS_Y, W8001_PEN_RESOLUTION);
428+
input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
429+
if (coord.tilt_x && coord.tilt_y) {
430+
input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
431+
input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
426432
}
427433

434+
w8001->id = 0x90;
435+
strlcat(w8001->name, " Penabled", sizeof(w8001->name));
436+
437+
return 0;
438+
}
439+
440+
static int w8001_setup_touch(struct w8001 *w8001)
441+
{
442+
struct input_dev *dev = w8001->dev;
443+
struct w8001_touch_query touch;
444+
int error;
445+
428446
/* Touch enabled? */
429-
err_touch = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
447+
error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
448+
if (error)
449+
return error;
450+
/*
451+
* Some non-touch devices may reply to the touch query. But their
452+
* second byte is empty, which indicates touch is not supported.
453+
*/
454+
if (!w8001->response[1])
455+
return -ENXIO;
430456

431-
if (!err_touch && !w8001->response[1])
432-
err_touch = -ENXIO;
457+
__set_bit(BTN_TOUCH, dev->keybit);
458+
__set_bit(BTN_TOOL_FINGER, dev->keybit);
433459

434-
if (!err_touch) {
435-
__set_bit(BTN_TOUCH, dev->keybit);
436-
__set_bit(BTN_TOOL_FINGER, dev->keybit);
460+
parse_touchquery(w8001->response, &touch);
461+
w8001->max_touch_x = touch.x;
462+
w8001->max_touch_y = touch.y;
437463

438-
parse_touchquery(w8001->response, &touch);
439-
w8001->max_touch_x = touch.x;
440-
w8001->max_touch_y = touch.y;
464+
if (w8001->max_pen_x && w8001->max_pen_y) {
465+
/* if pen is supported scale to pen maximum */
466+
touch.x = w8001->max_pen_x;
467+
touch.y = w8001->max_pen_y;
468+
touch.panel_res = W8001_PEN_RESOLUTION;
469+
}
441470

442-
if (w8001->max_pen_x && w8001->max_pen_y) {
443-
/* if pen is supported scale to pen maximum */
444-
touch.x = w8001->max_pen_x;
445-
touch.y = w8001->max_pen_y;
446-
touch.panel_res = W8001_PEN_RESOLUTION;
447-
}
471+
input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
472+
input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
473+
input_abs_set_res(dev, ABS_X, touch.panel_res);
474+
input_abs_set_res(dev, ABS_Y, touch.panel_res);
448475

449-
input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
450-
input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
451-
input_abs_set_res(dev, ABS_X, touch.panel_res);
452-
input_abs_set_res(dev, ABS_Y, touch.panel_res);
453-
454-
switch (touch.sensor_id) {
455-
case 0:
456-
case 2:
457-
w8001->pktlen = W8001_PKTLEN_TOUCH93;
458-
w8001->id = 0x93;
459-
strlcat(w8001->name, " 1FG", sizeof(w8001->name));
460-
break;
476+
switch (touch.sensor_id) {
477+
case 0:
478+
case 2:
479+
w8001->pktlen = W8001_PKTLEN_TOUCH93;
480+
w8001->id = 0x93;
481+
strlcat(w8001->name, " 1FG", sizeof(w8001->name));
482+
break;
461483

462-
case 1:
463-
case 3:
464-
case 4:
465-
w8001->pktlen = W8001_PKTLEN_TOUCH9A;
466-
strlcat(w8001->name, " 1FG", sizeof(w8001->name));
467-
w8001->id = 0x9a;
468-
break;
484+
case 1:
485+
case 3:
486+
case 4:
487+
w8001->pktlen = W8001_PKTLEN_TOUCH9A;
488+
strlcat(w8001->name, " 1FG", sizeof(w8001->name));
489+
w8001->id = 0x9a;
490+
break;
469491

470-
case 5:
471-
w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
472-
473-
__set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
474-
input_mt_init_slots(dev, 2, 0);
475-
input_set_abs_params(dev, ABS_MT_POSITION_X,
476-
0, touch.x, 0, 0);
477-
input_set_abs_params(dev, ABS_MT_POSITION_Y,
478-
0, touch.y, 0, 0);
479-
input_set_abs_params(dev, ABS_MT_TOOL_TYPE,
480-
0, MT_TOOL_MAX, 0, 0);
481-
482-
strlcat(w8001->name, " 2FG", sizeof(w8001->name));
483-
if (w8001->max_pen_x && w8001->max_pen_y)
484-
w8001->id = 0xE3;
485-
else
486-
w8001->id = 0xE2;
487-
break;
488-
}
492+
case 5:
493+
w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
494+
495+
__set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
496+
input_mt_init_slots(dev, 2, 0);
497+
input_set_abs_params(dev, ABS_MT_POSITION_X,
498+
0, touch.x, 0, 0);
499+
input_set_abs_params(dev, ABS_MT_POSITION_Y,
500+
0, touch.y, 0, 0);
501+
input_set_abs_params(dev, ABS_MT_TOOL_TYPE,
502+
0, MT_TOOL_MAX, 0, 0);
503+
504+
strlcat(w8001->name, " 2FG", sizeof(w8001->name));
505+
if (w8001->max_pen_x && w8001->max_pen_y)
506+
w8001->id = 0xE3;
507+
else
508+
w8001->id = 0xE2;
509+
break;
489510
}
490511

491512
strlcat(w8001->name, " Touchscreen", sizeof(w8001->name));
492513

493-
return !err_pen || !err_touch ? 0 : -ENXIO;
514+
return 0;
494515
}
495516

496517
/*
@@ -519,7 +540,7 @@ static int w8001_connect(struct serio *serio, struct serio_driver *drv)
519540
{
520541
struct w8001 *w8001;
521542
struct input_dev *input_dev;
522-
int err;
543+
int err, err_pen, err_touch;
523544

524545
w8001 = kzalloc(sizeof(struct w8001), GFP_KERNEL);
525546
input_dev = input_allocate_device();
@@ -538,10 +559,17 @@ static int w8001_connect(struct serio *serio, struct serio_driver *drv)
538559
if (err)
539560
goto fail2;
540561

541-
err = w8001_setup(w8001);
562+
err = w8001_detect(w8001);
542563
if (err)
543564
goto fail3;
544565

566+
err_pen = w8001_setup_pen(w8001);
567+
err_touch = w8001_setup_touch(w8001);
568+
if (err_pen && err_touch) {
569+
err = -ENXIO;
570+
goto fail3;
571+
}
572+
545573
input_dev->name = w8001->name;
546574
input_dev->phys = w8001->phys;
547575
input_dev->id.product = w8001->id;

0 commit comments

Comments
 (0)