Skip to contentSkip to conversation

Add support for SCCB devices into PXA27x I2C controller

PATCH Superseded Petr Cvek 3 participants 7 messages Nov 22, 2014 – Nov 25, 2014 I2C subsystem host drivers

lore
Share & tools
lore

Petr Cvek

author
#0 lore raw

PATCH 1/1 Add support for SCCB devices into PXA27x I2C controller

Add support for SCCB devices into PXA27x I2C controller.

Fix generated START but no STOP for message without I2C_M_NOSTART flag. Add support for I2C_M_IGNORE_NAK flag.

---
  drivers/i2c/busses/i2c-pxa.c | 22 ++++++++++++++++------
  1 file changed, 16 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-pxa.c +0 -0
index be671f7..adad044 100644
@@ -885,7 +885,14 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c 

*i2c, u32 isr)
return; /* ignore */
}

- if (isr & ISR_BED) {
+ /*

+     * Ignore NAK when flag I2C_M_IGNORE_NAK is present,
+     * this enables use of SCCB devices
+     */

+ if ((isr & ISR_BED) &&
+ (!((i2c->msg->flags & I2C_M_IGNORE_NAK) &&
+ (isr & ISR_ACKNAK)))) {
+

          int ret = BUS_ERROR;

          /*
@@ -919,12 +926,15 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c 
*i2c, u32 isr)
          icr |= ICR_ALDIE | ICR_TB;

          /*
-         * If this is the last byte of the last message, send
-         * a STOP.
+         * If this is the last byte of the last message or last byte
+         * or any message without I2C_M_NOSTART, send a STOP.
           */

- if (i2c->msg_ptr == i2c->msg->len &&
- i2c->msg_idx == i2c->msg_num - 1)
- icr |= ICR_STOP;
+ if (((i2c->msg_ptr == i2c->msg->len) &&

+            (!(i2c->msg->flags & I2C_M_NOSTART))) ||
+            ((i2c->msg_ptr == i2c->msg->len) &&
+            (i2c->msg_idx == i2c->msg_num - 1)))
+                icr |= ICR_STOP;
+
      } else if (i2c->msg_idx < i2c->msg_num - 1) {
          /*
           * Next segment of the message.
Signature · 1 line
1.7.12.1
#1 lore raw

PATCH 1/1 Add support for SCCB devices into PXA27x I2C controller

Quoted 6 lines · Petr Cvek

Add support for SCCB devices into PXA27x I2C controller.

Fix generated START but no STOP for message without I2C_M_NOSTART flag. Add support for I2C_M_IGNORE_NAK flag.

I can't apply the patch. What is this based on? Can you rebase it to i2c/for-next or the latest rc or at least the latest stable?

Quoted 9 lines
---
 drivers/i2c/busses/i2c-pxa.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-pxa.c +0 -0
index be671f7..adad044 100644

drivers/i2c/busses/i2c-pxa.c static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, · line 892

Quoted 9 lines
drivers/i2c/busses/i2c-pxa.c +4 -1
@@ -885,7 +885,14 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c,
 u32 isr)
         return; /* ignore */
     }
 
-    if (isr & ISR_BED) {
+    /*
+     * Ignore NAK when flag I2C_M_IGNORE_NAK is present,
+     * this enables use of SCCB devices
+     */

I'd think this comment is not needed since I2C_M_IGNORE_NAK is self-explaining.

Quoted 14 lines
drivers/i2c/busses/i2c-pxa.c +4 -0
+    if ((isr & ISR_BED) &&
+        (!((i2c->msg->flags & I2C_M_IGNORE_NAK) &&
+            (isr & ISR_ACKNAK)))) {
+
         int ret = BUS_ERROR;
 
         /*
drivers/i2c/busses/i2c-pxa.c +0 -2
@@ -919,12 +926,15 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c,
 u32 isr)
         icr |= ICR_ALDIE | ICR_TB;
 
         /*
-         * If this is the last byte of the last message, send
-         * a STOP.

drivers/i2c/busses/i2c-pxa.c static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, · line 936

Quoted 10 lines
drivers/i2c/busses/i2c-pxa.c +6 -3
+         * If this is the last byte of the last message or last byte
+         * or any message without I2C_M_NOSTART, send a STOP.
          */
-        if (i2c->msg_ptr == i2c->msg->len &&
-            i2c->msg_idx == i2c->msg_num - 1)
-            icr |= ICR_STOP;
+        if (((i2c->msg_ptr == i2c->msg->len) &&
+            (!(i2c->msg->flags & I2C_M_NOSTART))) ||
+            ((i2c->msg_ptr == i2c->msg->len) &&
+            (i2c->msg_idx == i2c->msg_num - 1)))

You could factor out the length check. And you should check for I2C_M_STOP, no?

Quoted 4 lines
drivers/i2c/busses/i2c-pxa.c +2 -0
+                icr |= ICR_STOP;
+
     } else if (i2c->msg_idx < i2c->msg_num - 1) {
         /*
Quoted 8 lines

* Next segment of the message.

Signature · 6 lines
1.7.12.1

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141123/5b4b7190/attachment.sig>

#6 lore raw

PATCH 1/1 Add support for SCCB devices into PXA27x I2C controller

In reply to Petr Cvek

Hello.

Quoted 15 lines · Petr Cvek

Add support for SCCB devices into PXA27x I2C controller.

Fix generated START but no STOP for message without I2C_M_NOSTART flag. Add support for I2C_M_IGNORE_NAK flag.

---
  drivers/i2c/busses/i2c-pxa.c | 22 ++++++++++++++++------
  1 file changed, 16 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-pxa.c +0 -0
index be671f7..adad044 100644

drivers/i2c/busses/i2c-pxa.c static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 · line 889

Quoted 6 lines
drivers/i2c/busses/i2c-pxa.c +1 -1
@@ -885,7 +885,14 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32
 isr)
          return; /* ignore */
      }
 
-    if (isr & ISR_BED) {
+    /*

Your patch has tabs replaces by spaces; probably your email agent's work. :-)

drivers/i2c/busses/i2c-pxa.c static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 · line 896

Quoted 7 lines
drivers/i2c/busses/i2c-pxa.c +7 -0
+     * Ignore NAK when flag I2C_M_IGNORE_NAK is present,
+     * this enables use of SCCB devices
+     */
+    if ((isr & ISR_BED) &&
+        (!((i2c->msg->flags & I2C_M_IGNORE_NAK) &&
+            (isr & ISR_ACKNAK)))) {
+

This empty line is not needed.

[...]

WBR, Sergei

author
#2 lore raw

PATCH v2 1/1 Add support for SCCB devices into PXA27x I2C controller

In reply to Wolfram Sang

I'm sorry for spacing, I didn't realize thunderbird automatically replaces tabs with spaces. Now it should be OK.

I created this patch by fixing both I2C controller and SCCB device, so it seems I incorrectly used I2C_M_NOSTART instead I2C_M_STOP. Problem with I2C_M_STOP is that it causes bus freeze when using userspace utility "i2cget" on SCCB device (unfreeze can be done with i2c-pxa module reload). But this can be probably repaired in i2cget.

Patched kernel was from vanilla 3.18.0-rc5 commit fc14f9c1272f62c3e8d01300f52467c0d9af50f9

---
 drivers/i2c/busses/i2c-pxa.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-pxa.c +12 -7
index be671f7..f80df8f 100644
@@ -885,7 +885,9 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
 		return; /* ignore */
 	}
 
-	if (isr & ISR_BED) {
+	if ((isr & ISR_BED) &&
+		(!((i2c->msg->flags & I2C_M_IGNORE_NAK) &&
+			(isr & ISR_ACKNAK)))) {
 		int ret = BUS_ERROR;
 
 		/*
@@ -919,12 +921,14 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
 		icr |= ICR_ALDIE | ICR_TB;
 
 		/*
-		 * If this is the last byte of the last message, send
-		 * a STOP.
+		 * If this is the last byte of the last message or last byte
+		 * of any message with I2C_M_STOP (e.g. SCCB), send a STOP.
 		 */
-		if (i2c->msg_ptr == i2c->msg->len &&
-		    i2c->msg_idx == i2c->msg_num - 1)
-			icr |= ICR_STOP;
+		if ((i2c->msg_ptr == i2c->msg->len) &&
+			((i2c->msg->flags & I2C_M_STOP) ||
+			(i2c->msg_idx == i2c->msg_num - 1)))
+				icr |= ICR_STOP;
+
 	} else if (i2c->msg_idx < i2c->msg_num - 1) {
 		/*
 		 * Next segment of the message.
@@ -1071,7 +1075,8 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
 
 static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
 {
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
+		I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART;
 }
 
 static const struct i2c_algorithm i2c_pxa_algorithm = {
Signature · 1 line
1.7.12.1
#3 lore raw

PATCH v2 1/1 Add support for SCCB devices into PXA27x I2C controller

Quoted 5 lines · Petr Cvek

I created this patch by fixing both I2C controller and SCCB device, so it seems I incorrectly used I2C_M_NOSTART instead I2C_M_STOP. Problem with I2C_M_STOP is that it causes bus freeze when using userspace utility "i2cget" on SCCB device (unfreeze can be done with i2c-pxa module reload). But this can be probably repaired in i2cget.

Please CC Jean Delvare, he maintains the I2C tools.

Quoted 1 line

Patched kernel was from vanilla 3.18.0-rc5 commit fc14f9c1272f62c3e8d01300f52467c0d9af50f9

Thanks but all these paragraphs describing the updates should have gone below the "---" line. Your original commit message was more apropriate and should have stayed.

drivers/i2c/busses/i2c-pxa.c static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num · line 1079

Quoted 5 lines

static u32 i2c_pxa_functionality(struct i2c_adapter *adap) {

drivers/i2c/busses/i2c-pxa.c +2 -1
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
+		I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART;

Okay, so NOSTART was previously implemented but not advertised? Please update the commit log to say that this will be also fixed by your patch.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141124/21258621/attachment.sig>

author
#4 lore raw

PATCH v3 1/1 i2c-pxa: add support for SCCB devices

Fixed missing functionality flag I2C_FUNC_NOSTART.

Added support for SCCB by implementing I2C_M_IGNORE_NAK and I2C_M_STOP flag and belonging functionality flag I2C_FUNC_PROTOCOL_MANGLING.

---
 drivers/i2c/busses/i2c-pxa.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-pxa.c +12 -7
index be671f7..f80df8f 100644
@@ -885,7 +885,9 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
 		return; /* ignore */
 	}
 
-	if (isr & ISR_BED) {
+	if ((isr & ISR_BED) &&
+		(!((i2c->msg->flags & I2C_M_IGNORE_NAK) &&
+			(isr & ISR_ACKNAK)))) {
 		int ret = BUS_ERROR;
 
 		/*
@@ -919,12 +921,14 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
 		icr |= ICR_ALDIE | ICR_TB;
 
 		/*
-		 * If this is the last byte of the last message, send
-		 * a STOP.
+		 * If this is the last byte of the last message or last byte
+		 * of any message with I2C_M_STOP (e.g. SCCB), send a STOP.
 		 */
-		if (i2c->msg_ptr == i2c->msg->len &&
-		    i2c->msg_idx == i2c->msg_num - 1)
-			icr |= ICR_STOP;
+		if ((i2c->msg_ptr == i2c->msg->len) &&
+			((i2c->msg->flags & I2C_M_STOP) ||
+			(i2c->msg_idx == i2c->msg_num - 1)))
+				icr |= ICR_STOP;
+
 	} else if (i2c->msg_idx < i2c->msg_num - 1) {
 		/*
 		 * Next segment of the message.
@@ -1071,7 +1075,8 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
 
 static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
 {
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
+		I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART;
 }
 
 static const struct i2c_algorithm i2c_pxa_algorithm = {
Signature · 1 line
1.7.12.1
Applied
#5 lore raw

PATCH v3 1/1 i2c-pxa: add support for SCCB devices

Quoted 5 lines · Petr Cvek

Fixed missing functionality flag I2C_FUNC_NOSTART.

Added support for SCCB by implementing I2C_M_IGNORE_NAK and I2C_M_STOP flag and belonging functionality flag I2C_FUNC_PROTOCOL_MANGLING.

Applied to for-next, thanks!

Please send new patches as seperate threads, not as a reply to the old patch.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141125/c1709f10/attachment.sig>