aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/input-mt.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-11-27 03:16:48 -0500
committerHenrik Rydberg <rydberg@euromail.se>2010-12-16 04:39:57 -0500
commit47c78e891323513e9909729b44033e2c6649e2b7 (patch)
tree828e0da90418a890653ef2f0af3cf81714fe5c80 /drivers/input/input-mt.c
parentc8ddb2713c624f432fa5fe3c7ecffcdda46ea0d4 (diff)
input: mt: Break out slots handling
In preparation for common code to handle a larger set of MT slots devices, move the slots handling over to a separate file. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'drivers/input/input-mt.c')
-rw-r--r--drivers/input/input-mt.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
new file mode 100644
index 00000000000..463a4d7d54f
--- /dev/null
+++ b/drivers/input/input-mt.c
@@ -0,0 +1,58 @@
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/**
15 * input_mt_create_slots() - create MT input slots
16 * @dev: input device supporting MT events and finger tracking
17 * @num_slots: number of slots used by the device
18 *
19 * This function allocates all necessary memory for MT slot handling in the
20 * input device, and adds ABS_MT_SLOT to the device capabilities. All slots
21 * are initially marked as unused by setting ABS_MT_TRACKING_ID to -1.
22 */
23int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots)
24{
25 int i;
26
27 if (!num_slots)
28 return 0;
29
30 dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL);
31 if (!dev->mt)
32 return -ENOMEM;
33
34 dev->mtsize = num_slots;
35 input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0);
36
37 /* Mark slots as 'unused' */
38 for (i = 0; i < num_slots; i++)
39 input_mt_set_value(&dev->mt[i], ABS_MT_TRACKING_ID, -1);
40
41 return 0;
42}
43EXPORT_SYMBOL(input_mt_create_slots);
44
45/**
46 * input_mt_destroy_slots() - frees the MT slots of the input device
47 * @dev: input device with allocated MT slots
48 *
49 * This function is only needed in error path as the input core will
50 * automatically free the MT slots when the device is destroyed.
51 */
52void input_mt_destroy_slots(struct input_dev *dev)
53{
54 kfree(dev->mt);
55 dev->mt = NULL;
56 dev->mtsize = 0;
57}
58EXPORT_SYMBOL(input_mt_destroy_slots);