Skip to contentSkip to conversation

i2c: designware: add I2C SLAVE support

PATCH RESEND Superseded Luis Oliveira 3 participants 17 messages Mar 1, 2017 – Mar 17, 2017

Subsystems (4)

v6 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v6 cover i2c: designware: add I2C SLAVE support

The purpose of this patchset is to enable Linux to be a I2C slave by enabling the slave functionality in the designware I2C controller and at the same time it does some cleaning of the existing code.

The patch 1 is for cleaning and commentary fix.
The patch 2 refactors the original i2c-designware-core and extracts all master functions to a i2c-designware-master source file as suggested by Andy Shevchenko when I first submited the update. The patch 3 then separates the MASTER flow from the common flow.
The patch 4 introduces the SLAVE necessary definitions to the i2c-designware library and adds a how-to-use example to the designware.txt in device tree bindings.
The patch 5 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 6 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 (6):
i2c: designware: Cleaning and comment style fixes.
i2c: designware: refactoring of the i2c-designware
i2c: designware: MASTER mode as separated driver
i2c: designware: introducing I2C_SLAVE definitions
i2c: designware: add SLAVE mode functions
i2c: designware: enable SLAVE in platform module

 .../devicetree/bindings/i2c/i2c-designware.txt     |  16 +-
 drivers/i2c/busses/Kconfig                         |  15 +-
 drivers/i2c/busses/Makefile                        |   2 +
 drivers/i2c/busses/i2c-designware-common.c         | 281 ++++++++++++
 drivers/i2c/busses/i2c-designware-core.h           | 180 +++++++-
 ...c-designware-core.c => i2c-designware-master.c} | 469 +++------------------
 drivers/i2c/busses/i2c-designware-platdrv.c        | 116 +++--
 drivers/i2c/busses/i2c-designware-slave.c          | 403 ++++++++++++++++++
 8 files changed, 1031 insertions(+), 451 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-common.c
 rename drivers/i2c/busses/{i2c-designware-core.c => i2c-designware-master.c} (59%)
 create mode 100644 drivers/i2c/busses/i2c-designware-slave.c
Signature · 1 line
2.11.0
#1 lore raw

PATCH RESEND v6 1/6 i2c: designware: Cleaning and comment style fixes.

The purpose of this commit is to fix some comments and styling in the existing code due to the need of reuse this code. What is being made here is:

- Sorted the headers files
- Corrected some comments style (capital letters, lowcase i2c)
- Reverse tree in the variables declaration
- Add/remove empty lines and tabs where needed
- Fix of misspelled word "endianness" and "transferred"
- Replaced the return variable "r" with the more standard "ret"

The value of this, besides the rules of coding style, is because I will use this code after and it will make my future patch a lot bigger and complicated to review. The work here won't bring any additional work to backported fixes because is just style and reordering.

---
- Added the replacement of "r" for "ret" return variables, before it was done in the 7th patch

 drivers/i2c/busses/i2c-designware-core.c    | 80 ++++++++++++++---------------
 drivers/i2c/busses/i2c-designware-core.h    |  2 +-
 drivers/i2c/busses/i2c-designware-platdrv.c | 42 +++++++--------
 3 files changed, 63 insertions(+), 61 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +40 -40
index 7a3faa551cf8..46937865ef8f 100644
@@ -21,17 +21,17 @@
  * ----------------------------------------------------------------------------
  *
  */
+#include <linux/delay.h>
 #include <linux/export.h>
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
-#include <linux/pm_runtime.h>
-#include <linux/delay.h>
 #include <linux/module.h>
-#include "i2c-designware-core.h"
+#include <linux/pm_runtime.h>
 
+#include "i2c-designware-core.h"
 /*
  * Registers offset
  */
@@ -98,7 +98,7 @@
 
 #define DW_IC_ERR_TX_ABRT	0x1
 
-#define DW_IC_TAR_10BITADDR_MASTER BIT(12)
+#define DW_IC_TAR_10BITADDR_MASTER		BIT(12)
 
 #define DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH	(BIT(2) | BIT(3))
 #define DW_IC_COMP_PARAM_1_SPEED_MODE_MASK	GENMASK(3, 2)
@@ -113,10 +113,10 @@
 #define TIMEOUT			20 /* ms */
 
 /*
- * hardware abort codes from the DW_IC_TX_ABRT_SOURCE register
+ * Hardware abort codes from the DW_IC_TX_ABRT_SOURCE register
  *
- * only expected abort codes are listed here
- * refer to the datasheet for the full list
+ * Only expected abort codes are listed here,
+ * refer to the datasheet for the full list.
  */
 #define ABRT_7B_ADDR_NOACK	0
 #define ABRT_10ADDR1_NOACK	1
@@ -318,7 +318,7 @@ static void i2c_dw_release_lock(struct dw_i2c_dev *dev)
 }
 
 /**
- * i2c_dw_init() - initialize the designware i2c master hardware
+ * i2c_dw_init() - Initialize the designware I2C master hardware
  * @dev: device private data
  *
  * This functions configures and enables the I2C master.
@@ -338,14 +338,14 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 	reg = dw_readl(dev, DW_IC_COMP_TYPE);
 	if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
-		/* Configure register endianess access */
+		/* Configure register endianness access */
 		dev->accessor_flags |= ACCESS_SWAP;
 	} else if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
 		/* Configure register access mode 16bit */
 		dev->accessor_flags |= ACCESS_16BIT;
 	} else if (reg != DW_IC_COMP_TYPE_VALUE) {
-		dev_err(dev->dev, "Unknown Synopsys component type: "
-			"0x%08x\n", reg);
+		dev_err(dev->dev,
+			"Unknown Synopsys component type: 0x%08x\n", reg);
 		i2c_dw_release_lock(dev);
 		return -ENODEV;
 	}
@@ -355,7 +355,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 	/* Disable the adapter */
 	__i2c_dw_enable_and_wait(dev, false);
 
-	/* set standard and fast speed deviders for high/low periods */
+	/* Set standard and fast speed deviders for high/low periods */
 
 	sda_falling_time = dev->sda_falling_time ?: 300; /* ns */
 	scl_falling_time = dev->scl_falling_time ?: 300; /* ns */
@@ -444,7 +444,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 	dw_writel(dev, dev->tx_fifo_depth / 2, DW_IC_TX_TL);
 	dw_writel(dev, 0, DW_IC_RX_TL);
 
-	/* configure the i2c master */
+	/* Configure the I2C master */
 	dw_writel(dev, dev->master_cfg , DW_IC_CON);
 
 	i2c_dw_release_lock(dev);
@@ -480,7 +480,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
 	/* Disable the adapter */
 	__i2c_dw_enable_and_wait(dev, false);
 
-	/* if the slave address is ten bit address, enable 10BITADDR */
+	/* If the slave address is ten bit address, enable 10BITADDR */
 	ic_con = dw_readl(dev, DW_IC_CON);
 	if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) {
 		ic_con |= DW_IC_CON_10BITADDR_MASTER;
@@ -503,7 +503,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
 	 */
 	dw_writel(dev, msgs[dev->msg_write_idx].addr | ic_tar, DW_IC_TAR);
 
-	/* enforce disabled interrupts (due to HW issues) */
+	/* Enforce disabled interrupts (due to HW issues) */
 	i2c_dw_disable_int(dev);
 
 	/* Enable the adapter */
@@ -537,9 +537,9 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
 		u32 flags = msgs[dev->msg_write_idx].flags;
 
 		/*
-		 * if target address has changed, we need to
-		 * reprogram the target address in the i2c
-		 * adapter when we are done with this transfer
+		 * If target address has changed, we need to
+		 * reprogram the target address in the I2C
+		 * adapter when we are done with this transfer.
 		 */
 		if (msgs[dev->msg_write_idx].addr != addr) {
 			dev_err(dev->dev,
@@ -599,7 +599,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
 
 			if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
 
-				/* avoid rx buffer overrun */
+				/* Avoid rx buffer overrun */
 				if (dev->rx_outstanding >= dev->rx_fifo_depth)
 					break;
 
@@ -728,7 +728,7 @@ static int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev)
 }
 
 /*
- * Prepare controller for a transaction and call i2c_dw_xfer_msg
+ * Prepare controller for a transaction and call i2c_dw_xfer_msg.
  */
 static int
 i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
@@ -759,10 +759,10 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 	if (ret < 0)
 		goto done;
 
-	/* start the transfers */
+	/* Start the transfers */
 	i2c_dw_xfer_init(dev);
 
-	/* wait for tx to complete */
+	/* Wait for tx to complete */
 	if (!wait_for_completion_timeout(&dev->cmd_complete, adap->timeout)) {
 		dev_err(dev->dev, "controller timed out\n");
 		/* i2c_dw_init implicitly disables the adapter */
@@ -786,7 +786,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 		goto done;
 	}
 
-	/* no error */
+	/* No error */
 	if (likely(!dev->cmd_err && !dev->status)) {
 		ret = num;
 		goto done;
@@ -821,8 +821,8 @@ static u32 i2c_dw_func(struct i2c_adapter *adap)
 }
 
 static const struct i2c_algorithm i2c_dw_algo = {
-	.master_xfer	= i2c_dw_xfer,
-	.functionality	= i2c_dw_func,
+	.master_xfer = i2c_dw_xfer,
+	.functionality = i2c_dw_func,
 };
 
 static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
@@ -903,7 +903,7 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
 
 		/*
 		 * Anytime TX_ABRT is set, the contents of the tx/rx
-		 * buffers are flushed.  Make sure to skip them.
+		 * buffers are flushed. Make sure to skip them.
 		 */
 		dw_writel(dev, 0, DW_IC_INTR_MASK);
 		goto tx_aborted;
@@ -925,7 +925,7 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
 	if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err)
 		complete(&dev->cmd_complete);
 	else if (unlikely(dev->accessor_flags & ACCESS_INTR_MASK)) {
-		/* workaround to trigger pending interrupt */
+		/* Workaround to trigger pending interrupt */
 		stat = dw_readl(dev, DW_IC_INTR_MASK);
 		i2c_dw_disable_int(dev);
 		dw_writel(dev, stat, DW_IC_INTR_MASK);
@@ -960,13 +960,13 @@ EXPORT_SYMBOL_GPL(i2c_dw_read_comp_param);
 int i2c_dw_probe(struct dw_i2c_dev *dev)
 {
 	struct i2c_adapter *adap = &dev->adapter;
-	int r;
-
+	int ret;
+	
 	init_completion(&dev->cmd_complete);
 
-	r = i2c_dw_init(dev);
-	if (r)
-		return r;
+	ret = i2c_dw_init(dev);
+	if (ret)
+		return ret;
 
 	snprintf(adap->name, sizeof(adap->name),
 		 "Synopsys DesignWare I2C adapter");
@@ -976,13 +976,13 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
 	i2c_set_adapdata(adap, dev);
 
 	i2c_dw_disable_int(dev);
-	r = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr,
+	ret = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr,
 			     IRQF_SHARED | IRQF_COND_SUSPEND,
 			     dev_name(dev->dev), dev);
-	if (r) {
+	if (ret) {
 		dev_err(dev->dev, "failure requesting irq %i: %d\n",
-			dev->irq, r);
-		return r;
+			dev->irq, ret);
+		return ret;
 	}
 
 	/*
@@ -992,12 +992,12 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
 	 * registered I2C slaves that do I2C transfers in their probe.
 	 */
 	pm_runtime_get_noresume(dev->dev);
-	r = i2c_add_numbered_adapter(adap);
-	if (r)
-		dev_err(dev->dev, "failure adding adapter: %d\n", r);
+	ret = i2c_add_numbered_adapter(adap);
+	if (ret)
+		dev_err(dev->dev, "failure adding adapter: %d\n", ret);
 	pm_runtime_put_noidle(dev->dev);
 
-	return r;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(i2c_dw_probe);
 
drivers/i2c/busses/i2c-designware-core.h +1 -1
index c1db3a5a340f..1a010730be43 100644
@@ -48,7 +48,7 @@
  * @cmd_complete: tx completion indicator
  * @clk: input reference clock
  * @cmd_err: run time hadware error code
- * @msgs: points to an array of messages currently being transfered
+ * @msgs: points to an array of messages currently being transferred
  * @msgs_num: the number of elements in msgs
  * @msg_write_idx: the element index of the current tx message in the msgs
  *	array
drivers/i2c/busses/i2c-designware-platdrv.c +22 -20

86 lines not on this page · raw message

Signature · 1 line
2.11.0
#2 lore raw

PATCH RESEND v6 2/6 i2c: designware: refactoring of the i2c-designware

In reply to Luis Oliveira

- Factor out all _master() part of code from i2c-designware-core and i2c-designware-platdrv to separate functions.
- Standardize all code related with MASTER mode.
- I have to take off DW_IC_INTR_TX_EMPTY from DW_IC_INTR_DEFAULT_MASK because it is master specific.

The purpose of this is to prepare the controller to have is I2C MASTER flow in a separate driver. To do this first all the functions/definitions related to the MASTER flow were identified.

---
V5->v6
- Removed the __func__ of dev_dbg prints
- Fix i2c_dw_configure_master() to accept dw_i2c_dev *

 drivers/i2c/busses/i2c-designware-core.c    | 56 +++++++++++++++++------------
 drivers/i2c/busses/i2c-designware-platdrv.c | 31 +++++++++-------
 2 files changed, 52 insertions(+), 35 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +34 -22
index 46937865ef8f..8b1b61f06a3f 100644
@@ -87,10 +87,10 @@
 #define DW_IC_INTR_GEN_CALL	0x800
 
 #define DW_IC_INTR_DEFAULT_MASK		(DW_IC_INTR_RX_FULL | \
-					 DW_IC_INTR_TX_EMPTY | \
 					 DW_IC_INTR_TX_ABRT | \
 					 DW_IC_INTR_STOP_DET)
-
+#define DW_IC_INTR_MASTER_MASK		(DW_IC_INTR_DEFAULT_MASK | \
+					 DW_IC_INTR_TX_EMPTY)
 #define DW_IC_STATUS_ACTIVITY	0x1
 
 #define DW_IC_SDA_HOLD_RX_SHIFT		16
@@ -202,6 +202,16 @@ static void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset)
 	}
 }
 
+static void i2c_dw_configure_fifo_master(struct dw_i2c_dev *dev)
+{
+	/* Configure Tx/Rx FIFO threshold levels */
+	dw_writel(dev, dev->tx_fifo_depth / 2, DW_IC_TX_TL);
+	dw_writel(dev, 0, DW_IC_RX_TL);
+
+	/* Configure the I2C master */
+	dw_writel(dev, dev->master_cfg, DW_IC_CON);
+}
+
 static u32
 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
 {
@@ -440,13 +450,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 			"Hardware too old to adjust SDA hold time.\n");
 	}
 
-	/* Configure Tx/Rx FIFO threshold levels */
-	dw_writel(dev, dev->tx_fifo_depth / 2, DW_IC_TX_TL);
-	dw_writel(dev, 0, DW_IC_RX_TL);
-
-	/* Configure the I2C master */
-	dw_writel(dev, dev->master_cfg , DW_IC_CON);
-
+	i2c_dw_configure_fifo_master(dev);
 	i2c_dw_release_lock(dev);
 
 	return 0;
@@ -511,7 +515,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
 
 	/* Clear and enable interrupts */
 	dw_readl(dev, DW_IC_CLR_INTR);
-	dw_writel(dev, DW_IC_INTR_DEFAULT_MASK, DW_IC_INTR_MASK);
+	dw_writel(dev, DW_IC_INTR_MASTER_MASK, DW_IC_INTR_MASK);
 }
 
 /*
@@ -531,7 +535,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
 	u8 *buf = dev->tx_buf;
 	bool need_restart = false;
 
-	intr_mask = DW_IC_INTR_DEFAULT_MASK;
+	intr_mask = DW_IC_INTR_MASTER_MASK;
 
 	for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) {
 		u32 flags = msgs[dev->msg_write_idx].flags;
@@ -881,22 +885,14 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
 }
 
 /*
- * Interrupt service routine. This gets called whenever an I2C interrupt
+ * Interrupt service routine. This gets called whenever an I2C master interrupt
  * occurs.
  */
-static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
+static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)
 {
-	struct dw_i2c_dev *dev = dev_id;
-	u32 stat, enabled;
-
-	enabled = dw_readl(dev, DW_IC_ENABLE);
-	stat = dw_readl(dev, DW_IC_RAW_INTR_STAT);
-	dev_dbg(dev->dev, "%s: enabled=%#x stat=%#x\n", __func__, enabled, stat);
-	if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY))
-		return IRQ_NONE;
+	u32 stat;
 
 	stat = i2c_dw_read_clear_intrbits(dev);
-
 	if (stat & DW_IC_INTR_TX_ABRT) {
 		dev->cmd_err |= DW_IC_ERR_TX_ABRT;
 		dev->status = STATUS_IDLE;
@@ -931,6 +927,22 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
 		dw_writel(dev, stat, DW_IC_INTR_MASK);
 	}
 
+	return 0;
+}
+
+static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
+{
+	struct dw_i2c_dev *dev = dev_id;
+	u32 stat, enabled;
+
+	enabled = dw_readl(dev, DW_IC_ENABLE);
+	stat = dw_readl(dev, DW_IC_RAW_INTR_STAT);
+	dev_dbg(dev->dev, "enabled=%#x stat=%#x\n", enabled, stat);
+	if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY))
+		return IRQ_NONE;
+
+	i2c_dw_irq_handler_master(dev);
+
 	return IRQ_HANDLED;
 }
 
drivers/i2c/busses/i2c-designware-platdrv.c +18 -13
index 381f0c1058b4..206dea03b0d0 100644
@@ -140,6 +140,23 @@ static inline int dw_i2c_acpi_configure(struct platform_device *pdev)
 }
 #endif
 
+static void i2c_dw_configure_master(struct dw_i2c_dev *dev)
+{
+	dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
+			  DW_IC_CON_RESTART_EN;
+
+	switch (dev->clk_freq) {
+	case 100000:
+		dev->master_cfg |= DW_IC_CON_SPEED_STD;
+		break;
+	case 3400000:
+		dev->master_cfg |= DW_IC_CON_SPEED_HIGH;
+		break;
+	default:
+		dev->master_cfg |= DW_IC_CON_SPEED_FAST;
+	}
+}
+
 static int i2c_dw_plat_prepare_clk(struct dw_i2c_dev *i_dev, bool prepare)
 {
 	if (IS_ERR(i_dev->clk))
@@ -246,19 +263,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 
 	dev->functionality = I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY;
 
-	dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
-			  DW_IC_CON_RESTART_EN;
-
-	switch (dev->clk_freq) {
-	case 100000:
-		dev->master_cfg |= DW_IC_CON_SPEED_STD;
-		break;
-	case 3400000:
-		dev->master_cfg |= DW_IC_CON_SPEED_HIGH;
-		break;
-	default:
-		dev->master_cfg |= DW_IC_CON_SPEED_FAST;
-	}
+	i2c_dw_configure_master(dev);
 
 	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (!i2c_dw_plat_prepare_clk(dev, true)) {
Signature · 1 line
2.11.0
Acked-by on v6 2/6
#3 lore raw

Re: [RESEND PATCH v6 2/6] i2c: designware: refactoring of the i2c-designware

Quoted 12 lines · Luis Oliveira

- Factor out all _master() part of code from i2c-designware-core and i2c-designware-platdrv to separate functions.
- Standardize all code related with MASTER mode.
- I have to take off DW_IC_INTR_TX_EMPTY from DW_IC_INTR_DEFAULT_MASK because it is master specific.

The purpose of this is to prepare the controller to have is I2C MASTER flow in a separate driver. To do this first all the functions/definitions related to the MASTER flow were identified.

Quoted 9 lines

---
V5->v6
- Removed the __func__ of dev_dbg prints
- Fix i2c_dw_configure_master() to accept dw_i2c_dev *

 drivers/i2c/busses/i2c-designware-core.c    | 56 +++++++++++++++++------------
 drivers/i2c/busses/i2c-designware-platdrv.c | 31 +++++++++-------
 2 files changed, 52 insertions(+), 35 deletions(-)
#4 lore raw

PATCH RESEND v6 3/6 i2c: designware: MASTER mode as separated driver

In reply to Luis Oliveira

- The functions related to I2C master mode of operation were transformed in a single driver.
- Common definitions were moved to i2c-designware-core.h
- The i2c-designware-core is now only a library file, the functions associated are in a source file called i2c-designware-common and are used by both i2c-designware-master and i2c-designware-slave.
- To decrease noise in namespace common i2c_dw_*() functions are now using ops to keep them private.

Almost all of the "core" source is now part of the "master" source. The difference is the functions used by both modes and they are in the "common" source file.

---
V5->V6
- Now using ops

 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-designware-common.c         | 274 +++++++++++++++
 drivers/i2c/busses/i2c-designware-core.h           | 140 +++++++-
 ...c-designware-core.c => i2c-designware-master.c} | 367 +--------------------
 drivers/i2c/busses/i2c-designware-platdrv.c        |   6 +-
 5 files changed, 423 insertions(+), 365 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-common.c
 rename drivers/i2c/busses/{i2c-designware-core.c => i2c-designware-master.c} (64%)
drivers/i2c/busses/Makefile +1 -0
index a2c6ff558578..b7abbe167686 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_I2C_CBUS_GPIO)	+= i2c-cbus-gpio.o
 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
 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 new file +274 -0

274 lines not on this page · raw message

drivers/i2c/busses/i2c-designware-core.h +137 -3

158 lines not on this page · raw message

drivers/i2c/busses/i2c-designware-master.c renamed from drivers/i2c/busses/i2c-designware-core.c +8 -359

420 lines not on this page · raw message

drivers/i2c/busses/i2c-designware-platdrv.c +3 -3
index 206dea03b0d0..671bdc0fdb24 100644
@@ -307,7 +307,7 @@ static int dw_i2c_plat_remove(struct platform_device *pdev)
 
 	i2c_del_adapter(&dev->adapter);
 
-	i2c_dw_disable(dev);
+	dev->disable(dev);
 
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_put_sync(&pdev->dev);
@@ -347,7 +347,7 @@ static int dw_i2c_plat_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
 
-	i2c_dw_disable(i_dev);
+	dev->disable(i_dev);
 	i2c_dw_plat_prepare_clk(i_dev, false);
 
 	return 0;
@@ -361,7 +361,7 @@ static int dw_i2c_plat_resume(struct device *dev)
 	i2c_dw_plat_prepare_clk(i_dev, true);
 
 	if (!i_dev->pm_runtime_disabled)
-		i2c_dw_init(i_dev);
+		dev->init(i_dev);
 
 	return 0;
 }
Signature · 1 line
2.11.0
#5 lore raw

Re: [RESEND PATCH v6 3/6] i2c: designware: MASTER mode as separated driver

Quoted 28 lines · Luis Oliveira

- The functions related to I2C master mode of operation were transformed in a single driver.
- Common definitions were moved to i2c-designware-core.h
- The i2c-designware-core is now only a library file, the functions associated are in a source file called i2c-designware-common and are used by both i2c-designware-master and i2c-designware-slave.
- To decrease noise in namespace common i2c_dw_*() functions are now using ops to keep them private.

Almost all of the "core" source is now part of the "master" source. The difference is the functions used by both modes and they are in the "common" source file.

---
V5->V6
- Now using ops

 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-designware-common.c         | 274 +++++++++++++++
 drivers/i2c/busses/i2c-designware-core.h           | 140 +++++++-
 ...c-designware-core.c => i2c-designware-master.c} | 367 +--------------------
 drivers/i2c/busses/i2c-designware-platdrv.c        |   6 +-
 5 files changed, 423 insertions(+), 365 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-common.c
 rename drivers/i2c/busses/{i2c-designware-core.c => i2c-designware-master.c} (64%)

...

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 1a010730be43..35d7264d9e3a 100644
@@ -40,6 +40,124 @@

...

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 248

Quoted 9 lines

/**
* struct dw_i2c_dev - private i2c-designware data

drivers/i2c/busses/i2c-designware-core.h +3 -0
@@ -125,15 +243,31 @@ struct dw_i2c_dev {
 	int			(*acquire_lock)(struct dw_i2c_dev *dev);
 	void			(*release_lock)(struct dw_i2c_dev *dev);
 	bool			pm_runtime_disabled;
+	void			(*disable)(struct dw_i2c_dev *dev);
+	void			(*disable_int)(struct dw_i2c_dev *dev);
+	int			(*init)(struct dw_i2c_dev *dev);

Please move kernel doc comments for these members from patch 4/6 here. Adding new members and comments should go together.

Quoted 4 lines
drivers/i2c/busses/i2c-designware-platdrv.c +0 -0
index 206dea03b0d0..671bdc0fdb24 100644

...

drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_suspend(struct device *dev) · line 351

Quoted 7 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1 -1
@@ -347,7 +347,7 @@ static int dw_i2c_plat_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
 
-	i2c_dw_disable(i_dev);
+	dev->disable(i_dev);
 	i2c_dw_plat_prepare_clk(i_dev, false);

This doesn't compile. Looks like copy-paste from your dw_i2c_plat_remove() change but here you must access through the i_dev.

You need to convert also the i2c-designware-pcidrv.c.

Signature · 1 line
Jarkko
#6 lore raw

Re: [RESEND PATCH v6 3/6] i2c: designware: MASTER mode as separated driver

Quoted 38 lines · Jarkko Nikula
Quoted 29 lines · Luis Oliveira

- The functions related to I2C master mode of operation were transformed in a single driver.
- Common definitions were moved to i2c-designware-core.h
- The i2c-designware-core is now only a library file, the functions associated are in a source file called i2c-designware-common and are used by both i2c-designware-master and i2c-designware-slave.
- To decrease noise in namespace common i2c_dw_*() functions are now using ops to keep them private.

Almost all of the "core" source is now part of the "master" source. The difference is the functions used by both modes and they are in the "common" source file.

---
V5->V6
- Now using ops

 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-designware-common.c         | 274 +++++++++++++++
 drivers/i2c/busses/i2c-designware-core.h           | 140 +++++++-
 ...c-designware-core.c => i2c-designware-master.c} | 367 +--------------------
 drivers/i2c/busses/i2c-designware-platdrv.c        |   6 +-
 5 files changed, 423 insertions(+), 365 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-common.c
 rename drivers/i2c/busses/{i2c-designware-core.c => i2c-designware-master.c}

(64%)

...

Quoted 6 lines
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 1a010730be43..35d7264d9e3a 100644
@@ -40,6 +40,124 @@

...

Quoted 12 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 248

Quoted 9 lines

/**
* struct dw_i2c_dev - private i2c-designware data

drivers/i2c/busses/i2c-designware-core.h +3 -0
@@ -125,15 +243,31 @@ struct dw_i2c_dev {
     int            (*acquire_lock)(struct dw_i2c_dev *dev);
     void            (*release_lock)(struct dw_i2c_dev *dev);
     bool            pm_runtime_disabled;
+    void            (*disable)(struct dw_i2c_dev *dev);
+    void            (*disable_int)(struct dw_i2c_dev *dev);
+    int            (*init)(struct dw_i2c_dev *dev);

Please move kernel doc comments for these members from patch 4/6 here. Adding new members and comments should go together.

I will. Thanks

Quoted 11 lines
Quoted 6 lines
drivers/i2c/busses/i2c-designware-platdrv.c +0 -0
index 206dea03b0d0..671bdc0fdb24 100644

...

Quoted 4 lines
drivers/i2c/busses/i2c-designware-platdrv.c +0 -0
@@ -347,7 +347,7 @@ static int dw_i2c_plat_suspend(struct device *dev)
     struct platform_device *pdev = to_platform_device(dev);
     struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
 
Quoted 6 lines

drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_suspend(struct device *dev) · line 351

Quoted 3 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1 -1
-    i2c_dw_disable(i_dev);
+    dev->disable(i_dev);
     i2c_dw_plat_prepare_clk(i_dev, false);

This doesn't compile. Looks like copy-paste from your dw_i2c_plat_remove() change but here you must access through the i_dev.

It's true! sorry, I forgot to change the "i_dev". And with the CONFIG_PM not defined I didn't get the compile error.

Quoted 2 lines

You need to convert also the i2c-designware-pcidrv.c.

I will check that

Quoted 1 line
#7 lore raw

Re: [RESEND PATCH v6 3/6] i2c: designware: MASTER mode as separated driver

In reply to Luis Oliveira
reproduce:

Hi Luis,

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on next-20170302]
[cannot apply to v4.10]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Luis-Oliveira/i2c-designware-add-I2C-SLAVE-support/20170303-034755
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: x86_64-randconfig-x016-201709 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

drivers/i2c/busses/i2c-designware-platdrv.c: In function 'dw_i2c_plat_suspend':

>> drivers/i2c/busses/i2c-designware-platdrv.c:350:5: error: 'struct device' has no member named 'disable'
     dev->disable(i_dev);
        ^~
   drivers/i2c/busses/i2c-designware-platdrv.c: In function 'dw_i2c_plat_resume':
>> drivers/i2c/busses/i2c-designware-platdrv.c:364:6: error: 'struct device' has no member named 'init'
      dev->init(i_dev);
         ^~

vim +350 drivers/i2c/busses/i2c-designware-platdrv.c

344 #ifdef CONFIG_PM
345 static int dw_i2c_plat_suspend(struct device *dev)
346 {
347 struct platform_device *pdev = to_platform_device(dev);
348 struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
349

 > 350		dev->disable(i_dev);
   351		i2c_dw_plat_prepare_clk(i_dev, false);
   352	
   353		return 0;
   354	}
   355	
   356	static int dw_i2c_plat_resume(struct device *dev)
   357	{
   358		struct platform_device *pdev = to_platform_device(dev);
   359		struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
   360	
   361		i2c_dw_plat_prepare_clk(i_dev, true);
   362	
   363		if (!i_dev->pm_runtime_disabled)
 > 364			dev->init(i_dev);

365
366 return 0;
367 }

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#8 lore raw

Re: [RESEND PATCH v6 3/6] i2c: designware: MASTER mode as separated driver

In reply to Luis Oliveira
reproduce:

Hi Luis,

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on next-20170302]
[cannot apply to v4.10]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Luis-Oliveira/i2c-designware-add-I2C-SLAVE-support/20170303-034755
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: i386-randconfig-x0-03030046 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

>> ERROR: "i2c_dw_disable" [drivers/i2c/busses/i2c-designware-pci.ko] undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#9 lore raw

PATCH RESEND v6 4/6 i2c: designware: introducing I2C_SLAVE definitions

In reply to Luis Oliveira

- Definitions were added to core library
- A example was added to designware-core.txt Documentation that shows how the slave can be setup using DTS

SLAVE related definitions were added to the core of the controller.

---
V5->V6
- Included an example of use in the device tree binding document (with the RESEND)
- Removed the i2c-designware.txt binding leading 0 to add the Rob Herring ack.

 .../devicetree/bindings/i2c/i2c-designware.txt     | 16 +++++++++-
 drivers/i2c/busses/i2c-designware-core.h           | 35 ++++++++++++++++++++--
 2 files changed, 48 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-designware.txt +15 -1
index fee26dc3e858..fbb0a6d8b964 100644
@@ -20,7 +20,7 @@ Optional properties :
  - i2c-sda-falling-time-ns : should contain the SDA falling time in nanoseconds.
    This value which is by default 300ns is used to compute the tHIGH period.
 
-Example :
+Examples :
 
 	i2c@f0000 {
 		#address-cells = <1>;
@@ -43,3 +43,17 @@ Example :
 		i2c-sda-falling-time-ns = <300>;
 		i2c-scl-falling-time-ns = <300>;
 	};
+
+	i2c@1120000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <0x2000 0x100>;
+		clock-frequency = <400000>;
+		clocks = <&i2cclk>;
+		interrupts = <0>;
+
+		eeprom@64 {
+			compatible = "linux,slave-24c02";
+			reg = <0x40000064>;
+		};
+	};
drivers/i2c/busses/i2c-designware-core.h +33 -2
index 35d7264d9e3a..b620d76ffc8d 100644
@@ -1,5 +1,5 @@
 /*
- * Synopsys DesignWare I2C adapter driver (master only).
+ * Synopsys DesignWare I2C adapter driver.
  *
  * Based on the TI DAVINCI I2C adapter driver.
  *
@@ -36,15 +36,20 @@
 #define DW_IC_CON_SPEED_FAST		0x4
 #define DW_IC_CON_SPEED_HIGH		0x6
 #define DW_IC_CON_SPEED_MASK		0x6
+#define DW_IC_CON_10BITADDR_SLAVE		0x8
 #define DW_IC_CON_10BITADDR_MASTER	0x10
 #define DW_IC_CON_RESTART_EN		0x20
 #define DW_IC_CON_SLAVE_DISABLE		0x40
+#define DW_IC_CON_STOP_DET_IFADDRESSED		0x80
+#define DW_IC_CON_TX_EMPTY_CTRL		0x100
+#define DW_IC_CON_RX_FIFO_FULL_HLD_CTRL		0x200
 
 /*
  * Registers offset
  */
 #define DW_IC_CON		0x0
 #define DW_IC_TAR		0x4
+#define DW_IC_SAR		0x8
 #define DW_IC_DATA_CMD		0x10
 #define DW_IC_SS_SCL_HCNT	0x14
 #define DW_IC_SS_SCL_LCNT	0x18
@@ -75,6 +80,7 @@
 #define DW_IC_SDA_HOLD		0x7c
 #define DW_IC_TX_ABRT_SOURCE	0x80
 #define DW_IC_ENABLE_STATUS	0x9c
+#define DW_IC_CLR_RESTART_DET	0xa8
 #define DW_IC_COMP_PARAM_1	0xf4
 #define DW_IC_COMP_VERSION	0xf8
 #define DW_IC_SDA_HOLD_MIN_VERS	0x3131312A
@@ -93,15 +99,22 @@
 #define DW_IC_INTR_STOP_DET	0x200
 #define DW_IC_INTR_START_DET	0x400
 #define DW_IC_INTR_GEN_CALL	0x800
+#define DW_IC_INTR_RESTART_DET	0x1000
 
 #define DW_IC_INTR_DEFAULT_MASK		(DW_IC_INTR_RX_FULL | \
 					 DW_IC_INTR_TX_ABRT | \
 					 DW_IC_INTR_STOP_DET)
 #define DW_IC_INTR_MASTER_MASK		(DW_IC_INTR_DEFAULT_MASK | \
 					 DW_IC_INTR_TX_EMPTY)
+#define DW_IC_INTR_SLAVE_MASK		(DW_IC_INTR_DEFAULT_MASK | \
+					 DW_IC_INTR_RX_DONE | \
+					 DW_IC_INTR_RX_UNDER | \
+					 DW_IC_INTR_RD_REQ)
+
 #define DW_IC_STATUS_ACTIVITY		0x1
 #define DW_IC_STATUS_TFE		BIT(2)
 #define DW_IC_STATUS_MASTER_ACTIVITY	BIT(5)
+#define DW_IC_STATUS_SLAVE_ACTIVITY	BIT(6)
 
 #define DW_IC_SDA_HOLD_RX_SHIFT		16
 #define DW_IC_SDA_HOLD_RX_MASK		GENMASK(23, DW_IC_SDA_HOLD_RX_SHIFT)
@@ -123,6 +136,12 @@
 #define TIMEOUT			20 /* ms */
 
 /*
+ * operation modes
+ */
+#define DW_IC_MASTER		0
+#define DW_IC_SLAVE		1
+
+/*
  * hardware abort codes from the DW_IC_TX_ABRT_SOURCE register
  *
  * only expected abort codes are listed here
@@ -139,6 +158,9 @@
 #define ABRT_10B_RD_NORSTRT	10
 #define ABRT_MASTER_DIS		11
 #define ARB_LOST		12
+#define ABRT_SLAVE_FLUSH_TXFIFO	13
+#define ABRT_SLAVE_ARBLOST	14
+#define ABRT_SLAVE_RD_INTX	15
 
 #define DW_IC_TX_ABRT_7B_ADDR_NOACK	(1UL << ABRT_7B_ADDR_NOACK)
 #define DW_IC_TX_ABRT_10ADDR1_NOACK	(1UL << ABRT_10ADDR1_NOACK)
@@ -151,6 +173,9 @@
 #define DW_IC_TX_ABRT_10B_RD_NORSTRT	(1UL << ABRT_10B_RD_NORSTRT)
 #define DW_IC_TX_ABRT_MASTER_DIS	(1UL << ABRT_MASTER_DIS)
 #define DW_IC_TX_ARB_LOST		(1UL << ARB_LOST)
+#define DW_IC_RX_ABRT_SLAVE_RD_INTX	(1UL << ABRT_SLAVE_RD_INTX)
+#define DW_IC_RX_ABRT_SLAVE_ARBLOST	(1UL << ABRT_SLAVE_ARBLOST)
+#define DW_IC_RX_ABRT_SLAVE_FLUSH_TXFIFO	(1UL << ABRT_SLAVE_FLUSH_TXFIFO)
 
 #define DW_IC_TX_ABRT_NOACK		(DW_IC_TX_ABRT_7B_ADDR_NOACK | \
 					 DW_IC_TX_ABRT_10ADDR1_NOACK | \
@@ -196,7 +221,11 @@
  * @acquire_lock: function to acquire a hardware lock on the bus
  * @release_lock: function to release a hardware lock on the bus
  * @pm_runtime_disabled: true if pm runtime is disabled
- *
+ * @dynamic_tar_update_enabled: true if dynamic TAR update is enabled
+ * @disable: function to disable the controller
+ * @disable_int: function to disable all interrupts
+ * @init: function to initialize the I2C hardware
+ * @mode: operation mode - I2C slave or I2C master
  * 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.
  * Leave them to be %0 if not used.
@@ -206,6 +235,7 @@ struct dw_i2c_dev {
 	void __iomem		*base;
 	struct completion	cmd_complete;
 	struct clk		*clk;
+	struct i2c_client		*slave;
 	u32			(*get_clk_rate_khz) (struct dw_i2c_dev *dev);
 	struct dw_pci_controller *controller;
 	int			cmd_err;
@@ -225,6 +255,7 @@ struct dw_i2c_dev {
 	struct i2c_adapter	adapter;
 	u32			functionality;
 	u32			master_cfg;
+	u32			slave_cfg;
 	unsigned int		tx_fifo_depth;
 	unsigned int		rx_fifo_depth;
 	int			rx_outstanding;
Signature · 1 line
2.11.0
#10 lore raw

Re: [RESEND PATCH v6 4/6] i2c: designware: introducing I2C_SLAVE definitions

Quoted 20 lines · Luis Oliveira

- Definitions were added to core library
- A example was added to designware-core.txt Documentation that shows how the slave can be setup using DTS

SLAVE related definitions were added to the core of the controller.

---
V5->V6
- Included an example of use in the device tree binding document (with the RESEND)
- Removed the i2c-designware.txt binding leading 0 to add the Rob Herring ack.

 .../devicetree/bindings/i2c/i2c-designware.txt     | 16 +++++++++-
 drivers/i2c/busses/i2c-designware-core.h           | 35 ++++++++++++++++++++--
 2 files changed, 48 insertions(+), 3 deletions(-)

...

Quoted 5 lines
drivers/i2c/busses/i2c-designware-core.h +0 -0
index 35d7264d9e3a..b620d76ffc8d 100644
@@ -1,5 +1,5 @@

...

Quoted 22 lines
drivers/i2c/busses/i2c-designware-core.h +6 -1
@@ -196,7 +221,11 @@
  * @acquire_lock: function to acquire a hardware lock on the bus
  * @release_lock: function to release a hardware lock on the bus
  * @pm_runtime_disabled: true if pm runtime is disabled
- *
+ * @dynamic_tar_update_enabled: true if dynamic TAR update is enabled
+ * @disable: function to disable the controller
+ * @disable_int: function to disable all interrupts
+ * @init: function to initialize the I2C hardware
+ * @mode: operation mode - I2C slave or I2C master
  * 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.
  * Leave them to be %0 if not used.
@@ -206,6 +235,7 @@ struct dw_i2c_dev {
 	void __iomem		*base;
 	struct completion	cmd_complete;
 	struct clk		*clk;
+	struct i2c_client		*slave;
 	u32			(*get_clk_rate_khz) (struct dw_i2c_dev *dev);
 	struct dw_pci_controller *controller;
 	int			cmd_err;

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 261

Quoted 7 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -225,6 +255,7 @@ struct dw_i2c_dev {
 	struct i2c_adapter	adapter;
 	u32			functionality;
 	u32			master_cfg;
+	u32			slave_cfg;
 	unsigned int		tx_fifo_depth;
 	unsigned int		rx_fifo_depth;
 	int			rx_outstanding;

You should add comments for "slave" and "slave_cfg" since they are added here and move comments for other members variables to patches 3/6 and 5/6 where they are added.

Signature · 1 line
Jarkko
#11 lore raw

PATCH RESEND v6 5/6 i2c: designware: add SLAVE mode functions

In reply to 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.

---
V5->V6
- Enable Slave mode using a different option (kbuild reported an error)
- Identation fixes needed
- Changed debug prints to dev_vdbg
- Fixed slave enumeration

 drivers/i2c/busses/Kconfig                 |  14 +-
 drivers/i2c/busses/Makefile                |   1 +
 drivers/i2c/busses/i2c-designware-common.c |   7 +
 drivers/i2c/busses/i2c-designware-core.h   |   3 +
 drivers/i2c/busses/i2c-designware-slave.c  | 403 +++++++++++++++++++++++++++++
 5 files changed, 427 insertions(+), 1 deletion(-)
 create mode 100644 drivers/i2c/busses/i2c-designware-slave.c
drivers/i2c/busses/Kconfig +13 -1
index c64221d143ff..b3d37ac9f5f6 100644
@@ -474,11 +474,23 @@ config I2C_DESIGNWARE_PLATFORM
 	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
+	select I2C_SLAVE_EEPROM
+	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 +1 -0
index b7abbe167686..477104e2a58f 100644
@@ -41,6 +41,7 @@ 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
+i2c-designware-core-$(CONFIG_I2C_DESIGNWARE_SLAVE) += i2c-designware-slave.o
 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 +7 -0
index 6357c7c78f6d..24641635aa20 100644
@@ -56,6 +56,13 @@ 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] =
+		"slave request for data to be transmitted and there is a 1 in "
+		"bit 8 of IC_DATA_CMD",
 };
 
 u32 dw_readl(struct dw_i2c_dev *dev, int offset)
drivers/i2c/busses/i2c-designware-core.h +3 -0
index b620d76ffc8d..6c70945cccea 100644
@@ -277,6 +277,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);
+	bool			mode;
 };
 
 #define ACCESS_SWAP		0x00000001
@@ -298,9 +299,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_eval_lock_support(struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-slave.c new file +403 -0

403 lines not on this page · raw message

Signature · 7 lines
2.11.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
#12 lore raw

Re: [RESEND PATCH v6 5/6] i2c: designware: add SLAVE mode functions

Quoted 26 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.

---
V5->V6
- Enable Slave mode using a different option (kbuild reported an error)
- Identation fixes needed
- Changed debug prints to dev_vdbg
- Fixed slave enumeration

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

...

Quoted 6 lines
drivers/i2c/busses/i2c-designware-common.c +0 -0
index 6357c7c78f6d..24641635aa20 100644
@@ -56,6 +56,13 @@ static char *abort_sources[] = {
 		"trying to use disabled adapter",

drivers/i2c/busses/i2c-designware-common.c static char *abort_sources[] = { · line 66

Quoted 10 lines
drivers/i2c/busses/i2c-designware-common.c +7 -0
 	[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] =
+		"slave request for data to be transmitted and there is a 1 in "
+		"bit 8 of IC_DATA_CMD",
 };

I know ABRT_SLAVE_RD_INTX case is from the specification but I would prefer here one-line error text so it will be easier to grep from sources.

I would like it to be also be more understandable. I don't know did I understood it correctly but does it occur when attempting to read controller while transmitting or something like that?

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 282

Quoted 11 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
index b620d76ffc8d..6c70945cccea 100644
@@ -277,6 +277,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);
+	bool			mode;
 };
 

As I mentioned add here comment for "mode" not in patch 4/6.

Signature · 5 lines
Jarkko
--
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
#13 lore raw

Re: [RESEND PATCH v6 5/6] i2c: designware: add SLAVE mode functions

Quoted 49 lines · Jarkko Nikula
Quoted 26 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.

---
V5->V6
- Enable Slave mode using a different option (kbuild reported an error)
- Identation fixes needed
- Changed debug prints to dev_vdbg
- Fixed slave enumeration

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

...

Quoted 7 lines
drivers/i2c/busses/i2c-designware-common.c +0 -0
index 6357c7c78f6d..24641635aa20 100644
@@ -56,6 +56,13 @@ static char *abort_sources[] = {
         "trying to use disabled adapter",

drivers/i2c/busses/i2c-designware-common.c static char *abort_sources[] = { · line 66

Quoted 10 lines
drivers/i2c/busses/i2c-designware-common.c +7 -0
     [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] =
+        "slave request for data to be transmitted and there is a 1 in "
+        "bit 8 of IC_DATA_CMD",
 };

I know ABRT_SLAVE_RD_INTX case is from the specification but I would prefer here one-line error text so it will be easier to grep from sources.

Quoted 3 lines

I would like it to be also be more understandable. I don't know did I understood it correctly but does it occur when attempting to read controller while transmitting or something like that?

It happens in the "slave-transmitter" mode, when the processor side responds to a request for data to be transmitted and at the same time someone writes 1 to the bit 8 of the IC_DATA_CMD. This bit in "slave-transmitter" mode has to be "0" to indicate the data is to be transmitted.

In "slave-receiver" mode it has no purpose since writes to this register are not required.

Quoted 16 lines

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 282

Quoted 13 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
index b620d76ffc8d..6c70945cccea 100644
@@ -277,6 +277,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);
+    bool            mode;
 };
 

As I mentioned add here comment for "mode" not in patch 4/6.

Ok, I will.
Thanks.

#14 lore raw

Re: [RESEND PATCH v6 5/6] i2c: designware: add SLAVE mode functions

Quoted 54 lines · Luis Oliveira
Quoted 49 lines · Jarkko Nikula
Quoted 26 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.

---
V5->V6
- Enable Slave mode using a different option (kbuild reported an error)
- Identation fixes needed
- Changed debug prints to dev_vdbg
- Fixed slave enumeration

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

...

Quoted 7 lines
drivers/i2c/busses/i2c-designware-common.c +0 -0
index 6357c7c78f6d..24641635aa20 100644
@@ -56,6 +56,13 @@ static char *abort_sources[] = {
         "trying to use disabled adapter",

drivers/i2c/busses/i2c-designware-common.c static char *abort_sources[] = { · line 66

Quoted 10 lines
drivers/i2c/busses/i2c-designware-common.c +7 -0
     [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] =
+        "slave request for data to be transmitted and there is a 1 in "
+        "bit 8 of IC_DATA_CMD",
 };

I know ABRT_SLAVE_RD_INTX case is from the specification but I would prefer here one-line error text so it will be easier to grep from sources.

Quoted 3 lines

I would like it to be also be more understandable. I don't know did I understood it correctly but does it occur when attempting to read controller while transmitting or something like that?

Quoted 7 lines

It happens in the "slave-transmitter" mode, when the processor side responds to a request for data to be transmitted and at the same time someone writes 1 to the bit 8 of the IC_DATA_CMD. This bit in "slave-transmitter" mode has to be "0" to indicate the data is to be transmitted.

In "slave-receiver" mode it has no purpose since writes to this register are not required.

If you agree for the v7 I can change it to "incorrect slave-transmitter mode configuration", it's not as clear but it gives a clue of where the error comes from.

Quoted 20 lines
Quoted 17 lines
Quoted 8 lines
drivers/i2c/busses/i2c-designware-core.h +0 -0
index b620d76ffc8d..6c70945cccea 100644

drivers/i2c/busses/i2c-designware-core.h struct dw_i2c_dev { · line 282

Quoted 6 lines
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -277,6 +277,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);
+    bool            mode;
 };
 

As I mentioned add here comment for "mode" not in patch 4/6.

Ok, I will.
Thanks.

#15 lore raw

Re: [RESEND PATCH v6 5/6] i2c: designware: add SLAVE mode functions

Quoted 60 lines · Luis Oliveira
Quoted 59 lines · Luis Oliveira
Quoted 49 lines · Jarkko Nikula
Quoted 26 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.

---
V5->V6
- Enable Slave mode using a different option (kbuild reported an error)
- Identation fixes needed
- Changed debug prints to dev_vdbg
- Fixed slave enumeration

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

...

Quoted 7 lines
drivers/i2c/busses/i2c-designware-common.c +0 -0
index 6357c7c78f6d..24641635aa20 100644
@@ -56,6 +56,13 @@ static char *abort_sources[] = {
         "trying to use disabled adapter",

drivers/i2c/busses/i2c-designware-common.c static char *abort_sources[] = { · line 66

Quoted 10 lines
drivers/i2c/busses/i2c-designware-common.c +7 -0
     [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] =
+        "slave request for data to be transmitted and there is a 1 in "
+        "bit 8 of IC_DATA_CMD",
 };

I know ABRT_SLAVE_RD_INTX case is from the specification but I would prefer here one-line error text so it will be easier to grep from sources.

Quoted 3 lines

I would like it to be also be more understandable. I don't know did I understood it correctly but does it occur when attempting to read controller while transmitting or something like that?

It happens in the "slave-transmitter" mode, when the processor side responds to a request for data to be transmitted and at the same time someone writes 1 to the bit 8 of the IC_DATA_CMD. This bit in "slave-transmitter" mode has to be "0" to indicate the data is to be transmitted.

Quoted 6 lines
Quoted 2 lines

In "slave-receiver" mode it has no purpose since writes to this register are not required.

If you agree for the v7 I can change it to "incorrect slave-transmitter mode configuration", it's not as clear but it gives a clue of where the error comes from.

I'm fine with it. I think it's more understandable.

Signature · 5 lines
Jarkko
--
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
#16 lore raw

PATCH RESEND v6 6/6 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.

---
V5->V6
- No changes

 drivers/i2c/busses/Kconfig                  |  1 +
 drivers/i2c/busses/i2c-designware-platdrv.c | 41 +++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 5 deletions(-)
drivers/i2c/busses/Kconfig +1 -0
index b3d37ac9f5f6..13bd932c81f7 100644
@@ -484,6 +484,7 @@ config I2C_DESIGNWARE_SLAVE
 	select I2C_SLAVE
 	select I2C_SLAVE_EEPROM
 	depends on I2C_DESIGNWARE_PLATFORM
+	default y
 	help
 	  If you say yes to this option, support will be included for the
 	  Synopsys DesignWare I2C slave adapter.
drivers/i2c/busses/i2c-designware-platdrv.c +36 -5

72 lines not on this page · raw message

Signature · 7 lines
2.11.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