Commit 8cde8100 authored by Henrik Rydberg's avatar Henrik Rydberg

input: mt: Collect slots initialization code

The MT slots devices all follow the same initialization pattern
of creating slots and hinting about buffer size. Let drivers call
an initialization function instead, and make sure it can be called
repeatedly without side effects.
Signed-off-by: default avatarHenrik Rydberg <rydberg@euromail.se>
parent 47c78e89
...@@ -29,7 +29,6 @@ MODULE_LICENSE("GPL"); ...@@ -29,7 +29,6 @@ MODULE_LICENSE("GPL");
#define MAX_SLOTS 60 #define MAX_SLOTS 60
#define MAX_TRKID USHRT_MAX #define MAX_TRKID USHRT_MAX
#define MAX_EVENTS 360
/* estimated signal-to-noise ratios */ /* estimated signal-to-noise ratios */
#define SN_MOVE 2048 #define SN_MOVE 2048
...@@ -123,9 +122,7 @@ static int mmm_input_mapping(struct hid_device *hdev, struct hid_input *hi, ...@@ -123,9 +122,7 @@ static int mmm_input_mapping(struct hid_device *hdev, struct hid_input *hi,
EV_ABS, ABS_MT_TRACKING_ID); EV_ABS, ABS_MT_TRACKING_ID);
input_set_abs_params(hi->input, ABS_MT_TRACKING_ID, input_set_abs_params(hi->input, ABS_MT_TRACKING_ID,
0, MAX_TRKID, 0, 0); 0, MAX_TRKID, 0, 0);
if (!hi->input->mt) input_mt_init_slots(hi->input, MAX_SLOTS);
input_mt_create_slots(hi->input, MAX_SLOTS);
input_set_events_per_packet(hi->input, MAX_EVENTS);
return 1; return 1;
} }
/* let hid-input decide for the others */ /* let hid-input decide for the others */
......
...@@ -12,20 +12,25 @@ ...@@ -12,20 +12,25 @@
#include <linux/slab.h> #include <linux/slab.h>
/** /**
* input_mt_create_slots() - create MT input slots * input_mt_init_slots() - initialize MT input slots
* @dev: input device supporting MT events and finger tracking * @dev: input device supporting MT events and finger tracking
* @num_slots: number of slots used by the device * @num_slots: number of slots used by the device
* *
* This function allocates all necessary memory for MT slot handling in the * This function allocates all necessary memory for MT slot handling
* input device, and adds ABS_MT_SLOT to the device capabilities. All slots * in the input device, adds ABS_MT_SLOT to the device capabilities
* are initially marked as unused by setting ABS_MT_TRACKING_ID to -1. * and sets up appropriate event buffers. All slots are initially
* marked as unused by setting ABS_MT_TRACKING_ID to -1. May be called
* repeatedly. Returns -EINVAL if attempting to reinitialize with a
* different number of slots.
*/ */
int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots) int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots)
{ {
int i; int i;
if (!num_slots) if (!num_slots)
return 0; return 0;
if (dev->mt)
return dev->mtsize != num_slots ? -EINVAL : 0;
dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL); dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL);
if (!dev->mt) if (!dev->mt)
...@@ -33,6 +38,7 @@ int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots) ...@@ -33,6 +38,7 @@ int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots)
dev->mtsize = num_slots; dev->mtsize = num_slots;
input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0); input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0);
input_set_events_per_packet(dev, 6 * num_slots);
/* Mark slots as 'unused' */ /* Mark slots as 'unused' */
for (i = 0; i < num_slots; i++) for (i = 0; i < num_slots; i++)
...@@ -40,7 +46,7 @@ int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots) ...@@ -40,7 +46,7 @@ int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots)
return 0; return 0;
} }
EXPORT_SYMBOL(input_mt_create_slots); EXPORT_SYMBOL(input_mt_init_slots);
/** /**
* input_mt_destroy_slots() - frees the MT slots of the input device * input_mt_destroy_slots() - frees the MT slots of the input device
...@@ -54,5 +60,6 @@ void input_mt_destroy_slots(struct input_dev *dev) ...@@ -54,5 +60,6 @@ void input_mt_destroy_slots(struct input_dev *dev)
kfree(dev->mt); kfree(dev->mt);
dev->mt = NULL; dev->mt = NULL;
dev->mtsize = 0; dev->mtsize = 0;
dev->slot = 0;
} }
EXPORT_SYMBOL(input_mt_destroy_slots); EXPORT_SYMBOL(input_mt_destroy_slots);
...@@ -407,8 +407,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu ...@@ -407,8 +407,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
goto exit; goto exit;
if (test_bit(ABS_MT_SLOT, dev->absbit)) { if (test_bit(ABS_MT_SLOT, dev->absbit)) {
int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1; int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
input_mt_create_slots(dev, nslot); input_mt_init_slots(dev, nslot);
input_set_events_per_packet(dev, 6 * nslot);
} else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
input_set_events_per_packet(dev, 60); input_set_events_per_packet(dev, 60);
} }
......
...@@ -1273,7 +1273,7 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev, ...@@ -1273,7 +1273,7 @@ void wacom_setup_input_capabilities(struct input_dev *input_dev,
__set_bit(BTN_TOOL_FINGER, input_dev->keybit); __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
__set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
input_mt_create_slots(input_dev, 2); input_mt_init_slots(input_dev, 2);
input_set_abs_params(input_dev, ABS_MT_POSITION_X, input_set_abs_params(input_dev, ABS_MT_POSITION_X,
0, features->x_max, 0, features->x_max,
features->x_fuzz, 0); features->x_fuzz, 0);
......
...@@ -318,7 +318,7 @@ static int w8001_setup(struct w8001 *w8001) ...@@ -318,7 +318,7 @@ static int w8001_setup(struct w8001 *w8001)
case 5: case 5:
w8001->pktlen = W8001_PKTLEN_TOUCH2FG; w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
input_mt_create_slots(dev, 2); input_mt_init_slots(dev, 2);
input_set_abs_params(dev, ABS_MT_TRACKING_ID, input_set_abs_params(dev, ABS_MT_TRACKING_ID,
0, MAX_TRACKING_ID, 0, 0); 0, MAX_TRACKING_ID, 0, 0);
input_set_abs_params(dev, ABS_MT_POSITION_X, input_set_abs_params(dev, ABS_MT_POSITION_X,
......
...@@ -33,7 +33,7 @@ static inline int input_mt_get_value(const struct input_mt_slot *slot, ...@@ -33,7 +33,7 @@ static inline int input_mt_get_value(const struct input_mt_slot *slot,
return slot->abs[code - ABS_MT_FIRST]; return slot->abs[code - ABS_MT_FIRST];
} }
int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots); int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots);
void input_mt_destroy_slots(struct input_dev *dev); void input_mt_destroy_slots(struct input_dev *dev);
static inline void input_mt_slot(struct input_dev *dev, int slot) static inline void input_mt_slot(struct input_dev *dev, int slot)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment