Browse Source

Merge "ipc: gpr-lite: Add wake lock with timeout while handling callback"

qctecmdr 2 years ago
parent
commit
e1150e5ac2
1 changed files with 14 additions and 0 deletions
  1. 14 0
      ipc/gpr-lite.c

+ 14 - 0
ipc/gpr-lite.c

@@ -26,6 +26,9 @@
 #include <soc/snd_event.h>
 #include <dsp/audio_notifier.h>
 
+#define APM_EVENT_MODULE_TO_CLIENT	0x03001000
+#define WAKELOCK_TIMEOUT 200
+
 struct gpr {
 	struct rpmsg_endpoint *ch;
 	struct device *dev;
@@ -36,6 +39,7 @@ struct gpr {
 	struct idr svcs_idr;
 	int dest_domain_id;
 	struct work_struct notifier_reg_work;
+	struct wakeup_source *wsource;
 };
 
 static struct gpr_q6 q6;
@@ -297,6 +301,11 @@ static int gpr_callback(struct rpmsg_device *rpdev, void *buf,
 	dev_dbg(gpr->dev, "%s: dst_port %x hdr_size %d pkt_size %d\n",
 	__func__ , hdr->dst_port, hdr_size, pkt_size);
 
+	if (hdr->opcode == APM_EVENT_MODULE_TO_CLIENT) {
+		dev_err(gpr->dev, "%s: Acquire wakelock in case of module event with timeout %d",
+			__func__, WAKELOCK_TIMEOUT);
+		pm_wakeup_ws_event(gpr_priv->wsource, WAKELOCK_TIMEOUT, true);
+	}
 	svc_id = hdr->dst_port;
 	spin_lock_irqsave(&gpr->svcs_lock, flags);
 	svc = idr_find(&gpr->svcs_idr, svc_id);
@@ -312,6 +321,8 @@ static int gpr_callback(struct rpmsg_device *rpdev, void *buf,
 
 	if (!adrv) {
 		dev_err_ratelimited(gpr->dev, "GPR: service is not registered\n");
+		if (hdr->opcode == APM_EVENT_MODULE_TO_CLIENT)
+			__pm_relax(gpr_priv->wsource);
 		return -EINVAL;
 	}
 
@@ -524,6 +535,7 @@ static int gpr_probe(struct rpmsg_device *rpdev)
 		return -EINVAL;
 	}
 
+	gpr_priv->wsource = wakeup_source_register(gpr_priv->dev, "audio-gpr");
 	dev_info(dev, "%s: gpr-lite probe success\n",
 		__func__);
 
@@ -540,6 +552,8 @@ static int gpr_remove_device(struct device *dev, void *null)
 static void gpr_remove(struct rpmsg_device *rpdev)
 {
 	struct device *dev = &rpdev->dev;
+
+	wakeup_source_unregister(gpr_priv->wsource);
 	snd_event_client_deregister(&rpdev->dev);
 	dev_info(dev, "%s: deregistering via subsys_notif_register for domain_id(%d)",
 		__func__, gpr_priv->dest_domain_id );