Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c - Don't read/write the device if iic_acquire_bus...



details:   https://anonhg.NetBSD.org/src/rev/8a29ce7878cc
branches:  trunk
changeset: 967839:8a29ce7878cc
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Dec 23 19:12:22 2019 +0000

description:
- Don't read/write the device if iic_acquire_bus() fails.
- axp20x_poweroff(): report the error code if power off fails.
- Don't use polled access in axp20xreg_{get,set}_voltage().

diffstat:

 sys/dev/i2c/axp20x.c |  40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)

diffs (90 lines):

diff -r b93fba56d393 -r 8a29ce7878cc sys/dev/i2c/axp20x.c
--- a/sys/dev/i2c/axp20x.c      Mon Dec 23 19:00:59 2019 +0000
+++ b/sys/dev/i2c/axp20x.c      Mon Dec 23 19:12:22 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: axp20x.c,v 1.14 2019/12/23 02:50:50 thorpej Exp $ */
+/* $NetBSD: axp20x.c,v 1.15 2019/12/23 19:12:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_fdt.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.14 2019/12/23 02:50:50 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.15 2019/12/23 19:12:22 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -567,10 +567,14 @@
     int flags)
 {
        int ret;
-       iic_acquire_bus(sc->sc_i2c, flags);
-       ret = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr,
-           &reg, 1, val, len, flags);
-       iic_release_bus(sc->sc_i2c, flags);
+
+       ret = iic_acquire_bus(sc->sc_i2c, flags);
+       if (ret == 0) {
+               ret = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr,
+                   &reg, 1, val, len, flags);
+               iic_release_bus(sc->sc_i2c, flags);
+       }
+
        return ret;
 
 }
@@ -580,10 +584,14 @@
     int flags)
 {
        int ret;
-       iic_acquire_bus(sc->sc_i2c, flags);
-       ret = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr,
-           &reg, 1, val, len, flags);
-       iic_release_bus(sc->sc_i2c, flags);
+
+       ret = iic_acquire_bus(sc->sc_i2c, flags);
+       if (ret == 0) {
+               ret = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr,
+                   &reg, 1, val, len, flags);
+               iic_release_bus(sc->sc_i2c, flags);
+       }
+
        return ret;
 }
 
@@ -667,9 +675,13 @@
 {
        struct axp20x_softc * const sc = device_private(dev);
        uint8_t reg = AXP_SHUTDOWN_CTRL;
+       int error;
 
-       if (axp20x_write(sc, AXP_SHUTDOWN, &reg, 1, I2C_F_POLL) != 0)
-               device_printf(dev, "WARNING: poweroff failed\n");
+       error = axp20x_write(sc, AXP_SHUTDOWN, &reg, 1, I2C_F_POLL);
+       if (error) {
+               device_printf(dev, "WARNING: unable to power off, error %d\n",
+                   error);
+       }
 }
 
 #ifdef FDT
@@ -714,7 +726,7 @@
 {
        struct axp20xreg_softc * const sc = device_private(dev);
        
-       return axp20x_set_dcdc(device_parent(dev), sc->sc_regdef->dcdc, min_uvol / 1000, true);
+       return axp20x_set_dcdc(device_parent(dev), sc->sc_regdef->dcdc, min_uvol / 1000, false);
 }
 
 static int
@@ -723,7 +735,7 @@
        struct axp20xreg_softc * const sc = device_private(dev);
        int mvol, error;
 
-       error = axp20x_get_dcdc(device_parent(dev), sc->sc_regdef->dcdc, &mvol, true);
+       error = axp20x_get_dcdc(device_parent(dev), sc->sc_regdef->dcdc, &mvol, false);
        if (error != 0)
                return error;
 



Home | Main Index | Thread Index | Old Index