From mboxrd@z Thu Jan 1 00:00:00 1970 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=-11.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 09324C2D0C6 for ; Fri, 27 Dec 2019 08:49:22 +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 0D25A206F4 for ; Fri, 27 Dec 2019 08:49:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="NG/eV4v2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D25A206F4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de 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 DA3E5170D; Fri, 27 Dec 2019 09:48:28 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DA3E5170D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1577436558; bh=E5BLHgIG1PCRUO2bk84bwc43vB0o2vk0KzUPZKBO6LU=; h=Date:From:To:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NG/eV4v26AgmIJhac/JMtU0HAWKs4EkKPta0E4oddr538AFFuYXq9SqHpEmTxy9VK PFJVNxz4wY/OTUqMGm8O/K4QAgmH0WaeBu3iBP0ILcCSx1K9M89Rnm8784QlvnFoae Es01AxdJnmM4SD4xrr83es6RfKimJI/Q87QuVbLQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5B289F80131; Fri, 27 Dec 2019 09:48:28 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B1C46F80132; Fri, 27 Dec 2019 09:48:26 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 180AFF800AE for ; Fri, 27 Dec 2019 09:48:23 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 180AFF800AE X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 16EADACBD; Fri, 27 Dec 2019 08:48:23 +0000 (UTC) Date: Fri, 27 Dec 2019 09:48:22 +0100 Message-ID: From: Takashi Iwai To: mickflemm@gmail.com In-Reply-To: <5e02cab4.1c69fb81.83bec.f334@mx.google.com> References: <5e02cab4.1c69fb81.83bec.f334@mx.google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Cc: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] [PATCH] ALSA: usb-audio: Add support for Presonus Studio 1810c 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Wed, 25 Dec 2019 03:34:24 +0100, mickflemm@gmail.com wrote: > > This patch adds support for Presonus Studio 1810c, a usb interface > that's UAC2 compliant with a few quirks and a few extra hw-specific > controls. I've tested all 3 altsettings and the added switch > controls and they work as expected. > > More infos on the card: > https://www.presonus.com/products/Studio-1810c > > Note that this work is based on packet inspection with > usbmon. I just wanted to get this card to work for using > it on our open-source radio station: > https://github.com/UoC-Radio > > Signed-off-by: Nick Kossifidis Thanks for the patch. In addition to the issues kbuild bot suggested, below are my quick review comments: > diff --git a/sound/usb/format.c b/sound/usb/format.c > index d79db7130..edf3f2a55 100644 > --- a/sound/usb/format.c > +++ b/sound/usb/format.c > @@ -262,6 +262,23 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, > } > > for (rate = min; rate <= max; rate += res) { > + > + /* > + * Presonus Studio 1810c anounces invalid > + * sampling rates for its streams. > + */ > + if (chip->usb_id == USB_ID(0x0194f, 0x010c) && > + ((rate > 48000 && fp->altsetting == 1) || > + ((rate < 88200 || rate > 96000) > + && fp->altsetting == 2) || > + ((rate < 176400 || rate > 192000) > + && fp->altsetting == 3))) { > + if (res) > + continue; > + else > + break; > + } It's hard to imagine what result this would lead to, because the conditions are so complex. Maybe better to prepare a fixed table instead? Or, can we simply take a fixed quirk? > diff --git a/sound/usb/mixer_s1810c.c b/sound/usb/mixer_s1810c.c > new file mode 100644 > index 000000000..ff86e4aab > --- /dev/null > +++ b/sound/usb/mixer_s1810c.c > @@ -0,0 +1,565 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Presonus Studio 1810c driver for ALSA > + * Copyright (C) 2019 Nick Kossifidis > + * > + * Based on reverse engineering of the communication protocol > + * between the windows driver / Univeral Control (UC) program > + * and the device, through usbmon. > + * > + * For now this bypasses the mixer, with all channels split, > + * so that the software can mix with greater flexibility. > + * It also adds controls for the 4 buttons on the front of > + * the device. > + */ Usually place a blank line here. > +#include > +#include > +#include > +#include The common practice is to group linux/*.h first, followed by sound/*.h. And is almost always needed before other sound/*.h. > +struct s1810c_ctl_packet { > + uint32_t a; > + uint32_t b; > + uint32_t fixed1; > + uint32_t fixed2; > + uint32_t c; > + uint32_t d; > + uint32_t e; Use u32, u16 or such types instead of uint*_t. It's the standard type for kernel codes. Also applied in other places in the patch, too. > +static int > +snd_sc1810c_get_status_field(struct usb_device *dev, > + uint32_t *field, int field_idx, uint16_t *seqnum) > +{ > + struct s1810c_state_packet pkt_out = { 0 }; > + struct s1810c_state_packet pkt_in = { 0 }; > + int ret = 0; > + > + pkt_out.fields[SC1810C_STATE_F1_IDX] = SC1810C_SET_STATE_F1; > + pkt_out.fields[SC1810C_STATE_F2_IDX] = SC1810C_SET_STATE_F2; > + ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), > + SC1810C_SET_STATE_REQ, > + SC1810C_SET_STATE_REQTYPE, > + (*seqnum), 0, &pkt_out, sizeof(pkt_out)); Avoid unnecessary parentheses around *seqnum. Ditto for other possible places. > +static int > +snd_s1810c_switch_set(struct snd_kcontrol *kctl, > + struct snd_ctl_elem_value *ctl_elem) > +{ > + struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); > + struct usb_mixer_interface *mixer = list->mixer; > + uint32_t curval = 0; > + uint32_t newval = (uint32_t) ctl_elem->value.integer.value[0]; > + int ret = 0; > + > + ret = snd_s1810c_get_switch_state(mixer, kctl, &curval); > + if (ret < 0) > + return 0; > + > + if (curval == newval) > + return 0; > + > + kctl->private_value &= ~(0x1 << 16); > + kctl->private_value |= (unsigned int)(newval & 0x1) << 16; > + ret = snd_s1810c_set_switch_state(mixer, kctl); Hm, this can be racy. The control get/put isn't protected, so you might get the inconsistency here when multiple kctls are accessed concurrently. > +static int > +snd_s1810c_line_sw_info(struct snd_kcontrol *kctl, > + struct snd_ctl_elem_info *uinfo) > +{ > + static const char *const texts[2] = { "Preamp on (Mic/Inst)", > + "Preamp off (Line in)" > + }; Better to put "Preamp on..." item in the next line. > +static struct snd_kcontrol_new snd_s1810c_line_sw = { This (and other following definitions) can be const? > + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, > + .name = "Line 1/2 source type", The control name should consist of words starting with a capital letter, so it should be "Line 1/2 Source Type". Also, usually a control name needs a standard suffix. Though, this has a special return enum type, so it can be OK as is. However... > + .info = snd_s1810c_line_sw_info, > + .get = snd_s1810c_switch_get, > + .put = snd_s1810c_switch_set, ... this shows that the combination is invalid. The enum type doesn't get/put the values in integer fields. It's incompatible. > + .private_value = (SC1810C_STATE_LINE_SW | SC1810C_CTL_LINE_SW << 8) > +}; > + > +static struct snd_kcontrol_new snd_s1810c_mute_sw = { > + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, > + .name = "Mute Main Out", ... and this one, for example, should deserve for "Switch" suffix, as it's a standard boolean switch (which use integer fields unlike enum). > +/* Entry point, called from mixer_quirks.c */ > +int snd_sc1810_init_mixer(struct usb_mixer_interface *mixer) > +{ > + struct s1810_mixer_state *private = NULL; > + struct snd_usb_audio *chip = mixer->chip; > + struct usb_device *dev = chip->dev; > + int ret = 0; > + > + /* Run this only once */ > + if (!list_empty(&chip->mixer_list)) > + return 0; > + > + dev_info(&dev->dev, > + "Presonus Studio 1810c, device_setup: %u\n", chip->setup); > + if (chip->setup == 1) > + dev_info(&dev->dev, "(8out/18in @ 48KHz)\n"); > + else if (chip->setup == 2) > + dev_info(&dev->dev, "(6out/8in @ 192KHz)\n"); > + else > + dev_info(&dev->dev, "(8out/14in @ 96KHz)\n"); > + > + ret = snd_s1810c_init_mixer_maps(chip); > + if (ret < 0) > + return ret; > + > + private = vzalloc(sizeof(struct s1810_mixer_state)); I don't think vmalloc is needed here, as the object is so small. Use kzalloc() and kfree() instead (unless I overlook something). > + if (!private) { > + dev_err(&dev->dev, "could not allocate mixer state\n"); The error message is usually superfluous, as kernel spews the warning in anyway at each allocation error. thanks, Takashi _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org https://mailman.alsa-project.org/mailman/listinfo/alsa-devel