From nobody Wed Nov 27 11:43:58 2024 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 7DD391A0700; Fri, 11 Oct 2024 00:07:38 +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=1728605261; cv=none; b=otDOTzSyuAA/GDe03vEpHQjqc2sX/jY83ozstLnsRKaw2DpoT0LGtxEhNt+4hjBUlkQ+7XHuVzdmnheqTnUhR0h9B27xSqhHyGzE+rFlDnHR9gH7wMbNHP6loCs0YHD8Ms5OIk9ZCiEZ4EygAoozc0oUvTrDX/asGXWl9qv8QAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728605261; c=relaxed/simple; bh=4fgBKxtPRpDiHtCjcjtA+uBufM2OdVE/YSR6AUVarCM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KMjEJj+VtLMyeyG92hi6rh5mK3TktO61RatSNfNv3e+15hzpr/hKrsWO8ZpE3eB1BQJMa21WiHl5L7firbhO6UybotB541P/eGxsC7ZZGyKeJ7DXCCX8AHCvw66ISC9la7cTlmUrmQ+kPHTqSeYSB8fIZxEIZrFCanz6H8/MPRs= 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=HqZop1Ve; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="HqZop1Ve" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49ABqtAI027130; Fri, 11 Oct 2024 00:07:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= t3S/a23F2/gUNPP5kv7berwz+e6A9EkuP6r3IZeyhew=; b=HqZop1VeE5S06T3w H649SAvEN2APftz3JkBqvxLMkYOP+RW0Yw/q/dtdJN55LbCZWjUM9vwxUd1uH9aC yV/Ft4FjynILDuflQsMGeh0Wu8qBlzzuPvoOCkad/WfSgwHhtNTebJ0SGHloL5Ms OJ9Bj7uU3wHEOPyEPBHecty/Azx1QpLLrOSxtVnMXUcT5GEDOqLSZebjBDCodN9V uwbh3wXtuVB0ukrQ4YkFMqhUXUGM/npUoMvVBP89nm80MtyRJrHaSW0FKwiKSQ+A VaL+PhLNsH6DjfEYj+7CED/vlkdgdIvYBFJHR+TezLG14vzWRwSvJ2nU5kyzBFCo GugiTQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 425c8qydrm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 11 Oct 2024 00:07:17 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 49B07GiU009344 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 11 Oct 2024 00:07:16 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.1544.9; Thu, 10 Oct 2024 17:07:16 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v28 24/33] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Date: Thu, 10 Oct 2024 17:06:33 -0700 Message-ID: <20241011000650.2585600-49-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011000650.2585600-1-quic_wcheng@quicinc.com> References: <20241011000650.2585600-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-Transfer-Encoding: quoted-printable 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: MR6v6n-LgwsIExLi1r-bjioJunEZmGjc X-Proofpoint-ORIG-GUID: MR6v6n-LgwsIExLi1r-bjioJunEZmGjc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 priorityscore=1501 mlxscore=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410100159 Content-Type: text/plain; charset="utf-8" Create a USB BE component that will register a new USB port to the ASoC USB framework. This will handle determination on if the requested audio profile is supported by the USB device currently selected. Check for if the PCM format is supported during the hw_params callback. If the profile is not supported then the userspace ALSA entity will receive an error, and can take further action. Signed-off-by: Wesley Cheng --- include/sound/q6usboffload.h | 20 +++ sound/soc/qcom/Kconfig | 10 ++ sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6usb.c | 246 ++++++++++++++++++++++++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 include/sound/q6usboffload.h create mode 100644 sound/soc/qcom/qdsp6/q6usb.c diff --git a/include/sound/q6usboffload.h b/include/sound/q6usboffload.h new file mode 100644 index 000000000000..35fd7388fd52 --- /dev/null +++ b/include/sound/q6usboffload.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * sound/q6usboffload.h -- QDSP6 USB offload + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +/** + * struct q6usb_offload + * @dev - dev handle to usb be + * @domain - allocated iommu domain + * @sid - streamID for iommu + * @intr_num - usb interrupter number + **/ +struct q6usb_offload { + struct device *dev; + struct iommu_domain *domain; + long long sid; + u16 intr_num; +}; diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 762491d6f2f2..a1beafe2b1dd 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -118,6 +118,16 @@ config SND_SOC_QDSP6_PRM tristate select SND_SOC_QDSP6_PRM_LPASS_CLOCKS =20 +config SND_SOC_QDSP6_USB + tristate "SoC ALSA USB offloading backing for QDSP6" + depends on SND_SOC_USB + help + Adds support for USB offloading for QDSP6 ASoC + based platform sound cards. This will enable the + Q6USB DPCM backend DAI link, which will interact + with the SoC USB framework to initialize a session + with active USB SND devices. + config SND_SOC_QDSP6 tristate "SoC ALSA audio driver for QDSP6" depends on QCOM_APR diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index 26b7c55c9c11..67267304e7e9 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_APM_DAI) +=3D q6apm-dai.o obj-$(CONFIG_SND_SOC_QDSP6_APM_LPASS_DAI) +=3D q6apm-lpass-dais.o obj-$(CONFIG_SND_SOC_QDSP6_PRM) +=3D q6prm.o obj-$(CONFIG_SND_SOC_QDSP6_PRM_LPASS_CLOCKS) +=3D q6prm-clocks.o +obj-$(CONFIG_SND_SOC_QDSP6_USB) +=3D q6usb.o diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c new file mode 100644 index 000000000000..2b3e24520070 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -0,0 +1,246 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights res= erved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "q6afe.h" +#include "q6dsp-lpass-ports.h" + +#define Q6_USB_SID_MASK 0xF + +struct q6usb_port_data { + struct q6afe_usb_cfg usb_cfg; + struct snd_soc_usb *usb; + struct q6usb_offload priv; + + /* Protects against operations between SOC USB and ASoC */ + struct mutex mutex; + struct list_head devices; +}; + +static const struct snd_soc_dapm_widget q6usb_dai_widgets[] =3D { + SND_SOC_DAPM_HP("USB_RX_BE", NULL), +}; + +static const struct snd_soc_dapm_route q6usb_dapm_routes[] =3D { + {"USB Playback", NULL, "USB_RX_BE"}, +}; + +static int q6usb_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(dai->dev); + struct snd_soc_pcm_runtime *rtd =3D substream->private_data; + struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(rtd, 0); + int direction =3D substream->stream; + struct q6afe_port *q6usb_afe; + struct snd_soc_usb_device *sdev; + int ret =3D -EINVAL; + + mutex_lock(&data->mutex); + + /* No active chip index */ + if (list_empty(&data->devices)) + goto out; + + sdev =3D list_last_entry(&data->devices, struct snd_soc_usb_device, list); + + ret =3D snd_soc_usb_find_supported_format(sdev->chip_idx, params, directi= on); + if (ret < 0) + goto out; + + q6usb_afe =3D q6afe_port_get_from_id(cpu_dai->dev, USB_RX); + if (IS_ERR(q6usb_afe)) + goto out; + + /* Notify audio DSP about the devices being offloaded */ + ret =3D afe_port_send_usb_dev_param(q6usb_afe, sdev->card_idx, + sdev->ppcm_idx[sdev->num_playback - 1]); + +out: + mutex_unlock(&data->mutex); + + return ret; +} + +static const struct snd_soc_dai_ops q6usb_ops =3D { + .hw_params =3D q6usb_hw_params, +}; + +static struct snd_soc_dai_driver q6usb_be_dais[] =3D { + { + .playback =3D { + .stream_name =3D "USB BE RX", + .rates =3D SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | + SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_192000, + .formats =3D SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, + .channels_min =3D 1, + .channels_max =3D 2, + .rate_max =3D 192000, + .rate_min =3D 8000, + }, + .id =3D USB_RX, + .name =3D "USB_RX_BE", + .ops =3D &q6usb_ops, + }, +}; + +static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *c= omponent, + const struct of_phandle_args *args, + const char **dai_name) +{ + int id =3D args->args[0]; + int ret =3D -EINVAL; + int i; + + for (i =3D 0; i < ARRAY_SIZE(q6usb_be_dais); i++) { + if (q6usb_be_dais[i].id =3D=3D id) { + *dai_name =3D q6usb_be_dais[i].name; + ret =3D 0; + break; + } + } + + return ret; +} + +static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, + struct snd_soc_usb_device *sdev, bool connected) +{ + struct q6usb_port_data *data; + + if (!usb->component) + return -ENODEV; + + data =3D dev_get_drvdata(usb->component->dev); + + mutex_lock(&data->mutex); + if (connected) { + /* Selects the latest USB headset plugged in for offloading */ + list_add_tail(&sdev->list, &data->devices); + } else { + list_del(&sdev->list); + } + mutex_unlock(&data->mutex); + + return 0; +} + +static int q6usb_component_probe(struct snd_soc_component *component) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(component->dev); + struct snd_soc_usb *usb; + + usb =3D snd_soc_usb_allocate_port(component, &data->priv); + if (IS_ERR(usb)) + return -ENOMEM; + + usb->connection_status_cb =3D q6usb_alsa_connection_cb; + + snd_soc_usb_add_port(usb); + data->usb =3D usb; + + return 0; +} + +static void q6usb_component_remove(struct snd_soc_component *component) +{ + struct q6usb_port_data *data =3D dev_get_drvdata(component->dev); + + snd_soc_usb_remove_port(data->usb); + snd_soc_usb_free_port(data->usb); +} + +static const struct snd_soc_component_driver q6usb_dai_component =3D { + .probe =3D q6usb_component_probe, + .remove =3D q6usb_component_remove, + .name =3D "q6usb-dai-component", + .dapm_widgets =3D q6usb_dai_widgets, + .num_dapm_widgets =3D ARRAY_SIZE(q6usb_dai_widgets), + .dapm_routes =3D q6usb_dapm_routes, + .num_dapm_routes =3D ARRAY_SIZE(q6usb_dapm_routes), + .of_xlate_dai_name =3D q6usb_audio_ports_of_xlate_dai_name, +}; + +static int q6usb_dai_dev_probe(struct platform_device *pdev) +{ + struct device_node *node =3D pdev->dev.of_node; + struct q6usb_port_data *data; + struct device *dev =3D &pdev->dev; + struct of_phandle_args args; + int ret; + + data =3D devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret =3D of_property_read_u16(node, "qcom,usb-audio-intr-idx", + &data->priv.intr_num); + if (ret) { + dev_err(&pdev->dev, "failed to read intr idx.\n"); + return ret; + } + + ret =3D of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); + if (ret < 0) + data->priv.sid =3D -1; + else + data->priv.sid =3D args.args[0] & Q6_USB_SID_MASK; + + data->priv.domain =3D iommu_get_domain_for_dev(&pdev->dev); + + data->priv.dev =3D dev; + INIT_LIST_HEAD(&data->devices); + dev_set_drvdata(dev, data); + + return devm_snd_soc_register_component(dev, &q6usb_dai_component, + q6usb_be_dais, ARRAY_SIZE(q6usb_be_dais)); +} + +static const struct of_device_id q6usb_dai_device_id[] =3D { + { .compatible =3D "qcom,q6usb" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6usb_dai_device_id); + +static struct platform_driver q6usb_dai_platform_driver =3D { + .driver =3D { + .name =3D "q6usb-dai", + .of_match_table =3D of_match_ptr(q6usb_dai_device_id), + }, + .probe =3D q6usb_dai_dev_probe, + /* + * Remove not required as resources are cleaned up as part of + * component removal. Others are device managed resources. + */ +}; +module_platform_driver(q6usb_dai_platform_driver); + +MODULE_DESCRIPTION("Q6 USB backend dai driver"); +MODULE_LICENSE("GPL");