This commit is contained in:
Aditya Garg
2025-07-28 15:41:34 +05:30
parent 8b18e29155
commit 0fc9a7e288
11 changed files with 108 additions and 622 deletions
@@ -1,158 +0,0 @@
From f36469772a759d953c95719dd3a8b8c78cbf61b5 Mon Sep 17 00:00:00 2001
From: Hector Martin <marcan@marcan.st>
Date: Tue, 8 Apr 2025 12:17:57 +0530
Subject: [PATCH 1/5] lib/vsprintf: Add support for generic FourCCs by
extending %p4cc
%p4cc is designed for DRM/V4L2 FourCCs with their specific quirks, but
it's useful to be able to print generic 4-character codes formatted as
an integer. Extend it to add format specifiers for printing generic
32-bit FourCCs with various endian semantics:
%p4ch Host byte order
%p4cn Network byte order
%p4cl Little-endian
%p4cb Big-endian
The endianness determines how bytes are interpreted as a u32, and the
FourCC is then always printed MSByte-first (this is the opposite of
V4L/DRM FourCCs). This covers most practical cases, e.g. %p4cn would
allow printing LSByte-first FourCCs stored in host endian order
(other than the hex form being in character order, not the integer
value).
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/PN3PR01MB9597B01823415CB7FCD3BC27B8B52@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
Documentation/core-api/printk-formats.rst | 32 +++++++++++++++++++++
lib/vsprintf.c | 35 +++++++++++++++++++----
scripts/checkpatch.pl | 2 +-
3 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index 4bdc394e8..125fd0397 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -648,6 +648,38 @@ Examples::
%p4cc Y10 little-endian (0x20303159)
%p4cc NV12 big-endian (0xb231564e)
+Generic FourCC code
+-------------------
+
+::
+ %p4c[hnlb] gP00 (0x67503030)
+
+Print a generic FourCC code, as both ASCII characters and its numerical
+value as hexadecimal.
+
+The generic FourCC code is always printed in the big-endian format,
+the most significant byte first. This is the opposite of V4L/DRM FourCCs.
+
+The additional ``h``, ``n``, ``l``, and ``b`` specifiers define what
+endianness is used to load the stored bytes. The data might be interpreted
+using the host byte order, network byte order, little-endian, or big-endian.
+
+Passed by reference.
+
+Examples for a little-endian machine, given &(u32)0x67503030::
+
+ %p4ch gP00 (0x67503030)
+ %p4cn 00Pg (0x30305067)
+ %p4cl gP00 (0x67503030)
+ %p4cb 00Pg (0x30305067)
+
+Examples for a big-endian machine, given &(u32)0x67503030::
+
+ %p4ch gP00 (0x67503030)
+ %p4cn 00Pg (0x30305067)
+ %p4cl 00Pg (0x30305067)
+ %p4cb gP00 (0x67503030)
+
Rust
----
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 01699852f..6bc64ae52 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1793,27 +1793,50 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc,
char output[sizeof("0123 little-endian (0x01234567)")];
char *p = output;
unsigned int i;
+ bool pixel_fmt = false;
u32 orig, val;
- if (fmt[1] != 'c' || fmt[2] != 'c')
+ if (fmt[1] != 'c')
return error_string(buf, end, "(%p4?)", spec);
if (check_pointer(&buf, end, fourcc, spec))
return buf;
orig = get_unaligned(fourcc);
- val = orig & ~BIT(31);
+ switch (fmt[2]) {
+ case 'h':
+ break;
+ case 'n':
+ orig = swab32(orig);
+ break;
+ case 'l':
+ orig = (__force u32)cpu_to_le32(orig);
+ break;
+ case 'b':
+ orig = (__force u32)cpu_to_be32(orig);
+ break;
+ case 'c':
+ /* Pixel formats are printed LSB-first */
+ pixel_fmt = true;
+ break;
+ default:
+ return error_string(buf, end, "(%p4?)", spec);
+ }
+
+ val = pixel_fmt ? swab32(orig & ~BIT(31)) : orig;
for (i = 0; i < sizeof(u32); i++) {
- unsigned char c = val >> (i * 8);
+ unsigned char c = val >> ((3 - i) * 8);
/* Print non-control ASCII characters as-is, dot otherwise */
*p++ = isascii(c) && isprint(c) ? c : '.';
}
- *p++ = ' ';
- strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian");
- p += strlen(p);
+ if (pixel_fmt) {
+ *p++ = ' ';
+ strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian");
+ p += strlen(p);
+ }
*p++ = ' ';
*p++ = '(';
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3d22bf863..44e233b6f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6891,7 +6891,7 @@ sub process {
($extension eq "f" &&
defined $qualifier && $qualifier !~ /^w/) ||
($extension eq "4" &&
- defined $qualifier && $qualifier !~ /^cc/)) {
+ defined $qualifier && $qualifier !~ /^c[hnlbc]/)) {
$bad_specifier = $specifier;
last;
}
--
2.49.0
@@ -1,81 +0,0 @@
From 459024d6769c96a110d434b0eb80580ea370c4b5 Mon Sep 17 00:00:00 2001
From: Aditya Garg <gargaditya08@live.com>
Date: Tue, 8 Apr 2025 12:18:32 +0530
Subject: [PATCH 2/5] printf: add tests for generic FourCCs
This patch adds support for kunit tests of generic 32-bit FourCCs added to
vsprintf.
Acked-by: Tamir Duberstein <tamird@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/PN3PR01MB95973AF4F6262B2D1996FB25B8B52@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
lib/tests/printf_kunit.c | 39 ++++++++++++++++++++++++++++++++-------
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index 2c9f6170b..b1fa0dcea 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -701,21 +701,46 @@ static void fwnode_pointer(struct kunit *kunittest)
software_node_unregister_node_group(group);
}
+struct fourcc_struct {
+ u32 code;
+ const char *str;
+};
+
+static void fourcc_pointer_test(struct kunit *kunittest, const struct fourcc_struct *fc,
+ size_t n, const char *fmt)
+{
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ test(fc[i].str, fmt, &fc[i].code);
+}
+
static void fourcc_pointer(struct kunit *kunittest)
{
- struct {
- u32 code;
- char *str;
- } const try[] = {
+ static const struct fourcc_struct try_cc[] = {
{ 0x3231564e, "NV12 little-endian (0x3231564e)", },
{ 0xb231564e, "NV12 big-endian (0xb231564e)", },
{ 0x10111213, ".... little-endian (0x10111213)", },
{ 0x20303159, "Y10 little-endian (0x20303159)", },
};
- unsigned int i;
+ static const struct fourcc_struct try_ch[] = {
+ { 0x41424344, "ABCD (0x41424344)", },
+ };
+ static const struct fourcc_struct try_cn[] = {
+ { 0x41424344, "DCBA (0x44434241)", },
+ };
+ static const struct fourcc_struct try_cl[] = {
+ { (__force u32)cpu_to_le32(0x41424344), "ABCD (0x41424344)", },
+ };
+ static const struct fourcc_struct try_cb[] = {
+ { (__force u32)cpu_to_be32(0x41424344), "ABCD (0x41424344)", },
+ };
- for (i = 0; i < ARRAY_SIZE(try); i++)
- test(try[i].str, "%p4cc", &try[i].code);
+ fourcc_pointer_test(kunittest, try_cc, ARRAY_SIZE(try_cc), "%p4cc");
+ fourcc_pointer_test(kunittest, try_ch, ARRAY_SIZE(try_ch), "%p4ch");
+ fourcc_pointer_test(kunittest, try_cn, ARRAY_SIZE(try_cn), "%p4cn");
+ fourcc_pointer_test(kunittest, try_cl, ARRAY_SIZE(try_cl), "%p4cl");
+ fourcc_pointer_test(kunittest, try_cb, ARRAY_SIZE(try_cb), "%p4cb");
}
static void
--
2.49.0
@@ -1,43 +0,0 @@
From f58df41bb14f6e1cf5cd88eb9b681ac57eaed8b0 Mon Sep 17 00:00:00 2001
From: Aditya Garg <gargaditya08@live.com>
Date: Tue, 8 Apr 2025 12:19:11 +0530
Subject: [PATCH 3/5] drm/appletbdrm: use %p4cl instead of %p4cc
Due to lack of a proper format specifier, %p4cc was being used instead
of %p4cl for the purpose of printing FourCCs. But the disadvange was
that they were being printed in a reverse order. %p4cl should correct
this issue.
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
Link: https://lore.kernel.org/r/PN3PR01MB959783DC6377C4CAB203D7ADB8B52@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
drivers/gpu/drm/tiny/appletbdrm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/tiny/appletbdrm.c b/drivers/gpu/drm/tiny/appletbdrm.c
index 4370ba22d..8643216ba 100644
--- a/drivers/gpu/drm/tiny/appletbdrm.c
+++ b/drivers/gpu/drm/tiny/appletbdrm.c
@@ -214,7 +214,7 @@ static int appletbdrm_read_response(struct appletbdrm_device *adev,
}
if (response->msg != expected_response) {
- drm_err(drm, "Unexpected response from device (expected %p4cc found %p4cc)\n",
+ drm_err(drm, "Unexpected response from device (expected %p4cl found %p4cl)\n",
&expected_response, &response->msg);
return -EIO;
}
@@ -288,7 +288,7 @@ static int appletbdrm_get_information(struct appletbdrm_device *adev)
}
if (pixel_format != APPLETBDRM_PIXEL_FORMAT) {
- drm_err(drm, "Encountered unknown pixel format (%p4cc)\n", &pixel_format);
+ drm_err(drm, "Encountered unknown pixel format (%p4cl)\n", &pixel_format);
ret = -EINVAL;
goto free_info;
}
--
2.49.0
@@ -1,139 +0,0 @@
From 391f6d69ac9f0ce2f16636505c8b74025a93889b Mon Sep 17 00:00:00 2001
From: Petr Mladek <pmladek@suse.com>
Date: Mon, 28 Apr 2025 14:31:32 +0200
Subject: [PATCH 4/5] vsprintf: Use %p4chR instead of %p4cn for reading data in
reversed host ordering
The generic FourCC format always prints the data using the big endian
order. It is generic because it allows to read the data using a custom
ordering.
The current code uses "n" for reading data in the reverse host ordering.
It makes the 4 variants [hnbl] consistent with the generic printing
of IPv4 addresses.
Unfortunately, it creates confusion on big endian systems. For example,
it shows the data &(u32)0x67503030 as
%p4cn 00Pg (0x30305067)
But people expect that the ordering stays the same. The network ordering
is a big-endian ordering.
The problem is that the semantic is not the same. The modifiers affect
the output ordering of IPv4 addresses while they affect the reading order
in case of FourCC code.
Avoid the confusion by replacing the "n" modifier with "hR", aka
reverse host ordering. It is inspired by the existing %p[mM]R printf
format.
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/r/CAMuHMdV9tX=TG7E_CrSF=2PY206tXf+_yYRuacG48EWEtJLo-Q@mail.gmail.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Aditya Garg <gargaditya08@live.com>
Link: https://lore.kernel.org/r/20250428123132.578771-1-pmladek@suse.com
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
Documentation/core-api/printk-formats.rst | 10 +++++-----
lib/tests/printf_kunit.c | 4 ++--
lib/vsprintf.c | 11 ++++++++---
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index 125fd0397..f531873bb 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -652,7 +652,7 @@ Generic FourCC code
-------------------
::
- %p4c[hnlb] gP00 (0x67503030)
+ %p4c[h[R]lb] gP00 (0x67503030)
Print a generic FourCC code, as both ASCII characters and its numerical
value as hexadecimal.
@@ -660,23 +660,23 @@ value as hexadecimal.
The generic FourCC code is always printed in the big-endian format,
the most significant byte first. This is the opposite of V4L/DRM FourCCs.
-The additional ``h``, ``n``, ``l``, and ``b`` specifiers define what
+The additional ``h``, ``hR``, ``l``, and ``b`` specifiers define what
endianness is used to load the stored bytes. The data might be interpreted
-using the host byte order, network byte order, little-endian, or big-endian.
+using the host, reversed host byte order, little-endian, or big-endian.
Passed by reference.
Examples for a little-endian machine, given &(u32)0x67503030::
%p4ch gP00 (0x67503030)
- %p4cn 00Pg (0x30305067)
+ %p4chR 00Pg (0x30305067)
%p4cl gP00 (0x67503030)
%p4cb 00Pg (0x30305067)
Examples for a big-endian machine, given &(u32)0x67503030::
%p4ch gP00 (0x67503030)
- %p4cn 00Pg (0x30305067)
+ %p4chR 00Pg (0x30305067)
%p4cl 00Pg (0x30305067)
%p4cb gP00 (0x67503030)
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index b1fa0dcea..bc54cca2d 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -726,7 +726,7 @@ static void fourcc_pointer(struct kunit *kunittest)
static const struct fourcc_struct try_ch[] = {
{ 0x41424344, "ABCD (0x41424344)", },
};
- static const struct fourcc_struct try_cn[] = {
+ static const struct fourcc_struct try_chR[] = {
{ 0x41424344, "DCBA (0x44434241)", },
};
static const struct fourcc_struct try_cl[] = {
@@ -738,7 +738,7 @@ static void fourcc_pointer(struct kunit *kunittest)
fourcc_pointer_test(kunittest, try_cc, ARRAY_SIZE(try_cc), "%p4cc");
fourcc_pointer_test(kunittest, try_ch, ARRAY_SIZE(try_ch), "%p4ch");
- fourcc_pointer_test(kunittest, try_cn, ARRAY_SIZE(try_cn), "%p4cn");
+ fourcc_pointer_test(kunittest, try_chR, ARRAY_SIZE(try_chR), "%p4chR");
fourcc_pointer_test(kunittest, try_cl, ARRAY_SIZE(try_cl), "%p4cl");
fourcc_pointer_test(kunittest, try_cb, ARRAY_SIZE(try_cb), "%p4cb");
}
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 6bc64ae52..d8a2ec083 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1805,9 +1805,8 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc,
orig = get_unaligned(fourcc);
switch (fmt[2]) {
case 'h':
- break;
- case 'n':
- orig = swab32(orig);
+ if (fmt[3] == 'R')
+ orig = swab32(orig);
break;
case 'l':
orig = (__force u32)cpu_to_le32(orig);
@@ -2397,6 +2396,12 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
* read the documentation (path below) first.
* - 'NF' For a netdev_features_t
* - '4cc' V4L2 or DRM FourCC code, with endianness and raw numerical value.
+ * - '4c[h[R]lb]' For generic FourCC code with raw numerical value. Both are
+ * displayed in the big-endian format. This is the opposite of V4L2 or
+ * DRM FourCCs.
+ * The additional specifiers define what endianness is used to load
+ * the stored bytes. The data might be interpreted using the host,
+ * reversed host byte order, little-endian, or big-endian.
* - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
* a certain separator (' ' by default):
* C colon
--
2.49.0
-30
View File
@@ -1,30 +0,0 @@
From 1b4d677851177100a28d372838fd56a3f3c5a3e2 Mon Sep 17 00:00:00 2001
From: Aditya Garg <gargaditya08@live.com>
Date: Wed, 30 Apr 2025 19:19:08 +0530
Subject: [PATCH 5/5] checkpatch: remove %p4cn
%p4cn was recently removed and replaced by %p4chR in vsprintf. So,
remove the check for %p4cn from checkpatch.pl.
Fixes: 37eed892cc5f ("vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering")
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 44e233b6f..d5bde8322 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6891,7 +6891,7 @@ sub process {
($extension eq "f" &&
defined $qualifier && $qualifier !~ /^w/) ||
($extension eq "4" &&
- defined $qualifier && $qualifier !~ /^c[hnlbc]/)) {
+ defined $qualifier && $qualifier !~ /^c(?:[hlbc]|hR)$/)) {
$bad_specifier = $specifier;
last;
}
--
2.49.0
-8
View File
@@ -16,14 +16,6 @@ diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/dis
index 49b5cc01c..1435f49f2 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -4685,6 +4685,7 @@ intel_ddi_init_hdmi_connector(struct intel_digital_port *dig_port)
static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dig_port)
{
+ struct intel_display *display = to_intel_display(dig_port);
struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
if (dig_port->base.port != PORT_A)
@@ -4693,6 +4694,9 @@ static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dig_port)
if (dig_port->ddi_a_4_lanes)
return false;
+67 -69
View File
@@ -698,16 +698,22 @@ index e3f5776ad..09e8a7c2d 100644
static int magicmouse_input_mapping(struct hid_device *hdev,
struct hid_input *hi, struct hid_field *field,
struct hid_usage *usage, unsigned long **bit, int *max)
@@ -779,6 +1015,9 @@ static int magicmouse_enable_multitouch(struct hid_device *hdev)
feature_size = sizeof(feature_mt_trackpad2_usb);
feature = feature_mt_trackpad2_usb;
}
+ } else if (hdev->vendor == SPI_VENDOR_ID_APPLE) {
+ feature_size = sizeof(feature_mt_trackpad2_usb);
+ feature = feature_mt_trackpad2_usb;
} else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
feature_size = sizeof(feature_mt_mouse2);
@@ -766,8 +766,13 @@ static int magicmouse_enable_multitouch(struct hid_device *hdev)
feature = feature_mt_mouse2;
break;
default:
- feature_size = sizeof(feature_mt);
- feature = feature_mt;
+ if (hdev->vendor == SPI_VENDOR_ID_APPLE) {
+ feature_size = sizeof(feature_mt_trackpad2_usb);
+ feature = feature_mt_trackpad2_usb;
+ } else {
+ feature_size = sizeof(feature_mt);
+ feature = feature_mt;
+ }
}
buf = kmemdup(feature, feature_size, GFP_KERNEL);
@@ -854,14 +1093,26 @@ static int magicmouse_probe(struct hid_device *hdev,
struct hid_report *report;
int ret;
@@ -737,15 +743,25 @@ index e3f5776ad..09e8a7c2d 100644
msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
msc->hdev = hdev;
@@ -914,6 +1165,8 @@ static int magicmouse_probe(struct hid_device *hdev,
else /* USB_VENDOR_ID_APPLE */
report = hid_register_report(hdev, HID_INPUT_REPORT,
TRACKPAD2_USB_REPORT_ID, 0);
+ } else if (id->vendor == SPI_VENDOR_ID_APPLE) {
+ report = hid_register_report(hdev, HID_INPUT_REPORT, 2, 0);
} else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
report = hid_register_report(hdev, HID_INPUT_REPORT,
TRACKPAD_REPORT_ID, 0);
@@ -908,10 +908,14 @@ static int magicmouse_probe(struct hid_device *hdev,
}
break;
default: /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
- report = hid_register_report(hdev, HID_INPUT_REPORT,
- TRACKPAD_REPORT_ID, 0);
- report = hid_register_report(hdev, HID_INPUT_REPORT,
- DOUBLE_REPORT_ID, 0);
+ if (id->vendor == SPI_VENDOR_ID_APPLE) {
+ report = hid_register_report(hdev, HID_INPUT_REPORT, 2, 0);
+ } else {
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ TRACKPAD_REPORT_ID, 0);
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ DOUBLE_REPORT_ID, 0);
+ }
}
if (!report) {
@@ -1013,6 +1266,8 @@ static const struct hid_device_id magic_mice[] = {
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC), .driver_data = 0 },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
@@ -2353,19 +2369,19 @@ index 09e8a7c2d..82c9ca7ea 100644
msc->input_ops.raw_event = magicmouse_raw_event_spi;
msc->input_ops.setup_input = magicmouse_setup_input_spi;
@@ -1165,8 +1188,10 @@ static int magicmouse_probe(struct hid_device *hdev,
else /* USB_VENDOR_ID_APPLE */
@@ -908,8 +908,10 @@ static int magicmouse_probe(struct hid_device *hdev,
}
break;
default: /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
- if (id->vendor == SPI_VENDOR_ID_APPLE) {
- report = hid_register_report(hdev, HID_INPUT_REPORT, 2, 0);
+ if (id->bus == BUS_SPI) {
+ report = hid_register_report(hdev, HID_INPUT_REPORT, SPI_REPORT_ID, 0);
+ } else if (id->bus == BUS_HOST) {
+ report = hid_register_report(hdev, HID_INPUT_REPORT, MTP_REPORT_ID, 0);
} else {
report = hid_register_report(hdev, HID_INPUT_REPORT,
TRACKPAD2_USB_REPORT_ID, 0);
- } else if (id->vendor == SPI_VENDOR_ID_APPLE) {
- report = hid_register_report(hdev, HID_INPUT_REPORT, 2, 0);
+ } else if (id->bus == BUS_SPI) {
+ report = hid_register_report(hdev, HID_INPUT_REPORT, SPI_REPORT_ID, 0);
+ } else if (id->bus == BUS_HOST) {
+ report = hid_register_report(hdev, HID_INPUT_REPORT, MTP_REPORT_ID, 0);
} else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
report = hid_register_report(hdev, HID_INPUT_REPORT,
TRACKPAD_REPORT_ID, 0);
TRACKPAD_REPORT_ID, 0);
@@ -1181,6 +1206,10 @@ static int magicmouse_probe(struct hid_device *hdev,
}
report->size = 6;
@@ -4809,7 +4825,7 @@ index 7ec80fe86..71ba59b84 100644
+ } else if (hdev->vendor == SPI_VENDOR_ID_APPLE) {
+ feature_size = sizeof(feature_mt_trackpad2_usb);
+ feature = feature_mt_trackpad2_usb;
+ } else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
+ } else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
+ feature_size = sizeof(feature_mt_mouse2);
+ feature = feature_mt_mouse2;
+ } else {
@@ -4948,7 +4964,7 @@ index 7ec80fe86..71ba59b84 100644
static int magicmouse_input_mapping(struct hid_device *hdev,
struct hid_input *hi, struct hid_field *field,
struct hid_usage *usage, unsigned long **bit, int *max)
@@ -1015,58 +1141,6 @@ static int magicmouse_input_configured(struct hid_device *hdev,
@@ -736,66 +736,6 @@ static int magicmouse_input_configured(struct hid_device *hdev,
return 0;
}
@@ -4963,24 +4979,32 @@ index 7ec80fe86..71ba59b84 100644
- 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->vendor == SPI_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 {
- feature_size = sizeof(feature_mt);
- feature = feature_mt;
- break;
- default:
- if (hdev->vendor == SPI_VENDOR_ID_APPLE) {
- feature_size = sizeof(feature_mt_trackpad2_usb);
- feature = feature_mt_trackpad2_usb;
- } else {
- feature_size = sizeof(feature_mt);
- feature = feature_mt;
- }
- }
-
- buf = kmemdup(feature, feature_size, GFP_KERNEL);
@@ -5016,32 +5040,6 @@ index 7ec80fe86..71ba59b84 100644
} else if (id->bus == BUS_SPI) {
msc->input_ops.raw_event = magicmouse_raw_event_spi;
msc->input_ops.setup_input = magicmouse_setup_input_spi;
@@ -1210,21 +1284,10 @@ static int magicmouse_probe(struct hid_device *hdev,
if (id->bus == BUS_HOST)
return 0;
- /*
- * Some devices repond with 'invalid report id' when feature
- * report switching it into multitouch mode is sent to it.
- *
- * This results in -EIO from the _raw low-level transport callback,
- * but there seems to be no other way of switching the mode.
- * Thus the super-ugly hacky success check below.
- */
- ret = magicmouse_enable_multitouch(hdev);
- if (ret != -EIO && ret < 0) {
- hid_err(hdev, "unable to request touch data (%d)\n", ret);
- goto err_stop_hw;
- }
- if (ret == -EIO && id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
- schedule_delayed_work(&msc->work, msecs_to_jiffies(500));
+ /* SPI devices need to watch for reset events to re-send the MT enable */
+ if (id->bus == BUS_SPI) {
+ report = hid_register_report(hdev, HID_INPUT_REPORT, SPI_RESET_REPORT_ID, 0);
+ report->size = 2;
}
return 0;
--
2.49.0
@@ -125,7 +125,7 @@ index d5ab547b1..eb62752d7 100644
struct magicmouse_input_ops {
int (*raw_event)(struct hid_device *hdev,
@@ -196,24 +288,45 @@ static int magicmouse_enable_multitouch(struct hid_device *hdev)
@@ -196,24 +288,46 @@ static int magicmouse_enable_multitouch(struct hid_device *hdev)
int ret;
int feature_size;
@@ -167,6 +167,7 @@ index d5ab547b1..eb62752d7 100644
feature = feature_mt_trackpad2_usb;
+ break;
+ case USB_DEVICE_ID_APPLE_MAGICMOUSE2:
+ case USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC:
+ feature_size = sizeof(feature_mt_mouse2);
+ feature = feature_mt_mouse2;
+ break;
@@ -177,7 +178,7 @@ index d5ab547b1..eb62752d7 100644
- } else if (hdev->vendor == SPI_VENDOR_ID_APPLE) {
- feature_size = sizeof(feature_mt_trackpad2_usb);
- feature = feature_mt_trackpad2_usb;
- } else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) {
- } else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) {
- feature_size = sizeof(feature_mt_mouse2);
- feature = feature_mt_mouse2;
- } else {
@@ -398,78 +399,24 @@ index d5ab547b1..eb62752d7 100644
}
msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
@@ -1304,29 +1522,50 @@ 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)
- report = hid_register_report(hdev, HID_INPUT_REPORT,
- TRACKPAD2_BT_REPORT_ID, 0);
- else /* USB_VENDOR_ID_APPLE */
- report = hid_register_report(hdev, HID_INPUT_REPORT,
- TRACKPAD2_USB_REPORT_ID, 0);
- } else if (id->bus == BUS_SPI) {
+ switch (id->bus) {
+ case BUS_SPI:
report = hid_register_report(hdev, HID_INPUT_REPORT, SPI_REPORT_ID, 0);
- } else if (id->bus == BUS_HOST) {
@@ -1336,6 +1336,17 @@ static int magicmouse_probe(struct hid_device *hdev,
TRACKPAD2_USB_REPORT_ID, 0);
}
break;
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F:
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ TRACKPAD2_USB_REPORT_ID, 0);
+ break;
+ case BUS_HOST:
report = hid_register_report(hdev, HID_INPUT_REPORT, MTP_REPORT_ID, 0);
- } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
- report = hid_register_report(hdev, HID_INPUT_REPORT,
- TRACKPAD_REPORT_ID, 0);
- report = hid_register_report(hdev, HID_INPUT_REPORT,
- DOUBLE_REPORT_ID, 0);
+ break;
+ default:
+ 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:
+ report = hid_register_report(hdev, HID_INPUT_REPORT, MOUSE2_REPORT_ID, 0);
+ break;
+ case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2:
+ case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC:
+ switch (id->vendor) {
+ case BT_VENDOR_ID_APPLE:
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ TRACKPAD2_BT_REPORT_ID, 0);
+ break;
+ default:
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ TRACKPAD2_USB_REPORT_ID, 0);
+ }
+ break;
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F:
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ TRACKPAD2_USB_REPORT_ID, 0);
+ break;
+ default: /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ TRACKPAD_REPORT_ID, 0);
+ report = hid_register_report(hdev, HID_INPUT_REPORT,
+ DOUBLE_REPORT_ID, 0);
+ }
}
if (!report) {
default: /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
if (id->bus == BUS_SPI) {
report = hid_register_report(hdev, HID_INPUT_REPORT, SPI_REPORT_ID, 0);
@@ -1414,6 +1653,22 @@ static const struct hid_device_id magic_mice[] = {
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC), .driver_data = 0 },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
@@ -1,7 +1,7 @@
From 8a980335aa7495020760fb507bb906975b864ada Mon Sep 17 00:00:00 2001
From 9e5a69ced6bf9e879a93215dc498bfb07f0fa518 Mon Sep 17 00:00:00 2001
From: Aditya Garg <gargaditya08@live.com>
Date: Tue, 18 Mar 2025 21:27:25 +0530
Subject: [PATCH 5/5] HID: magicmouse: Add MacBookPro15,1 replacement trackpad
Subject: [PATCH] HID: magicmouse: Add MacBookPro15,1 replacement trackpad
support
This commit adds support for third party replacement trackpad for
@@ -13,10 +13,10 @@ Signed-off-by: Aditya Garg <gargaditya08@live.com>
1 file changed, 18 insertions(+)
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index eb62752d7..769c31706 100644
index 41926b389..328df8118 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -150,6 +150,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
@@ -151,6 +151,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
#define J680_TP_RES_Y \
((J680_TP_MAX_Y - J680_TP_MIN_Y) / (J680_TP_DIMENSION_Y / 100))
@@ -34,7 +34,7 @@ index eb62752d7..769c31706 100644
#define J213_TP_DIMENSION_X (float)13500
#define J213_TP_MIN_X -6243
#define J213_TP_MAX_X 6749
@@ -311,6 +322,7 @@ static int magicmouse_enable_multitouch(struct hid_device *hdev)
@@ -312,6 +323,7 @@ static int magicmouse_enable_multitouch(struct hid_device *hdev)
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
@@ -42,7 +42,7 @@ index eb62752d7..769c31706 100644
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
@@ -1204,6 +1216,7 @@ static const struct magicmouse_t2_properties magicmouse_t2_configs[] = {
@@ -1215,6 +1227,7 @@ static const struct magicmouse_t2_properties magicmouse_t2_configs[] = {
T2_TOUCHPAD_ENTRY(J140K),
T2_TOUCHPAD_ENTRY(J132),
T2_TOUCHPAD_ENTRY(J680),
@@ -50,7 +50,7 @@ index eb62752d7..769c31706 100644
T2_TOUCHPAD_ENTRY(J213),
T2_TOUCHPAD_ENTRY(J214K),
T2_TOUCHPAD_ENTRY(J223),
@@ -1439,6 +1452,7 @@ static int magicmouse_probe(struct hid_device *hdev,
@@ -1451,6 +1464,7 @@ static int magicmouse_probe(struct hid_device *hdev,
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
@@ -58,7 +58,7 @@ index eb62752d7..769c31706 100644
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
@@ -1471,6 +1485,7 @@ static int magicmouse_probe(struct hid_device *hdev,
@@ -1483,6 +1497,7 @@ static int magicmouse_probe(struct hid_device *hdev,
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
@@ -66,15 +66,15 @@ index eb62752d7..769c31706 100644
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
@@ -1552,6 +1567,7 @@ static int magicmouse_probe(struct hid_device *hdev,
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680_ALT:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
@@ -1659,6 +1675,8 @@ static const struct hid_device_id magic_mice[] = {
@@ -1558,6 +1573,7 @@ static int magicmouse_probe(struct hid_device *hdev,
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680_ALT:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
@@ -1687,6 +1703,8 @@ static const struct hid_device_id magic_mice[] = {
USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132), .driver_data = 0 },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680), .driver_data = 0 },
@@ -84,5 +84,5 @@ index eb62752d7..769c31706 100644
USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213), .driver_data = 0 },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
--
2.43.0
2.49.0
@@ -14,7 +14,7 @@ diff --git a/drivers/gpu/drm/i915/display/intel_fbdev.c b/drivers/gpu/drm/i915/d
index 49a1ac4f549195..c8c10a6104c4e9 100644
--- a/drivers/gpu/drm/i915/display/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/display/intel_fbdev.c
@@ -199,10 +199,10 @@ static int intelfb_create(struct drm_fb_helper *helper,
@@ -224,10 +224,10 @@ int intel_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
ifbdev->fb = NULL;
if (fb &&
@@ -22,7 +22,7 @@ index 49a1ac4f549195..c8c10a6104c4e9 100644
- sizes->fb_height > fb->base.height)) {
+ (sizes->fb_width != fb->base.width ||
+ sizes->fb_height != fb->base.height)) {
drm_dbg_kms(&dev_priv->drm,
drm_dbg_kms(display->drm,
- "BIOS fb too small (%dx%d), we require (%dx%d),"
+ "BIOS fb not valid (%dx%d), we require (%dx%d),"
" releasing it\n",
+1 -1
View File
@@ -1 +1 @@
KVER=6.15.2
KVER=6.16