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>
46 #include <dev/sound/pcm/sound.h>
47 #include <dev/sound/pcm/ac97.h>
63 struct emu_pcm_info *pcm;
81 struct emu_pcm_info *pcm;
166 static uint32_t emu_pcm_intr(void *pcm, uint32_t stat);
177 [SOUND_MIXER_LINE2] = {1, 1, 4}, /* in4 Line-In2 */
178 [SOUND_MIXER_DIGITAL3] = {1, 1, 5}, /* in5 on-card SPDIF */
187 [SOUND_MIXER_VOLUME] = {1, 0, (-1)},
188 [SOUND_MIXER_PCM] = {1, 0, (-1)},
194 [SOUND_MIXER_LINE2] = {1, 1, 4}, /* in4 Line-In2 */
195 [SOUND_MIXER_DIGITAL3] = {1, 1, 5}, /* in5 on-card SPDIF */
212 if (sc->route == RT_FRONT) {
214 if ((sc->ac97_mixerclass != NULL) && (sc->codec != NULL)) {
215 sc->sm = mixer_create(sc->dev, sc->ac97_mixerclass, sc->codec, "ac97");
216 if (sc->sm != NULL) {
217 p = mix_getdevs(sc->sm);
218 r = mix_getrecdevs(sc->sm);
222 sc->ac97_playdevs = p;
223 sc->ac97_recdevs = r;
230 if (sc->route == RT_FRONT) {
231 if (sc->is_emu10k1) {
262 if (sc->sm != NULL) {
263 err = mixer_delete(sc->sm);
266 sc->sm = NULL;
280 switch (sc->route) {
282 if (sc->sm != NULL)
283 mix_set(sc->sm, dev, left, right);
284 if (sc->mch_disabled) {
285 /* In emu10k1 case PCM volume does not affect
289 if (sc->is_emu10k1) {
290 sc->emu10k1_volcache[0][0] = left;
291 left = left * sc->emu10k1_volcache[1][0] / 100;
292 sc->emu10k1_volcache[0][1] = right;
293 right = right * sc->emu10k1_volcache[1][1] / 100;
296 emumix_set_volume(sc->card, M_MASTER_REAR_L, left);
297 emumix_set_volume(sc->card, M_MASTER_REAR_R, right);
298 if (!sc->is_emu10k1) {
299 emumix_set_volume(sc->card, M_MASTER_CENTER, (left+right)/2);
300 emumix_set_volume(sc->card, M_MASTER_SUBWOOFER, (left+right)/2);
306 emumix_set_volume(sc->card, M_MASTER_REAR_L, left);
307 emumix_set_volume(sc->card, M_MASTER_REAR_R, right);
310 emumix_set_volume(sc->card, M_MASTER_CENTER, (left+right)/2);
313 emumix_set_volume(sc->card, M_MASTER_SUBWOOFER, (left+right)/2);
318 switch (sc->route) {
320 if (sc->sm != NULL)
321 mix_set(sc->sm, dev, left, right);
322 if (sc->mch_disabled) {
324 if (sc->is_emu10k1) {
325 sc->emu10k1_volcache[1][0] = left;
326 left = left * sc->emu10k1_volcache[0][0] / 100;
327 sc->emu10k1_volcache[1][1] = right;
328 right = right * sc->emu10k1_volcache[0][1] / 100;
330 emumix_set_volume(sc->card, M_MASTER_REAR_L, left);
331 emumix_set_volume(sc->card, M_MASTER_REAR_R, right);
333 if (!sc->is_emu10k1) {
334 emumix_set_volume(sc->card, M_MASTER_CENTER, (left+right)/2);
335 emumix_set_volume(sc->card, M_MASTER_SUBWOOFER, (left+right)/2);
341 emumix_set_volume(sc->card, M_FX2_REAR_L, left);
342 emumix_set_volume(sc->card, M_FX3_REAR_R, right);
345 emumix_set_volume(sc->card, M_FX4_CENTER, (left+right)/2);
348 emumix_set_volume(sc->card, M_FX5_SUBWOOFER, (left+right)/2);
353 emumix_set_volume(sc->card, M_IN1_FRONT_L, left);
354 emumix_set_volume(sc->card, M_IN1_FRONT_R, right);
357 if (sc->is_emu10k1) {
359 emumix_set_volume(sc->card, M_IN3_FRONT_L, left);
360 emumix_set_volume(sc->card, M_IN3_FRONT_R, right);
363 emumix_set_volume(sc->card, M_IN2_FRONT_L, left);
364 emumix_set_volume(sc->card, M_IN2_FRONT_R, right);
367 case SOUND_MIXER_LINE2: /* Line-In2, in4 */
368 emumix_set_volume(sc->card, M_IN4_FRONT_L, left);
369 emumix_set_volume(sc->card, M_IN4_FRONT_R, right);
371 case SOUND_MIXER_DIGITAL3: /* on-card SPDIF, in5 */
372 emumix_set_volume(sc->card, M_IN5_FRONT_L, left);
373 emumix_set_volume(sc->card, M_IN5_FRONT_R, right);
376 emumix_set_volume(sc->card, M_IN6_FRONT_L, left);
377 emumix_set_volume(sc->card, M_IN6_FRONT_R, right);
380 if (sc->sm != NULL) {
382 emumix_set_volume(sc->card, M_IN0_FRONT_L, 100);
383 emumix_set_volume(sc->card, M_IN0_FRONT_R, 100);
384 mix_set(sc->sm, dev, left, right);
386 device_printf(sc->dev, "mixer error: unknown device %d\n", dev);
404 if (sc->sm != NULL)
405 if ((src & sc->ac97_recdevs) !=0)
406 if (mix_setrecsrc(sc->sm, src & sc->ac97_recdevs) == 0) {
407 recmask |= (src & sc->ac97_recdevs);
412 if (sc->is_emu10k1) {
431 emumix_set_volume(sc->card, M_IN0_REC_L, input[0] == 1 ? 100 : 0);
432 emumix_set_volume(sc->card, M_IN0_REC_R, input[0] == 1 ? 100 : 0);
434 emumix_set_volume(sc->card, M_IN1_REC_L, input[1] == 1 ? 100 : 0);
435 emumix_set_volume(sc->card, M_IN1_REC_R, input[1] == 1 ? 100 : 0);
437 if (!sc->is_emu10k1) {
438 emumix_set_volume(sc->card, M_IN2_REC_L, input[2] == 1 ? 100 : 0);
439 emumix_set_volume(sc->card, M_IN2_REC_R, input[2] == 1 ? 100 : 0);
442 if (sc->is_emu10k1) {
443 emumix_set_volume(sc->card, M_IN3_REC_L, input[3] == 1 ? 100 : 0);
444 emumix_set_volume(sc->card, M_IN3_REC_R, input[3] == 1 ? 100 : 0);
447 emumix_set_volume(sc->card, M_IN4_REC_L, input[4] == 1 ? 100 : 0);
448 emumix_set_volume(sc->card, M_IN4_REC_R, input[4] == 1 ? 100 : 0);
450 emumix_set_volume(sc->card, M_IN5_REC_L, input[5] == 1 ? 100 : 0);
451 emumix_set_volume(sc->card, M_IN5_REC_R, input[5] == 1 ? 100 : 0);
453 emumix_set_volume(sc->card, M_IN6_REC_L, input[6] == 1 ? 100 : 0);
454 emumix_set_volume(sc->card, M_IN6_REC_R, input[6] == 1 ? 100 : 0);
458 emumix_set_volume(sc->card, M_FX0_REC_L, emumix_get_volume(sc->card, M_FX0_FRONT_L));
459 emumix_set_volume(sc->card, M_FX1_REC_R, emumix_get_volume(sc->card, M_FX1_FRONT_R));
461 emumix_set_volume(sc->card, M_FX0_REC_L, 0);
462 emumix_set_volume(sc->card, M_FX1_REC_R, 0);
509 * to change some DSP controls via AC97 mixer interface. This includes:
510 * - master volume controls MASTER_FRONT_[R|L]
511 * - pcm volume controls FX[0|1]_FRONT_[R|L]
512 * - rec volume controls MASTER_REC_[R|L]
520 #define BIT4_TO100(x) (100-(x)*100/(0x0f))
521 #define BIT6_TO100(x) (100-(x)*100/(0x3f))
522 #define BIT4_TO255(x) (255-(x)*255/(0x0f))
523 #define BIT6_TO255(x) (255-(x)*255/(0x3f))
524 #define V100_TOBIT6(x) (0x3f*(100-x)/100)
525 #define V100_TOBIT4(x) (0x0f*(100-x)/100)
540 emulated = sc->ac97_state[AC97_MIX_MASTER];
544 emulated = sc->ac97_state[AC97_MIX_PCM];
552 emulated = sc->ac97_state[AC97_MIX_RGAIN];
557 emu_wr(sc->card, EMU_AC97ADDR, regno, 1);
558 tmp = emu_rd(sc->card, EMU_AC97DATA, 2);
577 emu_left = BIT6_TO100(left); /* We show us as 6-bit AC97 mixer */
587 emumix_set_volume(sc->card, M_MASTER_FRONT_L, emu_left);
588 emumix_set_volume(sc->card, M_MASTER_FRONT_R, emu_right);
589 sc->ac97_state[AC97_MIX_MASTER] = data & (0x8000 | 0x3f3f);
592 case AC97_MIX_PCM: /* PCM OUT VOL */
593 emumix_set_volume(sc->card, M_FX0_FRONT_L, emu_left);
594 emumix_set_volume(sc->card, M_FX1_FRONT_R, emu_right);
595 sc->ac97_state[AC97_MIX_PCM] = data & (0x8000 | 0x3f3f);
596 data = 0x8000; /* Mute AC97 PCM out */
600 * PCM recording source is set to "stereo mix" (labeled "vol"
601 * in mixer). There is no 'playback' from AC97 codec -
608 emu_left = BIT4_TO100(left); /* rgain is 4-bit */
610 emumix_set_volume(sc->card, M_MASTER_REC_L, 100-emu_left);
611 emumix_set_volume(sc->card, M_MASTER_REC_R, 100-emu_right);
618 sc->ac97_state[AC97_MIX_RGAIN] = data & (0x8000 | 0x0f0f);
623 emu_wr(sc->card, EMU_AC97ADDR, regno, 1);
624 emu_wr(sc->card, EMU_AC97DATA, data, 2);
659 KASSERT(sc->card != NULL, ("emu_rdcd: no soundcard"));
660 emu_wr(sc->card, EMU_AC97ADDR, regno, 1);
661 rd = emu_rd(sc->card, EMU_AC97DATA, 2);
670 KASSERT(sc->card != NULL, ("emu_wrcd: no soundcard"));
671 emu_wr(sc->card, EMU_AC97ADDR, regno, 1);
672 emu_wr(sc->card, EMU_AC97DATA, data, 2);
713 KASSERT(sc->card != NULL, ("empchan_init: no soundcard"));
715 if (sc->pnum >= MAX_CHANNELS)
717 ch = &(sc->pch[sc->pnum++]);
718 ch->buffer = b;
719 ch->pcm = sc;
720 ch->channel = c;
721 ch->blksz = sc->bufsz;
722 ch->fmt = SND_FORMAT(AFMT_U8, 1, 0);
723 ch->spd = 8000;
724 ch->master = emu_valloc(sc->card);
729 ch->slave = emu_valloc(sc->card);
730 ch->timer = emu_timer_create(sc->card);
731 r = (emu_vinit(sc->card, ch->master, ch->slave, EMU_PLAY_BUFSZ, ch->buffer)) ? NULL : ch;
739 struct emu_pcm_info *sc = ch->pcm;
741 emu_timer_clear(sc->card, ch->timer);
742 if (ch->slave != NULL)
743 emu_vfree(sc->card, ch->slave);
744 emu_vfree(sc->card, ch->master);
753 ch->fmt = format;
762 ch->spd = speed;
763 return (ch->spd);
770 struct emu_pcm_info *sc = ch->pcm;
772 if (blocksize > ch->pcm->bufsz)
773 blocksize = ch->pcm->bufsz;
774 snd_mtxlock(sc->lock);
775 ch->blksz = blocksize;
776 emu_timer_set(sc->card, ch->timer, ch->blksz / sndbuf_getalign(ch->buffer));
777 snd_mtxunlock(sc->lock);
778 return (ch->blksz);
785 struct emu_pcm_info *sc = ch->pcm;
790 snd_mtxlock(sc->lock); /* XXX can we trigger on parallel threads ? */
792 emu_vsetup(ch->master, ch->fmt, ch->spd);
793 if (AFMT_CHANNEL(ch->fmt) > 1)
794 emu_vroute(sc->card, &(sc->rt), ch->master);
796 emu_vroute(sc->card, &(sc->rt_mono), ch->master);
797 emu_vwrite(sc->card, ch->master);
798 emu_timer_set(sc->card, ch->timer, ch->blksz / sndbuf_getalign(ch->buffer));
799 emu_timer_enable(sc->card, ch->timer, 1);
801 /* PCM interrupt handler will handle PCMTRIG_STOP event */
802 ch->run = (go == PCMTRIG_START) ? 1 : 0;
803 emu_vtrigger(sc->card, ch->master, ch->run);
804 snd_mtxunlock(sc->lock);
812 struct emu_pcm_info *sc = ch->pcm;
815 r = emu_vpos(sc->card, ch->master);
824 struct emu_pcm_info *sc = ch->pcm;
826 switch (sc->route) {
863 ch = &sc->rch_adc;
864 ch->buffer = b;
865 ch->pcm = sc;
866 ch->channel = c;
867 ch->blksz = sc->bufsz / 2; /* We rise interrupt for half-full buffer */
868 ch->fmt = SND_FORMAT(AFMT_U8, 1, 0);
869 ch->spd = 8000;
870 ch->idxreg = sc->is_emu10k1 ? EMU_ADCIDX : EMU_A_ADCIDX;
871 ch->basereg = EMU_ADCBA;
872 ch->sizereg = EMU_ADCBS;
873 ch->setupreg = EMU_ADCCR;
874 ch->irqmask = EMU_INTE_ADCBUFENABLE;
875 ch->iprmask = EMU_IPR_ADCBUFFULL | EMU_IPR_ADCBUFHALFFULL;
877 if (sndbuf_alloc(ch->buffer, emu_gettag(sc->card), 0, sc->bufsz) != 0)
880 ch->timer = emu_timer_create(sc->card);
881 emu_wrptr(sc->card, 0, ch->basereg, sndbuf_getbufaddr(ch->buffer));
882 emu_wrptr(sc->card, 0, ch->sizereg, 0); /* off */
891 struct emu_pcm_info *sc = ch->pcm;
893 emu_timer_clear(sc->card, ch->timer);
902 ch->fmt = format;
911 if (ch->pcm->is_emu10k1) {
916 ch->spd = speed;
917 return (ch->spd);
924 struct emu_pcm_info *sc = ch->pcm;
926 ch->blksz = blocksize;
932 if (ch->blksz < (ch->pcm->bufsz / 2)) {
933 emu_timer_set(sc->card, ch->timer, ch->blksz / sndbuf_getalign(ch->buffer));
934 emu_timer_enable(sc->card, ch->timer, 1);
936 emu_timer_enable(sc->card, ch->timer, 0);
938 return (ch->blksz);
945 struct emu_pcm_info *sc = ch->pcm;
951 switch (sc->bufsz) {
971 snd_mtxlock(sc->lock);
974 ch->run = 1;
975 emu_wrptr(sc->card, 0, ch->sizereg, sz);
976 val = sc->is_emu10k1 ? EMU_ADCCR_LCHANENABLE : EMU_A_ADCCR_LCHANENABLE;
977 if (AFMT_CHANNEL(ch->fmt) > 1)
978 val |= sc->is_emu10k1 ? EMU_ADCCR_RCHANENABLE : EMU_A_ADCCR_RCHANENABLE;
979 val |= sc->is_emu10k1 ? emu_k1_recval(ch->spd) : emu_k2_recval(ch->spd);
980 emu_wrptr(sc->card, 0, ch->setupreg, 0);
981 emu_wrptr(sc->card, 0, ch->setupreg, val);
982 ch->ihandle = emu_intr_register(sc->card, ch->irqmask, ch->iprmask, &emu_pcm_intr, sc);
987 ch->run = 0;
988 emu_wrptr(sc->card, 0, ch->sizereg, 0);
989 if (ch->setupreg)
990 emu_wrptr(sc->card, 0, ch->setupreg, 0);
991 (void)emu_intr_unregister(sc->card, ch->ihandle);
1000 snd_mtxunlock(sc->lock);
1009 struct emu_pcm_info *sc = ch->pcm;
1012 r = emu_rdptr(sc->card, 0, ch->idxreg) & 0x0000ffff;
1046 ch = &(sc->rch_efx);
1047 ch->fmt = SND_FORMAT(AFMT_S16_LE, 1, 0);
1048 ch->spd = sc->is_emu10k1 ? 48000*32 : 48000 * 64;
1049 ch->idxreg = EMU_FXIDX;
1050 ch->basereg = EMU_FXBA;
1051 ch->sizereg = EMU_FXBS;
1052 ch->irqmask = EMU_INTE_EFXBUFENABLE;
1053 ch->iprmask = EMU_IPR_EFXBUFFULL | EMU_IPR_EFXBUFHALFFULL;
1054 ch->buffer = b;
1055 ch->pcm = sc;
1056 ch->channel = c;
1057 ch->blksz = sc->bufsz / 2;
1059 if (sndbuf_alloc(ch->buffer, emu_gettag(sc->card), 0, sc->bufsz) != 0)
1062 emu_wrptr(sc->card, 0, ch->basereg, sndbuf_getbufaddr(ch->buffer));
1063 emu_wrptr(sc->card, 0, ch->sizereg, 0); /* off */
1080 /* FIXED RATE CHANNEL */
1081 return (ch->spd);
1089 ch->blksz = blocksize;
1096 if (ch->blksz < (ch->pcm->bufsz / 2))
1097 ch->blksz = ch->pcm->bufsz / 2;
1098 return (ch->blksz);
1105 struct emu_pcm_info *sc = ch->pcm;
1111 switch (sc->bufsz) {
1131 snd_mtxlock(sc->lock);
1134 ch->run = 1;
1135 emu_wrptr(sc->card, 0, ch->sizereg, sz);
1136 ch->ihandle = emu_intr_register(sc->card, ch->irqmask, ch->iprmask, &emu_pcm_intr, sc);
1143 if (sc->is_emu10k1) {
1144 emu_wrptr(sc->card, 0, EMU_FXWC, 0xffffffff);
1146 emu_wrptr(sc->card, 0, EMU_A_FXWC1, 0xffffffff);
1147 emu_wrptr(sc->card, 0, EMU_A_FXWC2, 0xffffffff);
1153 ch->run = 0;
1154 if (sc->is_emu10k1) {
1155 emu_wrptr(sc->card, 0, EMU_FXWC, 0x0);
1157 emu_wrptr(sc->card, 0, EMU_A_FXWC1, 0x0);
1158 emu_wrptr(sc->card, 0, EMU_A_FXWC2, 0x0);
1160 emu_wrptr(sc->card, 0, ch->sizereg, 0);
1161 (void)emu_intr_unregister(sc->card, ch->ihandle);
1170 snd_mtxunlock(sc->lock);
1179 struct emu_pcm_info *sc = ch->pcm;
1182 r = emu_rdptr(sc->card, 0, ch->idxreg) & 0x0000ffff;
1191 struct emu_pcm_info *sc = ch->pcm;
1193 if (sc->is_emu10k1)
1203 struct emu_pcm_info *sc = ch->pcm;
1205 if (sc->is_emu10k1)
1227 emu_pcm_intr(void *pcm, uint32_t stat)
1229 struct emu_pcm_info *sc = (struct emu_pcm_info *)pcm;
1235 snd_mtxlock(sc->lock);
1240 if (sc->pch[i].channel) {
1241 if (sc->pch[i].run == 1) {
1242 snd_mtxunlock(sc->lock);
1243 chn_intr(sc->pch[i].channel);
1244 snd_mtxlock(sc->lock);
1246 emu_timer_enable(sc->card, sc->pch[i].timer, 0);
1248 /* ADC may install timer to get low-latency interrupts */
1249 if ((sc->rch_adc.channel) && (sc->rch_adc.run)) {
1250 snd_mtxunlock(sc->lock);
1251 chn_intr(sc->rch_adc.channel);
1252 snd_mtxlock(sc->lock);
1262 if (sc->rch_adc.channel) {
1263 snd_mtxunlock(sc->lock);
1264 chn_intr(sc->rch_adc.channel);
1265 snd_mtxlock(sc->lock);
1271 if (sc->rch_efx.channel) {
1272 snd_mtxunlock(sc->lock);
1273 chn_intr(sc->rch_efx.channel);
1274 snd_mtxlock(sc->lock);
1277 snd_mtxunlock(sc->lock);
1285 sc->bufsz = pcm_getbuffersize(sc->dev, EMUPAGESIZE, EMU_REC_BUFSZ, EMU_MAX_BUFSZ);
1329 device_set_descf(dev, "EMU10Kx DSP %s PCM interface", rt);
1343 sc->card = (struct emu_sc_info *)(device_get_softc(device_get_parent(dev)));
1344 if (sc->card == NULL) {
1350 sc->lock = snd_mtxcreate(device_get_nameunit(dev), "snd_emu10kx pcm softc");
1351 sc->dev = dev;
1354 sc->is_emu10k1 = ivar ? 1 : 0;
1357 sc->mch_disabled = ivar ? 1 : 0;
1359 sc->codec = NULL;
1362 sc->rt.routing_left[i] = i;
1363 sc->rt.amounts_left[i] = 0x00;
1364 sc->rt.routing_right[i] = i;
1365 sc->rt.amounts_right[i] = 0x00;
1369 sc->rt_mono.routing_left[i] = i;
1370 sc->rt_mono.amounts_left[i] = 0x00;
1371 sc->rt_mono.routing_right[i] = i;
1372 sc->rt_mono.amounts_right[i] = 0x00;
1375 sc->emu10k1_volcache[0][0] = 75;
1376 sc->emu10k1_volcache[1][0] = 75;
1377 sc->emu10k1_volcache[0][1] = 75;
1378 sc->emu10k1_volcache[1][1] = 75;
1380 sc->route = route;
1383 sc->rt.amounts_left[0] = 0xff;
1384 sc->rt.amounts_right[1] = 0xff;
1385 sc->rt_mono.amounts_left[0] = 0xff;
1386 sc->rt_mono.amounts_left[1] = 0xff;
1387 if (sc->is_emu10k1)
1388 sc->codec = AC97_CREATE(dev, sc, emu_ac97);
1390 sc->codec = AC97_CREATE(dev, sc, emu_eac97);
1391 sc->ac97_mixerclass = NULL;
1392 if (sc->codec != NULL)
1393 sc->ac97_mixerclass = ac97_getmixerclass();
1400 sc->rt.amounts_left[2] = 0xff;
1401 sc->rt.amounts_right[3] = 0xff;
1402 sc->rt_mono.amounts_left[2] = 0xff;
1403 sc->rt_mono.amounts_left[3] = 0xff;
1410 sc->rt.amounts_left[4] = 0xff;
1411 sc->rt_mono.amounts_left[4] = 0xff;
1418 sc->rt.amounts_left[5] = 0xff;
1419 sc->rt_mono.amounts_left[5] = 0xff;
1426 sc->rt.amounts_left[6] = 0xff;
1427 sc->rt.amounts_right[7] = 0xff;
1428 sc->rt_mono.amounts_left[6] = 0xff;
1429 sc->rt_mono.amounts_left[7] = 0xff;
1448 sc->ihandle = emu_intr_register(sc->card, inte, ipr, &emu_pcm_intr, sc);
1450 if (emu_pcm_init(sc) == -1) {
1451 device_printf(dev, "unable to initialize PCM part of the card\n");
1457 * in pcm device. Mark pcm device as MPSAFE manually.
1463 sc->pnum = 0;
1482 if (sc->codec)
1483 ac97_destroy(sc->codec);
1484 if (sc->lock)
1485 snd_mtxfree(sc->lock);
1504 if (sc->lock)
1505 snd_mtxfree(sc->lock);
1520 "pcm",