Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c Suppressing the ACK after the last byte read mus...



details:   https://anonhg.NetBSD.org/src/rev/9ddffe562543
branches:  trunk
changeset: 764358:9ddffe562543
user:      phx <phx%NetBSD.org@localhost>
date:      Sun Apr 17 15:14:59 2011 +0000

description:
Suppressing the ACK after the last byte read must not depend on
I2C_OP_STOP_P(), but all read-transfers have to be finished that way.
Otherwise a chip might hang after a read-operation without stop.

Removed sc_start from the softc structure, which is unused.

diffstat:

 sys/dev/i2c/motoi2c.c    |  28 +++++++++++++---------------
 sys/dev/i2c/motoi2cvar.h |   3 +--
 2 files changed, 14 insertions(+), 17 deletions(-)

diffs (92 lines):

diff -r 2b4159e3b457 -r 9ddffe562543 sys/dev/i2c/motoi2c.c
--- a/sys/dev/i2c/motoi2c.c     Sun Apr 17 15:03:37 2011 +0000
+++ b/sys/dev/i2c/motoi2c.c     Sun Apr 17 15:14:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: motoi2c.c,v 1.3 2011/01/12 18:06:26 phx Exp $ */
+/* $NetBSD: motoi2c.c,v 1.4 2011/04/17 15:14:59 phx Exp $ */
 
 /*-
  * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.3 2011/01/12 18:06:26 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.4 2011/04/17 15:14:59 phx Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -98,7 +98,6 @@
 
        sc->sc_i2c = motoi2c;
        sc->sc_i2c.ic_cookie = sc;
-       sc->sc_start = false;
        if (sc->sc_iord == NULL)
                sc->sc_iord = motoi2c_iord1;
        if (sc->sc_iowr == NULL)
@@ -131,7 +130,6 @@
 {
        struct motoi2c_softc * const sc = v;
 
-       sc->sc_start = false;
        I2C_WRITE(I2CCR, 0);            /* reset before changing anything */
        mutex_exit(&sc->sc_buslock);
 }
@@ -289,9 +287,8 @@
        if (I2C_OP_READ_P(op)) {
                uint8_t *dataptr = databuf;
                cr &= ~CR_MTX;          /* clear transmit flags */
-               if (datalen <= 1 && I2C_OP_STOP_P(op)) {
+               if (datalen <= 1)
                        cr |= CR_TXAK;
-               }
                I2C_WRITE(I2CCR, cr);
                DELAY(10);
                (void)I2C_READ(I2CDR);          /* dummy read */
@@ -309,19 +306,20 @@
                                    __func__, i, error));
                                goto out;
                        }
-                       if (I2C_OP_STOP_P(op)) {
-                               if (i == datalen - 2) {
-                                       cr |= CR_TXAK;
-                                       I2C_WRITE(I2CCR, cr);
-                               } else if (i == datalen - 1) {
-                                       cr = CR_MEN;
-                                       I2C_WRITE(I2CCR, cr);
-                                       sc->sc_start = false;
-                               }
+                       if (i == datalen - 2) {
+                               cr |= CR_TXAK;
+                               I2C_WRITE(I2CCR, cr);
+                       } else if (i == datalen - 1 && I2C_OP_STOP_P(op)) {
+                               cr = CR_MEN;
+                               I2C_WRITE(I2CCR, cr);
                        }
                        *dataptr++ = I2C_READ(I2CDR);
                }
                if (datalen == 0) {
+                       if (I2C_OP_STOP_P(op)) {
+                               cr = CR_MEN;
+                               I2C_WRITE(I2CCR, cr);
+                       }
                        (void)I2C_READ(I2CDR);  /* dummy read */
                        error = motoi2c_busy_wait(sc, cr);
                        if (error) {
diff -r 2b4159e3b457 -r 9ddffe562543 sys/dev/i2c/motoi2cvar.h
--- a/sys/dev/i2c/motoi2cvar.h  Sun Apr 17 15:03:37 2011 +0000
+++ b/sys/dev/i2c/motoi2cvar.h  Sun Apr 17 15:14:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: motoi2cvar.h,v 1.3 2011/01/12 18:05:18 phx Exp $ */
+/* $NetBSD: motoi2cvar.h,v 1.4 2011/04/17 15:14:59 phx Exp $ */
 
 /*-
  * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
@@ -49,7 +49,6 @@
        bus_space_handle_t      sc_ioh;
        struct i2c_controller   sc_i2c;
        kmutex_t                sc_buslock;
-       bool                    sc_start;
        motoi2c_iord_t          sc_iord;
        motoi2c_iowr_t          sc_iowr;
 };



Home | Main Index | Thread Index | Old Index