Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Documentation/gpu/apple-dcp-notch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -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/asahi/afk-compact-start-tests.py
F: tools/asahi/dcp-tunnel-prepare-tests.py
F: tools/testing/selftests/drivers/gpu/apple-afkv2/
Expand Down
15 changes: 15 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "dcp-indicator.h"
#include "dcp-notch.h"
#include <linux/soc/apple/panel-notch.h>
#include <drm/drm_mode.h>
#include <linux/atomic.h>
#include <linux/backlight.h>
Expand Down Expand Up @@ -1131,6 +1132,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;

Expand Down Expand Up @@ -1442,6 +1445,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) &&
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7837,6 +7837,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);
/* Restore a soft-off panel while the IOMFB queue is still active. */
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/apple/iomfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4804,7 +4804,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);
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpu/drm/apple/iomfb_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
WRITE_ONCE(dcp->notch_scanout_y, 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;
Expand Down
54 changes: 47 additions & 7 deletions drivers/hid/hid-apple-mtp-kiwi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <linux/debugfs.h>
Expand All @@ -38,6 +48,7 @@
#include <linux/input/mt.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/soc/apple/panel-notch.h>
#include <linux/string.h>
#include <linux/unaligned.h>

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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(&notch, 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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
22 changes: 22 additions & 0 deletions drivers/soc/apple/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.

If unsure, say N.

config APPLE_DBGVIEW
tristate "Apple SoC read-only debug register views"
depends on ARCH_APPLE || COMPILE_TEST
Expand Down
3 changes: 3 additions & 0 deletions drivers/soc/apple/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
117 changes: 117 additions & 0 deletions drivers/soc/apple/panel-notch-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
/*
* KUnit tests for the built-in panel's notch geometry (panel-notch.h): the
* record's packed form, and the translation of a whole-panel touch axis onto the
* picture below a hidden notch.
*/
#include <kunit/test.h>
#include <linux/soc/apple/panel-notch.h>

/* A 1986-row panel with 74 notch rows, its touch axis 1986 positions. */
#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 n;

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);

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. */
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);
KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&n, ROWS), 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");
Loading
Loading