linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add support for SCCB devices into PXA27x I2C controller
@ 2014-11-22 22:52 Petr Cvek
       [not found] ` <54711397.9060601-qphu/3gb4gc@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Petr Cvek @ 2014-11-22 22:52 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA

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.

Signed-off-by: Petr Cvek <petr.cvek-qphu/3gb4gc@public.gmane.org>
---
  drivers/i2c/busses/i2c-pxa.c | 22 ++++++++++++++++------
  1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index be671f7..adad044 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -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.
-- 
1.7.12.1

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

* Re: [PATCH] Add support for SCCB devices into PXA27x I2C controller
       [not found] ` <54711397.9060601-qphu/3gb4gc@public.gmane.org>
@ 2014-11-23  8:31   ` Wolfram Sang
  2014-11-23 22:21     ` [PATCH v2] " Petr Cvek
  2014-11-23 16:23   ` [PATCH] Add support for SCCB devices into PXA27x I2C controller Sergei Shtylyov
  1 sibling, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2014-11-23  8:31 UTC (permalink / raw)
  To: Petr Cvek
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

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

On Sat, Nov 22, 2014 at 11:52:07PM +0100, Petr Cvek wrote:
> 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.
> 
> Signed-off-by: Petr Cvek <petr.cvek-qphu/3gb4gc@public.gmane.org>

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?

> ---
>  drivers/i2c/busses/i2c-pxa.c | 22 ++++++++++++++++------
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> index be671f7..adad044 100644
> --- a/drivers/i2c/busses/i2c-pxa.c
> +++ b/drivers/i2c/busses/i2c-pxa.c
> @@ -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.

> +    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)))

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

> +                icr |= ICR_STOP;
> +
>      } else if (i2c->msg_idx < i2c->msg_num - 1) {
>          /*
>           * Next segment of the message.
> -- 
> 1.7.12.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

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

* Re: [PATCH] Add support for SCCB devices into PXA27x I2C controller
       [not found] ` <54711397.9060601-qphu/3gb4gc@public.gmane.org>
  2014-11-23  8:31   ` Wolfram Sang
@ 2014-11-23 16:23   ` Sergei Shtylyov
  1 sibling, 0 replies; 7+ messages in thread
From: Sergei Shtylyov @ 2014-11-23 16:23 UTC (permalink / raw)
  To: Petr Cvek, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA

Hello.

On 11/23/2014 1:52 AM, Petr Cvek wrote:

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

> Signed-off-by: Petr Cvek <petr.cvek-qphu/3gb4gc@public.gmane.org>
> ---
>   drivers/i2c/busses/i2c-pxa.c | 22 ++++++++++++++++------
>   1 file changed, 16 insertions(+), 6 deletions(-)

> diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> index be671f7..adad044 100644
> --- a/drivers/i2c/busses/i2c-pxa.c
> +++ b/drivers/i2c/busses/i2c-pxa.c
> @@ -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. :-)

> +     * 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

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

* Re: [PATCH v2] Add support for SCCB devices into PXA27x I2C controller
  2014-11-23  8:31   ` Wolfram Sang
@ 2014-11-23 22:21     ` Petr Cvek
       [not found]       ` <54725DE2.9090800-qphu/3gb4gc@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Petr Cvek @ 2014-11-23 22:21 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8

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

Signed-off-by: Petr Cvek <petr.cvek-qphu/3gb4gc@public.gmane.org>
---
 drivers/i2c/busses/i2c-pxa.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index be671f7..f80df8f 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -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 = {
-- 
1.7.12.1

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

* Re: [PATCH v2] Add support for SCCB devices into PXA27x I2C controller
       [not found]       ` <54725DE2.9090800-qphu/3gb4gc@public.gmane.org>
@ 2014-11-24 17:27         ` Wolfram Sang
  2014-11-25  5:05           ` [PATCH v3] i2c-pxa: add support for SCCB devices Petr Cvek
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2014-11-24 17:27 UTC (permalink / raw)
  To: Petr Cvek
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8

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

On Sun, Nov 23, 2014 at 11:21:22PM +0100, Petr Cvek wrote:

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

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

>  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;

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.


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

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

* Re: [PATCH v3] i2c-pxa: add support for SCCB devices
  2014-11-24 17:27         ` Wolfram Sang
@ 2014-11-25  5:05           ` Petr Cvek
       [not found]             ` <54740E1D.9060508-qphu/3gb4gc@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Petr Cvek @ 2014-11-25  5:05 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8

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.

Signed-off-by: Petr Cvek <petr.cvek-qphu/3gb4gc@public.gmane.org>
---
 drivers/i2c/busses/i2c-pxa.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index be671f7..f80df8f 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -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 = {
-- 
1.7.12.1

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

* Re: [PATCH v3] i2c-pxa: add support for SCCB devices
       [not found]             ` <54740E1D.9060508-qphu/3gb4gc@public.gmane.org>
@ 2014-11-25 14:26               ` Wolfram Sang
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2014-11-25 14:26 UTC (permalink / raw)
  To: Petr Cvek
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8

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

On Tue, Nov 25, 2014 at 06:05:33AM +0100, Petr Cvek wrote:
> 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.
> 
> Signed-off-by: Petr Cvek <petr.cvek-qphu/3gb4gc@public.gmane.org>

Applied to for-next, thanks!

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


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

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

end of thread, other threads:[~2014-11-25 14:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-22 22:52 [PATCH] Add support for SCCB devices into PXA27x I2C controller Petr Cvek
     [not found] ` <54711397.9060601-qphu/3gb4gc@public.gmane.org>
2014-11-23  8:31   ` Wolfram Sang
2014-11-23 22:21     ` [PATCH v2] " Petr Cvek
     [not found]       ` <54725DE2.9090800-qphu/3gb4gc@public.gmane.org>
2014-11-24 17:27         ` Wolfram Sang
2014-11-25  5:05           ` [PATCH v3] i2c-pxa: add support for SCCB devices Petr Cvek
     [not found]             ` <54740E1D.9060508-qphu/3gb4gc@public.gmane.org>
2014-11-25 14:26               ` Wolfram Sang
2014-11-23 16:23   ` [PATCH] Add support for SCCB devices into PXA27x I2C controller Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).