From patchwork Tue Apr 29 15:45:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 4088161 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CAF189F39D for ; Tue, 29 Apr 2014 15:45:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E80FF201D5 for ; Tue, 29 Apr 2014 15:45:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0E096201C0 for ; Tue, 29 Apr 2014 15:45:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F6196EA77; Tue, 29 Apr 2014 08:45:12 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTP id 00D676EA77 for ; Tue, 29 Apr 2014 08:45:10 -0700 (PDT) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E9239AAF1; Tue, 29 Apr 2014 15:45:09 +0000 (UTC) From: Takashi Iwai To: David Airlie Subject: [PATCH] drm/mgag200: Implement basic PM support Date: Tue, 29 Apr 2014 17:45:09 +0200 Message-Id: <1398786309-1570-1-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 1.9.2 Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 --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 #include #include +#include #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); +}