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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,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 4AC11C4338F for ; Wed, 11 Aug 2021 15:27:11 +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 7856260EB2 for ; Wed, 11 Aug 2021 15:27:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7856260EB2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=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 6A1CE174C; Wed, 11 Aug 2021 17:26:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6A1CE174C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1628695627; bh=ns68QrXEZaN87B+t6HFj35tI6Mfk7xun7e+jNDx67VU=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CB59hjt9VwLk1afpXMT5mpH8ZtVmFJmRLKegb6droqZl0asHbsJ7PrAFCGKv8al5M 5Ag3UTqeCffU5VVcM5CUhz6b88EdpeOV7jdFGd36OeddFJ033InDei5WaV0xhe2+6V H/xlV7KPtwloH3SBP+hiEr8mSvgG5Yfa4qrDzzSk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 08B38F8016B; Wed, 11 Aug 2021 17:26:17 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5044AF8020D; Wed, 11 Aug 2021 17:26:15 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 6D1EEF80148 for ; Wed, 11 Aug 2021 17:26:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6D1EEF80148 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OqdRWrTB"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="RG2xGvWz" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id AE9EE20183; Wed, 11 Aug 2021 15:26:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1628695570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6OYnzBvpehxl2TCV0hJo0/rGzlW7Sk7CLAiUwHsUqGI=; b=OqdRWrTBJRGoqSJaBqdlfj1oFiJqGtVla/UvUwWD1msCCAHQyh7tv9g2d55JP0Y5ItPmHQ z8zjU8WfXrxEcUv8jTFzzpstYrBum57bzQ+D1ohkOu8wSm4SUWtSwRmuZ03qVW/SLrZQiY eEO57X+ElzVE3NZizwFFyxy6Hd2QtFo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1628695570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6OYnzBvpehxl2TCV0hJo0/rGzlW7Sk7CLAiUwHsUqGI=; b=RG2xGvWzY7xGKQ3kEjxHkEZ6Y0uoa9Xvoiw9GaPBrNiifhYxbBjKxKiCuNiUGJjJJuqCaH vsQ+YKhPQWa1amDg== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id A93B3A3CE2; Wed, 11 Aug 2021 15:26:10 +0000 (UTC) Date: Wed, 11 Aug 2021 17:26:10 +0200 Message-ID: From: Takashi Iwai To: Damien Zammit Subject: Re: [PATCH] usb-audio: Input source control - digidesign mbox In-Reply-To: <20210808050931.59356-1-damien@zamaudio.com> References: <20210808050931.59356-1-damien@zamaudio.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") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org 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" On Sun, 08 Aug 2021 07:09:31 +0200, Damien Zammit wrote: > > This adds a second mixer control to Digidesign Mbox > to select between Analog/SPDIF capture. > > Users will note that selecting the SPDIF input source > automatically switches the clock mode to sync to SPDIF, > which is a feature of the hardware. > > (You can change the clock source back to internal if you want > to capture from spdif but not sync to its clock although this mode > is probably not recommended). > > Unfortunately, starting the stream resets both modes > to Internally clocked and Analog input mode. Please add your Signed-off-by line. It's mandatory. About the code change: > @@ -596,31 +596,53 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) > > /* Digidesign Mbox 1 clock source switch (internal/spdif) */ > > -static int snd_mbox1_switch_get(struct snd_kcontrol *kctl, > - struct snd_ctl_elem_value *ucontrol) > +static int snd_mbox1_clk_switch_get(struct snd_kcontrol *kctl, > + struct snd_ctl_elem_value *ucontrol) > { > + struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); > + struct snd_usb_audio *chip = list->mixer->chip; > + unsigned char buff[3]; > + You need to wrap the execution with snd_usb_lock_shutdown() / snd_usb_unlock_shutdown(). > + /* Read clock source */ > + snd_usb_ctl_msg(chip->dev, > + usb_rcvctrlpipe(chip->dev, 0), 0x81, > + USB_DIR_IN | > + USB_TYPE_CLASS | > + USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); Please try to align the indent level. And, the execution error check is missing. Also, I believe it'd be wise to make it a helper function, as this is used in another place, too. Ditto for other snd_usb_ctl_msg() calls, too. > +static int snd_mbox1_src_switch_get(struct snd_kcontrol *kctl, > + struct snd_ctl_elem_value *ucontrol) > +{ > + struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); > + struct snd_usb_audio *chip = list->mixer->chip; > + unsigned char source[1]; Missing snd_usb_lock_shutdown() / *_unlock_*() here, too. > + /* Read input source */ > + snd_usb_ctl_msg(chip->dev, > + usb_rcvctrlpipe(chip->dev, 0), 0x81, > + USB_DIR_IN | > + USB_TYPE_CLASS | > + USB_RECIP_INTERFACE, 0x00, 0x500, source, 1); Check the error. > + kctl->private_value = source[0] - 1; The value returned from the hardware isn't reliable. Check whether it's a valid value. > + ucontrol->value.enumerated.item[0] = kctl->private_value; > + return 0; > +} > + > +static int snd_mbox1_src_switch_update(struct usb_mixer_interface *mixer, int val) > +{ > + struct snd_usb_audio *chip = mixer->chip; > + int err; > + unsigned char buff[3]; > + unsigned char source[1]; > + > + err = snd_usb_lock_shutdown(chip); > + if (err < 0) > + return err; > + > + /* Read input source */ > + err = snd_usb_ctl_msg(chip->dev, > + usb_rcvctrlpipe(chip->dev, 0), 0x81, > + USB_DIR_IN | > + USB_TYPE_CLASS | > + USB_RECIP_INTERFACE, 0x00, 0x500, source, 1); > + if (err < 0) > + goto err; > + > + /* 2 possibilities: ANALOG Source -> 0x01 > + * S/PDIF Source -> 0x02 > + * Setting the input source to S/PDIF resets the clock source to S/PDIF > + */ > + source[0] = (val + 1) & 0xff; Here better to trust private_value is a valid value, and you can drop the superfluous "& 0xff". It's cut down anyway. thanks, Takashi