1 /* $NetBSD: paud_isa.c,v 1.14 2011/07/01 16:57:29 dyoung 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: paud_isa.c,v 1.14 2011/07/01 16:57:29 dyoung Exp $"); 34 35 #include "audio.h" 36 #if NAUDIO > 0 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/errno.h> 41 #include <sys/device.h> 42 #include <sys/malloc.h> 43 44 #include <sys/bus.h> 45 #include <machine/intr.h> 46 47 #include <sys/audioio.h> 48 #include <dev/audio_if.h> 49 50 #include <dev/isa/isavar.h> 51 #include <dev/isa/isadmavar.h> 52 53 #include <dev/ic/ad1848reg.h> 54 #include <dev/ic/cs4231reg.h> 55 56 #include <dev/isa/ad1848var.h> 57 #include <dev/isa/cs4231var.h> 58 59 #define PAUD_MIC_IN_LVL 0 60 #define PAUD_LINE_IN_LVL 1 61 #define PAUD_DAC_LVL 2 62 #define PAUD_REC_LVL 3 63 #define PAUD_MONITOR_LVL 4 64 #define PAUD_MIC_IN_MUTE 5 65 #define PAUD_LINE_IN_MUTE 6 66 #define PAUD_DAC_MUTE 7 67 #define PAUD_MONITOR_MUTE 8 68 #define PAUD_RECORD_SOURCE 9 69 #define PAUD_INPUT_CLASS 10 70 #define PAUD_RECORD_CLASS 11 71 #define PAUD_MONITOR_CLASS 12 72 73 74 /* autoconfiguration driver */ 75 static void paud_attach_isa(device_t, device_t, void *); 76 static int paud_match_isa(device_t, cfdata_t, void *); 77 78 CFATTACH_DECL_NEW(paud_isa, sizeof(struct ad1848_isa_softc), 79 paud_match_isa, paud_attach_isa, NULL, NULL); 80 81 /* 82 * Define our interface to the higher level audio driver. 83 */ 84 static struct audio_device paud_device = { 85 "paud,cs4232", 86 "", 87 "" 88 }; 89 90 static int paud_getdev(void *, struct audio_device *); 91 static int paud_mixer_set_port(void *, mixer_ctrl_t *); 92 static int paud_mixer_get_port(void *, mixer_ctrl_t *); 93 static int paud_query_devinfo(void *, mixer_devinfo_t *); 94 95 static const struct audio_hw_if paud_hw_if = { 96 ad1848_isa_open, 97 ad1848_isa_close, 98 NULL, 99 ad1848_query_encoding, 100 ad1848_set_params, 101 ad1848_round_blocksize, 102 ad1848_commit_settings, 103 NULL, 104 NULL, 105 NULL, 106 NULL, 107 ad1848_isa_halt_output, 108 ad1848_isa_halt_input, 109 NULL, 110 paud_getdev, 111 NULL, 112 paud_mixer_set_port, 113 paud_mixer_get_port, 114 paud_query_devinfo, 115 ad1848_isa_malloc, 116 ad1848_isa_free, 117 ad1848_isa_round_buffersize, 118 ad1848_isa_mappage, 119 ad1848_isa_get_props, 120 ad1848_isa_trigger_output, 121 ad1848_isa_trigger_input, 122 NULL, 123 }; 124 125 /* autoconfig routines */ 126 127 static int 128 paud_match_isa(device_t parent, cfdata_t cf, void *aux) 129 { 130 struct ad1848_isa_softc probesc, *sc = &probesc; 131 struct isa_attach_args *ia = aux; 132 133 if (ia->ia_io[0].ir_addr != 0x830) 134 return 0; 135 136 sc->sc_ad1848.sc_iot = ia->ia_iot; 137 sc->sc_ic = ia->ia_ic; 138 if (ad1848_isa_mapprobe(sc, ia->ia_io[0].ir_addr)) { 139 ia->ia_io[0].ir_size = AD1848_NPORT; 140 ad1848_isa_unmap(sc); 141 return 1; 142 } 143 return 0; 144 } 145 146 /* 147 * Audio chip found. 148 */ 149 static void 150 paud_attach_isa(device_t parent, device_t self, void *aux) 151 { 152 struct ad1848_isa_softc *sc; 153 struct isa_attach_args *ia; 154 155 sc = device_private(self); 156 sc->sc_ad1848.sc_dev = self; 157 ia = aux; 158 sc->sc_ad1848.sc_iot = ia->ia_iot; 159 sc->sc_ic = ia->ia_ic; 160 161 if (ad1848_isa_mapprobe(sc, ia->ia_io[0].ir_addr) == 0) { 162 aprint_error(": attach failed\n"); 163 return; 164 } 165 sc->sc_playdrq = ia->ia_drq[0].ir_drq; 166 sc->sc_recdrq = ia->ia_drq[1].ir_drq; 167 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, 168 IST_EDGE, IPL_AUDIO, ad1848_isa_intr, sc); 169 ad1848_isa_attach(sc); 170 aprint_normal("\n"); 171 audio_attach_mi(&paud_hw_if, &sc->sc_ad1848, self); 172 173 } 174 175 static int 176 paud_getdev(void *addr, struct audio_device *retp) 177 { 178 179 *retp = paud_device; 180 return 0; 181 } 182 183 static ad1848_devmap_t mappings[] = { 184 { PAUD_MIC_IN_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL }, 185 { PAUD_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL }, 186 { PAUD_DAC_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL }, 187 { PAUD_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL }, 188 { PAUD_MIC_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL }, 189 { PAUD_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL }, 190 { PAUD_DAC_MUTE, AD1848_KIND_MUTE, AD1848_DAC_CHANNEL }, 191 { PAUD_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL }, 192 { PAUD_REC_LVL, AD1848_KIND_RECORDGAIN, -1 }, 193 { PAUD_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1} 194 }; 195 196 static const int nummap = sizeof(mappings) / sizeof(mappings[0]); 197 198 static int 199 paud_mixer_set_port(void *addr, mixer_ctrl_t *cp) 200 { 201 struct ad1848_softc *ac; 202 203 ac = addr; 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; 211 212 ac = addr; 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