From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795959992; b=gS4+GJDtDsda0Zz9TZ4+Ea/lpqMs99oqIePF5RLRokKjkxMnpKH90mbu20xaTU+/gHAA AIeIUIPLpbfgZ2hXzty9TENlyp/Hmx/K0mZDopPiGQ3DxPEnkMpzUQJJiVb0zXHA8b2ZE rh6WVsWCbqrhgY1BZ2M2dwsIf+795csCEYAoJg/qeBku93VkFgVwM+GEjgRlsVisOHHC7 qO6rnWlIjXt7p3gN1SuLIJj6PjylIqlkemJWd7+vuYL9HqbHHC+stnDDZSCRJEAVUqEmf b6xnxWmd6HSXKrE1WfV9w5GaMPe7eLjy2/oY5GbjD34A1UyV4SDfHRImtFbDGUTFXyQ== 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=5JxD/aeDIJgcMBKv9QAVIJx/r2uFeO4Li9ibABe06KykrOjSwTlee1WpR8KpoSErrCXE 3xMp4gQxz071L1iNu0h0+zEDz7jj9ZMyz+IR/XWpDUECsmPU38I4P08rHoN/cdo76B4uN 1r5Pmyfk6CuFKkI7B5sJfh141WT4gFZ79uaMXMIlRV9fAR0RHUl0PTABARngSVpSIvs2g tffjo0xCBzR1be9VKtVRouP4hA3IQsVCWiRPQ60dKBOn0cV2w9AZGgbNddKtVglHp+Avm c/5bsPwerrZfrtf7g90TzaGhq4OJVHAU0tDXO3M6AKmxLXVx8BtaRwm8nVDzNKlJGMQ== 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.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 C94ED606A327 for ; Sun, 29 Nov 2026 13:46:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C94ED606A327 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-f53.google.com with SMTP id 5b1f17b1804b1-4bb64ef5a00so78216035e9.3 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=0rznfZ2XHPERxh1AKlqvX7gzMhvlEsfGWq41DLmDgbz7WsKNwXMXdnUj+57JN/EADT ThzS2thbKogfmglBNE3MT1qm489fe0pUJVXqXN1X+xJvegfIb3ZV3pLsgETfexta6C9k bGHHYUN2bgMQE8sIW8B7S7rNy8F2QeYiZbLeapa6WCR5KV0mKh59sh0+3g6ZeQMEFS0P r1zvrrKe5vKnW8/vooCn+DTPrP6gwDcFs9LmWSW4PHmRk1n5j23k/Bg5G1J3vd4cVxCa efYeErUFXI/Zve4WAP0X1tHvT0q5Kcja+S01bEil41MKBF0NbWxoEu8TEaZffiIw9muA YFAw== X-Forwarded-Encrypted: i=1; AL+hErEB4ejSnjovuM37KDf4HAb+19w+UIqRbpb3TIiPd3Er3asJGQiYCUwswYOR644sWv87OlEuM8qS9kI=@vger.kernel.org X-Gm-Message-State: APuU4Z9Zbq3UgRBsZWFxHnQJ8V3an2U4qsbUdirMjeF9IopD41EEK+Vt 8fbJbHsPlov5Bbbv4V9qJ1wDpoGbo3BuUm++xBmnAX/qgRXA3VM6towM X-Gm-Gg: AZFdTZcEPNKg1T7t0KH0US3KXovtiA58hNijO8mu79yg3Onjr+3pF2mB+DbiTbvCeQR e2dwnFNZKoO1JT6XKgpdYe8l6ES7KgGzlhJ8xJnVpXkDKwUPLlUZWRYWGbyPw5sxATlpPPaZtsn JbyiyPqa9ByTAwmq9O3wXLaLe5M7J60/CDT2Ak0O3Wn2cLqJa3M4yWQD5lCz1IjjmMMi3RdruFH m4w0HQoIqWsyXP/4BFbJtucn6u2/PqZh0PB9XH4XrPhfTIDxW1s9+GS0qs40Wsujhzz0JBhJTBL vjDAXppOMZVWhNubdVZa/HEPTNFchIHG/nR4HyQU0CKaZDvFdGnaO0WIUThsvZBY0Nb8rZfjZsk OPpLMlTPU6AkO3D+I+QLwfs4Xnt1VeL8YTBS0I2ruRMSj1KRselIP0L4TeVvR5dRKaV2ayyDbv9 d57xnl+eA+SWyjfAvLrMmdQX0UQYHvEwQfEXp7pq8yGMfTFi05TY3MgXiJWVoxW3e7SZ5wBBeKV qjNGreSMCWk5l/EHTVuDEe2TqdLzsv5SkLNnRxJfP/8nYwkQHsVSDsexc9t6MzBdzxGpSxkecqv YLFG0aSWL3MzJ9AWIA4av0K2eD257rT4ynjtJNYdhh/UpuL4s+A8RjLc 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-usb@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