Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c When initiating a transfer, if a device isn't pr...



details:   https://anonhg.NetBSD.org/src/rev/a29edb58eb8f
branches:  trunk
changeset: 323355:a29edb58eb8f
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jun 12 13:18:48 2018 +0000

description:
When initiating a transfer, if a device isn't present, we won't
get an ACK after sending the address.  Check for this alternate
state and suppress the error message when it occurs.

Fixes PR kern/53356.

diffstat:

 sys/dev/i2c/gttwsi_core.c |  49 ++++++++++++++++++++++++++++++----------------
 1 files changed, 32 insertions(+), 17 deletions(-)

diffs (142 lines):

diff -r 7946840d901c -r a29edb58eb8f sys/dev/i2c/gttwsi_core.c
--- a/sys/dev/i2c/gttwsi_core.c Tue Jun 12 10:28:55 2018 +0000
+++ b/sys/dev/i2c/gttwsi_core.c Tue Jun 12 13:18:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $ */
+/*     $NetBSD: gttwsi_core.c,v 1.6 2018/06/12 13:18:48 thorpej Exp $  */
 /*
  * Copyright (c) 2008 Eiji Kawauchi.
  * All rights reserved.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.6 2018/06/12 13:18:48 thorpej Exp $");
 #include "locators.h"
 
 #include <sys/param.h>
@@ -91,7 +91,8 @@
 static int     gttwsi_read_byte(void *v, uint8_t *valp, int flags);
 static int     gttwsi_write_byte(void *v, uint8_t val, int flags);
 
-static int     gttwsi_wait(struct gttwsi_softc *, uint32_t, uint32_t, int);
+static int     gttwsi_wait(struct gttwsi_softc *, uint32_t, uint32_t,
+                           uint32_t, int);
 
 static inline uint32_t
 gttwsi_default_read_4(struct gttwsi_softc *sc, uint32_t reg)
@@ -243,7 +244,7 @@
        else
                expect = STAT_SCT;
        sc->sc_started = true;
-       return gttwsi_wait(sc, CONTROL_START, expect, flags);
+       return gttwsi_wait(sc, CONTROL_START, expect, 0, flags);
 }
 
 static int
@@ -277,7 +278,7 @@
 gttwsi_initiate_xfer(void *v, i2c_addr_t addr, int flags)
 {
        struct gttwsi_softc *sc = v;
-       uint32_t data, expect;
+       uint32_t data, expect, alt;
        int error, read;
 
        KASSERT(sc->sc_inuse);
@@ -285,10 +286,13 @@
        gttwsi_send_start(v, flags);
 
        read = (flags & I2C_F_READ) != 0;
-       if (read)
+       if (read) {
                expect = STAT_ARBT_AR;
-       else
+               alt    = STAT_ARBT_ANR;
+       } else {
                expect = STAT_AWBT_AR;
+               alt    = STAT_AWBT_ANR;
+       }
 
        /*
         * First byte contains whether this xfer is a read or write.
@@ -301,23 +305,26 @@
                 */
                data |= 0xf0 | ((addr & 0x300) >> 7);
                gttwsi_write_4(sc, TWSI_DATA, data);
-               error = gttwsi_wait(sc, 0, expect, flags);
+               error = gttwsi_wait(sc, 0, expect, alt, flags);
                if (error)
                        return error;
                /*
                 * The first address byte has been sent, now to send
                 * the second one.
                 */
-               if (read)
+               if (read) {
                        expect = STAT_SARBT_AR;
-               else
+                       alt    = STAT_SARBT_ANR;
+               } else {
                        expect = STAT_SAWBT_AR;
+                       alt    = STAT_SAWBT_ANR;
+               }
                data = (uint8_t)addr;
        } else
                data |= (addr << 1);
 
        gttwsi_write_4(sc, TWSI_DATA, data);
-       return gttwsi_wait(sc, 0, expect, flags);
+       return gttwsi_wait(sc, 0, expect, alt, flags);
 }
 
 static int
@@ -329,9 +336,9 @@
        KASSERT(sc->sc_inuse);
 
        if (flags & I2C_F_LAST)
-               error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, flags);
+               error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, 0, flags);
        else
-               error = gttwsi_wait(sc, CONTROL_ACK, STAT_MRRD_AT, flags);
+               error = gttwsi_wait(sc, CONTROL_ACK, STAT_MRRD_AT, 0, flags);
        if (!error)
                *valp = gttwsi_read_4(sc, TWSI_DATA);
        if ((flags & (I2C_F_LAST | I2C_F_STOP)) == (I2C_F_LAST | I2C_F_STOP))
@@ -348,7 +355,7 @@
        KASSERT(sc->sc_inuse);
 
        gttwsi_write_4(sc, TWSI_DATA, val);
-       error = gttwsi_wait(sc, 0, STAT_MTDB_AR, flags);
+       error = gttwsi_wait(sc, 0, STAT_MTDB_AR, 0, flags);
        if (flags & I2C_F_STOP)
                gttwsi_send_stop(sc, flags);
        return error;
@@ -356,7 +363,7 @@
 
 static int
 gttwsi_wait(struct gttwsi_softc *sc, uint32_t control, uint32_t expect,
-           int flags)
+           uint32_t alt, int flags)
 {
        uint32_t status;
        int timo, error = 0;
@@ -389,8 +396,16 @@
 
        status = gttwsi_read_4(sc, TWSI_STATUS);
        if (status != expect) {
-               aprint_error_dev(sc->sc_dev,
-                   "unexpected status 0x%x: expect 0x%x\n", status, expect);
+               /*
+                * In the case of probing for a device, we are expecting
+                * 2 different status codes: the ACK case (device exists),
+                * or the NACK case (device does not exist).  We don't
+                * need to report an error in the later case.
+                */
+               if (alt != 0 && status != alt)
+                       aprint_error_dev(sc->sc_dev,
+                           "unexpected status 0x%x: expect 0x%x\n", status,
+                           expect);
                return EIO;
        }
        return error;



Home | Main Index | Thread Index | Old Index