summaryrefslogtreecommitdiff
path: root/sound/pci/emu10k1/voice.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2023-06-29 10:46:47 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2023-06-29 10:46:47 -0700
commitf8824e151fbfa0ac0a258015d606ea6f4a10251b (patch)
tree805b029bf3a550168d66ac9f1f5e9aa6f2a68b84 /sound/pci/emu10k1/voice.c
parent86e203edf24bb327ce8fcd3c5c8c6bf530a846df (diff)
parentd6048fdc870240e5020343f8af0c825829c232bd (diff)
Merge tag 'sound-6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound updates from Takashi Iwai: "Lots of changes as usual, but the only significant stuff in ALSA core part is the MIDI 2.0 support, while ASoC core kept receiving the code refactoring. The majority of changes are seen rather in device drivers, and quite a few new drivers can be found there. Here we go, some highlights: ALSA and ASoC Core: - Support of MIDI 2.0 devices: rawmidi and sequencer API have been extended for the support of the new UMP (Universal MIDI Packet) protocol, USB audio driver got the USB MIDI 2.0 interface support - Continued refactoring around ASoC DAI links and the ordering of trigger callbacks - PCM ABI extension for better drain support ASoC Drivers: - Conversions of many drivers to use maple tree based caches - Everlasting improvement works on ASoC Intel drivers - Compressed audio support for Qualcomm - Support for AMD SoundWire, Analog Devices SSM3515, Google Chameleon, Ingenic X1000, Intel systems with various CODECs, Loongson platforms, Maxim MAX98388, Mediatek MT8188, Nuvoton NAU8825C, NXP platforms with NAU8822, Qualcomm WSA884x, StarFive JH7110, Texas Instruments TAS2781 HD-audio: - Quirks for HP and ASUS machines - CS35L41 HD-audio codec fixes - Loongson HD-audio support Misc: - A new virtual PCM test driver for kselftests - Continued refactoring and improvements on the legacy emu10k1 driver" * tag 'sound-6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (556 commits) ALSA: hda/realtek: Enable mute/micmute LEDs and limit mic boost on EliteBook ASoC: hdmi-codec: fix channel info for compressed formats ALSA: pcm: fix ELD constraints for (E)AC3, DTS(-HD) and MLP formats ASoC: core: Always store of_node when getting DAI link component ASoC: tas2781: Fix error code in tas2781_load_calibration() ASoC: amd: update pm_runtime enable sequence ALSA: ump: Export MIDI1 / UMP conversion helpers ASoC: tas2781: fix Kconfig dependencies ASoC: amd: acp: remove acp poweroff function ASoC: amd: acp: clear pdm dma interrupt mask ASoC: codecs: max98090: Allow dsp_a mode ASoC: qcom: common: add default jack dapm pins ASoC: loongson: fix address space confusion ASoC: dt-bindings: microchip,sama7g5-pdmc: Simplify "microchip,mic-pos" constraints ASoC: tegra: Remove stale comments in AHUB ASoC: tegra: Use normal system sleep for ASRC ALSA: hda/realtek: Add quirks for ROG ALLY CS35l41 audio ASoC: fsl-asoc-card: Allow passing the number of slots in use ASoC: codecs: wsa884x: Add WSA884x family of speakers ASoC: dt-bindings: qcom,wsa8840: Add WSA884x family of speakers ...
Diffstat (limited to 'sound/pci/emu10k1/voice.c')
-rw-r--r--sound/pci/emu10k1/voice.c136
1 files changed, 64 insertions, 72 deletions
diff --git a/sound/pci/emu10k1/voice.c b/sound/pci/emu10k1/voice.c
index cbeb8443492c..6939498e26f0 100644
--- a/sound/pci/emu10k1/voice.c
+++ b/sound/pci/emu10k1/voice.c
@@ -23,110 +23,101 @@
* allocator uses a round robin scheme. The next free voice is tracked in
* the card record and each allocation begins where the last left off. The
* hardware requires stereo interleaved voices be aligned to an even/odd
- * boundary. For multichannel voice allocation we ensure than the block of
- * voices does not cross the 32 voice boundary. This simplifies the
- * multichannel support and ensures we can use a single write to the
- * (set|clear)_loop_stop registers. Otherwise (for example) the voices would
- * get out of sync when pausing/resuming a stream.
+ * boundary.
* --rlrevell
*/
static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
- struct snd_emu10k1_voice **rvoice)
+ struct snd_emu10k1_pcm *epcm, struct snd_emu10k1_voice **rvoice)
{
struct snd_emu10k1_voice *voice;
- int i, j, k, first_voice, last_voice, skip;
+ int i, j, k, skip;
- *rvoice = NULL;
- first_voice = last_voice = 0;
- for (i = emu->next_free_voice, j = 0; j < NUM_G ; i += number, j += number) {
+ for (i = emu->next_free_voice, j = 0; j < NUM_G; i = (i + skip) % NUM_G, j += skip) {
/*
dev_dbg(emu->card->dev, "i %d j %d next free %d!\n",
i, j, emu->next_free_voice);
*/
- i %= NUM_G;
/* stereo voices must be even/odd */
- if ((number == 2) && (i % 2)) {
- i++;
+ if ((number > 1) && (i % 2)) {
+ skip = 1;
continue;
}
-
- skip = 0;
+
for (k = 0; k < number; k++) {
- voice = &emu->voices[(i+k) % NUM_G];
+ voice = &emu->voices[i + k];
if (voice->use) {
- skip = 1;
- break;
+ skip = k + 1;
+ goto next;
}
}
- if (!skip) {
- /* dev_dbg(emu->card->dev, "allocated voice %d\n", i); */
- first_voice = i;
- last_voice = (i + number) % NUM_G;
- emu->next_free_voice = last_voice;
- break;
- }
- }
-
- if (first_voice == last_voice)
- return -ENOMEM;
-
- for (i = 0; i < number; i++) {
- voice = &emu->voices[(first_voice + i) % NUM_G];
- /*
- dev_dbg(emu->card->dev, "voice alloc - %i, %i of %i\n",
- voice->number, idx-first_voice+1, number);
- */
- voice->use = 1;
- switch (type) {
- case EMU10K1_PCM:
- voice->pcm = 1;
- break;
- case EMU10K1_SYNTH:
- voice->synth = 1;
- break;
- case EMU10K1_MIDI:
- voice->midi = 1;
- break;
- case EMU10K1_EFX:
- voice->efx = 1;
- break;
+
+ for (k = 0; k < number; k++) {
+ voice = &emu->voices[i + k];
+ voice->use = type;
+ voice->epcm = epcm;
+ /* dev_dbg(emu->card->dev, "allocated voice %d\n", i + k); */
}
+ voice->last = 1;
+
+ *rvoice = &emu->voices[i];
+ emu->next_free_voice = (i + number) % NUM_G;
+ return 0;
+
+ next: ;
}
- *rvoice = &emu->voices[first_voice];
- return 0;
+ return -ENOMEM; // -EBUSY would have been better
+}
+
+static void voice_free(struct snd_emu10k1 *emu,
+ struct snd_emu10k1_voice *pvoice)
+{
+ if (pvoice->dirty)
+ snd_emu10k1_voice_init(emu, pvoice->number);
+ pvoice->interrupt = NULL;
+ pvoice->use = pvoice->dirty = pvoice->last = 0;
+ pvoice->epcm = NULL;
}
-int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int number,
- struct snd_emu10k1_voice **rvoice)
+int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int count, int channels,
+ struct snd_emu10k1_pcm *epcm, struct snd_emu10k1_voice **rvoice)
{
unsigned long flags;
int result;
if (snd_BUG_ON(!rvoice))
return -EINVAL;
- if (snd_BUG_ON(!number))
+ if (snd_BUG_ON(!count))
+ return -EINVAL;
+ if (snd_BUG_ON(!channels))
return -EINVAL;
spin_lock_irqsave(&emu->voice_lock, flags);
- for (;;) {
- result = voice_alloc(emu, type, number, rvoice);
- if (result == 0 || type == EMU10K1_SYNTH || type == EMU10K1_MIDI)
- break;
-
- /* free a voice from synth */
- if (emu->get_synth_voice) {
+ for (int got = 0; got < channels; ) {
+ result = voice_alloc(emu, type, count, epcm, &rvoice[got]);
+ if (result == 0) {
+ got++;
+ /*
+ dev_dbg(emu->card->dev, "voice alloc - %i, %i of %i\n",
+ rvoice[got - 1]->number, got, want);
+ */
+ continue;
+ }
+ if (type != EMU10K1_SYNTH && emu->get_synth_voice) {
+ /* free a voice from synth */
result = emu->get_synth_voice(emu);
if (result >= 0) {
- struct snd_emu10k1_voice *pvoice = &emu->voices[result];
- pvoice->interrupt = NULL;
- pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = pvoice->efx = 0;
- pvoice->epcm = NULL;
+ voice_free(emu, &emu->voices[result]);
+ continue;
}
}
- if (result < 0)
- break;
+ for (int i = 0; i < got; i++) {
+ for (int j = 0; j < count; j++)
+ voice_free(emu, rvoice[i] + j);
+ rvoice[i] = NULL;
+ }
+ break;
}
spin_unlock_irqrestore(&emu->voice_lock, flags);
@@ -139,14 +130,15 @@ int snd_emu10k1_voice_free(struct snd_emu10k1 *emu,
struct snd_emu10k1_voice *pvoice)
{
unsigned long flags;
+ int last;
if (snd_BUG_ON(!pvoice))
return -EINVAL;
spin_lock_irqsave(&emu->voice_lock, flags);
- pvoice->interrupt = NULL;
- pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = pvoice->efx = 0;
- pvoice->epcm = NULL;
- snd_emu10k1_voice_init(emu, pvoice->number);
+ do {
+ last = pvoice->last;
+ voice_free(emu, pvoice++);
+ } while (!last);
spin_unlock_irqrestore(&emu->voice_lock, flags);
return 0;
}