From patchwork Wed Dec 20 22:45:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 181851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp61690dyi; Wed, 20 Dec 2023 15:04:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaggVny67t6tfuNMZ4Yahc+4qpoHJBZ3mBIn8lbW1iIdl4+ynjiNLpK5e5mAjgCLWdY7d1 X-Received: by 2002:a50:ba86:0:b0:552:d75b:c6d9 with SMTP id x6-20020a50ba86000000b00552d75bc6d9mr3333100ede.7.1703113497309; Wed, 20 Dec 2023 15:04:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703113497; cv=none; d=google.com; s=arc-20160816; b=OGjdjgbkRJp0esQwqfWIh34nBzX8B7u82YCgOeQa6ALDkgoCHFWwKv+ofsAne0J5Bz 2iVHWO2QvWFHMl17uELlzX3ej49JPX5ancyYdK30uIHkEIoOOOpx4ELN1usG7j0NfEHh uqXMKmQXPbtqlRO0JDB73oxT2dxwLj9+3/RpIQMnppqkt/tMgyqeJV3fESyTJ3XosbRJ l0E6NqAU1/6NAOxS7cw+V9hWHLFKdRw8a4VSoRN6CygG4hIgEjQ1Lo7Hb+Qp0dlMt6oD eg+Jf/zfcz3IaOWqI5JELcQJpFN231MsFYDiiKWSbdUllWfkS2zEHo1fOlwTAsIomk7a jwMA== ARC-Message-Signature: i=1; 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=dF6QUt6bj0KwOs7HHOgoxVmbHFD9fJB0ffHCN3hLSEM=; fh=0KzismZj+xI0Z//ZGdqKIH/FO9LtSZM7Yj4P0VtrCz0=; b=uqtSwAa4wY7gEeCHZr6q16ECJieZkpDv7MY6VHIOZj4dUl5ORRGghsrpSgMCd/n480 gzUCPCHzV7mw6odSZQhoBSEjQ0nXA+eZZVSOVMbP2fc0rC+dkr9dBwB0Oba8ETdUVma3 yFBF93B8hwo5GwLkhjlfa+9Dueqe+oq8jhfKx+RdV4IJE746Y1eezQcpoW3h+gxmf/uE /2QOSUuUba9Is4xmxBH2jOC1sbvFKNfit7TZj8qjCZewNGwROwdMwdlspEspl7gP3TaZ Dq0d7yJIriAGMR0d2YR608t+mY+MQk/XH3rbrypiYwRlWGpZ/TkouRoLkF0A/ylN7vN6 mdWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=NUMoNOI+; spf=pass (google.com: domain of linux-kernel+bounces-7582-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7582-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cq7-20020a056402220700b00552e805a5fasi247084edb.251.2023.12.20.15.04.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 15:04:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7582-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=NUMoNOI+; spf=pass (google.com: domain of linux-kernel+bounces-7582-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7582-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 E72B31F22CA1 for ; Wed, 20 Dec 2023 23:04:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 584E26FCFF; Wed, 20 Dec 2023 22:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="NUMoNOI+" X-Original-To: linux-kernel@vger.kernel.org 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 A74A152F8F; Wed, 20 Dec 2023 22:46:22 +0000 (UTC) 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 (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BKLUmHP020658; Wed, 20 Dec 2023 22:46:04 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=dF6QUt6bj0KwOs7HHOgo xVmbHFD9fJB0ffHCN3hLSEM=; b=NUMoNOI+n/aXF4MSbaFZx1S+umul5wEP7IVk o3JmCnzHoFzrC7vGq6e8jhH6lPzITGQNIrwQUVTR+yspBrYsU65bLigKTcmmk7jm kfW6YAxOvaHBTdRX95CbtlgaoTLmW2ivfnqoEsOng9B0aSKnA1oATtGkg8730qOG auQHVyzyiftxwbOCk0ysIGKjHGeQCMRZ8ij8JbRdeqUH2JDH5LPWOoSgaP07lOPN 4Bhz1KPz0WG8WlPIlSc1frUXHMj8g9Y2cA8yulSv8hqDVdk7kiOZ20FdAB9CNngX AjkC27ZIyPvpfYDeGJ1r/Ar79fzV37frve9SdNabxI0WZgjyTg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3v3rppjmet-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 22:46:04 +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 3BKMk2DO014067 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Dec 2023 22:46:03 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; Wed, 20 Dec 2023 14:46:02 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v11 29/41] ASoC: Introduce SND kcontrols to select sound card and PCM device Date: Wed, 20 Dec 2023 14:45:32 -0800 Message-ID: <20231220224544.18031-30-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231220224544.18031-1-quic_wcheng@quicinc.com> References: <20231220224544.18031-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: nalasex01a.na.qualcomm.com (10.47.209.196) 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: HehXm2C-0kt83L_n9bwEFDnX9iL3ccDt X-Proofpoint-GUID: HehXm2C-0kt83L_n9bwEFDnX9iL3ccDt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 impostorscore=0 clxscore=1015 spamscore=0 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312200163 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785843938799726827 X-GMAIL-MSGID: 1785843938799726827 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 | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index f42e7f224549..195300510acc 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 d62a51d9196c..622916a82b77 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,7 +218,11 @@ 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);