Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp186807ybg; Tue, 28 Jul 2020 03:27:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeKKR65VtElo5QrNBmfl70G4ZnWPxhIN0g5vM/dq30Dsp9fuBIVlkLj5etVEK/JDkRknW0 X-Received: by 2002:a17:906:c1c3:: with SMTP id bw3mr17037890ejb.8.1595932028547; Tue, 28 Jul 2020 03:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595932028; cv=none; d=google.com; s=arc-20160816; b=ICTrrGm7kZFVxE4LUCUtg96fJEHhuzsZLeh8/KjBJM1xCEfusUUUEUEeOMHTzy6ib9 ZEKXb+M4jvXDx7b0eUKHsJUnHGK3Pa/dw9E73yn2q/Z8AGxLB56/+nSe/U8rjEHcxUpT m1KOrt298+VrYCpefgUShdICjyxSUQI1yAhTmQ048cHMcytWA5Dyc6B5oKZYnu6YZnCA PkC4g2GJsCchUPQRa7BftwGLwMxSVtdMJ/PT2otajQrAfGU5U1tulAgTSfRGF03rb86E f/q1XbyoNVdefVXD4osJWagdSWSSyvkIBbO2Nz8+O3S4fPT3ssGCM4pVUGhKYTZrADX4 kykA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=aAK7NZIIkVIKxbhw+1qDbbbtZdz+xeC5teBUBWJVzQI=; b=uqxiA8bTxobu6u5O/0RwzBLx+tf3/MenUsZ2OWfYq+RMPWtzox/T50ypfMntE9bs5J oXlDGMMEC+4Pi3dumXg33gVQanL/qv1inLCUQ8iFsYeqBwHBxN9YryHx/Q3XWGTwfdOa 51jVIuYZdwyvphTeJK7Ui9IDsjw/5OPEl5kdb6txcPwEpZvzeY78xEhUB/tm60J84gx5 zOGs4F+ctX5+nrj6oKtglZ+gNMy40uq6AUAbR3KDxJ1xqLgu9PBCOoIWRqKRgwCb1Y/y sz9n1VYQewNp/bYUzjfHlfBSkvI+IsG80uwpU4Yp1DY+GnUM9fZVTvADONY7bbjGHIJl 5Rqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Wmz69gtA; 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 a3si2206088edk.48.2020.07.28.03.26.44; Tue, 28 Jul 2020 03:27: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=Wmz69gtA; 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 S1728632AbgG1KZv (ORCPT + 99 others); Tue, 28 Jul 2020 06:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728424AbgG1KZu (ORCPT ); Tue, 28 Jul 2020 06:25:50 -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 611A5C061794; Tue, 28 Jul 2020 03:25:50 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id a9so11263232pjd.3; Tue, 28 Jul 2020 03:25:50 -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:mime-version :content-transfer-encoding; bh=aAK7NZIIkVIKxbhw+1qDbbbtZdz+xeC5teBUBWJVzQI=; b=Wmz69gtAJ/8KHH9ECmxzv3ZOuWv5DZ0Uz6a5vygrxjfsooBYBQfIJDbjnVvs58z7bn 3PCWAZA17+61JdwYRbakstPRLIOXhKGtTycCBBdfUtWPPbd5QWrjNelnWXZ5CLVzuFcc Jw/1pMHBhfLoENQNdnlcXF9lglMgB4VIx83hbl+eQ4Dbsv1npCm1cOosvz9MapH7/FQj rG2t/KgZzxQniLMXFlSc/HsGECD8YBRo8YWtLVBiKcDv/Kz/h47GzWF9MPZsQ4nVDNbQ USkL5/AZSjI9+c3xQti2wt6zqvSlKmoR7FRmjuEmRAcw5ZkEs73Kif5YKV/03h98WShB AmQA== 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:mime-version :content-transfer-encoding; bh=aAK7NZIIkVIKxbhw+1qDbbbtZdz+xeC5teBUBWJVzQI=; b=BxCBrqym8wXy/OyFSLPdFN+pNJ/FpD638hiy/T2mCjLWJwLHNRddMm+J6BWWDcWVlM i31x3gpPvaAw5tcf5Jg58+PAvJ0GcVTLti3fdeSZAccaXsq6vtNiJ20JMLKpZ8O4e1/F h1oizvBeMt29YUbKzENdu86ZNPyBuNg2eF8xQcQz/FtrL3JGsWqzF9SKpkkiKZbHJtTt 1bymd7fcHetEaYhIV3LkRKTwuE3Ok+H9V6fbTI5UIldcpB3e5PohctlZjERAMdEMHjjL FyMWRiO4BjK1ebX5reRmNTEw+wzvO0HodOrkyB2dSJ/2kItIWc+TE/ry1B/Aas3PeClC yExg== X-Gm-Message-State: AOAM530OF6P/TP7lnNYBXHfu4y8rCXED9TrPg4ZWfpm/nb1Yn/TfuPGY RDG4znKq6pIe/gBnc0FCoQI= X-Received: by 2002:a17:90a:8985:: with SMTP id v5mr3698662pjn.181.1595931949843; Tue, 28 Jul 2020 03:25:49 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id q73sm2709295pjc.11.2020.07.28.03.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 03:25:49 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , Mauro Carvalho Chehab , Hans Verkuil Cc: Vaibhav Gupta , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Shuah Khan Subject: [PATCH v1] [media] bttv: use generic power management Date: Tue, 28 Jul 2020 15:54:18 +0530 Message-Id: <20200728102418.1069512-1-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.27.0 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/media/pci/bt8xx/bttv-driver.c | 56 ++++++++------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c index 9144f795fb93..cb8d955d1d5d 100644 --- a/drivers/media/pci/bt8xx/bttv-driver.c +++ b/drivers/media/pci/bt8xx/bttv-driver.c @@ -4263,15 +4263,14 @@ static void bttv_remove(struct pci_dev *pci_dev) return; } -#ifdef CONFIG_PM -static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) +static int __maybe_unused bttv_suspend(struct device *dev) { - struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); + struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); struct bttv *btv = to_bttv(v4l2_dev); struct bttv_buffer_set idle; unsigned long flags; - dprintk("%d: suspend %d\n", btv->c.nr, state.event); + dprintk("%d: suspend\n", btv->c.nr); /* stop dma + irqs */ spin_lock_irqsave(&btv->s_lock,flags); @@ -4291,42 +4290,19 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN); btv->state.gpio_data = gpio_read(); - /* save pci state */ - pci_save_state(pci_dev); - if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { - pci_disable_device(pci_dev); - btv->state.disabled = 1; - } + btv->state.disabled = 1; return 0; } -static int bttv_resume(struct pci_dev *pci_dev) +static int __maybe_unused bttv_resume(struct device *dev) { - struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); + struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); struct bttv *btv = to_bttv(v4l2_dev); unsigned long flags; - int err; dprintk("%d: resume\n", btv->c.nr); - /* restore pci state */ - if (btv->state.disabled) { - err=pci_enable_device(pci_dev); - if (err) { - pr_warn("%d: Can't enable device\n", btv->c.nr); - return err; - } - btv->state.disabled = 0; - } - err=pci_set_power_state(pci_dev, PCI_D0); - if (err) { - pci_disable_device(pci_dev); - pr_warn("%d: Can't enable device\n", btv->c.nr); - btv->state.disabled = 1; - return err; - } - - pci_restore_state(pci_dev); + btv->state.disabled = 0; /* restore bt878 state */ bttv_reinit_bt848(btv); @@ -4344,7 +4320,6 @@ static int bttv_resume(struct pci_dev *pci_dev) spin_unlock_irqrestore(&btv->s_lock,flags); return 0; } -#endif static const struct pci_device_id bttv_pci_tbl[] = { {PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT848), 0}, @@ -4357,15 +4332,16 @@ static const struct pci_device_id bttv_pci_tbl[] = { MODULE_DEVICE_TABLE(pci, bttv_pci_tbl); +static SIMPLE_DEV_PM_OPS(bttv_pm_ops, + bttv_suspend, + bttv_resume); + static struct pci_driver bttv_pci_driver = { - .name = "bttv", - .id_table = bttv_pci_tbl, - .probe = bttv_probe, - .remove = bttv_remove, -#ifdef CONFIG_PM - .suspend = bttv_suspend, - .resume = bttv_resume, -#endif + .name = "bttv", + .id_table = bttv_pci_tbl, + .probe = bttv_probe, + .remove = bttv_remove, + .driver.pm = &bttv_pm_ops, }; static int __init bttv_init_module(void) -- 2.27.0