From patchwork Sat Feb 3 02:36:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 196181 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp821488dyc; Fri, 2 Feb 2024 18:59:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXrt8B2yRVWUT+wfPEL8sFEISpxEf5cBgvGfi7i7qc5J020N8/aKJSV1NhbJx5MdVTsZe2 X-Received: by 2002:a17:903:2452:b0:1d9:342:e6bd with SMTP id l18-20020a170903245200b001d90342e6bdmr11462721pls.13.1706929165653; Fri, 02 Feb 2024 18:59:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706929165; cv=pass; d=google.com; s=arc-20160816; b=cbhCbnp5gT2jAPXNixAQ0SXChRixuam18l84dTHFw13TQmbcT1xtAFS7zcyDX9uR+T CEdgBXJcxvJsUyvI1tHsODhnOeD7BaCZLMVYLtOJ9717COPWLxbrtPiJwoE/6d77dUmX KVDxWgOFN6Ce4bInk/ncX/QDTuGf+FfhJdpTApi0wTyUugpMg7edalUC555+7ux8nEb5 M1dkIkZmbIOyh/zhmYYlWL+6xpkQbPPqPlSKGtMG1Rodb27jUp8ShHE8bvVuFf75vw+t PNy7GVneQf9kzAKFTvRkhu0OJTZv0DzxSSLkp2DJQp32XcWgXNNbyI8LJwwgOBKh5nxn 8fUw== 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=7VZfx/Bay9jjE9Iv4MJzJiR4uxKr/xQofmWH8gbXo0Y=; fh=pka8lsPy3w/2g2x3gCFos9F6C0Fyc3qdLBM73pb7hjM=; b=As5Y89fvbFYrMDuDxASWsY1JshopzFpPQcuStZA8fFzPJbUTxHYmvsIwnSudfy1ufs 8Elrw38N7rEoHgAiPcogLAs98h4Sh5XqiPUPA+g53bIp/K1+Wa2rY/Fo5oatQCHn0sBI LganPxUINqwpQJubf8D56gRRvg/tiQQl8EBZkMMTAPk+cBQV2jdyIcZr73AuPsq7wi9q fGRRlG3wIvXXXW5ijvBf7r+EZ3tTfO0h0wpOhP+OW1XCrBzBl8wITYIxaYDKnLzZK9kq DEfeR7tuMPDKwmUl+1wCXEoqeT7it6mPsBoBfx+VD+UkqqM2pm3LX1F5KzyA2Pb6I1hu fsGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MS4hlyNP; 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-50878-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50878-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=1; AJvYcCXbwK7gOyaVuGBp8yE9pfMblsPBmW1gC99iS36NHeAn82C69ghumMhMXDkW2mQaHvYvCSPia8XYZ322wSQvQiKmZ0FH8w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c9-20020a170902d48900b001d8dbb867a5si2644808plg.592.2024.02.02.18.59.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 18:59:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50878-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MS4hlyNP; 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-50878-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50878-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D8016281EF7 for ; Sat, 3 Feb 2024 02:59:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5E135D492; Sat, 3 Feb 2024 02:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="MS4hlyNP" 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 1A3EC48CC8; Sat, 3 Feb 2024 02:38:22 +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=tPVDQ5Y/XfwN+UFqWDR9EPhGUM6ACC5p/F4IksOQKVfnZDXkCU0J/Buo97keRuwftjiW0l420Ahvdjt4xQI4hOAkFc+UsPuytvJsGIlAXHZBE337woeZ9AP/bbPjuNG8O9tgJKfA6GQ7dkuKcnql+YtwPvHC8dU75eaSkySxuow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706927904; c=relaxed/simple; bh=5j0LD4cU0Gyh4u94KaYfLWqCDiM58ryYVYdm0d3ckJ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=drEDBHI+L4Qoq4yF6wL2wMsS8qHtH3Dr7HZi6aN9QszffM4fhD1fZ8Sgc4ymj1BrtDZd09TcyF1iaoC4y/X+YO15PGURoBMwavI58Y0XSPVxkvqAMcIMK/PdhYc0LN7l3kGbCiPZxZlBnJt4MiqsOAm2TTgTU5n9wCFM5y/apXs= 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=MS4hlyNP; 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 4132Q51D004181; 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=7VZfx/Bay9jjE9Iv4MJz JiR4uxKr/xQofmWH8gbXo0Y=; b=MS4hlyNPK3M+7a4w+eUQ4Uf0h/FmwZAWKjzc sQB262Wm/T/KwKzXYZeAXr2hVs1w2m+4zSiPZqNs3D8Ns2gnxYgBiyEwPeM4EXfD BUGNPhJ3guW+KrwgGVdMprbXCmo+q4xZmYzkmFZI2Hzt2fte+pHBL5kp5zHTF1A5 S6JKqm6KbzHicrrW5HATTjSry805CI4m3bCSRKkynaHj/zWAY10ZLG2gLWzFsLoC 9F8A7oFwU0EGfOiy4EMHIGYAWMlrY6q//GgeqSg37BmU6x5Rceh74BiQ6nupvwKK OR5nfZeLmINSF3gX+h8b1NkIGEb3FYTk7zEPS+QTvdZAad6uuA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w0pwjjuj9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 03 Feb 2024 02:38:05 +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 4132bUB0004284 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 3 Feb 2024 02:37:30 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:29 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v13 41/53] ASoC: Introduce SND kcontrols to select sound card and PCM device Date: Fri, 2 Feb 2024 18:36:33 -0800 Message-ID: <20240203023645.31105-42-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 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: 9HxCtAv8oQakOhJsPFDxs9FhU7a2yUtv X-Proofpoint-ORIG-GUID: 9HxCtAv8oQakOhJsPFDxs9FhU7a2yUtv 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789844956909770456 X-GMAIL-MSGID: 1789844956909770456 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 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 cad8e1d798e4..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,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);