Date: Wed, 21 Sep 2011 22:47:47 -0400 From: Justin Hibbits <jrh29@alumni.cwru.edu> To: FreeBSD PowerPC ML <freebsd-ppc@freebsd.org> Subject: ofw syscons brightness patch Message-ID: <91CC14C1-14F2-41B3-81F1-D90B42F038CA@alumni.cwru.edu>
next in thread | raw e-mail | index | archive | help
--Apple-Mail-7--949948817 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Hey guys, Attached is a patch that adds brightness control to ofw syscons (dev.sc.0.brightness sysctl). Pretty simple. Comments and tests requested. Hopefully the listserv doesn't eat the patch. Thanks, Justin --Apple-Mail-7--949948817 Content-Disposition: attachment; filename=ofw_sc_brightness.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="ofw_sc_brightness.diff" Content-Transfer-Encoding: 7bit Index: sys/powerpc/ofw/ofw_syscons.c =================================================================== --- sys/powerpc/ofw/ofw_syscons.c (revision 225715) +++ sys/powerpc/ofw/ofw_syscons.c (working copy) @@ -98,7 +98,11 @@ static vi_putc_t ofwfb_putc; static vi_puts_t ofwfb_puts; static vi_putm_t ofwfb_putm; +static int brightness; +static void ofwfb_set_brightness(int); +static int ofwfb_set_brightness_sc(SYSCTL_HANDLER_ARGS); + static video_switch_t ofwfbvidsw = { .probe = ofwfb_probe, .init = ofwfb_init, @@ -185,6 +189,7 @@ static u_int16_t ofwfb_static_window[ROW*COL]; static struct ofwfb_softc ofwfb_softc; +static ihandle_t stdout_ih; static __inline int ofwfb_background(uint8_t attr) @@ -399,7 +404,6 @@ { struct ofwfb_softc *sc; char name[64]; - ihandle_t ih; int i, retval; sc = (struct ofwfb_softc *)adp; @@ -410,7 +414,7 @@ memset(name, 0, sizeof(name)); OF_package_to_path(sc->sc_node, name, sizeof(name)); - ih = OF_open(name); + stdout_ih = OF_open(name); if (sc->sc_depth == 8) { /* @@ -418,7 +422,7 @@ * don't do this by default */ for (i = 0; i < 16; i++) { - OF_call_method("color!", ih, 4, 1, + OF_call_method("color!", stdout_ih, 4, 1, ofwfb_cmap[i].red, ofwfb_cmap[i].green, ofwfb_cmap[i].blue, @@ -965,10 +969,49 @@ static int ofwfb_scattach(device_t dev) { + struct sysctl_ctx_list *ctx; + struct sysctl_oid *tree; + + ctx = device_get_sysctl_ctx(dev); + tree = device_get_sysctl_tree(dev); + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "brightness", CTLTYPE_INT | CTLFLAG_RW, NULL, 0, + ofwfb_set_brightness_sc, "I", "Adjust the brightness of the screen"); + + ofwfb_set_brightness(DEFAULT_BRIGHTNESS); + return (sc_attach_unit(device_get_unit(dev), device_get_flags(dev) | SC_AUTODETECT_KBD)); } +static void ofwfb_set_brightness(int newbright) +{ + /* If the backlight is off already, turn it on. */ + if (newbright < MIN_BRIGHTNESS) + if (brightness == 0) + newbright = MIN_BRIGHTNESS; + else + newbright = 0; + else if (newbright > MAX_BRIGHTNESS) + newbright = MAX_BRIGHTNESS; + OF_call_method("set-contrast", stdout_ih, 1, 0, newbright); + brightness = newbright; +} + +static int ofwfb_set_brightness_sc(SYSCTL_HANDLER_ARGS) +{ + int newbright = brightness; + int error; + + error = sysctl_handle_int(oidp, &newbright, 0, req); + + if (error || !req->newptr) + return error; + ofwfb_set_brightness(newbright); + return (0); +} + static device_method_t ofwfb_sc_methods[] = { DEVMETHOD(device_identify, ofwfb_scidentify), DEVMETHOD(device_probe, ofwfb_scprobe), Index: sys/powerpc/ofw/ofw_syscons.h =================================================================== --- sys/powerpc/ofw/ofw_syscons.h (revision 225715) +++ sys/powerpc/ofw/ofw_syscons.h (working copy) @@ -29,6 +29,11 @@ #ifndef _OFW_SYSCONS_H_ #define _OFW_SYSCONS_H_ +#define MIN_BRIGHTNESS 0x34 +#define MAX_BRIGHTNESS 0xFF +#define DEFAULT_BRIGHTNESS 0x80 +#define STEP_BRIGHTNESS 0x08 + struct ofwfb_softc { video_adapter_t sc_va; struct cdev *sc_si; --Apple-Mail-7--949948817 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-7--949948817--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?91CC14C1-14F2-41B3-81F1-D90B42F038CA>