From: Wesley Cheng <quic_wcheng@quicinc.com>
To: "Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>,
srinivas.kandagatla@linaro.org, mathias.nyman@intel.com,
perex@perex.cz, lgirdwood@gmail.com, andersson@kernel.org,
krzysztof.kozlowski+dt@linaro.org, gregkh@linuxfoundation.org,
Thinh.Nguyen@synopsys.com, broonie@kernel.org,
bgoswami@quicinc.com, tiwai@suse.com, robh+dt@kernel.org,
agross@kernel.org
Cc: <linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
<alsa-devel@alsa-project.org>, <devicetree@vger.kernel.org>,
<linux-usb@vger.kernel.org>, <quic_jackp@quicinc.com>,
<quic_plai@quicinc.com>
Subject: Re: [PATCH v5 10/32] ASoC: qcom: Add USB backend ASoC driver for Q6
Date: Thu, 31 Aug 2023 12:34:38 -0700 [thread overview]
Message-ID: <ee16db64-661f-c28c-59ed-d895041f7ea5@quicinc.com> (raw)
In-Reply-To: <cd39ced8-fa89-a666-383f-8fd1c7a14d23@linux.intel.com>
Hi,
On 8/30/2023 5:50 AM, Amadeusz Sławiński wrote:
> On 8/29/2023 11:06 PM, 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.
>>
>> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
>> ---
>> include/sound/q6usboffload.h | 20 ++++
>> sound/soc/qcom/Kconfig | 4 +
>> sound/soc/qcom/qdsp6/Makefile | 1 +
>> sound/soc/qcom/qdsp6/q6usb.c | 200 ++++++++++++++++++++++++++++++++++
>> 4 files changed, 225 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..4fb1912d9f55
>> --- /dev/null
>> +++ b/include/sound/q6usboffload.h
>> @@ -0,0 +1,20 @@
>> +/* SPDX-License-Identifier: GPL-2.0
>> + *
>> + * linux/sound/q6usboffload.h -- QDSP6 USB offload
>> + *
>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All
>> rights reserved.
>> + */
>> +
>> +/**
>> + * struct q6usb_offload
>> + * @dev - dev handle to usb be
>> + * @sid - streamID for iommu
>> + * @intr_num - usb interrupter number
>> + * @domain - allocated iommu domain
>> + **/
>> +struct q6usb_offload {
>> + struct device *dev;
>> + long long sid;
>> + u32 intr_num;
>> + struct iommu_domain *domain;
>> +};
>> diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
>> index e7b00d1d9e99..bb285af6bb04 100644
>> --- a/sound/soc/qcom/Kconfig
>> +++ b/sound/soc/qcom/Kconfig
>> @@ -114,6 +114,9 @@ config SND_SOC_QDSP6_APM
>> config SND_SOC_QDSP6_PRM_LPASS_CLOCKS
>> tristate
>> +config SND_SOC_QDSP6_USB
>> + tristate
>> +
>> config SND_SOC_QDSP6_PRM
>> tristate
>> select SND_SOC_QDSP6_PRM_LPASS_CLOCKS
>> @@ -134,6 +137,7 @@ config SND_SOC_QDSP6
>> select SND_SOC_TOPOLOGY
>> select SND_SOC_QDSP6_APM
>> select SND_SOC_QDSP6_PRM
>> + select SND_SOC_QDSP6_USB
>> help
>> To add support for MSM QDSP6 Soc Audio.
>> This will enable sound soc platform specific
>> diff --git a/sound/soc/qcom/qdsp6/Makefile
>> b/sound/soc/qcom/qdsp6/Makefile
>> index 3963bf234664..c9457ee898d0 100644
>> --- a/sound/soc/qcom/qdsp6/Makefile
>> +++ b/sound/soc/qcom/qdsp6/Makefile
>> @@ -17,3 +17,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_APM_DAI) += q6apm-dai.o
>> obj-$(CONFIG_SND_SOC_QDSP6_APM_LPASS_DAI) += q6apm-lpass-dais.o
>> obj-$(CONFIG_SND_SOC_QDSP6_PRM) += q6prm.o
>> obj-$(CONFIG_SND_SOC_QDSP6_PRM_LPASS_CLOCKS) += q6prm-clocks.o
>> +obj-$(CONFIG_SND_SOC_QDSP6_USB) += q6usb.o
>> diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c
>> new file mode 100644
>> index 000000000000..88aa0a64201a
>> --- /dev/null
>> +++ b/sound/soc/qcom/qdsp6/q6usb.c
>> @@ -0,0 +1,200 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All
>> rights reserved.
>> + */
>> +
>> +#include <linux/err.h>
>> +#include <linux/init.h>
>> +#include <linux/module.h>
>> +#include <linux/device.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/slab.h>
>> +#include <linux/iommu.h>
>> +#include <linux/dma-mapping.h>
>> +#include <linux/dma-map-ops.h>
>> +
>> +#include <sound/pcm.h>
>> +#include <sound/soc.h>
>> +#include <sound/soc-usb.h>
>> +#include <sound/pcm_params.h>
>> +#include <sound/asound.h>
>> +#include <sound/q6usboffload.h>
>> +
>> +#include "q6dsp-lpass-ports.h"
>> +#include "q6afe.h"
>> +
>> +#define SID_MASK 0xF
>> +
>> +struct q6usb_port_data {
>> + struct q6afe_usb_cfg usb_cfg;
>> + struct snd_soc_usb *usb;
>> + struct q6usb_offload priv;
>> + int active_idx;
>> +};
>> +
>> +static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = {
>> + SND_SOC_DAPM_HP("USB_RX_BE", NULL),
>> +};
>> +
>> +static const struct snd_soc_dapm_route q6usb_dapm_routes[] = {
>> + {"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)
>> +{
>> + return 0;
>> +}
>
> Missing new line after closing bracket between function and following
> struct.
>
Thanks for the review, will fix this.
>> +static const struct snd_soc_dai_ops q6usb_ops = {
>> + .hw_params = q6usb_hw_params,
>> +};
>> +
>> +static struct snd_soc_dai_driver q6usb_be_dais[] = {
>> + {
>> + .playback = {
>> + .stream_name = "USB BE RX",
>> + .rates = 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 = 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 = 1,
>> + .channels_max = 2,
>> + .rate_max = 192000,
>> + .rate_min = 8000,
>> + },
>> + .id = USB_RX,
>> + .name = "USB_RX_BE",
>> + .ops = &q6usb_ops,
>> + },
>> +};
>> +
>> +static int q6usb_audio_ports_of_xlate_dai_name(struct
>> snd_soc_component *component,
>> + const struct of_phandle_args *args,
>> + const char **dai_name)
>> +{
>> + int id = args->args[0];
>> + int ret = -EINVAL;
>> + int i;
>> +
>> + for (i = 0; i < ARRAY_SIZE(q6usb_be_dais); i++) {
>
> Double space after second i.
>
Will change.
>> + if (q6usb_be_dais[i].id == id) {
>> + *dai_name = q6usb_be_dais[i].name;
>> + ret = 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 = dev_get_drvdata(usb->component->dev);
>> +
>> + if (connected)
>> + /* We only track the latest USB headset plugged in */
>> + data->active_idx = sdev->card_idx;
>
> Maybe add brackets around both comment and code? Not sure what guidance
> there is in such cases, but above code looks weird to me.
>
Sure.
>> +
>> + return 0;
>> +}
>> +
>> +static int q6usb_component_probe(struct snd_soc_component *component)
>> +{
>> + struct q6usb_port_data *data = dev_get_drvdata(component->dev);
>> +
>> + data->usb = snd_soc_usb_add_port(component->dev, &data->priv,
>> q6usb_alsa_connection_cb);
>> + if (IS_ERR(data->usb)) {
>> + dev_err(component->dev, "failed to add usb port\n");
>> + return -ENODEV;
>> + }
>> +
>> + data->usb->component = component;
>> +
>> + return 0;
>> +}
>> +
>> +static void q6usb_component_remove(struct snd_soc_component *component)
>> +{
>> + snd_soc_usb_remove_port(component->dev);
>> +}
>> +
>> +static const struct snd_soc_component_driver q6usb_dai_component = {
>> + .probe = q6usb_component_probe,
>> + .remove = q6usb_component_remove,
>> + .name = "q6usb-dai-component",
>> + .dapm_widgets = q6usb_dai_widgets,
>> + .num_dapm_widgets = ARRAY_SIZE(q6usb_dai_widgets),
>> + .dapm_routes = q6usb_dapm_routes,
>> + .num_dapm_routes = ARRAY_SIZE(q6usb_dapm_routes),
>> + .of_xlate_dai_name = q6usb_audio_ports_of_xlate_dai_name,
>> +};
>> +
>> +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_u32(node, "qcom,usb-audio-intr-num",
>> + &data->priv.intr_num);
>> + if (ret) {
>> + dev_err(&pdev->dev, "failed to read intr num.\n");
>> + return ret;
>> + }
>> +
>> + ret = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args);
>> + if (ret < 0)
>> + data->priv.sid = -1;
>> + else
>> + data->priv.sid = args.args[0] & SID_MASK;
>> +
>> + data->priv.domain = iommu_get_domain_for_dev(&pdev->dev);
>> +
>> + data->priv.dev = dev;
>> + dev_set_drvdata(dev, data);
>> +
>> + return devm_snd_soc_register_component(dev, &q6usb_dai_component,
>> + q6usb_be_dais, ARRAY_SIZE(q6usb_be_dais));
>> +}
>> +
>> +static int q6usb_dai_dev_remove(struct platform_device *pdev)
>> +{
>> + return 0;
>> +}
>
> Does platform driver really need empty remove function? Remove it.
>
Wasn't too sure about this either, so I included it to be consistent.
Will remove this and add a small comment on why it isn't required..
Thanks
Wesley Cheng
next prev parent reply other threads:[~2023-08-31 19:35 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 21:06 [PATCH v5 00/32] Introduce QC USB SND audio offloading support Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 01/32] xhci: add support to allocate several interrupters Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 02/32] xhci: add helper to stop endpoint and wait for completion Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 03/32] xhci: sideband: add initial api to register a sideband entity Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 04/32] usb: host: xhci-mem: Cleanup pending secondary event ring events Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 05/32] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 06/32] ASoC: Add SOC USB APIs for adding an USB backend Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 07/32] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 08/32] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 09/32] ASoC: qdsp6: q6afe: Increase APR timeout Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 10/32] ASoC: qcom: Add USB backend ASoC driver for Q6 Wesley Cheng
2023-08-30 12:50 ` Amadeusz Sławiński
2023-08-31 19:34 ` Wesley Cheng [this message]
2023-08-29 21:06 ` [PATCH v5 11/32] sound: usb: card: Introduce USB SND platform op callbacks Wesley Cheng
2023-09-07 15:36 ` Takashi Iwai
2023-09-11 17:57 ` Wesley Cheng
2023-09-12 22:36 ` Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 12/32] sound: usb: Export USB SND APIs for modules Wesley Cheng
2023-08-30 12:50 ` Amadeusz Sławiński
2023-08-31 19:36 ` Wesley Cheng
2023-09-07 15:38 ` Takashi Iwai
2023-09-11 17:58 ` Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 13/32] dt-bindings: usb: dwc3: Add snps,num-hc-interrupters definition Wesley Cheng
2023-08-31 17:24 ` Rob Herring
2023-08-31 19:25 ` Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 14/32] dt-bindings: usb: xhci: Add num-hc-interrupters definition Wesley Cheng
2023-08-31 17:22 ` Rob Herring
2023-08-29 21:06 ` [PATCH v5 15/32] usb: dwc3: Add DT parameter to specify maximum number of interrupters Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 16/32] usb: host: xhci-plat: Set XHCI max interrupters if property is present Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 17/32] sound: usb: qcom: Add USB QMI definitions Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 18/32] sound: usb: Introduce QC USB SND offloading support Wesley Cheng
2023-09-07 15:51 ` Takashi Iwai
2023-09-11 17:59 ` Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 19/32] sound: usb: card: Check for support for requested audio format Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 20/32] sound: soc: soc-usb: Add PCM format check API for USB backend Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 21/32] sound: soc: qcom: qusb6: Ensure PCM format is supported by USB audio device Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 22/32] sound: usb: Prevent starting of audio stream if in use Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 23/32] ASoC: dt-bindings: Add Q6USB backend Wesley Cheng
2023-08-31 17:29 ` Rob Herring
2023-08-31 19:32 ` Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 24/32] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Wesley Cheng
2023-08-31 17:29 ` Rob Herring
2023-08-29 21:06 ` [PATCH v5 25/32] ASoC: qcom: qdsp6: q6afe: Split USB AFE dev_token param into separate API Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 26/32] sound: Pass USB SND card and PCM information to SOC USB Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 27/32] sound: soc: qdsp6: Add SND kcontrol to select offload device Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 28/32] sound: soc: qdsp6: Add SND kcontrol for fetching offload status Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 29/32] sound: soc: qcom: q6usb: Add headphone jack for offload connection status Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 30/32] sound: usb: qc_audio_offload: Use card and PCM index from QMI request Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 31/32] sound: usb: card: Allow for rediscovery of connected USB SND devices Wesley Cheng
2023-08-29 21:06 ` [PATCH v5 32/32] sound: soc: soc-usb: Rediscover USB SND devices on USB port add Wesley Cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee16db64-661f-c28c-59ed-d895041f7ea5@quicinc.com \
--to=quic_wcheng@quicinc.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=agross@kernel.org \
--cc=alsa-devel@alsa-project.org \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=andersson@kernel.org \
--cc=bgoswami@quicinc.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=perex@perex.cz \
--cc=quic_jackp@quicinc.com \
--cc=quic_plai@quicinc.com \
--cc=robh+dt@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox