touchpad: normalize the touchpad resolution to 400dpi, not 10 units/mm
[platform/upstream/libinput.git] / src / evdev-mt-touchpad.c
1 /*
2  * Copyright © 2014 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include "config.h"
24
25 #include <assert.h>
26 #include <math.h>
27 #include <stdbool.h>
28
29 #include "evdev-mt-touchpad.h"
30
31 #define DEFAULT_ACCEL_NUMERATOR 1200.0
32 #define DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR 700.0
33
34 static inline int
35 tp_hysteresis(int in, int center, int margin)
36 {
37         int diff = in - center;
38         if (abs(diff) <= margin)
39                 return center;
40
41         if (diff > margin)
42                 return center + diff - margin;
43         else
44                 return center + diff + margin;
45 }
46
47 static inline struct tp_motion *
48 tp_motion_history_offset(struct tp_touch *t, int offset)
49 {
50         int offset_index =
51                 (t->history.index - offset + TOUCHPAD_HISTORY_LENGTH) %
52                 TOUCHPAD_HISTORY_LENGTH;
53
54         return &t->history.samples[offset_index];
55 }
56
57 static void
58 tp_filter_motion(struct tp_dispatch *tp,
59                  double *dx, double *dy, uint64_t time)
60 {
61         struct motion_params motion;
62
63         motion.dx = *dx * tp->accel.x_scale_coeff;
64         motion.dy = *dy * tp->accel.y_scale_coeff;
65
66         if (motion.dx != 0.0 || motion.dy != 0.0)
67                 filter_dispatch(tp->filter, &motion, tp, time);
68
69         *dx = motion.dx;
70         *dy = motion.dy;
71 }
72
73 static inline void
74 tp_motion_history_push(struct tp_touch *t)
75 {
76         int motion_index = (t->history.index + 1) % TOUCHPAD_HISTORY_LENGTH;
77
78         if (t->history.count < TOUCHPAD_HISTORY_LENGTH)
79                 t->history.count++;
80
81         t->history.samples[motion_index].x = t->x;
82         t->history.samples[motion_index].y = t->y;
83         t->history.index = motion_index;
84 }
85
86 static inline void
87 tp_motion_hysteresis(struct tp_dispatch *tp,
88                      struct tp_touch *t)
89 {
90         int x = t->x,
91             y = t->y;
92
93         if (t->history.count == 0) {
94                 t->hysteresis.center_x = t->x;
95                 t->hysteresis.center_y = t->y;
96         } else {
97                 x = tp_hysteresis(x,
98                                   t->hysteresis.center_x,
99                                   tp->hysteresis.margin_x);
100                 y = tp_hysteresis(y,
101                                   t->hysteresis.center_y,
102                                   tp->hysteresis.margin_y);
103                 t->hysteresis.center_x = x;
104                 t->hysteresis.center_y = y;
105                 t->x = x;
106                 t->y = y;
107         }
108 }
109
110 static inline void
111 tp_motion_history_reset(struct tp_touch *t)
112 {
113         t->history.count = 0;
114 }
115
116 static inline struct tp_touch *
117 tp_current_touch(struct tp_dispatch *tp)
118 {
119         return &tp->touches[min(tp->slot, tp->ntouches - 1)];
120 }
121
122 static inline struct tp_touch *
123 tp_get_touch(struct tp_dispatch *tp, unsigned int slot)
124 {
125         assert(slot < tp->ntouches);
126         return &tp->touches[slot];
127 }
128
129 static inline void
130 tp_begin_touch(struct tp_dispatch *tp, struct tp_touch *t)
131 {
132         if (t->state != TOUCH_UPDATE) {
133                 tp_motion_history_reset(t);
134                 t->dirty = true;
135                 t->state = TOUCH_BEGIN;
136                 t->pinned.is_pinned = false;
137                 tp->nfingers_down++;
138                 assert(tp->nfingers_down >= 1);
139                 tp->queued |= TOUCHPAD_EVENT_MOTION;
140         }
141 }
142
143 static inline void
144 tp_end_touch(struct tp_dispatch *tp, struct tp_touch *t)
145 {
146         if (t->state == TOUCH_NONE)
147                 return;
148
149         t->dirty = true;
150         t->is_pointer = false;
151         t->state = TOUCH_END;
152         t->pinned.is_pinned = false;
153         assert(tp->nfingers_down >= 1);
154         tp->nfingers_down--;
155         tp->queued |= TOUCHPAD_EVENT_MOTION;
156 }
157
158 static double
159 tp_estimate_delta(int x0, int x1, int x2, int x3)
160 {
161         return (x0 + x1 - x2 - x3) / 4;
162 }
163
164 void
165 tp_get_delta(struct tp_touch *t, double *dx, double *dy)
166 {
167         if (t->history.count < 4) {
168                 *dx = 0;
169                 *dy = 0;
170                 return;
171         }
172
173         *dx = tp_estimate_delta(tp_motion_history_offset(t, 0)->x,
174                                 tp_motion_history_offset(t, 1)->x,
175                                 tp_motion_history_offset(t, 2)->x,
176                                 tp_motion_history_offset(t, 3)->x);
177         *dy = tp_estimate_delta(tp_motion_history_offset(t, 0)->y,
178                                 tp_motion_history_offset(t, 1)->y,
179                                 tp_motion_history_offset(t, 2)->y,
180                                 tp_motion_history_offset(t, 3)->y);
181 }
182
183 static void
184 tp_process_absolute(struct tp_dispatch *tp,
185                     const struct input_event *e,
186                     uint64_t time)
187 {
188         struct tp_touch *t = tp_current_touch(tp);
189
190         switch(e->code) {
191         case ABS_MT_POSITION_X:
192                 t->x = e->value;
193                 t->millis = time;
194                 t->dirty = true;
195                 tp->queued |= TOUCHPAD_EVENT_MOTION;
196                 break;
197         case ABS_MT_POSITION_Y:
198                 t->y = e->value;
199                 t->millis = time;
200                 t->dirty = true;
201                 tp->queued |= TOUCHPAD_EVENT_MOTION;
202                 break;
203         case ABS_MT_SLOT:
204                 tp->slot = e->value;
205                 break;
206         case ABS_MT_TRACKING_ID:
207                 t->millis = time;
208                 if (e->value != -1)
209                         tp_begin_touch(tp, t);
210                 else
211                         tp_end_touch(tp, t);
212         }
213 }
214
215 static void
216 tp_process_absolute_st(struct tp_dispatch *tp,
217                        const struct input_event *e,
218                        uint64_t time)
219 {
220         struct tp_touch *t = tp_current_touch(tp);
221
222         switch(e->code) {
223         case ABS_X:
224                 t->x = e->value;
225                 t->millis = time;
226                 t->dirty = true;
227                 tp->queued |= TOUCHPAD_EVENT_MOTION;
228                 break;
229         case ABS_Y:
230                 t->y = e->value;
231                 t->millis = time;
232                 t->dirty = true;
233                 tp->queued |= TOUCHPAD_EVENT_MOTION;
234                 break;
235         }
236 }
237
238 static void
239 tp_process_fake_touch(struct tp_dispatch *tp,
240                       const struct input_event *e,
241                       uint64_t time)
242 {
243         struct tp_touch *t;
244         unsigned int fake_touches;
245         unsigned int nfake_touches;
246         unsigned int i;
247         unsigned int shift;
248
249         if (e->code != BTN_TOUCH &&
250             (e->code < BTN_TOOL_DOUBLETAP || e->code > BTN_TOOL_QUADTAP))
251                 return;
252
253         shift = e->code == BTN_TOUCH ? 0 : (e->code - BTN_TOOL_DOUBLETAP + 1);
254
255         if (e->value)
256                 tp->fake_touches |= 1 << shift;
257         else
258                 tp->fake_touches &= ~(0x1 << shift);
259
260         fake_touches = tp->fake_touches;
261         nfake_touches = 0;
262         while (fake_touches) {
263                 nfake_touches++;
264                 fake_touches >>= 1;
265         }
266
267         for (i = 0; i < tp->ntouches; i++) {
268                 t = tp_get_touch(tp, i);
269                 if (i >= nfake_touches) {
270                         if (t->state != TOUCH_NONE) {
271                                 tp_end_touch(tp, t);
272                                 t->millis = time;
273                         }
274                 } else if (t->state != TOUCH_UPDATE &&
275                            t->state != TOUCH_BEGIN) {
276                         t->state = TOUCH_NONE;
277                         tp_begin_touch(tp, t);
278                         t->millis = time;
279                         t->fake =true;
280                 }
281         }
282
283         assert(tp->nfingers_down == nfake_touches);
284 }
285
286 static void
287 tp_process_key(struct tp_dispatch *tp,
288                const struct input_event *e,
289                uint64_t time)
290 {
291         switch (e->code) {
292                 case BTN_LEFT:
293                 case BTN_MIDDLE:
294                 case BTN_RIGHT:
295                         tp_process_button(tp, e, time);
296                         break;
297                 case BTN_TOUCH:
298                 case BTN_TOOL_DOUBLETAP:
299                 case BTN_TOOL_TRIPLETAP:
300                 case BTN_TOOL_QUADTAP:
301                         if (!tp->has_mt)
302                                 tp_process_fake_touch(tp, e, time);
303                         break;
304         }
305 }
306
307 static void
308 tp_unpin_finger(struct tp_dispatch *tp, struct tp_touch *t)
309 {
310         unsigned int xdist, ydist;
311
312         if (!t->pinned.is_pinned)
313                 return;
314
315         xdist = abs(t->x - t->pinned.center_x);
316         ydist = abs(t->y - t->pinned.center_y);
317
318         if (xdist * xdist + ydist * ydist >=
319                         tp->buttons.motion_dist * tp->buttons.motion_dist) {
320                 t->pinned.is_pinned = false;
321                 tp_set_pointer(tp, t);
322         }
323 }
324
325 static void
326 tp_pin_fingers(struct tp_dispatch *tp)
327 {
328         struct tp_touch *t;
329
330         tp_for_each_touch(tp, t) {
331                 t->is_pointer = false;
332                 t->pinned.is_pinned = true;
333                 t->pinned.center_x = t->x;
334                 t->pinned.center_y = t->y;
335         }
336 }
337
338 static int
339 tp_touch_active(struct tp_dispatch *tp, struct tp_touch *t)
340 {
341         return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) &&
342                 !t->pinned.is_pinned && tp_button_touch_active(tp, t);
343 }
344
345 void
346 tp_set_pointer(struct tp_dispatch *tp, struct tp_touch *t)
347 {
348         struct tp_touch *tmp = NULL;
349
350         /* Only set the touch as pointer if we don't have one yet */
351         tp_for_each_touch(tp, tmp) {
352                 if (tmp->is_pointer)
353                         return;
354         }
355
356         if (tp_touch_active(tp, t))
357                 t->is_pointer = true;
358 }
359
360 static void
361 tp_process_state(struct tp_dispatch *tp, uint64_t time)
362 {
363         struct tp_touch *t;
364         struct tp_touch *first = tp_get_touch(tp, 0);
365
366         tp_for_each_touch(tp, t) {
367                 if (!tp->has_mt && t != first && first->fake) {
368                         t->x = first->x;
369                         t->y = first->y;
370                         if (!t->dirty)
371                                 t->dirty = first->dirty;
372                 } else if (!t->dirty)
373                         continue;
374
375                 tp_motion_hysteresis(tp, t);
376                 tp_motion_history_push(t);
377
378                 tp_unpin_finger(tp, t);
379         }
380
381         tp_button_handle_state(tp, time);
382
383         /*
384          * We have a physical button down event on a clickpad. To avoid
385          * spurious pointer moves by the clicking finger we pin all fingers.
386          * We unpin fingers when they move more then a certain threshold to
387          * to allow drag and drop.
388          */
389         if ((tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS) &&
390             tp->buttons.is_clickpad)
391                 tp_pin_fingers(tp);
392 }
393
394 static void
395 tp_post_process_state(struct tp_dispatch *tp, uint64_t time)
396 {
397         struct tp_touch *t;
398
399         tp_for_each_touch(tp, t) {
400                 if (!t->dirty)
401                         continue;
402
403                 if (t->state == TOUCH_END) {
404                         t->state = TOUCH_NONE;
405                         t->fake = false;
406                 } else if (t->state == TOUCH_BEGIN)
407                         t->state = TOUCH_UPDATE;
408
409                 t->dirty = false;
410         }
411
412         tp->buttons.old_state = tp->buttons.state;
413
414         tp->queued = TOUCHPAD_EVENT_NONE;
415 }
416
417 static void
418 tp_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
419 {
420         struct tp_touch *t;
421         int nchanged = 0;
422         double dx = 0, dy =0;
423         double tmpx, tmpy;
424
425         tp_for_each_touch(tp, t) {
426                 if (tp_touch_active(tp, t) && t->dirty) {
427                         nchanged++;
428                         tp_get_delta(t, &tmpx, &tmpy);
429
430                         dx += tmpx;
431                         dy += tmpy;
432                 }
433                 /* Stop spurious MOTION events at the end of scrolling */
434                 t->is_pointer = false;
435         }
436
437         if (nchanged == 0)
438                 return;
439
440         dx /= nchanged;
441         dy /= nchanged;
442
443         tp_filter_motion(tp, &dx, &dy, time);
444
445         /* Require at least five px scrolling to start */
446         if (dy <= -5.0 || dy >= 5.0)
447                 tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
448
449         if (dx <= -5.0 || dx >= 5.0)
450                 tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
451
452         if (dy != 0.0 &&
453             (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))) {
454                 pointer_notify_axis(&tp->device->base,
455                                     time,
456                                     LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
457                                     dy);
458         }
459
460         if (dx != 0.0 &&
461             (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))) {
462                 pointer_notify_axis(&tp->device->base,
463                                     time,
464                                     LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
465                                     dx);
466         }
467 }
468
469 static void
470 tp_stop_scroll_events(struct tp_dispatch *tp, uint64_t time)
471 {
472         /* terminate scrolling with a zero scroll event */
473         if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
474                 pointer_notify_axis(&tp->device->base,
475                                     time,
476                                     LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
477                                     0);
478         if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
479                 pointer_notify_axis(&tp->device->base,
480                                     time,
481                                     LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
482                                     0);
483
484         tp->scroll.direction = 0;
485 }
486
487 static int
488 tp_post_scroll_events(struct tp_dispatch *tp, uint64_t time)
489 {
490         struct tp_touch *t;
491         int nfingers_down = 0;
492
493         /* Only count active touches for 2 finger scrolling */
494         tp_for_each_touch(tp, t) {
495                 if (tp_touch_active(tp, t))
496                         nfingers_down++;
497         }
498
499         if (nfingers_down != 2) {
500                 tp_stop_scroll_events(tp, time);
501                 return 0;
502         }
503
504         tp_post_twofinger_scroll(tp, time);
505         return 1;
506 }
507
508 static void
509 tp_post_events(struct tp_dispatch *tp, uint64_t time)
510 {
511         struct tp_touch *t = tp_current_touch(tp);
512         double dx, dy;
513         int consumed = 0;
514
515         consumed |= tp_tap_handle_state(tp, time);
516         consumed |= tp_post_button_events(tp, time);
517
518         if (consumed) {
519                 tp_stop_scroll_events(tp, time);
520                 return;
521         }
522
523         if (tp_post_scroll_events(tp, time) != 0)
524                 return;
525
526         if (t->history.count >= TOUCHPAD_MIN_SAMPLES) {
527                 if (!t->is_pointer) {
528                         tp_for_each_touch(tp, t) {
529                                 if (t->is_pointer)
530                                         break;
531                         }
532                 }
533
534                 if (!t->is_pointer)
535                         return;
536
537                 tp_get_delta(t, &dx, &dy);
538                 tp_filter_motion(tp, &dx, &dy, time);
539
540                 if (dx != 0.0 || dy != 0.0)
541                         pointer_notify_motion(&tp->device->base, time, dx, dy);
542         }
543 }
544
545 static void
546 tp_process(struct evdev_dispatch *dispatch,
547            struct evdev_device *device,
548            struct input_event *e,
549            uint64_t time)
550 {
551         struct tp_dispatch *tp =
552                 (struct tp_dispatch *)dispatch;
553
554         switch (e->type) {
555         case EV_ABS:
556                 if (tp->has_mt)
557                         tp_process_absolute(tp, e, time);
558                 else
559                         tp_process_absolute_st(tp, e, time);
560                 break;
561         case EV_KEY:
562                 tp_process_key(tp, e, time);
563                 break;
564         case EV_SYN:
565                 tp_process_state(tp, time);
566                 tp_post_events(tp, time);
567                 tp_post_process_state(tp, time);
568                 break;
569         }
570 }
571
572 static void
573 tp_destroy(struct evdev_dispatch *dispatch)
574 {
575         struct tp_dispatch *tp =
576                 (struct tp_dispatch*)dispatch;
577
578         tp_destroy_tap(tp);
579         tp_destroy_buttons(tp);
580
581         filter_destroy(tp->filter);
582         free(tp->touches);
583         free(tp);
584 }
585
586 static struct evdev_dispatch_interface tp_interface = {
587         tp_process,
588         tp_destroy
589 };
590
591 static void
592 tp_init_touch(struct tp_dispatch *tp,
593               struct tp_touch *t)
594 {
595         t->tp = tp;
596 }
597
598 static int
599 tp_init_slots(struct tp_dispatch *tp,
600               struct evdev_device *device)
601 {
602         size_t i;
603         const struct input_absinfo *absinfo;
604
605         absinfo = libevdev_get_abs_info(device->evdev, ABS_MT_SLOT);
606         if (absinfo) {
607                 tp->ntouches = absinfo->maximum + 1;
608                 tp->slot = absinfo->value;
609                 tp->has_mt = true;
610         } else {
611                 struct map {
612                         unsigned int code;
613                         int ntouches;
614                 } max_touches[] = {
615                         { BTN_TOOL_QUINTTAP, 5 },
616                         { BTN_TOOL_QUADTAP, 4 },
617                         { BTN_TOOL_TRIPLETAP, 3 },
618                         { BTN_TOOL_DOUBLETAP, 2 },
619                 };
620                 struct map *m;
621
622                 tp->slot = 0;
623                 tp->has_mt = false;
624                 tp->ntouches = 1;
625
626                 ARRAY_FOR_EACH(max_touches, m) {
627                         if (libevdev_has_event_code(device->evdev,
628                                                     EV_KEY,
629                                                     m->code)) {
630                                 tp->ntouches = m->ntouches;
631                                 break;
632                         }
633                 }
634         }
635         tp->touches = calloc(tp->ntouches,
636                              sizeof(struct tp_touch));
637         if (!tp->touches)
638                 return -1;
639
640         for (i = 0; i < tp->ntouches; i++)
641                 tp_init_touch(tp, &tp->touches[i]);
642
643         return 0;
644 }
645
646 static int
647 tp_init_accel(struct tp_dispatch *tp, double diagonal)
648 {
649         struct motion_filter *accel;
650         int res_x, res_y;
651
652         if (tp->has_mt) {
653                 res_x = libevdev_get_abs_resolution(tp->device->evdev,
654                                                     ABS_MT_POSITION_X);
655                 res_y = libevdev_get_abs_resolution(tp->device->evdev,
656                                                     ABS_MT_POSITION_Y);
657         } else {
658                 res_x = libevdev_get_abs_resolution(tp->device->evdev,
659                                                     ABS_X);
660                 res_y = libevdev_get_abs_resolution(tp->device->evdev,
661                                                     ABS_Y);
662         }
663
664         /*
665          * Not all touchpads report the same amount of units/mm (resolution).
666          * Normalize motion events to a resolution of 15.74 units/mm
667          * (== 400 dpi) as base (unaccelerated) speed. This also evens out any
668          * differences in x and y resolution, so that a circle on the
669          * touchpad does not turn into an elipse on the screen.
670          *
671          * We pick 400dpi as thats one of the many default resolutions
672          * for USB mice, so we end up with a similar base speed on the device.
673          */
674         if (res_x > 1 && res_y > 1) {
675                 tp->accel.x_scale_coeff = (400/25.4) / res_x;
676                 tp->accel.y_scale_coeff = (400/25.4) / res_y;
677         } else {
678         /*
679          * For touchpads where the driver does not provide resolution, fall
680          * back to scaling motion events based on the diagonal size in units.
681          */
682                 tp->accel.x_scale_coeff = DEFAULT_ACCEL_NUMERATOR / diagonal;
683                 tp->accel.y_scale_coeff = DEFAULT_ACCEL_NUMERATOR / diagonal;
684         }
685
686         accel = create_pointer_accelator_filter(
687                         pointer_accel_profile_smooth_simple);
688         if (accel == NULL)
689                 return -1;
690
691         tp->filter = accel;
692
693         return 0;
694 }
695
696 static int
697 tp_init_scroll(struct tp_dispatch *tp)
698 {
699         tp->scroll.direction = 0;
700
701         return 0;
702 }
703
704 static int
705 tp_init(struct tp_dispatch *tp,
706         struct evdev_device *device)
707 {
708         int width, height;
709         double diagonal;
710
711         tp->base.interface = &tp_interface;
712         tp->device = device;
713
714         if (tp_init_slots(tp, device) != 0)
715                 return -1;
716
717         width = abs(device->abs.absinfo_x->maximum -
718                     device->abs.absinfo_x->minimum);
719         height = abs(device->abs.absinfo_y->maximum -
720                      device->abs.absinfo_y->minimum);
721         diagonal = sqrt(width*width + height*height);
722
723         tp->hysteresis.margin_x =
724                 diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
725         tp->hysteresis.margin_y =
726                 diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
727
728         if (tp_init_scroll(tp) != 0)
729                 return -1;
730
731         if (tp_init_accel(tp, diagonal) != 0)
732                 return -1;
733
734         if (tp_init_tap(tp) != 0)
735                 return -1;
736
737         if (tp_init_buttons(tp, device) != 0)
738                 return -1;
739
740         return 0;
741 }
742
743 struct evdev_dispatch *
744 evdev_mt_touchpad_create(struct evdev_device *device)
745 {
746         struct tp_dispatch *tp;
747
748         tp = zalloc(sizeof *tp);
749         if (!tp)
750                 return NULL;
751
752         if (tp_init(tp, device) != 0) {
753                 tp_destroy(&tp->base);
754                 return NULL;
755         }
756
757         return  &tp->base;
758 }