In a qcspmi_cmd_read() error case, the register is only returning the error
authormglocker <mglocker@openbsd.org>
Wed, 14 Aug 2024 10:54:58 +0000 (10:54 +0000)
committermglocker <mglocker@openbsd.org>
Wed, 14 Aug 2024 10:54:58 +0000 (10:54 +0000)
bit, not SPMI_STATUS_DONE.  Therefore, catch the error at the right place,
and print the specific error type.

ok patrick@

sys/dev/fdt/qcpmic.c
sys/dev/fdt/qcspmi.c

index 3a93fd5..7b3a711 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: qcpmic.c,v 1.1 2022/11/08 19:40:08 patrick Exp $      */
+/*     $OpenBSD: qcpmic.c,v 1.2 2024/08/14 10:54:58 mglocker Exp $     */
 /*
  * Copyright (c) 2022 Patrick Wildt <patrick@blueri.se>
  *
@@ -117,7 +117,7 @@ qcpmic_read(struct qcpmic_softc *sc, uint16_t addr)
        err = spmi_cmd_read(sc->sc_tag, sc->sc_sid, SPMI_CMD_EXT_READL,
            addr, &reg, sizeof(reg));
        if (err)
-               printf("%s: error (%u) reading 0x%x\n", sc->sc_dev.dv_xname,
+               printf("%s: error (%u) reading 0x%x", sc->sc_dev.dv_xname,
                    err, addr);
 
        return reg;
index 5cc807f..656213a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: qcspmi.c,v 1.5 2024/07/04 21:54:38 kettenis Exp $     */
+/*     $OpenBSD: qcspmi.c,v 1.6 2024/08/14 10:54:58 mglocker Exp $     */
 /*
  * Copyright (c) 2022 Patrick Wildt <patrick@blueri.se>
  *
@@ -408,14 +408,23 @@ qcspmi_cmd_read(void *cookie, uint8_t sid, uint8_t cmd, uint16_t addr,
                    SPMI_OBSV_OFF(sc, sc->sc_ee, apid) + SPMI_STATUS);
                if (reg & SPMI_STATUS_DONE)
                        break;
+               if (reg & SPMI_STATUS_FAILURE) {
+                       printf(": transaction failed\n");
+                       return EIO;
+               }
+               if (reg & SPMI_STATUS_DENIED) {
+                       printf(": transaction denied\n");
+                       return EIO;
+               }
+               if (reg & SPMI_STATUS_DROPPED) {
+                       printf(": transaction dropped\n");
+                       return EIO;
+               }
        }
-       if (i == 0)
+       if (i == 0) {
+               printf("\n");
                return ETIMEDOUT;
-
-       if (reg & SPMI_STATUS_FAILURE ||
-           reg & SPMI_STATUS_DENIED ||
-           reg & SPMI_STATUS_DROPPED)
-               return EIO;
+       }
 
        if (len > 0) {
                reg = HREAD4(sc, QCSPMI_REG_OBSRVR,