Subject: am7930 on vax status: i'm giving up
To: None <port-vax@NetBSD.org>
From: Blaz Antonic <blaz.antonic@siol.net>
List: port-vax
Date: 02/17/2004 17:04:30
This is a multi-part message in MIME format.
--------------3AA858306AD3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello,
This audio driver has eaten so much of my nerves over the past few days
i'm giving up on it. My bodgery of machine-dependent code is attached
for anybody who might want to toy with it and perhaps even get it to
work :-)
Things have have to do to get it to compile and attach, in no particular
order:
1: modify vax/machdep.c to include IPL_AUDIO among the valid choices in
softintr_establish()
2: modify conf/files.vax to include an entry similar as that in the
sparc tree (files.sparc), the audioamd one, replace audioamd with
vs4kaud in that entry
3: add device entry for audio in your conf.c (i forgot where it's
located, find . -name conf.c in vax arch directory) - mine ended up
being major 76.
4: create propper devices in /dev dierctory. Look up one of my last
mails on the topic, substitute Major numbers from that mail with the
actual numbers you set in step #3.
5: add the following to your kernel config file:
vs4kaud0 at vsbus0 csr 200d0000
audio0 at vs4kaud0
6: create dummy autoconf.h file so MI-part will compile (touch
arch/vax/include/autoconf.h)
This should result in kernel with audio driver compiled in and
sucessfully attaching itself. Audioctl works, cat file.au > /dev/audio
deosn't. There are some debug lines included to help you figure out
what's going on (dread prinf is bogus, it should & 0xff, it's a
byte-wide register only). #define AUDIO_DEBUG 2 or something like that
in the relevant files if you want even more debug output.
I give up, somebody else should try to make it work :) Use e/l/n:7
200d0000 on your Vaxstation 4000 to see if the audio chip is located
there. You should see 0000FF00 on all 8 locations. Also, chip is
detected by the audio interrupt it generates when i flood its input
buffer (of unknown size but apparently under 10 bytes) in
vs4kaud_match().
Blaz Antonic
--
Hi! I'm a signature virus!
Copy me into your signature to help me spread!
--------------3AA858306AD3
Content-Type: text/plain; charset=us-ascii; name="VS4KAUD.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="VS4KAUD.C"
/* $NetBSD: vs4kaud.c,v 1.0 2004/02/13 20:46:00 Blaz Antonic Exp $ */
/*
* Majority of code stolen from audioamd.c Copyright (c) 1995 Rolf Grossmann
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Rolf Grossmann.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "audio.h"
#if NAUDIO > 0
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <machine/vsbus.h>
#include <machine/sid.h>
#include <machine/cpu.h>
#include <machine/scb.h>
#include <sys/audioio.h>
#include <dev/audio_if.h>
#include <dev/ic/am7930reg.h>
#include <dev/ic/am7930var.h>
#include <vax/vsa/vs4kaudvar.h>
#ifdef AUDIO_DEBUG
#define DPRINTF(x) if (am7930debug) printf x
#define DPRINTFN(n,x) if (am7930debug>(n)) printf x
#else
#define DPRINTF(x)
#define DPRINTFN(n,x)
#endif /* AUDIO_DEBUG */
/* AM7930 registers */
volatile long * regs;
/* interrupt interfaces */
int am7930hwintr __P((void *));
//int am7930swintr __P((void *));
void am7930swintr __P((void *));
void *cookie;
/*
* interrupt-handler status
*/
struct am7930_intrhand {
int (*ih_fun) __P((void *));
void *ih_arg;
};
struct vs4kaud_softc {
struct am7930_softc sc_am7930; /* glue to MI code */
bus_space_tag_t sc_bt; /* bus cookie */
bus_space_handle_t sc_bh; /* device registers */
struct am7930_intrhand sc_ih; /* interrupt vector (hw or sw) */
void (*sc_rintr)(void*); /* input completion intr handler */
void *sc_rarg; /* arg for sc_rintr() */
void (*sc_pintr)(void*); /* output completion intr handler */
void *sc_parg; /* arg for sc_pintr() */
/* sc_au is special in that the hardware interrupt handler uses it */
struct auio sc_au; /* recv and xmit buffers, etc */
#define sc_intrcnt sc_au.au_intrcnt /* statistics */
};
void vs4kaud_attach __P((struct device *, struct device *, void *));
int vs4kaud_match __P((struct device *, struct cfdata *, void *));
// void vs4kaud_attach(struct vs4kaud_softc *sc, int);
struct cfattach vs4kaud_ca = {
sizeof(struct vs4kaud_softc),
vs4kaud_match,
vs4kaud_attach
};
/*
* Define our interface into the am7930 MI driver.
*/
u_int8_t vs4kaud_codec_iread __P((struct am7930_softc *, int));
u_int16_t vs4kaud_codec_iread16 __P((struct am7930_softc *, int));
u_int8_t vs4kaud_codec_dread __P((struct vs4kaud_softc *, int));
void vs4kaud_codec_iwrite __P((struct am7930_softc *, int, u_int8_t));
void vs4kaud_codec_iwrite16 __P((struct am7930_softc *, int, u_int16_t));
void vs4kaud_codec_dwrite __P((struct vs4kaud_softc *, int, u_int8_t));
void vs4kaud_onopen __P((struct am7930_softc *sc));
void vs4kaud_onclose __P((struct am7930_softc *sc));
struct am7930_glue vs4kaud_glue = {
vs4kaud_codec_iread,
vs4kaud_codec_iwrite,
vs4kaud_codec_iread16,
vs4kaud_codec_iwrite16,
vs4kaud_onopen,
vs4kaud_onclose,
0,
0,
0,
};
/*
* Define our interface to the higher level audio driver.
*/
int vs4kaud_start_output __P((void *, void *, int, void (*)(void *),
void *));
int vs4kaud_start_input __P((void *, void *, int, void (*)(void *),
void *));
int vs4kaud_getdev __P((void *, struct audio_device *));
struct audio_hw_if sa_hw_if = {
am7930_open,
am7930_close,
0,
am7930_query_encoding,
am7930_set_params,
am7930_round_blocksize,
am7930_commit_settings,
0,
0,
vs4kaud_start_output, /* md */
vs4kaud_start_input, /* md */
am7930_halt_output,
am7930_halt_input,
0,
vs4kaud_getdev,
0,
am7930_set_port,
am7930_get_port,
am7930_query_devinfo,
0,
0,
0,
0,
am7930_get_props,
0,
0,
0,
};
struct audio_device vs4kaud_device = {
"am7930",
"x",
"vs4kaud"
};
int
vs4kaud_match(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct vsbus_attach_args *va = aux;
int i;
if ((vax_boardtype != VAX_BTYP_46) && (vax_boardtype != VAX_BTYP_48) && (vax_boardtype != VAX_BTYP_49))
/* VS 4k VLC, 60 and 9x only */
return 0;
// printf("vs4kaud_match: preparing to generate interrupt\n");
// DELAY(100000);
regs = (long *) va->va_addr;
regs[AM7930_DREG_CR] = AM7930_IREG_INIT;
regs[AM7930_DREG_DR] = (AM7930_INIT_PMS_ACTIVE | AM7930_INIT_INT_ENABLE);
regs[AM7930_DREG_CR] = AM7930_IREG_MUX_MCR1;
regs[AM7930_DREG_DR] = 0;
regs[AM7930_DREG_CR] = AM7930_IREG_MUX_MCR2;
regs[AM7930_DREG_DR] = 0;
regs[AM7930_DREG_CR] = AM7930_IREG_MUX_MCR3;
regs[AM7930_DREG_DR] = ((AM7930_MCRCHAN_BB << 4) | AM7930_MCRCHAN_BA);
regs[AM7930_DREG_CR] = AM7930_IREG_MUX_MCR4;
regs[AM7930_DREG_DR] = AM7930_MCR4_INT_ENABLE;
for (i = 10; i < 20; i++)
regs[AM7930_DREG_BBTB] = i;
DELAY(1000000);
return 1;
}
void
vs4kaud_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct vsbus_attach_args *va = aux;
struct vs4kaud_softc *sc = (struct vs4kaud_softc *)self;
// bus_space_handle_t bh;
// sc->sc_bt = va->va_iot;
regs = (long*)vax_map_physmem(va->va_paddr, 1);
if (regs == 0) {
// if (bus_space_map(sc->sc_bt, va->va_paddr, AM7930_DREG_SIZE * 4, 0, &bh) != 0) {
printf("%s: cannot map AM7930 registers\n", self->dv_xname);
return;
}
// sc->sc_bh = bh;
/*
* Set up glue for MI code early; we use some of it here.
*/
sc->sc_am7930.sc_glue = &vs4kaud_glue;
am7930_init(&sc->sc_am7930, AUDIOAMD_POLL_MODE);
scb_vecalloc(va->va_cvec, (void (*)(void *)) am7930hwintr,
sc, SCB_ISTACK, &sc->sc_intrcnt);
cookie = softintr_establish(IPL_AUDIO, &am7930swintr, sc);
#if 0
(void)bus_intr_establish(sc->sc_bt, PIL_AUSOFT, IPL_AUDIO,
BUS_INTR_ESTABLISH_SOFTINTR,
am7930swintr, sc);
#endif
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
sc->sc_am7930.sc_dev.dv_xname, "intr");
audio_attach_mi(&sa_hw_if, sc, &sc->sc_am7930.sc_dev);
}
void
vs4kaud_onopen(sc)
struct am7930_softc *sc;
{
struct vs4kaud_softc *mdsc = (struct vs4kaud_softc *)sc;
/* reset pdma state */
mdsc->sc_rintr = 0;
mdsc->sc_rarg = 0;
mdsc->sc_pintr = 0;
mdsc->sc_parg = 0;
mdsc->sc_au.au_rdata = 0;
mdsc->sc_au.au_pdata = 0;
}
void
vs4kaud_onclose(sc)
struct am7930_softc *sc;
{
/* Just do the chipset-level halt ? */
am7930_halt_input(sc);
am7930_halt_output(sc);
}
int
vs4kaud_start_output(addr, p, cc, intr, arg)
void *addr;
void *p;
int cc;
void (*intr) __P((void *));
void *arg;
{
struct vs4kaud_softc *sc = addr;
DPRINTFN(1, ("sa_start_output: cc=%d %p (%p)\n", cc, intr, arg));
if (!sc->sc_am7930.sc_locked) {
vs4kaud_codec_iwrite(&sc->sc_am7930,
AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
sc->sc_am7930.sc_locked = 1;
DPRINTF(("sa_start_output: started intrs.\n"));
}
sc->sc_pintr = intr;
sc->sc_parg = arg;
sc->sc_au.au_pdata = p;
sc->sc_au.au_pend = (char *)p + cc - 1;
return(0);
}
int
vs4kaud_start_input(addr, p, cc, intr, arg)
void *addr;
void *p;
int cc;
void (*intr) __P((void *));
void *arg;
{
struct vs4kaud_softc *sc = addr;
DPRINTFN(1, ("sa_start_input: cc=%d %p (%p)\n", cc, intr, arg));
if (!sc->sc_am7930.sc_locked) {
vs4kaud_codec_iwrite(&sc->sc_am7930,
AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
sc->sc_am7930.sc_locked = 1;
DPRINTF(("sa_start_input: started intrs.\n"));
}
sc->sc_rintr = intr;
sc->sc_rarg = arg;
sc->sc_au.au_rdata = p;
sc->sc_au.au_rend = (char *)p + cc -1;
return(0);
}
/*
* Pseudo-DMA support: either C or locore assember.
*/
int
am7930hwintr(v)
void *v;
{
struct vs4kaud_softc *sc = v;
struct auio *au = &sc->sc_au;
u_int8_t *d, *e;
int k;
/* clear interrupt */
k = vs4kaud_codec_dread(sc, AM7930_DREG_IR);
/* receive incoming data */
d = au->au_rdata;
e = au->au_rend;
if (d && d <= e) {
*d = vs4kaud_codec_dread(sc, AM7930_DREG_BBRB);
au->au_rdata++;
if (d == e) {
DPRINTFN(1, ("am7930hwintr: swintr(r) requested"));
softintr_schedule(cookie);
}
}
/* send outgoing data */
d = au->au_pdata;
e = au->au_pend;
if (d && d <= e) {
vs4kaud_codec_dwrite(sc, AM7930_DREG_BBTB, *d);
au->au_pdata++;
if (d == e) {
DPRINTFN(1, ("am7930hwintr: swintr(p) requested"));
softintr_schedule(cookie);
}
}
au->au_intrcnt.ev_count++;
return (1);
}
// int
void
am7930swintr(sc0)
void *sc0;
{
struct vs4kaud_softc *sc = sc0;
struct auio *au;
int s, ret = 0;
DPRINTFN(1, ("audiointr: sc=%p\n", sc));
au = &sc->sc_au;
s = splaudio();
if (au->au_rdata > au->au_rend && sc->sc_rintr != NULL) {
splx(s);
ret = 1;
(*sc->sc_rintr)(sc->sc_rarg);
s = splaudio();
}
if (au->au_pdata > au->au_pend && sc->sc_pintr != NULL) {
splx(s);
ret = 1;
(*sc->sc_pintr)(sc->sc_parg);
} else
splx(s);
// return (ret);
return;
}
/* indirect write */
void
vs4kaud_codec_iwrite(sc, reg, val)
struct am7930_softc *sc;
int reg;
u_int8_t val;
{
struct vs4kaud_softc *mdsc = (struct vs4kaud_softc *)sc;
vs4kaud_codec_dwrite(mdsc, AM7930_DREG_CR * 4, reg);
vs4kaud_codec_dwrite(mdsc, AM7930_DREG_DR * 4, val);
}
void
vs4kaud_codec_iwrite16(sc, reg, val)
struct am7930_softc *sc;
int reg;
u_int16_t val;
{
struct vs4kaud_softc *mdsc = (struct vs4kaud_softc *)sc;
vs4kaud_codec_dwrite(mdsc, AM7930_DREG_CR * 4, reg);
vs4kaud_codec_dwrite(mdsc, AM7930_DREG_DR * 4, val);
vs4kaud_codec_dwrite(mdsc, AM7930_DREG_DR * 4, val>>8);
}
/* indirect read */
u_int8_t
vs4kaud_codec_iread(sc, reg)
struct am7930_softc *sc;
int reg;
{
struct vs4kaud_softc *mdsc = (struct vs4kaud_softc *)sc;
vs4kaud_codec_dwrite(mdsc, AM7930_DREG_CR * 4, reg);
return (vs4kaud_codec_dread(mdsc, AM7930_DREG_DR * 4));
}
u_int16_t
vs4kaud_codec_iread16(sc, reg)
struct am7930_softc *sc;
int reg;
{
struct vs4kaud_softc *mdsc = (struct vs4kaud_softc *)sc;
u_int8_t lo, hi;
vs4kaud_codec_dwrite(mdsc, AM7930_DREG_CR * 4, reg);
lo = vs4kaud_codec_dread(mdsc, AM7930_DREG_DR * 4);
hi = vs4kaud_codec_dread(mdsc, AM7930_DREG_DR * 4);
return ((hi << 8) | lo);
}
/* direct read */
u_int8_t
vs4kaud_codec_dread(sc, reg)
struct vs4kaud_softc *sc;
int reg;
{
printf("vs4kaud_dread(%d): returning %ld\n", reg, regs[reg]);
return regs[reg];
// return (0xff & (bus_space_read_1(sc->sc_bt, sc->sc_bh, reg * 4)));
}
/* direct write */
void
vs4kaud_codec_dwrite(sc, reg, val)
struct vs4kaud_softc *sc;
int reg;
u_int8_t val;
{
printf("vs4kaud_dwrite(%d): writing %d\n", reg, val);
regs[reg] = val;
// bus_space_write_1(sc->sc_bt, sc->sc_bh, reg * 4, val);
}
int
vs4kaud_getdev(addr, retp)
void *addr;
struct audio_device *retp;
{
*retp = vs4kaud_device;
return (0);
}
#endif /* NAUDIO > 0 */
--------------3AA858306AD3--