From owner-freebsd-current@FreeBSD.ORG Wed Jun 6 18:00:50 2007 Return-Path: X-Original-To: current@FreeBSD.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7CC9A16A468; Wed, 6 Jun 2007 18:00:50 +0000 (UTC) (envelope-from rpaulo@fnop.net) Received: from core.fnop.net (mx.fnop.net [82.102.11.82]) by mx1.freebsd.org (Postfix) with ESMTP id 1E3E113C45B; Wed, 6 Jun 2007 18:00:50 +0000 (UTC) (envelope-from rpaulo@fnop.net) Received: from core.fnop.net (mx.fnop.net [82.102.11.82]) by core.fnop.net (Postfix) with ESMTP id D8D26690AED; Wed, 6 Jun 2007 18:58:28 +0100 (WEST) Received: by core.fnop.net (Postfix, from userid 1015) id A5F94690B10; Wed, 6 Jun 2007 18:58:28 +0100 (WEST) X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on core.fnop.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.1.7 Received: from epsilon.local.fnop.net (unknown [193.136.24.154]) by core.fnop.net (Postfix) with ESMTP id 269FF690AED; Wed, 6 Jun 2007 18:58:28 +0100 (WEST) Date: Wed, 06 Jun 2007 19:00:42 +0100 Message-ID: <86bqftgdyt.wl%rpaulo@fnop.net> From: Rui Paulo To: Joe Marcus Clarke In-Reply-To: <86ejkpge09.wl%rpaulo@fnop.net> References: <86k5vffjz8.wl%rpaulo@fnop.net> <86ejkx56y6.wl%rpaulo@fnop.net> <465EF64B.9000505@FreeBSD.org> <86fy5drlro.wl%rpaulo@fnop.net> <465EFCDF.5010903@FreeBSD.org> <86ira6saqv.wl%rpaulo@fnop.net> <466469E4.2070106@FreeBSD.org> <86ejkpge09.wl%rpaulo@fnop.net> User-Agent: Wanderlust/2.15.5 (Almost Unreal) Emacs/21.3 Mule/5.0 (SAKAKI) X-cite-me: rpaulo MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Wed_Jun__6_19:00:42_2007-1" X-Virus-Scanned: ClamAV using ClamSMTP Cc: Rui Paulo , current@FreeBSD.org Subject: Re: MacBook patches X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jun 2007 18:00:50 -0000 --Multipart_Wed_Jun__6_19:00:42_2007-1 Content-Type: text/plain; charset=US-ASCII At Wed, 06 Jun 2007 18:59:50 +0100, Rui Paulo wrote: > > [1 ] > At Mon, 04 Jun 2007 15:37:08 -0400, > Joe Marcus Clarke wrote: > > > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > Rui Paulo wrote: > > > At Thu, 31 May 2007 12:50:39 -0400, > > > Joe Marcus Clarke wrote: > > >>> I can try to make this work for you if you are willing to test :-) > > >> Sure. > > > > > > Grab my p4 branch and then apply the attached patch. > > > > This doesn't seem to do anything different that the previous version: > > Can you try the attached version? > Thanks. Oops, blank file. Sorry. -- Rui Paulo --Multipart_Wed_Jun__6_19:00:42_2007-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="backlight.diff" Content-Transfer-Encoding: 7bit ==== //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#5 - /home/rpaulo/p4/rpaulo-macbook/dev/backlight/backlight.c ==== --- /tmp/tmp.90382.50 Wed Jun 6 19:00:01 2007 +++ /home/rpaulo/p4/rpaulo-macbook/dev/backlight/backlight.c Wed Jun 6 18:55:41 2007 @@ -65,8 +65,15 @@ static int backlight_detach(device_t); static int macbook_attach(device_t); static int macbook_enable(SYSCTL_HANDLER_ARGS); static int macbook_level(SYSCTL_HANDLER_ARGS); +static int macbookpro_attach(device_t); +static int macbookpro_enable(SYSCTL_HANDLER_ARGS); +static int macbookpro_level(SYSCTL_HANDLER_ARGS); + struct backlight_model backlight_models[] = { + /* + * MacBook. + */ { "MacBook1,1", 0x8086, 0x27a2, "MacBook Core Duo Backlight Control", macbook_attach, macbook_enable, macbook_level }, @@ -75,6 +82,26 @@ struct backlight_model backlight_models[ "MacBook Core 2 Duo Backlight Control", macbook_attach, macbook_enable, macbook_level }, + /* + * MacBook Pro. + */ + { "MacBookPro1,1", 0x1002, 0x71c5, + "MacBook Pro Core Duo (15-inch) Backlight Control", + macbookpro_attach, macbookpro_enable, macbookpro_level }, + + { "MacBookPro1,2", 0x1002, 0x71c5, + "MacBook Pro Core Duo (17-inch) Backlight Control", + macbookpro_attach, macbookpro_enable, macbookpro_level }, + + { "MacBookPro2,1", 0x1002, 0x71c5, + "MacBook Pro Core 2 Duo (17-inch) Backlight Control", + macbookpro_attach, macbookpro_enable, macbookpro_level }, + + { "MacBookPro2,2", 0x1002, 0x71c5, + "MacBook Pro Core 2 Duo (15-inch) Backlight Control", + macbookpro_attach, macbookpro_enable, macbookpro_level }, + + { NULL, 0, 0 } }; @@ -348,6 +375,125 @@ macbook_level(SYSCTL_HANDLER_ARGS) curlevel = (level * (BACKLIGHT_MB_MAX - BACKLIGHT_MB_MIN) / 100) + BACKLIGHT_MB_MIN; macbook_set_current(sc, curlevel); + + *(unsigned int *)oidp->oid_arg1 = level; + sc->sc_level = curlevel; + + } + + return error; +} + + +/* + * Apple's MacBook Pro specific functions. + */ + +static uint32_t +macbookpro_get_current(struct backlight_softc *sc) +{ + uint32_t level; + + level = bus_read_4(sc->sc_res, BACKLIGHT_MBP_OFFSET); + level = level >> BACKLIGHT_MBP_CUR_SHIFT; + + return level; +} + +static void +macbookpro_set_current(struct backlight_softc *sc, uint32_t value) +{ + uint32_t newlevel; + + newlevel = 0x00000001 | (value << BACKLIGHT_MBP_CUR_SHIFT); + + bus_write_4(sc->sc_res, BACKLIGHT_MBP_OFFSET, newlevel); + + return; +} + +static int +macbookpro_attach(device_t dev) +{ + struct backlight_softc *sc = device_get_softc(dev); + int rid; + uint32_t state; + + rid = PCIR_BAR(0); + sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, + RF_ACTIVE); + if (sc->sc_res == NULL) + return ENOMEM; + + + bus_write_4(sc->sc_res, 0x4dc, 5); + state = bus_read_4(sc->sc_res, 0x7ae4); + bus_write_4(sc->sc_res, 0x7ae4, state); + + device_printf(dev, "%d\n", macbookpro_get_current(sc)); + + sc->sc_enable = macbookpro_get_current(sc) >= BACKLIGHT_MBP_MIN ? 1 : 0; + sc->sc_level = macbookpro_get_current(sc); + + return 0; +} + +static int +macbookpro_enable(SYSCTL_HANDLER_ARGS) +{ + struct backlight_softc *sc = (struct backlight_softc *) arg1; + int error; + unsigned int enable; + + enable = macbookpro_get_current(sc) >= BACKLIGHT_MBP_MIN ? 1 : 0; + + error = sysctl_handle_int(oidp, &enable, 0, req); + + if (error == 0 && req->newptr != NULL) { + enable = *(unsigned int *)req->newptr; + + switch (enable) { + case 0: + macbookpro_set_current(sc, 0); + break; + case 1: + macbookpro_set_current(sc, sc->sc_level); + break; + default: + return EINVAL; + + } + *(unsigned int *)oidp->oid_arg1 = enable; + } + + + return error; +} + +static int +macbookpro_level(SYSCTL_HANDLER_ARGS) +{ + struct backlight_softc *sc = (struct backlight_softc *) arg1; + int error; + uint32_t curlevel; + unsigned int level; + + curlevel = macbookpro_get_current(sc); + + level = (curlevel - BACKLIGHT_MBP_MIN) * 100 / + BACKLIGHT_MBP_MAX; + + error = sysctl_handle_int(oidp, &level, 0, req); + + if (error == 0 && req->newptr != NULL) { + level = *(unsigned int *)req->newptr; + + if (level > 100) + return EINVAL; + + curlevel = (level * (BACKLIGHT_MBP_MAX - BACKLIGHT_MBP_MIN) + / 100) + BACKLIGHT_MBP_MIN; + macbookpro_set_current(sc, curlevel); *(unsigned int *)oidp->oid_arg1 = level; sc->sc_level = curlevel; ==== //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlightvar.h#2 - /home/rpaulo/p4/rpaulo-macbook/dev/backlight/backlightvar.h ==== --- /tmp/tmp.90382.109 Wed Jun 6 19:00:01 2007 +++ /home/rpaulo/p4/rpaulo-macbook/dev/backlight/backlightvar.h Sat Jun 2 15:30:59 2007 @@ -65,3 +65,12 @@ struct backlight_model { #define BACKLIGHT_MB_MAX 0x94 #define BACKLIGHT_MB_OFF 0x12 #define BACKLIGHT_MB_ON 0x1f + +/* + * MacBook Pro specific. + */ +#define BACKLIGHT_MBP_OFFSET 0x7af8 /* register offset */ +#define BACKLIGHT_MBP_CUR_SHIFT 0x08 + +#define BACKLIGHT_MBP_MIN 0x00 +#define BACKLIGHT_MBP_MAX 0xff --Multipart_Wed_Jun__6_19:00:42_2007-1--