Commit | Line | Data |
---|---|---|
47c78e89 HR |
1 | /* |
2 | * Input Multitouch Library | |
3 | * | |
4 | * Copyright (c) 2008-2010 Henrik Rydberg | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License version 2 as published by | |
8 | * the Free Software Foundation. | |
9 | */ | |
10 | ||
11 | #include <linux/input/mt.h> | |
12 | #include <linux/slab.h> | |
13 | ||
14 | /** | |
8cde8100 | 15 | * input_mt_init_slots() - initialize MT input slots |
47c78e89 HR |
16 | * @dev: input device supporting MT events and finger tracking |
17 | * @num_slots: number of slots used by the device | |
18 | * | |
8cde8100 HR |
19 | * This function allocates all necessary memory for MT slot handling |
20 | * in the input device, adds ABS_MT_SLOT to the device capabilities | |
21 | * and sets up appropriate event buffers. All slots are initially | |
22 | * marked as unused by setting ABS_MT_TRACKING_ID to -1. May be called | |
23 | * repeatedly. Returns -EINVAL if attempting to reinitialize with a | |
24 | * different number of slots. | |
47c78e89 | 25 | */ |
8cde8100 | 26 | int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots) |
47c78e89 HR |
27 | { |
28 | int i; | |
29 | ||
30 | if (!num_slots) | |
31 | return 0; | |
8cde8100 HR |
32 | if (dev->mt) |
33 | return dev->mtsize != num_slots ? -EINVAL : 0; | |
47c78e89 HR |
34 | |
35 | dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL); | |
36 | if (!dev->mt) | |
37 | return -ENOMEM; | |
38 | ||
39 | dev->mtsize = num_slots; | |
40 | input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0); | |
8cde8100 | 41 | input_set_events_per_packet(dev, 6 * num_slots); |
47c78e89 HR |
42 | |
43 | /* Mark slots as 'unused' */ | |
44 | for (i = 0; i < num_slots; i++) | |
45 | input_mt_set_value(&dev->mt[i], ABS_MT_TRACKING_ID, -1); | |
46 | ||
47 | return 0; | |
48 | } | |
8cde8100 | 49 | EXPORT_SYMBOL(input_mt_init_slots); |
47c78e89 HR |
50 | |
51 | /** | |
52 | * input_mt_destroy_slots() - frees the MT slots of the input device | |
53 | * @dev: input device with allocated MT slots | |
54 | * | |
55 | * This function is only needed in error path as the input core will | |
56 | * automatically free the MT slots when the device is destroyed. | |
57 | */ | |
58 | void input_mt_destroy_slots(struct input_dev *dev) | |
59 | { | |
60 | kfree(dev->mt); | |
61 | dev->mt = NULL; | |
62 | dev->mtsize = 0; | |
8cde8100 | 63 | dev->slot = 0; |
47c78e89 HR |
64 | } |
65 | EXPORT_SYMBOL(input_mt_destroy_slots); |