Skip to content

spi: spi-apple: Implement Runtime PM support#530

Open
gg582 wants to merge 1 commit into
AsahiLinux:fairydustfrom
maintaining-m1-linux:fix-spi-apple-pm
Open

spi: spi-apple: Implement Runtime PM support#530
gg582 wants to merge 1 commit into
AsahiLinux:fairydustfrom
maintaining-m1-linux:fix-spi-apple-pm

Conversation

@gg582

@gg582 gg582 commented Jul 1, 2026

Copy link
Copy Markdown

Implementing Runtime PM support...

Just a small change

@gg582 gg582 force-pushed the fix-spi-apple-pm branch from 33ffbe9 to 4b6c68b Compare July 1, 2026 10:41
@gg582

gg582 commented Jul 1, 2026

Copy link
Copy Markdown
Author

This makes a kernel panic...patching soon.

@gg582 gg582 force-pushed the fix-spi-apple-pm branch from 79f13ac to 9a46f0e Compare July 1, 2026 13:44
@gg582

gg582 commented Jul 1, 2026

Copy link
Copy Markdown
Author

Tested on Apple MacBook Pro (13-inch, M1, 2020). done

@WhatAmISupposedToPutHere

Copy link
Copy Markdown
Member

Can you tell me how you tested it?

@gg582

gg582 commented Jul 1, 2026

Copy link
Copy Markdown
Author

good question.

first, the test result after pressing F2 at a touchbar:

Logs

yjlee@fedora:~$ sudo ./check.sh 
[sudo] yjlee 암호: 
==================================================
Target SPI Device: 235100000.spi
Path: /sys/bus/platform/devices/235100000.spi
==================================================
Enabling dynamic debug logs...
-> Dynamic debug enabled.
--------------------------------------------------
Initial Runtime PM Configuration:
--------------------------------------------------
Power Control Mode: auto
Autosuspend Delay : 100 ms
--------------------------------------------------
Starting real-time Runtime PM status monitoring...
Press [CTRL+C] to stop.

Timestamp          | Status
--------------------------------------------------
2026-07-02 07:52:30.351 | suspended
^[OQ2026-07-02 07:53:13.311 | active
2026-07-02 07:53:13.529 | suspended

Script

#!/bin/bash
# Check if running as root
if [ "$EUID" -ne 0 ]; then
  echo "Error: Please run as root (sudo ./check.sh)"
  exit 1
fi

# Find the spi-apple device directory
SPI_DIR=$(find /sys/bus/platform/devices/ -name "*.spi" | head -n 1)

if [ -z "$SPI_DIR" ]; then
  echo "Error: apple-spi device not found in sysfs."
  exit 1
fi

echo "=================================================="
echo "Target SPI Device: $(basename "$SPI_DIR")"
echo "Path: $SPI_DIR"
echo "=================================================="

# 1. Enable Dynamic Debug for Runtime PM and spi-apple
echo "Enabling dynamic debug logs..."
if [ -f /sys/kernel/debug/dynamic_debug/control ]; then
  echo 'file drivers/base/power/runtime.c +p' > /sys/kernel/debug/dynamic_debug/control
  echo 'file drivers/spi/spi-apple.c +p' > /sys/kernel/debug/dynamic_debug/control
  echo "-> Dynamic debug enabled."
else
  echo "-> Warning: /sys/kernel/debug/dynamic_debug/control not found."
  echo "   Make sure CONFIG_DYNAMIC_DEBUG is enabled in your kernel."
fi

# 2. Check current configuration
echo "--------------------------------------------------"
echo "Initial Runtime PM Configuration:"
echo "--------------------------------------------------"
if [ -f "$SPI_DIR/power/control" ]; then
  echo "Power Control Mode: $(cat "$SPI_DIR/power/control")"
else
  echo "Power Control Mode: N/A"
fi

if [ -f "$SPI_DIR/power/autosuspend_delay_ms" ]; then
  echo "Autosuspend Delay : $(cat "$SPI_DIR/power/autosuspend_delay_ms") ms"
else
  echo "Autosuspend Delay : N/A"
fi
echo "--------------------------------------------------"

# 3. Monitor state changes
echo "Starting real-time Runtime PM status monitoring..."
echo "Press [CTRL+C] to stop."
echo ""
echo "Timestamp          | Status"
echo "--------------------------------------------------"

while true; do
  STATUS=$(cat "$SPI_DIR/power/runtime_status" 2>/dev/null)
  TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S.%3N")
  
  if [ "$STATUS" != "$LAST_STATUS" ]; then
    echo "$TIMESTAMP | $STATUS"
    LAST_STATUS=$STATUS
  fi
  sleep 0.05
done

@gg582

gg582 commented Jul 1, 2026

Copy link
Copy Markdown
Author

@gg582

gg582 commented Jul 3, 2026

Copy link
Copy Markdown
Author

A feature is okay after resume, no long delay when using touch bars...I will submit a full dmesg after fixing another PR's bluetooth power manager

Signed-off-by: Lee Yunjin <gzblues61@gmail.com>
@gg582 gg582 force-pushed the fix-spi-apple-pm branch from 9a46f0e to 14013af Compare July 3, 2026 13:55
@gg582

gg582 commented Jul 3, 2026

Copy link
Copy Markdown
Author
[    2.485335] apple-spi 235104000.spi: Runtime PM usage count underflow!
[    2.486563] apple-spi 23510c000.spi: Runtime PM usage count underflow!
[    2.488883] apple-spi 235100000.spi: Runtime PM usage count underflow!
[    2.687906] spi-hid-apple-of spi1.0: limiting the number of devices to mngt, kbd and mouse
[    2.697780] input: Apple SPI Trackpad as /devices/platform/soc/23510c000.spi/spi_master/spi1/spi1.0/001C:05AC:0341.0002/input/input0
[    2.697904] magicmouse 001C:05AC:0341.0002: input,hidraw0: SPI HID v1.75 Mouse [Apple SPI Trackpad] on spi1.0 (2)
[    2.700662] input: Apple SPI Keyboard as /devices/platform/soc/23510c000.spi/spi_master/spi1/spi1.0/001C:05AC:0341.0001/input/input1
[    2.721739] apple 001C:05AC:0341.0001: input,hidraw1: SPI HID v1.75 Keyboard [Apple SPI Keyboard] on spi1.0 (1)
[    6.214999] input: MacBookPro17,1 Touch Bar as /devices/platform/soc/235100000.spi/spi_master/spi2/spi2.0/input/input2
[    6.375615] spi-nor spi0.0: supply vcc not found, using dummy regulator
[    6.382756] 1 fixed-partitions partitions found on MTD device spi0.0
[    6.382758] Creating 1 MTD partitions on "spi0.0":

underflow detected. Currently fixing

@gg582

gg582 commented Jul 4, 2026

Copy link
Copy Markdown
Author

root@fedora:/home/yjlee# dmesg | grep apple-spi

now clean...yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants