Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1685052rdb; Thu, 7 Dec 2023 06:18:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJs2uQe/CLJsaAIcovEh4EVM1C8HKhSmkGYLiBy3N9cusTO3LQaHkB6OT33QxOVWrNXBXK X-Received: by 2002:a17:903:2349:b0:1d0:b080:c7f6 with SMTP id c9-20020a170903234900b001d0b080c7f6mr5451779plh.52.1701958693803; Thu, 07 Dec 2023 06:18:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701958693; cv=none; d=google.com; s=arc-20160816; b=G3qyRdfjQnjE+jy3kY6NFCB1JzqlZftiTe31/lECAW+gQ8PY7qIvkfp7EhWJsqAEEH ZpkS2zl+MQK7kRCwVVgorVE/kpZ8e122gda0dZplrvx+lh31Nek1G/6o+fkS2ySo9u6u WzrRgb1QiXmnaqJho8AiBVbIwUNR/xdrCjNku+ysJgiZvWirm1UrDI1eGZKGdUxonSEx LG1p8eJ1Q24AhGohAps/KCJ7yLF+R1M2XtGgeAL0vFl3o2KT+UCHpX5vBwseUn0DOC3o xulubmLDf8eoVU+ptvEMPHeyVdJ3bHOVH7YJa4co8AXj+iNT2pg54+r/BeT/qStxaRXk lwgg== 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=x+I5Ynwb7d16Qn0heCthV89zdeph91AD52l9PpkLTqs=; fh=2EyuYZuFv7pvbWODgXyYvSVo1Jt/nOD9U4n59BuOM5Q=; b=Fk0aOdglGhe8tZNvvBys34W02COrXe2z8wmwOCRZJX4oGcrHoCzJaair8VYaU4/z8W /Zif1l+uF7WF5nq2OqsBVGzmed6He4EVPWDiyQh+f6ab95IxD0UnGuZR+NQsEaGBi7Sq ng+VNRvjhrujpAyALBFNAO7YfQ1mNPtEO8GPsO1b0Q7A7gVwb+WjVirZ5OuBZYfeKiJp B3W830VnoMqKtES3P0Ac4LzzKiC6T6RAiyZV5li4mHRWRR2KyVf+4tIRPrvl65kSTdey 94hmEcp0NYTFZjnqltjxddNjGNpBUmdKGmie/gm9cuN0qt7AAbUyN3q6kN75LNUiQIXZ NFbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kJXfNbuJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e11-20020a170902b78b00b001d0a0ee28eesi1231802pls.254.2023.12.07.06.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 06:18:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kJXfNbuJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 8158180477A1; Thu, 7 Dec 2023 06:18:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443233AbjLGORv (ORCPT + 99 others); Thu, 7 Dec 2023 09:17:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443199AbjLGORS (ORCPT ); Thu, 7 Dec 2023 09:17:18 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1288C170E; Thu, 7 Dec 2023 06:17:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701958636; x=1733494636; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cLhx/cbjOW6NN+L3Mt9bOKya7+6S3YKamFyKNCPF6Ns=; b=kJXfNbuJzxkt/aQbrxxOnaEtM2Qs0EklQ3JHFcdFnSc3qSR3Z5glymeP BA8wSPwhhbQ0ybGl1dOsMgRs1QkGqSCaeaW+/zof4xElcifxItnpyxmTr Zx4FL8eiaylkQUSIGX/dqjSORv+mW8A92MMmD9t3DL337mtHwoXT446IF uzrIdIZDvVjlKyv1ccKib5o6Hy4I/KFv7y1nWsnsmTHnbKpFANVYnNA0j 4X2bmCoB+sxLZKC2z3K5YJz0WOfwowtWqZgHjvd9ShcFfCWBudxsSgO0g khTepPBQO6MRRBHG1+eLaKsa1LhZB8G3DyBp+crN0YI4m0qYWAVom1WRk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="460726144" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="460726144" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 06:17:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="862490643" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="862490643" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 07 Dec 2023 06:17:08 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2241FB9F; Thu, 7 Dec 2023 16:17:03 +0200 (EET) From: Andy Shevchenko To: Mario Limonciello , Jarkko Nikula , Herbert Xu , Andy Shevchenko , Wolfram Sang , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , Jan Dabros , Philipp Zabel , Serge Semin Subject: [PATCH v5 14/24] i2c: designware: Consolidate firmware parsing and configuring code Date: Thu, 7 Dec 2023 16:13:54 +0200 Message-ID: <20231207141653.2785124-15-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20231207141653.2785124-1-andriy.shevchenko@linux.intel.com> References: <20231207141653.2785124-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 07 Dec 2023 06:18:12 -0800 (PST) We have the same code flows in the PCI and plaform drivers. Moreover, the flow requires the common code to export a few functions. Instead, consolidate that flow under new function called i2c_dw_fw_parse_and_configure() and drop unneeded exports. Reviewed-by: Andi Shyti Reviewed-by: Mario Limonciello Tested-by: Serge Semin Acked-by: Jarkko Nikula Link: https://lore.kernel.org/r/20231120144641.1660574-15-andriy.shevchenko@linux.intel.com Signed-off-by: Andy Shevchenko --- drivers/i2c/busses/i2c-designware-common.c | 68 +++++++++++++++++++-- drivers/i2c/busses/i2c-designware-core.h | 9 +-- drivers/i2c/busses/i2c-designware-pcidrv.c | 11 +--- drivers/i2c/busses/i2c-designware-platdrv.c | 48 +-------------- 4 files changed, 66 insertions(+), 70 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c index 7a53a732981b..d3ddfec46200 100644 --- a/drivers/i2c/busses/i2c-designware-common.c +++ b/drivers/i2c/busses/i2c-designware-common.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -188,7 +189,7 @@ static const u32 supported_speeds[] = { I2C_MAX_STANDARD_MODE_FREQ, }; -int i2c_dw_validate_speed(struct dw_i2c_dev *dev) +static int i2c_dw_validate_speed(struct dw_i2c_dev *dev) { struct i2c_timings *t = &dev->timings; unsigned int i; @@ -208,7 +209,44 @@ int i2c_dw_validate_speed(struct dw_i2c_dev *dev) return -EINVAL; } -EXPORT_SYMBOL_GPL(i2c_dw_validate_speed); + +#ifdef CONFIG_OF + +#include + +#define MSCC_ICPU_CFG_TWI_DELAY 0x0 +#define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) +#define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 + +static int mscc_twi_set_sda_hold_time(struct dw_i2c_dev *dev) +{ + writel((dev->sda_hold_time << 1) | MSCC_ICPU_CFG_TWI_DELAY_ENABLE, + dev->ext + MSCC_ICPU_CFG_TWI_DELAY); + + return 0; +} + +static void i2c_dw_of_configure(struct device *device) +{ + struct platform_device *pdev = to_platform_device(device); + struct dw_i2c_dev *dev = dev_get_drvdata(device); + + switch (dev->flags & MODEL_MASK) { + case MODEL_MSCC_OCELOT: + dev->ext = devm_platform_ioremap_resource(pdev, 1); + if (!IS_ERR(dev->ext)) + dev->set_sda_hold_time = mscc_twi_set_sda_hold_time; + break; + default: + break; + } +} + +#else /* CONFIG_OF */ + +static inline void i2c_dw_of_configure(struct device *device) { } + +#endif /* CONFIG_OF */ #ifdef CONFIG_ACPI @@ -255,7 +293,7 @@ static void i2c_dw_acpi_params(struct device *device, char method[], kfree(buf.pointer); } -void i2c_dw_acpi_configure(struct device *device) +static void i2c_dw_acpi_configure(struct device *device) { struct dw_i2c_dev *dev = dev_get_drvdata(device); struct i2c_timings *t = &dev->timings; @@ -286,7 +324,6 @@ void i2c_dw_acpi_configure(struct device *device) break; } } -EXPORT_SYMBOL_GPL(i2c_dw_acpi_configure); static u32 i2c_dw_acpi_round_bus_speed(struct device *device) { @@ -308,11 +345,13 @@ static u32 i2c_dw_acpi_round_bus_speed(struct device *device) #else /* CONFIG_ACPI */ +static inline void i2c_dw_acpi_configure(struct device *device) { } + static inline u32 i2c_dw_acpi_round_bus_speed(struct device *device) { return 0; } #endif /* CONFIG_ACPI */ -void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev) +static void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev) { u32 acpi_speed = i2c_dw_acpi_round_bus_speed(dev->dev); struct i2c_timings *t = &dev->timings; @@ -328,7 +367,24 @@ void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev) else t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ; } -EXPORT_SYMBOL_GPL(i2c_dw_adjust_bus_speed); + +int i2c_dw_fw_parse_and_configure(struct dw_i2c_dev *dev) +{ + struct i2c_timings *t = &dev->timings; + struct device *device = dev->dev; + + i2c_parse_fw_timings(device, t, false); + + i2c_dw_adjust_bus_speed(dev); + + if (device->of_node) + i2c_dw_of_configure(device); + if (has_acpi_companion(device)) + i2c_dw_acpi_configure(device); + + return i2c_dw_validate_speed(dev); +} +EXPORT_SYMBOL_GPL(i2c_dw_fw_parse_and_configure); u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) { diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index b7884f15e0e9..22477143bb98 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -395,11 +395,4 @@ int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev); int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev); #endif -int i2c_dw_validate_speed(struct dw_i2c_dev *dev); -void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev); - -#if IS_ENABLED(CONFIG_ACPI) -void i2c_dw_acpi_configure(struct device *device); -#else -static inline void i2c_dw_acpi_configure(struct device *device) { } -#endif +int i2c_dw_fw_parse_and_configure(struct dw_i2c_dev *dev); diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c index cf736a8b9023..7556e9cbf8d2 100644 --- a/drivers/i2c/busses/i2c-designware-pcidrv.c +++ b/drivers/i2c/busses/i2c-designware-pcidrv.c @@ -253,7 +253,6 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, int r; struct dw_pci_controller *controller; struct dw_scl_sda_cfg *cfg; - struct i2c_timings *t; if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) return dev_err_probe(&pdev->dev, -EINVAL, @@ -288,9 +287,6 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, dev->irq = pci_irq_vector(pdev, 0); dev->flags |= controller->flags; - t = &dev->timings; - i2c_parse_fw_timings(&pdev->dev, t, false); - pci_set_drvdata(pdev, dev); if (controller->setup) { @@ -299,12 +295,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, return r; } - i2c_dw_adjust_bus_speed(dev); - - if (has_acpi_companion(&pdev->dev)) - i2c_dw_acpi_configure(&pdev->dev); - - r = i2c_dw_validate_speed(dev); + r = i2c_dw_fw_parse_and_configure(dev); if (r) return r; diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index b8606b651feb..b275a1b19eec 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -97,43 +96,11 @@ static int bt1_i2c_request_regs(struct dw_i2c_dev *dev) dev->map = devm_regmap_init(dev->dev, NULL, dev, &bt1_i2c_cfg); return PTR_ERR_OR_ZERO(dev->map); } - -#define MSCC_ICPU_CFG_TWI_DELAY 0x0 -#define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) -#define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 - -static int mscc_twi_set_sda_hold_time(struct dw_i2c_dev *dev) -{ - writel((dev->sda_hold_time << 1) | MSCC_ICPU_CFG_TWI_DELAY_ENABLE, - dev->ext + MSCC_ICPU_CFG_TWI_DELAY); - - return 0; -} - -static void i2c_dw_of_configure(struct device *device) -{ - struct platform_device *pdev = to_platform_device(device); - struct dw_i2c_dev *dev = dev_get_drvdata(device); - - switch (dev->flags & MODEL_MASK) { - case MODEL_MSCC_OCELOT: - dev->ext = devm_platform_ioremap_resource(pdev, 1); - if (!IS_ERR(dev->ext)) - dev->set_sda_hold_time = mscc_twi_set_sda_hold_time; - break; - default: - break; - } -} #else static int bt1_i2c_request_regs(struct dw_i2c_dev *dev) { return -ENODEV; } - -static inline void i2c_dw_of_configure(struct device *device) -{ -} #endif static int txgbe_i2c_request_regs(struct dw_i2c_dev *dev) @@ -274,7 +241,6 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) { struct i2c_adapter *adap; struct dw_i2c_dev *dev; - struct i2c_timings *t; int irq, ret; irq = platform_get_irq(pdev, 0); @@ -301,18 +267,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) if (ret) return ret; - t = &dev->timings; - i2c_parse_fw_timings(&pdev->dev, t, false); - - i2c_dw_adjust_bus_speed(dev); - - if (pdev->dev.of_node) - i2c_dw_of_configure(&pdev->dev); - - if (has_acpi_companion(&pdev->dev)) - i2c_dw_acpi_configure(&pdev->dev); - - ret = i2c_dw_validate_speed(dev); + ret = i2c_dw_fw_parse_and_configure(dev); if (ret) return ret; @@ -336,6 +291,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) return ret; if (dev->clk) { + struct i2c_timings *t = &dev->timings; u64 clk_khz; dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; -- 2.43.0.rc1.1.gbec44491f096