Skip to contentSkip to conversation

i2c: mlxcpld: Add fixes and features for transaction polling time setting

PATCH New Vadim Pasternak 1 participant 5 messages Aug 16, 2021

Subsystems (3)
lore
Share & tools
lore

Vadim Pasternak

author maintainer
#0 lore raw

cover i2c: mlxcpld: Add fixes and features for transaction polling time setting

This patch set contains:
Patches #1-#2: Fixes for frequency setting.
Patch #3: Reducing driver's transaction polling time.
Patch #4: Flexible setting of transaction polling time according to I2C
bus frequency

Vadim Pasternak (4):
i2c: mlxcpld: Fix criteria for frequency setting
i2c: mlxcpld: Modify register setting for 400KHz frequency
i2c: mlxcpld: Reduce polling time for performance improvement
i2c: mlxcpld: Allow flexible polling time setting for I2C transactions

 drivers/i2c/busses/i2c-mlxcpld.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 1/4 i2c: mlxcpld: Fix criteria for frequency setting

Value for getting frequency capability wrongly has been taken from register offset instead of register value.

Fixes 66b0c2846ba8 ("i2c: mlxcpld: Add support for I2C bus frequency setting")
---
 drivers/i2c/busses/i2c-mlxcpld.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-mlxcpld.c +1 -1
index 4e0b7c2882ce..6d41c3db8a2b 100644
@@ -495,7 +495,7 @@ mlxcpld_i2c_set_frequency(struct mlxcpld_i2c_priv *priv,
 		return err;
 
 	/* Set frequency only if it is not 100KHz, which is default. */
-	switch ((data->reg & data->mask) >> data->bit) {
+	switch ((regval & data->mask) >> data->bit) {
 	case MLXCPLD_I2C_FREQ_1000KHZ:
 		freq = MLXCPLD_I2C_FREQ_1000KHZ_SET;
 		break;
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH 2/4 i2c: mlxcpld: Modify register setting for 400KHz frequency

In reply to Vadim Pasternak

Change setting for 400KHz frequency support by more accurate value.

Fixes 66b0c2846ba8 ("i2c: mlxcpld: Add support for I2C bus frequency setting")
---
 drivers/i2c/busses/i2c-mlxcpld.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-mlxcpld.c +1 -1
index 6d41c3db8a2b..015e11c4663f 100644
@@ -49,7 +49,7 @@
 #define MLXCPLD_LPCI2C_NACK_IND		2
 
 #define MLXCPLD_I2C_FREQ_1000KHZ_SET	0x04
-#define MLXCPLD_I2C_FREQ_400KHZ_SET	0x0f
+#define MLXCPLD_I2C_FREQ_400KHZ_SET	0x0c
 #define MLXCPLD_I2C_FREQ_100KHZ_SET	0x42
 
 enum mlxcpld_i2c_frequency {
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH 3/4 i2c: mlxcpld: Reduce polling time for performance improvement

In reply to Vadim Pasternak

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

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

---
 drivers/i2c/busses/i2c-mlxcpld.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-mlxcpld.c +1 -1
index 015e11c4663f..615f0a98640e 100644
@@ -27,7 +27,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		400   /* usec */
+#define MLXCPLD_I2C_POLL_TIME		200   /* usec */
 
 /* LPC I2C registers */
 #define MLXCPLD_LPCI2C_CPBLTY_REG	0x0
Signature · 1 line
2.20.1
author maintainer
#4 lore raw

PATCH 4/4 i2c: mlxcpld: Allow flexible polling time setting for I2C transactions

In reply to Vadim Pasternak

Allow polling time setting according to I2C frequency supported across the system. For base frequency 400 KHz and 1 MHz set polling time is set four times less than for system with base frequency 100KHz.

---
 drivers/i2c/busses/i2c-mlxcpld.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-mlxcpld.c +8 -4
index 615f0a98640e..56aa424fd71d 100644
@@ -73,6 +73,7 @@ struct mlxcpld_i2c_priv {
 	struct  mlxcpld_i2c_curr_xfer xfer;
 	struct device *dev;
 	bool smbus_block;
+	int polling_time;
 };
 
 static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr)
@@ -267,8 +268,8 @@ static int mlxcpld_i2c_wait_for_free(struct mlxcpld_i2c_priv *priv)
 	do {
 		if (!mlxcpld_i2c_check_busy(priv))
 			break;
-		usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME);
-		timeout += MLXCPLD_I2C_POLL_TIME;
+		usleep_range(priv->polling_time / 2, priv->polling_time);
+		timeout += priv->polling_time;
 	} while (timeout <= MLXCPLD_I2C_XFER_TO);
 
 	if (timeout > MLXCPLD_I2C_XFER_TO)
@@ -288,10 +289,10 @@ static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
 	u8 datalen, val;
 
 	do {
-		usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME);
+		usleep_range(priv->polling_time / 2, priv->polling_time);
 		if (!mlxcpld_i2c_check_status(priv, &status))
 			break;
-		timeout += MLXCPLD_I2C_POLL_TIME;
+		timeout += priv->polling_time;
 	} while (status == 0 && timeout < MLXCPLD_I2C_XFER_TO);
 
 	switch (status) {
@@ -498,9 +499,11 @@ mlxcpld_i2c_set_frequency(struct mlxcpld_i2c_priv *priv,
 	switch ((regval & data->mask) >> data->bit) {
 	case MLXCPLD_I2C_FREQ_1000KHZ:
 		freq = MLXCPLD_I2C_FREQ_1000KHZ_SET;
+		priv->polling_time /= 4;
 		break;
 	case MLXCPLD_I2C_FREQ_400KHZ:
 		freq = MLXCPLD_I2C_FREQ_400KHZ_SET;
+		priv->polling_time /= 4;
 		break;
 	default:
 		return 0;
@@ -527,6 +530,7 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
 
 	priv->dev = &pdev->dev;
 	priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
+	priv->polling_time = MLXCPLD_I2C_POLL_TIME;
 
 	/* Set I2C bus frequency if platform data provides this info. */
 	pdata = dev_get_platdata(&pdev->dev);
Signature · 1 line
2.20.1