Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4555868pxa; Mon, 10 Aug 2020 12:01:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzs1MYp6fa9MJUchEdjD8fT9JXlB5EVQ1f8jCly6EX3XZ4wIWtn/7teGMduNW4CdBBbvzlr X-Received: by 2002:a17:906:7a16:: with SMTP id d22mr23440326ejo.478.1597086068795; Mon, 10 Aug 2020 12:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597086068; cv=none; d=google.com; s=arc-20160816; b=PEi+kzlQMZ/6Wwntk3gSXYyJDBgVOXEkoBTWSZew43dSTKQewrrIi70ce0J5p0SI6g etATPF35rs/mMYA7zL/Bb9m/sPubO6VX5jOjOX/JGd7HqKQJf0/oR6DRPgpEfzylbl9M BqADaaenB3ro/NuDYmqPB5LuJ382BngJ1AVznis1xn0sg03HvvzRUH6hTJLWS5VtN5/c 3ePoEvr/EJondBMJEPI1XWmyzsYrlVVwee6hNaxAXLZdY8Yqc2gwrf+JamDI7r7CVHuN 3WQ+YaSPzxPB3Ond+4AM2pZ9422qaNuDK8HrBuUHHy7ocY+BDJdrW0LGn7npRI+WLs08 Mn/g== 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=alhqoEvoDzB6EgYbPZouIY7wwoSwqK7ATGTbSeQXdVM=; b=YzRxxXG54lt70cgAQpxaE8hizjNpgzwg21/W0FktauvXiU8Yvzg79mq0sWcbBNdzln G1eRmSDnPX0hPmN7ZNBesGKzUdNVVef5mwZmAWDEoJDBjIhGI//MzSsYUJNE5jshWEsv TESirWMRpvOtH0Xf6r41/N7a7RnJg4JsonwVui49+luamn4IIZJu9wTTd33Ei7cR55tD VTaHA2LPtTzTfFzE6qHMVKsRroeITEDPNVOCcOUih+SOO2hABM8/0f0jwjxF8ryVfmbL rmAXt2pdEl3OCnsp//7j/7PjDu33GEd1ycjLw97TnY0ebD7QQrkciLH7coLMdmlvl7Tn cCug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=boaPJgd9; 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 a20si3828213eda.489.2020.08.10.12.00.44; Mon, 10 Aug 2020 12:01:08 -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=boaPJgd9; 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 S1728342AbgHJS7l (ORCPT + 99 others); Mon, 10 Aug 2020 14:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbgHJS7k (ORCPT ); Mon, 10 Aug 2020 14:59:40 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE529C061756; Mon, 10 Aug 2020 11:59:40 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id u20so6138249pfn.0; Mon, 10 Aug 2020 11:59:40 -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=alhqoEvoDzB6EgYbPZouIY7wwoSwqK7ATGTbSeQXdVM=; b=boaPJgd9MUTMhnVe3c0WDxW7vqkOz7PWgP40Ngq9aEBR/wFbk5+SnGqmKkykQlWzuF Brq7EEbO75RrpB/tncOFRjPF4quasLr6mJF7gtiX7ztYynOUkkJuaPBXzkE2Uvyx/3kB VwyqDO3g5gjG1oB1bTUkRAUlpOfFlkB0Igv1fOqGPCY//rPv3P4mRVzsY9w6LI0B3dlI Juc8CWOB/ZyI+Mwg21i0RoG2bHf/966tu5IYXcA6pMScmf4OE/1jKbOfeBC5vhSLYYIX Tg1xkk+q16sJhRRuZEtgXAezUk4jqbvfynzUFsD6ZAxX5nV8HfsD4swaYAhuC4uINelV SpPQ== 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=alhqoEvoDzB6EgYbPZouIY7wwoSwqK7ATGTbSeQXdVM=; b=H+O+UTdoRmL/erRYfZ7tDVlbNIUVsEoAC57z9RDOo8utsxUWoq4ib73fsXMKjfWHM3 ZeX01A1I+eeJBkIXHx9hSD0BTwxCn0WmmPUpV8hcF11HittNMahaUTlPmyEglN3PAe3t +t8fbU8p/A+PzBXDYw9v4dQL0n081gq8QOyo6FW3LgZ/+2CwVtuRw8wAh4EF9XdIzqhX iDXkQ9qaIgOtfub4NgDar44T1ZpuCy6jTWKYMq4rgzGjBGRowb2qs578QVRCIv9cY7qe szOANLNpGdR6Un4RLgAGW8pykEoz2I4S535CxQG0oJMMpHBMj69uI2pW4YSsTI3+2khe 9zAw== X-Gm-Message-State: AOAM533LIbaItU2myC/HW3rYIdhkG8C7y2A5RDZYgqBWaKE2Bi7Mevx1 r19OfpLvqUJQauX5FqTASxw= X-Received: by 2002:a63:e118:: with SMTP id z24mr22301979pgh.230.1597085980258; Mon, 10 Aug 2020 11:59:40 -0700 (PDT) Received: from varodek.localdomain ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id f27sm22683547pfk.217.2020.08.10.11.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 11:59:39 -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 03/12] fbdev: via-core: use generic power management Date: Tue, 11 Aug 2020 00:27:14 +0530 Message-Id: <20200810185723.15540-4-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. Additionally, this helps us to remove the unnecessary call to via_suspend() in the event of Freeze and Hibernate, as the function does nothing in their case. Signed-off-by: Vaibhav Gupta --- drivers/video/fbdev/via/via-core.c | 39 ++++++++++++------------------ include/linux/via-core.h | 2 -- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/drivers/video/fbdev/via/via-core.c b/drivers/video/fbdev/via/via-core.c index 703ddee9a244..89d75079b730 100644 --- a/drivers/video/fbdev/via/via-core.c +++ b/drivers/video/fbdev/via/via-core.c @@ -558,9 +558,8 @@ static void via_teardown_subdevs(void) /* * Power management functions */ -#ifdef CONFIG_PM -static LIST_HEAD(viafb_pm_hooks); -static DEFINE_MUTEX(viafb_pm_hooks_lock); +static __maybe_unused LIST_HEAD(viafb_pm_hooks); +static __maybe_unused DEFINE_MUTEX(viafb_pm_hooks_lock); void viafb_pm_register(struct viafb_pm_hooks *hooks) { @@ -580,12 +579,10 @@ void viafb_pm_unregister(struct viafb_pm_hooks *hooks) } EXPORT_SYMBOL_GPL(viafb_pm_unregister); -static int via_suspend(struct pci_dev *pdev, pm_message_t state) +static int __maybe_unused via_suspend(struct device *dev) { struct viafb_pm_hooks *hooks; - if (state.event != PM_EVENT_SUSPEND) - return 0; /* * "I've occasionally hit a few drivers that caused suspend * failures, and each and every time it was a driver bug, and @@ -600,24 +597,13 @@ static int via_suspend(struct pci_dev *pdev, pm_message_t state) hooks->suspend(hooks->private); mutex_unlock(&viafb_pm_hooks_lock); - pci_save_state(pdev); - pci_disable_device(pdev); - pci_set_power_state(pdev, pci_choose_state(pdev, state)); return 0; } -static int via_resume(struct pci_dev *pdev) +static int __maybe_unused via_resume(struct device *dev) { struct viafb_pm_hooks *hooks; - /* Get the bus side powered up */ - pci_set_power_state(pdev, PCI_D0); - pci_restore_state(pdev); - if (pci_enable_device(pdev)) - return 0; - - pci_set_master(pdev); - /* Now bring back any subdevs */ mutex_lock(&viafb_pm_hooks_lock); list_for_each_entry(hooks, &viafb_pm_hooks, list) @@ -626,7 +612,6 @@ static int via_resume(struct pci_dev *pdev) return 0; } -#endif /* CONFIG_PM */ static int via_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -712,15 +697,23 @@ static const struct pci_device_id via_pci_table[] = { }; MODULE_DEVICE_TABLE(pci, via_pci_table); +static const struct dev_pm_ops via_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .suspend = via_suspend, + .resume = via_resume, + .freeze = NULL, + .thaw = via_resume, + .poweroff = NULL, + .restore = via_resume, +#endif +}; + static struct pci_driver via_driver = { .name = "viafb", .id_table = via_pci_table, .probe = via_pci_probe, .remove = via_pci_remove, -#ifdef CONFIG_PM - .suspend = via_suspend, - .resume = via_resume, -#endif + .driver.pm = &via_pm_ops, }; static int __init via_core_init(void) diff --git a/include/linux/via-core.h b/include/linux/via-core.h index 9e802deedb2d..8737599b9148 100644 --- a/include/linux/via-core.h +++ b/include/linux/via-core.h @@ -47,7 +47,6 @@ struct via_port_cfg { /* * Allow subdevs to register suspend/resume hooks. */ -#ifdef CONFIG_PM struct viafb_pm_hooks { struct list_head list; int (*suspend)(void *private); @@ -57,7 +56,6 @@ struct viafb_pm_hooks { void viafb_pm_register(struct viafb_pm_hooks *hooks); void viafb_pm_unregister(struct viafb_pm_hooks *hooks); -#endif /* CONFIG_PM */ /* * This is the global viafb "device" containing stuff needed by -- 2.27.0