diff mbox

drm/mgag200: Implement basic PM support

Message ID 1398786309-1570-1-git-send-email-tiwai@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Takashi Iwai April 29, 2014, 3:45 p.m. UTC
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 | 75 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/mgag200/mgag200_drv.h |  1 +
 drivers/gpu/drm/mgag200/mgag200_fb.c  |  5 +++
 3 files changed, 81 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c
index f15ea3c4a90a..35ef919788e4 100644
--- a/drivers/gpu/drm/mgag200/mgag200_drv.c
+++ b/drivers/gpu/drm/mgag200/mgag200_drv.c
@@ -11,6 +11,7 @@ 
 #include <linux/module.h>
 #include <linux/console.h>
 #include <drm/drmP.h>
+#include <drm/drm_crtc_helper.h>
 
 #include "mgag200_drv.h"
 
@@ -74,6 +75,79 @@  static void mga_pci_remove(struct pci_dev *pdev)
 	drm_put_dev(dev);
 }
 
+static int mgag200_pm_freeze(struct device *dev)
+{
+	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct mga_device *mdev = drm_dev->dev_private;
+	struct drm_connector *connector;
+
+	drm_kms_helper_poll_disable(drm_dev);
+	list_for_each_entry(connector, &drm_dev->mode_config.connector_list,
+			    head)
+		drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
+
+	console_lock();
+	mgag200_fbdev_set_suspend(mdev, FBINFO_STATE_SUSPENDED);
+	console_unlock();
+
+	return 0;
+}
+
+static int mgag200_pm_thaw(struct device *dev)
+{
+	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct mga_device *mdev = drm_dev->dev_private;
+	struct drm_connector *connector;
+
+	console_lock();
+	mgag200_fbdev_set_suspend(mdev, FBINFO_STATE_RUNNING);
+	console_unlock();
+
+	drm_helper_resume_force_mode(drm_dev);
+	list_for_each_entry(connector, &drm_dev->mode_config.connector_list,
+			    head)
+		drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
+
+	drm_kms_helper_poll_enable(drm_dev);
+	return 0;
+}
+
+static int mgag200_pm_suspend(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	int err;
+
+	err = mgag200_pm_freeze(dev);
+	if (err)
+		return err;
+
+	pci_save_state(pdev);
+	pci_disable_device(pdev);
+	pci_set_power_state(pdev, PCI_D3hot);
+	return 0;
+}
+
+static int mgag200_pm_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+
+	pci_set_power_state(pdev, PCI_D0);
+	pci_restore_state(pdev);
+	if (pci_enable_device(pdev))
+		return -EIO;
+
+	return mgag200_pm_thaw(dev);
+}
+
+static const struct dev_pm_ops mgag200_pm_ops = {
+	.suspend = mgag200_pm_suspend,
+	.resume = mgag200_pm_resume,
+	.freeze = mgag200_pm_freeze,
+	.thaw = mgag200_pm_thaw,
+	.poweroff = mgag200_pm_freeze,
+	.restore = mgag200_pm_resume,
+};
+
 static const struct file_operations mgag200_driver_fops = {
 	.owner = THIS_MODULE,
 	.open = drm_open,
@@ -110,6 +184,7 @@  static struct pci_driver mgag200_pci_driver = {
 	.id_table = pciidlist,
 	.probe = mga_pci_probe,
 	.remove = mga_pci_remove,
+	.driver.pm = &mgag200_pm_ops,
 };
 
 static int __init mgag200_init(void)
diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h
index cf11ee68a6d9..493f56d6f421 100644
--- a/drivers/gpu/drm/mgag200/mgag200_drv.h
+++ b/drivers/gpu/drm/mgag200/mgag200_drv.h
@@ -247,6 +247,7 @@  void mgag200_modeset_fini(struct mga_device *mdev);
 				/* mgag200_fb.c */
 int mgag200_fbdev_init(struct mga_device *mdev);
 void mgag200_fbdev_fini(struct mga_device *mdev);
+void mgag200_fbdev_set_suspend(struct mga_device *mdev, int state);
 
 				/* mgag200_main.c */
 int mgag200_framebuffer_init(struct drm_device *dev,
diff --git a/drivers/gpu/drm/mgag200/mgag200_fb.c b/drivers/gpu/drm/mgag200/mgag200_fb.c
index 13b7dd83faa9..0fdb8b247541 100644
--- a/drivers/gpu/drm/mgag200/mgag200_fb.c
+++ b/drivers/gpu/drm/mgag200/mgag200_fb.c
@@ -318,3 +318,8 @@  void mgag200_fbdev_fini(struct mga_device *mdev)
 
 	mga_fbdev_destroy(mdev->dev, mdev->mfbdev);
 }
+
+void mgag200_fbdev_set_suspend(struct mga_device *mdev, int state)
+{
+	fb_set_suspend(mdev->mfbdev->helper.fbdev, state);
+}