NetBSD/sys/arch/sparc/dev/am7930_sparc.c

630 lines
15 KiB
C
Raw Normal View History

1998-08-28 12:57:38 +04:00
/* $NetBSD: am7930_sparc.c,v 1.41 1998/08/28 08:57:38 pk Exp $ */
1995-04-26 00:05:32 +04:00
/*
* 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/ioctl.h>
#include <sys/device.h>
#include <sys/proc.h>
#include <machine/bus.h>
1995-04-26 00:05:32 +04:00
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <sys/audioio.h>
#include <dev/audio_if.h>
#include <dev/ic/am7930reg.h>
#include <dev/ic/am7930var.h>
1995-04-26 00:05:32 +04:00
#define AUDIO_ROM_NAME "audio"
#ifdef AUDIO_DEBUG
1998-08-28 12:57:38 +04:00
#define DPRINTF(x) if (am7930debug) printf x
1995-04-26 00:05:32 +04:00
#else
#define DPRINTF(x)
#endif /* AUDIO_DEBUG */
1995-04-26 00:05:32 +04:00
/* interrupt interfaces */
#ifdef AUDIO_C_HANDLER
int am7930hwintr __P((void *));
#if defined(SUN4M)
#define AUDIO_SET_SWINTR do { \
if (CPU_ISSUN4M) \
raise(0, 4); \
else \
ienab_bis(IE_L4); \
} while(0);
#else
1995-04-26 00:05:32 +04:00
#define AUDIO_SET_SWINTR ienab_bis(IE_L4)
#endif /* defined(SUN4M) */
1995-04-26 00:05:32 +04:00
#else
struct auio *auiop;
#endif /* AUDIO_C_HANDLER */
int am7930swintr __P((void *));
1995-04-26 00:05:32 +04:00
/* forward declarations */
void am7930_sparc_onopen __P((struct am7930_softc *sc));
void am7930_sparc_onclose __P((struct am7930_softc *sc));
1995-04-26 00:05:32 +04:00
/* autoconfiguration driver */
void am7930attach_mainbus __P((struct device *, struct device *, void *));
int am7930match_mainbus __P((struct device *, struct cfdata *, void *));
void am7930attach_sbus __P((struct device *, struct device *, void *));
int am7930match_sbus __P((struct device *, struct cfdata *, void *));
void am7930_sparc_attach(struct am7930_softc *sc, int);
1995-04-26 00:05:32 +04:00
struct cfattach audioamd_mainbus_ca = {
sizeof(struct am7930_softc), am7930match_mainbus, am7930attach_mainbus
};
struct cfattach audioamd_sbus_ca = {
sizeof(struct am7930_softc), am7930match_sbus, am7930attach_sbus
1995-04-26 00:05:32 +04:00
};
/*
* Define our interface to the higher level audio driver.
*/
int am7930_start_output __P((void *, void *, int, void (*)(void *),
void *));
int am7930_start_input __P((void *, void *, int, void (*)(void *),
void *));
int am7930_set_port __P((void *, mixer_ctrl_t *));
int am7930_get_port __P((void *, mixer_ctrl_t *));
int am7930_query_devinfo __P((void *, mixer_devinfo_t *));
1995-04-26 00:05:32 +04:00
void am7930_sparc_w16 __P((volatile struct am7930 *amd, u_int16_t val));
1995-04-26 00:05:32 +04:00
struct audio_hw_if sa_hw_if = {
am7930_open,
am7930_close,
0,
am7930_query_encoding,
am7930_set_params,
am7930_round_blocksize, /* XXX md? */
am7930_commit_settings,
0,
0,
am7930_start_output, /* XXX md? */
am7930_start_input, /* XXX md? */
am7930_halt_output, /* XXX md? */
am7930_halt_input, /* XXX md? */
0,
am7930_getdev,
0,
am7930_set_port,
am7930_get_port,
am7930_query_devinfo,
0,
0,
0,
0,
am7930_get_props,
1995-04-26 00:05:32 +04:00
};
/* autoconfig routines */
1995-04-26 00:05:32 +04:00
int
am7930match_mainbus(parent, cf, aux)
1995-04-26 00:05:32 +04:00
struct device *parent;
struct cfdata *cf;
void *aux;
1995-04-26 00:05:32 +04:00
{
struct mainbus_attach_args *ma = aux;
1995-04-26 00:05:32 +04:00
1996-02-26 00:53:49 +03:00
if (CPU_ISSUN4)
1995-04-26 00:05:32 +04:00
return (0);
return (strcmp(AUDIO_ROM_NAME, ma->ma_name) == 0);
}
int
am7930match_sbus(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct sbus_attach_args *sa = aux;
return (strcmp(AUDIO_ROM_NAME, sa->sa_name) == 0);
1995-04-26 00:05:32 +04:00
}
/*
* Audio chip found.
*/
void
am7930attach_mainbus(parent, self, aux)
1995-04-26 00:05:32 +04:00
struct device *parent, *self;
void *aux;
1995-04-26 00:05:32 +04:00
{
struct mainbus_attach_args *ma = aux;
struct am7930_softc *sc = (struct am7930_softc *)self;
bus_space_handle_t bh;
sc->sc_bustag = ma->ma_bustag;
if (bus_space_map2(
ma->ma_bustag,
ma->ma_iospace,
ma->ma_paddr,
sizeof(struct am7930),
BUS_SPACE_MAP_LINEAR,
0,
&bh) != 0) {
printf("%s: cannot map registers\n", self->dv_xname);
return;
}
sc->sc_amd = (volatile struct am7930 *)bh;
am7930_sparc_attach(sc, ma->ma_pri);
}
1995-04-26 00:05:32 +04:00
void
am7930attach_sbus(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct sbus_attach_args *sa = aux;
struct am7930_softc *sc = (struct am7930_softc *)self;
bus_space_handle_t bh;
sc->sc_bustag = sa->sa_bustag;
if (sbus_bus_map(
sa->sa_bustag,
sa->sa_slot,
sa->sa_offset,
sizeof(struct am7930),
0, 0,
&bh) != 0) {
printf("%s: cannot map registers\n", self->dv_xname);
1995-04-26 00:05:32 +04:00
return;
}
sc->sc_amd = (volatile struct am7930 *)bh;
am7930_sparc_attach(sc, sa->sa_pri);
}
void
am7930_sparc_attach(sc, pri)
struct am7930_softc *sc;
int pri;
{
printf(" softpri %d\n", PIL_AUSOFT);
1995-04-26 00:05:32 +04:00
sc->sc_au.au_amd = sc->sc_amd;
am7930_init(sc);
sc->sc_wam16 = am7930_sparc_w16;
sc->sc_onopen = am7930_sparc_onopen;
sc->sc_onclose = am7930_sparc_onclose;
1995-04-26 00:05:32 +04:00
#ifndef AUDIO_C_HANDLER
auiop = &sc->sc_au;
(void)bus_intr_establish(sc->sc_bustag, pri,
BUS_INTR_ESTABLISH_FASTTRAP,
(int (*) __P((void *)))amd7930_trap, NULL);
1995-04-26 00:05:32 +04:00
#else
(void)bus_intr_establish(sc->sc_bustag, pri, 0,
am7930hwintr, &sc->sc_au);
1995-04-26 00:05:32 +04:00
#endif
(void)bus_intr_establish(sc->sc_bustag, PIL_AUSOFT,
BUS_INTR_ESTABLISH_SOFTINTR,
am7930swintr, sc);
1995-04-26 00:05:32 +04:00
1995-05-04 23:43:27 +04:00
evcnt_attach(&sc->sc_dev, "intr", &sc->sc_intrcnt);
audio_attach_mi(&sa_hw_if, sc, &sc->sc_dev);
1995-04-26 00:05:32 +04:00
}
/*
* 16-bit register write, big-endian mapping.
*/
void
am7930_sparc_w16(amd, val)
volatile struct am7930 *amd;
u_int16_t val;
1995-04-26 00:05:32 +04:00
{
amd->dr = val;
amd->dr = val >> 8;
1995-04-26 00:05:32 +04:00
}
/*
* MD attach-dependent middle layer:
* move bytes to/from MAP chip.
*/
1995-04-26 00:05:32 +04:00
void
am7930_sparc_onopen(sc)
struct am7930_softc *sc;
{
/* reset pdma state */
1995-04-26 00:05:32 +04:00
sc->sc_rintr = 0;
sc->sc_rarg = 0;
sc->sc_pintr = 0;
sc->sc_parg = 0;
sc->sc_au.au_rdata = 0;
sc->sc_au.au_pdata = 0;
}
void
am7930_sparc_onclose(sc)
struct am7930_softc *sc;
1995-04-26 00:05:32 +04:00
{
/* On sparc, just do the chipset-level halt. */
am7930_halt_input(sc);
am7930_halt_output(sc);
1995-04-26 00:05:32 +04:00
}
int
am7930_start_output(addr, p, cc, intr, arg)
1995-04-26 00:05:32 +04:00
void *addr;
void *p;
int cc;
void (*intr) __P((void *));
1995-04-26 00:05:32 +04:00
void *arg;
{
register struct am7930_softc *sc = addr;
1995-04-26 00:05:32 +04:00
#ifdef AUDIO_DEBUG
if (am7930debug > 1)
1998-08-28 12:57:38 +04:00
printf("sa_start_output: cc=%d %p (%p)\n", cc, intr, arg);
1995-04-26 00:05:32 +04:00
#endif
if (!sc->sc_locked) {
register volatile struct am7930 *amd;
1995-04-26 00:05:32 +04:00
amd = sc->sc_au.au_amd;
amd->cr = AMDR_INIT;
amd->dr = AMD_INIT_PMS_ACTIVE;
sc->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 = p + cc - 1;
1995-04-26 00:05:32 +04:00
return(0);
}
/* ARGSUSED */
int
am7930_start_input(addr, p, cc, intr, arg)
1995-04-26 00:05:32 +04:00
void *addr;
void *p;
int cc;
void (*intr) __P((void *));
1995-04-26 00:05:32 +04:00
void *arg;
{
register struct am7930_softc *sc = addr;
1995-04-26 00:05:32 +04:00
#ifdef AUDIO_DEBUG
if (am7930debug > 1)
1998-08-28 12:57:38 +04:00
printf("sa_start_input: cc=%d %p (%p)\n", cc, intr, arg);
1995-04-26 00:05:32 +04:00
#endif
if (!sc->sc_locked) {
register volatile struct am7930 *amd;
1995-04-26 00:05:32 +04:00
amd = sc->sc_au.au_amd;
amd->cr = AMDR_INIT;
amd->dr = AMD_INIT_PMS_ACTIVE;
sc->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 = p + cc -1;
1995-04-26 00:05:32 +04:00
return(0);
}
1998-08-28 12:57:38 +04:00
/*
* halt routines: on Sparc, just use MI chipset halt.
*/
1995-04-26 00:05:32 +04:00
/*
* Pseudo-DMA support: either C or locore assember.
*/
1995-04-26 00:05:32 +04:00
#ifdef AUDIO_C_HANDLER
1995-04-26 00:05:32 +04:00
int
am7930hwintr(au0)
void *au0;
1995-04-26 00:05:32 +04:00
{
register struct auio *au = au0;
register volatile struct am7930 *amd = au->au_amd;
register u_char *d, *e;
register int k;
1995-04-26 00:05:32 +04:00
k = amd->ir; /* clear interrupt */
1995-04-26 00:05:32 +04:00
/* receive incoming data */
d = au->au_rdata;
e = au->au_rend;
if (d && d <= e) {
*d = amd->bbrb;
au->au_rdata++;
if (d == e) {
#ifdef AUDIO_DEBUG
if (am7930debug > 1)
1998-08-28 12:57:38 +04:00
printf("am7930hwintr: swintr(r) requested");
#endif
AUDIO_SET_SWINTR;
}
}
/* send outgoing data */
d = au->au_pdata;
e = au->au_pend;
if (d && d <= e) {
amd->bbtb = *d;
au->au_pdata++;
if (d == e) {
#ifdef AUDIO_DEBUG
if (am7930debug > 1)
1998-08-28 12:57:38 +04:00
printf("am7930hwintr: swintr(p) requested");
#endif
AUDIO_SET_SWINTR;
}
}
*(au->au_intrcnt)++;
return (1);
1995-04-26 00:05:32 +04:00
}
#endif /* AUDIO_C_HANDLER */
1995-04-26 00:05:32 +04:00
int
am7930swintr(sc0)
void *sc0;
1995-04-26 00:05:32 +04:00
{
register struct am7930_softc *sc = sc0;
register struct auio *au;
register int s, ret = 0;
#ifdef AUDIO_DEBUG
if (am7930debug > 1)
1998-08-28 12:57:38 +04:00
printf("audiointr: sc=%p\n", sc);
#endif
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);
1995-04-26 00:05:32 +04:00
}
/*
1998-08-28 12:57:38 +04:00
* Attach-dependent channel set/query
*/
1995-04-26 00:05:32 +04:00
int
am7930_set_port(addr, cp)
1995-04-26 00:05:32 +04:00
void *addr;
mixer_ctrl_t *cp;
{
register struct am7930_softc *sc = addr;
1995-04-26 00:05:32 +04:00
DPRINTF(("am7930_set_port: port=%d", cp->dev));
1995-04-26 00:05:32 +04:00
if (cp->dev == SUNAUDIO_SOURCE || cp->dev == SUNAUDIO_OUTPUT) {
if (cp->type != AUDIO_MIXER_ENUM)
return(EINVAL);
1998-08-28 12:57:38 +04:00
} else if (cp->type != AUDIO_MIXER_VALUE ||
cp->un.value.num_channels != 1) {
1995-04-26 00:05:32 +04:00
return(EINVAL);
}
1995-04-26 00:05:32 +04:00
switch(cp->dev) {
case SUNAUDIO_MIC_PORT:
sc->sc_rlevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
break;
case SUNAUDIO_SPEAKER:
case SUNAUDIO_HEADPHONES:
sc->sc_plevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
break;
case SUNAUDIO_MONITOR:
sc->sc_mlevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
break;
case SUNAUDIO_SOURCE:
1997-10-20 00:34:54 +04:00
if (cp->un.ord != SUNAUDIO_MIC_PORT)
return EINVAL;
break;
case SUNAUDIO_OUTPUT:
1997-10-20 00:34:54 +04:00
if (cp->un.ord != SUNAUDIO_SPEAKER &&
cp->un.ord != SUNAUDIO_HEADPHONES)
return EINVAL;
1997-10-20 00:34:54 +04:00
sc->sc_out_port = cp->un.ord;
break;
1995-04-26 00:05:32 +04:00
default:
return(EINVAL);
/* NOTREACHED */
}
return(0);
}
int
am7930_get_port(addr, cp)
1995-04-26 00:05:32 +04:00
void *addr;
mixer_ctrl_t *cp;
{
register struct am7930_softc *sc = addr;
1995-04-26 00:05:32 +04:00
DPRINTF(("am7930_get_port: port=%d", cp->dev));
1995-04-26 00:05:32 +04:00
if (cp->dev == SUNAUDIO_SOURCE || cp->dev == SUNAUDIO_OUTPUT) {
if (cp->type != AUDIO_MIXER_ENUM)
return(EINVAL);
1998-08-28 12:57:38 +04:00
} else if (cp->type != AUDIO_MIXER_VALUE ||
cp->un.value.num_channels != 1) {
1995-04-26 00:05:32 +04:00
return(EINVAL);
}
1995-04-26 00:05:32 +04:00
switch(cp->dev) {
case SUNAUDIO_MIC_PORT:
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_rlevel;
break;
case SUNAUDIO_SPEAKER:
case SUNAUDIO_HEADPHONES:
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_plevel;
break;
case SUNAUDIO_MONITOR:
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_mlevel;
break;
case SUNAUDIO_SOURCE:
1997-10-20 00:34:54 +04:00
cp->un.ord = SUNAUDIO_MIC_PORT;
break;
case SUNAUDIO_OUTPUT:
1997-10-20 00:34:54 +04:00
cp->un.ord = sc->sc_out_port;
break;
1995-04-26 00:05:32 +04:00
default:
return(EINVAL);
/* NOTREACHED */
}
return(0);
}
1995-04-26 00:05:32 +04:00
int
am7930_query_devinfo(addr, dip)
1995-04-26 00:05:32 +04:00
void *addr;
register mixer_devinfo_t *dip;
{
switch(dip->index) {
case SUNAUDIO_MIC_PORT:
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = SUNAUDIO_INPUT_CLASS;
dip->prev = dip->next = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioNmicrophone);
dip->un.v.num_channels = 1;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case SUNAUDIO_SPEAKER:
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = SUNAUDIO_OUTPUT_CLASS;
dip->prev = dip->next = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioNspeaker);
dip->un.v.num_channels = 1;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case SUNAUDIO_HEADPHONES:
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = SUNAUDIO_OUTPUT_CLASS;
dip->prev = dip->next = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioNheadphone);
dip->un.v.num_channels = 1;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case SUNAUDIO_MONITOR:
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = SUNAUDIO_MONITOR_CLASS;
dip->prev = dip->next = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioNmonitor);
dip->un.v.num_channels = 1;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case SUNAUDIO_SOURCE:
dip->type = AUDIO_MIXER_ENUM;
dip->mixer_class = SUNAUDIO_RECORD_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioNsource);
dip->un.e.num_mem = 1;
strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
dip->un.e.member[0].ord = SUNAUDIO_MIC_PORT;
break;
case SUNAUDIO_OUTPUT:
dip->type = AUDIO_MIXER_ENUM;
dip->mixer_class = SUNAUDIO_MONITOR_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioNoutput);
dip->un.e.num_mem = 2;
strcpy(dip->un.e.member[0].label.name, AudioNspeaker);
dip->un.e.member[0].ord = SUNAUDIO_SPEAKER;
strcpy(dip->un.e.member[1].label.name, AudioNheadphone);
dip->un.e.member[1].ord = SUNAUDIO_HEADPHONES;
break;
1995-04-26 00:05:32 +04:00
case SUNAUDIO_INPUT_CLASS:
dip->type = AUDIO_MIXER_CLASS;
dip->mixer_class = SUNAUDIO_INPUT_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioCinputs);
1995-04-26 00:05:32 +04:00
break;
case SUNAUDIO_OUTPUT_CLASS:
dip->type = AUDIO_MIXER_CLASS;
dip->mixer_class = SUNAUDIO_OUTPUT_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioCoutputs);
break;
case SUNAUDIO_RECORD_CLASS:
dip->type = AUDIO_MIXER_CLASS;
dip->mixer_class = SUNAUDIO_RECORD_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioCrecord);
1995-04-26 00:05:32 +04:00
break;
case SUNAUDIO_MONITOR_CLASS:
dip->type = AUDIO_MIXER_CLASS;
dip->mixer_class = SUNAUDIO_MONITOR_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioCmonitor);
break;
1995-04-26 00:05:32 +04:00
default:
return ENXIO;
/*NOTREACHED*/
}
DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
1995-04-26 00:05:32 +04:00
return(0);
}
#endif /* NAUDIO > 0 */