Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt - remove unnecessary code



details:   https://anonhg.NetBSD.org/src/rev/f69dd3c9f796
branches:  trunk
changeset: 979544:f69dd3c9f796
user:      ryo <ryo%NetBSD.org@localhost>
date:      Fri Jan 01 03:07:51 2021 +0000

description:
- remove unnecessary code
- handle "enable-gpios" property, and enable/disable GPIOs in pwmregulator_enable()

pointed out by thorpej@, thanks

diffstat:

 sys/dev/fdt/pwmregulator.c |  32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)

diffs (85 lines):

diff -r 7e8b24c12841 -r f69dd3c9f796 sys/dev/fdt/pwmregulator.c
--- a/sys/dev/fdt/pwmregulator.c        Fri Jan 01 01:42:55 2021 +0000
+++ b/sys/dev/fdt/pwmregulator.c        Fri Jan 01 03:07:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pwmregulator.c,v 1.1 2020/12/31 15:12:33 ryo Exp $ */
+/* $NetBSD: pwmregulator.c,v 1.2 2021/01/01 03:07:51 ryo Exp $ */
 
 /*
  * Copyright (c) 2020 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pwmregulator.c,v 1.1 2020/12/31 15:12:33 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pwmregulator.c,v 1.2 2021/01/01 03:07:51 ryo Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -63,6 +63,7 @@
 struct pwmregulator_softc {
        device_t sc_dev;
        pwm_tag_t sc_pwm;
+       struct fdtbus_gpio_pin *sc_pin;
        struct voltage_duty *sc_voltage_table;
        int sc_voltage_table_num;
        int sc_phandle;
@@ -132,8 +133,6 @@
            &sc->sc_dutycycle_unit) != 0)
                sc->sc_dutycycle_unit = 100;
 
-       len = of_getprop_uint32_array(phandle, "pwm-dutycycle-range",
-           sc->sc_dutycycle_range, 2);
        if (of_getprop_uint32_array(phandle, "pwm-dutycycle-range",
            sc->sc_dutycycle_range, 2) != 0) {
                sc->sc_dutycycle_range[0] = 0;
@@ -193,6 +192,10 @@
 {
        struct pwmregulator_softc * const sc = device_private(dev);
 
+       /* "enable-gpios" is optional */
+       sc->sc_pin = fdtbus_gpio_acquire(sc->sc_phandle, "enable-gpios",
+           GPIO_PIN_OUTPUT);
+
        sc->sc_pwm = fdtbus_pwm_acquire(sc->sc_phandle, "pwms");
        if (sc->sc_pwm == NULL)
                return ENXIO;
@@ -205,6 +208,11 @@
 {
        struct pwmregulator_softc * const sc = device_private(dev);
 
+       if (sc->sc_pin != NULL) {
+               fdtbus_gpio_write(sc->sc_pin, 0);
+               fdtbus_gpio_release(sc->sc_pin);
+       }
+
        sc->sc_pwm = NULL;
 }
 
@@ -212,14 +220,22 @@
 pwmregulator_enable(device_t dev, bool enable)
 {
        struct pwmregulator_softc * const sc = device_private(dev);
+       int error;
 
        if (sc->sc_pwm == NULL)
                return ENXIO;
 
-       if (enable)
-               return pwm_enable(sc->sc_pwm);
-       else
-               return pwm_disable(sc->sc_pwm);
+       if (enable) {
+               if (sc->sc_pin != NULL)
+                       fdtbus_gpio_write(sc->sc_pin, 1);
+               error = pwm_enable(sc->sc_pwm);
+       } else {
+               error = pwm_disable(sc->sc_pwm);
+               if (sc->sc_pin != NULL)
+                       fdtbus_gpio_write(sc->sc_pin, 0);
+       }
+
+       return error;
 }
 
 static int



Home | Main Index | Thread Index | Old Index