From patchwork Sun Sep 18 18:59:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Krutak X-Patchwork-Id: 9338097 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 240C7607D0 for ; Sun, 18 Sep 2016 19:37:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DCA727C7A for ; Sun, 18 Sep 2016 19:37:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F308E28C20; Sun, 18 Sep 2016 19:37:52 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,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 9EF1A27C7A for ; Sun, 18 Sep 2016 19:37:51 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0B7912669B5; Sun, 18 Sep 2016 21:37:50 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 2889126155B; Sun, 18 Sep 2016 21:35:32 +0200 (CEST) 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 8D7DD261564; Sun, 18 Sep 2016 21:00:48 +0200 (CEST) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by alsa0.perex.cz (Postfix) with ESMTP id 44D8B260A59 for ; Sun, 18 Sep 2016 21:00:46 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id 133so11707958wmq.2 for ; Sun, 18 Sep 2016 12:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=DjZYu9tTP9ExU7L/26xgsyFRilLV3qnShVklQ4uffnY=; b=FniG6E1KW/tGqIeTWdIRCqM2dVVxN6uNqDGBp7PRuCi4VaG5MgoXhwdR6+DsLXsEOo aelJ/p/ozgjGCKtQDDgq65kPlx/SZAb8ZTu0cGXEt7E9JamxogstuklpIklQAdFLXyi5 nMG800rl3f3Ntb6E8Gf3aJXTjGNJ/Ssl6P+K6mt+RYIcQErXygfK+S6qAI0wEZGbUWXt 3pbqlU5Q3Vn7dsFfvoyAjJVOHURp51dZgfLiYY9DUMCcjFXSD9mHJ/WraEcm6uEbjD9V IBDygtDltUjzxhxsRBn4AIJWdGp9m3Q9SyEo37RenUv0JMH1DuaCmScnpXd5ivK6kIxs txCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=DjZYu9tTP9ExU7L/26xgsyFRilLV3qnShVklQ4uffnY=; b=D8VWmPuisbYmI6mIhqWkWu1UOVoKcYJKHVisEiriVrcg5oI+wzc2qxn2pUhxGM4uXE o6X80xLT3b2AfvOJE9zYD33TZTif9Gzf5FOVFhVjvrED9YyKrwFPanhE/WZqKDMJRhxF GH+Wvdnueo+SGCULFu0VMukkwO3XTEV7P/eZ3iQ5VHzDjoUCqbxcSTXJ6Y8GzIBw1C7/ QfNhsdZMyR2T1pamIwOKP2cDRLvsjp5MbKlW1FqPSkDktRHVMGEdEO5jGZuwcdJGWEUL zA+mX49m4SzUio9T/6z/skAygyrwjVaDWbq6/hZBnrB6umb3XW9tVJCPc2Dyzc/n/xrE ds4A== X-Gm-Message-State: AE9vXwOLS+G6vFJi80f3as89JzqwrC7PaZOAFwjq+Opvu5Sl6PI33N9U6+p17JAMWf/ktg== X-Received: by 10.28.10.138 with SMTP id 132mr6798347wmk.1.1474225245833; Sun, 18 Sep 2016 12:00:45 -0700 (PDT) Received: from andree.lan ([217.30.74.231]) by smtp.gmail.com with ESMTPSA id 142sm18158112wmh.12.2016.09.18.12.00.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Sep 2016 12:00:45 -0700 (PDT) From: Andrej Krutak To: tiwai@suse.com, perex@perex.cz, stefanha@gmail.com, grabner@icg.tugraz.at, alsa-devel@alsa-project.org Date: Sun, 18 Sep 2016 20:59:22 +0200 Message-Id: <1474225172-32081-3-git-send-email-dev@andree.sk> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1474225172-32081-1-git-send-email-dev@andree.sk> References: <1470942147-19848-1-git-send-email-dev@andree.sk> <1474225172-32081-1-git-send-email-dev@andree.sk> Cc: Andrej Krutak Subject: [alsa-devel] [PATCH v4 02/12] ALSA: line6: Add high-speed USB support 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 This has two parts: * intervals_per_second setup (high speed needs 8000, instead of 1000) * iso_buffers setup (count of iso buffers depends on USB speed, 2 is not enough for high speed) Signed-off-by: Andrej Krutak --- sound/usb/line6/capture.c | 10 +++++++++- sound/usb/line6/driver.c | 15 ++++++++++----- sound/usb/line6/driver.h | 15 ++++++++++++--- sound/usb/line6/pcm.h | 6 ++---- sound/usb/line6/playback.c | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/sound/usb/line6/capture.c b/sound/usb/line6/capture.c index e20a6bd..44e9a8c 100644 --- a/sound/usb/line6/capture.c +++ b/sound/usb/line6/capture.c @@ -181,7 +181,15 @@ static void audio_in_callback(struct urb *urb) length += fsize; - /* the following assumes LINE6_ISO_PACKETS == 1: */ + BUILD_BUG_ON_MSG(LINE6_ISO_PACKETS != 1, + "The following code assumes LINE6_ISO_PACKETS == 1"); + /* TODO: + * Also, if iso_buffers != 2, the prev frame is almost random at + * playback side. + * This needs to be redesigned. It should be "stable", but we may + * experience sync problems on such high-speed configs. + */ + line6pcm->prev_fbuf = fbuf; line6pcm->prev_fsize = fsize; diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index 527c408..14032d9 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -462,14 +462,18 @@ static void line6_destruct(struct snd_card *card) static void line6_get_interval(struct usb_line6 *line6) { struct usb_device *usbdev = line6->usbdev; - struct usb_host_endpoint *ep; - unsigned pipe = usb_rcvintpipe(usbdev, line6->properties->ep_ctrl_r); - unsigned epnum = usb_pipeendpoint(pipe); + struct usb_host_endpoint *ep = usbdev->ep_in[line6->properties->ep_ctrl_r]; - ep = usbdev->ep_in[epnum]; - line6->iso_buffers = LINE6_ISO_BUFFERS; if (ep) { line6->interval = ep->desc.bInterval; + if (usbdev->speed == USB_SPEED_LOW) { + line6->intervals_per_second = USB_LOW_INTERVALS_PER_SECOND; + line6->iso_buffers = USB_LOW_ISO_BUFFERS; + } else { + line6->intervals_per_second = USB_HIGH_INTERVALS_PER_SECOND; + line6->iso_buffers = USB_HIGH_ISO_BUFFERS; + } + line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize); } else { dev_err(line6->ifcdev, @@ -559,6 +563,7 @@ int line6_probe(struct usb_interface *interface, /* query interface number */ interface_number = interface->cur_altsetting->desc.bInterfaceNumber; + /* TODO reserves the bus bandwidth even without actual transfer */ ret = usb_set_interface(usbdev, interface_number, properties->altsetting); if (ret < 0) { diff --git a/sound/usb/line6/driver.h b/sound/usb/line6/driver.h index 43dd1d0..a55eb88 100644 --- a/sound/usb/line6/driver.h +++ b/sound/usb/line6/driver.h @@ -18,7 +18,13 @@ #include "midi.h" -#define USB_INTERVALS_PER_SECOND 1000 +/* USB 1.1 speed configuration */ +#define USB_LOW_INTERVALS_PER_SECOND 1000 +#define USB_LOW_ISO_BUFFERS 2 + +/* USB 2.0+ speed configuration */ +#define USB_HIGH_INTERVALS_PER_SECOND 8000 +#define USB_HIGH_ISO_BUFFERS 16 /* Fallback USB interval and max packet size values */ #define LINE6_FALLBACK_INTERVAL 10 @@ -109,12 +115,15 @@ struct usb_line6 { /* Properties */ const struct line6_properties *properties; - /* Interval (ms) */ + /* Interval for data USB packets */ int interval; + /* ...for isochronous transfers framing */ + int intervals_per_second; + /* Number of isochronous URBs used for frame transfers */ int iso_buffers; - /* Maximum size of USB packet */ + /* Maximum size of data USB packet */ int max_packet_size; /* Device representing the USB interface */ diff --git a/sound/usb/line6/pcm.h b/sound/usb/line6/pcm.h index e983880..38bf4df 100644 --- a/sound/usb/line6/pcm.h +++ b/sound/usb/line6/pcm.h @@ -20,9 +20,6 @@ #include "driver.h" -/* number of URBs */ -#define LINE6_ISO_BUFFERS 2 - /* number of USB frames per URB The Line 6 Windows driver always transmits two frames per packet, but @@ -31,7 +28,8 @@ */ #define LINE6_ISO_PACKETS 1 -/* in a "full speed" device (such as the PODxt Pro) this means 1ms */ +/* in a "full speed" device (such as the PODxt Pro) this means 1ms, + for "high speed" it's 1/8ms */ #define LINE6_ISO_INTERVAL 1 #define LINE6_IMPULSE_DEFAULT_PERIOD 100 diff --git a/sound/usb/line6/playback.c b/sound/usb/line6/playback.c index 7a52806..d53aad1 100644 --- a/sound/usb/line6/playback.c +++ b/sound/usb/line6/playback.c @@ -151,7 +151,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) line6pcm->properties->rates.rats[0].num_min; const int frame_factor = line6pcm->properties->rates.rats[0].den * - (USB_INTERVALS_PER_SECOND / LINE6_ISO_INTERVAL); + (line6pcm->line6->intervals_per_second / LINE6_ISO_INTERVAL); struct urb *urb_out; index = find_first_zero_bit(&line6pcm->out.active_urbs,