Browse Source

soc: swr-mstr-ctrl: allow runtime suspend first before system suspend

Allow the swrm to runtime suspend first before entering system
suspend. This will prevent suspend being blocked for about 700ms.

Change-Id: I8f90a9f1ba4f6af0decc256cace2f3bd2295dece
Phani Kumar Uppalapati 2 years ago
parent
commit
42f2072808
1 changed files with 16 additions and 1 deletions
  1. 16 1
      soc/swr-mstr-ctrl.c

+ 16 - 1
soc/swr-mstr-ctrl.c

@@ -3957,7 +3957,21 @@ static int swrm_suspend(struct device *dev)
 		dev_dbg(swrm->dev, "%s: suspending system, state %d, wlock %d\n",
 			 __func__, swrm->pm_state,
 			swrm->wlock_holders);
-		swrm->pm_state = SWRM_PM_ASLEEP;
+		/*
+		 * before updating the pm_state to ASLEEP, check if device is
+		 * runtime suspended or not. If it is not, then first make it
+		 * runtime suspend, and then update the pm_state to ASLEEP.
+		 */
+		mutex_unlock(&swrm->pm_lock); /* release pm_lock before dev suspend */
+		swrm_device_suspend(swrm->dev); /* runtime suspend the device */
+		mutex_lock(&swrm->pm_lock); /* acquire pm_lock and update state */
+		if (swrm->pm_state == SWRM_PM_SLEEPABLE) {
+			swrm->pm_state = SWRM_PM_ASLEEP;
+		} else if (swrm->pm_state == SWRM_PM_AWAKE) {
+			ret = -EBUSY;
+			mutex_unlock(&swrm->pm_lock);
+			goto check_ebusy;
+		}
 	} else if (swrm->pm_state == SWRM_PM_AWAKE) {
 		/*
 		 * unlock to wait for pm_state == SWRM_PM_SLEEPABLE
@@ -4010,6 +4024,7 @@ static int swrm_suspend(struct device *dev)
 			pm_runtime_enable(dev);
 		}
 	}
+check_ebusy:
 	if (ret == -EBUSY) {
 		/*
 		 * There is a possibility that some audio stream is active