Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp686995pxa; Wed, 19 Aug 2020 12:02:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEyxojNoT2EnilTmXHi2lxx9HkGbdF9qdWoDrhwv+ieS3HhNynyXNiDmE9mcV2PZ8J8AKz X-Received: by 2002:aa7:dd05:: with SMTP id i5mr26677750edv.324.1597863760087; Wed, 19 Aug 2020 12:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597863760; cv=none; d=google.com; s=arc-20160816; b=Mol0DnnQ4ZY4jJHq7EpwyAH5NMraEZ4F0xZy0SPyEyjFx3Jz/vva8jMF7xbcUUZjt5 v/kOQTW3ZTl+9aanQTDhmPM+sbnKCWUx4CURQDmElPceuaYxCBK5MM1GDhkHRpOzxmq0 7b8OQGIpRN5eLY5UX9zQFnyDpB7aLeRVSKpVb2eUm1WOUS5JNpXsv/telu2xdMOeBxay Qle0Yrwo2o9pbFg1uASmEgLaV9kP6kgyRtIdqYiRNwuD1ageV3zveW/guC13u85EyuFl VMltQX2idAwUb4aZgwpvzWg0GnJhzhTBu4RlmZUYKBExaSohv50RUYx//1h4/hFSt7Av NPaQ== 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=0Gdix+uPKbEr2q1rAkmQ4/zXt/qoiwYZqyXTLXnmDDk=; b=FarcdRT4AQhSIwJ05fyKJICIpfqxJU7ifkmQkuK5N+dxGoOGwebumGY/3Pg8D0C3X0 1swoSIgaMRGflHmOIp2muGL1MlBFXukcfkXs7WpUYh6BGuvkWd/EPBcA43Ldexe1Xomp +UaLMuMf86v5GYpFwri9LU58Lok5asz6QHbPHZTeBIQz0paMYWoUWOUY4iACl2/AwwdE Ohc7cahQ9XjGI7OOdXXlwxRp/qnBaIuFgKFpNAJLWVcHiVhAcQ66id1RR2FYhkN9vjbx Yt+lsb9MUTSbV+W6CQunjKMy08wHBSghJGEpN2C9e8muV7stV2oyyuQQNcjJkeDQ91HJ HGGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XlyEM40X; 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 x8si20647467edl.249.2020.08.19.12.02.15; Wed, 19 Aug 2020 12:02: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=XlyEM40X; 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 S1726912AbgHSTAh (ORCPT + 99 others); Wed, 19 Aug 2020 15:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727001AbgHSTAP (ORCPT ); Wed, 19 Aug 2020 15:00:15 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFF84C061757; Wed, 19 Aug 2020 12:00:14 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id 189so11198396pgg.13; Wed, 19 Aug 2020 12:00:14 -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=0Gdix+uPKbEr2q1rAkmQ4/zXt/qoiwYZqyXTLXnmDDk=; b=XlyEM40XfAobLwrCnJxZ+PpEMMRq+xMolyrVrj2Tww7bjz1hZdQsPVecl2oXGO2qAP Q8Oq7jWKduW4VFOrONqraQQKRNouWLsvhjGuFErzhO9S5d5F2F/LoY+IivVJja8W2rVz G0H9ILJHMA16FuIjSL/G3o8gHb32786BH7x3EkMOnGeBgqiczEFCZTDuIt7Re78Zyo11 dorsoAnyjfy+je/HYLmnVCi5njPmKRQa/icsPmDmqBYtF5I2TOYrIg4gQfkxUE2Eah8l +sM0imdXocGmRkbXfFZh4hyoamEY3SxoIce9Zk0IRNLN6x0XdYQgCr5VLk0+/xltYYtI OXYA== 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=0Gdix+uPKbEr2q1rAkmQ4/zXt/qoiwYZqyXTLXnmDDk=; b=B0eMigUuNQqWLxEQeOG+1Crz0EJ9YehmjLn2k39gidfdIn9cjMPnPXLr5JyETMId5n wLKpyo6Rt1AMm9/AgVXfaq/OL8eW7ATCl2BiAD+l2EfSmIBZND2AE2r8MWfSr7rYEfle P8/9Bv4sWR8pNJ6mrHhf5vRBtQEHqrV98Z0nf5tDNR5I1jxnmTJ2WvGjyRrcjP3LcYdR yFSqrUhOBsz1uzYcLuogzk6GeftjGO0JWFx4pa8EOSZvCnTnaZTIa8Fz7FOmNMGUjn9b 8ozbGxhm3V1jQX7O+xu9CTgTaywiNuNXf7pzFjVjkcczZtXLQZhHhSVF8AUjvAP5ucfa 6aIQ== X-Gm-Message-State: AOAM533Ja2TJmbOfEA0Aj99GHQN2Lv6SwJKKwI0JlfSLrbjDamdJ0FYU buFpnZlVZKX8+fjckonnlaM= X-Received: by 2002:a63:1342:: with SMTP id 2mr17049990pgt.214.1597863614285; Wed, 19 Aug 2020 12:00:14 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id o134sm29149305pfg.200.2020.08.19.12.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 12:00:13 -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 12/12] fbdev: arkfb: use generic power management Date: Thu, 20 Aug 2020 00:26:54 +0530 Message-Id: <20200819185654.151170-13-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 ark_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 "ark_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/arkfb.c | 41 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c index 11ab9a153860..edf169d0816e 100644 --- a/drivers/video/fbdev/arkfb.c +++ b/drivers/video/fbdev/arkfb.c @@ -1085,12 +1085,11 @@ static void ark_pci_remove(struct pci_dev *dev) } -#ifdef CONFIG_PM /* PCI suspend */ -static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state) +static int __maybe_unused ark_pci_suspend(struct device *dev) { - struct fb_info *info = pci_get_drvdata(dev); + struct fb_info *info = dev_get_drvdata(dev); struct arkfb_info *par = info->par; dev_info(info->device, "suspend\n"); @@ -1098,7 +1097,7 @@ static int ark_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; @@ -1106,10 +1105,6 @@ static int ark_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(); @@ -1119,9 +1114,9 @@ static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state) /* PCI resume */ -static int ark_pci_resume (struct pci_dev* dev) +static int __maybe_unused ark_pci_resume(struct device *dev) { - struct fb_info *info = pci_get_drvdata(dev); + struct fb_info *info = dev_get_drvdata(dev); struct arkfb_info *par = info->par; dev_info(info->device, "resume\n"); @@ -1132,14 +1127,6 @@ static int ark_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); - arkfb_set_par(info); fb_set_suspend(info, 0); @@ -1148,10 +1135,17 @@ static int ark_pci_resume (struct pci_dev* dev) console_unlock(); return 0; } -#else -#define ark_pci_suspend NULL -#define ark_pci_resume NULL -#endif /* CONFIG_PM */ + +static const struct dev_pm_ops ark_pci_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .suspend = ark_pci_suspend, + .resume = ark_pci_resume, + .freeze = NULL, + .thaw = ark_pci_resume, + .poweroff = ark_pci_suspend, + .restore = ark_pci_resume, +#endif +}; /* List of boards that we are trying to support */ @@ -1168,8 +1162,7 @@ static struct pci_driver arkfb_pci_driver = { .id_table = ark_devices, .probe = ark_pci_probe, .remove = ark_pci_remove, - .suspend = ark_pci_suspend, - .resume = ark_pci_resume, + .driver.pm = &ark_pci_pm_ops, }; /* Cleanup */ -- 2.28.0