Skip to contentSkip to conversation

i2c: designware: add I2C SLAVE support

PATCH Applied Luis Oliveira 4 participants 8 messages Jun 22, 2017 – Jun 27, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v12 cover i2c: designware: add I2C SLAVE support

This patches follows the merged patchset that refactors I2C Designware and enables it to have I2C support.

The patch 1 adds the necessary functions to give the ability to be a SLAVE to the controller and for that changes also had to be made in the Makefile and Kconfig.
The patch 2 enables the SLAVE mode to be detected by the platform module.

The functionality was tested using the hardware independent slave-eeprom driver based on top of i2c/for-next. The tree I used can be found here:

https://git.kernel.org/cgit/linux/kernel/git/wsa/linux.git/log/?h=i2c/for-next

Luis Oliveira (2):
i2c: designware: add SLAVE mode functions
i2c: designware: enable SLAVE in platform module

 drivers/i2c/busses/Kconfig                  |  14 +-
 drivers/i2c/busses/Makefile                 |   3 +
 drivers/i2c/busses/i2c-designware-common.c  |   6 +
 drivers/i2c/busses/i2c-designware-core.h    |   4 +
 drivers/i2c/busses/i2c-designware-platdrv.c |  41 ++-
 drivers/i2c/busses/i2c-designware-slave.c   | 395 ++++++++++++++++++++++++++++
 6 files changed, 457 insertions(+), 6 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-slave.c
Signature · 7 lines
2.13.0


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH v12 1/2 i2c: designware: add SLAVE mode functions

- Changes in Kconfig to enable I2C_DESIGNWARE_SLAVE support
- Slave functions added to core library file
- Slave abort sources added to common source file
- New driver: i2c-designware-slave added
- Changes in the Makefile to compile the I2C_DESIGNWARE_SLAVE module when supported by the architecture.

All the SLAVE flow is added but it is not enabled via platform driver.

---
V11-v12
- Changed ifdef condition in the Makefile fixed Kbuild error

 drivers/i2c/busses/Kconfig                 |  14 +-
 drivers/i2c/busses/Makefile                |   3 +
 drivers/i2c/busses/i2c-designware-common.c |   6 +
 drivers/i2c/busses/i2c-designware-core.h   |   2 +
 drivers/i2c/busses/i2c-designware-slave.c  | 395 +++++++++++++++++++++++++++++
 5 files changed, 419 insertions(+), 1 deletion(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-slave.c
drivers/i2c/busses/Kconfig +13 -1
index ed7106e48ba4..ed92bf560825 100644
@@ -473,14 +473,26 @@ config I2C_DESIGNWARE_CORE
 config I2C_DESIGNWARE_PLATFORM
 	tristate "Synopsys DesignWare Platform"
 	select I2C_DESIGNWARE_CORE
+	select I2C_DESIGNWARE_SLAVE
 	depends on (ACPI && COMMON_CLK) || !ACPI
 	help
 	  If you say yes to this option, support will be included for the
-	  Synopsys DesignWare I2C adapter. Only master mode is supported.
+	  Synopsys DesignWare I2C adapter.
 
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-designware-platform.
 
+config I2C_DESIGNWARE_SLAVE
+	bool "Synopsys DesignWare Slave"
+	select I2C_SLAVE
+	depends on I2C_DESIGNWARE_PLATFORM
+	help
+	  If you say yes to this option, support will be included for the
+	  Synopsys DesignWare I2C slave adapter.
+
+	  This is not a standalone module, this module compiles together with
+	  i2c-designware-core.
+
 config I2C_DESIGNWARE_PCI
 	tristate "Synopsys DesignWare PCI"
 	depends on PCI
drivers/i2c/busses/Makefile +3 -0
index c89a4314c563..d630a6cbafeb 100644
@@ -41,6 +41,9 @@ obj-$(CONFIG_I2C_CPM)		+= i2c-cpm.o
 obj-$(CONFIG_I2C_DAVINCI)	+= i2c-davinci.o
 obj-$(CONFIG_I2C_DESIGNWARE_CORE)	+= i2c-designware-core.o
 i2c-designware-core-objs := i2c-designware-common.o i2c-designware-master.o
+ifeq ($(CONFIG_I2C_DESIGNWARE_SLAVE),y)
+i2c-designware-core-objs += i2c-designware-slave.o
+endif
 obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM)	+= i2c-designware-platform.o
 i2c-designware-platform-objs := i2c-designware-platdrv.o
 i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_BAYTRAIL) += i2c-designware-baytrail.o
drivers/i2c/busses/i2c-designware-common.c +6 -0
index 0d0ccb73f0e6..d1a69372432f 100644
@@ -56,6 +56,12 @@ static char *abort_sources[] = {
 		"trying to use disabled adapter",
 	[ARB_LOST] =
 		"lost arbitration",
+	[ABRT_SLAVE_FLUSH_TXFIFO] =
+		"read command so flush old data in the TX FIFO",
+	[ABRT_SLAVE_ARBLOST] =
+		"slave lost the bus while transmitting data to a remote master",
+	[ABRT_SLAVE_RD_INTX] =
+		"incorrect slave-transmitter mode configuration",
 };
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)
drivers/i2c/busses/i2c-designware-core.h +2 -0
index 76807eafda53..64a39a983410 100644
@@ -305,9 +305,11 @@ u32 i2c_dw_func(struct i2c_adapter *adap);
 void i2c_dw_disable(struct dw_i2c_dev *dev);
 void i2c_dw_disable_int(struct dw_i2c_dev *dev);
 int i2c_dw_init(struct dw_i2c_dev *dev);
+int i2c_dw_init_slave(struct dw_i2c_dev *dev);
 
 extern u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev);
 extern int i2c_dw_probe(struct dw_i2c_dev *dev);
+extern int i2c_dw_probe_slave(struct dw_i2c_dev *dev);
 
 #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_BAYTRAIL)
 extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-slave.c new file +395 -0

395 lines not on this page · raw message

Signature · 1 line
2.13.0
reviewer Reviewed-by on v12 1/2
#2 lore raw

Re: [PATCH v12 1/2] i2c: designware: add SLAVE mode functions

Quoted 9 lines · Luis Oliveira

- Changes in Kconfig to enable I2C_DESIGNWARE_SLAVE support
- Slave functions added to core library file
- Slave abort sources added to common source file
- New driver: i2c-designware-slave added
- Changes in the Makefile to compile the I2C_DESIGNWARE_SLAVE module when supported by the architecture.

All the SLAVE flow is added but it is not enabled via platform driver.

There are couple of nits, otherwise I'm okay with the patch.

Quoted 2 lines

V11-v12
- Changed ifdef condition in the Makefile fixed Kbuild error

+ rebased on top of latest i2c-next (drop applied patches effectively)

drivers/i2c/busses/i2c-designware-slave.c line 281

Quoted 8 lines
drivers/i2c/busses/i2c-designware-slave.c new file +5 -0
+static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev)
+{
 
 
+	dev_dbg(dev->dev,
 
+		"%#x STAUTS SLAVE_ACTTVITY=%#x : RAW_INTR_STAT=%#x"
+		" : INTR_STAT=%#x\n",

Don't split string literals.

drivers/i2c/busses/i2c-designware-slave.c line 296

Quoted 6 lines
(quoted diff) +2 -0
+		enabled, slave_activity, raw_stat, stat);
 
 
+					dev_vdbg(dev->dev, "Byte %X

acked!",

drivers/i2c/busses/i2c-designware-slave.c new file +1 -0
+						 val);

I'm not sure it's any helpful.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
Acked-by on v12 1/2
#3 lore raw

Re: [PATCH v12 1/2] i2c: designware: add SLAVE mode functions

In reply to Luis Oliveira
Quoted 23 lines · Luis Oliveira

- Changes in Kconfig to enable I2C_DESIGNWARE_SLAVE support
- Slave functions added to core library file
- Slave abort sources added to common source file
- New driver: i2c-designware-slave added
- Changes in the Makefile to compile the I2C_DESIGNWARE_SLAVE module when supported by the architecture.

All the SLAVE flow is added but it is not enabled via platform driver.

---
V11-v12
- Changed ifdef condition in the Makefile fixed Kbuild error

 drivers/i2c/busses/Kconfig                 |  14 +-
 drivers/i2c/busses/Makefile                |   3 +
 drivers/i2c/busses/i2c-designware-common.c |   6 +
 drivers/i2c/busses/i2c-designware-core.h   |   2 +
 drivers/i2c/busses/i2c-designware-slave.c  | 395 +++++++++++++++++++++++++++++
 5 files changed, 419 insertions(+), 1 deletion(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-slave.c

...

Quoted 9 lines
drivers/i2c/busses/i2c-designware-slave.c new file +9 -0
+static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev)
+{
+	u32 raw_stat, stat, enabled;
+	u8 val, slave_activity;
+
+	stat = dw_readl(dev, DW_IC_INTR_STAT);
+	enabled = dw_readl(dev, DW_IC_ENABLE);
+	raw_stat = dw_readl(dev, DW_IC_RAW_INTR_STAT);
+	slave_activity = ((dw_readl(dev, DW_IC_STATUS) &

drivers/i2c/busses/i2c-designware-slave.c line 283

Quoted 10 lines
drivers/i2c/busses/i2c-designware-slave.c new file +10 -0
+		DW_IC_STATUS_SLAVE_ACTIVITY) >> 6);
+
+	if (!enabled || !(raw_stat & ~DW_IC_INTR_ACTIVITY))
+		return 0;
+
+	dev_dbg(dev->dev,
+		"%#x STAUTS SLAVE_ACTTVITY=%#x : RAW_INTR_STAT=%#x"
+		" : INTR_STAT=%#x\n",
+		enabled, slave_activity, raw_stat, stat);
+

Minor notes:
- Strings that are printed should fit in single line for making easier to grep them from sources. Maybe not all of those variables are not necessary in this debug print (e.g. are we interested other than bit 0 in DW_IC_ENABLE and line above already returns if it reads zero).
- Typos "STAUTS SLAVE_ACTTVITY".

You may add my acked by if you want to send another version or I'm fine with incremental patch also.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Applied
#4 lore raw

Re: [PATCH v12 1/2] i2c: designware: add SLAVE mode functions

In reply to Luis Oliveira
Quoted 11 lines · Luis Oliveira

- Changes in Kconfig to enable I2C_DESIGNWARE_SLAVE support
- Slave functions added to core library file
- Slave abort sources added to common source file
- New driver: i2c-designware-slave added
- Changes in the Makefile to compile the I2C_DESIGNWARE_SLAVE module when supported by the architecture.

All the SLAVE flow is added but it is not enabled via platform driver.

I fixed this checkpatch warning for you:

WARNING: quoted string split across lines
#391: FILE: drivers/i2c/busses/i2c-designware-slave.c:281:
+ "%#x STAUTS SLAVE_ACTTVITY=%#x : RAW_INTR_STAT=%#x"
+ " : INTR_STAT=%#x\n",

Nice, you fooled two code checkers by having code in comments :) No need to fix, of course:

SMATCH
drivers/i2c/busses/i2c-designware-slave.c:318 i2c_dw_irq_handler_slave warn: unused return: stat = i2c_dw_read_clear_intrbits_slave() drivers/i2c/busses/i2c-designware-slave.c:329 i2c_dw_irq_handler_slave warn: unused return: stat = i2c_dw_read_clear_intrbits_slave()
CPPCHECK
drivers/i2c/busses/i2c-designware-slave.c:329: style: Variable 'stat' is assigned a value that is never used.

Build warning:

CC drivers/i2c/busses/i2c-designware-slave.o
drivers/i2c/busses/i2c-designware-slave.c:173:5: warning: no previous prototype for ‘i2c_dw_reg_slave’ [-Wmissing-prototypes]
int i2c_dw_reg_slave(struct i2c_client *slave)

I declared the function static to fix it.

Applied to for-next, thanks!

#5 lore raw

PATCH v12 2/2 i2c: designware: enable SLAVE in platform module

In reply to Luis Oliveira

- Slave mode selected in platform module if the support is detected in the DT.

---
V11-V12
- no changes

 drivers/i2c/busses/i2c-designware-core.h    |  2 ++
 drivers/i2c/busses/i2c-designware-platdrv.c | 41 +++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +2 -0
index 64a39a983410..7bfbcc62f6c5 100644
@@ -228,6 +228,7 @@
  * @disable: function to disable the controller
  * @disable_int: function to disable all interrupts
  * @init: function to initialize the I2C hardware
+ * @mode: operation mode - DW_IC_MASTER or DW_IC_SLAVE
  *
  * HCNT and LCNT parameters can be used if the platform knows more accurate
  * values than the one computed based only on the input clock frequency.
@@ -282,6 +283,7 @@ struct dw_i2c_dev {
 	void			(*disable)(struct dw_i2c_dev *dev);
 	void			(*disable_int)(struct dw_i2c_dev *dev);
 	int			(*init)(struct dw_i2c_dev *dev);
+	int			mode;
 };
 
 #define ACCESS_SWAP		0x00000001
drivers/i2c/busses/i2c-designware-platdrv.c +36 -5

72 lines not on this page · raw message

Signature · 1 line
2.13.0
Acked-by on v12 2/2
#6 lore raw

Re: [PATCH v12 2/2] i2c: designware: enable SLAVE in platform module

Quoted 5 lines · Luis Oliveira

- Slave mode selected in platform module if the support is detected in the DT.

Quoted 8 lines

---
V11-V12
- no changes

 drivers/i2c/busses/i2c-designware-core.h    |  2 ++
 drivers/i2c/busses/i2c-designware-platdrv.c | 41 +++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 5 deletions(-)