Message ID | 20240208231406.27397-49-quic_wcheng@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-58854-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp518232dyd; Thu, 8 Feb 2024 15:35:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuL56xIJF+k8czWCMeroo/RpaUqzP64TzAOZB+mXCKBApixEDDxUfVxSFakeOdZQwXMXE1 X-Received: by 2002:a05:620a:3902:b0:783:ae0c:5e8f with SMTP id qr2-20020a05620a390200b00783ae0c5e8fmr1342856qkn.71.1707435327559; Thu, 08 Feb 2024 15:35:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435327; cv=pass; d=google.com; s=arc-20160816; b=xV9Owx1bPWJ0pMrfU58lhqh04+mAG127b5h0BhkrMO50VpZT+04BGOo++O8f/Vbvlz w/WDdaRC4b8ukMMLjGxv+/2chli5zDjB1HtR9Yj4fHpJbd3HSzB61tVp61qBlObiZgZU wjZq4bn06mUoHfSgTVbJWE8pAEeNfWcKGQTlEVfDz2HFc7nain3Lch/CuyJVumQfN5l9 4Y7LZ3RnanPK4SGtCpEBPAkhd7CuHCVskKaIcPi5eBPjlMsIf+GrLtqo14hXe1VMtkFG 6UMEFguCnM+acSSbkVHHbuM3O9EOvpZrv15JOxLbEhBzc92uutKzwALHhPww24omsPiu FdHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6MDZdz79HYTo4EmUJtI2TotOggbgYgDt+zthz34wuRw=; fh=fcnAqnOxFKuvI2gVuKkjl8dj2KiZr8A+0qEPrmeXReE=; b=fGgda+a1a7NdeuRmGFqdWXm6jRad8/Vib4jzIN/QOebeBC2unOynbJw8JS8eulupu+ eB8HaupPSuvj4+JSjzRjpUNuKRYAhVcEe4gHDL6XacVScWdi0C9cZ8M9PARoe0Pu0Zxd le0R2VMPRp9vcgTeU9IF9e4NZCWvDYPz3uHXlp19AYXsKqOYj/V1pjA2vqeZJBjCjqWi S6zUngStBaiWSoOA8vxRHhi2VA6BVtvmXMAyqhjnkw8c0iH9AqXDfgu6iEZgqrC+Vy9i asJvpsHSQyZzXEwjJlARSPhCvygoXS3N2oUzBVcZEnOyfxYHW2Qo1+hmuU4bznVianSW 5fCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JACMIod4; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58854-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCVn9gxycCh+5mlPxd3FCHknJQDIaqddXSSBYj35bq8shgMuJVlKUrU2Ya2wcWw5SSno8mSG3cP1Ez2hJD9tlGSK9HJ5Sg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s19-20020ae9f713000000b007840798bb28si669614qkg.240.2024.02.08.15.35.27 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:35:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JACMIod4; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58854-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C713A1C20AFA for <ouuuleilei@gmail.com>; Thu, 8 Feb 2024 23:35:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92ECD65BBC; Thu, 8 Feb 2024 23:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="JACMIod4" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79E7B55C02; Thu, 8 Feb 2024 23:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434094; cv=none; b=MI3yjQ/4WoLgmnLOcD/aGKxisohbvQ7LphlfSUU/wp+DJOkgwjJxQrXS1cPVibzlaDUI7Wf70U3PvKvvl6z2CA39l8XJrI7nJXC/4Hr/HsGE7vl97GwiykajNWCMIcY1Ak++YQzX0iDhmdp3A2yYC1cQLFReWmTZZ5lcRHZhnl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434094; c=relaxed/simple; bh=1bLwLr0EX/0lvwIzLyQnWS6s7hCSGP8YBc8NPNbcw8w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BfRiFcfbJria6X34GCQ0gH2cCJMEsFkM5egbpUPQ5sD/3IMUWHPiq0l33bRazm9QWvtJh6laZBNRtKihABo/yH0WlKupcoq6Y/4mePV24NAfrUhfFQx8jd9fJyILn2hRq35Li2TBzv28tCQAGalUP2iHy4JhsGHJmcA5Cq0cBmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=JACMIod4; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418N3G8k027491; Thu, 8 Feb 2024 23:14:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=6MDZdz79HYTo4EmUJtI2 TotOggbgYgDt+zthz34wuRw=; b=JACMIod45ACt+XoJzYnI8bXHgWPxrf/ThDRz ZfZUnIbQJsMhewume4mpPeGOit2aWSUm/DlFpu38qJ2frf75qXjAIcXFsWTQVpKQ vfAIbIU/gYd0Rkx8/8QYirW2A4jHrEi5Bs8uoU8WIsx16ntJ9ZyHx14ceYd53AT3 FyySG7/LBZeGLUpMEKZfv0Q3qEZkIrKwbdNUupbqh9VXJzYmn3WXuonBAzIhwKy7 nlvMNHCwK7bss17QdYL/pvJKfAvlcgL/dphvjWwVoswKs/9XhnG7sb3u+otgGFnt NeOyXVU368TCTUOcT81yB/fqZ6qxrOeLhijUFeobuHC/xsZDwg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sns2ab3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:30 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 418NETpo005648 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:29 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:28 -0800 From: Wesley Cheng <quic_wcheng@quicinc.com> To: <srinivas.kandagatla@linaro.org>, <mathias.nyman@intel.com>, <perex@perex.cz>, <conor+dt@kernel.org>, <corbet@lwn.net>, <lgirdwood@gmail.com>, <andersson@kernel.org>, <krzysztof.kozlowski+dt@linaro.org>, <gregkh@linuxfoundation.org>, <Thinh.Nguyen@synopsys.com>, <broonie@kernel.org>, <bgoswami@quicinc.com>, <tiwai@suse.com>, <robh+dt@kernel.org>, <konrad.dybcio@linaro.org> CC: <linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>, <linux-sound@vger.kernel.org>, <linux-usb@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>, <linux-doc@vger.kernel.org>, <alsa-devel@alsa-project.org>, Wesley Cheng <quic_wcheng@quicinc.com> Subject: [PATCH v14 48/53] ALSA: usb-audio: mixer: Add USB offloading mixer control Date: Thu, 8 Feb 2024 15:14:01 -0800 Message-ID: <20240208231406.27397-49-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: a5yJ6nA3VQT2S0mNjM3lD1FT4BtXQGer X-Proofpoint-GUID: a5yJ6nA3VQT2S0mNjM3lD1FT4BtXQGer X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375706095552867 X-GMAIL-MSGID: 1790375706095552867 |
Series |
Introduce QC USB SND audio offloading support
|
|
Commit Message
Wesley Cheng
Feb. 8, 2024, 11:14 p.m. UTC
In order to allow userspace/applications know about USB offloading status,
expose a sound kcontrol that fetches information about which sound card
index is associated with the ASoC platform card supporting offloading. In
the USB audio offloading framework, the ASoC BE DAI link is the entity
responsible for registering to the SOC USB layer. SOC USB will expose more
details about the current offloading status, which includes the USB sound
card and USB PCM device indexes currently being used.
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
---
sound/usb/Kconfig | 4 ++
sound/usb/Makefile | 1 +
sound/usb/mixer.c | 5 +++
sound/usb/mixer_usb_offload.c | 72 +++++++++++++++++++++++++++++++++++
sound/usb/mixer_usb_offload.h | 17 +++++++++
5 files changed, 99 insertions(+)
create mode 100644 sound/usb/mixer_usb_offload.c
create mode 100644 sound/usb/mixer_usb_offload.h
Comments
On Fri, 09 Feb 2024 00:14:01 +0100, Wesley Cheng wrote: > > In order to allow userspace/applications know about USB offloading status, > expose a sound kcontrol that fetches information about which sound card > index is associated with the ASoC platform card supporting offloading. In > the USB audio offloading framework, the ASoC BE DAI link is the entity > responsible for registering to the SOC USB layer. SOC USB will expose more > details about the current offloading status, which includes the USB sound > card and USB PCM device indexes currently being used. > > Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com> Now looking at this again, I noticed that this will bring the hard-dependency on ASoC stuff to USB-audio driver, since it adds the call of snd_soc_usb_device_offload_available(). Maybe we can let the add-on platform adding/removing the control element on the fly instead? thanks, Takashi > --- > sound/usb/Kconfig | 4 ++ > sound/usb/Makefile | 1 + > sound/usb/mixer.c | 5 +++ > sound/usb/mixer_usb_offload.c | 72 +++++++++++++++++++++++++++++++++++ > sound/usb/mixer_usb_offload.h | 17 +++++++++ > 5 files changed, 99 insertions(+) > create mode 100644 sound/usb/mixer_usb_offload.c > create mode 100644 sound/usb/mixer_usb_offload.h > > diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig > index 4c842fbe6365..3e7be258d0e3 100644 > --- a/sound/usb/Kconfig > +++ b/sound/usb/Kconfig > @@ -176,10 +176,14 @@ config SND_BCD2000 > To compile this driver as a module, choose M here: the module > will be called snd-bcd2000. > > +config SND_USB_OFFLOAD_MIXER > + bool > + > config SND_USB_AUDIO_QMI > tristate "Qualcomm Audio Offload driver" > depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND > select SND_PCM > + select SND_USB_OFFLOAD_MIXER > help > Say Y here to enable the Qualcomm USB audio offloading feature. > > diff --git a/sound/usb/Makefile b/sound/usb/Makefile > index 246788268ddd..8c54660a11b0 100644 > --- a/sound/usb/Makefile > +++ b/sound/usb/Makefile > @@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ > stream.o \ > validate.o > > +snd-usb-audio-$(CONFIG_SND_USB_OFFLOAD_MIXER) += mixer_usb_offload.o > snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o > snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o > > diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c > index 409fc1164694..09229e623469 100644 > --- a/sound/usb/mixer.c > +++ b/sound/usb/mixer.c > @@ -48,6 +48,7 @@ > #include "mixer.h" > #include "helper.h" > #include "mixer_quirks.h" > +#include "mixer_usb_offload.h" > #include "power.h" > > #define MAX_ID_ELEMS 256 > @@ -3609,6 +3610,10 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif) > if (err < 0) > goto _error; > > + err = snd_usb_offload_init_mixer(mixer); > + if (err < 0) > + goto _error; > + > err = snd_device_new(chip->card, SNDRV_DEV_CODEC, mixer, &dev_ops); > if (err < 0) > goto _error; > diff --git a/sound/usb/mixer_usb_offload.c b/sound/usb/mixer_usb_offload.c > new file mode 100644 > index 000000000000..61b17359b987 > --- /dev/null > +++ b/sound/usb/mixer_usb_offload.c > @@ -0,0 +1,72 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. > + */ > + > +#include <linux/usb.h> > + > +#include <sound/core.h> > +#include <sound/control.h> > +#include <sound/soc-usb.h> > + > +#include "card.h" > +#include "mixer.h" > +#include "mixer_usb_offload.h" > +#include "usbaudio.h" > + > +static int > +snd_usb_offload_create_mixer(struct usb_mixer_interface *mixer, > + const struct snd_kcontrol_new *new_kctl) > +{ > + struct snd_usb_audio *chip = mixer->chip; > + struct usb_device *udev = chip->dev; > + > + return snd_ctl_add(chip->card, > + snd_ctl_new1(new_kctl, udev->bus->sysdev)); > +} > + > +static int > +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + struct device *sysdev = snd_kcontrol_chip(kcontrol); > + int ret; > + > + ret = snd_soc_usb_device_offload_available(sysdev); > + ucontrol->value.integer.value[0] = ret < 0 ? -1 : ret; > + > + return ret < 0 ? ret : 0; > +} > + > +static int snd_usb_offload_available_info(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_info *uinfo) > +{ > + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; > + uinfo->count = 1; > + uinfo->value.integer.min = -1; > + uinfo->value.integer.max = SNDRV_CARDS; > + > + return 0; > +} > + > +static const struct snd_kcontrol_new snd_usb_offload_available_ctl = { > + .iface = SNDRV_CTL_ELEM_IFACE_CARD, > + .access = SNDRV_CTL_ELEM_ACCESS_READ, > + .name = "USB Offload Playback Capable Card", > + .info = snd_usb_offload_available_info, > + .get = snd_usb_offload_available_get, > +}; > + > +/** > + * snd_usb_offload_init_mixer() - Add USB offload bounded mixer > + * @mixer - USB mixer > + * > + * Creates a sound control for a USB audio device, so that applications can > + * query for if there is an available USB audio offload path, and which > + * card is managing it. > + */ > +int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer) > +{ > + return snd_usb_offload_create_mixer(mixer, &snd_usb_offload_available_ctl); > +} > +EXPORT_SYMBOL_GPL(snd_usb_offload_init_mixer); > diff --git a/sound/usb/mixer_usb_offload.h b/sound/usb/mixer_usb_offload.h > new file mode 100644 > index 000000000000..fb88e872d8fa > --- /dev/null > +++ b/sound/usb/mixer_usb_offload.h > @@ -0,0 +1,17 @@ > +/* SPDX-License-Identifier: GPL-2.0 > + * > + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. > + */ > + > +#ifndef __USB_OFFLOAD_MIXER_H > +#define __USB_OFFLOAD_MIXER_H > + > +#if IS_ENABLED(CONFIG_SND_USB_OFFLOAD_MIXER) > +int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer); > +#else > +static int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer) > +{ > + return 0; > +} > +#endif > +#endif /* __USB_OFFLOAD_MIXER_H */
Hi Takashi, On 2/9/2024 2:36 AM, Takashi Iwai wrote: > On Fri, 09 Feb 2024 00:14:01 +0100, > Wesley Cheng wrote: >> >> In order to allow userspace/applications know about USB offloading status, >> expose a sound kcontrol that fetches information about which sound card >> index is associated with the ASoC platform card supporting offloading. In >> the USB audio offloading framework, the ASoC BE DAI link is the entity >> responsible for registering to the SOC USB layer. SOC USB will expose more >> details about the current offloading status, which includes the USB sound >> card and USB PCM device indexes currently being used. >> >> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com> > > Now looking at this again, I noticed that this will bring the > hard-dependency on ASoC stuff to USB-audio driver, since it adds the > call of snd_soc_usb_device_offload_available(). > > Maybe we can let the add-on platform adding/removing the control > element on the fly instead? > Sure, I'll move it into the QC offload driver. As long as we have a standard API within USB SND that other vendors can also add to their offload drivers, I think that is sufficient. Thanks Wesley Cheng > > thanks, > > Takashi > >> --- >> sound/usb/Kconfig | 4 ++ >> sound/usb/Makefile | 1 + >> sound/usb/mixer.c | 5 +++ >> sound/usb/mixer_usb_offload.c | 72 +++++++++++++++++++++++++++++++++++ >> sound/usb/mixer_usb_offload.h | 17 +++++++++ >> 5 files changed, 99 insertions(+) >> create mode 100644 sound/usb/mixer_usb_offload.c >> create mode 100644 sound/usb/mixer_usb_offload.h >> >> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig >> index 4c842fbe6365..3e7be258d0e3 100644 >> --- a/sound/usb/Kconfig >> +++ b/sound/usb/Kconfig >> @@ -176,10 +176,14 @@ config SND_BCD2000 >> To compile this driver as a module, choose M here: the module >> will be called snd-bcd2000. >> >> +config SND_USB_OFFLOAD_MIXER >> + bool >> + >> config SND_USB_AUDIO_QMI >> tristate "Qualcomm Audio Offload driver" >> depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND >> select SND_PCM >> + select SND_USB_OFFLOAD_MIXER >> help >> Say Y here to enable the Qualcomm USB audio offloading feature. >> >> diff --git a/sound/usb/Makefile b/sound/usb/Makefile >> index 246788268ddd..8c54660a11b0 100644 >> --- a/sound/usb/Makefile >> +++ b/sound/usb/Makefile >> @@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ >> stream.o \ >> validate.o >> >> +snd-usb-audio-$(CONFIG_SND_USB_OFFLOAD_MIXER) += mixer_usb_offload.o >> snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o >> snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o >> >> diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c >> index 409fc1164694..09229e623469 100644 >> --- a/sound/usb/mixer.c >> +++ b/sound/usb/mixer.c >> @@ -48,6 +48,7 @@ >> #include "mixer.h" >> #include "helper.h" >> #include "mixer_quirks.h" >> +#include "mixer_usb_offload.h" >> #include "power.h" >> >> #define MAX_ID_ELEMS 256 >> @@ -3609,6 +3610,10 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif) >> if (err < 0) >> goto _error; >> >> + err = snd_usb_offload_init_mixer(mixer); >> + if (err < 0) >> + goto _error; >> + >> err = snd_device_new(chip->card, SNDRV_DEV_CODEC, mixer, &dev_ops); >> if (err < 0) >> goto _error; >> diff --git a/sound/usb/mixer_usb_offload.c b/sound/usb/mixer_usb_offload.c >> new file mode 100644 >> index 000000000000..61b17359b987 >> --- /dev/null >> +++ b/sound/usb/mixer_usb_offload.c >> @@ -0,0 +1,72 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. >> + */ >> + >> +#include <linux/usb.h> >> + >> +#include <sound/core.h> >> +#include <sound/control.h> >> +#include <sound/soc-usb.h> >> + >> +#include "card.h" >> +#include "mixer.h" >> +#include "mixer_usb_offload.h" >> +#include "usbaudio.h" >> + >> +static int >> +snd_usb_offload_create_mixer(struct usb_mixer_interface *mixer, >> + const struct snd_kcontrol_new *new_kctl) >> +{ >> + struct snd_usb_audio *chip = mixer->chip; >> + struct usb_device *udev = chip->dev; >> + >> + return snd_ctl_add(chip->card, >> + snd_ctl_new1(new_kctl, udev->bus->sysdev)); >> +} >> + >> +static int >> +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, >> + struct snd_ctl_elem_value *ucontrol) >> +{ >> + struct device *sysdev = snd_kcontrol_chip(kcontrol); >> + int ret; >> + >> + ret = snd_soc_usb_device_offload_available(sysdev); >> + ucontrol->value.integer.value[0] = ret < 0 ? -1 : ret; >> + >> + return ret < 0 ? ret : 0; >> +} >> + >> +static int snd_usb_offload_available_info(struct snd_kcontrol *kcontrol, >> + struct snd_ctl_elem_info *uinfo) >> +{ >> + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; >> + uinfo->count = 1; >> + uinfo->value.integer.min = -1; >> + uinfo->value.integer.max = SNDRV_CARDS; >> + >> + return 0; >> +} >> + >> +static const struct snd_kcontrol_new snd_usb_offload_available_ctl = { >> + .iface = SNDRV_CTL_ELEM_IFACE_CARD, >> + .access = SNDRV_CTL_ELEM_ACCESS_READ, >> + .name = "USB Offload Playback Capable Card", >> + .info = snd_usb_offload_available_info, >> + .get = snd_usb_offload_available_get, >> +}; >> + >> +/** >> + * snd_usb_offload_init_mixer() - Add USB offload bounded mixer >> + * @mixer - USB mixer >> + * >> + * Creates a sound control for a USB audio device, so that applications can >> + * query for if there is an available USB audio offload path, and which >> + * card is managing it. >> + */ >> +int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer) >> +{ >> + return snd_usb_offload_create_mixer(mixer, &snd_usb_offload_available_ctl); >> +} >> +EXPORT_SYMBOL_GPL(snd_usb_offload_init_mixer); >> diff --git a/sound/usb/mixer_usb_offload.h b/sound/usb/mixer_usb_offload.h >> new file mode 100644 >> index 000000000000..fb88e872d8fa >> --- /dev/null >> +++ b/sound/usb/mixer_usb_offload.h >> @@ -0,0 +1,17 @@ >> +/* SPDX-License-Identifier: GPL-2.0 >> + * >> + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. >> + */ >> + >> +#ifndef __USB_OFFLOAD_MIXER_H >> +#define __USB_OFFLOAD_MIXER_H >> + >> +#if IS_ENABLED(CONFIG_SND_USB_OFFLOAD_MIXER) >> +int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer); >> +#else >> +static int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer) >> +{ >> + return 0; >> +} >> +#endif >> +#endif /* __USB_OFFLOAD_MIXER_H */
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 4c842fbe6365..3e7be258d0e3 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,10 +176,14 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000. +config SND_USB_OFFLOAD_MIXER + bool + config SND_USB_AUDIO_QMI tristate "Qualcomm Audio Offload driver" depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND select SND_PCM + select SND_USB_OFFLOAD_MIXER help Say Y here to enable the Qualcomm USB audio offloading feature. diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 246788268ddd..8c54660a11b0 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ stream.o \ validate.o +snd-usb-audio-$(CONFIG_SND_USB_OFFLOAD_MIXER) += mixer_usb_offload.o snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index 409fc1164694..09229e623469 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -48,6 +48,7 @@ #include "mixer.h" #include "helper.h" #include "mixer_quirks.h" +#include "mixer_usb_offload.h" #include "power.h" #define MAX_ID_ELEMS 256 @@ -3609,6 +3610,10 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif) if (err < 0) goto _error; + err = snd_usb_offload_init_mixer(mixer); + if (err < 0) + goto _error; + err = snd_device_new(chip->card, SNDRV_DEV_CODEC, mixer, &dev_ops); if (err < 0) goto _error; diff --git a/sound/usb/mixer_usb_offload.c b/sound/usb/mixer_usb_offload.c new file mode 100644 index 000000000000..61b17359b987 --- /dev/null +++ b/sound/usb/mixer_usb_offload.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include <linux/usb.h> + +#include <sound/core.h> +#include <sound/control.h> +#include <sound/soc-usb.h> + +#include "card.h" +#include "mixer.h" +#include "mixer_usb_offload.h" +#include "usbaudio.h" + +static int +snd_usb_offload_create_mixer(struct usb_mixer_interface *mixer, + const struct snd_kcontrol_new *new_kctl) +{ + struct snd_usb_audio *chip = mixer->chip; + struct usb_device *udev = chip->dev; + + return snd_ctl_add(chip->card, + snd_ctl_new1(new_kctl, udev->bus->sysdev)); +} + +static int +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct device *sysdev = snd_kcontrol_chip(kcontrol); + int ret; + + ret = snd_soc_usb_device_offload_available(sysdev); + ucontrol->value.integer.value[0] = ret < 0 ? -1 : ret; + + return ret < 0 ? ret : 0; +} + +static int snd_usb_offload_available_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new snd_usb_offload_available_ctl = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .name = "USB Offload Playback Capable Card", + .info = snd_usb_offload_available_info, + .get = snd_usb_offload_available_get, +}; + +/** + * snd_usb_offload_init_mixer() - Add USB offload bounded mixer + * @mixer - USB mixer + * + * Creates a sound control for a USB audio device, so that applications can + * query for if there is an available USB audio offload path, and which + * card is managing it. + */ +int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer) +{ + return snd_usb_offload_create_mixer(mixer, &snd_usb_offload_available_ctl); +} +EXPORT_SYMBOL_GPL(snd_usb_offload_init_mixer); diff --git a/sound/usb/mixer_usb_offload.h b/sound/usb/mixer_usb_offload.h new file mode 100644 index 000000000000..fb88e872d8fa --- /dev/null +++ b/sound/usb/mixer_usb_offload.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __USB_OFFLOAD_MIXER_H +#define __USB_OFFLOAD_MIXER_H + +#if IS_ENABLED(CONFIG_SND_USB_OFFLOAD_MIXER) +int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer); +#else +static int snd_usb_offload_init_mixer(struct usb_mixer_interface *mixer) +{ + return 0; +} +#endif +#endif /* __USB_OFFLOAD_MIXER_H */