Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Oct 2011 22:25:19 -0400
From:      Justin Hibbits <jrh29@alumni.cwru.edu>
To:        FreeBSD PowerPC ML <freebsd-ppc@freebsd.org>
Subject:   RFT: PowerBook lid detection
Message-ID:  <1AEF648C-5F24-44F6-893C-1E82C2192DE8@alumni.cwru.edu>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Attached is a patch which sends devctl notifications when the lid is  
opened and closed on a powerbook.  It should turn off the backlight on  
PMU-controlled-backlight laptops (doesn't on mine, because mine is  
controlled by the video card).

Testing please?

- Justin

[-- Attachment #2 --]
Index: ../powermac/pmu.c
===================================================================
--- ../powermac/pmu.c	(revision 226307)
+++ ../powermac/pmu.c	(working copy)
@@ -705,6 +705,24 @@
 		adb_receive_raw_packet(sc->adb_bus,resp[1],resp[2],
 			len - 3,&resp[3]);
 	}
+	if (resp[1] & PMU_INT_ENVIRONMENT) {
+		// if the lid was just closed, do this
+		if ((resp[2] & PMU_ENV_LID_CLOSED) && (!sc->lid_closed)) {
+			uint8_t power_events = PMU_POW_BACKLIGHT | PMU_POW_OFF;
+			pmu_send(sc, PMU_POWER_CTRL, 1, &power_events, 16, resp);
+			sc->lid_closed = 1;
+			if (devctl_process_running())
+				devctl_notify("PMU", "lid", "close", NULL);
+		}
+		else if (!(resp[2] & PMU_ENV_LID_CLOSED) && (sc->lid_closed)) {
+			uint8_t power_events = PMU_POW_BACKLIGHT | PMU_POW_ON;
+			// if the lid was just opened, do this
+			pmu_send(sc, PMU_POWER_CTRL, 1, &power_events, 16, resp);
+			if (devctl_process_running())
+				devctl_notify("PMU", "lid", "open", NULL);
+			sc->lid_closed = 0;
+		}
+	}
 }
 
 static u_int
Index: ../powermac/pmuvar.h
===================================================================
--- ../powermac/pmuvar.h	(revision 226307)
+++ ../powermac/pmuvar.h	(working copy)
@@ -160,6 +160,7 @@
 	volatile int	sc_autopoll;
 	int		sc_batteries;
 	struct cdev	*sc_leddev;
+	int	lid_closed;
 };
 
 struct pmu_battstate {

[-- Attachment #3 --]

help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1AEF648C-5F24-44F6-893C-1E82C2192DE8>