From nobody Fri Apr 3 17:33:21 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 0983A34F489 for ; Thu, 2 Apr 2026 01:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775095193; cv=none; b=qUKkiWEomPltsUWwiP8uHHE60IT8Q0YTA7ZM+CE9XlQQPaNwHhg2t8E/mIysGdsax4A44616W3QXrN+L+y13xX71NIw22tm9ER5O1oJ2/elmvuOvDNVdN9gx5gbb48qZwdQNYYr4D75t/o74cSOuwldjjQ4kffmDmFKitnnz3QM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775095193; c=relaxed/simple; bh=IsaZ710oxuBN4PiA+69dKS/EYofhjm1DhhAZbjz2WWI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PUM+s9WzWWkR5TSe6Pzm/hxf/6u2XumXpWk+Q72DcfIb06h10T7dXhxzeVGi703OiOLaU8ViixWe3l++zezMhoY9XI0bKujfnpmhOJAK7mk9YDiqZeb6SXsxL1ki4v9fq/+6eHmEHhatlsg3JfYk1DtOY/e7G1Lo58AtgB204cU= 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=M+Y59rIf; arc=none smtp.client-ip=209.85.216.53 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="M+Y59rIf" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-35d99bae2ebso281188a91.3 for ; Wed, 01 Apr 2026 18:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775095190; x=1775699990; 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=eD7F1u44Jio2+2ZFUsBLXdqQbokoRei5mkxn2sOyNEM=; b=M+Y59rIfmowLxJXl3UOfLRPIBM3hrzyEK650qtn2g2croO3QMu4QbVL2hVuD5rFkDN mqAHLihFGFyR4GulofsALlJl485BRhnQevdY9NT3JmikPPn8LxlSAtKQDDTqEv8TzYCW 1l+SVw57NOoI4PuRPha67Q+IhyRezvV0be71c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775095190; x=1775699990; 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=eD7F1u44Jio2+2ZFUsBLXdqQbokoRei5mkxn2sOyNEM=; b=o3aoDu3F/doxfKMjzWIL3WkA9CWVcIz12Ckkp6D6bFhWN0FQ4t1dgV0Le4SJ5gs+yP DIbXI+hBnNpEEmrt7X+nR9hfmOTiC0IGWgK6jvFotgmwAoCsToUjo8imAJCCUZRPGxZt 5FR2H2vPezQo7BZNAfdkYmqjZEp+CMB9afbzNPgjQuK/JJpMwRiCwP1EQ1pUCjf3sTJ+ HZ0spTY/34a8hAMDRjgi5Zi3X9dvLYPhELE6HW7NbJMNMBDEVkMmQeuN/1PQkMthHcyv wABZd7iHG1Slz8gWOGqlPHg7ZcbvlETB9VMVjgmLntNmBNdSZIdxzOL6Cyv3gEnIYDPz go7Q== X-Forwarded-Encrypted: i=1; AJvYcCX0z7qOrddIgXqoxKHjIm7t3WOacwF4O4uMI0ktppWh3U/7A5mtmDO2yIInr/mFx62bUFu6yofcAAW+4LE=@vger.kernel.org X-Gm-Message-State: AOJu0YygcaYnaLLFYi8QE651L1KS115x4SI4g554tyTn4w8UsXal3Xp2 X78DIjX2l9bmtNiw9slWx1F5ybcjvuhjxXjPulQZ/Vce4dpNEYnlc+0s1BVLV8sQRA== X-Gm-Gg: ATEYQzzD2ZVMQ71j4NKmF8FvuhndLd+Jn+YsmjqmE/QH0E0kLX+LP4i6DSdW9BSU7WU MzIgwA6xEzq+mLtSALhlkCe1tAmh9BGn4HyKKyAFNUymgJckiyt6NdNdYn1hYIRkVsMAD3Cn9z0 p8VyM4VhDTP0BqnS4G2y94d8pJdQ44DKJIZysehZrYihyDBtqkzaSHjI5lNpiekz+8H4o08Sbtj EIjOUg6cI84kGHwGHO+uIPeMpLrMBIAq4JKrjw75zarJn9Vkci/8nfw2q4nZcdYuOnXVtNaR8ZC dRjsd4uG+2hfkk/Ed/6IbKuj5lSD01/jk9QIBWfkh9QCBw0eXHuPkepe7dHj9b5QEyrEK4dmYf1 JwRwPlT1IEodnvljJoupWerIpuE7D8QUP0vIKasszYI8ASALhCh0EJfU/rjiKpzkYhRv6GzdD2F DIU/UpsNm6zVLiqweqR8Y6rkQTKVisya1LBZFYdPUtV55YEEuaFV+d/dOI3LzvrXInF3nSVO3AA boNTinXmHWrG6OVwioTm6hBEgYjBVUL9Q== X-Received: by 2002:a17:902:e54a:b0:2b0:cb96:9815 with SMTP id d9443c01a7336-2b275da7802mr13614315ad.43.1775095189867; Wed, 01 Apr 2026 18:59:49 -0700 (PDT) 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-2b27478cb4fsm11187535ad.29.2026.04.01.18.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 18:59:49 -0700 (PDT) From: Jingyuan Liang Date: Thu, 02 Apr 2026 01:59:47 +0000 Subject: [PATCH v3 10/11] HID: spi-hid: add power management implementation 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: <20260402-send-upstream-v3-10-6091c458d357@chromium.org> References: <20260402-send-upstream-v3-0-6091c458d357@chromium.org> In-Reply-To: <20260402-send-upstream-v3-0-6091c458d357@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, tfiga@chromium.org, Jingyuan Liang X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775095180; l=5452; i=jingyliang@chromium.org; s=20260213; h=from:subject:message-id; bh=IsaZ710oxuBN4PiA+69dKS/EYofhjm1DhhAZbjz2WWI=; b=sBQZ5/1CaFm4bih4+ceHjvhV3qaKwRPf7JlWoD907mU3+jK+oEsLVs4ps/CdORmGFzJTYd57q Za+4vFrNs19BHkaem3YK//a6rCIcoj3XRCtafJnCAeYZzipz0Z1T3uK X-Developer-Key: i=jingyliang@chromium.org; a=ed25519; pk=VTYSdqslTtYOjWWoIGgYoWupGWqNSidrggReKMgfPo4= Implement HID over SPI driver power management callbacks. Signed-off-by: Jingyuan Liang --- drivers/hid/spi-hid/spi-hid-acpi.c | 1 + drivers/hid/spi-hid/spi-hid-core.c | 107 +++++++++++++++++++++++++++++++++= ++++ drivers/hid/spi-hid/spi-hid-of.c | 1 + drivers/hid/spi-hid/spi-hid.h | 1 + 4 files changed, 110 insertions(+) diff --git a/drivers/hid/spi-hid/spi-hid-acpi.c b/drivers/hid/spi-hid/spi-h= id-acpi.c index 298e3ba44d8a..15cfc4e6cc2f 100644 --- a/drivers/hid/spi-hid/spi-hid-acpi.c +++ b/drivers/hid/spi-hid/spi-hid-acpi.c @@ -238,6 +238,7 @@ static struct spi_driver spi_hid_acpi_driver =3D { .driver =3D { .name =3D "spi_hid_acpi", .owner =3D THIS_MODULE, + .pm =3D &spi_hid_core_pm, .acpi_match_table =3D spi_hid_acpi_match, .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, .dev_groups =3D spi_hid_groups, diff --git a/drivers/hid/spi-hid/spi-hid-core.c b/drivers/hid/spi-hid/spi-h= id-core.c index d48175c764b9..5f7a5bb692d9 100644 --- a/drivers/hid/spi-hid/spi-hid-core.c +++ b/drivers/hid/spi-hid/spi-hid-core.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include #include @@ -244,6 +246,81 @@ static const char *spi_hid_power_mode_string(enum hids= pi_power_state power_state } } =20 +static void spi_hid_suspend(struct spi_hid *shid) +{ + int error; + struct device *dev =3D &shid->spi->dev; + + guard(mutex)(&shid->power_lock); + if (shid->power_state =3D=3D HIDSPI_OFF) + return; + + if (shid->hid) { + error =3D hid_driver_suspend(shid->hid, PMSG_SUSPEND); + if (error) { + dev_err(dev, "%s failed to suspend hid driver: %d", + __func__, error); + return; + } + } + + disable_irq(shid->spi->irq); + + clear_bit(SPI_HID_READY, &shid->flags); + + if (!device_may_wakeup(dev)) { + set_bit(SPI_HID_RESET_PENDING, &shid->flags); + + shid->ops->assert_reset(shid->ops); + + error =3D shid->ops->power_down(shid->ops); + if (error) { + dev_err(dev, "%s: could not power down.", __func__); + shid->regulator_error_count++; + shid->regulator_last_error =3D error; + return; + } + + shid->power_state =3D HIDSPI_OFF; + } +} + +static void spi_hid_resume(struct spi_hid *shid) +{ + int error; + struct device *dev =3D &shid->spi->dev; + + guard(mutex)(&shid->power_lock); + if (shid->power_state =3D=3D HIDSPI_ON) + return; + + enable_irq(shid->spi->irq); + + if (!device_may_wakeup(dev)) { + shid->ops->assert_reset(shid->ops); + + shid->ops->sleep_minimal_reset_delay(shid->ops); + + error =3D shid->ops->power_up(shid->ops); + if (error) { + dev_err(dev, "%s: could not power up.", __func__); + shid->regulator_error_count++; + shid->regulator_last_error =3D error; + return; + } + shid->power_state =3D HIDSPI_ON; + + shid->ops->deassert_reset(shid->ops); + } + + if (shid->hid) { + error =3D hid_driver_reset_resume(shid->hid); + if (error) + dev_err(dev, "%s: failed to reset resume hid driver: %d.", + __func__, error); + } +} + static void spi_hid_stop_hid(struct spi_hid *shid) { struct hid_device *hid =3D shid->hid; @@ -1200,6 +1277,13 @@ int spi_hid_core_probe(struct spi_device *spi, struc= t spihid_ops *ops, dev_err(dev, "%s: unable to request threaded IRQ.", __func__); return error; } + if (device_may_wakeup(dev)) { + error =3D dev_pm_set_wake_irq(dev, spi->irq); + if (error) { + dev_err(dev, "%s: failed to set wake IRQ.", __func__); + return error; + } + } =20 error =3D shid->ops->power_up(shid->ops); if (error) { @@ -1231,6 +1315,29 @@ void spi_hid_core_remove(struct spi_device *spi) } EXPORT_SYMBOL_GPL(spi_hid_core_remove); =20 +static int spi_hid_core_pm_suspend(struct device *dev) +{ + struct spi_hid *shid =3D dev_get_drvdata(dev); + + spi_hid_suspend(shid); + + return 0; +} + +static int spi_hid_core_pm_resume(struct device *dev) +{ + struct spi_hid *shid =3D dev_get_drvdata(dev); + + spi_hid_resume(shid); + + return 0; +} + +const struct dev_pm_ops spi_hid_core_pm =3D { + SYSTEM_SLEEP_PM_OPS(spi_hid_core_pm_suspend, spi_hid_core_pm_resume) +}; +EXPORT_SYMBOL_GPL(spi_hid_core_pm); + MODULE_DESCRIPTION("HID over SPI transport driver"); MODULE_AUTHOR("Dmitry Antipov "); MODULE_LICENSE("GPL"); diff --git a/drivers/hid/spi-hid/spi-hid-of.c b/drivers/hid/spi-hid/spi-hid= -of.c index 651456b6906d..80c481b77149 100644 --- a/drivers/hid/spi-hid/spi-hid-of.c +++ b/drivers/hid/spi-hid/spi-hid-of.c @@ -227,6 +227,7 @@ static struct spi_driver spi_hid_of_driver =3D { .driver =3D { .name =3D "spi_hid_of", .owner =3D THIS_MODULE, + .pm =3D &spi_hid_core_pm, .of_match_table =3D spi_hid_of_match, .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, .dev_groups =3D spi_hid_groups, diff --git a/drivers/hid/spi-hid/spi-hid.h b/drivers/hid/spi-hid/spi-hid.h index f5a5f4d54beb..17b2fdf192ed 100644 --- a/drivers/hid/spi-hid/spi-hid.h +++ b/drivers/hid/spi-hid/spi-hid.h @@ -41,5 +41,6 @@ int spi_hid_core_probe(struct spi_device *spi, struct spi= hid_ops *ops, void spi_hid_core_remove(struct spi_device *spi); =20 extern const struct attribute_group *spi_hid_groups[]; +extern const struct dev_pm_ops spi_hid_core_pm; =20 #endif /* SPI_HID_H */ --=20 2.53.0.1185.g05d4b7b318-goog