* [PATCH v2 1/5] usb: typec: ucsi: glink: Handle a restart of the remote before the work runs
2026-11-29 13:44 [PATCH v2 0/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue Vladyslav Tymoshchuk
@ 2026-11-29 13:44 ` Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 2/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue Vladyslav Tymoshchuk
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Vladyslav Tymoshchuk @ 2026-11-29 13:44 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
Heikki Krogerus, Greg Kroah-Hartman
Cc: Neil Armstrong, Abel Vesa, Jishnu Prakash, Joonhoe Kim,
linux-arm-msm, linux-pm, linux-usb, linux-kernel
When the remote service goes down and comes back up before the register
work runs, the work finds the service running and UCSI registered, and
does nothing. The restarted firmware is then never initialized, and no
longer reports connector changes.
Remember that the service went down, and register UCSI anew.
Fixes: 62b5412b1f4a ("usb: typec: ucsi: add PMIC Glink UCSI driver")
Signed-off-by: Vladyslav Tymoshchuk <tvlad744@gmail.com>
---
drivers/usb/typec/ucsi/ucsi_glink.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
index 2696e0b978f6..053571027182 100644
--- a/drivers/usb/typec/ucsi/ucsi_glink.c
+++ b/drivers/usb/typec/ucsi/ucsi_glink.c
@@ -77,6 +77,7 @@ struct pmic_glink_ucsi {
spinlock_t state_lock;
bool ucsi_registered;
bool pd_running;
+ bool pd_restarted;
u8 read_buf[UCSI_BUF_V2_SIZE];
};
@@ -314,18 +315,22 @@ static void pmic_glink_ucsi_register(struct work_struct *work)
{
struct pmic_glink_ucsi *ucsi = container_of(work, struct pmic_glink_ucsi, register_work);
unsigned long flags;
- bool pd_running;
+ bool pd_running, pd_restarted;
spin_lock_irqsave(&ucsi->state_lock, flags);
pd_running = ucsi->pd_running;
+ pd_restarted = ucsi->pd_restarted;
+ ucsi->pd_restarted = false;
spin_unlock_irqrestore(&ucsi->state_lock, flags);
+ if (ucsi->ucsi_registered && (pd_restarted || !pd_running)) {
+ ucsi_unregister(ucsi->ucsi);
+ ucsi->ucsi_registered = false;
+ }
+
if (!ucsi->ucsi_registered && pd_running) {
ucsi_register(ucsi->ucsi);
ucsi->ucsi_registered = true;
- } else if (ucsi->ucsi_registered && !pd_running) {
- ucsi_unregister(ucsi->ucsi);
- ucsi->ucsi_registered = false;
}
}
@@ -354,6 +359,8 @@ static void pmic_glink_ucsi_pdr_notify(void *priv, int state)
spin_lock_irqsave(&ucsi->state_lock, flags);
ucsi->pd_running = (state == SERVREG_SERVICE_STATE_UP);
+ if (!ucsi->pd_running)
+ ucsi->pd_restarted = true;
spin_unlock_irqrestore(&ucsi->state_lock, flags);
schedule_work(&ucsi->register_work);
}
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 2/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue
2026-11-29 13:44 [PATCH v2 0/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 1/5] usb: typec: ucsi: glink: Handle a restart of the remote before the work runs Vladyslav Tymoshchuk
@ 2026-11-29 13:44 ` Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 3/5] soc: qcom: pmic_glink: Report wakeup events on behalf of clients Vladyslav Tymoshchuk
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Vladyslav Tymoshchuk @ 2026-11-29 13:44 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
Heikki Krogerus, Greg Kroah-Hartman
Cc: Neil Armstrong, Abel Vesa, Jishnu Prakash, Joonhoe Kim,
linux-arm-msm, linux-pm, linux-usb, linux-kernel
The GLINK interrupt is not suspended, so notifications reach the clients
during system suspend and resume. The clients handle them in work on the
system workqueue, which can then use devices that are suspended. On
SM8750, unplugging USB in suspend-to-idle makes dwc3-qcom access its
registers with the clocks off, and the SoC resets.
Queue the notifications, and pass them on from work on
system_freezable_wq, which is frozen before the devices suspend and
thawed after they have resumed. Queue changes of the service state as
well, so that the clients see both in order. Responses are passed on
right away, as the sender of the request is waiting for them.
Clients treat a notification as the latest state or as a hint to read
it, so keep only the latest of identical ones, and at most 64.
Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Signed-off-by: Vladyslav Tymoshchuk <tvlad744@gmail.com>
---
drivers/soc/qcom/pmic_glink.c | 192 ++++++++++++++++++++++++++++++----
1 file changed, 169 insertions(+), 23 deletions(-)
diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c
index 0e354fcd87c9..805c4ee85bba 100644
--- a/drivers/soc/qcom/pmic_glink.c
+++ b/drivers/soc/qcom/pmic_glink.c
@@ -14,8 +14,11 @@
#include <linux/soc/qcom/pdr.h>
#include <linux/soc/qcom/pmic_glink.h>
#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/workqueue.h>
#define PMIC_GLINK_SEND_TIMEOUT (5 * HZ)
+#define PMIC_GLINK_MAX_NOTIFICATIONS 64
enum {
PMIC_GLINK_CLIENT_BATT = 0,
@@ -41,15 +44,23 @@ struct pmic_glink {
struct auxiliary_device ps_aux;
struct auxiliary_device ucsi_aux;
- /* serializing client_state and pdr_state updates */
+ /* serializing client_state, service_state and pdr_state updates */
struct mutex state_lock;
- unsigned int client_state;
+ unsigned int client_state; /* last state passed on to the clients */
+ unsigned int service_state; /* last state queued for the clients */
unsigned int pdr_state;
bool pdr_available;
/* serializing clients list updates */
spinlock_t client_lock;
struct list_head clients;
+
+ /* serializing the queue of events for the clients */
+ spinlock_t event_lock;
+ struct list_head events;
+ unsigned int num_notifications;
+ unsigned int num_dropped;
+ struct work_struct deliver_work;
};
static struct pmic_glink *__pmic_glink;
@@ -66,6 +77,14 @@ struct pmic_glink_client {
void *priv;
};
+/* A notification, or a change of the service state if @len is 0 */
+struct pmic_glink_event {
+ struct list_head node;
+ unsigned int state;
+ size_t len;
+ u8 data[] __counted_by(len);
+};
+
static void _devm_pmic_glink_release_client(struct device *dev, void *res)
{
struct pmic_glink_client *client = (struct pmic_glink_client *)res;
@@ -149,13 +168,62 @@ int pmic_glink_send(struct pmic_glink_client *client, void *data, size_t len)
}
EXPORT_SYMBOL_GPL(pmic_glink_send);
+static void pmic_glink_dispatch(struct pmic_glink *pg, const void *data, size_t len)
+{
+ const struct pmic_glink_hdr *hdr = data;
+ struct pmic_glink_client *client;
+ unsigned long flags;
+
+ spin_lock_irqsave(&pg->client_lock, flags);
+ list_for_each_entry(client, &pg->clients, node) {
+ if (client->id == le32_to_cpu(hdr->owner))
+ client->cb(data, len, client->priv);
+ }
+ spin_unlock_irqrestore(&pg->client_lock, flags);
+}
+
+static void pmic_glink_add_notification(struct pmic_glink *pg, const void *data, size_t len)
+{
+ struct pmic_glink_event *event;
+
+ lockdep_assert_held(&pg->event_lock);
+
+ /* An identical notification brings nothing new, keep the latest one */
+ list_for_each_entry(event, &pg->events, node) {
+ if (event->len == len && !memcmp(event->data, data, len)) {
+ list_move_tail(&event->node, &pg->events);
+ return;
+ }
+ }
+
+ if (pg->num_notifications == PMIC_GLINK_MAX_NOTIFICATIONS) {
+ list_for_each_entry(event, &pg->events, node) {
+ if (event->len)
+ break;
+ }
+ list_del(&event->node);
+ kfree(event);
+ pg->num_notifications--;
+ pg->num_dropped++;
+ }
+
+ event = kmalloc_flex(*event, data, len, GFP_ATOMIC);
+ if (!event) {
+ pg->num_dropped++;
+ return;
+ }
+
+ event->len = len;
+ memcpy(event->data, data, len);
+ list_add_tail(&event->node, &pg->events);
+ pg->num_notifications++;
+}
+
static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data,
int len, void *priv, u32 addr)
{
- struct pmic_glink_client *client;
struct pmic_glink_hdr *hdr;
struct pmic_glink *pg = dev_get_drvdata(&rpdev->dev);
- unsigned long flags;
if (len < sizeof(*hdr)) {
dev_warn(pg->dev, "ignoring truncated message\n");
@@ -164,12 +232,16 @@ static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data,
hdr = data;
- spin_lock_irqsave(&pg->client_lock, flags);
- list_for_each_entry(client, &pg->clients, node) {
- if (client->id == le32_to_cpu(hdr->owner))
- client->cb(data, len, client->priv);
+ /* The sender of a request is waiting for the response */
+ if (le32_to_cpu(hdr->type) == PMIC_GLINK_REQ_RESP) {
+ pmic_glink_dispatch(pg, data, len);
+ return 0;
}
- spin_unlock_irqrestore(&pg->client_lock, flags);
+
+ guard(spinlock_irqsave)(&pg->event_lock);
+
+ pmic_glink_add_notification(pg, data, len);
+ queue_work(system_freezable_wq, &pg->deliver_work);
return 0;
}
@@ -210,13 +282,14 @@ static void pmic_glink_del_aux_device(struct pmic_glink *pg,
auxiliary_device_uninit(aux);
}
-static void pmic_glink_state_notify_clients(struct pmic_glink *pg)
+static void pmic_glink_update_state(struct pmic_glink *pg)
{
- struct pmic_glink_client *client;
- unsigned int new_state = pg->client_state;
- unsigned long flags;
+ unsigned int new_state = pg->service_state;
+ struct pmic_glink_event *event;
+
+ lockdep_assert_held(&pg->state_lock);
- if (pg->client_state != SERVREG_SERVICE_STATE_UP) {
+ if (pg->service_state != SERVREG_SERVICE_STATE_UP) {
if (pg->pdr_state == SERVREG_SERVICE_STATE_UP && pg->ept)
new_state = SERVREG_SERVICE_STATE_UP;
} else {
@@ -224,13 +297,78 @@ static void pmic_glink_state_notify_clients(struct pmic_glink *pg)
new_state = SERVREG_SERVICE_STATE_DOWN;
}
- if (new_state != pg->client_state) {
- spin_lock_irqsave(&pg->client_lock, flags);
- list_for_each_entry(client, &pg->clients, node)
- client->pdr_notify(client->priv, new_state);
- spin_unlock_irqrestore(&pg->client_lock, flags);
- pg->client_state = new_state;
+ if (new_state == pg->service_state)
+ return;
+
+ event = kzalloc_obj(*event);
+ if (!event)
+ return;
+
+ event->state = new_state;
+ pg->service_state = new_state;
+
+ guard(spinlock_irqsave)(&pg->event_lock);
+
+ list_add_tail(&event->node, &pg->events);
+ queue_work(system_freezable_wq, &pg->deliver_work);
+}
+
+static void pmic_glink_notify_state(struct pmic_glink *pg, unsigned int state)
+{
+ struct pmic_glink_client *client;
+ unsigned long flags;
+
+ guard(mutex)(&pg->state_lock);
+
+ spin_lock_irqsave(&pg->client_lock, flags);
+ list_for_each_entry(client, &pg->clients, node)
+ client->pdr_notify(client->priv, state);
+ spin_unlock_irqrestore(&pg->client_lock, flags);
+ pg->client_state = state;
+}
+
+static void pmic_glink_deliver_work(struct work_struct *work)
+{
+ struct pmic_glink *pg = container_of(work, struct pmic_glink, deliver_work);
+ struct pmic_glink_event *event;
+ unsigned int dropped;
+ unsigned long flags;
+
+ for (;;) {
+ spin_lock_irqsave(&pg->event_lock, flags);
+ event = list_first_entry_or_null(&pg->events, struct pmic_glink_event, node);
+ if (!event) {
+ dropped = pg->num_dropped;
+ pg->num_dropped = 0;
+ spin_unlock_irqrestore(&pg->event_lock, flags);
+ break;
+ }
+
+ list_del(&event->node);
+ if (event->len)
+ pg->num_notifications--;
+ spin_unlock_irqrestore(&pg->event_lock, flags);
+
+ if (event->len)
+ pmic_glink_dispatch(pg, event->data, event->len);
+ else
+ pmic_glink_notify_state(pg, event->state);
+ kfree(event);
}
+
+ if (dropped)
+ dev_warn(pg->dev, "%u notifications lost\n", dropped);
+}
+
+static void pmic_glink_release_events(void *data)
+{
+ struct pmic_glink *pg = data;
+ struct pmic_glink_event *event, *tmp;
+
+ disable_work_sync(&pg->deliver_work);
+
+ list_for_each_entry_safe(event, tmp, &pg->events, node)
+ kfree(event);
}
static void pmic_glink_pdr_callback(int state, char *svc_path, void *priv)
@@ -240,7 +378,7 @@ static void pmic_glink_pdr_callback(int state, char *svc_path, void *priv)
guard(mutex)(&pg->state_lock);
pg->pdr_state = state;
- pmic_glink_state_notify_clients(pg);
+ pmic_glink_update_state(pg);
}
static int pmic_glink_rpmsg_probe(struct rpmsg_device *rpdev)
@@ -260,7 +398,7 @@ static int pmic_glink_rpmsg_probe(struct rpmsg_device *rpdev)
pg->ept = rpdev->ept;
if (!pg->pdr_available)
pg->pdr_state = SERVREG_SERVICE_STATE_UP;
- pmic_glink_state_notify_clients(pg);
+ pmic_glink_update_state(pg);
return 0;
}
@@ -278,7 +416,7 @@ static void pmic_glink_rpmsg_remove(struct rpmsg_device *rpdev)
pg->ept = NULL;
if (!pg->pdr_available)
pg->pdr_state = SERVREG_SERVICE_STATE_DOWN;
- pmic_glink_state_notify_clients(pg);
+ pmic_glink_update_state(pg);
}
static const struct rpmsg_device_id pmic_glink_rpmsg_id_match[] = {
@@ -315,6 +453,14 @@ static int pmic_glink_probe(struct platform_device *pdev)
spin_lock_init(&pg->client_lock);
mutex_init(&pg->state_lock);
+ INIT_LIST_HEAD(&pg->events);
+ spin_lock_init(&pg->event_lock);
+ INIT_WORK(&pg->deliver_work, pmic_glink_deliver_work);
+
+ ret = devm_add_action_or_reset(&pdev->dev, pmic_glink_release_events, pg);
+ if (ret)
+ return ret;
+
pg->data = of_device_get_match_data(&pdev->dev);
if (!pg->data)
return -EINVAL;
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 3/5] soc: qcom: pmic_glink: Report wakeup events on behalf of clients
2026-11-29 13:44 [PATCH v2 0/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 1/5] usb: typec: ucsi: glink: Handle a restart of the remote before the work runs Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 2/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue Vladyslav Tymoshchuk
@ 2026-11-29 13:44 ` Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 4/5] usb: typec: ucsi: glink: Wake up the system on connector changes Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 5/5] power: supply: qcom_battmgr: Allow charger changes to wake up the system Vladyslav Tymoshchuk
4 siblings, 0 replies; 6+ messages in thread
From: Vladyslav Tymoshchuk @ 2026-11-29 13:44 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
Heikki Krogerus, Greg Kroah-Hartman
Cc: Neil Armstrong, Abel Vesa, Jishnu Prakash, Joonhoe Kim,
linux-arm-msm, linux-pm, linux-usb, linux-kernel
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 <tvlad744@gmail.com>
---
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 <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/pm_wakeup.h>
#include <linux/rpmsg.h>
#include <linux/slab.h>
#include <linux/soc/qcom/pdr.h>
#include <linux/soc/qcom/pmic_glink.h>
#include <linux/spinlock.h>
#include <linux/string.h>
+#include <linux/suspend.h>
#include <linux/workqueue.h>
#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
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 4/5] usb: typec: ucsi: glink: Wake up the system on connector changes
2026-11-29 13:44 [PATCH v2 0/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue Vladyslav Tymoshchuk
` (2 preceding siblings ...)
2026-11-29 13:44 ` [PATCH v2 3/5] soc: qcom: pmic_glink: Report wakeup events on behalf of clients Vladyslav Tymoshchuk
@ 2026-11-29 13:44 ` Vladyslav Tymoshchuk
2026-11-29 13:44 ` [PATCH v2 5/5] power: supply: qcom_battmgr: Allow charger changes to wake up the system Vladyslav Tymoshchuk
4 siblings, 0 replies; 6+ messages in thread
From: Vladyslav Tymoshchuk @ 2026-11-29 13:44 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
Heikki Krogerus, Greg Kroah-Hartman
Cc: Neil Armstrong, Abel Vesa, Jishnu Prakash, Joonhoe Kim,
linux-arm-msm, linux-pm, linux-usb, linux-kernel
Enable wakeup on the device, so that pmic_glink reports the UCSI
notifications as wakeup events: plugging a cable in or out brings the
system out of suspend-to-idle. User space can change it through
power/wakeup.
Jishnu Prakash proposed the same [1], with the event reported from the
callback, which now runs only after the system has resumed.
Link: https://lore.kernel.org/all/20260722-ucsi_glink_wakeup-v2-1-b43dee56df24@oss.qualcomm.com/ [1]
Signed-off-by: Vladyslav Tymoshchuk <tvlad744@gmail.com>
---
drivers/usb/typec/ucsi/ucsi_glink.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
index 053571027182..a0e28ec715bd 100644
--- a/drivers/usb/typec/ucsi/ucsi_glink.c
+++ b/drivers/usb/typec/ucsi/ucsi_glink.c
@@ -7,6 +7,7 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of_device.h>
+#include <linux/pm_wakeup.h>
#include <linux/property.h>
#include <linux/soc/qcom/pdr.h>
#include <linux/usb/typec_mux.h>
@@ -462,6 +463,11 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
ucsi->port_orientation[port] = desc;
}
+ /* pmic_glink reports the notifications as wakeup events */
+ ret = devm_device_init_wakeup(dev);
+ if (ret)
+ return ret;
+
ucsi->client = devm_pmic_glink_client_alloc(dev, PMIC_GLINK_OWNER_USBC,
pmic_glink_ucsi_callback,
pmic_glink_ucsi_pdr_notify,
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 5/5] power: supply: qcom_battmgr: Allow charger changes to wake up the system
2026-11-29 13:44 [PATCH v2 0/5] soc: qcom: pmic_glink: Deliver notifications from a freezable workqueue Vladyslav Tymoshchuk
` (3 preceding siblings ...)
2026-11-29 13:44 ` [PATCH v2 4/5] usb: typec: ucsi: glink: Wake up the system on connector changes Vladyslav Tymoshchuk
@ 2026-11-29 13:44 ` Vladyslav Tymoshchuk
4 siblings, 0 replies; 6+ messages in thread
From: Vladyslav Tymoshchuk @ 2026-11-29 13:44 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel,
Heikki Krogerus, Greg Kroah-Hartman
Cc: Neil Armstrong, Abel Vesa, Jishnu Prakash, Joonhoe Kim,
linux-arm-msm, linux-pm, linux-usb, linux-kernel
Most notifications of the battery manager report battery status, which
is not worth a wakeup. Changes of the USB and wireless charger, like
plugging one in, can be.
Make the device wakeup capable, with a filter for the charger
notifications. Leave wakeup disabled by default, it is up to user space
through power/wakeup.
Do this only for the SM8350 and SM8550 firmware, as the SC8280XP and
X1E80100 firmware sends no notification when a charger changes.
Signed-off-by: Vladyslav Tymoshchuk <tvlad744@gmail.com>
---
drivers/power/supply/qcom_battmgr.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
index 69473ea753f6..9902192b2921 100644
--- a/drivers/power/supply/qcom_battmgr.c
+++ b/drivers/power/supply/qcom_battmgr.c
@@ -9,6 +9,7 @@
#include <linux/mutex.h>
#include <linux/nvmem-consumer.h>
#include <linux/of_device.h>
+#include <linux/pm_wakeup.h>
#include <linux/power_supply.h>
#include <linux/property.h>
#include <linux/soc/qcom/pdr.h>
@@ -1723,6 +1724,20 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr,
complete(&battmgr->ack);
}
+static bool qcom_battmgr_is_charger_notification(const void *data, size_t len, void *priv)
+{
+ const struct qcom_battmgr_message *msg = data;
+ unsigned int notification;
+
+ if (le32_to_cpu(msg->hdr.opcode) != BATTMGR_NOTIFICATION ||
+ len != sizeof(msg->hdr) + sizeof(msg->notification))
+ return false;
+
+ notification = le32_to_cpu(msg->notification) & 0xff;
+
+ return notification == NOTIF_USB_PROPERTY || notification == NOTIF_WLS_PROPERTY;
+}
+
static void qcom_battmgr_callback(const void *data, size_t len, void *priv)
{
const struct pmic_glink_hdr *hdr = data;
@@ -1896,6 +1911,13 @@ static int qcom_battmgr_probe(struct auxiliary_device *adev,
if (ret)
return ret;
+ if (battmgr->variant == QCOM_BATTMGR_SM8350 ||
+ battmgr->variant == QCOM_BATTMGR_SM8550) {
+ device_set_wakeup_capable(dev, true);
+ pmic_glink_client_set_wakeup_filter(battmgr->client,
+ qcom_battmgr_is_charger_notification);
+ }
+
pmic_glink_client_register(battmgr->client);
return 0;
^ permalink raw reply [flat|nested] 6+ messages in thread