All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01  1:13 ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: kernel-bIcnvbaLZ9MEGnE8C9+IrQ
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ, w.sang-bIcnvbaLZ9MEGnE8C9+IrQ,
	Richard Zhao

After START/RESTART, wait for busy bit to be set and
after STOP, wait for busy bit to be clear.

Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 4afba3e..156cc95 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -125,14 +125,19 @@ struct imx_i2c_struct {
 /** Functions for IMX I2C adapter driver ***************************************
 *******************************************************************************/
 
-static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
+static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 {
 	unsigned long orig_jiffies = jiffies;
+	unsigned int temp;
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
-	/* wait for bus not busy */
-	while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
+	temp = readb(i2c_imx->base + IMX_I2C_I2SR);
+	while (1) {
+		if (for_busy && (temp & I2SR_IBB))
+			break;
+		if (!for_busy && !(temp & I2SR_IBB))
+			break;
 		if (signal_pending(current)) {
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> I2C Interrupted\n", __func__);
@@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
 			return -EIO;
 		}
 		schedule();
+		temp = readb(i2c_imx->base + IMX_I2C_I2SR);
 	}
 
 	return 0;
@@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
 	return 0;
 }
 
-static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
+static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
 {
 	unsigned int temp = 0;
+	int result;
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
 	/* Enable I2C controller */
+	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
+
+	result = i2c_imx_bus_busy(i2c_imx, 0);
+	if (result)
+		return result;
+
 	/* Start I2C transaction */
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 	temp |= I2CR_MSTA;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+	result = i2c_imx_bus_busy(i2c_imx, 1);
+	if (result)
+		return result;
+
 	temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+	return result;
 }
 
 static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
@@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
 	/* Stop I2C transaction */
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
-	temp &= ~I2CR_MSTA;
+	temp &= ~(I2CR_MSTA | I2CR_MTX);
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
-	/* setup chip registers to defaults */
-	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
-	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	/*
 	 * This delay caused by an i.MXL hardware bug.
 	 * If no (or too short) delay, no "STOP" bit will be generated.
 	 */
 	udelay(i2c_imx->disable_delay);
+
+	i2c_imx_bus_busy(i2c_imx, 0);
+
 	/* Disable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
 }
@@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> clear MSTA\n", __func__);
 			temp = readb(i2c_imx->base + IMX_I2C_I2CR);
-			temp &= ~I2CR_MSTA;
+			temp &= ~(I2CR_MSTA | I2CR_MTX);
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 		} else if (i == (msgs->len - 2)) {
 			dev_dbg(&i2c_imx->adapter.dev,
@@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
-	/* Check if i2c bus is not busy */
-	result = i2c_imx_bus_busy(i2c_imx);
+	/* Start I2C transfer */
+	result = i2c_imx_start(i2c_imx);
 	if (result)
 		goto fail0;
 
-	/* Start I2C transfer */
-	i2c_imx_start(i2c_imx);
-
 	/* read/write data */
 	for (i = 0; i < num; i++) {
 		if (i) {
@@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 			temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 			temp |= I2CR_RSTA;
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+			result =  i2c_imx_bus_busy(i2c_imx, 1);
+			if (result)
+				goto fail0;
 		}
 		dev_dbg(&i2c_imx->adapter.dev,
 			"<%s> transfer message: %d\n", __func__, i);
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01  1:13 ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: linux-arm-kernel

After START/RESTART, wait for busy bit to be set and
after STOP, wait for busy bit to be clear.

Signed-off-by: Richard Zhao <linuxzsc@gmail.com>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 4afba3e..156cc95 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -125,14 +125,19 @@ struct imx_i2c_struct {
 /** Functions for IMX I2C adapter driver ***************************************
 *******************************************************************************/
 
-static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
+static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 {
 	unsigned long orig_jiffies = jiffies;
+	unsigned int temp;
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
-	/* wait for bus not busy */
-	while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
+	temp = readb(i2c_imx->base + IMX_I2C_I2SR);
+	while (1) {
+		if (for_busy && (temp & I2SR_IBB))
+			break;
+		if (!for_busy && !(temp & I2SR_IBB))
+			break;
 		if (signal_pending(current)) {
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> I2C Interrupted\n", __func__);
@@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
 			return -EIO;
 		}
 		schedule();
+		temp = readb(i2c_imx->base + IMX_I2C_I2SR);
 	}
 
 	return 0;
@@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
 	return 0;
 }
 
-static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
+static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
 {
 	unsigned int temp = 0;
+	int result;
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
 	/* Enable I2C controller */
+	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
+
+	result = i2c_imx_bus_busy(i2c_imx, 0);
+	if (result)
+		return result;
+
 	/* Start I2C transaction */
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 	temp |= I2CR_MSTA;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+	result = i2c_imx_bus_busy(i2c_imx, 1);
+	if (result)
+		return result;
+
 	temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+	return result;
 }
 
 static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
@@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
 	/* Stop I2C transaction */
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
-	temp &= ~I2CR_MSTA;
+	temp &= ~(I2CR_MSTA | I2CR_MTX);
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
-	/* setup chip registers to defaults */
-	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
-	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	/*
 	 * This delay caused by an i.MXL hardware bug.
 	 * If no (or too short) delay, no "STOP" bit will be generated.
 	 */
 	udelay(i2c_imx->disable_delay);
+
+	i2c_imx_bus_busy(i2c_imx, 0);
+
 	/* Disable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
 }
@@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> clear MSTA\n", __func__);
 			temp = readb(i2c_imx->base + IMX_I2C_I2CR);
-			temp &= ~I2CR_MSTA;
+			temp &= ~(I2CR_MSTA | I2CR_MTX);
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 		} else if (i == (msgs->len - 2)) {
 			dev_dbg(&i2c_imx->adapter.dev,
@@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
-	/* Check if i2c bus is not busy */
-	result = i2c_imx_bus_busy(i2c_imx);
+	/* Start I2C transfer */
+	result = i2c_imx_start(i2c_imx);
 	if (result)
 		goto fail0;
 
-	/* Start I2C transfer */
-	i2c_imx_start(i2c_imx);
-
 	/* read/write data */
 	for (i = 0; i < num; i++) {
 		if (i) {
@@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 			temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 			temp |= I2CR_RSTA;
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+			result =  i2c_imx_bus_busy(i2c_imx, 1);
+			if (result)
+				goto fail0;
 		}
 		dev_dbg(&i2c_imx->adapter.dev,
 			"<%s> transfer message: %d\n", __func__, i);
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH 2/4] i2c: imx: only imx1 needs disable delay
  2009-10-01  1:13 ` Richard Zhao
@ 2009-10-01  1:13     ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: kernel-bIcnvbaLZ9MEGnE8C9+IrQ
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ, w.sang-bIcnvbaLZ9MEGnE8C9+IrQ,
	Richard Zhao

check cpu_is_mx1() when set disable_delay.

Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 156cc95..c1e541c 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
 	/* Write divider value to register */
 	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
 
-	/*
-	 * There dummy delay is calculated.
-	 * It should be about one I2C clock period long.
-	 * This delay is used in I2C bus disable function
-	 * to fix chip hardware bug.
-	 */
-	i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
-		+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
+	if (cpu_is_mx1()) {
+		/*
+		 * There dummy delay is calculated.
+		 * It should be about one I2C clock period long.
+		 * This delay is used in I2C bus disable function
+		 * to fix chip hardware bug.
+		 */
+		i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
+			+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
+	}
 
 	/* dev_dbg() can't be used, because adapter is not yet registered */
 #ifdef CONFIG_I2C_DEBUG_BUS
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH 2/4] i2c: imx: only imx1 needs disable delay
@ 2009-10-01  1:13     ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: linux-arm-kernel

check cpu_is_mx1() when set disable_delay.

Signed-off-by: Richard Zhao <linuxzsc@gmail.com>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 156cc95..c1e541c 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
 	/* Write divider value to register */
 	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
 
-	/*
-	 * There dummy delay is calculated.
-	 * It should be about one I2C clock period long.
-	 * This delay is used in I2C bus disable function
-	 * to fix chip hardware bug.
-	 */
-	i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
-		+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
+	if (cpu_is_mx1()) {
+		/*
+		 * There dummy delay is calculated.
+		 * It should be about one I2C clock period long.
+		 * This delay is used in I2C bus disable function
+		 * to fix chip hardware bug.
+		 */
+		i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
+			+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
+	}
 
 	/* dev_dbg() can't be used, because adapter is not yet registered */
 #ifdef CONFIG_I2C_DEBUG_BUS
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
  2009-10-01  1:13     ` Richard Zhao
@ 2009-10-01  1:13         ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: kernel-bIcnvbaLZ9MEGnE8C9+IrQ
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ, w.sang-bIcnvbaLZ9MEGnE8C9+IrQ,
	Richard Zhao

When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
fail condition, and print i2c_msg to xfer.

Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index c1e541c..87faea4 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -125,6 +125,20 @@ struct imx_i2c_struct {
 /** Functions for IMX I2C adapter driver ***************************************
 *******************************************************************************/
 
+#ifdef CONFIG_I2C_DEBUG_BUS
+#define reg_dump(i2c_imx) \
+{ \
+	printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
+	printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
+		readb(i2c_imx->base + IMX_I2C_IADR), \
+		readb(i2c_imx->base + IMX_I2C_IFDR), \
+		readb(i2c_imx->base + IMX_I2C_I2CR), \
+		readb(i2c_imx->base + IMX_I2C_I2SR)); \
+}
+#else
+#define reg_dump(i2c_imx)
+#endif
+
 static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 {
 	unsigned long orig_jiffies = jiffies;
@@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 		if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> I2C bus is busy\n", __func__);
+			reg_dump(i2c_imx);
 			return -EIO;
 		}
 		schedule();
@@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
 
 	if (unlikely(result < 0)) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
+		reg_dump(i2c_imx);
 		return result;
 	} else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
+		reg_dump(i2c_imx);
 		return -ETIMEDOUT;
 	}
 	dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
@@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
 {
 	if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
+		reg_dump(i2c_imx);
 		return -EIO;  /* No ACK */
 	}
 
@@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
 	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
 
 	result = i2c_imx_bus_busy(i2c_imx, 0);
-	if (result)
+	if (result) {
+		reg_dump(i2c_imx);
 		return result;
+	}
 
 	/* Start I2C transaction */
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 	temp |= I2CR_MSTA;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 	result = i2c_imx_bus_busy(i2c_imx, 1);
-	if (result)
+	if (result) {
+		reg_dump(i2c_imx);
 		return result;
-
+	}
 	temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 	return result;
@@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
 	 */
 	udelay(i2c_imx->disable_delay);
 
-	i2c_imx_bus_busy(i2c_imx, 0);
+	if (i2c_imx_bus_busy(i2c_imx, 0))
+		reg_dump(i2c_imx);
 
 	/* Disable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
@@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 	struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
-
+#ifdef CONFIG_I2C_DEBUG_BUS
+	for (i = 0; i < num; i++) {
+		printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
+			msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
+		if (!(msgs[i].flags & I2C_M_RD)) {
+			int j;
+			for (j = 0; j < msgs[i].len; j++)
+				printk("%02x ", msgs[i].buf[j]);
+		}
+		printk("\n");
+	}
+#endif
 	/* Start I2C transfer */
 	result = i2c_imx_start(i2c_imx);
 	if (result)
@@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 			temp |= I2CR_RSTA;
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 			result =  i2c_imx_bus_busy(i2c_imx, 1);
-			if (result)
+			if (result) {
+				reg_dump(i2c_imx);
 				goto fail0;
+			}
 		}
 		dev_dbg(&i2c_imx->adapter.dev,
 			"<%s> transfer message: %d\n", __func__, i);
@@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 		res_size, i2c_imx->res->start);
 	dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
 		i2c_imx->adapter.name);
-	dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
+	dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
 
 	return 0;   /* Return OK */
 
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
@ 2009-10-01  1:13         ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: linux-arm-kernel

When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
fail condition, and print i2c_msg to xfer.

Signed-off-by: Richard Zhao <linuxzsc@gmail.com>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index c1e541c..87faea4 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -125,6 +125,20 @@ struct imx_i2c_struct {
 /** Functions for IMX I2C adapter driver ***************************************
 *******************************************************************************/
 
+#ifdef CONFIG_I2C_DEBUG_BUS
+#define reg_dump(i2c_imx) \
+{ \
+	printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
+	printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
+		readb(i2c_imx->base + IMX_I2C_IADR), \
+		readb(i2c_imx->base + IMX_I2C_IFDR), \
+		readb(i2c_imx->base + IMX_I2C_I2CR), \
+		readb(i2c_imx->base + IMX_I2C_I2SR)); \
+}
+#else
+#define reg_dump(i2c_imx)
+#endif
+
 static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 {
 	unsigned long orig_jiffies = jiffies;
@@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 		if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> I2C bus is busy\n", __func__);
+			reg_dump(i2c_imx);
 			return -EIO;
 		}
 		schedule();
@@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
 
 	if (unlikely(result < 0)) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
+		reg_dump(i2c_imx);
 		return result;
 	} else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
+		reg_dump(i2c_imx);
 		return -ETIMEDOUT;
 	}
 	dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
@@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
 {
 	if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
+		reg_dump(i2c_imx);
 		return -EIO;  /* No ACK */
 	}
 
@@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
 	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
 
 	result = i2c_imx_bus_busy(i2c_imx, 0);
-	if (result)
+	if (result) {
+		reg_dump(i2c_imx);
 		return result;
+	}
 
 	/* Start I2C transaction */
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 	temp |= I2CR_MSTA;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 	result = i2c_imx_bus_busy(i2c_imx, 1);
-	if (result)
+	if (result) {
+		reg_dump(i2c_imx);
 		return result;
-
+	}
 	temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 	return result;
@@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
 	 */
 	udelay(i2c_imx->disable_delay);
 
-	i2c_imx_bus_busy(i2c_imx, 0);
+	if (i2c_imx_bus_busy(i2c_imx, 0))
+		reg_dump(i2c_imx);
 
 	/* Disable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
@@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 	struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
-
+#ifdef CONFIG_I2C_DEBUG_BUS
+	for (i = 0; i < num; i++) {
+		printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
+			msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
+		if (!(msgs[i].flags & I2C_M_RD)) {
+			int j;
+			for (j = 0; j < msgs[i].len; j++)
+				printk("%02x ", msgs[i].buf[j]);
+		}
+		printk("\n");
+	}
+#endif
 	/* Start I2C transfer */
 	result = i2c_imx_start(i2c_imx);
 	if (result)
@@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 			temp |= I2CR_RSTA;
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 			result =  i2c_imx_bus_busy(i2c_imx, 1);
-			if (result)
+			if (result) {
+				reg_dump(i2c_imx);
 				goto fail0;
+			}
 		}
 		dev_dbg(&i2c_imx->adapter.dev,
 			"<%s> transfer message: %d\n", __func__, i);
@@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 		res_size, i2c_imx->res->start);
 	dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
 		i2c_imx->adapter.name);
-	dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
+	dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
 
 	return 0;   /* Return OK */
 
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
  2009-10-01  1:13         ` Richard Zhao
@ 2009-10-01  1:13             ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: kernel-bIcnvbaLZ9MEGnE8C9+IrQ
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ, w.sang-bIcnvbaLZ9MEGnE8C9+IrQ,
	Richard Zhao

Enable clock before START, disable it after STOP.

Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 87faea4..72ddea3 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -120,6 +120,7 @@ struct imx_i2c_struct {
 	wait_queue_head_t	queue;
 	unsigned long		i2csr;
 	unsigned int 		disable_delay;
+	unsigned int		ifdr; /* IMX_I2C_IFDR */
 };
 
 /** Functions for IMX I2C adapter driver ***************************************
@@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
+	clk_enable(i2c_imx->clk);
+	writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
 	/* Enable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
@@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
 
 	/* Disable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
+	clk_disable(i2c_imx->clk);
 }
 
 static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
@@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
 	else
 		for (i = 0; i2c_clk_div[i][0] < div; i++);
 
-	/* Write divider value to register */
-	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
+	/* Store divider value */
+	i2c_imx->ifdr = i2c_clk_div[i][1];
 
 	if (cpu_is_mx1()) {
 		/*
@@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "can't get I2C clock\n");
 		goto fail3;
 	}
-	clk_enable(i2c_imx->clk);
 
 	/* Request IRQ */
 	ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
@@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 fail5:
 	free_irq(i2c_imx->irq, i2c_imx);
 fail4:
-	clk_disable(i2c_imx->clk);
 	clk_put(i2c_imx->clk);
 fail3:
 	release_mem_region(i2c_imx->res->start, resource_size(res));
@@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
 	if (pdata && pdata->exit)
 		pdata->exit(&pdev->dev);
 
-	/* Disable I2C clock */
-	clk_disable(i2c_imx->clk);
 	clk_put(i2c_imx->clk);
 
 	release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
@ 2009-10-01  1:13             ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  1:13 UTC (permalink / raw)
  To: linux-arm-kernel

Enable clock before START, disable it after STOP.

Signed-off-by: Richard Zhao <linuxzsc@gmail.com>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 87faea4..72ddea3 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -120,6 +120,7 @@ struct imx_i2c_struct {
 	wait_queue_head_t	queue;
 	unsigned long		i2csr;
 	unsigned int 		disable_delay;
+	unsigned int		ifdr; /* IMX_I2C_IFDR */
 };
 
 /** Functions for IMX I2C adapter driver ***************************************
@@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
+	clk_enable(i2c_imx->clk);
+	writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
 	/* Enable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
@@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
 
 	/* Disable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
+	clk_disable(i2c_imx->clk);
 }
 
 static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
@@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
 	else
 		for (i = 0; i2c_clk_div[i][0] < div; i++);
 
-	/* Write divider value to register */
-	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
+	/* Store divider value */
+	i2c_imx->ifdr = i2c_clk_div[i][1];
 
 	if (cpu_is_mx1()) {
 		/*
@@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "can't get I2C clock\n");
 		goto fail3;
 	}
-	clk_enable(i2c_imx->clk);
 
 	/* Request IRQ */
 	ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
@@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
 fail5:
 	free_irq(i2c_imx->irq, i2c_imx);
 fail4:
-	clk_disable(i2c_imx->clk);
 	clk_put(i2c_imx->clk);
 fail3:
 	release_mem_region(i2c_imx->res->start, resource_size(res));
@@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
 	if (pdata && pdata->exit)
 		pdata->exit(&pdev->dev);
 
-	/* Disable I2C clock */
-	clk_disable(i2c_imx->clk);
 	clk_put(i2c_imx->clk);
 
 	release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

* Re: [PATCH 2/4] i2c: imx: only imx1 needs disable delay
  2009-10-01  1:13     ` Richard Zhao
@ 2009-10-01  7:26         ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:26 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 09:13:31AM +0800, Richard Zhao wrote:
> check cpu_is_mx1() when set disable_delay.
> 
> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 156cc95..c1e541c 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>  	/* Write divider value to register */
>  	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
>  
> -	/*
> -	 * There dummy delay is calculated.
> -	 * It should be about one I2C clock period long.
> -	 * This delay is used in I2C bus disable function
> -	 * to fix chip hardware bug.
> -	 */
> -	i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> -		+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> +	if (cpu_is_mx1()) {
> +		/*
> +		 * There dummy delay is calculated.
> +		 * It should be about one I2C clock period long.
> +		 * This delay is used in I2C bus disable function
> +		 * to fix chip hardware bug.
> +		 */
> +		i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> +			+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> +	}

I think you should put the udelay(i2c_imx->disable_delay) in
cpu_is_mx1() rather than the calculation.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 2/4] i2c: imx: only imx1 needs disable delay
@ 2009-10-01  7:26         ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 09:13:31AM +0800, Richard Zhao wrote:
> check cpu_is_mx1() when set disable_delay.
> 
> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 156cc95..c1e541c 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>  	/* Write divider value to register */
>  	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
>  
> -	/*
> -	 * There dummy delay is calculated.
> -	 * It should be about one I2C clock period long.
> -	 * This delay is used in I2C bus disable function
> -	 * to fix chip hardware bug.
> -	 */
> -	i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> -		+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> +	if (cpu_is_mx1()) {
> +		/*
> +		 * There dummy delay is calculated.
> +		 * It should be about one I2C clock period long.
> +		 * This delay is used in I2C bus disable function
> +		 * to fix chip hardware bug.
> +		 */
> +		i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> +			+ (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> +	}

I think you should put the udelay(i2c_imx->disable_delay) in
cpu_is_mx1() rather than the calculation.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
  2009-10-01  1:13         ` Richard Zhao
@ 2009-10-01  7:29             ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:29 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
> fail condition, and print i2c_msg to xfer.
> 
> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Honestly I don't think we need this. It makes the driver too verbose for
my taste.

Sascha


> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index c1e541c..87faea4 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
>  /** Functions for IMX I2C adapter driver ***************************************
>  *******************************************************************************/
>  
> +#ifdef CONFIG_I2C_DEBUG_BUS
> +#define reg_dump(i2c_imx) \
> +{ \
> +	printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
> +	printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
> +		readb(i2c_imx->base + IMX_I2C_IADR), \
> +		readb(i2c_imx->base + IMX_I2C_IFDR), \
> +		readb(i2c_imx->base + IMX_I2C_I2CR), \
> +		readb(i2c_imx->base + IMX_I2C_I2SR)); \
> +}
> +#else
> +#define reg_dump(i2c_imx)
> +#endif
> +
>  static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>  {
>  	unsigned long orig_jiffies = jiffies;
> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>  		if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
>  			dev_dbg(&i2c_imx->adapter.dev,
>  				"<%s> I2C bus is busy\n", __func__);
> +			reg_dump(i2c_imx);
>  			return -EIO;
>  		}
>  		schedule();
> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
>  
>  	if (unlikely(result < 0)) {
>  		dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
> +		reg_dump(i2c_imx);
>  		return result;
>  	} else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
>  		dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
> +		reg_dump(i2c_imx);
>  		return -ETIMEDOUT;
>  	}
>  	dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>  {
>  	if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
>  		dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
> +		reg_dump(i2c_imx);
>  		return -EIO;  /* No ACK */
>  	}
>  
> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>  	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>  
>  	result = i2c_imx_bus_busy(i2c_imx, 0);
> -	if (result)
> +	if (result) {
> +		reg_dump(i2c_imx);
>  		return result;
> +	}
>  
>  	/* Start I2C transaction */
>  	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>  	temp |= I2CR_MSTA;
>  	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>  	result = i2c_imx_bus_busy(i2c_imx, 1);
> -	if (result)
> +	if (result) {
> +		reg_dump(i2c_imx);
>  		return result;
> -
> +	}
>  	temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>  	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>  	return result;
> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>  	 */
>  	udelay(i2c_imx->disable_delay);
>  
> -	i2c_imx_bus_busy(i2c_imx, 0);
> +	if (i2c_imx_bus_busy(i2c_imx, 0))
> +		reg_dump(i2c_imx);
>  
>  	/* Disable I2C controller */
>  	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>  	struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>  
>  	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> -
> +#ifdef CONFIG_I2C_DEBUG_BUS
> +	for (i = 0; i < num; i++) {
> +		printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
> +			msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
> +		if (!(msgs[i].flags & I2C_M_RD)) {
> +			int j;
> +			for (j = 0; j < msgs[i].len; j++)
> +				printk("%02x ", msgs[i].buf[j]);
> +		}
> +		printk("\n");
> +	}
> +#endif
>  	/* Start I2C transfer */
>  	result = i2c_imx_start(i2c_imx);
>  	if (result)
> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>  			temp |= I2CR_RSTA;
>  			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>  			result =  i2c_imx_bus_busy(i2c_imx, 1);
> -			if (result)
> +			if (result) {
> +				reg_dump(i2c_imx);
>  				goto fail0;
> +			}
>  		}
>  		dev_dbg(&i2c_imx->adapter.dev,
>  			"<%s> transfer message: %d\n", __func__, i);
> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>  		res_size, i2c_imx->res->start);
>  	dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
>  		i2c_imx->adapter.name);
> -	dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
> +	dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>  
>  	return 0;   /* Return OK */
>  
> -- 
> 1.6.0.4
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
@ 2009-10-01  7:29             ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:29 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
> fail condition, and print i2c_msg to xfer.
> 
> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>

Honestly I don't think we need this. It makes the driver too verbose for
my taste.

Sascha


> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index c1e541c..87faea4 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
>  /** Functions for IMX I2C adapter driver ***************************************
>  *******************************************************************************/
>  
> +#ifdef CONFIG_I2C_DEBUG_BUS
> +#define reg_dump(i2c_imx) \
> +{ \
> +	printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
> +	printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
> +		readb(i2c_imx->base + IMX_I2C_IADR), \
> +		readb(i2c_imx->base + IMX_I2C_IFDR), \
> +		readb(i2c_imx->base + IMX_I2C_I2CR), \
> +		readb(i2c_imx->base + IMX_I2C_I2SR)); \
> +}
> +#else
> +#define reg_dump(i2c_imx)
> +#endif
> +
>  static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>  {
>  	unsigned long orig_jiffies = jiffies;
> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>  		if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
>  			dev_dbg(&i2c_imx->adapter.dev,
>  				"<%s> I2C bus is busy\n", __func__);
> +			reg_dump(i2c_imx);
>  			return -EIO;
>  		}
>  		schedule();
> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
>  
>  	if (unlikely(result < 0)) {
>  		dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
> +		reg_dump(i2c_imx);
>  		return result;
>  	} else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
>  		dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
> +		reg_dump(i2c_imx);
>  		return -ETIMEDOUT;
>  	}
>  	dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>  {
>  	if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
>  		dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
> +		reg_dump(i2c_imx);
>  		return -EIO;  /* No ACK */
>  	}
>  
> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>  	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>  
>  	result = i2c_imx_bus_busy(i2c_imx, 0);
> -	if (result)
> +	if (result) {
> +		reg_dump(i2c_imx);
>  		return result;
> +	}
>  
>  	/* Start I2C transaction */
>  	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>  	temp |= I2CR_MSTA;
>  	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>  	result = i2c_imx_bus_busy(i2c_imx, 1);
> -	if (result)
> +	if (result) {
> +		reg_dump(i2c_imx);
>  		return result;
> -
> +	}
>  	temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>  	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>  	return result;
> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>  	 */
>  	udelay(i2c_imx->disable_delay);
>  
> -	i2c_imx_bus_busy(i2c_imx, 0);
> +	if (i2c_imx_bus_busy(i2c_imx, 0))
> +		reg_dump(i2c_imx);
>  
>  	/* Disable I2C controller */
>  	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>  	struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>  
>  	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> -
> +#ifdef CONFIG_I2C_DEBUG_BUS
> +	for (i = 0; i < num; i++) {
> +		printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
> +			msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
> +		if (!(msgs[i].flags & I2C_M_RD)) {
> +			int j;
> +			for (j = 0; j < msgs[i].len; j++)
> +				printk("%02x ", msgs[i].buf[j]);
> +		}
> +		printk("\n");
> +	}
> +#endif
>  	/* Start I2C transfer */
>  	result = i2c_imx_start(i2c_imx);
>  	if (result)
> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>  			temp |= I2CR_RSTA;
>  			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>  			result =  i2c_imx_bus_busy(i2c_imx, 1);
> -			if (result)
> +			if (result) {
> +				reg_dump(i2c_imx);
>  				goto fail0;
> +			}
>  		}
>  		dev_dbg(&i2c_imx->adapter.dev,
>  			"<%s> transfer message: %d\n", __func__, i);
> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>  		res_size, i2c_imx->res->start);
>  	dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
>  		i2c_imx->adapter.name);
> -	dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
> +	dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>  
>  	return 0;   /* Return OK */
>  
> -- 
> 1.6.0.4
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
  2009-10-01  1:13             ` Richard Zhao
@ 2009-10-01  7:34                 ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:34 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 09:13:33AM +0800, Richard Zhao wrote:
> Enable clock before START, disable it after STOP.

The clk_diable/enable calls in suspend/resume should be removed also.

Sascha

> 
> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 87faea4..72ddea3 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -120,6 +120,7 @@ struct imx_i2c_struct {
>  	wait_queue_head_t	queue;
>  	unsigned long		i2csr;
>  	unsigned int 		disable_delay;
> +	unsigned int		ifdr; /* IMX_I2C_IFDR */
>  };
>  
>  /** Functions for IMX I2C adapter driver ***************************************
> @@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>  
>  	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>  
> +	clk_enable(i2c_imx->clk);
> +	writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
>  	/* Enable I2C controller */
>  	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>  	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> @@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>  
>  	/* Disable I2C controller */
>  	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> +	clk_disable(i2c_imx->clk);
>  }
>  
>  static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> @@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>  	else
>  		for (i = 0; i2c_clk_div[i][0] < div; i++);
>  
> -	/* Write divider value to register */
> -	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
> +	/* Store divider value */
> +	i2c_imx->ifdr = i2c_clk_div[i][1];
>  
>  	if (cpu_is_mx1()) {
>  		/*
> @@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>  		dev_err(&pdev->dev, "can't get I2C clock\n");
>  		goto fail3;
>  	}
> -	clk_enable(i2c_imx->clk);
>  
>  	/* Request IRQ */
>  	ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
> @@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>  fail5:
>  	free_irq(i2c_imx->irq, i2c_imx);
>  fail4:
> -	clk_disable(i2c_imx->clk);
>  	clk_put(i2c_imx->clk);
>  fail3:
>  	release_mem_region(i2c_imx->res->start, resource_size(res));
> @@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
>  	if (pdata && pdata->exit)
>  		pdata->exit(&pdev->dev);
>  
> -	/* Disable I2C clock */
> -	clk_disable(i2c_imx->clk);
>  	clk_put(i2c_imx->clk);
>  
>  	release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
> -- 
> 1.6.0.4
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
@ 2009-10-01  7:34                 ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 09:13:33AM +0800, Richard Zhao wrote:
> Enable clock before START, disable it after STOP.

The clk_diable/enable calls in suspend/resume should be removed also.

Sascha

> 
> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 87faea4..72ddea3 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -120,6 +120,7 @@ struct imx_i2c_struct {
>  	wait_queue_head_t	queue;
>  	unsigned long		i2csr;
>  	unsigned int 		disable_delay;
> +	unsigned int		ifdr; /* IMX_I2C_IFDR */
>  };
>  
>  /** Functions for IMX I2C adapter driver ***************************************
> @@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>  
>  	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>  
> +	clk_enable(i2c_imx->clk);
> +	writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
>  	/* Enable I2C controller */
>  	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>  	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> @@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>  
>  	/* Disable I2C controller */
>  	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> +	clk_disable(i2c_imx->clk);
>  }
>  
>  static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> @@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>  	else
>  		for (i = 0; i2c_clk_div[i][0] < div; i++);
>  
> -	/* Write divider value to register */
> -	writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
> +	/* Store divider value */
> +	i2c_imx->ifdr = i2c_clk_div[i][1];
>  
>  	if (cpu_is_mx1()) {
>  		/*
> @@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>  		dev_err(&pdev->dev, "can't get I2C clock\n");
>  		goto fail3;
>  	}
> -	clk_enable(i2c_imx->clk);
>  
>  	/* Request IRQ */
>  	ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
> @@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>  fail5:
>  	free_irq(i2c_imx->irq, i2c_imx);
>  fail4:
> -	clk_disable(i2c_imx->clk);
>  	clk_put(i2c_imx->clk);
>  fail3:
>  	release_mem_region(i2c_imx->res->start, resource_size(res));
> @@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
>  	if (pdata && pdata->exit)
>  		pdata->exit(&pdev->dev);
>  
> -	/* Disable I2C clock */
> -	clk_disable(i2c_imx->clk);
>  	clk_put(i2c_imx->clk);
>  
>  	release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
> -- 
> 1.6.0.4
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 2/4] i2c: imx: only imx1 needs disable delay
  2009-10-01  7:26         ` Sascha Hauer
@ 2009-10-01  7:52           ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  7:52 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: linux-arm-kernel, linux-i2c, kernel, w.sang

On Thu, Oct 1, 2009 at 3:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 09:13:31AM +0800, Richard Zhao wrote:
>> check cpu_is_mx1() when set disable_delay.
>>
>> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>>
>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> index 156cc95..c1e541c 100644
>> --- a/drivers/i2c/busses/i2c-imx.c
>> +++ b/drivers/i2c/busses/i2c-imx.c
>> @@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>>       /* Write divider value to register */
>>       writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
>>
>> -     /*
>> -      * There dummy delay is calculated.
>> -      * It should be about one I2C clock period long.
>> -      * This delay is used in I2C bus disable function
>> -      * to fix chip hardware bug.
>> -      */
>> -     i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
>> -             + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
>> +     if (cpu_is_mx1()) {
>> +             /*
>> +              * There dummy delay is calculated.
>> +              * It should be about one I2C clock period long.
>> +              * This delay is used in I2C bus disable function
>> +              * to fix chip hardware bug.
>> +              */
>> +             i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
>> +                     + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
>> +     }
>
> I think you should put the udelay(i2c_imx->disable_delay) in
> cpu_is_mx1() rather than the calculation.
>
> Sascha
>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>
Do you think udelay(0) wast any more time than if()?
And Could I get all you comments in a single patch loop?

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 2/4] i2c: imx: only imx1 needs disable delay
@ 2009-10-01  7:52           ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  7:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 3:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 09:13:31AM +0800, Richard Zhao wrote:
>> check cpu_is_mx1() when set disable_delay.
>>
>> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>>
>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> index 156cc95..c1e541c 100644
>> --- a/drivers/i2c/busses/i2c-imx.c
>> +++ b/drivers/i2c/busses/i2c-imx.c
>> @@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>> ? ? ? /* Write divider value to register */
>> ? ? ? writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
>>
>> - ? ? /*
>> - ? ? ?* There dummy delay is calculated.
>> - ? ? ?* It should be about one I2C clock period long.
>> - ? ? ?* This delay is used in I2C bus disable function
>> - ? ? ?* to fix chip hardware bug.
>> - ? ? ?*/
>> - ? ? i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
>> - ? ? ? ? ? ? + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
>> + ? ? if (cpu_is_mx1()) {
>> + ? ? ? ? ? ? /*
>> + ? ? ? ? ? ? ?* There dummy delay is calculated.
>> + ? ? ? ? ? ? ?* It should be about one I2C clock period long.
>> + ? ? ? ? ? ? ?* This delay is used in I2C bus disable function
>> + ? ? ? ? ? ? ?* to fix chip hardware bug.
>> + ? ? ? ? ? ? ?*/
>> + ? ? ? ? ? ? i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
>> + ? ? ? ? ? ? ? ? ? ? + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
>> + ? ? }
>
> I think you should put the udelay(i2c_imx->disable_delay) in
> cpu_is_mx1() rather than the calculation.
>
> Sascha
>
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>
Do you think udelay(0) wast any more time than if()?
And Could I get all you comments in a single patch loop?

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
  2009-10-01  7:34                 ` Sascha Hauer
@ 2009-10-01  7:56                     ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  7:56 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 1, 2009 at 3:34 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> On Thu, Oct 01, 2009 at 09:13:33AM +0800, Richard Zhao wrote:
>> Enable clock before START, disable it after STOP.
>
> The clk_diable/enable calls in suspend/resume should be removed also.
>
> Sascha
>
>>
>> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>>
>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> index 87faea4..72ddea3 100644
>> --- a/drivers/i2c/busses/i2c-imx.c
>> +++ b/drivers/i2c/busses/i2c-imx.c
>> @@ -120,6 +120,7 @@ struct imx_i2c_struct {
>>       wait_queue_head_t       queue;
>>       unsigned long           i2csr;
>>       unsigned int            disable_delay;
>> +     unsigned int            ifdr; /* IMX_I2C_IFDR */
>>  };
>>
>>  /** Functions for IMX I2C adapter driver ***************************************
>> @@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>>
>>       dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>>
>> +     clk_enable(i2c_imx->clk);
>> +     writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
>>       /* Enable I2C controller */
>>       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>>       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> @@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>>
>>       /* Disable I2C controller */
>>       writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> +     clk_disable(i2c_imx->clk);
>>  }
>>
>>  static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>> @@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>>       else
>>               for (i = 0; i2c_clk_div[i][0] < div; i++);
>>
>> -     /* Write divider value to register */
>> -     writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
>> +     /* Store divider value */
>> +     i2c_imx->ifdr = i2c_clk_div[i][1];
>>
>>       if (cpu_is_mx1()) {
>>               /*
>> @@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>>               dev_err(&pdev->dev, "can't get I2C clock\n");
>>               goto fail3;
>>       }
>> -     clk_enable(i2c_imx->clk);
>>
>>       /* Request IRQ */
>>       ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
>> @@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>>  fail5:
>>       free_irq(i2c_imx->irq, i2c_imx);
>>  fail4:
>> -     clk_disable(i2c_imx->clk);
>>       clk_put(i2c_imx->clk);
>>  fail3:
>>       release_mem_region(i2c_imx->res->start, resource_size(res));
>> @@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
>>       if (pdata && pdata->exit)
>>               pdata->exit(&pdev->dev);
>>
>> -     /* Disable I2C clock */
>> -     clk_disable(i2c_imx->clk);
>>       clk_put(i2c_imx->clk);
>>
>>       release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
>> --
>> 1.6.0.4
>>
>>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>

I don't think we have any suspend/resume routine. And we won't need it any more.

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
@ 2009-10-01  7:56                     ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  7:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 3:34 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 09:13:33AM +0800, Richard Zhao wrote:
>> Enable clock before START, disable it after STOP.
>
> The clk_diable/enable calls in suspend/resume should be removed also.
>
> Sascha
>
>>
>> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>>
>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> index 87faea4..72ddea3 100644
>> --- a/drivers/i2c/busses/i2c-imx.c
>> +++ b/drivers/i2c/busses/i2c-imx.c
>> @@ -120,6 +120,7 @@ struct imx_i2c_struct {
>> ? ? ? wait_queue_head_t ? ? ? queue;
>> ? ? ? unsigned long ? ? ? ? ? i2csr;
>> ? ? ? unsigned int ? ? ? ? ? ?disable_delay;
>> + ? ? unsigned int ? ? ? ? ? ?ifdr; /* IMX_I2C_IFDR */
>> ?};
>>
>> ?/** Functions for IMX I2C adapter driver ***************************************
>> @@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>>
>> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>>
>> + ? ? clk_enable(i2c_imx->clk);
>> + ? ? writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
>> ? ? ? /* Enable I2C controller */
>> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> @@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>>
>> ? ? ? /* Disable I2C controller */
>> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> + ? ? clk_disable(i2c_imx->clk);
>> ?}
>>
>> ?static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>> @@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>> ? ? ? else
>> ? ? ? ? ? ? ? for (i = 0; i2c_clk_div[i][0] < div; i++);
>>
>> - ? ? /* Write divider value to register */
>> - ? ? writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
>> + ? ? /* Store divider value */
>> + ? ? i2c_imx->ifdr = i2c_clk_div[i][1];
>>
>> ? ? ? if (cpu_is_mx1()) {
>> ? ? ? ? ? ? ? /*
>> @@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>> ? ? ? ? ? ? ? dev_err(&pdev->dev, "can't get I2C clock\n");
>> ? ? ? ? ? ? ? goto fail3;
>> ? ? ? }
>> - ? ? clk_enable(i2c_imx->clk);
>>
>> ? ? ? /* Request IRQ */
>> ? ? ? ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
>> @@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>> ?fail5:
>> ? ? ? free_irq(i2c_imx->irq, i2c_imx);
>> ?fail4:
>> - ? ? clk_disable(i2c_imx->clk);
>> ? ? ? clk_put(i2c_imx->clk);
>> ?fail3:
>> ? ? ? release_mem_region(i2c_imx->res->start, resource_size(res));
>> @@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
>> ? ? ? if (pdata && pdata->exit)
>> ? ? ? ? ? ? ? pdata->exit(&pdev->dev);
>>
>> - ? ? /* Disable I2C clock */
>> - ? ? clk_disable(i2c_imx->clk);
>> ? ? ? clk_put(i2c_imx->clk);
>>
>> ? ? ? release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
>> --
>> 1.6.0.4
>>
>>
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

I don't think we have any suspend/resume routine. And we won't need it any more.

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 2/4] i2c: imx: only imx1 needs disable delay
  2009-10-01  7:52           ` Richard Zhao
@ 2009-10-01  7:57               ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:57 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 03:52:15PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 3:26 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> > On Thu, Oct 01, 2009 at 09:13:31AM +0800, Richard Zhao wrote:
> >> check cpu_is_mx1() when set disable_delay.
> >>
> >> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >>
> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> index 156cc95..c1e541c 100644
> >> --- a/drivers/i2c/busses/i2c-imx.c
> >> +++ b/drivers/i2c/busses/i2c-imx.c
> >> @@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> >>       /* Write divider value to register */
> >>       writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
> >>
> >> -     /*
> >> -      * There dummy delay is calculated.
> >> -      * It should be about one I2C clock period long.
> >> -      * This delay is used in I2C bus disable function
> >> -      * to fix chip hardware bug.
> >> -      */
> >> -     i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> >> -             + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> >> +     if (cpu_is_mx1()) {
> >> +             /*
> >> +              * There dummy delay is calculated.
> >> +              * It should be about one I2C clock period long.
> >> +              * This delay is used in I2C bus disable function
> >> +              * to fix chip hardware bug.
> >> +              */
> >> +             i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> >> +                     + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> >> +     }
> >
> > I think you should put the udelay(i2c_imx->disable_delay) in
> > cpu_is_mx1() rather than the calculation.
> >
> > Sascha
> >
> >
> > --
> > Pengutronix e.K.                           |                             |
> > Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> >
> Do you think udelay(0) wast any more time than if()?

if (cpu_is_mx1()) is optimized out by the compiler.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 2/4] i2c: imx: only imx1 needs disable delay
@ 2009-10-01  7:57               ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  7:57 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 03:52:15PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 3:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > On Thu, Oct 01, 2009 at 09:13:31AM +0800, Richard Zhao wrote:
> >> check cpu_is_mx1() when set disable_delay.
> >>
> >> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
> >>
> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> index 156cc95..c1e541c 100644
> >> --- a/drivers/i2c/busses/i2c-imx.c
> >> +++ b/drivers/i2c/busses/i2c-imx.c
> >> @@ -254,14 +254,16 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> >> ? ? ? /* Write divider value to register */
> >> ? ? ? writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
> >>
> >> - ? ? /*
> >> - ? ? ?* There dummy delay is calculated.
> >> - ? ? ?* It should be about one I2C clock period long.
> >> - ? ? ?* This delay is used in I2C bus disable function
> >> - ? ? ?* to fix chip hardware bug.
> >> - ? ? ?*/
> >> - ? ? i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> >> - ? ? ? ? ? ? + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> >> + ? ? if (cpu_is_mx1()) {
> >> + ? ? ? ? ? ? /*
> >> + ? ? ? ? ? ? ?* There dummy delay is calculated.
> >> + ? ? ? ? ? ? ?* It should be about one I2C clock period long.
> >> + ? ? ? ? ? ? ?* This delay is used in I2C bus disable function
> >> + ? ? ? ? ? ? ?* to fix chip hardware bug.
> >> + ? ? ? ? ? ? ?*/
> >> + ? ? ? ? ? ? i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0]
> >> + ? ? ? ? ? ? ? ? ? ? + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
> >> + ? ? }
> >
> > I think you should put the udelay(i2c_imx->disable_delay) in
> > cpu_is_mx1() rather than the calculation.
> >
> > Sascha
> >
> >
> > --
> > Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> > Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> > Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
> >
> Do you think udelay(0) wast any more time than if()?

if (cpu_is_mx1()) is optimized out by the compiler.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
  2009-10-01  7:56                     ` Richard Zhao
@ 2009-10-01  8:00                         ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  8:00 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 03:56:29PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 3:34 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> > On Thu, Oct 01, 2009 at 09:13:33AM +0800, Richard Zhao wrote:
> >> Enable clock before START, disable it after STOP.
> >
> > The clk_diable/enable calls in suspend/resume should be removed also.
> >
> > Sascha
> >
> >>
> >> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >>
> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> index 87faea4..72ddea3 100644
> >> --- a/drivers/i2c/busses/i2c-imx.c
> >> +++ b/drivers/i2c/busses/i2c-imx.c
> >> @@ -120,6 +120,7 @@ struct imx_i2c_struct {
> >>       wait_queue_head_t       queue;
> >>       unsigned long           i2csr;
> >>       unsigned int            disable_delay;
> >> +     unsigned int            ifdr; /* IMX_I2C_IFDR */
> >>  };
> >>
> >>  /** Functions for IMX I2C adapter driver ***************************************
> >> @@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >>
> >>       dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >>
> >> +     clk_enable(i2c_imx->clk);
> >> +     writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
> >>       /* Enable I2C controller */
> >>       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >>       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >> @@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >>
> >>       /* Disable I2C controller */
> >>       writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> >> +     clk_disable(i2c_imx->clk);
> >>  }
> >>
> >>  static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> >> @@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> >>       else
> >>               for (i = 0; i2c_clk_div[i][0] < div; i++);
> >>
> >> -     /* Write divider value to register */
> >> -     writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
> >> +     /* Store divider value */
> >> +     i2c_imx->ifdr = i2c_clk_div[i][1];
> >>
> >>       if (cpu_is_mx1()) {
> >>               /*
> >> @@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
> >>               dev_err(&pdev->dev, "can't get I2C clock\n");
> >>               goto fail3;
> >>       }
> >> -     clk_enable(i2c_imx->clk);
> >>
> >>       /* Request IRQ */
> >>       ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
> >> @@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
> >>  fail5:
> >>       free_irq(i2c_imx->irq, i2c_imx);
> >>  fail4:
> >> -     clk_disable(i2c_imx->clk);
> >>       clk_put(i2c_imx->clk);
> >>  fail3:
> >>       release_mem_region(i2c_imx->res->start, resource_size(res));
> >> @@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
> >>       if (pdata && pdata->exit)
> >>               pdata->exit(&pdev->dev);
> >>
> >> -     /* Disable I2C clock */
> >> -     clk_disable(i2c_imx->clk);
> >>       clk_put(i2c_imx->clk);
> >>
> >>       release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
> >> --
> >> 1.6.0.4
> >>
> >>
> >
> > --
> > Pengutronix e.K.                           |                             |
> > Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> >
> 
> I don't think we have any suspend/resume routine. And we won't need it any more.

Ups, my bad. I have it in my local tree and didn't realize it isn't
upstream.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
@ 2009-10-01  8:00                         ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  8:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 03:56:29PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 3:34 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > On Thu, Oct 01, 2009 at 09:13:33AM +0800, Richard Zhao wrote:
> >> Enable clock before START, disable it after STOP.
> >
> > The clk_diable/enable calls in suspend/resume should be removed also.
> >
> > Sascha
> >
> >>
> >> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
> >>
> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> index 87faea4..72ddea3 100644
> >> --- a/drivers/i2c/busses/i2c-imx.c
> >> +++ b/drivers/i2c/busses/i2c-imx.c
> >> @@ -120,6 +120,7 @@ struct imx_i2c_struct {
> >> ? ? ? wait_queue_head_t ? ? ? queue;
> >> ? ? ? unsigned long ? ? ? ? ? i2csr;
> >> ? ? ? unsigned int ? ? ? ? ? ?disable_delay;
> >> + ? ? unsigned int ? ? ? ? ? ?ifdr; /* IMX_I2C_IFDR */
> >> ?};
> >>
> >> ?/** Functions for IMX I2C adapter driver ***************************************
> >> @@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >>
> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >>
> >> + ? ? clk_enable(i2c_imx->clk);
> >> + ? ? writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
> >> ? ? ? /* Enable I2C controller */
> >> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >> ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >> @@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >>
> >> ? ? ? /* Disable I2C controller */
> >> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> >> + ? ? clk_disable(i2c_imx->clk);
> >> ?}
> >>
> >> ?static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> >> @@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> >> ? ? ? else
> >> ? ? ? ? ? ? ? for (i = 0; i2c_clk_div[i][0] < div; i++);
> >>
> >> - ? ? /* Write divider value to register */
> >> - ? ? writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
> >> + ? ? /* Store divider value */
> >> + ? ? i2c_imx->ifdr = i2c_clk_div[i][1];
> >>
> >> ? ? ? if (cpu_is_mx1()) {
> >> ? ? ? ? ? ? ? /*
> >> @@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
> >> ? ? ? ? ? ? ? dev_err(&pdev->dev, "can't get I2C clock\n");
> >> ? ? ? ? ? ? ? goto fail3;
> >> ? ? ? }
> >> - ? ? clk_enable(i2c_imx->clk);
> >>
> >> ? ? ? /* Request IRQ */
> >> ? ? ? ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
> >> @@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
> >> ?fail5:
> >> ? ? ? free_irq(i2c_imx->irq, i2c_imx);
> >> ?fail4:
> >> - ? ? clk_disable(i2c_imx->clk);
> >> ? ? ? clk_put(i2c_imx->clk);
> >> ?fail3:
> >> ? ? ? release_mem_region(i2c_imx->res->start, resource_size(res));
> >> @@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
> >> ? ? ? if (pdata && pdata->exit)
> >> ? ? ? ? ? ? ? pdata->exit(&pdev->dev);
> >>
> >> - ? ? /* Disable I2C clock */
> >> - ? ? clk_disable(i2c_imx->clk);
> >> ? ? ? clk_put(i2c_imx->clk);
> >>
> >> ? ? ? release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
> >> --
> >> 1.6.0.4
> >>
> >>
> >
> > --
> > Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> > Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> > Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
> >
> 
> I don't think we have any suspend/resume routine. And we won't need it any more.

Ups, my bad. I have it in my local tree and didn't realize it isn't
upstream.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
  2009-10-01  7:29             ` Sascha Hauer
@ 2009-10-01  8:01                 ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  8:01 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 1, 2009 at 3:29 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
>> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
>> fail condition, and print i2c_msg to xfer.
>>
>> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
> Honestly I don't think we need this. It makes the driver too verbose for
> my taste.
>
> Sascha
>
>
>>
>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> index c1e541c..87faea4 100644
>> --- a/drivers/i2c/busses/i2c-imx.c
>> +++ b/drivers/i2c/busses/i2c-imx.c
>> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
>>  /** Functions for IMX I2C adapter driver ***************************************
>>  *******************************************************************************/
>>
>> +#ifdef CONFIG_I2C_DEBUG_BUS
>> +#define reg_dump(i2c_imx) \
>> +{ \
>> +     printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
>> +     printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
>> +             readb(i2c_imx->base + IMX_I2C_IADR), \
>> +             readb(i2c_imx->base + IMX_I2C_IFDR), \
>> +             readb(i2c_imx->base + IMX_I2C_I2CR), \
>> +             readb(i2c_imx->base + IMX_I2C_I2SR)); \
>> +}
>> +#else
>> +#define reg_dump(i2c_imx)
>> +#endif
>> +
>>  static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>>  {
>>       unsigned long orig_jiffies = jiffies;
>> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>>               if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
>>                       dev_dbg(&i2c_imx->adapter.dev,
>>                               "<%s> I2C bus is busy\n", __func__);
>> +                     reg_dump(i2c_imx);
>>                       return -EIO;
>>               }
>>               schedule();
>> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
>>
>>       if (unlikely(result < 0)) {
>>               dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
>> +             reg_dump(i2c_imx);
>>               return result;
>>       } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
>>               dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
>> +             reg_dump(i2c_imx);
>>               return -ETIMEDOUT;
>>       }
>>       dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
>> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>>  {
>>       if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
>>               dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
>> +             reg_dump(i2c_imx);
>>               return -EIO;  /* No ACK */
>>       }
>>
>> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>>       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>>
>>       result = i2c_imx_bus_busy(i2c_imx, 0);
>> -     if (result)
>> +     if (result) {
>> +             reg_dump(i2c_imx);
>>               return result;
>> +     }
>>
>>       /* Start I2C transaction */
>>       temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>>       temp |= I2CR_MSTA;
>>       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>>       result = i2c_imx_bus_busy(i2c_imx, 1);
>> -     if (result)
>> +     if (result) {
>> +             reg_dump(i2c_imx);
>>               return result;
>> -
>> +     }
>>       temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>>       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>>       return result;
>> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>>        */
>>       udelay(i2c_imx->disable_delay);
>>
>> -     i2c_imx_bus_busy(i2c_imx, 0);
>> +     if (i2c_imx_bus_busy(i2c_imx, 0))
>> +             reg_dump(i2c_imx);
>>
>>       /* Disable I2C controller */
>>       writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>>       struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>>
>>       dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> -
>> +#ifdef CONFIG_I2C_DEBUG_BUS
>> +     for (i = 0; i < num; i++) {
>> +             printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
>> +                     msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
>> +             if (!(msgs[i].flags & I2C_M_RD)) {
>> +                     int j;
>> +                     for (j = 0; j < msgs[i].len; j++)
>> +                             printk("%02x ", msgs[i].buf[j]);
>> +             }
>> +             printk("\n");
>> +     }
>> +#endif
>>       /* Start I2C transfer */
>>       result = i2c_imx_start(i2c_imx);
>>       if (result)
>> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>>                       temp |= I2CR_RSTA;
>>                       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>>                       result =  i2c_imx_bus_busy(i2c_imx, 1);
>> -                     if (result)
>> +                     if (result) {
>> +                             reg_dump(i2c_imx);
>>                               goto fail0;
>> +                     }
>>               }
>>               dev_dbg(&i2c_imx->adapter.dev,
>>                       "<%s> transfer message: %d\n", __func__, i);
>> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>>               res_size, i2c_imx->res->start);
>>       dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
>>               i2c_imx->adapter.name);
>> -     dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>> +     dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>>
>>       return 0;   /* Return OK */
>>
>> --
>> 1.6.0.4
>>
>>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>

1. i2c is more important bus in embedded system than PC. Many PMICs
are connected to cpu via i2c. Before system boot up, we depend much on
printk message.
2. When we add a new i2c device, it's easy to have problems. Maybe
it's hw issue, one device fails, all ones in the same bus fails. In
such condition, debug message is very helpfull.

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
@ 2009-10-01  8:01                 ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  8:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 3:29 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
>> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
>> fail condition, and print i2c_msg to xfer.
>>
>> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>
> Honestly I don't think we need this. It makes the driver too verbose for
> my taste.
>
> Sascha
>
>
>>
>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> index c1e541c..87faea4 100644
>> --- a/drivers/i2c/busses/i2c-imx.c
>> +++ b/drivers/i2c/busses/i2c-imx.c
>> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
>> ?/** Functions for IMX I2C adapter driver ***************************************
>> ?*******************************************************************************/
>>
>> +#ifdef CONFIG_I2C_DEBUG_BUS
>> +#define reg_dump(i2c_imx) \
>> +{ \
>> + ? ? printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
>> + ? ? printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
>> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IADR), \
>> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IFDR), \
>> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2CR), \
>> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2SR)); \
>> +}
>> +#else
>> +#define reg_dump(i2c_imx)
>> +#endif
>> +
>> ?static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> ?{
>> ? ? ? unsigned long orig_jiffies = jiffies;
>> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> ? ? ? ? ? ? ? if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
>> ? ? ? ? ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "<%s> I2C bus is busy\n", __func__);
>> + ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
>> ? ? ? ? ? ? ? ? ? ? ? return -EIO;
>> ? ? ? ? ? ? ? }
>> ? ? ? ? ? ? ? schedule();
>> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
>>
>> ? ? ? if (unlikely(result < 0)) {
>> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
>> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> ? ? ? ? ? ? ? return result;
>> ? ? ? } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
>> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
>> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> ? ? ? ? ? ? ? return -ETIMEDOUT;
>> ? ? ? }
>> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
>> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>> ?{
>> ? ? ? if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
>> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
>> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> ? ? ? ? ? ? ? return -EIO; ?/* No ACK */
>> ? ? ? }
>>
>> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>>
>> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
>> - ? ? if (result)
>> + ? ? if (result) {
>> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> ? ? ? ? ? ? ? return result;
>> + ? ? }
>>
>> ? ? ? /* Start I2C transaction */
>> ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> ? ? ? temp |= I2CR_MSTA;
>> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
>> - ? ? if (result)
>> + ? ? if (result) {
>> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> ? ? ? ? ? ? ? return result;
>> -
>> + ? ? }
>> ? ? ? temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> ? ? ? return result;
>> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> ? ? ? ?*/
>> ? ? ? udelay(i2c_imx->disable_delay);
>>
>> - ? ? i2c_imx_bus_busy(i2c_imx, 0);
>> + ? ? if (i2c_imx_bus_busy(i2c_imx, 0))
>> + ? ? ? ? ? ? reg_dump(i2c_imx);
>>
>> ? ? ? /* Disable I2C controller */
>> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> ? ? ? struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>>
>> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> -
>> +#ifdef CONFIG_I2C_DEBUG_BUS
>> + ? ? for (i = 0; i < num; i++) {
>> + ? ? ? ? ? ? printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
>> + ? ? ? ? ? ? ? ? ? ? msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
>> + ? ? ? ? ? ? if (!(msgs[i].flags & I2C_M_RD)) {
>> + ? ? ? ? ? ? ? ? ? ? int j;
>> + ? ? ? ? ? ? ? ? ? ? for (j = 0; j < msgs[i].len; j++)
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? printk("%02x ", msgs[i].buf[j]);
>> + ? ? ? ? ? ? }
>> + ? ? ? ? ? ? printk("\n");
>> + ? ? }
>> +#endif
>> ? ? ? /* Start I2C transfer */
>> ? ? ? result = i2c_imx_start(i2c_imx);
>> ? ? ? if (result)
>> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> ? ? ? ? ? ? ? ? ? ? ? temp |= I2CR_RSTA;
>> ? ? ? ? ? ? ? ? ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
>> - ? ? ? ? ? ? ? ? ? ? if (result)
>> + ? ? ? ? ? ? ? ? ? ? if (result) {
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
>> + ? ? ? ? ? ? ? ? ? ? }
>> ? ? ? ? ? ? ? }
>> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
>> ? ? ? ? ? ? ? ? ? ? ? "<%s> transfer message: %d\n", __func__, i);
>> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>> ? ? ? ? ? ? ? res_size, i2c_imx->res->start);
>> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
>> ? ? ? ? ? ? ? i2c_imx->adapter.name);
>> - ? ? dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>> + ? ? dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>>
>> ? ? ? return 0; ? /* Return OK */
>>
>> --
>> 1.6.0.4
>>
>>
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

1. i2c is more important bus in embedded system than PC. Many PMICs
are connected to cpu via i2c. Before system boot up, we depend much on
printk message.
2. When we add a new i2c device, it's easy to have problems. Maybe
it's hw issue, one device fails, all ones in the same bus fails. In
such condition, debug message is very helpfull.

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-01  1:13 ` Richard Zhao
@ 2009-10-01  8:03     ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  8:03 UTC (permalink / raw)
  To: kernel-bIcnvbaLZ9MEGnE8C9+IrQ
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ, w.sang-bIcnvbaLZ9MEGnE8C9+IrQ,
	Richard Zhao

On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> After START/RESTART, wait for busy bit to be set and
> after STOP, wait for busy bit to be clear.
>
> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 4afba3e..156cc95 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -125,14 +125,19 @@ struct imx_i2c_struct {
>  /** Functions for IMX I2C adapter driver ***************************************
>  *******************************************************************************/
>
> -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>  {
>        unsigned long orig_jiffies = jiffies;
> +       unsigned int temp;
>
>        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>
> -       /* wait for bus not busy */
> -       while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
> +       temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> +       while (1) {
> +               if (for_busy && (temp & I2SR_IBB))
> +                       break;
> +               if (!for_busy && !(temp & I2SR_IBB))
> +                       break;
>                if (signal_pending(current)) {
>                        dev_dbg(&i2c_imx->adapter.dev,
>                                "<%s> I2C Interrupted\n", __func__);
> @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>                        return -EIO;
>                }
>                schedule();
> +               temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>        }
>
>        return 0;
> @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>        return 0;
>  }
>
> -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>  {
>        unsigned int temp = 0;
> +       int result;
>
>        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>
>        /* Enable I2C controller */
> +       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>        writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> +
> +       result = i2c_imx_bus_busy(i2c_imx, 0);
> +       if (result)
> +               return result;
> +
>        /* Start I2C transaction */
>        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>        temp |= I2CR_MSTA;
>        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> +       result = i2c_imx_bus_busy(i2c_imx, 1);
> +       if (result)
> +               return result;
> +
>        temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> +       return result;
>  }
>
>  static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>        /* Stop I2C transaction */
>        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> -       temp &= ~I2CR_MSTA;
> +       temp &= ~(I2CR_MSTA | I2CR_MTX);
>        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> -       /* setup chip registers to defaults */
> -       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> -       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>        /*
>         * This delay caused by an i.MXL hardware bug.
>         * If no (or too short) delay, no "STOP" bit will be generated.
>         */
>        udelay(i2c_imx->disable_delay);
> +
> +       i2c_imx_bus_busy(i2c_imx, 0);
> +
>        /* Disable I2C controller */
>        writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>  }
> @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
>                        dev_dbg(&i2c_imx->adapter.dev,
>                                "<%s> clear MSTA\n", __func__);
>                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> -                       temp &= ~I2CR_MSTA;
> +                       temp &= ~(I2CR_MSTA | I2CR_MTX);
>                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>                } else if (i == (msgs->len - 2)) {
>                        dev_dbg(&i2c_imx->adapter.dev,
> @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>
>        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>
> -       /* Check if i2c bus is not busy */
> -       result = i2c_imx_bus_busy(i2c_imx);
> +       /* Start I2C transfer */
> +       result = i2c_imx_start(i2c_imx);
>        if (result)
>                goto fail0;
>
> -       /* Start I2C transfer */
> -       i2c_imx_start(i2c_imx);
> -
>        /* read/write data */
>        for (i = 0; i < num; i++) {
>                if (i) {
> @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>                        temp |= I2CR_RSTA;
>                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> +                       result =  i2c_imx_bus_busy(i2c_imx, 1);
> +                       if (result)
> +                               goto fail0;
>                }
>                dev_dbg(&i2c_imx->adapter.dev,
>                        "<%s> transfer message: %d\n", __func__, i);
> --
> 1.6.0.4
>
>

Hi Sascha,

So I assume you have no comments about this patch ?

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01  8:03     ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  8:03 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc@gmail.com> wrote:
> After START/RESTART, wait for busy bit to be set and
> after STOP, wait for busy bit to be clear.
>
> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 4afba3e..156cc95 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -125,14 +125,19 @@ struct imx_i2c_struct {
> ?/** Functions for IMX I2C adapter driver ***************************************
> ?*******************************************************************************/
>
> -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> ?{
> ? ? ? ?unsigned long orig_jiffies = jiffies;
> + ? ? ? unsigned int temp;
>
> ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>
> - ? ? ? /* wait for bus not busy */
> - ? ? ? while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
> + ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> + ? ? ? while (1) {
> + ? ? ? ? ? ? ? if (for_busy && (temp & I2SR_IBB))
> + ? ? ? ? ? ? ? ? ? ? ? break;
> + ? ? ? ? ? ? ? if (!for_busy && !(temp & I2SR_IBB))
> + ? ? ? ? ? ? ? ? ? ? ? break;
> ? ? ? ? ? ? ? ?if (signal_pending(current)) {
> ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> I2C Interrupted\n", __func__);
> @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> ? ? ? ? ? ? ? ? ? ? ? ?return -EIO;
> ? ? ? ? ? ? ? ?}
> ? ? ? ? ? ? ? ?schedule();
> + ? ? ? ? ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> ? ? ? ?}
>
> ? ? ? ?return 0;
> @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> ? ? ? ?return 0;
> ?}
>
> -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> ?{
> ? ? ? ?unsigned int temp = 0;
> + ? ? ? int result;
>
> ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>
> ? ? ? ?/* Enable I2C controller */
> + ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> ? ? ? ?writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> +
> + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
> + ? ? ? if (result)
> + ? ? ? ? ? ? ? return result;
> +
> ? ? ? ?/* Start I2C transaction */
> ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> ? ? ? ?temp |= I2CR_MSTA;
> ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
> + ? ? ? if (result)
> + ? ? ? ? ? ? ? return result;
> +
> ? ? ? ?temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
> ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> + ? ? ? return result;
> ?}
>
> ?static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> ? ? ? ?/* Stop I2C transaction */
> ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> - ? ? ? temp &= ~I2CR_MSTA;
> + ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
> ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> - ? ? ? /* setup chip registers to defaults */
> - ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> - ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> ? ? ? ?/*
> ? ? ? ? * This delay caused by an i.MXL hardware bug.
> ? ? ? ? * If no (or too short) delay, no "STOP" bit will be generated.
> ? ? ? ? */
> ? ? ? ?udelay(i2c_imx->disable_delay);
> +
> + ? ? ? i2c_imx_bus_busy(i2c_imx, 0);
> +
> ? ? ? ?/* Disable I2C controller */
> ? ? ? ?writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> ?}
> @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
> ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> clear MSTA\n", __func__);
> ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> - ? ? ? ? ? ? ? ? ? ? ? temp &= ~I2CR_MSTA;
> + ? ? ? ? ? ? ? ? ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
> ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> ? ? ? ? ? ? ? ?} else if (i == (msgs->len - 2)) {
> ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>
> ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>
> - ? ? ? /* Check if i2c bus is not busy */
> - ? ? ? result = i2c_imx_bus_busy(i2c_imx);
> + ? ? ? /* Start I2C transfer */
> + ? ? ? result = i2c_imx_start(i2c_imx);
> ? ? ? ?if (result)
> ? ? ? ? ? ? ? ?goto fail0;
>
> - ? ? ? /* Start I2C transfer */
> - ? ? ? i2c_imx_start(i2c_imx);
> -
> ? ? ? ?/* read/write data */
> ? ? ? ?for (i = 0; i < num; i++) {
> ? ? ? ? ? ? ? ?if (i) {
> @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> ? ? ? ? ? ? ? ? ? ? ? ?temp |= I2CR_RSTA;
> ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> + ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
> + ? ? ? ? ? ? ? ? ? ? ? if (result)
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
> ? ? ? ? ? ? ? ?}
> ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> ? ? ? ? ? ? ? ? ? ? ? ?"<%s> transfer message: %d\n", __func__, i);
> --
> 1.6.0.4
>
>

Hi Sascha,

So I assume you have no comments about this patch ?

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
  2009-10-01  8:01                 ` Richard Zhao
@ 2009-10-01  8:26                     ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  8:26 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 04:01:50PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 3:29 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> > On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
> >> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
> >> fail condition, and print i2c_msg to xfer.
> >>
> >> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >
> > Honestly I don't think we need this. It makes the driver too verbose for
> > my taste.
> >
> > Sascha
> >
> >
> >>
> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> index c1e541c..87faea4 100644
> >> --- a/drivers/i2c/busses/i2c-imx.c
> >> +++ b/drivers/i2c/busses/i2c-imx.c
> >> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
> >>  /** Functions for IMX I2C adapter driver ***************************************
> >>  *******************************************************************************/
> >>
> >> +#ifdef CONFIG_I2C_DEBUG_BUS
> >> +#define reg_dump(i2c_imx) \
> >> +{ \
> >> +     printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
> >> +     printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
> >> +             readb(i2c_imx->base + IMX_I2C_IADR), \
> >> +             readb(i2c_imx->base + IMX_I2C_IFDR), \
> >> +             readb(i2c_imx->base + IMX_I2C_I2CR), \
> >> +             readb(i2c_imx->base + IMX_I2C_I2SR)); \
> >> +}
> >> +#else
> >> +#define reg_dump(i2c_imx)
> >> +#endif
> >> +
> >>  static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> >>  {
> >>       unsigned long orig_jiffies = jiffies;
> >> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> >>               if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
> >>                       dev_dbg(&i2c_imx->adapter.dev,
> >>                               "<%s> I2C bus is busy\n", __func__);
> >> +                     reg_dump(i2c_imx);
> >>                       return -EIO;
> >>               }
> >>               schedule();
> >> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
> >>
> >>       if (unlikely(result < 0)) {
> >>               dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
> >> +             reg_dump(i2c_imx);
> >>               return result;
> >>       } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
> >>               dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
> >> +             reg_dump(i2c_imx);
> >>               return -ETIMEDOUT;
> >>       }
> >>       dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
> >> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> >>  {
> >>       if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
> >>               dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
> >> +             reg_dump(i2c_imx);
> >>               return -EIO;  /* No ACK */
> >>       }
> >>
> >> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >>       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >>
> >>       result = i2c_imx_bus_busy(i2c_imx, 0);
> >> -     if (result)
> >> +     if (result) {
> >> +             reg_dump(i2c_imx);
> >>               return result;
> >> +     }
> >>
> >>       /* Start I2C transaction */
> >>       temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >>       temp |= I2CR_MSTA;
> >>       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >>       result = i2c_imx_bus_busy(i2c_imx, 1);
> >> -     if (result)
> >> +     if (result) {
> >> +             reg_dump(i2c_imx);
> >>               return result;
> >> -
> >> +     }
> >>       temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
> >>       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >>       return result;
> >> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >>        */
> >>       udelay(i2c_imx->disable_delay);
> >>
> >> -     i2c_imx_bus_busy(i2c_imx, 0);
> >> +     if (i2c_imx_bus_busy(i2c_imx, 0))
> >> +             reg_dump(i2c_imx);
> >>
> >>       /* Disable I2C controller */
> >>       writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> >> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >>       struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
> >>
> >>       dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> -
> >> +#ifdef CONFIG_I2C_DEBUG_BUS
> >> +     for (i = 0; i < num; i++) {
> >> +             printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
> >> +                     msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
> >> +             if (!(msgs[i].flags & I2C_M_RD)) {
> >> +                     int j;
> >> +                     for (j = 0; j < msgs[i].len; j++)
> >> +                             printk("%02x ", msgs[i].buf[j]);
> >> +             }
> >> +             printk("\n");
> >> +     }
> >> +#endif
> >>       /* Start I2C transfer */
> >>       result = i2c_imx_start(i2c_imx);
> >>       if (result)
> >> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >>                       temp |= I2CR_RSTA;
> >>                       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >>                       result =  i2c_imx_bus_busy(i2c_imx, 1);
> >> -                     if (result)
> >> +                     if (result) {
> >> +                             reg_dump(i2c_imx);
> >>                               goto fail0;
> >> +                     }
> >>               }
> >>               dev_dbg(&i2c_imx->adapter.dev,
> >>                       "<%s> transfer message: %d\n", __func__, i);
> >> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
> >>               res_size, i2c_imx->res->start);
> >>       dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
> >>               i2c_imx->adapter.name);
> >> -     dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
> >> +     dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
> >>
> >>       return 0;   /* Return OK */
> >>
> >> --
> >> 1.6.0.4
> >>
> >>
> >
> > --
> > Pengutronix e.K.                           |                             |
> > Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> >
> 
> 1. i2c is more important bus in embedded system than PC. Many PMICs
> are connected to cpu via i2c. Before system boot up, we depend much on
> printk message.
> 2. When we add a new i2c device, it's easy to have problems. Maybe
> it's hw issue, one device fails, all ones in the same bus fails. In
> such condition, debug message is very helpfull.

The driver already consists to 15% of debug statements, there is
definitely no need to add even more. If anything, you could concentrate
on making the output more useful.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
@ 2009-10-01  8:26                     ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  8:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 04:01:50PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 3:29 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
> >> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
> >> fail condition, and print i2c_msg to xfer.
> >>
> >> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
> >
> > Honestly I don't think we need this. It makes the driver too verbose for
> > my taste.
> >
> > Sascha
> >
> >
> >>
> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> index c1e541c..87faea4 100644
> >> --- a/drivers/i2c/busses/i2c-imx.c
> >> +++ b/drivers/i2c/busses/i2c-imx.c
> >> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
> >> ?/** Functions for IMX I2C adapter driver ***************************************
> >> ?*******************************************************************************/
> >>
> >> +#ifdef CONFIG_I2C_DEBUG_BUS
> >> +#define reg_dump(i2c_imx) \
> >> +{ \
> >> + ? ? printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
> >> + ? ? printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IADR), \
> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IFDR), \
> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2CR), \
> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2SR)); \
> >> +}
> >> +#else
> >> +#define reg_dump(i2c_imx)
> >> +#endif
> >> +
> >> ?static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> >> ?{
> >> ? ? ? unsigned long orig_jiffies = jiffies;
> >> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> >> ? ? ? ? ? ? ? if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
> >> ? ? ? ? ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
> >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "<%s> I2C bus is busy\n", __func__);
> >> + ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
> >> ? ? ? ? ? ? ? ? ? ? ? return -EIO;
> >> ? ? ? ? ? ? ? }
> >> ? ? ? ? ? ? ? schedule();
> >> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
> >>
> >> ? ? ? if (unlikely(result < 0)) {
> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
> >> ? ? ? ? ? ? ? return result;
> >> ? ? ? } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
> >> ? ? ? ? ? ? ? return -ETIMEDOUT;
> >> ? ? ? }
> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
> >> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> >> ?{
> >> ? ? ? if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
> >> ? ? ? ? ? ? ? return -EIO; ?/* No ACK */
> >> ? ? ? }
> >>
> >> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >> ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >>
> >> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
> >> - ? ? if (result)
> >> + ? ? if (result) {
> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
> >> ? ? ? ? ? ? ? return result;
> >> + ? ? }
> >>
> >> ? ? ? /* Start I2C transaction */
> >> ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> ? ? ? temp |= I2CR_MSTA;
> >> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
> >> - ? ? if (result)
> >> + ? ? if (result) {
> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
> >> ? ? ? ? ? ? ? return result;
> >> -
> >> + ? ? }
> >> ? ? ? temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
> >> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> ? ? ? return result;
> >> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >> ? ? ? ?*/
> >> ? ? ? udelay(i2c_imx->disable_delay);
> >>
> >> - ? ? i2c_imx_bus_busy(i2c_imx, 0);
> >> + ? ? if (i2c_imx_bus_busy(i2c_imx, 0))
> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
> >>
> >> ? ? ? /* Disable I2C controller */
> >> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> >> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >> ? ? ? struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
> >>
> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> -
> >> +#ifdef CONFIG_I2C_DEBUG_BUS
> >> + ? ? for (i = 0; i < num; i++) {
> >> + ? ? ? ? ? ? printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
> >> + ? ? ? ? ? ? ? ? ? ? msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
> >> + ? ? ? ? ? ? if (!(msgs[i].flags & I2C_M_RD)) {
> >> + ? ? ? ? ? ? ? ? ? ? int j;
> >> + ? ? ? ? ? ? ? ? ? ? for (j = 0; j < msgs[i].len; j++)
> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? printk("%02x ", msgs[i].buf[j]);
> >> + ? ? ? ? ? ? }
> >> + ? ? ? ? ? ? printk("\n");
> >> + ? ? }
> >> +#endif
> >> ? ? ? /* Start I2C transfer */
> >> ? ? ? result = i2c_imx_start(i2c_imx);
> >> ? ? ? if (result)
> >> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >> ? ? ? ? ? ? ? ? ? ? ? temp |= I2CR_RSTA;
> >> ? ? ? ? ? ? ? ? ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
> >> - ? ? ? ? ? ? ? ? ? ? if (result)
> >> + ? ? ? ? ? ? ? ? ? ? if (result) {
> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
> >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
> >> + ? ? ? ? ? ? ? ? ? ? }
> >> ? ? ? ? ? ? ? }
> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
> >> ? ? ? ? ? ? ? ? ? ? ? "<%s> transfer message: %d\n", __func__, i);
> >> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
> >> ? ? ? ? ? ? ? res_size, i2c_imx->res->start);
> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
> >> ? ? ? ? ? ? ? i2c_imx->adapter.name);
> >> - ? ? dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
> >> + ? ? dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
> >>
> >> ? ? ? return 0; ? /* Return OK */
> >>
> >> --
> >> 1.6.0.4
> >>
> >>
> >
> > --
> > Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> > Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> > Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
> >
> 
> 1. i2c is more important bus in embedded system than PC. Many PMICs
> are connected to cpu via i2c. Before system boot up, we depend much on
> printk message.
> 2. When we add a new i2c device, it's easy to have problems. Maybe
> it's hw issue, one device fails, all ones in the same bus fails. In
> such condition, debug message is very helpfull.

The driver already consists to 15% of debug statements, there is
definitely no need to add even more. If anything, you could concentrate
on making the output more useful.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-01  8:03     ` Richard Zhao
@ 2009-10-01  8:38         ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  8:38 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > After START/RESTART, wait for busy bit to be set and
> > after STOP, wait for busy bit to be clear.
> >
> > Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >
> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> > index 4afba3e..156cc95 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
> >  /** Functions for IMX I2C adapter driver ***************************************
> >  *******************************************************************************/
> >
> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> >  {
> >        unsigned long orig_jiffies = jiffies;
> > +       unsigned int temp;
> >
> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >
> > -       /* wait for bus not busy */
> > -       while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
> > +       temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> > +       while (1) {
> > +               if (for_busy && (temp & I2SR_IBB))
> > +                       break;
> > +               if (!for_busy && !(temp & I2SR_IBB))
> > +                       break;
> >                if (signal_pending(current)) {
> >                        dev_dbg(&i2c_imx->adapter.dev,
> >                                "<%s> I2C Interrupted\n", __func__);
> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> >                        return -EIO;
> >                }
> >                schedule();
> > +               temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> >        }
> >
> >        return 0;
> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> >        return 0;
> >  }
> >
> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >  {
> >        unsigned int temp = 0;
> > +       int result;
> >
> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >
> >        /* Enable I2C controller */
> > +       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >        writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> > +
> > +       result = i2c_imx_bus_busy(i2c_imx, 0);
> > +       if (result)
> > +               return result;
> > +
> >        /* Start I2C transaction */
> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >        temp |= I2CR_MSTA;
> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > +       result = i2c_imx_bus_busy(i2c_imx, 1);
> > +       if (result)
> > +               return result;
> > +
> >        temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > +       return result;
> >  }
> >
> >  static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >        /* Stop I2C transaction */
> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> > -       temp &= ~I2CR_MSTA;
> > +       temp &= ~(I2CR_MSTA | I2CR_MTX);
> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > -       /* setup chip registers to defaults */
> > -       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> > -       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >        /*
> >         * This delay caused by an i.MXL hardware bug.
> >         * If no (or too short) delay, no "STOP" bit will be generated.
> >         */
> >        udelay(i2c_imx->disable_delay);
> > +
> > +       i2c_imx_bus_busy(i2c_imx, 0);
> > +
> >        /* Disable I2C controller */
> >        writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> >  }
> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
> >                        dev_dbg(&i2c_imx->adapter.dev,
> >                                "<%s> clear MSTA\n", __func__);
> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> > -                       temp &= ~I2CR_MSTA;
> > +                       temp &= ~(I2CR_MSTA | I2CR_MTX);
> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >                } else if (i == (msgs->len - 2)) {
> >                        dev_dbg(&i2c_imx->adapter.dev,
> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >
> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >
> > -       /* Check if i2c bus is not busy */
> > -       result = i2c_imx_bus_busy(i2c_imx);
> > +       /* Start I2C transfer */
> > +       result = i2c_imx_start(i2c_imx);
> >        if (result)
> >                goto fail0;
> >
> > -       /* Start I2C transfer */
> > -       i2c_imx_start(i2c_imx);
> > -
> >        /* read/write data */
> >        for (i = 0; i < num; i++) {
> >                if (i) {
> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >                        temp |= I2CR_RSTA;
> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > +                       result =  i2c_imx_bus_busy(i2c_imx, 1);
> > +                       if (result)
> > +                               goto fail0;
> >                }
> >                dev_dbg(&i2c_imx->adapter.dev,
> >                        "<%s> transfer message: %d\n", __func__, i);
> > --
> > 1.6.0.4
> >
> >
> 
> Hi Sascha,
> 
> So I assume you have no comments about this patch ?

No, I'm still thinking about it. The commit message says *what* you're
doing, but not *why*. Is it a concrete bug that you fix or is it just
because it might be a good idea to do so?
Also, we leave i2c_imx_xfer with the controller in a well defined state.
So if we leave this function with the controller in non busy state, why
do we have to check for non busy again when we enter it again?

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01  8:38         ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  8:38 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc@gmail.com> wrote:
> > After START/RESTART, wait for busy bit to be set and
> > after STOP, wait for busy bit to be clear.
> >
> > Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
> >
> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> > index 4afba3e..156cc95 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
> > ?/** Functions for IMX I2C adapter driver ***************************************
> > ?*******************************************************************************/
> >
> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> > ?{
> > ? ? ? ?unsigned long orig_jiffies = jiffies;
> > + ? ? ? unsigned int temp;
> >
> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >
> > - ? ? ? /* wait for bus not busy */
> > - ? ? ? while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
> > + ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> > + ? ? ? while (1) {
> > + ? ? ? ? ? ? ? if (for_busy && (temp & I2SR_IBB))
> > + ? ? ? ? ? ? ? ? ? ? ? break;
> > + ? ? ? ? ? ? ? if (!for_busy && !(temp & I2SR_IBB))
> > + ? ? ? ? ? ? ? ? ? ? ? break;
> > ? ? ? ? ? ? ? ?if (signal_pending(current)) {
> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> I2C Interrupted\n", __func__);
> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> > ? ? ? ? ? ? ? ? ? ? ? ?return -EIO;
> > ? ? ? ? ? ? ? ?}
> > ? ? ? ? ? ? ? ?schedule();
> > + ? ? ? ? ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> > ? ? ? ?}
> >
> > ? ? ? ?return 0;
> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> > ? ? ? ?return 0;
> > ?}
> >
> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> > ?{
> > ? ? ? ?unsigned int temp = 0;
> > + ? ? ? int result;
> >
> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >
> > ? ? ? ?/* Enable I2C controller */
> > + ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> > ? ? ? ?writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> > +
> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
> > + ? ? ? if (result)
> > + ? ? ? ? ? ? ? return result;
> > +
> > ? ? ? ?/* Start I2C transaction */
> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> > ? ? ? ?temp |= I2CR_MSTA;
> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
> > + ? ? ? if (result)
> > + ? ? ? ? ? ? ? return result;
> > +
> > ? ? ? ?temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > + ? ? ? return result;
> > ?}
> >
> > ?static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> > ? ? ? ?/* Stop I2C transaction */
> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> > - ? ? ? temp &= ~I2CR_MSTA;
> > + ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > - ? ? ? /* setup chip registers to defaults */
> > - ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> > - ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> > ? ? ? ?/*
> > ? ? ? ? * This delay caused by an i.MXL hardware bug.
> > ? ? ? ? * If no (or too short) delay, no "STOP" bit will be generated.
> > ? ? ? ? */
> > ? ? ? ?udelay(i2c_imx->disable_delay);
> > +
> > + ? ? ? i2c_imx_bus_busy(i2c_imx, 0);
> > +
> > ? ? ? ?/* Disable I2C controller */
> > ? ? ? ?writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> > ?}
> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> clear MSTA\n", __func__);
> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> > - ? ? ? ? ? ? ? ? ? ? ? temp &= ~I2CR_MSTA;
> > + ? ? ? ? ? ? ? ? ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > ? ? ? ? ? ? ? ?} else if (i == (msgs->len - 2)) {
> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >
> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >
> > - ? ? ? /* Check if i2c bus is not busy */
> > - ? ? ? result = i2c_imx_bus_busy(i2c_imx);
> > + ? ? ? /* Start I2C transfer */
> > + ? ? ? result = i2c_imx_start(i2c_imx);
> > ? ? ? ?if (result)
> > ? ? ? ? ? ? ? ?goto fail0;
> >
> > - ? ? ? /* Start I2C transfer */
> > - ? ? ? i2c_imx_start(i2c_imx);
> > -
> > ? ? ? ?/* read/write data */
> > ? ? ? ?for (i = 0; i < num; i++) {
> > ? ? ? ? ? ? ? ?if (i) {
> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> > ? ? ? ? ? ? ? ? ? ? ? ?temp |= I2CR_RSTA;
> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> > + ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
> > + ? ? ? ? ? ? ? ? ? ? ? if (result)
> > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
> > ? ? ? ? ? ? ? ?}
> > ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> > ? ? ? ? ? ? ? ? ? ? ? ?"<%s> transfer message: %d\n", __func__, i);
> > --
> > 1.6.0.4
> >
> >
> 
> Hi Sascha,
> 
> So I assume you have no comments about this patch ?

No, I'm still thinking about it. The commit message says *what* you're
doing, but not *why*. Is it a concrete bug that you fix or is it just
because it might be a good idea to do so?
Also, we leave i2c_imx_xfer with the controller in a well defined state.
So if we leave this function with the controller in non busy state, why
do we have to check for non busy again when we enter it again?

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-01  8:38         ` Sascha Hauer
@ 2009-10-01  9:11             ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  9:11 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 1, 2009 at 4:38 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
>> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> > After START/RESTART, wait for busy bit to be set and
>> > after STOP, wait for busy bit to be clear.
>> >
>> > Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> >
>> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> > index 4afba3e..156cc95 100644
>> > --- a/drivers/i2c/busses/i2c-imx.c
>> > +++ b/drivers/i2c/busses/i2c-imx.c
>> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
>> >  /** Functions for IMX I2C adapter driver ***************************************
>> >  *******************************************************************************/
>> >
>> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> >  {
>> >        unsigned long orig_jiffies = jiffies;
>> > +       unsigned int temp;
>> >
>> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >
>> > -       /* wait for bus not busy */
>> > -       while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
>> > +       temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> > +       while (1) {
>> > +               if (for_busy && (temp & I2SR_IBB))
>> > +                       break;
>> > +               if (!for_busy && !(temp & I2SR_IBB))
>> > +                       break;
>> >                if (signal_pending(current)) {
>> >                        dev_dbg(&i2c_imx->adapter.dev,
>> >                                "<%s> I2C Interrupted\n", __func__);
>> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> >                        return -EIO;
>> >                }
>> >                schedule();
>> > +               temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> >        }
>> >
>> >        return 0;
>> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>> >        return 0;
>> >  }
>> >
>> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >  {
>> >        unsigned int temp = 0;
>> > +       int result;
>> >
>> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >
>> >        /* Enable I2C controller */
>> > +       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> >        writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> > +
>> > +       result = i2c_imx_bus_busy(i2c_imx, 0);
>> > +       if (result)
>> > +               return result;
>> > +
>> >        /* Start I2C transaction */
>> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >        temp |= I2CR_MSTA;
>> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > +       result = i2c_imx_bus_busy(i2c_imx, 1);
>> > +       if (result)
>> > +               return result;
>> > +
>> >        temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > +       return result;
>> >  }
>> >
>> >  static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >        /* Stop I2C transaction */
>> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> > -       temp &= ~I2CR_MSTA;
>> > +       temp &= ~(I2CR_MSTA | I2CR_MTX);
>> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > -       /* setup chip registers to defaults */
>> > -       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> > -       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> >        /*
>> >         * This delay caused by an i.MXL hardware bug.
>> >         * If no (or too short) delay, no "STOP" bit will be generated.
>> >         */
>> >        udelay(i2c_imx->disable_delay);
>> > +
>> > +       i2c_imx_bus_busy(i2c_imx, 0);
>> > +
>> >        /* Disable I2C controller */
>> >        writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> >  }
>> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
>> >                        dev_dbg(&i2c_imx->adapter.dev,
>> >                                "<%s> clear MSTA\n", __func__);
>> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> > -                       temp &= ~I2CR_MSTA;
>> > +                       temp &= ~(I2CR_MSTA | I2CR_MTX);
>> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >                } else if (i == (msgs->len - 2)) {
>> >                        dev_dbg(&i2c_imx->adapter.dev,
>> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >
>> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >
>> > -       /* Check if i2c bus is not busy */
>> > -       result = i2c_imx_bus_busy(i2c_imx);
>> > +       /* Start I2C transfer */
>> > +       result = i2c_imx_start(i2c_imx);
>> >        if (result)
>> >                goto fail0;
>> >
>> > -       /* Start I2C transfer */
>> > -       i2c_imx_start(i2c_imx);
>> > -
>> >        /* read/write data */
>> >        for (i = 0; i < num; i++) {
>> >                if (i) {
>> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >                        temp |= I2CR_RSTA;
>> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > +                       result =  i2c_imx_bus_busy(i2c_imx, 1);
>> > +                       if (result)
>> > +                               goto fail0;
>> >                }
>> >                dev_dbg(&i2c_imx->adapter.dev,
>> >                        "<%s> transfer message: %d\n", __func__, i);
>> > --
>> > 1.6.0.4
>> >
>> >
>>
>> Hi Sascha,
>>
>> So I assume you have no comments about this patch ?
>
> No, I'm still thinking about it. The commit message says *what* you're
> doing, but not *why*. Is it a concrete bug that you fix or is it just
> because it might be a good idea to do so?
The driver doesn't work with mx51, which is a fast cpu. So I checked
the driver, and find it didn't check IBB.
> Also, we leave i2c_imx_xfer with the controller in a well defined state.
> So if we leave this function with the controller in non busy state, why
> do we have to check for non busy again when we enter it again?
I2C is a multi-master bus.
Richard
>
> Sascha
>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01  9:11             ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  9:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 4:38 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
>> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc@gmail.com> wrote:
>> > After START/RESTART, wait for busy bit to be set and
>> > after STOP, wait for busy bit to be clear.
>> >
>> > Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>> >
>> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> > index 4afba3e..156cc95 100644
>> > --- a/drivers/i2c/busses/i2c-imx.c
>> > +++ b/drivers/i2c/busses/i2c-imx.c
>> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
>> > ?/** Functions for IMX I2C adapter driver ***************************************
>> > ?*******************************************************************************/
>> >
>> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> > ?{
>> > ? ? ? ?unsigned long orig_jiffies = jiffies;
>> > + ? ? ? unsigned int temp;
>> >
>> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >
>> > - ? ? ? /* wait for bus not busy */
>> > - ? ? ? while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
>> > + ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> > + ? ? ? while (1) {
>> > + ? ? ? ? ? ? ? if (for_busy && (temp & I2SR_IBB))
>> > + ? ? ? ? ? ? ? ? ? ? ? break;
>> > + ? ? ? ? ? ? ? if (!for_busy && !(temp & I2SR_IBB))
>> > + ? ? ? ? ? ? ? ? ? ? ? break;
>> > ? ? ? ? ? ? ? ?if (signal_pending(current)) {
>> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> I2C Interrupted\n", __func__);
>> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> > ? ? ? ? ? ? ? ? ? ? ? ?return -EIO;
>> > ? ? ? ? ? ? ? ?}
>> > ? ? ? ? ? ? ? ?schedule();
>> > + ? ? ? ? ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> > ? ? ? ?}
>> >
>> > ? ? ? ?return 0;
>> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>> > ? ? ? ?return 0;
>> > ?}
>> >
>> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> > ?{
>> > ? ? ? ?unsigned int temp = 0;
>> > + ? ? ? int result;
>> >
>> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >
>> > ? ? ? ?/* Enable I2C controller */
>> > + ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> > ? ? ? ?writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> > +
>> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
>> > + ? ? ? if (result)
>> > + ? ? ? ? ? ? ? return result;
>> > +
>> > ? ? ? ?/* Start I2C transaction */
>> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> > ? ? ? ?temp |= I2CR_MSTA;
>> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
>> > + ? ? ? if (result)
>> > + ? ? ? ? ? ? ? return result;
>> > +
>> > ? ? ? ?temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > + ? ? ? return result;
>> > ?}
>> >
>> > ?static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> > ? ? ? ?/* Stop I2C transaction */
>> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> > - ? ? ? temp &= ~I2CR_MSTA;
>> > + ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
>> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > - ? ? ? /* setup chip registers to defaults */
>> > - ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> > - ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> > ? ? ? ?/*
>> > ? ? ? ? * This delay caused by an i.MXL hardware bug.
>> > ? ? ? ? * If no (or too short) delay, no "STOP" bit will be generated.
>> > ? ? ? ? */
>> > ? ? ? ?udelay(i2c_imx->disable_delay);
>> > +
>> > + ? ? ? i2c_imx_bus_busy(i2c_imx, 0);
>> > +
>> > ? ? ? ?/* Disable I2C controller */
>> > ? ? ? ?writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> > ?}
>> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
>> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> clear MSTA\n", __func__);
>> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> > - ? ? ? ? ? ? ? ? ? ? ? temp &= ~I2CR_MSTA;
>> > + ? ? ? ? ? ? ? ? ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
>> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > ? ? ? ? ? ? ? ?} else if (i == (msgs->len - 2)) {
>> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >
>> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >
>> > - ? ? ? /* Check if i2c bus is not busy */
>> > - ? ? ? result = i2c_imx_bus_busy(i2c_imx);
>> > + ? ? ? /* Start I2C transfer */
>> > + ? ? ? result = i2c_imx_start(i2c_imx);
>> > ? ? ? ?if (result)
>> > ? ? ? ? ? ? ? ?goto fail0;
>> >
>> > - ? ? ? /* Start I2C transfer */
>> > - ? ? ? i2c_imx_start(i2c_imx);
>> > -
>> > ? ? ? ?/* read/write data */
>> > ? ? ? ?for (i = 0; i < num; i++) {
>> > ? ? ? ? ? ? ? ?if (i) {
>> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> > ? ? ? ? ? ? ? ? ? ? ? ?temp |= I2CR_RSTA;
>> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> > + ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
>> > + ? ? ? ? ? ? ? ? ? ? ? if (result)
>> > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
>> > ? ? ? ? ? ? ? ?}
>> > ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> > ? ? ? ? ? ? ? ? ? ? ? ?"<%s> transfer message: %d\n", __func__, i);
>> > --
>> > 1.6.0.4
>> >
>> >
>>
>> Hi Sascha,
>>
>> So I assume you have no comments about this patch ?
>
> No, I'm still thinking about it. The commit message says *what* you're
> doing, but not *why*. Is it a concrete bug that you fix or is it just
> because it might be a good idea to do so?
The driver doesn't work with mx51, which is a fast cpu. So I checked
the driver, and find it didn't check IBB.
> Also, we leave i2c_imx_xfer with the controller in a well defined state.
> So if we leave this function with the controller in non busy state, why
> do we have to check for non busy again when we enter it again?
I2C is a multi-master bus.
Richard
>
> Sascha
>
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
  2009-10-01  8:26                     ` Sascha Hauer
@ 2009-10-01  9:30                         ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  9:30 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 1, 2009 at 4:26 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> On Thu, Oct 01, 2009 at 04:01:50PM +0800, Richard Zhao wrote:
>> On Thu, Oct 1, 2009 at 3:29 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
>> > On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
>> >> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
>> >> fail condition, and print i2c_msg to xfer.
>> >>
>> >> Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> >
>> > Honestly I don't think we need this. It makes the driver too verbose for
>> > my taste.
>> >
>> > Sascha
>> >
>> >
>> >>
>> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> >> index c1e541c..87faea4 100644
>> >> --- a/drivers/i2c/busses/i2c-imx.c
>> >> +++ b/drivers/i2c/busses/i2c-imx.c
>> >> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
>> >>  /** Functions for IMX I2C adapter driver ***************************************
>> >>  *******************************************************************************/
>> >>
>> >> +#ifdef CONFIG_I2C_DEBUG_BUS
>> >> +#define reg_dump(i2c_imx) \
>> >> +{ \
>> >> +     printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
>> >> +     printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
>> >> +             readb(i2c_imx->base + IMX_I2C_IADR), \
>> >> +             readb(i2c_imx->base + IMX_I2C_IFDR), \
>> >> +             readb(i2c_imx->base + IMX_I2C_I2CR), \
>> >> +             readb(i2c_imx->base + IMX_I2C_I2SR)); \
>> >> +}
>> >> +#else
>> >> +#define reg_dump(i2c_imx)
>> >> +#endif
>> >> +
>> >>  static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> >>  {
>> >>       unsigned long orig_jiffies = jiffies;
>> >> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> >>               if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
>> >>                       dev_dbg(&i2c_imx->adapter.dev,
>> >>                               "<%s> I2C bus is busy\n", __func__);
>> >> +                     reg_dump(i2c_imx);
>> >>                       return -EIO;
>> >>               }
>> >>               schedule();
>> >> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
>> >>
>> >>       if (unlikely(result < 0)) {
>> >>               dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
>> >> +             reg_dump(i2c_imx);
>> >>               return result;
>> >>       } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
>> >>               dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
>> >> +             reg_dump(i2c_imx);
>> >>               return -ETIMEDOUT;
>> >>       }
>> >>       dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
>> >> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>> >>  {
>> >>       if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
>> >>               dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
>> >> +             reg_dump(i2c_imx);
>> >>               return -EIO;  /* No ACK */
>> >>       }
>> >>
>> >> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >>       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> >>
>> >>       result = i2c_imx_bus_busy(i2c_imx, 0);
>> >> -     if (result)
>> >> +     if (result) {
>> >> +             reg_dump(i2c_imx);
>> >>               return result;
>> >> +     }
>> >>
>> >>       /* Start I2C transaction */
>> >>       temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >>       temp |= I2CR_MSTA;
>> >>       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >>       result = i2c_imx_bus_busy(i2c_imx, 1);
>> >> -     if (result)
>> >> +     if (result) {
>> >> +             reg_dump(i2c_imx);
>> >>               return result;
>> >> -
>> >> +     }
>> >>       temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>> >>       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >>       return result;
>> >> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >>        */
>> >>       udelay(i2c_imx->disable_delay);
>> >>
>> >> -     i2c_imx_bus_busy(i2c_imx, 0);
>> >> +     if (i2c_imx_bus_busy(i2c_imx, 0))
>> >> +             reg_dump(i2c_imx);
>> >>
>> >>       /* Disable I2C controller */
>> >>       writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> >> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >>       struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>> >>
>> >>       dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> -
>> >> +#ifdef CONFIG_I2C_DEBUG_BUS
>> >> +     for (i = 0; i < num; i++) {
>> >> +             printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
>> >> +                     msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
>> >> +             if (!(msgs[i].flags & I2C_M_RD)) {
>> >> +                     int j;
>> >> +                     for (j = 0; j < msgs[i].len; j++)
>> >> +                             printk("%02x ", msgs[i].buf[j]);
>> >> +             }
>> >> +             printk("\n");
>> >> +     }
>> >> +#endif
>> >>       /* Start I2C transfer */
>> >>       result = i2c_imx_start(i2c_imx);
>> >>       if (result)
>> >> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >>                       temp |= I2CR_RSTA;
>> >>                       writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >>                       result =  i2c_imx_bus_busy(i2c_imx, 1);
>> >> -                     if (result)
>> >> +                     if (result) {
>> >> +                             reg_dump(i2c_imx);
>> >>                               goto fail0;
>> >> +                     }
>> >>               }
>> >>               dev_dbg(&i2c_imx->adapter.dev,
>> >>                       "<%s> transfer message: %d\n", __func__, i);
>> >> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>> >>               res_size, i2c_imx->res->start);
>> >>       dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
>> >>               i2c_imx->adapter.name);
>> >> -     dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>> >> +     dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>> >>
>> >>       return 0;   /* Return OK */
>> >>
>> >> --
>> >> 1.6.0.4
>> >>
>> >>
>> >
>> > --
>> > Pengutronix e.K.                           |                             |
>> > Industrial Linux Solutions                 | http://www.pengutronix.de/  |
>> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
>> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>> >
>>
>> 1. i2c is more important bus in embedded system than PC. Many PMICs
>> are connected to cpu via i2c. Before system boot up, we depend much on
>> printk message.
>> 2. When we add a new i2c device, it's easy to have problems. Maybe
>> it's hw issue, one device fails, all ones in the same bus fails. In
>> such condition, debug message is very helpfull.
>
> The driver already consists to 15% of debug statements, there is
> definitely no need to add even more. If anything, you could concentrate
> on making the output more useful.
The dump_reg are only added when operation fails. It's not used to
track function call path or anything else.
I'm not supposed to show detailed message when there's operation fail?
The reason to add a switch to disable it is, when i2c tools scan the
bus, it will cause operation fail.

Richard
>
> Sascha
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
@ 2009-10-01  9:30                         ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01  9:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 4:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 04:01:50PM +0800, Richard Zhao wrote:
>> On Thu, Oct 1, 2009 at 3:29 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> > On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
>> >> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
>> >> fail condition, and print i2c_msg to xfer.
>> >>
>> >> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>> >
>> > Honestly I don't think we need this. It makes the driver too verbose for
>> > my taste.
>> >
>> > Sascha
>> >
>> >
>> >>
>> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> >> index c1e541c..87faea4 100644
>> >> --- a/drivers/i2c/busses/i2c-imx.c
>> >> +++ b/drivers/i2c/busses/i2c-imx.c
>> >> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
>> >> ?/** Functions for IMX I2C adapter driver ***************************************
>> >> ?*******************************************************************************/
>> >>
>> >> +#ifdef CONFIG_I2C_DEBUG_BUS
>> >> +#define reg_dump(i2c_imx) \
>> >> +{ \
>> >> + ? ? printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
>> >> + ? ? printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IADR), \
>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IFDR), \
>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2CR), \
>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2SR)); \
>> >> +}
>> >> +#else
>> >> +#define reg_dump(i2c_imx)
>> >> +#endif
>> >> +
>> >> ?static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> >> ?{
>> >> ? ? ? unsigned long orig_jiffies = jiffies;
>> >> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> >> ? ? ? ? ? ? ? if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
>> >> ? ? ? ? ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
>> >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "<%s> I2C bus is busy\n", __func__);
>> >> + ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
>> >> ? ? ? ? ? ? ? ? ? ? ? return -EIO;
>> >> ? ? ? ? ? ? ? }
>> >> ? ? ? ? ? ? ? schedule();
>> >> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
>> >>
>> >> ? ? ? if (unlikely(result < 0)) {
>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> >> ? ? ? ? ? ? ? return result;
>> >> ? ? ? } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> >> ? ? ? ? ? ? ? return -ETIMEDOUT;
>> >> ? ? ? }
>> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
>> >> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>> >> ?{
>> >> ? ? ? if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> >> ? ? ? ? ? ? ? return -EIO; ?/* No ACK */
>> >> ? ? ? }
>> >>
>> >> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >> ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> >>
>> >> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
>> >> - ? ? if (result)
>> >> + ? ? if (result) {
>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> >> ? ? ? ? ? ? ? return result;
>> >> + ? ? }
>> >>
>> >> ? ? ? /* Start I2C transaction */
>> >> ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> ? ? ? temp |= I2CR_MSTA;
>> >> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
>> >> - ? ? if (result)
>> >> + ? ? if (result) {
>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> >> ? ? ? ? ? ? ? return result;
>> >> -
>> >> + ? ? }
>> >> ? ? ? temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>> >> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> ? ? ? return result;
>> >> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >> ? ? ? ?*/
>> >> ? ? ? udelay(i2c_imx->disable_delay);
>> >>
>> >> - ? ? i2c_imx_bus_busy(i2c_imx, 0);
>> >> + ? ? if (i2c_imx_bus_busy(i2c_imx, 0))
>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>> >>
>> >> ? ? ? /* Disable I2C controller */
>> >> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> >> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >> ? ? ? struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>> >>
>> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> -
>> >> +#ifdef CONFIG_I2C_DEBUG_BUS
>> >> + ? ? for (i = 0; i < num; i++) {
>> >> + ? ? ? ? ? ? printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
>> >> + ? ? ? ? ? ? ? ? ? ? msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
>> >> + ? ? ? ? ? ? if (!(msgs[i].flags & I2C_M_RD)) {
>> >> + ? ? ? ? ? ? ? ? ? ? int j;
>> >> + ? ? ? ? ? ? ? ? ? ? for (j = 0; j < msgs[i].len; j++)
>> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? printk("%02x ", msgs[i].buf[j]);
>> >> + ? ? ? ? ? ? }
>> >> + ? ? ? ? ? ? printk("\n");
>> >> + ? ? }
>> >> +#endif
>> >> ? ? ? /* Start I2C transfer */
>> >> ? ? ? result = i2c_imx_start(i2c_imx);
>> >> ? ? ? if (result)
>> >> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >> ? ? ? ? ? ? ? ? ? ? ? temp |= I2CR_RSTA;
>> >> ? ? ? ? ? ? ? ? ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
>> >> - ? ? ? ? ? ? ? ? ? ? if (result)
>> >> + ? ? ? ? ? ? ? ? ? ? if (result) {
>> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
>> >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
>> >> + ? ? ? ? ? ? ? ? ? ? }
>> >> ? ? ? ? ? ? ? }
>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
>> >> ? ? ? ? ? ? ? ? ? ? ? "<%s> transfer message: %d\n", __func__, i);
>> >> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>> >> ? ? ? ? ? ? ? res_size, i2c_imx->res->start);
>> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
>> >> ? ? ? ? ? ? ? i2c_imx->adapter.name);
>> >> - ? ? dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>> >> + ? ? dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>> >>
>> >> ? ? ? return 0; ? /* Return OK */
>> >>
>> >> --
>> >> 1.6.0.4
>> >>
>> >>
>> >
>> > --
>> > Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
>> > Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
>> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
>> > Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>> >
>>
>> 1. i2c is more important bus in embedded system than PC. Many PMICs
>> are connected to cpu via i2c. Before system boot up, we depend much on
>> printk message.
>> 2. When we add a new i2c device, it's easy to have problems. Maybe
>> it's hw issue, one device fails, all ones in the same bus fails. In
>> such condition, debug message is very helpfull.
>
> The driver already consists to 15% of debug statements, there is
> definitely no need to add even more. If anything, you could concentrate
> on making the output more useful.
The dump_reg are only added when operation fails. It's not used to
track function call path or anything else.
I'm not supposed to show detailed message when there's operation fail?
The reason to add a switch to disable it is, when i2c tools scan the
bus, it will cause operation fail.

Richard
>
> Sascha
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-01  9:11             ` Richard Zhao
@ 2009-10-01  9:52                 ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  9:52 UTC (permalink / raw)
  To: Richard Zhao
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 01, 2009 at 05:11:30PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 4:38 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> > On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
> >> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >> > After START/RESTART, wait for busy bit to be set and
> >> > after STOP, wait for busy bit to be clear.
> >> >
> >> > Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >> >
> >> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> > index 4afba3e..156cc95 100644
> >> > --- a/drivers/i2c/busses/i2c-imx.c
> >> > +++ b/drivers/i2c/busses/i2c-imx.c
> >> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
> >> >  /** Functions for IMX I2C adapter driver ***************************************
> >> >  *******************************************************************************/
> >> >
> >> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> >> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> >> >  {
> >> >        unsigned long orig_jiffies = jiffies;
> >> > +       unsigned int temp;
> >> >
> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> >
> >> > -       /* wait for bus not busy */
> >> > -       while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
> >> > +       temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> >> > +       while (1) {
> >> > +               if (for_busy && (temp & I2SR_IBB))
> >> > +                       break;
> >> > +               if (!for_busy && !(temp & I2SR_IBB))
> >> > +                       break;
> >> >                if (signal_pending(current)) {
> >> >                        dev_dbg(&i2c_imx->adapter.dev,
> >> >                                "<%s> I2C Interrupted\n", __func__);
> >> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> >> >                        return -EIO;
> >> >                }
> >> >                schedule();
> >> > +               temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> >> >        }
> >> >
> >> >        return 0;
> >> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> >> >        return 0;
> >> >  }
> >> >
> >> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >> >  {
> >> >        unsigned int temp = 0;
> >> > +       int result;
> >> >
> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> >
> >> >        /* Enable I2C controller */
> >> > +       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >> >        writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >> > +
> >> > +       result = i2c_imx_bus_busy(i2c_imx, 0);
> >> > +       if (result)
> >> > +               return result;
> >> > +
> >> >        /* Start I2C transaction */
> >> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> >        temp |= I2CR_MSTA;
> >> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > +       result = i2c_imx_bus_busy(i2c_imx, 1);
> >> > +       if (result)
> >> > +               return result;
> >> > +
> >> >        temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
> >> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > +       return result;
> >> >  }
> >> >
> >> >  static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >> >        /* Stop I2C transaction */
> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> > -       temp &= ~I2CR_MSTA;
> >> > +       temp &= ~(I2CR_MSTA | I2CR_MTX);
> >> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > -       /* setup chip registers to defaults */
> >> > -       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >> > -       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >> >        /*
> >> >         * This delay caused by an i.MXL hardware bug.
> >> >         * If no (or too short) delay, no "STOP" bit will be generated.
> >> >         */
> >> >        udelay(i2c_imx->disable_delay);
> >> > +
> >> > +       i2c_imx_bus_busy(i2c_imx, 0);
> >> > +
> >> >        /* Disable I2C controller */
> >> >        writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> >> >  }
> >> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
> >> >                        dev_dbg(&i2c_imx->adapter.dev,
> >> >                                "<%s> clear MSTA\n", __func__);
> >> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> > -                       temp &= ~I2CR_MSTA;
> >> > +                       temp &= ~(I2CR_MSTA | I2CR_MTX);
> >> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> >                } else if (i == (msgs->len - 2)) {
> >> >                        dev_dbg(&i2c_imx->adapter.dev,
> >> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >> >
> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> >
> >> > -       /* Check if i2c bus is not busy */
> >> > -       result = i2c_imx_bus_busy(i2c_imx);
> >> > +       /* Start I2C transfer */
> >> > +       result = i2c_imx_start(i2c_imx);
> >> >        if (result)
> >> >                goto fail0;
> >> >
> >> > -       /* Start I2C transfer */
> >> > -       i2c_imx_start(i2c_imx);
> >> > -
> >> >        /* read/write data */
> >> >        for (i = 0; i < num; i++) {
> >> >                if (i) {
> >> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> >                        temp |= I2CR_RSTA;
> >> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > +                       result =  i2c_imx_bus_busy(i2c_imx, 1);
> >> > +                       if (result)
> >> > +                               goto fail0;
> >> >                }
> >> >                dev_dbg(&i2c_imx->adapter.dev,
> >> >                        "<%s> transfer message: %d\n", __func__, i);
> >> > --
> >> > 1.6.0.4
> >> >
> >> >
> >>
> >> Hi Sascha,
> >>
> >> So I assume you have no comments about this patch ?
> >
> > No, I'm still thinking about it. The commit message says *what* you're
> > doing, but not *why*. Is it a concrete bug that you fix or is it just
> > because it might be a good idea to do so?
> The driver doesn't work with mx51, which is a fast cpu. So I checked
> the driver, and find it didn't check IBB.

Ah, so 'make the driver work on i.MX51' is a good statement which should
be part of the commit message.

> > Also, we leave i2c_imx_xfer with the controller in a well defined state.
> > So if we leave this function with the controller in non busy state, why
> > do we have to check for non busy again when we enter it again?
> I2C is a multi-master bus.

So you say with this patch the driver becomes multi master capable? If
so, it should also be part of the commit message.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01  9:52                 ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-01  9:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 01, 2009 at 05:11:30PM +0800, Richard Zhao wrote:
> On Thu, Oct 1, 2009 at 4:38 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
> >> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc@gmail.com> wrote:
> >> > After START/RESTART, wait for busy bit to be set and
> >> > after STOP, wait for busy bit to be clear.
> >> >
> >> > Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
> >> >
> >> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> >> > index 4afba3e..156cc95 100644
> >> > --- a/drivers/i2c/busses/i2c-imx.c
> >> > +++ b/drivers/i2c/busses/i2c-imx.c
> >> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
> >> > ?/** Functions for IMX I2C adapter driver ***************************************
> >> > ?*******************************************************************************/
> >> >
> >> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> >> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
> >> > ?{
> >> > ? ? ? ?unsigned long orig_jiffies = jiffies;
> >> > + ? ? ? unsigned int temp;
> >> >
> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> >
> >> > - ? ? ? /* wait for bus not busy */
> >> > - ? ? ? while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
> >> > + ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> >> > + ? ? ? while (1) {
> >> > + ? ? ? ? ? ? ? if (for_busy && (temp & I2SR_IBB))
> >> > + ? ? ? ? ? ? ? ? ? ? ? break;
> >> > + ? ? ? ? ? ? ? if (!for_busy && !(temp & I2SR_IBB))
> >> > + ? ? ? ? ? ? ? ? ? ? ? break;
> >> > ? ? ? ? ? ? ? ?if (signal_pending(current)) {
> >> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> I2C Interrupted\n", __func__);
> >> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
> >> > ? ? ? ? ? ? ? ? ? ? ? ?return -EIO;
> >> > ? ? ? ? ? ? ? ?}
> >> > ? ? ? ? ? ? ? ?schedule();
> >> > + ? ? ? ? ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
> >> > ? ? ? ?}
> >> >
> >> > ? ? ? ?return 0;
> >> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
> >> > ? ? ? ?return 0;
> >> > ?}
> >> >
> >> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
> >> > ?{
> >> > ? ? ? ?unsigned int temp = 0;
> >> > + ? ? ? int result;
> >> >
> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> >
> >> > ? ? ? ?/* Enable I2C controller */
> >> > + ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >> > ? ? ? ?writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >> > +
> >> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
> >> > + ? ? ? if (result)
> >> > + ? ? ? ? ? ? ? return result;
> >> > +
> >> > ? ? ? ?/* Start I2C transaction */
> >> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> > ? ? ? ?temp |= I2CR_MSTA;
> >> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
> >> > + ? ? ? if (result)
> >> > + ? ? ? ? ? ? ? return result;
> >> > +
> >> > ? ? ? ?temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
> >> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > + ? ? ? return result;
> >> > ?}
> >> >
> >> > ?static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
> >> > ? ? ? ?/* Stop I2C transaction */
> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> > - ? ? ? temp &= ~I2CR_MSTA;
> >> > + ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
> >> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > - ? ? ? /* setup chip registers to defaults */
> >> > - ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
> >> > - ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
> >> > ? ? ? ?/*
> >> > ? ? ? ? * This delay caused by an i.MXL hardware bug.
> >> > ? ? ? ? * If no (or too short) delay, no "STOP" bit will be generated.
> >> > ? ? ? ? */
> >> > ? ? ? ?udelay(i2c_imx->disable_delay);
> >> > +
> >> > + ? ? ? i2c_imx_bus_busy(i2c_imx, 0);
> >> > +
> >> > ? ? ? ?/* Disable I2C controller */
> >> > ? ? ? ?writeb(0, i2c_imx->base + IMX_I2C_I2CR);
> >> > ?}
> >> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
> >> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> clear MSTA\n", __func__);
> >> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> > - ? ? ? ? ? ? ? ? ? ? ? temp &= ~I2CR_MSTA;
> >> > + ? ? ? ? ? ? ? ? ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
> >> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > ? ? ? ? ? ? ? ?} else if (i == (msgs->len - 2)) {
> >> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> >> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >> >
> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
> >> >
> >> > - ? ? ? /* Check if i2c bus is not busy */
> >> > - ? ? ? result = i2c_imx_bus_busy(i2c_imx);
> >> > + ? ? ? /* Start I2C transfer */
> >> > + ? ? ? result = i2c_imx_start(i2c_imx);
> >> > ? ? ? ?if (result)
> >> > ? ? ? ? ? ? ? ?goto fail0;
> >> >
> >> > - ? ? ? /* Start I2C transfer */
> >> > - ? ? ? i2c_imx_start(i2c_imx);
> >> > -
> >> > ? ? ? ?/* read/write data */
> >> > ? ? ? ?for (i = 0; i < num; i++) {
> >> > ? ? ? ? ? ? ? ?if (i) {
> >> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
> >> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
> >> > ? ? ? ? ? ? ? ? ? ? ? ?temp |= I2CR_RSTA;
> >> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
> >> > + ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
> >> > + ? ? ? ? ? ? ? ? ? ? ? if (result)
> >> > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
> >> > ? ? ? ? ? ? ? ?}
> >> > ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
> >> > ? ? ? ? ? ? ? ? ? ? ? ?"<%s> transfer message: %d\n", __func__, i);
> >> > --
> >> > 1.6.0.4
> >> >
> >> >
> >>
> >> Hi Sascha,
> >>
> >> So I assume you have no comments about this patch ?
> >
> > No, I'm still thinking about it. The commit message says *what* you're
> > doing, but not *why*. Is it a concrete bug that you fix or is it just
> > because it might be a good idea to do so?
> The driver doesn't work with mx51, which is a fast cpu. So I checked
> the driver, and find it didn't check IBB.

Ah, so 'make the driver work on i.MX51' is a good statement which should
be part of the commit message.

> > Also, we leave i2c_imx_xfer with the controller in a well defined state.
> > So if we leave this function with the controller in non busy state, why
> > do we have to check for non busy again when we enter it again?
> I2C is a multi-master bus.

So you say with this patch the driver becomes multi master capable? If
so, it should also be part of the commit message.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-01  9:52                 ` Sascha Hauer
@ 2009-10-01 14:54                     ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01 14:54 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

On Thu, Oct 1, 2009 at 5:52 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> On Thu, Oct 01, 2009 at 05:11:30PM +0800, Richard Zhao wrote:
>> On Thu, Oct 1, 2009 at 4:38 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
>> > On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
>> >> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> >> > After START/RESTART, wait for busy bit to be set and
>> >> > after STOP, wait for busy bit to be clear.
>> >> >
>> >> > Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> >> >
>> >> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> >> > index 4afba3e..156cc95 100644
>> >> > --- a/drivers/i2c/busses/i2c-imx.c
>> >> > +++ b/drivers/i2c/busses/i2c-imx.c
>> >> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
>> >> >  /** Functions for IMX I2C adapter driver ***************************************
>> >> >  *******************************************************************************/
>> >> >
>> >> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> >> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> >> >  {
>> >> >        unsigned long orig_jiffies = jiffies;
>> >> > +       unsigned int temp;
>> >> >
>> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> >
>> >> > -       /* wait for bus not busy */
>> >> > -       while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
>> >> > +       temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> >> > +       while (1) {
>> >> > +               if (for_busy && (temp & I2SR_IBB))
>> >> > +                       break;
>> >> > +               if (!for_busy && !(temp & I2SR_IBB))
>> >> > +                       break;
>> >> >                if (signal_pending(current)) {
>> >> >                        dev_dbg(&i2c_imx->adapter.dev,
>> >> >                                "<%s> I2C Interrupted\n", __func__);
>> >> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> >> >                        return -EIO;
>> >> >                }
>> >> >                schedule();
>> >> > +               temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> >> >        }
>> >> >
>> >> >        return 0;
>> >> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>> >> >        return 0;
>> >> >  }
>> >> >
>> >> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >> >  {
>> >> >        unsigned int temp = 0;
>> >> > +       int result;
>> >> >
>> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> >
>> >> >        /* Enable I2C controller */
>> >> > +       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> >> >        writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> >> > +
>> >> > +       result = i2c_imx_bus_busy(i2c_imx, 0);
>> >> > +       if (result)
>> >> > +               return result;
>> >> > +
>> >> >        /* Start I2C transaction */
>> >> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> >        temp |= I2CR_MSTA;
>> >> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > +       result = i2c_imx_bus_busy(i2c_imx, 1);
>> >> > +       if (result)
>> >> > +               return result;
>> >> > +
>> >> >        temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>> >> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > +       return result;
>> >> >  }
>> >> >
>> >> >  static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >> >        /* Stop I2C transaction */
>> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> >        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> > -       temp &= ~I2CR_MSTA;
>> >> > +       temp &= ~(I2CR_MSTA | I2CR_MTX);
>> >> >        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > -       /* setup chip registers to defaults */
>> >> > -       writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> >> > -       writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> >> >        /*
>> >> >         * This delay caused by an i.MXL hardware bug.
>> >> >         * If no (or too short) delay, no "STOP" bit will be generated.
>> >> >         */
>> >> >        udelay(i2c_imx->disable_delay);
>> >> > +
>> >> > +       i2c_imx_bus_busy(i2c_imx, 0);
>> >> > +
>> >> >        /* Disable I2C controller */
>> >> >        writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> >> >  }
>> >> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
>> >> >                        dev_dbg(&i2c_imx->adapter.dev,
>> >> >                                "<%s> clear MSTA\n", __func__);
>> >> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> > -                       temp &= ~I2CR_MSTA;
>> >> > +                       temp &= ~(I2CR_MSTA | I2CR_MTX);
>> >> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> >                } else if (i == (msgs->len - 2)) {
>> >> >                        dev_dbg(&i2c_imx->adapter.dev,
>> >> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >> >
>> >> >        dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> >
>> >> > -       /* Check if i2c bus is not busy */
>> >> > -       result = i2c_imx_bus_busy(i2c_imx);
>> >> > +       /* Start I2C transfer */
>> >> > +       result = i2c_imx_start(i2c_imx);
>> >> >        if (result)
>> >> >                goto fail0;
>> >> >
>> >> > -       /* Start I2C transfer */
>> >> > -       i2c_imx_start(i2c_imx);
>> >> > -
>> >> >        /* read/write data */
>> >> >        for (i = 0; i < num; i++) {
>> >> >                if (i) {
>> >> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >> >                        temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> >                        temp |= I2CR_RSTA;
>> >> >                        writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > +                       result =  i2c_imx_bus_busy(i2c_imx, 1);
>> >> > +                       if (result)
>> >> > +                               goto fail0;
>> >> >                }
>> >> >                dev_dbg(&i2c_imx->adapter.dev,
>> >> >                        "<%s> transfer message: %d\n", __func__, i);
>> >> > --
>> >> > 1.6.0.4
>> >> >
>> >> >
>> >>
>> >> Hi Sascha,
>> >>
>> >> So I assume you have no comments about this patch ?
>> >
>> > No, I'm still thinking about it. The commit message says *what* you're
>> > doing, but not *why*. Is it a concrete bug that you fix or is it just
>> > because it might be a good idea to do so?
>> The driver doesn't work with mx51, which is a fast cpu. So I checked
>> the driver, and find it didn't check IBB.
>
> Ah, so 'make the driver work on i.MX51' is a good statement which should
> be part of the commit message.
Well, maybe I can mention it.
But I think the good point is to present what you modified, not the side effect.
>
>> > Also, we leave i2c_imx_xfer with the controller in a well defined state.
>> > So if we leave this function with the controller in non busy state, why
>> > do we have to check for non busy again when we enter it again?
>> I2C is a multi-master bus.
>
> So you say with this patch the driver becomes multi master capable? If
> so, it should also be part of the commit message.
Yes. But I don't have multi-master system. So I can't say that.
The code is just taken from Freescale latest code. Without it, It
could also cause a device error. I forget the details.  Anyway, it
doesn't make anything wrong.

Thanks
Richard
>
> Sascha
>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01 14:54                     ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-01 14:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 5:52 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 05:11:30PM +0800, Richard Zhao wrote:
>> On Thu, Oct 1, 2009 at 4:38 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> > On Thu, Oct 01, 2009 at 04:03:20PM +0800, Richard Zhao wrote:
>> >> On Thu, Oct 1, 2009 at 9:13 AM, Richard Zhao <linuxzsc@gmail.com> wrote:
>> >> > After START/RESTART, wait for busy bit to be set and
>> >> > after STOP, wait for busy bit to be clear.
>> >> >
>> >> > Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>> >> >
>> >> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> >> > index 4afba3e..156cc95 100644
>> >> > --- a/drivers/i2c/busses/i2c-imx.c
>> >> > +++ b/drivers/i2c/busses/i2c-imx.c
>> >> > @@ -125,14 +125,19 @@ struct imx_i2c_struct {
>> >> > ?/** Functions for IMX I2C adapter driver ***************************************
>> >> > ?*******************************************************************************/
>> >> >
>> >> > -static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> >> > +static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>> >> > ?{
>> >> > ? ? ? ?unsigned long orig_jiffies = jiffies;
>> >> > + ? ? ? unsigned int temp;
>> >> >
>> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> >
>> >> > - ? ? ? /* wait for bus not busy */
>> >> > - ? ? ? while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
>> >> > + ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> >> > + ? ? ? while (1) {
>> >> > + ? ? ? ? ? ? ? if (for_busy && (temp & I2SR_IBB))
>> >> > + ? ? ? ? ? ? ? ? ? ? ? break;
>> >> > + ? ? ? ? ? ? ? if (!for_busy && !(temp & I2SR_IBB))
>> >> > + ? ? ? ? ? ? ? ? ? ? ? break;
>> >> > ? ? ? ? ? ? ? ?if (signal_pending(current)) {
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> I2C Interrupted\n", __func__);
>> >> > @@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?return -EIO;
>> >> > ? ? ? ? ? ? ? ?}
>> >> > ? ? ? ? ? ? ? ?schedule();
>> >> > + ? ? ? ? ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2SR);
>> >> > ? ? ? ?}
>> >> >
>> >> > ? ? ? ?return 0;
>> >> > @@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>> >> > ? ? ? ?return 0;
>> >> > ?}
>> >> >
>> >> > -static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >> > +static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >> > ?{
>> >> > ? ? ? ?unsigned int temp = 0;
>> >> > + ? ? ? int result;
>> >> >
>> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> >
>> >> > ? ? ? ?/* Enable I2C controller */
>> >> > + ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> >> > ? ? ? ?writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> >> > +
>> >> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
>> >> > + ? ? ? if (result)
>> >> > + ? ? ? ? ? ? ? return result;
>> >> > +
>> >> > ? ? ? ?/* Start I2C transaction */
>> >> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> > ? ? ? ?temp |= I2CR_MSTA;
>> >> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > + ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
>> >> > + ? ? ? if (result)
>> >> > + ? ? ? ? ? ? ? return result;
>> >> > +
>> >> > ? ? ? ?temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>> >> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > + ? ? ? return result;
>> >> > ?}
>> >> >
>> >> > ?static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >> > @@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >> > ? ? ? ?/* Stop I2C transaction */
>> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> > ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> > - ? ? ? temp &= ~I2CR_MSTA;
>> >> > + ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
>> >> > ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > - ? ? ? /* setup chip registers to defaults */
>> >> > - ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> >> > - ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> >> > ? ? ? ?/*
>> >> > ? ? ? ? * This delay caused by an i.MXL hardware bug.
>> >> > ? ? ? ? * If no (or too short) delay, no "STOP" bit will be generated.
>> >> > ? ? ? ? */
>> >> > ? ? ? ?udelay(i2c_imx->disable_delay);
>> >> > +
>> >> > + ? ? ? i2c_imx_bus_busy(i2c_imx, 0);
>> >> > +
>> >> > ? ? ? ?/* Disable I2C controller */
>> >> > ? ? ? ?writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> >> > ?}
>> >> > @@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"<%s> clear MSTA\n", __func__);
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> > - ? ? ? ? ? ? ? ? ? ? ? temp &= ~I2CR_MSTA;
>> >> > + ? ? ? ? ? ? ? ? ? ? ? temp &= ~(I2CR_MSTA | I2CR_MTX);
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > ? ? ? ? ? ? ? ?} else if (i == (msgs->len - 2)) {
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> >> > @@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >> >
>> >> > ? ? ? ?dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >> >
>> >> > - ? ? ? /* Check if i2c bus is not busy */
>> >> > - ? ? ? result = i2c_imx_bus_busy(i2c_imx);
>> >> > + ? ? ? /* Start I2C transfer */
>> >> > + ? ? ? result = i2c_imx_start(i2c_imx);
>> >> > ? ? ? ?if (result)
>> >> > ? ? ? ? ? ? ? ?goto fail0;
>> >> >
>> >> > - ? ? ? /* Start I2C transfer */
>> >> > - ? ? ? i2c_imx_start(i2c_imx);
>> >> > -
>> >> > ? ? ? ?/* read/write data */
>> >> > ? ? ? ?for (i = 0; i < num; i++) {
>> >> > ? ? ? ? ? ? ? ?if (i) {
>> >> > @@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?temp |= I2CR_RSTA;
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>> >> > + ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
>> >> > + ? ? ? ? ? ? ? ? ? ? ? if (result)
>> >> > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
>> >> > ? ? ? ? ? ? ? ?}
>> >> > ? ? ? ? ? ? ? ?dev_dbg(&i2c_imx->adapter.dev,
>> >> > ? ? ? ? ? ? ? ? ? ? ? ?"<%s> transfer message: %d\n", __func__, i);
>> >> > --
>> >> > 1.6.0.4
>> >> >
>> >> >
>> >>
>> >> Hi Sascha,
>> >>
>> >> So I assume you have no comments about this patch ?
>> >
>> > No, I'm still thinking about it. The commit message says *what* you're
>> > doing, but not *why*. Is it a concrete bug that you fix or is it just
>> > because it might be a good idea to do so?
>> The driver doesn't work with mx51, which is a fast cpu. So I checked
>> the driver, and find it didn't check IBB.
>
> Ah, so 'make the driver work on i.MX51' is a good statement which should
> be part of the commit message.
Well, maybe I can mention it.
But I think the good point is to present what you modified, not the side effect.
>
>> > Also, we leave i2c_imx_xfer with the controller in a well defined state.
>> > So if we leave this function with the controller in non busy state, why
>> > do we have to check for non busy again when we enter it again?
>> I2C is a multi-master bus.
>
> So you say with this patch the driver becomes multi master capable? If
> so, it should also be part of the commit message.
Yes. But I don't have multi-master system. So I can't say that.
The code is just taken from Freescale latest code. Without it, It
could also cause a device error. I forget the details.  Anyway, it
doesn't make anything wrong.

Thanks
Richard
>
> Sascha
>
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-01 14:54                     ` Richard Zhao
@ 2009-10-01 16:37                         ` Wolfram Sang
  -1 siblings, 0 replies; 52+ messages in thread
From: Wolfram Sang @ 2009-10-01 16:37 UTC (permalink / raw)
  To: Richard Zhao
  Cc: Sascha Hauer, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

> > Ah, so 'make the driver work on i.MX51' is a good statement which should
> > be part of the commit message.
> Well, maybe I can mention it.
> But I think the good point is to present what you modified, not the side effect.

It is not the side effect but the intention :) As no code is changed without a
need, the reason really should be in the patch description.

> Yes. But I don't have multi-master system. So I can't say that.
> The code is just taken from Freescale latest code. Without it, It
> could also cause a device error. I forget the details.  Anyway, it
> doesn't make anything wrong.

Do you know where the details are explained?

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-01 16:37                         ` Wolfram Sang
  0 siblings, 0 replies; 52+ messages in thread
From: Wolfram Sang @ 2009-10-01 16:37 UTC (permalink / raw)
  To: linux-arm-kernel

> > Ah, so 'make the driver work on i.MX51' is a good statement which should
> > be part of the commit message.
> Well, maybe I can mention it.
> But I think the good point is to present what you modified, not the side effect.

It is not the side effect but the intention :) As no code is changed without a
need, the reason really should be in the patch description.

> Yes. But I don't have multi-master system. So I can't say that.
> The code is just taken from Freescale latest code. Without it, It
> could also cause a device error. I forget the details.  Anyway, it
> doesn't make anything wrong.

Do you know where the details are explained?

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20091001/c5b3f439/attachment.sig>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-01 16:37                         ` Wolfram Sang
@ 2009-10-02  0:57                             ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-02  0:57 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Sascha Hauer, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
>> > Ah, so 'make the driver work on i.MX51' is a good statement which should
>> > be part of the commit message.
>> Well, maybe I can mention it.
>> But I think the good point is to present what you modified, not the side effect.
>
> It is not the side effect but the intention :) As no code is changed without a
> need, the reason really should be in the patch description.
No, it's not intention. I'm just trying to make the controller work in
a right way. Without this patch, maybe some other fast cpus have
problem too. I just tested mx31 and mx51. I will add "Without this
patch, i2c on some fast SoCs (for example imx51) will not work". Is it
ok for you?
>
>> Yes. But I don't have multi-master system. So I can't say that.
>> The code is just taken from Freescale latest code. Without it, It
>> could also cause a device error. I forget the details.  Anyway, it
>> doesn't make anything wrong.
>
> Do you know where the details are explained?
No, I don't. I don't have device in hand now. If you have, could you
please help do a simple test?
Use hw to simulate multi-master system. Before execute xfer, you first
pull down SDA, then pull down SDC. It simulates a START. and execute
xfer to see whether IBB is set?

Thanks
Richard
>
> Regards,
>
>   Wolfram
>
> --
> Pengutronix e.K.                           | Wolfram Sang                |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkrE2uEACgkQD27XaX1/VRumZQCeL4x9oaBKKjSKzJLlRrkfvvqg
> nlEAoLpQdpI3TeKEvK13rs46kSZRDsZU
> =7kM6
> -----END PGP SIGNATURE-----
>
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-02  0:57                             ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-02  0:57 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
>> > Ah, so 'make the driver work on i.MX51' is a good statement which should
>> > be part of the commit message.
>> Well, maybe I can mention it.
>> But I think the good point is to present what you modified, not the side effect.
>
> It is not the side effect but the intention :) As no code is changed without a
> need, the reason really should be in the patch description.
No, it's not intention. I'm just trying to make the controller work in
a right way. Without this patch, maybe some other fast cpus have
problem too. I just tested mx31 and mx51. I will add "Without this
patch, i2c on some fast SoCs (for example imx51) will not work". Is it
ok for you?
>
>> Yes. But I don't have multi-master system. So I can't say that.
>> The code is just taken from Freescale latest code. Without it, It
>> could also cause a device error. I forget the details. ?Anyway, it
>> doesn't make anything wrong.
>
> Do you know where the details are explained?
No, I don't. I don't have device in hand now. If you have, could you
please help do a simple test?
Use hw to simulate multi-master system. Before execute xfer, you first
pull down SDA, then pull down SDC. It simulates a START. and execute
xfer to see whether IBB is set?

Thanks
Richard
>
> Regards,
>
> ? Wolfram
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | Wolfram Sang ? ? ? ? ? ? ? ?|
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkrE2uEACgkQD27XaX1/VRumZQCeL4x9oaBKKjSKzJLlRrkfvvqg
> nlEAoLpQdpI3TeKEvK13rs46kSZRDsZU
> =7kM6
> -----END PGP SIGNATURE-----
>
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-02  0:57                             ` Richard Zhao
@ 2009-10-02  7:26                                 ` Sascha Hauer
  -1 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-02  7:26 UTC (permalink / raw)
  To: Richard Zhao
  Cc: Wolfram Sang, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Fri, Oct 02, 2009 at 08:57:04AM +0800, Richard Zhao wrote:
> On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> >> > Ah, so 'make the driver work on i.MX51' is a good statement which should
> >> > be part of the commit message.
> >> Well, maybe I can mention it.
> >> But I think the good point is to present what you modified, not the side effect.
> >
> > It is not the side effect but the intention :) As no code is changed without a
> > need, the reason really should be in the patch description.
> No, it's not intention. I'm just trying to make the controller work in
> a right way. Without this patch, maybe some other fast cpus have
> problem too. I just tested mx31 and mx51. I will add "Without this
> patch, i2c on some fast SoCs (for example imx51) will not work". Is it
> ok for you?

Please remember that we do not have i.MX51 support in mainline, so this
is irrelevant atm.

> >
> >> Yes. But I don't have multi-master system. So I can't say that.
> >> The code is just taken from Freescale latest code. Without it, It
> >> could also cause a device error. I forget the details.  Anyway, it
> >> doesn't make anything wrong.
> >
> > Do you know where the details are explained?
> No, I don't. I don't have device in hand now. If you have, could you
> please help do a simple test?
> Use hw to simulate multi-master system. Before execute xfer, you first
> pull down SDA, then pull down SDC. It simulates a START. and execute
> xfer to see whether IBB is set?

No, we won't do any tests on hardware.

At the moment we have a driver which is not multi master capable.
Looking at the datasheet the change you do seems not enough to change
this. So we should take a patch which changes something from which you
think it might be needed? And you don't even have the details at hand?

No.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-02  7:26                                 ` Sascha Hauer
  0 siblings, 0 replies; 52+ messages in thread
From: Sascha Hauer @ 2009-10-02  7:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Oct 02, 2009 at 08:57:04AM +0800, Richard Zhao wrote:
> On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
> >> > Ah, so 'make the driver work on i.MX51' is a good statement which should
> >> > be part of the commit message.
> >> Well, maybe I can mention it.
> >> But I think the good point is to present what you modified, not the side effect.
> >
> > It is not the side effect but the intention :) As no code is changed without a
> > need, the reason really should be in the patch description.
> No, it's not intention. I'm just trying to make the controller work in
> a right way. Without this patch, maybe some other fast cpus have
> problem too. I just tested mx31 and mx51. I will add "Without this
> patch, i2c on some fast SoCs (for example imx51) will not work". Is it
> ok for you?

Please remember that we do not have i.MX51 support in mainline, so this
is irrelevant atm.

> >
> >> Yes. But I don't have multi-master system. So I can't say that.
> >> The code is just taken from Freescale latest code. Without it, It
> >> could also cause a device error. I forget the details. ?Anyway, it
> >> doesn't make anything wrong.
> >
> > Do you know where the details are explained?
> No, I don't. I don't have device in hand now. If you have, could you
> please help do a simple test?
> Use hw to simulate multi-master system. Before execute xfer, you first
> pull down SDA, then pull down SDC. It simulates a START. and execute
> xfer to see whether IBB is set?

No, we won't do any tests on hardware.

At the moment we have a driver which is not multi master capable.
Looking at the datasheet the change you do seems not enough to change
this. So we should take a patch which changes something from which you
think it might be needed? And you don't even have the details at hand?

No.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-02  7:26                                 ` Sascha Hauer
@ 2009-10-02  8:17                                     ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-02  8:17 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: Wolfram Sang, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Fri, Oct 2, 2009 at 3:26 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> On Fri, Oct 02, 2009 at 08:57:04AM +0800, Richard Zhao wrote:
>> On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
>> >> > Ah, so 'make the driver work on i.MX51' is a good statement which should
>> >> > be part of the commit message.
>> >> Well, maybe I can mention it.
>> >> But I think the good point is to present what you modified, not the side effect.
>> >
>> > It is not the side effect but the intention :) As no code is changed without a
>> > need, the reason really should be in the patch description.
>> No, it's not intention. I'm just trying to make the controller work in
>> a right way. Without this patch, maybe some other fast cpus have
>> problem too. I just tested mx31 and mx51. I will add "Without this
>> patch, i2c on some fast SoCs (for example imx51) will not work". Is it
>> ok for you?
>
> Please remember that we do not have i.MX51 support in mainline, so this
> is irrelevant atm.
So I don't need to meantion mx51? "Without this patch, i2c on some
fast SoCs will not work" is all right?
>
>> >
>> >> Yes. But I don't have multi-master system. So I can't say that.
>> >> The code is just taken from Freescale latest code. Without it, It
>> >> could also cause a device error. I forget the details.  Anyway, it
>> >> doesn't make anything wrong.
>> >
>> > Do you know where the details are explained?
>> No, I don't. I don't have device in hand now. If you have, could you
>> please help do a simple test?
>> Use hw to simulate multi-master system. Before execute xfer, you first
>> pull down SDA, then pull down SDC. It simulates a START. and execute
>> xfer to see whether IBB is set?
>
> No, we won't do any tests on hardware.
>
> At the moment we have a driver which is not multi master capable.
> Looking at the datasheet the change you do seems not enough to change
> this. So we should take a patch which changes something from which you
> think it might be needed? And you don't even have the details at hand?
>
> No.
Ok, It seems I have no reason to keep the busy wait before START.
Wolfram, do you agree to remove the busy wait? I saw you submmited the
original driver.
Let get away from multi-master. There's nearly no multi-master i2c bus
system in reality.

Thanks
Richard
>
> Sascha
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-02  8:17                                     ` Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-02  8:17 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Oct 2, 2009 at 3:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Fri, Oct 02, 2009 at 08:57:04AM +0800, Richard Zhao wrote:
>> On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
>> >> > Ah, so 'make the driver work on i.MX51' is a good statement which should
>> >> > be part of the commit message.
>> >> Well, maybe I can mention it.
>> >> But I think the good point is to present what you modified, not the side effect.
>> >
>> > It is not the side effect but the intention :) As no code is changed without a
>> > need, the reason really should be in the patch description.
>> No, it's not intention. I'm just trying to make the controller work in
>> a right way. Without this patch, maybe some other fast cpus have
>> problem too. I just tested mx31 and mx51. I will add "Without this
>> patch, i2c on some fast SoCs (for example imx51) will not work". Is it
>> ok for you?
>
> Please remember that we do not have i.MX51 support in mainline, so this
> is irrelevant atm.
So I don't need to meantion mx51? "Without this patch, i2c on some
fast SoCs will not work" is all right?
>
>> >
>> >> Yes. But I don't have multi-master system. So I can't say that.
>> >> The code is just taken from Freescale latest code. Without it, It
>> >> could also cause a device error. I forget the details. ?Anyway, it
>> >> doesn't make anything wrong.
>> >
>> > Do you know where the details are explained?
>> No, I don't. I don't have device in hand now. If you have, could you
>> please help do a simple test?
>> Use hw to simulate multi-master system. Before execute xfer, you first
>> pull down SDA, then pull down SDC. It simulates a START. and execute
>> xfer to see whether IBB is set?
>
> No, we won't do any tests on hardware.
>
> At the moment we have a driver which is not multi master capable.
> Looking at the datasheet the change you do seems not enough to change
> this. So we should take a patch which changes something from which you
> think it might be needed? And you don't even have the details at hand?
>
> No.
Ok, It seems I have no reason to keep the busy wait before START.
Wolfram, do you agree to remove the busy wait? I saw you submmited the
original driver.
Let get away from multi-master. There's nearly no multi-master i2c bus
system in reality.

Thanks
Richard
>
> Sascha
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* Re: [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-02  8:17                                     ` Richard Zhao
@ 2009-10-02 14:11                                         ` Wolfram Sang
  -1 siblings, 0 replies; 52+ messages in thread
From: Wolfram Sang @ 2009-10-02 14:11 UTC (permalink / raw)
  To: Richard Zhao
  Cc: Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ, linux-i2c-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 2264 bytes --]

On Fri, Oct 02, 2009 at 04:17:09PM +0800, Richard Zhao wrote:
> On Fri, Oct 2, 2009 at 3:26 PM, Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> > On Fri, Oct 02, 2009 at 08:57:04AM +0800, Richard Zhao wrote:
> >> On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> >> >> > Ah, so 'make the driver work on i.MX51' is a good statement which should
> >> >> > be part of the commit message.
> >> >> Well, maybe I can mention it.
> >> >> But I think the good point is to present what you modified, not the side effect.
> >> >
> >> > It is not the side effect but the intention :) As no code is changed without a
> >> > need, the reason really should be in the patch description.
> >> No, it's not intention. I'm just trying to make the controller work in
> >> a right way. Without this patch, maybe some other fast cpus have
> >> problem too. I just tested mx31 and mx51. I will add "Without this
> >> patch, i2c on some fast SoCs (for example imx51) will not work". Is it
> >> ok for you?
> >
> > Please remember that we do not have i.MX51 support in mainline, so this
> > is irrelevant atm.
> So I don't need to meantion mx51? "Without this patch, i2c on some
> fast SoCs will not work" is all right?

Sounds good to me!

> > At the moment we have a driver which is not multi master capable.
> > Looking at the datasheet the change you do seems not enough to change
> > this. So we should take a patch which changes something from which you
> > think it might be needed? And you don't even have the details at hand?
> >
> > No.
> Ok, It seems I have no reason to keep the busy wait before START.
> Wolfram, do you agree to remove the busy wait?

If somebody really needs multi-master and is able to test it, then it can be
reimplemented (but as said, this needs a lot more changes). Have to have a
closer look though, if it may detect a stalled bus.

> I saw you submmited the original driver.

I helped in getting it accepted, but the commit is mainly from Darius.

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-10-02 14:11                                         ` Wolfram Sang
  0 siblings, 0 replies; 52+ messages in thread
From: Wolfram Sang @ 2009-10-02 14:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Oct 02, 2009 at 04:17:09PM +0800, Richard Zhao wrote:
> On Fri, Oct 2, 2009 at 3:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > On Fri, Oct 02, 2009 at 08:57:04AM +0800, Richard Zhao wrote:
> >> On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
> >> >> > Ah, so 'make the driver work on i.MX51' is a good statement which should
> >> >> > be part of the commit message.
> >> >> Well, maybe I can mention it.
> >> >> But I think the good point is to present what you modified, not the side effect.
> >> >
> >> > It is not the side effect but the intention :) As no code is changed without a
> >> > need, the reason really should be in the patch description.
> >> No, it's not intention. I'm just trying to make the controller work in
> >> a right way. Without this patch, maybe some other fast cpus have
> >> problem too. I just tested mx31 and mx51. I will add "Without this
> >> patch, i2c on some fast SoCs (for example imx51) will not work". Is it
> >> ok for you?
> >
> > Please remember that we do not have i.MX51 support in mainline, so this
> > is irrelevant atm.
> So I don't need to meantion mx51? "Without this patch, i2c on some
> fast SoCs will not work" is all right?

Sounds good to me!

> > At the moment we have a driver which is not multi master capable.
> > Looking at the datasheet the change you do seems not enough to change
> > this. So we should take a patch which changes something from which you
> > think it might be needed? And you don't even have the details at hand?
> >
> > No.
> Ok, It seems I have no reason to keep the busy wait before START.
> Wolfram, do you agree to remove the busy wait?

If somebody really needs multi-master and is able to test it, then it can be
reimplemented (but as said, this needs a lot more changes). Have to have a
closer look though, if it may detect a stalled bus.

> I saw you submmited the original driver.

I helped in getting it accepted, but the commit is mainly from Darius.

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20091002/81cecc6c/attachment.sig>

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
  2009-10-02 14:11                                         ` Wolfram Sang
  (?)
@ 2009-10-04 12:22                                         ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-04 12:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Oct 2, 2009 at 10:11 PM, Wolfram Sang <w.sang@pengutronix.de> wrote:
> On Fri, Oct 02, 2009 at 04:17:09PM +0800, Richard Zhao wrote:
>> On Fri, Oct 2, 2009 at 3:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> > On Fri, Oct 02, 2009 at 08:57:04AM +0800, Richard Zhao wrote:
>> >> On Fri, Oct 2, 2009 at 12:37 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
>> >> >> > Ah, so 'make the driver work on i.MX51' is a good statement which should
>> >> >> > be part of the commit message.
>> >> >> Well, maybe I can mention it.
>> >> >> But I think the good point is to present what you modified, not the side effect.
>> >> >
>> >> > It is not the side effect but the intention :) As no code is changed without a
>> >> > need, the reason really should be in the patch description.
>> >> No, it's not intention. I'm just trying to make the controller work in
>> >> a right way. Without this patch, maybe some other fast cpus have
>> >> problem too. I just tested mx31 and mx51. I will add "Without this
>> >> patch, i2c on some fast SoCs (for example imx51) will not work". Is it
>> >> ok for you?
>> >
>> > Please remember that we do not have i.MX51 support in mainline, so this
>> > is irrelevant atm.
>> So I don't need to meantion mx51? "Without this patch, i2c on some
>> fast SoCs will not work" is all right?
>
> Sounds good to me!
>
>> > At the moment we have a driver which is not multi master capable.
>> > Looking at the datasheet the change you do seems not enough to change
>> > this. So we should take a patch which changes something from which you
>> > think it might be needed? And you don't even have the details at hand?
>> >
>> > No.
>> Ok, It seems I have no reason to keep the busy wait before START.
>> Wolfram, do you agree to remove the busy wait?
>
> If somebody really needs multi-master and is able to test it, then it can be
> reimplemented (but as said, this needs a lot more changes). Have to have a
> closer look though, if it may detect a stalled bus.
>
>> I saw you submmited the original driver.
>
> I helped in getting it accepted, but the commit is mainly from Darius.
>
> Regards,
>
> ? Wolfram
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | Wolfram Sang ? ? ? ? ? ? ? ?|
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkrGCfoACgkQD27XaX1/VRtdtQCfQY/HExUvAyQbilCV+F83UZZ4
> /ZQAnicn78e46mlqE3Z/9xXFMW8B2QCA
> =qYV9
> -----END PGP SIGNATURE-----
>
>

Let me sumerize the comments:
1. Sascha, Wolfram: tell why add IBB check in commit message. Add
something like "Without this patch, i2c on some fast SoCs will not
work". Agree
2. Sascha: Remove IBB check before START.  Agree.
3. Andrew: Optimize the busy wait loop. Agree.

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 3/4] i2c: imx: add macros and printk to make debug easy
  2009-10-01  9:30                         ` Richard Zhao
  (?)
@ 2009-10-04 12:23                         ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-04 12:23 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 5:30 PM, Richard Zhao <linuxzsc@gmail.com> wrote:
> On Thu, Oct 1, 2009 at 4:26 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> On Thu, Oct 01, 2009 at 04:01:50PM +0800, Richard Zhao wrote:
>>> On Thu, Oct 1, 2009 at 3:29 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>>> > On Thu, Oct 01, 2009 at 09:13:32AM +0800, Richard Zhao wrote:
>>> >> When CONFIG_I2C_DEBUG_BUS is enabled, it helps dump registers at operation
>>> >> fail condition, and print i2c_msg to xfer.
>>> >>
>>> >> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>>> >
>>> > Honestly I don't think we need this. It makes the driver too verbose for
>>> > my taste.
>>> >
>>> > Sascha
>>> >
>>> >
>>> >>
>>> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>>> >> index c1e541c..87faea4 100644
>>> >> --- a/drivers/i2c/busses/i2c-imx.c
>>> >> +++ b/drivers/i2c/busses/i2c-imx.c
>>> >> @@ -125,6 +125,20 @@ struct imx_i2c_struct {
>>> >> ?/** Functions for IMX I2C adapter driver ***************************************
>>> >> ?*******************************************************************************/
>>> >>
>>> >> +#ifdef CONFIG_I2C_DEBUG_BUS
>>> >> +#define reg_dump(i2c_imx) \
>>> >> +{ \
>>> >> + ? ? printk(KERN_DEBUG "fun %s:%d ", __func__, __LINE__); \
>>> >> + ? ? printk(KERN_DEBUG "IADR %02x IFDR %02x I2CR %02x I2SR %02x\n", \
>>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IADR), \
>>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_IFDR), \
>>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2CR), \
>>> >> + ? ? ? ? ? ? readb(i2c_imx->base + IMX_I2C_I2SR)); \
>>> >> +}
>>> >> +#else
>>> >> +#define reg_dump(i2c_imx)
>>> >> +#endif
>>> >> +
>>> >> ?static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>>> >> ?{
>>> >> ? ? ? unsigned long orig_jiffies = jiffies;
>>> >> @@ -146,6 +160,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
>>> >> ? ? ? ? ? ? ? if (time_after(jiffies, orig_jiffies + HZ / 1000)) {
>>> >> ? ? ? ? ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
>>> >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "<%s> I2C bus is busy\n", __func__);
>>> >> + ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >> ? ? ? ? ? ? ? ? ? ? ? return -EIO;
>>> >> ? ? ? ? ? ? ? }
>>> >> ? ? ? ? ? ? ? schedule();
>>> >> @@ -164,9 +179,11 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
>>> >>
>>> >> ? ? ? if (unlikely(result < 0)) {
>>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
>>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >> ? ? ? ? ? ? ? return result;
>>> >> ? ? ? } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
>>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
>>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >> ? ? ? ? ? ? ? return -ETIMEDOUT;
>>> >> ? ? ? }
>>> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__);
>>> >> @@ -178,6 +195,7 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
>>> >> ?{
>>> >> ? ? ? if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) {
>>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
>>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >> ? ? ? ? ? ? ? return -EIO; ?/* No ACK */
>>> >> ? ? ? }
>>> >>
>>> >> @@ -197,17 +215,20 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>>> >> ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>>> >>
>>> >> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 0);
>>> >> - ? ? if (result)
>>> >> + ? ? if (result) {
>>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >> ? ? ? ? ? ? ? return result;
>>> >> + ? ? }
>>> >>
>>> >> ? ? ? /* Start I2C transaction */
>>> >> ? ? ? temp = readb(i2c_imx->base + IMX_I2C_I2CR);
>>> >> ? ? ? temp |= I2CR_MSTA;
>>> >> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>>> >> ? ? ? result = i2c_imx_bus_busy(i2c_imx, 1);
>>> >> - ? ? if (result)
>>> >> + ? ? if (result) {
>>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >> ? ? ? ? ? ? ? return result;
>>> >> -
>>> >> + ? ? }
>>> >> ? ? ? temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
>>> >> ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>>> >> ? ? ? return result;
>>> >> @@ -228,7 +249,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>>> >> ? ? ? ?*/
>>> >> ? ? ? udelay(i2c_imx->disable_delay);
>>> >>
>>> >> - ? ? i2c_imx_bus_busy(i2c_imx, 0);
>>> >> + ? ? if (i2c_imx_bus_busy(i2c_imx, 0))
>>> >> + ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >>
>>> >> ? ? ? /* Disable I2C controller */
>>> >> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>>> >> @@ -389,7 +411,18 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>>> >> ? ? ? struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>>> >>
>>> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>>> >> -
>>> >> +#ifdef CONFIG_I2C_DEBUG_BUS
>>> >> + ? ? for (i = 0; i < num; i++) {
>>> >> + ? ? ? ? ? ? printk(KERN_DEBUG "msg%d addr %02x RD %d cnt %d d:", i,
>>> >> + ? ? ? ? ? ? ? ? ? ? msgs[i].addr, msgs[i].flags & I2C_M_RD, msgs[i].len);
>>> >> + ? ? ? ? ? ? if (!(msgs[i].flags & I2C_M_RD)) {
>>> >> + ? ? ? ? ? ? ? ? ? ? int j;
>>> >> + ? ? ? ? ? ? ? ? ? ? for (j = 0; j < msgs[i].len; j++)
>>> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? printk("%02x ", msgs[i].buf[j]);
>>> >> + ? ? ? ? ? ? }
>>> >> + ? ? ? ? ? ? printk("\n");
>>> >> + ? ? }
>>> >> +#endif
>>> >> ? ? ? /* Start I2C transfer */
>>> >> ? ? ? result = i2c_imx_start(i2c_imx);
>>> >> ? ? ? if (result)
>>> >> @@ -404,8 +437,10 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>>> >> ? ? ? ? ? ? ? ? ? ? ? temp |= I2CR_RSTA;
>>> >> ? ? ? ? ? ? ? ? ? ? ? writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
>>> >> ? ? ? ? ? ? ? ? ? ? ? result = ?i2c_imx_bus_busy(i2c_imx, 1);
>>> >> - ? ? ? ? ? ? ? ? ? ? if (result)
>>> >> + ? ? ? ? ? ? ? ? ? ? if (result) {
>>> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? reg_dump(i2c_imx);
>>> >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto fail0;
>>> >> + ? ? ? ? ? ? ? ? ? ? }
>>> >> ? ? ? ? ? ? ? }
>>> >> ? ? ? ? ? ? ? dev_dbg(&i2c_imx->adapter.dev,
>>> >> ? ? ? ? ? ? ? ? ? ? ? "<%s> transfer message: %d\n", __func__, i);
>>> >> @@ -562,7 +597,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>>> >> ? ? ? ? ? ? ? res_size, i2c_imx->res->start);
>>> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
>>> >> ? ? ? ? ? ? ? i2c_imx->adapter.name);
>>> >> - ? ? dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>>> >> + ? ? dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
>>> >>
>>> >> ? ? ? return 0; ? /* Return OK */
>>> >>
>>> >> --
>>> >> 1.6.0.4
>>> >>
>>> >>
>>> >
>>> > --
>>> > Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
>>> > Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
>>> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
>>> > Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>>> >
>>>
>>> 1. i2c is more important bus in embedded system than PC. Many PMICs
>>> are connected to cpu via i2c. Before system boot up, we depend much on
>>> printk message.
>>> 2. When we add a new i2c device, it's easy to have problems. Maybe
>>> it's hw issue, one device fails, all ones in the same bus fails. In
>>> such condition, debug message is very helpfull.
>>
>> The driver already consists to 15% of debug statements, there is
>> definitely no need to add even more. If anything, you could concentrate
>> on making the output more useful.
> The dump_reg are only added when operation fails. It's not used to
> track function call path or anything else.
> I'm not supposed to show detailed message when there's operation fail?
> The reason to add a switch to disable it is, when i2c tools scan the
> bus, it will cause operation fail.
>
> Richard
>>
>> Sascha
>>
>> --
>> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
>> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
>> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
>> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>>
>

Hi Sascha,

Follow your suggestion. I will remove the patch.

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 4/4] i2c: imx: disable clock when it's possible to save power.
  2009-10-01  8:00                         ` Sascha Hauer
  (?)
@ 2009-10-04 12:30                         ` Richard Zhao
  -1 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-10-04 12:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Oct 1, 2009 at 4:00 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Oct 01, 2009 at 03:56:29PM +0800, Richard Zhao wrote:
>> On Thu, Oct 1, 2009 at 3:34 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> > On Thu, Oct 01, 2009 at 09:13:33AM +0800, Richard Zhao wrote:
>> >> Enable clock before START, disable it after STOP.
>> >
>> > The clk_diable/enable calls in suspend/resume should be removed also.
>> >
>> > Sascha
>> >
>> >>
>> >> Signed-off-by: Richard Zhao <linuxzsc@gmail.com>
>> >>
>> >> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> >> index 87faea4..72ddea3 100644
>> >> --- a/drivers/i2c/busses/i2c-imx.c
>> >> +++ b/drivers/i2c/busses/i2c-imx.c
>> >> @@ -120,6 +120,7 @@ struct imx_i2c_struct {
>> >> ? ? ? wait_queue_head_t ? ? ? queue;
>> >> ? ? ? unsigned long ? ? ? ? ? i2csr;
>> >> ? ? ? unsigned int ? ? ? ? ? ?disable_delay;
>> >> + ? ? unsigned int ? ? ? ? ? ?ifdr; /* IMX_I2C_IFDR */
>> >> ?};
>> >>
>> >> ?/** Functions for IMX I2C adapter driver ***************************************
>> >> @@ -210,6 +211,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
>> >>
>> >> ? ? ? dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>> >>
>> >> + ? ? clk_enable(i2c_imx->clk);
>> >> + ? ? writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
>> >> ? ? ? /* Enable I2C controller */
>> >> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2SR);
>> >> ? ? ? writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
>> >> @@ -254,6 +257,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
>> >>
>> >> ? ? ? /* Disable I2C controller */
>> >> ? ? ? writeb(0, i2c_imx->base + IMX_I2C_I2CR);
>> >> + ? ? clk_disable(i2c_imx->clk);
>> >> ?}
>> >>
>> >> ?static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>> >> @@ -273,8 +277,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
>> >> ? ? ? else
>> >> ? ? ? ? ? ? ? for (i = 0; i2c_clk_div[i][0] < div; i++);
>> >>
>> >> - ? ? /* Write divider value to register */
>> >> - ? ? writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR);
>> >> + ? ? /* Store divider value */
>> >> + ? ? i2c_imx->ifdr = i2c_clk_div[i][1];
>> >>
>> >> ? ? ? if (cpu_is_mx1()) {
>> >> ? ? ? ? ? ? ? /*
>> >> @@ -555,7 +559,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>> >> ? ? ? ? ? ? ? dev_err(&pdev->dev, "can't get I2C clock\n");
>> >> ? ? ? ? ? ? ? goto fail3;
>> >> ? ? ? }
>> >> - ? ? clk_enable(i2c_imx->clk);
>> >>
>> >> ? ? ? /* Request IRQ */
>> >> ? ? ? ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
>> >> @@ -604,7 +607,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
>> >> ?fail5:
>> >> ? ? ? free_irq(i2c_imx->irq, i2c_imx);
>> >> ?fail4:
>> >> - ? ? clk_disable(i2c_imx->clk);
>> >> ? ? ? clk_put(i2c_imx->clk);
>> >> ?fail3:
>> >> ? ? ? release_mem_region(i2c_imx->res->start, resource_size(res));
>> >> @@ -641,8 +643,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
>> >> ? ? ? if (pdata && pdata->exit)
>> >> ? ? ? ? ? ? ? pdata->exit(&pdev->dev);
>> >>
>> >> - ? ? /* Disable I2C clock */
>> >> - ? ? clk_disable(i2c_imx->clk);
>> >> ? ? ? clk_put(i2c_imx->clk);
>> >>
>> >> ? ? ? release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
>> >> --
>> >> 1.6.0.4
>> >>
>> >>
>> >
>> > --
>> > Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
>> > Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
>> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
>> > Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>> >
>>
>> I don't think we have any suspend/resume routine. And we won't need it any more.
>
> Ups, my bad. I have it in my local tree and didn't realize it isn't
> upstream.
>
> Sascha
>
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
>

Hi Sascha,

Do I need re-send this patch when I re-send out other patches?

Thanks
Richard

^ permalink raw reply	[flat|nested] 52+ messages in thread

* [PATCH 1/4] i2c: imx: check busy bit when START/STOP
@ 2009-09-30  5:55 Richard Zhao
  0 siblings, 0 replies; 52+ messages in thread
From: Richard Zhao @ 2009-09-30  5:55 UTC (permalink / raw)
  To: kernel-bIcnvbaLZ9MEGnE8C9+IrQ
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Richard Zhao

After START/RESTART, wait for busy bit to be set and
after STOP, wait for busy bit to be clear.

Signed-off-by: Richard Zhao <linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 4afba3e..156cc95 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -125,14 +125,19 @@ struct imx_i2c_struct {
 /** Functions for IMX I2C adapter driver ***************************************
 *******************************************************************************/
 
-static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
+static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 {
 	unsigned long orig_jiffies = jiffies;
+	unsigned int temp;
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
-	/* wait for bus not busy */
-	while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) {
+	temp = readb(i2c_imx->base + IMX_I2C_I2SR);
+	while (1) {
+		if (for_busy && (temp & I2SR_IBB))
+			break;
+		if (!for_busy && !(temp & I2SR_IBB))
+			break;
 		if (signal_pending(current)) {
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> I2C Interrupted\n", __func__);
@@ -144,6 +149,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx)
 			return -EIO;
 		}
 		schedule();
+		temp = readb(i2c_imx->base + IMX_I2C_I2SR);
 	}
 
 	return 0;
@@ -179,20 +185,32 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
 	return 0;
 }
 
-static void i2c_imx_start(struct imx_i2c_struct *i2c_imx)
+static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
 {
 	unsigned int temp = 0;
+	int result;
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
 	/* Enable I2C controller */
+	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
+
+	result = i2c_imx_bus_busy(i2c_imx, 0);
+	if (result)
+		return result;
+
 	/* Start I2C transaction */
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 	temp |= I2CR_MSTA;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+	result = i2c_imx_bus_busy(i2c_imx, 1);
+	if (result)
+		return result;
+
 	temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+	return result;
 }
 
 static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
@@ -202,16 +220,16 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
 	/* Stop I2C transaction */
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 	temp = readb(i2c_imx->base + IMX_I2C_I2CR);
-	temp &= ~I2CR_MSTA;
+	temp &= ~(I2CR_MSTA | I2CR_MTX);
 	writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
-	/* setup chip registers to defaults */
-	writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
-	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 	/*
 	 * This delay caused by an i.MXL hardware bug.
 	 * If no (or too short) delay, no "STOP" bit will be generated.
 	 */
 	udelay(i2c_imx->disable_delay);
+
+	i2c_imx_bus_busy(i2c_imx, 0);
+
 	/* Disable I2C controller */
 	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
 }
@@ -344,7 +362,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> clear MSTA\n", __func__);
 			temp = readb(i2c_imx->base + IMX_I2C_I2CR);
-			temp &= ~I2CR_MSTA;
+			temp &= ~(I2CR_MSTA | I2CR_MTX);
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
 		} else if (i == (msgs->len - 2)) {
 			dev_dbg(&i2c_imx->adapter.dev,
@@ -370,14 +388,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
-	/* Check if i2c bus is not busy */
-	result = i2c_imx_bus_busy(i2c_imx);
+	/* Start I2C transfer */
+	result = i2c_imx_start(i2c_imx);
 	if (result)
 		goto fail0;
 
-	/* Start I2C transfer */
-	i2c_imx_start(i2c_imx);
-
 	/* read/write data */
 	for (i = 0; i < num; i++) {
 		if (i) {
@@ -386,6 +401,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 			temp = readb(i2c_imx->base + IMX_I2C_I2CR);
 			temp |= I2CR_RSTA;
 			writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
+			result =  i2c_imx_bus_busy(i2c_imx, 1);
+			if (result)
+				goto fail0;
 		}
 		dev_dbg(&i2c_imx->adapter.dev,
 			"<%s> transfer message: %d\n", __func__, i);
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 52+ messages in thread

end of thread, other threads:[~2009-10-04 12:30 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-01  1:13 [PATCH 1/4] i2c: imx: check busy bit when START/STOP Richard Zhao
2009-10-01  1:13 ` Richard Zhao
     [not found] ` <1254359613-21210-1-git-send-email-linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-10-01  1:13   ` [PATCH 2/4] i2c: imx: only imx1 needs disable delay Richard Zhao
2009-10-01  1:13     ` Richard Zhao
     [not found]     ` <1254359613-21210-2-git-send-email-linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-10-01  1:13       ` [PATCH 3/4] i2c: imx: add macros and printk to make debug easy Richard Zhao
2009-10-01  1:13         ` Richard Zhao
     [not found]         ` <1254359613-21210-3-git-send-email-linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-10-01  1:13           ` [PATCH 4/4] i2c: imx: disable clock when it's possible to save power Richard Zhao
2009-10-01  1:13             ` Richard Zhao
     [not found]             ` <1254359613-21210-4-git-send-email-linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-10-01  7:34               ` Sascha Hauer
2009-10-01  7:34                 ` Sascha Hauer
     [not found]                 ` <20091001073434.GY27039-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-10-01  7:56                   ` Richard Zhao
2009-10-01  7:56                     ` Richard Zhao
     [not found]                     ` <4e090d470910010056n56bff9f4l1fec703c2dde9edf-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-01  8:00                       ` Sascha Hauer
2009-10-01  8:00                         ` Sascha Hauer
2009-10-04 12:30                         ` Richard Zhao
2009-10-01  7:29           ` [PATCH 3/4] i2c: imx: add macros and printk to make debug easy Sascha Hauer
2009-10-01  7:29             ` Sascha Hauer
     [not found]             ` <20091001072934.GX27039-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-10-01  8:01               ` Richard Zhao
2009-10-01  8:01                 ` Richard Zhao
     [not found]                 ` <4e090d470910010101r6839cc9ax4fe84f04a1afbb00-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-01  8:26                   ` Sascha Hauer
2009-10-01  8:26                     ` Sascha Hauer
     [not found]                     ` <20091001082610.GB27039-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-10-01  9:30                       ` Richard Zhao
2009-10-01  9:30                         ` Richard Zhao
2009-10-04 12:23                         ` Richard Zhao
2009-10-01  7:26       ` [PATCH 2/4] i2c: imx: only imx1 needs disable delay Sascha Hauer
2009-10-01  7:26         ` Sascha Hauer
2009-10-01  7:52         ` Richard Zhao
2009-10-01  7:52           ` Richard Zhao
     [not found]           ` <4e090d470910010052k37a0a4eep6d436e45e6524234-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-01  7:57             ` Sascha Hauer
2009-10-01  7:57               ` Sascha Hauer
2009-10-01  8:03   ` [PATCH 1/4] i2c: imx: check busy bit when START/STOP Richard Zhao
2009-10-01  8:03     ` Richard Zhao
     [not found]     ` <4e090d470910010103o611d9fb2t3acf93632216fc88-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-01  8:38       ` Sascha Hauer
2009-10-01  8:38         ` Sascha Hauer
     [not found]         ` <20091001083831.GD27039-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-10-01  9:11           ` Richard Zhao
2009-10-01  9:11             ` Richard Zhao
     [not found]             ` <4e090d470910010211k4ce78763i1a5163ec6ea57fe8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-01  9:52               ` Sascha Hauer
2009-10-01  9:52                 ` Sascha Hauer
     [not found]                 ` <20091001095239.GE27039-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-10-01 14:54                   ` Richard Zhao
2009-10-01 14:54                     ` Richard Zhao
     [not found]                     ` <4e090d470910010754r1ebc4455u6220ccfd803491b0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-01 16:37                       ` Wolfram Sang
2009-10-01 16:37                         ` Wolfram Sang
     [not found]                         ` <20091001163753.GA20103-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-10-02  0:57                           ` Richard Zhao
2009-10-02  0:57                             ` Richard Zhao
     [not found]                             ` <4e090d470910011757g261c693ehdca40ce43ebee2ec-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-02  7:26                               ` Sascha Hauer
2009-10-02  7:26                                 ` Sascha Hauer
     [not found]                                 ` <20091002072643.GH27039-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-10-02  8:17                                   ` Richard Zhao
2009-10-02  8:17                                     ` Richard Zhao
     [not found]                                     ` <4e090d470910020117w620fda4cta7b26b912d01bc24-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-02 14:11                                       ` Wolfram Sang
2009-10-02 14:11                                         ` Wolfram Sang
2009-10-04 12:22                                         ` Richard Zhao
  -- strict thread matches above, loose matches on Subject: below --
2009-09-30  5:55 Richard Zhao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.