From f55f5ea8d1f98f4b236643ca20d31519a1201d87 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 1 Dec 2026 12:16:06 +1100 Subject: [PATCH 1/6] soc: apple: record the built-in panel's scanned-out notch geometry The touch screen of a notched panel reports positions over the whole panel, while the display may scan its picture out below the notch rows. Only the display driver knows which, and the touch driver must work with or without it, in any load order. Add a small built-in record of the geometry: the panel's active rows and the rows above the picture. The display driver publishes it with every frame; readers take it lock-free in any context. Nothing published reads as a picture on the whole panel. Two helpers map a touch axis that spans the whole panel onto the picture: the hidden band is reported as such, the band's lower edge maps to 0 and the panel's bottom edge stays the axis maximum. KUnit covers the published state and the translation. Signed-off-by: Ryan Murray --- .github/workflows/apple-build-kunit.yml | 1 + MAINTAINERS | 2 + drivers/soc/apple/Kconfig | 22 ++++ drivers/soc/apple/Makefile | 3 + drivers/soc/apple/panel-notch-test.c | 125 ++++++++++++++++++++++ drivers/soc/apple/panel-notch.c | 46 ++++++++ drivers/soc/apple/panel-notch.kunitconfig | 5 + include/linux/soc/apple/panel-notch.h | 81 ++++++++++++++ 8 files changed, 285 insertions(+) create mode 100644 drivers/soc/apple/panel-notch-test.c create mode 100644 drivers/soc/apple/panel-notch.c create mode 100644 drivers/soc/apple/panel-notch.kunitconfig create mode 100644 include/linux/soc/apple/panel-notch.h diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index dff0b26c24bbb..5de7dbeb00a04 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -210,6 +210,7 @@ jobs: - { suite: scaler, kunitconfig: drivers/media/platform/apple/scaler/.kunitconfig } - { suite: macsmc, kunitconfig: drivers/mfd/macsmc.kunitconfig } - { suite: clpc, kunitconfig: drivers/soc/apple/clpc.kunitconfig } + - { suite: panel-notch, kunitconfig: drivers/soc/apple/panel-notch.kunitconfig } - { suite: apple-spmi-nvmem, kunitconfig: drivers/nvmem/apple-spmi-nvmem.kunitconfig } - { suite: trusted-keys, kunitconfig: security/keys/trusted-keys/tests/.kunitconfig } steps: diff --git a/MAINTAINERS b/MAINTAINERS index 44bc76d8e6555..d9d8291b8bf18 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2061,6 +2061,8 @@ F: Documentation/devicetree/bindings/display/apple,dcp-typec-routes.yaml F: Documentation/gpu/apple-dcp-*.rst F: drivers/gpu/drm/apple/ F: drivers/gpu/drm/apple/dcp-fabric* +F: drivers/soc/apple/panel-notch* +F: include/linux/soc/apple/panel-notch.h F: tools/testing/selftests/drivers/gpu/apple-afkv2/ F: tools/testing/selftests/drivers/gpu/apple-dcp/ diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 978833308016d..d98c4028bcf48 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -12,6 +12,28 @@ config APPLE_J613_DISPLAY_SYNC Built-in arbitration between the J613 display handoff and USB PD. State survives an absent, failed or later-loaded display module. +config APPLE_PANEL_NOTCH + bool + default DRM_APPLE != n + help + Built-in record of the notch geometry the built-in panel scans + out. The display driver publishes it; drivers whose coordinates + span the whole panel, such as the touch screen, map onto the + picture with it. Without a publisher it reads as the whole panel. + +config APPLE_PANEL_NOTCH_KUNIT_TEST + tristate "KUnit tests for the Apple panel notch geometry" if !KUNIT_ALL_TESTS + depends on KUNIT + select APPLE_PANEL_NOTCH + default KUNIT_ALL_TESTS + help + Publish and read the panel notch geometry, and map a touch axis + that spans the whole panel onto the picture below a hidden notch: + the band is dropped, the edges stay the axis's edges. The tests + touch no hardware. + + If unsure, say N. + config APPLE_DBGVIEW tristate "Apple SoC read-only debug register views" depends on ARCH_APPLE || COMPILE_TEST diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 216234e3aba5d..7cfc1004d2a36 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -4,6 +4,9 @@ obj-$(CONFIG_APPLE_MCC_BOOT_DMA) += mcc-boot-dma.o obj-$(CONFIG_APPLE_J613_DISPLAY_SYNC) += j613-display.o +obj-$(CONFIG_APPLE_PANEL_NOTCH) += panel-notch.o +obj-$(CONFIG_APPLE_PANEL_NOTCH_KUNIT_TEST) += panel-notch-test.o + obj-$(CONFIG_APPLE_DBGVIEW) += apple-dbgview.o apple-dbgview-y = dbgview.o obj-$(CONFIG_APPLE_DBGVIEW_KUNIT_TEST) += dbgview-test.o diff --git a/drivers/soc/apple/panel-notch-test.c b/drivers/soc/apple/panel-notch-test.c new file mode 100644 index 0000000000000..9fa14dc7aa685 --- /dev/null +++ b/drivers/soc/apple/panel-notch-test.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * KUnit tests for the built-in panel's notch geometry (panel-notch.h): the + * published state, and the translation of a whole-panel touch axis onto the + * picture below a hidden notch. + */ +#include +#include + +/* A 1986-row panel with 74 notch rows, its touch axis 1986 positions. */ +#define ROWS 1986 +#define NOTCH 74 + +static void panel_notch_state(struct kunit *test) +{ + struct apple_panel_notch saved = apple_panel_notch_get(), n; + + /* The record is the live one: leave it to a running display driver. */ + if (saved.panel_rows) + kunit_skip(test, "a display driver publishes the notch geometry"); + + apple_panel_notch_publish(ROWS, NOTCH); + n = apple_panel_notch_get(); + KUNIT_EXPECT_EQ(test, n.panel_rows, ROWS); + KUNIT_EXPECT_EQ(test, n.top, NOTCH); + + apple_panel_notch_publish(ROWS, 0); + n = apple_panel_notch_get(); + KUNIT_EXPECT_EQ(test, n.panel_rows, ROWS); + KUNIT_EXPECT_EQ(test, n.top, 0); + + /* Withdrawn, or no picture left: nothing published. */ + apple_panel_notch_publish(0, NOTCH); + n = apple_panel_notch_get(); + KUNIT_EXPECT_EQ(test, n.panel_rows, 0); + KUNIT_EXPECT_EQ(test, n.top, 0); + apple_panel_notch_publish(ROWS, ROWS); + n = apple_panel_notch_get(); + KUNIT_EXPECT_EQ(test, n.panel_rows, 0); + KUNIT_EXPECT_EQ(test, n.top, 0); + + apple_panel_notch_publish(0, 0); +} + +static void panel_notch_band(struct kunit *test) +{ + struct apple_panel_notch hidden = { ROWS, NOTCH }; + struct apple_panel_notch shown = { ROWS, 0 }; + struct apple_panel_notch none = { }; + struct apple_panel_notch full = { ROWS, ROWS }; + + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, ROWS), NOTCH); + /* An axis of another size gets the band in its own positions. */ + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, ROWS / 2), NOTCH / 2); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, 2 * ROWS), 2 * NOTCH); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&shown, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&none, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&full, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, 1), 0); +} + +static void panel_notch_map_shown(struct kunit *test) +{ + u32 y, out; + + /* No band: identity everywhere, nothing dropped. */ + for (y = 0; y < ROWS; y += 97) { + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(0, ROWS, y, &out)); + KUNIT_EXPECT_EQ(test, out, y); + } + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(0, ROWS, ROWS - 1, &out)); + KUNIT_EXPECT_EQ(test, out, ROWS - 1); +} + +static void panel_notch_map_hidden(struct kunit *test) +{ + u32 y, out, last = 0; + + /* The band is dropped and pinned to the picture's top edge. */ + KUNIT_EXPECT_FALSE(test, apple_panel_notch_map(NOTCH, ROWS, 0, &out)); + KUNIT_EXPECT_EQ(test, out, 0); + KUNIT_EXPECT_FALSE(test, apple_panel_notch_map(NOTCH, ROWS, NOTCH - 1, &out)); + KUNIT_EXPECT_EQ(test, out, 0); + + /* The picture's edges are the axis's edges. */ + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, NOTCH, &out)); + KUNIT_EXPECT_EQ(test, out, 0); + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, ROWS - 1, &out)); + KUNIT_EXPECT_EQ(test, out, ROWS - 1); + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, ROWS + 5, &out)); + KUNIT_EXPECT_EQ(test, out, ROWS - 1); + + /* The picture's middle row is the axis's middle. */ + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, + NOTCH + (ROWS - 1 - NOTCH) / 2, &out)); + KUNIT_EXPECT_EQ(test, out, (ROWS - 1) / 2); + + /* Monotonic, no gap wider than the stretch (span + 1 over span). */ + for (y = NOTCH; y < ROWS; y++) { + KUNIT_ASSERT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, y, &out)); + if (y > NOTCH) { + KUNIT_EXPECT_GE(test, out, last); + KUNIT_EXPECT_LE(test, out - last, 2); + } + last = out; + } +} + +static struct kunit_case panel_notch_cases[] = { + KUNIT_CASE(panel_notch_state), + KUNIT_CASE(panel_notch_band), + KUNIT_CASE(panel_notch_map_shown), + KUNIT_CASE(panel_notch_map_hidden), + { } +}; + +static struct kunit_suite panel_notch_suite = { + .name = "apple-panel-notch", + .test_cases = panel_notch_cases, +}; + +kunit_test_suite(panel_notch_suite); + +MODULE_DESCRIPTION("KUnit tests for the Apple panel notch geometry"); +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/drivers/soc/apple/panel-notch.c b/drivers/soc/apple/panel-notch.c new file mode 100644 index 0000000000000..67fd9cfd09d75 --- /dev/null +++ b/drivers/soc/apple/panel-notch.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The built-in panel's scanned-out notch geometry (panel-notch.h), built in + * so that the display driver and its readers need not load in any order or + * at all: a reader without a publisher sees the whole panel. + */ +#include +#include +#include +#include + +/* panel_rows in the high word, top in the low one: one state, read whole. */ +static atomic64_t apple_panel_notch_state = ATOMIC64_INIT(0); + +/** + * apple_panel_notch_publish - record what the built-in panel scans out + * @panel_rows: active rows of the whole panel; 0 withdraws the geometry + * @top: panel rows above the picture, 0 for a picture on the whole panel + * + * A @top that leaves no picture withdraws the geometry. Safe in any context. + */ +void apple_panel_notch_publish(u32 panel_rows, u32 top) +{ + u64 state = 0; + + if (panel_rows && top < panel_rows) + state = (u64)panel_rows << 32 | top; + atomic64_set(&apple_panel_notch_state, state); +} +EXPORT_SYMBOL_GPL(apple_panel_notch_publish); + +/** + * apple_panel_notch_get - the last published geometry + * + * Return: the geometry, all zero if none is published. Safe in any context. + */ +struct apple_panel_notch apple_panel_notch_get(void) +{ + u64 state = atomic64_read(&apple_panel_notch_state); + + return (struct apple_panel_notch){ + .panel_rows = upper_32_bits(state), + .top = lower_32_bits(state), + }; +} +EXPORT_SYMBOL_GPL(apple_panel_notch_get); diff --git a/drivers/soc/apple/panel-notch.kunitconfig b/drivers/soc/apple/panel-notch.kunitconfig new file mode 100644 index 0000000000000..bbb7a09ba678b --- /dev/null +++ b/drivers/soc/apple/panel-notch.kunitconfig @@ -0,0 +1,5 @@ +CONFIG_KUNIT=y +CONFIG_COMPILE_TEST=y +CONFIG_APPLE_PANEL_NOTCH_KUNIT_TEST=y +CONFIG_UBSAN=y +CONFIG_UBSAN_BOUNDS=y diff --git a/include/linux/soc/apple/panel-notch.h b/include/linux/soc/apple/panel-notch.h new file mode 100644 index 0000000000000..f5a4f3969b8fb --- /dev/null +++ b/include/linux/soc/apple/panel-notch.h @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * The notch geometry of the built-in panel, as the display driver scans it + * out, for drivers whose coordinates span the whole panel (the touch screen). + * + * The display driver publishes the panel's active rows and the rows above + * the picture on every frame it swaps in; a reader takes the last published + * state whenever it needs it. Nothing published (no display driver, or not + * bound yet) reads as a picture covering the whole panel. + */ +#ifndef _APPLE_PANEL_NOTCH_H +#define _APPLE_PANEL_NOTCH_H + +#include +#include +#include +#include + +/** + * struct apple_panel_notch - what the built-in panel scans out + * @panel_rows: active rows of the whole panel, notch rows included; 0: unknown + * @top: panel rows above the picture: the notch rows while they are hidden, + * 0 while the picture covers the whole panel + */ +struct apple_panel_notch { + u32 panel_rows; + u32 top; +}; + +#if IS_ENABLED(CONFIG_APPLE_PANEL_NOTCH) +void apple_panel_notch_publish(u32 panel_rows, u32 top); +struct apple_panel_notch apple_panel_notch_get(void); +#else +static inline void apple_panel_notch_publish(u32 panel_rows, u32 top) { } + +static inline struct apple_panel_notch apple_panel_notch_get(void) +{ + return (struct apple_panel_notch){ }; +} +#endif + +/* + * The hidden band at the top of an axis of @size positions that spans the + * whole panel, in those positions; 0 if the picture covers the whole panel. + */ +static inline u32 apple_panel_notch_band(const struct apple_panel_notch *n, u32 size) +{ + u32 band; + + if (!n->panel_rows || !n->top || n->top >= n->panel_rows || size < 2) + return 0; + band = div_u64((u64)n->top * size + n->panel_rows / 2, n->panel_rows); + return band < size - 1 ? band : 0; +} + +/* + * Map @y, on an axis of @size positions that spans the whole panel with 0 at + * the top, onto the picture below a hidden band of @band positions: the + * band's lower edge goes to 0 and the panel's bottom edge stays at + * @size - 1, so the whole axis covers the picture alone. Returns false for + * a @y inside the band; *@out is then 0, the picture's top edge. + */ +static inline bool apple_panel_notch_map(u32 band, u32 size, u32 y, u32 *out) +{ + u32 span; + + if (!band || band >= size - 1) { + *out = y; + return true; + } + if (y < band) { + *out = 0; + return false; + } + y = min(y, size - 1) - band; + span = size - 1 - band; + *out = div_u64((u64)y * (size - 1) + span / 2, span); + return true; +} + +#endif From 9db9b3523722867ce9b0c94ebec6dd30fa9c71c0 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 1 Dec 2026 12:16:07 +1100 Subject: [PATCH 2/6] drm/apple: publish the internal panel's notch geometry with each frame Wherever a swap records the rows above the frame (the notch rows for a notch-free mode, else 0), also publish them with the panel's active rows to the built-in panel notch record, for the touch screen. It follows what is scanned out, so the "notch" property, the sysfs attribute, the boot default and the console's notch-free geometry are all covered. Only a pipe with notch rows publishes, and unbinding it withdraws the geometry. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-internal.h | 13 +++++++++++++ drivers/gpu/drm/apple/dcp.c | 3 +++ drivers/gpu/drm/apple/iomfb.c | 2 +- drivers/gpu/drm/apple/iomfb_template.c | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 6b98091e78d27..e06a073998080 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -6,6 +6,7 @@ #include "dcp-indicator.h" #include "dcp-notch.h" +#include #include #include #include @@ -1425,6 +1426,18 @@ static inline bool dcp_notch_dynamic(const struct apple_dcp *dcp) dcp->fw_compat != DCP_FIRMWARE_V_26_6; } +/* + * A frame was swapped in @rows below the notch rows' top (dcp-notch.h): keep + * it for debugfs and publish the panel's picture to the touch screen + * (panel-notch.h), which maps its whole-panel coordinates onto it. + */ +static inline void dcp_notch_scanned_out(struct apple_dcp *dcp, u32 rows) +{ + WRITE_ONCE(dcp->notch_scanout_y, rows); + if (dcp->notch_rows) + apple_panel_notch_publish(READ_ONCE(dcp->notch_panel_rows), rows); +} + static inline bool iomfb_is_m4(const struct apple_dcp *dcp) { return IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) && diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e90ac4e251c8e..5fe34ecb6aecc 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -7769,6 +7769,9 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v if (!dcp) return; + /* The touch screen goes back to the whole panel (panel-notch.h). */ + if (dcp->notch_rows) + apple_panel_notch_publish(0, 0); if (IS_ENABLED(CONFIG_APPLE_SOC_SLEEP)) apple_sleep_v27_unregister(dev); dcp_indicator_release(dcp); diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index eb1044da9220f..9be69f2788ed2 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -4799,7 +4799,7 @@ void dcp_flush(struct drm_crtc *crtc, struct drm_atomic_commit *commit) ret = obj ? iomfb_m4_present_at(dcp, plane->fb, obj->dma_addr, obj->base.size, dst_y) : -EINVAL; if (!ret) - WRITE_ONCE(dcp->notch_scanout_y, dst_y); + dcp_notch_scanned_out(dcp, dst_y); } if (ret) dcp_drm_crtc_error(to_apple_crtc(crtc), new, -EIO); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index c5ca1cb1f1408..1b8552c94f96f 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -4704,7 +4704,7 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru notch_y = dcp_notch_offset(&crtc_state->mode, READ_ONCE(dcp->notch_panel_rows), dcp->notch_rows); - WRITE_ONCE(dcp->notch_scanout_y, notch_y); + dcp_notch_scanned_out(dcp, notch_y); req->swap.dst_rect[l].y += dcp->notch_height + notch_y; req->surf_iova[l] = apple_state->iova; From cd76b9ae061e8bb350e28248834e709fa57d413f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 1 Dec 2026 12:16:07 +1100 Subject: [PATCH 3/6] HID: apple-mtp-kiwi: map touches onto the picture when the notch is hidden The touch screen reports positions over the whole panel, notch rows included. With the notch hidden at run time the display offers only the notch-free modes, the compositor maps the whole ABS_Y range onto that shorter output, and every touch lands too high, most near the top. Read the panel's scanned-out geometry with every frame and, while a band is hidden above the picture, map the panel below it onto the whole ABS_Y range: the band's lower edge reports 0 and the bottom edge the maximum. A contact in the band is not reported until it first reaches the picture, so a tap on the black band is never seen and a swipe down from the glass edge starts at the picture's top edge; a reported contact that slides back into the band stays on that edge. When the geometry changes, every contact lifts for one frame and touches down again under the new geometry. The ABS ranges never change, and with the notch shown or no display driver the positions are as before. Closes: https://github.com/aurora-silicon/linux/issues/3719 Signed-off-by: Ryan Murray --- Documentation/gpu/apple-dcp-notch.rst | 31 +++++++++++++++ drivers/hid/hid-apple-mtp-kiwi.c | 54 +++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Documentation/gpu/apple-dcp-notch.rst b/Documentation/gpu/apple-dcp-notch.rst index b24d8ea2a2c5b..b6dba9a8f7690 100644 --- a/Documentation/gpu/apple-dcp-notch.rst +++ b/Documentation/gpu/apple-dcp-notch.rst @@ -59,3 +59,34 @@ tree gives it, otherwise the full height scaled by the rows. The standalone firmware 14.7 and 26.6 pipes build their one mode from the boot framebuffer and keep the boot loader's geometry for the boot. + +The touch screen +================ + +A touch screen on the panel (``hid-apple-mtp-kiwi``) reports positions over +the whole panel, notch rows included, and its ABS ranges never change. The +display driver publishes what it scans out with every frame it swaps in: +the panel's active rows and the rows above the picture +(``include/linux/soc/apple/panel-notch.h``, built in, so neither driver +depends on the other). While the picture is notch-free, the touch driver +maps the panel below the notch onto the whole ``ABS_MT_POSITION_Y`` range: +the notch band's lower edge reports 0 and the panel's bottom edge the +maximum, so a compositor that maps the range onto its output needs no +notch support. The geometry is the one scanned out, so it follows the +property, the sysfs attribute, the boot default and the console alike. + +* A contact in the notch band is not reported until it first reaches the + picture; a swipe down from the glass edge then starts at the picture's + top edge, and a tap on the band is never seen. +* A reported contact that slides into the band stays on the picture's top + edge. +* When the geometry changes with fingers down, every contact is lifted for + one frame and touches down again under the new geometry, as a new + contact. Userspace sees a release at the finger's position. + +Without the display driver, or before its first frame, nothing is +published and positions cover the whole panel. The standalone firmware +14.7 and 26.6 pipes, which keep the boot loader's geometry for the boot, +publish nothing either. ``ABS_MT_POSITION_Y``'s +resolution stays the whole panel's; while the notch is hidden one unit is +slightly shorter on the glass. diff --git a/drivers/hid/hid-apple-mtp-kiwi.c b/drivers/hid/hid-apple-mtp-kiwi.c index e41646a140918..2fa8b37c1b741 100644 --- a/drivers/hid/hid-apple-mtp-kiwi.c +++ b/drivers/hid/hid-apple-mtp-kiwi.c @@ -30,6 +30,16 @@ * and a per-row mean is removed from the rest. The raw image has no * baseline, so the driver keeps one per cell, picks local maxima of * (baseline - raw), and centroids 3x3. + * + * The sensor covers the whole panel, notch rows included, and so do the ABS + * ranges. While the display hides the notch rows the picture is shorter + * than the panel, and a compositor maps the whole ABS range onto it: the + * driver then maps the panel below the notch onto the whole range + * (panel-notch.h). A contact in the notch band is not reported until it + * first reaches the picture (an edge swipe then starts at its top edge); + * once reported, a contact that slides into the band stays on the top edge. + * When the geometry changes, every contact lifts and touches down again + * under the new one. */ #include @@ -38,6 +48,7 @@ #include #include #include +#include #include #include @@ -92,12 +103,14 @@ struct kiwi_contact { int bx, by; /* birth position: net drift past a cell over a sane hold = phantom */ s16 b_sig; /* signal at the birth cell when born: flatness marks a stuck cell */ bool lively; /* the birth-cell signal moved more than KIWI_STILL_COUNTS */ + bool shown; /* has reached the picture (panel-notch.h): reported */ }; struct kiwi { struct input_dev *input; int size_x, size_y; int res_x, res_y; + u32 notch_band; /* ABS_Y positions hidden above the picture, 0: none */ spinlock_t lock; /* serialises kiwi_raw_event() against kiwi_input_open() */ bool have_base; int rowmean[KIWI_ROWS]; /* per-row mean of the last frame, pre-removal */ @@ -458,6 +471,7 @@ static void kiwi_centroid(struct kiwi *k, int r, int c, struct kiwi_contact *out out->size = cells; out->on = true; out->miss = 0; + out->shown = false; /* shape and pressure: weighted second moments over 5x5, cells up to the peak's level */ for (dr = -2; dr <= 2; dr++) { @@ -583,11 +597,22 @@ static void kiwi_sup_mark(struct kiwi *k, int row, int col) static void kiwi_report(struct kiwi *k) { + struct apple_panel_notch notch = apple_panel_notch_get(); struct input_dev *input = k->input; + bool relift = false; + u32 band; int j, j2; + /* a new picture: lift every contact, they touch down again next frame */ + band = apple_panel_notch_band(¬ch, k->size_y); + if (band != k->notch_band) { + k->notch_band = band; + relift = true; + } + for (j = 0; j < KIWI_MAX_SLOTS; j++) { struct kiwi_contact *c = &k->cont[j]; + bool report; int x, y; if (c->on && k->now - c->born >= KIWI_STATIC_FRAMES && !c->lively) { @@ -651,14 +676,27 @@ static void kiwi_report(struct kiwi *k) k->last_end = k->now; } input_mt_slot(input, j); - input_mt_report_slot_state(input, MT_TOOL_FINGER, c->on); - if (!c->on) + report = c->on; + if (c->on) { + bool on_picture; + u32 py; + + x = div_s64((s64)c->x * k->size_x, KIWI_COLS * KIWI_FP); + y = div_s64((s64)c->y * k->size_y, KIWI_ROWS * KIWI_FP); + /* Row 0 is the bottom edge of the panel. */ + x = clamp(x, 0, k->size_x - 1); + y = clamp(k->size_y - 1 - y, 0, k->size_y - 1); + on_picture = apple_panel_notch_map(k->notch_band, k->size_y, y, &py); + y = py; + if (relift) + c->shown = false; + else if (on_picture) + c->shown = true; + report = c->shown; + } + input_mt_report_slot_state(input, MT_TOOL_FINGER, report); + if (!report) continue; - x = div_s64((s64)c->x * k->size_x, KIWI_COLS * KIWI_FP); - y = div_s64((s64)c->y * k->size_y, KIWI_ROWS * KIWI_FP); - /* Row 0 is the bottom edge of the panel. */ - x = clamp(x, 0, k->size_x - 1); - y = clamp(k->size_y - 1 - y, 0, k->size_y - 1); input_report_abs(input, ABS_MT_POSITION_X, x); input_report_abs(input, ABS_MT_POSITION_Y, y); input_report_abs(input, ABS_MT_TOUCH_MAJOR, @@ -687,6 +725,7 @@ static void kiwi_track(struct kiwi *k, struct kiwi_contact *found, int n) int bx = k->cont[j].bx, by = k->cont[j].by; s16 bs = k->cont[j].b_sig; bool lv = k->cont[j].lively; + bool shown = k->cont[j].shown; k->cont[j] = found[i]; k->cont[j].born = b; @@ -695,6 +734,7 @@ static void kiwi_track(struct kiwi *k, struct kiwi_contact *found, int n) k->cont[j].b_sig = bs; /* liveliness is sticky: the claim copy must not wipe it */ k->cont[j].lively = lv; + k->cont[j].shown = shown; /* still the same touch */ if (!k->cont[j].lively) { int d = k->sig[(by / KIWI_FP) * KIWI_COLS + (bx / KIWI_FP)] - bs; From 702e9123d686f8f7789b92bc6ae562256bf4a513 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 1 Dec 2026 14:56:56 +1100 Subject: [PATCH 4/6] drm/apple: publish the notch geometry once the firmware takes the swap The template flush published the rows above the picture while it built the swap request. If the firmware then rejected that swap, the touch screen mapped onto a picture that never appeared; after the first hidden-notch swap of a full-panel picture failed, it dropped touches on rows that were still visible. Keep the rows with the swap being submitted and publish them, with the debugfs scanout rows, in dcp_swapped() once the firmware has taken it. A rejected swap leaves the previous frame's geometry in place. The firmware-M4 path already publishes only after a successful present. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-internal.h | 2 ++ drivers/gpu/drm/apple/iomfb_template.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index e06a073998080..5c959aeaf900f 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -1117,6 +1117,8 @@ struct apple_dcp { bool notch_owned; /* Panel rows above the last frame swapped in: the notch rows, or 0. */ u32 notch_scanout_y; + /* The same for the swap being submitted, until the firmware takes it. */ + u32 notch_swap_y; /* The notch-free geometry is what a compositor is offered now. */ bool notch_free_offered; diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 1b8552c94f96f..7b996d9afec09 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -3616,6 +3616,8 @@ static void dcp_swapped(struct apple_dcp *dcp, void *data, void *cookie) } return; } + /* A rejected swap above keeps the previous frame's notch geometry. */ + dcp_notch_scanned_out(dcp, READ_ONCE(dcp->notch_swap_y)); if (dcp_is_ext26(dcp) && dcp->ext26_early_complete && dcp->ext26_early_id == swap_id) { u64 received = dcp->ext26_rx_ns; @@ -4704,7 +4706,8 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru notch_y = dcp_notch_offset(&crtc_state->mode, READ_ONCE(dcp->notch_panel_rows), dcp->notch_rows); - dcp_notch_scanned_out(dcp, notch_y); + /* Published once the firmware takes the swap (dcp_swapped()). */ + WRITE_ONCE(dcp->notch_swap_y, notch_y); req->swap.dst_rect[l].y += dcp->notch_height + notch_y; req->surf_iova[l] = apple_state->iova; From 945689d69bb1215ce4ddc6cb5740be354c10c351 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 1 Dec 2026 14:56:56 +1100 Subject: [PATCH 5/6] soc: apple: panel-notch: test the record on a value of the test's own The state test wrote test values into the live record that the touch screen reads, so a display frame published between its check and its writes could be overwritten, leaving the band at zero until the next frame. Move the packing of the record into header helpers, test those on a value the test owns, and keep apple_panel_notch_publish() and apple_panel_notch_get() as thin wrappers over the live record. Signed-off-by: Ryan Murray --- drivers/soc/apple/Kconfig | 2 +- drivers/soc/apple/panel-notch-test.c | 28 ++++++++++----------------- drivers/soc/apple/panel-notch.c | 16 +++------------ include/linux/soc/apple/panel-notch.h | 19 ++++++++++++++++++ 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index d98c4028bcf48..1f75b30155ed4 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -27,7 +27,7 @@ config APPLE_PANEL_NOTCH_KUNIT_TEST select APPLE_PANEL_NOTCH default KUNIT_ALL_TESTS help - Publish and read the panel notch geometry, and map a touch axis + Pack and unpack the panel notch record, and map a touch axis that spans the whole panel onto the picture below a hidden notch: the band is dropped, the edges stay the axis's edges. The tests touch no hardware. diff --git a/drivers/soc/apple/panel-notch-test.c b/drivers/soc/apple/panel-notch-test.c index 9fa14dc7aa685..7f53ae1b6021e 100644 --- a/drivers/soc/apple/panel-notch-test.c +++ b/drivers/soc/apple/panel-notch-test.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT /* * KUnit tests for the built-in panel's notch geometry (panel-notch.h): the - * published state, and the translation of a whole-panel touch axis onto the + * record's packed form, and the translation of a whole-panel touch axis onto the * picture below a hidden notch. */ #include @@ -11,35 +11,27 @@ #define ROWS 1986 #define NOTCH 74 +/* The record's word, on a value of the test's own: the live record is the display's. */ static void panel_notch_state(struct kunit *test) { - struct apple_panel_notch saved = apple_panel_notch_get(), n; + struct apple_panel_notch n; - /* The record is the live one: leave it to a running display driver. */ - if (saved.panel_rows) - kunit_skip(test, "a display driver publishes the notch geometry"); - - apple_panel_notch_publish(ROWS, NOTCH); - n = apple_panel_notch_get(); + n = apple_panel_notch_unpack(apple_panel_notch_pack(ROWS, NOTCH)); KUNIT_EXPECT_EQ(test, n.panel_rows, ROWS); KUNIT_EXPECT_EQ(test, n.top, NOTCH); - apple_panel_notch_publish(ROWS, 0); - n = apple_panel_notch_get(); + n = apple_panel_notch_unpack(apple_panel_notch_pack(ROWS, 0)); KUNIT_EXPECT_EQ(test, n.panel_rows, ROWS); KUNIT_EXPECT_EQ(test, n.top, 0); /* Withdrawn, or no picture left: nothing published. */ - apple_panel_notch_publish(0, NOTCH); - n = apple_panel_notch_get(); - KUNIT_EXPECT_EQ(test, n.panel_rows, 0); - KUNIT_EXPECT_EQ(test, n.top, 0); - apple_panel_notch_publish(ROWS, ROWS); - n = apple_panel_notch_get(); + KUNIT_EXPECT_EQ(test, apple_panel_notch_pack(0, NOTCH), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_pack(ROWS, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_pack(ROWS, U32_MAX), 0); + n = apple_panel_notch_unpack(0); KUNIT_EXPECT_EQ(test, n.panel_rows, 0); KUNIT_EXPECT_EQ(test, n.top, 0); - - apple_panel_notch_publish(0, 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&n, ROWS), 0); } static void panel_notch_band(struct kunit *test) diff --git a/drivers/soc/apple/panel-notch.c b/drivers/soc/apple/panel-notch.c index 67fd9cfd09d75..3ff572525801b 100644 --- a/drivers/soc/apple/panel-notch.c +++ b/drivers/soc/apple/panel-notch.c @@ -7,9 +7,8 @@ #include #include #include -#include -/* panel_rows in the high word, top in the low one: one state, read whole. */ +/* apple_panel_notch_pack(): one state, written and read whole. */ static atomic64_t apple_panel_notch_state = ATOMIC64_INIT(0); /** @@ -21,11 +20,7 @@ static atomic64_t apple_panel_notch_state = ATOMIC64_INIT(0); */ void apple_panel_notch_publish(u32 panel_rows, u32 top) { - u64 state = 0; - - if (panel_rows && top < panel_rows) - state = (u64)panel_rows << 32 | top; - atomic64_set(&apple_panel_notch_state, state); + atomic64_set(&apple_panel_notch_state, apple_panel_notch_pack(panel_rows, top)); } EXPORT_SYMBOL_GPL(apple_panel_notch_publish); @@ -36,11 +31,6 @@ EXPORT_SYMBOL_GPL(apple_panel_notch_publish); */ struct apple_panel_notch apple_panel_notch_get(void) { - u64 state = atomic64_read(&apple_panel_notch_state); - - return (struct apple_panel_notch){ - .panel_rows = upper_32_bits(state), - .top = lower_32_bits(state), - }; + return apple_panel_notch_unpack(atomic64_read(&apple_panel_notch_state)); } EXPORT_SYMBOL_GPL(apple_panel_notch_get); diff --git a/include/linux/soc/apple/panel-notch.h b/include/linux/soc/apple/panel-notch.h index f5a4f3969b8fb..f29884692302f 100644 --- a/include/linux/soc/apple/panel-notch.h +++ b/include/linux/soc/apple/panel-notch.h @@ -15,6 +15,7 @@ #include #include #include +#include /** * struct apple_panel_notch - what the built-in panel scans out @@ -27,6 +28,24 @@ struct apple_panel_notch { u32 top; }; +/* + * The record as one word, panel_rows high and top low, so that it is + * written and read whole. A geometry without a picture packs as nothing + * published. + */ +static inline u64 apple_panel_notch_pack(u32 panel_rows, u32 top) +{ + return panel_rows && top < panel_rows ? (u64)panel_rows << 32 | top : 0; +} + +static inline struct apple_panel_notch apple_panel_notch_unpack(u64 state) +{ + return (struct apple_panel_notch){ + .panel_rows = upper_32_bits(state), + .top = lower_32_bits(state), + }; +} + #if IS_ENABLED(CONFIG_APPLE_PANEL_NOTCH) void apple_panel_notch_publish(u32 panel_rows, u32 top); struct apple_panel_notch apple_panel_notch_get(void); From 8b9c1d987ff826cb02b330874dde261660fb8ee0 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 1 Dec 2026 16:14:18 +1100 Subject: [PATCH 6/6] tools/asahi: dcpext26-present-tests: cover the notch publish in dcp_swapped() dcp_swapped() now publishes the panel's notch geometry once the firmware takes a swap. Give the harness the new field and a recording stub, and check that a rejected, missing or cancelled swap response publishes nothing while an accepted one publishes the rows recorded with its swap. Signed-off-by: Ryan Murray --- tools/asahi/dcpext26-present-tests.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/asahi/dcpext26-present-tests.py b/tools/asahi/dcpext26-present-tests.py index bdc3accb16580..4b4fb2b1ee8c0 100644 --- a/tools/asahi/dcpext26-present-tests.py +++ b/tools/asahi/dcpext26-present-tests.py @@ -17,6 +17,7 @@ def function(name): #include typedef uint32_t u32;typedef uint64_t u64; #define WRITE_ONCE(x,y) ((x)=(y)) +#define READ_ONCE(x) (x) #define DCP_FW_NAME(n) n #define DCP_FW_UNION(x) ((x).h17p) #define DCP_FW_SWAP(d) ((d)->swap.h17p) @@ -28,11 +29,12 @@ def function(name): #define trace_iomfb_swap_submit(...) ((void)0) struct dcp_swap_submit_resp { u32 ret; }; struct dcp_swap_start_resp { u32 swap_id,ret; }; -struct apple_dcp { bool native,crashed,ext26_blocked,ext26_early_complete;u32 ext26_early_id,started_swap_id; +struct apple_dcp { bool native,crashed,ext26_blocked,ext26_early_complete;u32 ext26_early_id,started_swap_id,notch_swap_y; u64 ext26_rx_ns,ext26_early_ns,swap_start,swap_submit_timestamp;void *dev,*crtc; struct { struct { struct {u32 swap_id;} swap; } h17p; } swap; }; static int submit_result;static bool begin_allowed=true; -static unsigned failures,events,armed,watchdogs,completed,sent;static u64 completion_time; +static unsigned failures,events,armed,watchdogs,completed,sent,published;static u64 completion_time;static u32 published_rows; +static void dcp_notch_scanned_out(struct apple_dcp *d,u32 rows) { (void)d;published++;published_rows=rows; } static bool dcp_is_ext26(struct apple_dcp *d) { return d->native; } static int dcp_present_submit(struct apple_dcp *d,u32 id,bool ok) { (void)d;(void)id;(void)ok;return submit_result; } static void dcp_present_failed(struct apple_dcp *d) { (void)d;failures++; } @@ -57,7 +59,7 @@ def function(name): check=r''' static struct apple_dcp fresh(bool native) { struct apple_dcp d={.native=native};d.swap.h17p.swap.swap_id=7; - failures=events=armed=watchdogs=completed=sent=0;submit_result=0;begin_allowed=true;return d; + failures=events=armed=watchdogs=completed=sent=published=0;published_rows=~0U;submit_result=0;begin_allowed=true;return d; } int main(void) { struct dcp_swap_submit_resp bad={1},ok={0};struct apple_dcp d=fresh(true); @@ -68,12 +70,18 @@ def function(name): d=fresh(true);d.ext26_early_complete=true;d.ext26_early_id=7;d.ext26_early_ns=15;d.ext26_rx_ns=20; dcp_swapped(&d,&ok,NULL);assert(completed==1&&completion_time==15&&d.ext26_rx_ns==20&&!d.ext26_early_complete&&!watchdogs&&!d.crashed); d=fresh(true);dcp_swapped(&d,&ok,NULL);assert(watchdogs==1&&!d.crashed&&!failures); + /* The notch geometry follows only a swap the firmware took (panel-notch.h). */ + d=fresh(false);d.notch_swap_y=74;dcp_swapped(&d,&bad,NULL);assert(!published); + d=fresh(false);d.notch_swap_y=74;dcp_swapped(&d,NULL,NULL);assert(!published); + d=fresh(false);d.notch_swap_y=74;submit_result=-ECANCELED;dcp_swapped(&d,&ok,NULL);assert(!published); + d=fresh(false);d.notch_swap_y=74;dcp_swapped(&d,&ok,NULL);assert(published==1&&published_rows==74); + d=fresh(false);d.notch_swap_y=0;dcp_swapped(&d,&ok,NULL);assert(published==1&&published_rows==0); struct dcp_swap_start_resp start={8,1};d=fresh(true);dcp_swap_started(&d,&start,NULL);assert(d.crashed&&d.ext26_blocked&&!armed&&!sent); d=fresh(false);dcp_swap_started(&d,&start,NULL);assert(!d.crashed&&!sent); d=fresh(true);start=(struct dcp_swap_start_resp){0,0};dcp_swap_started(&d,&start,NULL);assert(d.crashed&&!sent); d=fresh(true);start.swap_id=8;begin_allowed=false;dcp_swap_started(&d,&start,NULL);assert(d.crashed&&!sent&&!armed); d=fresh(true);dcp_swap_started(&d,&start,NULL);assert(!d.crashed&&sent==1&&armed==1&&d.swap.h17p.swap.swap_id==8); - puts("PASS actual native DRM start/submit rejection, classic controls and original-time early D590 joining"); + puts("PASS actual native DRM start/submit rejection, classic controls, original-time early D590 joining and notch publish on accepted swaps only"); } ''' with tempfile.TemporaryDirectory() as t: