Blob Blame History Raw
From 9b355fbe03201dd1c3050988d23d3270eb487c29 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 18 Jul 2017 16:43:20 +0200
Message-Id: <20170718144320.8354-15-tiwai@suse.de>
Subject: [PATCH 14/14] drm/mgag200: Implement basic PM support
Patch-mainline: Submitted, dri-devel ML
References: bnc#872213

Add a basic PM support to mgag200 driver.
As there is no hardware specific init codes for this device, the
callbacks are written in a fairly simple way.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/gpu/drm/mgag200/mgag200_drv.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

--- a/drivers/gpu/drm/mgag200/mgag200_drv.c
+++ b/drivers/gpu/drm/mgag200/mgag200_drv.c
@@ -8,6 +8,8 @@
 #include <linux/module.h>
 #include <linux/console.h>
 #include <drm/drmP.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_probe_helper.h>
 
 #include "mgag200_drv.h"
 
@@ -54,6 +56,37 @@ static void mga_pci_remove(struct pci_de
 	drm_put_dev(dev);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int mgag200_pm_suspend(struct device *dev)
+{
+	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct mga_device *mdev = drm_dev->dev_private;
+
+	drm_kms_helper_poll_disable(drm_dev);
+	if (mdev->mfbdev)
+		drm_fb_helper_set_suspend_unlocked(&mdev->mfbdev->helper, 1);
+
+	return 0;
+}
+
+static int mgag200_pm_resume(struct device *dev)
+{
+	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct mga_device *mdev = drm_dev->dev_private;
+
+	drm_helper_resume_force_mode(drm_dev);
+	if (mdev->mfbdev)
+		drm_fb_helper_set_suspend_unlocked(&mdev->mfbdev->helper, 0);
+	drm_kms_helper_poll_enable(drm_dev);
+
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops mgag200_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(mgag200_pm_suspend, mgag200_pm_resume)
+};
+
 static const struct file_operations mgag200_driver_fops = {
 	.owner = THIS_MODULE,
 	DRM_VRAM_MM_FILE_OPERATIONS
@@ -78,6 +111,7 @@ static struct pci_driver mgag200_pci_dri
 	.id_table = pciidlist,
 	.probe = mga_pci_probe,
 	.remove = mga_pci_remove,
+	.driver.pm = &mgag200_pm_ops,
 };
 
 static int __init mgag200_init(void)