From patchwork Fri Nov 10 18:11:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 163924 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp1323393vqs; Fri, 10 Nov 2023 11:06:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0IYdJwew9nY0Ff79ZcmTxT7yZyhxiMe8yMsfhekb7eASxsy4hnS63gNjL3cHgc6L/FDK6 X-Received: by 2002:a17:90a:b293:b0:280:47ba:767a with SMTP id c19-20020a17090ab29300b0028047ba767amr4729598pjr.16.1699643193971; Fri, 10 Nov 2023 11:06:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699643193; cv=none; d=google.com; s=arc-20160816; b=n98WZ+Djkzqa4z8FKlwePxM6gcGF5HFpr64ugYvhiar95WK03Kh5kzcCBWnU7BLLl7 qPDICJhcPq8zo9463Qp+CBDYV/b9DaU9cnj4wj1QCdudBPHrmBcOMsTfqDbrBLQKkJsb kWY5Gh1SM05JsulK984xkTVWkUseWaFUFsVlfiI+0knuSYmTeqmtRu2cERHAY75H2KT8 LHZma53LYJxscSU+c1xJM/lNuguGe+82ZgNmjQL6LZvB8uOAOBMun/aFR7XzWuomoqlZ PIemosO8dzdWZPwLqDC94DhgPQB6AGGJaXS6tB6C6NE65/+0fY59ul+ppDkHTsJ55J9G 1wuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yiQuY9CeHGunj/xu2TPhZYIlISf0Td60hm9xeNcHMY0=; fh=oqZDtrV02dtzkTHSBiwo+TWR13WhTCI6t34Q5J0VV5o=; b=RWG4h/rPQsopqL7WVI3IsvdJpy2dOJptR/ccNoNths0TavxdRqCNmT3iOcpHEYtN30 f5VVrM0XobpI4w0Ma2LFnMAZxrosJN+VtecFZuh19ijmxopl0vkCi4T7V7irxy3cdwcZ GU2m++ilGp/q92OWMpKCwY4o10pU23ZYCu08X1Ec3uBF9PT2CKQ1hNBCIYxsC2vqygVo Klo3QUhOpkEJDtP3Hu8YC08TsAS1qf8PgunT/SF6uCAUtMlwJo4/OH1DT1CwDAN15k/a 1DXO+/2u/tjoDoluXg/TVJac9JlgA7u9w+b/OEgVDSlh5coIS+Ub1UyCiPRpbHrupm2g +Szw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SKyRDH++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id i8-20020a17090a7e0800b0027901ee93fbsi4533132pjl.156.2023.11.10.11.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 11:06:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SKyRDH++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 162E5837ED38; Fri, 10 Nov 2023 11:05:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235970AbjKJTD4 (ORCPT + 29 others); Fri, 10 Nov 2023 14:03:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235976AbjKJTDj (ORCPT ); Fri, 10 Nov 2023 14:03:39 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 221824C3E; Fri, 10 Nov 2023 10:27:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699640826; x=1731176826; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FDUwAH8xOLBxnLuBaj9E/OeMnat6GwenshE3bhi4w4o=; b=SKyRDH++rgqyPnTkSLufddY9m/7env76007vWSiPtRpL+MUI6OtgDO/v dowzZWLVAjYAias1uCwZZPBDbIDr+3YfTRlRP1+IRqBgxIy0oPzptPqr9 6g9rs4UP81RDFN3hBMgzNYYGOd/KTZpyAkjqM7IhaarESv6SJ7C1VOOgB s2Pv/+1c6wH5TDoX1zfWb00twIWLqPe1e3TkK+L+U9D+VfMLfQqoxCbki UxjMRKyrxKw3GYPutLKZmZFpNPlLihgyjw6bmYFGkYvk+7BL2bFx9YD5r ZMZ71SlWBAtTQ0Lmp9/HwDb3wLmSOtFCot5lD1wxt2K3TSD7wAYKGMXfO A==; X-IronPort-AV: E=McAfee;i="6600,9927,10890"; a="375251983" X-IronPort-AV: E=Sophos;i="6.03,291,1694761200"; d="scan'208";a="375251983" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2023 10:23:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10890"; a="798663771" X-IronPort-AV: E=Sophos;i="6.03,291,1694761200"; d="scan'208";a="798663771" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 10 Nov 2023 10:23:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 34FE98D6; Fri, 10 Nov 2023 20:23:08 +0200 (EET) From: Andy Shevchenko To: Jarkko Nikula , Mario Limonciello , Herbert Xu , Andy Shevchenko , Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , Jan Dabros , Andi Shyti , Philipp Zabel , Hans de Goede Subject: [PATCH v3 19/25] i2c: designware: Consolidate PM ops Date: Fri, 10 Nov 2023 20:11:39 +0200 Message-ID: <20231110182304.3894319-20-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20231110182304.3894319-1-andriy.shevchenko@linux.intel.com> References: <20231110182304.3894319-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 10 Nov 2023 11:05:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782205061903822417 X-GMAIL-MSGID: 1782205061903822417 We have the same (*) PM ops in the PCI and plaform drivers. Instead, consolidate that PM ops under exported variable and deduplicate them. *) With the subtle ACPI and P-Unit behaviour differences in PCI case. But this is not a problem as for ACPI we need to take care of the P-Unit semaphore anyway and calling PM ops for ACPI makes sense as it might provide specific operation regions in (however there are no known devices on market that are using it with PCI enabled I2C). Note, the clocks are not in use in the PCI case. Signed-off-by: Andy Shevchenko --- drivers/i2c/busses/i2c-designware-common.c | 62 ++++++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 5 +- drivers/i2c/busses/i2c-designware-pcidrv.c | 44 +------------- drivers/i2c/busses/i2c-designware-platdrv.c | 64 +-------------------- 4 files changed, 69 insertions(+), 106 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c index 50cf4cbfeff3..b7e653e939bd 100644 --- a/drivers/i2c/busses/i2c-designware-common.c +++ b/drivers/i2c/busses/i2c-designware-common.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -712,5 +713,66 @@ void i2c_dw_disable(struct dw_i2c_dev *dev) i2c_dw_release_lock(dev); } +static int i2c_dw_prepare(struct device *device) +{ + /* + * If the ACPI companion device object is present for this device, + * it may be accessed during suspend and resume of other devices via + * I2C operation regions, so tell the PM core and middle layers to + * avoid skipping system suspend/resume callbacks for it in that case. + */ + return !has_acpi_companion(device); +} + +static int i2c_dw_runtime_suspend(struct device *device) +{ + struct dw_i2c_dev *dev = dev_get_drvdata(device); + + if (dev->shared_with_punit) + return 0; + + i2c_dw_disable(dev); + i2c_dw_prepare_clk(dev, false); + + return 0; +} + +static int i2c_dw_suspend(struct device *device) +{ + struct dw_i2c_dev *dev = dev_get_drvdata(device); + + i2c_mark_adapter_suspended(&dev->adapter); + + return i2c_dw_runtime_suspend(device); +} + +static int i2c_dw_runtime_resume(struct device *device) +{ + struct dw_i2c_dev *dev = dev_get_drvdata(device); + + if (!dev->shared_with_punit) + i2c_dw_prepare_clk(dev, true); + + dev->init(dev); + + return 0; +} + +static int i2c_dw_resume(struct device *device) +{ + struct dw_i2c_dev *dev = dev_get_drvdata(device); + + i2c_dw_runtime_resume(device); + i2c_mark_adapter_resumed(&dev->adapter); + + return 0; +} + +EXPORT_GPL_DEV_PM_OPS(i2c_dw_dev_pm_ops) = { + .prepare = pm_sleep_ptr(i2c_dw_prepare), + LATE_SYSTEM_SLEEP_PM_OPS(i2c_dw_suspend, i2c_dw_resume) + RUNTIME_PM_OPS(i2c_dw_runtime_suspend, i2c_dw_runtime_resume, NULL) +}; + MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter core"); MODULE_LICENSE("GPL"); diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 52667d670363..f6ebf86dcc6f 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -337,7 +338,8 @@ int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev); int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev); int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev); u32 i2c_dw_func(struct i2c_adapter *adap); -void i2c_dw_disable(struct dw_i2c_dev *dev); + +extern const struct dev_pm_ops i2c_dw_dev_pm_ops; static inline void __i2c_dw_enable(struct dw_i2c_dev *dev) { @@ -352,6 +354,7 @@ static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev) } void __i2c_dw_disable(struct dw_i2c_dev *dev); +void i2c_dw_disable(struct dw_i2c_dev *dev); extern void i2c_dw_configure_master(struct dw_i2c_dev *dev); extern int i2c_dw_probe_master(struct dw_i2c_dev *dev); diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c index 6fd4a3d8764a..c9eb01a16048 100644 --- a/drivers/i2c/busses/i2c-designware-pcidrv.c +++ b/drivers/i2c/busses/i2c-designware-pcidrv.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -194,47 +195,6 @@ static struct dw_pci_controller dw_pci_controllers[] = { }, }; -static int __maybe_unused i2c_dw_pci_runtime_suspend(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - - i2c_dw_disable(i_dev); - return 0; -} - -static int __maybe_unused i2c_dw_pci_suspend(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - - i2c_mark_adapter_suspended(&i_dev->adapter); - - return i2c_dw_pci_runtime_suspend(dev); -} - -static int __maybe_unused i2c_dw_pci_runtime_resume(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - - return i_dev->init(i_dev); -} - -static int __maybe_unused i2c_dw_pci_resume(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - int ret; - - ret = i2c_dw_pci_runtime_resume(dev); - - i2c_mark_adapter_resumed(&i_dev->adapter); - - return ret; -} - -static const struct dev_pm_ops i2c_dw_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(i2c_dw_pci_suspend, i2c_dw_pci_resume) - SET_RUNTIME_PM_OPS(i2c_dw_pci_runtime_suspend, i2c_dw_pci_runtime_resume, NULL) -}; - static const struct property_entry dgpu_properties[] = { /* USB-C doesn't power the system */ PROPERTY_ENTRY_U8("scope", POWER_SUPPLY_SCOPE_DEVICE), @@ -402,7 +362,7 @@ static struct pci_driver dw_i2c_driver = { .probe = i2c_dw_pci_probe, .remove = i2c_dw_pci_remove, .driver = { - .pm = &i2c_dw_pm_ops, + .pm = pm_ptr(&i2c_dw_dev_pm_ops), }, .id_table = i2c_designware_pci_ids, }; diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 9b249d27841d..d9a64006a3d6 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "i2c-designware-core.h" @@ -349,67 +348,6 @@ static void dw_i2c_plat_remove(struct platform_device *pdev) pm_runtime_put_sync(&pdev->dev); } -static int dw_i2c_plat_prepare(struct device *dev) -{ - /* - * If the ACPI companion device object is present for this device, it - * may be accessed during suspend and resume of other devices via I2C - * operation regions, so tell the PM core and middle layers to avoid - * skipping system suspend/resume callbacks for it in that case. - */ - return !has_acpi_companion(dev); -} - -static int dw_i2c_plat_runtime_suspend(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - - if (i_dev->shared_with_punit) - return 0; - - i2c_dw_disable(i_dev); - i2c_dw_prepare_clk(i_dev, false); - - return 0; -} - -static int dw_i2c_plat_suspend(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - - i2c_mark_adapter_suspended(&i_dev->adapter); - - return dw_i2c_plat_runtime_suspend(dev); -} - -static int dw_i2c_plat_runtime_resume(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - - if (!i_dev->shared_with_punit) - i2c_dw_prepare_clk(i_dev, true); - - i_dev->init(i_dev); - - return 0; -} - -static int dw_i2c_plat_resume(struct device *dev) -{ - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); - - dw_i2c_plat_runtime_resume(dev); - i2c_mark_adapter_resumed(&i_dev->adapter); - - return 0; -} - -static const struct dev_pm_ops dw_i2c_dev_pm_ops = { - .prepare = pm_sleep_ptr(dw_i2c_plat_prepare), - LATE_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) - RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, dw_i2c_plat_runtime_resume, NULL) -}; - static const struct of_device_id dw_i2c_of_match[] = { { .compatible = "snps,designware-i2c", }, { .compatible = "mscc,ocelot-i2c", .data = (void *)MODEL_MSCC_OCELOT }, @@ -451,7 +389,7 @@ static struct platform_driver dw_i2c_driver = { .name = "i2c_designware", .of_match_table = dw_i2c_of_match, .acpi_match_table = dw_i2c_acpi_match, - .pm = pm_ptr(&dw_i2c_dev_pm_ops), + .pm = pm_ptr(&i2c_dw_dev_pm_ops), }, .id_table = dw_i2c_platform_ids, };