Re: [PATCH v37 24/31] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6

From: Wesley Cheng
Date: Mon Apr 07 2025 - 19:00:49 EST


Hi Stephan,

On 4/4/2025 2:54 AM, Stephan Gerhold wrote:
On Thu, Apr 03, 2025 at 05:27:21PM -0700, Wesley Cheng wrote:
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 <quic_wcheng@xxxxxxxxxxx>
---
include/sound/q6usboffload.h | 20 +++
sound/soc/qcom/Kconfig | 12 ++
sound/soc/qcom/qdsp6/Makefile | 1 +
sound/soc/qcom/qdsp6/q6usb.c | 278 ++++++++++++++++++++++++++++++++++
4 files changed, 311 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..35ae26ba6509
--- /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-2025 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+/**
+ * struct q6usb_offload - USB backend DAI link offload parameters
+ * @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;

"long long" feels like overkill for sid, given that it's essentially
either an u8 or -1. I see you just copied this from q6asm-dai.c, but
unlike q6asm-dai, you don't seem to check for sid < 0 in PATCH 28/31
(qc_audio_offload.c).

Looking at the logic in q6asm-dai.c, it feels like this could really
just be an "u8", since the -1 for "no iommus specified" is effectively
just handled like sid = 0.


Thanks for the detailed feedback and review. Will change it accordingly as you suggested.

+ u16 intr_num;
+};
[...]
diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c
new file mode 100644
index 000000000000..cb8c4a62a816
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6usb.c
[...]
+static int q6usb_dai_dev_probe(struct platform_device *pdev)
+{
+ struct device_node *node = pdev->dev.of_node;
+ struct q6usb_port_data *data;
+ struct device *dev = &pdev->dev;
+ struct of_phandle_args args;
+ int ret;
+
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ ret = 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 = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args);
+ if (ret < 0)
+ data->priv.sid = -1;
+ else

Could just do if (ret == 0) here and drop the if branch above, if you
make sid an u8 like I suggested above.


Will do.

+ data->priv.sid = args.args[0] & Q6_USB_SID_MASK;
+
+ data->priv.domain = iommu_get_domain_for_dev(&pdev->dev);
+
+ data->priv.dev = dev;
+ INIT_LIST_HEAD(&data->devices);

I think you also need devm_mutex_init(&data->lock) or separate
mutex_init()/mutex_destroy() here, if someone enables
CONFIG_DEBUG_MUTEXES.


Ah, yes, will explicitly initialize the mutex here.

Thanks
Wesley Cheng