Lines Matching +full:pcm +full:- +full:interface +full:- +full:rate
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2003-2007 Yuriy Tsibizov <yuriy.tsibizov@gfk.ru>
52 #include <dev/sound/pcm/sound.h>
53 #include <dev/sound/pcm/ac97.h>
96 #define GPR(i) (sc->gpr_base+(i))
97 #define INP(i) (sc->input_base+(i))
98 #define OUTP(i) (sc->output_base+(i))
100 #define FX2(i) (sc->efxc_base+(i))
101 #define DSP_CONST(i) (sc->dsp_zero+(i))
160 /* Live! 5.1 Digital, non-standard 5.1 (center & sub) outputs */
314 device_t pcm[RT_COUNT]; member
430 if (mtx_owned(&sc->rw)) { \
432 __LINE__ , device_get_nameunit(sc->dev)); \
433 printf("rw lock owned: %d\n", mtx_owned(&sc->rw)); \
435 ((&sc->rw)->mtx_lock & ~MTX_FLAGMASK), \
437 printf("rw lock: recursed %d\n", mtx_recursed(&sc->rw));\
438 db_show_mtx(&sc->rw); \
448 mtx_lock(&(sc->rw)); \
452 mtx_unlock(&(sc->rw)); \
502 /* 0x0051..0x0051 5.1 CA0100-IAF cards */
504 /* ES is CA0100-IDF chip that don't work in digital mode */
506 /* 0x0053..0x005C 5.1 CA0101-NAF cards */
510 /* 0x1002..0x1009 5.1 CA0102-IAT cards */
515 /* 0x2001..0x2003 7.1 CA0102-ICT cards */
523 /* (range unknown) 7.1 CA0102-xxx Audigy 4 cards */
529 /* We don't support CA0103-DAT (Audigy LS) cards */
530 /* There is NO CA0104-xxx cards */
531 /* There is NO CA0105-xxx cards */
532 /* We don't support CA0106-DAT (SB Live! 24 bit) cards */
533 /* There is NO CA0107-xxx cards */
535 /* 0x1000..0x1001 7.1 CA0108-IAT cards */
548 {0x1102, 0x0002, 0x1102, 0x4001, "EMUAPS", "E-mu APS", 0},
549 {0x1102, 0x0002, 0x1102, 0x4002, "EMUAPS", "E-mu APS", 0},
550 {0x1102, 0x0004, 0x1102, 0x4001, "EMU???", "E-mu 1212m [4001]", 0},
551 /* Similar-named ("Live!" or "Audigy") cards on different chipsets */
604 * Base hardware interface are 32 (Audigy) or 64 (Audigy2) registers.
614 return (bus_space_read_1(sc->st, sc->sh, regno)); in emu_rd_nolock()
616 return (bus_space_read_2(sc->st, sc->sh, regno)); in emu_rd_nolock()
618 return (bus_space_read_4(sc->st, sc->sh, regno)); in emu_rd_nolock()
630 bus_space_write_1(sc->st, sc->sh, regno, data); in emu_wr_nolock()
633 bus_space_write_2(sc->st, sc->sh, regno, data); in emu_wr_nolock()
636 bus_space_write_4(sc->st, sc->sh, regno, data); in emu_wr_nolock()
641 * EMU_PTR / EMU_DATA interface. Access to EMU10Kx is made
642 * via (channel, register) pair. Some registers are channel-specific,
650 ptr = ((reg << 16) & sc->address_mask) | (chn & EMU_PTR_CHNO_MASK); in emu_rdptr()
665 mask = ((1 << size) - 1) << offset; in emu_rdptr()
677 ptr = ((reg << 16) & sc->address_mask) | (chn & EMU_PTR_CHNO_MASK); in emu_wrptr()
683 * give you side effect - it will read previous data from register in emu_wrptr()
689 mask = ((1 << size) - 1) << offset; in emu_wrptr()
698 * EMU_A2_PTR / EMU_DATA2 interface. Access to P16v is made
699 * via (channel, register) pair. Some registers are channel-specific,
700 * some not. This interface is supported by CA0102 and CA0108 chips only.
727 * XXX CardBus interface. Not tested on any real hardware.
747 * Assume that it is never used to access EMU_PTR-based registers and can run unlocked.
779 if (sc->is_emu10k2 || sc->is_ca0102) { in emu_enable_ir()
788 device_printf(sc->dev, "Audigy IR MIDI events enabled.\n"); in emu_enable_ir()
789 sc->enable_ir = 1; in emu_enable_ir()
791 if (sc->is_emu10k1) { in emu_enable_ir()
798 device_printf(sc->dev, "SB Live! IR MIDI events enabled.\n"); in emu_enable_ir()
799 sc->enable_ir = 1; in emu_enable_ir()
804 * emu_timer_ - HW timer management
811 timer = -1; in emu_timer_create()
813 mtx_lock(&sc->lock); in emu_timer_create()
815 if (sc->timer[i] == 0) { in emu_timer_create()
816 sc->timer[i] = -1; /* disable it */ in emu_timer_create()
818 mtx_unlock(&sc->lock); in emu_timer_create()
821 mtx_unlock(&sc->lock); in emu_timer_create()
823 return (-1); in emu_timer_create()
832 return (-1); in emu_timer_set()
835 RANGE(timer, 0, EMU_MAX_IRQ_CONSUMERS-1); in emu_timer_set()
837 mtx_lock(&sc->lock); in emu_timer_set()
838 sc->timer[timer] = delay; in emu_timer_set()
840 if (sc->timerinterval > sc->timer[i]) in emu_timer_set()
841 sc->timerinterval = sc->timer[i]; in emu_timer_set()
844 emu_wr(sc, EMU_TIMER, sc->timerinterval & 0x03ff, 2); in emu_timer_set()
845 mtx_unlock(&sc->lock); in emu_timer_set()
858 return (-1); in emu_timer_enable()
860 RANGE(timer, 0, EMU_MAX_IRQ_CONSUMERS-1); in emu_timer_enable()
862 mtx_lock(&sc->lock); in emu_timer_enable()
864 if ((go == 1) && (sc->timer[timer] < 0)) in emu_timer_enable()
865 sc->timer[timer] = -sc->timer[timer]; in emu_timer_enable()
866 if ((go == 0) && (sc->timer[timer] > 0)) in emu_timer_enable()
867 sc->timer[timer] = -sc->timer[timer]; in emu_timer_enable()
871 if (sc->timerinterval > sc->timer[i]) in emu_timer_enable()
872 sc->timerinterval = sc->timer[i]; in emu_timer_enable()
873 if (sc->timer[i] > 0) in emu_timer_enable()
877 emu_wr(sc, EMU_TIMER, sc->timerinterval & 0x03ff, 2); in emu_timer_enable()
888 mtx_unlock(&sc->lock); in emu_timer_enable()
896 return (-1); in emu_timer_clear()
898 RANGE(timer, 0, EMU_MAX_IRQ_CONSUMERS-1); in emu_timer_clear()
902 mtx_lock(&sc->lock); in emu_timer_clear()
903 if (sc->timer[timer] != 0) in emu_timer_clear()
904 sc->timer[timer] = 0; in emu_timer_clear()
905 mtx_unlock(&sc->lock); in emu_timer_clear()
911 * emu_intr_ - HW interrupt handler management
919 mtx_lock(&sc->lock); in emu_intr_register()
921 if (sc->ihandler[i].inte_mask == 0) { in emu_intr_register()
922 sc->ihandler[i].inte_mask = inte_mask; in emu_intr_register()
923 sc->ihandler[i].intr_mask = intr_mask; in emu_intr_register()
924 sc->ihandler[i].softc = isc; in emu_intr_register()
925 sc->ihandler[i].irq_func = func; in emu_intr_register()
929 mtx_unlock(&sc->lock); in emu_intr_register()
930 if (sc->dbg_level > 1) in emu_intr_register()
931 device_printf(sc->dev, "ihandle %d registered\n", i); in emu_intr_register()
935 mtx_unlock(&sc->lock); in emu_intr_register()
936 if (sc->dbg_level > 1) in emu_intr_register()
937 device_printf(sc->dev, "ihandle not registered\n"); in emu_intr_register()
939 return (-1); in emu_intr_register()
948 mtx_lock(&sc->lock); in emu_intr_unregister()
950 if (sc->ihandler[hnumber].inte_mask == 0) { in emu_intr_unregister()
951 mtx_unlock(&sc->lock); in emu_intr_unregister()
952 return (-1); in emu_intr_unregister()
956 x &= ~sc->ihandler[hnumber].inte_mask; in emu_intr_unregister()
958 sc->ihandler[hnumber].inte_mask = 0; in emu_intr_unregister()
959 sc->ihandler[hnumber].intr_mask = 0; in emu_intr_unregister()
960 sc->ihandler[hnumber].softc = NULL; in emu_intr_unregister()
961 sc->ihandler[hnumber].irq_func = NULL; in emu_intr_unregister()
965 if (sc->ihandler[i].inte_mask != 0) in emu_intr_unregister()
966 x |= sc->ihandler[i].inte_mask; in emu_intr_unregister()
970 mtx_unlock(&sc->lock); in emu_intr_unregister()
988 if ((((sc->ihandler[i].intr_mask) & stat) != 0) && in emu_intr()
989 (((void *)sc->ihandler[i].irq_func) != NULL)) { in emu_intr()
990 ack |= sc->ihandler[i].irq_func(sc->ihandler[i].softc, in emu_intr()
991 (sc->ihandler[i].intr_mask) & stat); in emu_intr()
994 if (sc->dbg_level > 1) in emu_intr()
996 device_printf(sc->dev, "Unhandled interrupt: %08x\n", stat & (~ack)); in emu_intr()
999 if ((sc->is_ca0102) || (sc->is_ca0108)) in emu_intr()
1006 if (sc->dbg_level > 1) in emu_intr()
1007 device_printf(sc->dev, "EMU_IPR2: %08x\n", stat); in emu_intr()
1010 * after completion of P16V interface. */ in emu_intr()
1013 if (sc->is_ca0102) in emu_intr()
1020 if (sc->dbg_level > 1) in emu_intr()
1021 device_printf(sc->dev, "EMU_IPR3: %08x\n", stat); in emu_intr()
1024 * after completion of S/PDIF interface */ in emu_intr()
1029 * Get data from private emu10kx structure for PCM buffer allocation.
1030 * Used by PCM code only.
1035 return (sc->mem.dmat); in emu_gettag()
1043 *phys = error ? 0 : (bus_addr_t) segs->ds_addr; in emu_setmap()
1047 (unsigned long)segs->ds_addr, (unsigned long)segs->ds_len, in emu_setmap()
1060 if ((error = bus_dmamem_alloc(mem->dmat, &dmabuf, BUS_DMA_NOWAIT, map))) { in emu_malloc()
1061 if (mem->card->dbg_level > 2) in emu_malloc()
1062 device_printf(mem->card->dev, "emu_malloc: failed to alloc DMA map: %d\n", error); in emu_malloc()
1065 if ((error = bus_dmamap_load(mem->dmat, *map, dmabuf, sz, emu_setmap, addr, 0)) || !*addr) { in emu_malloc()
1066 if (mem->card->dbg_level > 2) in emu_malloc()
1067 device_printf(mem->card->dev, "emu_malloc: failed to load DMA memory: %d\n", error); in emu_malloc()
1068 bus_dmamem_free(mem->dmat, dmabuf, *map); in emu_malloc()
1077 bus_dmamap_unload(mem->dmat, map); in emu_free()
1078 bus_dmamem_free(mem->dmat, dmabuf, map); in emu_free()
1092 if (mem->card->dbg_level > 2) in emu_memalloc()
1093 device_printf(mem->card->dev, "emu_memalloc: memory request tool large\n"); in emu_memalloc()
1102 if (mem->bmap[idx >> 3] & (1 << (idx & 7))) in emu_memalloc()
1108 if (mem->card->dbg_level > 2) in emu_memalloc()
1109 device_printf(mem->card->dev, "emu_memalloc: no free space in bitmap\n"); in emu_memalloc()
1114 if (mem->card->dbg_level > 2) in emu_memalloc()
1115 device_printf(mem->card->dev, "emu_memalloc: buffer allocation failed\n"); in emu_memalloc()
1119 membuf = emu_malloc(mem, sz, &blk->buf_addr, &blk->buf_map); in emu_memalloc()
1120 *addr = blk->buf_addr; in emu_memalloc()
1122 if (mem->card->dbg_level > 2) in emu_memalloc()
1123 device_printf(mem->card->dev, "emu_memalloc: can't setup HW memory\n"); in emu_memalloc()
1127 blk->buf = membuf; in emu_memalloc()
1128 blk->pte_start = start; in emu_memalloc()
1129 blk->pte_size = blksz; in emu_memalloc()
1130 strncpy(blk->owner, owner, 15); in emu_memalloc()
1131 blk->owner[15] = '\0'; in emu_memalloc()
1134 mem->bmap[idx >> 3] |= 1 << (idx & 7); in emu_memalloc()
1135 tmp = (uint32_t) (blk->buf_addr + ofs); in emu_memalloc()
1136 mem->ptb_pages[idx] = (tmp << 1) | idx; in emu_memalloc()
1139 SLIST_INSERT_HEAD(&mem->blocks, blk, link); in emu_memalloc()
1150 SLIST_FOREACH(i, &mem->blocks, link) { in emu_memfree()
1151 if (i->buf == membuf) in emu_memfree()
1156 SLIST_REMOVE(&mem->blocks, blk, emu_memblk, link); in emu_memfree()
1157 emu_free(mem, membuf, blk->buf_map); in emu_memfree()
1158 tmp = (uint32_t) (mem->silent_page_addr) << 1; in emu_memfree()
1159 for (idx = blk->pte_start; idx < blk->pte_start + blk->pte_size; idx++) { in emu_memfree()
1160 mem->bmap[idx >> 3] &= ~(1 << (idx & 7)); in emu_memfree()
1161 mem->ptb_pages[idx] = tmp | idx; in emu_memfree()
1173 SLIST_FOREACH(i, &mem->blocks, link) { in emu_memstart()
1174 if (i->buf == membuf) in emu_memstart()
1178 return (-1); in emu_memstart()
1179 return (blk->pte_start); in emu_memstart()
1183 emu_rate_to_pitch(uint32_t rate) in emu_rate_to_pitch() argument
1223 if (rate == 0) in emu_rate_to_pitch()
1225 rate *= 11185; /* Scale 48000 to 0x20002380 */ in emu_rate_to_pitch()
1226 for (i = 31; i > 0; i--) { in emu_rate_to_pitch()
1227 if (rate & 0x80000000) { /* Detect leading "1" */ in emu_rate_to_pitch()
1228 return (((uint32_t) (i - 15) << 20) + in emu_rate_to_pitch()
1229 logMagTable[0x7f & (rate >> 24)] + in emu_rate_to_pitch()
1230 (0x7f & (rate >> 17)) * in emu_rate_to_pitch()
1231 logSlopeTable[0x7f & (rate >> 24)]); in emu_rate_to_pitch()
1233 rate <<= 1; in emu_rate_to_pitch()
1240 emu_rate_to_linearpitch(uint32_t rate) in emu_rate_to_linearpitch() argument
1242 rate = (rate << 8) / 375; in emu_rate_to_linearpitch()
1243 return ((rate >> 1) + (rate & 1)); in emu_rate_to_linearpitch()
1253 mtx_lock(&sc->lock); in emu_valloc()
1254 for (i = 0; i < NUM_G && sc->voice[i].busy; i++); in emu_valloc()
1256 v = &sc->voice[i]; in emu_valloc()
1257 v->busy = 1; in emu_valloc()
1259 mtx_unlock(&sc->lock); in emu_valloc()
1267 mtx_lock(&sc->lock); in emu_vfree()
1269 if (v == &sc->voice[i] && sc->voice[i].busy) { in emu_vfree()
1270 v->busy = 0; in emu_vfree()
1273 * See -pcm.c emupchan_init for other side of in emu_vfree()
1276 if (v->slave != NULL) in emu_vfree()
1277 emu_memfree(&sc->mem, v->vbuf); in emu_vfree()
1280 mtx_unlock(&sc->lock); in emu_vfree()
1290 vbuf = emu_memalloc(&sc->mem, sz, &tmp_addr, "vinit"); in emu_vinit()
1292 if(sc->dbg_level > 2) in emu_vinit()
1293 device_printf(sc->dev, "emu_memalloc returns NULL in enu_vinit\n"); in emu_vinit()
1298 m->start = emu_memstart(&sc->mem, vbuf) * EMUPAGESIZE; in emu_vinit()
1299 if (m->start < 0) { in emu_vinit()
1300 if(sc->dbg_level > 2) in emu_vinit()
1301 device_printf(sc->dev, "emu_memstart returns (-1) in enu_vinit\n"); in emu_vinit()
1302 emu_memfree(&sc->mem, vbuf); in emu_vinit()
1305 m->end = m->start + sz; in emu_vinit()
1306 m->speed = 0; in emu_vinit()
1307 m->b16 = 0; in emu_vinit()
1308 m->stereo = 0; in emu_vinit()
1309 m->running = 0; in emu_vinit()
1310 m->ismaster = 1; in emu_vinit()
1311 m->vol = 0xff; in emu_vinit()
1312 m->buf = tmp_addr; in emu_vinit()
1313 m->vbuf = vbuf; in emu_vinit()
1314 m->slave = s; in emu_vinit()
1316 s->start = m->start; in emu_vinit()
1317 s->end = m->end; in emu_vinit()
1318 s->speed = 0; in emu_vinit()
1319 s->b16 = 0; in emu_vinit()
1320 s->stereo = 0; in emu_vinit()
1321 s->running = 0; in emu_vinit()
1322 s->ismaster = 0; in emu_vinit()
1323 s->vol = m->vol; in emu_vinit()
1324 s->buf = m->buf; in emu_vinit()
1325 s->vbuf = NULL; in emu_vinit()
1326 s->slave = NULL; in emu_vinit()
1335 v->b16 = (fmt & AFMT_16BIT) ? 1 : 0; in emu_vsetup()
1336 v->stereo = (AFMT_CHANNEL(fmt) > 1) ? 1 : 0; in emu_vsetup()
1337 if (v->slave != NULL) { in emu_vsetup()
1338 v->slave->b16 = v->b16; in emu_vsetup()
1339 v->slave->stereo = v->stereo; in emu_vsetup()
1343 v->speed = spd; in emu_vsetup()
1344 if (v->slave != NULL) in emu_vsetup()
1345 v->slave->speed = v->speed; in emu_vsetup()
1355 v->routing[i] = rt->routing_left[i]; in emu_vroute()
1356 v->amounts[i] = rt->amounts_left[i]; in emu_vroute()
1358 if ((v->stereo) && (v->ismaster == 0)) in emu_vroute()
1360 v->routing[i] = rt->routing_right[i]; in emu_vroute()
1361 v->amounts[i] = rt->amounts_right[i]; in emu_vroute()
1364 if ((v->stereo) && (v->slave != NULL)) in emu_vroute()
1365 emu_vroute(sc, rt, v->slave); in emu_vroute()
1374 s = (v->stereo ? 1 : 0) + (v->b16 ? 1 : 0); in emu_vwrite()
1376 v->sa = v->start >> s; in emu_vwrite()
1377 v->ea = v->end >> s; in emu_vwrite()
1379 if (v->stereo) { in emu_vwrite()
1380 emu_wrptr(sc, v->vnum, EMU_CHAN_CPF, EMU_CHAN_CPF_STEREO_MASK); in emu_vwrite()
1382 emu_wrptr(sc, v->vnum, EMU_CHAN_CPF, 0); in emu_vwrite()
1384 val = v->stereo ? 28 : 30; in emu_vwrite()
1385 val *= v->b16 ? 1 : 2; in emu_vwrite()
1386 start = v->sa + val; in emu_vwrite()
1388 if (sc->is_emu10k1) { in emu_vwrite()
1389 emu_wrptr(sc, v->vnum, EMU_CHAN_FXRT, ((v->routing[3] << 12) | in emu_vwrite()
1390 (v->routing[2] << 8) | in emu_vwrite()
1391 (v->routing[1] << 4) | in emu_vwrite()
1392 (v->routing[0] << 0)) << 16); in emu_vwrite()
1394 emu_wrptr(sc, v->vnum, EMU_A_CHAN_FXRT1, (v->routing[3] << 24) | in emu_vwrite()
1395 (v->routing[2] << 16) | in emu_vwrite()
1396 (v->routing[1] << 8) | in emu_vwrite()
1397 (v->routing[0] << 0)); in emu_vwrite()
1398 emu_wrptr(sc, v->vnum, EMU_A_CHAN_FXRT2, (v->routing[7] << 24) | in emu_vwrite()
1399 (v->routing[6] << 16) | in emu_vwrite()
1400 (v->routing[5] << 8) | in emu_vwrite()
1401 (v->routing[4] << 0)); in emu_vwrite()
1402 emu_wrptr(sc, v->vnum, EMU_A_CHAN_SENDAMOUNTS, (v->amounts[7] << 24) | in emu_vwrite()
1403 (v->amounts[6] << 26) | in emu_vwrite()
1404 (v->amounts[5] << 8) | in emu_vwrite()
1405 (v->amounts[4] << 0)); in emu_vwrite()
1407 emu_wrptr(sc, v->vnum, EMU_CHAN_PTRX, (v->amounts[0] << 8) | (v->amounts[1] << 0)); in emu_vwrite()
1408 emu_wrptr(sc, v->vnum, EMU_CHAN_DSL, v->ea | (v->amounts[3] << 24)); in emu_vwrite()
1409 emu_wrptr(sc, v->vnum, EMU_CHAN_PSST, v->sa | (v->amounts[2] << 24)); in emu_vwrite()
1411 emu_wrptr(sc, v->vnum, EMU_CHAN_CCCA, start | (v->b16 ? 0 : EMU_CHAN_CCCA_8BITSELECT)); in emu_vwrite()
1412 emu_wrptr(sc, v->vnum, EMU_CHAN_Z1, 0); in emu_vwrite()
1413 emu_wrptr(sc, v->vnum, EMU_CHAN_Z2, 0); in emu_vwrite()
1415 silent_page = ((uint32_t) (sc->mem.silent_page_addr) << 1) | EMU_CHAN_MAP_PTI_MASK; in emu_vwrite()
1416 emu_wrptr(sc, v->vnum, EMU_CHAN_MAPA, silent_page); in emu_vwrite()
1417 emu_wrptr(sc, v->vnum, EMU_CHAN_MAPB, silent_page); in emu_vwrite()
1419 emu_wrptr(sc, v->vnum, EMU_CHAN_CVCF, EMU_CHAN_CVCF_CURRFILTER_MASK); in emu_vwrite()
1420 emu_wrptr(sc, v->vnum, EMU_CHAN_VTFT, EMU_CHAN_VTFT_FILTERTARGET_MASK); in emu_vwrite()
1421 emu_wrptr(sc, v->vnum, EMU_CHAN_ATKHLDM, 0); in emu_vwrite()
1422 emu_wrptr(sc, v->vnum, EMU_CHAN_DCYSUSM, EMU_CHAN_DCYSUSM_DECAYTIME_MASK); in emu_vwrite()
1423 emu_wrptr(sc, v->vnum, EMU_CHAN_LFOVAL1, 0x8000); in emu_vwrite()
1424 emu_wrptr(sc, v->vnum, EMU_CHAN_LFOVAL2, 0x8000); in emu_vwrite()
1425 emu_wrptr(sc, v->vnum, EMU_CHAN_FMMOD, 0); in emu_vwrite()
1426 emu_wrptr(sc, v->vnum, EMU_CHAN_TREMFRQ, 0); in emu_vwrite()
1427 emu_wrptr(sc, v->vnum, EMU_CHAN_FM2FRQ2, 0); in emu_vwrite()
1428 emu_wrptr(sc, v->vnum, EMU_CHAN_ENVVAL, 0x8000); in emu_vwrite()
1430 …emu_wrptr(sc, v->vnum, EMU_CHAN_ATKHLDV, EMU_CHAN_ATKHLDV_HOLDTIME_MASK | EMU_CHAN_ATKHLDV_ATTACKT… in emu_vwrite()
1431 emu_wrptr(sc, v->vnum, EMU_CHAN_ENVVOL, 0x8000); in emu_vwrite()
1433 emu_wrptr(sc, v->vnum, EMU_CHAN_PEFE_FILTERAMOUNT, 0x7f); in emu_vwrite()
1434 emu_wrptr(sc, v->vnum, EMU_CHAN_PEFE_PITCHAMOUNT, 0); in emu_vwrite()
1435 if ((v->stereo) && (v->slave != NULL)) in emu_vwrite()
1436 emu_vwrite(sc, v->slave); in emu_vwrite()
1460 cs = v->stereo ? 4 : 2; in emu_vtrigger()
1461 ccis = v->stereo ? 28 : 30; in emu_vtrigger()
1462 ccis *= v->b16 ? 1 : 2; in emu_vtrigger()
1463 sample = v->b16 ? 0x00000000 : 0x80808080; in emu_vtrigger()
1465 emu_wrptr(sc, v->vnum, EMU_CHAN_CD0 + i, sample); in emu_vtrigger()
1466 emu_wrptr(sc, v->vnum, EMU_CHAN_CCR_CACHEINVALIDSIZE, 0); in emu_vtrigger()
1467 emu_wrptr(sc, v->vnum, EMU_CHAN_CCR_READADDRESS, cra); in emu_vtrigger()
1468 emu_wrptr(sc, v->vnum, EMU_CHAN_CCR_CACHEINVALIDSIZE, ccis); in emu_vtrigger()
1470 emu_wrptr(sc, v->vnum, EMU_CHAN_IFATN, 0xff00); in emu_vtrigger()
1471 emu_wrptr(sc, v->vnum, EMU_CHAN_VTFT, 0xffffffff); in emu_vtrigger()
1472 emu_wrptr(sc, v->vnum, EMU_CHAN_CVCF, 0xffffffff); in emu_vtrigger()
1473 emu_wrptr(sc, v->vnum, EMU_CHAN_DCYSUSV, 0x00007f7f); in emu_vtrigger()
1474 emu_vstop(sc, v->vnum, 0); in emu_vtrigger()
1476 pitch_target = emu_rate_to_linearpitch(v->speed); in emu_vtrigger()
1477 initial_pitch = emu_rate_to_pitch(v->speed) >> 8; in emu_vtrigger()
1478 emu_wrptr(sc, v->vnum, EMU_CHAN_PTRX_PITCHTARGET, pitch_target); in emu_vtrigger()
1479 emu_wrptr(sc, v->vnum, EMU_CHAN_CPF_PITCH, pitch_target); in emu_vtrigger()
1480 emu_wrptr(sc, v->vnum, EMU_CHAN_IP, initial_pitch); in emu_vtrigger()
1482 emu_wrptr(sc, v->vnum, EMU_CHAN_PTRX_PITCHTARGET, 0); in emu_vtrigger()
1483 emu_wrptr(sc, v->vnum, EMU_CHAN_CPF_PITCH, 0); in emu_vtrigger()
1484 emu_wrptr(sc, v->vnum, EMU_CHAN_IFATN, 0xffff); in emu_vtrigger()
1485 emu_wrptr(sc, v->vnum, EMU_CHAN_VTFT, 0x0000ffff); in emu_vtrigger()
1486 emu_wrptr(sc, v->vnum, EMU_CHAN_CVCF, 0x0000ffff); in emu_vtrigger()
1487 emu_wrptr(sc, v->vnum, EMU_CHAN_IP, 0); in emu_vtrigger()
1488 emu_vstop(sc, v->vnum, 1); in emu_vtrigger()
1490 if ((v->stereo) && (v->slave != NULL)) in emu_vtrigger()
1491 emu_vtrigger(sc, v->slave, go); in emu_vtrigger()
1499 s = (v->b16 ? 1 : 0) + (v->stereo ? 1 : 0); in emu_vpos()
1500 ptr = (emu_rdptr(sc, v->vnum, EMU_CHAN_CCCA_CURRADDR) - (v->start >> s)) << s; in emu_vpos()
1508 emu_wrptr(sc, 0, sc->code_base + pc, data); in emu_wrefx()
1514 if ((*pc) + 1 > sc->code_size) { in emu_addefxop()
1515 device_printf(sc->dev, "DSP CODE OVERRUN: attept to write past code_size (pc=%d)\n", (*pc)); in emu_addefxop()
1518 emu_wrefx(sc, (*pc) * 2, (x << sc->high_operand_shift) | y); in emu_addefxop()
1519 emu_wrefx(sc, (*pc) * 2 + 1, (op << sc->opcode_shift) | (z << sc->high_operand_shift) | w); in emu_addefxop()
1537 if (err || req->newptr == NULL) in sysctl_emu_mixer_control()
1552 volgpr = emu_rm_gpr_alloc(sc->rm, 1); in emu_addefxmixer()
1556 * by AC97 emulation code or PCM mixer. in emu_addefxmixer()
1561 * see freebsd-current mailing list, emu10kx driver in emu_addefxmixer()
1562 * discussion around 2006-05-24. in emu_addefxmixer()
1565 SYSCTL_ADD_PROC(sc->ctx, in emu_addefxmixer()
1566 SYSCTL_CHILDREN(sc->root), OID_AUTO, sysctl_name, in emu_addefxmixer()
1583 new_val = (sc->mode == MODE_DIGITAL) ? 1 : 0; in sysctl_emu_digitalswitch_control()
1586 if (err || req->newptr == NULL) in sysctl_emu_digitalswitch_control()
1606 SYSCTL_ADD_PROC(sc->ctx, SYSCTL_CHILDREN(sc->root), OID_AUTO, in emu_digitalswitch()
1619 sc->cache_gpr[CACHE_IDX] = emu_rm_gpr_alloc(sc->rm, 1); \
1621 GPR(sc->cache_gpr[CACHE_IDX]), \
1630 sc->mixer_gpr[IN_GPR_IDX] = emu_addefxmixer(sc, TITLE, IN_GPR_IDX, DEF); \
1631 sc->mixer_volcache[IN_GPR_IDX] = DEF; \
1633 GPR(sc->cache_gpr[OUT_CACHE_IDX]), \
1634 GPR(sc->cache_gpr[OUT_CACHE_IDX]), \
1636 GPR(sc->mixer_gpr[IN_GPR_IDX]), \
1642 sc->mixer_gpr[OUT_GPR_IDX] = emu_addefxmixer(sc, TITLE, OUT_GPR_IDX, DEF); \
1643 sc->mixer_volcache[OUT_GPR_IDX] = DEF; \
1647 GPR(sc->cache_gpr[OUT_CACHE_IDX]), \
1648 GPR(sc->mixer_gpr[OUT_GPR_IDX]), \
1657 GPR(sc->cache_gpr[OUT_CACHE_IDX]), \
1658 GPR(sc->mixer_gpr[OUT_GPR_IDX]), \
1666 GPR(sc->mute_gpr[FLAG_GPR]), \
1694 if (sc->is_emu10k1) { in emu_initefx()
1702 for (i = 0; i < sc->code_size; i++) { in emu_initefx()
1703 if (sc->is_emu10k1) { in emu_initefx()
1712 sc->mute_gpr[i] = emu_rm_gpr_alloc(sc->rm, 1); in emu_initefx()
1713 emumix_set_gpr(sc, sc->mute_gpr[i], 1); in emu_initefx()
1732 if (sc->is_emu10k1) { in emu_initefx()
1758 if (sc->dbg_level > 0) { in emu_initefx()
1777 /* in5, on-card S/PDIF */ in emu_initefx()
1789 if (sc->dbg_level > 0) { in emu_initefx()
1811 if (!(sc->mch_disabled)) { in emu_initefx()
1814 * emu_dspmixer_set() in -pcm.c in emu_initefx()
1825 if (sc->has_51) { in emu_initefx()
1854 if (sc->has_51) { in emu_initefx()
1858 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1859 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1861 GPR(sc->cache_gpr[C_FRONT_L]), in emu_initefx()
1864 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1865 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1867 GPR(sc->cache_gpr[C_FRONT_R]), in emu_initefx()
1879 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1880 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1882 GPR(sc->cache_gpr[C_FRONT_L]), in emu_initefx()
1885 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1886 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
1888 GPR(sc->cache_gpr[C_FRONT_R]), in emu_initefx()
1901 if (sc->mch_rec) { in emu_initefx()
1915 * 0x00..0x1E - outputs in emu_initefx()
1916 * 0x20..0x3E - FX, inputs and sync stream in emu_initefx()
1920 for(i = (sc->has_51 ? 2 : 0); i < 2; i++) in emu_initefx()
1923 /* PCM Playback monitoring, offset 0x24..0x2A */ in emu_initefx()
1932 sc->dummy_gpr = emu_rm_gpr_alloc(sc->rm, 1); in emu_initefx()
1933 emumix_set_gpr(sc, sc->dummy_gpr, 0xc0de0000); in emu_initefx()
1935 EFX_COPY(FX2(15), GPR(sc->dummy_gpr)); in emu_initefx()
1946 * emu_ac97_[read|write]_emulation in -pcm.c in emu_initefx()
1972 if (sc->dbg_level > 0) { in emu_initefx()
1986 /* in5, on-card S/PDIF */ in emu_initefx()
1998 if (sc->dbg_level > 0) { in emu_initefx()
2020 if (!(sc->mch_disabled)) { in emu_initefx()
2023 * emu_dspmixer_set() in -pcm.c in emu_initefx()
2059 if (sc->has_71) { in emu_initefx()
2078 if (sc->has_51) { in emu_initefx()
2082 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
2083 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
2085 GPR(sc->cache_gpr[C_FRONT_L]), in emu_initefx()
2088 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
2089 GPR(sc->cache_gpr[C_CENTER]), in emu_initefx()
2091 GPR(sc->cache_gpr[C_FRONT_R]), in emu_initefx()
2103 GPR(sc->cache_gpr[C_SUB]), in emu_initefx()
2104 GPR(sc->cache_gpr[C_SUB]), in emu_initefx()
2106 GPR(sc->cache_gpr[C_FRONT_L]), in emu_initefx()
2109 GPR(sc->cache_gpr[C_SUB]), in emu_initefx()
2110 GPR(sc->cache_gpr[C_SUB]), in emu_initefx()
2112 GPR(sc->cache_gpr[C_FRONT_R]), in emu_initefx()
2124 if (sc->mch_rec) { in emu_initefx()
2129 * 0x00..0x3E - outputs in emu_initefx()
2130 * 0x40..0x7E - FX, inputs in emu_initefx()
2140 /* PCM Playback monitoring, offsets 0x40..0x5E */ in emu_initefx()
2150 sc->dummy_gpr = emu_rm_gpr_alloc(sc->rm, 1); in emu_initefx()
2151 emumix_set_gpr(sc, sc->dummy_gpr, 0xc0de0000); in emu_initefx()
2152 EFX_COPY(FX2(31), GPR(sc->dummy_gpr)); in emu_initefx()
2157 sc->routing_code_end = pc; in emu_initefx()
2160 if (sc->is_emu10k1) { in emu_initefx()
2186 sc = i_dev->si_drv1; in emu10kx_open()
2187 mtx_lock(&sc->emu10kx_lock); in emu10kx_open()
2188 if (sc->emu10kx_isopen) { in emu10kx_open()
2189 mtx_unlock(&sc->emu10kx_lock); in emu10kx_open()
2192 sc->emu10kx_isopen = 1; in emu10kx_open()
2193 mtx_unlock(&sc->emu10kx_lock); in emu10kx_open()
2194 if (sbuf_new(&sc->emu10kx_sbuf, NULL, 4096, 0) == NULL) { in emu10kx_open()
2198 sc->emu10kx_bufptr = 0; in emu10kx_open()
2199 error = (emu10kx_prepare(sc, &sc->emu10kx_sbuf) > 0) ? 0 : ENOMEM; in emu10kx_open()
2202 mtx_lock(&sc->emu10kx_lock); in emu10kx_open()
2203 sc->emu10kx_isopen = 0; in emu10kx_open()
2204 mtx_unlock(&sc->emu10kx_lock); in emu10kx_open()
2214 sc = i_dev->si_drv1; in emu10kx_close()
2216 mtx_lock(&sc->emu10kx_lock); in emu10kx_close()
2217 if (!(sc->emu10kx_isopen)) { in emu10kx_close()
2218 mtx_unlock(&sc->emu10kx_lock); in emu10kx_close()
2221 sbuf_delete(&sc->emu10kx_sbuf); in emu10kx_close()
2222 sc->emu10kx_isopen = 0; in emu10kx_close()
2223 mtx_unlock(&sc->emu10kx_lock); in emu10kx_close()
2234 sc = i_dev->si_drv1; in emu10kx_read()
2235 mtx_lock(&sc->emu10kx_lock); in emu10kx_read()
2236 if (!(sc->emu10kx_isopen)) { in emu10kx_read()
2237 mtx_unlock(&sc->emu10kx_lock); in emu10kx_read()
2240 mtx_unlock(&sc->emu10kx_lock); in emu10kx_read()
2242 l = min(buf->uio_resid, sbuf_len(&sc->emu10kx_sbuf) - sc->emu10kx_bufptr); in emu10kx_read()
2243 err = (l > 0) ? uiomove(sbuf_data(&sc->emu10kx_sbuf) + sc->emu10kx_bufptr, l, buf) : 0; in emu10kx_read()
2244 sc->emu10kx_bufptr += l; in emu10kx_read()
2256 …sbuf_printf(s, "DSP General Purpose Registers: %d used, %d total\n", sc->rm->num_used, sc->rm->num… in emu10kx_prepare()
2257 …sbuf_printf(s, "DSP Instruction Registers: %d used, %d total\n", sc->routing_code_end, sc->code_si… in emu10kx_prepare()
2259 if (sc->has_ac97) { in emu10kx_prepare()
2264 if (sc->has_51) { in emu10kx_prepare()
2265 if (sc->has_71) in emu10kx_prepare()
2270 if (sc->is_emu10k1) in emu10kx_prepare()
2272 if (sc->is_emu10k2) in emu10kx_prepare()
2274 if (sc->is_ca0102) in emu10kx_prepare()
2276 if (sc->is_ca0108) in emu10kx_prepare()
2279 if (sc->broken_digital) in emu10kx_prepare()
2283 if (sc->pcm[i] != NULL) in emu10kx_prepare()
2284 if (device_is_attached(sc->pcm[i])) { in emu10kx_prepare()
2285 sbuf_printf(s, "%s on %s\n", device_get_desc(sc->pcm[i]), device_get_nameunit(sc->pcm[i])); in emu10kx_prepare()
2287 if (sc->midi[0] != NULL) in emu10kx_prepare()
2288 if (device_is_attached(sc->midi[0])) { in emu10kx_prepare()
2289 sbuf_printf(s, "EMU10Kx MIDI Interface\n"); in emu10kx_prepare()
2290 sbuf_printf(s, "\tOn-card connector on %s\n", device_get_nameunit(sc->midi[0])); in emu10kx_prepare()
2292 if (sc->midi[1] != NULL) in emu10kx_prepare()
2293 if (device_is_attached(sc->midi[1])) { in emu10kx_prepare()
2294 sbuf_printf(s, "\tOn-Drive connector on %s\n", device_get_nameunit(sc->midi[1])); in emu10kx_prepare()
2296 if (sc->midi[0] != NULL) in emu10kx_prepare()
2297 if (device_is_attached(sc->midi[0])) { in emu10kx_prepare()
2298 sbuf_printf(s, "\tIR receiver MIDI events %s\n", sc->enable_ir ? "enabled" : "disabled"); in emu10kx_prepare()
2300 sbuf_printf(s, "Card is in %s mode\n", (sc->mode == MODE_ANALOG) ? "analog" : "digital"); in emu10kx_prepare()
2312 mtx_init(&sc->emu10kx_lock, device_get_nameunit(sc->dev), "kxdevlock", 0); in emu10kx_dev_init()
2313 unit = device_get_unit(sc->dev); in emu10kx_dev_init()
2315 sc->cdev = make_dev(&emu10kx_cdevsw, unit, UID_ROOT, GID_WHEEL, 0640, "emu10kx%d", unit); in emu10kx_dev_init()
2316 if (sc->cdev != NULL) { in emu10kx_dev_init()
2317 sc->cdev->si_drv1 = sc; in emu10kx_dev_init()
2326 mtx_lock(&sc->emu10kx_lock); in emu10kx_dev_uninit()
2327 if (sc->emu10kx_isopen) { in emu10kx_dev_uninit()
2328 mtx_unlock(&sc->emu10kx_lock); in emu10kx_dev_uninit()
2331 if (sc->cdev) in emu10kx_dev_uninit()
2332 destroy_dev(sc->cdev); in emu10kx_dev_uninit()
2333 sc->cdev = NULL; in emu10kx_dev_uninit()
2335 mtx_destroy(&sc->emu10kx_lock); in emu10kx_dev_uninit()
2351 sc->rm = rm; in emu_rm_init()
2352 rm->card = sc; in emu_rm_init()
2353 maxcount = sc->num_gprs; in emu_rm_init()
2354 rm->num_used = 0; in emu_rm_init()
2355 mtx_init(&(rm->gpr_lock), device_get_nameunit(sc->dev), "gpr alloc", MTX_DEF); in emu_rm_init()
2356 rm->num_gprs = (maxcount < EMU_MAX_GPR ? maxcount : EMU_MAX_GPR); in emu_rm_init()
2357 for (i = 0; i < rm->num_gprs; i++) in emu_rm_init()
2358 rm->allocmap[i] = 0; in emu_rm_init()
2359 /* pre-allocate gpr[0] */ in emu_rm_init()
2360 rm->allocmap[0] = 1; in emu_rm_init()
2361 rm->last_free_gpr = 1; in emu_rm_init()
2371 if (sc->dbg_level > 1) { in emu_rm_uninit()
2372 mtx_lock(&(sc->rm->gpr_lock)); in emu_rm_uninit()
2373 for (i = 1; i < sc->rm->last_free_gpr; i++) in emu_rm_uninit()
2374 if (sc->rm->allocmap[i] > 0) in emu_rm_uninit()
2375 device_printf(sc->dev, "rm: gpr %d not free before uninit\n", i); in emu_rm_uninit()
2376 mtx_unlock(&(sc->rm->gpr_lock)); in emu_rm_uninit()
2379 mtx_destroy(&(sc->rm->gpr_lock)); in emu_rm_uninit()
2380 free(sc->rm, M_DEVBUF); in emu_rm_uninit()
2390 allocated_gpr = rm->num_gprs; in emu_rm_gpr_alloc()
2392 mtx_lock(&(rm->gpr_lock)); in emu_rm_gpr_alloc()
2393 if (rm->last_free_gpr + count <= rm->num_gprs) { in emu_rm_gpr_alloc()
2394 allocated_gpr = rm->last_free_gpr; in emu_rm_gpr_alloc()
2395 rm->last_free_gpr += count; in emu_rm_gpr_alloc()
2396 rm->allocmap[allocated_gpr] = count; in emu_rm_gpr_alloc()
2398 rm->allocmap[allocated_gpr + i] = -(count - i); in emu_rm_gpr_alloc()
2402 allocated_gpr = rm->num_gprs; in emu_rm_gpr_alloc()
2403 while (i < rm->last_free_gpr - count) { in emu_rm_gpr_alloc()
2404 if (rm->allocmap[i] > 0) { in emu_rm_gpr_alloc()
2405 i += rm->allocmap[i]; in emu_rm_gpr_alloc()
2409 if (rm->allocmap[i + j] != 0) in emu_rm_gpr_alloc()
2410 allocated_gpr = rm->num_gprs; in emu_rm_gpr_alloc()
2416 if (allocated_gpr + count < rm->last_free_gpr) { in emu_rm_gpr_alloc()
2417 rm->allocmap[allocated_gpr] = count; in emu_rm_gpr_alloc()
2419 rm->allocmap[allocated_gpr + i] = -(count - i); in emu_rm_gpr_alloc()
2422 if (allocated_gpr == rm->num_gprs) in emu_rm_gpr_alloc()
2423 allocated_gpr = (-1); in emu_rm_gpr_alloc()
2425 rm->num_used += count; in emu_rm_gpr_alloc()
2426 mtx_unlock(&(rm->gpr_lock)); in emu_rm_gpr_alloc()
2450 if (sc->rev >= 6) in emumix_set_mode()
2453 if (sc->is_emu10k1) in emumix_set_mode()
2459 if (sc->broken_digital) { in emumix_set_mode()
2460 device_printf(sc->dev, "Digital mode is reported as broken on this card.\n"); in emumix_set_mode()
2469 if (sc->is_emu10k2) in emumix_set_mode()
2472 if ((sc->is_ca0102) || (sc->is_ca0108)) in emumix_set_mode()
2481 if (sc->is_ca0108) in emumix_set_mode()
2486 emumix_set_gpr(sc, sc->mute_gpr[ANALOGMUTE], 1); in emumix_set_mode()
2490 if ((sc->is_emu10k2) || (sc->is_ca0102) || (sc->is_ca0108)) { in emumix_set_mode()
2499 emumix_set_gpr(sc, sc->mute_gpr[ANALOGMUTE], 0); in emumix_set_mode()
2501 sc->mode = mode; in emumix_set_mode()
2513 device_printf(sc->dev, "AC3 mode does not work and disabled\n"); in emumix_set_spdif_mode()
2575 idx = (L2L_POINTS - 1) - log_t / (L2L_POINTS); in log2lin()
2592 if (sc->dbg_level > 1) in emumix_set_gpr()
2594 device_printf(sc->dev, "Zero gpr write access\n"); in emumix_set_gpr()
2610 sc->mixer_volcache[mixer_idx] = volume; in emumix_set_volume()
2611 emumix_set_fxvol(sc, sc->mixer_gpr[mixer_idx], volume); in emumix_set_volume()
2619 return (sc->mixer_volcache[mixer_idx]); in emumix_get_volume()
2620 return (-1); in emumix_get_volume()
2672 if ((sc->is_ca0102) || (sc->is_ca0108)) in emu_init()
2675 if (sc->is_ca0102) in emu_init()
2680 if (sc->has_51) in emu_init()
2682 if (sc->has_71) in emu_init()
2684 if (sc->is_emu10k2) in emu_init()
2688 if (sc->is_emu10k2) /* XXX for later cards? */ in emu_init()
2692 if (bus_dma_tag_create( /* parent */ bus_get_dma_tag(sc->dev), in emu_init()
2694 /* lowaddr */ (1U << 31) - 1, /* can only access 0-2gb */ in emu_init()
2699 &sc->mem.dmat) != 0) { in emu_init()
2700 device_printf(sc->dev, "unable to create dma tag\n"); in emu_init()
2701 bus_dma_tag_destroy(sc->mem.dmat); in emu_init()
2705 sc->mem.card = sc; in emu_init()
2706 SLIST_INIT(&sc->mem.blocks); in emu_init()
2707 …sc->mem.ptb_pages = emu_malloc(&sc->mem, EMU_MAXPAGES * sizeof(uint32_t), &sc->mem.ptb_pages_addr,… in emu_init()
2708 if (sc->mem.ptb_pages == NULL) in emu_init()
2711 …sc->mem.silent_page = emu_malloc(&sc->mem, EMUPAGESIZE, &sc->mem.silent_page_addr, &sc->mem.silent… in emu_init()
2712 if (sc->mem.silent_page == NULL) { in emu_init()
2713 emu_free(&sc->mem, sc->mem.ptb_pages, sc->mem.ptb_map); in emu_init()
2717 bzero(sc->mem.silent_page, EMUPAGESIZE); in emu_init()
2718 tmp = (uint32_t) (sc->mem.silent_page_addr) << 1; in emu_init()
2720 sc->mem.ptb_pages[i] = tmp | i; in emu_init()
2726 emu_wrptr(sc, 0, EMU_PTB, (sc->mem.ptb_pages_addr)); in emu_init()
2763 if ((sc->is_emu10k2) || (sc->is_ca0102) || (sc->is_ca0108)) { in emu_init()
2776 if ((sc->is_emu10k2) || (sc->is_ca0102) || (sc->is_ca0108)) in emu_init()
2781 * 1. Set I2S capture sample rate to 96000 in emu_init()
2785 if ((sc->is_ca0102) || (sc->is_ca0108)) { in emu_init()
2795 if (sc->is_ca0102) in emu_init()
2808 if ((sc->is_emu10k2) || (sc->is_ca0102) || (sc->is_ca0108)) in emu_init()
2810 if (((sc->is_emu10k2) || (sc->is_ca0102) || (sc->is_ca0108)) && (sc->broken_digital)) { in emu_init()
2811 device_printf(sc->dev, "Audigy card initialized in analog mode.\n"); in emu_init()
2818 device_printf(sc->dev, "Card Configuration ( 0x%08x )\n", tmp); in emu_init()
2819 device_printf(sc->dev, "Card Configuration ( & 0xff000000 ) : %s%s%s%s%s%s%s%s\n", in emu_init()
2828 device_printf(sc->dev, "Card Configuration ( & 0x00ff0000 ) : %s%s%s%s%s%s%s%s\n", in emu_init()
2837 device_printf(sc->dev, "Card Configuration ( & 0x0000ff00 ) : %s%s%s%s%s%s%s%s\n", in emu_init()
2846 device_printf(sc->dev, "Card Configuration ( & 0x000000ff ) : %s%s%s%s%s%s%s%s\n", in emu_init()
2856 if ((sc->is_emu10k2) || (sc->is_ca0102) || (sc->is_ca0108)) { in emu_init()
2858 device_printf(sc->dev, "Audigy Card Configuration ( 0x%04x )\n", tmp); in emu_init()
2859 device_printf(sc->dev, "Audigy Card Configuration ( & 0xff00 )"); in emu_init()
2869 device_printf(sc->dev, "Audigy Card Configuration ( & 0x00ff )"); in emu_init()
2921 if (!SLIST_EMPTY(&sc->mem.blocks)) in emu_uninit()
2922 device_printf(sc->dev, "warning: memblock list not empty\n"); in emu_uninit()
2924 SLIST_FOREACH(blk, &sc->mem.blocks, link) in emu_uninit()
2926 device_printf(sc->dev, "lost %d for %s\n", blk->pte_size, blk->owner); in emu_uninit()
2928 emu_free(&sc->mem, sc->mem.ptb_pages, sc->mem.ptb_map); in emu_uninit()
2929 emu_free(&sc->mem, sc->mem.silent_page, sc->mem.silent_map); in emu_uninit()
2947 *result = func->func; in emu_read_ivar()
2950 if (func->varinfo == NULL) in emu_read_ivar()
2952 *result = ((struct emu_pcminfo *)func->varinfo)->route; in emu_read_ivar()
2955 *result = sc->is_emu10k1; in emu_read_ivar()
2958 *result = sc->mch_disabled; in emu_read_ivar()
2961 *result = sc->mch_rec; in emu_read_ivar()
3024 sc->ctx = device_get_sysctl_ctx(dev); in emu_pci_attach()
3025 if (sc->ctx == NULL) in emu_pci_attach()
3027 sc->root = device_get_sysctl_tree(dev); in emu_pci_attach()
3028 if (sc->root == NULL) in emu_pci_attach()
3031 if (resource_int_value("emu10kx", unit, "multichannel_disabled", &(sc->mch_disabled))) in emu_pci_attach()
3032 RANGE(sc->mch_disabled, 0, 1); in emu_pci_attach()
3035 …OID_AUTO, "multichannel_disabled", CTLFLAG_RD, &(sc->mch_disabled), 0, "Multichannel playback sett… in emu_pci_attach()
3037 if (resource_int_value("emu10kx", unit, "multichannel_recording", &(sc->mch_rec))) in emu_pci_attach()
3038 RANGE(sc->mch_rec, 0, 1); in emu_pci_attach()
3041 …OID_AUTO, "multichannel_recording", CTLFLAG_RD, &(sc->mch_rec), 0, "Multichannel recording settin… in emu_pci_attach()
3043 if (resource_int_value("emu10kx", unit, "debug", &(sc->dbg_level))) in emu_pci_attach()
3044 RANGE(sc->mch_rec, 0, 2); in emu_pci_attach()
3047 OID_AUTO, "debug", CTLFLAG_RW, &(sc->dbg_level), 0, "Debug level"); in emu_pci_attach()
3050 mtx_init(&sc->lock, device_get_nameunit(dev), "bridge conf", MTX_DEF); in emu_pci_attach()
3051 mtx_init(&sc->rw, device_get_nameunit(dev), "exclusive io", MTX_DEF); in emu_pci_attach()
3052 sc->dev = dev; in emu_pci_attach()
3053 sc->type = pci_get_devid(dev); in emu_pci_attach()
3054 sc->rev = pci_get_revid(dev); in emu_pci_attach()
3055 sc->enable_ir = 0; in emu_pci_attach()
3056 sc->has_ac97 = 0; in emu_pci_attach()
3057 sc->has_51 = 0; in emu_pci_attach()
3058 sc->has_71 = 0; in emu_pci_attach()
3059 sc->broken_digital = 0; in emu_pci_attach()
3060 sc->is_emu10k1 = 0; in emu_pci_attach()
3061 sc->is_emu10k2 = 0; in emu_pci_attach()
3062 sc->is_ca0102 = 0; in emu_pci_attach()
3063 sc->is_ca0108 = 0; in emu_pci_attach()
3064 sc->is_cardbus = 0; in emu_pci_attach()
3068 sc->has_51 = 1; in emu_pci_attach()
3070 sc->has_51 = 1; in emu_pci_attach()
3071 sc->has_71 = 1; in emu_pci_attach()
3074 sc->is_emu10k1 = 1; in emu_pci_attach()
3076 sc->is_emu10k2 = 1; in emu_pci_attach()
3078 sc->is_ca0102 = 1; in emu_pci_attach()
3080 sc->is_ca0108 = 1; in emu_pci_attach()
3081 if ((sc->is_emu10k2) && (sc->rev == 4)) { in emu_pci_attach()
3082 sc->is_emu10k2 = 0; in emu_pci_attach()
3083 sc->is_ca0102 = 1; /* for unknown Audigy 2 cards */ in emu_pci_attach()
3085 if ((sc->is_ca0102 == 1) || (sc->is_ca0108 == 1)) in emu_pci_attach()
3087 sc->is_cardbus = 1; in emu_pci_attach()
3089 if ((sc->is_emu10k1 + sc->is_emu10k2 + sc->is_ca0102 + sc->is_ca0108) != 1) { in emu_pci_attach()
3090 device_printf(sc->dev, "Unable to detect HW chipset\n"); in emu_pci_attach()
3094 sc->broken_digital = 1; in emu_pci_attach()
3096 sc->has_ac97 = 1; in emu_pci_attach()
3098 sc->opcode_shift = 0; in emu_pci_attach()
3099 if ((sc->is_emu10k2) || (sc->is_ca0102) || (sc->is_ca0108)) { in emu_pci_attach()
3100 sc->opcode_shift = 24; in emu_pci_attach()
3101 sc->high_operand_shift = 12; in emu_pci_attach()
3104 /* sc->fx_base = 0x0 */ in emu_pci_attach()
3105 sc->input_base = 0x40; in emu_pci_attach()
3106 /* sc->p16vinput_base = 0x50; */ in emu_pci_attach()
3107 sc->output_base = 0x60; in emu_pci_attach()
3108 sc->efxc_base = 0x80; in emu_pci_attach()
3109 /* sc->output32h_base = 0xa0; */ in emu_pci_attach()
3110 /* sc->output32l_base = 0xb0; */ in emu_pci_attach()
3111 sc->dsp_zero = 0xc0; in emu_pci_attach()
3113 /* sc->tram_base = 0x200 */ in emu_pci_attach()
3114 /* sc->tram_addr_base = 0x300 */ in emu_pci_attach()
3115 sc->gpr_base = EMU_A_FXGPREGBASE; in emu_pci_attach()
3116 sc->num_gprs = 0x200; in emu_pci_attach()
3117 sc->code_base = EMU_A_MICROCODEBASE; in emu_pci_attach()
3118 sc->code_size = 0x800 / 2; /* 0x600-0xdff, 2048 words, in emu_pci_attach()
3121 sc->mchannel_fx = 8; in emu_pci_attach()
3122 sc->num_fxbuses = 16; in emu_pci_attach()
3123 sc->num_inputs = 8; in emu_pci_attach()
3124 sc->num_outputs = 16; in emu_pci_attach()
3125 sc->address_mask = EMU_A_PTR_ADDR_MASK; in emu_pci_attach()
3127 if (sc->is_emu10k1) { in emu_pci_attach()
3128 sc->has_51 = 0; /* We don't support 5.1 sound on SB Live! 5.1 */ in emu_pci_attach()
3129 sc->opcode_shift = 20; in emu_pci_attach()
3130 sc->high_operand_shift = 10; in emu_pci_attach()
3131 sc->code_base = EMU_MICROCODEBASE; in emu_pci_attach()
3132 sc->code_size = 0x400 / 2; /* 0x400-0x7ff, 1024 words, in emu_pci_attach()
3134 sc->gpr_base = EMU_FXGPREGBASE; in emu_pci_attach()
3135 sc->num_gprs = 0x100; in emu_pci_attach()
3136 sc->input_base = 0x10; in emu_pci_attach()
3137 sc->output_base = 0x20; in emu_pci_attach()
3143 sc->efxc_base = 0x30; in emu_pci_attach()
3144 sc->dsp_zero = 0x40; in emu_pci_attach()
3145 sc->mchannel_fx = 0; in emu_pci_attach()
3146 sc->num_fxbuses = 8; in emu_pci_attach()
3147 sc->num_inputs = 8; in emu_pci_attach()
3148 sc->num_outputs = 16; in emu_pci_attach()
3149 sc->address_mask = EMU_PTR_ADDR_MASK; in emu_pci_attach()
3151 if (sc->opcode_shift == 0) in emu_pci_attach()
3157 sc->reg = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &i, RF_ACTIVE); in emu_pci_attach()
3158 if (sc->reg == NULL) { in emu_pci_attach()
3162 sc->st = rman_get_bustag(sc->reg); in emu_pci_attach()
3163 sc->sh = rman_get_bushandle(sc->reg); in emu_pci_attach()
3166 sc->timer[i] = 0; /* disable it */ in emu_pci_attach()
3169 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &i, RF_ACTIVE | RF_SHAREABLE); in emu_pci_attach()
3170 if ((sc->irq == NULL) || bus_setup_intr(dev, sc->irq, INTR_MPSAFE | INTR_TYPE_AV, in emu_pci_attach()
3172 emu_intr, sc, &sc->ih)) { in emu_pci_attach()
3180 if (sc->is_cardbus) in emu_pci_attach()
3182 device_printf(dev, "unable to initialize CardBus interface\n"); in emu_pci_attach()
3193 …rintf(status, 255, "rev %d at io 0x%jx irq %jd", sc->rev, rman_get_start(sc->reg), rman_get_start(… in emu_pci_attach()
3197 sc->voice[i].vnum = i; in emu_pci_attach()
3198 sc->voice[i].slave = NULL; in emu_pci_attach()
3199 sc->voice[i].busy = 0; in emu_pci_attach()
3200 sc->voice[i].ismaster = 0; in emu_pci_attach()
3201 sc->voice[i].running = 0; in emu_pci_attach()
3202 sc->voice[i].b16 = 0; in emu_pci_attach()
3203 sc->voice[i].stereo = 0; in emu_pci_attach()
3204 sc->voice[i].speed = 0; in emu_pci_attach()
3205 sc->voice[i].start = 0; in emu_pci_attach()
3206 sc->voice[i].end = 0; in emu_pci_attach()
3209 /* PCM Audio */ in emu_pci_attach()
3211 sc->pcm[i] = NULL; in emu_pci_attach()
3216 pcminfo->card = sc; in emu_pci_attach()
3217 pcminfo->route = RT_FRONT; in emu_pci_attach()
3219 func->func = SCF_PCM; in emu_pci_attach()
3220 func->varinfo = pcminfo; in emu_pci_attach()
3221 sc->pcm[RT_FRONT] = device_add_child(dev, "pcm", DEVICE_UNIT_ANY); in emu_pci_attach()
3222 device_set_ivars(sc->pcm[RT_FRONT], func); in emu_pci_attach()
3224 if (!(sc->mch_disabled)) { in emu_pci_attach()
3228 pcminfo->card = sc; in emu_pci_attach()
3229 pcminfo->route = RT_REAR; in emu_pci_attach()
3231 func->func = SCF_PCM; in emu_pci_attach()
3232 func->varinfo = pcminfo; in emu_pci_attach()
3233 sc->pcm[RT_REAR] = device_add_child(dev, "pcm", DEVICE_UNIT_ANY); in emu_pci_attach()
3234 device_set_ivars(sc->pcm[RT_REAR], func); in emu_pci_attach()
3235 if (sc->has_51) { in emu_pci_attach()
3239 pcminfo->card = sc; in emu_pci_attach()
3240 pcminfo->route = RT_CENTER; in emu_pci_attach()
3242 func->func = SCF_PCM; in emu_pci_attach()
3243 func->varinfo = pcminfo; in emu_pci_attach()
3244 sc->pcm[RT_CENTER] = device_add_child(dev, "pcm", DEVICE_UNIT_ANY); in emu_pci_attach()
3245 device_set_ivars(sc->pcm[RT_CENTER], func); in emu_pci_attach()
3249 pcminfo->card = sc; in emu_pci_attach()
3250 pcminfo->route = RT_SUB; in emu_pci_attach()
3252 func->func = SCF_PCM; in emu_pci_attach()
3253 func->varinfo = pcminfo; in emu_pci_attach()
3254 sc->pcm[RT_SUB] = device_add_child(dev, "pcm", DEVICE_UNIT_ANY); in emu_pci_attach()
3255 device_set_ivars(sc->pcm[RT_SUB], func); in emu_pci_attach()
3257 if (sc->has_71) { in emu_pci_attach()
3261 pcminfo->card = sc; in emu_pci_attach()
3262 pcminfo->route = RT_SIDE; in emu_pci_attach()
3264 func->func = SCF_PCM; in emu_pci_attach()
3265 func->varinfo = pcminfo; in emu_pci_attach()
3266 sc->pcm[RT_SIDE] = device_add_child(dev, "pcm", DEVICE_UNIT_ANY); in emu_pci_attach()
3267 device_set_ivars(sc->pcm[RT_SIDE], func); in emu_pci_attach()
3271 if (sc->mch_rec) { in emu_pci_attach()
3274 pcminfo->card = sc; in emu_pci_attach()
3275 pcminfo->route = RT_MCHRECORD; in emu_pci_attach()
3277 func->func = SCF_PCM; in emu_pci_attach()
3278 func->varinfo = pcminfo; in emu_pci_attach()
3279 sc->pcm[RT_MCHRECORD] = device_add_child(dev, "pcm", DEVICE_UNIT_ANY); in emu_pci_attach()
3280 device_set_ivars(sc->pcm[RT_MCHRECORD], func); in emu_pci_attach()
3284 sc->midi[i] = NULL; in emu_pci_attach()
3288 /* Midi Interface 1: Live!, Audigy, Audigy 2 */ in emu_pci_attach()
3289 if ((sc->is_emu10k1) || (sc->is_emu10k2) || (sc->is_ca0102)) { in emu_pci_attach()
3292 midiinfo->card = sc; in emu_pci_attach()
3293 if (sc->is_emu10k2 || (sc->is_ca0102)) { in emu_pci_attach()
3294 midiinfo->port = EMU_A_MUDATA1; in emu_pci_attach()
3295 midiinfo->portnr = 1; in emu_pci_attach()
3297 if (sc->is_emu10k1) { in emu_pci_attach()
3298 midiinfo->port = MUDATA; in emu_pci_attach()
3299 midiinfo->portnr = 1; in emu_pci_attach()
3301 func->func = SCF_MIDI; in emu_pci_attach()
3302 func->varinfo = midiinfo; in emu_pci_attach()
3303 sc->midi[0] = device_add_child(dev, "midi", DEVICE_UNIT_ANY); in emu_pci_attach()
3304 device_set_ivars(sc->midi[0], func); in emu_pci_attach()
3306 /* Midi Interface 2: Audigy, Audigy 2 (on AudigyDrive) */ in emu_pci_attach()
3307 if (sc->is_emu10k2 || (sc->is_ca0102)) { in emu_pci_attach()
3310 midiinfo->card = sc; in emu_pci_attach()
3312 midiinfo->port = EMU_A_MUDATA2; in emu_pci_attach()
3313 midiinfo->portnr = 2; in emu_pci_attach()
3315 func->func = SCF_MIDI; in emu_pci_attach()
3316 func->varinfo = midiinfo; in emu_pci_attach()
3317 sc->midi[1] = device_add_child(dev, "midi", DEVICE_UNIT_ANY); in emu_pci_attach()
3318 device_set_ivars(sc->midi[1], func); in emu_pci_attach()
3326 if (sc->cdev) in emu_pci_attach()
3328 if (sc->rm != NULL) in emu_pci_attach()
3330 if (sc->reg) in emu_pci_attach()
3331 bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(0), sc->reg); in emu_pci_attach()
3332 if (sc->ih) in emu_pci_attach()
3333 bus_teardown_intr(dev, sc->irq, sc->ih); in emu_pci_attach()
3334 if (sc->irq) in emu_pci_attach()
3335 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq); in emu_pci_attach()
3336 mtx_destroy(&sc->rw); in emu_pci_attach()
3337 mtx_destroy(&sc->lock); in emu_pci_attach()
3348 free(func->varinfo, M_DEVBUF); in emu_pci_child_deleted()
3364 if (sc->pcm[i] != NULL) { in emu_pci_detach()
3365 r = device_delete_child(dev, sc->pcm[i]); in emu_pci_detach()
3370 if (sc->midi[0] != NULL) { in emu_pci_detach()
3371 r = device_delete_child(dev, sc->midi[0]); in emu_pci_detach()
3375 if (sc->midi[1] != NULL) { in emu_pci_detach()
3376 r = device_delete_child(dev, sc->midi[1]); in emu_pci_detach()
3381 for (i = 0; i < devcount - 1; i++) { in emu_pci_detach()
3396 if (sc->mem.dmat) in emu_pci_detach()
3397 bus_dma_tag_destroy(sc->mem.dmat); in emu_pci_detach()
3399 if (sc->reg) in emu_pci_detach()
3400 bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(0), sc->reg); in emu_pci_detach()
3401 bus_teardown_intr(dev, sc->irq, sc->ih); in emu_pci_detach()
3402 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq); in emu_pci_detach()
3403 mtx_destroy(&sc->rw); in emu_pci_detach()
3404 mtx_destroy(&sc->lock); in emu_pci_detach()
3410 /* Device interface */
3443 /* XXX Should we check state of pcm & midi subdevices here? */ in emu_modevent()