Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp735356pxa; Wed, 5 Aug 2020 11:26:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9YGAQVY2blqlmcYsmtKNeQnGN/+ewqW0nrLizNmmC5yXUt6Z0egHJigtBLrjToFhkxswN X-Received: by 2002:a50:d697:: with SMTP id r23mr511421edi.223.1596652000723; Wed, 05 Aug 2020 11:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596652000; cv=none; d=google.com; s=arc-20160816; b=RpTQ7eze8tpmSxbTjqwH1RKEPt74JNb+S+OvoGhEIzkUCntHA9DseuScDwYleNTy9q dYdibrFhR6HKdeb88WcIVrXxa1zw015PZ3VwKpUKTb3S36xhJO1QjG4PNqmNM60XaZAv ZTuXA3LXoYD43LRwnZYcdiof9nNfi5G8ZEzdnOAaeLPjrfG3oFl6UJicev7JtmOAnIb1 VS6QhqRqIptYEjfOkFoVLEOuSu9WQ7nT4Uh/DnwYiXxNGjJYYJdM47foPgljQGdiAptw eCykWme1gMUW+YA+74HiVeKCUTRgIeqU/17zLPQWt9Q7sw+Ow9Iucf5bo+U8Bb9zSX/g omLw== 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=WTM3EObT3LvzgDa2Th+yu/O1H5aR0y1ccsFniyABYRo=; b=Xkgfg3Fc1d1Yy+GEI5Spx4eHZAgkR+Prdl75RlcoPW6hKM3EnAbKS0xyr483amv2ua IfgAmnxjVUlXY5pl/wZx7B0Z1aaHXjGUrweSflA14tLyiESBn4lTgGxi/nKuI9g/x37L USzAHanHfAUpKSI8+8NtPc4SutT08eQn/xo616o4Y535+KyTbW5/BE329mzI8dszAvTY wdSS8/pyxUOmgmVn5bl3WkXrlPlja29CvYTwkkrdWJN8C0m+wwFpmZhz/zie2qKwMwRj rjTgdhfwr0V96bXf+iZ+hjvSSq3pu27cMIJub1VFkMj3XtvkXs3SdIMPjTZfV6Eps1pc j5zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=l4cTspdy; 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 g1si1644776edy.259.2020.08.05.11.25.42; Wed, 05 Aug 2020 11:26: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=l4cTspdy; 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 S1728712AbgHESXi (ORCPT + 99 others); Wed, 5 Aug 2020 14:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729177AbgHESLJ (ORCPT ); Wed, 5 Aug 2020 14:11:09 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C17C0617AA; Wed, 5 Aug 2020 11:10:04 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id kr4so5002588pjb.2; Wed, 05 Aug 2020 11:10:04 -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=WTM3EObT3LvzgDa2Th+yu/O1H5aR0y1ccsFniyABYRo=; b=l4cTspdyAYCWbEjppQX+Fb2L416fUEAwNKrrHUm6B4zJghAaxhcegEK8Omg5m8tif/ IZZ7CHtevkQEffmuJ1bfi14ttSviBep+rxI3x1uiPcSCOPbV8SGOR5Ukk9akWvIRUjNF eXKOL3rKqc+no4ChaLWdTpnV2Z0Dj0sRtEPpwojRcq1N4b1ChtPil14pHqATbTm8saxO kg2KDNbbddnL7mzL0c1I7Qykl5BwT/ekAqUX0uL6zJaMidx5y1hZDeQDpsPr0YvLpgoH /ieDeUaCUV2Ib8+avnDnARBYJn6BzHmXrWswCJv1H1XTKdofPT61EMyIx96bGPkCf6Fv DPQA== 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=WTM3EObT3LvzgDa2Th+yu/O1H5aR0y1ccsFniyABYRo=; b=O4VFaBqj/AJG12uYBtk1WsrKk3wLAQOdSYI/hgi9wSenAqBq+IvVbkHJURIiZM7W5d tZv0QiyqYTSZ24m5Lg2QLLKOdm294UilCctKQsoYWwBvhDMvySH0JEuw6790dtwjpS88 QA9ohGt91Gpk9yiM7odjEOoagpi2zlWE4TCReIUdVyLj00J2MR8+QnQXX8nwpTEMSNbG 6msBH03qkn4zQTMVDP3DSky17eOekmSXzoeIvDEof7qQyImnMnzBQeZUkROFWY3m9caT 7TQBgQI94Ydw2gNUSWLZbJjN4ErpZmGJQlK5NyhaIlHawdcj8w8WAHiAaCFJDqaE8zPe WiNQ== X-Gm-Message-State: AOAM531npVDJpq6YBPqVkxFX+zfZTY7RCLAbIYd6KTh9hUfsV3u/wGyg 6+csPFF70JcSxYd2R+v18yY= X-Received: by 2002:a17:90a:a511:: with SMTP id a17mr4595964pjq.23.1596651004006; Wed, 05 Aug 2020 11:10:04 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 11:10:03 -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 07/12] fbdev: savagefb: use generic power management Date: Wed, 5 Aug 2020 23:37:17 +0530 Message-Id: <20200805180722.244008-8-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/savage/savagefb_driver.c | 52 ++++++++++++-------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/drivers/video/fbdev/savage/savagefb_driver.c b/drivers/video/fbdev/savage/savagefb_driver.c index 3c8ae87f0ea7..d6aae759e90f 100644 --- a/drivers/video/fbdev/savage/savagefb_driver.c +++ b/drivers/video/fbdev/savage/savagefb_driver.c @@ -2346,9 +2346,9 @@ static void savagefb_remove(struct pci_dev *dev) } } -static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg) +static int savagefb_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 savagefb_par *par = info->par; DBG("savagefb_suspend"); @@ -2356,7 +2356,7 @@ static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg) if (mesg.event == PM_EVENT_PRETHAW) mesg.event = PM_EVENT_FREEZE; par->pm_state = mesg.event; - dev->dev.power.power_state = mesg; + dev->power.power_state = mesg; /* * For PM_EVENT_FREEZE, do not power down so the console @@ -2374,17 +2374,29 @@ static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg) savagefb_blank(FB_BLANK_POWERDOWN, info); savage_set_default_par(par, &par->save); savage_disable_mmio(par); - pci_save_state(dev); - pci_disable_device(dev); - pci_set_power_state(dev, pci_choose_state(dev, mesg)); console_unlock(); return 0; } -static int savagefb_resume(struct pci_dev* dev) +static int __maybe_unused savagefb_suspend(struct device *dev) { - struct fb_info *info = pci_get_drvdata(dev); + return savagefb_suspend_late(dev, PMSG_SUSPEND); +} + +static int __maybe_unused savagefb_hibernate(struct device *dev) +{ + return savagefb_suspend_late(dev, PMSG_HIBERNATE); +} + +static int __maybe_unused savagefb_freeze(struct device *dev) +{ + return savagefb_suspend_late(dev, PMSG_FREEZE); +} + +static int __maybe_unused savagefb_resume(struct device *dev) +{ + struct fb_info *info = dev_get_drvdata(dev); struct savagefb_par *par = info->par; int cur_state = par->pm_state; @@ -2396,20 +2408,11 @@ static int savagefb_resume(struct pci_dev* dev) * The adapter was not powered down coming back from a * PM_EVENT_FREEZE. */ - if (cur_state == PM_EVENT_FREEZE) { - pci_set_power_state(dev, PCI_D0); + if (cur_state == PM_EVENT_FREEZE) return 0; - } console_lock(); - pci_set_power_state(dev, PCI_D0); - pci_restore_state(dev); - - if (pci_enable_device(dev)) - DBG("err"); - - pci_set_master(dev); savage_enable_mmio(par); savage_init_hw(par); savagefb_set_par(info); @@ -2420,6 +2423,16 @@ static int savagefb_resume(struct pci_dev* dev) return 0; } +static const struct dev_pm_ops savagefb_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .suspend = savagefb_suspend, + .resume = savagefb_resume, + .freeze = savagefb_freeze, + .thaw = savagefb_resume, + .poweroff = savagefb_hibernate, + .restore = savagefb_resume, +#endif +}; static const struct pci_device_id savagefb_devices[] = { {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX128, @@ -2500,8 +2513,7 @@ static struct pci_driver savagefb_driver = { .name = "savagefb", .id_table = savagefb_devices, .probe = savagefb_probe, - .suspend = savagefb_suspend, - .resume = savagefb_resume, + .driver.pm = &savagefb_pm_ops, .remove = savagefb_remove, }; -- 2.27.0