Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Add White LED initialize function.



details:   https://anonhg.NetBSD.org/src/rev/03f47998a821
branches:  trunk
changeset: 818485:03f47998a821
user:      kiyohara <kiyohara%NetBSD.org@localhost>
date:      Sat Oct 15 14:40:41 2016 +0000

description:
Add White LED initialize function.

diffstat:

 sys/dev/i2c/tps65217pmic.c |  67 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 2 deletions(-)

diffs (114 lines):

diff -r e5d993284b8a -r 03f47998a821 sys/dev/i2c/tps65217pmic.c
--- a/sys/dev/i2c/tps65217pmic.c        Sat Oct 15 14:30:36 2016 +0000
+++ b/sys/dev/i2c/tps65217pmic.c        Sat Oct 15 14:40:41 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tps65217pmic.c,v 1.10 2014/07/20 23:01:22 bouyer Exp $ */
+/*     $NetBSD: tps65217pmic.c,v 1.11 2016/10/15 14:40:41 kiyohara Exp $ */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tps65217pmic.c,v 1.10 2014/07/20 23:01:22 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tps65217pmic.c,v 1.11 2016/10/15 14:40:41 kiyohara Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -154,6 +154,8 @@
 static void tps65217pmic_power_monitor_init(struct tps65217pmic_softc *);
 static void tps65217pmic_power_monitor(void *);
 
+static void tps65217pmic_wled_init(struct tps65217pmic_softc *, int, int, int);
+
 CFATTACH_DECL_NEW(tps65217pmic, sizeof (struct tps65217pmic_softc),
     tps65217pmic_match, tps65217pmic_attach, NULL, NULL);
 
@@ -291,11 +293,20 @@
 {
        struct tps65217pmic_softc *sc = device_private(self);
        struct i2c_attach_args *ia = aux;
+       prop_dictionary_t dict;
+       int isel, fdim, brightness;
 
        sc->sc_dev = self;
        sc->sc_addr = ia->ia_addr;
        sc->sc_tag = ia->ia_tag;
 
+       dict = device_properties(self);
+       if (prop_dictionary_get_int32(dict, "isel", &isel)) {
+               prop_dictionary_get_int32(dict, "fdim", &fdim);
+               prop_dictionary_get_int32(dict, "brightness", &brightness);
+       } else
+               isel = -1;
+
        tps65217pmic_version(sc);
 
        aprint_normal(": TPS65217");
@@ -333,6 +344,9 @@
 
        tps65217pmic_power_monitor_init(sc);
 
+       if (isel != -1)
+               tps65217pmic_wled_init(sc, isel, fdim, brightness);
+
        tps65217pmic_envsys_register(sc);
 }
 
@@ -409,6 +423,55 @@
 }
 
 static void
+tps65217pmic_wled_init(struct tps65217pmic_softc *sc, int isel, int fdim,
+                      int brightness)
+{
+       uint8_t val = 0;
+
+       switch (isel) {
+       case 1:
+       case 2:
+               val |= ((isel - 1) << TPS65217PMIC_WLEDCTRL1_ISEL);
+               break;
+       default:
+               aprint_error_dev(sc->sc_dev,
+                   "WLED ISET selection is 1 or 2: isel %d\n", isel);
+               return;
+       }
+       switch (fdim) {
+       case 100:
+               val |= TPS65217PMIC_WLEDCTRL1_FDIM_100Hz;
+               break;
+       case 200:
+               val |= TPS65217PMIC_WLEDCTRL1_FDIM_200Hz;
+               break;
+       case 500:
+               val |= TPS65217PMIC_WLEDCTRL1_FDIM_500Hz;
+               break;
+       case 1000:
+               val |= TPS65217PMIC_WLEDCTRL1_FDIM_1000Hz;
+               break;
+       default:
+               aprint_error_dev(sc->sc_dev,
+                   "WLED PWM dimming frequency is 100, 200, 500 or 1000:"
+                   " fdim %d\n", fdim);
+               return;
+       }
+       if (brightness > 100 ||
+           brightness < 0) {
+               aprint_error_dev(sc->sc_dev,
+                   "invalid brightness: between 0 and 100: %d\n", brightness);
+               return;
+       }
+
+       tps65217pmic_reg_write(sc, TPS65217PMIC_WLEDCTRL1, val);
+       tps65217pmic_reg_write(sc, TPS65217PMIC_WLEDCTRL2,
+           (brightness - 1) & TPS65217PMIC_WLEDCTRL2_DUTY);
+       val |= TPS65217PMIC_WLEDCTRL1_ISINK_EN;
+       tps65217pmic_reg_write(sc, TPS65217PMIC_WLEDCTRL1, val);
+}
+
+static void
 tps65217pmic_reg_refresh(struct tps65217pmic_softc *sc)
 {
        int i;



Home | Main Index | Thread Index | Old Index