diff mbox

Add support for SCCB devices into PXA27x I2C controller

Message ID 54711397.9060601@tul.cz (mailing list archive)
State New, archived
Headers show

Commit Message

Petr Cvek Nov. 22, 2014, 10:52 p.m. UTC
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@tul.cz>
---
  drivers/i2c/busses/i2c-pxa.c | 22 ++++++++++++++++------
  1 file changed, 16 insertions(+), 6 deletions(-)

          /*
@@ -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.

Comments

Wolfram Sang Nov. 23, 2014, 8:31 a.m. UTC | #1
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@tul.cz>

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@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sergei Shtylyov Nov. 23, 2014, 4:23 p.m. UTC | #2
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@tul.cz>
> ---
>   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
diff mbox

Patch

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;