Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/macppc/dev don't poke GPIOs directly, use obio_*() ...



details:   https://anonhg.NetBSD.org/src/rev/d843cdbd7df1
branches:  trunk
changeset: 360699:d843cdbd7df1
user:      macallan <macallan%NetBSD.org@localhost>
date:      Sat Mar 24 16:22:48 2018 +0000

description:
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.

diffstat:

 sys/arch/macppc/dev/snapper.c |  67 +++++++++++++++++++++++-------------------
 1 files changed, 36 insertions(+), 31 deletions(-)

diffs (180 lines):

diff -r 7739c1838e8a -r d843cdbd7df1 sys/arch/macppc/dev/snapper.c
--- a/sys/arch/macppc/dev/snapper.c     Sat Mar 24 15:51:57 2018 +0000
+++ b/sys/arch/macppc/dev/snapper.c     Sat Mar 24 16:22:48 2018 +0000
@@ -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_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 @@
         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 @@
                                     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 @@
 }
 
 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 @@
 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 @@
 {
        u_int x;
 
-       if (headphone_mute != NULL) {
+       if (headphone_mute != 0) {
                DPRINTF("headphonemute %d --> ", gpio_read(headphone_mute));
 
                if (mute)
@@ -1961,9 +1961,9 @@
        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 @@
 {
 
        /* No reset port.  Nothing to do. */
-       if (audio_hw_reset == NULL)
+       if (audio_hw_reset == 0)
                goto noreset;
 
        /* Reset TAS3004. */
@@ -2065,7 +2065,7 @@
        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 @@
                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 @@
                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 @@
        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))



Home | Main Index | Thread Index | Old Index