Wed Jan 1 12:55:03 2020 UTC ()
No need to print all supported levels at attach, print the range and total number of steps


(jmcneill)
diff -r1.4 -r1.5 src/sys/dev/fdt/pwm_backlight.c

cvs diff -r1.4 -r1.5 src/sys/dev/fdt/pwm_backlight.c (expand / switch to unified diff)

--- src/sys/dev/fdt/pwm_backlight.c 2018/05/10 13:11:21 1.4
+++ src/sys/dev/fdt/pwm_backlight.c 2020/01/01 12:55:03 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pwm_backlight.c,v 1.4 2018/05/10 13:11:21 jmcneill Exp $ */ 1/* $NetBSD: pwm_backlight.c,v 1.5 2020/01/01 12:55:03 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.4 2018/05/10 13:11:21 jmcneill Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.5 2020/01/01 12:55:03 jmcneill Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/bus.h> 33#include <sys/bus.h>
34#include <sys/device.h> 34#include <sys/device.h>
35#include <sys/systm.h> 35#include <sys/systm.h>
36#include <sys/sysctl.h> 36#include <sys/sysctl.h>
37#include <sys/kmem.h> 37#include <sys/kmem.h>
38#include <sys/gpio.h> 38#include <sys/gpio.h>
39 39
40#include <dev/pwm/pwmvar.h> 40#include <dev/pwm/pwmvar.h>
41 41
42#include <dev/fdt/fdtvar.h> 42#include <dev/fdt/fdtvar.h>
43 43
@@ -107,31 +107,31 @@ pwm_backlight_attach(device_t parent, de @@ -107,31 +107,31 @@ pwm_backlight_attach(device_t parent, de
107 107
108 levels = fdtbus_get_prop(phandle, "brightness-levels", &len); 108 levels = fdtbus_get_prop(phandle, "brightness-levels", &len);
109 if (len < 4) { 109 if (len < 4) {
110 aprint_error(": couldn't get 'brightness-levels' property\n"); 110 aprint_error(": couldn't get 'brightness-levels' property\n");
111 return; 111 return;
112 } 112 }
113 sc->sc_levels = kmem_alloc(len, KM_SLEEP); 113 sc->sc_levels = kmem_alloc(len, KM_SLEEP);
114 sc->sc_nlevels = len / 4; 114 sc->sc_nlevels = len / 4;
115 for (n = 0; n < sc->sc_nlevels; n++) 115 for (n = 0; n < sc->sc_nlevels; n++)
116 sc->sc_levels[n] = be32toh(levels[n]); 116 sc->sc_levels[n] = be32toh(levels[n]);
117 117
118 aprint_naive("\n"); 118 aprint_naive("\n");
119 aprint_normal(": PWM Backlight"); 119 aprint_normal(": PWM Backlight");
120 aprint_verbose(" <"); 120 if (sc->sc_nlevels > 1) {
121 for (n = 0; n < sc->sc_nlevels; n++) { 121 aprint_normal(", %u-%u (%u steps)",
122 aprint_verbose("%s%u", n ? " " : "", sc->sc_levels[n]); 122 sc->sc_levels[0], sc->sc_levels[sc->sc_nlevels - 1],
 123 sc->sc_nlevels);
123 } 124 }
124 aprint_verbose(">"); 
125 aprint_normal("\n"); 125 aprint_normal("\n");
126 126
127 sc->sc_lid_state = true; 127 sc->sc_lid_state = true;
128 128
129 if (of_getprop_uint32(phandle, "default-brightness-level", &default_level) == 0) { 129 if (of_getprop_uint32(phandle, "default-brightness-level", &default_level) == 0) {
130 /* set the default level now */ 130 /* set the default level now */
131 pwm_backlight_set(sc, default_level); 131 pwm_backlight_set(sc, default_level);
132 } 132 }
133 133
134 pwm_backlight_sysctl_init(sc); 134 pwm_backlight_sysctl_init(sc);
135 pwm_backlight_pmf_init(sc); 135 pwm_backlight_pmf_init(sc);
136} 136}
137 137