From owner-p4-projects@FreeBSD.ORG Thu Aug 16 18:02:46 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 332FC16A468; Thu, 16 Aug 2007 18:02:46 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E8D5A16A419 for ; Thu, 16 Aug 2007 18:02:45 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CCB4713C45B for ; Thu, 16 Aug 2007 18:02:45 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l7GI2j35002355 for ; Thu, 16 Aug 2007 18:02:45 GMT (envelope-from rpaulo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l7GI2jrD002352 for perforce@freebsd.org; Thu, 16 Aug 2007 18:02:45 GMT (envelope-from rpaulo@FreeBSD.org) Date: Thu, 16 Aug 2007 18:02:45 GMT Message-Id: <200708161802.l7GI2jrD002352@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rpaulo@FreeBSD.org using -f From: Rui Paulo To: Perforce Change Reviews Cc: Subject: PERFORCE change 125226 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Aug 2007 18:02:46 -0000 http://perforce.freebsd.org/chv.cgi?CH=125226 Change 125226 by rpaulo@rpaulo_alpha on 2007/08/16 18:02:36 Add some new comments, fix others. Do some kind of initialization routine that's likely to be needed for MacBook Pros. Affected files ... .. //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#13 edit Differences ... ==== //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#13 (text+ko) ==== @@ -23,10 +23,19 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#12 $ + * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#13 $ * */ +/* + * Driver to control LCD backlight on the MacBook and MacBook Pro + * Apple laptops. + * + * All the technical information regarding to register offsets and + * modus operadi (see the big MacBook comment) came from the + * userland utilities for Linux. + */ + #include __FBSDID("$FreeBSD$"); @@ -218,7 +227,7 @@ * Apple's MacBook specific functions. * * This code was inspired on the MacBook backlight control utility by - * Ryan Lortie. The whole reverse engineering was done by him. + * Ryan Lortie. * * There's a register at BACKLIGHT_MB_OFFSET on PCI_BAR(0) that controls * the LCD backlight. @@ -228,7 +237,6 @@ * * The y bits are the maximum brightness level, the x bits are the * current brightness level. - * Apple's firmware sets the x bits to BACKLIGHT_MB_DEF. * There are two thresholds: BACKLIGHT_MB_OFF and BACKLIGHT_MB_ON that * turn off and on the backlight respectively. * @@ -396,6 +404,7 @@ { struct backlight_softc *sc = device_get_softc(dev); int rid; + int32_t state; rid = PCIR_BAR(0); sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, @@ -404,6 +413,14 @@ if (sc->sc_res == NULL) return (ENOMEM); + /* + * Magic values came from backlight.c written by Nicolas + * Boichat. + */ + bus_write_4(sc->sc_res, 0x4dc, 0x00000005); + state = bus_read_4(sc->sc_res, 0x7ae4); + bus_write_4(sc->sc_res, 0x7ae4, state); + sc->sc_enable = macbookpro_get_current(sc) >= BACKLIGHT_MBP_MIN ? 1 : 0; sc->sc_level = macbookpro_get_current(sc);