Skip to contentSkip to conversation

add support for Zhaoxin I2C controller

RFC New Hans Hu 1 participant 3 messages Aug 3, 2023

Subsystems (2)
lore
Share & tools
lore

Hans Hu

author
#0 lore raw

cover add support for Zhaoxin I2C controller

Hi Andi,

As discussed earlier, the Zhaoxin i2c controller uses the same IP as Wonder Media. Therefore, some codes of i2c-wmt.c can be re-used by i2c-zhaoxin.c.

As you suggested, I created two files, named i2c-viai2c-common.{c,h}. They contains the macro definition, function declaration and data structure used by i2c-zhaoxin.c and i2c-wmt.c.

Hans Hu (2):
i2c: separate i2c-viai2c-common from i2c-wmt
i2c: add support for Zhaoxin I2C controller

 MAINTAINERS                            |   7 +
 drivers/i2c/busses/Kconfig             |  15 +
 drivers/i2c/busses/Makefile            |   2 +
 drivers/i2c/busses/i2c-viai2c-common.c | 239 +++++++++++++++
 drivers/i2c/busses/i2c-viai2c-common.h |  76 +++++
 drivers/i2c/busses/i2c-wmt.c           | 402 ++-----------------------
 drivers/i2c/busses/i2c-zhaoxin.c       | 275 +++++++++++++++++
 7 files changed, 645 insertions(+), 371 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-viai2c-common.c
 create mode 100644 drivers/i2c/busses/i2c-viai2c-common.h
 create mode 100644 drivers/i2c/busses/i2c-zhaoxin.c
Signature · 1 line
2.34.1
author
#1 lore raw

RFC 1/2 i2c: separate i2c-viai2c-common from i2c-wmt

export common definitions to i2c-viai2c-common.{c,h}:
1. export common marcos and use prefix VIAI2C rename them.
2. export common functions and use prefix via_i2c rename them.
3. rename data structure wmt_i2c_dev to via_i2c and export it.
4. remove some redundant code.

---
 drivers/i2c/busses/Kconfig             |   4 +
 drivers/i2c/busses/Makefile            |   1 +
 drivers/i2c/busses/i2c-viai2c-common.c | 233 ++++++++++++++
 drivers/i2c/busses/i2c-viai2c-common.h |  65 ++++
 drivers/i2c/busses/i2c-wmt.c           | 402 ++-----------------------
 5 files changed, 333 insertions(+), 372 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-viai2c-common.c
 create mode 100644 drivers/i2c/busses/i2c-viai2c-common.h
drivers/i2c/busses/Kconfig +4 -0
index 9cfe8fc509d7..d0dd0a892d50 100644
@@ -1178,9 +1178,13 @@ config I2C_VERSATILE
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-versatile.
 
+config I2C_VIA_COMMON
+	tristate
+
 config I2C_WMT
 	tristate "Wondermedia WM8xxx SoC I2C bus support"
 	depends on ARCH_VT8500 || COMPILE_TEST
+	select I2C_VIA_COMMON
 	help
 	  Say yes if you want to support the I2C bus on Wondermedia 8xxx-series
 	  SoCs.
drivers/i2c/busses/Makefile +1 -0
index af56fe2c75c0..62b2ed4862e0 100644
@@ -120,6 +120,7 @@ obj-$(CONFIG_I2C_TEGRA_BPMP)	+= i2c-tegra-bpmp.o
 obj-$(CONFIG_I2C_UNIPHIER)	+= i2c-uniphier.o
 obj-$(CONFIG_I2C_UNIPHIER_F)	+= i2c-uniphier-f.o
 obj-$(CONFIG_I2C_VERSATILE)	+= i2c-versatile.o
+obj-$(CONFIG_I2C_VIA_COMMON)	+= i2c-viai2c-common.o
 obj-$(CONFIG_I2C_WMT)		+= i2c-wmt.o
 i2c-octeon-objs := i2c-octeon-core.o i2c-octeon-platdrv.o
 obj-$(CONFIG_I2C_OCTEON)	+= i2c-octeon.o
drivers/i2c/busses/i2c-viai2c-common.c new file +233 -0

233 lines not on this page · raw message

drivers/i2c/busses/i2c-viai2c-common.h new file +65 -0

65 lines not on this page · raw message

drivers/i2c/busses/i2c-wmt.c +30 -372

457 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#2 lore raw

RFC 2/2 i2c: add support for Zhaoxin I2C controller

In reply to Hans Hu

Add Zhaoxin I2C controller driver. It provides the access to the i2c busses, which connects to the touchpad, eeprom, etc.

Zhaoxin I2C controller provides two modes of operation:
FIFO mode: works in access requests without restart. Byte mode: same IP with i2c-wmt and use driver i2c-viai2c-common.

Zhaoxin I2C controller has two separate busses, so may accommodate up to two I2C adapters. Those adapters are listed in the ACPI namespace with the "IIC1D17" HID, and probed by a platform driver.

The driver works with IRQ mode, and supports basic I2C features. Flags I2C_AQ_NO_ZERO_LEN and I2C_AQ_COMB_WRITE_THEN_READ are used to limit the unsupported access.

---
 MAINTAINERS                            |   7 +
 drivers/i2c/busses/Kconfig             |  11 +
 drivers/i2c/busses/Makefile            |   1 +
 drivers/i2c/busses/i2c-viai2c-common.c |  12 +-
 drivers/i2c/busses/i2c-viai2c-common.h |  11 +
 drivers/i2c/busses/i2c-wmt.c           |   2 +
 drivers/i2c/busses/i2c-zhaoxin.c       | 275 +++++++++++++++++++++++++
 7 files changed, 316 insertions(+), 3 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-zhaoxin.c
MAINTAINERS +7 -0
index b3648da1c5b2..bb65f7d748eb 100644
@@ -9864,6 +9864,13 @@ L:	[email protected]
 F:	Documentation/i2c/busses/i2c-ismt.rst
 F:	drivers/i2c/busses/i2c-ismt.c
 
+I2C/SMBUS ZHAOXIN DRIVER
+M:	Hans Hu <[email protected]>
+L:	[email protected]
+S:	Maintained
+W:	https://www.zhaoxin.com
+F:	drivers/i2c/busses/i2c-zhaoxin.c
+
 I2C/SMBUS STUB DRIVER
 M:	Jean Delvare <[email protected]>
 L:	[email protected]
drivers/i2c/busses/Kconfig +11 -0
index d0dd0a892d50..282c26b28a9e 100644
@@ -347,6 +347,17 @@ config I2C_SCMI
 	  To compile this driver as a module, choose M here:
 	  the module will be called i2c-scmi.
 
+config I2C_ZHAOXIN
+	tristate "Zhaoxin I2C Interface"
+	depends on PCI || COMPILE_TEST
+	select I2C_VIA_COMMON
+	help
+	  If you say yes to this option, support will be included for the
+	  ZHAOXIN I2C interface
+
+	  This driver can also be built as a module. If so, the module
+	  will be called i2c-zhaoxin.
+
 endif # ACPI
 
 comment "Mac SMBus host controller drivers"
drivers/i2c/busses/Makefile +1 -0
index 62b2ed4862e0..62cebb72b323 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_I2C_SIS630)	+= i2c-sis630.o
 obj-$(CONFIG_I2C_SIS96X)	+= i2c-sis96x.o
 obj-$(CONFIG_I2C_VIA)		+= i2c-via.o
 obj-$(CONFIG_I2C_VIAPRO)	+= i2c-viapro.o
+obj-$(CONFIG_I2C_ZHAOXIN)	+= i2c-zhaoxin.o
 
 # Mac SMBus host controller drivers
 obj-$(CONFIG_I2C_HYDRA)		+= i2c-hydra.o
drivers/i2c/busses/i2c-viai2c-common.c +9 -3
index 671117caba75..47778ce24367 100644
@@ -53,7 +53,8 @@ static int via_i2c_write(struct via_i2c *i2c, struct i2c_msg *pmsg, int last)
 		writew(pmsg->buf[0], base + VIAI2C_CDR);
 	}
 
-	if (!(pmsg->flags & I2C_M_NOSTART)) {
+	if (!(pmsg->flags & I2C_M_NOSTART)
+	   && (i2c->platform & VIAI2C_PLAT_WMT)) {
 		val = readb(base + VIAI2C_CR);
 		val &= ~VIAI2C_CR_TX_END;
 		val |= VIAI2C_CR_CPU_RDY;
@@ -94,8 +95,10 @@ static int via_i2c_write(struct via_i2c *i2c, struct i2c_msg *pmsg, int last)
 		}
 
 		if (xfer_len == pmsg->len) {
-			if (last != 1)
+			if (last != 1 && (i2c->platform & VIAI2C_PLAT_WMT))
 				writeb(VIAI2C_CR_ENABLE, base + VIAI2C_CR);
+			else if (last && (i2c->platform & VIAI2C_PLAT_ZHAOXIN))
+				writeb(VIAI2C_CR_TX_END, base + VIAI2C_CR);
 		} else {
 			writeb(pmsg->buf[xfer_len] & 0xFF, base + VIAI2C_CDR);
 			writeb(VIAI2C_CR_CONTINUE_MASK, base + VIAI2C_CR);
@@ -159,7 +162,8 @@ int via_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 	for (i = 0; ret >= 0 && i < num; i++) {
 		struct i2c_msg * pmsg = &msgs[i];
 
-		if (!(pmsg->flags & I2C_M_NOSTART)) {
+		if (!(pmsg->flags & I2C_M_NOSTART)
+		   && (i2c->platform & VIAI2C_PLAT_WMT)) {
 			ret = via_i2c_wait_bus_ready(i2c);
 			if (ret < 0)
 				return ret;
@@ -181,6 +185,8 @@ static irqreturn_t via_i2c_isr(int irq, void *data)
 
 	/* save the status and write-clear it */
 	i2c->event = readw(i2c->base + VIAI2C_ISR);
+	if (!i2c->event)
+		return IRQ_NONE;
 	writew(i2c->event, i2c->base + VIAI2C_ISR);
 
 	complete(&i2c->complete);
drivers/i2c/busses/i2c-viai2c-common.h +11 -0
index 39deda1c42c4..98f1895bf0a6 100644
@@ -46,6 +46,11 @@
 
 #define VIAI2C_TIMEOUT		(msecs_to_jiffies(1000))
 
+enum {
+	VIAI2C_PLAT_WMT,
+	VIAI2C_PLAT_ZHAOXIN
+};
+
 struct via_i2c {
 	struct i2c_adapter	adapter;
 	struct completion	complete;
@@ -55,6 +60,12 @@ struct via_i2c {
 	int			irq;
 	u16			event;
 	u16			tcr;
+	bool			platform;
+	u16			tr;
+	u16			mcr;
+	u16			csr;
+	u8			fstp;
+	u8			hrv;
 };
 
 int via_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num);
drivers/i2c/busses/i2c-wmt.c +2 -0
index e445155d1a60..0496c0328314 100644
@@ -78,6 +78,8 @@ static int wmt_i2c_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
+	i2c_dev->platform = VIAI2C_PLAT_WMT;
+
 	i2c_dev->clk = of_clk_get(np, 0);
 	if (IS_ERR(i2c_dev->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->clk),
drivers/i2c/busses/i2c-zhaoxin.c new file +275 -0

275 lines not on this page · raw message

Signature · 1 line
2.34.1