Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Will Porter <mrwillporter@gmail.com>
To: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>
Cc: Christian Ruppert <arc@gmx.li>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	Neil Andrews <neil@androos.io>, Nikita Tarasov <nik@tarasov.top>
Subject: [PATCH v2 21/21] ALSA: mixer_audient: Replace the Audient iD14 MkI FU 12 control
Date: Mon, 30 Nov 2026 10:44:28 -0600	[thread overview]
Message-ID: <20261130164428.2930348-22-mrwillporter@gmail.com> (raw)
In-Reply-To: <20261130164428.2930348-1-mrwillporter@gmail.com>

Feature unit 12 sets the level of the mixer outputs: channels 1-2 Main,
3-4 Cue. Two firmware faults make the generic control wrong on the
MkI:

- GET CUR does not return the FU 12 value. It returns a reply buffer
  that the device shares with FU 10, MU 60 and XU 51. The buffer holds
  the data of the last GET or SET to any of them. So the generic
  sticky-GET check passes, because GET echoes the SET just sent. The
  check then writes the stale value that it read first to channel 1.
- Main L ignores its level, but Main R applies it. So any Main value
  other than 0 dB unbalances the main outputs. audient_id14_map already
  records this asymmetry. A loopback cable measured it: Main R at
  -20 dB and -40 dB changes its output by -20.0 and -40.9 dB. Main L
  at the same values changes nothing. Cue L and Cue R both work: Cue L
  follows the set value within about 1 dB down to at least -70 dB; the
  headphone residual hides lower levels.

Replace the generic control with one of the same name, count and range.
It is "Monitor Mix Playback Volume", with four values from 0 to 127 in
1 dB steps. 127 is 0 dB. For Cue, value 0 writes 0x8000 (-128 dB, one
step below the GET RANGE minimum of -127 dB), and the TLV declares it as
mute. On Cue L, value 0 gives no output above the fixed headphone
residual, about 76 dB below 0 dB. The four values keep the Main L/R,
Cue L/R layout of existing saved ALSA states.

The control holds Main at 0 dB: Main L does not apply a level, so 0 dB
on Main R keeps the main outputs balanced. A put always sends 0 dB to
channels 1-2, whatever Main values it asks for. After a successful
write, get reports 127 (0 dB) for them. For Cue the control shows the
last value the device accepted. At probe the driver writes Main 0 dB and
Cue muted, once per channel. A channel whose probe write fails reads as
mute until a put succeeds.

The iD14 MkI profile in alsa-ucm-conf writes 127,127,127,127 to this
control at boot and when its HiFi verb starts. The new control accepts
that write: Main stays at 0 dB and Cue goes to 0 dB, the same result as
with the generic control.

Differences from the generic control:
- Value 0 is now mute. It was -127 dB.
- The control holds Main at 0 dB. A Main R attenuation stored with the
  generic control (for example 107, -20 dB) now restores as 0 dB, which
  raises Main R by 20 dB. Main L never applied that attenuation, so
  Main R comes up to the level that Main L already had. FU 12 comes
  before the monitor controller (XU 54) and the headphone level
  (FU 10), so the volume knob still sets the listening level.
- Cue starts muted at every probe. An output routed to the Cue Mix
  keeps that routing across a module reload or a rebind. On mains
  power it also keeps it across a replug. If the probe writes succeed,
  that output is then muted until user space sets the Cue level
  (alsactl restore or the UCM boot write). On bus power the MkI returns
  to DAW Thru when it enumerates, so no output is on the Cue Mix at
  probe.

The control is a new type in the device table, with the INIT_HW, CACHE
and GET_BROKEN flags. GET_BROKEN, because of the shared reply buffer:
the driver sends no GET to FU 12. The unified get and put convert
between the control value and the device value, and hold Main at 0 dB.

Co-developed-by: Christian Ruppert <arc@gmx.li>
Signed-off-by: Christian Ruppert <arc@gmx.li>
Signed-off-by: Will Porter <mrwillporter@gmail.com>
---
 sound/usb/mixer_audient.c | 124 +++++++++++++++++++++++++++++++++++---
 sound/usb/mixer_maps.c    |   2 +-
 2 files changed, 115 insertions(+), 11 deletions(-)

diff --git a/sound/usb/mixer_audient.c b/sound/usb/mixer_audient.c
index cc33ccf83c1c2..93fad4b74e18d 100644
--- a/sound/usb/mixer_audient.c
+++ b/sound/usb/mixer_audient.c
@@ -55,17 +55,45 @@ enum snd_audient_type {
 	SND_AUDIENT_TYPE_ID14_MON_ID_KEY,
 	SND_AUDIENT_TYPE_ID14_MON_TALKBACK_SRC,
 	SND_AUDIENT_TYPE_ID14_OPTICAL_MODE,
+	SND_AUDIENT_TYPE_ID14_FU12,
 	SND_AUDIENT_TYPE_NCTYPES
 };
 
 /* Mixer matrix: -128dB (mute) to +6dB */
 static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_mixer, -12800, 600);
 
+/*
+ * iD14 MkI FU 12, the mixer output level: CN 1-2 Main, 3-4 Cue. GET RANGE
+ * works (-127 ... 0 dB, 1 dB steps), but GET CUR returns a reply buffer the
+ * device shares with other units, not the FU 12 value. So the generic
+ * control shows stale data, and its sticky-GET check passes and then writes
+ * that stale value to Main L.
+ *
+ * The firmware ignores Main L (CN 1) but applies Main R (CN 2), so any Main
+ * level other than 0 dB unbalances the main outputs (Cue L and Cue R both
+ * work). This control holds Main at 0 dB: a put sends 0 dB to CN 1-2
+ * whatever it asks for, and get reports it.
+ *
+ * It keeps the generic control's name and format: four values, 0 ... 127
+ * in 1 dB steps, 127 = 0 dB, 0 = mute (0x8000). It shows the last value the
+ * device accepted, and every put sends all four channels.
+ */
+#define ID14_FU12_MAIN_CHANNELS	2	/* CN 1-2, held at 0 dB */
+#define ID14_FU12_MAX		127
+#define ID14_FU12_MUTE		0
+#define ID14_FU12_HW_MUTE	(-128 * 256)
+
+static const DECLARE_TLV_DB_MINMAX_MUTE(snd_audient_tlv_id14_fu12, -12700, 0);
+
+/* control type flags */
 #define SND_AUDIENT_CTYPE_FLAGS_SIGNED		BIT(0)
 #define SND_AUDIENT_CTYPE_FLAGS_INIT_HW		BIT(1)
 #define SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN	BIT(2)
 #define SND_AUDIENT_CTYPE_FLAGS_CACHE		BIT(3)
 
+/* Private control element types for quirky controls */
+#define SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12	(SNDRV_CTL_ELEM_TYPE_LAST + 1)
+
 /*
  * An enumerated control: item i sends values[i]. A get of a device value
  * outside the list returns -EIO; it does not show a wrong item.
@@ -376,6 +404,21 @@ static const struct snd_audient_ctrl_type {
 		.unit = ID14_IT_DIGITAL,
 		.sel = ID14_IT_OPTICAL_MODE,
 	},
+	[SND_AUDIENT_TYPE_ID14_FU12] = {
+		.type = SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12,
+		.flags = SND_AUDIENT_CTYPE_FLAGS_SIGNED
+			 | SND_AUDIENT_CTYPE_FLAGS_INIT_HW
+			 | SND_AUDIENT_CTYPE_FLAGS_GET_BROKEN
+			 | SND_AUDIENT_CTYPE_FLAGS_CACHE,
+		.len = 2,
+		.min.integer = -127 * 256,
+		.max.integer = 0,
+		.init = ID14_FU12_HW_MUTE,
+		.res = 256,
+		.unit = ID14_FU_MIX,
+		.sel = UAC_FU_VOLUME,
+		.tlv = snd_audient_tlv_id14_fu12,
+	},
 };
 
 
@@ -470,6 +513,7 @@ static const struct snd_audient_ctrl snd_audient_id14_mk1_controls[] = {
 	ID14_CTRL("iD Key Function Playback Enum", MON_ID_KEY, 0, 1),
 	ID14_CTRL("Talkback Source Capture Enum", MON_TALKBACK_SRC, 0, 1),
 	ID14_CTRL("Digital In Mode Capture Enum", OPTICAL_MODE, 0, 1),
+	ID14_CTRL("Monitor Mix Playback Volume", FU12, 1, 4),
 	{ 0 }, /* sentinel */
 };
 
@@ -734,6 +778,31 @@ static int snd_audient_enum_item(const struct snd_audient_enum *e, u32 value)
 	return -EIO;
 }
 
+static inline u32
+snd_audient_fu12_from_ctl(const struct snd_audient_ctrl_type *ctype, long val)
+{
+	s32 ret;
+
+	if (val == ID14_FU12_MUTE)
+		ret = ID14_FU12_HW_MUTE;
+	else
+		ret = ctype->min.integer + val * ctype->res;
+
+	return (u32)ret;
+}
+
+static inline long
+snd_audient_fu12_to_ctl(const struct snd_audient_ctrl_type *ctype, u32 buf)
+{
+	s32 val = (s32)buf;
+
+	if (val == ID14_FU12_HW_MUTE)
+		return ID14_FU12_MUTE;
+	else
+		return min(DIV_ROUND_CLOSEST(val - ctype->min.integer,
+					     (long)ctype->res),
+			   snd_audient_int_max(ctype));
+}
 
 static int snd_ctl_audient_get(struct snd_kcontrol *kctl,
 				       struct snd_ctl_elem_value *ctl_val)
@@ -798,6 +867,10 @@ static int snd_ctl_audient_get(struct snd_kcontrol *kctl,
 				ctl_val->value.enumerated.item[i] = ret;
 			}
 			break;
+		case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12:
+			ctl_val->value.integer.value[i] =
+					snd_audient_fu12_to_ctl(ctype, buf);
+			break;
 		}
 	}
 
@@ -833,6 +906,11 @@ static int snd_ctl_audient_set(struct snd_kcontrol *kctl,
 			if (v->enumerated.item[i] >= e->items)
 				return -EINVAL;
 			break;
+		case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12:
+			if (v->integer.value[i] < 0
+			    || v->integer.value[i] > ID14_FU12_MAX)
+				return -EINVAL;
+			break;
 		}
 	}
 
@@ -858,6 +936,14 @@ static int snd_ctl_audient_set(struct snd_kcontrol *kctl,
 		case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
 			val = e->values[v->enumerated.item[i]];
 			break;
+		case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12:
+			if (i < ID14_FU12_MAIN_CHANNELS) {
+				val = ctype->max.integer;
+			} else {
+				val = snd_audient_fu12_from_ctl(ctype,
+							v->integer.value[i]);
+			}
+			break;
 		}
 
 		ret = snd_audient_raw_set_one(elem, ctype, base + i, val,
@@ -878,25 +964,30 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl,
 	const struct snd_audient_ctrl_type *const ctype
 						= snd_audient_kctl_type(kctl);
 
+	uinfo->type = ctype->type;
+	uinfo->count = snd_audient_kctl_channels(kctl);
+
 	switch (ctype->type) {
-	case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
-		return snd_ctl_enum_info(uinfo,
-					 snd_audient_kctl_channels(kctl),
-					 ctype->enumeration->items,
-					 ctype->enumeration->texts);
 	case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
 		uinfo->value.integer.min = 0;
 		uinfo->value.integer.max = 1;
 		break;
-	default:
+	case SNDRV_CTL_ELEM_TYPE_INTEGER:
 		uinfo->value.integer.min = snd_audient_int_min(ctype);
 		uinfo->value.integer.max = snd_audient_int_max(ctype);
 		break;
+	case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
+		return snd_ctl_enum_info(uinfo,
+					 snd_audient_kctl_channels(kctl),
+					 ctype->enumeration->items,
+					 ctype->enumeration->texts);
+	case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12:
+		uinfo->value.integer.min = 0;
+		uinfo->value.integer.max = ID14_FU12_MAX;
+		uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+		break;
 	}
 
-	uinfo->type = ctype->type;
-	uinfo->count = snd_audient_kctl_channels(kctl);
-
 	return 0;
 }
 
@@ -948,9 +1039,22 @@ static int snd_audient_add_ctrl(struct usb_mixer_interface *mixer,
 		int i;
 
 		for (i = 0; i < ctrl->hwchannels; i++) {
+			u32 init;
+
+			switch (ctype->type) {
+			case SNDRV_AUDIENT_CTL_ELEM_TYPE_ID14_FU12:
+				if (i < ID14_FU12_MAIN_CHANNELS)
+					init = ctype->max.integer;
+				else
+					init = ctype->init;
+				break;
+			default:
+				init = ctype->init;
+				break;
+			}
 			ret = snd_audient_raw_set_one(elem, ctype,
 						      ctrl->val_offs + i,
-						      ctype->init, true);
+						      init, true);
 			if (ret < 0)
 				usb_audio_warn(mixer->chip,
 					       "%s: cannot set channel %d (%d)\n",
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index b88244b12a98a..0ff180e450b5b 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -543,7 +543,7 @@ static const struct usbmix_name_map audient_id14_map[] = {
 /* Audient iD14 MkI: model-specific control map. */
 static const struct usbmix_name_map audient_id14_mk1_map[] = {
 	{ 11, NULL },			/* FU, see mixer_audient.c */
-	{ 12, "Monitor Mix Playback" },	/* FU, partial coverage */
+	{ 12, NULL },			/* FU, see mixer_audient.c */
 	{ 60, NULL },			/* MU, see mixer_audient.c */
 	{}
 };
-- 
2.47.3


      parent reply	other threads:[~2026-11-30 16:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:44 [PATCH v2 00/21] ALSA: usb-audio: Audient driver and iD14 MkI support Will Porter
2026-11-30 16:44 ` [PATCH v2 01/21] ALSA: mixer_evo: Remove double end marker device list Will Porter
2026-11-30 16:44 ` [PATCH v2 02/21] ALSA: mixer_evo: Fix endianness of boolean inversion Will Porter
2026-11-30 16:44 ` [PATCH v2 03/21] ALSA: mixer_evo: Add tlv for mixer channels Will Porter
2026-11-30 16:44 ` [PATCH v2 04/21] ALSA: mixer_evo: Add missing snd_usb_lock calls Will Porter
2026-11-30 16:54   ` sashiko-bot
2026-11-30 16:44 ` [PATCH v2 05/21] ALSA: rename mixer_evo to mixer_audient Will Porter
2026-11-30 16:44 ` [PATCH v2 06/21] ALSA: mixer_audient: explicitly define full control names Will Porter
2026-11-30 16:44 ` [PATCH v2 07/21] ALSA: mixer_audient: clarify USB control message definition Will Porter
2026-11-30 16:44 ` [PATCH v2 08/21] ALSA: mixer_audient: Add length check to USB transfer Will Porter
2026-11-30 16:44 ` [PATCH v2 09/21] ALSA: mixer_audient: make USB control transfer size configurable Will Porter
2026-11-30 16:44 ` [PATCH v2 10/21] ALSA: mixer_audient: Allow arbitrary boolean control values Will Porter
2026-11-30 16:44 ` [PATCH v2 11/21] ALSA: mixer_audient: Add integer range checks Will Porter
2026-11-30 16:44 ` [PATCH v2 12/21] ALSA: mixer_audient: Add control initialization at probe Will Porter
2026-11-30 16:44 ` [PATCH v2 13/21] ALSA: mixer_audient: Add readback-free parameter set Will Porter
2026-11-30 16:44 ` [PATCH v2 14/21] ALSA: mixer_audient: add control value caching Will Porter
2026-11-30 16:44 ` [PATCH v2 15/21] ALSA: mixer_audient: Create matrix programmatically Will Porter
2026-11-30 16:44 ` [PATCH v2 16/21] ALSA: mixer_audient: Add a step size to integer controls Will Porter
2026-11-30 16:44 ` [PATCH v2 17/21] ALSA: mixer_audient: Add enumerated controls Will Porter
2026-11-30 16:44 ` [PATCH v2 18/21] ALSA: usb-audio: Give the Audient iD14 MkI its own mixer map Will Porter
2026-11-30 16:44 ` [PATCH v2 19/21] ALSA: mixer_audient: Add Audient iD14 MkI controls Will Porter
2026-11-30 16:44 ` [PATCH v2 20/21] ALSA: mixer_audient: Unify snd_audient_*_set/get functions for different types Will Porter
2026-11-30 16:44 ` Will Porter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130164428.2930348-22-mrwillporter@gmail.com \
    --to=mrwillporter@gmail.com \
    --cc=arc@gmx.li \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=neil@androos.io \
    --cc=nik@tarasov.top \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox