Skip to contentSkip to conversation

Add I2C driver for ZTE ZX2967 family SoCs

PATCH New Shawn Guo 2 participants 12 messages May 28, 2017 – Jun 22, 2017

Subsystems (2)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

cover Add I2C driver for ZTE ZX2967 family SoCs

From: Shawn Guo <[email protected]>

Hi Wolfram,

The ZX2967 I2C driver submission had gone through quite a number of review iterations [1], and seems close to be accepted. But for some reason, the ball got dropped from there. I'm here to pick it up and hopefully move it forward.

This is basically a resend of the latest posting from Baoyou with Wolfram's comments on v7 fully addressed.

Changes since v7:
- Rebase and test on v4.12-rc2.
- Drop the dev_err() and hardware reset on timeout, which is not really necessary.
- Return -ETIMEDOUT instead of -EIO on timeout.
- Unify zx2967_i2c_xfer_write_bytes() and zx2967_i2c_xfer_read_bytes() into one function zx2967_i2c_xfer_bytes(), and zx2967_i2c_xfer_write() and zx2967_i2c_xfer_read() into zx2967_i2c_xfer_msg().

Shawn

[1] https://lkml.org/lkml/2017/2/22/101

Baoyou Xie (2):
dt: bindings: add documentation for zx2967 family i2c controller
i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

 .../devicetree/bindings/i2c/i2c-zx2967.txt         |  22 +
 drivers/i2c/busses/Kconfig                         |   9 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-zx2967.c                    | 610 +++++++++++++++++++++
 4 files changed, 642 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-zx2967.txt
 create mode 100644 drivers/i2c/busses/i2c-zx2967.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/2 dt: bindings: add documentation for zx2967 family i2c controller

From: Baoyou Xie <[email protected]>

This patch adds dt-binding documentation for zx2967 family i2c controller.

---
 .../devicetree/bindings/i2c/i2c-zx2967.txt         | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-zx2967.txt
Documentation/devicetree/bindings/i2c/i2c-zx2967.txt new file +22 -0
new file mode 100644
index 000000000000..cb806d1ae4c9
@@ -0,0 +1,22 @@
+ZTE zx2967 I2C controller
+
+Required properties:
+ - compatible: must be "zte,zx296718-i2c"
+ - reg: physical address and length of the device registers
+ - interrupts: a single interrupt specifier
+ - clocks: clock for the device
+ - #address-cells: should be <1>
+ - #size-cells: should be <0>
+ - clock-frequency: the desired I2C bus clock frequency.
+
+Examples:
+
+	i2c at 112000 {
+		compatible = "zte,zx296718-i2c";
+		reg = <0x00112000 0x1000>;
+		interrupts = <GIC_SPI 112 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&osc24m>;
+		#address-cells = <1>
+		#size-cells = <0>;
+		clock-frequency = <1600000>;
+	};
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

In reply to Shawn Guo

From: Baoyou Xie <[email protected]>

This patch adds i2c controller driver for ZTE's zx2967 family.

---
 drivers/i2c/busses/Kconfig      |   9 +
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-zx2967.c | 610 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 620 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-zx2967.c
drivers/i2c/busses/Kconfig +9 -0
index 144cbadc7c72..f9f0ed61df2e 100644
@@ -1258,4 +1258,13 @@ config I2C_OPAL
 	  This driver can also be built as a module. If so, the module will be
 	  called as i2c-opal.
 
+config I2C_ZX2967
+	tristate "ZTE ZX2967 I2C support"
+	depends on ARCH_ZX
+	default y
+	help
+	  Selecting this option will add ZX2967 I2C driver.
+	  This driver can also be built as a module. If so, the module will be
+	  called i2c-zx2967.
+
 endmenu
drivers/i2c/busses/Makefile +1 -0
index 30b60855fbcd..6ece77785a29 100644
@@ -102,6 +102,7 @@ obj-$(CONFIG_I2C_XILINX)	+= i2c-xiic.o
 obj-$(CONFIG_I2C_XLR)		+= i2c-xlr.o
 obj-$(CONFIG_I2C_XLP9XX)	+= i2c-xlp9xx.o
 obj-$(CONFIG_I2C_RCAR)		+= i2c-rcar.o
+obj-$(CONFIG_I2C_ZX2967)	+= i2c-zx2967.o
 
 # External I2C/SMBus adapter drivers
 obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
drivers/i2c/busses/i2c-zx2967.c new file +610 -0

610 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#11 lore raw

cover Add I2C driver for ZTE ZX2967 family SoCs

In reply to Shawn Guo

Hi Wolfram,

Quoted 12 lines · Shawn Guo

From: Shawn Guo <[email protected]>

Hi Wolfram,

The ZX2967 I2C driver submission had gone through quite a number of review iterations [1], and seems close to be accepted. But for some reason, the ball got dropped from there. I'm here to pick it up and hopefully move it forward.

This is basically a resend of the latest posting from Baoyou with Wolfram's comments on v7 fully addressed.

Quoted 8 lines

Changes since v7:
- Rebase and test on v4.12-rc2.
- Drop the dev_err() and hardware reset on timeout, which is not really necessary.
- Return -ETIMEDOUT instead of -EIO on timeout.
- Unify zx2967_i2c_xfer_write_bytes() and zx2967_i2c_xfer_read_bytes() into one function zx2967_i2c_xfer_bytes(), and zx2967_i2c_xfer_write() and zx2967_i2c_xfer_read() into zx2967_i2c_xfer_msg().

Any comments on the series? We hope it can get into v4.13 merge window.

Shawn

#3 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

In reply to Shawn Guo

Hi Shawn,

Quoted 8 lines · Shawn Guo

From: Baoyou Xie <[email protected]>

This patch adds i2c controller driver for ZTE's zx2967 family.

What about this patch from the old series updating the MAINTAINERS entry? I think it is a good idea?

http://patchwork.ozlabs.org/patch/731006/

Quoted 12 lines
---
 drivers/i2c/busses/Kconfig      |   9 +
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-zx2967.c | 610 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 620 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-zx2967.c
drivers/i2c/busses/Kconfig +0 -0
index 144cbadc7c72..f9f0ed61df2e 100644

drivers/i2c/busses/Kconfig config I2C_OPAL · line 1263

Quoted 6 lines
drivers/i2c/busses/Kconfig +3 -0
@@ -1258,4 +1258,13 @@ config I2C_OPAL
 	  This driver can also be built as a module. If so, the module will be
 	  called as i2c-opal.
 
+config I2C_ZX2967
+	tristate "ZTE ZX2967 I2C support"
+	depends on ARCH_ZX

|| COMPILE_TEST?

Quoted 7 lines
drivers/i2c/busses/Kconfig +6 -0
+	default y
+	help
+	  Selecting this option will add ZX2967 I2C driver.
+	  This driver can also be built as a module. If so, the module will be
+	  called i2c-zx2967.
+
 endmenu

...

Quoted 14 lines
drivers/i2c/busses/Kconfig +14 -0
+static int zx2967_i2c_reset_hardware(struct zx2967_i2c_info *zx_i2c)
+{
+	u32 val;
+	u32 clk_div;
+	u32 status;
+
+	val = I2C_MASTER | I2C_IRQ_MSK_ENABLE;
+	zx2967_i2c_writel(zx_i2c, val, REG_CMD);
+
+	clk_div = clk_get_rate(zx_i2c->clk) / zx_i2c->clk_freq - 1;
+	zx2967_i2c_writel(zx_i2c, clk_div, REG_CLK_DIV_FS);
+	zx2967_i2c_writel(zx_i2c, clk_div, REG_CLK_DIV_HS);
+
+	zx2967_i2c_writel(zx_i2c, I2C_FIFO_MAX - 1, REG_WRCONF);

drivers/i2c/busses/Kconfig

Quoted 10 lines
drivers/i2c/busses/Kconfig +10 -0
+	zx2967_i2c_writel(zx_i2c, I2C_FIFO_MAX - 1, REG_RDCONF);
+	zx2967_i2c_writel(zx_i2c, 1, REG_RDCONF);
+
+	zx2967_i2c_flush_fifos(zx_i2c);
+
+	status = zx2967_i2c_readl(zx_i2c, REG_STAT);
+	if (status & I2C_SR_BUSY)
+		return -EBUSY;
+	if (status & (I2C_SR_EDEVICE | I2C_SR_EDATA))
+		return -EIO;

Is this the error handling (NACK, etc)? Then, it got lost now since we don't reset the hardware anymore after timeouts. But that would have meant that errors are only detected after the timeout was reached instead of instantly? If so, no good design. But maybe I misunderstand.

Quoted 15 lines
drivers/i2c/busses/Kconfig +15 -0
+
+	enable_irq(zx_i2c->irq);
+
+	return 0;
+}
+
+static void zx2967_i2c_isr_clr(struct zx2967_i2c_info *zx_i2c)
+{
+	u32 status;
+
+	status = zx2967_i2c_readl(zx_i2c, REG_STAT);
+	status |= I2C_IRQ_ACK_CLEAR;
+	zx2967_i2c_writel(zx_i2c, status, REG_STAT);
+}
+

drivers/i2c/busses/Kconfig

Quoted 10 lines
drivers/i2c/busses/Kconfig +10 -0
+static irqreturn_t zx2967_i2c_isr(int irq, void *dev_id)
+{
+	u32 status;
+	struct zx2967_i2c_info *zx_i2c = (struct zx2967_i2c_info *)dev_id;
+
+	status = zx2967_i2c_readl(zx_i2c, REG_STAT) & I2C_INT_MASK;
+	zx2967_i2c_isr_clr(zx_i2c);
+
+	if (status & I2C_ERROR_MASK)
+		return IRQ_HANDLED;

I would have expected the error handling here.

Quoted 6 lines
drivers/i2c/busses/Kconfig +6 -0
+
+	if (status & I2C_TRANS_DONE)
+		complete(&zx_i2c->complete);
+
+	return IRQ_HANDLED;
+}

...

Quoted 26 lines
drivers/i2c/busses/Kconfig +26 -0
+static int zx2967_smbus_xfer_read(struct zx2967_i2c_info *zx_i2c, int size,
+				  union i2c_smbus_data *data)
+{
+	unsigned long time_left;
+	u8 buf[2];
+	u32 val;
+
+	reinit_completion(&zx_i2c->complete);
+
+	val = zx2967_i2c_readl(zx_i2c, REG_CMD);
+	val |= I2C_CMB_RW_EN;
+	zx2967_i2c_writel(zx_i2c, val, REG_CMD);
+
+	val = zx2967_i2c_readl(zx_i2c, REG_CMD);
+	val |= I2C_START;
+	zx2967_i2c_writel(zx_i2c, val, REG_CMD);
+
+	time_left = wait_for_completion_timeout(&zx_i2c->complete,
+						I2C_TIMEOUT);
+	if (time_left == 0)
+		return -ETIMEDOUT;
+
+	switch (size) {
+	case I2C_SMBUS_BYTE:
+	case I2C_SMBUS_BYTE_DATA:
+		val = zx2967_i2c_readl(zx_i2c, REG_DATA);

drivers/i2c/busses/Kconfig

Quoted 10 lines
drivers/i2c/busses/Kconfig +10 -0
+		data->byte = val;
+		break;
+	case I2C_SMBUS_WORD_DATA:
+	case I2C_SMBUS_PROC_CALL:
+		buf[0] = zx2967_i2c_readl(zx_i2c, REG_DATA);
+		buf[1] = zx2967_i2c_readl(zx_i2c, REG_DATA);
+		data->word = (buf[0] << 8) | buf[1];
+		break;
+	default:
+		dev_warn(DEV(zx_i2c), "Unsupported transaction %d\n", size);

I wouldn't print something here. If an unsupported SMBus transfer is used, your driver will fall back to emulate them via I2C. No need to print a warning then.

Quoted 5 lines
drivers/i2c/busses/Kconfig +5 -0
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}

drivers/i2c/busses/Kconfig

Quoted 10 lines
drivers/i2c/busses/Kconfig +10 -0
+
+#define ZX2967_I2C_FUNCS (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |	\
+		I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |	\
+		I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL |	\
+		I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK)
+
+static u32 zx2967_i2c_func(struct i2c_adapter *adap)
+{
+	return ZX2967_I2C_FUNCS;
+}

No strong opinion but I think we can return that value directly without a define.

...

drivers/i2c/busses/Kconfig

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+	ret = i2c_add_numbered_adapter(&zx_i2c->adap);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to add zx2967 i2c adapter\n");

Drop the message, the core will do the reporting.

drivers/i2c/busses/Kconfig

Quoted 2 lines
drivers/i2c/busses/Kconfig +2 -0
+		goto err_clk_unprepare;
+	}

How was this driver tested BTW?

Regards,

Wolfram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170619/f0b4ecde/attachment.sig>

author
#4 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

Hi Wolfram,

Thanks for taking time help review.

Quoted 12 lines · Wolfram Sang

Hi Shawn,

Quoted 8 lines · Shawn Guo

From: Baoyou Xie <[email protected]>

This patch adds i2c controller driver for ZTE's zx2967 family.

Quoted 4 lines

What about this patch from the old series updating the MAINTAINERS entry? I think it is a good idea?

http://patchwork.ozlabs.org/patch/731006/

Oh, yes, I should have mentioned it in the cover-letter. Instead of changing MAINTAINERS file in different subsystem patch series, which may introduce merge conflicts, we plan to update it with a separate patch adding all driver entries that lands on mainline, and get it in through arm-soc tree. Are you okay with that?

Quoted 16 lines
Quoted 16 lines
---
 drivers/i2c/busses/Kconfig      |   9 +
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-zx2967.c | 610 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 620 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-zx2967.c
drivers/i2c/busses/Kconfig +0 -0
index 144cbadc7c72..f9f0ed61df2e 100644
@@ -1258,4 +1258,13 @@ config I2C_OPAL
 	  This driver can also be built as a module. If so, the module will be
 	  called as i2c-opal.
 
Quoted 5 lines

drivers/i2c/busses/Kconfig config I2C_OPAL · line 1263

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+config I2C_ZX2967
+	tristate "ZTE ZX2967 I2C support"
+	depends on ARCH_ZX

|| COMPILE_TEST?

Yeah, good suggestion.

Quoted 32 lines
Quoted 8 lines
drivers/i2c/busses/Kconfig +6 -0
+	default y
+	help
+	  Selecting this option will add ZX2967 I2C driver.
+	  This driver can also be built as a module. If so, the module will be
+	  called i2c-zx2967.
+
 endmenu

...

Quoted 21 lines
drivers/i2c/busses/Kconfig +21 -0
+static int zx2967_i2c_reset_hardware(struct zx2967_i2c_info *zx_i2c)
+{
+	u32 val;
+	u32 clk_div;
+	u32 status;
+
+	val = I2C_MASTER | I2C_IRQ_MSK_ENABLE;
+	zx2967_i2c_writel(zx_i2c, val, REG_CMD);
+
+	clk_div = clk_get_rate(zx_i2c->clk) / zx_i2c->clk_freq - 1;
+	zx2967_i2c_writel(zx_i2c, clk_div, REG_CLK_DIV_FS);
+	zx2967_i2c_writel(zx_i2c, clk_div, REG_CLK_DIV_HS);
+
+	zx2967_i2c_writel(zx_i2c, I2C_FIFO_MAX - 1, REG_WRCONF);
+	zx2967_i2c_writel(zx_i2c, I2C_FIFO_MAX - 1, REG_RDCONF);
+	zx2967_i2c_writel(zx_i2c, 1, REG_RDCONF);
+
+	zx2967_i2c_flush_fifos(zx_i2c);
+
+	status = zx2967_i2c_readl(zx_i2c, REG_STAT);
+	if (status & I2C_SR_BUSY)
Quoted 8 lines

drivers/i2c/busses/Kconfig

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+		return -EBUSY;
+	if (status & (I2C_SR_EDEVICE | I2C_SR_EDATA))
+		return -EIO;

Is this the error handling (NACK, etc)? Then, it got lost now since we don't reset the hardware anymore after timeouts. But that would have meant that errors are only detected after the timeout was reached instead of instantly? If so, no good design. But maybe I misunderstand.

Hmm, this doesn't make too much sense now, since this reset function is only being called at probe time to ensure the device is in a sane initial state. There is no data transfer happening at this point at all. I will drop these error bits checking from here, and add the error handling in irq handler.

Quoted 20 lines
Quoted 20 lines
drivers/i2c/busses/Kconfig +19 -0
+
+	enable_irq(zx_i2c->irq);
+
+	return 0;
+}
+
+static void zx2967_i2c_isr_clr(struct zx2967_i2c_info *zx_i2c)
+{
+	u32 status;
+
+	status = zx2967_i2c_readl(zx_i2c, REG_STAT);
+	status |= I2C_IRQ_ACK_CLEAR;
+	zx2967_i2c_writel(zx_i2c, status, REG_STAT);
+}
+
+static irqreturn_t zx2967_i2c_isr(int irq, void *dev_id)
+{
+	u32 status;
+	struct zx2967_i2c_info *zx_i2c = (struct zx2967_i2c_info *)dev_id;
Quoted 8 lines

drivers/i2c/busses/Kconfig

Quoted 6 lines
drivers/i2c/busses/Kconfig +6 -0
+
+	status = zx2967_i2c_readl(zx_i2c, REG_STAT) & I2C_INT_MASK;
+	zx2967_i2c_isr_clr(zx_i2c);
+
+	if (status & I2C_ERROR_MASK)
+		return IRQ_HANDLED;

I would have expected the error handling here.

Yes, we should check error status here.

Quoted 42 lines
Quoted 7 lines
drivers/i2c/busses/Kconfig +6 -0
+
+	if (status & I2C_TRANS_DONE)
+		complete(&zx_i2c->complete);
+
+	return IRQ_HANDLED;
+}

...

Quoted 32 lines
drivers/i2c/busses/Kconfig +32 -0
+static int zx2967_smbus_xfer_read(struct zx2967_i2c_info *zx_i2c, int size,
+				  union i2c_smbus_data *data)
+{
+	unsigned long time_left;
+	u8 buf[2];
+	u32 val;
+
+	reinit_completion(&zx_i2c->complete);
+
+	val = zx2967_i2c_readl(zx_i2c, REG_CMD);
+	val |= I2C_CMB_RW_EN;
+	zx2967_i2c_writel(zx_i2c, val, REG_CMD);
+
+	val = zx2967_i2c_readl(zx_i2c, REG_CMD);
+	val |= I2C_START;
+	zx2967_i2c_writel(zx_i2c, val, REG_CMD);
+
+	time_left = wait_for_completion_timeout(&zx_i2c->complete,
+						I2C_TIMEOUT);
+	if (time_left == 0)
+		return -ETIMEDOUT;
+
+	switch (size) {
+	case I2C_SMBUS_BYTE:
+	case I2C_SMBUS_BYTE_DATA:
+		val = zx2967_i2c_readl(zx_i2c, REG_DATA);
+		data->byte = val;
+		break;
+	case I2C_SMBUS_WORD_DATA:
+	case I2C_SMBUS_PROC_CALL:
+		buf[0] = zx2967_i2c_readl(zx_i2c, REG_DATA);
+		buf[1] = zx2967_i2c_readl(zx_i2c, REG_DATA);
Quoted 8 lines

drivers/i2c/busses/Kconfig

Quoted 4 lines
drivers/i2c/busses/Kconfig +4 -0
+		data->word = (buf[0] << 8) | buf[1];
+		break;
+	default:
+		dev_warn(DEV(zx_i2c), "Unsupported transaction %d\n", size);

I wouldn't print something here. If an unsupported SMBus transfer is used, your driver will fall back to emulate them via I2C. No need to print a warning then.

Okay, will drop it.

Quoted 11 lines
Quoted 11 lines
drivers/i2c/busses/Kconfig +10 -0
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+#define ZX2967_I2C_FUNCS (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |	\
+		I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |	\
+		I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL |	\
+		I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK)
Quoted 8 lines

drivers/i2c/busses/Kconfig

Quoted 5 lines
drivers/i2c/busses/Kconfig +5 -0
+
+static u32 zx2967_i2c_func(struct i2c_adapter *adap)
+{
+	return ZX2967_I2C_FUNCS;
+}

No strong opinion but I think we can return that value directly without a define.

I do not have a strong opinion either, but since you ask, I will do what you are asking here.

Quoted 8 lines

...

drivers/i2c/busses/Kconfig

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+	ret = i2c_add_numbered_adapter(&zx_i2c->adap);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to add zx2967 i2c adapter\n");

Drop the message, the core will do the reporting.

Okay, will do.

Quoted 5 lines

drivers/i2c/busses/Kconfig

Quoted 3 lines
drivers/i2c/busses/Kconfig +2 -0
+		goto err_clk_unprepare;
+	}

How was this driver tested BTW?

The driver is being used to access an Audio codec on the I2C bus.

Shawn

#5 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

Hi Shawn,

Quoted 5 lines

Oh, yes, I should have mentioned it in the cover-letter. Instead of changing MAINTAINERS file in different subsystem patch series, which may introduce merge conflicts, we plan to update it with a separate patch adding all driver entries that lands on mainline, and get it in through arm-soc tree. Are you okay with that?

Yup, totally fine! Good approach.

Quoted 10 lines
Quoted 4 lines

Is this the error handling (NACK, etc)? Then, it got lost now since we don't reset the hardware anymore after timeouts. But that would have meant that errors are only detected after the timeout was reached instead of instantly? If so, no good design. But maybe I misunderstand.

Hmm, this doesn't make too much sense now, since this reset function is only being called at probe time to ensure the device is in a sane initial state. There is no data transfer happening at this point at all. I will drop these error bits checking from here, and add the error handling in irq handler.

Great, thanks!

Quoted 3 lines
Quoted 1 line

How was this driver tested BTW?

The driver is being used to access an Audio codec on the I2C bus.

Nice. Can you also run 'i2cdetect' on the bus to see if we have proper NAK handling? AFAICS this should be broken now. And very slow with previous versions of the driver.

Thanks,

Wolfram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170620/997f5aa4/attachment.sig>

author
#6 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

Quoted 3 lines · Wolfram Sang

Nice. Can you also run 'i2cdetect' on the bus to see if we have proper NAK handling? AFAICS this should be broken now. And very slow with previous versions of the driver.

Sure, thanks for the suggestion. I will make sure that 'i2cdetect' is happy with the driver.

Shawn

author
#7 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

In reply to Wolfram Sang
Quoted 7 lines · Wolfram Sang
Quoted 3 lines
Quoted 1 line

How was this driver tested BTW?

The driver is being used to access an Audio codec on the I2C bus.

Nice. Can you also run 'i2cdetect' on the bus to see if we have proper NAK handling? AFAICS this should be broken now. And very slow with previous versions of the driver.

Hmm, it seems that 'i2cdetect' works fine with the driver.

$ i2cdetect -l
i2c-0   i2c             zx2967 i2c adapter                      I2C adapter
$ i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] Y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- 5a -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         
$

The audio codec is on address 0x22.

Why do you think it should be broken now?

Shawn

#8 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

Quoted 4 lines

The audio codec is on address 0x22.

Why do you think it should be broken now?

Because I thought that we skipped the error handling for every transfer when we removed the call to reset_hardware from the xfer function.

So, either it still works because the transfer times out. But then i2cdetect should be really slow. The timeout is set to 1s, so it should take 1s to scan every address.

Or I am completely missing something. Then, I am sorry for the noise.

Thanks for testing anyhow!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170622/4dc2b97f/attachment.sig>

author
#9 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

Quoted 5 lines · Wolfram Sang
Quoted 4 lines

The audio codec is on address 0x22.

Why do you think it should be broken now?

Quoted 8 lines

Because I thought that we skipped the error handling for every transfer when we removed the call to reset_hardware from the xfer function.

So, either it still works because the transfer times out. But then i2cdetect should be really slow. The timeout is set to 1s, so it should take 1s to scan every address.

Or I am completely missing something. Then, I am sorry for the noise.

It's me who is missing something. You are right. With the current driver, i2cdetect takes 1s to scan most addresses. Except address 0x22, those devices detected on other addresses are just wrong, and the addresses vary from a scan to another.

With the proper error handling, i2cdetect now works very fast and only gets audio codec on 0x22, which is correct.

$ i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] Y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

Thanks a lot for identifying the bug.

Shawn

#10 lore raw

PATCH 2/2 i2c: zx2967: add i2c controller driver for ZTE's zx2967 family

Quoted 3 lines

With the proper error handling, i2cdetect now works very fast and only gets audio codec on 0x22, which is correct.

Cool! Now make sure that the error codes are matching Documentation/i2c/fault-codes and I think we are ready to go.

Quoted 1 line

Thanks a lot for identifying the bug.

You are welcome!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170622/43eccea0/attachment.sig>