From patchwork Fri Oct 4 14:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geoffrey D. Bennett" X-Patchwork-Id: 13822464 Received: from m.b4.vu (m.b4.vu [203.16.231.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B68951D5AB8 for ; Fri, 4 Oct 2024 14:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.16.231.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052080; cv=none; b=M5I6+ZmF+Qvw5G6qmPp2hdyQDUWcIAMB3ksD/Vk41JTvQOyd8iCIB4RVpr8BfQ/V0iKpTTnYLq3Yn7Rod51Lc5N+32FL/JOrrJqSU7zncG+oTPVzhSTuSS8TQqPZNxl9Xp9h5eNkwXkcsX8/MXT16cHvXcpapu0MaQhqgmqxjcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052080; c=relaxed/simple; bh=1XiSumeCOguOZ7wbwoGRQuDU1RrpuDMZu/3tHzq4LOw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=myoff9EU6O+Ct6SWQAwqOn2YTXc2ZZbdq8FV1l4ZgfdmXHhcLwmwdg1s6j/Xf/yoSl+OVzRTLxeMw/Pm6W1nbd3qrOeUyoHNvYUEDvxAUkUWANFK9ZVcF/VuNdUrph/0nKEO/j8/Du8hbRhUCJLCLtBab55FaNDtUXoc0yAow7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu; spf=pass smtp.mailfrom=b4.vu; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b=WWXrM9yp; arc=none smtp.client-ip=203.16.231.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=b4.vu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b="WWXrM9yp" Received: by m.b4.vu (Postfix, from userid 1000) id 5738461ADE7B; Fri, 4 Oct 2024 23:57:54 +0930 (ACST) DKIM-Filter: OpenDKIM Filter v2.11.0 m.b4.vu 5738461ADE7B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=b4.vu; s=m1; t=1728052074; bh=gWqIkaot0segzTgelNwgDzKzxMXvz5CqB8jjGYKQR1c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WWXrM9yp8w1T7F+hupj8ibWzcnp9ciUu57JjzlU10a1ZbEtle+adICjt03nbkDoEU Lx36e1ZSLbgWnVyhVLnpXe4lbCguwFowEdCLcUauj+C54zGB7XT4qCjpGMYNESa3Av ireSJZTlyAclNELGEzLqzecsOwz+LXx2f/4IdtlayDbb8jPdpvsS/n6oSb6OEFfvnu q9l+twSnvH0aF8fD9Z2PF62F5HX0vO6tqmkG45aP34mSrKHRi19THnRD3RYP/+6MzG BucO6bwiE1+0VL3nmonw0vr3/7XrbPjbIUKr4tzpMCQTGOiiF3CXkF/PCHYNFJ4Tzq 0GXXC4csBnkNA== Date: Fri, 4 Oct 2024 23:57:54 +0930 From: "Geoffrey D. Bennett" To: Takashi Iwai Cc: linux-sound@vger.kernel.org Subject: [PATCH 1/5] ALSA: scarlett2: Fix redeclaration of loop variable Message-ID: References: Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Was using both "for (i = 0, ..." and "for (int i = 0, ..." in scarlett2_update_autogain(). Remove "int" to fix. Signed-off-by: Geoffrey D. Bennett --- sound/usb/mixer_scarlett2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c index 1150cf104985..003e91f9e43c 100644 --- a/sound/usb/mixer_scarlett2.c +++ b/sound/usb/mixer_scarlett2.c @@ -3409,7 +3409,7 @@ static int scarlett2_update_autogain(struct usb_mixer_interface *mixer) private->num_autogain_status_texts - 1; - for (int i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++) + for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++) if (scarlett2_has_config_item(private, scarlett2_ag_target_configs[i])) { err = scarlett2_usb_get_config( @@ -3420,7 +3420,7 @@ static int scarlett2_update_autogain(struct usb_mixer_interface *mixer) } /* convert from negative dBFS as used by the device */ - for (int i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++) + for (i = 0; i < SCARLETT2_AG_TARGET_COUNT; i++) private->ag_targets[i] = -ag_target_values[i]; return 0; From patchwork Fri Oct 4 14:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geoffrey D. Bennett" X-Patchwork-Id: 13822465 Received: from m.b4.vu (m.b4.vu [203.16.231.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3333D69D2B for ; Fri, 4 Oct 2024 14:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.16.231.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052097; cv=none; b=FAxiyIBxcpWMwMcijVw4mb51pyinH0inilLj6rWW3Vgo/C7+CMfDhfeNgAo50mg792X6/3is4+L1pMk+7LfjJOvi4cziLNvE0/XOrrsETG3eCkqaReX+yaSSRPOQ50t8Cz91B5dU0y1Lcuyjq+YT2BodW59AvUKmpIUgQF4CtBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052097; c=relaxed/simple; bh=D9T3qhcglVm+E5H/Y1cqcOgDni/g6udaIH7wCzg3NQY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nL4y6G9N7kJprVEr2LbBo9FJwM7IglCH2NbEWlFh6ipF8+tWPMGtgKvcBmVHQ9Q6V/cotQizP15GPT6DW9YoyeWGKDS6Vhj5yb3RfXnBS1D2MrY4NEFM5WlsuXuLj5p19q1+kfaEQ/yTfSTLrxHjICx9fmW60dQNUbj2DP8TM8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu; spf=pass smtp.mailfrom=b4.vu; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b=r8LUwFjr; arc=none smtp.client-ip=203.16.231.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=b4.vu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b="r8LUwFjr" Received: by m.b4.vu (Postfix, from userid 1000) id 4705761ADE7C; Fri, 4 Oct 2024 23:58:12 +0930 (ACST) DKIM-Filter: OpenDKIM Filter v2.11.0 m.b4.vu 4705761ADE7C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=b4.vu; s=m1; t=1728052092; bh=lBmtPz5SMR8x2RA0GWpTrsMS35fh9YMP6A5FFTzhFHw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r8LUwFjr0W7bpGoMxOk2syJv/L1WMsJPNDzwE0g2+6JCqVlGd6xQ+LWrvhTh9n0bQ Jq1muAZB0hcu1TKPhLsYhX+BTcfzhEZFWdoYFCQJJxuAl2fzGgWRYzM60CMZauMqk2 dkLijsk0Xx+b7PRSNrW43h8oiCGWa6+sIXiv+3Bwtnb0WDCpz6NqmHWmchSE/2+V7w kMF/oxCD00rPUzazBTWIZSKvdO/CZPelcQGnyglR612x/o+9Wpz4vY+2bAEqHNIaGQ h1wdPjrsVW0v07G4PrwzzCVshVtO0siRrNEt+5mneypDhscc1SuADQGynCifMAXDIN Poxh53REDTGrA== Date: Fri, 4 Oct 2024 23:58:12 +0930 From: "Geoffrey D. Bennett" To: Takashi Iwai Cc: linux-sound@vger.kernel.org Subject: [PATCH 2/5] ALSA: scarlett2: Fix mixed declarations and code warning Message-ID: References: Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In scarlett2_compressor_ctl_put(), move the declaration of param to the beginning of the function to avoid mixed declarations and code. Signed-off-by: Geoffrey D. Bennett --- sound/usb/mixer_scarlett2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c index 003e91f9e43c..aa7c3d74ce8f 100644 --- a/sound/usb/mixer_scarlett2.c +++ b/sound/usb/mixer_scarlett2.c @@ -5385,6 +5385,8 @@ static int scarlett2_compressor_ctl_put( int index = elem->control; int channel = index / SCARLETT2_COMPRESSOR_PARAM_COUNT; int param_index = index % SCARLETT2_COMPRESSOR_PARAM_COUNT; + const struct compressor_param *param = &compressor_params[param_index]; + int oval, val, err; s32 scaled_val; @@ -5406,8 +5408,6 @@ static int scarlett2_compressor_ctl_put( private->compressor_values[index] = val; - const struct compressor_param *param = &compressor_params[param_index]; - scaled_val = val << param->scale_bits; /* Send change to the device */ From patchwork Fri Oct 4 14:28:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geoffrey D. Bennett" X-Patchwork-Id: 13822466 Received: from m.b4.vu (m.b4.vu [203.16.231.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F02C69D2B for ; Fri, 4 Oct 2024 14:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.16.231.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052124; cv=none; b=IJ9xogbwmhGw60fjFQ4Y9J+Lzb7LnybRtn7BNrmXRBwU3eY+oL5RpsDsJKl7usE+aIe+V2qGxd6cUgfv4YNrRgdOUqZKNoq9RAIQPSKbv7KjHT5S5nasLQXXtt9+hKLFz3TSsmiR1bml2xPj6oJ3bqQxnTpdzd3VquJxQua9HMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052124; c=relaxed/simple; bh=Qx9ibklWoTECgN1ANUuhsfNxPq4iFE0t1KDs/4wy7Ls=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MXIBa9Ft2ZqQhn2mwPBKUbaCXBBgW0rZ6MUm5naWLkTjqOMhBH5/pej0ryF919ekW7KbnCM4Ulx4vtPKKsQ45Q22H0UEDbM2Fs9W2Zx5u5rwu0nSupXQ4CIwW8XlYJaIOMtHtKQCmagZToza7gdi6QXgsMStMgelvuWSuMkU5Uc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu; spf=pass smtp.mailfrom=b4.vu; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b=oPDplXuy; arc=none smtp.client-ip=203.16.231.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=b4.vu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b="oPDplXuy" Received: by m.b4.vu (Postfix, from userid 1000) id E7B8C61AD441; Fri, 4 Oct 2024 23:58:39 +0930 (ACST) DKIM-Filter: OpenDKIM Filter v2.11.0 m.b4.vu E7B8C61AD441 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=b4.vu; s=m1; t=1728052119; bh=xJDS0SyZZ/t5jVZvFG0e4monFG4FgwHosF8FQgv2zsc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oPDplXuyQ+uypNTTgzvla5Dwkr+i5pYNHrDt/mA1OSP01f+dBALS9LPpVfZHwMNU0 D3oQfD5MH8LW31qvEgH8l1GRywnmuEpZ5HAoPSyCHuuhNtVnC1E7x/Hxd7+pQpT/eC etRPYxy9iiqG8Wscz1Ncserdw3tvmbfo4JgBe79rzaJgE2OltudlgfHbN9HfVhjLY7 YqRkCWdtpz+n6Ff5B3GdwlMQ+M3IEy5cfTdA4Y0o/l+X+CoSFh/R41XjdTIurCHNIi d66UySGaXnUyyAO4tLn8xSAqWEF6fAR/GWv58rPwnSwKXGQZVgl1FzQpPCJIdQxsj0 sLo8w4HtvygGQ== Date: Fri, 4 Oct 2024 23:58:39 +0930 From: "Geoffrey D. Bennett" To: Takashi Iwai Cc: linux-sound@vger.kernel.org Subject: [PATCH 3/5] ALSA: scarlett2: Return ENOSPC for out-of-bounds flash writes Message-ID: <3a4af07b0329bed5ffb6994594e4f7bd202aad0f.1727971672.git.g@b4.vu> References: Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When writing to flash, return ENOSPC instead of EINVAL if the requested write would exceed the size of the flash segment. Signed-off-by: Geoffrey D. Bennett --- sound/usb/mixer_scarlett2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c index aa7c3d74ce8f..844e95cc965e 100644 --- a/sound/usb/mixer_scarlett2.c +++ b/sound/usb/mixer_scarlett2.c @@ -9516,7 +9516,7 @@ static long scarlett2_hwdep_write(struct snd_hwdep *hw, SCARLETT2_FLASH_BLOCK_SIZE; if (count < 0 || *offset < 0 || *offset + count >= flash_size) - return -EINVAL; + return -ENOSPC; if (!count) return 0; From patchwork Fri Oct 4 14:28:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geoffrey D. Bennett" X-Patchwork-Id: 13822467 Received: from m.b4.vu (m.b4.vu [203.16.231.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71B0569D2B for ; Fri, 4 Oct 2024 14:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.16.231.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052135; cv=none; b=rDKgbTMU9gygc2fRtx853hXU+ENffQ7s72RQvy/Z7Xof+fczkFuu4jlCAZoTPgzgq5qg29n75N6GlCTq6iFeRmsc/n5EdEAjwunlh/r2prq2sVgD28G46a/1NMdAKt1YR0sGiWCvjBUihMt5i7lC9YDnyXlov+TLSb5BJMO074M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052135; c=relaxed/simple; bh=NH2VFOdUTMGJEMwD6ydxZlfdLkzzL3jtHCzUVzuwHLk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kJJ+PsKQm/r+pj+vPu61ee6B4fyzcNHuZrKDiDqSRePJrKZkAZ9zH/EaLe0Zf8ZJEXifxWQ1SbUR8vUlXBq4B/nYoffBQhLRBcUC1qRCQ8e88gv6h1heyTjxEs4UWRDKjKaM1rEmf0KqObhFRiZ3r12/5KetjdNinbRMUyDbv3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu; spf=pass smtp.mailfrom=b4.vu; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b=s03W/K9b; arc=none smtp.client-ip=203.16.231.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=b4.vu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b="s03W/K9b" Received: by m.b4.vu (Postfix, from userid 1000) id 8B3E161AD440; Fri, 4 Oct 2024 23:58:51 +0930 (ACST) DKIM-Filter: OpenDKIM Filter v2.11.0 m.b4.vu 8B3E161AD440 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=b4.vu; s=m1; t=1728052131; bh=IZG3USkQoGh9Z2kJwzdLlmp1Kyoo/XhaH/pSq0M8Gpo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s03W/K9bqdKGV2UCjIiZeiaR7cTkIr4CknMXhpcxKzVEKixCusZLLKMQmZIqELoNY TsKhAokk/vk9WJgggbWkwSM1PvwlWEaaRApNdFITKSQF9iFRrCQ4OdpYCnrxBpU2LB 8e4/vdyqtiaI5iSVMOu/3EkVQr/CbHdIvisbKScjzWl+XbRyFNroTjWwkNunRbOz/+ SaL0MWWWr2ql6fu5AsJS6xZRtbl6JNRa8wVjQWYpZ5pvHJ7ohDw58hg0QzQId/xVK8 PTSKoraeL8QsSNh4ygTMZ3ZT+/Pc9Lf32gI2pVdvX4hbbtz/qpFGwZAua8KQc4jwnD Fwj6PKd1EvO2g== Date: Fri, 4 Oct 2024 23:58:51 +0930 From: "Geoffrey D. Bennett" To: Takashi Iwai Cc: linux-sound@vger.kernel.org Subject: [PATCH 4/5] ALSA: scarlett2: Simplify linked channel handling Message-ID: <9bf8a2ab35f243820d066319b7d407b45a61281b.1727971672.git.g@b4.vu> References: Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The current handling of linked channels for the 4th Gen 2i2 and 4i4 models is more complicated than necessary. The firmware has a link control for each channel, and the channel selection can be any channel regardless of the channel link status. The driver can therefore be simplified by having it reflect the controls presented by the firmware, and complexities related to trying to reflect the channel link status in the Input Select Capture Enum control are not necessary. Signed-off-by: Geoffrey D. Bennett --- sound/usb/mixer_scarlett2.c | 71 ++++++++++++------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c index 844e95cc965e..b0eca4785bc6 100644 --- a/sound/usb/mixer_scarlett2.c +++ b/sound/usb/mixer_scarlett2.c @@ -11,7 +11,7 @@ * - Clarett 2Pre/4Pre/8Pre USB * - Clarett+ 2Pre/4Pre/8Pre * - * Copyright (c) 2018-2023 by Geoffrey D. Bennett + * Copyright (c) 2018-2024 by Geoffrey D. Bennett * Copyright (c) 2020-2021 by Vladimir Sadovnikov * Copyright (c) 2022 by Christian Colglazier * @@ -1253,7 +1253,7 @@ struct scarlett2_data { u8 phantom_switch[SCARLETT2_PHANTOM_SWITCH_MAX]; u8 phantom_persistence; u8 input_select_switch; - u8 input_link_switch[SCARLETT2_INPUT_GAIN_MAX / 2]; + u8 input_link_switch[SCARLETT2_INPUT_GAIN_MAX]; u8 gain[SCARLETT2_INPUT_GAIN_MAX]; u8 autogain_switch[SCARLETT2_INPUT_GAIN_MAX]; u8 autogain_status[SCARLETT2_INPUT_GAIN_MAX]; @@ -1284,7 +1284,7 @@ struct scarlett2_data { struct snd_kcontrol *input_mute_ctls[SCARLETT2_INPUT_MUTE_SWITCH_MAX]; struct snd_kcontrol *phantom_ctls[SCARLETT2_PHANTOM_SWITCH_MAX]; struct snd_kcontrol *input_select_ctl; - struct snd_kcontrol *input_link_ctls[SCARLETT2_INPUT_GAIN_MAX / 2]; + struct snd_kcontrol *input_link_ctls[SCARLETT2_INPUT_GAIN_MAX]; struct snd_kcontrol *input_gain_ctls[SCARLETT2_INPUT_GAIN_MAX]; struct snd_kcontrol *autogain_ctls[SCARLETT2_INPUT_GAIN_MAX]; struct snd_kcontrol *autogain_status_ctls[SCARLETT2_INPUT_GAIN_MAX]; @@ -3439,7 +3439,7 @@ static void scarlett2_autogain_update_access(struct usb_mixer_interface *mixer) scarlett2_set_ctl_access(private->input_select_ctl, val); if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_INPUT_LINK_SWITCH)) - for (i = 0; i < info->gain_input_count / 2; i++) + for (i = 0; i < info->gain_input_count; i++) scarlett2_set_ctl_access(private->input_link_ctls[i], val); for (i = 0; i < info->gain_input_count; i++) @@ -3480,7 +3480,7 @@ static void scarlett2_autogain_notify_access(struct usb_mixer_interface *mixer) &private->input_select_ctl->id); if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_INPUT_LINK_SWITCH)) - for (i = 0; i < info->gain_input_count / 2; i++) + for (i = 0; i < info->gain_input_count; i++) snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, &private->input_link_ctls[i]->id); for (i = 0; i < info->gain_input_count; i++) @@ -3825,7 +3825,7 @@ static int scarlett2_update_input_select(struct usb_mixer_interface *mixer) { struct scarlett2_data *private = mixer->private_data; const struct scarlett2_device_info *info = private->info; - int link_count = info->gain_input_count / 2; + int link_count = info->gain_input_count; int err; private->input_select_updated = 0; @@ -3847,10 +3847,6 @@ static int scarlett2_update_input_select(struct usb_mixer_interface *mixer) if (err < 0) return err; - /* simplified because no model yet has link_count > 1 */ - if (private->input_link_switch[0]) - private->input_select_switch = 0; - return 0; } @@ -3887,9 +3883,9 @@ static int scarlett2_input_select_ctl_put( struct usb_mixer_elem_info *elem = kctl->private_data; struct usb_mixer_interface *mixer = elem->head.mixer; struct scarlett2_data *private = mixer->private_data; + const struct scarlett2_device_info *info = private->info; int oval, val, err; - int max_val = private->input_link_switch[0] ? 0 : 1; mutex_lock(&private->data_mutex); @@ -3907,19 +3903,18 @@ static int scarlett2_input_select_ctl_put( if (val < 0) val = 0; - else if (val > max_val) - val = max_val; + else if (val >= info->gain_input_count) + val = info->gain_input_count - 1; if (oval == val) goto unlock; private->input_select_switch = val; - /* Send switch change to the device if inputs not linked */ - if (!private->input_link_switch[0]) - err = scarlett2_usb_set_config( - mixer, SCARLETT2_CONFIG_INPUT_SELECT_SWITCH, - 1, val); + /* Send new value to the device */ + err = scarlett2_usb_set_config( + mixer, SCARLETT2_CONFIG_INPUT_SELECT_SWITCH, + 0, val); if (err == 0) err = 1; @@ -3936,8 +3931,7 @@ static int scarlett2_input_select_ctl_info( struct scarlett2_data *private = mixer->private_data; int inputs = private->info->gain_input_count; - int i, j; - int err; + int i, err; char **values = kcalloc(inputs, sizeof(char *), GFP_KERNEL); if (!values) @@ -3954,21 +3948,11 @@ static int scarlett2_input_select_ctl_info( if (err < 0) goto unlock; - /* Loop through each input - * Linked inputs have one value for the pair - */ - for (i = 0, j = 0; i < inputs; i++) { - if (private->input_link_switch[i / 2]) { - values[j++] = kasprintf( - GFP_KERNEL, "Input %d-%d", i + 1, i + 2); - i++; - } else { - values[j++] = kasprintf( - GFP_KERNEL, "Input %d", i + 1); - } - } + /* Loop through each input */ + for (i = 0; i < inputs; i++) + values[i] = kasprintf(GFP_KERNEL, "Input %d", i + 1); - err = snd_ctl_enum_info(uinfo, 1, j, + err = snd_ctl_enum_info(uinfo, 1, i, (const char * const *)values); unlock: @@ -4077,18 +4061,8 @@ static int scarlett2_input_link_ctl_put( private->input_link_switch[index] = val; - /* Notify of change in input select options available */ - snd_ctl_notify(mixer->chip->card, - SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, - &private->input_select_ctl->id); - private->input_select_updated = 1; - - /* Send switch change to the device - * Link for channels 1-2 is at index 1 - * No device yet has more than 2 channels linked - */ err = scarlett2_usb_set_config( - mixer, SCARLETT2_CONFIG_INPUT_LINK_SWITCH, index + 1, val); + mixer, SCARLETT2_CONFIG_INPUT_LINK_SWITCH, index, val); if (err == 0) err = 1; @@ -6914,10 +6888,9 @@ static int scarlett2_add_line_in_ctls(struct usb_mixer_interface *mixer) if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_INPUT_LINK_SWITCH)) { - for (i = 0; i < info->gain_input_count / 2; i++) { + for (i = 0; i < info->gain_input_count; i++) { scnprintf(s, sizeof(s), - "Line In %d-%d Link Capture Switch", - (i * 2) + 1, (i * 2) + 2); + "Line In %d Link Capture Switch", i + 1); err = scarlett2_add_new_ctl( mixer, &scarlett2_input_link_ctl, i, 1, s, &private->input_link_ctls[i]); @@ -8244,7 +8217,7 @@ static void scarlett2_notify_input_select(struct usb_mixer_interface *mixer) SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &private->input_select_ctl->id); - for (i = 0; i < info->gain_input_count / 2; i++) + for (i = 0; i < info->gain_input_count; i++) snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &private->input_link_ctls[i]->id); } From patchwork Fri Oct 4 14:29:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geoffrey D. Bennett" X-Patchwork-Id: 13822468 Received: from m.b4.vu (m.b4.vu [203.16.231.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 008D169D2B for ; Fri, 4 Oct 2024 14:29:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.16.231.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052147; cv=none; b=m0QWIsR2mCePTbtex3N5tL2zLDLElGP3UPTMSugvzrEU25q8rjV2FaPft8fvU67kKr+6xibrbvXVpUkBXVnzuNg72piZc3D3PRwl3VX9YP6aLVoEbWqlm1Z+n0Ec/FpeVXVtjVSATVFY27eI79PhrKJ+hk3K9Rqw1CANZnx9j7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728052147; c=relaxed/simple; bh=0laVtbVpbafhMqABkALz9StUX//CbqWBeufGAYughUY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Aqe+sFnmgXH3u4P46Sd+mSG6h3+N34HcBSSLHJs9Wv7Ep4mokxnMZhRVNq+GM1flGjLhnXEvQjV45Ksm3dF1nTp8kKhj/ErR4gMh/uyCM8LvylvZ9iBhK/8w+RAeRoLcHWjaEISNZVsDowCpFtjhIh8Pzr6Dbl+bH4qc0PyWJNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu; spf=pass smtp.mailfrom=b4.vu; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b=FD8EPII+; arc=none smtp.client-ip=203.16.231.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=b4.vu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=b4.vu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=b4.vu header.i=@b4.vu header.b="FD8EPII+" Received: by m.b4.vu (Postfix, from userid 1000) id 471B761AD441; Fri, 4 Oct 2024 23:59:04 +0930 (ACST) DKIM-Filter: OpenDKIM Filter v2.11.0 m.b4.vu 471B761AD441 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=b4.vu; s=m1; t=1728052144; bh=zrXl6Lbowz6qw6c0UeQY6heqill2klFlnQuaTfCRImk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FD8EPII+1bO4t3P8lPcAKLbcZFEujYYE7KuwjEzY2Kz0FX/WTbv5OI9MQDhwIe9Y7 +80iJtic7UyRrRhwZwdn2sEAAvampLhOt3ZbR0S5Kl8ktvLvC+SgwncLIseqYDXunO iSyoTCkRSLdeA59k+QRC6bnw+ru1nE0l4+Hq/ManB7NSafNrlbckiwLPLH6rQMBsme +Nl7yj/1Mt8X0nfm9LsjME4wdJFfSYfsvnorwV9PWDtVPuwoESPPMGN2YkwqM3wm+C JbGDkWFr/TSeV+JNcuK+Ot3KHS2uHKj0dWMmiRsUHbRmVhXF6NK1fGkiGZh3tg044b SM6rTxa6sGFmA== Date: Fri, 4 Oct 2024 23:59:04 +0930 From: "Geoffrey D. Bennett" To: Takashi Iwai Cc: linux-sound@vger.kernel.org Subject: [PATCH 5/5] ALSA: scarlett2: Add support for device map retrieval Message-ID: References: Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add support for retrieving the device map from Focusrite Scarlett 4th Gen and Vocaster devices. The device map is a base64-encoded, zlib-compressed JSON description of the device's capabilities and configuration. This patch adds: - a has_devmap field to the scarlett2_device_info struct - a /proc/asound/cardX/device-map.json.zz.b64 file when supported Signed-off-by: Geoffrey D. Bennett --- sound/usb/mixer_scarlett2.c | 139 +++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c index b0eca4785bc6..69fa80b9d5bf 100644 --- a/sound/usb/mixer_scarlett2.c +++ b/sound/usb/mixer_scarlett2.c @@ -1079,6 +1079,9 @@ struct scarlett2_device_info { /* minimum firmware version required */ u16 min_firmware_version; + /* has a downloadable device map */ + u8 has_devmap; + /* support for main/alt speaker switching */ u8 has_speaker_switching; @@ -1773,6 +1776,7 @@ static const struct scarlett2_device_info s18i20_gen3_info = { static const struct scarlett2_device_info vocaster_one_info = { .config_set = &scarlett2_config_set_vocaster, .min_firmware_version = 1769, + .has_devmap = 1, .phantom_count = 1, .inputs_per_phantom = 1, @@ -1815,6 +1819,7 @@ static const struct scarlett2_device_info vocaster_one_info = { static const struct scarlett2_device_info vocaster_two_info = { .config_set = &scarlett2_config_set_vocaster, .min_firmware_version = 1769, + .has_devmap = 1, .phantom_count = 2, .inputs_per_phantom = 1, @@ -1858,6 +1863,7 @@ static const struct scarlett2_device_info vocaster_two_info = { static const struct scarlett2_device_info solo_gen4_info = { .config_set = &scarlett2_config_set_gen4_solo, .min_firmware_version = 2115, + .has_devmap = 1, .level_input_count = 1, .air_input_count = 1, @@ -1912,6 +1918,7 @@ static const struct scarlett2_device_info solo_gen4_info = { static const struct scarlett2_device_info s2i2_gen4_info = { .config_set = &scarlett2_config_set_gen4_2i2, .min_firmware_version = 2115, + .has_devmap = 1, .level_input_count = 2, .air_input_count = 2, @@ -1966,6 +1973,7 @@ static const struct scarlett2_device_info s2i2_gen4_info = { static const struct scarlett2_device_info s4i4_gen4_info = { .config_set = &scarlett2_config_set_gen4_4i4, .min_firmware_version = 2089, + .has_devmap = 1, .level_input_count = 2, .air_input_count = 2, @@ -2264,6 +2272,8 @@ static int scarlett2_get_port_start_num( #define SCARLETT2_USB_GET_DATA 0x00800000 #define SCARLETT2_USB_SET_DATA 0x00800001 #define SCARLETT2_USB_DATA_CMD 0x00800002 +#define SCARLETT2_USB_INFO_DEVMAP 0x0080000c +#define SCARLETT2_USB_GET_DEVMAP 0x0080000d #define SCARLETT2_USB_CONFIG_SAVE 6 @@ -2277,6 +2287,14 @@ static int scarlett2_get_port_start_num( #define SCARLETT2_SEGMENT_SETTINGS_NAME "App_Settings" #define SCARLETT2_SEGMENT_FIRMWARE_NAME "App_Upgrade" +/* Gen 4 device firmware provides access to a base64-encoded + * zlib-compressed JSON description of the device's capabilities and + * configuration. This device map is made available in + * /proc/asound/cardX/device-map.json.zz.b64 + */ +#define SCARLETT2_DEVMAP_BLOCK_SIZE 1024 +#define SCARLETT2_DEVMAP_FILENAME "device-map.json.zz.b64" + /* proprietary request/response format */ struct scarlett2_usb_packet { __le32 cmd; @@ -9562,6 +9580,116 @@ static int scarlett2_hwdep_init(struct usb_mixer_interface *mixer) return 0; } +/*** device-map file ***/ + +static ssize_t scarlett2_devmap_read( + struct snd_info_entry *entry, + void *file_private_data, + struct file *file, + char __user *buf, + size_t count, + loff_t pos) +{ + struct usb_mixer_interface *mixer = entry->private_data; + u8 *resp_buf; + const size_t block_size = SCARLETT2_DEVMAP_BLOCK_SIZE; + size_t copied = 0; + + if (pos >= entry->size) + return 0; + + if (pos + count > entry->size) + count = entry->size - pos; + + resp_buf = kmalloc(block_size, GFP_KERNEL); + if (!resp_buf) + return -ENOMEM; + + while (count > 0) { + /* SCARLETT2_USB_GET_DEVMAP reads only on block boundaries, + * so we need to read a whole block and copy the requested + * chunk to userspace. + */ + + __le32 req; + int err; + + /* offset within the block that we're reading */ + size_t offset = pos % block_size; + + /* read_size is block_size except for the last block */ + size_t block_start = pos - offset; + size_t read_size = min_t(size_t, + block_size, + entry->size - block_start); + + /* size of the chunk to copy to userspace */ + size_t copy_size = min_t(size_t, count, read_size - offset); + + /* request the block */ + req = cpu_to_le32(pos / block_size); + err = scarlett2_usb(mixer, SCARLETT2_USB_GET_DEVMAP, + &req, sizeof(req), resp_buf, read_size); + if (err < 0) { + kfree(resp_buf); + return copied ? copied : err; + } + + if (copy_to_user(buf, resp_buf + offset, copy_size)) { + kfree(resp_buf); + return -EFAULT; + } + + buf += copy_size; + pos += copy_size; + copied += copy_size; + count -= copy_size; + } + + kfree(resp_buf); + return copied; +} + +static const struct snd_info_entry_ops scarlett2_devmap_ops = { + .read = scarlett2_devmap_read, +}; + +static int scarlett2_devmap_init(struct usb_mixer_interface *mixer) +{ + struct snd_card *card = mixer->chip->card; + struct scarlett2_data *private = mixer->private_data; + const struct scarlett2_device_info *info = private->info; + __le16 config_len_buf[2]; + int config_len; + struct snd_info_entry *entry; + int err; + + /* If the device doesn't support the DEVMAP commands, don't + * create the /proc/asound/cardX/scarlett.json.zlib entry + */ + if (!info->has_devmap) + return 0; + + err = scarlett2_usb(mixer, SCARLETT2_USB_INFO_DEVMAP, + NULL, 0, &config_len_buf, sizeof(config_len_buf)); + if (err < 0) + return err; + + config_len = le16_to_cpu(config_len_buf[1]); + + err = snd_card_proc_new(card, SCARLETT2_DEVMAP_FILENAME, &entry); + if (err < 0) + return err; + + entry->content = SNDRV_INFO_CONTENT_DATA; + entry->private_data = mixer; + entry->c.ops = &scarlett2_devmap_ops; + entry->size = config_len; + entry->mode = S_IFREG | 0444; + + return 0; +} + int snd_scarlett2_init(struct usb_mixer_interface *mixer) { struct snd_usb_audio *chip = mixer->chip; @@ -9612,11 +9740,20 @@ int snd_scarlett2_init(struct usb_mixer_interface *mixer) } err = scarlett2_hwdep_init(mixer); - if (err < 0) + if (err < 0) { usb_audio_err(mixer->chip, "Error creating %s hwdep device: %d", entry->series_name, err); + return err; + } + + err = scarlett2_devmap_init(mixer); + if (err < 0) + usb_audio_err(mixer->chip, + "Error creating %s devmap entry: %d", + entry->series_name, + err); return err; }