From patchwork Fri Aug 23 03:02:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13774524 X-Patchwork-Delegate: kuba@kernel.org Received: from smtpbgbr1.qq.com (smtpbgbr1.qq.com [54.207.19.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD4F820B33; Fri, 23 Aug 2024 03:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.19.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724382303; cv=none; b=hAeShtHmIBAvhp1zSl3H4EuAjB58qmaV0chbS2lyn1Y+faxh/jKr3AgUkhCwZTeIF7PSiN/EifWoh95zCLDCHWwyyphKTu2bHQGy+Depwdq7EySwFquoxa2JYxjJfAkf6JaHd8J8AN6JV49lLZS+UZxZUbbAMyq7697KKOT98as= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724382303; c=relaxed/simple; bh=wYA32n8apsDrrCroaz23XiRgtIN6FLOe59UHYpX+gP8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KDQyYWwntxaaeKtdq8wCCQY+/A3TnvYb+cGYV8OIsydfZf1JWlF2C68RYFe87DNcpyiY9Xlz/wCYl2Z0e8BQ8ajS3V/h0EoyIvS5H3eEgbKp4zkPneiyxyB9KqTkqgL/53QaCbjyHZXI867lBt2aH1whDmZRQGZMzD20oGoyQXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com; spf=pass smtp.mailfrom=trustnetic.com; arc=none smtp.client-ip=54.207.19.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trustnetic.com X-QQ-mid: bizesmtpsz10t1724382253t0w8cy X-QQ-Originating-IP: DLfjgWbWDrqS3+pDl8ep5c3vVgAjqF/4QIofPLFmZfU= Received: from wxdbg.localdomain.com ( [125.118.254.234]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 23 Aug 2024 11:04:11 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5009362697263220875 From: Jiawen Wu To: andi.shyti@kernel.org, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jsd@semihalf.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rmk+kernel@armlinux.org.uk, piotr.raczynski@intel.com, andrew@lunn.ch, linux-i2c@vger.kernel.org, netdev@vger.kernel.org Cc: mengyuanlou@net-swift.com, duanqiangwen@net-swift.com, Jiawen Wu , stable@vger.kernel.org Subject: [PATCH net 1/3] net: txgbe: add IO address in I2C platform device data Date: Fri, 23 Aug 2024 11:02:40 +0800 Message-Id: <20240823030242.3083528-2-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240823030242.3083528-1-jiawenwu@trustnetic.com> References: <20240823030242.3083528-1-jiawenwu@trustnetic.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz8a-1 X-Patchwork-Delegate: kuba@kernel.org Consider the necessity of reading/writing the IO address to acquire and release the lock between software and firmware, add the IO address as the platform data to register I2C platform device. Cc: stable@vger.kernel.org Fixes: c625e72561f6 ("net: txgbe: Register I2C platform device") Signed-off-by: Jiawen Wu --- drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c | 5 +++++ include/linux/platform_data/i2c-wx.h | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 include/linux/platform_data/i2c-wx.h diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c index 5f502265f0a6..781a3a34aa4c 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -618,6 +619,7 @@ static const struct regmap_config i2c_regmap_config = { static int txgbe_i2c_register(struct txgbe *txgbe) { + struct txgbe_i2c_platform_data pdata = {}; struct platform_device_info info = {}; struct platform_device *i2c_dev; struct regmap *i2c_regmap; @@ -636,6 +638,9 @@ static int txgbe_i2c_register(struct txgbe *txgbe) info.fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_I2C]); info.name = "i2c_designware"; info.id = pci_dev_id(pdev); + pdata.hw_addr = wx->hw_addr; + info.data = &pdata; + info.size_data = sizeof(pdata); info.res = &DEFINE_RES_IRQ(pdev->irq); info.num_res = 1; diff --git a/include/linux/platform_data/i2c-wx.h b/include/linux/platform_data/i2c-wx.h new file mode 100644 index 000000000000..b46777fa1d85 --- /dev/null +++ b/include/linux/platform_data/i2c-wx.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2015 - 2024 Beijing WangXun Technology Co., Ltd. */ + +#ifndef _I2C_WX_H_ +#define _I2C_WX_H_ + +struct txgbe_i2c_platform_data { + void __iomem *hw_addr; +}; + +#endif /* _I2C_WX_H_ */ From patchwork Fri Aug 23 03:02:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13774522 X-Patchwork-Delegate: kuba@kernel.org Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B4AF286A2; Fri, 23 Aug 2024 03:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.206.16.166 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724382287; cv=none; b=nGsLH+TyCeVVUtDN6Ie/hePNvJYt6kXEuHfPd6tq8eyc42V1XHWNa9/p+h5bonEpbyeeRmcxfFB7qDNy7K7Cgx/ofmRaoMKWC1BbPylXhcEPf/chOTSoqpw/xsJuqxkMoWIOdKW4cp/ljo3sAtWnH+IVwqCB12su/Qm2+FoxSwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724382287; c=relaxed/simple; bh=TFy/88oldcTouickwwwIRQ5m+qUrSWHc0cHVKxDkfX4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rDt0DkOlIx2PdJpu/BfPbBUvaWdoMhjPn8yagrk7RxJaDZE7qinE8X1oM2UjwvgxF2CbYKALSgeQLJawJ7UGtwXShYt+7AG19Oih9bGXjF7jybYqIOPQPeJ+CAnhdICOavyUyY2Cgz2+quOge1qt8eoztNuyH3e1UWbQdSK7HdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com; spf=pass smtp.mailfrom=trustnetic.com; arc=none smtp.client-ip=54.206.16.166 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trustnetic.com X-QQ-mid: bizesmtpsz10t1724382256twwbaw X-QQ-Originating-IP: 8lSusnd7n+jDw/4gqO+6NWF+GBzzw5FLUMqwVNhN7ao= Received: from wxdbg.localdomain.com ( [125.118.254.234]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 23 Aug 2024 11:04:14 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13398459795474154738 From: Jiawen Wu To: andi.shyti@kernel.org, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jsd@semihalf.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rmk+kernel@armlinux.org.uk, piotr.raczynski@intel.com, andrew@lunn.ch, linux-i2c@vger.kernel.org, netdev@vger.kernel.org Cc: mengyuanlou@net-swift.com, duanqiangwen@net-swift.com, Jiawen Wu , stable@vger.kernel.org Subject: [PATCH net 2/3] i2c: designware: add device private data passing to lock functions Date: Fri, 23 Aug 2024 11:02:41 +0800 Message-Id: <20240823030242.3083528-3-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240823030242.3083528-1-jiawenwu@trustnetic.com> References: <20240823030242.3083528-1-jiawenwu@trustnetic.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz8a-1 X-Patchwork-Delegate: kuba@kernel.org In order to add the hardware lock for Wangxun devices with minimal modification, pass struct dw_i2c_dev to the acquire and release lock functions. Cc: stable@vger.kernel.org Fixes: 2f8d1ed79345 ("i2c: designware: Add driver support for Wangxun 10Gb NIC") Signed-off-by: Jiawen Wu --- drivers/i2c/busses/i2c-designware-amdpsp.c | 4 ++-- drivers/i2c/busses/i2c-designware-baytrail.c | 14 ++++++++++++-- drivers/i2c/busses/i2c-designware-common.c | 4 ++-- drivers/i2c/busses/i2c-designware-core.h | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 63454b06e5da..ee7cc4b33f4b 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -167,7 +167,7 @@ static void psp_release_i2c_bus_deferred(struct work_struct *work) } static DECLARE_DELAYED_WORK(release_queue, psp_release_i2c_bus_deferred); -static int psp_acquire_i2c_bus(void) +static int psp_acquire_i2c_bus(struct dw_i2c_dev *dev) { int status; @@ -206,7 +206,7 @@ static int psp_acquire_i2c_bus(void) return 0; } -static void psp_release_i2c_bus(void) +static void psp_release_i2c_bus(struct dw_i2c_dev *dev) { mutex_lock(&psp_i2c_access_mutex); diff --git a/drivers/i2c/busses/i2c-designware-baytrail.c b/drivers/i2c/busses/i2c-designware-baytrail.c index 45774aa47c28..9dde796e0fcc 100644 --- a/drivers/i2c/busses/i2c-designware-baytrail.c +++ b/drivers/i2c/busses/i2c-designware-baytrail.c @@ -12,6 +12,16 @@ #include "i2c-designware-core.h" +static int iosf_mbi_block_punit_i2c_access_dev(struct dw_i2c_dev *dev) +{ + return iosf_mbi_block_punit_i2c_access(); +} + +static void iosf_mbi_unblock_punit_i2c_access_dev(struct dw_i2c_dev *dev) +{ + return iosf_mbi_unblock_punit_i2c_access(); +} + int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev) { acpi_status status; @@ -36,8 +46,8 @@ int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev) return -EPROBE_DEFER; dev_info(dev->dev, "I2C bus managed by PUNIT\n"); - dev->acquire_lock = iosf_mbi_block_punit_i2c_access; - dev->release_lock = iosf_mbi_unblock_punit_i2c_access; + dev->acquire_lock = iosf_mbi_block_punit_i2c_access_dev; + dev->release_lock = iosf_mbi_unblock_punit_i2c_access_dev; dev->shared_with_punit = true; return 0; diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c index e8a688d04aee..743875090356 100644 --- a/drivers/i2c/busses/i2c-designware-common.c +++ b/drivers/i2c/busses/i2c-designware-common.c @@ -524,7 +524,7 @@ int i2c_dw_acquire_lock(struct dw_i2c_dev *dev) if (!dev->acquire_lock) return 0; - ret = dev->acquire_lock(); + ret = dev->acquire_lock(dev); if (!ret) return 0; @@ -536,7 +536,7 @@ int i2c_dw_acquire_lock(struct dw_i2c_dev *dev) void i2c_dw_release_lock(struct dw_i2c_dev *dev) { if (dev->release_lock) - dev->release_lock(); + dev->release_lock(dev); } /* diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index e9606c00b8d1..12b77f464fb5 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -291,8 +291,8 @@ struct dw_i2c_dev { u16 fp_lcnt; u16 hs_hcnt; u16 hs_lcnt; - int (*acquire_lock)(void); - void (*release_lock)(void); + int (*acquire_lock)(struct dw_i2c_dev *dev); + void (*release_lock)(struct dw_i2c_dev *dev); int semaphore_idx; bool shared_with_punit; void (*disable)(struct dw_i2c_dev *dev); From patchwork Fri Aug 23 03:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13774523 X-Patchwork-Delegate: kuba@kernel.org Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0C17286A2; Fri, 23 Aug 2024 03:04:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.204.34.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724382295; cv=none; b=TqzHcqQXK0eUZLv1mVyPSPS5DrsnvHvc/7SXuyKxi7ZdWfD6HcH605pywg/rWy/oKCd7f23eaywGUlgIjqmMOa090nqh3AfcLo601xaLltv4LL406HniwdIyv/tAQAOSl+XS5QsmdQ7dJfkyKmHWgRIHwzIODZQNj0vUmWK8WFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724382295; c=relaxed/simple; bh=mcEAXU1FvnggaQBD5YJ9DeWVw3HJs/NjfryhgfYZUs4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fw2duDjKq3a6tmvtN6qKunF1kJJRRa2rIhCdECJNbaVRf7z9SL5pV0NgByjMsu0MROCS10E1gMwixIAnpBlZdn7uJnzojLNvP4iexk1hkquzy9aqjFncjYH6CObhI3Swt+isJuJmHe2TcaAnLw9vS4Lekky0tKPHt6ZCrNeA/Fk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com; spf=pass smtp.mailfrom=trustnetic.com; arc=none smtp.client-ip=54.204.34.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=trustnetic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trustnetic.com X-QQ-mid: bizesmtpsz10t1724382259ta2caz X-QQ-Originating-IP: gbUqlHL0NTEjZfGdEQ+MEW0Ib4b1Gf1GRt+0vWy6wNE= Received: from wxdbg.localdomain.com ( [125.118.254.234]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 23 Aug 2024 11:04:17 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11173995996635364265 From: Jiawen Wu To: andi.shyti@kernel.org, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jsd@semihalf.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rmk+kernel@armlinux.org.uk, piotr.raczynski@intel.com, andrew@lunn.ch, linux-i2c@vger.kernel.org, netdev@vger.kernel.org Cc: mengyuanlou@net-swift.com, duanqiangwen@net-swift.com, Jiawen Wu , stable@vger.kernel.org Subject: [PATCH net 3/3] i2c: designware: support hardware lock for Wangxun 10Gb NIC Date: Fri, 23 Aug 2024 11:02:42 +0800 Message-Id: <20240823030242.3083528-4-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240823030242.3083528-1-jiawenwu@trustnetic.com> References: <20240823030242.3083528-1-jiawenwu@trustnetic.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz8a-1 X-Patchwork-Delegate: kuba@kernel.org Support acquire_lock() and release_lock() for Wangxun 10Gb NIC. Since the firmware needs to access I2C all the time for some features, the semaphore is used between software and firmware. The driver should set software semaphore before accessing I2C bus and release it when it is finished. Otherwise, there is probability that the correct information on I2C bus will not be obtained. Cc: stable@vger.kernel.org Fixes: 2f8d1ed79345 ("i2c: designware: Add driver support for Wangxun 10Gb NIC") Signed-off-by: Jiawen Wu --- drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-designware-core.h | 2 + drivers/i2c/busses/i2c-designware-platdrv.c | 3 + drivers/i2c/busses/i2c-designware-wx.c | 65 +++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 drivers/i2c/busses/i2c-designware-wx.c diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 78d0561339e5..f0ad9ebaacaa 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -58,6 +58,7 @@ i2c-designware-core-y += i2c-designware-master.o i2c-designware-core-$(CONFIG_I2C_DESIGNWARE_SLAVE) += i2c-designware-slave.o obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o i2c-designware-platform-y := i2c-designware-platdrv.o +i2c-designware-platform-y += i2c-designware-wx.o i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_AMDPSP) += i2c-designware-amdpsp.o i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_BAYTRAIL) += i2c-designware-baytrail.o obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 12b77f464fb5..eae2c4cdc851 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -414,6 +414,8 @@ 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_txgbe_probe_lock_support(struct dw_i2c_dev *dev); + int i2c_dw_validate_speed(struct dw_i2c_dev *dev); void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev); diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index df3dc1e8093e..49c71ae5b6c1 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -229,6 +229,9 @@ static const struct i2c_dw_semaphore_callbacks i2c_dw_semaphore_cb_table[] = { .probe = i2c_dw_amdpsp_probe_lock_support, }, #endif + { + .probe = i2c_dw_txgbe_probe_lock_support, + }, {} }; diff --git a/drivers/i2c/busses/i2c-designware-wx.c b/drivers/i2c/busses/i2c-designware-wx.c new file mode 100644 index 000000000000..0f98160b956d --- /dev/null +++ b/drivers/i2c/busses/i2c-designware-wx.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2015 - 2024 Beijing WangXun Technology Co., Ltd. */ + +#include +#include +#include +#include + +#include "i2c-designware-core.h" + +#define I2C_DW_TXGBE_REQ_RETRY_CNT 4000 +#define I2C_DW_TXGBE_MNG_SW 0x1E004 +#define I2C_DW_TXGBE_MNG_SW_SM BIT(0) +#define I2C_DW_TXGBE_FLUSH 0x10000 + +static int i2c_dw_txgbe_acquire_lock(struct dw_i2c_dev *dev) +{ + void __iomem *req_addr; + u32 swsm; + int i; + + req_addr = dev->ext + I2C_DW_TXGBE_MNG_SW; + + for (i = 0; i < I2C_DW_TXGBE_REQ_RETRY_CNT; i++) { + writel(I2C_DW_TXGBE_MNG_SW_SM, req_addr); + + /* If we set the bit successfully then we got semaphore. */ + swsm = readl(req_addr); + if (swsm & I2C_DW_TXGBE_MNG_SW_SM) + break; + + udelay(50); + } + + if (i == I2C_DW_TXGBE_REQ_RETRY_CNT) + return -ETIMEDOUT; + + return 0; +} + +static void i2c_dw_txgbe_release_lock(struct dw_i2c_dev *dev) +{ + writel(0, dev->ext + I2C_DW_TXGBE_MNG_SW); + /* flush register status */ + readl(dev->ext + I2C_DW_TXGBE_FLUSH); +} + +int i2c_dw_txgbe_probe_lock_support(struct dw_i2c_dev *dev) +{ + struct platform_device *pdev = to_platform_device(dev->dev); + struct txgbe_i2c_platform_data *pdata; + + pdata = dev_get_platdata(&pdev->dev); + if (!pdata) + return -ENXIO; + + dev->ext = pdata->hw_addr; + if (!dev->ext) + return -ENXIO; + + dev->acquire_lock = i2c_dw_txgbe_acquire_lock; + dev->release_lock = i2c_dw_txgbe_release_lock; + + return 0; +}