From patchwork Thu Feb 8 23:13:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp517956dyd; Thu, 8 Feb 2024 15:34:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqOT6XgRuZfuZQDauNidvJuWYxATvsuWy1JsjtFilyq30HjAIksOlD72WiZqO4QO3OwJYw X-Received: by 2002:a17:906:11da:b0:a38:5658:54aa with SMTP id o26-20020a17090611da00b00a38565854aamr924756eja.12.1707435285914; Thu, 08 Feb 2024 15:34:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435285; cv=pass; d=google.com; s=arc-20160816; b=L5z/77g5UPswXr+BCrypVFjj4rA17ClnqqzVn1qCFKJjr3+G/ILnXRNVazW6YHTc29 C/S7L7qdDQUrrR/Hx6BMFzTk6x/veS9PA5w2JaDQHQpux/mhHpLzyzkYMVbNc8kmHAa7 dhWYRPKERsne8lr8vwWGIEY/fimqqvsmL8MLRQivtFI4hPcyoqdUKdNfCA+aRmVGqF+u moP6tUXYqB2r6B6/VJs/aYgGBTDAkZQCoH76miBI7Sl+8iEnDryRynS2PWZ1P8h4a20t qtONjNpLnlFOdQ0udppLAV648Wv7EV8xbmBD5I7Tb3/D6IkYMHhgrVcBFUjn0GlPFxun DWVg== 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=/sTR0p9zlpS7eU37j5GfC+kimrOVjLRydHUUztF1zZ0=; fh=6vGHtAY++xld/oA5O3T/vfhVZpCGOZqds7/bXt+/g14=; b=D280naFkiikh/CIVfAhZgxVfuxekD4XUo/NH9qeFANHB7udLysClxI4FmBuG6+etkn WzoFDofa/qWTsW4MsekZv2Okj2LfTRizyDR+TiAuvKkH32kGctOfx/TuHwiqnhcGYGyM s956i22Ex1Ewml95hhLGiWDmU+4rkCbjPkqEFtFdHM45Dh0W18mpI+727Z9WNXO0sMIW +K94o5k+P2GpqWFzPQZNKRJ9zfnz47dyoLnC12R70tHuZy1pH0ZGB/NoaQP+zGkeOpJt jolvj+yW0Qi6R3nkhPSekCJUFXWrVfbZdQFyE+t+PYS/kkoXD+kk2OKqkCVCYr3nU1G+ l7jA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QlZcP5CD; 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-58847-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58847-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUsX/qolC7CYqbUPySyEWMwCO697ezuczyNayqkqxlggnkDx2azGgopuKLi8Q0ogprOYnejj16l8JQqUtLXDRT6EpugTQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j18-20020a170906279200b00a38273c1415si166066ejc.275.2024.02.08.15.34.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:34:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58847-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QlZcP5CD; 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-58847-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58847-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 565021F2450A for ; Thu, 8 Feb 2024 23:34:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF99960EFD; Thu, 8 Feb 2024 23:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QlZcP5CD" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 18F2F50A91; Thu, 8 Feb 2024 23:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; cv=none; b=mie22rX444gJ20m0wSRHQPgAKfIvU/INzYk/DLIM5O8bUbYIj7yfwND6NJ0SLzcj0qRe1RfBASCCgDJoSpmR+VmwRbs0s8yfFYmF1FuIzJdQkaY9EbgpniD4gDGKztuQaKzyz+sOILiM5S4iLwojPqUCqyBOiJipHVTbV6DUTHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434091; c=relaxed/simple; bh=dxm4+VEN51l4gmeKDtMJd2TXPbMeemernY3Jm3jbXQE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dzqvHO74guoPk+SSfENnY+qiIxy0ah4kJF+dXZbu74zZqiX5ocTnZGq7ZjR88mus6nGs/xvmTQmiBbSxJxd7ZPRMXzWLs9Eef/6vdi4wln496zJSNdTZ7u1KWxMmHkagHO7rFpighgqXOKpjKQsZ53KPU7z1MairKUhCv44suuo= 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=QlZcP5CD; arc=none smtp.client-ip=205.220.168.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 (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418MHZDd026120; Thu, 8 Feb 2024 23:14:28 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=/sTR0p9zlpS7eU37j5Gf C+kimrOVjLRydHUUztF1zZ0=; b=QlZcP5CDZmHFWxFfULldSBsqtmO9eaorSk+B SJBaEm+ulcE++gHF4GDI6SUruoDSkCspAAeptH0jvgzIDAOGtfRqHkgqo55Duwpx DC+laR7Tr9cn8my3bHa6pUN9pFeZM8MYibNbbh+rTwsa75tuz35uq+2RU+i0YvzQ 1ezvRztKejfQQc37RWST/ZqkaCzXx62UA6fIpmkMQCqPaSwMdyP/VWbPZjLpCHBF /p4J1Gh2Juto+8Eg/ewNReoEMOJeVF+TJJa1HRAQv6sxyVK1JUmOF1YlXACV5Tb1 jsriPz3XWUq4qoIyOBtDFuPpIkdznNxgNKP8XhpfUxk8Js8Hpg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4sudj9ym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:27 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 418NERiC013186 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:27 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:26 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 41/53] ASoC: Introduce SND kcontrols to select sound card and PCM device Date: Thu, 8 Feb 2024 15:13:54 -0800 Message-ID: <20240208231406.27397-42-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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-GUID: PUKlfc6x5ILTNzz8LOwrSeJyB5PM3q5c X-Proofpoint-ORIG-GUID: PUKlfc6x5ILTNzz8LOwrSeJyB5PM3q5c 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 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 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: 1790375661987864681 X-GMAIL-MSGID: 1790375661987864681 Add SND kcontrol to SOC USB, which will allow for userpsace 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 'SNDUSB OFFLD device select' 1 0 The above command will configure the offload path to utilize card#1 and PCM stream#0. Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 7 ++++- sound/soc/soc-usb.c | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index d9fc83180c56..20d7b32bba07 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -26,14 +26,19 @@ struct snd_soc_usb_device { * @dev - USB backend device reference * @component - reference to ASoC component * @connection_status_cb - callback to notify connection events + * @put_offload_dev - callback to select USB sound card/PCM device + * @get_offload_dev - callback to fetch selected USB sound card/PCM device * @priv_data - driver data **/ struct snd_soc_usb { struct list_head list; - struct device *dev; struct snd_soc_component *component; int (*connection_status_cb)(struct snd_soc_usb *usb, struct snd_soc_usb_device *sdev, bool connected); + int (*put_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); + int (*get_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); void *priv_data; }; diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index e3556c397b39..c568c67e3e4a 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -15,6 +15,9 @@ static struct device_node *snd_soc_find_phandle(struct device *dev) { struct device_node *node; + if (!dev) + return ERR_PTR(-ENODEV); + node = of_parse_phandle(dev->of_node, "usb-soc-be", 0); if (!node) return ERR_PTR(-ENODEV); @@ -38,6 +41,64 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device_node *node) return NULL; } +/* SOC USB sound kcontrols */ +static int soc_usb_put_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_find_priv_data(component->dev); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->put_offload_dev) + ret = ctx->put_offload_dev(kcontrol, ucontrol); + mutex_unlock(&ctx_mutex); + + return ret; +} + +static int soc_usb_get_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_find_priv_data(component->dev); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->get_offload_dev) + ret = ctx->get_offload_dev(kcontrol, ucontrol); + mutex_unlock(&ctx_mutex); + + return ret; + +} + +static int soc_usb_offload_dev_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 2; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new soc_usb_dev_ctrl = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .name = "SNDUSB OFFLD device select", + .info = soc_usb_offload_dev_info, + .get = soc_usb_get_offload_dev, + .put = soc_usb_put_offload_dev, +}; + +static int snd_soc_usb_control_init(struct snd_soc_component *component) +{ + return snd_ctl_add(component->card->snd_card, + snd_ctl_new1(&soc_usb_dev_ctrl, component)); +} + /** * snd_soc_usb_get_components_tag() - Retrieve SOC USB component tag * @playback: direction of audio stream @@ -157,6 +218,12 @@ EXPORT_SYMBOL_GPL(snd_soc_usb_free_port); */ int snd_soc_usb_add_port(struct snd_soc_usb *usb) { + int ret; + + ret = snd_soc_usb_control_init(usb->component); + if (ret < 0) + return ret; + mutex_lock(&ctx_mutex); list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex);