From patchwork Sat Apr 18 17:19:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Tsoy X-Patchwork-Id: 192977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53DBDC38A29 for ; Sat, 18 Apr 2020 17:20:20 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C953C20776 for ; Sat, 18 Apr 2020 17:20:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="gQhZpKxq"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=tsoy.me header.i=@tsoy.me header.b="ju5jacMh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C953C20776 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=tsoy.me Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1C21E1612; Sat, 18 Apr 2020 19:19:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1C21E1612 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1587230418; bh=vGOsgdAW/IN5jS4Hv45FLJSyLamJDnD+VuNAQpHp5x8=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=gQhZpKxqPXK9KGmspvk/lTxMEhHPe9c3BU9fpLngBQVp0QCqgfqylZRXLsBahLavk CwwLTTQBsMH8jCp2o/tG3E46j17UCdNnU3DR9owjR2WcwhzZav142cn5uOzsV4zQNH iED8kufw+ox4uHFWGjmROBRYLzCC7xeIE4jKbdqo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8B4C9F8014E; Sat, 18 Apr 2020 19:19:27 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CD2EAF8021E; Sat, 18 Apr 2020 19:19:24 +0200 (CEST) Received: from puleglot.ru (puleglot.ru [IPv6:2a01:4f8:1c0c:58e8::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 98A29F8012E for ; Sat, 18 Apr 2020 19:19:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 98A29F8012E Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=tsoy.me header.i=@tsoy.me header.b="ju5jacMh" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tsoy.me; s=mymail; h=Sender:Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=LC4FI5qCqT1TXBHO72NCXSGVI2xp52OATPzLvat5yR4=; b=ju5jacMh3BS9XrVwC1VSeEuTbm a+gGH/W3+Cvbrxd7pHfNWiVwfJkim0r+geiBY/7mDJJ8XUDZUVf5R6UxLwRlHbgBcdO9BMVI8iz/V 7jWS8pNtZiQcJpUXjjVXF6yfRy0SDxb4LaEfFPg7UAWEKfz0wdjtjzc4o6hZWScIS3z0=; Received: from [2a00:1370:8125:3f98:890:f100:d37d:7ada] (helo=home.puleglot.ru) by puleglot.ru with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1jPr7W-00010j-7T; Sat, 18 Apr 2020 20:19:10 +0300 From: Alexander Tsoy To: alsa-devel@alsa-project.org Subject: [PATCH] ALSA: usb-audio: Filter out unsupported sample rates on Focusrite devices Date: Sat, 18 Apr 2020 20:19:08 +0300 Message-Id: <20200418171908.10402-1-alexander@tsoy.me> X-Mailer: git-send-email 2.25.3 MIME-Version: 1.0 Cc: Takashi Iwai , Alexey Skobkin X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Many Focusrite devices supports a limited set of sample rates per altsetting. This includes interfaces with ADAT ports and interfaces with dedicated feedback channels: - Scarlett 18i6, 18i8 1st gen, 18i20 1st gen; - Scarlett 18i8 2nd gen, 18i20 2nd gen; - all Scarlett 3rd gen devices (feedback channels works only up to 96 kHz); - Clarett 2Pre USB, 4Pre USB, 8Pre USB. Tested-by: Alexey Skobkin Signed-off-by: Alexander Tsoy --- sound/usb/format.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/sound/usb/format.c b/sound/usb/format.c index 50e1874c847c..5ffb457cc88c 100644 --- a/sound/usb/format.c +++ b/sound/usb/format.c @@ -277,6 +277,52 @@ static bool s1810c_valid_sample_rate(struct audioformat *fp, return false; } +/* + * Many Focusrite devices supports a limited set of sampling rates per + * altsetting. Maximum rate is exposed in the last 4 bytes of Format Type + * descriptor which has a non-standard bLength = 10. + */ +static bool focusrite_valid_sample_rate(struct snd_usb_audio *chip, + struct audioformat *fp, + unsigned int rate) +{ + struct usb_interface *iface; + struct usb_host_interface *alts; + unsigned char *fmt; + unsigned int max_rate; + + iface = usb_ifnum_to_if(chip->dev, fp->iface); + if (!iface) + return true; + + alts = &iface->altsetting[fp->altset_idx]; + fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, + NULL, UAC_FORMAT_TYPE); + if (!fmt) + return true; + + if (fmt[0] == 10) { /* bLength */ + max_rate = combine_quad(&fmt[6]); + + /* Validate max rate */ + if (max_rate != 48000 && + max_rate != 96000 && + max_rate != 192000 && + max_rate != 384000) { + + usb_audio_info(chip, + "%u:%d : unexpected max rate: %u\n", + fp->iface, fp->altsetting, max_rate); + + return true; + } + + return rate <= max_rate; + } + + return true; +} + /* * Helper function to walk the array of sample rate triplets reported by * the device. The problem is that we need to parse whole array first to @@ -319,6 +365,11 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, !s1810c_valid_sample_rate(fp, rate)) goto skip_rate; + /* Filter out invalid rates on Focusrite devices */ + if (USB_ID_VENDOR(chip->usb_id) == 0x1235 && + !focusrite_valid_sample_rate(chip, fp, rate)) + goto skip_rate; + if (fp->rate_table) fp->rate_table[nr_rates] = rate; if (!fp->rate_min || rate < fp->rate_min)