2006-10-15 23:43:45 +04:00
|
|
|
/* $NetBSD: cs4231_ebus.c,v 1.22 2006/10/15 19:43:45 martin Exp $ */
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-07-14 19:47:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
2006-10-15 23:43:45 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: cs4231_ebus.c,v 1.22 2006/10/15 19:43:45 martin Exp $");
|
2003-07-14 19:47:00 +04:00
|
|
|
|
2002-03-12 07:48:28 +03:00
|
|
|
#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>
|
|
|
|
|
|
|
|
#ifdef AUDIO_DEBUG
|
|
|
|
int cs4231_ebus_debug = 0;
|
2002-03-12 09:00:42 +03:00
|
|
|
#define DPRINTF(x) if (cs4231_ebus_debug) printf x
|
2002-03-12 07:48:28 +03:00
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
struct cs4231_ebus_softc {
|
|
|
|
struct cs4231_softc sc_cs4231;
|
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
bus_space_tag_t sc_bt;
|
|
|
|
bus_space_handle_t sc_pdmareg; /* playback DMA */
|
|
|
|
bus_space_handle_t sc_cdmareg; /* record DMA */
|
2002-03-12 07:48:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void cs4231_ebus_attach(struct device *, struct device *, void *);
|
|
|
|
int cs4231_ebus_match(struct device *, struct cfdata *, void *);
|
|
|
|
|
2002-10-01 00:54:25 +04:00
|
|
|
CFATTACH_DECL(audiocs_ebus, sizeof(struct cs4231_ebus_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
cs4231_ebus_match, cs4231_ebus_attach, NULL, NULL);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2003-05-03 22:10:37 +04:00
|
|
|
/* audio_hw_if methods specific to ebus DMA */
|
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework
Summary of changes:
* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.
* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t
* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.
* add `struct device *' parameter to ac97_attach()
* all of audio HW drivers follow audio_hw_if and ac97 changes
2005-01-11 01:01:36 +03:00
|
|
|
static int cs4231_ebus_round_blocksize(void *, int, int,
|
|
|
|
const audio_params_t *);
|
2002-03-12 07:48:28 +03:00
|
|
|
static int cs4231_ebus_trigger_output(void *, void *, void *, int,
|
|
|
|
void (*)(void *), void *,
|
2005-01-11 06:45:17 +03:00
|
|
|
const audio_params_t *);
|
2002-03-12 07:48:28 +03:00
|
|
|
static int cs4231_ebus_trigger_input(void *, void *, void *, int,
|
|
|
|
void (*)(void *), void *,
|
2005-01-11 06:45:17 +03:00
|
|
|
const audio_params_t *);
|
2002-03-12 07:48:28 +03:00
|
|
|
static int cs4231_ebus_halt_output(void *);
|
|
|
|
static int cs4231_ebus_halt_input(void *);
|
|
|
|
|
2004-10-29 16:57:15 +04:00
|
|
|
const struct audio_hw_if audiocs_ebus_hw_if = {
|
2002-03-12 07:48:28 +03:00
|
|
|
cs4231_open,
|
|
|
|
cs4231_close,
|
|
|
|
NULL, /* drain */
|
|
|
|
ad1848_query_encoding,
|
|
|
|
ad1848_set_params,
|
2003-09-10 14:40:40 +04:00
|
|
|
cs4231_ebus_round_blocksize,
|
2002-03-12 07:48:28 +03:00
|
|
|
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,
|
2003-09-10 14:40:40 +04:00
|
|
|
NULL, /* round_buffersize */
|
2002-03-12 09:00:42 +03:00
|
|
|
NULL, /* mappage */
|
2002-03-12 07:48:28 +03:00
|
|
|
cs4231_get_props,
|
|
|
|
cs4231_ebus_trigger_output,
|
|
|
|
cs4231_ebus_trigger_input,
|
|
|
|
NULL, /* dev_ioctl */
|
2006-10-15 23:43:45 +04:00
|
|
|
NULL, /* powerstate */
|
2002-03-12 07:48:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef AUDIO_DEBUG
|
|
|
|
static void cs4231_ebus_regdump(char *, struct cs4231_ebus_softc *);
|
|
|
|
#endif
|
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
static int cs4231_ebus_dma_reset(bus_space_tag_t, bus_space_handle_t);
|
2002-03-12 07:48:28 +03:00
|
|
|
static int cs4231_ebus_trigger_transfer(struct cs4231_softc *,
|
2002-03-21 07:09:27 +03:00
|
|
|
struct cs_transfer *,
|
|
|
|
bus_space_tag_t, bus_space_handle_t,
|
2002-03-12 07:48:28 +03:00
|
|
|
int, void *, void *, int, void (*)(void *), void *,
|
2005-01-11 06:45:17 +03:00
|
|
|
const audio_params_t *);
|
2002-03-12 07:48:28 +03:00
|
|
|
static void cs4231_ebus_dma_advance(struct cs_transfer *,
|
2002-03-21 07:09:27 +03:00
|
|
|
bus_space_tag_t, bus_space_handle_t);
|
2002-03-12 07:48:28 +03:00
|
|
|
static int cs4231_ebus_dma_intr(struct cs_transfer *,
|
2002-03-21 07:09:27 +03:00
|
|
|
bus_space_tag_t, bus_space_handle_t);
|
2002-03-12 07:48:28 +03:00
|
|
|
static int cs4231_ebus_intr(void *);
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_match(struct device *parent, struct cfdata *cf, void *aux)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
struct ebus_attach_args *ea;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
ea = aux;
|
2002-03-12 07:48:28 +03:00
|
|
|
if (strcmp(ea->ea_name, AUDIOCS_PROM_NAME) == 0)
|
2005-01-11 07:23:14 +03:00
|
|
|
return 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
#ifdef __sparc__ /* XXX: Krups */
|
|
|
|
if (strcmp(ea->ea_name, "sound") == 0)
|
2005-01-11 07:23:14 +03:00
|
|
|
return 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
#endif
|
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_attach(struct device *parent, struct device *self, void *aux)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
struct cs4231_ebus_softc *ebsc;
|
|
|
|
struct cs4231_softc *sc;
|
|
|
|
struct ebus_attach_args *ea;
|
2002-03-12 07:48:28 +03:00
|
|
|
bus_space_handle_t bh;
|
|
|
|
int i;
|
|
|
|
|
2006-03-29 10:28:38 +04:00
|
|
|
ebsc = device_private(self);
|
2005-01-11 07:23:14 +03:00
|
|
|
sc = &ebsc->sc_cs4231;
|
|
|
|
ea = aux;
|
2002-03-21 07:09:27 +03:00
|
|
|
sc->sc_bustag = ebsc->sc_bt = ea->ea_bustag;
|
2002-03-12 07:48:28 +03:00
|
|
|
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.
|
|
|
|
*/
|
2002-03-22 00:33:57 +03:00
|
|
|
if (bus_space_map(ea->ea_bustag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
|
|
|
|
ea->ea_reg[0].size, 0, &bh) != 0) {
|
2002-04-04 21:41:09 +04:00
|
|
|
printf(": unable to map registers\n");
|
2002-03-22 00:33:57 +03:00
|
|
|
return;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-03-12 07:48:28 +03:00
|
|
|
/* 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 */
|
2002-03-21 07:09:27 +03:00
|
|
|
EBUS_DMAC_SIZE,
|
|
|
|
0, &ebsc->sc_pdmareg) != 0)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2002-04-04 21:41:09 +04:00
|
|
|
printf(": unable to map playback DMA registers\n");
|
2002-03-12 09:00:42 +03:00
|
|
|
return;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
2002-03-21 07:09:27 +03:00
|
|
|
EBUS_DMAC_SIZE,
|
|
|
|
0, &ebsc->sc_cdmareg) != 0)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2002-04-04 21:41:09 +04:00
|
|
|
printf(": unable to map capture DMA registers\n");
|
2002-03-12 09:00:42 +03:00
|
|
|
return;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* establish interrupt channels */
|
|
|
|
for (i = 0; i < ea->ea_nintr; ++i)
|
|
|
|
bus_intr_establish(ea->ea_bustag,
|
2002-12-10 16:44:47 +03:00
|
|
|
ea->ea_intr[i], IPL_AUDIO,
|
2002-03-12 07:48:28 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-10 14:40:40 +04:00
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_round_blocksize(void *addr, int blk, int mode,
|
|
|
|
const audio_params_t *param)
|
2003-09-10 14:40:40 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
/* we want to use DMA burst size of 16 words */
|
2005-01-11 07:23:14 +03:00
|
|
|
return blk & -64;
|
2003-09-10 14:40:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-12 07:48:28 +03:00
|
|
|
#ifdef AUDIO_DEBUG
|
|
|
|
static void
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_regdump(char *label, struct cs4231_ebus_softc *ebsc)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
|
|
|
/* char bits[128]; */
|
|
|
|
|
|
|
|
printf("cs4231regdump(%s): regs:", label);
|
2003-05-03 22:10:37 +04:00
|
|
|
/* XXX: dump ebus DMA and aux registers */
|
2002-03-12 07:48:28 +03:00
|
|
|
ad1848_dump_regs(&ebsc->sc_cs4231.sc_ad1848);
|
|
|
|
}
|
|
|
|
#endif /* AUDIO_DEBUG */
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX: nothing CS4231-specific in this code... */
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_dma_reset(bus_space_tag_t dt, bus_space_handle_t dh)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2002-03-21 07:09:27 +03:00
|
|
|
u_int32_t csr;
|
2002-03-12 07:48:28 +03:00
|
|
|
int timo;
|
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
/* reset, also clear TC, just in case */
|
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DCSR, EBDMA_RESET | EBDMA_TC);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
for (timo = 50000; timo != 0; --timo) {
|
|
|
|
csr = bus_space_read_4(dt, dh, EBUS_DMAC_DCSR);
|
|
|
|
if ((csr & (EBDMA_CYC_PEND | EBDMA_DRAIN)) == 0)
|
2002-03-12 07:48:28 +03:00
|
|
|
break;
|
2002-03-21 07:09:27 +03:00
|
|
|
}
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
if (timo == 0) {
|
2002-03-21 07:09:27 +03:00
|
|
|
char bits[128];
|
|
|
|
|
|
|
|
printf("cs4231_ebus_dma_reset: timed out: csr=%s\n",
|
|
|
|
bitmask_snprintf(csr, EBUS_DCSR_BITS,
|
|
|
|
bits, sizeof(bits)));
|
2005-01-11 07:23:14 +03:00
|
|
|
return ETIMEDOUT;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DCSR, csr & ~EBDMA_RESET);
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_dma_advance(struct cs_transfer *t, bus_space_tag_t dt,
|
|
|
|
bus_space_handle_t dh)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
|
|
|
bus_addr_t dmaaddr;
|
|
|
|
bus_size_t dmasize;
|
|
|
|
|
|
|
|
cs4231_transfer_advance(t, &dmaaddr, &dmasize);
|
2002-03-21 07:09:27 +03:00
|
|
|
|
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DNBR, (u_int32_t)dmasize);
|
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DNAR, (u_int32_t)dmaaddr);
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2003-09-10 14:40:40 +04:00
|
|
|
* Trigger transfer "t" using DMA controller at "dt"/"dh".
|
2002-03-12 07:48:28 +03:00
|
|
|
* "iswrite" defines direction of the transfer.
|
|
|
|
*/
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_trigger_transfer(
|
|
|
|
struct cs4231_softc *sc,
|
|
|
|
struct cs_transfer *t,
|
|
|
|
bus_space_tag_t dt,
|
|
|
|
bus_space_handle_t dh,
|
|
|
|
int iswrite,
|
|
|
|
void *start, void *end,
|
|
|
|
int blksize,
|
|
|
|
void (*intr)(void *),
|
|
|
|
void *arg,
|
|
|
|
const audio_params_t *param)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
uint32_t csr;
|
2002-03-12 07:48:28 +03:00
|
|
|
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)
|
2005-01-11 07:23:14 +03:00
|
|
|
return ret;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
ret = cs4231_ebus_dma_reset(dt, dh);
|
2002-03-12 07:48:28 +03:00
|
|
|
if (ret != 0)
|
2005-01-11 07:23:14 +03:00
|
|
|
return ret;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2002-03-22 14:52:07 +03:00
|
|
|
csr = bus_space_read_4(dt, dh, EBUS_DMAC_DCSR);
|
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DCSR,
|
2002-03-21 07:09:27 +03:00
|
|
|
csr | EBDMA_EN_NEXT | (iswrite ? EBDMA_WRITE : 0)
|
2003-09-10 14:40:40 +04:00
|
|
|
| EBDMA_EN_DMA | EBDMA_EN_CNT | EBDMA_INT_EN
|
|
|
|
| EBDMA_BURST_SIZE_16);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
/* first load: propagated to DACR/DBCR */
|
2005-01-11 07:23:14 +03:00
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DNBR, (uint32_t)dmasize);
|
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DNAR, (uint32_t)dmaaddr);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
/* next load: goes to DNAR/DNBR */
|
2002-03-21 07:09:27 +03:00
|
|
|
cs4231_ebus_dma_advance(t, dt, dh);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_trigger_output(void *addr, void *start, void *end, int blksize,
|
|
|
|
void (*intr)(void *), void *arg,
|
|
|
|
const audio_params_t *param)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
struct cs4231_ebus_softc *ebsc;
|
|
|
|
struct cs4231_softc *sc;
|
2002-03-21 07:09:27 +03:00
|
|
|
int cfg, ret;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
ebsc = addr;
|
|
|
|
sc = &ebsc->sc_cs4231;
|
2002-03-21 07:09:27 +03:00
|
|
|
ret = cs4231_ebus_trigger_transfer(sc, &sc->sc_playback,
|
|
|
|
ebsc->sc_bt, ebsc->sc_pdmareg,
|
|
|
|
0, /* iswrite */
|
2002-03-12 07:48:28 +03:00
|
|
|
start, end, blksize,
|
2002-03-21 07:09:27 +03:00
|
|
|
intr, arg, param);
|
2002-03-12 07:48:28 +03:00
|
|
|
if (ret != 0)
|
2005-01-11 07:23:14 +03:00
|
|
|
return ret;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
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);
|
2002-03-21 07:09:27 +03:00
|
|
|
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, cfg | PLAYBACK_ENABLE);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_trigger_input(void *addr, void *start, void *end, int blksize,
|
|
|
|
void (*intr)(void *), void *arg,
|
|
|
|
const audio_params_t *param)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
struct cs4231_ebus_softc *ebsc;
|
|
|
|
struct cs4231_softc *sc;
|
2002-03-21 07:09:27 +03:00
|
|
|
int cfg, ret;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
ebsc = addr;
|
|
|
|
sc = &ebsc->sc_cs4231;
|
2002-03-21 07:09:27 +03:00
|
|
|
ret = cs4231_ebus_trigger_transfer(sc, &sc->sc_capture,
|
|
|
|
ebsc->sc_bt, ebsc->sc_cdmareg,
|
|
|
|
1, /* iswrite */
|
2002-03-12 07:48:28 +03:00
|
|
|
start, end, blksize,
|
2002-03-21 07:09:27 +03:00
|
|
|
intr, arg, param);
|
2002-03-12 07:48:28 +03:00
|
|
|
if (ret != 0)
|
2005-01-11 07:23:14 +03:00
|
|
|
return ret;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
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);
|
2002-03-21 07:09:27 +03:00
|
|
|
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, cfg | CAPTURE_ENABLE);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_halt_output(void *addr)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
struct cs4231_ebus_softc *ebsc;
|
|
|
|
struct cs4231_softc *sc;
|
2002-03-21 07:09:27 +03:00
|
|
|
u_int32_t csr;
|
2002-03-12 07:48:28 +03:00
|
|
|
int cfg;
|
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
ebsc = addr;
|
|
|
|
sc = &ebsc->sc_cs4231;
|
2002-03-12 07:48:28 +03:00
|
|
|
sc->sc_playback.t_active = 0;
|
2002-03-21 07:09:27 +03:00
|
|
|
|
|
|
|
csr = bus_space_read_4(ebsc->sc_bt, ebsc->sc_pdmareg, EBUS_DMAC_DCSR);
|
|
|
|
bus_space_write_4(ebsc->sc_bt, ebsc->sc_pdmareg, EBUS_DMAC_DCSR,
|
|
|
|
csr & ~EBDMA_EN_DMA);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
|
2002-03-21 07:09:27 +03:00
|
|
|
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
|
|
|
|
cfg & ~PLAYBACK_ENABLE);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_halt_input(void *addr)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
struct cs4231_ebus_softc *ebsc;
|
|
|
|
struct cs4231_softc *sc;
|
|
|
|
uint32_t csr;
|
2002-03-12 07:48:28 +03:00
|
|
|
int cfg;
|
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
ebsc = addr;
|
|
|
|
sc = &ebsc->sc_cs4231;
|
2002-03-12 07:48:28 +03:00
|
|
|
sc->sc_capture.t_active = 0;
|
2002-03-21 07:09:27 +03:00
|
|
|
|
|
|
|
csr = bus_space_read_4(ebsc->sc_bt, ebsc->sc_cdmareg, EBUS_DMAC_DCSR);
|
|
|
|
bus_space_write_4(ebsc->sc_bt, ebsc->sc_cdmareg, EBUS_DMAC_DCSR,
|
|
|
|
csr & ~EBDMA_EN_DMA);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
|
2002-03-21 07:09:27 +03:00
|
|
|
ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
|
|
|
|
cfg & ~CAPTURE_ENABLE);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_dma_intr(struct cs_transfer *t, bus_space_tag_t dt,
|
|
|
|
bus_space_handle_t dh)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
uint32_t csr;
|
2002-03-12 07:48:28 +03:00
|
|
|
#ifdef AUDIO_DEBUG
|
|
|
|
char bits[128];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* read DMA status, clear TC bit by writing it back */
|
2002-03-21 07:09:27 +03:00
|
|
|
csr = bus_space_read_4(dt, dh, EBUS_DMAC_DCSR);
|
|
|
|
bus_space_write_4(dt, dh, EBUS_DMAC_DCSR, csr);
|
2002-03-12 07:48:28 +03:00
|
|
|
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);
|
2002-03-21 07:09:27 +03:00
|
|
|
cs4231_ebus_dma_reset(dt, dh);
|
2002-03-12 07:48:28 +03:00
|
|
|
/* how to notify audio(9)??? */
|
2005-01-11 07:23:14 +03:00
|
|
|
return 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((csr & EBDMA_INT_PEND) == 0)
|
2005-01-11 07:23:14 +03:00
|
|
|
return 0;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
++t->t_intrcnt.ev_count;
|
|
|
|
|
|
|
|
if ((csr & EBDMA_TC) == 0) { /* can this happen? */
|
|
|
|
printf("audiocs: %s INT_PEND but !TC\n", t->t_name);
|
2005-01-11 07:23:14 +03:00
|
|
|
return 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!t->t_active)
|
2005-01-11 07:23:14 +03:00
|
|
|
return 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
cs4231_ebus_dma_advance(t, dt, dh);
|
2002-03-12 07:48:28 +03:00
|
|
|
|
2003-05-03 22:10:37 +04:00
|
|
|
/* call audio(9) framework while DMA is chugging along */
|
2002-03-12 07:48:28 +03:00
|
|
|
if (t->t_intr != NULL)
|
|
|
|
(*t->t_intr)(t->t_arg);
|
2005-01-11 07:23:14 +03:00
|
|
|
return 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-01-11 07:23:14 +03:00
|
|
|
cs4231_ebus_intr(void *arg)
|
2002-03-12 07:48:28 +03:00
|
|
|
{
|
2005-01-11 07:23:14 +03:00
|
|
|
struct cs4231_ebus_softc *ebsc;
|
|
|
|
struct cs4231_softc *sc;
|
2002-03-12 07:48:28 +03:00
|
|
|
int status;
|
|
|
|
int ret;
|
|
|
|
#ifdef AUDIO_DEBUG
|
|
|
|
char bits[128];
|
|
|
|
#endif
|
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
ebsc = arg;
|
|
|
|
sc = &ebsc->sc_cs4231;
|
2002-03-12 07:48:28 +03:00
|
|
|
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
|
2002-03-12 09:00:42 +03:00
|
|
|
int reason;
|
2002-03-12 07:48:28 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
if (cs4231_ebus_dma_intr(&sc->sc_capture,
|
|
|
|
ebsc->sc_bt, ebsc->sc_cdmareg) != 0)
|
|
|
|
{
|
2002-03-12 09:00:42 +03:00
|
|
|
++sc->sc_intrcnt.ev_count;
|
|
|
|
ret = 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
2002-03-21 07:09:27 +03:00
|
|
|
if (cs4231_ebus_dma_intr(&sc->sc_playback,
|
|
|
|
ebsc->sc_bt, ebsc->sc_pdmareg) != 0)
|
|
|
|
{
|
2002-03-12 09:00:42 +03:00
|
|
|
++sc->sc_intrcnt.ev_count;
|
|
|
|
ret = 1;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|
|
|
|
|
2005-01-11 07:23:14 +03:00
|
|
|
return ret;
|
2002-03-12 07:48:28 +03:00
|
|
|
}
|