Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3467207rdg; Tue, 17 Oct 2023 16:24:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIV9siOB1Pgl7A1sbXDKJu9Vse0Hm8bO6tqUAw1nMKqdp6m9slpPO+cDl6oFFmX9V//Beo X-Received: by 2002:a17:903:1251:b0:1c6:25c2:e784 with SMTP id u17-20020a170903125100b001c625c2e784mr4439146plh.35.1697585046242; Tue, 17 Oct 2023 16:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697585046; cv=none; d=google.com; s=arc-20160816; b=KGK46nZpNWE3J15xCnkWPakY0Puce48ju71ouUzW+SzXSFy4rqsVHb90tUSispERIo fA41AgYfuxm64E7RS1IeAo2j3JwI/hxL0fGyH9OybakkMIRCj7gWPOEac9fqfV24Ljak NoOzSOD3wNsyfnBhI2OcxrruIOvaZJCKUCJrkPlipYU+bakmcesNB1YgOYDj7IqAGLtj +C/lvnazJYFS0i6CPqV73lXHpGF6Osfgis+DcGzPsr03IrRQuEqI9wx53+j1AjKlcwhc MYSEf/s2EMG/2KAmbaYq8PcodBpRLQPcsEBqouvU4qxCD4pSjcIw43rgLUTiacSWLFRU 76qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=E0AidXWt3rl43sW2d8wXWtXV5jZi/gimyKovB3SQEmM=; fh=T2kIl/luTXifFXsTyrv3SMMIMK/cqEF9ESJJzecA3Cs=; b=ffAPmeY7ZSMAUCiSWQFHRyuHjOaKD8EHSn+O1wWufwvYM+SuWXAarzOWV6fbzDVZQ8 spSvt0hdN+m3RqWci7EAJs0BOU9Imwc730GiQsf1bP+KcRcuc7/BsKnhCXv2Gu7E4PqW z0BL1UwxBiTFhDbypgYk9Y3+xPDat7LFoPLFuBP3OofVJMPregFWGjiqlYwrJioVj9iW S1rxH7p7y6KDqDVZpi3Yzfvcv9VSnPd+47f8M56Zk5mLa+kGpi5qRSaeiDjJdbkyQ8gw zrE1JkQt1etlkAZVdrWkZ0+obq53x8AmEQg6xTUKzQH8IuV/iMCro+06yqEQLP1OEyIw jClA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EED5YeiC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c15-20020a170903234f00b001ca4ad8635esi2904877plh.240.2023.10.17.16.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:24:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EED5YeiC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 16A4C81068C4; Tue, 17 Oct 2023 16:24:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344307AbjJQXXy (ORCPT + 99 others); Tue, 17 Oct 2023 19:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344398AbjJQXXa (ORCPT ); Tue, 17 Oct 2023 19:23:30 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C661B114; Tue, 17 Oct 2023 16:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697585007; x=1729121007; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=0FJzvTVerGtzjb/XtkA0Zjwjnc3FkHsgF3DnNB3GZGY=; b=EED5YeiC9C3KY3npBGdds5EDQlNPwbmP2hDHi+NuoFpNz8orNspxFDYY jWNEVrG29ASFxTvZQRN3zy2hOq246uzg6Az+cPS4g4sh+zLLhNVO24FwV /WwjJWqmtFUmGuhDwgZocRxp6CSECDvLewjRt1ACNm3l+9WeVAewhoikl staxDOk8qiCjqQet+himbQPzIVTpagnKFx2/NHT6XJQV9oJUZENcbdXcE NrBmxee7b5WTRGs5D+CpduKEr2sZKx4w1/IKy9LntSUzUoP1A+929MKJs j7SUjqn1+dX8ct34u2AChEc+t9JvK24Ngiuypl/96DqnUUcqrr18YOPtD w==; X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="384778191" X-IronPort-AV: E=Sophos;i="6.03,233,1694761200"; d="scan'208";a="384778191" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 16:23:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="826637499" X-IronPort-AV: E=Sophos;i="6.03,233,1694761200"; d="scan'208";a="826637499" Received: from asprado-mobl2.amr.corp.intel.com (HELO [10.212.55.179]) ([10.212.55.179]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 16:23:26 -0700 Message-ID: Date: Tue, 17 Oct 2023 17:50:54 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 29/34] ASoC: qcom: qdsp6: Add SND kcontrol to select offload device Content-Language: en-US To: Wesley Cheng , mathias.nyman@intel.com, gregkh@linuxfoundation.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, srinivas.kandagatla@linaro.org, bgoswami@quicinc.com, Thinh.Nguyen@synopsys.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org References: <20231017200109.11407-1-quic_wcheng@quicinc.com> <20231017200109.11407-30-quic_wcheng@quicinc.com> From: Pierre-Louis Bossart In-Reply-To: <20231017200109.11407-30-quic_wcheng@quicinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 17 Oct 2023 16:24:05 -0700 (PDT) On 10/17/23 15:01, Wesley Cheng wrote: > Expose a kcontrol on the platform sound card, which will allow for > userspace to determine which USB card number and PCM device to offload. > This allows for userspace to potentially tag an alternate path for a > specific USB SND card and PCM device. Previously, control was absent, and > the offload path would be enabled on the last USB SND device which was > connected. This logic will continue to be applicable if no mixer input is > received for specific device selection. > > An example to configure the offload device using tinymix: > tinymix -D 0 set 'Q6USB offload SND device select' 1 0 > > The above will set the Q6AFE device token to choose offload on card#1 and > pcm#0. Device selection is made possible by setting the Q6AFE device > token. The audio DSP utilizes this parameter, and will pass this field > back to the USB offload driver within the QMI stream requests. This still begs the question on how userspace would figure what the card1 is and which endpoint is used when PCM0 is opened? Ideally userpace would not have to know anything about "Q6USB". Presumably when other vendors expose their USB offload solution, we would want a generic control name, no? Jaroslav should chime in on this one :-) > Signed-off-by: Wesley Cheng > --- > sound/soc/qcom/qdsp6/q6usb.c | 125 ++++++++++++++++++++++++++++++++++- > 1 file changed, 122 insertions(+), 3 deletions(-) > > diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c > index d697cbe7f184..a95276b7d91d 100644 > --- a/sound/soc/qcom/qdsp6/q6usb.c > +++ b/sound/soc/qcom/qdsp6/q6usb.c > @@ -14,6 +14,7 @@ > #include > > #include > +#include > #include > #include > #include > @@ -35,9 +36,12 @@ struct q6usb_port_data { > struct q6afe_usb_cfg usb_cfg; > struct snd_soc_usb *usb; > struct q6usb_offload priv; > + struct mutex mutex; missing comment on what this protects. "mutex" is really a poor choice/name if I am honest. > unsigned long available_card_slot; > struct q6usb_status status[SNDRV_CARDS]; > - int active_idx; > + bool idx_valid; > + int sel_card_idx; > + int sel_pcm_idx; > }; > +/* Build a mixer control for a UAC connector control (jack-detect) */ > +static void q6usb_connector_control_init(struct snd_soc_component *component) > +{ > + int ret; > + > + ret = snd_ctl_add(component->card->snd_card, > + snd_ctl_new1(&q6usb_offload_dev_ctrl, component)); > + if (ret < 0) > + return; that error handling does not seem terribly useful... > +} > + > static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *component, > const struct of_phandle_args *args, > const char **dai_name) > @@ -115,9 +227,11 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, > > data = dev_get_drvdata(usb->component->dev); > > + mutex_lock(&data->mutex); > if (connected) { > /* We only track the latest USB headset plugged in */ > - data->active_idx = sdev->card_idx; > + if (!data->idx_valid || data->sel_card_idx < 0) > + data->sel_card_idx = sdev->card_idx; > > set_bit(sdev->card_idx, &data->available_card_slot); > data->status[sdev->card_idx].num_pcm = sdev->num_playback; > @@ -127,6 +241,7 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, > data->status[sdev->card_idx].num_pcm = 0; > data->status[sdev->card_idx].chip_index = 0; > } > + mutex_unlock(&data->mutex); > > return 0; > } > @@ -135,6 +250,8 @@ static int q6usb_component_probe(struct snd_soc_component *component) > { > struct q6usb_port_data *data = dev_get_drvdata(component->dev); > > + q6usb_connector_control_init(component); > + > data->usb = snd_soc_usb_add_port(component->dev, &data->priv, q6usb_alsa_connection_cb); > if (IS_ERR(data->usb)) { > dev_err(component->dev, "failed to add usb port\n"); > @@ -189,6 +306,8 @@ static int q6usb_dai_dev_probe(struct platform_device *pdev) > > data->priv.domain = iommu_get_domain_for_dev(&pdev->dev); > > + mutex_init(&data->mutex); > + > data->priv.dev = dev; > dev_set_drvdata(dev, data); >