1
/***************************************************************************
4
* Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
**************************************************************************/
22
#include "capabilities.h"
24
#define SETABS(c, x, map, key, fd) \
25
(c->has_##x = getbit(map, key) && getabs(&c->x, key, fd))
27
#define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "")
29
static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */
30
static const int SN_WIDTH = 100; /* width signal-to-noise ratio */
31
static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */
33
static const int bits_per_long = 8 * sizeof(long);
35
static inline int nlongs(int nbit)
37
return (nbit + bits_per_long - 1) / bits_per_long;
40
static inline int getbit(const unsigned long *map, int key)
42
return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01;
45
static int getabs(struct input_absinfo *abs, int key, int fd)
48
SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs));
52
static int has_mt_data(const struct Capabilities *cap)
54
return cap->has_abs[MTDEV_POSITION_X] && cap->has_abs[MTDEV_POSITION_Y];
57
static int has_integrated_button(const struct Capabilities *cap)
59
static const int bcm5974_vmask_ibt = 1;
61
if (cap->devid.vendor == 0x05ac && cap->devid.product == 0x030e)
64
if (strcmp(cap->devname, "bcm5974"))
66
return cap->devid.version & bcm5974_vmask_ibt;
69
static void default_fuzz(struct Capabilities *cap, unsigned int code, int sn)
71
int bit = mtdev_abs2mt(code);
72
if (cap->has_abs[bit] && cap->abs[bit].fuzz == 0)
74
(cap->abs[bit].maximum - cap->abs[bit].minimum) / sn;
77
int read_capabilities(struct Capabilities *cap, int fd)
79
unsigned long evbits[nlongs(EV_MAX)];
80
unsigned long absbits[nlongs(ABS_MAX)];
81
unsigned long keybits[nlongs(KEY_MAX)];
84
memset(cap, 0, sizeof(struct Capabilities));
86
SYSCALL(rc = ioctl(fd, EVIOCGID, &cap->devid));
89
SYSCALL(rc = ioctl(fd, EVIOCGNAME(sizeof(cap->devname)), cap->devname));
92
SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits));
95
SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits));
98
SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits));
102
cap->has_left = getbit(keybits, BTN_LEFT);
103
cap->has_middle = getbit(keybits, BTN_MIDDLE);
104
cap->has_right = getbit(keybits, BTN_RIGHT);
106
SETABS(cap, slot, absbits, ABS_MT_SLOT, fd);
107
for (i = 0; i < MT_ABS_SIZE; i++)
108
SETABS(cap, abs[i], absbits, mtdev_mt2abs(i), fd);
110
cap->has_mtdata = has_mt_data(cap);
111
cap->has_ibt = has_integrated_button(cap);
113
default_fuzz(cap, ABS_MT_POSITION_X, SN_COORD);
114
default_fuzz(cap, ABS_MT_POSITION_Y, SN_COORD);
115
default_fuzz(cap, ABS_MT_TOUCH_MAJOR, SN_WIDTH);
116
default_fuzz(cap, ABS_MT_TOUCH_MINOR, SN_WIDTH);
117
default_fuzz(cap, ABS_MT_WIDTH_MAJOR, SN_WIDTH);
118
default_fuzz(cap, ABS_MT_WIDTH_MINOR, SN_WIDTH);
119
default_fuzz(cap, ABS_MT_ORIENTATION, SN_ORIENT);
124
int get_cap_xsize(const struct Capabilities *cap)
126
const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X];
127
return x->maximum - x->minimum;
130
int get_cap_ysize(const struct Capabilities *cap)
132
const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y];
133
return y->maximum - y->minimum;
136
int get_cap_wsize(const struct Capabilities *cap)
138
const struct input_absinfo *w = &cap->abs[MTDEV_TOUCH_MAJOR];
139
return w->maximum - w->minimum;
142
int get_cap_xmid(const struct Capabilities *cap)
144
const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X];
145
return (x->maximum + x->minimum) >> 1;
148
int get_cap_ymid(const struct Capabilities *cap)
150
const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y];
151
return (y->maximum + y->minimum) >> 1;
154
int get_cap_xflip(const struct Capabilities *cap, int x)
156
const struct input_absinfo *i = &cap->abs[MTDEV_POSITION_X];
157
return i->maximum - (x - i->minimum);
160
int get_cap_yflip(const struct Capabilities *cap, int y)
162
const struct input_absinfo *i = &cap->abs[MTDEV_POSITION_Y];
163
return i->maximum - (y - i->minimum);
166
void output_capabilities(const struct Capabilities *cap)
170
memset(line, 0, sizeof(line));
171
ADDCAP(line, cap, left);
172
ADDCAP(line, cap, middle);
173
ADDCAP(line, cap, right);
174
ADDCAP(line, cap, mtdata);
175
ADDCAP(line, cap, ibt);
176
xf86Msg(X_INFO, "mtrack: devname: %s\n", cap->devname);
177
xf86Msg(X_INFO, "mtrack: devid: %x %x %x\n",
178
cap->devid.vendor, cap->devid.product, cap->devid.version);
179
xf86Msg(X_INFO, "mtrack: caps:%s\n", line);
180
for (i = 0; i < MT_ABS_SIZE; i++) {
182
xf86Msg(X_INFO, "mtrack: %d: min: %d max: %d\n",
185
cap->abs[i].maximum);