Module Name:    src
Committed By:   macallan
Date:           Sat Mar 24 16:22:48 UTC 2018

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

Log Message:
don't poke GPIOs directly, use obio_*() access functions, now this
has a chance of working on G5 where we can't just BAT-map everything with
paddr == busaddr.
Doesn't play audio yet but things like headphone detection work.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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.43 src/sys/arch/macppc/dev/snapper.c:1.44
--- src/sys/arch/macppc/dev/snapper.c:1.43	Mon Jan 29 19:33:39 2018
+++ src/sys/arch/macppc/dev/snapper.c	Sat Mar 24 16:22:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: snapper.c,v 1.43 2018/01/29 19:33:39 macallan Exp $	*/
+/*	$NetBSD: snapper.c,v 1.44 2018/03/24 16:22:48 macallan 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.43 2018/01/29 19:33:39 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snapper.c,v 1.44 2018/03/24 16:22:48 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/audioio.h>
@@ -145,8 +145,8 @@ static void snapper_set_bass(struct snap
 static void snapper_write_mixers(struct snapper_softc *);
 
 static int tas3004_write(struct snapper_softc *, u_int, const void *);
-static int gpio_read(char *);
-static void gpio_write(char *, int);
+static int gpio_read(bus_size_t);
+static void gpio_write(bus_size_t, int);
 static void snapper_mute_speaker(struct snapper_softc *, int);
 static void snapper_mute_headphone(struct snapper_softc *, int);
 static int snapper_cint(void *);
@@ -549,11 +549,11 @@ static const struct audio_format tumbler
 	 2, AUFMT_STEREO, 4, {32000, 44100, 48000, 96000}},
 };
 
-static u_char *amp_mute;
-static u_char *headphone_mute;
-static u_char *audio_hw_reset;
-static u_char *headphone_detect;
-static int headphone_detect_active;
+static bus_size_t amp_mute;
+static bus_size_t headphone_mute;
+static bus_size_t audio_hw_reset;
+static bus_size_t headphone_detect;
+static uint8_t headphone_detect_active;
 
 
 /* I2S registers */
@@ -761,6 +761,7 @@ snapper_attach(device_t parent, device_t
 				     sizeof(struct dbdma_command), NULL);
 
 	sc->sc_baseaddr = ca->ca_baseaddr;
+
 	OF_getprop(soundbus, "reg", reg, sizeof reg);
 	reg[0] += ca->ca_baseaddr;
 	reg[2] += ca->ca_baseaddr;
@@ -1894,24 +1895,23 @@ tas3004_write(struct snapper_softc *sc, 
 }
 
 static int
-gpio_read(char *addr)
+gpio_read(bus_size_t addr)
 {
 
-	if (*addr & GPIO_DATA)
+	if (obio_read_1(addr) & GPIO_DATA)
 		return 1;
 	return 0;
 }
 
 static void
-gpio_write(char *addr, int val)
+gpio_write(bus_size_t addr, int val)
 {
-	u_int data;
+	uint8_t data;
 
 	data = GPIO_DDR_OUTPUT;
 	if (val)
 		data |= GPIO_DATA;
-	*addr = data;
-	__asm volatile ("eieio");
+	obio_write_1(addr, data);
 }
 
 #define headphone_active 0	/* XXX OF */
@@ -1920,7 +1920,7 @@ gpio_write(char *addr, int val)
 static void
 snapper_mute_speaker(struct snapper_softc *sc, int mute)
 {
-	u_int x;
+	int x;
 
 	if (amp_mute) {
 		DPRINTF("ampmute %d --> ", gpio_read(amp_mute));
@@ -1941,7 +1941,7 @@ snapper_mute_headphone(struct snapper_so
 {
 	u_int x;
 
-	if (headphone_mute != NULL) {
+	if (headphone_mute != 0) {
 		DPRINTF("headphonemute %d --> ", gpio_read(headphone_mute));
 
 		if (mute)
@@ -1961,9 +1961,9 @@ snapper_cint(void *v)
 	struct snapper_softc *sc;
 	u_int sense;
 
-	if (headphone_detect != NULL) {
+	if (headphone_detect != 0) {
 		sc = v;
-		sense = *headphone_detect;
+		sense = obio_read_1(headphone_detect);
 		DPRINTF("headphone detect = 0x%x\n", sense);
 
 		if (((sense & 0x02) >> 1) == headphone_detect_active) {
@@ -1992,7 +1992,7 @@ tas3004_init(struct snapper_softc *sc)
 {
 
 	/* No reset port.  Nothing to do. */
-	if (audio_hw_reset == NULL)
+	if (audio_hw_reset == 0)
 		goto noreset;
 
 	/* Reset TAS3004. */
@@ -2065,7 +2065,7 @@ snapper_init(struct snapper_softc *sc, i
 	while (gpio) {
 		char name[64], audio_gpio[64];
 		int intr[2];
-		char *addr;
+		bus_size_t addr;
 
 		memset(name, 0, sizeof name);
 		memset(audio_gpio, 0, sizeof audio_gpio);
@@ -2075,9 +2075,14 @@ snapper_init(struct snapper_softc *sc, i
 		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);
+				addr = gpio_base + reg[0];
+		/*
+		 * XXX
+		 * APL,address contains the absolute address, we only want the
+		 * offset from mac-io's base address
+		 */
+		addr &= 0x7fff;
+		DPRINTF(" 0x%x %s %s %08x\n", gpio, name, audio_gpio, addr);
 
 		/* gpio5 */
 		if (strcmp(audio_gpio, "headphone-mute") == 0 ||
@@ -2105,12 +2110,12 @@ snapper_init(struct snapper_softc *sc, i
 		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);
+	DPRINTF(" headphone-mute %x\n", headphone_mute);
+	DPRINTF(" amp-mute %x\n", amp_mute);
+	DPRINTF(" headphone-detect %x\n", headphone_detect);
 	DPRINTF(" headphone-detect active %x\n", headphone_detect_active);
 	DPRINTF(" headphone-detect intr %x\n", headphone_detect_intr);
-	DPRINTF(" audio-hw-reset %p\n", audio_hw_reset);
+	DPRINTF(" audio-hw-reset %x\n", audio_hw_reset);
 
 	if (headphone_detect_intr != -1)
 		intr_establish(headphone_detect_intr, IST_EDGE, IPL_AUDIO,
@@ -2120,9 +2125,9 @@ snapper_init(struct snapper_softc *sc, i
 	sc->sc_bitspersample = 16;
 
 	/* Enable headphone interrupt? */
-	if (headphone_detect != NULL) {
-		*headphone_detect |= 0x80;
-		__asm volatile ("eieio");
+	if (headphone_detect != 0) {
+		obio_write_1(headphone_detect,
+		    obio_read_1(headphone_detect) | 0x80);
 	}
 
 	if (tas3004_init(sc))

Reply via email to