Merge tag 'meminit-v5.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
[linux-block.git] / include / linux / input / mt.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
47c78e89
HR
2#ifndef _INPUT_MT_H
3#define _INPUT_MT_H
4
5/*
6 * Input Multitouch Library
7 *
8 * Copyright (c) 2010 Henrik Rydberg
47c78e89
HR
9 */
10
11#include <linux/input.h>
12
c5f4dec1
HR
13#define TRKID_MAX 0xffff
14
55e49089
HR
15#define INPUT_MT_POINTER 0x0001 /* pointer device, e.g. trackpad */
16#define INPUT_MT_DIRECT 0x0002 /* direct device, e.g. touchscreen */
17#define INPUT_MT_DROP_UNUSED 0x0004 /* drop contacts not seen in frame */
7c1a8789 18#define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */
a0ef6a34 19#define INPUT_MT_SEMI_MT 0x0010 /* semi-mt device, finger count handled manually */
7c1a8789 20
47c78e89
HR
21/**
22 * struct input_mt_slot - represents the state of an input MT slot
23 * @abs: holds current values of ABS_MT axes for this slot
55e49089 24 * @frame: last frame at which input_mt_report_slot_state() was called
17a465a7 25 * @key: optional driver designation of this slot
47c78e89
HR
26 */
27struct input_mt_slot {
28 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
55e49089 29 unsigned int frame;
17a465a7 30 unsigned int key;
47c78e89
HR
31};
32
8d18fba2
HR
33/**
34 * struct input_mt - state of tracked contacts
35 * @trkid: stores MT tracking ID for the next contact
36 * @num_slots: number of MT slots the device uses
37 * @slot: MT slot currently being transmitted
b4adbbef 38 * @flags: input_mt operation flags
55e49089 39 * @frame: increases every time input_mt_sync_frame() is called
7c1a8789 40 * @red: reduced cost matrix for in-kernel tracking
8d18fba2
HR
41 * @slots: array of slots holding current values of tracked contacts
42 */
43struct input_mt {
44 int trkid;
45 int num_slots;
46 int slot;
b4adbbef 47 unsigned int flags;
55e49089 48 unsigned int frame;
7c1a8789 49 int *red;
8d18fba2
HR
50 struct input_mt_slot slots[];
51};
52
47c78e89
HR
53static inline void input_mt_set_value(struct input_mt_slot *slot,
54 unsigned code, int value)
55{
56 slot->abs[code - ABS_MT_FIRST] = value;
57}
58
59static inline int input_mt_get_value(const struct input_mt_slot *slot,
60 unsigned code)
61{
62 return slot->abs[code - ABS_MT_FIRST];
63}
64
7c1a8789
HR
65static inline bool input_mt_is_active(const struct input_mt_slot *slot)
66{
67 return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0;
68}
69
29807d1e
BT
70static inline bool input_mt_is_used(const struct input_mt *mt,
71 const struct input_mt_slot *slot)
72{
73 return slot->frame == mt->frame;
74}
75
b4adbbef
HR
76int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
77 unsigned int flags);
47c78e89
HR
78void input_mt_destroy_slots(struct input_dev *dev);
79
8d18fba2 80static inline int input_mt_new_trkid(struct input_mt *mt)
c5f4dec1 81{
8d18fba2 82 return mt->trkid++ & TRKID_MAX;
c5f4dec1
HR
83}
84
47c78e89
HR
85static inline void input_mt_slot(struct input_dev *dev, int slot)
86{
87 input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
88}
89
b89529a1
HR
90static inline bool input_is_mt_value(int axis)
91{
92 return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
93}
94
80b4895a
JB
95static inline bool input_is_mt_axis(int axis)
96{
b89529a1 97 return axis == ABS_MT_SLOT || input_is_mt_value(axis);
80b4895a
JB
98}
99
bf6247a7 100bool input_mt_report_slot_state(struct input_dev *dev,
c5f4dec1
HR
101 unsigned int tool_type, bool active);
102
103void input_mt_report_finger_count(struct input_dev *dev, int count);
104void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
f8ec8949 105void input_mt_drop_unused(struct input_dev *dev);
c5f4dec1 106
55e49089
HR
107void input_mt_sync_frame(struct input_dev *dev);
108
7c1a8789
HR
109/**
110 * struct input_mt_pos - contact position
111 * @x: horizontal coordinate
112 * @y: vertical coordinate
113 */
114struct input_mt_pos {
115 s16 x, y;
116};
117
118int input_mt_assign_slots(struct input_dev *dev, int *slots,
448c7f38
HR
119 const struct input_mt_pos *pos, int num_pos,
120 int dmax);
7c1a8789 121
17a465a7
HR
122int input_mt_get_slot_by_key(struct input_dev *dev, int key);
123
47c78e89 124#endif