linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH i2c-next 0/3] i2c: mlxcpld: Extend driver functionality and update license
@ 2020-12-10 16:51 Vadim Pasternak
  2020-12-10 16:51 ` [PATCH i2c-next 1/3] i2c: mlxcpld: Update module license Vadim Pasternak
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Vadim Pasternak @ 2020-12-10 16:51 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, Vadim Pasternak

The patch set adds new features for the Mellanox/Nvidia systems and
updates module license.

Patch #1 - changes license to SPDX-License.
Patch #2 - changes polling time.
Patch #3 - allows I2C bus frequency setting according to the platform
	   configuration.

Vadim Pasternak (3):
  i2c: mlxcpld: Update module license
  i2c: mlxcpld: Decrease polling time for performance improvement
  i2c: mlxcpld: Add support for I2C bus frequency setting

 drivers/i2c/busses/i2c-mlxcpld.c | 96 +++++++++++++++++++++++++++-------------
 1 file changed, 65 insertions(+), 31 deletions(-)

-- 
2.11.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH i2c-next 1/3] i2c: mlxcpld: Update module license
  2020-12-10 16:51 [PATCH i2c-next 0/3] i2c: mlxcpld: Extend driver functionality and update license Vadim Pasternak
@ 2020-12-10 16:51 ` Vadim Pasternak
  2021-01-05 10:18   ` Wolfram Sang
  2020-12-10 16:51 ` [PATCH i2c-next 2/3] i2c: mlxcpld: Decrease polling time for performance improvement Vadim Pasternak
  2020-12-10 16:51 ` [PATCH i2c-next 3/3] i2c: mlxcpld: Add support for I2C bus frequency setting Vadim Pasternak
  2 siblings, 1 reply; 7+ messages in thread
From: Vadim Pasternak @ 2020-12-10 16:51 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, Vadim Pasternak

Update license to SPDX-License.

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
---
 drivers/i2c/busses/i2c-mlxcpld.c | 32 +++-----------------------------
 1 file changed, 3 insertions(+), 29 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index 71d7bae2cbca..dbd185368c38 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -1,34 +1,8 @@
+// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
 /*
- * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
- * Copyright (c) 2016 Michael Shych <michaels@mellanox.com>
+ * Mellanox i2c driver
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (C) 2016-2020 Mellanox Technologies
  */
 
 #include <linux/delay.h>
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH i2c-next 2/3] i2c: mlxcpld: Decrease polling time for performance improvement
  2020-12-10 16:51 [PATCH i2c-next 0/3] i2c: mlxcpld: Extend driver functionality and update license Vadim Pasternak
  2020-12-10 16:51 ` [PATCH i2c-next 1/3] i2c: mlxcpld: Update module license Vadim Pasternak
@ 2020-12-10 16:51 ` Vadim Pasternak
  2021-01-05 10:18   ` Wolfram Sang
  2020-12-10 16:51 ` [PATCH i2c-next 3/3] i2c: mlxcpld: Add support for I2C bus frequency setting Vadim Pasternak
  2 siblings, 1 reply; 7+ messages in thread
From: Vadim Pasternak @ 2020-12-10 16:51 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, Vadim Pasternak

Decrease polling time 'MLXCPLD_I2C_POLL_TIME' from 2000 usec to 400
usec. It greatly improves performance of I2C transactions.

Reliability of setting polling time to 400 usec has been thoroughly
validated across all the supported systems.

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
---
 drivers/i2c/busses/i2c-mlxcpld.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index dbd185368c38..9e45214d1eb6 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -25,7 +25,7 @@
 #define MLXCPLD_I2C_MAX_ADDR_LEN	4
 #define MLXCPLD_I2C_RETR_NUM		2
 #define MLXCPLD_I2C_XFER_TO		500000 /* usec */
-#define MLXCPLD_I2C_POLL_TIME		2000   /* usec */
+#define MLXCPLD_I2C_POLL_TIME		400   /* usec */
 
 /* LPC I2C registers */
 #define MLXCPLD_LPCI2C_CPBLTY_REG	0x0
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH i2c-next 3/3] i2c: mlxcpld: Add support for I2C bus frequency setting
  2020-12-10 16:51 [PATCH i2c-next 0/3] i2c: mlxcpld: Extend driver functionality and update license Vadim Pasternak
  2020-12-10 16:51 ` [PATCH i2c-next 1/3] i2c: mlxcpld: Update module license Vadim Pasternak
  2020-12-10 16:51 ` [PATCH i2c-next 2/3] i2c: mlxcpld: Decrease polling time for performance improvement Vadim Pasternak
@ 2020-12-10 16:51 ` Vadim Pasternak
  2021-01-05 10:19   ` Wolfram Sang
  2 siblings, 1 reply; 7+ messages in thread
From: Vadim Pasternak @ 2020-12-10 16:51 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, Vadim Pasternak

Add support for I2C bus frequency setting according to the specific
system capability. This capability is obtained from CPLD frequency
setting register, which could be provided through the platform data.
If such register is provided, it specifies minimal I2C bus frequency
to be used for the devices attached to the I2C bus. Supported
freqeuncies are 100KHz, 400KHz, 1MHz, while 100KHz is the default.

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
---
 drivers/i2c/busses/i2c-mlxcpld.c | 62 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index 9e45214d1eb6..093da27261fd 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -11,7 +11,9 @@
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/platform_data/mlxreg.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 
 /* General defines */
 #define MLXPLAT_CPLD_LPC_I2C_BASE_ADDR	0x2000
@@ -46,6 +48,16 @@
 #define MLXCPLD_LPCI2C_ACK_IND		1
 #define MLXCPLD_LPCI2C_NACK_IND		2
 
+#define MLXCPLD_I2C_FREQ_1000KHZ_SET	0x04
+#define MLXCPLD_I2C_FREQ_400KHZ_SET	0x0f
+#define MLXCPLD_I2C_FREQ_100KHZ_SET	0x42
+
+enum mlxcpld_i2c_frequency {
+	MLXCPLD_I2C_FREQ_1000KHZ = 1,
+	MLXCPLD_I2C_FREQ_400KHZ = 2,
+	MLXCPLD_I2C_FREQ_100KHZ = 3,
+};
+
 struct  mlxcpld_i2c_curr_xfer {
 	u8 cmd;
 	u8 addr_width;
@@ -463,8 +475,44 @@ static struct i2c_adapter mlxcpld_i2c_adapter = {
 	.nr		= MLXCPLD_I2C_BUS_NUM,
 };
 
+static int
+mlxcpld_i2c_set_frequency(struct mlxcpld_i2c_priv *priv,
+			  struct mlxreg_core_hotplug_platform_data *pdata)
+{
+	struct mlxreg_core_item *item = pdata->items;
+	struct mlxreg_core_data *data;
+	u8 freq;
+	int regval, err;
+
+	if (!item || !item->data)
+		return 0;
+
+	/* Read frequency setting. */
+	data = item->data;
+	err = regmap_read(pdata->regmap, data->reg, &regval);
+	if (err)
+		return err;
+
+	/* Set frequency only if it is not 100KHz, which is default. */
+	switch ((regval & data->mask) >> data->bit) {
+	case MLXCPLD_I2C_FREQ_1000KHZ:
+		freq = MLXCPLD_I2C_FREQ_1000KHZ_SET;
+		break;
+	case MLXCPLD_I2C_FREQ_400KHZ:
+		freq = MLXCPLD_I2C_FREQ_400KHZ_SET;
+		break;
+	default:
+		return 0;
+	}
+
+	mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_HALF_CYC_REG, &freq, 1);
+
+	return 0;
+}
+
 static int mlxcpld_i2c_probe(struct platform_device *pdev)
 {
+	struct mlxreg_core_hotplug_platform_data *pdata;
 	struct mlxcpld_i2c_priv *priv;
 	int err;
 	u8 val;
@@ -479,6 +527,14 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
 	priv->dev = &pdev->dev;
 	priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
 
+	/* Set I2C bus frequency if platform data provides this info. */
+	pdata = dev_get_platdata(&pdev->dev);
+	if (pdata) {
+		err = mlxcpld_i2c_set_frequency(priv, pdata);
+		if (err)
+			goto mlxcpld_i2_probe_failed;
+	}
+
 	/* Register with i2c layer */
 	mlxcpld_i2c_adapter.timeout = usecs_to_jiffies(MLXCPLD_I2C_XFER_TO);
 	/* Read capability register */
@@ -497,8 +553,12 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
 
 	err = i2c_add_numbered_adapter(&priv->adap);
 	if (err)
-		mutex_destroy(&priv->lock);
+		goto mlxcpld_i2_probe_failed;
 
+	return 0;
+
+mlxcpld_i2_probe_failed:
+	mutex_destroy(&priv->lock);
 	return err;
 }
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH i2c-next 1/3] i2c: mlxcpld: Update module license
  2020-12-10 16:51 ` [PATCH i2c-next 1/3] i2c: mlxcpld: Update module license Vadim Pasternak
@ 2021-01-05 10:18   ` Wolfram Sang
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2021-01-05 10:18 UTC (permalink / raw)
  To: Vadim Pasternak; +Cc: linux-i2c

[-- Attachment #1: Type: text/plain, Size: 193 bytes --]

On Thu, Dec 10, 2020 at 06:51:11PM +0200, Vadim Pasternak wrote:
> Update license to SPDX-License.
> 
> Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH i2c-next 2/3] i2c: mlxcpld: Decrease polling time for performance improvement
  2020-12-10 16:51 ` [PATCH i2c-next 2/3] i2c: mlxcpld: Decrease polling time for performance improvement Vadim Pasternak
@ 2021-01-05 10:18   ` Wolfram Sang
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2021-01-05 10:18 UTC (permalink / raw)
  To: Vadim Pasternak; +Cc: linux-i2c

[-- Attachment #1: Type: text/plain, Size: 413 bytes --]

On Thu, Dec 10, 2020 at 06:51:12PM +0200, Vadim Pasternak wrote:
> Decrease polling time 'MLXCPLD_I2C_POLL_TIME' from 2000 usec to 400
> usec. It greatly improves performance of I2C transactions.
> 
> Reliability of setting polling time to 400 usec has been thoroughly
> validated across all the supported systems.
> 
> Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH i2c-next 3/3] i2c: mlxcpld: Add support for I2C bus frequency setting
  2020-12-10 16:51 ` [PATCH i2c-next 3/3] i2c: mlxcpld: Add support for I2C bus frequency setting Vadim Pasternak
@ 2021-01-05 10:19   ` Wolfram Sang
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2021-01-05 10:19 UTC (permalink / raw)
  To: Vadim Pasternak; +Cc: linux-i2c

[-- Attachment #1: Type: text/plain, Size: 288 bytes --]


> +	err = regmap_read(pdata->regmap, data->reg, &regval);

drivers/i2c/busses/i2c-mlxcpld.c:492:54: warning: incorrect type in argument 3 (different signedness)
drivers/i2c/busses/i2c-mlxcpld.c:492:54:    expected unsigned int *val
drivers/i2c/busses/i2c-mlxcpld.c:492:54:    got int *


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-01-05 10:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 16:51 [PATCH i2c-next 0/3] i2c: mlxcpld: Extend driver functionality and update license Vadim Pasternak
2020-12-10 16:51 ` [PATCH i2c-next 1/3] i2c: mlxcpld: Update module license Vadim Pasternak
2021-01-05 10:18   ` Wolfram Sang
2020-12-10 16:51 ` [PATCH i2c-next 2/3] i2c: mlxcpld: Decrease polling time for performance improvement Vadim Pasternak
2021-01-05 10:18   ` Wolfram Sang
2020-12-10 16:51 ` [PATCH i2c-next 3/3] i2c: mlxcpld: Add support for I2C bus frequency setting Vadim Pasternak
2021-01-05 10:19   ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).