Add Apple SPI keyboard and trackpad driver
Subsystems (5)
v6 cover Add Apple SPI keyboard and trackpad driver
This changeset adds a driver for the SPI keyboard and trackpad on recent MacBook's and MacBook Pro's. The driver has seen a fair amount of use over the last 2 years (basically anybody running linux on these machines), with only relatively small changes in the last year or so. For those interested, the driver development has been hosted at
https://github.com/cb22/macbook12-spi-driver/ (as well as my clone at
https://github.com/roadrunner2/macbook12-spi-driver/).
The first patch fixes a problem during config. While it affects the drm tree, Andrzej Hajda has given his ok for this patch to be taken via the input tree because the second patch here depends on it.
The second patch contains the new applespi driver.
Changes in v6:
Applied all feedback from review by Andy Shevchenko:
- use memchr() and friends instead of hand-rolled loops
- minor code tweak
The full set of changes to applespi can be viewed at
https://github.com/roadrunner2/macbook12-spi-driver/ as individual commits 36afd70..fa81d40 in the upstreaming-review branch.
Ronald Tschalär (2):
drm/bridge: sil_sii8620: make remote control optional.
Input: add Apple SPI keyboard and trackpad driver.
drivers/gpu/drm/bridge/Kconfig | 3 +- drivers/gpu/drm/bridge/sil-sii8620.c | 10 +- drivers/input/keyboard/Kconfig | 15 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/applespi.c | 1975 +++++++++++++++++++++++ drivers/input/keyboard/applespi.h | 29 + drivers/input/keyboard/applespi_trace.h | 94 ++ 7 files changed, 2122 insertions(+), 5 deletions(-) create mode 100644 drivers/input/keyboard/applespi.c create mode 100644 drivers/input/keyboard/applespi.h create mode 100644 drivers/input/keyboard/applespi_trace.h
Signature · 1 line
2.20.1
PATCH v6 1/2 drm/bridge: sil_sii8620: make remote control optional.
commit d6abe6df706c (drm/bridge: sil_sii8620: do not have a dependency of RC_CORE) changed the driver to select both RC_CORE and INPUT. However, this causes problems with other drivers, in particular an input driver that depends on MFD_INTEL_LPSS_PCI (to be added in a separate commit):
drivers/clk/Kconfig:9:error: recursive dependency detected!
drivers/clk/Kconfig:9: symbol COMMON_CLK is selected by MFD_INTEL_LPSS drivers/mfd/Kconfig:566: symbol MFD_INTEL_LPSS is selected by MFD_INTEL_LPSS_PCI drivers/mfd/Kconfig:580: symbol MFD_INTEL_LPSS_PCI is implied by KEYBOARD_APPLESPI drivers/input/keyboard/Kconfig:73: symbol KEYBOARD_APPLESPI depends on INPUT drivers/input/Kconfig:8: symbol INPUT is selected by DRM_SIL_SII8620 drivers/gpu/drm/bridge/Kconfig:83: symbol DRM_SIL_SII8620 depends on DRM_BRIDGE drivers/gpu/drm/bridge/Kconfig:1: symbol DRM_BRIDGE is selected by DRM_PL111 drivers/gpu/drm/pl111/Kconfig:1: symbol DRM_PL111 depends on COMMON_CLK
According to the docs and general consensus, select should only be used for non user-visible symbols, but both RC_CORE and INPUT are user-visible. Furthermore almost all other references to INPUT throughout the kernel config are depends, not selects. For this reason the first part of this change reverts commit d6abe6df706c.
In order to address the original reason for commit d6abe6df706c, namely that not all boards use the remote controller functionality and hence should not need have to deal with RC_CORE, the second part of this change now makes the remote control support in the driver optional and contingent on RC_CORE being defined. And with this the hard dependency on INPUT also goes away as that is only needed if RC_CORE is defined (which in turn already depends on INPUT).
--- drivers/gpu/drm/bridge/Kconfig | 3 +-- drivers/gpu/drm/bridge/sil-sii8620.c | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/bridge/Kconfig +1 -2
@@ -85,8 +85,7 @@ config DRM_SIL_SII8620 depends on OF select DRM_KMS_HELPER imply EXTCON - select INPUT - select RC_CORE + imply RC_CORE help Silicon Image SII8620 HDMI/MHL bridge chip driver.
drivers/gpu/drm/bridge/sil-sii8620.c +7 -3
@@ -1763,10 +1763,8 @@ static bool sii8620_rcp_consume(struct sii8620 *ctx, u8 scancode) scancode &=MHL_RCP_KEY_ID_MASK ; -if (!ctx->rc_dev) { -dev_dbg (ctx->dev,"RCP input device not initialized\n" ); +if (!IS_ENABLED (CONFIG_RC_CORE ) || !ctx->rc_dev)return false; - }if (pressed)rc_keydown (ctx->rc_dev,RC_PROTO_CEC , scancode,0 );
@@ -2103,6 +2101,9 @@ static void sii8620_init_rcp_input_dev(struct sii8620 *ctx)struct rc_dev *rc_dev;int ret; +if (!IS_ENABLED (CONFIG_RC_CORE )) +return ; + rc_dev =rc_allocate_device (RC_DRIVER_SCANCODE );if (!rc_dev) {dev_err (ctx->dev,"Failed to allocate RC device\n" );
@@ -2217,6 +2218,9 @@ static void sii8620_detach(struct drm_bridge *bridge) {struct sii8620 *ctx =bridge_to_sii8620 (bridge); +if (!IS_ENABLED (CONFIG_RC_CORE )) +return ; +rc_unregister_device (ctx->rc_dev); }
Signature · 1 line
2.20.1
PATCH v6 2/2 Input: add Apple SPI keyboard and trackpad driver.
In reply to Ronald TschalärThe keyboard and trackpad on recent MacBook's (since 8,1) and MacBookPro's (13,* and 14,*) are attached to an SPI controller instead of USB, as previously. The higher level protocol is not publicly documented and hence has been reverse engineered. As a consequence there are still a number of unknown fields and commands. However, the known parts have been working well and received extensive testing and use.
In order for this driver to work, the proper SPI drivers need to be loaded too; for MB8,1 these are spi_pxa2xx_platform and spi_pxa2xx_pci; for all others they are spi_pxa2xx_platform and intel_lpss_pci. For this reason enabling this driver in the config implies enabling the above drivers.
--- drivers/input/keyboard/Kconfig | 15 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/applespi.c | 1975 +++++++++++++++++++++++ drivers/input/keyboard/applespi.h | 29 + drivers/input/keyboard/applespi_trace.h | 94 ++ 5 files changed, 2114 insertions(+) create mode 100644 drivers/input/keyboard/applespi.c create mode 100644 drivers/input/keyboard/applespi.h create mode 100644 drivers/input/keyboard/applespi_trace.h
drivers/input/keyboard/Kconfig +15 -0
@@ -70,6 +70,21 @@ config KEYBOARD_AMIGA config ATARI_KBD_CORE bool +config KEYBOARD_APPLESPI + tristate "Apple SPI keyboard and trackpad" + depends on ACPI && EFI + depends on SPI + depends on X86 || COMPILE_TEST + imply SPI_PXA2XX + imply SPI_PXA2XX_PCI + imply MFD_INTEL_LPSS_PCI + help + Say Y here if you are running Linux on any Apple MacBook8,1 or later, + or any MacBookPro13,* or MacBookPro14,*. + + To compile this driver as a module, choose M here: the + module will be called applespi. + config KEYBOARD_ATARI tristate "Atari keyboard" depends on ATARI
drivers/input/keyboard/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_KEYBOARD_ADP5520) += adp5520-keys.o obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o obj-$(CONFIG_KEYBOARD_ADP5589) += adp5589-keys.o obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o +obj-$(CONFIG_KEYBOARD_APPLESPI) += applespi.o obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o obj-$(CONFIG_KEYBOARD_BCM) += bcm-keypad.o
drivers/input/keyboard/applespi.c new file +1975 -0
1,975 lines not on this page · raw message
drivers/input/keyboard/applespi.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* MacBook (Pro) SPI keyboard and touchpad driver +* +* Copyright (c) 2015-2019 Federico Lorenzi +* Copyright (c) 2017-2019 Ronald Tschalär +*/ + +#ifndef _APPLESPI_H_ +#define _APPLESPI_H_ + +enum applespi_evt_type { +ET_CMD_TP_INI =BIT (0 ), +ET_CMD_BL =BIT (1 ), +ET_CMD_CL =BIT (2 ), +ET_RD_KEYB =BIT (8 ), +ET_RD_TPAD =BIT (9 ), +ET_RD_UNKN =BIT (10 ), +ET_RD_IRQ =BIT (11 ), +ET_RD_CRC =BIT (12 ), +}; + +enum applespi_pkt_type { +PT_READ , +PT_WRITE , +PT_STATUS , +}; + +#endif /* _APPLESPI_H_ */
drivers/input/keyboard/applespi_trace.h new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.20.1