Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2652229pxa; Mon, 17 Aug 2020 15:34:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJlD7fijC2eC0S8U6bnDDTtSPVsRKRGtqQT8FHDwuaEtk8fHUctOfiQh7Ok0u8G13Y3jA2 X-Received: by 2002:a17:906:7e05:: with SMTP id e5mr17964827ejr.252.1597703647528; Mon, 17 Aug 2020 15:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597703647; cv=none; d=google.com; s=arc-20160816; b=h3ZuZaOddFay5/lndvGrP7IstjpKSLpK7XU6BEYL+CV7izpXvdrtOwnGJOSS/E4grk b5UrsuGLfbRAhnK5GVEnIkJvVKBi1d//2C5EJcUlxQg/XVYFzUaig3BP56Tk1aq7a9hX 5IEOcj3XHVN9qIzX3xLjTzyUD39SSa8kWaQEhXCqO/Su5fzxtp6cB2ZzhtjDn3gmvVpS kxJm3+9Yai0/Q6pWZX0fvtfX3l78k7BiO5bx8H/wLKKxL/dwMLLG4g9ZJapUJ5ToxsD0 EfjYvm1Wwue2HTTS8pgF07GR4OU27UpOQPyyF1iwhUKgONkfUAkb50qI21nrqEpc4P6P EXNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5hgvEqfDbr2WZW/QyKJ1+LiaV6Sty72eIuzSJpDKQy0=; b=ITyTBbrLOsVZoId7/oOve2bTpuinK7LJHM/EOgPIpxrirzUTY9FBzDonSmfXHOBDtX 9/Mhc5P0zispm0FymO+sSQ7pqpzAG1ALnw+1YSWIsXDaEMnhXJiPCRzxVtH/nu8iuXIM pZZ2IlclZ0lf5P37+o+/x+mOkShMVMQo64T82ORsGrInDuHHGclkSF5ED8qnBzlWZmhJ v9tKRBnUyo5FEAFjX4r5N5wCdBHD1XsJkQdwSxuEE7ADZUFYK41w72ljGX6NnGUg5Z4B N2KeWOzGruvp8kud2lwexDfgXXfCHvRXtkIWrUCMvV/7e1+x8gJ1KAEMrhSMOVAKxY8L IFug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Bpthls62; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si11538140edo.79.2020.08.17.15.33.37; Mon, 17 Aug 2020 15:34:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Bpthls62; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388649AbgHQRIV (ORCPT + 99 others); Mon, 17 Aug 2020 13:08:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:36744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388553AbgHQQKh (ORCPT ); Mon, 17 Aug 2020 12:10:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A0E9120578; Mon, 17 Aug 2020 16:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680630; bh=eLivimOm56pMwF4gQgsZcnUOz4mOosZfB22sIXPRjfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bpthls62uMb3MDy+7/l0lX7Z+arxTAioRB1O7Jorzjo772UzoPsoiHVvToYnW21Xy 4PkW6FqoTlkTAsm1juywdgXFWkspHRQuxZpp2vAtx4Ea3i4s0alW2hxnb64l7aPirP 20oXvWQXwHtuB/urRN3F5iu3JQU1LlOgn/hm4YVc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hector Martin , Takashi Iwai Subject: [PATCH 5.4 233/270] ALSA: usb-audio: work around streaming quirk for MacroSilicon MS2109 Date: Mon, 17 Aug 2020 17:17:14 +0200 Message-Id: <20200817143807.401358620@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hector Martin commit 1b7ecc241a67ad6b584e071bd791a54e0cd5f097 upstream. Further investigation of the L-R swap problem on the MS2109 reveals that the problem isn't that the channels are swapped, but rather that they are swapped and also out of phase by one sample. In other words, the issue is actually that the very first frame that comes from the hardware is a half-frame containing only the right channel, and after that everything becomes offset. So introduce a new quirk field to drop the very first 2 bytes that come in after the format is configured and a capture stream starts. This puts the channels in phase and in the correct order. Cc: stable@vger.kernel.org Signed-off-by: Hector Martin Link: https://lore.kernel.org/r/20200810082400.225858-1-marcan@marcan.st Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/card.h | 1 + sound/usb/pcm.c | 6 ++++++ sound/usb/quirks.c | 3 +++ sound/usb/stream.c | 1 + 4 files changed, 11 insertions(+) --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -133,6 +133,7 @@ struct snd_usb_substream { unsigned int tx_length_quirk:1; /* add length specifier to transfers */ unsigned int fmt_type; /* USB audio format type (1-3) */ unsigned int pkt_offset_adj; /* Bytes to drop from beginning of packets (for non-compliant devices) */ + unsigned int stream_offset_adj; /* Bytes to drop from beginning of stream (for non-compliant devices) */ unsigned int running: 1; /* running status */ --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1417,6 +1417,12 @@ static void retire_capture_urb(struct sn // continue; } bytes = urb->iso_frame_desc[i].actual_length; + if (subs->stream_offset_adj > 0) { + unsigned int adj = min(subs->stream_offset_adj, bytes); + cp += adj; + bytes -= adj; + subs->stream_offset_adj -= adj; + } frames = bytes / stride; if (!subs->txfr_quirk) bytes = frames * stride; --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -1432,6 +1432,9 @@ void snd_usb_set_format_quirk(struct snd case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */ set_format_emu_quirk(subs, fmt); break; + case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */ + subs->stream_offset_adj = 2; + break; } } --- a/sound/usb/stream.c +++ b/sound/usb/stream.c @@ -94,6 +94,7 @@ static void snd_usb_init_substream(struc subs->tx_length_quirk = as->chip->tx_length_quirk; subs->speed = snd_usb_get_speed(subs->dev); subs->pkt_offset_adj = 0; + subs->stream_offset_adj = 0; snd_usb_set_pcm_ops(as->pcm, stream);