1 1.56 tsutsui /* $NetBSD: vs.c,v 1.56 2022/05/26 14:33:29 tsutsui Exp $ */ 2 1.1 minoura 3 1.1 minoura /* 4 1.1 minoura * Copyright (c) 2001 Tetsuya Isaki. All rights reserved. 5 1.1 minoura * 6 1.1 minoura * Redistribution and use in source and binary forms, with or without 7 1.1 minoura * modification, are permitted provided that the following conditions 8 1.1 minoura * are met: 9 1.1 minoura * 1. Redistributions of source code must retain the above copyright 10 1.1 minoura * notice, this list of conditions and the following disclaimer. 11 1.1 minoura * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 minoura * notice, this list of conditions and the following disclaimer in the 13 1.1 minoura * documentation and/or other materials provided with the distribution. 14 1.1 minoura * 15 1.1 minoura * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 1.1 minoura * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 1.1 minoura * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 1.1 minoura * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 1.1 minoura * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 1.1 minoura * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 1.1 minoura * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 1.1 minoura * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 1.1 minoura * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 1.1 minoura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 1.1 minoura * SUCH DAMAGE. 26 1.1 minoura */ 27 1.1 minoura 28 1.1 minoura /* 29 1.1 minoura * VS - OKI MSM6258 ADPCM voice synthesizer device driver. 30 1.1 minoura */ 31 1.22 lukem 32 1.22 lukem #include <sys/cdefs.h> 33 1.56 tsutsui __KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.56 2022/05/26 14:33:29 tsutsui Exp $"); 34 1.1 minoura 35 1.1 minoura #include "audio.h" 36 1.1 minoura #include "vs.h" 37 1.1 minoura #if NAUDIO > 0 && NVS > 0 38 1.1 minoura 39 1.1 minoura #include <sys/param.h> 40 1.1 minoura #include <sys/systm.h> 41 1.1 minoura #include <sys/device.h> 42 1.35 jmcneill #include <sys/kmem.h> 43 1.1 minoura 44 1.1 minoura #include <sys/audioio.h> 45 1.51 isaki #include <dev/audio/audio_if.h> 46 1.1 minoura 47 1.1 minoura #include <machine/bus.h> 48 1.1 minoura #include <machine/cpu.h> 49 1.1 minoura 50 1.1 minoura #include <dev/ic/msm6258var.h> 51 1.1 minoura 52 1.1 minoura #include <arch/x68k/dev/dmacvar.h> 53 1.1 minoura #include <arch/x68k/dev/intiovar.h> 54 1.24 minoura #include <arch/x68k/dev/opmvar.h> 55 1.1 minoura 56 1.1 minoura #include <arch/x68k/dev/vsvar.h> 57 1.1 minoura 58 1.56 tsutsui #include "ioconf.h" 59 1.56 tsutsui 60 1.1 minoura #ifdef VS_DEBUG 61 1.28 kent #define DPRINTF(y,x) if (vs_debug >= (y)) printf x 62 1.9 isaki static int vs_debug; 63 1.1 minoura #ifdef AUDIO_DEBUG 64 1.1 minoura extern int audiodebug; 65 1.1 minoura #endif 66 1.1 minoura #else 67 1.9 isaki #define DPRINTF(y,x) 68 1.1 minoura #endif 69 1.1 minoura 70 1.33 isaki static int vs_match(device_t, cfdata_t, void *); 71 1.33 isaki static void vs_attach(device_t, device_t, void *); 72 1.1 minoura 73 1.28 kent static int vs_dmaintr(void *); 74 1.28 kent static int vs_dmaerrintr(void *); 75 1.1 minoura 76 1.1 minoura /* MI audio layer interface */ 77 1.51 isaki static int vs_query_format(void *, audio_format_query_t *); 78 1.51 isaki static int vs_set_format(void *, int, 79 1.51 isaki const audio_params_t *, const audio_params_t *, 80 1.51 isaki audio_filter_reg_t *, audio_filter_reg_t *); 81 1.51 isaki static int vs_commit_settings(void *); 82 1.43 isaki static int vs_start_input(void *, void *, int, void (*)(void *), void *); 83 1.43 isaki static int vs_start_output(void *, void *, int, void (*)(void *), void *); 84 1.28 kent static int vs_halt_output(void *); 85 1.28 kent static int vs_halt_input(void *); 86 1.35 jmcneill static int vs_allocmem(struct vs_softc *, size_t, size_t, size_t, 87 1.28 kent struct vs_dma *); 88 1.28 kent static void vs_freemem(struct vs_dma *); 89 1.28 kent static int vs_getdev(void *, struct audio_device *); 90 1.28 kent static int vs_set_port(void *, mixer_ctrl_t *); 91 1.28 kent static int vs_get_port(void *, mixer_ctrl_t *); 92 1.28 kent static int vs_query_devinfo(void *, mixer_devinfo_t *); 93 1.35 jmcneill static void *vs_allocm(void *, int, size_t); 94 1.35 jmcneill static void vs_freem(void *, void *, size_t); 95 1.28 kent static size_t vs_round_buffersize(void *, int, size_t); 96 1.28 kent static int vs_get_props(void *); 97 1.35 jmcneill static void vs_get_locks(void *, kmutex_t **, kmutex_t **); 98 1.1 minoura 99 1.1 minoura /* lower functions */ 100 1.2 minoura static int vs_round_sr(u_long); 101 1.51 isaki static inline void vs_set_panout(struct vs_softc *, u_long); 102 1.1 minoura 103 1.33 isaki CFATTACH_DECL_NEW(vs, sizeof(struct vs_softc), 104 1.18 thorpej vs_match, vs_attach, NULL, NULL); 105 1.1 minoura 106 1.26 chs static int vs_attached; 107 1.26 chs 108 1.25 yamt static const struct audio_hw_if vs_hw_if = { 109 1.51 isaki .query_format = vs_query_format, 110 1.51 isaki .set_format = vs_set_format, 111 1.51 isaki .commit_settings = vs_commit_settings, 112 1.50 isaki .start_output = vs_start_output, 113 1.50 isaki .start_input = vs_start_input, 114 1.50 isaki .halt_output = vs_halt_output, 115 1.50 isaki .halt_input = vs_halt_input, 116 1.50 isaki .getdev = vs_getdev, 117 1.50 isaki .set_port = vs_set_port, 118 1.50 isaki .get_port = vs_get_port, 119 1.50 isaki .query_devinfo = vs_query_devinfo, 120 1.50 isaki .allocm = vs_allocm, 121 1.50 isaki .freem = vs_freem, 122 1.50 isaki .round_buffersize = vs_round_buffersize, 123 1.50 isaki .get_props = vs_get_props, 124 1.50 isaki .get_locks = vs_get_locks, 125 1.1 minoura }; 126 1.1 minoura 127 1.1 minoura static struct audio_device vs_device = { 128 1.1 minoura "OKI MSM6258", 129 1.1 minoura "", 130 1.1 minoura "vs" 131 1.1 minoura }; 132 1.1 minoura 133 1.51 isaki static const struct audio_format vs_formats = { 134 1.51 isaki .mode = AUMODE_PLAY | AUMODE_RECORD, 135 1.51 isaki .encoding = AUDIO_ENCODING_ADPCM, 136 1.51 isaki .validbits = 4, 137 1.51 isaki .precision = 4, 138 1.51 isaki .channels = 1, 139 1.51 isaki .channel_mask = AUFMT_MONAURAL, 140 1.51 isaki .frequency_type = 5, 141 1.51 isaki .frequency = { VS_RATE_3K, VS_RATE_5K, VS_RATE_7K, 142 1.51 isaki VS_RATE_10K, VS_RATE_15K }, 143 1.51 isaki }; 144 1.51 isaki 145 1.1 minoura struct { 146 1.1 minoura u_long rate; 147 1.1 minoura u_char clk; 148 1.1 minoura u_char den; 149 1.1 minoura } vs_l2r[] = { 150 1.2 minoura { VS_RATE_15K, VS_CLK_8MHZ, VS_SRATE_512 }, 151 1.2 minoura { VS_RATE_10K, VS_CLK_8MHZ, VS_SRATE_768 }, 152 1.2 minoura { VS_RATE_7K, VS_CLK_8MHZ, VS_SRATE_1024}, 153 1.2 minoura { VS_RATE_5K, VS_CLK_4MHZ, VS_SRATE_768 }, 154 1.2 minoura { VS_RATE_3K, VS_CLK_4MHZ, VS_SRATE_1024} 155 1.1 minoura }; 156 1.1 minoura 157 1.2 minoura #define NUM_RATE (sizeof(vs_l2r)/sizeof(vs_l2r[0])) 158 1.1 minoura 159 1.1 minoura static int 160 1.33 isaki vs_match(device_t parent, cfdata_t cf, void *aux) 161 1.1 minoura { 162 1.28 kent struct intio_attach_args *ia; 163 1.1 minoura 164 1.28 kent ia = aux; 165 1.26 chs if (strcmp(ia->ia_name, "vs") || vs_attached) 166 1.1 minoura return 0; 167 1.1 minoura 168 1.1 minoura if (ia->ia_addr == INTIOCF_ADDR_DEFAULT) 169 1.1 minoura ia->ia_addr = VS_ADDR; 170 1.1 minoura if (ia->ia_dma == INTIOCF_DMA_DEFAULT) 171 1.1 minoura ia->ia_dma = VS_DMA; 172 1.1 minoura if (ia->ia_dmaintr == INTIOCF_DMAINTR_DEFAULT) 173 1.1 minoura ia->ia_dmaintr = VS_DMAINTR; 174 1.1 minoura 175 1.1 minoura /* fixed parameters */ 176 1.1 minoura if (ia->ia_addr != VS_ADDR) 177 1.1 minoura return 0; 178 1.1 minoura if (ia->ia_dma != VS_DMA) 179 1.1 minoura return 0; 180 1.1 minoura if (ia->ia_dmaintr != VS_DMAINTR) 181 1.1 minoura return 0; 182 1.1 minoura 183 1.9 isaki #ifdef VS_DEBUG 184 1.9 isaki vs_debug = 1; 185 1.1 minoura #ifdef AUDIO_DEBUG 186 1.1 minoura audiodebug = 2; 187 1.1 minoura #endif 188 1.9 isaki #endif 189 1.1 minoura 190 1.1 minoura return 1; 191 1.1 minoura } 192 1.1 minoura 193 1.1 minoura static void 194 1.33 isaki vs_attach(device_t parent, device_t self, void *aux) 195 1.1 minoura { 196 1.28 kent struct vs_softc *sc; 197 1.1 minoura bus_space_tag_t iot; 198 1.1 minoura bus_space_handle_t ioh; 199 1.28 kent struct intio_attach_args *ia; 200 1.1 minoura 201 1.33 isaki sc = device_private(self); 202 1.33 isaki sc->sc_dev = self; 203 1.28 kent ia = aux; 204 1.26 chs vs_attached = 1; 205 1.26 chs 206 1.1 minoura printf("\n"); 207 1.28 kent 208 1.1 minoura /* Re-map the I/O space */ 209 1.1 minoura iot = ia->ia_bst; 210 1.1 minoura bus_space_map(iot, ia->ia_addr, 0x2000, BUS_SPACE_MAP_SHIFTED, &ioh); 211 1.1 minoura 212 1.1 minoura /* Initialize sc */ 213 1.1 minoura sc->sc_iot = iot; 214 1.1 minoura sc->sc_ioh = ioh; 215 1.31 christos sc->sc_addr = (void *) ia->ia_addr; 216 1.1 minoura sc->sc_dmas = NULL; 217 1.47 isaki sc->sc_prev_vd = NULL; 218 1.35 jmcneill mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); 219 1.51 isaki mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_VM); 220 1.1 minoura 221 1.1 minoura /* XXX */ 222 1.1 minoura bus_space_map(iot, PPI_ADDR, PPI_MAPSIZE, BUS_SPACE_MAP_SHIFTED, 223 1.1 minoura &sc->sc_ppi); 224 1.1 minoura 225 1.1 minoura /* Initialize DMAC */ 226 1.1 minoura sc->sc_dmat = ia->ia_dmat; 227 1.1 minoura sc->sc_dma_ch = dmac_alloc_channel(parent, ia->ia_dma, "vs", 228 1.1 minoura ia->ia_dmaintr, vs_dmaintr, sc, 229 1.46 isaki ia->ia_dmaintr+1, vs_dmaerrintr, sc, 230 1.46 isaki (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC | DMAC_DCR_OPS_8BIT), 231 1.46 isaki (DMAC_OCR_SIZE_BYTE | DMAC_OCR_REQG_EXTERNAL)); 232 1.1 minoura 233 1.33 isaki aprint_normal_dev(self, "MSM6258V ADPCM voice synthesizer\n"); 234 1.1 minoura 235 1.33 isaki audio_attach_mi(&vs_hw_if, sc, sc->sc_dev); 236 1.1 minoura } 237 1.1 minoura 238 1.1 minoura /* 239 1.1 minoura * vs interrupt handler 240 1.1 minoura */ 241 1.1 minoura static int 242 1.1 minoura vs_dmaintr(void *hdl) 243 1.1 minoura { 244 1.28 kent struct vs_softc *sc; 245 1.1 minoura 246 1.9 isaki DPRINTF(2, ("vs_dmaintr\n")); 247 1.28 kent sc = hdl; 248 1.35 jmcneill 249 1.35 jmcneill mutex_spin_enter(&sc->sc_intr_lock); 250 1.35 jmcneill 251 1.1 minoura if (sc->sc_pintr) { 252 1.1 minoura sc->sc_pintr(sc->sc_parg); 253 1.1 minoura } else if (sc->sc_rintr) { 254 1.1 minoura sc->sc_rintr(sc->sc_rarg); 255 1.1 minoura } else { 256 1.19 isaki printf("vs_dmaintr: spurious interrupt\n"); 257 1.1 minoura } 258 1.1 minoura 259 1.35 jmcneill mutex_spin_exit(&sc->sc_intr_lock); 260 1.35 jmcneill 261 1.1 minoura return 1; 262 1.1 minoura } 263 1.1 minoura 264 1.1 minoura static int 265 1.1 minoura vs_dmaerrintr(void *hdl) 266 1.1 minoura { 267 1.28 kent struct vs_softc *sc; 268 1.1 minoura 269 1.28 kent sc = hdl; 270 1.33 isaki DPRINTF(1, ("%s: DMA transfer error.\n", device_xname(sc->sc_dev))); 271 1.1 minoura /* XXX */ 272 1.11 minoura vs_dmaintr(sc); 273 1.1 minoura 274 1.1 minoura return 1; 275 1.1 minoura } 276 1.1 minoura 277 1.1 minoura 278 1.1 minoura /* 279 1.1 minoura * audio MD layer interfaces 280 1.1 minoura */ 281 1.1 minoura 282 1.1 minoura static int 283 1.51 isaki vs_query_format(void *hdl, audio_format_query_t *afp) 284 1.1 minoura { 285 1.28 kent 286 1.51 isaki return audio_query_format(&vs_formats, 1, afp); 287 1.1 minoura } 288 1.1 minoura 289 1.2 minoura static int 290 1.1 minoura vs_round_sr(u_long rate) 291 1.1 minoura { 292 1.1 minoura int i; 293 1.2 minoura 294 1.2 minoura for (i = 0; i < NUM_RATE; i++) { 295 1.51 isaki if (rate == vs_l2r[i].rate) 296 1.51 isaki return i; 297 1.1 minoura } 298 1.51 isaki return -1; 299 1.1 minoura } 300 1.1 minoura 301 1.1 minoura static int 302 1.51 isaki vs_set_format(void *hdl, int setmode, 303 1.51 isaki const audio_params_t *play, const audio_params_t *rec, 304 1.51 isaki audio_filter_reg_t *pfil, audio_filter_reg_t *rfil) 305 1.1 minoura { 306 1.28 kent struct vs_softc *sc; 307 1.2 minoura int rate; 308 1.1 minoura 309 1.39 isaki sc = hdl; 310 1.39 isaki 311 1.51 isaki DPRINTF(1, ("%s: mode=%d %s/%dbit/%dch/%dHz: ", __func__, 312 1.51 isaki setmode, audio_encoding_name(play->encoding), 313 1.51 isaki play->precision, play->channels, play->sample_rate)); 314 1.1 minoura 315 1.41 isaki /* *play and *rec are identical because !AUDIO_PROP_INDEPENDENT */ 316 1.41 isaki 317 1.39 isaki rate = vs_round_sr(play->sample_rate); 318 1.51 isaki KASSERT(rate >= 0); 319 1.44 isaki sc->sc_current.rate = rate; 320 1.39 isaki 321 1.47 isaki if ((setmode & AUMODE_PLAY) != 0) { 322 1.51 isaki pfil->codec = msm6258_internal_to_adpcm; 323 1.51 isaki pfil->context = &sc->sc_codecvar; 324 1.47 isaki } 325 1.47 isaki if ((setmode & AUMODE_RECORD) != 0) { 326 1.51 isaki rfil->codec = msm6258_adpcm_to_internal; 327 1.51 isaki rfil->context = &sc->sc_codecvar; 328 1.47 isaki } 329 1.39 isaki 330 1.39 isaki DPRINTF(1, ("accepted\n")); 331 1.1 minoura return 0; 332 1.1 minoura } 333 1.1 minoura 334 1.51 isaki static int 335 1.51 isaki vs_commit_settings(void *hdl) 336 1.1 minoura { 337 1.51 isaki struct vs_softc *sc; 338 1.51 isaki int rate; 339 1.51 isaki 340 1.51 isaki sc = hdl; 341 1.51 isaki rate = sc->sc_current.rate; 342 1.28 kent 343 1.51 isaki DPRINTF(1, ("commit_settings: sample rate to %d, %d\n", 344 1.2 minoura rate, (int)vs_l2r[rate].rate)); 345 1.2 minoura bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC, 346 1.2 minoura (bus_space_read_1 (sc->sc_iot, sc->sc_ppi, 347 1.2 minoura PPI_PORTC) & 0xf0) 348 1.2 minoura | vs_l2r[rate].den); 349 1.2 minoura adpcm_chgclk(vs_l2r[rate].clk); 350 1.51 isaki 351 1.51 isaki return 0; 352 1.1 minoura } 353 1.1 minoura 354 1.1 minoura static inline void 355 1.51 isaki vs_set_panout(struct vs_softc *sc, u_long po) 356 1.1 minoura { 357 1.51 isaki 358 1.1 minoura bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC, 359 1.1 minoura (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC) 360 1.1 minoura & 0xfc) | po); 361 1.1 minoura } 362 1.1 minoura 363 1.1 minoura static int 364 1.43 isaki vs_start_output(void *hdl, void *block, int blksize, void (*intr)(void *), 365 1.43 isaki void *arg) 366 1.1 minoura { 367 1.28 kent struct vs_softc *sc; 368 1.1 minoura struct vs_dma *vd; 369 1.28 kent struct dmac_channel_stat *chan; 370 1.1 minoura 371 1.43 isaki DPRINTF(2, ("%s: block=%p blksize=%d\n", __func__, block, blksize)); 372 1.28 kent sc = hdl; 373 1.43 isaki 374 1.47 isaki /* Find DMA buffer. */ 375 1.47 isaki for (vd = sc->sc_dmas; vd != NULL; vd = vd->vd_next) { 376 1.47 isaki if (KVADDR(vd) <= block && block < KVADDR_END(vd) 377 1.47 isaki break; 378 1.47 isaki } 379 1.47 isaki if (vd == NULL) { 380 1.47 isaki printf("%s: start_output: bad addr %p\n", 381 1.47 isaki device_xname(sc->sc_dev), block); 382 1.47 isaki return EINVAL; 383 1.47 isaki } 384 1.2 minoura 385 1.43 isaki chan = sc->sc_dma_ch; 386 1.2 minoura 387 1.47 isaki if (vd != sc->sc_prev_vd) { 388 1.47 isaki sc->sc_current.xfer = dmac_prepare_xfer(chan, sc->sc_dmat, 389 1.47 isaki vd->vd_map, DMAC_OCR_DIR_MTD, 390 1.47 isaki (DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT), 391 1.47 isaki sc->sc_addr + MSM6258_DATA * 2 + 1); 392 1.47 isaki sc->sc_prev_vd = vd; 393 1.47 isaki } 394 1.47 isaki dmac_start_xfer_offset(chan->ch_softc, sc->sc_current.xfer, 395 1.47 isaki (int)block - (int)KVADDR(vd), blksize); 396 1.47 isaki 397 1.53 isaki if (sc->sc_pintr == NULL) { 398 1.53 isaki sc->sc_pintr = intr; 399 1.53 isaki sc->sc_parg = arg; 400 1.53 isaki 401 1.51 isaki vs_set_panout(sc, VS_PANOUT_LR); 402 1.49 isaki bus_space_write_1(sc->sc_iot, sc->sc_ioh, 403 1.49 isaki MSM6258_CMD, MSM6258_CMD_PLAY_START); 404 1.47 isaki } 405 1.1 minoura 406 1.1 minoura return 0; 407 1.1 minoura } 408 1.1 minoura 409 1.1 minoura static int 410 1.43 isaki vs_start_input(void *hdl, void *block, int blksize, void (*intr)(void *), 411 1.43 isaki void *arg) 412 1.1 minoura { 413 1.28 kent struct vs_softc *sc; 414 1.1 minoura struct vs_dma *vd; 415 1.28 kent struct dmac_channel_stat *chan; 416 1.1 minoura 417 1.43 isaki DPRINTF(2, ("%s: block=%p blksize=%d\n", __func__, block, blksize)); 418 1.28 kent sc = hdl; 419 1.43 isaki 420 1.47 isaki /* Find DMA buffer. */ 421 1.47 isaki for (vd = sc->sc_dmas; vd != NULL; vd = vd->vd_next) { 422 1.47 isaki if (KVADDR(vd) <= block && block < KVADDR_END(vd) 423 1.47 isaki break; 424 1.47 isaki } 425 1.47 isaki if (vd == NULL) { 426 1.47 isaki printf("%s: start_output: bad addr %p\n", 427 1.47 isaki device_xname(sc->sc_dev), block); 428 1.47 isaki return EINVAL; 429 1.47 isaki } 430 1.1 minoura 431 1.43 isaki chan = sc->sc_dma_ch; 432 1.2 minoura 433 1.47 isaki if (vd != sc->sc_prev_vd) { 434 1.47 isaki sc->sc_current.xfer = dmac_prepare_xfer(chan, sc->sc_dmat, 435 1.47 isaki vd->vd_map, DMAC_OCR_DIR_DTM, 436 1.47 isaki (DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT), 437 1.47 isaki sc->sc_addr + MSM6258_DATA * 2 + 1); 438 1.47 isaki sc->sc_prev_vd = vd; 439 1.47 isaki } 440 1.47 isaki dmac_start_xfer_offset(chan->ch_softc, sc->sc_current.xfer, 441 1.47 isaki (int)block - (int)KVADDR(vd), blksize); 442 1.47 isaki 443 1.53 isaki if (sc->sc_rintr == NULL) { 444 1.53 isaki sc->sc_rintr = intr; 445 1.53 isaki sc->sc_rarg = arg; 446 1.53 isaki 447 1.49 isaki bus_space_write_1(sc->sc_iot, sc->sc_ioh, 448 1.49 isaki MSM6258_CMD, MSM6258_CMD_REC_START); 449 1.47 isaki } 450 1.1 minoura 451 1.1 minoura return 0; 452 1.1 minoura } 453 1.1 minoura 454 1.1 minoura static int 455 1.1 minoura vs_halt_output(void *hdl) 456 1.1 minoura { 457 1.28 kent struct vs_softc *sc; 458 1.1 minoura 459 1.9 isaki DPRINTF(1, ("vs_halt_output\n")); 460 1.28 kent sc = hdl; 461 1.53 isaki 462 1.53 isaki /* stop ADPCM play */ 463 1.53 isaki dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer); 464 1.53 isaki bus_space_write_1(sc->sc_iot, sc->sc_ioh, 465 1.53 isaki MSM6258_CMD, MSM6258_CMD_STOP); 466 1.53 isaki sc->sc_pintr = NULL; 467 1.1 minoura 468 1.1 minoura return 0; 469 1.1 minoura } 470 1.1 minoura 471 1.1 minoura static int 472 1.1 minoura vs_halt_input(void *hdl) 473 1.1 minoura { 474 1.28 kent struct vs_softc *sc; 475 1.1 minoura 476 1.9 isaki DPRINTF(1, ("vs_halt_input\n")); 477 1.28 kent sc = hdl; 478 1.53 isaki 479 1.55 andvar /* stop ADPCM recording */ 480 1.53 isaki dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer); 481 1.53 isaki bus_space_write_1(sc->sc_iot, sc->sc_ioh, 482 1.53 isaki MSM6258_CMD, MSM6258_CMD_STOP); 483 1.53 isaki sc->sc_rintr = NULL; 484 1.1 minoura 485 1.1 minoura return 0; 486 1.1 minoura } 487 1.1 minoura 488 1.1 minoura static int 489 1.19 isaki vs_allocmem(struct vs_softc *sc, size_t size, size_t align, size_t boundary, 490 1.35 jmcneill struct vs_dma *vd) 491 1.1 minoura { 492 1.35 jmcneill int error; 493 1.1 minoura 494 1.1 minoura #ifdef DIAGNOSTIC 495 1.1 minoura if (size > DMAC_MAXSEGSZ) 496 1.1 minoura panic ("vs_allocmem: maximum size exceeded, %d", (int) size); 497 1.1 minoura #endif 498 1.1 minoura 499 1.1 minoura vd->vd_size = size; 500 1.28 kent 501 1.1 minoura error = bus_dmamem_alloc(vd->vd_dmat, vd->vd_size, align, boundary, 502 1.1 minoura vd->vd_segs, 503 1.1 minoura sizeof (vd->vd_segs) / sizeof (vd->vd_segs[0]), 504 1.35 jmcneill &vd->vd_nsegs, BUS_DMA_WAITOK); 505 1.1 minoura if (error) 506 1.1 minoura goto out; 507 1.1 minoura 508 1.1 minoura error = bus_dmamem_map(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs, 509 1.1 minoura vd->vd_size, &vd->vd_addr, 510 1.35 jmcneill BUS_DMA_WAITOK | BUS_DMA_COHERENT); 511 1.1 minoura if (error) 512 1.1 minoura goto free; 513 1.1 minoura 514 1.1 minoura error = bus_dmamap_create(vd->vd_dmat, vd->vd_size, 1, DMAC_MAXSEGSZ, 515 1.35 jmcneill 0, BUS_DMA_WAITOK, &vd->vd_map); 516 1.1 minoura if (error) 517 1.1 minoura goto unmap; 518 1.1 minoura 519 1.1 minoura error = bus_dmamap_load(vd->vd_dmat, vd->vd_map, vd->vd_addr, 520 1.35 jmcneill vd->vd_size, NULL, BUS_DMA_WAITOK); 521 1.1 minoura if (error) 522 1.1 minoura goto destroy; 523 1.1 minoura 524 1.28 kent return 0; 525 1.1 minoura 526 1.1 minoura destroy: 527 1.1 minoura bus_dmamap_destroy(vd->vd_dmat, vd->vd_map); 528 1.1 minoura unmap: 529 1.1 minoura bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size); 530 1.1 minoura free: 531 1.1 minoura bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs); 532 1.1 minoura out: 533 1.28 kent return error; 534 1.1 minoura } 535 1.1 minoura 536 1.1 minoura static void 537 1.19 isaki vs_freemem(struct vs_dma *vd) 538 1.1 minoura { 539 1.1 minoura 540 1.1 minoura bus_dmamap_unload(vd->vd_dmat, vd->vd_map); 541 1.1 minoura bus_dmamap_destroy(vd->vd_dmat, vd->vd_map); 542 1.1 minoura bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size); 543 1.1 minoura bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs); 544 1.1 minoura } 545 1.1 minoura 546 1.1 minoura static int 547 1.1 minoura vs_getdev(void *hdl, struct audio_device *retp) 548 1.1 minoura { 549 1.28 kent 550 1.9 isaki DPRINTF(1, ("vs_getdev\n")); 551 1.1 minoura *retp = vs_device; 552 1.1 minoura return 0; 553 1.1 minoura } 554 1.1 minoura 555 1.1 minoura static int 556 1.1 minoura vs_set_port(void *hdl, mixer_ctrl_t *cp) 557 1.1 minoura { 558 1.28 kent 559 1.9 isaki DPRINTF(1, ("vs_set_port\n")); 560 1.1 minoura return 0; 561 1.1 minoura } 562 1.1 minoura 563 1.1 minoura static int 564 1.1 minoura vs_get_port(void *hdl, mixer_ctrl_t *cp) 565 1.1 minoura { 566 1.28 kent 567 1.9 isaki DPRINTF(1, ("vs_get_port\n")); 568 1.1 minoura return 0; 569 1.1 minoura } 570 1.1 minoura 571 1.1 minoura static int 572 1.1 minoura vs_query_devinfo(void *hdl, mixer_devinfo_t *mi) 573 1.1 minoura { 574 1.28 kent 575 1.9 isaki DPRINTF(1, ("vs_query_devinfo\n")); 576 1.1 minoura switch (mi->index) { 577 1.1 minoura default: 578 1.1 minoura return EINVAL; 579 1.1 minoura } 580 1.1 minoura return 0; 581 1.1 minoura } 582 1.1 minoura 583 1.1 minoura static void * 584 1.35 jmcneill vs_allocm(void *hdl, int direction, size_t size) 585 1.1 minoura { 586 1.28 kent struct vs_softc *sc; 587 1.1 minoura struct vs_dma *vd; 588 1.1 minoura int error; 589 1.1 minoura 590 1.37 chs vd = kmem_alloc(sizeof(*vd), KM_SLEEP); 591 1.28 kent sc = hdl; 592 1.1 minoura vd->vd_dmat = sc->sc_dmat; 593 1.1 minoura 594 1.35 jmcneill error = vs_allocmem(sc, size, 32, 0, vd); 595 1.1 minoura if (error) { 596 1.35 jmcneill kmem_free(vd, sizeof(*vd)); 597 1.28 kent return NULL; 598 1.1 minoura } 599 1.1 minoura vd->vd_next = sc->sc_dmas; 600 1.1 minoura sc->sc_dmas = vd; 601 1.1 minoura 602 1.28 kent return KVADDR(vd); 603 1.1 minoura } 604 1.1 minoura 605 1.1 minoura static void 606 1.35 jmcneill vs_freem(void *hdl, void *addr, size_t size) 607 1.1 minoura { 608 1.28 kent struct vs_softc *sc; 609 1.1 minoura struct vs_dma *p, **pp; 610 1.1 minoura 611 1.28 kent sc = hdl; 612 1.1 minoura for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->vd_next) { 613 1.1 minoura if (KVADDR(p) == addr) { 614 1.1 minoura vs_freemem(p); 615 1.1 minoura *pp = p->vd_next; 616 1.35 jmcneill kmem_free(p, sizeof(*p)); 617 1.1 minoura return; 618 1.1 minoura } 619 1.1 minoura } 620 1.1 minoura } 621 1.1 minoura 622 1.1 minoura static size_t 623 1.1 minoura vs_round_buffersize(void *hdl, int direction, size_t bufsize) 624 1.1 minoura { 625 1.28 kent 626 1.1 minoura if (bufsize > DMAC_MAXSEGSZ) 627 1.1 minoura bufsize = DMAC_MAXSEGSZ; 628 1.1 minoura return bufsize; 629 1.1 minoura } 630 1.1 minoura 631 1.1 minoura static int 632 1.1 minoura vs_get_props(void *hdl) 633 1.1 minoura { 634 1.28 kent 635 1.9 isaki DPRINTF(1, ("vs_get_props\n")); 636 1.52 isaki return AUDIO_PROP_PLAYBACK | AUDIO_PROP_CAPTURE; 637 1.1 minoura } 638 1.35 jmcneill 639 1.35 jmcneill static void 640 1.35 jmcneill vs_get_locks(void *hdl, kmutex_t **intr, kmutex_t **thread) 641 1.35 jmcneill { 642 1.35 jmcneill struct vs_softc *sc; 643 1.35 jmcneill 644 1.35 jmcneill DPRINTF(1, ("vs_get_locks\n")); 645 1.35 jmcneill sc = hdl; 646 1.35 jmcneill *intr = &sc->sc_intr_lock; 647 1.35 jmcneill *thread = &sc->sc_lock; 648 1.35 jmcneill } 649 1.35 jmcneill 650 1.1 minoura #endif /* NAUDIO > 0 && NVS > 0*/ 651