Rework the driver to add EBus DMA support and improve APC DMA support.

Audio-related stuff is left almost intact.

* support audiocs at ebus playback and capture
    tested on krups and u5 (thanks, martin)
* make first attempt at supporting audiocs at sbus capture
* nb: full-duplex is not tested
* while here, fix CSAUDIO_MONITOR_MUTE to be of CSAUDIO_MONITOR_CLASS
    i.e. outputs.monitor.mute -> monitor.monitor.mute

Ok by pk, eeh.
This commit is contained in:
uwe 2002-03-12 04:48:28 +00:00
parent 7f7fe98c2c
commit a05702eaac
8 changed files with 1237 additions and 607 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.sparc,v 1.107 2002/01/21 21:57:05 jdolecek Exp $
# $NetBSD: files.sparc,v 1.108 2002/03/12 04:48:29 uwe Exp $
# @(#)files.sparc 8.1 (Berkeley) 7/19/93
# sparc-specific configuration info
@ -118,6 +118,9 @@ attach sbus at mainbus with sbus_mainbus
attach sbus at iommu with sbus_iommu
file arch/sparc/dev/sbus.c sbus needs-flag
attach audiocs at ebus with audiocs_ebus
file dev/ebus/cs4231_ebus.c audiocs_ebus
device tpcic: pcmciabus
attach tpcic at sbus
file arch/sparc/dev/ts102.c tpcic

View File

@ -1,4 +1,4 @@
# $NetBSD: files.sparc64,v 1.58 2002/01/21 21:57:05 jdolecek Exp $
# $NetBSD: files.sparc64,v 1.59 2002/03/12 04:48:30 uwe Exp $
# @(#)files.sparc64 8.1 (Berkeley) 7/19/93
# sparc64-specific configuration info
@ -104,7 +104,7 @@ file dev/sun/fd.c fdc | fd needs-flag
file arch/sparc64/sparc64/bsd_fdintr.s fdc
attach audiocs at ebus with audiocs_ebus
file arch/sparc64/dev/cs4231_ebus.c audiocs_ebus
file dev/ebus/cs4231_ebus.c audiocs_ebus
#
# Console related stuff

View File

@ -1,152 +0,0 @@
/* $NetBSD: cs4231_ebus.c,v 1.8 2002/03/01 11:51:00 martin Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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 <sys/malloc.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <dev/ebus/ebusreg.h>
#include <sparc64/dev/ebusvar.h>
#include <sys/audioio.h>
#include <dev/audio_if.h>
#include <dev/ic/ad1848reg.h>
#include <dev/ic/cs4231reg.h>
#include <dev/ic/ad1848var.h>
#include <dev/ic/cs4231var.h>
#define AUDIO_ROM_NAME "SUNW,CS4231"
#define CS4231_REG_SIZE 16
/* autoconfiguration driver */
void cs4231_attach_ebus __P((struct device *, struct device *, void *));
int cs4231_match_ebus __P((struct device *, struct cfdata *, void *));
struct cfattach audiocs_ebus_ca = {
sizeof(struct cs4231_softc), cs4231_match_ebus, cs4231_attach_ebus
};
/* autoconfig routines */
int
cs4231_match_ebus(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct ebus_attach_args *ea = aux;
return (strcmp(AUDIO_ROM_NAME, ea->ea_name) == 0);
}
/*
* Audio chip found.
*/
void
cs4231_attach_ebus(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct cs4231_softc *sc = (struct cs4231_softc *)self;
struct ebus_attach_args *ea = aux;
bus_space_handle_t bh;
int i;
sc->sc_bustag = ea->ea_bustag;
sc->sc_dmatag = ea->ea_dmatag;
sc->sc_ad1848.parent = sc;
sc->sc_ad1848.sc_iot = sc->sc_bustag;
sc->sc_ad1848.sc_readreg = cs4231_read;
sc->sc_ad1848.sc_writereg = cs4231_write;
/*
* These are the register we get from the prom:
* - CS4231 registers
* - DMA (play)
* - DMA (write)
* - AUXIO audio registers
*
* Map my registers in, if they aren't already in virtual
* address space.
*/
if (ea->ea_nvaddrs) {
bh = (bus_space_handle_t)ea->ea_vaddrs[0];
} else {
if (ebus_bus_map(ea->ea_bustag, 0,
EBUS_ADDR_FROM_REG(&ea->ea_regs[0]),
ea->ea_regs[0].size,
BUS_SPACE_MAP_LINEAR,
0, &bh) != 0) {
printf("%s @ ebus: cannot map registers\n",
self->dv_xname);
return;
}
}
/* XXX what to do with the DMA registers ? */
sc->sc_ad1848.sc_ioh = bh;
sc->sc_dmareg = (struct apc_dma *)(u_long)(bh + CS4231_REG_SIZE);
cs4231_init(sc);
/* Put ad1848 driver in `MODE 2' mode */
sc->sc_ad1848.mode = 2;
ad1848_attach(&sc->sc_ad1848);
printf("\n");
/* Establish interrupt channels */
for (i = 0; i < ea->ea_nintrs; i++)
bus_intr_establish(ea->ea_bustag,
ea->ea_intrs[i], IPL_AUDIO, 0,
cs4231_intr, sc);
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
sc->sc_ad1848.sc_dev.dv_xname, "intr");
audio_attach_mi(&audiocs_hw_if, sc, &sc->sc_ad1848.sc_dev);
}
#endif

520
sys/dev/ebus/cs4231_ebus.c Normal file
View File

@ -0,0 +1,520 @@
/* $NetBSD: cs4231_ebus.c,v 1.1 2002/03/12 04:48:29 uwe Exp $ */
/*
* Copyright (c) 2002 Valeriy E. Ushakov
* 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. 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 <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <dev/ebus/ebusreg.h>
#include <dev/ebus/ebusvar.h>
#include <sys/audioio.h>
#include <dev/audio_if.h>
#include <dev/ic/ad1848reg.h>
#include <dev/ic/cs4231reg.h>
#include <dev/ic/ad1848var.h>
#include <dev/ic/cs4231var.h>
#define AUDIO_ROM_NAME "sound"
#ifdef AUDIO_DEBUG
int cs4231_ebus_debug = 0;
#define DPRINTF(x) if (cs4231_ebus_debug) printf x
#else
#define DPRINTF(x)
#endif
struct cs4231_ebus_softc {
struct cs4231_softc sc_cs4231;
volatile struct ebus_dmac_reg *sc_pdmareg; /* playback DMA */
volatile struct ebus_dmac_reg *sc_rdmareg; /* record DMA */
};
void cs4231_ebus_attach(struct device *, struct device *, void *);
int cs4231_ebus_match(struct device *, struct cfdata *, void *);
struct cfattach audiocs_ebus_ca = {
sizeof(struct cs4231_ebus_softc), cs4231_ebus_match, cs4231_ebus_attach
};
/* audio_hw_if methods specific to ebus dma */
static int cs4231_ebus_trigger_output(void *, void *, void *, int,
void (*)(void *), void *,
struct audio_params *);
static int cs4231_ebus_trigger_input(void *, void *, void *, int,
void (*)(void *), void *,
struct audio_params *);
static int cs4231_ebus_halt_output(void *);
static int cs4231_ebus_halt_input(void *);
struct audio_hw_if audiocs_ebus_hw_if = {
cs4231_open,
cs4231_close,
NULL, /* drain */
ad1848_query_encoding,
ad1848_set_params,
cs4231_round_blocksize,
ad1848_commit_settings,
NULL, /* init_output */
NULL, /* init_input */
NULL, /* start_output */
NULL, /* start_input */
cs4231_ebus_halt_output,
cs4231_ebus_halt_input,
NULL, /* speaker_ctl */
cs4231_getdev,
NULL, /* setfd */
cs4231_set_port,
cs4231_get_port,
cs4231_query_devinfo,
cs4231_malloc,
cs4231_free,
cs4231_round_buffersize,
NULL, /* mappage */
cs4231_get_props,
cs4231_ebus_trigger_output,
cs4231_ebus_trigger_input,
NULL, /* dev_ioctl */
};
#ifdef AUDIO_DEBUG
static void cs4231_ebus_regdump(char *, struct cs4231_ebus_softc *);
#endif
static int cs4231_ebus_dma_reset(volatile struct ebus_dmac_reg *);
static int cs4231_ebus_trigger_transfer(struct cs4231_softc *,
struct cs_transfer *, volatile struct ebus_dmac_reg *,
int, void *, void *, int, void (*)(void *), void *,
struct audio_params *);
static void cs4231_ebus_dma_advance(struct cs_transfer *,
volatile struct ebus_dmac_reg *);
static int cs4231_ebus_dma_intr(struct cs_transfer *,
volatile struct ebus_dmac_reg *);
static int cs4231_ebus_intr(void *);
int
cs4231_ebus_match(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct ebus_attach_args *ea = aux;
if (strcmp(ea->ea_name, AUDIOCS_PROM_NAME) == 0)
return (1);
#ifdef __sparc__ /* XXX: Krups */
if (strcmp(ea->ea_name, "sound") == 0)
return (1);
#endif
return (0);
}
void
cs4231_ebus_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct cs4231_ebus_softc *ebsc = (struct cs4231_ebus_softc *)self;
struct cs4231_softc *sc = &ebsc->sc_cs4231;
struct ebus_attach_args *ea = aux;
bus_space_handle_t bh;
int i;
sc->sc_bustag = ea->ea_bustag;
sc->sc_dmatag = ea->ea_dmatag;
/*
* These are the register we get from the prom:
* - CS4231 registers
* - Playback EBus DMA controller
* - Capture EBus DMA controller
* - AUXIO audio register (codec powerdown)
*
* Map my registers in, if they aren't already in virtual
* address space.
*/
if (ea->ea_nvaddr) {
bh = (bus_space_handle_t)ea->ea_vaddr[0];
} else {
if (bus_space_map(ea->ea_bustag,
EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
ea->ea_reg[0].size,
BUS_SPACE_MAP_LINEAR,
&bh) != 0)
{
printf("%s: unable to map registers\n",
self->dv_xname);
return;
}
}
/* XXX: map playback DMA registers (we just know where they are) */
if (bus_space_map(ea->ea_bustag,
BUS_ADDR(0x14, 0x702000), /* XXX: magic num */
sizeof(struct ebus_dmac_reg),
BUS_SPACE_MAP_LINEAR,
(bus_space_handle_t *)&ebsc->sc_pdmareg) != 0)
{
printf("%s: unable to map playback DMA registers\n",
self->dv_xname);
return;
}
/* XXX: map capture DMA registers (we just know where they are) */
if (bus_space_map(ea->ea_bustag,
BUS_ADDR(0x14, 0x704000), /* XXX: magic num */
sizeof(struct ebus_dmac_reg),
BUS_SPACE_MAP_LINEAR,
(bus_space_handle_t *)&ebsc->sc_rdmareg) != 0)
{
printf("%s: unable to map capture DMA registers\n",
self->dv_xname);
return;
}
/* establish interrupt channels */
for (i = 0; i < ea->ea_nintr; ++i)
bus_intr_establish(ea->ea_bustag,
ea->ea_intr[i], IPL_AUDIO, 0,
cs4231_ebus_intr, ebsc);
cs4231_common_attach(sc, bh);
printf("\n");
/* XXX: todo: move to cs4231_common_attach, pass hw_if as arg? */
audio_attach_mi(&audiocs_ebus_hw_if, sc, &sc->sc_ad1848.sc_dev);
}
#ifdef AUDIO_DEBUG
static void
cs4231_ebus_regdump(label, ebsc)
char *label;
struct cs4231_ebus_softc *ebsc;
{
/* char bits[128]; */
printf("cs4231regdump(%s): regs:", label);
/* XXX: dump ebus dma and aux registers */
ad1848_dump_regs(&ebsc->sc_cs4231.sc_ad1848);
}
#endif /* AUDIO_DEBUG */
/* XXX: nothing CS4231-specific in this code... */
static int
cs4231_ebus_dma_reset(dmac)
volatile struct ebus_dmac_reg *dmac;
{
int timo;
dmac->dcsr = EBDMA_RESET | EBDMA_TC; /* also clear TC, just in case */
for (timo = 50000; timo != 0; --timo)
if ((dmac->dcsr & (EBDMA_CYC_PEND | EBDMA_DRAIN)) == 0)
break;
if (timo == 0) {
printf("cs4231_ebus_dma_reset: dcsr = %x, reset timed out\n",
dmac->dcsr);
return (ETIMEDOUT);
}
dmac->dcsr &= ~EBDMA_RESET;
return (0);
}
static void
cs4231_ebus_dma_advance(t, dmac)
struct cs_transfer *t;
volatile struct ebus_dmac_reg *dmac;
{
bus_addr_t dmaaddr;
bus_size_t dmasize;
cs4231_transfer_advance(t, &dmaaddr, &dmasize);
dmac->dbcr = (u_int32_t)dmasize;
dmac->dacr = (u_int32_t)dmaaddr;
}
/*
* Trigger transfer "t" using DMA controller "dmac".
* "iswrite" defines direction of the transfer.
*/
static int
cs4231_ebus_trigger_transfer(sc, t, dmac, iswrite,
start, end, blksize,
intr, arg, param)
struct cs4231_softc *sc;
struct cs_transfer *t;
volatile struct ebus_dmac_reg *dmac;
int iswrite;
void *start, *end;
int blksize;
void (*intr)(void *);
void *arg;
struct audio_params *param;
{
bus_addr_t dmaaddr;
bus_size_t dmasize;
int ret;
ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
start, end, blksize, intr, arg);
if (ret != 0)
return (ret);
ret = cs4231_ebus_dma_reset(dmac);
if (ret != 0)
return (ret);
dmac->dcsr |= EBDMA_EN_NEXT | (iswrite ? EBDMA_WRITE : 0)
| EBDMA_EN_DMA | EBDMA_EN_CNT | EBDMA_INT_EN;
/* first load: goes to DACR/DBCR */
dmac->dbcr = (u_int32_t)dmasize;
dmac->dacr = (u_int32_t)dmaaddr;
/* next load: goes to DNAR/DNBR */
cs4231_ebus_dma_advance(t, dmac);
return (0);
}
static int
cs4231_ebus_trigger_output(addr, start, end, blksize, intr, arg, param)
void *addr;
void *start, *end;
int blksize;
void (*intr)(void *);
void *arg;
struct audio_params *param;
{
struct cs4231_ebus_softc *ebsc = addr;
struct cs4231_softc *sc = &ebsc->sc_cs4231;
struct cs_transfer *t = &sc->sc_playback;
volatile struct ebus_dmac_reg *dma = ebsc->sc_pdmareg;
int cfg;
int ret;
ret = cs4231_ebus_trigger_transfer(sc, t, dma, 0,
start, end, blksize,
intr, arg,
param);
if (ret != 0)
return (ret);
ad_write(&sc->sc_ad1848, SP_LOWER_BASE_COUNT, 0xff);
ad_write(&sc->sc_ad1848, SP_UPPER_BASE_COUNT, 0xff);
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (cfg | PLAYBACK_ENABLE));
return (0);
}
static int
cs4231_ebus_trigger_input(addr, start, end, blksize, intr, arg, param)
void *addr;
void *start, *end;
int blksize;
void (*intr)(void *);
void *arg;
struct audio_params *param;
{
struct cs4231_ebus_softc *ebsc = addr;
struct cs4231_softc *sc = &ebsc->sc_cs4231;
struct cs_transfer *t = &sc->sc_capture;
volatile struct ebus_dmac_reg *dmac = ebsc->sc_rdmareg;
int cfg;
int ret;
ret = cs4231_ebus_trigger_transfer(sc, t, dmac, 1,
start, end, blksize,
intr, arg,
param);
if (ret != 0)
return (ret);
ad_write(&sc->sc_ad1848, CS_LOWER_REC_CNT, 0xff);
ad_write(&sc->sc_ad1848, CS_UPPER_REC_CNT, 0xff);
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (cfg | CAPTURE_ENABLE));
return (0);
}
static int
cs4231_ebus_halt_output(addr)
void *addr;
{
struct cs4231_ebus_softc *ebsc = (struct cs4231_ebus_softc *)addr;
struct cs4231_softc *sc = &ebsc->sc_cs4231;
int cfg;
sc->sc_playback.t_active = 0;
ebsc->sc_pdmareg->dcsr &= ~EBDMA_EN_DMA;
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,(cfg & ~PLAYBACK_ENABLE));
return (0);
}
static int
cs4231_ebus_halt_input(addr)
void *addr;
{
struct cs4231_ebus_softc *ebsc = (struct cs4231_ebus_softc *)addr;
struct cs4231_softc *sc = &ebsc->sc_cs4231;
int cfg;
sc->sc_capture.t_active = 0;
ebsc->sc_pdmareg->dcsr &= ~EBDMA_EN_DMA;
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (cfg & ~CAPTURE_ENABLE));
return (0);
}
static int
cs4231_ebus_dma_intr(t, dmac)
struct cs_transfer *t;
volatile struct ebus_dmac_reg *dmac;
{
u_int32_t csr;
#ifdef AUDIO_DEBUG
char bits[128];
#endif
/* read DMA status, clear TC bit by writing it back */
csr = dmac->dcsr;
dmac->dcsr = csr;
DPRINTF(("audiocs: %s dcsr=%s\n", t->t_name,
bitmask_snprintf(csr, EBUS_DCSR_BITS, bits, sizeof(bits))));
if (csr & EBDMA_ERR_PEND) {
++t->t_ierrcnt.ev_count;
printf("audiocs: %s DMA error, resetting\n", t->t_name);
cs4231_ebus_dma_reset(dmac);
/* how to notify audio(9)??? */
return (1);
}
if ((csr & EBDMA_INT_PEND) == 0)
return (0);
++t->t_intrcnt.ev_count;
if ((csr & EBDMA_TC) == 0) { /* can this happen? */
printf("audiocs: %s INT_PEND but !TC\n", t->t_name);
return (1);
}
if (!t->t_active)
return (1);
cs4231_ebus_dma_advance(t, dmac);
/* call audio(9) framework while dma is chugging along */
if (t->t_intr != NULL)
(*t->t_intr)(t->t_arg);
return (1);
}
static int
cs4231_ebus_intr(arg)
void *arg;
{
struct cs4231_ebus_softc *ebsc = (struct cs4231_ebus_softc *)arg;
struct cs4231_softc *sc = &ebsc->sc_cs4231;
int status;
int ret;
#ifdef AUDIO_DEBUG
char bits[128];
#endif
status = ADREAD(&sc->sc_ad1848, AD1848_STATUS);
#ifdef AUDIO_DEBUG
if (cs4231_ebus_debug > 1)
cs4231_ebus_regdump("audiointr", ebsc);
DPRINTF(("%s: status: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
bitmask_snprintf(status, AD_R2_BITS, bits, sizeof(bits))));
#endif
if (status & INTERRUPT_STATUS) {
#ifdef AUDIO_DEBUG
int reason;
reason = ad_read(&sc->sc_ad1848, CS_IRQ_STATUS);
DPRINTF(("%s: i24: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
bitmask_snprintf(reason, CS_I24_BITS, bits, sizeof(bits))));
#endif
/* clear interrupt from ad1848 */
ADWRITE(&sc->sc_ad1848, AD1848_STATUS, 0);
}
ret = 0;
if (cs4231_ebus_dma_intr(&sc->sc_capture, ebsc->sc_rdmareg)) {
++sc->sc_intrcnt.ev_count;
ret = 1;
}
if (cs4231_ebus_dma_intr(&sc->sc_playback, ebsc->sc_pdmareg)) {
++sc->sc_intrcnt.ev_count;
ret = 1;
}
return (ret);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: apcdmareg.h,v 1.2 2000/06/16 11:47:34 pk Exp $ */
/* $NetBSD: apcdmareg.h,v 1.3 2002/03/12 04:48:28 uwe Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -41,6 +41,9 @@
* Thanks to Derrick J. Brashear for additional info on the
* meaning of some of these bits.
*/
#ifndef _DEV_IC_APCDMAREG_H_
#define _DEV_IC_APCDMAREG_H_
struct apc_dma {
volatile u_int32_t dmacsr; /* APC CSR */
volatile u_int32_t lpad[3]; /* */
@ -86,27 +89,22 @@ struct apc_dma {
"\14CM\13CD\12CMI\11CMIE\10PPAUSE\7CPAUSE\6PDN\4PGO\3CGO"
/*
* To start DMA, you write to dma[cp]nva and dma[cp]nc and set [CP]DMA_GO
* in dmacsr. dma[cp]va and dma[cp]c, when read, appear to be the live
* counter as the DMA operation progresses.
* Supposedly, you get an interrupt with the "dirty" bits (APC_PD,APC_CD)
* set, when the next DMA buffer can be programmed, while the current one
* is still in progress. We don't currently use this feature, since I
* haven't been able to make it work.. instead the next buffer goes in
* as soon as we see a "pipe empty" (APC_PM) interrupt.
* Note that when we program CSR, we should be careful to not
* accidentally clear any pending interrupt bits (a pending interrupt
* reads as 1 and writing back 1 will clear), so instead of
*
* dma->dmacsr |= bits;
*
* we should do
*
* temp = dma->dmacsr & ~APC_INTR_MASK;
* temp |= bits;
* dma->dmacsr = temp;
*
* When clearing bits, always add APC_INTR_MASK, i.e.
*
* dma->dmacsr &= ~(bits | APC_INTR_MASK);
*/
#define APC_INTR_MASK (APC_IP|APC_PI|APC_CI|APC_EI|APC_PMI|APC_CMI)
/* It's not clear if there's a maximum DMA size.. */
#define APC_MAX (sc->sc_blksz)/*(16*1024)*/
/*
* List of device memory allocations (see cs4231_malloc/cs4231_free).
*/
struct cs_dma {
struct cs_dma *next;
caddr_t addr;
bus_dmamap_t dmamap;
bus_dma_segment_t segs[1];
int nsegs;
size_t size;
};
#endif /* _DEV_IC_APCDMAREG_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cs4231.c,v 1.6 2001/11/13 13:14:36 lukem Exp $ */
/* $NetBSD: cs4231.c,v 1.7 2002/03/12 04:48:28 uwe Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cs4231.c,v 1.6 2001/11/13 13:14:36 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: cs4231.c,v 1.7 2002/03/12 04:48:28 uwe Exp $");
#include "audio.h"
#if NAUDIO > 0
@ -58,7 +58,6 @@ __KERNEL_RCSID(0, "$NetBSD: cs4231.c,v 1.6 2001/11/13 13:14:36 lukem Exp $");
#include <dev/ic/cs4231reg.h>
#include <dev/ic/ad1848var.h>
#include <dev/ic/cs4231var.h>
#include <dev/ic/apcdmareg.h>
/*---*/
#define CSAUDIO_DAC_LVL 0
@ -81,8 +80,8 @@ __KERNEL_RCSID(0, "$NetBSD: cs4231.c,v 1.6 2001/11/13 13:14:36 lukem Exp $");
#define CSAUDIO_MONITOR_CLASS 16
#ifdef AUDIO_DEBUG
int cs4231debug = 0;
#define DPRINTF(x) if (cs4231debug) printf x
int cs4231_debug = 0;
#define DPRINTF(x) if (cs4231_debug) printf x
#else
#define DPRINTF(x)
#endif
@ -94,39 +93,16 @@ struct audio_device cs4231_device = {
};
/*
* Define our interface to the higher level audio driver.
*/
int cs4231_open __P((void *, int));
void cs4231_close __P((void *));
size_t cs4231_round_buffersize __P((void *, int, size_t));
int cs4231_round_blocksize __P((void *, int));
int cs4231_halt_output __P((void *));
int cs4231_halt_input __P((void *));
int cs4231_getdev __P((void *, struct audio_device *));
int cs4231_set_port __P((void *, mixer_ctrl_t *));
int cs4231_get_port __P((void *, mixer_ctrl_t *));
int cs4231_query_devinfo __P((void *, mixer_devinfo_t *));
int cs4231_get_props __P((void *));
void *cs4231_malloc __P((void *, int, size_t, int, int));
void cs4231_free __P((void *, void *, int));
int cs4231_trigger_output __P((void *, void *, void *, int,
void (*)(void *), void *,
struct audio_params *));
int cs4231_trigger_input __P((void *, void *, void *, int,
void (*)(void *), void *,
struct audio_params *));
#ifdef AUDIO_DEBUG
static void cs4231_regdump __P((char *, struct cs4231_softc *));
#endif
/* ad1848 sc_{read,write}reg */
static int cs4231_read(struct ad1848_softc *, int);
static void cs4231_write(struct ad1848_softc *, int, int);
int
cs4231_read(sc, index)
struct ad1848_softc *sc;
int index;
{
return bus_space_read_1(sc->sc_iot, sc->sc_ioh, (index << 2));
}
@ -135,86 +111,53 @@ cs4231_write(sc, index, value)
struct ad1848_softc *sc;
int index, value;
{
bus_space_write_1(sc->sc_iot, sc->sc_ioh, (index << 2), value);
}
struct audio_hw_if audiocs_hw_if = {
cs4231_open,
cs4231_close,
0,
ad1848_query_encoding,
ad1848_set_params,
cs4231_round_blocksize,
ad1848_commit_settings,
0,
0,
NULL,
NULL,
cs4231_halt_output,
cs4231_halt_input,
0,
cs4231_getdev,
0,
cs4231_set_port,
cs4231_get_port,
cs4231_query_devinfo,
cs4231_malloc,
cs4231_free,
cs4231_round_buffersize,
0,
cs4231_get_props,
cs4231_trigger_output,
cs4231_trigger_input,
NULL,
};
#ifdef AUDIO_DEBUG
static void
cs4231_regdump(label, sc)
char *label;
struct cs4231_softc *sc;
{
char bits[128];
volatile struct apc_dma *dma = sc->sc_dmareg;
printf("cs4231regdump(%s): regs:", label);
printf("dmapva: 0x%x; ", dma->dmapva);
printf("dmapc: 0x%x; ", dma->dmapc);
printf("dmapnva: 0x%x; ", dma->dmapnva);
printf("dmapnc: 0x%x\n", dma->dmapnc);
printf("dmacva: 0x%x; ", dma->dmacva);
printf("dmacc: 0x%x; ", dma->dmacc);
printf("dmacnva: 0x%x; ", dma->dmacnva);
printf("dmacnc: 0x%x\n", dma->dmacnc);
printf("apc_dmacsr=%s\n",
bitmask_snprintf(dma->dmacsr, APC_BITS, bits, sizeof(bits)) );
ad1848_dump_regs(&sc->sc_ad1848);
}
#endif
void
cs4231_init(sc)
cs4231_common_attach(sc, ioh)
struct cs4231_softc *sc;
bus_space_handle_t ioh;
{
char *buf;
#if 0
volatile struct apc_dma *dma = sc->sc_dmareg;
#endif
int reg;
#if 0
dma->dmacsr = APC_CODEC_PDN;
delay(20);
dma->dmacsr &= ~APC_CODEC_PDN;
#endif
/* First, put chip in native mode */
sc->sc_ad1848.parent = sc;
sc->sc_ad1848.sc_iot = sc->sc_bustag;
sc->sc_ad1848.sc_ioh = ioh;
sc->sc_ad1848.sc_readreg = cs4231_read;
sc->sc_ad1848.sc_writereg = cs4231_write;
sc->sc_playback.t_name = "playback";
sc->sc_capture.t_name = "capture";
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR,
NULL,
sc->sc_ad1848.sc_dev.dv_xname, "total");
evcnt_attach_dynamic(&sc->sc_playback.t_intrcnt, EVCNT_TYPE_INTR,
&sc->sc_intrcnt,
sc->sc_ad1848.sc_dev.dv_xname, "playback");
evcnt_attach_dynamic(&sc->sc_playback.t_ierrcnt, EVCNT_TYPE_INTR,
&sc->sc_intrcnt,
sc->sc_ad1848.sc_dev.dv_xname, "perrors");
evcnt_attach_dynamic(&sc->sc_capture.t_intrcnt, EVCNT_TYPE_INTR,
&sc->sc_intrcnt,
sc->sc_ad1848.sc_dev.dv_xname, "capture");
evcnt_attach_dynamic(&sc->sc_capture.t_ierrcnt, EVCNT_TYPE_INTR,
&sc->sc_intrcnt,
sc->sc_ad1848.sc_dev.dv_xname, "cerrors");
/* put chip in native mode to access (extended) ID register */
reg = ad_read(&sc->sc_ad1848, SP_MISC_INFO);
ad_write(&sc->sc_ad1848, SP_MISC_INFO, reg | MODE2);
/* Read version numbers from I25 */
/* read version numbers from I25 */
reg = ad_read(&sc->sc_ad1848, CS_VERSION_ID);
switch (reg & (CS_VERSION_NUMBER | CS_VERSION_CHIPID)) {
case 0xa0:
@ -228,10 +171,22 @@ cs4231_init(sc)
break;
default:
if ((buf = malloc(32, M_TEMP, M_NOWAIT)) != NULL) {
sprintf(buf, "unknown rev: %x/%x", reg&0xe, reg&7);
sprintf(buf, "unknown rev: %x/%x", reg&0xe0, reg&7);
sc->sc_ad1848.chip_name = buf;
}
}
sc->sc_ad1848.mode = 2; /* put ad1848 driver in `MODE 2' mode */
ad1848_attach(&sc->sc_ad1848);
#if 0
/*
* Before we give audiocs proper "outputs" handling, always mute
* internal speaker so that I can test this w/out waking up my family.
*/
reg = ad_read(&sc->sc_ad1848, CS_MONO_IO_CONTROL);
ad_write(&sc->sc_ad1848, CS_MONO_IO_CONTROL, reg | MONO_OUTPUT_MUTE);
#endif
}
void *
@ -310,39 +265,125 @@ cs4231_free(addr, ptr, pool)
printf("cs4231_free: rogue pointer\n");
}
/*
* Set up transfer and return DMA address and byte count in paddr and psize
* for bus dependent trigger_{in,out}put to load into the dma controller.
*/
int
cs4231_transfer_init(sc, t, paddr, psize, start, end, blksize, intr, arg)
struct cs4231_softc *sc;
struct cs_transfer *t;
bus_addr_t *paddr;
bus_size_t *psize;
void *start, *end;
int blksize;
void (*intr)(void *);
void *arg;
{
struct cs_dma *p;
vsize_t n;
if (t->t_active) {
printf("%s: %s already running\n",
sc->sc_ad1848.sc_dev.dv_xname, t->t_name);
return (EINVAL);
}
t->t_intr = intr;
t->t_arg = arg;
for (p = sc->sc_dmas; p != NULL && p->addr != start; p = p->next)
continue;
if (p == NULL) {
printf("%s: bad %s addr %p\n",
sc->sc_ad1848.sc_dev.dv_xname, t->t_name, start);
return (EINVAL);
}
n = (char *)end - (char *)start;
t->t_dma = p; /* the DMA memory segment */
t->t_segsz = n; /* size of DMA segment */
t->t_blksz = blksize; /* do transfers in blksize chunks */
if (n > t->t_blksz)
n = t->t_blksz;
t->t_cnt = n;
/* for caller to load into dma controller */
*paddr = t->t_dma->dmamap->dm_segs[0].ds_addr;
*psize = n;
DPRINTF(("%s: init %s: [%p..%p] %lu bytes %lu blocks;"
" dma at 0x%lx count %lu\n",
sc->sc_ad1848.sc_dev.dv_xname, t->t_name,
start, end, (u_long)t->t_segsz, (u_long)t->t_blksz,
(u_long)*paddr, (u_long)*psize));
t->t_active = 1;
return (0);
}
/*
* Compute next DMA address/counter, update transfer status.
*/
void
cs4231_transfer_advance(t, paddr, psize)
struct cs_transfer *t;
bus_addr_t *paddr;
bus_size_t *psize;
{
bus_addr_t dmabase, nextaddr;
bus_size_t togo;
dmabase = t->t_dma->dmamap->dm_segs[0].ds_addr;
togo = t->t_segsz - t->t_cnt;
if (togo == 0) { /* roll over */
nextaddr = dmabase;
t->t_cnt = togo = t->t_blksz;
} else {
nextaddr = dmabase + t->t_cnt;
if (togo > t->t_blksz)
togo = t->t_blksz;
t->t_cnt += togo;
}
/* for caller to load into dma controller */
*paddr = nextaddr;
*psize = togo;
}
int
cs4231_open(addr, flags)
void *addr;
int flags;
{
struct cs4231_softc *sc = addr;
#if 0
struct apc_dma *dma = sc->sc_dmareg;
#endif
DPRINTF(("sa_open: unit %p\n", sc));
if (sc->sc_open)
return (EBUSY);
sc->sc_open = 1;
sc->sc_locked = 0;
sc->sc_rintr = 0;
sc->sc_rarg = 0;
sc->sc_pintr = 0;
sc->sc_parg = 0;
#if 1
/*No interrupts from ad1848 */
sc->sc_playback.t_active = 0;
sc->sc_playback.t_intr = NULL;
sc->sc_playback.t_arg = NULL;
sc->sc_capture.t_active = 0;
sc->sc_capture.t_intr = NULL;
sc->sc_capture.t_arg = NULL;
/* no interrupts from ad1848 */
ad_write(&sc->sc_ad1848, SP_PIN_CONTROL, 0);
#endif
#if 0
dma->dmacsr = APC_RESET;
delay(10);
dma->dmacsr = 0;
delay(10);
#endif
ad1848_reset(&sc->sc_ad1848);
DPRINTF(("saopen: ok -> sc=%p\n", sc));
DPRINTF(("sa_open: ok -> sc=%p\n", sc));
return (0);
}
@ -353,11 +394,8 @@ cs4231_close(addr)
struct cs4231_softc *sc = addr;
DPRINTF(("sa_close: sc=%p\n", sc));
/*
* halt i/o, clear open flag, and done.
*/
cs4231_halt_input(sc);
cs4231_halt_output(sc);
/* audio(9) already called halt methods */
sc->sc_open = 0;
DPRINTF(("sa_close: closed.\n"));
@ -369,10 +407,7 @@ cs4231_round_buffersize(addr, direction, size)
int direction;
size_t size;
{
#if 0
if (size > APC_MAX)
size = APC_MAX;
#endif
return (size);
}
@ -381,7 +416,8 @@ cs4231_round_blocksize(addr, blk)
void *addr;
int blk;
{
return (blk & -4);
return (blk & ~3);
}
int
@ -389,6 +425,7 @@ cs4231_getdev(addr, retp)
void *addr;
struct audio_device *retp;
{
*retp = cs4231_device;
return (0);
}
@ -438,6 +475,7 @@ int
cs4231_get_props(addr)
void *addr;
{
return (AUDIO_PROP_FULLDUPLEX);
}
@ -448,27 +486,6 @@ cs4231_query_devinfo(addr, dip)
{
switch(dip->index) {
#if 0
case CSAUDIO_MIC_IN_LVL: /* Microphone */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = CSAUDIO_INPUT_CLASS;
dip->prev = AUDIO_MIXER_LAST;
dip->next = CSAUDIO_MIC_IN_MUTE;
strcpy(dip->label.name, AudioNmicrophone);
dip->un.v.num_channels = 2;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
#endif
case CSAUDIO_MONO_LVL: /* mono/microphone mixer */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = CSAUDIO_INPUT_CLASS;
dip->prev = AUDIO_MIXER_LAST;
dip->next = CSAUDIO_MONO_MUTE;
strcpy(dip->label.name, AudioNmicrophone);
dip->un.v.num_channels = 1;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case CSAUDIO_DAC_LVL: /* dacout */
dip->type = AUDIO_MIXER_VALUE;
@ -490,6 +507,16 @@ cs4231_query_devinfo(addr, dip)
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case CSAUDIO_MONO_LVL: /* mono/microphone mixer */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = CSAUDIO_INPUT_CLASS;
dip->prev = AUDIO_MIXER_LAST;
dip->next = CSAUDIO_MONO_MUTE;
strcpy(dip->label.name, AudioNmicrophone);
dip->un.v.num_channels = 1;
strcpy(dip->un.v.units.name, AudioNvolume);
break;
case CSAUDIO_CD_LVL: /* cd */
dip->type = AUDIO_MIXER_VALUE;
dip->mixer_class = CSAUDIO_INPUT_CLASS;
@ -549,7 +576,7 @@ cs4231_query_devinfo(addr, dip)
goto mute;
case CSAUDIO_MONITOR_MUTE:
dip->mixer_class = CSAUDIO_OUTPUT_CLASS;
dip->mixer_class = CSAUDIO_MONITOR_CLASS;
dip->type = AUDIO_MIXER_ENUM;
dip->prev = CSAUDIO_MONITOR_LVL;
dip->next = AUDIO_MIXER_LAST;
@ -626,222 +653,4 @@ cs4231_query_devinfo(addr, dip)
return (0);
}
int
cs4231_trigger_output(addr, start, end, blksize, intr, arg, param)
void *addr;
void *start, *end;
int blksize;
void (*intr) __P((void *));
void *arg;
struct audio_params *param;
{
struct cs4231_softc *sc = addr;
struct cs_dma *p;
volatile struct apc_dma *dma = sc->sc_dmareg;
int csr;
vsize_t n;
if (sc->sc_locked != 0) {
printf("cs4231_trigger_output: already running\n");
return (EINVAL);
}
sc->sc_locked = 1;
sc->sc_pintr = intr;
sc->sc_parg = arg;
for (p = sc->sc_dmas; p != NULL && p->addr != start; p = p->next)
/*void*/;
if (p == NULL) {
printf("cs4231_trigger_output: bad addr %p\n", start);
return (EINVAL);
}
n = (char *)end - (char *)start;
/* XXX
* Do only `blksize' at a time, so audio_pint() is kept
* synchronous with us...
*/
/*XXX*/sc->sc_blksz = blksize;
/*XXX*/sc->sc_nowplaying = p;
/*XXX*/sc->sc_playsegsz = n;
if (n > APC_MAX)
n = APC_MAX;
sc->sc_playcnt = n;
DPRINTF(("trigger_out: start %p, end %p, size %lu; "
"dmaaddr 0x%lx, dmacnt %lu, segsize %lu\n",
start, end, (u_long)sc->sc_playsegsz,
(u_long)p->dmamap->dm_segs[0].ds_addr,
(u_long)n, (u_long)p->size));
csr = dma->dmacsr;
dma->dmapnva = (u_long)p->dmamap->dm_segs[0].ds_addr;
dma->dmapnc = (u_long)n;
if ((csr & PDMA_GO) == 0 || (csr & APC_PPAUSE) != 0) {
int reg;
dma->dmacsr &= ~(APC_PIE|APC_PPAUSE);
dma->dmacsr |= APC_EI|APC_IE|APC_PIE|APC_EIE|APC_PMIE|PDMA_GO;
/* Start chip */
/* Probably should just ignore this.. */
ad_write(&sc->sc_ad1848, SP_LOWER_BASE_COUNT, 0xff);
ad_write(&sc->sc_ad1848, SP_UPPER_BASE_COUNT, 0xff);
reg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
(PLAYBACK_ENABLE|reg));
}
return (0);
}
int
cs4231_trigger_input(addr, start, end, blksize, intr, arg, param)
void *addr;
void *start, *end;
int blksize;
void (*intr) __P((void *));
void *arg;
struct audio_params *param;
{
return (ENXIO);
}
int
cs4231_halt_output(addr)
void *addr;
{
struct cs4231_softc *sc = addr;
volatile struct apc_dma *dma = sc->sc_dmareg;
int reg;
dma->dmacsr &= ~(APC_EI | APC_IE | APC_PIE | APC_EIE | PDMA_GO | APC_PMIE);
reg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (reg & ~PLAYBACK_ENABLE));
sc->sc_locked = 0;
return (0);
}
int
cs4231_halt_input(addr)
void *addr;
{
struct cs4231_softc *sc = addr;
int reg;
reg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (reg & ~CAPTURE_ENABLE));
sc->sc_locked = 0;
return (0);
}
int
cs4231_intr(arg)
void *arg;
{
struct cs4231_softc *sc = arg;
volatile struct apc_dma *dma = sc->sc_dmareg;
struct cs_dma *p;
int ret = 0;
int csr;
int reg, status;
#if defined(DEBUG) || defined(AUDIO_DEBUG)
char bits[128];
#endif
#ifdef AUDIO_DEBUG
if (cs4231debug > 1)
cs4231_regdump("audiointr", sc);
#endif
/* Read DMA status */
csr = dma->dmacsr;
DPRINTF((
"intr: csr=%s; dmapva=0x%lx,dmapc=%lu;dmapnva=0x%lx,dmapnc=%lu\n",
bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits)),
(u_long)dma->dmapva, (u_long)dma->dmapc,
(u_long)dma->dmapnva, (u_long)dma->dmapnc));
status = ADREAD(&sc->sc_ad1848, AD1848_STATUS);
DPRINTF(("%s: status: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
bitmask_snprintf(status, AD_R2_BITS, bits, sizeof(bits))));
if (status & (INTERRUPT_STATUS | SAMPLE_ERROR)) {
reg = ad_read(&sc->sc_ad1848, CS_IRQ_STATUS);
DPRINTF(("%s: i24: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
bitmask_snprintf(reg, CS_I24_BITS, bits, sizeof(bits))));
if (reg & CS_IRQ_PI) {
ad_write(&sc->sc_ad1848, SP_LOWER_BASE_COUNT, 0xff);
ad_write(&sc->sc_ad1848, SP_UPPER_BASE_COUNT, 0xff);
}
/* Clear interrupt bit */
ADWRITE(&sc->sc_ad1848, AD1848_STATUS, 0);
}
/* Write back DMA status (clears interrupt) */
dma->dmacsr = csr;
/*
* Simplistic.. if "play emtpy" is set advance to next chunk.
*/
#if 1
/* Ack all play interrupts*/
if ((csr & (APC_PI|APC_PD|APC_PIE|APC_PMI)) != 0)
ret = 1;
#endif
if (csr & APC_PM) {
u_long nextaddr, togo;
p = sc->sc_nowplaying;
togo = sc->sc_playsegsz - sc->sc_playcnt;
if (togo == 0) {
/* Roll over */
nextaddr = (u_long)p->dmamap->dm_segs[0].ds_addr;
sc->sc_playcnt = togo = APC_MAX;
} else {
nextaddr = dma->dmapnva + APC_MAX;
if (togo > APC_MAX)
togo = APC_MAX;
sc->sc_playcnt += togo;
}
dma->dmapnva = nextaddr;
dma->dmapnc = togo;
if (sc->sc_pintr != NULL)
(*sc->sc_pintr)(sc->sc_parg);
ret = 1;
}
if (csr & APC_CI) {
if (sc->sc_rintr != NULL) {
ret = 1;
(*sc->sc_rintr)(sc->sc_rarg);
}
}
#ifdef DEBUG
if (ret == 0) {
printf(
"oops: csr=%s; dmapva=0x%lx,dmapc=%lu;dmapnva=0x%lx,dmapnc=%lu\n",
bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits)),
(u_long)dma->dmapva, (u_long)dma->dmapc,
(u_long)dma->dmapnva, (u_long)dma->dmapnc);
ret = 1;
}
#endif
return (ret);
}
#endif /* NAUDIO > 0 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cs4231var.h,v 1.1 1999/06/05 14:29:10 mrg Exp $ */
/* $NetBSD: cs4231var.h,v 1.2 2002/03/12 04:48:28 uwe Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -36,36 +36,88 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DEV_IC_CS4231VAR_H_
#define _DEV_IC_CS4231VAR_H_
#define AUDIOCS_PROM_NAME "SUNW,CS4231"
/*
* List of device memory allocations (see cs4231_malloc/cs4231_free).
*/
struct cs_dma {
struct cs_dma *next;
caddr_t addr;
bus_dmamap_t dmamap;
bus_dma_segment_t segs[1];
int nsegs;
size_t size;
};
/*
* DMA transfer to/from CS4231.
*/
struct cs_transfer {
int t_active; /* this transfer is currently active */
struct cs_dma *t_dma; /* dma memory to transfer from/to */
vsize_t t_segsz; /* size of the segment */
vsize_t t_blksz; /* call audio(9) after this many bytes */
vsize_t t_cnt; /* how far are we into the segment */
void (*t_intr)(void*); /* audio(9) callback */
void *t_arg;
const char *t_name; /* for error/debug messages */
struct evcnt t_intrcnt;
struct evcnt t_ierrcnt;
};
/*
* Software state, per CS4231 audio chip.
*/
struct cs4231_softc {
struct ad1848_softc sc_ad1848; /* base device */
/* XXX */
struct sbusdev sc_sd; /* sbus device */
bus_space_tag_t sc_bustag;
bus_dma_tag_t sc_dmatag;
struct evcnt sc_intrcnt; /* statistics */
bus_dma_tag_t sc_dmatag;
struct cs_dma *sc_dmas;
struct cs_dma *sc_nowplaying; /*XXX*/
u_long sc_playsegsz; /*XXX*/
u_long sc_playcnt;
u_long sc_blksz;
int sc_open; /* single use device */
struct cs_dma *sc_dmas; /* allocated dma resources */
int sc_open; /* single use device */
int sc_locked; /* true when transfering data */
struct apc_dma *sc_dmareg; /* DMA registers */
struct evcnt sc_intrcnt; /* parent counter */
/* interfacing with the interrupt handlers */
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() */
struct cs_transfer sc_playback;
struct cs_transfer sc_capture;
};
void cs4231_init __P((struct cs4231_softc *));
int cs4231_read __P((struct ad1848_softc *, int));
void cs4231_write __P((struct ad1848_softc *, int, int));
int cs4231_intr __P((void *));
extern struct audio_hw_if audiocs_hw_if;
/*
* Bus independent code shared by sbus and ebus attachments.
*/
void cs4231_common_attach(struct cs4231_softc *, bus_space_handle_t);
int cs4231_transfer_init(struct cs4231_softc *, struct cs_transfer *,
bus_addr_t *, bus_size_t *,
void *, void *, int, void (*)(void *), void *);
void cs4231_transfer_advance(struct cs_transfer *,
bus_addr_t *, bus_size_t *);
/*
* Bus independent audio(9) methods.
*/
int cs4231_open(void *, int);
void cs4231_close(void *);
size_t cs4231_round_buffersize(void *, int, size_t);
int cs4231_round_blocksize(void *, int);
int cs4231_getdev(void *, struct audio_device *);
int cs4231_set_port(void *, mixer_ctrl_t *);
int cs4231_get_port(void *, mixer_ctrl_t *);
int cs4231_query_devinfo(void *, mixer_devinfo_t *);
int cs4231_get_props(void *);
void *cs4231_malloc(void *, int, size_t, int, int);
void cs4231_free(void *, void *, int);
#endif /* _DEV_IC_CS4231VAR_H_ */

View File

@ -1,7 +1,7 @@
/* $NetBSD: cs4231_sbus.c,v 1.17 2002/03/11 16:00:55 pk Exp $ */
/* $NetBSD: cs4231_sbus.c,v 1.18 2002/03/12 04:48:29 uwe Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* Copyright (c) 1998, 1999, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cs4231_sbus.c,v 1.17 2002/03/11 16:00:55 pk Exp $");
__KERNEL_RCSID(0, "$NetBSD: cs4231_sbus.c,v 1.18 2002/03/12 04:48:29 uwe Exp $");
#include "audio.h"
#if NAUDIO > 0
@ -61,50 +61,112 @@ __KERNEL_RCSID(0, "$NetBSD: cs4231_sbus.c,v 1.17 2002/03/11 16:00:55 pk Exp $");
#include <dev/ic/ad1848var.h>
#include <dev/ic/cs4231var.h>
#define AUDIO_ROM_NAME "SUNW,CS4231"
#define CS4231_REG_SIZE 16
#include <dev/ic/apcdmareg.h>
/* autoconfiguration driver */
void cs4231_attach_sbus __P((struct device *, struct device *, void *));
int cs4231_match_sbus __P((struct device *, struct cfdata *, void *));
#ifdef AUDIO_DEBUG
int cs4231_sbus_debug = 0;
#define DPRINTF(x) if (cs4231_sbus_debug) printf x
#else
#define DPRINTF(x)
#endif
struct cfattach audiocs_sbus_ca = {
sizeof(struct cs4231_softc), cs4231_match_sbus, cs4231_attach_sbus
/* where APC DMA registers are located */
#define CS4231_APCDMA_OFFSET 16
/* interrupt enable bits except those specific for playback/capture */
#define APC_ENABLE (APC_EI | APC_IE | APC_EIE)
struct cs4231_sbus_softc {
struct cs4231_softc sc_cs4231;
struct sbusdev sc_sd; /* sbus device */
volatile struct apc_dma *sc_dmareg; /* DMA controller registers */
};
/* autoconfig routines */
int
cs4231_match_sbus(parent, cf, aux)
static int cs4231_sbus_match(struct device *, struct cfdata *, void *);
static void cs4231_sbus_attach(struct device *, struct device *, void *);
struct cfattach audiocs_sbus_ca = {
sizeof(struct cs4231_sbus_softc), cs4231_sbus_match, cs4231_sbus_attach
};
/* audio_hw_if methods specific to apc dma */
static int cs4231_sbus_trigger_output(void *, void *, void *, int,
void (*)(void *), void *,
struct audio_params *);
static int cs4231_sbus_trigger_input(void *, void *, void *, int,
void (*)(void *), void *,
struct audio_params *);
static int cs4231_sbus_halt_output(void *);
static int cs4231_sbus_halt_input(void *);
struct audio_hw_if audiocs_sbus_hw_if = {
cs4231_open,
cs4231_close,
NULL, /* drain */
ad1848_query_encoding,
ad1848_set_params,
cs4231_round_blocksize,
ad1848_commit_settings,
NULL, /* init_output */
NULL, /* init_input */
NULL, /* start_output */
NULL, /* start_input */
cs4231_sbus_halt_output,
cs4231_sbus_halt_input,
NULL, /* speaker_ctl */
cs4231_getdev,
NULL, /* setfd */
cs4231_set_port,
cs4231_get_port,
cs4231_query_devinfo,
cs4231_malloc,
cs4231_free,
cs4231_round_buffersize,
NULL, /* mappage */
cs4231_get_props,
cs4231_sbus_trigger_output,
cs4231_sbus_trigger_input,
NULL, /* dev_ioctl */
};
#ifdef AUDIO_DEBUG
static void cs4231_sbus_regdump(char *, struct cs4231_sbus_softc *);
#endif
static int cs4231_sbus_intr(void *);
static int
cs4231_sbus_match(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);
return (strcmp(sa->sa_name, AUDIOCS_PROM_NAME) == 0);
}
/*
* Audio chip found.
*/
void
cs4231_attach_sbus(parent, self, aux)
static void
cs4231_sbus_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct cs4231_softc *sc = (struct cs4231_softc *)self;
struct cs4231_sbus_softc *sbsc = (struct cs4231_sbus_softc *)self;
struct cs4231_softc *sc = &sbsc->sc_cs4231;
struct sbus_attach_args *sa = aux;
bus_space_handle_t bh;
sc->sc_bustag = sa->sa_bustag;
sc->sc_dmatag = sa->sa_dmatag;
sc->sc_ad1848.parent = sc;
sc->sc_ad1848.sc_iot = sc->sc_bustag;
sc->sc_ad1848.sc_readreg = cs4231_read;
sc->sc_ad1848.sc_writereg = cs4231_write;
/*
* Map my registers in, if they aren't already in virtual
* address space.
@ -121,27 +183,365 @@ cs4231_attach_sbus(parent, self, aux)
}
}
sc->sc_ad1848.sc_ioh = bh;
sc->sc_dmareg = (struct apc_dma *)(u_long)(bh + CS4231_REG_SIZE);
cs4231_init(sc);
/* Put ad1848 driver in `MODE 2' mode */
sc->sc_ad1848.mode = 2;
ad1848_attach(&sc->sc_ad1848);
sbsc->sc_dmareg =
(volatile struct apc_dma *)(u_long)(bh + CS4231_APCDMA_OFFSET);
cs4231_common_attach(sc, bh);
printf("\n");
sbus_establish(&sc->sc_sd, &sc->sc_ad1848.sc_dev);
sbus_establish(&sbsc->sc_sd, &sc->sc_ad1848.sc_dev);
/* Establish interrupt channel */
if (sa->sa_nintr)
bus_intr_establish(sa->sa_bustag,
sa->sa_pri, IPL_AUDIO, 0,
cs4231_intr, sc);
cs4231_sbus_intr, sbsc);
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
sc->sc_ad1848.sc_dev.dv_xname, "intr");
audio_attach_mi(&audiocs_hw_if, sc, &sc->sc_ad1848.sc_dev);
audio_attach_mi(&audiocs_sbus_hw_if, sbsc, &sc->sc_ad1848.sc_dev);
}
#ifdef AUDIO_DEBUG
static void
cs4231_sbus_regdump(label, sc)
char *label;
struct cs4231_sbus_softc *sc;
{
char bits[128];
volatile struct apc_dma *dma = sc->sc_dmareg;
printf("cs4231regdump(%s): regs:", label);
printf("dmapva: 0x%x; ", dma->dmapva);
printf("dmapc: 0x%x; ", dma->dmapc);
printf("dmapnva: 0x%x; ", dma->dmapnva);
printf("dmapnc: 0x%x\n", dma->dmapnc);
printf("dmacva: 0x%x; ", dma->dmacva);
printf("dmacc: 0x%x; ", dma->dmacc);
printf("dmacnva: 0x%x; ", dma->dmacnva);
printf("dmacnc: 0x%x\n", dma->dmacnc);
printf("apc_dmacsr=%s\n",
bitmask_snprintf(dma->dmacsr, APC_BITS, bits, sizeof(bits)));
ad1848_dump_regs(&sc->sc_cs4231.sc_ad1848);
}
#endif /* AUDIO_DEBUG */
static int
cs4231_sbus_trigger_output(addr, start, end, blksize, intr, arg, param)
void *addr;
void *start, *end;
int blksize;
void (*intr)(void *);
void *arg;
struct audio_params *param;
{
struct cs4231_sbus_softc *sbsc = addr;
struct cs4231_softc *sc = &sbsc->sc_cs4231;
struct cs_transfer *t = &sc->sc_playback;
volatile struct apc_dma *dma = sbsc->sc_dmareg;
u_int32_t csr;
bus_addr_t dmaaddr;
bus_size_t dmasize;
int ret;
#ifdef AUDIO_DEBUG
char bits[128];
#endif
ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
start, end, blksize, intr, arg);
if (ret != 0)
return (ret);
DPRINTF(("trigger_output: csr=%s\n",
bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
DPRINTF(("trigger_output: was: %x %d, %x %d\n",
dma->dmapva, dma->dmapc, dma->dmapnva, dma->dmapnc));
/* load first block */
dma->dmapnva = (u_int32_t)dmaaddr;
dma->dmapnc = (u_int32_t)dmasize;
DPRINTF(("trigger_output: 1st: %x %d, %x %d\n",
dma->dmapva, dma->dmapc, dma->dmapnva, dma->dmapnc));
csr = dma->dmacsr;
if ((csr & PDMA_GO) == 0 || (csr & APC_PPAUSE) != 0) {
int cfg;
dma->dmacsr &= ~(APC_PPAUSE | APC_PMIE | APC_INTR_MASK);
csr = dma->dmacsr & ~APC_INTR_MASK;
csr |= APC_ENABLE | APC_PIE | APC_PMIE | PDMA_GO;
dma->dmacsr = csr;
ad_write(&sc->sc_ad1848, SP_LOWER_BASE_COUNT, 0xff);
ad_write(&sc->sc_ad1848, SP_UPPER_BASE_COUNT, 0xff);
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
(cfg | PLAYBACK_ENABLE));
} else {
DPRINTF(("trigger_output: already: csr=%s\n",
bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
}
/* load next block if we can */
if (dma->dmacsr & APC_PD) {
cs4231_transfer_advance(t, &dmaaddr, &dmasize);
dma->dmapnva = (u_int32_t)dmaaddr;
dma->dmapnc = (u_int32_t)dmasize;
DPRINTF(("trigger_output: 2nd: %x %d, %x %d\n",
dma->dmapva, dma->dmapc, dma->dmapnva, dma->dmapnc));
}
return (0);
}
static int
cs4231_sbus_halt_output(addr)
void *addr;
{
struct cs4231_sbus_softc *sbsc = addr;
struct cs4231_softc *sc = &sbsc->sc_cs4231;
volatile struct apc_dma *dma = sbsc->sc_dmareg;
u_int32_t csr;
int cfg;
#ifdef AUDIO_DEBUG
char bits[128];
#endif
sc->sc_playback.t_active = 0;
csr = dma->dmacsr;
DPRINTF(("halt_output: csr=%s\n",
bitmask_snprintf(dma->dmacsr, APC_BITS, bits, sizeof(bits))));
csr &= ~APC_INTR_MASK; /* do not clear interrupts accidentally */
csr |= APC_PPAUSE; /* pause playback (let current complete) */
dma->dmacsr = csr;
/* let the curernt transfer complete */
if (csr & PDMA_GO)
do {
csr = dma->dmacsr;
DPRINTF(("halt_output: csr=%s\n",
bitmask_snprintf(dma->dmacsr, APC_BITS,
bits, sizeof(bits))));
} while ((csr & APC_PM) == 0);
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,(cfg & ~PLAYBACK_ENABLE));
return (0);
}
/* NB: we don't enable APC_CMIE and won't use APC_CM */
static int
cs4231_sbus_trigger_input(addr, start, end, blksize, intr, arg, param)
void *addr;
void *start, *end;
int blksize;
void (*intr)(void *);
void *arg;
struct audio_params *param;
{
struct cs4231_sbus_softc *sbsc = addr;
struct cs4231_softc *sc = &sbsc->sc_cs4231;
struct cs_transfer *t = &sc->sc_capture;
volatile struct apc_dma *dma = sbsc->sc_dmareg;
u_int32_t csr;
bus_addr_t dmaaddr;
bus_size_t dmasize;
int ret;
#ifdef AUDIO_DEBUG
char bits[128];
#endif
ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
start, end, blksize, intr, arg);
if (ret != 0)
return (ret);
DPRINTF(("trigger_input: csr=%s\n",
bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
DPRINTF(("trigger_input: was: %x %d, %x %d\n",
dma->dmacva, dma->dmacc, dma->dmacnva, dma->dmacnc));
/* supply first block */
dma->dmacnva = (u_int32_t)dmaaddr;
dma->dmacnc = (u_int32_t)dmasize;
DPRINTF(("trigger_input: 1st: %x %d, %x %d\n",
dma->dmacva, dma->dmacc, dma->dmacnva, dma->dmacnc));
csr = dma->dmacsr;
if ((csr & CDMA_GO) == 0 || (csr & APC_CPAUSE) != 0) {
int cfg;
dma->dmacsr &= ~(APC_CPAUSE | APC_CMIE | APC_INTR_MASK);
csr = dma->dmacsr & ~APC_INTR_MASK;
csr |= APC_ENABLE | APC_CIE | CDMA_GO;
dma->dmacsr = csr;
ad_write(&sc->sc_ad1848, CS_LOWER_REC_CNT, 0xff);
ad_write(&sc->sc_ad1848, CS_UPPER_REC_CNT, 0xff);
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
(cfg | CAPTURE_ENABLE));
} else {
DPRINTF(("trigger_input: already: csr=%s\n",
bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits))));
}
/* supply next block if we can */
if (dma->dmacsr & APC_CD) {
cs4231_transfer_advance(t, &dmaaddr, &dmasize);
dma->dmacnva = (u_int32_t)dmaaddr;
dma->dmacnc = (u_int32_t)dmasize;
DPRINTF(("trigger_input: 2nd: %x %d, %x %d\n",
dma->dmacva, dma->dmacc, dma->dmacnva, dma->dmacnc));
}
return (0);
}
static int
cs4231_sbus_halt_input(addr)
void *addr;
{
struct cs4231_sbus_softc *sbsc = addr;
struct cs4231_softc *sc = &sbsc->sc_cs4231;
volatile struct apc_dma *dma = sbsc->sc_dmareg;
u_int32_t csr;
int cfg;
#ifdef AUDIO_DEBUG
char bits[128];
#endif
sc->sc_capture.t_active = 0;
csr = dma->dmacsr;
DPRINTF(("halt_input: csr=%s\n",
bitmask_snprintf(dma->dmacsr, APC_BITS, bits, sizeof(bits))));
csr &= ~APC_INTR_MASK; /* do not clear interrupts accidentally */
csr |= APC_CPAUSE;
dma->dmacsr = csr;
/* let the curernt transfer complete */
if (csr & CDMA_GO)
do {
csr = dma->dmacsr;
DPRINTF(("halt_input: csr=%s\n",
bitmask_snprintf(dma->dmacsr, APC_BITS,
bits, sizeof(bits))));
} while ((csr & APC_CM) == 0);
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, (cfg & ~CAPTURE_ENABLE));
return (0);
}
static int
cs4231_sbus_intr(arg)
void *arg;
{
struct cs4231_sbus_softc *sbsc = arg;
struct cs4231_softc *sc = &sbsc->sc_cs4231;
volatile struct apc_dma *dma = sbsc->sc_dmareg;
u_int32_t csr;
int status;
bus_addr_t dmaaddr;
bus_size_t dmasize;
int served;
#if defined(AUDIO_DEBUG) || defined(DIAGNOSTIC)
char bits[128];
#endif
csr = dma->dmacsr;
if ((csr & APC_INTR_MASK) == 0) /* any interrupt pedning? */
return (0);
dma->dmacsr = csr; /* write back DMA status to clear interrupt */
++sc->sc_intrcnt.ev_count;
served = 0;
#ifdef AUDIO_DEBUG
if (cs4231_sbus_debug > 1)
cs4231_sbus_regdump("audiointr", sbsc);
#endif
status = ADREAD(&sc->sc_ad1848, AD1848_STATUS);
DPRINTF(("%s: status: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
bitmask_snprintf(status, AD_R2_BITS, bits, sizeof(bits))));
if (status & INTERRUPT_STATUS) {
#ifdef AUDIO_DEBUG
int reason;
reason = ad_read(&sc->sc_ad1848, CS_IRQ_STATUS);
DPRINTF(("%s: i24: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
bitmask_snprintf(reason, CS_I24_BITS, bits, sizeof(bits))));
#endif
/* clear ad1848 interrupt */
ADWRITE(&sc->sc_ad1848, AD1848_STATUS, 0);
}
if (csr & APC_CI) {
if (csr & APC_CD) { /* can supply new block */
struct cs_transfer *t = &sc->sc_capture;
cs4231_transfer_advance(t, &dmaaddr, &dmasize);
dma->dmacnva = (u_int32_t)dmaaddr;
dma->dmacnc = (u_int32_t)dmasize;
if (t->t_intr != NULL)
(*t->t_intr)(t->t_arg);
++t->t_intrcnt.ev_count;
served = 1;
}
}
if (csr & APC_PMI) {
if (!sc->sc_playback.t_active)
served = 1; /* draining in halt_output() */
}
if (csr & APC_PI) {
if (csr & APC_PD) { /* can load new block */
struct cs_transfer *t = &sc->sc_playback;
if (t->t_active) {
cs4231_transfer_advance(t, &dmaaddr, &dmasize);
dma->dmapnva = (u_int32_t)dmaaddr;
dma->dmapnc = (u_int32_t)dmasize;
}
if (t->t_intr != NULL)
(*t->t_intr)(t->t_arg);
++t->t_intrcnt.ev_count;
served = 1;
}
}
/* got an interrupt we don't know how to handle */
if (!served) {
#ifdef DIAGNOSTIC
printf("%s: unhandled csr=%s\n", sc->sc_ad1848.sc_dev.dv_xname,
bitmask_snprintf(csr, APC_BITS, bits, sizeof(bits)));
#endif
/* evcnt? */
}
return (1);
}
#endif /* NAUDIO > 0 */