linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: magicmouse: Implement Multi-touch Protocol B (MT-B)
@ 2012-06-28 19:54 Yufeng Shen
  2012-07-02 10:07 ` Henrik Rydberg
  2012-07-02 18:52 ` Chase Douglas
  0 siblings, 2 replies; 4+ messages in thread
From: Yufeng Shen @ 2012-06-28 19:54 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Henrik Rydberg, linux-kernel, Yufeng Shen,
	Daniel Kurtz, Andrew de los Reyes

The driver for Apple Magic Trackpad/Mouse currently uses
Multi-touch Protocol A (MT-A) to report touch events and uses
ABS_MT_TRACKING_ID to do finger tracking. The fact of the device
being able to track individual finger makes it possible to
report touch events using MT-B. This patch adds the support
for the driver to report MT-B and makes it configurable through
module parameter so that existing codes that are relying on its
MT-A implemtation don't get affected.

Signed-off-by: Yufeng Shen <miletus@chromium.org>
---
 drivers/hid/hid-magicmouse.c |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 40ac665..18d1ea0 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -17,6 +17,7 @@
 #include <linux/device.h>
 #include <linux/hid.h>
 #include <linux/module.h>
+#include <linux/input/mt.h>
 #include <linux/slab.h>
 #include <linux/usb.h>
 
@@ -56,6 +57,10 @@ static bool report_undeciphered;
 module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
 
+static bool use_MTB;
+module_param(use_MTB, bool, 0644);
+MODULE_PARM_DESC(use_MTB, "Whether using MT-B protocol to report touch events");
+
 #define TRACKPAD_REPORT_ID 0x28
 #define MOUSE_REPORT_ID    0x29
 #define DOUBLE_REPORT_ID   0xf7
@@ -275,9 +280,18 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
 	} else if (msc->single_touch_id == id)
 		msc->single_touch_id = SINGLE_TOUCH_UP;
 
+	if (!report_touches)
+		return;
+
+	if (use_MTB) {
+		input_mt_slot(input, id);
+		input_mt_report_slot_state(input, MT_TOOL_FINGER, down);
+	}
+
 	/* Generate the input events for this touch. */
-	if (report_touches && down) {
-		input_report_abs(input, ABS_MT_TRACKING_ID, id);
+	if (down) {
+		if (!use_MTB)
+			input_report_abs(input, ABS_MT_TRACKING_ID, id);
 		input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major << 2);
 		input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor << 2);
 		input_report_abs(input, ABS_MT_ORIENTATION, -orientation);
@@ -290,8 +304,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
 			else /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
 				input_event(input, EV_MSC, MSC_RAW, tdata[8]);
 		}
-
-		input_mt_sync(input);
+		if (!use_MTB)
+			input_mt_sync(input);
 	}
 }
 
@@ -425,7 +439,12 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h
 	if (report_touches) {
 		__set_bit(EV_ABS, input->evbit);
 
-		input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15, 0, 0);
+		if (use_MTB)
+			input_mt_init_slots(input, 16);
+		else
+			input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15,
+					     0, 0);
+
 		input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255 << 2,
 				     4, 0);
 		input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255 << 2,
-- 
1.7.7.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: magicmouse: Implement Multi-touch Protocol B (MT-B)
  2012-06-28 19:54 [PATCH] HID: magicmouse: Implement Multi-touch Protocol B (MT-B) Yufeng Shen
@ 2012-07-02 10:07 ` Henrik Rydberg
  2012-07-02 18:50   ` Chase Douglas
  2012-07-02 18:52 ` Chase Douglas
  1 sibling, 1 reply; 4+ messages in thread
From: Henrik Rydberg @ 2012-07-02 10:07 UTC (permalink / raw)
  To: Yufeng Shen
  Cc: linux-input, Jiri Kosina, linux-kernel, Daniel Kurtz,
	Andrew de los Reyes

On Thu, Jun 28, 2012 at 03:54:31PM -0400, Yufeng Shen wrote:
> The driver for Apple Magic Trackpad/Mouse currently uses
> Multi-touch Protocol A (MT-A) to report touch events and uses
> ABS_MT_TRACKING_ID to do finger tracking. The fact of the device
> being able to track individual finger makes it possible to
> report touch events using MT-B. This patch adds the support
> for the driver to report MT-B and makes it configurable through
> module parameter so that existing codes that are relying on its
> MT-A implemtation don't get affected.

Are there any such codes? Most systems, if not all, seem to use mtdev,
which can handle both protocols. I do not think a parameter switch is
a good idea. Switching to MT-B or leaving things as is look like the
viable options.

Thanks,
Henrik

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: magicmouse: Implement Multi-touch Protocol B (MT-B)
  2012-07-02 10:07 ` Henrik Rydberg
@ 2012-07-02 18:50   ` Chase Douglas
  0 siblings, 0 replies; 4+ messages in thread
From: Chase Douglas @ 2012-07-02 18:50 UTC (permalink / raw)
  To: Henrik Rydberg
  Cc: Yufeng Shen, linux-input, Jiri Kosina, linux-kernel, Daniel Kurtz,
	Andrew de los Reyes

On 07/02/2012 03:07 AM, Henrik Rydberg wrote:
> On Thu, Jun 28, 2012 at 03:54:31PM -0400, Yufeng Shen wrote:
>> The driver for Apple Magic Trackpad/Mouse currently uses
>> Multi-touch Protocol A (MT-A) to report touch events and uses
>> ABS_MT_TRACKING_ID to do finger tracking. The fact of the device
>> being able to track individual finger makes it possible to
>> report touch events using MT-B. This patch adds the support
>> for the driver to report MT-B and makes it configurable through
>> module parameter so that existing codes that are relying on its
>> MT-A implemtation don't get affected.
>
> Are there any such codes? Most systems, if not all, seem to use mtdev,
> which can handle both protocols. I do not think a parameter switch is
> a good idea. Switching to MT-B or leaving things as is look like the
> viable options.

Yes, let's just switch to MT-B :). Part of open source is that one can 
look at other implementations to figure out how to make your own new 
device work. We don't want to proliferate MT-A since MT-B is the way 
forward.

In fact, I would also suggest preceding this patch with one that removes 
the switch to turn touch reporting on and off. It's really unnecessary. 
I bet no one in the world turns it off :).

-- Chase

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: magicmouse: Implement Multi-touch Protocol B (MT-B)
  2012-06-28 19:54 [PATCH] HID: magicmouse: Implement Multi-touch Protocol B (MT-B) Yufeng Shen
  2012-07-02 10:07 ` Henrik Rydberg
@ 2012-07-02 18:52 ` Chase Douglas
  1 sibling, 0 replies; 4+ messages in thread
From: Chase Douglas @ 2012-07-02 18:52 UTC (permalink / raw)
  To: Yufeng Shen
  Cc: linux-input, Jiri Kosina, Henrik Rydberg, linux-kernel,
	Daniel Kurtz, Andrew de los Reyes

On 06/28/2012 12:54 PM, Yufeng Shen wrote:
> The driver for Apple Magic Trackpad/Mouse currently uses
> Multi-touch Protocol A (MT-A) to report touch events and uses
> ABS_MT_TRACKING_ID to do finger tracking. The fact of the device
> being able to track individual finger makes it possible to
> report touch events using MT-B. This patch adds the support
> for the driver to report MT-B and makes it configurable through
> module parameter so that existing codes that are relying on its
> MT-A implemtation don't get affected.
>
> Signed-off-by: Yufeng Shen <miletus@chromium.org>
> ---
>   drivers/hid/hid-magicmouse.c |   29 ++++++++++++++++++++++++-----
>   1 files changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index 40ac665..18d1ea0 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -17,6 +17,7 @@
>   #include <linux/device.h>
>   #include <linux/hid.h>
>   #include <linux/module.h>
> +#include <linux/input/mt.h>
>   #include <linux/slab.h>
>   #include <linux/usb.h>
>
> @@ -56,6 +57,10 @@ static bool report_undeciphered;
>   module_param(report_undeciphered, bool, 0644);
>   MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
>
> +static bool use_MTB;
> +module_param(use_MTB, bool, 0644);
> +MODULE_PARM_DESC(use_MTB, "Whether using MT-B protocol to report touch events");
> +
>   #define TRACKPAD_REPORT_ID 0x28
>   #define MOUSE_REPORT_ID    0x29
>   #define DOUBLE_REPORT_ID   0xf7
> @@ -275,9 +280,18 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
>   	} else if (msc->single_touch_id == id)
>   		msc->single_touch_id = SINGLE_TOUCH_UP;
>
> +	if (!report_touches)
> +		return;
> +
> +	if (use_MTB) {
> +		input_mt_slot(input, id);
> +		input_mt_report_slot_state(input, MT_TOOL_FINGER, down);
> +	}
> +
>   	/* Generate the input events for this touch. */
> -	if (report_touches && down) {
> -		input_report_abs(input, ABS_MT_TRACKING_ID, id);
> +	if (down) {
> +		if (!use_MTB)
> +			input_report_abs(input, ABS_MT_TRACKING_ID, id);
>   		input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major << 2);
>   		input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor << 2);
>   		input_report_abs(input, ABS_MT_ORIENTATION, -orientation);
> @@ -290,8 +304,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
>   			else /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
>   				input_event(input, EV_MSC, MSC_RAW, tdata[8]);
>   		}
> -
> -		input_mt_sync(input);
> +		if (!use_MTB)
> +			input_mt_sync(input);
>   	}
>   }
>
> @@ -425,7 +439,12 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h
>   	if (report_touches) {
>   		__set_bit(EV_ABS, input->evbit);
>
> -		input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15, 0, 0);
> +		if (use_MTB)
> +			input_mt_init_slots(input, 16);
> +		else
> +			input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15,
> +					     0, 0);
> +
>   		input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255 << 2,
>   				     4, 0);
>   		input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255 << 2,

I can't easily test this right now, but this looks correct to me. It 
almost seems too simple :). Please remove the use_MTB option, and then I 
will be happy to send my acked-by tag.

Thanks!

-- Chase

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-02 18:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-28 19:54 [PATCH] HID: magicmouse: Implement Multi-touch Protocol B (MT-B) Yufeng Shen
2012-07-02 10:07 ` Henrik Rydberg
2012-07-02 18:50   ` Chase Douglas
2012-07-02 18:52 ` Chase Douglas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).