Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4557339pxa; Mon, 10 Aug 2020 12:03:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxINbSoy25Uoox2oE4tTzzoNH/Hdwt5i5Pr4bOX/Ep9U60ccheVj1ENLWhdiZg6AtZSg1Z0 X-Received: by 2002:a50:c449:: with SMTP id w9mr23264167edf.65.1597086181416; Mon, 10 Aug 2020 12:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597086181; cv=none; d=google.com; s=arc-20160816; b=QMOYVmbNyiK1jxEuxtt8rZDZKpsa++QjrgvVois2JoA6vnue1ZX76H7/WaW6OHLBa+ hU6PCtCEnQj1O+yYI+Q1bBdzj1GfWXptDZSYoP0hmdWWV9Zzq8p2bmJPBVJBdGZ4GDWf 4Z4v9XafcV/oW0DRRuv9RoHuSVfLxEydKPqukgeggPY72bxGbzg5cIt1u4rKQqtZtLcm ub3M2GmgtriYCn5tIwqk9JyBmmz9Vgw6laB2HRUhPTbxwuFAcK2T9vSPEUqY14jSJG+n rZnM/9WGo6sIo2Yn+ZG4oT1HQ9YXDPMn9qt51rswFgV8X12TGtutzntzmcRfOwpFEcPw zvBQ== 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=puMAU16yPRJjcWrBBbirtIhNXaGIaRb087rXL9a93dY=; b=mZuNTqyp5ddZ6h7qEXkeksAfdjCEmP0/Por3jXaxT1xgB3eZwn64L/PEafrgPYj4fk kF7h9sytk4xDygfqWgBbFpgwjJPsz23TRjpRhTEj/YbR0AX7d3Q6M0V9WGEpWA6cSus7 QFIBK0ckco/J+fN/nLhRSCuSSjV3vAmZ9+daY4pum/IDFZOWnbmfO7sC3huZ3xwMTqZ6 pkhc0OLIZ39R24bF4WvfK+8Vr0WGy72fMBExvBSYPcc2Iuz0Fs2hORvivkkcsElYIfyb OT8eSj+IGoLSvCPa3l3JPKch+X0izfal31hvgmUXdbZe8V1brVH8aG1KvlRa+hX/blbb D4zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dXiBXr6E; 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 l9si12671885ejq.65.2020.08.10.12.02.38; Mon, 10 Aug 2020 12:03:01 -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=dXiBXr6E; 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 S1728367AbgHJS74 (ORCPT + 99 others); Mon, 10 Aug 2020 14:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbgHJS74 (ORCPT ); Mon, 10 Aug 2020 14:59:56 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA545C061756; Mon, 10 Aug 2020 11:59:55 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id x25so2772929pff.4; Mon, 10 Aug 2020 11:59:55 -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=puMAU16yPRJjcWrBBbirtIhNXaGIaRb087rXL9a93dY=; b=dXiBXr6E0TYKVe5evLcBJVsXAmowNxpsmGxjs5usDMfgqZiDNBp07ub/f1J2Tn/lk2 30Ye7V77uvvn1d0xyyH5N2KwzDyNy9YtTyjXu8Oe3mZCf7acoTgeg0D/c40WRn+Zx9AV YLh5bOGmIOHuunBZ9CmRl1j+pacYeNhMpghSYprgJ0CXYtd1LoEF3oWPBVWQHhRsaKCA S21MN1pNfEesIxslEGmKrp4RxeHSa8TUV5B1G8NmqfyDxQ29+o1xJjwPATWw8JzzEJ/4 7AhZwkOz205ia1OGQv1FWyDyUwl+tx+hfZzMKwVUv7GQQk8IVLRv5L/oqa8cPkKNYE/y pbsQ== 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=puMAU16yPRJjcWrBBbirtIhNXaGIaRb087rXL9a93dY=; b=iyIuom9d+mZ4PniEqnzhfpDJRwKqbQfwYfqEvL/1CzVWLrrOuP+MbVcSMK2iMbycqQ qxh3ZdiaphqZerEclUfeicDozebiEf2lXzfzSnv00KdD6tNTDFeA4w2XkrKSMZ+EFw4A kKKilMj/vO+2jwbiwtACjA8uBa9EKBzX8TcvojQaRbNgMBs7M+VFRcZZbxW3U3z5rTpZ BIENJEyWBDGcsViAi0NB5X1uyT62WMD8U6YEiZnGqzdMJhRzWXkSLiWPEd4QwCBBveRF AelYKKKHDW7tHGhPJpi2WXup/K3mm0QVDY9s5RkrDhK/1UrL2Xn0kByjudLsQofbSkNU 3ICg== X-Gm-Message-State: AOAM531DbXWBANjC4j9LAdD3/JlZfSEI15ihxK8jBccqNbSY8CkDAMUj CyTiHpW5AFGD31lc2endejA= X-Received: by 2002:a63:aa04:: with SMTP id e4mr7515802pgf.318.1597085995343; Mon, 10 Aug 2020 11:59:55 -0700 (PDT) Received: from varodek.localdomain ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id f27sm22683547pfk.217.2020.08.10.11.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 11:59:54 -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 05/12] fbdev: aty128fb: use generic power management Date: Tue, 11 Aug 2020 00:27:16 +0530 Message-Id: <20200810185723.15540-6-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/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