From owner-freebsd-ppc@FreeBSD.ORG Thu Sep 22 02:47:51 2011 Return-Path: Delivered-To: freebsd-ppc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7AFB71065670 for ; Thu, 22 Sep 2011 02:47:51 +0000 (UTC) (envelope-from chmeeedalf@gmail.com) Received: from mail-yx0-f182.google.com (mail-yx0-f182.google.com [209.85.213.182]) by mx1.freebsd.org (Postfix) with ESMTP id 3713E8FC12 for ; Thu, 22 Sep 2011 02:47:50 +0000 (UTC) Received: by yxk36 with SMTP id 36so2099860yxk.13 for ; Wed, 21 Sep 2011 19:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:message-id:from:to:content-type:mime-version:subject:date :x-mailer; bh=TiVcaM3Uu3vUsSsJ4BT4Pm6uAPb47fflwFfYhALEeXk=; b=FkrHORkSqnkvk8K/8iItWCJvR9RQda4hqfG48pUI8yMQV6Tbgigwh8rUBGUIuwhwuY szZ3p7AG/5gfwDVyp3UHBguxZzRlYItQVyYXxKhlRF/mhHwB9u23wJ32RU5tdG51jq4k koq5ZqlmMbVbOeNCaq2PImr55uMfqY8Oy8q1M= Received: by 10.101.143.10 with SMTP id v10mr1450082ann.119.1316659670422; Wed, 21 Sep 2011 19:47:50 -0700 (PDT) Received: from triad.knownspace (216-15-41-8.c3-0.gth-ubr1.lnh-gth.md.cable.rcn.com. [216.15.41.8]) by mx.google.com with ESMTPS id r6sm17130176ank.23.2011.09.21.19.47.49 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 21 Sep 2011 19:47:49 -0700 (PDT) Sender: Justin Hibbits Message-Id: <91CC14C1-14F2-41B3-81F1-D90B42F038CA@alumni.cwru.edu> From: Justin Hibbits To: FreeBSD PowerPC ML Content-Type: multipart/mixed; boundary=Apple-Mail-7--949948817 Mime-Version: 1.0 (Apple Message framework v936) Date: Wed, 21 Sep 2011 22:47:47 -0400 X-Mailer: Apple Mail (2.936) Subject: ofw syscons brightness patch X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2011 02:47:51 -0000 --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--