From patchwork Fri Feb 16 03:59:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 201917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp290137dyb; Thu, 15 Feb 2024 20:22:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXlFa0o1fEG9qfKGC9uItv6jElAi3WvAEwiOQJXsd1sVCxi5NyOGzcVCkGAuM9FgtI92XXLs0hqe9ULugplaffPHIP09g== X-Google-Smtp-Source: AGHT+IFYYpsc1XnrRZFHPCf106YlXOHE9bgpPhMOQw/hBOA97HjP3+D50imtCNmYw7sjXAd8s8+I X-Received: by 2002:a17:90a:f18c:b0:298:cbfb:d257 with SMTP id bv12-20020a17090af18c00b00298cbfbd257mr3555290pjb.1.1708057338481; Thu, 15 Feb 2024 20:22:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708057338; cv=pass; d=google.com; s=arc-20160816; b=Aa9ZEHuCOl/Cl2xERLWZw8XW8zLSUrUwoI8u8/m6dX7rvV09Jlg6D44OmvwUDzUNmL +W0y2t3vmwPazsDtHzO6xgYeWqHnHpit2spIX78m1dqXrSp1XEUqWnKZhTsayt5txnBv 0890TER7/YZn88it7xNOvsT+ZxOP0TIrETtnnaRvXCXbEh3BMCRA+919FzROIs5CjyAU XbJpRc32bftii6CmJHDkD8FOakRjAJTtROIe2NBtyeCdv95D4MKta9iLdbqwl1sZqFOR C7MOp8/THe3VS/FOWAQfxqB3ewwaK1yj9kmtfKpF0+RlwZGvitsYq/sLU61Qw8ZpDFgs k+NA== 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=YgMbSpdThd+52u2tW8ty04Q0ADWlPVuDMRgoZX+EaX4=; fh=VKrp0Y7I/+wT36BfKZ6oI/4N9BIwFCn9zerObkOrgGw=; b=TW9dGU2WWqJ1ok2bEV+Cq3lPLGvBEw82DdzxBQ7tS8zkD08QQXCuW6gvFQUavP2Vvp loz7jYdkOOXnDj8VjPnFnNQRu7SKRsa7+ToD1cu+fA6LKcHBcpZPvCHCfXmgVJ8Varht qhZr/pruqLuW/TvtzoaQQMglput0YYRZ2Y1GX575rhUXpMT3Rm1koREhyoJii79CyL9C DcxMRF1ITcV845+xec/SJbXJN7o5TGe5mE+zSzgTR4ZdTJlCxQMynbKVCzB4cAMPQiX9 d01a095YMovd+3osuxaAk1EAaM+SEMMLvNPt4/cAieE4ANTFZWsBDDQi8ye5Kb1bZgzC siuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=d2aDqMml; 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-68034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68034-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h21-20020a17090aea9500b00298c3984d41si4090817pjz.127.2024.02.15.20.22.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:22:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=d2aDqMml; 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-68034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68034-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 56C3BB21F21 for ; Fri, 16 Feb 2024 04:16:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9A3D5A106; Fri, 16 Feb 2024 04:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="d2aDqMml" 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 E2BF21D6BD; Fri, 16 Feb 2024 04:00:04 +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=1708056008; cv=none; b=rYiNAAx865T0KSfXeO4tzhl6MV98yHDjs9qTE4hIcgxcWZHaJjpeLu2qUBSIgra5dOG5hLpJVspJstDZbtUjRJ5PBEAioIlZ5/w+d4eZ2xmfwqFmI3n4vJXGkRL+Z+VkInxHQFTakcb+EcB0KSoHU25gRwGrk6+JRsN3n2qPrVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056008; c=relaxed/simple; bh=IWEzTYooovusuufLCyetWQDO8aOMyj3MLGWCNH90IxY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E64Edrkek0XoN3nKAVkP0Ui60JIWQQG8/PpACT47zh0qafNmLf85P8ApJ+6xYgfn+M+9Gpi/9s0XicOlroJJtM/YM36Ze5W1m4wAMfFwzujB7XJq/XKuCwiutc88LnKNin7QqTEfIWf6Nu/4+mIj9QZr5bQZW+ULQumZbDtsO4I= 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=d2aDqMml; 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 (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41G3iu5n015135; Fri, 16 Feb 2024 03:59:45 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=YgMbSpdThd+52u2tW8ty 04Q0ADWlPVuDMRgoZX+EaX4=; b=d2aDqMmlqJfA5l2vlnB6CSS/frp1J+y23GNS gF0Psrmf62Yfz8UF+Wo4TCO/6UCoXGTcdk2GKicm5VF8DQUAvw+wMpcmqVqk1YEc cPoPK6wMnPSgQZYWyOkS53JCeHMBO+tUdV7GaZ+pf6qmGukEGJYiMt0L7ToeWkRA tj01EhrCO+n0wxHnUfVEwjrGt6DX4MGFNK1XUHQWui6096yIxhHZwXoVsi5RwwHd ZrgIlNVMEFOFP1hGCs7Vn2h8TcpmZMII4EItubD+netOv4Kgob+MbnkKKyx7+GEH 2zDXLICZ6CQ5dag5gzvEkxa1aG+D4RTLNjNohTYTFRxumTEWsw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w9xv9g3w3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 03:59:44 +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 41G3xiid014731 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 03:59:44 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, 15 Feb 2024 19:59:43 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v16 39/50] ASoC: Introduce SND kcontrols to select sound card and PCM device Date: Thu, 15 Feb 2024 19:59:12 -0800 Message-ID: <20240216035923.23392-40-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240216035923.23392-1-quic_wcheng@quicinc.com> References: <20240216035923.23392-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: TzQt_SKuhlhULYokY8llwr4vr83IyyId X-Proofpoint-GUID: TzQt_SKuhlhULYokY8llwr4vr83IyyId 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-16_03,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 bulkscore=0 adultscore=0 mlxscore=0 priorityscore=1501 suspectscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402160031 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791027931736179964 X-GMAIL-MSGID: 1791027931736179964 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 'USB Offload Playback Route Select' 1 0 The above command will configure the offload path to utilize card#1 and PCM stream#0. Change-Id: I02edabc01d198f7e0905080f0c751cd5146cb278 Signed-off-by: Wesley Cheng --- include/sound/soc-usb.h | 16 ++++ sound/soc/soc-usb.c | 157 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+) diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 8f2d3064b520..18cdc59df9aa 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -6,6 +6,12 @@ #ifndef __LINUX_SND_SOC_USB_H #define __LINUX_SND_SOC_USB_H +enum snd_soc_usb_kctl { + SND_SOC_USB_KCTL_CARD_ROUTE, + SND_SOC_USB_KCTL_PCM_ROUTE, + SND_SOC_USB_KCTL_MAX, +}; + /** * struct snd_soc_usb_device * @card_idx - sound card index associated with USB device @@ -24,16 +30,26 @@ struct snd_soc_usb_device { * struct snd_soc_usb * @list - list head for SND SOC struct list * @component - reference to ASoC component + * @kctl - list of kcontrols created * @num_supported_streams - number of supported concurrent sessions * @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 snd_soc_component *component; + struct snd_kcontrol *kctl[SND_SOC_USB_KCTL_MAX]; unsigned int num_supported_streams; 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, + enum snd_soc_usb_kctl type); + int (*get_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol, + enum snd_soc_usb_kctl type); void *priv_data; }; diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index bc77204fd2db..ade09b416d45 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,152 @@ 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_pcm_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_find_usb_ctx(component->dev->of_node); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->put_offload_dev) + ret = ctx->put_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_PCM_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; +} + +static int soc_usb_get_offload_pcm_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_find_usb_ctx(component->dev->of_node); + int ret = 0; + + ucontrol->value.integer.value[0] = -1; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->get_offload_dev) + ret = ctx->get_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_PCM_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; + +} + +static int soc_usb_put_offload_card_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_find_usb_ctx(component->dev->of_node); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->put_offload_dev) + ret = ctx->put_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_CARD_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; +} + +static int soc_usb_get_offload_card_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_find_usb_ctx(component->dev->of_node); + int ret = 0; + + ucontrol->value.integer.value[0] = -1; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->get_offload_dev) + ret = ctx->get_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_CARD_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; + +} + +static int soc_usb_offload_pcm_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; + /* Arbitrary max value, as there is no 'limit' on number of PCM devices */ + uinfo->value.integer.max = 0xff; + + return 0; +} + +static int soc_usb_offload_card_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 soc_usb_kcontrols[] = { + [SND_SOC_USB_KCTL_CARD_ROUTE] = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .name = "USB Offload Playback Route Card Select", + .info = soc_usb_offload_card_info, + .get = soc_usb_get_offload_card_dev, + .put = soc_usb_put_offload_card_dev, + }, + [SND_SOC_USB_KCTL_PCM_ROUTE] = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .name = "USB Offload Playback Route PCM Select", + .info = soc_usb_offload_pcm_info, + .get = soc_usb_get_offload_pcm_dev, + .put = soc_usb_put_offload_pcm_dev, + }, +}; + +static int snd_soc_usb_control_remove(struct snd_soc_usb *usb) +{ + struct snd_soc_component *component = usb->component; + int i; + + for (i = 0; i < SND_SOC_USB_KCTL_MAX; i++) { + if (usb->kctl[i]) { + snd_ctl_remove(component->card->snd_card, + usb->kctl[i]); + snd_ctl_free_one(usb->kctl[i]); + usb->kctl[i] = NULL; + } + } + + return 0; +} + +static int snd_soc_usb_control_init(struct snd_soc_usb *usb) +{ + struct snd_soc_component *component = usb->component; + int ret; + int i; + + for (i = 0; i < SND_SOC_USB_KCTL_MAX; i++) { + usb->kctl[i] = snd_ctl_new1(&soc_usb_kcontrols[i], component); + ret = snd_ctl_add(component->card->snd_card, usb->kctl[i]); + if (ret < 0) + return ret; + } + + return ret; +} + /** * snd_soc_usb_get_components_tag() - Retrieve SOC USB component tag * @playback: direction of audio stream @@ -158,6 +307,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); + if (ret < 0) + return ret; + mutex_lock(&ctx_mutex); list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex); @@ -187,6 +342,8 @@ int snd_soc_usb_remove_port(struct snd_soc_usb *usb) } mutex_unlock(&ctx_mutex); + snd_soc_usb_control_remove(usb); + return 0; } EXPORT_SYMBOL_GPL(snd_soc_usb_remove_port);