diff mbox

[1/2] input: mt: Add method to extract the MT slot state

Message ID 1274788379-11026-2-git-send-email-rydberg@euromail.se (mailing list archive)
State New, archived
Headers show

Commit Message

Henrik Rydberg May 25, 2010, 11:52 a.m. UTC
None
diff mbox

Patch

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 9b6d474..24d1105 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -659,6 +659,37 @@  static int input_default_setkeycode(struct input_dev *dev,
 }
 
 /**
+ * input_mt_get_abs_value - retrieve MT state variables from a device slot
+ * @dev: input device which state is being queried
+ * @code: ABS code to retrieve
+ * @slot: slot to retrieve from
+ *
+ * Return the ABS state of the given MT slot. If code is not an MT
+ * event, the corresponding ABS event is returned.
+ *
+ * This function may be called by anyone interested in extracting the
+ * current MT state. Used by evdev handlers.
+ */
+int input_mt_get_abs_value(struct input_dev *dev, unsigned int code, int slot)
+{
+	unsigned int mtmap = input_mt_abs_map[code];
+	unsigned long flags;
+	int retval;
+
+	spin_lock_irqsave(&dev->event_lock, flags);
+	if (!mtmap)
+		retval = dev->abs[code];
+	else if (slot >= 0 && slot < dev->mtsize)
+		retval = dev->mt[slot].abs[mtmap - 1];
+	else
+		retval = 0;
+	spin_unlock_irqrestore(&dev->event_lock, flags);
+
+	return retval;
+}
+EXPORT_SYMBOL(input_mt_get_abs_value);
+
+/**
  * input_get_keycode - retrieve keycode currently mapped to a given scancode
  * @dev: input device which keymap is being queried
  * @scancode: scancode (or its equivalent for device in question) for which
diff --git a/include/linux/input.h b/include/linux/input.h
index bea6958..03727d6 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -1436,6 +1436,8 @@  static inline void input_mt_slot(struct input_dev *dev, int slot)
 	input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
 }
 
+int input_mt_get_abs_value(struct input_dev *dev, unsigned int code, int slot);
+
 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
 
 static inline void input_set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat)