2003-12-04 16:57:30 +03:00
|
|
|
/* $NetBSD: esmvar.h,v 1.9 2003/12/04 13:57:31 keihan Exp $ */
|
2001-01-08 22:54:31 +03:00
|
|
|
|
|
|
|
/*-
|
2002-12-30 08:23:27 +03:00
|
|
|
* Copyright (c) 2002, 2003 Matt Fredette
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2003-12-04 16:57:30 +03:00
|
|
|
* Copyright (c) 2000, 2001 Rene Hexel <rh@NetBSD.org>
|
2001-01-08 22:54:31 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000 Taku YAMAMOTO <taku@cent.saitama-u.ac.jp>
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
* Taku Id: maestro.c,v 1.12 2000/09/06 03:32:34 taku Exp
|
|
|
|
* FreeBSD: /c/ncvs/src/sys/dev/sound/pci/maestro.c,v 1.4 2000/12/18 01:36:35 cg Exp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Credits:
|
|
|
|
*
|
|
|
|
* This code is based on the FreeBSD driver written by Taku YAMAMOTO
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original credits from the FreeBSD driver:
|
|
|
|
*
|
|
|
|
* Part of this code (especially in many magic numbers) was heavily inspired
|
|
|
|
* by the Linux driver originally written by
|
|
|
|
* Alan Cox <alan.cox@linux.org>, modified heavily by
|
|
|
|
* Zach Brown <zab@zabbo.net>.
|
|
|
|
*
|
|
|
|
* busdma()-ize and buffer size reduction were suggested by
|
|
|
|
* Cameron Grant <gandalf@vilnya.demon.co.uk>.
|
|
|
|
* Also he showed me the way to use busdma() suite.
|
|
|
|
*
|
|
|
|
* Internal speaker problems on NEC VersaPro's and Dell Inspiron 7500
|
|
|
|
* were looked at by
|
|
|
|
* Munehiro Matsuda <haro@tk.kubota.co.jp>,
|
|
|
|
* who brought patches based on the Linux driver with some simplification.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* IRQ timer fequency limits */
|
|
|
|
#define MAESTRO_MINFREQ 24
|
|
|
|
#define MAESTRO_MAXFREQ 48000
|
|
|
|
|
2002-12-30 08:23:27 +03:00
|
|
|
/*
|
|
|
|
* This driver allocates a contiguous 256KB region of memory.
|
|
|
|
* The Maestro's DMA interface, called the WaveCache, is weak
|
|
|
|
* (or at least incorrectly documented), and forces us to keep
|
|
|
|
* things very simple. This region is very carefully divided up
|
|
|
|
* into 64KB quarters, making 64KB a fundamental constant for
|
|
|
|
* this implementation - and this is as large as we can allow
|
|
|
|
* the upper-layer playback and record buffers to become.
|
|
|
|
*/
|
|
|
|
#define MAESTRO_QUARTER_SZ (64 * 1024)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first quarter of memory is used while recording. The
|
|
|
|
* first 512 bytes of it is reserved as a scratch area for the
|
|
|
|
* APUs that want to write (uninteresting, to us) FIFO status
|
|
|
|
* information. After some guard space, another 512 bytes is
|
|
|
|
* reserved for the APUs doing mixing. The remainder of this
|
|
|
|
* quarter of memory is wasted.
|
|
|
|
*/
|
|
|
|
#define MAESTRO_FIFO_OFF (MAESTRO_QUARTER_SZ * 0)
|
|
|
|
#define MAESTRO_FIFO_SZ (512)
|
|
|
|
#define MAESTRO_MIXBUF_OFF (MAESTRO_FIFO_OFF + 4096)
|
|
|
|
#define MAESTRO_MIXBUF_SZ (512)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The second quarter of memory is the playback buffer.
|
|
|
|
*/
|
|
|
|
#define MAESTRO_PLAYBUF_OFF (MAESTRO_QUARTER_SZ * 1)
|
|
|
|
#define MAESTRO_PLAYBUF_SZ MAESTRO_QUARTER_SZ
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The third quarter of memory is the mono record buffer.
|
|
|
|
* This is the only record buffer that the upper layer knows.
|
|
|
|
* When recording in stereo, our driver combines (in software)
|
|
|
|
* separately recorded left and right buffers here.
|
|
|
|
*/
|
|
|
|
#define MAESTRO_RECBUF_OFF (MAESTRO_QUARTER_SZ * 2)
|
|
|
|
#define MAESTRO_RECBUF_SZ MAESTRO_QUARTER_SZ
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The fourth quarter of memory is the stereo record buffer.
|
|
|
|
* When recording in stereo, the left and right channels are
|
|
|
|
* recorded separately into the two halves of this buffer.
|
|
|
|
*/
|
|
|
|
#define MAESTRO_RECBUF_L_OFF (MAESTRO_QUARTER_SZ * 3)
|
|
|
|
#define MAESTRO_RECBUF_L_SZ (MAESTRO_QUARTER_SZ / 2)
|
|
|
|
#define MAESTRO_RECBUF_R_OFF (MAESTRO_RECBUF_L_OFF + MAESTRO_RECBUF_L_SZ)
|
|
|
|
#define MAESTRO_RECBUF_R_SZ (MAESTRO_QUARTER_SZ / 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The size and alignment of the entire region. We keep
|
|
|
|
* the region aligned to a 128KB boundary, since this should
|
|
|
|
* force A16..A0 on all chip-generated addresses to correspond
|
|
|
|
* exactly to APU register contents.
|
|
|
|
*/
|
|
|
|
#define MAESTRO_DMA_SZ (MAESTRO_QUARTER_SZ * 4)
|
|
|
|
#define MAESTRO_DMA_ALIGN (128 * 1024)
|
|
|
|
|
2001-01-08 22:54:31 +03:00
|
|
|
struct esm_dma {
|
|
|
|
bus_dmamap_t map;
|
|
|
|
caddr_t addr;
|
|
|
|
bus_dma_segment_t segs[1];
|
|
|
|
int nsegs;
|
|
|
|
size_t size;
|
|
|
|
struct esm_dma *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
|
|
|
|
#define KERNADDR(p) ((void *)((p)->addr))
|
|
|
|
|
|
|
|
struct esm_chinfo {
|
|
|
|
u_int32_t base; /* DMA base */
|
2002-12-30 08:23:27 +03:00
|
|
|
caddr_t buffer; /* upper layer buffer */
|
|
|
|
u_int32_t offset; /* offset into buffer */
|
2001-01-08 22:54:31 +03:00
|
|
|
u_int32_t blocksize; /* block size in bytes */
|
2002-12-30 08:23:27 +03:00
|
|
|
u_int32_t bufsize; /* buffer size in bytes */
|
2001-01-08 22:54:31 +03:00
|
|
|
unsigned num; /* logical channel number */
|
|
|
|
u_int16_t aputype; /* APU channel type */
|
2002-12-30 08:23:27 +03:00
|
|
|
u_int16_t apubase; /* first sample number */
|
2001-01-08 22:54:31 +03:00
|
|
|
u_int16_t apublk; /* blk size in samples per ch */
|
|
|
|
u_int16_t apubuf; /* buf size in samples per ch */
|
|
|
|
u_int16_t nextirq; /* pos to trigger next IRQ at */
|
|
|
|
u_int16_t wcreg_tpl; /* wavecache tag and format */
|
|
|
|
u_int16_t sample_rate;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct esm_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
|
|
|
|
bus_space_tag_t st;
|
|
|
|
bus_space_handle_t sh;
|
|
|
|
|
|
|
|
pcitag_t tag;
|
|
|
|
pci_chipset_tag_t pc;
|
|
|
|
bus_dma_tag_t dmat;
|
|
|
|
pcireg_t subid;
|
|
|
|
|
|
|
|
void *ih;
|
|
|
|
|
|
|
|
struct ac97_codec_if *codec_if;
|
|
|
|
struct ac97_host_if host_if;
|
2001-01-10 02:27:07 +03:00
|
|
|
enum ac97_host_flags codec_flags;
|
2001-01-08 22:54:31 +03:00
|
|
|
|
2002-12-30 08:23:27 +03:00
|
|
|
struct esm_dma sc_dma;
|
|
|
|
int rings_alloced;
|
2001-01-08 22:54:31 +03:00
|
|
|
|
|
|
|
int pactive, ractive;
|
|
|
|
struct esm_chinfo pch;
|
|
|
|
struct esm_chinfo rch;
|
|
|
|
|
|
|
|
void (*sc_pintr)(void *);
|
|
|
|
void *sc_parg;
|
|
|
|
|
|
|
|
void (*sc_rintr)(void *);
|
|
|
|
void *sc_rarg;
|
2001-02-13 02:56:40 +03:00
|
|
|
|
|
|
|
/* Power Management */
|
|
|
|
char esm_suspend;
|
|
|
|
void *esm_powerhook;
|
2001-01-08 22:54:31 +03:00
|
|
|
};
|
|
|
|
|
2002-01-01 01:06:47 +03:00
|
|
|
enum esm_quirk_flags {
|
|
|
|
ESM_QUIRKF_GPIO = 0x1, /* needs GPIO operation */
|
|
|
|
ESM_QUIRKF_SWAPPEDCH = 0x2, /* left/right is reversed */
|
|
|
|
};
|
|
|
|
|
2001-01-10 02:27:07 +03:00
|
|
|
struct esm_quirks {
|
|
|
|
pci_vendor_id_t eq_vendor; /* subsystem vendor */
|
|
|
|
pci_product_id_t eq_product; /* and product */
|
|
|
|
|
|
|
|
enum esm_quirk_flags eq_quirks; /* needed quirks */
|
|
|
|
};
|
|
|
|
|
2001-01-08 22:54:31 +03:00
|
|
|
int esm_read_codec(void *, u_int8_t, u_int16_t *);
|
|
|
|
int esm_write_codec(void *, u_int8_t, u_int16_t);
|
|
|
|
int esm_attach_codec(void *, struct ac97_codec_if *);
|
|
|
|
void esm_reset_codec(void *);
|
2001-01-10 02:27:07 +03:00
|
|
|
enum ac97_host_flags esm_flags_codec(void *);
|
2001-01-08 22:54:31 +03:00
|
|
|
|
|
|
|
void esm_power(struct esm_softc *, int);
|
|
|
|
void esm_init(struct esm_softc *);
|
|
|
|
void esm_initcodec(struct esm_softc *);
|
|
|
|
|
|
|
|
int esm_init_output(void *, void *, int);
|
2002-12-30 08:23:27 +03:00
|
|
|
int esm_init_input(void *, void *, int);
|
2001-01-08 22:54:31 +03:00
|
|
|
int esm_trigger_output(void *, void *, void *, int, void (*)(void *),
|
|
|
|
void *, struct audio_params *);
|
|
|
|
int esm_trigger_input(void *, void *, void *, int, void (*)(void *),
|
|
|
|
void *, struct audio_params *);
|
|
|
|
int esm_halt_output(void *);
|
|
|
|
int esm_halt_input(void *);
|
|
|
|
int esm_open(void *, int);
|
|
|
|
void esm_close(void *);
|
|
|
|
int esm_getdev(void *, struct audio_device *);
|
|
|
|
int esm_round_blocksize(void *, int);
|
|
|
|
int esm_query_encoding(void *, struct audio_encoding *);
|
|
|
|
int esm_set_params(void *, int, int, struct audio_params *,
|
|
|
|
struct audio_params *);
|
|
|
|
int esm_set_port(void *, mixer_ctrl_t *);
|
|
|
|
int esm_get_port(void *, mixer_ctrl_t *);
|
|
|
|
int esm_query_devinfo(void *, mixer_devinfo_t *);
|
2003-02-01 09:23:35 +03:00
|
|
|
void *esm_malloc(void *, int, size_t, struct malloc_type *, int);
|
|
|
|
void esm_free(void *, void *, struct malloc_type *);
|
2001-01-08 22:54:31 +03:00
|
|
|
size_t esm_round_buffersize(void *, int, size_t);
|
|
|
|
paddr_t esm_mappage(void *, void *, off_t, int);
|
|
|
|
int esm_get_props(void *);
|
|
|
|
|
|
|
|
int esm_match(struct device *, struct cfdata *, void *);
|
|
|
|
void esm_attach(struct device *, struct device *, void *);
|
|
|
|
int esm_intr(void *);
|
|
|
|
|
|
|
|
int esm_allocmem(struct esm_softc *, size_t, size_t,
|
|
|
|
struct esm_dma *);
|
|
|
|
|
|
|
|
int esm_suspend(struct esm_softc *);
|
|
|
|
int esm_resume(struct esm_softc *);
|
|
|
|
int esm_shutdown(struct esm_softc *);
|
2001-01-10 02:27:07 +03:00
|
|
|
|
|
|
|
enum esm_quirk_flags esm_get_quirks(pcireg_t);
|