xref: /netbsd-src/sys/arch/prep/isa/paud_isa.c (revision 7cc2f76925f078d01ddc9e640a98f4ccfc9f8c3b)
1 /*	$NetBSD: paud_isa.c,v 1.1 2000/12/06 23:42:34 matt Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Kranenburg.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include "audio.h"
40 #if NAUDIO > 0
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/errno.h>
45 #include <sys/device.h>
46 #include <sys/malloc.h>
47 
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50 
51 #include <sys/audioio.h>
52 #include <dev/audio_if.h>
53 
54 #include <dev/isa/isavar.h>
55 #include <dev/isa/isadmavar.h>
56 
57 #include <dev/ic/ad1848reg.h>
58 #include <dev/ic/cs4231reg.h>
59 
60 #include <dev/isa/ad1848var.h>
61 #include <dev/isa/cs4231var.h>
62 
63 #define	PAUD_MIC_IN_LVL		0
64 #define	PAUD_LINE_IN_LVL        1
65 #define	PAUD_DAC_LVL		2
66 #define	PAUD_REC_LVL		3
67 #define	PAUD_MONITOR_LVL	4
68 #define	PAUD_MIC_IN_MUTE	5
69 #define	PAUD_LINE_IN_MUTE	6
70 #define	PAUD_DAC_MUTE		7
71 #define	PAUD_MONITOR_MUTE	8
72 #define	PAUD_RECORD_SOURCE	9
73 #define	PAUD_INPUT_CLASS	10
74 #define	PAUD_RECORD_CLASS	11
75 #define	PAUD_MONITOR_CLASS	12
76 
77 
78 /* autoconfiguration driver */
79 static void paud_attach_isa (struct device *, struct device *, void *);
80 static int  paud_match_isa (struct device *, struct cfdata *, void *);
81 
82 struct cfattach paud_isa_ca = {
83 	sizeof(struct ad1848_isa_softc), paud_match_isa, paud_attach_isa
84 };
85 
86 /*
87  * Define our interface to the higher level audio driver.
88  */
89 static struct audio_device paud_device = {
90 	"paud,cs4232",
91 	"",
92 	""
93 };
94 
95 static int paud_getdev(void *, struct audio_device *);
96 static int paud_mixer_set_port(void *, mixer_ctrl_t *);
97 static int paud_mixer_get_port(void *, mixer_ctrl_t *);
98 static int paud_query_devinfo(void *, mixer_devinfo_t *);
99 
100 static struct audio_hw_if paud_hw_if = {
101 	ad1848_isa_open,
102 	ad1848_isa_close,
103 	NULL,
104 	ad1848_query_encoding,
105 	ad1848_set_params,
106 	ad1848_round_blocksize,
107 	ad1848_commit_settings,
108 	NULL,
109 	NULL,
110 	NULL,
111 	NULL,
112 	ad1848_isa_halt_output,
113 	ad1848_isa_halt_input,
114 	NULL,
115 	paud_getdev,
116 	NULL,
117 	paud_mixer_set_port,
118 	paud_mixer_get_port,
119 	paud_query_devinfo,
120 	ad1848_isa_malloc,
121 	ad1848_isa_free,
122 	ad1848_isa_round_buffersize,
123 	ad1848_isa_mappage,
124 	ad1848_isa_get_props,
125 	ad1848_isa_trigger_output,
126 	ad1848_isa_trigger_input,
127 };
128 
129 /* autoconfig routines */
130 
131 static int
132 paud_match_isa(struct device *parent, struct cfdata *cf, void *aux)
133 {
134 	struct ad1848_isa_softc probesc, *sc = &probesc;
135 	struct isa_attach_args *ia = aux;
136 
137 	if (ia->ia_iobase != 0x830)
138 		return 0;
139 
140 	sc->sc_ad1848.sc_iot = ia->ia_iot;
141 	sc->sc_ic = ia->ia_ic;
142 	if (ad1848_isa_mapprobe(sc, ia->ia_iobase)) {
143 		ia->ia_iosize = AD1848_NPORT;
144 		ad1848_isa_unmap(sc);
145 		return 1;
146 	}
147 	return 0;
148 }
149 
150 /*
151  * Audio chip found.
152  */
153 static void
154 paud_attach_isa(struct device *parent, struct device *self, void *aux)
155 {
156 	struct ad1848_isa_softc *sc = (struct ad1848_isa_softc *) self;
157 	struct isa_attach_args *ia = aux;
158 
159 	sc->sc_ad1848.sc_iot = ia->ia_iot;
160 	sc->sc_ic = ia->ia_ic;
161 
162 	if (ad1848_isa_mapprobe(sc, ia->ia_iobase) == 0) {
163 		printf(": attach failed\n");
164 		return;
165 	}
166 	sc->sc_playdrq = ia->ia_drq;
167 	sc->sc_recdrq = ia->ia_drq2;
168 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq,
169 				       IST_EDGE, IPL_AUDIO,
170 				       ad1848_isa_intr, sc);
171 	ad1848_isa_attach(sc);
172 	printf("\n");
173 	audio_attach_mi(&paud_hw_if, &sc->sc_ad1848, &sc->sc_ad1848.sc_dev);
174 
175 }
176 
177 static int
178 paud_getdev(void *addr, struct audio_device *retp)
179 {
180 	*retp = paud_device;
181 	return 0;
182 }
183 
184 static ad1848_devmap_t mappings[] = {
185 	{ PAUD_MIC_IN_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
186 	{ PAUD_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
187 	{ PAUD_DAC_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
188 	{ PAUD_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL },
189 	{ PAUD_MIC_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
190 	{ PAUD_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
191 	{ PAUD_DAC_MUTE, AD1848_KIND_MUTE, AD1848_DAC_CHANNEL },
192 	{ PAUD_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL },
193 	{ PAUD_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
194 	{ PAUD_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1}
195 };
196 
197 static const int nummap = sizeof(mappings) / sizeof(mappings[0]);
198 
199 static int
200 paud_mixer_set_port(void *addr, mixer_ctrl_t *cp)
201 {
202 	struct ad1848_softc *ac = addr;
203 
204 	return (ad1848_mixer_set_port(ac, mappings, nummap, cp));
205 }
206 
207 static int
208 paud_mixer_get_port(void *addr, mixer_ctrl_t *cp)
209 {
210 	struct ad1848_softc *ac = addr;
211 
212 	return (ad1848_mixer_get_port(ac, mappings, nummap, cp));
213 }
214 
215 static int
216 paud_query_devinfo(void *addr, mixer_devinfo_t *dip)
217 {
218 
219 	switch(dip->index) {
220 	case PAUD_MIC_IN_LVL:	/* Microphone */
221 		dip->type = AUDIO_MIXER_VALUE;
222 		dip->mixer_class = PAUD_INPUT_CLASS;
223 		dip->prev = AUDIO_MIXER_LAST;
224 		dip->next = PAUD_MIC_IN_MUTE;
225 		strcpy(dip->label.name, AudioNmicrophone);
226 		dip->un.v.num_channels = 2;
227 		strcpy(dip->un.v.units.name, AudioNvolume);
228 		break;
229 
230 	case PAUD_LINE_IN_LVL:	/* line/CD */
231 		dip->type = AUDIO_MIXER_VALUE;
232 		dip->mixer_class = PAUD_INPUT_CLASS;
233 		dip->prev = AUDIO_MIXER_LAST;
234 		dip->next = PAUD_LINE_IN_MUTE;
235 		strcpy(dip->label.name, AudioNcd);
236 		dip->un.v.num_channels = 2;
237 		strcpy(dip->un.v.units.name, AudioNvolume);
238 		break;
239 
240 	case PAUD_DAC_LVL:		/*  dacout */
241 		dip->type = AUDIO_MIXER_VALUE;
242 		dip->mixer_class = PAUD_INPUT_CLASS;
243 		dip->prev = AUDIO_MIXER_LAST;
244 		dip->next = PAUD_DAC_MUTE;
245 		strcpy(dip->label.name, AudioNdac);
246 		dip->un.v.num_channels = 2;
247 		strcpy(dip->un.v.units.name, AudioNvolume);
248 		break;
249 
250 	case PAUD_REC_LVL:	/* record level */
251 		dip->type = AUDIO_MIXER_VALUE;
252 		dip->mixer_class = PAUD_RECORD_CLASS;
253 		dip->prev = AUDIO_MIXER_LAST;
254 		dip->next = PAUD_RECORD_SOURCE;
255 		strcpy(dip->label.name, AudioNrecord);
256 		dip->un.v.num_channels = 2;
257 		strcpy(dip->un.v.units.name, AudioNvolume);
258 		break;
259 
260 	case PAUD_MONITOR_LVL:	/* monitor level */
261 		dip->type = AUDIO_MIXER_VALUE;
262 		dip->mixer_class = PAUD_MONITOR_CLASS;
263 		dip->prev = AUDIO_MIXER_LAST;
264 		dip->next = PAUD_MONITOR_MUTE;
265 		strcpy(dip->label.name, AudioNmonitor);
266 		dip->un.v.num_channels = 1;
267 		strcpy(dip->un.v.units.name, AudioNvolume);
268 		break;
269 
270 	case PAUD_INPUT_CLASS:			/* input class descriptor */
271 		dip->type = AUDIO_MIXER_CLASS;
272 		dip->mixer_class = PAUD_INPUT_CLASS;
273 		dip->next = dip->prev = AUDIO_MIXER_LAST;
274 		strcpy(dip->label.name, AudioCinputs);
275 		break;
276 
277 	case PAUD_MONITOR_CLASS:			/* monitor class descriptor */
278 		dip->type = AUDIO_MIXER_CLASS;
279 		dip->mixer_class = PAUD_MONITOR_CLASS;
280 		dip->next = dip->prev = AUDIO_MIXER_LAST;
281 		strcpy(dip->label.name, AudioCmonitor);
282 		break;
283 
284 	case PAUD_RECORD_CLASS:			/* record source class */
285 		dip->type = AUDIO_MIXER_CLASS;
286 		dip->mixer_class = PAUD_RECORD_CLASS;
287 		dip->next = dip->prev = AUDIO_MIXER_LAST;
288 		strcpy(dip->label.name, AudioCrecord);
289 		break;
290 
291 	case PAUD_MIC_IN_MUTE:
292 		dip->mixer_class = PAUD_INPUT_CLASS;
293 		dip->type = AUDIO_MIXER_ENUM;
294 		dip->prev = PAUD_MIC_IN_LVL;
295 		dip->next = AUDIO_MIXER_LAST;
296 		goto mute;
297 
298 	case PAUD_LINE_IN_MUTE:
299 		dip->mixer_class = PAUD_INPUT_CLASS;
300 		dip->type = AUDIO_MIXER_ENUM;
301 		dip->prev = PAUD_LINE_IN_LVL;
302 		dip->next = AUDIO_MIXER_LAST;
303 		goto mute;
304 
305 	case PAUD_DAC_MUTE:
306 		dip->mixer_class = PAUD_INPUT_CLASS;
307 		dip->type = AUDIO_MIXER_ENUM;
308 		dip->prev = PAUD_DAC_LVL;
309 		dip->next = AUDIO_MIXER_LAST;
310 		goto mute;
311 
312 	case PAUD_MONITOR_MUTE:
313 		dip->mixer_class = PAUD_MONITOR_CLASS;
314 		dip->type = AUDIO_MIXER_ENUM;
315 		dip->prev = PAUD_MONITOR_LVL;
316 		dip->next = AUDIO_MIXER_LAST;
317 	mute:
318 		strcpy(dip->label.name, AudioNmute);
319 		dip->un.e.num_mem = 2;
320 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
321 		dip->un.e.member[0].ord = 0;
322 		strcpy(dip->un.e.member[1].label.name, AudioNon);
323 		dip->un.e.member[1].ord = 1;
324 		break;
325 
326 	case PAUD_RECORD_SOURCE:
327 		dip->mixer_class = PAUD_RECORD_CLASS;
328 		dip->type = AUDIO_MIXER_ENUM;
329 		dip->prev = PAUD_REC_LVL;
330 		dip->next = AUDIO_MIXER_LAST;
331 		strcpy(dip->label.name, AudioNsource);
332 		dip->un.e.num_mem = 3;
333 		strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
334 		dip->un.e.member[0].ord = PAUD_MIC_IN_LVL;
335 		strcpy(dip->un.e.member[1].label.name, AudioNcd);
336 		dip->un.e.member[1].ord = PAUD_LINE_IN_LVL;
337 		strcpy(dip->un.e.member[2].label.name, AudioNdac);
338 		dip->un.e.member[2].ord = PAUD_DAC_LVL;
339 		break;
340 
341 	default:
342 		return ENXIO;
343 		/*NOTREACHED*/
344 	}
345 
346 	return 0;
347 }
348 
349 #endif
350