blob: 9e409bb1364214eb07c56934225c19d6da09b3f2 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Henrik Rydberg47c78e82010-11-27 09:16:48 +01002#ifndef _INPUT_MT_H
3#define _INPUT_MT_H
4
5/*
6 * Input Multitouch Library
7 *
8 * Copyright (c) 2010 Henrik Rydberg
Henrik Rydberg47c78e82010-11-27 09:16:48 +01009 */
10
11#include <linux/input.h>
12
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010013#define TRKID_MAX 0xffff
14
Henrik Rydberg55e49082012-08-22 20:43:22 +020015#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 */
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020018#define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */
Henrik Rydberga0ef6a32013-04-07 20:52:22 -070019#define INPUT_MT_SEMI_MT 0x0010 /* semi-mt device, finger count handled manually */
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020020
Henrik Rydberg47c78e82010-11-27 09:16:48 +010021/**
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
Henrik Rydberg55e49082012-08-22 20:43:22 +020024 * @frame: last frame at which input_mt_report_slot_state() was called
Henrik Rydberg17a465a2012-09-01 09:27:20 +020025 * @key: optional driver designation of this slot
Henrik Rydberg47c78e82010-11-27 09:16:48 +010026 */
27struct input_mt_slot {
28 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
Henrik Rydberg55e49082012-08-22 20:43:22 +020029 unsigned int frame;
Henrik Rydberg17a465a2012-09-01 09:27:20 +020030 unsigned int key;
Henrik Rydberg47c78e82010-11-27 09:16:48 +010031};
32
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020033/**
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
Henrik Rydbergb4adbbe2012-08-11 22:07:55 +020038 * @flags: input_mt operation flags
Henrik Rydberg55e49082012-08-22 20:43:22 +020039 * @frame: increases every time input_mt_sync_frame() is called
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020040 * @red: reduced cost matrix for in-kernel tracking
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020041 * @slots: array of slots holding current values of tracked contacts
42 */
43struct input_mt {
44 int trkid;
45 int num_slots;
46 int slot;
Henrik Rydbergb4adbbe2012-08-11 22:07:55 +020047 unsigned int flags;
Henrik Rydberg55e49082012-08-22 20:43:22 +020048 unsigned int frame;
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020049 int *red;
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020050 struct input_mt_slot slots[];
51};
52
Henrik Rydberg47c78e82010-11-27 09:16:48 +010053static 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
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020065static 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
Benjamin Tissoires29807d12012-11-14 16:59:22 +010070static 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
Henrik Rydbergb4adbbe2012-08-11 22:07:55 +020076int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
77 unsigned int flags);
Henrik Rydberg47c78e82010-11-27 09:16:48 +010078void input_mt_destroy_slots(struct input_dev *dev);
79
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020080static inline int input_mt_new_trkid(struct input_mt *mt)
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010081{
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020082 return mt->trkid++ & TRKID_MAX;
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010083}
84
Henrik Rydberg47c78e82010-11-27 09:16:48 +010085static inline void input_mt_slot(struct input_dev *dev, int slot)
86{
87 input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
88}
89
Henrik Rydbergb89529a2012-01-12 19:40:34 +010090static inline bool input_is_mt_value(int axis)
91{
92 return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
93}
94
Jeff Brown80b48952011-04-18 10:08:02 -070095static inline bool input_is_mt_axis(int axis)
96{
Henrik Rydbergb89529a2012-01-12 19:40:34 +010097 return axis == ABS_MT_SLOT || input_is_mt_value(axis);
Jeff Brown80b48952011-04-18 10:08:02 -070098}
99
Dmitry Torokhovbf6247a2018-06-05 10:08:44 -0700100bool input_mt_report_slot_state(struct input_dev *dev,
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +0100101 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);
Henrik Rydbergf8ec8942014-07-25 17:16:42 -0700105void input_mt_drop_unused(struct input_dev *dev);
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +0100106
Henrik Rydberg55e49082012-08-22 20:43:22 +0200107void input_mt_sync_frame(struct input_dev *dev);
108
Henrik Rydberg7c1a8782012-08-12 20:47:05 +0200109/**
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,
Henrik Rydberg448c7f382015-02-01 11:25:14 -0800119 const struct input_mt_pos *pos, int num_pos,
120 int dmax);
Henrik Rydberg7c1a8782012-08-12 20:47:05 +0200121
Henrik Rydberg17a465a2012-09-01 09:27:20 +0200122int input_mt_get_slot_by_key(struct input_dev *dev, int key);
123
Henrik Rydberg47c78e82010-11-27 09:16:48 +0100124#endif