From patchwork Wed Feb 28 01:36:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 207606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3080115dyb; Tue, 27 Feb 2024 17:49:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW876KnkGQlM/tdx22AAzDW7WkRadmdQyB9oUe6+X6ySrfxSjvJ32CRsBFDoAr8EgazSsHe5vil3l0ovjA6iSf8KE600A== X-Google-Smtp-Source: AGHT+IEkEWX0O8t1JSJiN8HFgyc8gw27X0eY5H+zYyIyMzR1ItS0T3hcXHVBSLo3LCSeT5/uSvmZ X-Received: by 2002:a05:6358:ed10:b0:17b:bf5b:2ad2 with SMTP id hy16-20020a056358ed1000b0017bbf5b2ad2mr3688099rwb.22.1709084996679; Tue, 27 Feb 2024 17:49:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709084996; cv=pass; d=google.com; s=arc-20160816; b=T00hou8lV9/gs7jk3sL9qyKaag7KRz7GJamex2AucvWtPBziCP4s9hXP5uPDerhIfK 5caHXWfrIUmNvBOOMPi5Ih/LIpoGNIWTNK8kH/uvwlprlytngdpYhNa/0so4yX7U+nZh 1LRK890zQUH7FkOR6jYRqS4RKtK24GrCjcDqhcFJNEBw4Aqe2LYkmeucNaA9QUgm8Een QbUrNmptv4gaEKLU/6+RV7PdVBZiDIQ25i6Ncy333GWJZgy8/6nCOqLieedlfJ8knoB0 oWeMOon2gWQ14aD4WYp0TTMNH44wpmgz3s0OXHPu50Xp+5O9clpdvwidGTrn8cO4+JFb qIiw== 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=+gRV719uqSc7oMUSU9Bc8q0Q3IEefQWBi7497D++R6I=; fh=VKrp0Y7I/+wT36BfKZ6oI/4N9BIwFCn9zerObkOrgGw=; b=VFFvZOOLJqD2p6zXlfrZOw7Cgl3Ho6sYEggfgZHnkoGF3K1lXw8TpIeemIaOhls0IK yX53NgpPF2zYodM0P9gQy012jmdHUTluC/G5pfFXQsNWmxDZsSFgv0yKAs/1mCPn2P6G P51sQdWdybobUf8RXbzBVSp0/9+ypnDsJMnh7BCG87jYwhnVHDZJDdcZRwAwU+RuJQ7c lqKIeIa6VA81UinCGVkNgxY8/MZuaWubrr5v7pgFJFYujjK7qZqbX2txQIY8M3XpBWoZ 1RGkTh1pAai186zMZuQd+nayp1vMaqWNLst1jLWxXoKEQfyCs8FATndX9naaYU3YGKGk QdOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=TxmfHwg9; 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-84366-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84366-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v24-20020a05620a0a9800b00787ddbaf555si3892801qkg.118.2024.02.27.17.49.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:49:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84366-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=TxmfHwg9; 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-84366-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84366-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 677321C23A84 for ; Wed, 28 Feb 2024 01:49:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA3FC58ABC; Wed, 28 Feb 2024 01:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="TxmfHwg9" 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 5DB7C28DB3; Wed, 28 Feb 2024 01:36:58 +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=1709084221; cv=none; b=GhY17RjEE8cZFs275SOqXD7yy31wNb2Ow92Zj/GyM8cLPm/UQ48/ZmKNsVq6vJbVGtl7T34IV59nTybbeio0p/MzNgHlLMePKb+4c9CgXUiDoMoWE7ggxgq9lk7GUQnUEtJorYvWC7Wv/f56W7RQlmJ2af26l13fvbA0bOTJ61g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709084221; c=relaxed/simple; bh=AN/XgXmoDQDKQCkIKxg7LAaiRm5YSKCvNyan7MC6Bmo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EUpVSNKuq9KfqqxbPFCxP1Fqt2JjCTrmp6klMeXxYd9e9EJWO9utg3oLutXSrH/bWmO6cnX24xtkI9gpuYD1aS9xGl3h2ymaxgthXivaqbcxKEnDh6GQ/rGBj/H/DkkPmz1+NPorqpSJFM+0mtHyRohmKdg+fvw++vFOzGWoQeM= 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=TxmfHwg9; 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 (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41S0tsT2030269; Wed, 28 Feb 2024 01:36:40 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=+gRV719uqSc7oMUSU9Bc 8q0Q3IEefQWBi7497D++R6I=; b=TxmfHwg9D3l6DrOdrEFAok33US+wagr2PSHj /BVYwHbZ5bMGpCta58FmMk6qTPbbCKSw5MRw+nH6G81wxkoPpiL5Z1TOX2FjaREP cxqX6H+Jni484ZWv0nL86VNtOP69b+8G8G6KQ1yxx1yoXOKXNnxg+RXjhIFNRYJ2 UzqU0r/XKhBlpvoRfeV8QOTVVwSKzJScqrlzn3Aw4sezKJteEisxhOw4ABenEh0Y QFiAgjg7MJSwF8uyyClKaaBjxxqjx3LVqDKNYLdjUz4w9DPtdSX0UgULdK8p0qO4 jQUrEd+iiXa7FO8+IuK05gjBHHBjuoKLLNzXHRa6J0zmbGOHfw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wha07aj9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 01:36:40 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41S1ad6b016766 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 01:36:39 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; Tue, 27 Feb 2024 17:36:39 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v18 36/41] ALSA: usb-audio: Add USB offloading capable kcontrol Date: Tue, 27 Feb 2024 17:36:14 -0800 Message-ID: <20240228013619.29758-37-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240228013619.29758-1-quic_wcheng@quicinc.com> References: <20240228013619.29758-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: 0Gy4xBHAdZy-qYi8P2R2itZNsITwX-Go X-Proofpoint-GUID: 0Gy4xBHAdZy-qYi8P2R2itZNsITwX-Go 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-27_11,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 suspectscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402280011 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792105509627166104 X-GMAIL-MSGID: 1792105509627166104 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. It is expected for the USB offloading driver to add the kcontrol to the sound card associated with the USB audio device. An example output would look like: tinymix -D 1 get 'USB Offload Playback Capable Card' 0 (range -1->32) Ths example signifies that card#0 has an USB offload capable path available. Signed-off-by: Wesley Cheng --- sound/usb/Kconfig | 10 +++++ sound/usb/qcom/Makefile | 6 ++- sound/usb/qcom/mixer_usb_offload.c | 65 ++++++++++++++++++++++++++++++ sound/usb/qcom/mixer_usb_offload.h | 17 ++++++++ sound/usb/qcom/qc_audio_offload.c | 3 ++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 sound/usb/qcom/mixer_usb_offload.c create mode 100644 sound/usb/qcom/mixer_usb_offload.h diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 5cc3eaf53e6b..1228be3c1f83 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,6 +176,16 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000. +config SND_USB_QC_OFFLOAD_MIXER + bool "Qualcomm USB Audio Offload mixer control" + help + Say Y to enable the Qualcomm USB audio offloading mixer controls. + This exposes an USB offload capable kcontrol to signal to + applications about which platform sound card can support USB + audio offload. This can potentially be used to fetch further + information about the offloading status from the platform sound + card. + config SND_USB_AUDIO_QMI tristate "Qualcomm Audio Offload driver" depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND && SND_SOC_USB diff --git a/sound/usb/qcom/Makefile b/sound/usb/qcom/Makefile index a81c9b28d484..eada5cd7b71f 100644 --- a/sound/usb/qcom/Makefile +++ b/sound/usb/qcom/Makefile @@ -1,2 +1,6 @@ snd-usb-audio-qmi-objs := usb_audio_qmi_v01.o qc_audio_offload.o -obj-$(CONFIG_SND_USB_AUDIO_QMI) += snd-usb-audio-qmi.o \ No newline at end of file +obj-$(CONFIG_SND_USB_AUDIO_QMI) += snd-usb-audio-qmi.o + +ifneq ($(CONFIG_SND_USB_QC_OFFLOAD_MIXER),) +snd-usb-audio-qmi-objs += mixer_usb_offload.o +endif \ No newline at end of file diff --git a/sound/usb/qcom/mixer_usb_offload.c b/sound/usb/qcom/mixer_usb_offload.c new file mode 100644 index 000000000000..cd6e5600e795 --- /dev/null +++ b/sound/usb/qcom/mixer_usb_offload.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include + +#include +#include +#include + +#include "../card.h" +#include "../mixer.h" +#include "../usbaudio.h" + +#include "mixer_usb_offload.h" + +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_create_ctl() - Add USB offload bounded mixer + * @chip - USB SND chip device + * + * 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_create_ctl(struct snd_usb_audio *chip) +{ + struct usb_device *udev = chip->dev; + + return snd_ctl_add(chip->card, + snd_ctl_new1(&snd_usb_offload_available_ctl, + udev->bus->sysdev)); +} diff --git a/sound/usb/qcom/mixer_usb_offload.h b/sound/usb/qcom/mixer_usb_offload.h new file mode 100644 index 000000000000..0efda52e92b6 --- /dev/null +++ b/sound/usb/qcom/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_QC_OFFLOAD_MIXER) +int snd_usb_offload_create_ctl(struct snd_usb_audio *chip); +#else +static inline int snd_usb_offload_create_ctl(struct snd_usb_audio *chip) +{ + return -ENODEV; +} +#endif +#endif /* __USB_OFFLOAD_MIXER_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 4deec0b6fc08..6a25a390f8ae 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -37,6 +37,7 @@ #include "../pcm.h" #include "../power.h" +#include "mixer_usb_offload.h" #include "usb_audio_qmi_v01.h" /* Stream disable request timeout during USB device disconnect */ @@ -1660,6 +1661,8 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) uaudio_qdev->last_card_num = chip->card->number; snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + snd_usb_offload_create_ctl(chip); + mutex_unlock(&chip->mutex); mutex_unlock(&qdev_mutex);