From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796057122; b=a6UWrjurB/5RrUJj/Ns44ybyvjoXphX86BZFJ+CXfyXbMuNZGdFnoU5bI6GDPNsi2dJg i54LC8jnIk/5Occu7yLu/H+5OqXJ5U3YZOjYRHnrdgY48QeTuOj/ZY75JBeqmzqaIxT3y rk04v8Ss36O2NxaeELbkjs8Ag6shNQqu6oJZXeqRoGjo3s078Z3WtgukmvW7mZOKqgjHN YABv1pblu0WHvOY7wvTrQlopq33xBA0ur1w2PwEaAtF4MjHqr7xnLPcmtVXh+yV/EODh6 cYMjc60SdyNIb+/X9GKc1F8LmE1AbfveVRzgCje2OC7M0GanDoFqLEeTDJ5n37GMxyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796057122; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=x//R5m1YXi9sQvZTEhoNVYxg3TgTpK2B+ehF3R1HtGI=; b=Svp1XJVzcEksKiifNyDGHQrjAfE2Ldn0BnEMh1QGetLjdAzOIp5Jqk2brQLs+5WL2H6W t6S+UKvLhq6AtwV2zvpMECRiIfD+pfw5wwlnnDjqpgLaoE9z7Q+Vt3dqnxqEZOs+FWIYJ TKANV/KaQ436QA8FysKbvLUc19IfV5B7LA3U9WEgvUDN77ey5sv/ngLxp3eeMxdzxZznu 40CaqeNuW8Dw76jLV+SRLmGpw5nCidNZvE3II3Po3jEXOo+T+ocZZBV4wpeCGkFh+M7B6 xFx0S1RfEczhc/rXI9DwW5Ge7H4CmHq19ALR1niwgjunMetlr8sT/Ipxw0PhVsmGxqA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=sJmzzq2y; arc=none smtp.remote-ip=209.85.161.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BA79606A68A for ; Mon, 30 Nov 2026 16:45:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5BA79606A68A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=sJmzzq2y Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-71ab5e64742so6472836eaf.3 for ; Mon, 30 Nov 2026 08:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796057121; x=1796661921; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=x//R5m1YXi9sQvZTEhoNVYxg3TgTpK2B+ehF3R1HtGI=; b=sJmzzq2yM4+k6/TlLA5TmzjfNIxBYmNsMIBS1IgCL+954hH2+gDBThS0jQ258XGiz3 Kj6oGAyPRV5IHmNcvCdL5k/A2EFBOuqBD00Gb3BEZv138OqDmq6A4v6ADTIsl/bx9ofp ta6OF4+r1W8pc5t2VIFKuEPCUKBYRyw55eCs/DV6I22oG5UMhkjLIwwXTVS/M0KAiaKa E8+Vswsu6t+xrCTN6ahCT56yPPvhUuaegxMEO7AIeb/pAs1WlYuY6MiIvNJqrPyg6Jz3 DoH2drqjCDIsPlL601iEzyOz7IbScBt6y5CVQZb9Wb7B3CBRnAzKT5dQJEqujReAj7iK h76A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796057121; x=1796661921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=x//R5m1YXi9sQvZTEhoNVYxg3TgTpK2B+ehF3R1HtGI=; b=EU8afkXoo9tA9xW8mkrvpq6GYZgTG5lmW2llyq6uaMqMMZRCpgptBE4LN5eVjKM4GF GoXoshcpj78lHQJsPIQw3zipMlOatdVbAhV57ROKDgOrgO+9D1H07LSJXmZqBpE7Y1H9 TgtEcR2NWvcwTMfSyqz04BwB7+Fh/MR1ZdhCOw3ccBI3NRpkQRPA3R89m3m4x8JRjIuw KoPMxfvjHmxzWOvjmv9WpmscCia3vOmwSTo0QXFe+jDvZSlD2tfjGAYmas1iAI8jSBzJ UHgx0hvpADu30DI9C3h28tJlI5/Ty6ye7Em/+pB2l94I4qBDrSpCb5bd555leUzne4dt aDmQ== X-Forwarded-Encrypted: i=1; AL+hErEj3n4tHtBTC/sbrm2kIM1JF1BIwsYMcYhQWI25VcfICgOP+JFs822khFnZHqVpHMwAjm8Z2/VKLIX+4A==@vger.kernel.org X-Gm-Message-State: APuU4Z/G5yM8NIDDMTPyOarZ6cq2zbQFez5KamEKuEPDiEiGcLMuFUsj g12//ti3jjTYfmDNz1mqeMDsogE1M209orebZU3x4yiossE+TcLJGROw X-Gm-Gg: AZFdTZdfAM6JCVsUJSlWoLnoZ+EjjgXimmpZ8k4XKWzwHDcbHMBmrAwvdY07t3+g2yA BUIIDhwTaRJj7YW4CadeTNHDGwjsWhAeVHNk1W8qXFrusS+f21O311woQvS+ResRlQEKm9dQHek +KLoHzUoqcaePpMaVqgpRyw9n9nlvnEBnmwyotbIfWOen6cJdRUxYHWzpBdQrCBkMMLXZDK4pNp qRozpTeftF1/U+hVKQ69qTWLCAkVMpAqMW+OBiDXTedG71hyrUxFFf2txMfJMqtH3nPDT+2andF PzsZtGgvlqWGfyrcRrzObw1n57loaoZWTdAGZJNftg0oIdInlkkCneYrEW5WF/6V3BQTpkiB487 Ij5ido+dtt38DKBlr/yyPZgmN1PTGVCnccPx5Zv87NvevesyCm+CLqFZ+oCcO8xBOwNekz0XIAe q6b+YzNWGbVtfbwBYwqgo0/7WftcWPqjyIn7F+/05tO/vkOabYYVJYKW05Jy0WXj9YeYI8JjWE8 jrbo1EQQambi741S71YBOfUl9qDygRNEzbMsf8eutZTfsvClH9od2UxskNteEzS5bAJC8iVESQW hZ4pj7L1lExmCcHCUppxGNZLNuR5vC+QY9DXRzgXhrMq8/g= X-Received: by 2002:a05:6820:55da:20b0:6dd:4a4b:1843 with SMTP id 006d021491bc7-71b395213b2mr20431141eaf.14.1796057120948; Mon, 30 Nov 2026 08:45:20 -0800 (PST) Received: from localhost.localdomain ([2600:1702:4ff0:baa0:5054:ff:fe3d:4ddb]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc5f7ae7dcsm28002053fac.8.2026.11.30.08.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 08:45:20 -0800 (PST) From: Will Porter To: Takashi Iwai , Jaroslav Kysela Cc: Christian Ruppert , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Neil Andrews , Nikita Tarasov Subject: [PATCH v2 16/21] ALSA: mixer_audient: Add a step size to integer controls Date: Mon, 30 Nov 2026 10:44:23 -0600 Message-ID: <20261130164428.2930348-17-mrwillporter@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130164428.2930348-1-mrwillporter@gmail.com> References: <20261130164428.2930348-1-mrwillporter@gmail.com> X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The iD14 level controls use s16 values in 1/256 dB. Expose them in 1 dB steps, matching the volume knob's adjustment. Let a control type give a step size: the control then counts steps from the minimum, as the generic USB mixer does with the RANGE resolution. A device value between two steps reads as the nearest step, clamped to the maximum. Types without a step size keep the device value. Signed-off-by: Will Porter --- sound/usb/mixer_audient.c | 57 ++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/sound/usb/mixer_audient.c b/sound/usb/mixer_audient.c index 56a9b9c04b369..12b430ebed9e3 100644 --- a/sound/usb/mixer_audient.c +++ b/sound/usb/mixer_audient.c @@ -53,6 +53,7 @@ static const struct snd_audient_ctrl_type { long integer; } max; /* for booleans holds physical int value for true */ u32 init; /* hardware and cache are initialized to this value */ + unsigned int res; /* integers: device units per control step, 0 = 1 */ const unsigned int *tlv; u8 unit; u8 sel; @@ -418,6 +419,41 @@ static int snd_ctl_audient_boolean_set(struct snd_kcontrol *kctl, return changed; } +/* + * With a step size (res), an integer control counts steps from min: + * 0 ... (max - min) / res. Without one it shows the device value. + */ +static inline long +snd_audient_int_max(const struct snd_audient_ctrl_type *ctype) +{ + return ctype->res ? (ctype->max.integer - ctype->min.integer) / ctype->res + : ctype->max.integer; +} + +static inline long +snd_audient_int_min(const struct snd_audient_ctrl_type *ctype) +{ + return ctype->res ? 0 : ctype->min.integer; +} + +static long snd_audient_int_to_ctl(const struct snd_audient_ctrl_type *ctype, + long val) +{ + val = clamp(val, ctype->min.integer, ctype->max.integer); + if (!ctype->res) + return val; + + /* round a device value between two steps to the nearest one */ + return min(DIV_ROUND_CLOSEST(val - ctype->min.integer, (long)ctype->res), + snd_audient_int_max(ctype)); +} + +static inline long +snd_audient_int_from_ctl(const struct snd_audient_ctrl_type *ctype, long val) +{ + return ctype->res ? ctype->min.integer + val * ctype->res : val; +} + static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ctl_val) { @@ -448,17 +484,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl, else if (ret < 0) return ret; - if (val < ctype->min.integer) - val = ctype->min.integer; - - if (val > ctype->max.integer) - val = ctype->max.integer; - - ctl_val->value.integer.value[i] = val; + ctl_val->value.integer.value[i] = + snd_audient_int_to_ctl(ctype, val); } for (; i < nchan; i++) - ctl_val->value.integer.value[i] = ctype->min.integer; + ctl_val->value.integer.value[i] = snd_audient_int_min(ctype); return 0; } @@ -480,7 +511,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl, for (i = 0; i < hwchan; i++) { long val = ctl_val->value.integer.value[i]; - if ((val < ctype->min.integer) || (val > ctype->max.integer)) + if (val < snd_audient_int_min(ctype) || + val > snd_audient_int_max(ctype)) return -EINVAL; } @@ -491,7 +523,8 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl, guard(mutex)(&mixer->lock); for (i = 0; i < hwchan; i++) { - s32 val = ctl_val->value.integer.value[i]; + s32 val = snd_audient_int_from_ctl(ctype, + ctl_val->value.integer.value[i]); int ret; ret = snd_audient_raw_set_one(elem, ctype, base + i, val, @@ -519,8 +552,8 @@ static int snd_ctl_audient_info(struct snd_kcontrol *kctl, uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; } else { - uinfo->value.integer.min = ctype->min.integer; - uinfo->value.integer.max = ctype->max.integer; + uinfo->value.integer.min = snd_audient_int_min(ctype); + uinfo->value.integer.max = snd_audient_int_max(ctype); } return 0; -- 2.47.3