diff options
Diffstat (limited to 'drivers/input/input-mt.c')
| -rw-r--r-- | drivers/input/input-mt.c | 58 |
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 000000000000..463a4d7d54f2 --- /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 | */ | ||
| 23 | int 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 | } | ||
| 43 | EXPORT_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 | */ | ||
| 52 | void input_mt_destroy_slots(struct input_dev *dev) | ||
| 53 | { | ||
| 54 | kfree(dev->mt); | ||
| 55 | dev->mt = NULL; | ||
| 56 | dev->mtsize = 0; | ||
| 57 | } | ||
| 58 | EXPORT_SYMBOL(input_mt_destroy_slots); | ||
