Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp686932pxa; Wed, 19 Aug 2020 12:02:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkeSQf1ugvXyZZ1J90cR7//Bo9dQNaPcjVnYWDgNJqf7QFla95GIpUO6G1rdSrspPHxqNi X-Received: by 2002:a05:6402:44e:: with SMTP id p14mr26673629edw.1.1597863753390; Wed, 19 Aug 2020 12:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597863753; cv=none; d=google.com; s=arc-20160816; b=XIGwM06wAF5nvUV8NFBhk6XXNJAjMXB8Ku2h8A41BFuzfTJLVIC8eyB8aKFoG8cT/t ImEVS6XBbu6DHldiZ8+5VjnaE1rUhYbEGM1gU1noRO05W6EL+sgmIayfJosJ2q/4ebvK yUslg/eFsrHtnXm2tHhMBHdka+Pw99bzdck1znYsfwYrd7pAqmr5iE5GuuSTn8ruqj2n 2XuA8QLcBDfuQ8Yzm0Y31BrlIuG8unFNnQ7FRAabr3pDlii8rmAS6t3EyqKCtroAWJG0 0a/rQwPLAES1BeewO7pZdmxc4gpR0nRzkbSHeHWXcEJwSDF3Yb916LuptxqhocOjDz6k HVPA== 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=OQnwLM4dHzJRAnTfJIXhUQMR/ExLuRw9KF4MfB1j53g=; b=Or4SjnH+s86lDe9qLUtB4RciLNdDicdaQXEUcf1Ju7Gn0Ipmx16JgiW7dgzr41Z6H8 J7XEwcL1h3f2cdZkFsmyvimc77PZG86FYUfgsH7t8EwzkaVPK/TknXLnERDWwTkH6BkR AB/4hbAL1a5yBr8Zou3kVdLwZ7jL1fyseyIqRYUmISDzm/kjb0CTWRZZfzsCMad8IBCn Kz8d499AP6mlbyqkLPnn+JcVqFIy4y5jeMRmYn4DcAPaJ2VFGcIvW8t7+qF169ekESY/ y8nFwJk09wVulwPWntE8qFHfJGMSkgFvLtXNRa6ZHQDnqP0t/ucDmSeZOS1s4WV49H1J MjpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gx7mrlJc; 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 o18si15020930ejg.391.2020.08.19.12.02.09; Wed, 19 Aug 2020 12:02:33 -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=gx7mrlJc; 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 S1727030AbgHSTAS (ORCPT + 99 others); Wed, 19 Aug 2020 15:00:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbgHSTAD (ORCPT ); Wed, 19 Aug 2020 15:00:03 -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 C7FF9C061383; Wed, 19 Aug 2020 12:00:02 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id m71so12157480pfd.1; Wed, 19 Aug 2020 12:00:02 -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=OQnwLM4dHzJRAnTfJIXhUQMR/ExLuRw9KF4MfB1j53g=; b=gx7mrlJc35T2/ZQi9Ht3XPkUZr4qb95Oiy+82MqtFzf59AJSK64W3nD5D3fcnSWRX0 GL0MzqVUQTqzN6QVh20pRmm4cs2nTigUzBtI7lJWyOx8nme6vpWqrvujXYEZP0ZFMVnF 5NcmEZTeEZbgtIm5jgRdekRSCAtjU2wN7iBsbqlcB7LRdNasMVRuh7VDUVwfI5vkXqNx 9e903tRxOZIZXUTNPbQ+/y1y+Ij8Sj4FGiwjxF10BsepnmkBN5i4x3MMbQD23/v4dWQ4 J+comHnnOQiu3+IYsOml/pdcZp4DqO1I2qSDpq8NYQD1Xr+dE8cT/9rqGrrv/Pcgi9Yw nlnA== 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=OQnwLM4dHzJRAnTfJIXhUQMR/ExLuRw9KF4MfB1j53g=; b=ipNx42dzjpH4IgdMuE9m9XNRhsTYpI7d/341hQPTxlZwMprQY+5VJRGoik6CECG3TO mTJtTUvNZ+2ozG8lnvkYZuCD5zyr2FbG4RmNo6KiF5gF7GKxsP/3d6WWUYdQFt8uEb2M nCsOgZoYoGmCuqBZJhy2cQ3B4bQm3ABTnpZrjeyyD3CHwxYTceGB4BARfuRanhzXUQoN MQ1O+18yhBZulklCQBQ5K4TP94U8pLEJolPKtu4H412JH4myiSUXFgbA+qHj8sfkmBPB ii7TZfv+wEOiCKt6tWGHd5X5FGUmaBYO6PtzI9BS39/KH5nz7Dk4pfKWGEqG1CARgr1R gDNA== X-Gm-Message-State: AOAM530prXbEaInInCqMs/xfDBgyveJf4P+qpXVuNA/+FdNckpnfY3gI FB3BxbfojCkJpoBA1D4fF0A= X-Received: by 2002:aa7:92c7:: with SMTP id k7mr19149604pfa.239.1597863602281; Wed, 19 Aug 2020 12:00:02 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id o134sm29149305pfg.200.2020.08.19.11.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 12:00:01 -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 v3 10/12] fbdev: vt8623fb: use generic power management Date: Thu, 20 Aug 2020 00:26:52 +0530 Message-Id: <20200819185654.151170-11-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819185654.151170-1-vaibhavgupta40@gmail.com> References: <20200819185654.151170-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. The vt8623_pci_suspend() is not designed to function in the case of Freeze. Thus, the code checked for "if (state.event == PM_EVENT_FREEZE....)". This is because, in the legacy framework, this callback was invoked even in the event of Freeze. Hence, added the load of unnecessary function-call. The goal can be achieved by binding the callback with only ".suspend" and ".poweroff" in the "vt8623_pci_pm_ops" const variable. This also avoids the step of checking "state.event == PM_EVENT_FREEZE" every time the callback is invoked. Signed-off-by: Vaibhav Gupta --- drivers/video/fbdev/vt8623fb.c | 41 ++++++++++++++-------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/video/fbdev/vt8623fb.c b/drivers/video/fbdev/vt8623fb.c index 7b3eef1b893f..c488e0117758 100644 --- a/drivers/video/fbdev/vt8623fb.c +++ b/drivers/video/fbdev/vt8623fb.c @@ -815,12 +815,11 @@ static void vt8623_pci_remove(struct pci_dev *dev) } -#ifdef CONFIG_PM /* PCI suspend */ -static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state) +static int __maybe_unused vt8623_pci_suspend(struct device *dev) { - struct fb_info *info = pci_get_drvdata(dev); + struct fb_info *info = dev_get_drvdata(dev); struct vt8623fb_info *par = info->par; dev_info(info->device, "suspend\n"); @@ -828,7 +827,7 @@ static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state) console_lock(); mutex_lock(&(par->open_lock)); - if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) { + if (par->ref_count == 0) { mutex_unlock(&(par->open_lock)); console_unlock(); return 0; @@ -836,10 +835,6 @@ static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state) fb_set_suspend(info, 1); - pci_save_state(dev); - pci_disable_device(dev); - pci_set_power_state(dev, pci_choose_state(dev, state)); - mutex_unlock(&(par->open_lock)); console_unlock(); @@ -849,9 +844,9 @@ static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state) /* PCI resume */ -static int vt8623_pci_resume(struct pci_dev* dev) +static int __maybe_unused vt8623_pci_resume(struct device *dev) { - struct fb_info *info = pci_get_drvdata(dev); + struct fb_info *info = dev_get_drvdata(dev); struct vt8623fb_info *par = info->par; dev_info(info->device, "resume\n"); @@ -862,14 +857,6 @@ static int vt8623_pci_resume(struct pci_dev* dev) if (par->ref_count == 0) goto fail; - pci_set_power_state(dev, PCI_D0); - pci_restore_state(dev); - - if (pci_enable_device(dev)) - goto fail; - - pci_set_master(dev); - vt8623fb_set_par(info); fb_set_suspend(info, 0); @@ -879,10 +866,17 @@ static int vt8623_pci_resume(struct pci_dev* dev) return 0; } -#else -#define vt8623_pci_suspend NULL -#define vt8623_pci_resume NULL -#endif /* CONFIG_PM */ + +static const struct dev_pm_ops vt8623_pci_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .suspend = vt8623_pci_suspend, + .resume = vt8623_pci_resume, + .freeze = NULL, + .thaw = vt8623_pci_resume, + .poweroff = vt8623_pci_suspend, + .restore = vt8623_pci_resume, +#endif /* CONFIG_PM_SLEEP */ +}; /* List of boards that we are trying to support */ @@ -898,8 +892,7 @@ static struct pci_driver vt8623fb_pci_driver = { .id_table = vt8623_devices, .probe = vt8623_pci_probe, .remove = vt8623_pci_remove, - .suspend = vt8623_pci_suspend, - .resume = vt8623_pci_resume, + .driver.pm = &vt8623_pci_pm_ops, }; /* Cleanup */ -- 2.28.0