mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aditya Garg <gargaditya08@live.com>
To: jikos@kernel.org, jkosina@suse.com, bentiss@kernel.org,
	benjamin.tissoires@redhat.com
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org
Subject: Re: [PATCH] HID: magicmouse: Apple Magic Mouse 2 USB-C support
Date: Mon, 31 Mar 2025 13:26:42 +0530	[thread overview]
Message-ID: <PN3PR01MB9597C4CE02EC5DE00DAAD43EB8AD2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <PN3PR01MB9597EF3E56A1EE2191490E92B8AD2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>



On 31-03-2025 01:06 pm, Aditya Garg wrote:
> From: Aditya Garg <gargaditya08@live.com>
> 
> This patch adds support for USB-C model of Apple Magic Mouse 2.
> 
> Except for the hardware ID, it should resemble the existing configuration
> for the older Magic Mouse 2.
> 
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
>  drivers/hid/hid-ids.h        |  1 +
>  drivers/hid/hid-magicmouse.c | 74 ++++++++++++++++++++++++------------
>  2 files changed, 51 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> index 288a2b864..2d3f96af6 100644
> --- a/drivers/hid/hid-ids.h
> +++ b/drivers/hid/hid-ids.h
> @@ -92,6 +92,7 @@
>  #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE	0x0304
>  #define USB_DEVICE_ID_APPLE_MAGICMOUSE	0x030d
>  #define USB_DEVICE_ID_APPLE_MAGICMOUSE2	0x0269
> +#define USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC	0x0323
>  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD	0x030e
>  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2	0x0265
>  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC	0x0324
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index a76f17158..423d50702 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -218,7 +218,8 @@ static void magicmouse_emit_touch(struct
> magicmouse_sc *msc, int raw_id, u8 *tda
>  	int pressure = 0;
> 
>  	if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
> -	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
>  		id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
>  		x = (tdata[1] << 28 | tdata[0] << 20) >> 20;
>  		y = -((tdata[2] << 24 | tdata[1] << 16) >> 20);
> @@ -370,7 +371,8 @@ static void magicmouse_emit_touch(struct
> magicmouse_sc *msc, int raw_id, u8 *tda
> 
>  		if (report_undeciphered) {
>  			if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
> -			    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2)
> +			    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
> +			    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC)
>  				input_event(input, EV_MSC, MSC_RAW, tdata[7]);
>  			else if (input->id.product !=
>  					 USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
> @@ -497,7 +499,8 @@ static int magicmouse_raw_event(struct hid_device *hdev,
>  	}
> 
>  	if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
> -	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
>  		magicmouse_emit_buttons(msc, clicks & 3);
>  		input_report_rel(input, REL_X, x);
>  		input_report_rel(input, REL_Y, y);
> @@ -519,7 +522,8 @@ static int magicmouse_event(struct hid_device *hdev,
> struct hid_field *field,
>  		struct hid_usage *usage, __s32 value)
>  {
>  	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
> -	if (msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 &&
> +	if ((msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
> +	     msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) &&
>  	    field->report->id == MOUSE2_REPORT_ID) {
>  		/*
>  		 * magic_mouse_raw_event has done all the work. Skip hidinput.
> @@ -540,7 +544,8 @@ static int magicmouse_setup_input(struct input_dev
> *input, struct hid_device *hd
>  	__set_bit(EV_KEY, input->evbit);
> 
>  	if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
> -	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
>  		__set_bit(BTN_LEFT, input->keybit);
>  		__set_bit(BTN_RIGHT, input->keybit);
>  		if (emulate_3button)
> @@ -625,7 +630,8 @@ static int magicmouse_setup_input(struct input_dev
> *input, struct hid_device *hd
>  	 * inverse of the reported Y.
>  	 */
>  	if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
> -	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
> +	    input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
>  		input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0);
>  		input_set_abs_params(input, ABS_MT_POSITION_X,
>  				     MOUSE_MIN_X, MOUSE_MAX_X, 4, 0);
> @@ -741,19 +747,25 @@ static int magicmouse_enable_multitouch(struct
> hid_device *hdev)
>  	int ret;
>  	int feature_size;
> 
> -	if (hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
> -	    hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
> -		if (hdev->vendor == BT_VENDOR_ID_APPLE) {
> +	switch (hdev->product) {
> +	case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2:
> +	case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC:
> +		switch (hdev->vendor) {
> +		case BT_VENDOR_ID_APPLE:
>  			feature_size = sizeof(feature_mt_trackpad2_bt);
>  			feature = feature_mt_trackpad2_bt;
> -		} else { /* USB_VENDOR_ID_APPLE */
> +			break;
> +		default: /* USB_VENDOR_ID_APPLE */
>  			feature_size = sizeof(feature_mt_trackpad2_usb);
>  			feature = feature_mt_trackpad2_usb;
>  		}
> -	} else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
> +		break;
> +	case USB_DEVICE_ID_APPLE_MAGICMOUSE2:
> +	case USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC:
>  		feature_size = sizeof(feature_mt_mouse2);
>  		feature = feature_mt_mouse2;
> -	} else {
> +		break;
> +	default:
>  		feature_size = sizeof(feature_mt);
>  		feature = feature_mt;
>  	}
> @@ -787,6 +799,7 @@ static int magicmouse_fetch_battery(struct
> hid_device *hdev)
> 
>  	if (!hdev->battery || hdev->vendor != USB_VENDOR_ID_APPLE ||
>  	    (hdev->product != USB_DEVICE_ID_APPLE_MAGICMOUSE2 &&
> +	     hdev->product != USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC &&
>  	     hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
>  	     hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC))
>  		return -1;
> @@ -857,6 +870,7 @@ static int magicmouse_probe(struct hid_device *hdev,
> 
>  	if (id->vendor == USB_VENDOR_ID_APPLE &&
>  	    (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
> +	     id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC ||
>  	     ((id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
>  	       id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) &&
>  	      hdev->type != HID_TYPE_USBMOUSE)))
> @@ -868,21 +882,27 @@ static int magicmouse_probe(struct hid_device *hdev,
>  		goto err_stop_hw;
>  	}
> 
> -	if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
> -		report = hid_register_report(hdev, HID_INPUT_REPORT,
> -			MOUSE_REPORT_ID, 0);
> -	else if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2)
> -		report = hid_register_report(hdev, HID_INPUT_REPORT,
> -			MOUSE2_REPORT_ID, 0);
> -	else if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
> -		 id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
> -		if (id->vendor == BT_VENDOR_ID_APPLE)
> +	switch (id->product) {
> +	case USB_DEVICE_ID_APPLE_MAGICMOUSE:
> +		report = hid_register_report(hdev, HID_INPUT_REPORT, MOUSE_REPORT_ID, 0);
> +		break;
> +	case USB_DEVICE_ID_APPLE_MAGICMOUSE2:
> +	case USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC:
> +		report = hid_register_report(hdev, HID_INPUT_REPORT,
> MOUSE2_REPORT_ID, 0);

The patch is broken here. Fix sent here: https://lore.kernel.org/linux-input/PN3PR01MB95973E14FB234C6BCB6417A7B8AD2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM/T/#u

      reply	other threads:[~2025-03-31  7:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-31  7:36 Aditya Garg
2025-03-31  7:56 ` Aditya Garg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PN3PR01MB9597C4CE02EC5DE00DAAD43EB8AD2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM \
    --to=gargaditya08@live.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=jkosina@suse.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®