Skip to contentSkip to conversation

ALSA: emu10k1: add support for high-bitrate modes of E-MU cards

PATCH New Oswald Buddenhagen 2 participants 10 messages Aug 27, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v5 cover ALSA: emu10k1: add support for high-bitrate modes of E-MU cards

This series is what all the work was about: support the "dual-/quad-pumped" modes of the E-MU cards.
---

i don't suppose you had an epiphany, so as before i'm posting this for posterity, without expectation of it being applied.

---
v5:
- rebased onto new buffer copy callback
- added end-user documentation
v4:
- rebased onto locking changes
v3:
- rebased onto pulled ahead series
---
This patch series needs to be applied on top of the patch titled "ALSA:
emu10k1: add separate documentation for E-MU cards".

Oswald Buddenhagen (8):
ALSA: add snd_ctl_add_locked() & export snd_ctl_remove_locked()
ALSA: emu10k1: introduce alternative E-MU D.A.S. mode
ALSA: emu10k1: improve mixer control naming in E-MU D.A.S. mode
ALSA: emu10k1: make playback in E-MU D.A.S. mode 32-bit
ALSA: emu10k1: add support for 2x/4x word clocks in E-MU D.A.S. mode
ALSA: emu10k1: add high-rate capture in E-MU D.A.S. mode
ALSA: emu10k1: add high-rate playback in E-MU D.A.S. mode
ALSA: emu10k1: document E-MU D.A.S. mode

 Documentation/sound/cards/emu-mixer.rst |  59 +-
 include/sound/control.h                 |   2 +
 include/sound/emu10k1.h                 |  11 +
 sound/core/control.c                    |  43 +-
 sound/pci/emu10k1/emu10k1.c             |  29 +-
 sound/pci/emu10k1/emu10k1_main.c        |  30 +-
 sound/pci/emu10k1/emufx.c               | 109 ++-
 sound/pci/emu10k1/emumixer.c            | 902 +++++++++++++++++++++---
 sound/pci/emu10k1/emupcm.c              | 400 +++++++++--
 sound/pci/emu10k1/emuproc.c             |   5 +
 sound/pci/emu10k1/io.c                  |  30 +-
 sound/pci/emu10k1/voice.c               |   6 +
 12 files changed, 1423 insertions(+), 203 deletions(-)

base-commit: c5baafafd8411c19e27c6a2c7237538a34b8ca31
prerequisite-patch-id: 6b89fb2dc075fcf9e5b8d8ae36bed09ecf063344
prerequisite-patch-id: 44c4ce123c9838904e4fb3ce285ade080f09f306
prerequisite-patch-id: 40620a68c4ad5945a920ff05ba3c7f73e58ad45c

Signature · 1 line
2.40.0.152.g15d061e6df
#1 lore raw

PATCH v5 1/8 ALSA: add snd_ctl_add_locked() & export snd_ctl_remove_locked()

This will be used to dynamically change the available controls from another control's put() callback, which is already locked.

One might want to add snd_ctl_replace_locked() for completeness, but I have no use for it now.

---

applying this upstream would simplify applying the emu10k1 high bit-rate patchset locally, as it would limit the affected modules to the driver itself.

v4:
- adjust to recent locking changes
- mark exports as internal

v3:
- fixed typo in commit message

v2:
- extended commit message

---
 include/sound/control.h |  2 ++
 sound/core/control.c    | 43 ++++++++++++++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 5 deletions(-)
include/sound/control.h +2 -0
index 9a4f4f7138da..7729b4ee1509 100644
@@ -133,7 +133,9 @@ void snd_ctl_notify_one(struct snd_card * card, unsigned int mask, struct snd_kc
 
 struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new * kcontrolnew, void * private_data);
 void snd_ctl_free_one(struct snd_kcontrol * kcontrol);
+int snd_ctl_add_locked(struct snd_card *card, struct snd_kcontrol *kcontrol);
 int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol);
+int snd_ctl_remove_locked(struct snd_card *card, struct snd_kcontrol *kcontrol);
 int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol);
 int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, bool add_on_replace);
 int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id);
sound/core/control.c +38 -5

70 lines not on this page · raw message

Signature · 1 line
2.40.0.152.g15d061e6df
#2 lore raw

Re: [PATCH v5 1/8] ALSA: add snd_ctl_add_locked() & export snd_ctl_remove_locked()

kernel test robot noticed the following build warnings:

Hi Oswald,

kernel test robot noticed the following build warnings:

[auto build test WARNING on c5baafafd8411c19e27c6a2c7237538a34b8ca31]

url:    https://github.com/intel-lab-lkp/linux/commits/Oswald-Buddenhagen/ALSA-add-snd_ctl_add_locked-export-snd_ctl_remove_locked/20230828-011105
base:   c5baafafd8411c19e27c6a2c7237538a34b8ca31
patch link:    https://lore.kernel.org/r/20230825222158.171007-2-oswald.buddenhagen%40gmx.de
patch subject: [PATCH v5 1/8] ALSA: add snd_ctl_add_locked() & export snd_ctl_remove_locked()
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230828/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230828/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> sound/core/control.c:558: warning: Function parameter or member 'card' not described in 'snd_ctl_add_locked'
>> sound/core/control.c:558: warning: Function parameter or member 'kcontrol' not described in 'snd_ctl_add_locked'
>> sound/core/control.c:633: warning: Function parameter or member 'card' not described in 'snd_ctl_remove_locked'
>> sound/core/control.c:633: warning: Function parameter or member 'kcontrol' not described in 'snd_ctl_remove_locked'

vim +558 sound/core/control.c

552
553 /**
554 * snd_ctl_add_locked - same as snd_ctl_add(), but card->controls_rwsem
555 * is expected to be already locked if necessary.
556 */
557 int snd_ctl_add_locked(struct snd_card *card, struct snd_kcontrol *kcontrol)

 > 558	{
   559		return snd_ctl_add_replace_locked(card, kcontrol, CTL_ADD_EXCLUSIVE);
   560	}
   561	EXPORT_SYMBOL_GPL(snd_ctl_add_locked);
   562	
   563	/**
   564	 * snd_ctl_add - add the control instance to the card
   565	 * @card: the card instance
   566	 * @kcontrol: the control instance to add
   567	 *
   568	 * Adds the control instance created via snd_ctl_new() or
   569	 * snd_ctl_new1() to the given card. Assigns also an unique
   570	 * numid used for fast search.
   571	 *
   572	 * It frees automatically the control which cannot be added.
   573	 *
   574	 * Return: Zero if successful, or a negative error code on failure.
   575	 *
   576	 */
   577	int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
   578	{
   579		return snd_ctl_add_replace(card, kcontrol, CTL_ADD_EXCLUSIVE);
   580	}
   581	EXPORT_SYMBOL(snd_ctl_add);
   582	
   583	/**
   584	 * snd_ctl_replace - replace the control instance of the card
   585	 * @card: the card instance
   586	 * @kcontrol: the control instance to replace
   587	 * @add_on_replace: add the control if not already added
   588	 *
   589	 * Replaces the given control.  If the given control does not exist
   590	 * and the add_on_replace flag is set, the control is added.  If the
   591	 * control exists, it is destroyed first.
   592	 *
   593	 * It frees automatically the control which cannot be added or replaced.
   594	 *
   595	 * Return: Zero if successful, or a negative error code on failure.
   596	 */
   597	int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol,
   598			    bool add_on_replace)
   599	{
   600		return snd_ctl_add_replace(card, kcontrol,
   601					   add_on_replace ? CTL_ADD_ON_REPLACE : CTL_REPLACE);
   602	}
   603	EXPORT_SYMBOL(snd_ctl_replace);
   604	
   605	static int __snd_ctl_remove(struct snd_card *card,
   606				    struct snd_kcontrol *kcontrol,
   607				    bool remove_hash)
   608	{
   609		unsigned int idx;
   610	
   611		lockdep_assert_held_write(&card->controls_rwsem);
   612	
   613		if (snd_BUG_ON(!card || !kcontrol))
   614			return -EINVAL;
   615		list_del(&kcontrol->list);
   616	
   617		if (remove_hash)
   618			remove_hash_entries(card, kcontrol);
   619	
   620		card->controls_count -= kcontrol->count;
   621		for (idx = 0; idx < kcontrol->count; idx++)
   622			snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_REMOVE, kcontrol, idx);
   623		snd_ctl_free_one(kcontrol);
   624		return 0;
   625	}
   626	
   627	/**
   628	 * snd_ctl_remove_locked - same as snd_ctl_remove(), but card->controls_rwsem
   629	 * is expected to be already locked if necessary.
   630	 */
   631	int snd_ctl_remove_locked(struct snd_card *card,
   632				  struct snd_kcontrol *kcontrol)
 > 633	{

634 return __snd_ctl_remove(card, kcontrol, true);
635 }
636 EXPORT_SYMBOL_GPL(snd_ctl_remove_locked);
637

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

PATCH v5 2/8 ALSA: emu10k1: introduce alternative E-MU D.A.S. mode

In reply to Oswald Buddenhagen

As noted in a previous commit, the E-MU Digital Audio System cards don't try very hard to be Sound Blasters. This commit takes it further and introduces a module option to switch to a completely separate mode.

In that mode:
- The regular PCM playback/capture devices are removed
- The multi-channel playback/capture devices get index 0
- Consequently, the regular mixer controls are also completely removed, as the multi-channel devices already bypassed them.
This is no real loss, given the expected use with a sound server.
- The voice send routing+amount & attenuation controls are also removed, as they are just another mixer. The routing is redundant with the FPGA channel routing, and amounts/att'n can be done in software. The hardware implementation of the latter is also incompatible with 32-bit playback, which we'll add support for later.
- A_EXTOUT is now also free for multi-channel capture, so we use that instead of A_FXBUS2 - this will later simplify using both at once.
- For the same reason, the FX outputs are not listed in /proc anymore
- The device name is changed, so mixer settings don't get mixed up

This continues the pre-existing design with a single multi-channel device where the channels are routed by manual mixer controls from/to the physical ports. De-/multiplexing must be done by the sound server if independent streams are to be used.

An alternative design would be exposing each physical port as a separate device and automatically setting up the routes. This would be a somewhat radical departure from the status quo, and I don't know whether it would be a net benefit. It certainly would be harder to implement, as it would require sync start of streams and a channel allocator (the latter would have the added benefit of properly reporting EMU32 & EDI bus over- allocation, which the mixer does not). And there is only one big multi- channel capture engine, so streams would have to be de-multiplexed by the driver in software - which seems a bit counter-productive if the sound server would re-multiplex them again.

---
v3:
- commit message wording improvements

---
 include/sound/emu10k1.h          |   4 ++
 sound/pci/emu10k1/emu10k1.c      |  29 ++++++---
 sound/pci/emu10k1/emu10k1_main.c |  14 +++-
 sound/pci/emu10k1/emufx.c        |  94 ++++++++++++++++++++++++++-
 sound/pci/emu10k1/emumixer.c     |  93 ++++++++++++++-------------
 sound/pci/emu10k1/emupcm.c       | 107 +++++++++++++++++++++++++++----
 sound/pci/emu10k1/emuproc.c      |   5 ++
 7 files changed, 280 insertions(+), 66 deletions(-)
include/sound/emu10k1.h +4 -0
index 1af9e6819392..29cdae401e12 100644
@@ -1706,6 +1706,7 @@ struct snd_emu10k1 {
 	unsigned int address_mode;		/* address mode */
 	unsigned long dma_mask;			/* PCI DMA mask */
 	bool iommu_workaround;			/* IOMMU workaround needed */
+	bool das_mode;				/* Alternative E-MU Digital Audio System mode */
 	int max_cache_pages;			/* max memory size / PAGE_SIZE */
 	struct snd_dma_buffer silent_page;	/* silent page */
 	struct snd_dma_buffer ptb_pages;	/* page table pages */
@@ -1735,6 +1736,7 @@ struct snd_emu10k1 {
 	struct snd_pcm *pcm_mic;
 	struct snd_pcm *pcm_efx;
 	struct snd_pcm *pcm_multi;
+	struct snd_pcm *pcm_das;
 	struct snd_pcm *pcm_p16v;
 
 	spinlock_t synth_lock;
@@ -1801,17 +1803,19 @@ struct snd_emu10k1 {
 
 int snd_emu10k1_create(struct snd_card *card,
 		       struct pci_dev *pci,
+		       bool emu_das,
 		       unsigned short extin_mask,
 		       unsigned short extout_mask,
 		       long max_cache_bytes,
 		       int enable_ir,
 		       uint subsystem);
 
 int snd_emu10k1_pcm(struct snd_emu10k1 *emu, int device);
 int snd_emu10k1_pcm_mic(struct snd_emu10k1 *emu, int device);
 int snd_emu10k1_pcm_efx(struct snd_emu10k1 *emu, int device);
 int snd_p16v_pcm(struct snd_emu10k1 *emu, int device);
 int snd_p16v_mixer(struct snd_emu10k1 * emu);
+int snd_emu10k1_pcm_das(struct snd_emu10k1 *emu, int device);
 int snd_emu10k1_pcm_multi(struct snd_emu10k1 *emu, int device);
 int snd_emu10k1_fx8010_pcm(struct snd_emu10k1 *emu, int device);
 int snd_emu10k1_mixer(struct snd_emu10k1 * emu, int pcm_device, int multi_device);
sound/pci/emu10k1/emu10k1.c +20 -9
index fe72e7d77241..249f8d6843a3 100644
@@ -25,6 +25,7 @@ MODULE_LICENSE("GPL");
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */
+static bool emu_das[SNDRV_CARDS];
 static int extin[SNDRV_CARDS];
 static int extout[SNDRV_CARDS];
 static int seq_ports[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
@@ -39,6 +40,8 @@ module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for the EMU10K1 soundcard.");
 module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable the EMU10K1 soundcard.");
+module_param_array(emu_das, bool, NULL, 0444);
+MODULE_PARM_DESC(emu_das, "Use alternative E-MU Digital Audio System mode.");
 module_param_array(extin, int, NULL, 0444);
 MODULE_PARM_DESC(extin, "Available external inputs for FX8010. Zero=default.");
 module_param_array(extout, int, NULL, 0444);
@@ -93,22 +96,27 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci,
 		max_buffer_size[dev] = 32;
 	else if (max_buffer_size[dev] > 1024)
 		max_buffer_size[dev] = 1024;
-	err = snd_emu10k1_create(card, pci, extin[dev], extout[dev],
+	err = snd_emu10k1_create(card, pci, emu_das[dev], extin[dev], extout[dev],
 				 (long)max_buffer_size[dev] * 1024 * 1024,
 				 enable_ir[dev], subsystem[dev]);
 	if (err < 0)
 		return err;
-	err = snd_emu10k1_pcm(emu, 0);
+	if (emu->das_mode)
+		err = snd_emu10k1_pcm_das(emu, 0);
+	else
+		err = snd_emu10k1_pcm(emu, 0);
 	if (err < 0)
 		return err;
 	if (emu->card_capabilities->ac97_chip) {
 		err = snd_emu10k1_pcm_mic(emu, 1);
 		if (err < 0)
 			return err;
 	}
-	err = snd_emu10k1_pcm_efx(emu, 2);
-	if (err < 0)
-		return err;
+	if (!emu->das_mode) {
+		err = snd_emu10k1_pcm_efx(emu, 2);
+		if (err < 0)
+			return err;
+	}
 	/* This stores the periods table. */
 	if (emu->card_capabilities->ca0151_chip) { /* P16V */	
 		emu->p16v_buffer =
@@ -125,9 +133,11 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci,
 	if (err < 0)
 		return err;
 
-	err = snd_emu10k1_pcm_multi(emu, 3);
-	if (err < 0)
-		return err;
+	if (!emu->das_mode) {
+		err = snd_emu10k1_pcm_multi(emu, 3);
+		if (err < 0)
+			return err;
+	}
 	if (emu->card_capabilities->ca0151_chip) { /* P16V */
 		err = snd_p16v_pcm(emu, 4);
 		if (err < 0)
@@ -146,7 +156,8 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci,
 	if (err < 0)
 		return err;
 #ifdef ENABLE_SYNTH
-	if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
+	if (emu->das_mode) {
+	} else if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
 			       sizeof(struct snd_emu10k1_synth_arg), &wave) < 0 ||
 	    wave == NULL) {
 		dev_warn(emu->card->dev,
sound/pci/emu10k1/emu10k1_main.c +13 -1
index de5c41e578e1..b50bb6a55a6d 100644
@@ -1505,6 +1505,7 @@ static void snd_emu10k1_detect_iommu(struct snd_emu10k1 *emu)
 
 int snd_emu10k1_create(struct snd_card *card,
 		       struct pci_dev *pci,
+		       bool emu_das,
 		       unsigned short extin_mask,
 		       unsigned short extout_mask,
 		       long max_cache_bytes,
@@ -1584,8 +1585,19 @@ int snd_emu10k1_create(struct snd_card *card,
 			c->name, pci->vendor, pci->device,
 			emu->serial);
 
-	if (!*card->id && c->id)
+	if (c->emu_model) {
+		if (emu_das)
+			emu->das_mode = 1;
+		else
+			dev_notice(card->dev,
+				"You may want to use emu_das=1 with your %s\n", c->name);
+	}
+
+	if (!*card->id && c->id) {
 		strscpy(card->id, c->id, sizeof(card->id));
+		if (emu->das_mode)
+			strlcat(card->id, "das", sizeof(card->id));
+	}
 
 	is_audigy = emu->audigy = c->emu10k2_chip;
 
sound/pci/emu10k1/emufx.c +93 -1

106 lines not on this page · raw message

sound/pci/emu10k1/emumixer.c +49 -44

100 lines not on this page · raw message

sound/pci/emu10k1/emupcm.c +96 -11

178 lines not on this page · raw message

sound/pci/emu10k1/emuproc.c +5 -0
index 2f80fd91017c..24a085a953f7 100644
@@ -80,6 +80,11 @@ static void snd_emu10k1_proc_read(struct snd_info_entry *entry,
 	snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
 	snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
 
+	// The following are internal details in D.A.S. mode,
+	// so there is no use in displaying them to the user.
+	if (emu->das_mode)
+		return;
+
 	snd_iprintf(buffer, "\nEffect Send Routing & Amounts:\n");
 	for (idx = 0; idx < NUM_G; idx++) {
 		ptrx = snd_emu10k1_ptr_read(emu, PTRX, idx);
Signature · 1 line
2.40.0.152.g15d061e6df
#4 lore raw

PATCH v5 3/8 ALSA: emu10k1: improve mixer control naming in E-MU D.A.S. mode

In reply to Oswald Buddenhagen

Use the clearer "PbChn <n>" instead of "DSP <n>" for the source names. In particular, this is much less confusing in the capture source selection - "DSP 0" having the source "DSP 0" really didn't help. I didn't use "Playback Channel <n>", because that would be a tad too long to be sensibly displayed in alsamixer.

The capture enums also get a "DSP" => "CpChn" replacement.

I used zero-padded decimals, so the capture elements are properly sorted in alsamixer. I found hex too confusing.

Note that unlike in the legacy mixer, we define enum values only for actually "wired" channels.

I'm leaving the legacy mixer alone, as I don't want to completely invalidate saved mixer states. This introduces some bloat, but it seems bearable.

---
 sound/pci/emu10k1/emumixer.c | 108 ++++++++++++++++++++++++++---------
 1 file changed, 81 insertions(+), 27 deletions(-)
sound/pci/emu10k1/emumixer.c +81 -27
index 740bc6692559..34cf1219c99d 100644
@@ -100,6 +100,12 @@ static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
 	"DSP 16", "DSP 17", "DSP 18", "DSP 19", "DSP 20", "DSP 21", "DSP 22", "DSP 23", \
 	"DSP 24", "DSP 25", "DSP 26", "DSP 27", "DSP 28", "DSP 29", "DSP 30", "DSP 31"
 
+#define PB_TEXTS \
+	"PbChn 00", "PbChn 01", "PbChn 02", "PbChn 03", \
+	"PbChn 04", "PbChn 05", "PbChn 06", "PbChn 07", \
+	"PbChn 08", "PbChn 09", "PbChn 10", "PbChn 11", \
+	"PbChn 12", "PbChn 13", "PbChn 14", "PbChn 15"
+
 #define PAIR_TEXTS(base, one, two) PAIR_PS(base, one, two, "")
 #define LR_TEXTS(base) LR_PS(base, "")
 #define ADAT_TEXTS(pfx) ADAT_PS(pfx, "")
@@ -155,6 +161,11 @@ static const char * const emu1010_src_texts[] = {
 	DSP_TEXTS,
 };
 
+static const char * const emu1010_das_src_texts[] = {
+	EMU1010_COMMON_TEXTS,
+	PB_TEXTS,
+};
+
 static const unsigned short emu1010_src_regs[] = {
 	EMU_SRC_SILENCE,
 	PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
@@ -186,6 +197,11 @@ static const char * const emu1010b_src_texts[] = {
 	DSP_TEXTS,
 };
 
+static const char * const emu1010b_das_src_texts[] = {
+	EMU1010b_COMMON_TEXTS,
+	PB_TEXTS,
+};
+
 static const unsigned short emu1010b_src_regs[] = {
 	EMU_SRC_SILENCE,
 	PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
@@ -215,6 +231,11 @@ static const char * const emu1616_src_texts[] = {
 	DSP_TEXTS,
 };
 
+static const char * const emu1616_das_src_texts[] = {
+	EMU1616_COMMON_TEXTS,
+	PB_TEXTS,
+};
+
 static const unsigned short emu1616_src_regs[] = {
 	EMU_SRC_SILENCE,
 	PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
@@ -238,6 +259,11 @@ static const char * const emu0404_src_texts[] = {
 	DSP_TEXTS,
 };
 
+static const char * const emu0404_das_src_texts[] = {
+	EMU0404_COMMON_TEXTS,
+	PB_TEXTS,
+};
+
 static const unsigned short emu0404_src_regs[] = {
 	EMU_SRC_SILENCE,
 	LR_REGS(EMU_SRC_HAMOA_ADC),
@@ -421,6 +447,25 @@ static const char * const emu1010_input_texts[] = {
 };
 static_assert(ARRAY_SIZE(emu1010_input_texts) <= NUM_INPUT_DESTS);
 
+static const char * const emu1010_das_input_texts[] = {
+	"CpChn 00 Capture Enum",
+	"CpChn 01 Capture Enum",
+	"CpChn 02 Capture Enum",
+	"CpChn 03 Capture Enum",
+	"CpChn 04 Capture Enum",
+	"CpChn 05 Capture Enum",
+	"CpChn 06 Capture Enum",
+	"CpChn 07 Capture Enum",
+	"CpChn 08 Capture Enum",
+	"CpChn 09 Capture Enum",
+	"CpChn 10 Capture Enum",
+	"CpChn 11 Capture Enum",
+	"CpChn 12 Capture Enum",
+	"CpChn 13 Capture Enum",
+	"CpChn 14 Capture Enum",
+	"CpChn 15 Capture Enum",
+};
+
 static const unsigned short emu1010_input_dst[] = {
 	EMU_DST_ALICE2_EMU32_0,
 	EMU_DST_ALICE2_EMU32_1,
@@ -498,78 +543,78 @@ static const unsigned short emu0404_input_dflt[] = {
 };
 
 struct snd_emu1010_routing_info {
-	const char * const *src_texts;
+	const char * const *src_texts[2];
 	const char * const *out_texts;
 	const unsigned short *src_regs;
 	const unsigned short *out_regs;
 	const unsigned short *in_regs;
 	const unsigned short *out_dflts;
 	const unsigned short *in_dflts;
-	unsigned n_srcs;
+	unsigned n_srcs[2];
 	unsigned n_outs;
-	unsigned n_ins;
+	unsigned n_ins[2];
 };
 
 static const struct snd_emu1010_routing_info emu1010_routing_info[] = {
 	{
 		/* rev1 1010 */
 		.src_regs = emu1010_src_regs,
-		.src_texts = emu1010_src_texts,
-		.n_srcs = ARRAY_SIZE(emu1010_src_texts),
+		.src_texts = { emu1010_src_texts, emu1010_das_src_texts },
+		.n_srcs = { ARRAY_SIZE(emu1010_src_texts), ARRAY_SIZE(emu1010_das_src_texts) },
 
 		.out_dflts = emu1010_output_dflt,
 		.out_regs = emu1010_output_dst,
 		.out_texts = emu1010_output_texts,
 		.n_outs = ARRAY_SIZE(emu1010_output_dst),
 
 		.in_dflts = emu1010_input_dflt,
 		.in_regs = emu1010_input_dst,
-		.n_ins = ARRAY_SIZE(emu1010_input_dst),
+		.n_ins = { ARRAY_SIZE(emu1010_input_dst), 16 },
 	},
 	{
 		/* rev2 1010 */
 		.src_regs = emu1010b_src_regs,
-		.src_texts = emu1010b_src_texts,
-		.n_srcs = ARRAY_SIZE(emu1010b_src_texts),
+		.src_texts = { emu1010b_src_texts, emu1010b_das_src_texts },
+		.n_srcs = { ARRAY_SIZE(emu1010b_src_texts), ARRAY_SIZE(emu1010b_das_src_texts) },
 
 		.out_dflts = emu1010b_output_dflt,
 		.out_regs = emu1010b_output_dst,
 		.out_texts = snd_emu1010b_output_texts,
 		.n_outs = ARRAY_SIZE(emu1010b_output_dst),
 
 		.in_dflts = emu1010_input_dflt,
 		.in_regs = emu1010_input_dst,
-		.n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
+		.n_ins = { ARRAY_SIZE(emu1010_input_dst) - 6, 16 },
 	},
 	{
 		/* 1616(m) cardbus */
 		.src_regs = emu1616_src_regs,
-		.src_texts = emu1616_src_texts,
-		.n_srcs = ARRAY_SIZE(emu1616_src_texts),
+		.src_texts = { emu1616_src_texts, emu1616_das_src_texts },
+		.n_srcs = { ARRAY_SIZE(emu1616_src_texts), ARRAY_SIZE(emu1616_das_src_texts) },
 
 		.out_dflts = emu1616_output_dflt,
 		.out_regs = emu1616_output_dst,
 		.out_texts = snd_emu1616_output_texts,
 		.n_outs = ARRAY_SIZE(emu1616_output_dst),
 
 		.in_dflts = emu1010_input_dflt,
 		.in_regs = emu1010_input_dst,
-		.n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
+		.n_ins = { ARRAY_SIZE(emu1010_input_dst) - 6, 16 },
 	},
 	{
 		/* 0404 */
 		.src_regs = emu0404_src_regs,
-		.src_texts = emu0404_src_texts,
-		.n_srcs = ARRAY_SIZE(emu0404_src_texts),
+		.src_texts = { emu0404_src_texts, emu0404_das_src_texts },
+		.n_srcs = { ARRAY_SIZE(emu0404_src_texts), ARRAY_SIZE(emu0404_das_src_texts) },
 
 		.out_dflts = emu0404_output_dflt,
 		.out_regs = emu0404_output_dst,
 		.out_texts = snd_emu0404_output_texts,
 		.n_outs = ARRAY_SIZE(emu0404_output_dflt),
 
 		.in_dflts = emu0404_input_dflt,
 		.in_regs = emu1010_input_dst,
-		.n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
+		.n_ins = { ARRAY_SIZE(emu1010_input_dst) - 6, 16 },
 	},
 };
 
@@ -602,32 +647,34 @@ static void snd_emu1010_apply_sources(struct snd_emu10k1 *emu)
 {
 	const struct snd_emu1010_routing_info *emu_ri =
 		&emu1010_routing_info[emu1010_idx(emu)];
+	unsigned iidx = emu->das_mode;
 
 	for (unsigned i = 0; i < emu_ri->n_outs; i++)
 		snd_emu1010_output_source_apply(
 			emu, i, emu->emu1010.output_source[i]);
-	for (unsigned i = 0; i < emu_ri->n_ins; i++)
+	for (unsigned i = 0; i < emu_ri->n_ins[iidx]; i++)
 		snd_emu1010_input_source_apply(
 			emu, i, emu->emu1010.input_source[i]);
 }
 
 static u8 emu1010_map_source(const struct snd_emu1010_routing_info *emu_ri,
-			     unsigned val)
+			     unsigned das_mode, unsigned val)
 {
-	for (unsigned i = 0; i < emu_ri->n_srcs; i++)
+	for (unsigned i = 0; i < emu_ri->n_srcs[das_mode]; i++)
 		if (val == emu_ri->src_regs[i])
 			return i;
 	return 0;
 }
 
 static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol,
 						struct snd_ctl_elem_info *uinfo)
 {
 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
 	const struct snd_emu1010_routing_info *emu_ri =
 		&emu1010_routing_info[emu1010_idx(emu)];
+	unsigned iidx = emu->das_mode;
 
-	return snd_ctl_enum_info(uinfo, 1, emu_ri->n_srcs, emu_ri->src_texts);
+	return snd_ctl_enum_info(uinfo, 1, emu_ri->n_srcs[iidx], emu_ri->src_texts[iidx]);
 }
 
 static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol,
@@ -650,11 +697,12 @@ static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol,
 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
 	const struct snd_emu1010_routing_info *emu_ri =
 		&emu1010_routing_info[emu1010_idx(emu)];
+	unsigned iidx = emu->das_mode;
 	unsigned val = ucontrol->value.enumerated.item[0];
 	unsigned channel = kcontrol->private_value;
 	int change;
 
-	if (val >= emu_ri->n_srcs)
+	if (val >= emu_ri->n_srcs[iidx])
 		return -EINVAL;
 	if (channel >= emu_ri->n_outs)
 		return -EINVAL;
@@ -680,27 +728,29 @@ static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol,
 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
 	const struct snd_emu1010_routing_info *emu_ri =
 		&emu1010_routing_info[emu1010_idx(emu)];
+	unsigned iidx = emu->das_mode;
 	unsigned channel = kcontrol->private_value;
 
-	if (channel >= emu_ri->n_ins)
+	if (channel >= emu_ri->n_ins[iidx])
 		return -EINVAL;
 	ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel];
 	return 0;
 }
 
 static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
                                  struct snd_ctl_elem_value *ucontrol)
 {
 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
 	const struct snd_emu1010_routing_info *emu_ri =
 		&emu1010_routing_info[emu1010_idx(emu)];
+	unsigned iidx = emu->das_mode;
 	unsigned val = ucontrol->value.enumerated.item[0];
 	unsigned channel = kcontrol->private_value;
 	int change;
 
-	if (val >= emu_ri->n_srcs)
+	if (val >= emu_ri->n_srcs[iidx])
 		return -EINVAL;
-	if (channel >= emu_ri->n_ins)
+	if (channel >= emu_ri->n_ins[iidx])
 		return -EINVAL;
 	change = (emu->emu1010.input_source[channel] != val);
 	if (change) {
@@ -722,14 +772,17 @@ static int add_emu1010_source_mixers(struct snd_emu10k1 *emu)
 {
 	const struct snd_emu1010_routing_info *emu_ri =
 		&emu1010_routing_info[emu1010_idx(emu)];
+	unsigned iidx = emu->das_mode;
 	int err;
 
 	err = add_ctls(emu, &emu1010_output_source_ctl,
 		       emu_ri->out_texts, emu_ri->n_outs);
 	if (err < 0)
 		return err;
 	err = add_ctls(emu, &emu1010_input_source_ctl,
-		       emu1010_input_texts, emu_ri->n_ins);
+		       iidx ? emu1010_das_input_texts :
+			      emu1010_input_texts,
+		       emu_ri->n_ins[iidx]);
 	return err;
 }
 
@@ -2321,13 +2374,14 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
 		const struct snd_emu1010_routing_info *emu_ri =
 			&emu1010_routing_info[emu_idx];
 		const struct snd_emu1010_pads_info *emu_pi = &emu1010_pads_info[emu_idx];
+		int midx = emu->das_mode;
 
-		for (i = 0; i < emu_ri->n_ins; i++)
+		for (i = 0; i < emu_ri->n_ins[midx]; i++)
 			emu->emu1010.input_source[i] =
-				emu1010_map_source(emu_ri, emu_ri->in_dflts[i]);
+				emu1010_map_source(emu_ri, midx, emu_ri->in_dflts[i]);
 		for (i = 0; i < emu_ri->n_outs; i++)
 			emu->emu1010.output_source[i] =
-				emu1010_map_source(emu_ri, emu_ri->out_dflts[i]);
+				emu1010_map_source(emu_ri, midx, emu_ri->out_dflts[i]);
 		snd_emu1010_apply_sources(emu);
 
 		kctl = emu->ctl_clock_source = snd_ctl_new1(&snd_emu1010_clock_source, emu);
Signature · 1 line
2.40.0.152.g15d061e6df
#5 lore raw

PATCH v5 4/8 ALSA: emu10k1: make playback in E-MU D.A.S. mode 32-bit

In reply to Oswald Buddenhagen

Each channel now uses a stereo voice pair. But the FX send amounts and attenuation are per voice, so we have to use fixed values tuned to the DSP code to avoid messing up the split samples.

As "regular" mode allows manipulating the amounts and att'n via mixer controls, we can either:
- "Fake" them with DSP code, which doesn't seem worth the bother
- Ignore them, which doesn't seem very nice

So 32-bit playback simply remains unavailable in non-D.A.S. mode.

---
 sound/pci/emu10k1/emufx.c  | 18 ++++++++++-----
 sound/pci/emu10k1/emupcm.c | 46 +++++++++++++++++++++++++-------------
 2 files changed, 43 insertions(+), 21 deletions(-)
sound/pci/emu10k1/emufx.c +13 -5
index 8e33cc596825..9f27f07d5271 100644
@@ -1279,7 +1279,8 @@ static int _snd_emu10k1_das_init_efx(struct snd_emu10k1 *emu)
 {
 	enum {
 		ENUM_GPR(bit_shifter16, 1),
-		ENUM_GPR(tmp, 1),
+		ENUM_GPR(lowword_mask, 1),
+		ENUM_GPR(tmp, 2),
 		num_static_gprs
 	};
 	int gpr = num_static_gprs;
@@ -1310,10 +1311,14 @@ static int _snd_emu10k1_das_init_efx(struct snd_emu10k1 *emu)
 
 	gpr_map = icode->gpr_map;
 	gpr_map[bit_shifter16] = 0x00008000;
+	gpr_map[lowword_mask] = 0x0000ffff;
 
 	if (emu->card_capabilities->ca0108_chip) {
-		for (int z = 0; z < 16; z++)
-			A_OP(icode, &ptr, iMACINT0, A3_EMU32OUT(z), A_C_00000000, A_FXBUS(z), A_C_00000002);
+		for (int z = 0; z < 16; z++) {
+			A_OP(icode, &ptr, iMAC0, A_GPR(tmp), A_C_00000000, A_FXBUS(z * 2), A_C_00010000); // >> 15
+			A_OP(icode, &ptr, iMACINT0, A_GPR(tmp + 1), A_C_00000000, A_FXBUS(z * 2 + 1), A_C_00000002); // << 1
+			A_OP(icode, &ptr, iANDXOR, A3_EMU32OUT(z), A_GPR(tmp), A_GPR(lowword_mask), A_GPR(tmp + 1));
+		}
 
 		snd_emu10k1_audigy_dsp_convert_32_to_2x16(
 			icode, &ptr, tmp, bit_shifter16, A3_EMU32IN(0), A_EXTOUT(0));
@@ -1326,8 +1331,11 @@ static int _snd_emu10k1_das_init_efx(struct snd_emu10k1 *emu)
 			gpr_map[gpr++] = 0x00000000;
 		}
 	} else {
-		for (int z = 0; z < 16; z++)
-			A_OP(icode, &ptr, iMACINT0, A_EMU32OUTL(z), A_C_00000000, A_FXBUS(z), A_C_00000002);
+		for (int z = 0; z < 16; z++) {
+			A_OP(icode, &ptr, iMAC0, A_GPR(tmp), A_C_00000000, A_FXBUS(z * 2), A_C_00010000); // >> 15
+			A_OP(icode, &ptr, iMACINT0, A_GPR(tmp + 1), A_C_00000000, A_FXBUS(z * 2 + 1), A_C_00000002); // << 1
+			A_OP(icode, &ptr, iANDXOR, A_EMU32OUTL(z), A_GPR(tmp), A_GPR(lowword_mask), A_GPR(tmp + 1));
+		}
 
 		/* Note that the Alice2 DSPs have 6 I2S inputs which we don't use. */
 		snd_emu10k1_audigy_dsp_convert_32_to_2x16(
sound/pci/emu10k1/emupcm.c +30 -16

146 lines not on this page · raw message

Signature · 1 line
2.40.0.152.g15d061e6df
#6 lore raw

PATCH v5 5/8 ALSA: emu10k1: add support for 2x/4x word clocks in E-MU D.A.S. mode

In reply to Oswald Buddenhagen

This lays the groundwork for supporting 88.2/96/176.4/192 kHz rates without actually doing so yet - we simply multi-feed the same samples on playback, and throw away the excess ones on capture. Input-to-output monitoring does actually use the full sample rate, though.

Due to hardware constraints, changing the clock multiplier (CM) changes the available audio ports and the number of available channels. This has an impact on the channel routing mixer controls. One way to deal with this would be presenting a union of all possibilities, and simply ignoring currently inapplicable settings. However, this would be a terrible user experience, and go against the spirit of prior patches aimed at decluttering the mixer. Therefore, we do dynamic reconfiguration (DR) of the mixer in response to changing the CM.

DR is somewhat controversial, as it has the potential to crash poorly programmed applications. But that in itself isn't a very convincing argument against it, as by that logic we'd have to ban all hot-plugging. Such crashes would also not really qualify as regressions, as the D.A.S. mode is a new opt-in feature, and therefore no previously stable setups would be impacted. Also, pendantically, the driver already had DR via SNDRV_EMU10K1_IOCTL_CODE_POKE. A somewhat valid concern is that changing mixer settings is a non-privileged operation and therefore potential crashes could be exploited for a somewhat more impactful nuisance attack on another user than messing with the mixer per se. However, systemd & co. limit device access to the user currently logged in on the seat owning the device.

There is a specific concern about doing DR in response to changing a mixer control's value, as an application may legitimately react to DR by updating all mixer settings in turn. However, that update should write the same value to the clock multiplier, thus terminating the recursion.

One may limit DR to merely disabling inapplicable controls, in the hope that this would be better handled than completely tearing down and re-creating controls as we do. However, there is no guarantee for that. And because it is impossible to disable particular enum values within a control, it would be necessary to have three complete sets of per-channel controls. This would yield an extremely cluttered and confusing UI if the application (reasonably) chose to merely visually disable inactive controls rather than hiding them.

We do the DR synchronously from within snd_emu1010_clock_shift_put(). This was enabled by commit 5bbb1ab5bd ("control: use counting semaphore as write lock for ELEM_WRITE operation"); we merely need to make add_ctls() use snd_ctl_add_locked() instead of snd_ctl_add(), so it doesn't deadlock. That also affects the initial creation of the controls, which is OK, as that is done before the card is registered, where no concurrent access can occur.

It would be possible to do the DR in a tasklet after the ioctl finishes. However, it is not obvious what actual problem that would solve, and the added asynchronicity would significantly complicate matters, esp. wrt. the batch updates expected during mixer state restoration.

---
v4:
- adjust to recent locking changes

v3:
- locking adjustments

v2:
- expanded commit message

---
 include/sound/emu10k1.h          |   3 +
 sound/pci/emu10k1/emu10k1_main.c |  13 +-
 sound/pci/emu10k1/emumixer.c     | 649 ++++++++++++++++++++++++++++---
 sound/pci/emu10k1/emupcm.c       |  41 +-
 sound/pci/emu10k1/io.c           |  30 +-
 5 files changed, 666 insertions(+), 70 deletions(-)
include/sound/emu10k1.h +3 -0
index 29cdae401e12..aafa6ad2c5a0 100644
@@ -1682,6 +1682,8 @@ struct snd_emu1010 {
 	unsigned int word_clock;  /* Cached effective value */
 	unsigned int clock_source;
 	unsigned int clock_fallback;
+	unsigned int clock_shift;  /* EMU_HANA_WCLOCK_MULT_MASK >> 3 */
+	unsigned int clock_users;
 	unsigned int optical_in; /* 0:SPDIF, 1:ADAT */
 	unsigned int optical_out; /* 0:SPDIF, 1:ADAT */
 	struct work_struct firmware_work;
@@ -1763,6 +1765,7 @@ struct snd_emu10k1 {
 	struct snd_kcontrol *ctl_efx_send_volume;
 	struct snd_kcontrol *ctl_efx_attn;
 	struct snd_kcontrol *ctl_clock_source;
+	struct snd_kcontrol *ctl_clock_shift;
 
 	void (*hwvol_interrupt)(struct snd_emu10k1 *emu, unsigned int status);
 	void (*capture_interrupt)(struct snd_emu10k1 *emu, unsigned int status);
sound/pci/emu10k1/emu10k1_main.c +3 -10
index b50bb6a55a6d..0b660a7d0ef7 100644
@@ -798,7 +798,8 @@ static void emu1010_clock_work(struct work_struct *work)
 	spin_lock_irq(&emu->reg_lock);
 	// This is the only thing that can actually happen.
 	emu->emu1010.clock_source = emu->emu1010.clock_fallback;
-	emu->emu1010.wclock = 1 - emu->emu1010.clock_source;
+	emu->emu1010.wclock = (emu->emu1010.wclock & ~EMU_HANA_WCLOCK_SRC_MASK) |
+				(1 - emu->emu1010.clock_source);
 	snd_emu1010_update_clock(emu);
 	spin_unlock_irq(&emu->reg_lock);
 	snd_ctl_build_ioff(&id, emu->ctl_clock_source, 0);
@@ -822,14 +823,6 @@ static void emu1010_interrupt(struct snd_emu10k1 *emu)
 		schedule_work(&emu->emu1010.clock_work);
 }
 
-/*
- * Current status of the driver:
- * ----------------------------
- * 	* only 44.1/48kHz supported (the MS Win driver supports up to 192 kHz)
- * 	* PCM device nb. 2:
- *		16 x 16-bit playback - snd_emu10k1_fx8010_playback_ops
- * 		16 x 32-bit capture - snd_emu10k1_capture_efx_ops
- */
 static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
 {
 	u32 tmp, tmp2, reg;
@@ -924,12 +917,12 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
 
 	emu->emu1010.clock_source = 1;  /* 48000 */
 	emu->emu1010.clock_fallback = 1;  /* 48000 */
+	emu->emu1010.clock_shift = 0;  /* 1x */
 	/* Default WCLK set to 48kHz. */
 	snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K);
 	/* Word Clock source, Internal 48kHz x1 */
 	emu->emu1010.wclock = EMU_HANA_WCLOCK_INT_48K;
 	snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K);
-	/* snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X); */
 	snd_emu1010_update_clock(emu);
 
 	// The routes are all set to EMU_SRC_SILENCE due to the reset,
sound/pci/emu10k1/emumixer.c +592 -57

910 lines not on this page · raw message

sound/pci/emu10k1/emupcm.c +39 -2

79 lines not on this page · raw message

sound/pci/emu10k1/io.c +29 -1
index 74df2330015f..5c920cf6425b 100644
@@ -404,19 +404,47 @@ void snd_emu1010_update_clock(struct snd_emu10k1 *emu)
 		clock = 48000;
 		leds = EMU_HANA_DOCK_LEDS_2_48K;
 		break;
+	case EMU_HANA_WCLOCK_INT_44_1K | EMU_HANA_WCLOCK_2X:
+		clock = 44100;
+		leds = 0;
+		break;
+	case EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_2X:
+		clock = 48000;
+		leds = EMU_HANA_DOCK_LEDS_2_96K;
+		break;
+	case EMU_HANA_WCLOCK_INT_44_1K | EMU_HANA_WCLOCK_4X:
+		clock = 44100;
+		leds = 0;
+		break;
+	case EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X:
+		clock = 48000;
+		leds = EMU_HANA_DOCK_LEDS_2_192K;
+		break;
 	default:
 		clock = snd_emu1010_get_raw_rate(
 				emu, emu->emu1010.wclock & EMU_HANA_WCLOCK_SRC_MASK);
 		// The raw rate reading is rather coarse (it cannot accurately
 		// represent 44.1 kHz) and fluctuates slightly. Luckily, the
 		// clock comes from digital inputs, which use standardized rates.
 		// So we round to the closest standard rate and ignore discrepancies.
 		if (clock < 46000) {
 			clock = 44100;
 			leds = EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_44K;
-		} else {
+		} else if (clock < 75000) {
 			clock = 48000;
 			leds = EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_48K;
+		} else if (clock < 92000) {
+			clock = 44100;
+			leds = EMU_HANA_DOCK_LEDS_2_EXT;
+		} else if (clock < 150000) {
+			clock = 48000;
+			leds = EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_96K;
+		} else if (clock < 184000) {
+			clock = 44100;
+			leds = EMU_HANA_DOCK_LEDS_2_EXT;
+		} else {
+			clock = 48000;
+			leds = EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_192K;
 		}
 		break;
 	}
Signature · 1 line
2.40.0.152.g15d061e6df
#7 lore raw

PATCH v5 6/8 ALSA: emu10k1: add high-rate capture in E-MU D.A.S. mode

In reply to Oswald Buddenhagen

This is tested only with a 0404b card, so it is unclear whether the EMU_DST_TINA_EMU32B (1010b) & EMU_DST_TINA2_EMU32B (1616m CardBus) register definitions (derived from comments in the same file) are correct, and whether they actually lack the one-sample delay relative to EMU_DST_ALICE2_EMU32_0.

---
 include/sound/emu10k1.h          |   4 ++
 sound/pci/emu10k1/emu10k1_main.c |   3 +
 sound/pci/emu10k1/emufx.c        |   4 +-
 sound/pci/emu10k1/emumixer.c     | 107 +++++++++++++++++++++++++++----
 sound/pci/emu10k1/emupcm.c       |  40 +++++++++---
 5 files changed, 135 insertions(+), 23 deletions(-)
include/sound/emu10k1.h +4 -0
index aafa6ad2c5a0..fd4cf7d6eb3f 100644
@@ -1292,6 +1292,9 @@ SUB_REG_NC(A_EHC, A_I2S_CAPTURE_RATE, 0x00000e00)  /* This sets the capture PCM
 #define EMU_DST_HAMOA_DAC_RIGHT4	0x0307	/* Hamoa DAC Right, 4th or 192kHz */
 // In S/MUX mode, the samples of one channel are adjacent.
 #define EMU_DST_HANA_ADAT	0x0400	/* Hana ADAT 8 channel out +0 to +7 */
+/* FIXME: It is not clear whether these are actually enumerated like that. */
+#define EMU_DST_TINA2_EMU32B	0x0400	/* 16 EMU32 channels to Tina2 +0 to +0xf */
+#define EMU_DST_TINA_EMU32B	0x0500	/* 16 EMU32 channels to Tina +0 to +0xf */
 #define EMU_DST_ALICE_I2S0_LEFT		0x0500	/* Alice2 I2S0 Left */
 #define EMU_DST_ALICE_I2S0_RIGHT	0x0501	/* Alice2 I2S0 Right */
 #define EMU_DST_ALICE_I2S1_LEFT		0x0600	/* Alice2 I2S1 Left */
@@ -1654,6 +1657,7 @@ struct snd_emu_chip_details {
 	unsigned int ca0108_chip:1;	/* Audigy 2 Value */
 	unsigned int ca_cardbus_chip:1;	/* Audigy 2 ZS Notebook */
 	unsigned int ca0151_chip:1;	/* P16V */
+	unsigned int emu_in_32:1;	/* EMU32 input has 32 (connected) channels */
 	unsigned int spk20:1;		/* Stereo only */
 	unsigned int spk71:1;		/* Has 7.1 speakers */
 	unsigned int no_adat:1;		/* Has no ADAT, only SPDIF */
sound/pci/emu10k1/emu10k1_main.c +3 -0
index 0b660a7d0ef7..2125925c2d5e 100644
@@ -1109,6 +1109,7 @@ static const struct snd_emu_chip_details emu_chip_details[] = {
 	 .emu10k2_chip = 1,
 	 .ca0108_chip = 1,
 	 .ca_cardbus_chip = 1,
+	 .emu_in_32 = 1,
 	 .spk71 = 1 ,
 	 .emu_model = EMU_MODEL_EMU1616},
 	/* Tested by [email protected] 4th Nov 2007. */
@@ -1121,6 +1122,7 @@ static const struct snd_emu_chip_details emu_chip_details[] = {
 	 .id = "EMU1010",
 	 .emu10k2_chip = 1,
 	 .ca0108_chip = 1,
+	 .emu_in_32 = 1,
 	 .spk71 = 1,
 	 .emu_model = EMU_MODEL_EMU1010B}, /* EMU 1010 new revision */
 	/* Tested by Maxim Kachur <[email protected]> 17th Oct 2012. */
@@ -1135,6 +1137,7 @@ static const struct snd_emu_chip_details emu_chip_details[] = {
 	 .id = "EMU1010",
 	 .emu10k2_chip = 1,
 	 .ca0108_chip = 1,
+	 .emu_in_32 = 1,
 	 .spk71 = 1,
 	 .emu_model = EMU_MODEL_EMU1010B}, /* EMU 1010 PCIe */
 	/* Tested by [email protected] 8th July 2005. */
sound/pci/emu10k1/emufx.c +3 -1
index 9f27f07d5271..2f757096c2ee 100644
@@ -1314,17 +1314,19 @@ static int _snd_emu10k1_das_init_efx(struct snd_emu10k1 *emu)
 	gpr_map[lowword_mask] = 0x0000ffff;
 
 	if (emu->card_capabilities->ca0108_chip) {
+		int num_cap = emu->card_capabilities->emu_in_32 ? 32 : 16;
+
 		for (int z = 0; z < 16; z++) {
 			A_OP(icode, &ptr, iMAC0, A_GPR(tmp), A_C_00000000, A_FXBUS(z * 2), A_C_00010000); // >> 15
 			A_OP(icode, &ptr, iMACINT0, A_GPR(tmp + 1), A_C_00000000, A_FXBUS(z * 2 + 1), A_C_00000002); // << 1
 			A_OP(icode, &ptr, iANDXOR, A3_EMU32OUT(z), A_GPR(tmp), A_GPR(lowword_mask), A_GPR(tmp + 1));
 		}
 
 		snd_emu10k1_audigy_dsp_convert_32_to_2x16(
 			icode, &ptr, tmp, bit_shifter16, A3_EMU32IN(0), A_EXTOUT(0));
 		// A3_EMU32IN(0) is delayed by one sample, so all other A3_EMU32IN channels
 		// need to be delayed as well; we use an auxiliary register for that.
-		for (int z = 1; z < 16; z++) {
+		for (int z = 1; z < num_cap; z++) {
 			snd_emu10k1_audigy_dsp_convert_32_to_2x16(
 				icode, &ptr, tmp, bit_shifter16, A_GPR(gpr), A_EXTOUT(z * 2));
 			A_OP(icode, &ptr, iACC3, A_GPR(gpr), A3_EMU32IN(z), A_C_00000000, A_C_00000000);
sound/pci/emu10k1/emumixer.c +95 -12

151 lines not on this page · raw message

sound/pci/emu10k1/emupcm.c +30 -10
index 408db0d7c959..769096e05571 100644
@@ -230,6 +230,16 @@ static void snd_emu1010_constrain_efx_rate(struct snd_emu10k1 *emu,
 	runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
 }
 
+static void snd_emu1010_constrain_efx_capture_rate(struct snd_emu10k1 *emu,
+						   struct snd_pcm_runtime *runtime)
+{
+	int rate;
+
+	rate = emu->emu1010.word_clock << emu->emu1010.clock_shift;
+	runtime->hw.rate_min = runtime->hw.rate_max = rate;
+	runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate);
+}
+
 static unsigned int emu10k1_calc_pitch_target(unsigned int rate)
 {
 	unsigned int pitch_target;
@@ -564,8 +574,22 @@ static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream)
 		if (emu->card_capabilities->emu_model) {
 			unsigned mask = 0xffffffff >> (32 - runtime->channels * 2);
 			if (emu->das_mode) {
+				unsigned shift = emu->emu1010.clock_shift;
+				if (shift) {
+					if (emu->card_capabilities->emu_in_32) {
+						if (shift == 2)
+							mask |= mask << 16;
+						epcm->capture_cr_val2 = mask;
+					} else {
+						if (shift == 2)
+							mask |= mask << 8;
+						mask |= mask << 16;
+						epcm->capture_cr_val2 = 0;
+					}
+				} else {
+					epcm->capture_cr_val2 = 0;
+				}
 				epcm->capture_cr_val = mask;
-				epcm->capture_cr_val2 = 0;
 			} else {
 				// The upper 32 16-bit capture voices, two for each of the 16 32-bit channels.
 				// The lower voices are occupied by A_EXTOUT_*_CAP*.
@@ -1440,26 +1464,22 @@ static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream *substream)
 	substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
 	runtime->hw = snd_emu10k1_capture_efx;
 	if (emu->card_capabilities->emu_model) {
-		snd_emu1010_constrain_efx_rate(emu, runtime);
+		snd_emu1010_constrain_efx_capture_rate(emu, runtime);
 		/*
 		 * There are 32 mono channels of 16bits each.
 		 * 24bit Audio uses 2x channels over 16bit,
 		 * 96kHz uses 2x channels over 48kHz,
 		 * 192kHz uses 4x channels over 48kHz.
 		 * So, for 48kHz 24bit, one has 16 channels,
 		 * for 96kHz 24bit, one has 8 channels,
 		 * for 192kHz 24bit, one has 4 channels.
 		 * 1010rev2 and 1616(m) cards have double that,
 		 * but we don't exceed 16 channels anyway.
 		 */
-#if 0
-		/* For 96kHz */
-		runtime->hw.channels_min = runtime->hw.channels_max = 4;
-#endif
-#if 0
-		/* For 192kHz */
-		runtime->hw.channels_min = runtime->hw.channels_max = 2;
-#endif
+		if (emu->das_mode)
+			runtime->hw.channels_max =
+				min(16, 32 >> (emu->emu1010.clock_shift +
+					       !emu->card_capabilities->emu_in_32));
 		runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
 	} else {
 		spin_lock_irq(&emu->reg_lock);
Signature · 1 line
2.40.0.152.g15d061e6df
#8 lore raw

PATCH v5 7/8 ALSA: emu10k1: add high-rate playback in E-MU D.A.S. mode

In reply to Oswald Buddenhagen

This mode does not offer mmapped I/O, as we need to copy the buffer anyway to reshuffle it.

A limitation is that we'll refuse writes which aren't a multiple of 2/4 frames, but that's unlikely to be significant. But if one really wanted to make it work, this could be done either locally, or by reviving (and fixing) snd_pcm_sw_params.xfer_align, which was obsoleted in commit d948035a92 ("Remove PCM xfer_align sw params").

---
v3:
- rebased to new buffer copy callback.
fwiw, unlike the emu8000 driver, this open-codes the copy operation rather than calling copy_from_iter() for separate samples, as the latter seems insanely inefficient to me (which is particularly problematic for the emu8000, given that ISA systems are sloooow ... but then, literally no-one cares anymore for exactly that reason).
v2:
- fixed sparse warning re missing __user annotation

---
 sound/pci/emu10k1/emufx.c    |   7 +-
 sound/pci/emu10k1/emumixer.c |  59 ++++-----
 sound/pci/emu10k1/emupcm.c   | 240 +++++++++++++++++++++++++++--------
 sound/pci/emu10k1/voice.c    |   6 +
 4 files changed, 230 insertions(+), 82 deletions(-)
sound/pci/emu10k1/emufx.c +6 -1
index 2f757096c2ee..bb3ae8d84102 100644
@@ -1316,7 +1316,7 @@ static int _snd_emu10k1_das_init_efx(struct snd_emu10k1 *emu)
 	if (emu->card_capabilities->ca0108_chip) {
 		int num_cap = emu->card_capabilities->emu_in_32 ? 32 : 16;
 
-		for (int z = 0; z < 16; z++) {
+		for (int z = 0; z < 32; z++) {
 			A_OP(icode, &ptr, iMAC0, A_GPR(tmp), A_C_00000000, A_FXBUS(z * 2), A_C_00010000); // >> 15
 			A_OP(icode, &ptr, iMACINT0, A_GPR(tmp + 1), A_C_00000000, A_FXBUS(z * 2 + 1), A_C_00000002); // << 1
 			A_OP(icode, &ptr, iANDXOR, A3_EMU32OUT(z), A_GPR(tmp), A_GPR(lowword_mask), A_GPR(tmp + 1));
@@ -1338,6 +1338,11 @@ static int _snd_emu10k1_das_init_efx(struct snd_emu10k1 *emu)
 			A_OP(icode, &ptr, iMACINT0, A_GPR(tmp + 1), A_C_00000000, A_FXBUS(z * 2 + 1), A_C_00000002); // << 1
 			A_OP(icode, &ptr, iANDXOR, A_EMU32OUTL(z), A_GPR(tmp), A_GPR(lowword_mask), A_GPR(tmp + 1));
 		}
+		for (int z = 0; z < 16; z++) {
+			A_OP(icode, &ptr, iMAC0, A_GPR(tmp), A_C_00000000, A_FXBUS(z * 2 + 32), A_C_00010000); // >> 15
+			A_OP(icode, &ptr, iMACINT0, A_GPR(tmp + 1), A_C_00000000, A_FXBUS(z * 2 + 33), A_C_00000002); // << 1
+			A_OP(icode, &ptr, iANDXOR, A_EMU32OUTH(z), A_GPR(tmp), A_GPR(lowword_mask), A_GPR(tmp + 1));
+		}
 
 		/* Note that the Alice2 DSPs have 6 I2S inputs which we don't use. */
 		snd_emu10k1_audigy_dsp_convert_32_to_2x16(
sound/pci/emu10k1/emumixer.c +30 -29

83 lines not on this page · raw message

sound/pci/emu10k1/emupcm.c +188 -52

446 lines not on this page · raw message

sound/pci/emu10k1/voice.c +6 -0
index 77fb5427aaed..797784a31314 100644
@@ -39,6 +39,12 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
 			continue;
 		}
 
+		// The voices must be consecutive without wrap-around
+		if (i + number > NUM_G) {
+			skip = NUM_G - i;
+			continue;
+		}
+
 		for (k = 0; k < number; k++) {
 			voice = &emu->voices[i + k];
 			if (voice->use) {
Signature · 1 line
2.40.0.152.g15d061e6df
#9 lore raw

PATCH v5 8/8 ALSA: emu10k1: document E-MU D.A.S. mode

In reply to Oswald Buddenhagen
---
 Documentation/sound/cards/emu-mixer.rst | 59 ++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 10 deletions(-)
Documentation/sound/cards/emu-mixer.rst +49 -10
index d87a6338d3d8..f69e552a38d7 100644
@@ -30,15 +30,16 @@ but are otherwise identical) may be less problematic.
 Driver capabilities
 ===================
 
-This driver supports only 16-bit 44.1/48 kHz operation. The multi-channel
-device (see emu10k1-jack.rst) additionally supports 24-bit capture.
+This driver can operate in two modes: Sound Blaster mode (the default)
+and Digital Audio System mode (enabled by the emu_das=1 module option).
 
-A patchset to enhance the driver is available from `a GitHub repository
-<https://github.com/ossilator/linux/tree/ossis-emu10k1>`_.
-Its multi-channel device supports 24-bit for both playback and capture,
-and also supports full 88.2/96/176.4/192 kHz operation.
-It is not going to be upstreamed due to a fundamental disagreement about
-what constitutes a good user experience.
+In Sound Blaster mode, only 16-bit 44.1/48 kHz operation is supported.
+The multi-channel device (see emu10k1-jack.rst) additionally supports
+24-bit capture.
+
+In D.A.S. mode, only the multi-channel device is available (as device 0,
+unlike in SB mode). It supports 24-bit for both playback and capture,
+and full 88.2/96/176.4/192 kHz operation.
 
 
 Digital mixer controls
@@ -64,18 +65,23 @@ FX-bus
 	Each of the synthesizer voices can feed its output to these accumulators
 	and the DSP microcontroller can operate with the resulting sum.
 
+SB and D.A.S. modes
+~~~~~~~~~~~~~~~~~~~
+
 name='Clock Source',index=0
 ---------------------------
 This control allows switching the word clock between interally generated
-44.1 or 48 kHz, or a number of external sources.
+44.1 or 48 kHz (which are subjected to the clock multiplier), or a number
+of external sources (which must be compatible with the clock multiplier).
 
 Note: the sources for the 1616 CardBus card are unclear. Please report your
 findings.
 
 name='Clock Fallback',index=0
 -----------------------------
 This control determines the internal clock which the card switches to when
-the selected external clock source is/becomes invalid.
+the selected external clock source is/becomes invalid or incompatible with
+the clock multiplier.
 
 name='DAC1 0202 14dB PAD',index=0, etc.
 ---------------------------------------
@@ -95,6 +101,38 @@ name='Optical Input Mode',index=0
 Switches the TOSLINK input port between S/PDIF and ADAT.
 Not available on 0404 cards (fixed to S/PDIF).
 
+D.A.S. mode
+~~~~~~~~~~~
+
+In this mode, no attenuation controls are available. It is assumed that these
+are realized in software by the sound server, if necessary.
+
+name='Clock Multiplier',index=0
+-------------------------------
+This control switches the card between 44.1/48 kHz, 88.2/96 kHz, and
+176.4/192 kHz mode by setting the multiplier for the base word clock to
+1x, 2x, and 4x, respectively.
+Changing it also changes the available audio ports, which causes the mixer to
+be reconfigured. This may crash poorly programmed mixer applications running
+at that time (this is the reason why D.A.S. mode support is not going to be
+upstreamed - judge for yourself whether that is a wise trade-off).
+
+name='DAC Left',index=0, etc.
+-----------------------------
+Select the source for the given physical audio output. These may be physical
+inputs, playback channels (PbChn xx), or silence.
+
+name='CpChn xx',index=0
+-----------------------
+Select the source for the given capture channel. Same options as for the
+physical audio outputs.
+
+Note that not all combinations may work due to over-allocation of the
+internal buses; refer to the card's official documentation.
+
+SB mode
+~~~~~~~
+
 name='PCM Front Playback Volume',index=0
 ----------------------------------------
 This control is used to attenuate samples from left and right front PCM FX-bus
@@ -218,6 +256,7 @@ PCM stream related controls
 ===========================
 
 These controls are described in audigy-mixer.rst.
+They are available only in Sound Blaster mode.
 
 
 MANUALS/PATENTS
Signature · 1 line
2.40.0.152.g15d061e6df