From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795959992; b=jv8oJn26tifN4wFHor9bT+j/pN7BXapzQwTQdGHB93dkZxx7RtnlVCTycYCe4dAQh9zF WJWsKzyJY7/x+zv4PYqADgene81Z8NgPkW2s0uZYzG+RgnYqoQU2aqhpgWNFwQcf66Vwt LWOdyxQomHIcX7x4icPGlXFPysFofYQPal8k7z8e8kRFnS3K3fJlj5idZ8dB3DsVyK0iy G5FI3p8CvOhzB6RE+VOtQsaaOzs89sjPnF+O/Kyoa3mRnu2ZI7HzeRW2I626BWieQyD1S 8szCBnfnZ5OB8g/Bq9Z2SkbEk9R5pLdr6B49O+7JSxkKhGOTXXcggE7GG7wpblrT+WA== 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=GciGhynSyoExg1NW1O+DWkuxmBUmOc+53WpHH9Doxl4gmjRRSsG6sh3qmUQypEA7C8Xc C6rwZYcSguYnQltjIY+4BXH+IppQYc8dZABfQNo34gBZnGipAXsN+iHeWnjNHbzxolmNQ mYpJQHJ/J5knc0PlcCJFbp7zp1IKTu6lfxa8xr28X4S5zOkX81t+WTZ4XOmSjWYqXqENT HTERH+RG3BkY4bzc84pSDPQFpxc4IhcAal/WPfRI6pTTriV0OTEdqNSGDgGs+TFts3HnU QyD7z0wlYFEbKhYeA/44frWlxjOyJ0kEu8Sn8wii1ownWI+LhkWhwDKsVaC7mUri8yQ== 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.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 A8DE0606A31C for ; Sun, 29 Nov 2026 13:46:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A8DE0606A31C 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-f42.google.com with SMTP id 5b1f17b1804b1-4a2000d5fb1so55764415e9.1 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=Y/ETAveZpYWxL09KoufdRVfthkG3tdlMSDVc8aluNiPaG9B/UEow7Vb/4LIsrOob7c y3K7wbHf9iLrbt2er5J/1wjS2n1D+ctzpMlArmL5IrOiiBgnjeOwAUKYq/UNg68p7sca Ev/DiPI54g9/LOpklem+LRPItpT0NTddz+t4ZHfvn1KulfUhOu0a7f+0HiLDiNG0LmWK viAgzC/yqnbVZXi9q2XaVwUCkgdzkDccItA3aQbwl2SjEXLxNmGayOqTVne7zxPWBroH iS+ivJ9YcqxTaZCcv3M19afZFYP4ezfgO6U6B3OihkwPnWd73fTeQfPKx/1sMhWENA5B l22g== X-Forwarded-Encrypted: i=1; AL+hErGa8PerTFpC1bNxWqviA78kScJzh4KotiglZBugwk2RE9KG2P/PMR5NQ1jNgCR3D1V3WuneBEHmVw==@vger.kernel.org X-Gm-Message-State: APuU4Z+3d4/xrRmtk+cA/Ii2o0HvThqBVWKbabEA7IwyKn/pDRNFmm5G ud8EIBCYxkKRq9dTRCoJMlr0Jy6BANHbN77mT1Oi7IwpTtJflAJ075nO X-Gm-Gg: AZFdTZe8x6nkGQOK/psiogcD4EPVmQbPzMxt5xwojRdhT2uDIDs4qyKHAeCRSsiHayY GshrF7+GLEjkAcXlxCsqdaGMczfymuaYFNOUUqZMfJZ/PalHq96vHxeOWEwyTeFD1B84vzMpold pHcym+RfPH13m+hp8IH5SIKYCgGNCmolJAAH6Y1jX4oE0iQnGmheeOdosj6uQu1U1+oAapBK+Kz JnKpxxzjhcsI7gHqUtKrZ87z10AEBbUliFJHsozBTtYwVZeyX8U+UQ0mCGnFe2JE/itK8E/wvNT nUYIZ53nm/Jw03p6zQ+V6gMEEpPDQc0VtwkWRpjydbcfMSKfIK/9xGNbS1YDu8IQ9WnkA/EoQsh m9gKO+VPtTGYjvnwWGEG/ibYJbYoMYChO48Wa+5eU0UxXo4b3/tbCzeLsiw4x+8t9Op8EVoWW8E QgUaze9JLmOhgjOBykRJ3PnufrT9Zk+XRZtnCg8iI3lnYwG4UzVtaLAbCEf9vn0CMeQIfrBoGLj aZKM1qaMyZKjMC0aUVvin5VbMIhUKxu4pRLow+fAXDVEpQs0tMjn5ePuCeaJCY+27p/nb12gIeX d3a/Ged9/8VwhYlunCWDb97I7DbwZ1GK/Mfi89AeIYachTk3g/q40ePJ 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-pm@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