From owner-freebsd-ppc@FreeBSD.ORG Thu Sep 22 20:52:46 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 447A61065672; Thu, 22 Sep 2011 20:52:46 +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 D244D8FC12; Thu, 22 Sep 2011 20:52:45 +0000 (UTC) Received: by yxk36 with SMTP id 36so2872672yxk.13 for ; Thu, 22 Sep 2011 13:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:cc:message-id:from:to:in-reply-to:content-type:mime-version :subject:date:references:x-mailer; bh=LbjDarIXMv8f9AxJwuVMDdH1x0M/xg4Caiq5JsQ2vUo=; b=i2dCmjrlzZxVZO/4Ekz3fx87WtqrQ/IF11pTJpNRx5IBMv7OiebSpcVAK6Gz7xVi08 GhZ2e/P2I8aBElbx6L1Pzrz6xtW9CasmgX0zawn3YIrKiG3o8odHasMTGA5r1hhySPKv Ys9+umqc/H2MwdJcOlvrYx7yFlpIC2LxPKi74= Received: by 10.150.191.20 with SMTP id o20mr2695866ybf.205.1316724765209; Thu, 22 Sep 2011 13:52:45 -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 i28sm33948976anm.11.2011.09.22.13.52.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Sep 2011 13:52:44 -0700 (PDT) Sender: Justin Hibbits Message-Id: From: Justin Hibbits To: Peter Grehan In-Reply-To: <4E7AAA9D.9010503@freebsd.org> Content-Type: multipart/mixed; boundary=Apple-Mail-11--884856648 Mime-Version: 1.0 (Apple Message framework v936) Date: Thu, 22 Sep 2011 16:52:39 -0400 References: <91CC14C1-14F2-41B3-81F1-D90B42F038CA@alumni.cwru.edu> <4E7AAA9D.9010503@freebsd.org> X-Mailer: Apple Mail (2.936) Cc: FreeBSD PowerPC ML Subject: Re: 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 20:52:46 -0000 --Apple-Mail-11--884856648 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Sep 21, 2011, at 11:25 PM, Peter Grehan wrote: > Hi Justin, > >> 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. > > Is it possible to have the value in the sysctl be 0-100, or 0-10 ? > It might be a bit confusing for the user to have to know that the > range is 0x34-0xff, and have the sysctl code clamp to these. > > Are the MIN_BRIGHTNESS/MAX_BRIGHTNESS values the same for all models ? > > later, > > Peter. Patch take 2 - Range is 0-12. Not sure how to present this to the user. Anything above 12 is capped at 12. - Justin --Apple-Mail-11--884856648 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,66 @@ static int ofwfb_scattach(device_t dev) { + char model[32]; + struct sysctl_ctx_list *ctx; + struct sysctl_oid *tree; + phandle_t rootnode; + + ctx = device_get_sysctl_ctx(dev); + tree = device_get_sysctl_tree(dev); + + rootnode = OF_finddevice("/"); + + /* Brightness can only be adjusted on PowerBook/iBook + * (maybe iMac, but can't confirm) + */ + if (OF_getprop(rootnode, "model", model, sizeof(model)) > 0) { + if (strncmp(model, "PowerBook",9) == 0) { + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "brightness", CTLTYPE_UINT | 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 (newbright > MAX_BRIGHTNESS) + newbright = MAX_BRIGHTNESS; + + /* Cache the new brightness level before scaling. */ + brightness = newbright; + + if (newbright > 0) + { + /* Scale by 17, so it's a range of 0-12. Also, from OpenBSD's source, + * 0x34 is the minimum brightness allowed before the backlight shuts off. + */ + newbright = newbright * 17 + 0x34; + if (newbright > 255) + newbright = 255; + } + OF_call_method("set-contrast", stdout_ih, 1, 0, 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,10 @@ #ifndef _OFW_SYSCONS_H_ #define _OFW_SYSCONS_H_ +#define MIN_BRIGHTNESS 0 +#define MAX_BRIGHTNESS 12 +#define DEFAULT_BRIGHTNESS 6 + struct ofwfb_softc { video_adapter_t sc_va; struct cdev *sc_si; --Apple-Mail-11--884856648 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-11--884856648--