From owner-svn-src-stable-9@FreeBSD.ORG Thu Mar 8 01:10:24 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 96A6C106564A; Thu, 8 Mar 2012 01:10:24 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 836E08FC08; Thu, 8 Mar 2012 01:10:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q281AOww018685; Thu, 8 Mar 2012 01:10:24 GMT (envelope-from jhibbits@svn.freebsd.org) Received: (from jhibbits@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q281AO9X018679; Thu, 8 Mar 2012 01:10:24 GMT (envelope-from jhibbits@svn.freebsd.org) Message-Id: <201203080110.q281AO9X018679@svn.freebsd.org> From: Justin Hibbits Date: Thu, 8 Mar 2012 01:10:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r232677 - in stable/9: etc/devd sys/conf sys/powerpc/conf sys/powerpc/powermac X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Mar 2012 01:10:24 -0000 Author: jhibbits Date: Thu Mar 8 01:10:23 2012 New Revision: 232677 URL: http://svn.freebsd.org/changeset/base/232677 Log: MFC r232177: Add backlight control to ATI-graphics PowerBooks and iBooks. Approved by: nwhitehorn (mentor) Added: stable/9/sys/powerpc/powermac/atibl.c - copied unchanged from r232177, head/sys/powerpc/powermac/atibl.c Modified: stable/9/etc/devd/apple.conf stable/9/sys/conf/files.powerpc stable/9/sys/powerpc/conf/GENERIC stable/9/sys/powerpc/conf/GENERIC64 Directory Properties: stable/9/etc/ (props changed) stable/9/sys/ (props changed) Modified: stable/9/etc/devd/apple.conf ============================================================================== --- stable/9/etc/devd/apple.conf Wed Mar 7 23:57:49 2012 (r232676) +++ stable/9/etc/devd/apple.conf Thu Mar 8 01:10:23 2012 (r232677) @@ -19,6 +19,26 @@ notify 0 { }; +# The next blocks enable brightness hotkeys that can be found on Apple laptops +notify 0 { + match "system" "PMU"; + match "subsystem" "keys"; + match "type" "brightness"; + match "notify" "down"; + action "sysctl dev.backlight.0.level=\ + $(expr `sysctl -n dev.backlight.0.level` - 10)"; +}; + +notify 0 { + match "system" "PMU"; + match "subsystem" "keys"; + match "type" "brightness"; + match "notify" "up"; + action "sysctl dev.backlight.0.level=\ + $(expr `sysctl -n dev.backlight.0.level` + 10)"; +}; + + # The next blocks enable volume hotkeys that can be found on Apple laptops notify 0 { match "system" "PMU"; Modified: stable/9/sys/conf/files.powerpc ============================================================================== --- stable/9/sys/conf/files.powerpc Wed Mar 7 23:57:49 2012 (r232676) +++ stable/9/sys/conf/files.powerpc Thu Mar 8 01:10:23 2012 (r232677) @@ -144,6 +144,7 @@ powerpc/ofw/rtas.c optional aim powerpc/powermac/ata_kauai.c optional powermac ata | powermac atamacio powerpc/powermac/ata_macio.c optional powermac ata | powermac atamacio powerpc/powermac/ata_dbdma.c optional powermac ata | powermac atamacio +powerpc/powermac/atibl.c optional powermac atibl powerpc/powermac/cuda.c optional powermac cuda powerpc/powermac/cpcht.c optional powermac pci powerpc/powermac/dbdma.c optional powermac pci Modified: stable/9/sys/powerpc/conf/GENERIC ============================================================================== --- stable/9/sys/powerpc/conf/GENERIC Wed Mar 7 23:57:49 2012 (r232676) +++ stable/9/sys/powerpc/conf/GENERIC Thu Mar 8 01:10:23 2012 (r232677) @@ -177,6 +177,7 @@ device max6690 # PowerMac7,2 temperatu device powermac_nvram # Open Firmware configuration NVRAM device smu # Apple System Management Unit device windtunnel # Apple G4 MDD fan controller +device atibl # ATI-based backlight driver for PowerBooks/iBooks # ADB support device adb Modified: stable/9/sys/powerpc/conf/GENERIC64 ============================================================================== --- stable/9/sys/powerpc/conf/GENERIC64 Wed Mar 7 23:57:49 2012 (r232676) +++ stable/9/sys/powerpc/conf/GENERIC64 Thu Mar 8 01:10:23 2012 (r232677) @@ -184,6 +184,7 @@ device fcu # Apple Fan Control Unit device max6690 # PowerMac7,2 temperature sensor device powermac_nvram # Open Firmware configuration NVRAM device smu # Apple System Management Unit +device atibl # ATI-based backlight driver for PowerBooks/iBooks # ADB support device adb Copied: stable/9/sys/powerpc/powermac/atibl.c (from r232177, head/sys/powerpc/powermac/atibl.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/sys/powerpc/powermac/atibl.c Thu Mar 8 01:10:23 2012 (r232677, copy of r232177, head/sys/powerpc/powermac/atibl.c) @@ -0,0 +1,196 @@ +/*- + * Copyright (c) 2012 Justin Hibbits + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +/* From the xf86-video-ati driver's radeon_reg.h */ +#define RADEON_LVDS_GEN_CNTL 0x02d0 +#define RADEON_LVDS_ON (1 << 0) +#define RADEON_LVDS_DISPLAY_DIS (1 << 1) +#define RADEON_LVDS_PANEL_TYPE (1 << 2) +#define RADEON_LVDS_PANEL_FORMAT (1 << 3) +#define RADEON_LVDS_RST_FM (1 << 6) +#define RADEON_LVDS_EN (1 << 7) +#define RADEON_LVDS_BL_MOD_LEVEL_SHIFT 8 +#define RADEON_LVDS_BL_MOD_LEVEL_MASK (0xff << 8) +#define RADEON_LVDS_BL_MOD_EN (1 << 16) +#define RADEON_LVDS_DIGON (1 << 18) +#define RADEON_LVDS_BLON (1 << 19) + +struct atibl_softc { + device_t dev; + struct resource *sc_memr; +}; + +static void atibl_identify(driver_t *driver, device_t parent); +static int atibl_probe(device_t dev); +static int atibl_attach(device_t dev); +static int atibl_setlevel(struct atibl_softc *sc, int newlevel); +static int atibl_getlevel(struct atibl_softc *sc); +static int atibl_sysctl(SYSCTL_HANDLER_ARGS); + +static device_method_t atibl_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, atibl_identify), + DEVMETHOD(device_probe, atibl_probe), + DEVMETHOD(device_attach, atibl_attach), + {0, 0}, +}; + +static driver_t atibl_driver = { + "backlight", + atibl_methods, + sizeof(struct atibl_softc) +}; + +static devclass_t atibl_devclass; + +DRIVER_MODULE(atibl, vgapci, atibl_driver, atibl_devclass, 0, 0); + +static void +atibl_identify(driver_t *driver, device_t parent) +{ + if (device_find_child(parent, "backlight", -1) == NULL) + device_add_child(parent, "backlight", -1); +} + +static int +atibl_probe(device_t dev) +{ + char control[8]; + phandle_t handle; + + handle = OF_finddevice("mac-io/backlight"); + + if (handle <= 0) + return (ENXIO); + + if (OF_getprop(handle, "backlight-control", &control, sizeof(control)) < 0) + return (ENXIO); + + if (strcmp(control, "ati") != 0) + return (ENXIO); + + device_set_desc(dev, "PowerBook backlight"); + + return (0); +} + +static int +atibl_attach(device_t dev) +{ + struct atibl_softc *sc; + struct sysctl_ctx_list *ctx; + struct sysctl_oid *tree; + int rid; + + sc = device_get_softc(dev); + + rid = 0x18; /* BAR[2], for the MMIO register */ + sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, + RF_ACTIVE | RF_SHAREABLE); + if (sc->sc_memr == NULL) { + device_printf(dev, "Could not alloc mem resource!\n"); + return (ENXIO); + } + + ctx = device_get_sysctl_ctx(dev); + tree = device_get_sysctl_tree(dev); + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "level", CTLTYPE_INT | CTLFLAG_RW, sc, 0, + atibl_sysctl, "I", "Backlight level (0-100)"); + + return (0); +} + +static int +atibl_setlevel(struct atibl_softc *sc, int newlevel) +{ + uint32_t lvds_gen_cntl; + + if (newlevel > 100) + newlevel = 100; + + if (newlevel < 0) + newlevel = 0; + + newlevel = (newlevel * 5) / 2 + 5; + lvds_gen_cntl = bus_read_4(sc->sc_memr, RADEON_LVDS_GEN_CNTL); + lvds_gen_cntl |= RADEON_LVDS_BL_MOD_EN; + lvds_gen_cntl &= ~RADEON_LVDS_BL_MOD_LEVEL_MASK; + lvds_gen_cntl |= (newlevel << RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & + RADEON_LVDS_BL_MOD_LEVEL_MASK; + bus_write_4(sc->sc_memr, RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); + + return (0); +} + +static int +atibl_getlevel(struct atibl_softc *sc) +{ + uint32_t lvds_gen_cntl; + int level; + + lvds_gen_cntl = bus_read_4(sc->sc_memr, RADEON_LVDS_GEN_CNTL); + + level = ((lvds_gen_cntl & RADEON_LVDS_BL_MOD_LEVEL_MASK) >> + RADEON_LVDS_BL_MOD_LEVEL_SHIFT); + level = ((level - 5) * 2) / 5; + + return (level); +} + +static int +atibl_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct atibl_softc *sc; + int newlevel, error; + + sc = arg1; + + newlevel = atibl_getlevel(sc); + + error = sysctl_handle_int(oidp, &newlevel, 0, req); + + if (error || !req->newptr) + return (error); + + return (atibl_setlevel(sc, newlevel)); +}