From 9ce9060dea91951a330feeeda3ad636bc88c642c Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sat, 8 Jan 2022 23:25:44 +0100 Subject: [PATCH] fixup! WIP: HID: transport: spi: add Apple SPI transport Signed-off-by: Janne Grunau --- drivers/hid/spi-hid/spi-hid-apple-core.c | 30 +++++++++++++----------- drivers/hid/spi-hid/spi-hid-apple-of.c | 10 +++++++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/hid/spi-hid/spi-hid-apple-core.c b/drivers/hid/spi-hid/spi-hid-apple-core.c index a36c0e928377cb..3891fb67321a30 100644 --- a/drivers/hid/spi-hid/spi-hid-apple-core.c +++ b/drivers/hid/spi-hid/spi-hid-apple-core.c @@ -52,6 +52,7 @@ #define SPI_RW_CHG_DELAY_US 200 /* 'Inter Stage Us'? */ +static const u8 spi_hid_apple_booted[4] = { 0xa0, 0x80, 0x00, 0x00 }; static const u8 spi_hid_apple_status_ok[4] = { 0xac, 0x27, 0x68, 0xd5 }; struct spihid_interface { @@ -395,17 +396,9 @@ static bool spihid_status_report(struct spihid_apple *spihid, u8 *pl, { struct device *dev = &spihid->spidev->dev; dev_dbg(dev, "%s: len: %zu", __func__, len); - if (len == 5 && pl[0] == 0xe0) { - // e0 10 00 00 00 - if (pl[1] == 0x10 && pl[2] == 0x00 && pl[3] == 0x00 && - pl[4] == 0x00) { - if (!spihid->status_booted) { - spihid->status_booted = true; - wake_up_interruptible(&spihid->wait); - } - } + if (len == 5 && pl[0] == 0xe0) return true; - } + return false; } @@ -747,9 +740,17 @@ static void spihid_process_read(struct spihid_apple *spihid) length = le16_to_cpu(pkt->length); if (length < sizeof(struct spihid_msg_hdr) + 2) { - dev_info(dev, "R short packet: len:%zu\n", length); - print_hex_dump_debug("spihid pkt:", DUMP_PREFIX_OFFSET, 16, 1, - pkt->data, length, false); + if (length == sizeof(spi_hid_apple_booted) && + !memcmp(pkt->data, spi_hid_apple_booted, length)) { + if (!spihid->status_booted) { + spihid->status_booted = true; + wake_up_interruptible(&spihid->wait); + } + } else { + dev_info(dev, "R short packet: len:%zu\n", length); + print_hex_dump_debug("spihid pkt:", DUMP_PREFIX_OFFSET, 16, 1, + pkt->data, length, false); + } return; } @@ -942,7 +943,7 @@ int spihid_apple_core_probe(struct spi_device *spi, struct spihid_apple_ops *ops // wait for boot message err = wait_event_interruptible_timeout(spihid->wait, - spihid->status_booted, 500); + spihid->status_booted, msecs_to_jiffies(500)); if (err == 0) err = -ENODEV; if (err < 0) { @@ -991,6 +992,7 @@ int spihid_apple_core_probe(struct spi_device *spi, struct spihid_apple_ops *ops error: return err; } +EXPORT_SYMBOL_GPL(spihid_apple_core_probe); int spihid_apple_core_remove(struct spi_device *spi) { diff --git a/drivers/hid/spi-hid/spi-hid-apple-of.c b/drivers/hid/spi-hid/spi-hid-apple-of.c index b445dba18b6643..381f90ec7d5a76 100644 --- a/drivers/hid/spi-hid/spi-hid-apple-of.c +++ b/drivers/hid/spi-hid/spi-hid-apple-of.c @@ -111,7 +111,12 @@ static const struct of_device_id spihid_apple_of_match[] = { { .compatible = "apple,spi-hid-transport" }, {}, }; -MODULE_DEVICE_TABLE(of, spi_hid_apple_of_match); +MODULE_DEVICE_TABLE(of, spihid_apple_of_match); + +static struct spi_device_id spihid_apple_of_id[] = { + { "spi-hid-transport", 0 }, + {} +}; static struct spi_driver spihid_apple_of_driver = { .driver = { @@ -120,9 +125,12 @@ static struct spi_driver spihid_apple_of_driver = { .of_match_table = of_match_ptr(spihid_apple_of_match), }, + .id_table = spihid_apple_of_id, .probe = spihid_apple_of_probe, .remove = spihid_apple_core_remove, .shutdown = spihid_apple_core_shutdown, }; module_spi_driver(spihid_apple_of_driver); + +MODULE_LICENSE("GPL");