diff options
Diffstat (limited to 'mtdev/caps.c')
| -rw-r--r-- | mtdev/caps.c | 175 |
1 files changed, 0 insertions, 175 deletions
diff --git a/mtdev/caps.c b/mtdev/caps.c deleted file mode 100644 index 069816e..0000000 --- a/mtdev/caps.c +++ /dev/null | |||
| @@ -1,175 +0,0 @@ | |||
| 1 | /*************************************************************************** | ||
| 2 | * | ||
| 3 | * Multitouch X driver | ||
| 4 | * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | * | ||
| 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. | ||
| 10 | * | ||
| 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. | ||
| 15 | * | ||
| 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 | ||
| 19 | * | ||
| 20 | **************************************************************************/ | ||
| 21 | |||
| 22 | #include "mtdev-caps.h" | ||
| 23 | #include "mtbit.h" | ||
| 24 | |||
| 25 | #define SETABS(c, x, map, key, fd) \ | ||
| 26 | (c->has_##x = getbit(map, key) && getabs(&c->x, key, fd)) | ||
| 27 | |||
| 28 | #define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") | ||
| 29 | |||
| 30 | static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */ | ||
| 31 | static const int SN_WIDTH = 100; /* width signal-to-noise ratio */ | ||
| 32 | static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */ | ||
| 33 | |||
| 34 | static const int bits_per_long = 8 * sizeof(long); | ||
| 35 | |||
| 36 | static inline int nlongs(int nbit) | ||
| 37 | { | ||
| 38 | return (nbit + bits_per_long - 1) / bits_per_long; | ||
| 39 | } | ||
| 40 | |||
| 41 | static inline int getbit(const unsigned long *map, int key) | ||
| 42 | { | ||
| 43 | return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; | ||
| 44 | } | ||
| 45 | |||
| 46 | static int getabs(struct input_absinfo *abs, int key, int fd) | ||
| 47 | { | ||
| 48 | int rc; | ||
| 49 | SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs)); | ||
| 50 | return rc >= 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | static int has_mt_data(const struct Capabilities *cap) | ||
| 54 | { | ||
| 55 | return cap->has_abs[BIT_POSITION_X] && cap->has_abs[BIT_POSITION_Y]; | ||
| 56 | } | ||
| 57 | |||
| 58 | static int has_integrated_button(const struct Capabilities *cap) | ||
| 59 | { | ||
| 60 | static const int bcm5974_vmask_ibt = 1; | ||
| 61 | if (strcmp(cap->devname, "bcm5974")) | ||
| 62 | return 0; | ||
| 63 | return cap->devid.version & bcm5974_vmask_ibt; | ||
| 64 | } | ||
| 65 | |||
| 66 | static void default_fuzz(struct Capabilities *cap, unsigned int code, int sn) | ||
| 67 | { | ||
| 68 | int bit = abs2mt(code); | ||
| 69 | if (cap->has_abs[bit] && cap->abs[bit].fuzz == 0) | ||
| 70 | cap->abs[bit].fuzz = | ||
| 71 | (cap->abs[bit].maximum - cap->abs[bit].minimum) / sn; | ||
| 72 | } | ||
| 73 | |||
| 74 | int read_capabilities(struct Capabilities *cap, int fd) | ||
| 75 | { | ||
| 76 | unsigned long evbits[nlongs(EV_MAX)]; | ||
| 77 | unsigned long absbits[nlongs(ABS_MAX)]; | ||
| 78 | unsigned long keybits[nlongs(KEY_MAX)]; | ||
| 79 | int rc, i; | ||
| 80 | |||
| 81 | memset(cap, 0, sizeof(struct Capabilities)); | ||
| 82 | |||
| 83 | SYSCALL(rc = ioctl(fd, EVIOCGID, &cap->devid)); | ||
| 84 | if (rc < 0) | ||
| 85 | return rc; | ||
| 86 | SYSCALL(rc = ioctl(fd, EVIOCGNAME(sizeof(cap->devname)), cap->devname)); | ||
| 87 | if (rc < 0) | ||
| 88 | return rc; | ||
| 89 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits)); | ||
| 90 | if (rc < 0) | ||
| 91 | return rc; | ||
| 92 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits)); | ||
| 93 | if (rc < 0) | ||
| 94 | return rc; | ||
| 95 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); | ||
| 96 | if (rc < 0) | ||
| 97 | return rc; | ||
| 98 | |||
| 99 | cap->has_left = getbit(keybits, BTN_LEFT); | ||
| 100 | cap->has_middle = getbit(keybits, BTN_MIDDLE); | ||
| 101 | cap->has_right = getbit(keybits, BTN_RIGHT); | ||
| 102 | |||
| 103 | SETABS(cap, slot, absbits, ABS_MT_SLOT, fd); | ||
| 104 | for (i = 0; i < MT_ABS_SIZE; i++) | ||
| 105 | SETABS(cap, abs[i], absbits, mt2abs(i), fd); | ||
| 106 | |||
| 107 | cap->has_mtdata = has_mt_data(cap); | ||
| 108 | cap->has_ibt = has_integrated_button(cap); | ||
| 109 | |||
| 110 | if (cap->has_abs[BIT_TRACKING_ID]) | ||
| 111 | cap->nullid = cap->abs[BIT_TRACKING_ID].minimum - 1; | ||
| 112 | |||
| 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); | ||
| 120 | |||
| 121 | return 0; | ||
| 122 | } | ||
| 123 | |||
| 124 | int get_cap_xsize(const struct Capabilities *cap) | ||
| 125 | { | ||
| 126 | const struct input_absinfo *x = &cap->abs[BIT_POSITION_X]; | ||
| 127 | return x->maximum - x->minimum; | ||
| 128 | } | ||
| 129 | |||
| 130 | int get_cap_ysize(const struct Capabilities *cap) | ||
| 131 | { | ||
| 132 | const struct input_absinfo *y = &cap->abs[BIT_POSITION_Y]; | ||
| 133 | return y->maximum - y->minimum; | ||
| 134 | } | ||
| 135 | |||
| 136 | int get_cap_wsize(const struct Capabilities *cap) | ||
| 137 | { | ||
| 138 | const struct input_absinfo *w = &cap->abs[BIT_TOUCH_MAJOR]; | ||
| 139 | return w->maximum - w->minimum; | ||
| 140 | } | ||
| 141 | |||
| 142 | int get_cap_xmid(const struct Capabilities *cap) | ||
| 143 | { | ||
| 144 | const struct input_absinfo *x = &cap->abs[BIT_POSITION_X]; | ||
| 145 | return (x->maximum + x->minimum) >> 1; | ||
| 146 | } | ||
| 147 | |||
| 148 | int get_cap_ymid(const struct Capabilities *cap) | ||
| 149 | { | ||
| 150 | const struct input_absinfo *y = &cap->abs[BIT_POSITION_Y]; | ||
| 151 | return (y->maximum + y->minimum) >> 1; | ||
| 152 | } | ||
| 153 | |||
| 154 | void output_capabilities(const struct Capabilities *cap) | ||
| 155 | { | ||
| 156 | char line[1024]; | ||
| 157 | int i; | ||
| 158 | memset(line, 0, sizeof(line)); | ||
| 159 | ADDCAP(line, cap, left); | ||
| 160 | ADDCAP(line, cap, middle); | ||
| 161 | ADDCAP(line, cap, right); | ||
| 162 | ADDCAP(line, cap, mtdata); | ||
| 163 | ADDCAP(line, cap, ibt); | ||
| 164 | xf86Msg(X_INFO, "multitouch: devname: %s\n", cap->devname); | ||
| 165 | xf86Msg(X_INFO, "multitouch: devid: %x %x %x\n", | ||
| 166 | cap->devid.vendor, cap->devid.product, cap->devid.version); | ||
| 167 | xf86Msg(X_INFO, "multitouch: caps:%s\n", line); | ||
| 168 | for (i = 0; i < MT_ABS_SIZE; i++) { | ||
| 169 | if (cap->has_abs[i]) | ||
| 170 | xf86Msg(X_INFO, "multitouch: %d: min: %d max: %d\n", | ||
| 171 | i, | ||
| 172 | cap->abs[i].minimum, | ||
| 173 | cap->abs[i].maximum); | ||
| 174 | } | ||
| 175 | } | ||
