Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1210508rdb; Fri, 2 Feb 2024 18:58:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLdYzwByaMoX/13/S3KT+wjKtjhiiXnE9D2DyHVMsNVL50gpqt7vwJhT55Sy9PMYys1q8M X-Received: by 2002:ac8:5401:0:b0:42a:b2be:f417 with SMTP id b1-20020ac85401000000b0042ab2bef417mr90607qtq.49.1706929103160; Fri, 02 Feb 2024 18:58:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706929103; cv=pass; d=google.com; s=arc-20160816; b=QkgjMxR1PY8W41ZeLE3/lUoDMrsP+MwHyAlt0tOcNSb0q1whuzvf8DBseErjwGcy30 opVb/EBeh33nzI2Pq7kVtErq/WhircMW5tTfLwuUVgKCI2Y81mskrHvTD9GumT120DQr +6wW5HZbA32kwzEsm5oIE03RzguMb/ilX+lm/JBnS8UWMIMTz/CSPcgCUVqGpjtJ+xhq QTBBFIz87i6LfPScdghpKIZjlJ8wpJvRE1/fP6wu08yIqC67COQopOawJsm7QZ4+A9J7 HuIRlWEZx8uZ4HaIdgt0Op21BFi7mlA69cgTZBKnLeuOeeuBK6HtLPpaaiUao77NzK0c srMg== 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=R7Ld4BnZfChRIULoUhY4ktMr86baGRYw4svn11O/8cU=; fh=IMnd4nPeZnF17pctzc3NHAFddfKIjDntXCxtsLpzusI=; b=JvMJlpNRD1TlBJzgtR1mUcJL0Sn8JjFqmolbOXUp4eAdZBLqmHxxG75Vztgujvu/6e UyBkxt/HKxtgW2X4s+14lSKazCyKA/oiTDuAh/ocGMky9sETCpjXT/mlbuX/QRIa+SBn 0Z/fFcHMu75D6nCb9q1LxiTvIvHYwgwV9trwvpBCGpJUJOWHSqnL1isJVD0HiqzSw3++ 0FvRrmLO+WohJKyoE9LLxJuy3KX534RKROEvccSNxKlcBxK85NOl+TLYzAtTRHZsbDco AeH6NjbJQWktCipYs96+RdT3o0Owk1rli5wbXFpPy0s9ZwhYcYMYvZ0RXk7Qx8Gtyciw X2Wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="aYuKCm/m"; 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-50877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50877-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=1; AJvYcCXvt3caP0pM/DmXxY3MHQe+xuu8WHfTb8ZYRNPROyiQOIDN4Lbxz66PqEG2N41HG5bq9bDCpQ2NPzcp1xFNsMcHt+QHGamNbGmrA8GqyQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g15-20020ac87f4f000000b0042a7e2a02adsi3653637qtk.126.2024.02.02.18.58.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 18:58:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="aYuKCm/m"; 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-50877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50877-linux.lists.archive=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 D954F1C22419 for ; Sat, 3 Feb 2024 02:58:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACA5F5C60D; Sat, 3 Feb 2024 02:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="aYuKCm/m" 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 E324B40BE2; Sat, 3 Feb 2024 02:38:21 +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=1706927904; cv=none; b=e7/adGAImp9amxTY/nWtD1YLDLOT2lNcR8NYq76Fy2ZGcCxi8tbo0nHfh2AAlUzWS2ghswSAIcDL6vBHB/bWT5Jr7B1YW+4fi2uywWYagHoUTibZdcLmxhoxjxhyj2hku1srwf+kTTwV8/8vqB8Pt03gUpMcKzvRsKl98ycFsNA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706927904; c=relaxed/simple; bh=4QdlqEqxtPC4mmXJu+T98lLWUGZgarBl4SA8zeBnURo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nb7NPIisiiWyzeBBpmBoxHpPBTetA6NtancfAXv2LGOyAjScz3cTpGu4zWtmVgzrTJAIATeydgExG9+txnmj45Duc4V+cvwq3pDgr9UbShgtdAzOnHfgmxFHthBpfAk5fgeLrRZAvOKdqvFbgCU5Y7vOdiNuE70OJxzlBQf1OpI= 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=aYuKCm/m; 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 (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 4132X0Sr014263; Sat, 3 Feb 2024 02:38:06 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=R7Ld4BnZfChRIULoUhY4 ktMr86baGRYw4svn11O/8cU=; b=aYuKCm/my67wAi8YOObknCfO+3TUIIfXt6H8 DsbugA27O/FmljxrDWljwj424C8VQHk5GZQ+O0JotkGMNXfhpk5woI8IHMKjpbSh 7xLAm4KIsIHCuIU31alDLfEwld5DSXZCPaB9BdExWVv/btx76rCwoHbhRuRf+mmW qN3EHLynl+S5s5CMjT3yGu5CW+yI1U6ytvEAncBhZrzvFAPKkxPpnoVNUkVawD1O 2LJ1eV6c1IMeJ6jgm/r4p6eM++MOqCY/F1tEVGjC+Oc/4xOBT0YiVHN3DItSYBYB hs32J2pWtvh0L19ZhhOhTCvuwxkoTMBobgMiySWlJgmxeevIkw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w0pwjjuja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 03 Feb 2024 02:38:06 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 4132bWxo012320 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 3 Feb 2024 02:37:32 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; Fri, 2 Feb 2024 18:37:31 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v13 48/53] ALSA: usb-audio: mixer: Add USB offloading mixer control Date: Fri, 2 Feb 2024 18:36:40 -0800 Message-ID: <20240203023645.31105-49-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240203023645.31105-1-quic_wcheng@quicinc.com> References: <20240203023645.31105-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 Content-Type: text/plain 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-GUID: UZHJBavgvVi3BqblIZjh7NqB_QYPvzXl X-Proofpoint-ORIG-GUID: UZHJBavgvVi3BqblIZjh7NqB_QYPvzXl 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-02_16,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 adultscore=0 priorityscore=1501 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402030015 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 --- sound/usb/Kconfig | 4 ++ sound/usb/Makefile | 1 + sound/usb/mixer.c | 5 +++ sound/usb/mixer_usb_offload.c | 82 +++++++++++++++++++++++++++++++++++ sound/usb/mixer_usb_offload.h | 17 ++++++++ 5 files changed, 109 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..4e31c1848c53 --- /dev/null +++ b/sound/usb/mixer_usb_offload.c @@ -0,0 +1,82 @@ +// 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 "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_kcontrol *kctl; + struct usb_mixer_elem_info *elem; + + elem = kzalloc(sizeof(struct usb_mixer_elem_info), GFP_KERNEL); + if (!elem) + return -ENOMEM; + + elem->head.mixer = mixer; + elem->val_type = USB_MIXER_S32; + elem->control = 0; + elem->head.id = 0; + elem->channels = 1; + + kctl = snd_ctl_new1(new_kctl, elem); + if (!kctl) { + kfree(elem); + return -ENOMEM; + } + kctl->private_free = snd_usb_mixer_elem_free; + + return snd_usb_mixer_add_control(&elem->head, kctl); +} + +static int +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); + struct usb_mixer_interface *mixer = list->mixer; + struct snd_usb_audio *chip = mixer->chip; + struct usb_device *udev = chip->dev; + int ret; + + ret = snd_soc_usb_device_offload_available(udev->bus->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, + .name = "SNDUSB OFFLD playback available", + .info = snd_usb_offload_available_info, + .get = snd_usb_offload_available_get, +}; + +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 */