From patchwork Fri Mar 23 10:21:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nobutaka Okabe X-Patchwork-Id: 10303745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 851C6600F6 for ; Fri, 23 Mar 2018 10:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71B7D285A2 for ; Fri, 23 Mar 2018 10:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 663FC28DAD; Fri, 23 Mar 2018 10:21:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50A64285A2 for ; Fri, 23 Mar 2018 10:21:27 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id F10D42673DC; Fri, 23 Mar 2018 11:21:25 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id F35D22673E5; Fri, 23 Mar 2018 11:21:22 +0100 (CET) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by alsa0.perex.cz (Postfix) with ESMTP id DFA5C2673D2 for ; Fri, 23 Mar 2018 11:21:20 +0100 (CET) Received: by mail-pl0-f68.google.com with SMTP id f23-v6so7159009plr.10 for ; Fri, 23 Mar 2018 03:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TL/uL8SjKrq4gtp5f8KIEzv6ejR6KOqHQ+sNZ3tSFGw=; b=lIOdYMuIqfrXKSiLwR1fZ7xaD5SdOe7Jw6AaW7534t5P48OpvJyI3HiVzZ5mGu/TPd t4/GODRM9MMuQmmt2+XsyNlIda0mku2tKumHaj1s1iL9DiTjEtOIU8EBOYpMIz46fpZ/ rY2bIBLOLBlb6Cv7BgRmD240bnQ40KaUkPvnTtYAetfH9ysmcBZYY9wo784Niz7e0Ivz ftmNg1Pei1S2AMicjrZFCqtaWILHrF6CqmvBlFENwdepSe8UVaa77sdEbphxsTQ21IO4 ZCB0jFhjIHHEEhHe3Sw/6K8EYv1/9jd4tLndivhgbQl3hZt7FXSNFGRyJpVJXvv5gEnb iMCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TL/uL8SjKrq4gtp5f8KIEzv6ejR6KOqHQ+sNZ3tSFGw=; b=sbnSLnbUvpEPv0+y8tW2Clc+rGgIYJiaB8A3W818/CYF5D3hY7sECxGNSt1aH2BEH9 lHQ18xSPS2GEJs9cKc/mQ8SyKTeNcX3TNmq2trWqHBZf+J4wk8e2N44d4DsdWKqcXG8t 2r63YAmzfhedGBkvss8pUzVBcEpptGgKkFnT6rb2In8FVPtZe/KpNxfHaivFuqpKv6l1 KJlrLXs/MAC/gIp34vD2JY80zFo2/nPzL4KF2GWQ6knUoMhCDFJbjTkieOR7JMkprgW3 mm+FEt+pRK7lRBYEIePcUEJsVKIt4xTTENql6NtherkIpiRBbGa35QKFfNhTCpVWgnVE NxEQ== X-Gm-Message-State: AElRT7GWMtn5OHh28/kt6En9WSsi5QEGH8AJxPiDbF/HREzSkCw/LSDQ iEQPVBU5vXLxSK/ZrqYQqx4pXw== X-Google-Smtp-Source: AG47ELuMGRgiG5gIeShvdDJEK+QA6eJb7DbGsz0/q9Ln0cfs/ff1QU+fBibiJLiNCTk0aMgUj6drpA== X-Received: by 2002:a17:902:744b:: with SMTP id e11-v6mr2274193plt.351.1521800479362; Fri, 23 Mar 2018 03:21:19 -0700 (PDT) Received: from tiger24.localdomain (p58058-ipngnfx01hodogaya.kanagawa.ocn.ne.jp. [153.156.31.58]) by smtp.gmail.com with ESMTPSA id 85sm17754979pfz.155.2018.03.23.03.21.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Mar 2018 03:21:18 -0700 (PDT) From: Nobutaka Okabe To: alsa-devel@alsa-project.org Date: Fri, 23 Mar 2018 19:21:13 +0900 Message-Id: <20180323102113.6624-1-nob77413@gmail.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180323102000.6577-1-nob77413@gmail.com> References: <20180323102000.6577-1-nob77413@gmail.com> Cc: Nobutaka Okabe , Jurgen Kramer Subject: [alsa-devel] [PATCH 3/3] ALSA: usb-audio: Integrate native DSD support for ITF-USB based DACs. X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Integrate the native DSD support quirk codes of "ITF-USB DSD" based DACs. Now, "is_itf_usb_dsd_2alts_dac()" and "is_itf_usb_dsd_3alts_dac()" is integrated into one function "is_itf_usb_dsd_dac()". So, remove the logic to distinguish UD-501 and UD-501V2 by the "Product Name". The integration is possible by changing the following two functions. - snd_usb_select_mode_quirk(): Change the determination condition of the DSD mode switch command, from the altset number being used, to the audio format being played. Actually, this operation is same as playback using ASIO driver in Windows environment. - snd_usb_interface_dsd_format_quirk(): To which altset supports native DSD is determined by the number of altsets. Previously, it's a constant "2" or "3". Signed-off-by: Nobutaka Okabe --- sound/usb/quirks.c | 81 ++++++++++++++---------------------------------------- 1 file changed, 20 insertions(+), 61 deletions(-) diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 3d2437e88122..57f8e8b09396 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -1151,48 +1151,18 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) /* ITF-USB DSD based DACs need a vendor cmd to switch * between PCM and native DSD mode - * (2 altsets version) */ -static bool is_itf_usb_dsd_2alts_dac(struct snd_usb_audio *chip) +static bool is_itf_usb_dsd_dac(unsigned int id) { - char *product = chip->dev->product; /* DAC product name */ - - switch (chip->usb_id) { + switch (id) { case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */ case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */ case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */ case USB_ID(0x1852, 0x5065): /* Luxman DA-06 */ - return true; - case USB_ID(0x0644, 0x8043): - /* TEAC UD-501 */ - if (product && strcmp("UD-501", product)) { - return true; - } else { - return false; - } - } - return false; -} - -/* ITF-USB DSD based DACs need a vendor cmd to switch - * between PCM and native DSD mode - * (3 altsets version) - */ -static bool is_itf_usb_dsd_3alts_dac(struct snd_usb_audio *chip) -{ - char *product = chip->dev->product; /* DAC product name */ - - switch (chip->usb_id) { + case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-501V2/UD-503/NT-503 */ case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */ case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */ return true; - case USB_ID(0x0644, 0x8043): - /* TEAC UD-501V2/UD-503/NT-503 */ - if (product && !strcmp("UD-501", product)) { - return true; - } else { - return false; - } } return false; } @@ -1203,7 +1173,7 @@ int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, struct usb_device *dev = subs->dev; int err; - if (is_itf_usb_dsd_2alts_dac(subs->stream->chip)) { + if (is_itf_usb_dsd_dac(subs->stream->chip->usb_id)) { /* First switch to alt set 0, otherwise the mode switch cmd * will not be accepted by the DAC */ @@ -1213,37 +1183,26 @@ int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, mdelay(20); /* Delay needed after setting the interface */ - switch (fmt->altsetting) { - case 2: /* DSD mode requested */ - case 1: /* PCM mode requested */ - err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, - USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, - fmt->altsetting - 1, 1, NULL, 0); - if (err < 0) - return err; - break; - } - mdelay(20); - } else if (is_itf_usb_dsd_3alts_dac(subs->stream->chip)) { /* Vendor mode switch cmd is required. */ - switch (fmt->altsetting) { - case 3: /* DSD mode (DSD_U32) requested */ + if (fmt->formats & SNDRV_PCM_FMTBIT_DSD_U32_BE) { + /* DSD mode (DSD_U32) requested */ err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 1, 1, NULL, 0); if (err < 0) return err; - break; - case 2: /* PCM or DOP mode (S32) requested */ - case 1: /* PCM mode (S16) requested */ + } else { + /* PCM or DOP mode (S32) requested */ + /* PCM mode (S16) requested */ err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 0, 1, NULL, 0); if (err < 0) return err; - break; + } + mdelay(20); } return 0; } @@ -1323,7 +1282,7 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, /* ITF-USB DSD based DACs functionality need a delay * after each class compliant request */ - if (is_itf_usb_dsd_2alts_dac(chip) + if (is_itf_usb_dsd_dac(chip->usb_id) && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) mdelay(20); @@ -1349,6 +1308,8 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, struct audioformat *fp, unsigned int sample_bytes) { + struct usb_interface *iface; + /* Playback Designs */ if (USB_ID_VENDOR(chip->usb_id) == 0x23ba) { switch (fp->altsetting) { @@ -1410,15 +1371,13 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, break; } - /* ITF-USB DSD based DACs (2 altsets version) */ - if (is_itf_usb_dsd_2alts_dac(chip)) { - if (fp->altsetting == 2) - return SNDRV_PCM_FMTBIT_DSD_U32_BE; - } + /* ITF-USB DSD based DACs */ + if (is_itf_usb_dsd_dac(chip->usb_id)) { + iface = usb_ifnum_to_if(chip->dev, fp->iface); - /* ITF-USB DSD based DACs (3 altsets version) */ - if (is_itf_usb_dsd_3alts_dac(chip)) { - if (fp->altsetting == 3) + /* Altsetting 2 support native DSD if the num of altsets is three (0-2), + Altsetting 3 support native DSD if the num of altsets is four (0-3). */ + if (fp->altsetting == iface->num_altsetting - 1) return SNDRV_PCM_FMTBIT_DSD_U32_BE; }