ansify and KNF

This commit is contained in:
kent 2005-01-14 03:41:45 +00:00
parent d3eafb7e4f
commit c9ec679311
6 changed files with 481 additions and 525 deletions

@ -1,4 +1,4 @@
/* $NetBSD: pas.c,v 1.60 2004/10/29 12:57:17 yamt Exp $ */
/* $NetBSD: pas.c,v 1.61 2005/01/14 03:41:45 kent Exp $ */
/*
* Copyright (c) 1991-1993 Regents of the University of California.
@ -34,7 +34,7 @@
*
*/
/*
* jfw 7/13/97 - The soundblaster code requires the generic bus-space
* jfw 7/13/97 - The soundblaster code requires the generic bus-space
* structures to be set up properly. Rather than go to the effort of making
* code for a dead line fully generic, properly set up the SB structures and
* leave the rest x86/ISA/default-configuration specific. If you have a
@ -42,8 +42,8 @@
*/
/*
* Todo:
* - look at other PAS drivers (for PAS native suport)
* - use common sb.c once emulation is setup
* - look at other PAS drivers (for PAS native suport)
* - use common sb.c once emulation is setup
*/
/*
* jfw 6/21/98 - WARNING: the PAS native IO ports are scattered all around
@ -57,7 +57,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pas.c,v 1.60 2004/10/29 12:57:17 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: pas.c,v 1.61 2005/01/14 03:41:45 kent Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -108,14 +108,14 @@ int pasdebug = 0;
*/
struct pas_softc {
struct sbdsp_softc sc_sbdsp; /* base device, &c. */
bus_space_handle_t pas_port_handle; /* the pas-specific port */
bus_space_handle_t pas_port_handle; /* the pas-specific port */
int model;
int rev;
};
int pas_getdev __P((void *, struct audio_device *));
void pasconf __P((int, int, int, int));
int pas_getdev(void *, struct audio_device *);
void pasconf(int, int, int, int);
/*
@ -145,7 +145,7 @@ const struct audio_hw_if pas_hw_if = {
sb_malloc,
sb_free,
sb_round_buffersize,
sb_mappage,
sb_mappage,
sbdsp_get_props,
sbdsp_trigger_output,
sbdsp_trigger_input,
@ -155,7 +155,7 @@ const struct audio_hw_if pas_hw_if = {
/* The Address Translation code is used to convert I/O register addresses to
be relative to the given base -register */
static char *pasnames[] = {
static const char *pasnames[] = {
"",
"Plus",
"CDPC",
@ -174,12 +174,9 @@ static struct audio_device pas_device = {
#define paswrite(d, p) outb((p), (d))
void
pasconf(model, sbbase, sbirq, sbdrq)
int model;
int sbbase;
int sbirq;
int sbdrq;
pasconf(int model, int sbbase, int sbirq, int sbdrq)
{
paswrite(0x00, INTERRUPT_MASK);
/* Local timer control register */
paswrite(0x36, SAMPLE_COUNTER_CONTROL);
@ -193,23 +190,23 @@ pasconf(model, sbbase, sbirq, sbdrq)
paswrite(0, SAMPLE_BUFFER_COUNTER);
paswrite(P_C_PCM_MONO | P_C_PCM_DAC_MODE |
P_C_MIXER_CROSS_L_TO_L | P_C_MIXER_CROSS_R_TO_R,
PCM_CONTROL);
P_C_MIXER_CROSS_L_TO_L | P_C_MIXER_CROSS_R_TO_R,
PCM_CONTROL);
paswrite(S_M_PCM_RESET | S_M_FM_RESET |
S_M_SB_RESET | S_M_MIXER_RESET, SERIAL_MIXER);
S_M_SB_RESET | S_M_MIXER_RESET, SERIAL_MIXER);
/*XXX*/
paswrite(I_C_1_BOOT_RESET_ENABLE|1, IO_CONFIGURATION_1);
paswrite(I_C_2_PCM_DMA_DISABLED, IO_CONFIGURATION_2);
paswrite(I_C_3_PCM_IRQ_DISABLED, IO_CONFIGURATION_3);
#ifdef BROKEN_BUS_CLOCK
#ifdef BROKEN_BUS_CLOCK
paswrite(S_C_1_PCS_ENABLE | S_C_1_PCS_STEREO | S_C_1_PCS_REALSOUND |
S_C_1_FM_EMULATE_CLOCK, SYSTEM_CONFIGURATION_1);
S_C_1_FM_EMULATE_CLOCK, SYSTEM_CONFIGURATION_1);
#else
paswrite(S_C_1_PCS_ENABLE | S_C_1_PCS_STEREO | S_C_1_PCS_REALSOUND,
SYSTEM_CONFIGURATION_1);
SYSTEM_CONFIGURATION_1);
#endif
/*XXX*/
@ -226,37 +223,39 @@ pasconf(model, sbbase, sbirq, sbdrq)
paswrite(P_M_MV508_ADDRESS | P_M_MV508_PCM, PARALLEL_MIXER);
paswrite(5, PARALLEL_MIXER);
/*
* Setup SoundBlaster emulation.
*/
paswrite((sbbase >> 4) & 0xf, EMULATION_ADDRESS);
paswrite(E_C_SB_IRQ_translate[sbirq] | E_C_SB_DMA_translate[sbdrq],
EMULATION_CONFIGURATION);
EMULATION_CONFIGURATION);
paswrite(C_E_SB_ENABLE, COMPATIBILITY_ENABLE);
/*
* Set mid-range levels.
*/
paswrite(P_M_MV508_ADDRESS | P_M_MV508_MODE, PARALLEL_MIXER);
paswrite(P_M_MV508_LOUDNESS | P_M_MV508_ENHANCE_NONE, PARALLEL_MIXER);
paswrite(P_M_MV508_LOUDNESS | P_M_MV508_ENHANCE_NONE, PARALLEL_MIXER);
paswrite(P_M_MV508_ADDRESS | P_M_MV508_MASTER_A, PARALLEL_MIXER);
paswrite(50, PARALLEL_MIXER);
paswrite(P_M_MV508_ADDRESS | P_M_MV508_MASTER_B, PARALLEL_MIXER);
paswrite(50, PARALLEL_MIXER);
paswrite(P_M_MV508_ADDRESS | P_M_MV508_MIXER | P_M_MV508_SB, PARALLEL_MIXER);
paswrite(P_M_MV508_ADDRESS | P_M_MV508_MIXER | P_M_MV508_SB,
PARALLEL_MIXER);
paswrite(P_M_MV508_OUTPUTMIX | 30, PARALLEL_MIXER);
paswrite(P_M_MV508_ADDRESS | P_M_MV508_MIXER | P_M_MV508_MIC, PARALLEL_MIXER);
paswrite(P_M_MV508_ADDRESS | P_M_MV508_MIXER | P_M_MV508_MIC,
PARALLEL_MIXER);
paswrite(P_M_MV508_INPUTMIX | 30, PARALLEL_MIXER);
}
int pasprobe __P((struct device *, struct cfdata *, void *));
void pasattach __P((struct device *, struct device *, void *));
static int pasfind __P((struct device *, struct pas_softc *,
struct isa_attach_args *, int));
int pasprobe(struct device *, struct cfdata *, void *);
void pasattach(struct device *, struct device *, void *);
static int pasfind(struct device *, struct pas_softc *,
struct isa_attach_args *, int);
/* argument to pasfind */
#define PASPROBE 1
#define PASATTACH 0
@ -269,23 +268,22 @@ CFATTACH_DECL(pas, sizeof(struct pas_softc),
*/
int
pasprobe(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
pasprobe(struct device *parent, struct cfdata *match, void *aux)
{
struct isa_attach_args *ia = aux;
struct pas_softc probesc, *sc = &probesc;
struct isa_attach_args *ia;
struct pas_softc probesc, *sc;
ia = aux;
sc = &probesc;
if (ia->ia_nio < 1)
return (0);
return 0;
if (ia->ia_nirq < 1)
return (0);
return 0;
if (ia->ia_ndrq < 1)
return (0);
return 0;
if (ISA_DIRECT_CONFIG(ia))
return (0);
return 0;
memset(sc, 0, sizeof *sc);
sc->sc_sbdsp.sc_dev.dv_cfdata = match;
@ -297,27 +295,25 @@ pasprobe(parent, match, aux)
* Probe for the soundblaster hardware.
*/
static int
pasfind(parent, sc, ia, probing)
struct device *parent;
struct pas_softc *sc;
struct isa_attach_args *ia;
int probing;
pasfind(struct device *parent, struct pas_softc *sc,
struct isa_attach_args *ia, int probing)
{
int iobase;
u_char id, t;
int rc = 0; /* failure */
int rc;
/* ensure we can set this up as a sound blaster */
if (!SB_BASE_VALID(ia->ia_io[0].ir_addr)) {
rc = 0; /* failure */
/* ensure we can set this up as a sound blaster */
if (!SB_BASE_VALID(ia->ia_io[0].ir_addr)) {
printf("pas: configured SB iobase 0x%x invalid\n",
ia->ia_io[0].ir_addr);
return 0;
}
if (bus_space_map(sc->sc_sbdsp.sc_iot, PAS_DEFAULT_BASE, 1, 0,
&sc->pas_port_handle)) {
&sc->pas_port_handle)) {
printf("pas: can't map base register %x in probe\n",
PAS_DEFAULT_BASE);
PAS_DEFAULT_BASE);
return 0;
}
@ -326,7 +322,7 @@ pasfind(parent, sc, ia, probing)
* warm boot reset of the card will screw up this detect code
* something fierce. Adding code to handle this means possibly
* interfering with other cards on the bus if you have something
* on base port 0x388. SO be forewarned.
* on base port 0x388. SO be forewarned.
*/
/* Talk to first board */
outb(MASTER_DECODE, 0xbc);
@ -375,23 +371,22 @@ pasfind(parent, sc, ia, probing)
sc->model = O_M_1_to_card[t];
if (sc->model != 0) {
sc->rev = pasread(BOARD_REV_ID);
}
else {
} else {
DPRINTF(("pas: bogus model id\n"));
goto unmap1;
}
if (sc->model >= 0) {
if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
printf("pas: sb emulation requires known irq\n");
if (sc->model >= 0) {
if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
printf("pas: sb emulation requires known irq\n");
goto unmap1;
}
pasconf(sc->model, ia->ia_io[0].ir_addr,
ia->ia_irq[0].ir_irq, 1);
} else {
DPRINTF(("pas: could not probe pas\n"));
}
pasconf(sc->model, ia->ia_io[0].ir_addr,
ia->ia_irq[0].ir_irq, 1);
} else {
DPRINTF(("pas: could not probe pas\n"));
goto unmap1;
}
}
/* Now a SoundBlaster, so set up proper bus-space hooks
* appropriately
@ -430,7 +425,7 @@ pasfind(parent, sc, ia, probing)
sc->sc_sbdsp.sc_irq = ia->ia_irq[0].ir_irq;
sc->sc_sbdsp.sc_drq8 = ia->ia_drq[0].ir_drq;
sc->sc_sbdsp.sc_drq16 = -1; /* XXX */
if (sbdsp_probe(&sc->sc_sbdsp) == 0) {
DPRINTF(("pas: sbdsp probe failed\n"));
goto unmap;
@ -450,11 +445,11 @@ pasfind(parent, sc, ia, probing)
unmap:
if (rc == 0 || probing)
bus_space_unmap(sc->sc_sbdsp.sc_iot, sc->sc_sbdsp.sc_ioh,
SBP_NPORT);
bus_space_unmap(sc->sc_sbdsp.sc_iot, sc->sc_sbdsp.sc_ioh,
SBP_NPORT);
unmap1:
if (rc == 0 || probing)
bus_space_unmap(sc->sc_sbdsp.sc_iot, PAS_DEFAULT_BASE, 1);
bus_space_unmap(sc->sc_sbdsp.sc_iot, PAS_DEFAULT_BASE, 1);
return rc;
}
@ -463,14 +458,15 @@ pasfind(parent, sc, ia, probing)
* pseudo-device driver .
*/
void
pasattach(parent, self, aux)
struct device *parent, *self;
void *aux;
pasattach(struct device *parent, struct device *self, void *aux)
{
struct pas_softc *sc = (struct pas_softc *)self;
struct isa_attach_args *ia = (struct isa_attach_args *)aux;
int iobase = ia->ia_io[0].ir_addr;
struct pas_softc *sc;
struct isa_attach_args *ia;
int iobase;
sc = (struct pas_softc *)self;
ia = (struct isa_attach_args *)aux;
iobase = ia->ia_io[0].ir_addr;
if (!pasfind(parent, sc, ia, PASATTACH)) {
printf("%s: pasfind failed\n", sc->sc_sbdsp.sc_dev.dv_xname);
return;
@ -483,7 +479,7 @@ pasattach(parent, self, aux)
printf(" ProAudio Spectrum %s [rev %d] ", pasnames[sc->model],
sc->rev);
sbdsp_attach(&sc->sc_sbdsp);
snprintf(pas_device.name, sizeof(pas_device.name), "pas,%s",
@ -495,10 +491,9 @@ pasattach(parent, self, aux)
}
int
pas_getdev(addr, retp)
void *addr;
struct audio_device *retp;
pas_getdev(void *addr, struct audio_device *retp)
{
*retp = pas_device;
return 0;
}

@ -1,4 +1,4 @@
/* $NetBSD: wss.c,v 1.61 2004/10/29 12:57:17 yamt Exp $ */
/* $NetBSD: wss.c,v 1.62 2005/01/14 03:41:45 kent Exp $ */
/*
* Copyright (c) 1994 John Brezak
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wss.c,v 1.61 2004/10/29 12:57:17 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: wss.c,v 1.62 2005/01/14 03:41:45 kent Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -74,11 +74,11 @@ struct audio_device wss_device = {
"WSS"
};
int wss_getdev __P((void *, struct audio_device *));
int wss_getdev(void *, struct audio_device *);
int wss_mixer_set_port __P((void *, mixer_ctrl_t *));
int wss_mixer_get_port __P((void *, mixer_ctrl_t *));
int wss_query_devinfo __P((void *, mixer_devinfo_t *));
int wss_mixer_set_port(void *, mixer_ctrl_t *);
int wss_mixer_get_port(void *, mixer_ctrl_t *);
int wss_query_devinfo(void *, mixer_devinfo_t *);
/*
* Define our interface to the higher level audio driver.
@ -119,27 +119,24 @@ const struct audio_hw_if wss_hw_if = {
* pseudo-device driver .
*/
void
wssattach(sc)
struct wss_softc *sc;
wssattach(struct wss_softc *sc)
{
struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
struct ad1848_softc *ac;
#if 0 /* loses on CS423X chips */
int version;
#endif
ac = &sc->sc_ad1848.sc_ad1848;
madattach(sc);
sc->sc_ad1848.sc_ih = isa_intr_establish(sc->wss_ic, sc->wss_irq,
IST_EDGE,
IPL_AUDIO, ad1848_isa_intr,
&sc->sc_ad1848);
IST_EDGE, IPL_AUDIO, ad1848_isa_intr, &sc->sc_ad1848);
ad1848_isa_attach(&sc->sc_ad1848);
#if 0 /* loses on CS423X chips */
version = bus_space_read_1(sc->sc_iot, sc->sc_ioh, WSS_STATUS)
& WSS_VERSMASK;
version = bus_space_read_1(sc->sc_iot, sc->sc_ioh, WSS_STATUS)
& WSS_VERSMASK;
printf(" (vers %d)", version);
#endif
@ -175,10 +172,9 @@ wssattach(sc)
}
int
wss_getdev(addr, retp)
void *addr;
struct audio_device *retp;
wss_getdev(void *addr, struct audio_device *retp)
{
*retp = wss_device;
return 0;
}
@ -199,32 +195,28 @@ static ad1848_devmap_t mappings[] = {
static int nummap = sizeof(mappings) / sizeof(mappings[0]);
int
wss_mixer_set_port(addr, cp)
void *addr;
mixer_ctrl_t *cp;
wss_mixer_set_port(void *addr, mixer_ctrl_t *cp)
{
struct ad1848_softc *ac = addr;
struct ad1848_softc *ac;
return (ad1848_mixer_set_port(ac, mappings, nummap, cp));
ac = addr;
return ad1848_mixer_set_port(ac, mappings, nummap, cp);
}
int
wss_mixer_get_port(addr, cp)
void *addr;
mixer_ctrl_t *cp;
wss_mixer_get_port(void *addr, mixer_ctrl_t *cp)
{
struct ad1848_softc *ac = addr;
struct ad1848_softc *ac;
return (ad1848_mixer_get_port(ac, mappings, nummap, cp));
ac = addr;
return ad1848_mixer_get_port(ac, mappings, nummap, cp);
}
int
wss_query_devinfo(addr, dip)
void *addr;
mixer_devinfo_t *dip;
wss_query_devinfo(void *addr, mixer_devinfo_t *dip)
{
DPRINTF(("wss_query_devinfo: index=%d\n", dip->index));
switch(dip->index) {
case WSS_MIC_IN_LVL: /* Microphone */
dip->type = AUDIO_MIXER_VALUE;
@ -235,7 +227,7 @@ wss_query_devinfo(addr, dip)
dip->un.v.num_channels = 2;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case WSS_LINE_IN_LVL: /* line/CD */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = WSS_INPUT_CLASS;
@ -245,7 +237,7 @@ wss_query_devinfo(addr, dip)
dip->un.v.num_channels = 2;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case WSS_DAC_LVL: /* dacout */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = WSS_INPUT_CLASS;
@ -255,7 +247,7 @@ wss_query_devinfo(addr, dip)
dip->un.v.num_channels = 2;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case WSS_REC_LVL: /* record level */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = WSS_RECORD_CLASS;
@ -265,7 +257,7 @@ wss_query_devinfo(addr, dip)
dip->un.v.num_channels = 2;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case WSS_MONITOR_LVL: /* monitor level */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = WSS_MONITOR_CLASS;
@ -275,42 +267,42 @@ wss_query_devinfo(addr, dip)
dip->un.v.num_channels = 1;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case WSS_INPUT_CLASS: /* input class descriptor */
dip->type = AUDIO_MIXER_CLASS;
dip->mixer_class = WSS_INPUT_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioCinputs);
break;
case WSS_MONITOR_CLASS: /* monitor class descriptor */
dip->type = AUDIO_MIXER_CLASS;
dip->mixer_class = WSS_MONITOR_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioCmonitor);
break;
case WSS_RECORD_CLASS: /* record source class */
dip->type = AUDIO_MIXER_CLASS;
dip->mixer_class = WSS_RECORD_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioCrecord);
break;
case WSS_MIC_IN_MUTE:
dip->mixer_class = WSS_INPUT_CLASS;
dip->type = AUDIO_MIXER_ENUM;
dip->prev = WSS_MIC_IN_LVL;
dip->next = AUDIO_MIXER_LAST;
goto mute;
case WSS_LINE_IN_MUTE:
dip->mixer_class = WSS_INPUT_CLASS;
dip->type = AUDIO_MIXER_ENUM;
dip->prev = WSS_LINE_IN_LVL;
dip->next = AUDIO_MIXER_LAST;
goto mute;
case WSS_DAC_MUTE:
dip->mixer_class = WSS_INPUT_CLASS;
dip->type = AUDIO_MIXER_ENUM;
@ -331,7 +323,7 @@ wss_query_devinfo(addr, dip)
strcpy(dip->un.e.member[1].label.name, AudioNon);
dip->un.e.member[1].ord = 1;
break;
case WSS_RECORD_SOURCE:
dip->mixer_class = WSS_RECORD_CLASS;
dip->type = AUDIO_MIXER_ENUM;
@ -352,7 +344,7 @@ wss_query_devinfo(addr, dip)
/*NOTREACHED*/
}
DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
return 0;
}
@ -391,14 +383,12 @@ wss_query_devinfo(addr, dip)
*/
u_int
mad_read(sc, port)
struct wss_softc *sc;
int port;
mad_read(struct wss_softc *sc, int port)
{
u_int tmp;
int pwd;
int s;
switch (sc->mad_chip_type) { /* Output password */
case MAD_82C928:
case MAD_OTI601D:
@ -421,14 +411,11 @@ mad_read(sc, port)
}
void
mad_write(sc, port, value)
struct wss_softc *sc;
int port;
int value;
mad_write(struct wss_softc *sc, int port, int value)
{
int pwd;
int s;
switch (sc->mad_chip_type) { /* Output password */
case MAD_82C928:
case MAD_OTI601D:
@ -450,28 +437,28 @@ mad_write(sc, port, value)
}
void
madattach(sc)
struct wss_softc *sc;
madattach(struct wss_softc *sc)
{
struct ad1848_softc *ac = (struct ad1848_softc *)&sc->sc_ad1848;
struct ad1848_softc *ac;
unsigned char cs4231_mode;
int joy;
ac = (struct ad1848_softc *)&sc->sc_ad1848;
if (sc->mad_chip_type == MAD_NONE)
return;
/* Do we want the joystick disabled? */
joy = ac->sc_dev.dv_cfdata->cf_flags & 2 ? MC1_JOYDISABLE : 0;
/* enable WSS emulation at the I/O port */
mad_write(sc, MC1_PORT, M_WSS_PORT_SELECT(sc->mad_ioindex) | joy);
mad_write(sc, MC2_PORT, MC2_NO_CD_DRQ); /* disable CD */
mad_write(sc, MC3_PORT, 0xf0); /* Disable SB */
cs4231_mode =
cs4231_mode =
strncmp(ac->chip_name, "CS4248", 6) == 0 ||
strncmp(ac->chip_name, "CS4231", 6) == 0 ? 0x02 : 0;
if (sc->mad_chip_type == MAD_82C929) {
mad_write(sc, MC4_PORT, 0x92);
mad_write(sc, MC5_PORT, 0xA5 | cs4231_mode);
@ -480,12 +467,12 @@ madattach(sc)
mad_write(sc, MC4_PORT, 0x02);
mad_write(sc, MC5_PORT, 0x30 | cs4231_mode);
}
#ifdef AUDIO_DEBUG
if (wssdebug) {
int i;
for (i = MC1_PORT; i <= MC7_PORT; i++)
DPRINTF(("port %03x after init = %02x\n",
DPRINTF(("port %03x after init = %02x\n",
i, mad_read(sc, i)));
}
#endif

@ -1,4 +1,4 @@
/* $NetBSD: wss_isa.c,v 1.17 2004/09/14 20:20:49 drochner Exp $ */
/* $NetBSD: wss_isa.c,v 1.18 2005/01/14 03:41:45 kent Exp $ */
/*
* Copyright (c) 1994 John Brezak
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wss_isa.c,v 1.17 2004/09/14 20:20:49 drochner Exp $");
__KERNEL_RCSID(0, "$NetBSD: wss_isa.c,v 1.18 2005/01/14 03:41:45 kent Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -71,15 +71,15 @@ extern int wssdebug;
#define DPRINTF(x)
#endif
static int wssfind __P((struct device *, struct wss_softc *, int,
struct isa_attach_args *));
static int wssfind(struct device *, struct wss_softc *, int,
struct isa_attach_args *);
static void madprobe __P((struct wss_softc *, int));
static void madunmap __P((struct wss_softc *));
static int detect_mad16 __P((struct wss_softc *, int));
static void madprobe(struct wss_softc *, int);
static void madunmap(struct wss_softc *);
static int detect_mad16(struct wss_softc *, int);
int wss_isa_probe __P((struct device *, struct cfdata *, void *));
void wss_isa_attach __P((struct device *, struct device *, void *));
int wss_isa_probe(struct device *, struct cfdata *, void *);
void wss_isa_attach(struct device *, struct device *, void *);
CFATTACH_DECL(wss_isa, sizeof(struct wss_softc),
wss_isa_probe, wss_isa_attach, NULL, NULL);
@ -88,145 +88,143 @@ CFATTACH_DECL(wss_isa, sizeof(struct wss_softc),
* Probe for the Microsoft Sound System hardware.
*/
int
wss_isa_probe(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
wss_isa_probe(struct device *parent, struct cfdata *match, void *aux)
{
struct isa_attach_args *ia = aux;
struct wss_softc probesc, *sc = &probesc;
struct ad1848_softc *ac = (struct ad1848_softc *)&sc->sc_ad1848;
struct isa_attach_args *ia;
struct wss_softc probesc, *sc;
struct ad1848_softc *ac;
if (ia->ia_nio < 1)
return 0;
if (ia->ia_nirq < 1)
return 0;
if (ia->ia_ndrq < 1)
return 0;
ia = aux;
sc = &probesc;
ac = (struct ad1848_softc *)&sc->sc_ad1848;
if (ia->ia_nio < 1)
return 0;
if (ia->ia_nirq < 1)
return 0;
if (ia->ia_ndrq < 1)
return 0;
if (ISA_DIRECT_CONFIG(ia))
return 0;
if (ISA_DIRECT_CONFIG(ia))
return 0;
memset(sc, 0, sizeof *sc);
ac->sc_dev.dv_cfdata = match;
if (wssfind(parent, sc, 1, aux)) {
bus_space_unmap(sc->sc_iot, sc->sc_ioh, WSS_CODEC);
ad1848_isa_unmap(&sc->sc_ad1848);
madunmap(sc);
return 1;
} else
/* Everything is already unmapped */
return 0;
memset(sc, 0, sizeof *sc);
ac->sc_dev.dv_cfdata = match;
if (wssfind(parent, sc, 1, aux)) {
bus_space_unmap(sc->sc_iot, sc->sc_ioh, WSS_CODEC);
ad1848_isa_unmap(&sc->sc_ad1848);
madunmap(sc);
return 1;
} else
/* Everything is already unmapped */
return 0;
}
static int
wssfind(parent, sc, probing, ia)
struct device *parent;
struct wss_softc *sc;
int probing;
struct isa_attach_args *ia;
wssfind(struct device *parent, struct wss_softc *sc, int probing,
struct isa_attach_args *ia)
{
struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
static u_char interrupt_bits[12] = {
-1, -1, -1, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20
};
static u_char dma_bits[4] = {1, 2, 0, 3};
int ndrq, playdrq, recdrq;
static u_char interrupt_bits[12] = {
-1, -1, -1, -1, -1, -1, -1, 0x08, -1, 0x10, 0x18, 0x20
};
static u_char dma_bits[4] = {1, 2, 0, 3};
struct ad1848_softc *ac;
int ndrq, playdrq, recdrq;
sc->sc_iot = ia->ia_iot;
if (ac->sc_dev.dv_cfdata->cf_flags & 1)
madprobe(sc, ia->ia_io[0].ir_addr);
else
sc->mad_chip_type = MAD_NONE;
ac = &sc->sc_ad1848.sc_ad1848;
sc->sc_iot = ia->ia_iot;
if (ac->sc_dev.dv_cfdata->cf_flags & 1)
madprobe(sc, ia->ia_io[0].ir_addr);
else
sc->mad_chip_type = MAD_NONE;
#if 0
if (!WSS_BASE_VALID(ia->ia_io[0].ir_addr)) {
DPRINTF(("wss: configured iobase %x invalid\n", ia->ia_iobase));
goto bad1;
}
if (!WSS_BASE_VALID(ia->ia_io[0].ir_addr)) {
DPRINTF(("wss: configured iobase %x invalid\n", ia->ia_iobase));
goto bad1;
}
#endif
/* Map the ports upto the AD1848 port */
if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, WSS_CODEC,
0, &sc->sc_ioh))
goto bad1;
/* Map the ports upto the AD1848 port */
if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, WSS_CODEC,
0, &sc->sc_ioh))
goto bad1;
ac->sc_iot = sc->sc_iot;
ac->sc_iot = sc->sc_iot;
/* Is there an ad1848 chip at (WSS iobase + WSS_CODEC)? */
if (ad1848_isa_mapprobe(&sc->sc_ad1848,
ia->ia_io[0].ir_addr + WSS_CODEC) == 0)
goto bad;
/* Is there an ad1848 chip at (WSS iobase + WSS_CODEC)? */
if (ad1848_isa_mapprobe(&sc->sc_ad1848,
ia->ia_io[0].ir_addr + WSS_CODEC) == 0)
goto bad;
#if 0
/* Setup WSS interrupt and DMA */
if (!WSS_DRQ_VALID(ia->ia_drq[0].ir_drq)) {
DPRINTF(("wss: configured DMA chan %d invalid\n",
ia->ia_drq[0].ir_drq));
goto bad;
}
/* Setup WSS interrupt and DMA */
if (!WSS_DRQ_VALID(ia->ia_drq[0].ir_drq)) {
DPRINTF(("wss: configured DMA chan %d invalid\n",
ia->ia_drq[0].ir_drq));
goto bad;
}
#endif
sc->wss_playdrq = ia->ia_drq[0].ir_drq;
sc->wss_ic = ia->ia_ic;
sc->wss_playdrq = ia->ia_drq[0].ir_drq;
sc->wss_ic = ia->ia_ic;
if (sc->wss_playdrq != ISA_UNKNOWN_DRQ &&
!isa_drq_isfree(sc->wss_ic, sc->wss_playdrq))
goto bad;
if (sc->wss_playdrq != ISA_UNKNOWN_DRQ &&
!isa_drq_isfree(sc->wss_ic, sc->wss_playdrq))
goto bad;
#if 0
if (!WSS_IRQ_VALID(ia->ia_irq[0].ir_irq)) {
DPRINTF(("wss: configured interrupt %d invalid\n",
ia->ia_irq[0].ir_irq));
goto bad;
}
if (!WSS_IRQ_VALID(ia->ia_irq[0].ir_irq)) {
DPRINTF(("wss: configured interrupt %d invalid\n",
ia->ia_irq[0].ir_irq));
goto bad;
}
#endif
sc->wss_irq = ia->ia_irq[0].ir_irq;
sc->wss_irq = ia->ia_irq[0].ir_irq;
playdrq = ia->ia_drq[0].ir_drq;
if (ia->ia_ndrq > 1) {
ndrq = 2;
recdrq = ia->ia_drq[1].ir_drq;
} else {
ndrq = 1;
recdrq = ISA_UNKNOWN_DRQ;
}
playdrq = ia->ia_drq[0].ir_drq;
if (ia->ia_ndrq > 1) {
ndrq = 2;
recdrq = ia->ia_drq[1].ir_drq;
} else {
ndrq = 1;
recdrq = ISA_UNKNOWN_DRQ;
}
if (ac->mode <= 1)
ndrq = 1;
sc->wss_recdrq =
ac->mode > 1 && ndrq > 1 &&
recdrq != ISA_UNKNOWN_DRQ ? recdrq : playdrq;
if (sc->wss_recdrq != sc->wss_playdrq && !isa_drq_isfree(sc->wss_ic,
sc->wss_recdrq))
goto bad;
if (ac->mode <= 1)
ndrq = 1;
sc->wss_recdrq =
ac->mode > 1 && ndrq > 1 &&
recdrq != ISA_UNKNOWN_DRQ ? recdrq : playdrq;
if (sc->wss_recdrq != sc->wss_playdrq && !isa_drq_isfree(sc->wss_ic,
sc->wss_recdrq))
goto bad;
if (probing) {
ia->ia_nio = 1;
ia->ia_io[0].ir_size = WSS_NPORT;
if (probing) {
ia->ia_nio = 1;
ia->ia_io[0].ir_size = WSS_NPORT;
ia->ia_nirq = 1;
ia->ia_nirq = 1;
ia->ia_ndrq = ndrq;
ia->ia_drq[0].ir_drq = playdrq;
if (ndrq > 1)
ia->ia_drq[1].ir_drq = recdrq;
ia->ia_ndrq = ndrq;
ia->ia_drq[0].ir_drq = playdrq;
if (ndrq > 1)
ia->ia_drq[1].ir_drq = recdrq;
ia->ia_niomem = 0;
}
ia->ia_niomem = 0;
}
/* XXX recdrq */
bus_space_write_1(sc->sc_iot, sc->sc_ioh, WSS_CONFIG,
(interrupt_bits[ia->ia_irq[0].ir_irq] |
dma_bits[ia->ia_drq[0].ir_drq]));
/* XXX recdrq */
bus_space_write_1(sc->sc_iot, sc->sc_ioh, WSS_CONFIG,
(interrupt_bits[ia->ia_irq[0].ir_irq] |
dma_bits[ia->ia_drq[0].ir_drq]));
return 1;
return 1;
bad:
bus_space_unmap(sc->sc_iot, sc->sc_ioh, WSS_CODEC);
bus_space_unmap(sc->sc_iot, sc->sc_ioh, WSS_CODEC);
bad1:
madunmap(sc);
return 0;
madunmap(sc);
return 0;
}
/*
@ -234,22 +232,23 @@ bad1:
* pseudo-device driver .
*/
void
wss_isa_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
wss_isa_attach(struct device *parent, struct device *self, void *aux)
{
struct wss_softc *sc = (struct wss_softc *)self;
struct ad1848_softc *ac = (struct ad1848_softc *)&sc->sc_ad1848;
struct isa_attach_args *ia = (struct isa_attach_args *)aux;
if (!wssfind(parent, sc, 0, ia)) {
printf("%s: wssfind failed\n", ac->sc_dev.dv_xname);
return;
}
struct wss_softc *sc;
struct ad1848_softc *ac;
struct isa_attach_args *ia;
sc->wss_ic = ia->ia_ic;
sc = (struct wss_softc *)self;
ac = (struct ad1848_softc *)&sc->sc_ad1848;
ia = (struct isa_attach_args *)aux;
if (!wssfind(parent, sc, 0, ia)) {
printf("%s: wssfind failed\n", ac->sc_dev.dv_xname);
return;
}
wssattach(sc);
sc->wss_ic = ia->ia_ic;
wssattach(sc);
}
/*
@ -287,125 +286,121 @@ wss_isa_attach(parent, self, aux)
*/
static int
detect_mad16(sc, chip_type)
struct wss_softc *sc;
int chip_type;
detect_mad16(struct wss_softc *sc, int chip_type)
{
unsigned char tmp, tmp2;
unsigned char tmp, tmp2;
sc->mad_chip_type = chip_type;
/*
* Check that reading a register doesn't return bus float (0xff)
* when the card is accessed using password. This may fail in case
* the card is in low power mode. Normally at least the power saving mode
* bit should be 0.
*/
if ((tmp = mad_read(sc, MC1_PORT)) == 0xff) {
DPRINTF(("MC1_PORT returned 0xff\n"));
return 0;
}
sc->mad_chip_type = chip_type;
/*
* Check that reading a register doesn't return bus float (0xff)
* when the card is accessed using password. This may fail in case
* the card is in low power mode. Normally at least the power saving mode
* bit should be 0.
*/
if ((tmp = mad_read(sc, MC1_PORT)) == 0xff) {
DPRINTF(("MC1_PORT returned 0xff\n"));
return 0;
}
/*
* Now check that the gate is closed on first I/O after writing
* the password. (This is how a MAD16 compatible card works).
*/
if ((tmp2 = bus_space_read_1(sc->sc_iot, sc->mad_ioh, MC1_PORT)) == tmp) {
DPRINTF(("MC1_PORT didn't close after read (0x%02x)\n", tmp2));
return 0;
}
/*
* Now check that the gate is closed on first I/O after writing
* the password. (This is how a MAD16 compatible card works).
*/
if ((tmp2 = bus_space_read_1(sc->sc_iot, sc->mad_ioh, MC1_PORT)) == tmp) {
DPRINTF(("MC1_PORT didn't close after read (0x%02x)\n", tmp2));
return 0;
}
mad_write(sc, MC1_PORT, tmp ^ 0x80); /* Toggle a bit */
mad_write(sc, MC1_PORT, tmp ^ 0x80); /* Toggle a bit */
/* Compare the bit */
if ((tmp2 = mad_read(sc, MC1_PORT)) != (tmp ^ 0x80)) {
mad_write(sc, MC1_PORT, tmp); /* Restore */
DPRINTF(("Bit revert test failed (0x%02x, 0x%02x)\n", tmp, tmp2));
return 0;
}
/* Compare the bit */
if ((tmp2 = mad_read(sc, MC1_PORT)) != (tmp ^ 0x80)) {
mad_write(sc, MC1_PORT, tmp); /* Restore */
DPRINTF(("Bit revert test failed (0x%02x, 0x%02x)\n", tmp, tmp2));
return 0;
}
mad_write(sc, MC1_PORT, tmp); /* Restore */
return 1;
return 1;
}
static void
madprobe(sc, iobase)
struct wss_softc *sc;
int iobase;
madprobe(struct wss_softc *sc, int iobase)
{
static int valid_ports[M_WSS_NPORTS] =
{ M_WSS_PORT0, M_WSS_PORT1, M_WSS_PORT2, M_WSS_PORT3 };
int i;
static int valid_ports[M_WSS_NPORTS] =
{ M_WSS_PORT0, M_WSS_PORT1, M_WSS_PORT2, M_WSS_PORT3 };
int i;
/* Allocate bus space that the MAD chip wants */
if (bus_space_map(sc->sc_iot, MAD_BASE, MAD_NPORT, 0, &sc->mad_ioh))
goto bad0;
if (bus_space_map(sc->sc_iot, MAD_REG1, MAD_LEN1, 0, &sc->mad_ioh1))
goto bad1;
if (bus_space_map(sc->sc_iot, MAD_REG2, MAD_LEN2, 0, &sc->mad_ioh2))
goto bad2;
if (bus_space_map(sc->sc_iot, MAD_REG3, MAD_LEN3, 0, &sc->sc_opl_ioh))
goto bad3;
/* Allocate bus space that the MAD chip wants */
if (bus_space_map(sc->sc_iot, MAD_BASE, MAD_NPORT, 0, &sc->mad_ioh))
goto bad0;
if (bus_space_map(sc->sc_iot, MAD_REG1, MAD_LEN1, 0, &sc->mad_ioh1))
goto bad1;
if (bus_space_map(sc->sc_iot, MAD_REG2, MAD_LEN2, 0, &sc->mad_ioh2))
goto bad2;
if (bus_space_map(sc->sc_iot, MAD_REG3, MAD_LEN3, 0, &sc->sc_opl_ioh))
goto bad3;
DPRINTF(("mad: Detect using password = 0xE2\n"));
if (!detect_mad16(sc, MAD_82C928)) {
/* No luck. Try different model */
DPRINTF(("mad: Detect using password = 0xE3\n"));
if (!detect_mad16(sc, MAD_82C929))
goto bad;
sc->mad_chip_type = MAD_82C929;
DPRINTF(("mad: 82C929 detected\n"));
} else {
sc->mad_chip_type = MAD_82C928;
if ((mad_read(sc, MC3_PORT) & 0x03) == 0x03) {
DPRINTF(("mad: Mozart detected\n"));
sc->mad_chip_type = MAD_OTI601D;
DPRINTF(("mad: Detect using password = 0xE2\n"));
if (!detect_mad16(sc, MAD_82C928)) {
/* No luck. Try different model */
DPRINTF(("mad: Detect using password = 0xE3\n"));
if (!detect_mad16(sc, MAD_82C929))
goto bad;
sc->mad_chip_type = MAD_82C929;
DPRINTF(("mad: 82C929 detected\n"));
} else {
DPRINTF(("mad: 82C928 detected?\n"));
sc->mad_chip_type = MAD_82C928;
sc->mad_chip_type = MAD_82C928;
if ((mad_read(sc, MC3_PORT) & 0x03) == 0x03) {
DPRINTF(("mad: Mozart detected\n"));
sc->mad_chip_type = MAD_OTI601D;
} else {
DPRINTF(("mad: 82C928 detected?\n"));
sc->mad_chip_type = MAD_82C928;
}
}
}
#ifdef AUDIO_DEBUG
if (wssdebug)
for (i = MC1_PORT; i <= MC7_PORT; i++)
printf("mad: port %03x = %02x\n", i, mad_read(sc, i));
if (wssdebug)
for (i = MC1_PORT; i <= MC7_PORT; i++)
printf("mad: port %03x = %02x\n", i, mad_read(sc, i));
#endif
/* Set the WSS address. */
for (i = 0; i < M_WSS_NPORTS; i++)
if (valid_ports[i] == iobase)
break;
if (i >= M_WSS_NPORTS) { /* Not a valid port */
printf("mad: Bad WSS base address 0x%x\n", iobase);
goto bad;
}
sc->mad_ioindex = i;
/* enable WSS emulation at the I/O port, no joystick */
mad_write(sc, MC1_PORT, M_WSS_PORT_SELECT(i) | MC1_JOYDISABLE);
mad_write(sc, MC2_PORT, 0x03); /* ? */
mad_write(sc, MC3_PORT, 0xf0); /* Disable SB */
return;
/* Set the WSS address. */
for (i = 0; i < M_WSS_NPORTS; i++)
if (valid_ports[i] == iobase)
break;
if (i >= M_WSS_NPORTS) { /* Not a valid port */
printf("mad: Bad WSS base address 0x%x\n", iobase);
goto bad;
}
sc->mad_ioindex = i;
/* enable WSS emulation at the I/O port, no joystick */
mad_write(sc, MC1_PORT, M_WSS_PORT_SELECT(i) | MC1_JOYDISABLE);
mad_write(sc, MC2_PORT, 0x03); /* ? */
mad_write(sc, MC3_PORT, 0xf0); /* Disable SB */
return;
bad:
bus_space_unmap(sc->sc_iot, sc->sc_opl_ioh, MAD_LEN3);
bus_space_unmap(sc->sc_iot, sc->sc_opl_ioh, MAD_LEN3);
bad3:
bus_space_unmap(sc->sc_iot, sc->mad_ioh2, MAD_LEN2);
bus_space_unmap(sc->sc_iot, sc->mad_ioh2, MAD_LEN2);
bad2:
bus_space_unmap(sc->sc_iot, sc->mad_ioh1, MAD_LEN1);
bus_space_unmap(sc->sc_iot, sc->mad_ioh1, MAD_LEN1);
bad1:
bus_space_unmap(sc->sc_iot, sc->mad_ioh, MAD_NPORT);
bus_space_unmap(sc->sc_iot, sc->mad_ioh, MAD_NPORT);
bad0:
sc->mad_chip_type = MAD_NONE;
sc->mad_chip_type = MAD_NONE;
}
static void
madunmap(sc)
struct wss_softc *sc;
madunmap(struct wss_softc *sc)
{
if (sc->mad_chip_type == MAD_NONE)
return;
bus_space_unmap(sc->sc_iot, sc->mad_ioh, MAD_NPORT);
bus_space_unmap(sc->sc_iot, sc->mad_ioh1, MAD_LEN1);
bus_space_unmap(sc->sc_iot, sc->mad_ioh2, MAD_LEN2);
bus_space_unmap(sc->sc_iot, sc->sc_opl_ioh, MAD_LEN3);
if (sc->mad_chip_type == MAD_NONE)
return;
bus_space_unmap(sc->sc_iot, sc->mad_ioh, MAD_NPORT);
bus_space_unmap(sc->sc_iot, sc->mad_ioh1, MAD_LEN1);
bus_space_unmap(sc->sc_iot, sc->mad_ioh2, MAD_LEN2);
bus_space_unmap(sc->sc_iot, sc->sc_opl_ioh, MAD_LEN3);
}

@ -1,4 +1,4 @@
/* $NetBSD: wssvar.h,v 1.7 1999/08/14 21:19:29 augustss Exp $ */
/* $NetBSD: wssvar.h,v 1.8 2005/01/14 03:41:45 kent Exp $ */
/*
* Copyright (c) 1994 John Brezak
@ -67,7 +67,7 @@ struct wss_softc {
bus_space_handle_t sc_opl_ioh; /* OPL handle */
int mic_mute, cd_mute, dac_mute;
int mic_mute, cd_mute, dac_mute;
int mad_chip_type; /* chip type if MAD emulation of WSS */
int mad_ioindex;
@ -75,8 +75,8 @@ struct wss_softc {
bus_space_handle_t mad_ioh1, mad_ioh2;
};
void wssattach __P((struct wss_softc *));
void wssattach(struct wss_softc *);
u_int mad_read __P((struct wss_softc *, int));
void mad_write __P((struct wss_softc *, int, int));
void madattach __P((struct wss_softc *));
u_int mad_read(struct wss_softc *, int);
void mad_write(struct wss_softc *, int, int);
void madattach(struct wss_softc *);

@ -1,4 +1,4 @@
/* $NetBSD: ym.c,v 1.23 2004/10/29 12:57:17 yamt Exp $ */
/* $NetBSD: ym.c,v 1.24 2005/01/14 03:41:45 kent Exp $ */
/*-
* Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ym.c,v 1.23 2004/10/29 12:57:17 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: ym.c,v 1.24 2005/01/14 03:41:45 kent Exp $");
#include "mpu_ym.h"
#include "opt_ym.h"
@ -151,29 +151,29 @@ int ymdebug = 0;
#endif
#define DVNAME(softc) ((softc)->sc_ad1848.sc_ad1848.sc_dev.dv_xname)
int ym_getdev __P((void *, struct audio_device *));
int ym_mixer_set_port __P((void *, mixer_ctrl_t *));
int ym_mixer_get_port __P((void *, mixer_ctrl_t *));
int ym_query_devinfo __P((void *, mixer_devinfo_t *));
int ym_intr __P((void *));
int ym_getdev(void *, struct audio_device *);
int ym_mixer_set_port(void *, mixer_ctrl_t *);
int ym_mixer_get_port(void *, mixer_ctrl_t *);
int ym_query_devinfo(void *, mixer_devinfo_t *);
int ym_intr(void *);
#ifndef AUDIO_NO_POWER_CTL
static void ym_save_codec_regs __P((struct ym_softc *));
static void ym_restore_codec_regs __P((struct ym_softc *));
void ym_power_hook __P((int, void *));
int ym_codec_power_ctl __P((void *, int));
static void ym_chip_powerdown __P((struct ym_softc *));
static void ym_chip_powerup __P((struct ym_softc *, int));
void ym_powerdown_blocks __P((void *));
void ym_power_ctl __P((struct ym_softc *, int, int));
static void ym_save_codec_regs(struct ym_softc *);
static void ym_restore_codec_regs(struct ym_softc *);
void ym_power_hook(int, void *);
int ym_codec_power_ctl(void *, int);
static void ym_chip_powerdown(struct ym_softc *);
static void ym_chip_powerup(struct ym_softc *, int);
void ym_powerdown_blocks(void *);
void ym_power_ctl(struct ym_softc *, int, int);
#endif
static void ym_init __P((struct ym_softc *));
static void ym_mute __P((struct ym_softc *, int, int));
static void ym_set_master_gain __P((struct ym_softc *, struct ad1848_volume*));
static void ym_hvol_to_master_gain __P((struct ym_softc *));
static void ym_set_mic_gain __P((struct ym_softc *, int));
static void ym_set_3d __P((struct ym_softc *, mixer_ctrl_t *,
struct ad1848_volume *, int));
static void ym_init(struct ym_softc *);
static void ym_mute(struct ym_softc *, int, int);
static void ym_set_master_gain(struct ym_softc *, struct ad1848_volume*);
static void ym_hvol_to_master_gain(struct ym_softc *);
static void ym_set_mic_gain(struct ym_softc *, int);
static void ym_set_3d(struct ym_softc *, mixer_ctrl_t *,
struct ad1848_volume *, int);
const struct audio_hw_if ym_hw_if = {
@ -206,20 +206,20 @@ const struct audio_hw_if ym_hw_if = {
NULL,
};
static __inline int ym_read __P((struct ym_softc *, int));
static __inline void ym_write __P((struct ym_softc *, int, int));
static __inline int ym_read(struct ym_softc *, int);
static __inline void ym_write(struct ym_softc *, int, int);
void
ym_attach(sc)
struct ym_softc *sc;
ym_attach(struct ym_softc *sc)
{
struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
static struct ad1848_volume vol_master = {YM_VOL_MASTER, YM_VOL_MASTER};
static struct ad1848_volume vol_dac = {YM_VOL_DAC, YM_VOL_DAC};
static struct ad1848_volume vol_opl3 = {YM_VOL_OPL3, YM_VOL_OPL3};
struct ad1848_softc *ac;
mixer_ctrl_t mctl;
struct audio_attach_args arg;
ac = &sc->sc_ad1848.sc_ad1848;
callout_init(&sc->sc_powerdown_ch);
/* Mute the output to reduce noise during initialization. */
@ -230,8 +230,7 @@ ym_attach(sc)
ac->chip_name = YM_IS_SA3(sc) ? "OPL3-SA3" : "OPL3-SA2";
sc->sc_ad1848.sc_ih = isa_intr_establish(sc->sc_ic, sc->ym_irq,
IST_EDGE, IPL_AUDIO,
ym_intr, sc);
IST_EDGE, IPL_AUDIO, ym_intr, sc);
#ifndef AUDIO_NO_POWER_CTL
sc->sc_ad1848.powerctl = ym_codec_power_ctl;
@ -299,9 +298,9 @@ ym_attach(sc)
sc->sc_pow_timeout = YM_POWER_OFF_SEC;
sc->sc_on_blocks = sc->sc_turning_off =
YM_POWER_CODEC_P | YM_POWER_CODEC_R |
YM_POWER_OPL3 | YM_POWER_MPU401 | YM_POWER_3D |
YM_POWER_CODEC_DA | YM_POWER_CODEC_AD | YM_POWER_OPL3_DA;
YM_POWER_CODEC_P | YM_POWER_CODEC_R |
YM_POWER_OPL3 | YM_POWER_MPU401 | YM_POWER_3D |
YM_POWER_CODEC_DA | YM_POWER_CODEC_AD | YM_POWER_OPL3_DA;
#if NJOY > 0
sc->sc_on_blocks |= YM_POWER_JOYSTICK; /* prevents chip powerdown */
#endif
@ -330,39 +329,35 @@ ym_attach(sc)
}
static __inline int
ym_read(sc, reg)
struct ym_softc *sc;
int reg;
ym_read(struct ym_softc *sc, int reg)
{
bus_space_write_1(sc->sc_iot, sc->sc_controlioh,
SA3_CTL_INDEX, (reg & 0xff));
return (bus_space_read_1(sc->sc_iot, sc->sc_controlioh, SA3_CTL_DATA));
SA3_CTL_INDEX, (reg & 0xff));
return bus_space_read_1(sc->sc_iot, sc->sc_controlioh, SA3_CTL_DATA);
}
static __inline void
ym_write(sc, reg, data)
struct ym_softc *sc;
int reg;
int data;
ym_write(struct ym_softc *sc, int reg, int data)
{
bus_space_write_1(sc->sc_iot, sc->sc_controlioh,
SA3_CTL_INDEX, (reg & 0xff));
SA3_CTL_INDEX, (reg & 0xff));
bus_space_write_1(sc->sc_iot, sc->sc_controlioh,
SA3_CTL_DATA, (data & 0xff));
SA3_CTL_DATA, (data & 0xff));
}
static void
ym_init(sc)
struct ym_softc *sc;
ym_init(struct ym_softc *sc)
{
u_int8_t dpd, apd;
uint8_t dpd, apd;
/* Mute SoundBlaster output if possible. */
if (sc->sc_sb_ioh) {
bus_space_write_1(sc->sc_iot, sc->sc_sb_ioh, SBP_MIXER_ADDR,
SBP_MASTER_VOL);
SBP_MASTER_VOL);
bus_space_write_1(sc->sc_iot, sc->sc_sb_ioh, SBP_MIXER_DATA,
0x00);
0x00);
}
if (!YM_IS_SA3(sc)) {
@ -376,20 +371,20 @@ ym_init(sc)
/* Figure out which part can be power down. */
dpd = SA3_DPWRDWN_SB /* we never use SB */
#if NMPU_YM > 0
| (sc->sc_mpu_ioh ? 0 : SA3_DPWRDWN_MPU)
| (sc->sc_mpu_ioh ? 0 : SA3_DPWRDWN_MPU)
#else
| SA3_DPWRDWN_MPU
| SA3_DPWRDWN_MPU
#endif
#if NJOY == 0
| SA3_DPWRDWN_JOY
| SA3_DPWRDWN_JOY
#endif
| SA3_DPWRDWN_PNP /* ISA Plug and Play is done */
/*
* The master clock is for external wavetable synthesizer
* OPL4-ML (YMF704) or OPL4-ML2 (YMF721),
* and is currently unused.
*/
| SA3_DPWRDWN_MCLKO;
| SA3_DPWRDWN_PNP /* ISA Plug and Play is done */
/*
* The master clock is for external wavetable synthesizer
* OPL4-ML (YMF704) or OPL4-ML2 (YMF721),
* and is currently unused.
*/
| SA3_DPWRDWN_MCLKO;
apd = SA3_APWRDWN_SBDAC; /* we never use SB */
@ -409,13 +404,13 @@ ym_init(sc)
int
ym_getdev(addr, retp)
void *addr;
struct audio_device *retp;
ym_getdev(void *addr, struct audio_device *retp)
{
struct ym_softc *sc = addr;
struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
struct ym_softc *sc;
struct ad1848_softc *ac;
sc = addr;
ac = &sc->sc_ad1848.sc_ad1848;
strlcpy(retp->name, ac->chip_name, sizeof(retp->name));
snprintf(retp->version, sizeof(retp->version), "%d", sc->sc_version);
strlcpy(retp->config, "ym", sizeof(retp->config));
@ -445,12 +440,9 @@ static ad1848_devmap_t mappings[] = {
static void
ym_mute(sc, left_reg, mute)
struct ym_softc *sc;
int left_reg;
int mute;
ym_mute(struct ym_softc *sc, int left_reg, int mute)
{
u_int8_t reg;
uint8_t reg;
reg = ym_read(sc, left_reg);
if (mute)
@ -461,9 +453,7 @@ ym_mute(sc, left_reg, mute)
static void
ym_set_master_gain(sc, vol)
struct ym_softc *sc;
struct ad1848_volume *vol;
ym_set_master_gain(struct ym_softc *sc, struct ad1848_volume *vol)
{
u_int atten;
@ -486,12 +476,12 @@ ym_set_master_gain(sc, vol)
* [SA3] This function clears hardware volume interrupt.
*/
static void
ym_hvol_to_master_gain(sc)
struct ym_softc *sc;
ym_hvol_to_master_gain(struct ym_softc *sc)
{
u_int prevval, val;
int changed = 0;
int changed;
changed = 0;
val = SA3_VOL_MV & ~ym_read(sc, SA3_VOL_L);
prevval = (sc->master_gain.left * (SA3_VOL_MV + 1)) /
(AUDIO_MAX_GAIN + 1);
@ -518,9 +508,7 @@ ym_hvol_to_master_gain(sc)
}
static void
ym_set_mic_gain(sc, vol)
struct ym_softc *sc;
int vol;
ym_set_mic_gain(struct ym_softc *sc, int vol)
{
u_int atten;
@ -534,13 +522,10 @@ ym_set_mic_gain(sc, vol)
}
static void
ym_set_3d(sc, cp, val, reg)
struct ym_softc *sc;
mixer_ctrl_t *cp;
struct ad1848_volume *val;
int reg;
ym_set_3d(struct ym_softc *sc, mixer_ctrl_t *cp,
struct ad1848_volume *val, int reg)
{
u_int8_t l, r, e;
uint8_t l, r, e;
ad1848_to_vol(cp, val);
@ -553,9 +538,9 @@ ym_set_3d(sc, cp, val, reg)
}
e = (l * (SA3_3D_BITS + 1) + (SA3_3D_BITS + 1) / 2) /
(AUDIO_MAX_GAIN + 1) << SA3_3D_LSHIFT |
(AUDIO_MAX_GAIN + 1) << SA3_3D_LSHIFT |
(r * (SA3_3D_BITS + 1) + (SA3_3D_BITS + 1) / 2) /
(AUDIO_MAX_GAIN + 1) << SA3_3D_RSHIFT;
(AUDIO_MAX_GAIN + 1) << SA3_3D_RSHIFT;
#ifndef AUDIO_NO_POWER_CTL
/* turn wide stereo on if necessary */
@ -574,16 +559,17 @@ ym_set_3d(sc, cp, val, reg)
}
int
ym_mixer_set_port(addr, cp)
void *addr;
mixer_ctrl_t *cp;
ym_mixer_set_port(void *addr, mixer_ctrl_t *cp)
{
struct ad1848_softc *ac = addr;
struct ym_softc *sc = ac->parent;
struct ad1848_softc *ac;
struct ym_softc *sc;
struct ad1848_volume vol;
int error = 0;
u_int8_t extsources;
int error;
uint8_t extsources;
ac = addr;
sc = ac->parent;
error = 0;
DPRINTF(("%s: ym_mixer_set_port: dev 0x%x, type 0x%x, 0x%x (%d; %d, %d)\n",
DVNAME(sc), cp->dev, cp->type, cp->un.ord,
cp->un.value.num_channels, cp->un.value.level[0],
@ -615,13 +601,13 @@ ym_mixer_set_port(addr, cp)
error = EINVAL;
else
ym_set_mic_gain(sc,
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
goto out;
case YM_MASTER_EQMODE:
sc->sc_eqmode = cp->un.ord & SA3_SYS_CTL_YMODE;
ym_write(sc, SA3_SYS_CTL, (ym_read(sc, SA3_SYS_CTL) &
~SA3_SYS_CTL_YMODE) | sc->sc_eqmode);
~SA3_SYS_CTL_YMODE) | sc->sc_eqmode);
goto out;
case YM_MASTER_TREBLE:
@ -649,7 +635,7 @@ ym_mixer_set_port(addr, cp)
error = EINVAL;
else
sc->sc_pow_timeout =
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
goto out;
/*
@ -685,7 +671,7 @@ ym_mixer_set_port(addr, cp)
case YM_MONITOR_MUTE:
if ((ac->open_mode & (FREAD | FWRITE)) == FREAD)
ym_power_ctl(sc, YM_POWER_CODEC_P | YM_POWER_CODEC_DA,
cp->un.ord == 0);
cp->un.ord == 0);
break; /* fall to ad1848_mixer_set_port() */
#endif
}
@ -714,18 +700,18 @@ out:
ym_power_ctl(sc, YM_POWER_CODEC_CTL, 0);
#endif
return (error);
return error;
}
int
ym_mixer_get_port(addr, cp)
void *addr;
mixer_ctrl_t *cp;
ym_mixer_get_port(void *addr, mixer_ctrl_t *cp)
{
struct ad1848_softc *ac = addr;
struct ym_softc *sc = ac->parent;
struct ad1848_softc *ac;
struct ym_softc *sc;
int error;
ac = addr;
sc = ac->parent;
/* SA2 doesn't have equalizer */
if (!YM_IS_SA3(sc) && YM_MIXER_SA3_ONLY(cp->dev))
return ENXIO;
@ -792,7 +778,7 @@ ym_mixer_get_port(addr, cp)
error = ad1848_mixer_get_port(ac, mappings, NUMMAP, cp);
if (error != ENXIO)
return (error);
return error;
error = 0;
@ -806,7 +792,7 @@ ym_mixer_get_port(addr, cp)
break;
}
return(error);
return error;
}
static char *mixer_classes[] = {
@ -818,17 +804,17 @@ static char *mixer_classes[] = {
};
int
ym_query_devinfo(addr, dip)
void *addr;
mixer_devinfo_t *dip;
ym_query_devinfo(void *addr, mixer_devinfo_t *dip)
{
static char *mixer_port_names[] = {
AudioNdac, AudioNmidi, AudioNcd, AudioNline, AudioNspeaker,
AudioNmicrophone, AudioNmonitor
};
struct ad1848_softc *ac = addr;
struct ym_softc *sc = ac->parent;
struct ad1848_softc *ac;
struct ym_softc *sc;
ac = addr;
sc = ac->parent;
/* SA2 doesn't have equalizer */
if (!YM_IS_SA3(sc) && YM_MIXER_SA3_ONLY(dip->index))
return ENXIO;
@ -1032,13 +1018,13 @@ ym_query_devinfo(addr, dip)
}
int
ym_intr(arg)
void *arg;
ym_intr(void *arg)
{
struct ym_softc *sc = arg;
struct ym_softc *sc;
u_int8_t ist;
int processed;
sc = arg;
/* OPL3 timer is currently unused. */
if (((ist = ym_read(sc, SA3_IRQA_STAT)) &
~(SA3_IRQ_STAT_SB|SA3_IRQ_STAT_OPL3)) == 0) {
@ -1081,27 +1067,25 @@ ym_intr(arg)
#ifndef AUDIO_NO_POWER_CTL
static void
ym_save_codec_regs(sc)
struct ym_softc *sc;
ym_save_codec_regs(struct ym_softc *sc)
{
struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
struct ad1848_softc *ac;
int i;
DPRINTF(("%s: ym_save_codec_regs\n", DVNAME(sc)));
ac = &sc->sc_ad1848.sc_ad1848;
for (i = 0; i <= 0x1f; i++)
sc->sc_codec_scan[i] = ad_read(ac, i);
}
static void
ym_restore_codec_regs(sc)
struct ym_softc *sc;
ym_restore_codec_regs(struct ym_softc *sc)
{
struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
struct ad1848_softc *ac;
int i, t;
DPRINTF(("%s: ym_restore_codec_regs\n", DVNAME(sc)));
ac = &sc->sc_ad1848.sc_ad1848;
for (i = 0; i <= 0x1f; i++) {
/*
* Wait til the chip becomes ready.
@ -1127,14 +1111,13 @@ ym_restore_codec_regs(sc)
* DMA state should also be restored. FIXME.
*/
void
ym_power_hook(why, v)
int why;
void *v;
ym_power_hook(int why, void *v)
{
struct ym_softc *sc = v;
struct ym_softc *sc;
int i, max;
int s;
sc = v;
DPRINTF(("%s: ym_power_hook: why = %d\n", DVNAME(sc), why));
s = splaudio();
@ -1200,14 +1183,14 @@ ym_power_hook(why, v)
}
int
ym_codec_power_ctl(arg, flags)
void *arg;
int flags;
ym_codec_power_ctl(void *arg, int flags)
{
struct ym_softc *sc = arg;
struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
struct ym_softc *sc;
struct ad1848_softc *ac;
int parts;
sc = arg;
ac = &sc->sc_ad1848.sc_ad1848;
DPRINTF(("%s: ym_codec_power_ctl: flags = 0x%x\n", DVNAME(sc), flags));
if (flags != 0) {
@ -1235,8 +1218,7 @@ ym_codec_power_ctl(arg, flags)
* This must be called at splaudio().
*/
static void
ym_chip_powerdown(sc)
struct ym_softc *sc;
ym_chip_powerdown(struct ym_softc *sc)
{
int i, max;
@ -1262,12 +1244,10 @@ ym_chip_powerdown(sc)
* in power-down mode (or should be blocked by splaudio()).
*/
static void
ym_chip_powerup(sc, nosleep)
struct ym_softc *sc;
int nosleep;
ym_chip_powerup(struct ym_softc *sc, int nosleep)
{
int wchan;
u_int8_t pw;
uint8_t pw;
DPRINTF(("%s: ym_chip_powerup\n", DVNAME(sc)));
@ -1301,15 +1281,16 @@ ym_chip_powerup(sc, nosleep)
/* callout handler for power-down */
void
ym_powerdown_blocks(arg)
void *arg;
ym_powerdown_blocks(void *arg)
{
struct ym_softc *sc = arg;
u_int16_t parts;
u_int16_t on_blocks = sc->sc_on_blocks;
u_int8_t sv;
struct ym_softc *sc;
uint16_t parts;
uint16_t on_blocks;
uint8_t sv;
int s;
sc = arg;
on_blocks = sc->sc_on_blocks;
DPRINTF(("%s: ym_powerdown_blocks: turning_off 0x%x\n",
DVNAME(sc), sc->sc_turning_off));
@ -1366,9 +1347,7 @@ ym_powerdown_blocks(arg)
* Power control entry point.
*/
void
ym_power_ctl(sc, parts, onoff)
struct ym_softc *sc;
int parts, onoff;
ym_power_ctl(struct ym_softc *sc, int parts, int onoff)
{
int s;
int need_restore_codec;

@ -1,4 +1,4 @@
/* $NetBSD: ymvar.h,v 1.8 2002/03/10 13:57:11 itohy Exp $ */
/* $NetBSD: ymvar.h,v 1.9 2005/01/14 03:41:45 kent Exp $ */
/*-
* Copyright (c) 1999-2000, 2002 The NetBSD Foundation, Inc.
@ -165,15 +165,15 @@ struct ym_softc {
int master_mute, mic_mute;
struct ad1848_volume master_gain;
u_int8_t mic_gain;
uint8_t mic_gain;
u_int8_t sc_external_sources; /* non-zero value prevents power down */
uint8_t sc_external_sources; /* non-zero value prevents power down */
u_int8_t sc_version; /* hardware version */
uint8_t sc_version; /* hardware version */
#define YM_IS_SA3(sc) ((sc)->sc_version > SA3_MISC_VER_711)
/* 3D encehamcement */
u_int8_t sc_eqmode;
uint8_t sc_eqmode;
struct ad1848_volume sc_treble, sc_bass, sc_wide;
/*
* The equalizer of OPL3-SA3 is ``flat'' if it is turned off.
@ -204,13 +204,13 @@ struct ym_softc {
} sc_pow_mode;
int sc_pow_timeout;
u_int8_t sc_codec_scan[0x20];
uint8_t sc_codec_scan[0x20];
#define YM_SAVE_REG_MAX_SA3 SA3_HVOL_INTR_CNF
#define YM_SAVE_REG_MAX_SA2 SA3_DMA_CNT_REC_HIGH
u_int8_t sc_sa3_scan[YM_SAVE_REG_MAX_SA3 + 1];
uint8_t sc_sa3_scan[YM_SAVE_REG_MAX_SA3 + 1];
u_int16_t sc_on_blocks;
u_int16_t sc_turning_off;
uint16_t sc_on_blocks;
uint16_t sc_turning_off;
int sc_in_power_ctl;
#define YM_POWER_CTL_INUSE 1
@ -252,10 +252,10 @@ struct ym_softc {
#define YM_MIXER_TO_XS(m) (1 << ((m) - YM_CD_MUTE))
#ifdef _KERNEL
void ym_power_ctl __P((struct ym_softc *, int, int));
void ym_power_ctl(struct ym_softc *, int, int);
#endif
#endif /* not AUDIO_NO_POWER_CTL */
#ifdef _KERNEL
void ym_attach __P((struct ym_softc *));
void ym_attach(struct ym_softc *);
#endif