Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp728614pxa; Wed, 5 Aug 2020 11:16:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtWu+bZ/VQXLaAHDJVZ+L1+GNe5MllCIoVJ84zGMguq1Nqn6h8z9bADH04DYm6AxJyT+jd X-Received: by 2002:a17:906:1c84:: with SMTP id g4mr588427ejh.50.1596651398654; Wed, 05 Aug 2020 11:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596651398; cv=none; d=google.com; s=arc-20160816; b=Z1cpwW7SBjkEAt3IFpF+SryGj8HwI/h9G/1tzUjLdysHKZ25lAL3D9VnSkP4djCpJE ju9CeRg+ui/Ky/UdvRieBg1VqBYtUyM2uTkB0aI9lflZt0Xerc7X6DQyPLrBQ4BDb7K8 D6tkXmxRE1v8o7S4qOiGq+oFm3JdT5WQxjiQpNTzdV0ClLkpVi2SInA3IMACo+TwH4qb EgQ2Y/DXIAOdERUuCrQbbHYjR940c/XYCfJHQfQNgHbhnDCHS/leNjtgG3lGCNRI5Oz6 FEq39UsIp0XmRmwit1EUFEiukc0FBHrBJ435UuqkOUvs3F5pk5XT3A/BPjyoWfYJ/83i rGYQ== 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=VdNiALEgQ/Tw0IhAxmU7az6lLgcNbLOEAuDmANrnfiA=; b=isiWasSTWvMBTWpPgvlf2pVIQfaGUtviGnk65Xc6cb+7d+xvY0M2/Z2d6/bWrcYD6A a5GzkCsf9DgTXjWIHzpMoMGe2yRlZ2JAfL8Ftrf2T2FH8x3hyH5usWy5wLsf8ln1B1z1 v1yPW0SUSpYvoh/dOxKlUa5J8EpQLJw/j7GSz0MIdcuhQhid5iMUPwJDrZYeNhQO7QgE eu75PAwZZMzJJW73gc1B64NorUXOKqa3sFvheQL9dnBB6gB1711UdPmuK5EC5Ve+GKqo nkSKDKrE4k4QUIrRaDuga4QXue7c6uKkzojqdaNyVNnRJKNbUZjGL/q71VbTsc5tNZbl KFww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cpYfgwkQ; 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 z1si1546163edx.129.2020.08.05.11.15.59; Wed, 05 Aug 2020 11:16:38 -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=cpYfgwkQ; 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 S1728848AbgHESPR (ORCPT + 99 others); Wed, 5 Aug 2020 14:15:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbgHESLJ (ORCPT ); Wed, 5 Aug 2020 14:11:09 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91970C0617A4; Wed, 5 Aug 2020 11:09:51 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id z20so4998040plo.6; Wed, 05 Aug 2020 11:09:51 -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=VdNiALEgQ/Tw0IhAxmU7az6lLgcNbLOEAuDmANrnfiA=; b=cpYfgwkQEP2bfsWRB/iVZRH2zrSxLRKcuJ0SMrxw0P1y3eCwkEg98QxaDBvvtOL80B LJPRCOV1klEqeHCOroXhZRlVL+oWZgwRa8ajKVzDGk9zioTu5G3cmhenrt5ZX3SeSUxd NDBsNkd0dLRvlwt84lTb8Da1o38oGpVwEYRd4e6k6hxVLloxJMcPrCN5GjceT2b2cyFr ddbwvDOJzw7yPqzg6kx51vIvjDbRY2ZRq+8qxdAxC+UT5zl/vwTHeaP2RIvzQvhTbDOp Z2ahvmTpHyMuWu9aCcE7DKXUZ87kyLLqxMwFvKXFcNoeQVXZ1n330wFDOktOokpHONSF vyyw== 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=VdNiALEgQ/Tw0IhAxmU7az6lLgcNbLOEAuDmANrnfiA=; b=i7/GTG0fArZedU5bE4mL/k2wPQG57CwDE82CSSmO8S6wrXP4VfNMvztCKYGsMbM1XU 61H8leczaHGqbahgdNkj8lXHcENQsRzO354mQ1Jho1ANgyzpsJxSpJCOkYBCjuN8RvtA C1VywnxfnIQRmF9jkdYTSPtZUMFzoRwjfntzZDk9jmVMaq/03qe7K4edxN3ehmp8Vxe4 MoYuh26W/exFCgNzB/wuMX37nUywo9BtNOoLPKhO/ra7urrBSTICEOEP0cI1/1nASaYy C1USzJFKyw9CQVWGHWdIys4KmFAjpwoSo+aB7BoJ6u7/n+tsaR5uIOTHw1aorlcfDieB /agQ== X-Gm-Message-State: AOAM530yDqAs3NfL8zFNMpMR9oIHXbu1IFyWUcPljoDuIg7qTFHSe9JG ul8u9192GXEYw3VD0S9BWuw= X-Received: by 2002:a17:902:b203:: with SMTP id t3mr4063000plr.50.1596650991064; Wed, 05 Aug 2020 11:09:51 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id t63sm4977510pfb.210.2020.08.05.11.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 11:09:50 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , Bartlomiej Zolnierkiewicz , Paul Mackerras , Russell King , Andres Salomon , Antonino Daplas , Florian Tobias Schandinat 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 v1 05/12] fbdev: aty128fb: use generic power management Date: Wed, 5 Aug 2020 23:37:15 +0530 Message-Id: <20200805180722.244008-6-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200805180722.244008-1-vaibhavgupta40@gmail.com> References: <20200805180722.244008-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 using legacy power management .suspen()/.resume() callbacks have to manage PCI states and device's PM states themselves. They also need to take care of standard configuration registers. Switch to generic power management framework using a single "struct dev_pm_ops" variable to take the unnecessary load from the driver. This also avoids the need for the driver to directly call most of the PCI helper functions and device power state control functions, as through the generic framework PCI Core takes care of the necessary operations, and drivers are required to do only device-specific jobs. Signed-off-by: Vaibhav Gupta --- drivers/video/fbdev/aty/aty128fb.c | 51 ++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c index d05d4195acad..dd7762fea058 100644 --- a/drivers/video/fbdev/aty/aty128fb.c +++ b/drivers/video/fbdev/aty/aty128fb.c @@ -162,10 +162,22 @@ static char * const r128_family[] = { static int aty128_probe(struct pci_dev *pdev, const struct pci_device_id *ent); static void aty128_remove(struct pci_dev *pdev); -static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state); -static int aty128_pci_resume(struct pci_dev *pdev); +static int aty128_pci_suspend_late(struct device *dev, pm_message_t state); +static int __maybe_unused aty128_pci_suspend(struct device *dev); +static int __maybe_unused aty128_pci_hibernate(struct device *dev); +static int __maybe_unused aty128_pci_freeze(struct device *dev); +static int __maybe_unused aty128_pci_resume(struct device *dev); static int aty128_do_resume(struct pci_dev *pdev); +static const struct dev_pm_ops aty128_pci_pm_ops = { + .suspend = aty128_pci_suspend, + .resume = aty128_pci_resume, + .freeze = aty128_pci_freeze, + .thaw = aty128_pci_resume, + .poweroff = aty128_pci_hibernate, + .restore = aty128_pci_resume, +}; + /* supported Rage128 chipsets */ static const struct pci_device_id aty128_pci_tbl[] = { { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_LE, @@ -272,8 +284,7 @@ static struct pci_driver aty128fb_driver = { .id_table = aty128_pci_tbl, .probe = aty128_probe, .remove = aty128_remove, - .suspend = aty128_pci_suspend, - .resume = aty128_pci_resume, + .driver.pm = &aty128_pci_pm_ops, }; /* packed BIOS settings */ @@ -2320,7 +2331,6 @@ static int aty128fb_ioctl(struct fb_info *info, u_int cmd, u_long arg) static void aty128_set_suspend(struct aty128fb_par *par, int suspend) { u32 pmgt; - struct pci_dev *pdev = par->pdev; if (!par->pdev->pm_cap) return; @@ -2347,23 +2357,15 @@ static void aty128_set_suspend(struct aty128fb_par *par, int suspend) aty_st_le32(BUS_CNTL1, 0x00000010); aty_st_le32(MEM_POWER_MISC, 0x0c830000); msleep(100); - - /* Switch PCI power management to D2 */ - pci_set_power_state(pdev, PCI_D2); } } -static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state) +static int aty128_pci_suspend_late(struct device *dev, pm_message_t state) { + struct pci_dev *pdev = to_pci_dev(dev); struct fb_info *info = pci_get_drvdata(pdev); struct aty128fb_par *par = info->par; - /* Because we may change PCI D state ourselves, we need to - * first save the config space content so the core can - * restore it properly on resume. - */ - pci_save_state(pdev); - /* We don't do anything but D2, for now we return 0, but * we may want to change that. How do we know if the BIOS * can properly take care of D3 ? Also, with swsusp, we @@ -2422,6 +2424,21 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state) return 0; } +static int __maybe_unused aty128_pci_suspend(struct device *dev) +{ + return aty128_pci_suspend_late(dev, PMSG_SUSPEND); +} + +static int __maybe_unused aty128_pci_hibernate(struct device *dev) +{ + return aty128_pci_suspend_late(dev, PMSG_HIBERNATE); +} + +static int __maybe_unused aty128_pci_freeze(struct device *dev) +{ + return aty128_pci_suspend_late(dev, PMSG_FREEZE); +} + static int aty128_do_resume(struct pci_dev *pdev) { struct fb_info *info = pci_get_drvdata(pdev); @@ -2468,12 +2485,12 @@ static int aty128_do_resume(struct pci_dev *pdev) return 0; } -static int aty128_pci_resume(struct pci_dev *pdev) +static int __maybe_unused aty128_pci_resume(struct device *dev) { int rc; console_lock(); - rc = aty128_do_resume(pdev); + rc = aty128_do_resume(to_pci_dev(dev)); console_unlock(); return rc; -- 2.27.0