Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795959992; b=x7U9VP3fzhHaq4t7tV8oLRDoejByUuBvY+79p4ZAsUiPEPW3yb/pRI0VXCr8UmuVlOoC OwqPbjwYE5p7q4IEDCJ1BieWXVjihEDZo5giTIbj/OgteQXJhrUIWE7KgD8guFqF7NsB7 OaPjcOi29nUqn+0ly6HEPJarNonaDA3I1Lg5v3JOr/VduQ/tQBOGGOYfGguRLU2vrivQw 2RNVGv8mqvRKo5cZoR1UO6c3f+mNZCmG4WSXnoj6DmKMzl/8s4ZesqWVpHzsNBnEXPa16 zFlyTbtrc9HvXUg/M9r9sctVUKmimLWDlL0xVuVgZKZF7A3U1N973BUt8NLEuRyP5Tw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795959992; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=cK1LJp9Bx5mr9BcfMsdYa17ypz4qrRBmn8rj2AFvTlE=; b=c7hGdI+SAAAqBUuWPo3RLtO+oB22xslrZDojY4BJFVZkTXixT9AcOdUn6cBJRbVs7bpL gb3s3iym6k9EDrPh0xKOeZaYR5EcwKHyPhrj40xdvynkRWCQx3C/7k2D7ODTKF7JkOYAC kV1jd36QHT7xu+b15B8VWQ3ABD0wfuBuJJJzq/qeOvrymgwrirUBC/DZ6JjdEGlzY1Kqc 0/CdjQzDu7nejT37J+elpXA4t1T6mSeBEOh0EVqYARDIU/JLnsEDnRB4SKV8qUiIPUh/a Pboi9m9T0W7Z+f+iMm52gz1DLqJIWS9o3J1FUdLu4DiJrb7/vmxCfeavD617PQHsagg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=OkXaZnCG; arc=none smtp.remote-ip=209.85.128.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB1E4606A325 for ; Sun, 29 Nov 2026 13:46:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB1E4606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=OkXaZnCG Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4bba5e17728so38315495e9.2 for ; Sun, 29 Nov 2026 05:46:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795959990; x=1796564790; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=cK1LJp9Bx5mr9BcfMsdYa17ypz4qrRBmn8rj2AFvTlE=; b=OkXaZnCG1SDo59jDJ3YkgWXi+skX6LBfX2ilE7D7IkoF7ETPSkZQ/mzXiUjBKu/h9A OcwfaofnbAoUExCUVblzj4OizB0UEn30NHOs8901h73PW/fTZKOWx9oga4j1ohkudofe J4UQmlQnOXe1waybImW+oz4L5eE4o3zieY7WqcNCy14hlPyXg1GRjsW88V2Y661F8BIr 5i3VMjYqSkapafRifTyfOVenj3YvvRoIQJhzbiNjVYtIih5q9EkQIiCE6MoxuOzt6DWz cvhsweum7xIhdArcP3zh+TzwkpVf6Y7NBp6ll7zqpTS+lASlq57SNoHXEvs0Ow0roah/ WiIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795959990; x=1796564790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=cK1LJp9Bx5mr9BcfMsdYa17ypz4qrRBmn8rj2AFvTlE=; b=YH4gg1uai92JmSne49t/G9DxxHAQMrhXwzNvL4EU9j4UvgIw7inK0/xt9y43nOrf6t mHdNWLiaLzoyMpy/eSussYO8st1OJcyeSOgOxuItLNoWpXkAPWnhQrXuty7HtLzI0vvq SUemQtSV+7NZPUyaTPG8zbN3AsB/8reGHZqSg/UKslVUzHtK3dD4vlZJz5CmnPG9oCPN GXn0e20C9fSVLY75njqh8d5NUym87A/v5deKHY+w0KvtHZxHMiqjmuCg1EzAUyvSb+y7 We77V5vXaA2OnWMjyylAhCpQ1eFMGmm04N37hnKPLFT9jXn/U+sGrktKXveEy8ldVngP QVMQ== X-Forwarded-Encrypted: i=1; AL+hErGro5zyJj9gl8qoMAiplodXohpZM0/N3p0dYt4ErKAITW/kF9UzYLECgk4JOywX98+C9cY6ezXrp+++iHdv@vger.kernel.org X-Gm-Message-State: APuU4Z/QlcvsW48L5bUp9UV4AGqBuhGEdR+g7CjXuKsKslHBzGo1eG44 oshdXoZChC+8VTuccB8yygabc/xi8S6kmV9Yzwsrv51sM/m9xavvWJxy X-Gm-Gg: AZFdTZeRASCp3lExtRwDsNlunif9QX7PO+CG/BfsRRfDVxF5ReViibZat/rJKdZGLSZ ZmdeKgsfNojgngaZofWRmW6hjje8IChI7U0708p91phYQFTGojIxkGAYwdla8VxEwOgQgXWlvcj 49iGyxRX6Gv11PkA7qG7AxU0dBG4ujFhc/fzO0BGleSBCFG2CU0cky1xXMBhrjUggeoJaYntcQk BmaKcqrrpuIM/BkInZn4l/1k+vzRFSqjegk9qfI95Jj1x3+UGVLLecZ0FHJB7kWDab5yRS3E8Cu JznsCVJvCAMJnNs0TjEUJM2BZYV5Y466WoRaVd/QLW5J4eXPUHvLD23Qr73ExEFPfrY4vDrmTaK OKWj4bjLR7xLRCbjIG2qugKi0HD3hXz7mYQMAZlBCryrOdYsgBfwoPW/CritBMFpEOx7hd0u2Tj khaUYYcIWXAOL71Nti6k4DsTTkSkpnbqmjqTo0sLlbBxN0pY5qMqYIim/DFuoJBqbeoNccvuqGg 5Gmp901NOlJ7YVWcM8MehUMX5NvZjQ1ZvHRjLYEp/OYET2V0/LrqtO9VEfkbTUs1qkqBzoMzvEo rMKWzLGgLB69jSlHFRkz4s2ix4mEO5Y38yyQjyuGARk8qc/Ug71ARqNN X-Received: by 2002:a05:600c:4ec9:b0:4bb:6a5a:782d with SMTP id 5b1f17b1804b1-4bb88925fcdmr630439425e9.17.1795959990035; Sun, 29 Nov 2026 05:46:30 -0800 (PST) Received: from localhost.localdomain ([188.190.249.216]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4b33a596f9csm31253406f8f.12.2026.11.29.05.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 05:46:29 -0800 (PST) From: Vladyslav Tymoshchuk To: Bjorn Andersson , Konrad Dybcio , Sebastian Reichel , Heikki Krogerus , Greg Kroah-Hartman Cc: Neil Armstrong , Abel Vesa , Jishnu Prakash , Joonhoe Kim <26rote@gmail.com>, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] soc: qcom: pmic_glink: Report wakeup events on behalf of clients Date: Sun, 29 Nov 2026 15:44:39 +0200 Message-ID: <20261129134442.579-4-tvlad744@gmail.com> X-Mailer: git-send-email 2.45.1.windows.1 In-Reply-To: <20261129134442.579-1-tvlad744@gmail.com> References: <20261129134442.579-1-tvlad744@gmail.com> X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The GLINK interrupt is not a wakeup interrupt, as most PMIC GLINK messages must not wake up the system, and the clients get notifications only after the system has resumed. Report the wakeup events in pmic_glink, when a notification arrives: it is a wakeup event if the device of the client may wake up the system and the optional wakeup filter of the client accepts it. Use a wakeup source of pmic_glink, and keep it active until the queued notifications have been passed on, so that the system does not go back to sleep before that. No client enables wakeup yet, so nothing changes for them. Signed-off-by: Vladyslav Tymoshchuk --- drivers/soc/qcom/pmic_glink.c | 80 +++++++++++++++++++++++++++++ include/linux/soc/qcom/pmic_glink.h | 2 + 2 files changed, 82 insertions(+) diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c index 805c4ee85bba..a25d7967629d 100644 --- a/drivers/soc/qcom/pmic_glink.c +++ b/drivers/soc/qcom/pmic_glink.c @@ -9,12 +9,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #define PMIC_GLINK_SEND_TIMEOUT (5 * HZ) @@ -61,6 +63,8 @@ struct pmic_glink { unsigned int num_notifications; unsigned int num_dropped; struct work_struct deliver_work; + + struct wakeup_source *ws; }; static struct pmic_glink *__pmic_glink; @@ -70,10 +74,12 @@ struct pmic_glink_client { struct list_head node; struct pmic_glink *pg; + struct device *dev; unsigned int id; void (*cb)(const void *data, size_t len, void *priv); void (*pdr_notify)(void *priv, int state); + bool (*wakeup_filter)(const void *data, size_t len, void *priv); void *priv; }; @@ -96,6 +102,22 @@ static void _devm_pmic_glink_release_client(struct device *dev, void *res) spin_unlock_irqrestore(&pg->client_lock, flags); } +/** + * devm_pmic_glink_client_alloc() - allocate a client of the PMIC GLINK service + * @dev: client device, a child of the pmic_glink device + * @id: owner of the messages for the client + * @cb: called, in atomic context, with the messages for the client + * @pdr: called, in atomic context, with the state of the remote service + * @priv: passed to @cb, @pdr and the wakeup filter + * + * A notification for a client whose @dev may wake up the system, see + * device_may_wakeup(), is a wakeup event, unless the wakeup filter of the + * client rejects it. Notifications that arrive during system sleep reach @cb + * once the system has resumed, only the latest one of identical notifications. + * + * Return: the client, to be registered with pmic_glink_client_register(), or + * an ERR_PTR() on failure. + */ struct pmic_glink_client *devm_pmic_glink_client_alloc(struct device *dev, unsigned int id, void (*cb)(const void *, size_t, void *), @@ -110,6 +132,7 @@ struct pmic_glink_client *devm_pmic_glink_client_alloc(struct device *dev, return ERR_PTR(-ENOMEM); client->pg = pg; + client->dev = dev; client->id = id; client->cb = cb; client->pdr_notify = pdr; @@ -122,6 +145,22 @@ struct pmic_glink_client *devm_pmic_glink_client_alloc(struct device *dev, } EXPORT_SYMBOL_GPL(devm_pmic_glink_client_alloc); +/** + * pmic_glink_client_set_wakeup_filter() - select the wakeup notifications + * @client: client from devm_pmic_glink_client_alloc(), not registered yet + * @filter: called, in atomic context, with each notification for the client + * while its device may wake up the system; returns true to wake + * the system up + * + * Without a filter, every notification for the client is a wakeup event. + */ +void pmic_glink_client_set_wakeup_filter(struct pmic_glink_client *client, + bool (*filter)(const void *, size_t, void *)) +{ + client->wakeup_filter = filter; +} +EXPORT_SYMBOL_GPL(pmic_glink_client_set_wakeup_filter); + void pmic_glink_client_register(struct pmic_glink_client *client) { struct pmic_glink *pg = client->pg; @@ -168,6 +207,24 @@ int pmic_glink_send(struct pmic_glink_client *client, void *data, size_t len) } EXPORT_SYMBOL_GPL(pmic_glink_send); +static bool pmic_glink_is_wakeup_event(struct pmic_glink *pg, const void *data, size_t len) +{ + const struct pmic_glink_hdr *hdr = data; + struct pmic_glink_client *client; + + guard(spinlock_irqsave)(&pg->client_lock); + + list_for_each_entry(client, &pg->clients, node) { + if (client->id != le32_to_cpu(hdr->owner) || !device_may_wakeup(client->dev)) + continue; + + if (!client->wakeup_filter || client->wakeup_filter(data, len, client->priv)) + return true; + } + + return false; +} + static void pmic_glink_dispatch(struct pmic_glink *pg, const void *data, size_t len) { const struct pmic_glink_hdr *hdr = data; @@ -224,6 +281,7 @@ static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data, { struct pmic_glink_hdr *hdr; struct pmic_glink *pg = dev_get_drvdata(&rpdev->dev); + bool wakeup; if (len < sizeof(*hdr)) { dev_warn(pg->dev, "ignoring truncated message\n"); @@ -238,8 +296,16 @@ static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data, return 0; } + wakeup = pmic_glink_is_wakeup_event(pg, data, len); + guard(spinlock_irqsave)(&pg->event_lock); + /* Keep the system awake until the notification has been passed on */ + if (wakeup) { + __pm_stay_awake(pg->ws); + pm_system_wakeup(); + } + pmic_glink_add_notification(pg, data, len); queue_work(system_freezable_wq, &pg->deliver_work); @@ -340,6 +406,7 @@ static void pmic_glink_deliver_work(struct work_struct *work) if (!event) { dropped = pg->num_dropped; pg->num_dropped = 0; + __pm_relax(pg->ws); spin_unlock_irqrestore(&pg->event_lock, flags); break; } @@ -435,6 +502,11 @@ static struct rpmsg_driver pmic_glink_rpmsg_driver = { }, }; +static void pmic_glink_unregister_wakeup_source(void *ws) +{ + wakeup_source_unregister(ws); +} + static int pmic_glink_probe(struct platform_device *pdev) { struct pdr_service *service; @@ -453,6 +525,14 @@ static int pmic_glink_probe(struct platform_device *pdev) spin_lock_init(&pg->client_lock); mutex_init(&pg->state_lock); + pg->ws = wakeup_source_register(&pdev->dev, dev_name(&pdev->dev)); + if (!pg->ws && IS_ENABLED(CONFIG_PM_SLEEP)) + return -ENOMEM; + + ret = devm_add_action_or_reset(&pdev->dev, pmic_glink_unregister_wakeup_source, pg->ws); + if (ret) + return ret; + INIT_LIST_HEAD(&pg->events); spin_lock_init(&pg->event_lock); INIT_WORK(&pg->deliver_work, pmic_glink_deliver_work); diff --git a/include/linux/soc/qcom/pmic_glink.h b/include/linux/soc/qcom/pmic_glink.h index 7cddf1027752..786d2f35a9a9 100644 --- a/include/linux/soc/qcom/pmic_glink.h +++ b/include/linux/soc/qcom/pmic_glink.h @@ -28,6 +28,8 @@ struct pmic_glink_client *devm_pmic_glink_client_alloc(struct device *dev, void (*cb)(const void *, size_t, void *), void (*pdr)(void *, int), void *priv); +void pmic_glink_client_set_wakeup_filter(struct pmic_glink_client *client, + bool (*filter)(const void *, size_t, void *)); void pmic_glink_client_register(struct pmic_glink_client *client); #endif