Module Name:    src
Committed By:   phx
Date:           Sat Oct 16 18:22:37 UTC 2010

Modified Files:
        src/sys/arch/macppc/dev: snapper.c

Log Message:
Find all GPIOs in OF also on newer PowerBooks.
Do not use a GPIO or establish an interrupt when it was not found.
To be done: We should use bus_space(9) for reading/writing GPIOs.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/macppc/dev/snapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/macppc/dev/snapper.c
diff -u src/sys/arch/macppc/dev/snapper.c:1.34 src/sys/arch/macppc/dev/snapper.c:1.35
--- src/sys/arch/macppc/dev/snapper.c:1.34	Thu Sep  9 00:24:59 2010
+++ src/sys/arch/macppc/dev/snapper.c	Sat Oct 16 18:22:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: snapper.c,v 1.34 2010/09/09 00:24:59 macallan Exp $	*/
+/*	$NetBSD: snapper.c,v 1.35 2010/10/16 18:22:37 phx Exp $	*/
 /*	Id: snapper.c,v 1.11 2002/10/31 17:42:13 tsubai Exp	*/
 /*	Id: i2s.c,v 1.12 2005/01/15 14:32:35 tsubai Exp		*/
 
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: snapper.c,v 1.34 2010/09/09 00:24:59 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snapper.c,v 1.35 2010/10/16 18:22:37 phx Exp $");
 
 #include <sys/param.h>
 #include <sys/audioio.h>
@@ -1903,16 +1903,18 @@
 {
 	u_int x;
 
-	DPRINTF("ampmute %d --> ", gpio_read(amp_mute));
+	if (amp_mute) {
+		DPRINTF("ampmute %d --> ", gpio_read(amp_mute));
 
-	if (mute)
-		x = amp_active;		/* mute */
-	else
-		x = !amp_active;	/* unmute */
-	if (x != gpio_read(amp_mute))
-		gpio_write(amp_mute, x);
+		if (mute)
+			x = amp_active;		/* mute */
+		else
+			x = !amp_active;	/* unmute */
+		if (x != gpio_read(amp_mute))
+			gpio_write(amp_mute, x);
 
-	DPRINTF("%d\n", gpio_read(amp_mute));
+		DPRINTF("%d\n", gpio_read(amp_mute));
+	}
 }
 
 static void
@@ -1920,16 +1922,18 @@
 {
 	u_int x;
 
-	DPRINTF("headphonemute %d --> ", gpio_read(headphone_mute));
+	if (headphone_mute != NULL) {
+		DPRINTF("headphonemute %d --> ", gpio_read(headphone_mute));
 
-	if (mute)
-		x = headphone_active;	/* mute */
-	else
-		x = !headphone_active;	/* unmute */
-	if (x != gpio_read(headphone_mute))
-		gpio_write(headphone_mute, x);
+		if (mute)
+			x = headphone_active;	/* mute */
+		else
+			x = !headphone_active;	/* unmute */
+		if (x != gpio_read(headphone_mute))
+			gpio_write(headphone_mute, x);
 
-	DPRINTF("%d\n", gpio_read(headphone_mute));
+		DPRINTF("%d\n", gpio_read(headphone_mute));
+	}
 }
 
 static int
@@ -1938,20 +1942,22 @@
 	struct snapper_softc *sc;
 	u_int sense;
 
-	sc = v;
-	sense = *headphone_detect;
-	DPRINTF("headphone detect = 0x%x\n", sense);
-
-	if (((sense & 0x02) >> 1) == headphone_detect_active) {
-		DPRINTF("headphone is inserted\n");
-		snapper_mute_speaker(sc, 1);
-		snapper_mute_headphone(sc, 0);
-		sc->sc_output_mask = 1 << 1;
-	} else {
-		DPRINTF("headphone is NOT inserted\n");
-		snapper_mute_speaker(sc, 0);
-		snapper_mute_headphone(sc, 1);
-		sc->sc_output_mask = 1 << 0;
+	if (headphone_detect != NULL) {
+		sc = v;
+		sense = *headphone_detect;
+		DPRINTF("headphone detect = 0x%x\n", sense);
+
+		if (((sense & 0x02) >> 1) == headphone_detect_active) {
+			DPRINTF("headphone is inserted\n");
+			snapper_mute_speaker(sc, 1);
+			snapper_mute_headphone(sc, 0);
+			sc->sc_output_mask = 1 << 1;
+		} else {
+			DPRINTF("headphone is NOT inserted\n");
+			snapper_mute_speaker(sc, 0);
+			snapper_mute_headphone(sc, 1);
+			sc->sc_output_mask = 1 << 0;
+		}
 	}
 
 	return 1;
@@ -2020,6 +2026,7 @@
 {
 	int gpio;
 	int headphone_detect_intr, headphone_detect_intrtype;
+	uint32_t gpio_base, reg[1];
 #ifdef SNAPPER_DEBUG
 	char fcr[32];
 
@@ -2029,7 +2036,12 @@
 	headphone_detect_intr = -1;
 
 	gpio = of_getnode_byname(OF_parent(node), "gpio");
-	DPRINTF(" /gpio 0x%x\n", gpio);
+	if (OF_getprop(gpio, "reg", reg, sizeof(reg)) == sizeof(reg))
+		gpio_base = reg[0];
+	else
+		gpio_base = 0;
+	DPRINTF(" /gpio 0...@0x%x\n", (unsigned)gpio, gpio_base);
+
 	gpio = OF_child(gpio);
 	while (gpio) {
 		char name[64], audio_gpio[64];
@@ -2041,29 +2053,40 @@
 		addr = 0;
 		OF_getprop(gpio, "name", name, sizeof name);
 		OF_getprop(gpio, "audio-gpio", audio_gpio, sizeof audio_gpio);
-		OF_getprop(gpio, "AAPL,address", &addr, sizeof addr);
+		if (OF_getprop(gpio, "AAPL,address", &addr, sizeof addr) == -1)
+			if (OF_getprop(gpio, "reg", reg, sizeof reg)
+			    == sizeof reg)
+				addr = (char *)sc->sc_baseaddr +
+				    gpio_base + reg[0];
 		DPRINTF(" 0x%x %s %s\n", gpio, name, audio_gpio);
 
 		/* gpio5 */
-		if (strcmp(audio_gpio, "headphone-mute") == 0)
+		if (strcmp(audio_gpio, "headphone-mute") == 0 ||
+		    strcmp(name, "headphone-mute") == 0)
 			headphone_mute = addr;
 		/* gpio6 */
-		if (strcmp(audio_gpio, "amp-mute") == 0)
+		if (strcmp(audio_gpio, "amp-mute") == 0 ||
+		    strcmp(name, "amp-mute") == 0)
 			amp_mute = addr;
 		/* extint-gpio15 */
-		if (strcmp(audio_gpio, "headphone-detect") == 0) {
+		if (strcmp(audio_gpio, "headphone-detect") == 0 ||
+		    strcmp(name, "headphone-detect") == 0) {
 			headphone_detect = addr;
 			OF_getprop(gpio, "audio-gpio-active-state",
 			    &headphone_detect_active, 4);
-			OF_getprop(gpio, "interrupts", intr, 8);
-			headphone_detect_intr = intr[0];
-			headphone_detect_intrtype = intr[1];
+			if (OF_getprop(gpio, "interrupts", intr, 8) == 8) {
+				headphone_detect_intr = intr[0];
+				headphone_detect_intrtype = intr[1];
+			}
 		}
 		/* gpio11 (keywest-11) */
-		if (strcmp(audio_gpio, "audio-hw-reset") == 0)
+		if (strcmp(audio_gpio, "audio-hw-reset") == 0 ||
+		    strcmp(name, "hw-reset") == 0)
 			audio_hw_reset = addr;
+
 		gpio = OF_peer(gpio);
 	}
+
 	DPRINTF(" headphone-mute %p\n", headphone_mute);
 	DPRINTF(" amp-mute %p\n", amp_mute);
 	DPRINTF(" headphone-detect %p\n", headphone_detect);
@@ -2079,8 +2102,10 @@
 	sc->sc_bitspersample = 16;
 
 	/* Enable headphone interrupt? */
-	*headphone_detect |= 0x80;
-	__asm volatile ("eieio");
+	if (headphone_detect != NULL) {
+		*headphone_detect |= 0x80;
+		__asm volatile ("eieio");
+	}
 
 	/* i2c_set_port(port); */
 

Reply via email to