* [PATCH v1 - resent 1/5] i2c: busses: Add support for extended transaction length for i2c-mlxcpld
2018-03-27 14:01 [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld michaelsh
@ 2018-03-27 14:01 ` michaelsh
2018-03-27 14:01 ` [PATCH v1 - resent 2/5] i2c: busses: Add support for smbus block read transaction michaelsh
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: michaelsh @ 2018-03-27 14:01 UTC (permalink / raw)
To: wsa; +Cc: linux-i2c, linux-kernel, Michael Shych
From: Michael Shych <michaelsh@mellanox.com>
It adds support for extended length of read and write transactions.
New CPLD logic allows double size of the read and write transactions
length. This feature is verified through capability register, which is
renamed from unclear LPF_REG to CPBLTY_REG. Two bits 5 and 6 of these
register are used for length capability detection, while only 01
combination indicates support of extended transaction length.
Others mean lack of such support.
Signed-off-by: Michael Shych <michaelsh@mellanox.com>
---
drivers/i2c/busses/i2c-mlxcpld.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index 4c28fa2..6434f8c 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -45,13 +45,15 @@
#define MLXCPLD_I2C_VALID_FLAG (I2C_M_RECV_LEN | I2C_M_RD)
#define MLXCPLD_I2C_BUS_NUM 1
#define MLXCPLD_I2C_DATA_REG_SZ 36
+#define MLXCPLD_I2C_DATA_SZ_BIT BIT(5)
+#define MLXCPLD_I2C_DATA_SZ_MASK GENMASK(6, 5)
#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 */
/* LPC I2C registers */
-#define MLXCPLD_LPCI2C_LPF_REG 0x0
+#define MLXCPLD_LPCI2C_CPBLTY_REG 0x0
#define MLXCPLD_LPCI2C_CTRL_REG 0x1
#define MLXCPLD_LPCI2C_HALF_CYC_REG 0x4
#define MLXCPLD_LPCI2C_I2C_HOLD_REG 0x5
@@ -230,7 +232,7 @@ static void mlxcpld_i2c_set_transf_data(struct mlxcpld_i2c_priv *priv,
* All upper layers currently are never use transfer with more than
* 2 messages. Actually, it's also not so relevant in Mellanox systems
* because of HW limitation. Max size of transfer is not more than 32
- * bytes in the current x86 LPCI2C bridge.
+ * or 68 bytes in the current x86 LPCI2C bridge.
*/
priv->xfer.cmd = msgs[num - 1].flags & I2C_M_RD;
@@ -440,6 +442,13 @@ static const struct i2c_adapter_quirks mlxcpld_i2c_quirks = {
.max_comb_1st_msg_len = 4,
};
+static const struct i2c_adapter_quirks mlxcpld_i2c_quirks_ext = {
+ .flags = I2C_AQ_COMB_WRITE_THEN_READ,
+ .max_read_len = MLXCPLD_I2C_DATA_REG_SZ * 2 - MLXCPLD_I2C_MAX_ADDR_LEN,
+ .max_write_len = MLXCPLD_I2C_DATA_REG_SZ * 2,
+ .max_comb_1st_msg_len = 4,
+};
+
static struct i2c_adapter mlxcpld_i2c_adapter = {
.owner = THIS_MODULE,
.name = "i2c-mlxcpld",
@@ -454,6 +463,7 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
{
struct mlxcpld_i2c_priv *priv;
int err;
+ u8 val;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -466,6 +476,11 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
/* Register with i2c layer */
mlxcpld_i2c_adapter.timeout = usecs_to_jiffies(MLXCPLD_I2C_XFER_TO);
+ /* Read capability register */
+ mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_CPBLTY_REG, &val, 1);
+ /* Check support for extended transaction length */
+ if ((val & MLXCPLD_I2C_DATA_SZ_MASK) == MLXCPLD_I2C_DATA_SZ_BIT)
+ mlxcpld_i2c_adapter.quirks = &mlxcpld_i2c_quirks_ext;
priv->adap = mlxcpld_i2c_adapter;
priv->adap.dev.parent = &pdev->dev;
priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 - resent 2/5] i2c: busses: Add support for smbus block read transaction
2018-03-27 14:01 [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld michaelsh
2018-03-27 14:01 ` [PATCH v1 - resent 1/5] i2c: busses: Add support for extended transaction length for i2c-mlxcpld michaelsh
@ 2018-03-27 14:01 ` michaelsh
2018-03-27 14:01 ` [PATCH v1 - resent 3/5] i2c: busses: Fix adapter functionality support callback michaelsh
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: michaelsh @ 2018-03-27 14:01 UTC (permalink / raw)
To: wsa; +Cc: linux-i2c, linux-kernel, Michael Shych
From: Michael Shych <michaelsh@mellanox.com>
It adds support for smbus block read transaction. CPLD smbus block read bit
of capability register is verified during driver initialization, and driver
data is updated if such capability is available. In case an upper layer
requests a read transaction of length one and expects that length will be
the first received byte, driver will notify CPLD about SMBus block read
transaction flavor, so CPLD will know to execute such kind of transaction.
Signed-off-by: Michael Shych <michaelsh@mellanox.com>
---
drivers/i2c/busses/i2c-mlxcpld.c | 38 ++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index 6434f8c..4d8efe0 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -47,6 +47,7 @@
#define MLXCPLD_I2C_DATA_REG_SZ 36
#define MLXCPLD_I2C_DATA_SZ_BIT BIT(5)
#define MLXCPLD_I2C_DATA_SZ_MASK GENMASK(6, 5)
+#define MLXCPLD_I2C_SMBUS_BLK_BIT BIT(7)
#define MLXCPLD_I2C_MAX_ADDR_LEN 4
#define MLXCPLD_I2C_RETR_NUM 2
#define MLXCPLD_I2C_XFER_TO 500000 /* usec */
@@ -85,6 +86,7 @@ struct mlxcpld_i2c_priv {
struct mutex lock;
struct mlxcpld_i2c_curr_xfer xfer;
struct device *dev;
+ bool smbus_block;
};
static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr)
@@ -297,7 +299,7 @@ static int mlxcpld_i2c_wait_for_free(struct mlxcpld_i2c_priv *priv)
static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
{
int status, i, timeout = 0;
- u8 datalen;
+ u8 datalen, val;
do {
usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME);
@@ -326,9 +328,22 @@ static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
* Actual read data len will be always the same as
* requested len. 0xff (line pull-up) will be returned
* if slave has no data to return. Thus don't read
- * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD.
+ * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD. Only in case of
+ * SMBus block read transaction data len can be different,
+ * check this case.
*/
- datalen = priv->xfer.data_len;
+ mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val,
+ 1);
+ if (priv->smbus_block && (val & MLXCPLD_I2C_SMBUS_BLK_BIT)) {
+ mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG,
+ &datalen, 1);
+ if (unlikely(datalen > (I2C_SMBUS_BLOCK_MAX + 1))) {
+ dev_err(priv->dev, "Incorrect smbus block read message len\n");
+ return -E2BIG;
+ }
+ } else {
+ datalen = priv->xfer.data_len;
+ }
mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_DATA_REG,
priv->xfer.msg[i].buf, datalen);
@@ -346,12 +361,20 @@ static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
static void mlxcpld_i2c_xfer_msg(struct mlxcpld_i2c_priv *priv)
{
int i, len = 0;
- u8 cmd;
+ u8 cmd, val;
mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG,
&priv->xfer.data_len, 1);
- mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG,
- &priv->xfer.addr_width, 1);
+
+ val = priv->xfer.addr_width;
+ /* Notify HW about SMBus block read transaction */
+ if (priv->smbus_block && priv->xfer.msg_num >= 2 &&
+ priv->xfer.msg[1].len == 1 &&
+ (priv->xfer.msg[1].flags & I2C_M_RECV_LEN) &&
+ (priv->xfer.msg[1].flags & I2C_M_RD))
+ val |= MLXCPLD_I2C_SMBUS_BLK_BIT;
+
+ mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val, 1);
for (i = 0; i < priv->xfer.msg_num; i++) {
if ((priv->xfer.msg[i].flags & I2C_M_RD) != I2C_M_RD) {
@@ -481,6 +504,9 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
/* Check support for extended transaction length */
if ((val & MLXCPLD_I2C_DATA_SZ_MASK) == MLXCPLD_I2C_DATA_SZ_BIT)
mlxcpld_i2c_adapter.quirks = &mlxcpld_i2c_quirks_ext;
+ /* Check support for smbus block transaction */
+ if (val & MLXCPLD_I2C_SMBUS_BLK_BIT)
+ priv->smbus_block = true;
priv->adap = mlxcpld_i2c_adapter;
priv->adap.dev.parent = &pdev->dev;
priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 - resent 3/5] i2c: busses: Fix adapter functionality support callback
2018-03-27 14:01 [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld michaelsh
2018-03-27 14:01 ` [PATCH v1 - resent 1/5] i2c: busses: Add support for extended transaction length for i2c-mlxcpld michaelsh
2018-03-27 14:01 ` [PATCH v1 - resent 2/5] i2c: busses: Add support for smbus block read transaction michaelsh
@ 2018-03-27 14:01 ` michaelsh
2018-03-27 14:01 ` [PATCH v1 - resent 4/5] i2c: busses: Allow configurable adapter id for mlxcpld michaelsh
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: michaelsh @ 2018-03-27 14:01 UTC (permalink / raw)
To: wsa; +Cc: linux-i2c, linux-kernel, Michael Shych
From: Michael Shych <michaelsh@mellanox.com>
It fixes report about supported functionality.
Functionality can be different up to CPLD capability.
Fixes: 6bec23bff9149 (i2c: mlxcpld: add master driver for mellanox systems)
Signed-off-by: Michael Shych <michaelsh@mellanox.com>
---
drivers/i2c/busses/i2c-mlxcpld.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index 4d8efe0..7341cee9 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -450,7 +450,14 @@ static int mlxcpld_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
static u32 mlxcpld_i2c_func(struct i2c_adapter *adap)
{
- return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA;
+ struct mlxcpld_i2c_priv *priv = i2c_get_adapdata(adap);
+
+ if (priv->smbus_block)
+ return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
+ I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_BLOCK_DATA;
+ else
+ return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
+ I2C_FUNC_SMBUS_I2C_BLOCK;
}
static const struct i2c_algorithm mlxcpld_i2c_algo = {
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 - resent 4/5] i2c: busses: Allow configurable adapter id for mlxcpld
2018-03-27 14:01 [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld michaelsh
` (2 preceding siblings ...)
2018-03-27 14:01 ` [PATCH v1 - resent 3/5] i2c: busses: Fix adapter functionality support callback michaelsh
@ 2018-03-27 14:01 ` michaelsh
2018-03-27 14:01 ` [PATCH v1 - resent 5/5] i2c: busses: Add capability register description to documentation michaelsh
2018-04-28 13:22 ` [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld Wolfram Sang
5 siblings, 0 replies; 7+ messages in thread
From: michaelsh @ 2018-03-27 14:01 UTC (permalink / raw)
To: wsa; +Cc: linux-i2c, linux-kernel, Michael Shych
From: Michael Shych <michaelsh@mellanox.com>
It allows mlxcpld driver to be connected to pre-defined adapter number
equal or greater than one, in order to avoid current limitation, assuming
usage of id number one only.
Signed-off-by: Michael Shych <michaelsh@mellanox.com>
---
drivers/i2c/busses/i2c-mlxcpld.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index 7341cee9..745ed43 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -514,6 +514,8 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
/* Check support for smbus block transaction */
if (val & MLXCPLD_I2C_SMBUS_BLK_BIT)
priv->smbus_block = true;
+ if (pdev->id >= -1)
+ mlxcpld_i2c_adapter.nr = pdev->id;
priv->adap = mlxcpld_i2c_adapter;
priv->adap.dev.parent = &pdev->dev;
priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 - resent 5/5] i2c: busses: Add capability register description to documentation
2018-03-27 14:01 [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld michaelsh
` (3 preceding siblings ...)
2018-03-27 14:01 ` [PATCH v1 - resent 4/5] i2c: busses: Allow configurable adapter id for mlxcpld michaelsh
@ 2018-03-27 14:01 ` michaelsh
2018-04-28 13:22 ` [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld Wolfram Sang
5 siblings, 0 replies; 7+ messages in thread
From: michaelsh @ 2018-03-27 14:01 UTC (permalink / raw)
To: wsa; +Cc: linux-i2c, linux-kernel, Michael Shych
From: Michael Shych <michaelsh@mellanox.com>
It adds capability register description to documentation.
Signed-off-by: Michael Shych <michaelsh@mellanox.com>
---
Documentation/i2c/busses/i2c-mlxcpld | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/i2c/busses/i2c-mlxcpld b/Documentation/i2c/busses/i2c-mlxcpld
index 4e46c44..925904a 100644
--- a/Documentation/i2c/busses/i2c-mlxcpld
+++ b/Documentation/i2c/busses/i2c-mlxcpld
@@ -20,6 +20,10 @@ The next transaction types are supported:
- Write Byte/Block.
Registers:
+CPBLTY 0x0 - capability reg.
+ Bits [6:5] - transaction length. b01 - 72B is supported,
+ 36B in other case.
+ Bit 7 - SMBus block read support.
CTRL 0x1 - control reg.
Resets all the registers.
HALF_CYC 0x4 - cycle reg.
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld
2018-03-27 14:01 [PATCH v1 - resent 0/5] Add capabilities to i2c-mlxcpld michaelsh
` (4 preceding siblings ...)
2018-03-27 14:01 ` [PATCH v1 - resent 5/5] i2c: busses: Add capability register description to documentation michaelsh
@ 2018-04-28 13:22 ` Wolfram Sang
5 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2018-04-28 13:22 UTC (permalink / raw)
To: michaelsh; +Cc: linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 980 bytes --]
On Tue, Mar 27, 2018 at 02:01:21PM +0000, michaelsh@mellanox.com wrote:
> From: Michael Shych <michaelsh@mellanox.com>
>
> This series is resent (original series has been sent at 5/3/2018).
>
> PATCH1
> It adds support for extended length of read and write transactions.
>
> PATCH2
> It adds support for smbus block read transaction.
>
> PATCH3
> Fix report about supported functionality.
>
> PATCH4
> It allows mlxcpld driver to be connected to pre-defined adapter number.
>
> PATCH5
> It adds capability register description to documentation.
>
> Michael Shych (5):
> i2c: busses: Add support for extended transaction length for
> i2c-mlxcpld
> i2c: busses: Add support for smbus block read transaction
> i2c: busses: Fix adapter functionality support callback
> i2c: busses: Allow configurable adapter id for mlxcpld
> i2c: busses: Add capability register description to documentation
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