xref: /netbsd/sys/arch/prep/isa/paud_isa.c (revision bf9ec67e)
1 /*	$NetBSD: paud_isa.c,v 1.2 2001/10/03 00:04:48 augustss 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 	NULL,
128 };
129 
130 /* autoconfig routines */
131 
132 static int
133 paud_match_isa(struct device *parent, struct cfdata *cf, void *aux)
134 {
135 	struct ad1848_isa_softc probesc, *sc = &probesc;
136 	struct isa_attach_args *ia = aux;
137 
138 	if (ia->ia_iobase != 0x830)
139 		return 0;
140 
141 	sc->sc_ad1848.sc_iot = ia->ia_iot;
142 	sc->sc_ic = ia->ia_ic;
143 	if (ad1848_isa_mapprobe(sc, ia->ia_iobase)) {
144 		ia->ia_iosize = AD1848_NPORT;
145 		ad1848_isa_unmap(sc);
146 		return 1;
147 	}
148 	return 0;
149 }
150 
151 /*
152  * Audio chip found.
153  */
154 static void
155 paud_attach_isa(struct device *parent, struct device *self, void *aux)
156 {
157 	struct ad1848_isa_softc *sc = (struct ad1848_isa_softc *) self;
158 	struct isa_attach_args *ia = aux;
159 
160 	sc->sc_ad1848.sc_iot = ia->ia_iot;
161 	sc->sc_ic = ia->ia_ic;
162 
163 	if (ad1848_isa_mapprobe(sc, ia->ia_iobase) == 0) {
164 		printf(": attach failed\n");
165 		return;
166 	}
167 	sc->sc_playdrq = ia->ia_drq;
168 	sc->sc_recdrq = ia->ia_drq2;
169 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq,
170 				       IST_EDGE, IPL_AUDIO,
171 				       ad1848_isa_intr, sc);
172 	ad1848_isa_attach(sc);
173 	printf("\n");
174 	audio_attach_mi(&paud_hw_if, &sc->sc_ad1848, &sc->sc_ad1848.sc_dev);
175 
176 }
177 
178 static int
179 paud_getdev(void *addr, struct audio_device *retp)
180 {
181 	*retp = paud_device;
182 	return 0;
183 }
184 
185 static ad1848_devmap_t mappings[] = {
186 	{ PAUD_MIC_IN_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
187 	{ PAUD_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
188 	{ PAUD_DAC_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
189 	{ PAUD_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL },
190 	{ PAUD_MIC_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
191 	{ PAUD_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
192 	{ PAUD_DAC_MUTE, AD1848_KIND_MUTE, AD1848_DAC_CHANNEL },
193 	{ PAUD_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL },
194 	{ PAUD_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
195 	{ PAUD_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1}
196 };
197 
198 static const int nummap = sizeof(mappings) / sizeof(mappings[0]);
199 
200 static int
201 paud_mixer_set_port(void *addr, mixer_ctrl_t *cp)
202 {
203 	struct ad1848_softc *ac = addr;
204 
205 	return (ad1848_mixer_set_port(ac, mappings, nummap, cp));
206 }
207 
208 static int
209 paud_mixer_get_port(void *addr, mixer_ctrl_t *cp)
210 {
211 	struct ad1848_softc *ac = addr;
212 
213 	return (ad1848_mixer_get_port(ac, mappings, nummap, cp));
214 }
215 
216 static int
217 paud_query_devinfo(void *addr, mixer_devinfo_t *dip)
218 {
219 
220 	switch(dip->index) {
221 	case PAUD_MIC_IN_LVL:	/* Microphone */
222 		dip->type = AUDIO_MIXER_VALUE;
223 		dip->mixer_class = PAUD_INPUT_CLASS;
224 		dip->prev = AUDIO_MIXER_LAST;
225 		dip->next = PAUD_MIC_IN_MUTE;
226 		strcpy(dip->label.name, AudioNmicrophone);
227 		dip->un.v.num_channels = 2;
228 		strcpy(dip->un.v.units.name, AudioNvolume);
229 		break;
230 
231 	case PAUD_LINE_IN_LVL:	/* line/CD */
232 		dip->type = AUDIO_MIXER_VALUE;
233 		dip->mixer_class = PAUD_INPUT_CLASS;
234 		dip->prev = AUDIO_MIXER_LAST;
235 		dip->next = PAUD_LINE_IN_MUTE;
236 		strcpy(dip->label.name, AudioNcd);
237 		dip->un.v.num_channels = 2;
238 		strcpy(dip->un.v.units.name, AudioNvolume);
239 		break;
240 
241 	case PAUD_DAC_LVL:		/*  dacout */
242 		dip->type = AUDIO_MIXER_VALUE;
243 		dip->mixer_class = PAUD_INPUT_CLASS;
244 		dip->prev = AUDIO_MIXER_LAST;
245 		dip->next = PAUD_DAC_MUTE;
246 		strcpy(dip->label.name, AudioNdac);
247 		dip->un.v.num_channels = 2;
248 		strcpy(dip->un.v.units.name, AudioNvolume);
249 		break;
250 
251 	case PAUD_REC_LVL:	/* record level */
252 		dip->type = AUDIO_MIXER_VALUE;
253 		dip->mixer_class = PAUD_RECORD_CLASS;
254 		dip->prev = AUDIO_MIXER_LAST;
255 		dip->next = PAUD_RECORD_SOURCE;
256 		strcpy(dip->label.name, AudioNrecord);
257 		dip->un.v.num_channels = 2;
258 		strcpy(dip->un.v.units.name, AudioNvolume);
259 		break;
260 
261 	case PAUD_MONITOR_LVL:	/* monitor level */
262 		dip->type = AUDIO_MIXER_VALUE;
263 		dip->mixer_class = PAUD_MONITOR_CLASS;
264 		dip->prev = AUDIO_MIXER_LAST;
265 		dip->next = PAUD_MONITOR_MUTE;
266 		strcpy(dip->label.name, AudioNmonitor);
267 		dip->un.v.num_channels = 1;
268 		strcpy(dip->un.v.units.name, AudioNvolume);
269 		break;
270 
271 	case PAUD_INPUT_CLASS:			/* input class descriptor */
272 		dip->type = AUDIO_MIXER_CLASS;
273 		dip->mixer_class = PAUD_INPUT_CLASS;
274 		dip->next = dip->prev = AUDIO_MIXER_LAST;
275 		strcpy(dip->label.name, AudioCinputs);
276 		break;
277 
278 	case PAUD_MONITOR_CLASS:			/* monitor class descriptor */
279 		dip->type = AUDIO_MIXER_CLASS;
280 		dip->mixer_class = PAUD_MONITOR_CLASS;
281 		dip->next = dip->prev = AUDIO_MIXER_LAST;
282 		strcpy(dip->label.name, AudioCmonitor);
283 		break;
284 
285 	case PAUD_RECORD_CLASS:			/* record source class */
286 		dip->type = AUDIO_MIXER_CLASS;
287 		dip->mixer_class = PAUD_RECORD_CLASS;
288 		dip->next = dip->prev = AUDIO_MIXER_LAST;
289 		strcpy(dip->label.name, AudioCrecord);
290 		break;
291 
292 	case PAUD_MIC_IN_MUTE:
293 		dip->mixer_class = PAUD_INPUT_CLASS;
294 		dip->type = AUDIO_MIXER_ENUM;
295 		dip->prev = PAUD_MIC_IN_LVL;
296 		dip->next = AUDIO_MIXER_LAST;
297 		goto mute;
298 
299 	case PAUD_LINE_IN_MUTE:
300 		dip->mixer_class = PAUD_INPUT_CLASS;
301 		dip->type = AUDIO_MIXER_ENUM;
302 		dip->prev = PAUD_LINE_IN_LVL;
303 		dip->next = AUDIO_MIXER_LAST;
304 		goto mute;
305 
306 	case PAUD_DAC_MUTE:
307 		dip->mixer_class = PAUD_INPUT_CLASS;
308 		dip->type = AUDIO_MIXER_ENUM;
309 		dip->prev = PAUD_DAC_LVL;
310 		dip->next = AUDIO_MIXER_LAST;
311 		goto mute;
312 
313 	case PAUD_MONITOR_MUTE:
314 		dip->mixer_class = PAUD_MONITOR_CLASS;
315 		dip->type = AUDIO_MIXER_ENUM;
316 		dip->prev = PAUD_MONITOR_LVL;
317 		dip->next = AUDIO_MIXER_LAST;
318 	mute:
319 		strcpy(dip->label.name, AudioNmute);
320 		dip->un.e.num_mem = 2;
321 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
322 		dip->un.e.member[0].ord = 0;
323 		strcpy(dip->un.e.member[1].label.name, AudioNon);
324 		dip->un.e.member[1].ord = 1;
325 		break;
326 
327 	case PAUD_RECORD_SOURCE:
328 		dip->mixer_class = PAUD_RECORD_CLASS;
329 		dip->type = AUDIO_MIXER_ENUM;
330 		dip->prev = PAUD_REC_LVL;
331 		dip->next = AUDIO_MIXER_LAST;
332 		strcpy(dip->label.name, AudioNsource);
333 		dip->un.e.num_mem = 3;
334 		strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
335 		dip->un.e.member[0].ord = PAUD_MIC_IN_LVL;
336 		strcpy(dip->un.e.member[1].label.name, AudioNcd);
337 		dip->un.e.member[1].ord = PAUD_LINE_IN_LVL;
338 		strcpy(dip->un.e.member[2].label.name, AudioNdac);
339 		dip->un.e.member[2].ord = PAUD_DAC_LVL;
340 		break;
341 
342 	default:
343 		return ENXIO;
344 		/*NOTREACHED*/
345 	}
346 
347 	return 0;
348 }
349 
350 #endif
351