Lines Matching +full:blk +full:- +full:ctrl

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
46 /* -------------------------------------------------------------------- */
82 u_int32_t blk; /* hw block size(dword) */ member
164 u_int16_t blk[2]; /* transfer check blocksize(dword) */ member
179 /* -------------------------------------------------------------------- */
208 /* M-Audio Delta series AK4524 access interface */
215 /* -------------------------------------------------------------------- */
221 /* API -> hardware channel map */
236 /* mixer -> API channel map. see above */
238 -1, /* Master output level. It is depend on codec support */
239 -1, /* Treble level of all output channels */
240 -1, /* Bass level of all output channels */
241 -1, /* Volume of synthesier input */
243 -1, /* Output level for the PC speaker */
245 -1, /* microphone jack */
246 -1, /* CD audio input */
247 -1, /* Recording monitor */
249 -1, /* global recording level */
250 -1, /* Input gain */
251 -1, /* Output gain */
256 -1, /* Digital (input) 2 */
257 -1, /* Digital (input) 3 */
258 -1, /* Phone input */
259 -1, /* Phone output */
260 -1, /* Video/TV (audio) in */
261 -1, /* Radio in */
262 -1, /* Monitor volume */
400 /* -------------------------------------------------------------------- */
408 return bus_space_read_1(sc->cst, sc->csh, regno); in envy24_rdcs()
410 return bus_space_read_2(sc->cst, sc->csh, regno); in envy24_rdcs()
412 return bus_space_read_4(sc->cst, sc->csh, regno); in envy24_rdcs()
423 bus_space_write_1(sc->cst, sc->csh, regno, data); in envy24_wrcs()
426 bus_space_write_2(sc->cst, sc->csh, regno, data); in envy24_wrcs()
429 bus_space_write_4(sc->cst, sc->csh, regno, data); in envy24_wrcs()
439 return bus_space_read_1(sc->mtt, sc->mth, regno); in envy24_rdmt()
441 return bus_space_read_2(sc->mtt, sc->mth, regno); in envy24_rdmt()
443 return bus_space_read_4(sc->mtt, sc->mth, regno); in envy24_rdmt()
454 bus_space_write_1(sc->mtt, sc->mth, regno, data); in envy24_wrmt()
457 bus_space_write_2(sc->mtt, sc->mth, regno, data); in envy24_wrmt()
460 bus_space_write_4(sc->mtt, sc->mth, regno, data); in envy24_wrmt()
479 /* -------------------------------------------------------------------- */
490 device_printf(sc->dev, "envy24_rdi2c(sc, 0x%02x, 0x%02x)\n", dev, addr); in envy24_rdi2c()
499 return -1; in envy24_rdi2c()
511 return -1; in envy24_rdi2c()
516 device_printf(sc->dev, "envy24_rdi2c(): return 0x%x\n", data); in envy24_rdi2c()
529 device_printf(sc->dev, "envy24_rdi2c(sc, 0x%02x, 0x%02x)\n", dev, addr);
538 return -1;
551 return -1;
564 device_printf(sc->dev, "envy24_rdrom(sc, 0x%02x)\n", addr); in envy24_rdrom()
569 device_printf(sc->dev, "envy24_rdrom(): E2PROM not presented\n"); in envy24_rdrom()
571 return -1; in envy24_rdrom()
585 device_printf(sc->dev, "envy24_rom2cfg(sc)\n"); in envy24_rom2cfg()
590 device_printf(sc->dev, "envy24_rom2cfg(): ENVY24_E2PROM_SIZE-->%d\n", size); in envy24_rom2cfg()
597 device_printf(sc->dev, "envy24_rom2cfg(): malloc()\n"); in envy24_rom2cfg()
601 buff->free = 1; in envy24_rom2cfg()
603 buff->subvendor = envy24_rdrom(sc, ENVY24_E2PROM_SUBVENDOR) << 8; in envy24_rom2cfg()
604 buff->subvendor += envy24_rdrom(sc, ENVY24_E2PROM_SUBVENDOR + 1); in envy24_rom2cfg()
605 buff->subdevice = envy24_rdrom(sc, ENVY24_E2PROM_SUBDEVICE) << 8; in envy24_rom2cfg()
606 buff->subdevice += envy24_rdrom(sc, ENVY24_E2PROM_SUBDEVICE + 1); in envy24_rom2cfg()
607 buff->scfg = envy24_rdrom(sc, ENVY24_E2PROM_SCFG); in envy24_rom2cfg()
608 buff->acl = envy24_rdrom(sc, ENVY24_E2PROM_ACL); in envy24_rom2cfg()
609 buff->i2s = envy24_rdrom(sc, ENVY24_E2PROM_I2S); in envy24_rom2cfg()
610 buff->spdif = envy24_rdrom(sc, ENVY24_E2PROM_SPDIF); in envy24_rom2cfg()
611 buff->gpiomask = envy24_rdrom(sc, ENVY24_E2PROM_GPIOMASK); in envy24_rom2cfg()
612 buff->gpiostate = envy24_rdrom(sc, ENVY24_E2PROM_GPIOSTATE); in envy24_rom2cfg()
613 buff->gpiodir = envy24_rdrom(sc, ENVY24_E2PROM_GPIODIR); in envy24_rom2cfg()
616 if (cfg_table[i].subvendor == buff->subvendor && in envy24_rom2cfg()
617 cfg_table[i].subdevice == buff->subdevice) in envy24_rom2cfg()
619 buff->name = cfg_table[i].name; in envy24_rom2cfg()
620 buff->codec = cfg_table[i].codec; in envy24_rom2cfg()
629 if (cfg->free) in envy24_cfgfree()
634 /* -------------------------------------------------------------------- */
646 device_printf(sc->dev, "envy24_coldcd()\n");
659 return -1;
670 device_printf(sc->dev, "envy24_slavecd()\n"); in envy24_slavecd()
684 return -1; in envy24_slavecd()
696 device_printf(sc->dev, "envy24_rdcd(obj, sc, 0x%02x)\n", regno);
708 device_printf(sc->dev, "envy24_rdcd(): return 0x%x\n", data);
721 device_printf(sc->dev, "envy24_wrcd(obj, sc, 0x%02x, 0x%04x)\n", regno, data);
743 /* -------------------------------------------------------------------- */
757 device_printf(sc->dev, "envy24_gpiowr(sc, 0x%02x)\n", data & 0xff); in envy24_gpiowr()
794 /* -------------------------------------------------------------------- */
796 /* Envy24 I2C through GPIO bit-banging */
812 device_printf(ptr->parent->dev, "--> %d, %d\n", scl, sda); in envy24_gpio_i2c_ctl()
814 data = envy24_gpiord(ptr->parent); in envy24_gpio_i2c_ctl()
818 envy24_gpiowr(ptr->parent, data); in envy24_gpio_i2c_ctl()
823 i2c_wrbit(void *codec, void (*ctrl)(void*, unsigned int, unsigned int), int bit) in i2c_wrbit()
833 ctrl(ptr, 0, sda); in i2c_wrbit()
835 ctrl(ptr, 1, sda); in i2c_wrbit()
837 ctrl(ptr, 0, sda); in i2c_wrbit()
842 i2c_start(void *codec, void (*ctrl)(void*, unsigned int, unsigned int)) in i2c_start()
846 ctrl(ptr, 1, 1); in i2c_start()
848 ctrl(ptr, 1, 0); in i2c_start()
850 ctrl(ptr, 0, 0); in i2c_start()
855 i2c_stop(void *codec, void (*ctrl)(void*, unsigned int, unsigned int)) in i2c_stop()
859 ctrl(ptr, 0, 0); in i2c_stop()
861 ctrl(ptr, 1, 0); in i2c_stop()
863 ctrl(ptr, 1, 1); in i2c_stop()
868 i2c_ack(void *codec, void (*ctrl)(void*, unsigned int, unsigned int)) in i2c_ack()
872 ctrl(ptr, 0, 1); in i2c_ack()
874 ctrl(ptr, 1, 1); in i2c_ack()
877 ctrl(ptr, 0, 1); in i2c_ack()
882 i2c_wr(void *codec, void (*ctrl)(void*, unsigned int, unsigned int), u_int32_t dev, int reg, u_int… in i2c_wr()
887 i2c_start(ptr, ctrl); in i2c_wr()
890 i2c_wrbit(ptr, ctrl, dev & mask); in i2c_wr()
891 i2c_ack(ptr, ctrl); in i2c_wr()
895 i2c_wrbit(ptr, ctrl, reg & mask); in i2c_wr()
896 i2c_ack(ptr, ctrl); in i2c_wr()
900 i2c_wrbit(ptr, ctrl, val & mask); in i2c_wr()
901 i2c_ack(ptr, ctrl); in i2c_wr()
903 i2c_stop(ptr, ctrl); in i2c_wr()
906 /* -------------------------------------------------------------------- */
908 /* M-Audio Delta series AK4524 access interface routine */
917 device_printf(ptr->parent->dev, "--> %d, %d, %d\n", cs, cclk, cdti); in envy24_delta_ak4524_ctl()
919 data = envy24_gpiord(ptr->parent); in envy24_delta_ak4524_ctl()
920 data &= ~(ptr->cs | ptr->cclk | ptr->cdti); in envy24_delta_ak4524_ctl()
921 if (cs) data += ptr->cs; in envy24_delta_ak4524_ctl()
922 if (cclk) data += ptr->cclk; in envy24_delta_ak4524_ctl()
923 if (cdti) data += ptr->cdti; in envy24_delta_ak4524_ctl()
924 envy24_gpiowr(ptr->parent, data); in envy24_delta_ak4524_ctl()
935 device_printf(sc->dev, "envy24_delta_ak4524_create(dev, sc, %d, %d)\n", dir, num); in envy24_delta_ak4524_create()
942 if (dir == PCMDIR_REC && sc->adc[num] != NULL) in envy24_delta_ak4524_create()
943 buff->info = ((struct envy24_delta_ak4524_codec *)sc->adc[num])->info; in envy24_delta_ak4524_create()
944 else if (dir == PCMDIR_PLAY && sc->dac[num] != NULL) in envy24_delta_ak4524_create()
945 buff->info = ((struct envy24_delta_ak4524_codec *)sc->dac[num])->info; in envy24_delta_ak4524_create()
947 buff->info = spicds_create(dev, buff, num, envy24_delta_ak4524_ctl); in envy24_delta_ak4524_create()
948 if (buff->info == NULL) { in envy24_delta_ak4524_create()
953 buff->parent = sc; in envy24_delta_ak4524_create()
954 buff->dir = dir; in envy24_delta_ak4524_create()
955 buff->num = num; in envy24_delta_ak4524_create()
967 device_printf(ptr->parent->dev, "envy24_delta_ak4524_destroy()\n"); in envy24_delta_ak4524_destroy()
970 if (ptr->dir == PCMDIR_PLAY) { in envy24_delta_ak4524_destroy()
971 if (ptr->parent->dac[ptr->num] != NULL) in envy24_delta_ak4524_destroy()
972 spicds_destroy(ptr->info); in envy24_delta_ak4524_destroy()
975 if (ptr->parent->adc[ptr->num] != NULL) in envy24_delta_ak4524_destroy()
976 spicds_destroy(ptr->info); in envy24_delta_ak4524_destroy()
992 device_printf(ptr->parent->dev, "envy24_delta_ak4524_init()\n"); in envy24_delta_ak4524_init()
996 gpiomask = envy24_gpiogetmask(ptr->parent); in envy24_delta_ak4524_init()
998 envy24_gpiosetmask(ptr->parent, gpiomask); in envy24_delta_ak4524_init()
999 gpiodir = envy24_gpiogetdir(ptr->parent); in envy24_delta_ak4524_init()
1001 envy24_gpiosetdir(ptr->parent, gpiodir); in envy24_delta_ak4524_init()
1003 ptr->cs = ptr->parent->cfg->cs; in envy24_delta_ak4524_init()
1005 envy24_gpiosetmask(ptr->parent, ENVY24_GPIO_CS8414_STATUS); in envy24_delta_ak4524_init()
1006 envy24_gpiosetdir(ptr->parent, ~ENVY24_GPIO_CS8414_STATUS); in envy24_delta_ak4524_init()
1007 if (ptr->num == 0) in envy24_delta_ak4524_init()
1008 ptr->cs = ENVY24_GPIO_AK4524_CS0; in envy24_delta_ak4524_init()
1010 ptr->cs = ENVY24_GPIO_AK4524_CS1; in envy24_delta_ak4524_init()
1011 ptr->cclk = ENVY24_GPIO_AK4524_CCLK; in envy24_delta_ak4524_init()
1013 ptr->cclk = ptr->parent->cfg->cclk; in envy24_delta_ak4524_init()
1014 ptr->cdti = ptr->parent->cfg->cdti; in envy24_delta_ak4524_init()
1015 spicds_settype(ptr->info, ptr->parent->cfg->type); in envy24_delta_ak4524_init()
1016 spicds_setcif(ptr->info, ptr->parent->cfg->cif); in envy24_delta_ak4524_init()
1017 spicds_setformat(ptr->info, in envy24_delta_ak4524_init()
1019 spicds_setdvc(ptr->info, AK452X_DVC_DEMOFF); in envy24_delta_ak4524_init()
1021 if (ptr->num == 0) in envy24_delta_ak4524_init()
1022 spicds_init(ptr->info); in envy24_delta_ak4524_init()
1024 /* 6fire rear input init test, set ptr->num to 1 for test */ in envy24_delta_ak4524_init()
1025 if (ptr->parent->cfg->subvendor == 0x153b && \ in envy24_delta_ak4524_init()
1026 ptr->parent->cfg->subdevice == 0x1138 && ptr->num == 100) { in envy24_delta_ak4524_init()
1027 ptr->cs = 0x02; in envy24_delta_ak4524_init()
1028 spicds_init(ptr->info); in envy24_delta_ak4524_init()
1029 device_printf(ptr->parent->dev, "6fire rear input init\n"); in envy24_delta_ak4524_init()
1044 device_printf(ptr->parent->dev, "envy24_delta_ak4524_reinit()\n"); in envy24_delta_ak4524_reinit()
1047 spicds_reinit(ptr->info); in envy24_delta_ak4524_reinit()
1057 device_printf(ptr->parent->dev, "envy24_delta_ak4524_set()\n"); in envy24_delta_ak4524_setvolume()
1060 spicds_set(ptr->info, dir, left, right); in envy24_delta_ak4524_setvolume()
1071 /* -------------------------------------------------------------------- */
1101 device_printf(sc->dev, "envy24_setspeed(sc, %d)\n", speed); in envy24_setspeed()
1115 …device_printf(sc->dev, "envy24_setspeed(): speed %d/code 0x%04x\n", envy24_speedtab[i].speed, code… in envy24_setspeed()
1131 device_printf(sc->dev, "envy24_setspeed(): return %d\n", speed); in envy24_setspeed()
1140 device_printf(sc->dev, "envy24_setvolume(sc, %d)\n", ch); in envy24_setvolume()
1142 if (sc->cfg->subvendor==0x153b && sc->cfg->subdevice==0x1138 ) { in envy24_setvolume()
1150 envy24_wrmt(sc, ENVY24_MT_VOLUME, 0x7f00 | sc->left[ch], 2); in envy24_setvolume()
1152 envy24_wrmt(sc, ENVY24_MT_VOLUME, (sc->right[ch] << 8) | 0x7f, 2); in envy24_setvolume()
1161 device_printf(sc->dev, "envy24_mutevolume(sc, %d)\n", ch); in envy24_mutevolume()
1177 device_printf(sc->dev, "envy24_gethwptr(sc, %d)\n", dir); in envy24_gethwptr()
1180 rtn = sc->psize / 4; in envy24_gethwptr()
1185 rtn = sc->rsize / 4; in envy24_gethwptr()
1191 rtn -= (ptr + 1); in envy24_gethwptr()
1195 device_printf(sc->dev, "envy24_gethwptr(): return %d\n", rtn); in envy24_gethwptr()
1206 u_int16_t blk; in envy24_updintr() local
1209 device_printf(sc->dev, "envy24_updintr(sc, %d)\n", dir); in envy24_updintr()
1212 blk = sc->blk[0]; in envy24_updintr()
1217 blk = sc->blk[1]; in envy24_updintr()
1222 cnt = blk - 1; in envy24_updintr()
1224 device_printf(sc->dev, "envy24_updintr():blk = %d, cnt = %d\n", blk, cnt); in envy24_updintr()
1229 device_printf(sc->dev, "envy24_updintr():intr = 0x%02x, mask = 0x%02x\n", intr, mask); in envy24_updintr()
1233 device_printf(sc->dev, "envy24_updintr():INT-->0x%02x\n", in envy24_updintr()
1247 device_printf(sc->dev, "envy24_maskintr(sc, %d)\n", dir);
1266 device_printf(sc->dev, "envy24_checkintr(sc, %d)\n", dir); in envy24_checkintr()
1293 device_printf(sc->dev, "envy24_start(sc, %d)\n", dir); in envy24_start()
1304 device_printf(sc->dev, "PADDR:0x%08x\n", envy24_rdmt(sc, ENVY24_MT_PADDR, 4)); in envy24_start()
1305 device_printf(sc->dev, "PCNT:%ld\n", envy24_rdmt(sc, ENVY24_MT_PCNT, 2)); in envy24_start()
1317 device_printf(sc->dev, "envy24_stop(sc, %d)\n", dir); in envy24_stop()
1337 device_printf(sc->dev, "envy24_route(sc, %d, %d, %d, %d)\n", in envy24_route()
1342 return -1; in envy24_route()
1345 return -1; in envy24_route()
1360 device_printf(sc->dev, "envy24_route(): MT_SPDOUT-->0x%04x\n", reg); in envy24_route()
1369 device_printf(sc->dev, "envy24_route(): MT_PSDOUT-->0x%04x\n", reg); in envy24_route()
1378 device_printf(sc->dev, "envy24_route(): MT_RECORD-->0x%08x\n", reg); in envy24_route()
1389 /* -------------------------------------------------------------------- */
1401 length = sndbuf_getready(ch->buffer) / 8; in envy24_p32sl()
1402 dmabuf = ch->parent->pbuf; in envy24_p32sl()
1403 data = (u_int32_t *)ch->data; in envy24_p32sl()
1404 src = sndbuf_getreadyptr(ch->buffer) / 4; in envy24_p32sl()
1405 dst = src / 2 + ch->offset; in envy24_p32sl()
1406 ssize = ch->size / 4; in envy24_p32sl()
1407 dsize = ch->size / 8; in envy24_p32sl()
1408 slot = ch->num * 2; in envy24_p32sl()
1432 device_printf(ch->parent->dev, "envy24_p16sl()\n"); in envy24_p16sl()
1434 length = sndbuf_getready(ch->buffer) / 4; in envy24_p16sl()
1435 dmabuf = ch->parent->pbuf; in envy24_p16sl()
1436 data = (u_int16_t *)ch->data; in envy24_p16sl()
1437 src = sndbuf_getreadyptr(ch->buffer) / 2; in envy24_p16sl()
1438 dst = src / 2 + ch->offset; in envy24_p16sl()
1439 ssize = ch->size / 2; in envy24_p16sl()
1440 dsize = ch->size / 4; in envy24_p16sl()
1441 slot = ch->num * 2; in envy24_p16sl()
1443 device_printf(ch->parent->dev, "envy24_p16sl():%lu-->%lu(%lu)\n", src, dst, length); in envy24_p16sl()
1476 length = sndbuf_getready(ch->buffer) / 2; in envy24_p8u()
1477 dmabuf = ch->parent->pbuf; in envy24_p8u()
1478 data = (u_int8_t *)ch->data; in envy24_p8u()
1479 src = sndbuf_getreadyptr(ch->buffer); in envy24_p8u()
1480 dst = src / 2 + ch->offset; in envy24_p8u()
1481 ssize = ch->size; in envy24_p8u()
1482 dsize = ch->size / 4; in envy24_p8u()
1483 slot = ch->num * 2; in envy24_p8u()
1506 length = sndbuf_getfree(ch->buffer) / 8; in envy24_r32sl()
1507 dmabuf = ch->parent->rbuf; in envy24_r32sl()
1508 data = (u_int32_t *)ch->data; in envy24_r32sl()
1509 dst = sndbuf_getfreeptr(ch->buffer) / 4; in envy24_r32sl()
1510 src = dst / 2 + ch->offset; in envy24_r32sl()
1511 dsize = ch->size / 4; in envy24_r32sl()
1512 ssize = ch->size / 8; in envy24_r32sl()
1513 slot = (ch->num - ENVY24_CHAN_REC_ADC1) * 2; in envy24_r32sl()
1536 length = sndbuf_getfree(ch->buffer) / 4; in envy24_r16sl()
1537 dmabuf = ch->parent->rbuf; in envy24_r16sl()
1538 data = (u_int16_t *)ch->data; in envy24_r16sl()
1539 dst = sndbuf_getfreeptr(ch->buffer) / 2; in envy24_r16sl()
1540 src = dst / 2 + ch->offset; in envy24_r16sl()
1541 dsize = ch->size / 2; in envy24_r16sl()
1542 ssize = ch->size / 8; in envy24_r16sl()
1543 slot = (ch->num - ENVY24_CHAN_REC_ADC1) * 2; in envy24_r16sl()
1557 /* -------------------------------------------------------------------- */
1568 device_printf(sc->dev, "envy24chan_init(obj, devinfo, b, c, %d)\n", dir); in envy24chan_init()
1570 snd_mtxlock(sc->lock); in envy24chan_init()
1571 if ((sc->chnum > ENVY24_CHAN_PLAY_SPDIF && dir != PCMDIR_REC) || in envy24chan_init()
1572 (sc->chnum < ENVY24_CHAN_REC_ADC1 && dir != PCMDIR_PLAY)) { in envy24chan_init()
1573 snd_mtxunlock(sc->lock); in envy24chan_init()
1576 num = sc->chnum; in envy24chan_init()
1578 ch = &sc->chan[num]; in envy24chan_init()
1579 ch->size = 8 * ENVY24_SAMPLE_NUM; in envy24chan_init()
1580 ch->data = malloc(ch->size, M_ENVY24, M_NOWAIT); in envy24chan_init()
1581 if (ch->data == NULL) { in envy24chan_init()
1582 ch->size = 0; in envy24chan_init()
1586 ch->buffer = b; in envy24chan_init()
1587 ch->channel = c; in envy24chan_init()
1588 ch->parent = sc; in envy24chan_init()
1589 ch->dir = dir; in envy24chan_init()
1591 ch->num = envy24_chanmap[num]; in envy24chan_init()
1592 snd_mtxunlock(sc->lock); in envy24chan_init()
1593 sndbuf_setup(ch->buffer, ch->data, ch->size); in envy24chan_init()
1594 snd_mtxlock(sc->lock); in envy24chan_init()
1596 ch->unit = 4; in envy24chan_init()
1597 ch->blk = 10240; in envy24chan_init()
1599 snd_mtxunlock(sc->lock); in envy24chan_init()
1608 struct sc_info *sc = ch->parent; in envy24chan_free()
1611 device_printf(sc->dev, "envy24chan_free()\n"); in envy24chan_free()
1613 snd_mtxlock(sc->lock); in envy24chan_free()
1614 if (ch->data != NULL) { in envy24chan_free()
1615 free(ch->data, M_ENVY24); in envy24chan_free()
1616 ch->data = NULL; in envy24chan_free()
1618 snd_mtxunlock(sc->lock); in envy24chan_free()
1627 struct sc_info *sc = ch->parent; in envy24chan_setformat()
1633 device_printf(sc->dev, "envy24chan_setformat(obj, data, 0x%08x)\n", format); in envy24chan_setformat()
1635 snd_mtxlock(sc->lock); in envy24chan_setformat()
1637 if (ch->dir == PCMDIR_PLAY) in envy24chan_setformat()
1642 snd_mtxunlock(sc->lock); in envy24chan_setformat()
1643 return -1; in envy24chan_setformat()
1649 snd_mtxunlock(sc->lock); in envy24chan_setformat()
1650 return -1; in envy24chan_setformat()
1654 ch->format = format; in envy24chan_setformat()
1655 ch->emldma = emltab[i].emldma; in envy24chan_setformat()
1656 if (ch->unit > emltab[i].unit) in envy24chan_setformat()
1657 ch->blk *= ch->unit / emltab[i].unit; in envy24chan_setformat()
1659 ch->blk /= emltab[i].unit / ch->unit; in envy24chan_setformat()
1660 ch->unit = emltab[i].unit; in envy24chan_setformat()
1663 ch->size = ch->unit * ENVY24_SAMPLE_NUM; in envy24chan_setformat()
1665 if (ch->dir == PCMDIR_PLAY) in envy24chan_setformat()
1666 bsize = ch->blk * 4 / ENVY24_PLAY_BUFUNIT; in envy24chan_setformat()
1668 bsize = ch->blk * 4 / ENVY24_REC_BUFUNIT; in envy24chan_setformat()
1669 bsize *= ch->unit; in envy24chan_setformat()
1670 bcnt = ch->size / bsize; in envy24chan_setformat()
1671 sndbuf_resize(ch->buffer, bcnt, bsize); in envy24chan_setformat()
1673 snd_mtxunlock(sc->lock); in envy24chan_setformat()
1676 device_printf(sc->dev, "envy24chan_setformat(): return 0x%08x\n", 0); in envy24chan_setformat()
1697 device_printf(ch->parent->dev, "envy24chan_setspeed(obj, data, %d)\n", speed); in envy24chan_setspeed()
1701 if (abs(val - speed) < abs(prev - speed)) in envy24chan_setspeed()
1706 ch->speed = prev; in envy24chan_setspeed()
1709 device_printf(ch->parent->dev, "envy24chan_setspeed(): return %d\n", ch->speed); in envy24chan_setspeed()
1711 return ch->speed; in envy24chan_setspeed()
1718 /* struct sc_info *sc = ch->parent; */ in envy24chan_setblocksize()
1723 device_printf(sc->dev, "envy24chan_setblocksize(obj, data, %d)\n", blocksize); in envy24chan_setblocksize()
1726 /* snd_mtxlock(sc->lock); */ in envy24chan_setblocksize()
1727 for (size = ch->size / 2; size > 0; size /= 2) { in envy24chan_setblocksize()
1728 if (abs(size - blocksize) < abs(prev - blocksize)) in envy24chan_setblocksize()
1734 ch->blk = prev / ch->unit; in envy24chan_setblocksize()
1735 if (ch->dir == PCMDIR_PLAY) in envy24chan_setblocksize()
1736 ch->blk *= ENVY24_PLAY_BUFUNIT / 4; in envy24chan_setblocksize()
1738 ch->blk *= ENVY24_REC_BUFUNIT / 4; in envy24chan_setblocksize()
1740 /* ch->size = ch->unit * ENVY24_SAMPLE_NUM; */ in envy24chan_setblocksize()
1741 if (ch->dir == PCMDIR_PLAY) in envy24chan_setblocksize()
1742 bsize = ch->blk * 4 / ENVY24_PLAY_BUFUNIT; in envy24chan_setblocksize()
1744 bsize = ch->blk * 4 / ENVY24_REC_BUFUNIT; in envy24chan_setblocksize()
1745 bsize *= ch->unit; in envy24chan_setblocksize()
1746 bcnt = ch->size / bsize; in envy24chan_setblocksize()
1747 sndbuf_resize(ch->buffer, bcnt, bsize); in envy24chan_setblocksize()
1748 /* snd_mtxunlock(sc->lock); */ in envy24chan_setblocksize()
1751 device_printf(sc->dev, "envy24chan_setblocksize(): return %d\n", prev); in envy24chan_setblocksize()
1761 struct sc_info *sc = ch->parent; in envy24chan_trigger()
1768 device_printf(sc->dev, "envy24chan_trigger(obj, data, %d)\n", go); in envy24chan_trigger()
1770 snd_mtxlock(sc->lock); in envy24chan_trigger()
1771 if (ch->dir == PCMDIR_PLAY) in envy24chan_trigger()
1778 device_printf(sc->dev, "envy24chan_trigger(): start\n"); in envy24chan_trigger()
1781 if (sc->run[0] == 0 && sc->run[1] == 0) { in envy24chan_trigger()
1782 sc->speed = envy24_setspeed(sc, ch->speed); in envy24chan_trigger()
1783 sc->caps[0].minspeed = sc->caps[0].maxspeed = sc->speed; in envy24chan_trigger()
1784 sc->caps[1].minspeed = sc->caps[1].maxspeed = sc->speed; in envy24chan_trigger()
1786 else if (ch->speed != 0 && ch->speed != sc->speed) { in envy24chan_trigger()
1787 error = -1; in envy24chan_trigger()
1790 if (ch->speed == 0) in envy24chan_trigger()
1791 ch->channel->speed = sc->speed; in envy24chan_trigger()
1793 sc->run[slot]++; in envy24chan_trigger()
1794 if (sc->run[slot] == 1) { in envy24chan_trigger()
1796 ch->offset = 0; in envy24chan_trigger()
1797 sc->blk[slot] = ch->blk; in envy24chan_trigger()
1800 ptr = envy24_gethwptr(sc, ch->dir); in envy24chan_trigger()
1801 ch->offset = ((ptr / ch->blk + 1) * ch->blk % in envy24chan_trigger()
1802 (ch->size / 4)) * 4 / ch->unit; in envy24chan_trigger()
1803 if (ch->blk < sc->blk[slot]) in envy24chan_trigger()
1804 sc->blk[slot] = ch->blk; in envy24chan_trigger()
1806 if (ch->dir == PCMDIR_PLAY) { in envy24chan_trigger()
1807 ch->emldma(ch); in envy24chan_trigger()
1808 envy24_setvolume(sc, ch->num); in envy24chan_trigger()
1810 envy24_updintr(sc, ch->dir); in envy24chan_trigger()
1811 if (sc->run[slot] == 1) in envy24chan_trigger()
1812 envy24_start(sc, ch->dir); in envy24chan_trigger()
1813 ch->run = 1; in envy24chan_trigger()
1817 device_printf(sc->dev, "envy24chan_trigger(): emldmawr\n"); in envy24chan_trigger()
1819 if (ch->run != 1) { in envy24chan_trigger()
1820 error = -1; in envy24chan_trigger()
1823 ch->emldma(ch); in envy24chan_trigger()
1827 device_printf(sc->dev, "envy24chan_trigger(): emldmard\n"); in envy24chan_trigger()
1829 if (ch->run != 1) { in envy24chan_trigger()
1830 error = -1; in envy24chan_trigger()
1833 ch->emldma(ch); in envy24chan_trigger()
1836 if (ch->run) { in envy24chan_trigger()
1838 device_printf(sc->dev, "envy24chan_trigger(): abort\n"); in envy24chan_trigger()
1840 ch->run = 0; in envy24chan_trigger()
1841 sc->run[slot]--; in envy24chan_trigger()
1842 if (ch->dir == PCMDIR_PLAY) in envy24chan_trigger()
1843 envy24_mutevolume(sc, ch->num); in envy24chan_trigger()
1844 if (sc->run[slot] == 0) { in envy24chan_trigger()
1845 envy24_stop(sc, ch->dir); in envy24chan_trigger()
1846 sc->intr[slot] = 0; in envy24chan_trigger()
1849 else if (ch->blk == sc->blk[slot]) { in envy24chan_trigger()
1850 sc->blk[slot] = ENVY24_SAMPLE_NUM / 2; in envy24chan_trigger()
1852 if (sc->chan[i].dir == ch->dir && in envy24chan_trigger()
1853 sc->chan[i].run == 1 && in envy24chan_trigger()
1854 sc->chan[i].blk < sc->blk[slot]) in envy24chan_trigger()
1855 sc->blk[slot] = sc->chan[i].blk; in envy24chan_trigger()
1857 if (ch->blk != sc->blk[slot]) in envy24chan_trigger()
1858 envy24_updintr(sc, ch->dir); in envy24chan_trigger()
1865 snd_mtxunlock(sc->lock); in envy24chan_trigger()
1873 struct sc_info *sc = ch->parent; in envy24chan_getptr()
1877 device_printf(sc->dev, "envy24chan_getptr()\n"); in envy24chan_getptr()
1879 snd_mtxlock(sc->lock); in envy24chan_getptr()
1880 ptr = envy24_gethwptr(sc, ch->dir); in envy24chan_getptr()
1881 rtn = ptr * ch->unit; in envy24chan_getptr()
1882 snd_mtxunlock(sc->lock); in envy24chan_getptr()
1885 device_printf(sc->dev, "envy24chan_getptr(): return %d\n", in envy24chan_getptr()
1895 struct sc_info *sc = ch->parent; in envy24chan_getcaps()
1899 device_printf(sc->dev, "envy24chan_getcaps()\n"); in envy24chan_getcaps()
1901 snd_mtxlock(sc->lock); in envy24chan_getcaps()
1902 if (ch->dir == PCMDIR_PLAY) { in envy24chan_getcaps()
1903 if (sc->run[0] == 0) in envy24chan_getcaps()
1906 rtn = &sc->caps[0]; in envy24chan_getcaps()
1909 if (sc->run[1] == 0) in envy24chan_getcaps()
1912 rtn = &sc->caps[1]; in envy24chan_getcaps()
1914 snd_mtxunlock(sc->lock); in envy24chan_getcaps()
1932 /* -------------------------------------------------------------------- */
1942 device_printf(sc->dev, "envy24mixer_init()\n"); in envy24mixer_init()
1945 return -1; in envy24mixer_init()
1948 snd_mtxlock(sc->lock); in envy24mixer_init()
1953 snd_mtxunlock(sc->lock); in envy24mixer_init()
1964 return -1; in envy24mixer_reinit()
1966 device_printf(sc->dev, "envy24mixer_reinit()\n"); in envy24mixer_reinit()
1978 return -1; in envy24mixer_uninit()
1980 device_printf(sc->dev, "envy24mixer_uninit()\n"); in envy24mixer_uninit()
1995 return -1; in envy24mixer_set()
1996 if (dev == 0 && sc->cfg->codec->setvolume == NULL) in envy24mixer_set()
1997 return -1; in envy24mixer_set()
1998 if (dev != 0 && ch == -1) in envy24mixer_set()
1999 return -1; in envy24mixer_set()
2002 device_printf(sc->dev, "envy24mixer_set(m, %d, %d, %d)\n", in envy24mixer_set()
2006 snd_mtxlock(sc->lock); in envy24mixer_set()
2008 for (i = 0; i < sc->dacn; i++) { in envy24mixer_set()
2009 sc->cfg->codec->setvolume(sc->dac[i], PCMDIR_PLAY, left, right); in envy24mixer_set()
2014 if ((sc->left[hwch] = 100 - left) > ENVY24_VOL_MIN) in envy24mixer_set()
2015 sc->left[hwch] = ENVY24_VOL_MUTE; in envy24mixer_set()
2016 if ((sc->right[hwch] = 100 - right) > ENVY24_VOL_MIN) in envy24mixer_set()
2017 sc->right[hwch] = ENVY24_VOL_MUTE; in envy24mixer_set()
2020 if (hwch > ENVY24_CHAN_PLAY_SPDIF || sc->chan[ch].run) in envy24mixer_set()
2023 snd_mtxunlock(sc->lock); in envy24mixer_set()
2034 device_printf(sc->dev, "envy24mixer_setrecsrc(m, %d)\n", src); in envy24mixer_setrecsrc()
2038 sc->src = ch; in envy24mixer_setrecsrc()
2052 /* -------------------------------------------------------------------- */
2064 device_printf(sc->dev, "envy24_intr()\n"); in envy24_intr()
2066 snd_mtxlock(sc->lock); in envy24_intr()
2069 device_printf(sc->dev, "envy24_intr(): play\n"); in envy24_intr()
2071 dsize = sc->psize / 4; in envy24_intr()
2072 ptr = dsize - envy24_rdmt(sc, ENVY24_MT_PCNT, 2) - 1; in envy24_intr()
2074 device_printf(sc->dev, "envy24_intr(): ptr = %d-->", ptr); in envy24_intr()
2076 ptr -= ptr % sc->blk[0]; in envy24_intr()
2077 feed = (ptr + dsize - sc->intr[0]) % dsize; in envy24_intr()
2079 printf("%d intr = %d feed = %d\n", ptr, sc->intr[0], feed); in envy24_intr()
2082 ch = &sc->chan[i]; in envy24_intr()
2084 if (ch->run) in envy24_intr()
2085 device_printf(sc->dev, "envy24_intr(): chan[%d].blk = %d\n", i, ch->blk); in envy24_intr()
2087 if (ch->run && ch->blk <= feed) { in envy24_intr()
2088 snd_mtxunlock(sc->lock); in envy24_intr()
2089 chn_intr(ch->channel); in envy24_intr()
2090 snd_mtxlock(sc->lock); in envy24_intr()
2093 sc->intr[0] = ptr; in envy24_intr()
2098 device_printf(sc->dev, "envy24_intr(): rec\n"); in envy24_intr()
2100 dsize = sc->rsize / 4; in envy24_intr()
2101 ptr = dsize - envy24_rdmt(sc, ENVY24_MT_RCNT, 2) - 1; in envy24_intr()
2102 ptr -= ptr % sc->blk[1]; in envy24_intr()
2103 feed = (ptr + dsize - sc->intr[1]) % dsize; in envy24_intr()
2105 ch = &sc->chan[i]; in envy24_intr()
2106 if (ch->run && ch->blk <= feed) { in envy24_intr()
2107 snd_mtxunlock(sc->lock); in envy24_intr()
2108 chn_intr(ch->channel); in envy24_intr()
2109 snd_mtxlock(sc->lock); in envy24_intr()
2112 sc->intr[1] = ptr; in envy24_intr()
2115 snd_mtxunlock(sc->lock); in envy24_intr()
2162 sc->paddr = segs->ds_addr; in envy24_dmapsetmap()
2164 device_printf(sc->dev, "envy24_dmapsetmap()\n"); in envy24_dmapsetmap()
2167 (unsigned long)segs->ds_addr, in envy24_dmapsetmap()
2168 (unsigned long)segs->ds_len); in envy24_dmapsetmap()
2169 printf("%p -> %lx\n", sc->pmap, sc->paddr); in envy24_dmapsetmap()
2179 sc->raddr = segs->ds_addr; in envy24_dmarsetmap()
2181 device_printf(sc->dev, "envy24_dmarsetmap()\n"); in envy24_dmarsetmap()
2184 (unsigned long)segs->ds_addr, in envy24_dmarsetmap()
2185 (unsigned long)segs->ds_len); in envy24_dmarsetmap()
2186 printf("%p -> %lx\n", sc->rmap, sc->raddr); in envy24_dmarsetmap()
2195 device_printf(sc->dev, "envy24_dmafree():"); in envy24_dmafree()
2196 printf(" sc->raddr(0x%08x)", (u_int32_t)sc->raddr); in envy24_dmafree()
2197 printf(" sc->paddr(0x%08x)", (u_int32_t)sc->paddr); in envy24_dmafree()
2198 if (sc->rbuf) printf(" sc->rbuf(0x%08x)", (u_int32_t)sc->rbuf); in envy24_dmafree()
2199 else printf(" sc->rbuf(null)"); in envy24_dmafree()
2200 if (sc->pbuf) printf(" sc->pbuf(0x%08x)\n", (u_int32_t)sc->pbuf); in envy24_dmafree()
2201 else printf(" sc->pbuf(null)\n"); in envy24_dmafree()
2204 if (sc->raddr) in envy24_dmafree()
2205 bus_dmamap_unload(sc->dmat, sc->rmap); in envy24_dmafree()
2206 if (sc->paddr) in envy24_dmafree()
2207 bus_dmamap_unload(sc->dmat, sc->pmap); in envy24_dmafree()
2208 if (sc->rbuf) in envy24_dmafree()
2209 bus_dmamem_free(sc->dmat, sc->rbuf, sc->rmap); in envy24_dmafree()
2210 if (sc->pbuf) in envy24_dmafree()
2211 bus_dmamem_free(sc->dmat, sc->pbuf, sc->pmap); in envy24_dmafree()
2213 bus_dmamap_unload(sc->dmat, sc->rmap); in envy24_dmafree()
2214 bus_dmamap_unload(sc->dmat, sc->pmap); in envy24_dmafree()
2215 bus_dmamem_free(sc->dmat, sc->rbuf, sc->rmap); in envy24_dmafree()
2216 bus_dmamem_free(sc->dmat, sc->pbuf, sc->pmap); in envy24_dmafree()
2219 sc->raddr = sc->paddr = 0; in envy24_dmafree()
2220 sc->pbuf = NULL; in envy24_dmafree()
2221 sc->rbuf = NULL; in envy24_dmafree()
2231 device_printf(sc->dev, "envy24_dmainit()\n"); in envy24_dmainit()
2234 sc->psize = ENVY24_PLAY_BUFUNIT * ENVY24_SAMPLE_NUM; in envy24_dmainit()
2235 sc->rsize = ENVY24_REC_BUFUNIT * ENVY24_SAMPLE_NUM; in envy24_dmainit()
2236 sc->pbuf = NULL; in envy24_dmainit()
2237 sc->rbuf = NULL; in envy24_dmainit()
2238 sc->paddr = sc->raddr = 0; in envy24_dmainit()
2239 sc->blk[0] = sc->blk[1] = 0; in envy24_dmainit()
2243 device_printf(sc->dev, "envy24_dmainit(): bus_dmamem_alloc(): sc->pbuf\n"); in envy24_dmainit()
2245 if (bus_dmamem_alloc(sc->dmat, (void **)&sc->pbuf, BUS_DMA_NOWAIT, &sc->pmap)) in envy24_dmainit()
2248 device_printf(sc->dev, "envy24_dmainit(): bus_dmamem_alloc(): sc->rbuf\n"); in envy24_dmainit()
2250 if (bus_dmamem_alloc(sc->dmat, (void **)&sc->rbuf, BUS_DMA_NOWAIT, &sc->rmap)) in envy24_dmainit()
2253 device_printf(sc->dev, "envy24_dmainit(): bus_dmamem_load(): sc->pmap\n"); in envy24_dmainit()
2255 if (bus_dmamap_load(sc->dmat, sc->pmap, sc->pbuf, sc->psize, in envy24_dmainit()
2259 device_printf(sc->dev, "envy24_dmainit(): bus_dmamem_load(): sc->rmap\n"); in envy24_dmainit()
2261 if (bus_dmamap_load(sc->dmat, sc->rmap, sc->rbuf, sc->rsize, in envy24_dmainit()
2264 bzero(sc->pbuf, sc->psize); in envy24_dmainit()
2265 bzero(sc->rbuf, sc->rsize); in envy24_dmainit()
2269 device_printf(sc->dev, "paddr(0x%08x)\n", sc->paddr); in envy24_dmainit()
2271 envy24_wrmt(sc, ENVY24_MT_PADDR, sc->paddr, 4); in envy24_dmainit()
2273 device_printf(sc->dev, "PADDR-->(0x%08x)\n", envy24_rdmt(sc, ENVY24_MT_PADDR, 4)); in envy24_dmainit()
2274 device_printf(sc->dev, "psize(%ld)\n", sc->psize / 4 - 1); in envy24_dmainit()
2276 envy24_wrmt(sc, ENVY24_MT_PCNT, sc->psize / 4 - 1, 2); in envy24_dmainit()
2278 device_printf(sc->dev, "PCNT-->(%ld)\n", envy24_rdmt(sc, ENVY24_MT_PCNT, 2)); in envy24_dmainit()
2280 envy24_wrmt(sc, ENVY24_MT_RADDR, sc->raddr, 4); in envy24_dmainit()
2281 envy24_wrmt(sc, ENVY24_MT_RCNT, sc->rsize / 4 - 1, 2); in envy24_dmainit()
2292 device_printf(sc->dev, "system configuration\n"); in envy24_putcfg()
2294 sc->cfg->subvendor, sc->cfg->subdevice); in envy24_putcfg()
2296 switch (sc->cfg->scfg & PCIM_SCFG_XIN2) { in envy24_putcfg()
2309 printf(" MPU-401 UART(s) #: "); in envy24_putcfg()
2310 if (sc->cfg->scfg & PCIM_SCFG_MPU) in envy24_putcfg()
2315 if (sc->cfg->scfg & PCIM_SCFG_AC97) in envy24_putcfg()
2320 printf("%d\n", sc->adcn); in envy24_putcfg()
2322 printf("%d\n", sc->dacn); in envy24_putcfg()
2323 printf(" Multi-track converter type: "); in envy24_putcfg()
2324 if ((sc->cfg->acl & PCIM_ACL_MTC) == 0) { in envy24_putcfg()
2326 if (sc->cfg->acl & PCIM_ACL_OMODE) in envy24_putcfg()
2331 if (sc->cfg->acl & PCIM_ACL_IMODE) in envy24_putcfg()
2339 if (sc->cfg->i2s & PCIM_I2S_VOL) in envy24_putcfg()
2341 if (sc->cfg->i2s & PCIM_I2S_96KHZ) in envy24_putcfg()
2343 switch (sc->cfg->i2s & PCIM_I2S_RES) { in envy24_putcfg()
2357 printf("ID#0x%x)\n", sc->cfg->i2s & PCIM_I2S_ID); in envy24_putcfg()
2360 if (sc->cfg->spdif & PCIM_SPDIF_IN) in envy24_putcfg()
2364 if (sc->cfg->spdif & PCIM_SPDIF_OUT) in envy24_putcfg()
2368 if (sc->cfg->spdif & (PCIM_SPDIF_IN | PCIM_SPDIF_OUT)) in envy24_putcfg()
2369 printf("ID# 0x%02x\n", (sc->cfg->spdif & PCIM_SPDIF_ID) >> 2); in envy24_putcfg()
2371 sc->cfg->gpiomask, sc->cfg->gpiodir, sc->cfg->gpiostate); in envy24_putcfg()
2385 device_printf(sc->dev, "envy24_init()\n"); in envy24_init()
2395 data = pci_read_config(sc->dev, PCIR_LAC, 2); in envy24_init()
2397 pci_write_config(sc->dev, PCIR_LAC, data, 2); in envy24_init()
2400 sc->cfg = NULL; in envy24_init()
2403 sv = pci_get_subvendor(sc->dev); in envy24_init()
2404 sd = pci_get_subdevice(sc->dev); in envy24_init()
2407 device_printf(sc->dev, "Set configuration from table\n"); in envy24_init()
2409 sc->cfg = &cfg_table[i]; in envy24_init()
2413 if (sc->cfg == NULL) { in envy24_init()
2415 sc->cfg = envy24_rom2cfg(sc); in envy24_init()
2417 sc->adcn = ((sc->cfg->scfg & PCIM_SCFG_ADC) >> 2) + 1; in envy24_init()
2418 sc->dacn = (sc->cfg->scfg & PCIM_SCFG_DAC) + 1; in envy24_init()
2425 pci_write_config(sc->dev, PCIR_SCFG, sc->cfg->scfg, 1); in envy24_init()
2426 pci_write_config(sc->dev, PCIR_ACL, sc->cfg->acl, 1); in envy24_init()
2427 pci_write_config(sc->dev, PCIR_I2S, sc->cfg->i2s, 1); in envy24_init()
2428 pci_write_config(sc->dev, PCIR_SPDIF, sc->cfg->spdif, 1); in envy24_init()
2429 envy24_gpiosetmask(sc, sc->cfg->gpiomask); in envy24_init()
2430 envy24_gpiosetdir(sc, sc->cfg->gpiodir); in envy24_init()
2431 envy24_gpiowr(sc, sc->cfg->gpiostate); in envy24_init()
2432 for (i = 0; i < sc->adcn; i++) { in envy24_init()
2433 sc->adc[i] = sc->cfg->codec->create(sc->dev, sc, PCMDIR_REC, i); in envy24_init()
2434 sc->cfg->codec->init(sc->adc[i]); in envy24_init()
2436 for (i = 0; i < sc->dacn; i++) { in envy24_init()
2437 sc->dac[i] = sc->cfg->codec->create(sc->dev, sc, PCMDIR_PLAY, i); in envy24_init()
2438 sc->cfg->codec->init(sc->dac[i]); in envy24_init()
2443 device_printf(sc->dev, "envy24_init(): initialize DMA buffer\n"); in envy24_init()
2449 sc->run[0] = sc->run[1] = 0; in envy24_init()
2450 sc->intr[0] = sc->intr[1] = 0; in envy24_init()
2451 sc->speed = 0; in envy24_init()
2452 sc->caps[0].fmtlist = envy24_playfmt; in envy24_init()
2453 sc->caps[1].fmtlist = envy24_recfmt; in envy24_init()
2465 device_printf(sc->dev, "envy24_init(): CCS_IMASK-->0x%02x\n", data); in envy24_init()
2475 sc->csid = PCIR_CCS; in envy24_alloc_resource()
2476 sc->cs = bus_alloc_resource_any(sc->dev, SYS_RES_IOPORT, in envy24_alloc_resource()
2477 &sc->csid, RF_ACTIVE); in envy24_alloc_resource()
2478 sc->ddmaid = PCIR_DDMA; in envy24_alloc_resource()
2479 sc->ddma = bus_alloc_resource_any(sc->dev, SYS_RES_IOPORT, in envy24_alloc_resource()
2480 &sc->ddmaid, RF_ACTIVE); in envy24_alloc_resource()
2481 sc->dsid = PCIR_DS; in envy24_alloc_resource()
2482 sc->ds = bus_alloc_resource_any(sc->dev, SYS_RES_IOPORT, in envy24_alloc_resource()
2483 &sc->dsid, RF_ACTIVE); in envy24_alloc_resource()
2484 sc->mtid = PCIR_MT; in envy24_alloc_resource()
2485 sc->mt = bus_alloc_resource_any(sc->dev, SYS_RES_IOPORT, in envy24_alloc_resource()
2486 &sc->mtid, RF_ACTIVE); in envy24_alloc_resource()
2487 if (!sc->cs || !sc->ddma || !sc->ds || !sc->mt) { in envy24_alloc_resource()
2488 device_printf(sc->dev, "unable to map IO port space\n"); in envy24_alloc_resource()
2491 sc->cst = rman_get_bustag(sc->cs); in envy24_alloc_resource()
2492 sc->csh = rman_get_bushandle(sc->cs); in envy24_alloc_resource()
2493 sc->ddmat = rman_get_bustag(sc->ddma); in envy24_alloc_resource()
2494 sc->ddmah = rman_get_bushandle(sc->ddma); in envy24_alloc_resource()
2495 sc->dst = rman_get_bustag(sc->ds); in envy24_alloc_resource()
2496 sc->dsh = rman_get_bushandle(sc->ds); in envy24_alloc_resource()
2497 sc->mtt = rman_get_bustag(sc->mt); in envy24_alloc_resource()
2498 sc->mth = rman_get_bushandle(sc->mt); in envy24_alloc_resource()
2500 device_printf(sc->dev, in envy24_alloc_resource()
2502 pci_read_config(sc->dev, PCIR_CCS, 4), in envy24_alloc_resource()
2503 pci_read_config(sc->dev, PCIR_DDMA, 4), in envy24_alloc_resource()
2504 pci_read_config(sc->dev, PCIR_DS, 4), in envy24_alloc_resource()
2505 pci_read_config(sc->dev, PCIR_MT, 4)); in envy24_alloc_resource()
2509 sc->irqid = 0; in envy24_alloc_resource()
2510 sc->irq = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &sc->irqid, in envy24_alloc_resource()
2512 if (!sc->irq || in envy24_alloc_resource()
2513 snd_setup_intr(sc->dev, sc->irq, INTR_MPSAFE, envy24_intr, sc, &sc->ih)) { in envy24_alloc_resource()
2514 device_printf(sc->dev, "unable to map interrupt\n"); in envy24_alloc_resource()
2519 if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(sc->dev), in envy24_alloc_resource()
2528 &sc->dmat) != 0) { in envy24_alloc_resource()
2529 device_printf(sc->dev, "unable to create dma tag\n"); in envy24_alloc_resource()
2554 sc->lock = snd_mtxcreate(device_get_nameunit(dev), "snd_envy24 softc"); in envy24_pci_attach()
2555 sc->dev = dev; in envy24_pci_attach()
2579 sc->chnum = 0; in envy24_pci_attach()
2582 sc->chnum++; in envy24_pci_attach()
2584 for (i = 0; i < 2 + sc->adcn; i++) { in envy24_pci_attach()
2586 sc->chnum++; in envy24_pci_attach()
2592 rman_get_start(sc->cs), in envy24_pci_attach()
2593 rman_get_end(sc->cs) - rman_get_start(sc->cs) + 1, in envy24_pci_attach()
2594 rman_get_start(sc->ddma), in envy24_pci_attach()
2595 rman_get_end(sc->ddma) - rman_get_start(sc->ddma) + 1, in envy24_pci_attach()
2596 rman_get_start(sc->ds), in envy24_pci_attach()
2597 rman_get_end(sc->ds) - rman_get_start(sc->ds) + 1, in envy24_pci_attach()
2598 rman_get_start(sc->mt), in envy24_pci_attach()
2599 rman_get_end(sc->mt) - rman_get_start(sc->mt) + 1, in envy24_pci_attach()
2600 rman_get_start(sc->irq), in envy24_pci_attach()
2608 if (sc->ih) in envy24_pci_attach()
2609 bus_teardown_intr(dev, sc->irq, sc->ih); in envy24_pci_attach()
2610 if (sc->irq) in envy24_pci_attach()
2611 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq); in envy24_pci_attach()
2613 if (sc->dmat) in envy24_pci_attach()
2614 bus_dma_tag_destroy(sc->dmat); in envy24_pci_attach()
2615 if (sc->cfg->codec->destroy != NULL) { in envy24_pci_attach()
2616 for (i = 0; i < sc->adcn; i++) in envy24_pci_attach()
2617 sc->cfg->codec->destroy(sc->adc[i]); in envy24_pci_attach()
2618 for (i = 0; i < sc->dacn; i++) in envy24_pci_attach()
2619 sc->cfg->codec->destroy(sc->dac[i]); in envy24_pci_attach()
2621 envy24_cfgfree(sc->cfg); in envy24_pci_attach()
2622 if (sc->cs) in envy24_pci_attach()
2623 bus_release_resource(dev, SYS_RES_IOPORT, sc->csid, sc->cs); in envy24_pci_attach()
2624 if (sc->ddma) in envy24_pci_attach()
2625 bus_release_resource(dev, SYS_RES_IOPORT, sc->ddmaid, sc->ddma); in envy24_pci_attach()
2626 if (sc->ds) in envy24_pci_attach()
2627 bus_release_resource(dev, SYS_RES_IOPORT, sc->dsid, sc->ds); in envy24_pci_attach()
2628 if (sc->mt) in envy24_pci_attach()
2629 bus_release_resource(dev, SYS_RES_IOPORT, sc->mtid, sc->mt); in envy24_pci_attach()
2630 if (sc->lock) in envy24_pci_attach()
2631 snd_mtxfree(sc->lock); in envy24_pci_attach()
2654 if (sc->cfg->codec->destroy != NULL) { in envy24_pci_detach()
2655 for (i = 0; i < sc->adcn; i++) in envy24_pci_detach()
2656 sc->cfg->codec->destroy(sc->adc[i]); in envy24_pci_detach()
2657 for (i = 0; i < sc->dacn; i++) in envy24_pci_detach()
2658 sc->cfg->codec->destroy(sc->dac[i]); in envy24_pci_detach()
2660 envy24_cfgfree(sc->cfg); in envy24_pci_detach()
2661 bus_dma_tag_destroy(sc->dmat); in envy24_pci_detach()
2662 bus_teardown_intr(dev, sc->irq, sc->ih); in envy24_pci_detach()
2663 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq); in envy24_pci_detach()
2664 bus_release_resource(dev, SYS_RES_IOPORT, sc->csid, sc->cs); in envy24_pci_detach()
2665 bus_release_resource(dev, SYS_RES_IOPORT, sc->ddmaid, sc->ddma); in envy24_pci_detach()
2666 bus_release_resource(dev, SYS_RES_IOPORT, sc->dsid, sc->ds); in envy24_pci_detach()
2667 bus_release_resource(dev, SYS_RES_IOPORT, sc->mtid, sc->mt); in envy24_pci_detach()
2668 snd_mtxfree(sc->lock); in envy24_pci_detach()