Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp738547pxa; Wed, 5 Aug 2020 11:31:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv4WJ/jJMlrV76vgWa5ceJvLg6P4hBTF/vFM/Ya2wEXJT22/2QcWi9FH0672cip7NJqOGJ X-Received: by 2002:aa7:c1d4:: with SMTP id d20mr549127edp.81.1596652290939; Wed, 05 Aug 2020 11:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596652290; cv=none; d=google.com; s=arc-20160816; b=fs51uXvcrf78k6CYc5uUWDjG0sUgIOX9TNswRtM0e5VombEY+kc/0g2u5f2S7j7mD9 D50n3vC/DsmRIjhYZAMtO3ZFh6A5qOl+IBiH/5+wxwFsh2nA4m5XN3XyOIqHU5SOFV2v wMxmK/ru8lpt8wWz93urzsWWN1mBvIm4YhRUtNpdtP+GoYRY+32CFVS5Sey6DDNN+eZY 4UEBFG1Jw2Kf439H6I/W7AE8S4DPmQ+/n/61/lmoewCfDYD8LyWdBxznhwNC+IR39dmD YiPD4SET1ej2e5Kp5gzIM2TGlWAaQxgf37bxSr6CG6vXyQwCVHex4pUcEwkPqK5WFAqg vxSg== 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=3uItQaxawuJpK5je/oUH/UET1q9rEg6Zl2yCHgObWaU=; b=OeA8d+TVs01PMhN6IYhefT2kljYjWRJY9C6+GHMQ9jnJdIhFoXgNJrH6CNQifFOs8D YFznCvZ2IoJkYQocVpx/F5Bk/iTwYujPVwyCtz6V2DKLbBMerVRX2/AizhqFVsiDRsHP Xjfr50RJAo0+ks508gGmmWW1rczoFnv6alLaieaLcEpKvH/4CDHsUanSDwRxnO2m96Lr KAw0lnRnmHVGNLMZIvlSCTU+6MaGo6iG8STUvc4rvmHOscsu6MwEp2lHJ0BO5W+36H3J q3hMR5XDktjLl4H+8tNh0V9h+PaIUDKSctehliRADU50cVzlAad+HjlZlX3v2TbcoLMP 4yEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AZ+Ob5Uw; 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 f24si1731807edm.305.2020.08.05.11.30.35; Wed, 05 Aug 2020 11:31:30 -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=AZ+Ob5Uw; 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 S1729218AbgHESYx (ORCPT + 99 others); Wed, 5 Aug 2020 14:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729114AbgHESKM (ORCPT ); Wed, 5 Aug 2020 14:10:12 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD28AC0617A2; Wed, 5 Aug 2020 11:09:38 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id e4so5006882pjd.0; Wed, 05 Aug 2020 11:09:38 -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=3uItQaxawuJpK5je/oUH/UET1q9rEg6Zl2yCHgObWaU=; b=AZ+Ob5UwDYRFspLaKbnD3yYh2qZsQKHrcZDLyvODYGY1YbkFdqYvUpnWs+STSiKBit WLz2kwHe+aE4KxOc7yBn6ML9QYCd1mGW2siMD2WhuF/q9YMMA4dquWeum7W973iiC2YV X1u0h6MRWU2/yNBeQAjyu+4MW5mPWkvLREPJ1FzwtTQIezg31a3imnvvrKmTR12u9f5Y ueaIfnxZgNw4QSD1onlwxzEvBGGcMOek4BTA6qbPo+b8eO1x3SNxStKvABVAhIcpcVDb r/gcMW4yBFwRb4oRr6EeUXKxmKQ2qSLzJzytfLwwSm8M418t+2GulbS2UlAJoMrhdD1e l1Mw== 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=3uItQaxawuJpK5je/oUH/UET1q9rEg6Zl2yCHgObWaU=; b=QRBpLyAL2hVCP9qb37tevrY2qK/UxdRV3B8zfeCJZetAJXRggzwaAy3xDvEOUPZ1OS g4niOP1e3Iw6atTt9Nykij1zfzfOm38qt9kLz8I51HHRfw2wISDOWtntGm89xIrEBtm3 ndxEKfyTWAbJiRHNrkxt7F8L6KQmExx+hrsolQ1m30QX3C2ehoAwQIWyCd5jxKNP8Soe sv1FUdjzKoxaC42SJvdHg4o52fT7aWAwQvkOIKx8LSJh2wve5fiJ3sjuoIMFw31q8N2O usWWx8onYknRQdEDilmPuJgUeEw3cblj1MCHmzg2H60t2qrP0asfiK2VhkWePzaYuSK0 g68w== X-Gm-Message-State: AOAM530AREdGw3uoofvOE5s+LFss0miVyqgkmEieI+T7ZBtW6Jpp/cHr jAYqg9DPPAdgImy4lr87KqA= X-Received: by 2002:a17:90a:f192:: with SMTP id bv18mr4155781pjb.21.1596650978416; Wed, 05 Aug 2020 11:09:38 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 11:09:38 -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 03/12] fbdev: via-core: use generic power management Date: Wed, 5 Aug 2020 23:37:13 +0530 Message-Id: <20200805180722.244008-4-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/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