Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4556313pxa; Mon, 10 Aug 2020 12:01:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2qx5Cq50TExNSvLzX+0VEBNzwVSQNow15L/twcx5qNIXeEUlE0NDBYXzk6W6vDN5tdmkZ X-Received: by 2002:a17:906:27d7:: with SMTP id k23mr22779381ejc.74.1597086100533; Mon, 10 Aug 2020 12:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597086100; cv=none; d=google.com; s=arc-20160816; b=zUrP0De6mZwPLSgk+tyCbGWknheRr/AYVF4bU+qsvZPVtrJdR4aLlzTwte7h2prO5f 134M5x86A4phoJ/trNxGI4t3ZHXBrwehA9+d+x9XnhDVUACsoe7ppruNaSlyWdmdLngi /dtR99MYtAnk5k8W91/FV5KjbPEklOKWvNYQXILBT1rImW6yd8mUUXp+a78I5SdtD/sF 2IMth67F3ppNNnyY8W2iYRwJYUyYRxiuBhQoj5k08oKirV63MYf2ge8ef1FgEjUhEcBc 7sdo5UHyHZTpFyMJLAb4fhDLJu9anbN/5gFb8ozuXyvzu/MUmF6hvGoO+nXDZwMFRPVr evxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B3xuxPCTDSagW3xzL4fG+ocHNWklWNizDyTgB78WOog=; b=Z73VZCsQzV1iYwq5eyzHICmcS6OekZsYGdIBI9za1RXnnuZvnntswAPZDBUR3RYZWv gg23iF/dRrVo0BQMD9ERFqvx3lezoUNJpMRliSuVQn0tuHWLz9/ISwUq4KNOvM0IDvS1 McVaH4K0oCj0AiaMZHHNdc/P2TUMHi1gFEmApMsZpt2iryTJawIAAbqGqLGc5OOzv/UN PdUGH2ABB1q+S1+f0w7OffefGPfeD+VPxpTNWV2YIVMpywY+UvwRol1OuOZErszBQXW4 vmOJxPMHBKFwPnNRKZ3gqIzaM4mmql/SxKn8TZxuLoXUt6/HIg61IBGdKL9BKmWyjObE cHgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bigsBtDZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v11si11717458edy.276.2020.08.10.12.01.17; Mon, 10 Aug 2020 12:01:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bigsBtDZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728389AbgHJTAG (ORCPT + 99 others); Mon, 10 Aug 2020 15:00:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728215AbgHJTAD (ORCPT ); Mon, 10 Aug 2020 15:00:03 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED940C061756; Mon, 10 Aug 2020 12:00:02 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id ha11so482047pjb.1; Mon, 10 Aug 2020 12:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B3xuxPCTDSagW3xzL4fG+ocHNWklWNizDyTgB78WOog=; b=bigsBtDZSW3nOEhsH9wJDhxPzbB0qI4gIf/X8MwmqFua6RE4mtL8HEXDK/o8ryll37 UB8dnk+fMML76ml/Izn965dTLDf5MMMu95fqZ8GT0pb7urHTuyCIH6U3NvgEZTfGatcq Q96NnN33EwNmB9rikhvHlBm93KbiEy/GPdIH61iatn2wFT/Apqe6JiF5IWptCVQdb/nx 8sl61J+3GwJASDOrigK0c22GgKC4HliOlsigJlPFGJh2vsZP2qQpzpFmO7Uudvp/dfo+ tIuA3Lc2e7s2eL8tnL45LAzKDpPWYd5awUKXIIeYR+E1y+rOMP33STpgso6KXepnoDYy 6SPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B3xuxPCTDSagW3xzL4fG+ocHNWklWNizDyTgB78WOog=; b=BpJbwLH4rqDzp5mP0kcBO1RUifsFwo87TSXdS9Sktz4uBhTQpyrHjGkUJglIfso62a KJGoAwio0a8BZQmrtxeNxxXFGVS4555Q+nExj14nltwDx72vcqdEUlGoCYIj/Z52+09u ArezXJhZiOorVhrIReJd18H9RQsErgiT9nTBg9cn0QQO/PxzCBvB7t4hTgHYnOChAUvj Wn91v8h8gFf1GBVtGOr3njiNiCaZ8jFDG3TmIUUlYekeB7ENXA+McU/bfVAky69dIAlP GjmNDQKMrBGM4cbmb3L0zYOSBGEMuElLWpW4rv+rr9FpeBJRuT8DKJagm2sFAFwQQAd6 aaQg== X-Gm-Message-State: AOAM532lZpPfh1vjvXwa+3RFHs9xgjvegeNW3tf2GF/0qClYXOab+e/0 bHWedyeuigmbc6tsOSEWOog= X-Received: by 2002:a17:902:c286:: with SMTP id i6mr24403571pld.219.1597086002471; Mon, 10 Aug 2020 12:00:02 -0700 (PDT) Received: from varodek.localdomain ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id f27sm22683547pfk.217.2020.08.10.11.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 12:00:02 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , Bartlomiej Zolnierkiewicz , Sam Ravnborg , Paul Mackerras , Russell King , Andres Salomon , Antonino Daplas Cc: Vaibhav Gupta , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-geode@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Shuah Khan Subject: [PATCH v2 06/12] fbdev: nvidia: use generic power management Date: Tue, 11 Aug 2020 00:27:17 +0530 Message-Id: <20200810185723.15540-7-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200810185723.15540-1-vaibhavgupta40@gmail.com> References: <20200810165458.GA292825@ravnborg.org> <20200810185723.15540-1-vaibhavgupta40@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drivers should do only device-specific jobs. But in general, drivers using legacy PCI PM framework for .suspend()/.resume() have to manage many PCI PM-related tasks themselves which can be done by PCI Core itself. This brings extra load on the driver and it directly calls PCI helper functions to handle them. Switch to the new generic framework by updating function signatures and define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove unnecessary calls to the PCI Helper functions along with the legacy .suspend & .resume bindings. Signed-off-by: Vaibhav Gupta --- drivers/video/fbdev/nvidia/nvidia.c | 64 ++++++++++++++++------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c index c24de9107958..3a1a4330e0d3 100644 --- a/drivers/video/fbdev/nvidia/nvidia.c +++ b/drivers/video/fbdev/nvidia/nvidia.c @@ -1041,10 +1041,9 @@ static struct fb_ops nvidia_fb_ops = { .fb_sync = nvidiafb_sync, }; -#ifdef CONFIG_PM -static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t mesg) +static int nvidiafb_suspend_late(struct device *dev, pm_message_t mesg) { - struct fb_info *info = pci_get_drvdata(dev); + struct fb_info *info = dev_get_drvdata(dev); struct nvidia_par *par = info->par; if (mesg.event == PM_EVENT_PRETHAW) @@ -1056,46 +1055,54 @@ static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t mesg) fb_set_suspend(info, 1); nvidiafb_blank(FB_BLANK_POWERDOWN, info); nvidia_write_regs(par, &par->SavedReg); - pci_save_state(dev); - pci_disable_device(dev); - pci_set_power_state(dev, pci_choose_state(dev, mesg)); } - dev->dev.power.power_state = mesg; + dev->power.power_state = mesg; console_unlock(); return 0; } -static int nvidiafb_resume(struct pci_dev *dev) +static int __maybe_unused nvidiafb_suspend(struct device *dev) { - struct fb_info *info = pci_get_drvdata(dev); - struct nvidia_par *par = info->par; + return nvidiafb_suspend_late(dev, PMSG_SUSPEND); +} - console_lock(); - pci_set_power_state(dev, PCI_D0); +static int __maybe_unused nvidiafb_hibernate(struct device *dev) +{ + return nvidiafb_suspend_late(dev, PMSG_HIBERNATE); +} - if (par->pm_state != PM_EVENT_FREEZE) { - pci_restore_state(dev); +static int __maybe_unused nvidiafb_freeze(struct device *dev) +{ + return nvidiafb_suspend_late(dev, PMSG_FREEZE); +} - if (pci_enable_device(dev)) - goto fail; +static int __maybe_unused nvidiafb_resume(struct device *dev) +{ + struct fb_info *info = dev_get_drvdata(dev); + struct nvidia_par *par = info->par; - pci_set_master(dev); - } + console_lock(); par->pm_state = PM_EVENT_ON; nvidiafb_set_par(info); fb_set_suspend (info, 0); nvidiafb_blank(FB_BLANK_UNBLANK, info); -fail: console_unlock(); return 0; } -#else -#define nvidiafb_suspend NULL -#define nvidiafb_resume NULL -#endif + +static const struct dev_pm_ops nvidiafb_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .suspend = nvidiafb_suspend, + .resume = nvidiafb_resume, + .freeze = nvidiafb_freeze, + .thaw = nvidiafb_resume, + .poweroff = nvidiafb_hibernate, + .restore = nvidiafb_resume, +#endif /* CONFIG_PM_SLEEP */ +}; static int nvidia_set_fbinfo(struct fb_info *info) { @@ -1496,12 +1503,11 @@ static int nvidiafb_setup(char *options) #endif /* !MODULE */ static struct pci_driver nvidiafb_driver = { - .name = "nvidiafb", - .id_table = nvidiafb_pci_tbl, - .probe = nvidiafb_probe, - .suspend = nvidiafb_suspend, - .resume = nvidiafb_resume, - .remove = nvidiafb_remove, + .name = "nvidiafb", + .id_table = nvidiafb_pci_tbl, + .probe = nvidiafb_probe, + .driver.pm = &nvidiafb_pm_ops, + .remove = nvidiafb_remove, }; /* ------------------------------------------------------------------------- * -- 2.27.0