i2c: add support for Zhaoxin I2C controller
Subsystems (2)
v2 cover i2c: add support for Zhaoxin I2C controller
Hi Andi, Wolfram,
The Zhaoxin I2C controller uses the same I2C IP as Wonder Media. Both Zhaoxin and Wonder Media's I2C IP are come from VIA I2C IP. Therefore, some codes of i2c-wmt.c can be re-used by i2c-zhaoxin.c.
As suggested earlier, created two files, named i2c-viai2c-common.{c,h}. They contains the macro definitions, functions declaration and data structure used by both i2c-zhaoxin.c and i2c-wmt.c.
v1->v2:
1. Fixed a compilation error for header file references.
2. use I2C platform device's name to define the irq's name.
Hans Hu (2):
i2c: wmt: split out i2c-viai2c-common.{c,h}
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 | 274 +++++++++++++++++ 7 files changed, 644 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
PATCH v2 1/2 i2c: wmt: split out 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. adjust 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
@@ -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_VIAI2C_COMMON + tristate + config I2C_WMT tristate "Wondermedia WM8xxx SoC I2C bus support" depends on ARCH_VT8500 || COMPILE_TEST + select I2C_VIAI2C_COMMON help Say yes if you want to support the I2C bus on Wondermedia 8xxx-series SoCs.
drivers/i2c/busses/Makefile +1 -0
@@ -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_VIAI2C_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
Re: [PATCH v2 1/2] i2c: wmt: split out i2c-viai2c-common.{c,h}
Hi!
first of all, thank you for reworking your driver to share common code with the WMT driver. This effort is much appreciated and we are close to go, I think. But some remarks.
Quoted 15 lines
drivers/i2c/busses/Kconfig +4
-0+config I2C_VIAI2C_COMMON + tristate + config I2C_WMT tristate "Wondermedia WM8xxx SoC I2C bus support" depends on ARCH_VT8500 || COMPILE_TEST + select I2C_VIAI2C_COMMON help Say yes if you want to support the I2C bus on Wondermedia 8xxx-series SoCs.drivers/i2c/busses/Makefile +0
-0
drivers/i2c/busses/Makefile obj-$(CONFIG_I2C_TEGRA_BPMP) += i2c-tegra-bpmp.o · line 126
Quoted 7 lines
drivers/i2c/busses/Makefile +1
-0@@ -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_VIAI2C_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
I'd prefer to link the core object to the driver object like pasemi or octeon do. Or is there an argument for having a seperate module?
Regards!
Re: [PATCH v2 1/2] i2c: wmt: split out i2c-viai2c-common.{c,h}
Quoted 22 lines · Wolfram Sang
Hi!
first of all, thank you for reworking your driver to share common code with the WMT driver. This effort is much appreciated and we are close to go, I think. But some remarks.
Quoted 16 lines
drivers/i2c/busses/Kconfig +4
-0+config I2C_VIAI2C_COMMON + tristate + config I2C_WMT tristate "Wondermedia WM8xxx SoC I2C bus support" depends on ARCH_VT8500 || COMPILE_TEST + select I2C_VIAI2C_COMMON help Say yes if you want to support the I2C bus on Wondermedia 8xxx-series SoCs.drivers/i2c/busses/Makefile +0
-0@@ -120,6 +120,7 @@ obj-$(CONFIG_I2C_TEGRA_BPMP) += i2c-tegra-bpmp.o obj-$(CONFIG_I2C_UNIPHIER) += i2c-uniphier.o
Quoted 8 lines
drivers/i2c/busses/Makefile obj-$(CONFIG_I2C_TEGRA_BPMP) += i2c-tegra-bpmp.o · line 126
Quoted 6 lines
drivers/i2c/busses/Makefile +1
-0obj-$(CONFIG_I2C_UNIPHIER_F) += i2c-uniphier-f.o obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o +obj-$(CONFIG_I2C_VIAI2C_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.oI'd prefer to link the core object to the driver object like pasemi or octeon do. Or is there an argument for having a seperate module?
There are two main reasons:
1. I checked the MAINTAINERS section related to ARM/VT8500, Found that the entire ARM/VT8500 ARCHITECTURE is currently unmaintained, maybe one day it will be removed from the kernel. So I think it might be better as a separate module.
2. In addition, if not separated from wmt, the driver would become a bit confusing and difficult to maintain.
Quoted 2 lines
Regards!
Re: [PATCH v2 1/2] i2c: wmt: split out i2c-viai2c-common.{c,h}
Quoted 5 lines
1. I checked the
MAINTAINERSsection related to ARM/VT8500, Found that the entire ARM/VT8500 ARCHITECTURE is currently unmaintained, maybe one day it will be removed from the kernel. So I think it might be better as a separate module.
But even if we remove the arch, we will not remove the viai2c core, right? We just remove the Makefile entry for WMT. And your driver will still link two object files into one kernel object.
Quoted 2 lines
2. In addition, if not separated from wmt, the driver would become a bit confusing and difficult to maintain.
Ah, maybe this is the misunderstanding. The seperation from WMT is very good! It is just that the new viai2c core shouldn't be a module itself but only a seperate object file which gets linked into your driver. Please check the octeon or pasemi driver for an example.
Re: [PATCH v2 1/2] i2c: wmt: split out i2c-viai2c-common.{c,h}
Quoted 8 lines · Wolfram Sang
Quoted 4 lines
1. I checked the
MAINTAINERSsection related to ARM/VT8500, Found that the entire ARM/VT8500 ARCHITECTURE is currently unmaintained, maybe one day it will be removed from the kernel. So I think it might be better as a separate module.But even if we remove the arch, we will not remove the viai2c core, right? We just remove the
Makefileentry for WMT. And your driver will still link two object files into one kernel object.
Quoted 7 lines
Quoted 2 lines
2. In addition, if not separated from wmt, the driver would become a bit confusing and difficult to maintain.
Ah, maybe this is the misunderstanding. The seperation from WMT is very good! It is just that the new viai2c core shouldn't be a module itself but only a seperate object file which gets linked into your driver. Please check the octeon or pasemi driver for an example.
Sorry about the misunderstanding, will change to like below:
i2c-zhaoxin-objs:= i2c-viai2c-common.o i2c-zhaoxin-plt.o obj-$(CONFIG_I2C_ZHAOXIN) += i2c-zhaoxin.o i2c-wmt-objs:= i2c-viai2c-common.o i2c-wmt-plt.o obj-$(CONFIG_I2C_WMT) += i2c-wmt.o
But I'm not sure which way is more appropriate:
change file name i2c-wmt.c to i2c-wmt-plt.c.(I prefer this) or
change config name CONFIG_I2C_WMT to CONFIG_I2C_WMT_PLT.
Hans
Re: [PATCH v2 1/2] i2c: wmt: split out i2c-viai2c-common.{c,h}
Quoted 3 lines
i2c-zhaoxin-objs:= i2c-viai2c-common.o i2c-zhaoxin-plt.o obj-$(CONFIG_I2C_ZHAOXIN) += i2c-zhaoxin.o
Yes, exactly!
Quoted 5 lines
i2c-wmt-objs:= i2c-viai2c-common.o i2c-wmt-plt.o
obj-$(CONFIG_I2C_WMT) += i2c-wmt.oBut I'm not sure which way is more appropriate:
change file namei2c-wmt.cto i2c-wmt-plt.c.(I prefer this)
I prefer this, too!
Thank you and happy hacking!
PATCH v2 2/2 i2c: add support for Zhaoxin I2C controller
In reply to Hans HuAdd 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 | 274 +++++++++++++++++++++++++ 7 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 drivers/i2c/busses/i2c-zhaoxin.c
MAINTAINERS +7 -0
@@ -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
@@ -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_VIAI2C_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
@@ -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
@@ -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
@@ -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
@@ -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 +274 -0
274 lines not on this page · raw message
Signature · 1 line
2.34.1
MAINTAINERS L: [email protected] · line 9872
Quoted 7 lines
MAINTAINERS +6
-0+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
Are you open to maintain the viai2c core as well? If so, then I'd think adding another "F:"-entry here will do.
Quoted 8 lines · Wolfram Sang
MAINTAINERS L: [email protected] · line 9872
Quoted 6 lines
MAINTAINERS +6
-0+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.cAre you open to maintain the viai2c core as well? If so, then I'd think adding another "F:"-entry here will do.
Yes, we can, will add in V3.