Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1777950ybh; Mon, 20 Jul 2020 07:04:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVrAJIioLg6horATrpkPmUrnJKkLIGCZ9HI3NE0wCWLFIQUI1YJshhuuzhQNY9ET+7gvkb X-Received: by 2002:aa7:d88c:: with SMTP id u12mr12735807edq.29.1595253860078; Mon, 20 Jul 2020 07:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595253860; cv=none; d=google.com; s=arc-20160816; b=EHTcqJ+VKdhAklZvX8W5F+W29WNW/BFHxLjC+LcKvEmWNGCM4v37vAP1hUUWrEr4H8 LTPSNSlyhfuurz+GjAYU900Gn75MQQa4LVE1mDHUNTc9rDgELYFiqki9g+l4+x8lkxs1 CI/8f1GPmMqGg2oenoRfmEpYWOoL07hbvUSZD11zPj3Ftpe0mWDdZLaYRrEHP8V3+VnD MCoPdy+8/wXV9xjyFR4IXDmH7zl1VLLjfOOJ90pOfmXlnO7/kPOe9AwxjvEdYexD6d+v lyXqyaK+ZXi2gzurYwSuRhWVNEucKwTAAD2BX8VsNOPaly9aa3NCq4eaiArZNSa++mQf el3g== 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=NvjcerpoGbzCqh4PiBTodpMKQRC6COJGb/XldQjhF8w=; b=BhVmCKiq6Na9/r+SSd+nmJUjOJwdbSxQR6NNblVWxV02tcMr1+oxY2ksWHOQ0Bi78r 3hVxVvm/IV141Y+ndTsNMoml3f4DlWJejyTkDVD7tIeZKRn9Y7kLDN/16DqdQzVGBssz DsluyTN5sLG5ptl9NOXKt0BC+kns0biPXOiHEpmTe15rQK7BzXqvfEpZYH1rdjHU2Rav LaC9/Ie4iITdCL25Qq9gq5vu27u2AsqMWjJgB13uE5ffZG+l1AxuEQ92vNROnXYZQflJ dLcWDldIYoTSUqIEIDmV6G3GZ133exgqes/JV3SeuR71IGNjUdYsKViF21Zub2SMZLAL ug6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vdp2OlVt; 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 co19si10359505edb.605.2020.07.20.07.03.56; Mon, 20 Jul 2020 07:04:20 -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=vdp2OlVt; 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 S1728171AbgGTODM (ORCPT + 99 others); Mon, 20 Jul 2020 10:03:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbgGTODM (ORCPT ); Mon, 20 Jul 2020 10:03:12 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67118C061794; Mon, 20 Jul 2020 07:03:12 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id f16so10150712pjt.0; Mon, 20 Jul 2020 07:03:12 -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=NvjcerpoGbzCqh4PiBTodpMKQRC6COJGb/XldQjhF8w=; b=vdp2OlVtYtgwwNvWfxMZw0hNeAtgQ8Ohk4zCvTDYnF9fvZR8A/bM5eaUWE5WClGGMB Z9r8SVjpQCXZ05FMcQ6rDEAKzHo4qx/Q6dCuOX9U/EJCXyOoavZEC50SJkoJjGWUyk0A IUQh/xCh5zY616an3Ng6ObsbhT52rw7DPnzZi2kMVhsYzbPEif0qniIB6JKEQPNrD6O+ XbU46obyQLZ3apRH0ByW4x8oRrJ0A/8yIXONFA8Sup7PNu2VTKtVhz+wHTDZeKUFmTpB hrb5b56yPlcOvEoQTM5DH/dhTbx39GNThWzVoi8v9TBAc7r4CpUYCA18trSRC/tiQqIk vdPg== 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=NvjcerpoGbzCqh4PiBTodpMKQRC6COJGb/XldQjhF8w=; b=SMZHOW3ODRPMYjwHkrmG9JdlQ4zmYobROeAOmdjwjDF7HE1iGYtR/tAuGM54STStNV adq9yGBwWA5Ebo0JcE3Yv0D32sIOUcZvoLlItd+5vr17R6JvKR5ePJlfMEJsc42kiQ6t mClhNyM/e7jzFoXSnsfmdt63GH1Fnl65zIG5EqlMTKKwtBNedGWsRyE866kaK4o0mtP/ CYVwngA2qYzBTNY0K/Al83M1TDdmoXPfFXIEwo5AMfCkRsiU8yyfVU868oHayINwgMOm ETjPMMLr8HEDQ2KUWb34nE7xhlSqIDDh/wThm4QxzC0Yd3ZCavEOB7FB0MiIOGJRQii2 F/+w== X-Gm-Message-State: AOAM533cyW1a614xTtT9bXRwBgcE7FAbgxC9s1roLZcRE4rtogO7FZO5 VLhLlwFh7VHuJxZXPDWpoj4= X-Received: by 2002:a17:90a:1a13:: with SMTP id 19mr21689484pjk.167.1595253791829; Mon, 20 Jul 2020 07:03:11 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.153.67]) by smtp.gmail.com with ESMTPSA id w64sm15773459pgd.67.2020.07.20.07.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 07:03:10 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta Cc: Vaibhav Gupta , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Shuah Khan Subject: [PATCH v1] i2c: eg20t: use generic power management Date: Mon, 20 Jul 2020 19:30:32 +0530 Message-Id: <20200720140031.511830-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 PM have to manage PCI states and device's PM states themselves. They also need to take care of configuration registers. With improved and powerful support of generic PM, PCI Core takes care of above mentioned, device-independent, jobs. This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(), pci_enable_wake() and pci_set_power_state() to do required operations. In generic mode, they are no longer needed. Change function parameter in both .suspend() and .resume() to "struct device*" type. Use to_pci_dev() and dev_get_drvdata() to get "struct pci_dev*" variable and drv data. Compile-tested only. Signed-off-by: Vaibhav Gupta --- drivers/i2c/busses/i2c-eg20t.c | 39 ++++++++-------------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c index 73f139690e4e..c0ddc4cc2ce7 100644 --- a/drivers/i2c/busses/i2c-eg20t.c +++ b/drivers/i2c/busses/i2c-eg20t.c @@ -846,11 +846,10 @@ static void pch_i2c_remove(struct pci_dev *pdev) kfree(adap_info); } -#ifdef CONFIG_PM -static int pch_i2c_suspend(struct pci_dev *pdev, pm_message_t state) +static int __maybe_unused pch_i2c_suspend(struct device *dev) { - int ret; int i; + struct pci_dev *pdev = to_pci_dev(dev); struct adapter_info *adap_info = pci_get_drvdata(pdev); void __iomem *p = adap_info->pch_data[0].pch_base_address; @@ -872,34 +871,17 @@ static int pch_i2c_suspend(struct pci_dev *pdev, pm_message_t state) ioread32(p + PCH_I2CSR), ioread32(p + PCH_I2CBUFSTA), ioread32(p + PCH_I2CESRSTA)); - ret = pci_save_state(pdev); - - if (ret) { - pch_pci_err(pdev, "pci_save_state\n"); - return ret; - } - - pci_enable_wake(pdev, PCI_D3hot, 0); - pci_disable_device(pdev); - pci_set_power_state(pdev, pci_choose_state(pdev, state)); + device_wakeup_disable(dev); return 0; } -static int pch_i2c_resume(struct pci_dev *pdev) +static int __maybe_unused pch_i2c_resume(struct device *dev) { int i; - struct adapter_info *adap_info = pci_get_drvdata(pdev); - - pci_set_power_state(pdev, PCI_D0); - pci_restore_state(pdev); + struct adapter_info *adap_info = dev_get_drvdata(dev); - if (pci_enable_device(pdev) < 0) { - pch_pci_err(pdev, "pch_i2c_resume:pci_enable_device FAILED\n"); - return -EIO; - } - - pci_enable_wake(pdev, PCI_D3hot, 0); + device_wakeup_disable(dev); for (i = 0; i < adap_info->ch_num; i++) pch_i2c_init(&adap_info->pch_data[i]); @@ -908,18 +890,15 @@ static int pch_i2c_resume(struct pci_dev *pdev) return 0; } -#else -#define pch_i2c_suspend NULL -#define pch_i2c_resume NULL -#endif + +static SIMPLE_DEV_PM_OPS(pch_i2c_pm_ops, pch_i2c_suspend, pch_i2c_resume); static struct pci_driver pch_pcidriver = { .name = KBUILD_MODNAME, .id_table = pch_pcidev_id, .probe = pch_i2c_probe, .remove = pch_i2c_remove, - .suspend = pch_i2c_suspend, - .resume = pch_i2c_resume + .driver.pm = &pch_i2c_pm_ops, }; module_pci_driver(pch_pcidriver); -- 2.27.0