Skip to contentSkip to conversation

Apple M1 laptop keyboard support

PATCH In review Mark Kettenis 2 participants 5 messages Jan 23, 2022 – Feb 11, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Apple M1 laptop keyboard support

This short series implements support for the laptop keyboards on the Apple Silicon Mac laptops. These keyboards are connected to an SPI bus, so this adds a driver for the SPI controller integrated on the SoC, as well as the driver for the keyboard itself. This makes it possible to interact with U-Boot and EFI applications without the need for an external USB keyboard.

ChangeLog:

v2: - Drop delay after enabling controller
- Check for errors in spi calls
- Add comments

Mark Kettenis (2):
spi: apple: Add driver for Apple SPI controller
input: apple: Add support for Apple SPI keyboard

 arch/arm/Kconfig              |   2 +
 configs/apple_m1_defconfig    |   1 +
 drivers/input/Kconfig         |   8 +
 drivers/input/Makefile        |   1 +
 drivers/input/apple_spi_kbd.c | 271 ++++++++++++++++++++++++++++++++
 drivers/spi/Kconfig           |   7 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/apple_spi.c       | 285 ++++++++++++++++++++++++++++++++++
 include/configs/apple.h       |   2 +-
 9 files changed, 577 insertions(+), 1 deletion(-)
 create mode 100644 drivers/input/apple_spi_kbd.c
 create mode 100644 drivers/spi/apple_spi.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 spi: apple: Add driver for Apple SPI controller

Add a driver for the SPI controller integrated on Apple SoCs. This is necessary to support the keyboard on Apple Silicon laopts since their keyboard uses an Apple-specific HID over SPI protocol.

Tested on: Macbook Air M1

---

ChangeLog:

v2: - Add comments

 arch/arm/Kconfig        |   2 +
 drivers/spi/Kconfig     |   7 +
 drivers/spi/Makefile    |   1 +
 drivers/spi/apple_spi.c | 285 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 295 insertions(+)
 create mode 100644 drivers/spi/apple_spi.c
arch/arm/Kconfig +2 -0
index 14c83ea19e..af0be00f6d 100644
@@ -937,6 +937,7 @@ config ARCH_APPLE
 	select DM_MAILBOX
 	select DM_RESET
 	select DM_SERIAL
+	select DM_SPI
 	select DM_USB
 	select DM_VIDEO
 	select IOMMU
@@ -946,6 +947,7 @@ config ARCH_APPLE
 	select POSITION_INDEPENDENT
 	select POWER_DOMAIN
 	select REGMAP
+	select SPI
 	select SYSCON
 	select SYSRESET
 	select SYSRESET_WATCHDOG
drivers/spi/Kconfig +7 -0
index d07e9a28af..0a6a85f9c4 100644
@@ -50,6 +50,13 @@ config ALTERA_SPI
 	  IP core. Please find details on the "Embedded Peripherals IP
 	  User Guide" of Altera.
 
+config APPLE_SPI
+	bool "Apple SPI driver"
+	default y if ARCH_APPLE
+	help
+	  Enable the Apple SPI driver. This driver can be used to
+	  access the SPI flash and keyboard on machines based on Apple SoCs.
+
 config ATCSPI200_SPI
 	bool "Andestech ATCSPI200 SPI driver"
 	help
drivers/spi/Makefile +1 -0
index d2f24bccef..bea746f3e3 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_SPI_MEM) += spi-mem-nodm.o
 endif
 
 obj-$(CONFIG_ALTERA_SPI) += altera_spi.o
+obj-$(CONFIG_APPLE_SPI) += apple_spi.o
 obj-$(CONFIG_ATH79_SPI) += ath79_spi.o
 obj-$(CONFIG_ATMEL_QSPI) += atmel-quadspi.o
 obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
drivers/spi/apple_spi.c new file +285 -0

285 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/2] spi: apple: Add driver for Apple SPI controller

Quoted 8 lines · Mark Kettenis

Add a driver for the SPI controller integrated on Apple SoCs. This is necessary to support the keyboard on Apple Silicon laopts since their keyboard uses an Apple-specific HID over SPI protocol.

Tested on: Macbook Air M1

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v2 2/2 input: apple: Add support for Apple SPI keyboard

In reply to Mark Kettenis

This driver adds support for the keyboard on Apple Silicon laptops. The controller for this keyboard sits on an SPI bus and uses an Apple-specific HID over SPI protocol. The packets sent by this controller for key presses and key releases are fairly simple and are decoded directly by the code in this driver and converted into standard Linux keycodes. The same controller handles the touchpad found on these laptops. Packets for touchpad events are simply ignored.

Tested on: Macbook Air M1

---

ChangeLog:

v2: - Drop delay after enabling controller
- Check for errors in spi calls
- Add comments

 configs/apple_m1_defconfig    |   1 +
 drivers/input/Kconfig         |   8 +
 drivers/input/Makefile        |   1 +
 drivers/input/apple_spi_kbd.c | 271 ++++++++++++++++++++++++++++++++++
 include/configs/apple.h       |   2 +-
 5 files changed, 282 insertions(+), 1 deletion(-)
 create mode 100644 drivers/input/apple_spi_kbd.c
configs/apple_m1_defconfig +1 -0
index 1528217b17..433cc62334 100644
@@ -15,5 +15,6 @@ CONFIG_NVME_APPLE=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_KEYBOARD=y
+CONFIG_APPLE_SPI_KEYB=y
 CONFIG_VIDEO_SIMPLE=y
 # CONFIG_GENERATE_SMBIOS_TABLE is not set
drivers/input/Kconfig +8 -0
index 0b753f37bf..2718b3674a 100644
@@ -47,6 +47,14 @@ config KEYBOARD
 	  and is only used by novena. For new boards, use driver model
 	  instead.
 
+config APPLE_SPI_KEYB
+	bool "Enable Apple SPI keyboard support"
+	depends on DM_KEYBOARD && DM_SPI
+	help
+	  This adds a driver for the keyboards found on various
+	  laptops based on Apple SoCs. These keyboards use an
+	  Apple-specific HID-over-SPI protocol.
+
 config CROS_EC_KEYB
 	bool "Enable Chrome OS EC keyboard support"
 	depends on INPUT
drivers/input/Makefile +1 -0
index e440c921e4..b1133f772f 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_$(SPL_TPL_)DM_KEYBOARD) += input.o keyboard-uclass.o
 
 ifndef CONFIG_SPL_BUILD
 
+obj-$(CONFIG_APPLE_SPI_KEYB) += apple_spi_kbd.o
 obj-$(CONFIG_I8042_KEYB) += i8042.o
 obj-$(CONFIG_TEGRA_KEYBOARD) += input.o tegra-kbc.o
 obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
drivers/input/apple_spi_kbd.c new file +271 -0

271 lines not on this page · raw message

include/configs/apple.h +1 -1
index 47faad8150..f12e9bdef5 100644
@@ -5,7 +5,7 @@
 
 /* Environment */
 #define ENV_DEVICE_SETTINGS \
-	"stdin=serial,usbkbd\0" \
+	"stdin=serial,usbkbd,spikbd\0" \
 	"stdout=serial,vidconsole\0" \
 	"stderr=serial,vidconsole\0"
 
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v2 2/2] input: apple: Add support for Apple SPI keyboard

Quoted 9 lines · Mark Kettenis

This driver adds support for the keyboard on Apple Silicon laptops. The controller for this keyboard sits on an SPI bus and uses an Apple-specific HID over SPI protocol. The packets sent by this controller for key presses and key releases are fairly simple and are decoded directly by the code in this driver and converted into standard Linux keycodes. The same controller handles the touchpad found on these laptops. Packets for touchpad events are simply ignored.

Quoted 4 lines

Tested on: Macbook Air M1

Applied to u-boot/master, thanks!

Signature · 1 line
Tom