diff mbox

drm: mxsfb: Add PM support to MXSFB

Message ID 20161208024715.12634-1-marex@denx.de (mailing list archive)
State New, archived
Headers show

Commit Message

Marek Vasut Dec. 8, 2016, 2:47 a.m. UTC
Add simple PM hooks into the MXSFB controller to allow proper suspend
both of the controller and optionally an attached panel.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Stefan Agner <stefan@agner.ch>
---
 drivers/gpu/drm/mxsfb/mxsfb_drv.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
index 79a18bf..e4eecb3 100644
--- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
+++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
@@ -427,12 +427,49 @@  static int mxsfb_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int __maybe_unused mxsfb_pm_suspend(struct device *dev)
+{
+	struct drm_device *drm = dev_get_drvdata(dev);
+	struct mxsfb_drm_private *mxsfb = drm ? drm->dev_private : NULL;
+
+	if (!mxsfb)
+		return 0;
+
+	drm_kms_helper_poll_disable(drm);
+
+	mxsfb->state = drm_atomic_helper_suspend(drm);
+	if (IS_ERR(mxsfb->state)) {
+		drm_kms_helper_poll_enable(drm);
+		return PTR_ERR(mxsfb->state);
+	}
+
+	return 0;
+}
+
+static int __maybe_unused mxsfb_pm_resume(struct device *dev)
+{
+	struct drm_device *drm = dev_get_drvdata(dev);
+	struct mxsfb_drm_private *mxsfb = drm ? drm->dev_private : NULL;
+
+	if (!mxsfb)
+		return 0;
+
+	drm_atomic_helper_resume(drm, mxsfb->state);
+	drm_kms_helper_poll_enable(drm);
+	pm_runtime_set_active(dev);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(mxsfb_pm_ops, mxsfb_pm_suspend, mxsfb_pm_resume);
+
 static struct platform_driver mxsfb_platform_driver = {
 	.probe		= mxsfb_probe,
 	.remove		= mxsfb_remove,
 	.id_table	= mxsfb_devtype,
 	.driver	= {
 		.name		= "mxsfb",
+		.pm		= &mxsfb_pm_ops,
 		.of_match_table	= mxsfb_dt_ids,
 	},
 };