1 /* $NetBSD: esavar.h,v 1.12 2012/10/27 17:18:31 chs Exp $ */
2 
3 /*
4  * Copyright (c) 2001, 2002 Jared D. McNeill <jmcneill@invisible.ca>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 /*
29  * ESS Allegro-1 / Maestro3 Audio Driver
30  *
31  * Based on the FreeBSD maestro3 driver
32  *
33  */
34 
35 /*
36  * Number of simultaneous voices
37  *
38  * NOTE: The current code attaches audio0 thru audioESA_NUM_VOICES-1
39  *       to this driver, and a lot of people probably don't want that.
40  *       So, we'll default to 1 but we'll allow for the possibility of
41  *       more.
42  *
43  * The current MINISRC image limits us to a maximum of 4 simultaneous voices.
44  */
45 #ifndef ESA_NUM_VOICES
46 #define	ESA_NUM_VOICES		1
47 #endif
48 
49 #define KERNADDR(p)	((void *)((p)->addr))
50 #define	DMAADDR(p)	((p)->map->dm_segs[0].ds_addr)
51 
52 #define ESA_MINRATE	8000
53 #define ESA_MAXRATE	48000
54 
55 struct esa_list {
56 	int			currlen;
57 	int			mem_addr;
58 	int			max;
59 	int			indexmap[ESA_NUM_VOICES * 2];
60 };
61 
62 struct esa_dma {
63 	bus_dmamap_t		map;
64 	void *			addr;
65 	bus_dma_segment_t	segs[1];
66 	int			nsegs;
67 	size_t			size;
68 	struct esa_dma		*next;
69 };
70 
71 struct esa_channel {
72 	int			active;
73 	int			data_offset;
74 	int			index;
75 	size_t			bufsize;
76 	int			blksize;
77 	int			pos;
78 	void			*buf;
79 	uint32_t		start;
80 	uint32_t		count;
81 
82 	/* mode settings */
83 	struct audio_params	mode;
84 
85 	void			(*intr)(void *);
86 	void			*arg;
87 };
88 
89 struct esa_voice {
90 	device_t		parent;	/* pointer to our parent */
91 	struct esa_channel	play;
92 	struct esa_channel	rec;
93 	struct esa_dma		*dma;
94 	int			inlist;
95 	int			index;	/* 0: play, 1: record */
96 };
97 
98 struct esa_softc
99 {
100 	device_t		sc_dev;
101 	bus_space_tag_t		sc_iot;
102 	bus_space_handle_t	sc_ioh;
103 	bus_addr_t		sc_iob;
104 	bus_size_t		sc_ios;
105 	kmutex_t		sc_lock;
106 	kmutex_t		sc_intr_lock;
107 
108 	pcitag_t		sc_tag;
109 	pci_chipset_tag_t	sc_pct;
110 	bus_dma_tag_t		sc_dmat;
111 	pcireg_t		sc_pcireg;
112 
113 	void			*sc_ih;
114 
115 	struct ac97_codec_if	*codec_if;
116 	struct ac97_host_if	host_if;
117 	enum ac97_host_flags	codec_flags;
118 
119 	device_t		sc_audiodev[ESA_NUM_VOICES];
120 
121 	struct esa_voice	voice[ESA_NUM_VOICES];
122 	struct esa_dma		*sc_dmas;
123 	int			count;
124 
125 	/* timer management */
126 	int			sc_ntimers;
127 
128 	/* packed list structures */
129 	struct esa_list		mixer_list;
130 	struct esa_list		adc1_list;
131 	struct esa_list		dma_list;
132 	struct esa_list		msrc_list;
133 
134 	int			type;		/* Allegro-1 or Maestro 3? */
135 	int			delay1, delay2;
136 
137 	uint16_t		*savemem;
138 	size_t			savememsz;
139 };
140