From nobody Thu Apr 9 16:35:00 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39B5F377026 for ; Tue, 3 Mar 2026 06:13:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772518431; cv=none; b=sVhCt4fjUfu3cYEXTVFD2YrPU2yGM9JeCkPdnStGOyQVRhe0d+cq6xITTESZq//vzo9zcPdynz5wdNVwswCifpA+jRl/5Uln+c2d8FJTrDb8yon19wTyMzFOHS5nCT+kh6IimBbd9SW2m/fQK60iLaMto0Mz5s7jp9cl4a7TKpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772518431; c=relaxed/simple; bh=ukAwqv80HxjHW+IK9yJgq5/wKBS7G8D/LoqmQK1EFpk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LkTpbPvWbJzsEDizV0cJHHhdXx5ZBTnLqkfiTHEcB8yubX9bFvWrIwlUeJ38tel9tZ3sdYvSgEbbcWfMi9uW7w7iiQ+Fi/H3p45RKO2KORKMCMlTJNbjm4FVZu5olPWXUrxsF+oZ7ZBO1BaQGNWX8yZ94sKc80cIG1kbiciPzIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=iuzj3Z8v; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="iuzj3Z8v" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2ad21f437eeso38760635ad.0 for ; Mon, 02 Mar 2026 22:13:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1772518428; x=1773123228; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=15sCyctEjRQFVPkb/OR84xqS1QIlAJCOtqS1nQXjKcg=; b=iuzj3Z8vt17PxhgK2fbqsrEiHfL8XPnAEY2CKWF9fza1M5VwY28fA6SU+4N3Hh/s3Y oDknhDqJKQQSejsdmBhWs3kAjt5mvankM5MKJyLaL386eeraUrptrhr5kpX6yk1v6gnE uhMt+eEAi7dpGcaBc3QCnGNUfgpaczh/JVoR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772518428; x=1773123228; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=15sCyctEjRQFVPkb/OR84xqS1QIlAJCOtqS1nQXjKcg=; b=coe+k4efawIRk36Oa4Dv1iMyc2iE6wwcu4WO8fyao+H5kCRsGMt/oMYGPSHunte0vP iW+edMKAcekOAIzqS7X4VsoZ70vRPfEx8x9zRHTOY70iUvLkpPEoAu1uUziUFwfXtCbS 14n8uKNjA8nUqhznOsm2SixCijTEpBzUoyZRoQpqEz/oG5FcOB31XB28FFA00fr5xDu5 SiDxDgooE3aBXlq6ZlYoZ7hV1H7shXCehaBzSoqE/M1hRsOZ+naVECYWOHblxx3orCil HcQtsyjHOmzl3B6M7crzEt41dO4JDX8GyZMi9ERSkVctdYBWOEBJJhdfv+OIjALSqwFn qcqw== X-Forwarded-Encrypted: i=1; AJvYcCWBlBEhQRblBaJeR7iIC2gvz5a00zDlIWKDFKgTeD/ru41Nzg9efFr9d3dZFfeBRftRRfuYcRoehsdyyc0=@vger.kernel.org X-Gm-Message-State: AOJu0YwjjZJ1x4fUll81uucghAXtBWuMVDvibOln4cb4t/eEwdhTGxdW r0g77IgsioflDO5lKESXelgx1W7hWzWNNub3f50+kcuyOyEIzPR6NwjHmRzcQckTjQ== X-Gm-Gg: ATEYQzwRJsAbDdEubrprtY3zm2+O6hp8B7ayi3U33tAD6Lwc9glHsTPHvwrrpGvmNR8 eZ2D++9OkbBXeGajSxiTM2Mh7PnREEZuQXVuyE6+tOyEVBLLUXBQeyoGyG5oeZXfI1kW/s1R6hp wFf04D58dJoIRPruTsGErl8AYdiPjyMIkv+jwXzjALCD2ejSnS6THhe0G9l3YKo9Ws/BS9B7+U8 u9qREuqqkqLSJZ/K32ieLxm3VdT8E3KknwpAdOriWv5PTxb7KXw4T+CmSBq6AtMvxRuDNoUYvU+ xnY8HUpoaae9OAECYo7dE44UZX74Gqw3/W+GWrNWnk54bC4nvJfIsuzmEfslzNikyyyyT4AIGXG eAbsblthWNga3GsDHD97Btobp6i+hCRnwHkIhKQ31ePQ+dGHeUWvoVb3a7voZcyCf0HJdXC0KwZ Gjs1oYZno7pkpHqdbV66/F4lFEC6+ruauFHrcRO51sa+LHtu6/GxnkKoxKqQuBLirO34GYVEIdZ 1AYxzjb3zPp1ABEn5TFbsicHWvGI8hgsg== X-Received: by 2002:a17:903:2c05:b0:2aa:e47d:e3b with SMTP id d9443c01a7336-2ae60b26667mr12872645ad.0.1772518427680; Mon, 02 Mar 2026 22:13:47 -0800 (PST) Received: from jingyliang-input-linux.c.googlers.com (111.169.168.34.bc.googleusercontent.com. [34.168.169.111]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb6fe4f3sm152639735ad.91.2026.03.02.22.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 22:13:47 -0800 (PST) From: Jingyuan Liang Date: Tue, 03 Mar 2026 06:12:55 +0000 Subject: [PATCH 03/12] HID: spi-hid: add transport driver skeleton for HID over SPI bus Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260303-send-upstream-v1-3-1515ba218f3d@chromium.org> References: <20260303-send-upstream-v1-0-1515ba218f3d@chromium.org> In-Reply-To: <20260303-send-upstream-v1-0-1515ba218f3d@chromium.org> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Mark Brown , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-input@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-trace-kernel@vger.kernel.org, devicetree@vger.kernel.org, hbarnor@chromium.org, Jingyuan Liang , Angela Czubak , Dmitry Antipov X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1772518424; l=8445; i=jingyliang@chromium.org; s=20260213; h=from:subject:message-id; bh=hQmbG/SosSqChDJrbCFC+M2uTJ1VtkZ9O9Ov/oM9YU8=; b=njmLY56TaIFOGK/q2eYvB9wP7qYKVYE7KifLU9JLXlW3x7RybE/mEcCmwgZgeTrkr5x+vIsnT JwxHlYOrQhLBHI4v2F0Bg0Kho6t2KCpaeP+ZVNRxIrsOeEgHs+csMKA X-Developer-Key: i=jingyliang@chromium.org; a=ed25519; pk=VTYSdqslTtYOjWWoIGgYoWupGWqNSidrggReKMgfPo4= From: Angela Czubak Create spi-hid folder and add Kconfig and Makefile for spi-hid driver. Add basic device structure, definitions, and probe/remove functions. Signed-off-by: Dmitry Antipov Signed-off-by: Angela Czubak Signed-off-by: Jingyuan Liang --- drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/spi-hid/Kconfig | 15 +++ drivers/hid/spi-hid/Makefile | 9 ++ drivers/hid/spi-hid/spi-hid-core.c | 212 +++++++++++++++++++++++++++++++++= ++++ 5 files changed, 240 insertions(+) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 920a64b66b25..c6ae23bfb75d 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -1434,6 +1434,8 @@ source "drivers/hid/bpf/Kconfig" =20 source "drivers/hid/i2c-hid/Kconfig" =20 +source "drivers/hid/spi-hid/Kconfig" + source "drivers/hid/intel-ish-hid/Kconfig" =20 source "drivers/hid/amd-sfh-hid/Kconfig" diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 361a7daedeb8..6b43e789b39a 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -169,6 +169,8 @@ obj-$(CONFIG_USB_KBD) +=3D usbhid/ =20 obj-$(CONFIG_I2C_HID_CORE) +=3D i2c-hid/ =20 +obj-$(CONFIG_SPI_HID_CORE) +=3D spi-hid/ + obj-$(CONFIG_INTEL_ISH_HID) +=3D intel-ish-hid/ =20 obj-$(CONFIG_AMD_SFH_HID) +=3D amd-sfh-hid/ diff --git a/drivers/hid/spi-hid/Kconfig b/drivers/hid/spi-hid/Kconfig new file mode 100644 index 000000000000..836fdefe8345 --- /dev/null +++ b/drivers/hid/spi-hid/Kconfig @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (c) 2021 Microsoft Corporation +# + +menuconfig SPI_HID + tristate "SPI HID support" + default y + depends on SPI + +if SPI_HID + +config SPI_HID_CORE + tristate +endif diff --git a/drivers/hid/spi-hid/Makefile b/drivers/hid/spi-hid/Makefile new file mode 100644 index 000000000000..92e24cddbfc2 --- /dev/null +++ b/drivers/hid/spi-hid/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the SPI HID input drivers +# +# Copyright (c) 2021 Microsoft Corporation +# + +obj-$(CONFIG_SPI_HID_CORE) +=3D spi-hid.o +spi-hid-objs =3D spi-hid-core.o diff --git a/drivers/hid/spi-hid/spi-hid-core.c b/drivers/hid/spi-hid/spi-h= id-core.c new file mode 100644 index 000000000000..5431c60efd50 --- /dev/null +++ b/drivers/hid/spi-hid/spi-hid-core.c @@ -0,0 +1,212 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * HID over SPI protocol implementation + * + * Copyright (c) 2021 Microsoft Corporation + * Copyright (c) 2026 Google LLC + * + * This code is partly based on "HID over I2C protocol implementation: + * + * Copyright (c) 2012 Benjamin Tissoires + * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France + * Copyright (c) 2012 Red Hat, Inc + * + * which in turn is partly based on "USB HID support for Linux": + * + * Copyright (c) 1999 Andreas Gal + * Copyright (c) 2000-2005 Vojtech Pavlik + * Copyright (c) 2005 Michael Haboustak for Concept2= , Inc + * Copyright (c) 2007-2008 Oliver Neukum + * Copyright (c) 2006-2010 Jiri Kosina + */ + +#include +#include +#include +#include +#include +#include +#include + +/* struct spi_hid_conf - Conf provided to the core */ +struct spi_hid_conf { + u32 input_report_header_address; + u32 input_report_body_address; + u32 output_report_address; + u8 read_opcode; + u8 write_opcode; +}; + +/** + * struct spihid_ops - Ops provided to the core + * @power_up: do sequencing to power up the device + * @power_down: do sequencing to power down the device + * @assert_reset: do sequencing to assert the reset line + * @deassert_reset: do sequencing to deassert the reset line + */ +struct spihid_ops { + int (*power_up)(struct spihid_ops *ops); + int (*power_down)(struct spihid_ops *ops); + int (*assert_reset)(struct spihid_ops *ops); + int (*deassert_reset)(struct spihid_ops *ops); + void (*sleep_minimal_reset_delay)(struct spihid_ops *ops); +}; + +/* Driver context */ +struct spi_hid { + struct spi_device *spi; /* spi device. */ + struct hid_device *hid; /* pointer to corresponding HID dev. */ + + struct spihid_ops *ops; + struct spi_hid_conf *conf; + + enum hidspi_power_state power_state; + + u32 regulator_error_count; + int regulator_last_error; + u32 bus_error_count; + int bus_last_error; + u32 dir_count; /* device initiated reset count. */ +}; + +static const char *spi_hid_power_mode_string(enum hidspi_power_state power= _state) +{ + switch (power_state) { + case HIDSPI_ON: + return "d0"; + case HIDSPI_SLEEP: + return "d2"; + case HIDSPI_OFF: + return "d3"; + default: + return "unknown"; + } +} + +static irqreturn_t spi_hid_dev_irq(int irq, void *_shid) +{ + return IRQ_HANDLED; +} + +static ssize_t bus_error_count_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct spi_hid *shid =3D dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d (%d)\n", + shid->bus_error_count, shid->bus_last_error); +} +static DEVICE_ATTR_RO(bus_error_count); + +static ssize_t regulator_error_count_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct spi_hid *shid =3D dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d (%d)\n", + shid->regulator_error_count, + shid->regulator_last_error); +} +static DEVICE_ATTR_RO(regulator_error_count); + +static ssize_t device_initiated_reset_count_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct spi_hid *shid =3D dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", shid->dir_count); +} +static DEVICE_ATTR_RO(device_initiated_reset_count); + +static struct attribute *spi_hid_attrs[] =3D { + &dev_attr_bus_error_count.attr, + &dev_attr_regulator_error_count.attr, + &dev_attr_device_initiated_reset_count.attr, + NULL /* Terminator */ +}; + +static const struct attribute_group spi_hid_group =3D { + .attrs =3D spi_hid_attrs, +}; + +const struct attribute_group *spi_hid_groups[] =3D { + &spi_hid_group, + NULL +}; +EXPORT_SYMBOL_GPL(spi_hid_groups); + +int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops, + struct spi_hid_conf *conf) +{ + struct device *dev =3D &spi->dev; + struct spi_hid *shid; + int error; + + if (spi->irq <=3D 0) + return dev_err_probe(dev, spi->irq ?: -EINVAL, "Missing IRQ\n"); + + shid =3D devm_kzalloc(dev, sizeof(*shid), GFP_KERNEL); + if (!shid) + return -ENOMEM; + + shid->spi =3D spi; + shid->power_state =3D HIDSPI_ON; + shid->ops =3D ops; + shid->conf =3D conf; + + spi_set_drvdata(spi, shid); + + /* + * At the end of probe we initialize the device: + * 0) assert reset, bias the interrupt line + * 1) sleep minimal reset delay + * 2) request IRQ + * 3) power up the device + * 4) deassert reset (high) + * After this we expect an IRQ with a reset response. + */ + + shid->ops->assert_reset(shid->ops); + + shid->ops->sleep_minimal_reset_delay(shid->ops); + + error =3D devm_request_threaded_irq(dev, spi->irq, NULL, spi_hid_dev_irq, + IRQF_ONESHOT, dev_name(&spi->dev), shid); + if (error) { + dev_err(dev, "%s: unable to request threaded IRQ.", __func__); + return error; + } + + error =3D shid->ops->power_up(shid->ops); + if (error) { + dev_err(dev, "%s: could not power up.", __func__); + return error; + } + + shid->ops->deassert_reset(shid->ops); + + dev_dbg(dev, "%s: d3 -> %s.", __func__, + spi_hid_power_mode_string(shid->power_state)); + + return 0; +} +EXPORT_SYMBOL_GPL(spi_hid_core_probe); + +void spi_hid_core_remove(struct spi_device *spi) +{ + struct spi_hid *shid =3D spi_get_drvdata(spi); + struct device *dev =3D &spi->dev; + int error; + + shid->ops->assert_reset(shid->ops); + error =3D shid->ops->power_down(shid->ops); + if (error) + dev_err(dev, "failed to disable regulator."); +} +EXPORT_SYMBOL_GPL(spi_hid_core_remove); + +MODULE_DESCRIPTION("HID over SPI transport driver"); +MODULE_AUTHOR("Dmitry Antipov "); +MODULE_LICENSE("GPL"); --=20 2.53.0.473.g4a7958ca14-goog