Skip to content
Open
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
14 changes: 12 additions & 2 deletions docs/display-failures.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ of [#18](https://github.com/standardagents/t1bridge/issues/18).
The 13,3 boot failure and 14,2 suspend failure have different triggers and
reported recovery. Keep their results separate. A report-3 awake readback is
not an illumination measurement; accepted unpark writes did not relight the
reported panels. The next experiment is observation, not another reset or
speculative power write.
panels reported in #18 and #34 at the time.

The driver previously wrote report 3 only to park on suspend, and the
firmware keeps that value across a reprobe, so a parked panel stayed dark
through every later probe while accepting frames. An attended control on a
MacBookPro14,2 (0.1.12, lid open, hardware service stopped): park the panel
from userspace, unload and load the unmodified driver, panel stays dark;
unload and load a driver that writes the awake value after the probe-time
clear, panel relights from probe alone, with no "Failed to wake" warning. The
driver now writes the awake value after the probe-time and rearm-time clears.
Whether this repairs the #18 suspend path, where the stock rearm likewise
never wrote the awake value, is still to be observed on a unit that sleeps.

## Opt-in reply evidence

Expand Down
52 changes: 40 additions & 12 deletions kernel/appletbdrm-t1/appletbdrm.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,41 @@ static bool appletbdrm_is_t1(struct appletbdrm_device *adev)
APPLETBDRM_T1_PRODUCT_ID;
}

/*
* T1 display power is HID feature report 3 on the iBridge HID interface:
* byte 1 is 0x01 (parked, dark) or 0x02 (awake). The firmware keeps the
* value across reprobes and warm reboots, so a panel parked by a previous
* suspend, or left parked by firmware recovery, stays dark however many
* frames it accepts. Write the awake value wherever the panel is (re)armed.
*/
static int appletbdrm_t1_set_display_power(struct appletbdrm_device *adev,
bool awake)
{
static const u8 report[15] = { 0x03, 0x00, 0xf4, 0x01 };
struct usb_device *udev = adev_to_udev(adev);
u8 *buffer;
int ret;

buffer = kmemdup(report, sizeof(report), GFP_KERNEL);
if (!buffer)
return -ENOMEM;
buffer[1] = awake ? 0x02 : 0x01;

ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x09, 0x21,
0x0303, APPLETBDRM_T1_HID_INTERFACE, buffer,
sizeof(report), USB_CTRL_SET_TIMEOUT);
kfree(buffer);
return ret < 0 ? ret : 0;
}

static void appletbdrm_t1_wake_display(struct appletbdrm_device *adev)
{
int ret = appletbdrm_t1_set_display_power(adev, true);

if (ret)
drm_warn(&adev->drm, "Failed to wake T1 display (%d)\n", ret);
}

struct appletbdrm_plane_state {
struct drm_shadow_plane_state base;
struct appletbdrm_fb_request *request;
Expand Down Expand Up @@ -594,6 +629,9 @@ static int appletbdrm_probe(struct usb_interface *intf,
return ret;
}

if (appletbdrm_is_t1(adev))
appletbdrm_t1_wake_display(adev);

return 0;
}

Expand All @@ -619,23 +657,13 @@ static void appletbdrm_shutdown(struct usb_interface *intf)

static void appletbdrm_t1_park(struct appletbdrm_device *adev)
{
static const u8 report[15] = { 0x03, 0x01, 0xf4, 0x01 };
struct usb_device *udev = adev_to_udev(adev);
u8 *buffer;
int ret;

appletbdrm_clear_display(adev);
appletbdrm_clear_display(adev);

buffer = kmemdup(report, sizeof(report), GFP_KERNEL);
if (!buffer)
return;

ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x09, 0x21,
0x0303, APPLETBDRM_T1_HID_INTERFACE, buffer,
sizeof(report), USB_CTRL_SET_TIMEOUT);
kfree(buffer);
if (ret < 0)
ret = appletbdrm_t1_set_display_power(adev, false);
if (ret)
drm_warn(&adev->drm, "Failed to park T1 display (%d)\n", ret);

appletbdrm_clear_display(adev);
Expand Down
6 changes: 5 additions & 1 deletion kernel/appletbdrm-t1/appletbdrm_resume.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ static int appletbdrm_t1_rearm(struct appletbdrm_device *adev)
if (ret)
return ret;
ret = appletbdrm_clear_display(adev);
if (ret)
return ret;
ret = appletbdrm_clear_display(adev);
if (ret)
return ret;

return appletbdrm_clear_display(adev);
appletbdrm_t1_wake_display(adev);
return 0;
}

static int appletbdrm_resume(struct usb_interface *intf)
Expand Down
28 changes: 20 additions & 8 deletions kernel/appletbdrm-t1/test_appletbdrm_resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <stddef.h>
#include <stdio.h>

enum step { CLEAR_OUT, CLEAR_IN, INFORMATION, READINESS, CLEAR, RESTORE };
enum step { CLEAR_OUT, CLEAR_IN, INFORMATION, READINESS, CLEAR, WAKE, RESTORE };
static const enum step recovery[] = {
CLEAR_OUT, CLEAR_IN, INFORMATION, READINESS, CLEAR, CLEAR, RESTORE,
CLEAR_OUT, CLEAR_IN, INFORMATION, READINESS, CLEAR, CLEAR, WAKE, RESTORE,
};
static enum step observed[sizeof(recovery) / sizeof(recovery[0])];
static size_t calls, fail_at, errors;
static size_t calls, fail_at, errors, warnings;
static int failure;

struct usb_device { int unused; };
Expand Down Expand Up @@ -83,6 +83,14 @@ static int drm_mode_config_helper_resume(struct drm_device *drm)
return perform(RESTORE);
}

/* The driver warns and continues when the awake write fails. */
static void appletbdrm_t1_wake_display(struct appletbdrm_device *adev)
{
(void)adev;
if (perform(WAKE))
++warnings;
}

#include "appletbdrm_resume.h"

static void test_t1_resume(void)
Expand All @@ -96,13 +104,17 @@ static void test_t1_resume(void)
struct appletbdrm_device adev = { .t1 = true, .out_ep = 2, .in_ep = 5 };
struct usb_interface intf = { .data = &adev };

calls = errors = 0;
/* A failed awake write is reported, not fatal. */
bool fatal = failed && recovery[failed - 1] != WAKE;

calls = errors = warnings = 0;
fail_at = failed;
failure = failures[error];
assert(appletbdrm_resume(&intf) == (failed ? failure : 0));
assert(calls == (failed ? failed : count));
assert(intf.needs_binding == (failed != 0));
assert(errors == (failed != 0));
assert(appletbdrm_resume(&intf) == (fatal ? failure : 0));
assert(calls == (fatal ? failed : count));
assert(intf.needs_binding == fatal);
assert(errors == fatal);
assert(warnings == (failed && !fatal));
for (size_t i = 0; i < calls; ++i)
assert(observed[i] == recovery[i]);
}
Expand Down