Module Name:    src
Committed By:   kiyohara
Date:           Sat Oct 15 14:40:41 UTC 2016

Modified Files:
        src/sys/dev/i2c: tps65217pmic.c

Log Message:
Add White LED initialize function.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/tps65217pmic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/tps65217pmic.c
diff -u src/sys/dev/i2c/tps65217pmic.c:1.10 src/sys/dev/i2c/tps65217pmic.c:1.11
--- src/sys/dev/i2c/tps65217pmic.c:1.10	Sun Jul 20 23:01:22 2014
+++ src/sys/dev/i2c/tps65217pmic.c	Sat Oct 15 14:40:41 2016
@@ -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_envsys_refresh(
 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 @@ tps65217pmic_attach(device_t parent, dev
 {
 	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_attach(device_t parent, dev
 
 	tps65217pmic_power_monitor_init(sc);
 
+	if (isel != -1)
+		tps65217pmic_wled_init(sc, isel, fdim, brightness);
+
 	tps65217pmic_envsys_register(sc);
 }
 
@@ -409,6 +423,55 @@ tps65217pmic_power_monitor(void *aux)
 }
 
 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;

Reply via email to