From: Greg KH <gregkh@linuxfoundation.org>
To: Wesley Cheng <quic_wcheng@quicinc.com>
Cc: srinivas.kandagatla@linaro.org, mathias.nyman@intel.com,
perex@perex.cz, lgirdwood@gmail.com, andersson@kernel.org,
krzysztof.kozlowski+dt@linaro.org, Thinh.Nguyen@synopsys.com,
broonie@kernel.org, bgoswami@quicinc.com, tiwai@suse.com,
robh+dt@kernel.org, agross@kernel.org,
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: [RFC PATCH v2 07/22] ASoC: Add SOC USB APIs for adding an USB backend
Date: Sat, 28 Jan 2023 14:26:32 +0100 [thread overview]
Message-ID: <Y9UiiMbJFjkzyEol@kroah.com> (raw)
In-Reply-To: <20230126031424.14582-8-quic_wcheng@quicinc.com>
On Wed, Jan 25, 2023 at 07:14:09PM -0800, Wesley Cheng wrote:
> diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h
> new file mode 100644
> index 000000000000..ec422a8a834f
> --- /dev/null
> +++ b/include/sound/soc-usb.h
> @@ -0,0 +1,33 @@
> +/* SPDX-License-Identifier: GPL-2.0
> + *
> + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
It is now 2023 :)
> + */
> +
> +#ifndef __LINUX_SND_SOC_USB_H
> +#define __LINUX_SND_SOC_USB_H
> +
> +/**
> + * struct snd_soc_usb
> + * @component - Reference to DAPM component
> + * @connection_status_cb - callback to notify connection events
> + * @priv_data - vendor data
You do not document all items in the structure so you will get build
warnings :(
And what exactly is "vendor data"? You use that term in a few places in
this series, there is no such thing as a "vendor" in the kernel. This
could be a device or driver specific data, but not a "vendor".
> --- /dev/null
> +++ b/sound/soc/soc-usb.c
> @@ -0,0 +1,202 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
> + */
> +#include <linux/of.h>
> +#include <linux/usb.h>
> +#include <sound/soc.h>
> +#include <sound/soc-usb.h>
> +#include "../usb/card.h"
> +
> +static DEFINE_MUTEX(ctx_mutex);
> +static LIST_HEAD(usb_ctx_list);
What is this a list of? Why a list? This should be dynamic and tied to
the device itself somehow, not a separate list you have to walk.
> +
> +#define for_each_usb_ctx(ctx) \
> + list_for_each_entry(ctx, &usb_ctx_list, list)
No need for a #define like this, just spell it out.
> +
> +static struct device_node *snd_soc_find_phandle(struct device *dev)
> +{
> + struct device_node *node;
> +
> + node = of_parse_phandle(dev->of_node, "usb-soc-be", 0);
> + if (!node)
> + return ERR_PTR(-ENODEV);
> +
> + return node;
> +}
> +
> +static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device *dev)
> +{
> + struct device_node *node;
> + struct snd_soc_usb *ctx = NULL;
> +
> + node = snd_soc_find_phandle(dev);
> + if (IS_ERR(node))
> + return NULL;
> +
> + mutex_lock(&ctx_mutex);
> + for_each_usb_ctx(ctx) {
> + if (ctx->dev->of_node == node) {
> + of_node_put(node);
> + mutex_unlock(&ctx_mutex);
> + return ctx;
> + }
> + }
> + of_node_put(node);
> + mutex_unlock(&ctx_mutex);
> +
> + return NULL;
> +}
> +
> +/**
> + * snd_soc_usb_get_priv_data() - Retrieve private data stored
> + * @usbdev: USB bus sysdev
> + *
> + * Fetch the private data stored in the USB SND SOC structure. This is
> + * intended to be called by the USB offloading class driver, in order to
> + * attain parameters about the USB backend device.
> + *
> + */
> +void *snd_soc_usb_get_priv_data(struct device *usbdev)
> +{
> + struct snd_soc_usb *ctx;
> +
> + if (!usbdev)
> + return NULL;
How could usbdev ever be NULL?
> +
> + ctx = snd_soc_find_usb_ctx(usbdev);
> +
> + return ctx ? ctx->priv_data : NULL;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_usb_get_priv_data);
> +
> +/**
> + * snd_soc_usb_set_priv_data() - Set private data stored
> + * @dev: USB backend device
> + * @priv: private data to store
> + *
> + * Save data describing the USB backend device parameters. This is intended
> + * to be called by the ASoC USB backend driver.
> + *
> + */
> +void snd_soc_usb_set_priv_data(struct device *dev, void *priv)
> +{
> + struct snd_soc_usb *ctx;
Why does this function take a "struct device" but the get function take
a USB device?
> +
> + mutex_lock(&ctx_mutex);
> + for_each_usb_ctx(ctx) {
> + if (dev->of_node == ctx->dev->of_node) {
> + ctx->priv_data = priv;
> + break;
> + }
> + }
> + mutex_unlock(&ctx_mutex);
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_usb_set_priv_data);
> +
> +/**
> + * snd_soc_usb_add_port() - Add a USB backend port
> + * @dev: USB backend device
> + * @connection_cb: connection status callback
> + *
> + * Register a USB backend device to the SND USB SOC framework. Memory is
> + * allocated as part of the USB backend device.
> + *
> + */
> +struct snd_soc_usb *snd_soc_usb_add_port(struct device *dev,
> + int (*connection_cb)(struct snd_soc_usb *usb, int card_idx,
> + int connected))
> +{
> + struct snd_soc_usb *usb;
> +
> + usb = devm_kzalloc(dev, sizeof(*usb), GFP_KERNEL);
> + if (!usb)
> + return ERR_PTR(-ENOMEM);
> +
> + usb->connection_status_cb = connection_cb;
> + usb->dev = dev;
> +
> + mutex_lock(&ctx_mutex);
> + list_add_tail(&usb->list, &usb_ctx_list);
> + mutex_unlock(&ctx_mutex);
Again, why a list?
> +
> + return usb;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_usb_add_port);
> +
> +/**
> + * snd_soc_usb_remove_port() - Remove a USB backend port
> + * @dev: USB backend device
> + *
> + * Remove a USB backend device from USB SND SOC. Memory is freed when USB
> + * backend is removed.
> + *
> + */
> +int snd_soc_usb_remove_port(struct device *dev)
> +{
> + struct snd_soc_usb *ctx, *tmp;
> +
> + mutex_lock(&ctx_mutex);
> + list_for_each_entry_safe(ctx, tmp, &usb_ctx_list, list) {
> + if (ctx->dev == dev) {
> + list_del(&ctx->list);
> + break;
> + }
> + }
> + mutex_unlock(&ctx_mutex);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_usb_remove_port);
> +
> +/**
> + * snd_soc_usb_connect() - Notification of USB device connection
> + * @usbdev: USB bus device
> + * @card_idx: USB SND card instance
> + *
> + * Notify of a new USB SND device connection. The card_idx can be used to
> + * handle how the USB backend selects, which device to enable offloading on.
> + *
> + */
> +int snd_soc_usb_connect(struct device *usbdev, int card_idx)
> +{
> + struct snd_soc_usb *ctx;
> +
> + if (!usbdev)
> + return -ENODEV;
> +
> + ctx = snd_soc_find_usb_ctx(usbdev);
> + if (!ctx)
> + return -ENODEV;
> +
> + if (ctx->connection_status_cb)
> + ctx->connection_status_cb(ctx, card_idx, 1);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_usb_connect);
> +
> +/**
> + * snd_soc_usb_connect() - Notification of USB device connection
> + * @usbdev: USB bus device
> + *
> + * Notify of a new USB SND device disconnection to the USB backend.
> + *
> + */
> +int snd_soc_usb_disconnect(struct device *usbdev)
> +{
> + struct snd_soc_usb *ctx;
> +
> + if (!usbdev)
> + return -ENODEV;
> +
> + ctx = snd_soc_find_usb_ctx(usbdev);
> + if (!ctx)
> + return -ENODEV;
> +
> + if (ctx->connection_status_cb)
> + ctx->connection_status_cb(ctx, -1, 0);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_usb_disconnect);
Meta-comment, why are all of these in the sound directory? They are
only operating on USB devices, nothing else. So why here?
thanks,
greg k-h
next prev parent reply other threads:[~2023-01-28 13:26 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 3:14 [RFC PATCH v2 00/22] Introduce QC USB SND audio offloading support Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 01/22] xhci: fix event ring segment table related masks and variables in header Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 02/22] xhci: remove xhci_test_trb_in_td_math early development check Wesley Cheng
2023-01-26 7:48 ` Greg KH
2023-01-26 3:14 ` [RFC PATCH v2 03/22] xhci: Refactor interrupter code for initial multi interrupter support Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 04/22] xhci: Add support to allocate several interrupters Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 05/22] usb: xhci: Add XHCI APIs to support USB offloading Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 06/22] usb: host: xhci-mem: Cleanup pending secondary event ring events Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 07/22] ASoC: Add SOC USB APIs for adding an USB backend Wesley Cheng
2023-01-26 15:32 ` Pierre-Louis Bossart
2023-01-30 22:36 ` Wesley Cheng
2023-01-28 13:26 ` Greg KH [this message]
2023-01-29 6:54 ` Zhou Furong
2023-01-29 7:09 ` Greg KH
2023-01-30 8:34 ` Zhou Furong
2023-01-30 9:27 ` Greg KH
2023-02-10 22:46 ` Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 08/22] ASoC: dt-bindings: Add USB_RX port Wesley Cheng
2023-01-26 11:55 ` Krzysztof Kozlowski
2023-01-30 21:52 ` Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 09/22] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Wesley Cheng
2023-01-26 15:07 ` Srinivas Kandagatla
2023-01-26 15:38 ` Pierre-Louis Bossart
2023-01-30 22:54 ` Wesley Cheng
2023-01-30 23:59 ` Pierre-Louis Bossart
2023-02-01 2:40 ` Wesley Cheng
2023-02-01 3:02 ` Pierre-Louis Bossart
2023-02-03 1:23 ` Wesley Cheng
2023-02-03 1:44 ` Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 10/22] ASoC: qdsp6: q6afe: Increase APR timeout Wesley Cheng
2023-01-26 15:09 ` Srinivas Kandagatla
2023-01-26 3:14 ` [RFC PATCH v2 11/22] ASoC: qcom: Add USB backend ASoC driver for Q6 Wesley Cheng
2023-01-26 15:44 ` Pierre-Louis Bossart
2023-01-30 22:59 ` Wesley Cheng
2023-01-30 23:50 ` Pierre-Louis Bossart
2023-01-26 16:35 ` Srinivas Kandagatla
2023-01-26 3:14 ` [RFC PATCH v2 12/22] sound: usb: card: Introduce USB SND platform op callbacks Wesley Cheng
2023-01-26 15:50 ` Pierre-Louis Bossart
2023-01-30 23:00 ` Wesley Cheng
2023-01-28 13:28 ` Greg KH
2023-02-10 22:49 ` Wesley Cheng
2023-02-28 2:59 ` Wesley Cheng
2023-02-28 7:30 ` Greg KH
2023-02-28 9:19 ` Wesley Cheng
2023-02-28 15:29 ` Greg KH
2023-02-20 17:11 ` Albert Wang
2023-01-26 3:14 ` [RFC PATCH v2 13/22] sound: usb: Export USB SND APIs for modules Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 14/22] dt-bindings: usb: dwc3: Add snps,num-hc-interrupters definition Wesley Cheng
2023-01-26 12:01 ` Krzysztof Kozlowski
2023-01-30 22:02 ` Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 15/22] usb: dwc3: Add DT parameter to specify maximum number of interrupters Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 16/22] sound: usb: Introduce QC USB SND offloading support Wesley Cheng
2023-01-26 16:07 ` Pierre-Louis Bossart
2023-01-28 13:32 ` Greg KH
2023-02-11 0:03 ` Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 17/22] sound: usb: card: Check for support for requested audio format Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 18/22] sound: soc: soc-usb: Add PCM format check API for USB backend Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 19/22] sound: soc: qcom: qusb6: Ensure PCM format is supported by USB audio device Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 20/22] sound: usb: Prevent starting of audio stream if in use Wesley Cheng
2023-01-26 16:12 ` Pierre-Louis Bossart
2023-02-07 1:15 ` Wesley Cheng
2023-02-07 13:29 ` Pierre-Louis Bossart
2023-02-11 9:52 ` Wesley Cheng
2023-02-13 15:22 ` Pierre-Louis Bossart
2023-02-13 20:12 ` Wesley Cheng
2023-01-26 3:14 ` [RFC PATCH v2 21/22] ASoC: dt-bindings: Add Q6USB backend bindings Wesley Cheng
2023-01-26 12:03 ` Krzysztof Kozlowski
2023-01-26 16:01 ` Srinivas Kandagatla
2023-01-26 3:14 ` [RFC PATCH v2 22/22] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Wesley Cheng
2023-01-26 12:05 ` Krzysztof Kozlowski
2023-01-26 9:23 ` [RFC PATCH v2 00/22] Introduce QC USB SND audio offloading support Mathias Nyman
2023-01-30 21:51 ` Wesley Cheng
2023-01-26 16:22 ` Pierre-Louis Bossart
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=Y9UiiMbJFjkzyEol@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=Thinh.Nguyen@synopsys.com \
--cc=agross@kernel.org \
--cc=alsa-devel@alsa-project.org \
--cc=andersson@kernel.org \
--cc=bgoswami@quicinc.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.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=quic_wcheng@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;
as well as URLs for NNTP newsgroup(s).