Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 06 Jun 2007 19:00:42 +0100
From:      Rui Paulo <rpaulo@fnop.net>
To:        Joe Marcus Clarke <marcus@FreeBSD.org>
Cc:        Rui Paulo <rpaulo@fnop.net>, current@FreeBSD.org
Subject:   Re: MacBook patches
Message-ID:  <86bqftgdyt.wl%rpaulo@fnop.net>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
--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  <text/plain; US-ASCII (7bit)>]
> 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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86bqftgdyt.wl%rpaulo>