From nobody Thu Apr 9 16:34:57 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 DD13D382F28 for ; Tue, 3 Mar 2026 06:13:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772518440; cv=none; b=ENZDdiivxCYVek3eJN1/1Ff9FqrlKM6VuaBaQauSfYdsPn1ZVK/S+EkdBPR3TofV/dSWOHtYlM283n/NyjtifunQmL/8ypFTe41ZbR20bW25EA4SPWSwFKJ8fGGtoOK/m5Km3Ec5L9IB25oZoTewuB40AVMkq6OE+3YJIKXXfZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772518440; c=relaxed/simple; bh=9VBbxDeCBOwEkQqdAXnbqlSFol8sG1Sk8yHeuXnwVc8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k+XfOu7+7PiiQJhjcGUWX3L4+PFco8H7gNsvXp6HghBSys6W9IhLb2VFlwOJ1b/VgrNmaS8xygS1fBCHvqTEYXCsvH6bhSNzAFFyS52/Y1U8Euhw43lv+PumYxFawR9A4xF2thkm8IkKIKIQaAg6M5VZg2ymCN/jmT3MGVtJulY= 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=ZgRE2rPw; arc=none smtp.client-ip=209.85.214.180 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="ZgRE2rPw" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2ad9a9be502so36331375ad.0 for ; Mon, 02 Mar 2026 22:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1772518436; x=1773123236; 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=7CYLqWK3CZS7x6XnoVJUokrAtWYl16nmLP+jWdmHpw8=; b=ZgRE2rPwuTae0hGxG2C2ywFa0J02lqELncNOzg8b0JII/sW4eF9RT9I4Rco4iTmql3 6UV0+Ob991A3hskKPug+BNWNGkgU94gl2vUqdr6OMgI7winH5zhFH5jaWUYuZEqLAx+L dJdjEVad7WChPSwtooyZD3WSz9thGmw72XD/I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772518436; x=1773123236; 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=7CYLqWK3CZS7x6XnoVJUokrAtWYl16nmLP+jWdmHpw8=; b=jaE8kER/Gv3kCgJs54K3B4BTd+TR9ZNGnr8QVAuXygm+BVhpImY2f5o6+zbJ2fAHMb bz5sjia865CiOsp9sPG3s8OpDsKtz5Q91UEOl0ErVmofQ1Y7Pib0sHZeYfAZ+X9pEqOJ GKgpXlJmSy+oBi5FZUkzJ//M9qGuHeBRylvehSyJfzIy6t0EYXmJOcbBLpxOCaJGPrxs +hmLxCKZyNbAuReBjNCZEToNXixRswEvR6/rG+2RfBn9NbPRTmZZX9Hk94VtT5WwRodR RSRN+2MsJ2tEUEE9f0qvBhr6zy1pCmxtiT4PmwstHrW/92a1fO4A4b9cf8A2ZedplpV9 tzlw== X-Forwarded-Encrypted: i=1; AJvYcCXzuvQb62Eh2EYsdnjB/QQWuDb6GxeCVxcYNB6VxrVqnDFS4vlLPPVbFpfarHpHcmB8+fZZBS2Adl1kMZ4=@vger.kernel.org X-Gm-Message-State: AOJu0YzJzOsm9k497MOvtX/UIcM040XAnvRv5lY1ZOs9r3GK9UO+ESiO dfxzNxTPqzX9WPqJEbWKCLgFp4LBr6wz2j6WnsXz2bdJ0v3BG21/jwMcHO3MMbQf2A== X-Gm-Gg: ATEYQzxpqbNRBdA3BcRymKX4tZ9CL+2EkHakX6sK6v6gwa/F/lQwstT3CDcDr7eHgpf b8MPkWoXfQYST9KegeZQ5isNAzu9PZhssMj6Di3iu27nr137GFigV1LkAIXifXHOnbts3vFLLEQ sl/NjfFZ4rkYe6N8kBMtgMCMTI6jmgxoHP8p/0PGXkW6DdYjj7bAHcWW8RclXTQRf1UkoaMjuNg zkcUCyv0IzRlltgg0bn1QK4IWS8CEp535nGGgrz4kk20EVdYw02TMlOv3HleugkboAXHnBtVeEj jwdyKyEOqqfK/oJ0HYjUDitF0nFP+AUZwNvUBNcpYc0TeFLLoccXdof/zICrV/KXnEHIZ12+4q6 jjWAxqaICf94hTKIrpnvLjYWGZkYMLqjMY67n1I01m5l6N7XcTU+/zdYDUPk1TFD/6jdOS8mMNm yLEbgEasByOo+M0DwuzYOCTNZ/MQ9mxpTPbWOcBCUBRkDVD+gkMdtb+PztYMOVVOr2YC8JnyxL2 UMMwZDrj+WBfPUJz4nfrpG5acpE8mgZ2g== X-Received: by 2002:a17:902:f541:b0:2ab:344e:1413 with SMTP id d9443c01a7336-2ae2e46c080mr134889525ad.34.1772518436078; Mon, 02 Mar 2026 22:13:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 22:13:55 -0800 (PST) From: Jingyuan Liang Date: Tue, 03 Mar 2026 06:13:03 +0000 Subject: [PATCH 11/12] HID: spi-hid: add panel follower support 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-11-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 X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1772518424; l=10421; i=jingyliang@chromium.org; s=20260213; h=from:subject:message-id; bh=9VBbxDeCBOwEkQqdAXnbqlSFol8sG1Sk8yHeuXnwVc8=; b=jZHqmh4vIgwl89Ot2YigAOzVXGc+PbFSOe3mkaSX/v16i2WnGSlJIczYjrPpNxw149oHIEuXm 70WzKA8HtINA03O6OgK0QyBvu2GFsn6i7kFxc3m1WQDPblsHJcn13Kf X-Developer-Key: i=jingyliang@chromium.org; a=ed25519; pk=VTYSdqslTtYOjWWoIGgYoWupGWqNSidrggReKMgfPo4= Add support to spi-hid to be a panel follower. Signed-off-by: Jingyuan Liang --- drivers/hid/spi-hid/spi-hid-core.c | 199 +++++++++++++++++++++++++++++----= ---- drivers/hid/spi-hid/spi-hid-core.h | 7 ++ 2 files changed, 163 insertions(+), 43 deletions(-) diff --git a/drivers/hid/spi-hid/spi-hid-core.c b/drivers/hid/spi-hid/spi-h= id-core.c index 797ba99394f9..893a0d4642d2 100644 --- a/drivers/hid/spi-hid/spi-hid-core.c +++ b/drivers/hid/spi-hid/spi-hid-core.c @@ -238,21 +238,21 @@ static const char *spi_hid_power_mode_string(enum hid= spi_power_state power_state } } =20 -static void spi_hid_suspend(struct spi_hid *shid) +static int spi_hid_suspend(struct spi_hid *shid) { int error; struct device *dev =3D &shid->spi->dev; =20 guard(mutex)(&shid->power_lock); if (shid->power_state =3D=3D HIDSPI_OFF) - return; + return 0; =20 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; + return error; } } =20 @@ -270,21 +270,22 @@ static void spi_hid_suspend(struct spi_hid *shid) dev_err(dev, "%s: could not power down.", __func__); shid->regulator_error_count++; shid->regulator_last_error =3D error; - return; + return error; } =20 shid->power_state =3D HIDSPI_OFF; } + return 0; } =20 -static void spi_hid_resume(struct spi_hid *shid) +static int spi_hid_resume(struct spi_hid *shid) { int error; struct device *dev =3D &shid->spi->dev; =20 guard(mutex)(&shid->power_lock); if (shid->power_state =3D=3D HIDSPI_ON) - return; + return 0; =20 enable_irq(shid->spi->irq); =20 @@ -298,7 +299,7 @@ static void spi_hid_resume(struct spi_hid *shid) dev_err(dev, "%s: could not power up.", __func__); shid->regulator_error_count++; shid->regulator_last_error =3D error; - return; + return error; } shid->power_state =3D HIDSPI_ON; =20 @@ -307,10 +308,13 @@ static void spi_hid_resume(struct spi_hid *shid) =20 if (shid->hid) { error =3D hid_driver_reset_resume(shid->hid); - if (error) + if (error) { dev_err(dev, "%s: failed to reset resume hid driver: %d.", __func__, error); + return error; + } } + return 0; } =20 static void spi_hid_stop_hid(struct spi_hid *shid) @@ -1171,6 +1175,132 @@ const struct attribute_group *spi_hid_groups[] =3D { }; EXPORT_SYMBOL_GPL(spi_hid_groups); =20 +/* + * 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. + */ +static int spi_hid_dev_init(struct spi_hid *shid) +{ + struct spi_device *spi =3D shid->spi; + struct device *dev =3D &spi->dev; + int error; + + 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; + } + 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; + } + } + + 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 error; + } + + shid->ops->deassert_reset(shid->ops); + + return 0; +} + +static void spi_hid_panel_follower_work(struct work_struct *work) +{ + struct spi_hid *shid =3D container_of(work, struct spi_hid, + panel_follower_work); + int error; + + if (!shid->desc.hid_version) + error =3D spi_hid_dev_init(shid); + else + error =3D spi_hid_resume(shid); + if (error) + dev_warn(&shid->spi->dev, "Power on failed: %d", error); + else + WRITE_ONCE(shid->panel_follower_work_finished, true); + + /* + * The work APIs provide a number of memory ordering guarantees + * including one that says that memory writes before schedule_work() + * are always visible to the work function, but they don't appear to + * guarantee that a write that happened in the work is visible after + * cancel_work_sync(). We'll add a write memory barrier here to match + * with spi_hid_panel_unpreparing() to ensure that our write to + * panel_follower_work_finished is visible there. + */ + smp_wmb(); +} + +static int spi_hid_panel_follower_resume(struct drm_panel_follower *follow= er) +{ + struct spi_hid *shid =3D container_of(follower, struct spi_hid, panel_fol= lower); + + /* + * Powering on a touchscreen can be a slow process. Queue the work to + * the system workqueue so we don't block the panel's power up. + */ + WRITE_ONCE(shid->panel_follower_work_finished, false); + schedule_work(&shid->panel_follower_work); + + return 0; +} + +static int spi_hid_panel_follower_suspend(struct drm_panel_follower *follo= wer) +{ + struct spi_hid *shid =3D container_of(follower, struct spi_hid, panel_fol= lower); + + cancel_work_sync(&shid->panel_follower_work); + + /* Match with shid_core_panel_follower_work() */ + smp_rmb(); + if (!READ_ONCE(shid->panel_follower_work_finished)) + return 0; + + return spi_hid_suspend(shid); +} + +static const struct drm_panel_follower_funcs + spi_hid_panel_follower_prepare_funcs =3D { + .panel_prepared =3D spi_hid_panel_follower_resume, + .panel_unpreparing =3D spi_hid_panel_follower_suspend, +}; + +static int spi_hid_register_panel_follower(struct spi_hid *shid) +{ + struct device *dev =3D &shid->spi->dev; + + shid->panel_follower.funcs =3D &spi_hid_panel_follower_prepare_funcs; + + /* + * If we're not in control of our own power up/power down then we can't + * do the logic to manage wakeups. Give a warning if a user thought + * that was possible then force the capability off. + */ + if (device_can_wakeup(dev)) { + dev_warn(dev, "Can't wakeup if following panel\n"); + device_set_wakeup_capable(dev, false); + } + + return drm_panel_add_follower(dev, &shid->panel_follower); +} + int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops, struct spi_hid_conf *conf) { @@ -1190,6 +1320,7 @@ int spi_hid_core_probe(struct spi_device *spi, struct= spihid_ops *ops, shid->ops =3D ops; shid->conf =3D conf; set_bit(SPI_HID_RESET_PENDING, &shid->flags); + shid->is_panel_follower =3D drm_is_panel_follower(&spi->dev); =20 spi_set_drvdata(spi, shid); =20 @@ -1202,6 +1333,7 @@ int spi_hid_core_probe(struct spi_device *spi, struct= spihid_ops *ops, init_completion(&shid->output_done); =20 INIT_WORK(&shid->reset_work, spi_hid_reset_work); + INIT_WORK(&shid->panel_follower_work, spi_hid_panel_follower_work); =20 /* * We need to allocate the buffer without knowing the maximum @@ -1212,42 +1344,18 @@ int spi_hid_core_probe(struct spi_device *spi, stru= ct spihid_ops *ops, if (error) return error; =20 - /* - * 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; - } - if (device_may_wakeup(dev)) { - error =3D dev_pm_set_wake_irq(dev, spi->irq); + if (shid->is_panel_follower) { + error =3D spi_hid_register_panel_follower(shid); if (error) { - dev_err(dev, "%s: failed to set wake IRQ.", __func__); + dev_err(dev, "%s: could not add panel follower.", __func__); return error; } + } else { + error =3D spi_hid_dev_init(shid); + if (error) + return error; } =20 - 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)); =20 @@ -1261,6 +1369,9 @@ void spi_hid_core_remove(struct spi_device *spi) struct device *dev =3D &spi->dev; int error; =20 + if (shid->is_panel_follower) + drm_panel_remove_follower(&shid->panel_follower); + spi_hid_stop_hid(shid); =20 shid->ops->assert_reset(shid->ops); @@ -1274,18 +1385,20 @@ static int spi_hid_core_pm_suspend(struct device *d= ev) { struct spi_hid *shid =3D dev_get_drvdata(dev); =20 - spi_hid_suspend(shid); + if (shid->is_panel_follower) + return 0; =20 - return 0; + return spi_hid_suspend(shid); } =20 static int spi_hid_core_pm_resume(struct device *dev) { struct spi_hid *shid =3D dev_get_drvdata(dev); =20 - spi_hid_resume(shid); + if (shid->is_panel_follower) + return 0; =20 - return 0; + return spi_hid_resume(shid); } =20 const struct dev_pm_ops spi_hid_core_pm =3D { diff --git a/drivers/hid/spi-hid/spi-hid-core.h b/drivers/hid/spi-hid/spi-h= id-core.h index 2bfdfbe6d7fc..88e9020d37aa 100644 --- a/drivers/hid/spi-hid/spi-hid-core.h +++ b/drivers/hid/spi-hid/spi-hid-core.h @@ -7,6 +7,8 @@ #include #include =20 +#include + /* Protocol message size constants */ #define SPI_HID_READ_APPROVAL_LEN 5 #define SPI_HID_OUTPUT_HEADER_LEN 8 @@ -53,6 +55,10 @@ struct spi_hid { struct spi_hid_input_buf *input; /* Input buffer. */ struct spi_hid_input_buf *response; /* Response buffer. */ =20 + struct drm_panel_follower panel_follower; + bool is_panel_follower; + bool panel_follower_work_finished; + u16 response_length; u16 bufsize; =20 @@ -63,6 +69,7 @@ struct spi_hid { unsigned long flags; /* device flags. */ =20 struct work_struct reset_work; + struct work_struct panel_follower_work; =20 /* Control lock to make sure one output transaction at a time. */ struct mutex output_lock; --=20 2.53.0.473.g4a7958ca14-goog