Skip to contentSkip to conversation

mei: vsc: Don't stop/restart mei device during system suspend/resume

PATCH In review Wentong Wu 2 participants 3 messages May 27, 2024 – May 28, 2024

Subsystems (3)
lore
Share & tools
lore

Wentong Wu

author
#0 lore raw

PATCH v3 1/1 mei: vsc: Don't stop/restart mei device during system suspend/resume

The dynamically created mei client device (mei csi) is used as one V4L2 sub device of the whole video pipeline, and the V4L2 connection graph is built by software node. The mei_stop() and mei_restart() will delete the old mei csi client device and create a new mei client device, which will cause the software node information saved in old mei csi device lost and the whole video pipeline will be broken.

Removing mei_stop()/mei_restart() during system suspend/resume can fix the issue above and won't impact hardware actual power saving logic.

Fixes f6085a96c973 ("mei: vsc: Unregister interrupt handler for system suspend")
Cc [email protected] # for 6.8+

---
Changes since v2:
- add change log which is not covered by v2, and no code change

Changes since v1:
- correct Fixes commit id in commit message, and no code change

---
 drivers/misc/mei/platform-vsc.c | 39 +++++++++++++--------------------
 1 file changed, 15 insertions(+), 24 deletions(-)
drivers/misc/mei/platform-vsc.c +15 -24
index b543e6b9f3cf..1ec65d87488a 100644
@@ -399,41 +399,32 @@ static void mei_vsc_remove(struct platform_device *pdev)
 
 static int mei_vsc_suspend(struct device *dev)
 {
-	struct mei_device *mei_dev = dev_get_drvdata(dev);
-	struct mei_vsc_hw *hw = mei_dev_to_vsc_hw(mei_dev);
+	struct mei_device *mei_dev;
+	int ret = 0;
 
-	mei_stop(mei_dev);
+	mei_dev = dev_get_drvdata(dev);
+	if (!mei_dev)
+		return -ENODEV;
 
-	mei_disable_interrupts(mei_dev);
+	mutex_lock(&mei_dev->device_lock);
 
-	vsc_tp_free_irq(hw->tp);
+	if (!mei_write_is_idle(mei_dev))
+		ret = -EAGAIN;
 
-	return 0;
+	mutex_unlock(&mei_dev->device_lock);
+
+	return ret;
 }
 
 static int mei_vsc_resume(struct device *dev)
 {
-	struct mei_device *mei_dev = dev_get_drvdata(dev);
-	struct mei_vsc_hw *hw = mei_dev_to_vsc_hw(mei_dev);
-	int ret;
-
-	ret = vsc_tp_request_irq(hw->tp);
-	if (ret)
-		return ret;
-
-	ret = mei_restart(mei_dev);
-	if (ret)
-		goto err_free;
+	struct mei_device *mei_dev;
 
-	/* start timer if stopped in suspend */
-	schedule_delayed_work(&mei_dev->timer_work, HZ);
+	mei_dev = dev_get_drvdata(dev);
+	if (!mei_dev)
+		return -ENODEV;
 
 	return 0;
-
-err_free:
-	vsc_tp_free_irq(hw->tp);
-
-	return ret;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(mei_vsc_pm_ops, mei_vsc_suspend, mei_vsc_resume);
Signature · 1 line
2.34.1
Acked-by on v3 1/1
#1 lore raw
Quoted 23 lines

-----Original Message-----
From: Wu, Wentong <[email protected]>
Sent: Monday, May 27, 2024 3:39 PM
To: [email protected]; Winkler, Tomas <[email protected]>; [email protected]
Cc: [email protected]; Wu, Wentong <[email protected]>; [email protected]; Yao, Hao <[email protected]>; Chen, Jason Z <[email protected]>
Subject: [PATCH v3] mei: vsc: Don't stop/restart mei device during system suspend/resume

The dynamically created mei client device (mei csi) is used as one V4L2 sub device of the whole video pipeline, and the V4L2 connection graph is built by software node. The mei_stop() and mei_restart() will delete the old mei csi client device and create a new mei client device, which will cause the software node information saved in old mei csi device lost and the whole video pipeline will be broken.

Removing mei_stop()/mei_restart() during system suspend/resume can fix the issue above and won't impact hardware actual power saving logic.

Quoted 8 lines
Fixes f6085a96c973 ("mei: vsc: Unregister interrupt handler for system

suspend")

Quoted 9 lines

---
Changes since v2:
- add change log which is not covered by v2, and no code change

Changes since v1:
- correct Fixes commit id in commit message, and no code change

---

vX descriptions should go here

Quoted 66 lines
 drivers/misc/mei/platform-vsc.c | 39 +++++++++++++--------------------
 1 file changed, 15 insertions(+), 24 deletions(-)
drivers/misc/mei/platform- renamed from drivers/misc/mei/platform-vsc.c +0 -0

vsc.c index b543e6b9f3cf..1ec65d87488a 100644

drivers/misc/mei/platform-vsc.c +15 -25
@@ -399,41 +399,32 @@ static void mei_vsc_remove(struct platform_device
 *pdev)
 
 static int mei_vsc_suspend(struct device *dev)  {
-	struct mei_device *mei_dev = dev_get_drvdata(dev);
-	struct mei_vsc_hw *hw = mei_dev_to_vsc_hw(mei_dev);
+	struct mei_device *mei_dev;
+	int ret = 0;
 
-	mei_stop(mei_dev);
+	mei_dev = dev_get_drvdata(dev);
+	if (!mei_dev)
+		return -ENODEV;
 
-	mei_disable_interrupts(mei_dev);
+	mutex_lock(&mei_dev->device_lock);
 
-	vsc_tp_free_irq(hw->tp);
+	if (!mei_write_is_idle(mei_dev))
+		ret = -EAGAIN;
 
-	return 0;
+	mutex_unlock(&mei_dev->device_lock);
+
+	return ret;
 }
 
 static int mei_vsc_resume(struct device *dev)  {
-	struct mei_device *mei_dev = dev_get_drvdata(dev);
-	struct mei_vsc_hw *hw = mei_dev_to_vsc_hw(mei_dev);
-	int ret;
-
-	ret = vsc_tp_request_irq(hw->tp);
-	if (ret)
-		return ret;
-
-	ret = mei_restart(mei_dev);
-	if (ret)
-		goto err_free;
+	struct mei_device *mei_dev;
 
-	/* start timer if stopped in suspend */
-	schedule_delayed_work(&mei_dev->timer_work, HZ);
+	mei_dev = dev_get_drvdata(dev);
+	if (!mei_dev)
+		return -ENODEV;
 
 	return 0;
-
-err_free:
-	vsc_tp_free_irq(hw->tp);
-
-	return ret;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(mei_vsc_pm_ops, mei_vsc_suspend,
 mei_vsc_resume);
--

2.34.1

#2 lore raw
Quoted 22 lines

From: Winkler, Tomas <[email protected]>

Quoted 13 lines

From: Wu, Wentong <[email protected]>

The dynamically created mei client device (mei csi) is used as one V4L2 sub device of the whole video pipeline, and the V4L2 connection graph is built by software node. The mei_stop() and mei_restart() will delete the old mei csi client device and create a new mei client device, which will cause the software node information saved in old mei csi device lost and the whole video pipeline will be broken.

Removing mei_stop()/mei_restart() during system suspend/resume can fix the issue above and won't impact hardware actual power saving logic.

Fixes f6085a96c973 ("mei: vsc: Unregister interrupt handler for
Quoted 8 lines

system
suspend")

Quoted 1 line

Thanks

Quoted 10 lines
Quoted 9 lines

---
Changes since v2:
- add change log which is not covered by v2, and no code change

Changes since v1:
- correct Fixes commit id in commit message, and no code change

---

vX descriptions should go here

Thanks, I will follow this going forward, thanks

BR,
Wentong

Quoted 71 lines
Quoted 71 lines

 drivers/misc/mei/platform-vsc.c | 39
+++++++++++++--------------------
 1 file changed, 15 insertions(+), 24 deletions(-)
(quoted diff) +0 -0

b/drivers/misc/mei/platform- vsc.c index b543e6b9f3cf..1ec65d87488a 100644

drivers/misc/mei/platform-vsc.c +0 -0
@@ -399,41 +399,32 @@ static void mei_vsc_remove(struct

platform_device
*pdev)

static int mei_vsc_suspend(struct device *dev) {

drivers/misc/mei/platform-vsc.c +15 -24
-	struct mei_device *mei_dev = dev_get_drvdata(dev);
-	struct mei_vsc_hw *hw = mei_dev_to_vsc_hw(mei_dev);
+	struct mei_device *mei_dev;
+	int ret = 0;
 
-	mei_stop(mei_dev);
+	mei_dev = dev_get_drvdata(dev);
+	if (!mei_dev)
+		return -ENODEV;
 
-	mei_disable_interrupts(mei_dev);
+	mutex_lock(&mei_dev->device_lock);
 
-	vsc_tp_free_irq(hw->tp);
+	if (!mei_write_is_idle(mei_dev))
+		ret = -EAGAIN;
 
-	return 0;
+	mutex_unlock(&mei_dev->device_lock);
+
+	return ret;
 }
 
 static int mei_vsc_resume(struct device *dev)  {
-	struct mei_device *mei_dev = dev_get_drvdata(dev);
-	struct mei_vsc_hw *hw = mei_dev_to_vsc_hw(mei_dev);
-	int ret;
-
-	ret = vsc_tp_request_irq(hw->tp);
-	if (ret)
-		return ret;
-
-	ret = mei_restart(mei_dev);
-	if (ret)
-		goto err_free;
+	struct mei_device *mei_dev;
 
-	/* start timer if stopped in suspend */
-	schedule_delayed_work(&mei_dev->timer_work, HZ);
+	mei_dev = dev_get_drvdata(dev);
+	if (!mei_dev)
+		return -ENODEV;
 
 	return 0;
-
-err_free:
-	vsc_tp_free_irq(hw->tp);
-
-	return ret;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(mei_vsc_pm_ops, mei_vsc_suspend,

mei_vsc_resume);
--
2.34.1