From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796057122; b=ngWE/NZaKWpBQFmFqDMxpzX12JREsOgrGYxEx4hI/WUHlGHhI9AYmLwD+X3WXAf6Slbi yM1sNDmKksH+AIzO5ZMIv4D+28p0ZVgUzW7FvlAk9XX9ZA+ojhRt3sCYcKECbAy8SnvWr OR3z1vuzq4jGrMKNgCfU834u4dqsPdPlv3Yzy5PxeMXlQtEatQHN50QBZZR4VXjIvJy5h fn0DF03cESW33bsZLCD2bVy9yFsW4hSW2qAs4x+zr2mx+IInHK827m0cC2/07L9nDJxH1 ockLu8rLg1oI6VMHlXdD6Kjpmfl3nkb763ly8Mh5iYCri1YC/20s4xzCwgU0rag4Mkw== 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=D/nikgs/CbOjh97NkWGhjAvVR0JTXulbRTfRl/1gWYJVtghoECyw3shapySmzKIbxWbE tH0r6Pojv1to46tZpR+SBS2JYrPOCAN95manFqhAMqjke72TU//Qq+TKv9/Jok2lfqTZR 5O8QGiU3xtKusDzZpScwd92xQP9SzKzlze3uPfo7xLPisP5I91piTNTm4lkZOP1QqLPws ISDxXM/j+NY6UVeuO56AB3jB3DYx61ffb1DExMh0cKoJET2F9LBdl9YlkT3lPrQdI8Xmz 2caj5us6oMDqB6yhJy48uUzXVx0DHKHLMPrp9Ymlqb9WtJXfVL1pQBnh8oxi6ri8tAA== 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.46 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 38FBC60A2609 for ; Mon, 30 Nov 2026 16:45:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 38FBC60A2609 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-f46.google.com with SMTP id 006d021491bc7-71ac798b8bbso6398961eaf.1 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=juMg6cDRrvNQHslI92jCGTqG5ocDikHscTesJYfR0MTyQjR3AyBFiE2RM61Yiqi2AC OA257T0XYl7JW5f/MmZzZM2wFtaXh900p/Yov9BPOXP9gdnUyZyFvZCki6NsU+2pwZgg 8r/evwOsKDjDrDfGQvpwUWoZL0wNYs2+A9z3WRg0nY1Ywmh8mFRDjdgiBeDJI29qhOAx 0lEN+Rsn8hHZlOLy1RccmJ10MfMW2jHJ1462EEej8eL+rRdhOBIV3xFcEzQbP9gLQuuq 5ZLy8XgNUAgDCmYLDqqsKaDDO60kz4AI2kYTw/0YI9YM57Z/B0OxcdTfPIwnWq+H0hwF Hbtg== X-Forwarded-Encrypted: i=1; AL+hErGGWK49R4txizWSuqLWkNxedz8HAHxwzuiOA4cb1+V7KhGXIrPMEWAQOxNizQ+l2dscA61mYwDhQVUiZ5E=@vger.kernel.org X-Gm-Message-State: APuU4Z+X0Ub+BtWPQoqzXh7ACK3y276iw7LJ6My4Q65zt8sXjttIXy6k GwihLyy3iZC6fVPEbMPRa3ZtOanoE1DxsMu3Du/r2zIAnC9wYz2a1+T8PBX1CyjA X-Gm-Gg: AZFdTZf2TXxuCcxUCZ6Io+3EZ+yZCfoYOwOgAto3hXxiSPqMCcvtQVV/9M+Zs4edgsF XdTtJypFSuUUgsnS5bJKoJnWtBtB7wqsqd8thgVUAw1hIFSvTvoX/ujHEu5+ypx8KOsmR2VKzh7 r5lmn1fgvXkDH+oNKDf72MzuiRbMPlue7Obqhu8W07Y/x9YnaenC30RojLeQ+VfsSV6tw/X6N/s tG1yFF9O4uxvB2mFqdJUtEE9QqsroB2CLwN9fyTSxhKBgwfuyPgE8ep0IGCfv4GmlIAYOlVaZdU m9aT51IfoMd5HmvThF3hJpB4lF4KFQhwJUGv6afhxVHezHmF6RKSBaKaPptmiqbh1Zvtcg3kVO1 AS349saMkSJ4Rgje1Rx16Owkl41BQ2kV0UyaMOqmnxFCObJonzL12GY2FqXJlq4wBjQhVwqPO4U 26BXKOCWdRa1REG1qffRuQfIbQeaDBS7Rj+AQ9zAMiFrUXaW/fIfwjujf+3ycUUmOINi5oY23pi Sy5AAWXE7lSsgUphx9LJDt9yO1jeFS3C/VJ06gbm+C3eBiaWaGu+QPV5p66nO2iQ4Ng8KmCs9Uz +l0CHHgBhvNbYgJiRBlkeX2kkmm6JraGfLl+lK7YBgvoefo= 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-kernel@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