From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Vinod Koul <vinod.koul@intel.com>, Greg KH <gregkh@linuxfoundation.org>
Cc: tiwai@suse.de, liam.r.girdwood@linux.intel.com,
ALSA <alsa-devel@alsa-project.org>,
broonie@kernel.org, patches.audio@intel.com
Subject: Re: [PATCH v2 11/13] soundwire: cdns: Add stream routines
Date: Thu, 5 Apr 2018 19:29:11 -0500 [thread overview]
Message-ID: <03af620f-2961-32f0-99a2-dbf4e5bd0fd2@linux.intel.com> (raw)
In-Reply-To: <1522946904-2089-12-git-send-email-vinod.koul@intel.com>
On 4/5/18 11:48 AM, Vinod Koul wrote:
> Add support for Cadence stream initialization and implement
> stream APIs.
>
> Signed-off-by: Sanyog Kale <sanyog.r.kale@intel.com>
> Signed-off-by: Shreyas NC <shreyas.nc@intel.com>
> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
> ---
> drivers/soundwire/cadence_master.c | 180 +++++++++++++++++++++++++++++++++++++
> drivers/soundwire/cadence_master.h | 43 +++++++++
> 2 files changed, 223 insertions(+)
>
> diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c
> index 89a4ae86d36a..9400327c9fe2 100644
> --- a/drivers/soundwire/cadence_master.c
> +++ b/drivers/soundwire/cadence_master.c
> @@ -13,6 +13,8 @@
> #include <linux/mod_devicetable.h>
> #include <linux/soundwire/sdw_registers.h>
> #include <linux/soundwire/sdw.h>
> +#include <sound/pcm_params.h>
> +#include <sound/soc.h>
> #include "bus.h"
> #include "cadence_master.h"
>
> @@ -998,5 +1000,183 @@ int sdw_cdns_probe(struct sdw_cdns *cdns)
> }
> EXPORT_SYMBOL(sdw_cdns_probe);
>
> +int cdns_set_sdw_stream(struct snd_soc_dai *dai,
> + void *stream, bool pcm, int direction)
> +{
> + struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
> + struct sdw_cdns_dma_data *dma;
> +
> + dma = kzalloc(sizeof(*dma), GFP_KERNEL);
> + if (!dma)
> + return -ENOMEM;
> +
> + if (pcm)
> + dma->stream_type = SDW_STREAM_PCM;
> + else
> + dma->stream_type = SDW_STREAM_PDM;
> +
> + dma->bus = &cdns->bus;
> + dma->link_id = cdns->instance;
> +
> + dma->stream = stream;
> +
> + if (direction == SNDRV_PCM_STREAM_PLAYBACK)
> + dai->playback_dma_data = dma;
> + else
> + dai->capture_dma_data = dma;
> +
> + return 0;
> +
> +}
> +EXPORT_SYMBOL(cdns_set_sdw_stream);
> +
> +static struct sdw_cdns_pdi *cdns_find_pdi(struct sdw_cdns *cdns,
> + unsigned int num, struct sdw_cdns_pdi *pdi)
> +{
> + int i;
> +
> + for (i = 0; i < num; i++) {
> + if (pdi[i].assigned == true)
> + continue;
> + pdi[i].assigned = true;
> + return &pdi[i];
> + }
> +
> + return NULL;
> +}
> +
> +/**
> + * sdw_cdns_config_stream: Configure a stream
> + *
> + * @cdns: Cadence instance
> + * @port: Cadence data port
> + * @ch: Channel count
> + * @dir: Data direction
> + * @pdi: PDI to be used
> + */
> +void sdw_cdns_config_stream(struct sdw_cdns *cdns,
> + struct sdw_cdns_port *port,
> + u32 ch, u32 dir, struct sdw_cdns_pdi *pdi)
> +{
> + u32 offset, val = 0;
> +
> + if (dir == SDW_DATA_DIR_RX)
> + val = CDNS_PORTCTRL_DIRN;
> +
> + offset = CDNS_PORTCTRL + port->num * CDNS_PORT_OFFSET;
> + cdns_updatel(cdns, offset, CDNS_PORTCTRL_DIRN, val);
> +
> + val = port->num;
> + val |= ((1 << ch) - 1) << SDW_REG_SHIFT(CDNS_PDI_CONFIG_CHANNEL);
> + cdns_writel(cdns, CDNS_PDI_CONFIG(pdi->num), val);
> +}
> +EXPORT_SYMBOL(sdw_cdns_config_stream);
> +
> +static int cdns_get_pdi(struct sdw_cdns *cdns,
> + struct sdw_cdns_pdi *pdi,
> + unsigned int num, u32 ch)
> +{
> + int i, pdis = 0;
> + u32 ch_count = ch;
redundant variable without added value...
> +
> + for (i = 0; i < num; i++) {
> + if (pdi[i].assigned == true)
> + continue;
> +
> + if (pdi[i].ch_count < ch_count)
> + ch_count -= pdi[i].ch_count;
> + else
> + ch_count = 0;
> +
> + pdis++;
> +
> + if (!ch_count)
> + break;
> + }
> +
> + if (ch_count)
> + return 0;
> +
> + return pdis;
> +}
> +
> +/**
> + * sdw_cdns_get_stream: Get stream information
> + *
> + * @cdns: Cadence instance
> + * @stream: Stream to be allocated
> + * @ch: Channel count
> + * @dir: Data direction
> + */
> +int sdw_cdns_get_stream(struct sdw_cdns *cdns,
> + struct sdw_cdns_streams *stream,
> + u32 ch, u32 dir)
> +{
> + int pdis = 0;
> +
> + if (dir == SDW_DATA_DIR_RX)
> + pdis = cdns_get_pdi(cdns, stream->in, stream->num_in, ch);
> + else
> + pdis = cdns_get_pdi(cdns, stream->out, stream->num_out, ch);
> +
> + /* check if we found PDI, else find in bi-directional */
> + if (!pdis)
> + pdis = cdns_get_pdi(cdns, stream->bd, stream->num_bd, ch);
> +
> + return pdis;
> +}
> +EXPORT_SYMBOL(sdw_cdns_get_stream);
> +
> +/**
> + * sdw_cdns_alloc_stream: Allocate a stream
> + *
> + * @cdns: Cadence instance
> + * @stream: Stream to be allocated
> + * @port: Cadence data port
> + * @ch: Channel count
> + * @dir: Data direction
> + */
> +int sdw_cdns_alloc_stream(struct sdw_cdns *cdns,
> + struct sdw_cdns_streams *stream,
> + struct sdw_cdns_port *port, u32 ch, u32 dir)
> +{
> + struct sdw_cdns_pdi *pdi = NULL;
> +
> + if (dir == SDW_DATA_DIR_RX)
> + pdi = cdns_find_pdi(cdns, stream->num_in, stream->in);
> + else
> + pdi = cdns_find_pdi(cdns, stream->num_out, stream->out);
> +
> + /* check if we found a PDI, else find in bi-directional */
> + if (!pdi)
> + pdi = cdns_find_pdi(cdns, stream->num_bd, stream->bd);
> +
> + if (!pdi)
> + return -EIO;
> +
> + port->pdi = pdi;
> + pdi->l_ch_num = 0;
> + pdi->h_ch_num = ch - 1;
> + pdi->dir = dir;
> + pdi->ch_count = ch;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(sdw_cdns_alloc_stream);
can you clarify the difference between _get_pdi and _find_pdi and
alloc_stream/get_stream.
It's pretty confusing.
> +
> +void sdw_cdns_shutdown(struct snd_pcm_substream *substream,
> + struct snd_soc_dai *dai)
> +{
> + struct sdw_cdns_dma_data *dma;
> +
> + dma = snd_soc_dai_get_dma_data(dai, substream);
> + if (!dma)
> + return;
> +
> + snd_soc_dai_set_dma_data(dai, substream, NULL);
> + kfree(dma);
> +}
> +EXPORT_SYMBOL(sdw_cdns_shutdown);
> +
> MODULE_LICENSE("Dual BSD/GPL");
> MODULE_DESCRIPTION("Cadence Soundwire Library");
> diff --git a/drivers/soundwire/cadence_master.h b/drivers/soundwire/cadence_master.h
> index 98a17f57918f..eb902b19c5a4 100644
> --- a/drivers/soundwire/cadence_master.h
> +++ b/drivers/soundwire/cadence_master.h
> @@ -1,5 +1,6 @@
> // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
> // Copyright(c) 2015-17 Intel Corporation.
> +#include <sound/soc.h>
>
> #ifndef __SDW_CADENCE_H
> #define __SDW_CADENCE_H
> @@ -91,6 +92,26 @@ struct sdw_cdns_stream_config {
> };
>
> /**
> + * struct sdw_cdns_dma_data: Cadence DMA data
> + *
> + * @name: SoundWire stream name
> + * @nr_ports: Number of ports
> + * @port: Ports
> + * @bus: Bus handle
> + * @stream_type: Stream type
> + * @link_id: Master link id
> + */
> +struct sdw_cdns_dma_data {
> + char *name;
> + struct sdw_stream_runtime *stream;
> + int nr_ports;
> + struct sdw_cdns_port **port;
> + struct sdw_bus *bus;
> + enum sdw_stream_type stream_type;
> + int link_id;
> +};
> +
> +/**
> * struct sdw_cdns - Cadence driver context
> * @dev: Linux device
> * @bus: Bus handle
> @@ -142,6 +163,25 @@ int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
> struct sdw_cdns_stream_config config);
> int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns);
>
> +int sdw_cdns_get_stream(struct sdw_cdns *cdns,
> + struct sdw_cdns_streams *stream,
> + u32 ch, u32 dir);
> +int sdw_cdns_alloc_stream(struct sdw_cdns *cdns,
> + struct sdw_cdns_streams *stream,
> + struct sdw_cdns_port *port, u32 ch, u32 dir);
> +void sdw_cdns_config_stream(struct sdw_cdns *cdns, struct sdw_cdns_port *port,
> + u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
> +
> +void sdw_cdns_shutdown(struct snd_pcm_substream *substream,
> + struct snd_soc_dai *dai);
> +int sdw_cdns_pcm_set_stream(struct snd_soc_dai *dai,
> + void *stream, int direction);
> +int sdw_cdns_pdm_set_stream(struct snd_soc_dai *dai,
> + void *stream, int direction);
> +
> +enum sdw_command_response
> +cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
> +
> enum sdw_command_response
> cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
>
> @@ -153,4 +193,7 @@ enum sdw_command_response
> cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
>
> int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
> +
> +int cdns_set_sdw_stream(struct snd_soc_dai *dai,
> + void *stream, bool pcm, int direction);
> #endif /* __SDW_CADENCE_H */
>
next prev parent reply other threads:[~2018-04-06 0:29 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 16:48 [PATCH v2 00/13] soundwire: Add stream support Vinod Koul
2018-04-05 16:48 ` [PATCH v2 01/13] soundwire: Add more documentation Vinod Koul
2018-04-05 21:37 ` Pierre-Louis Bossart
2018-04-06 3:24 ` Vinod Koul
2018-04-06 15:24 ` Pierre-Louis Bossart
2018-04-10 4:04 ` Vinod Koul
2018-04-05 16:48 ` [PATCH v2 02/13] soundwire: Add support for SoundWire stream management Vinod Koul
2018-04-05 22:34 ` Pierre-Louis Bossart
2018-04-06 4:53 ` Vinod Koul
2018-04-06 15:21 ` Pierre-Louis Bossart
2018-04-10 4:43 ` Vinod Koul
2018-04-10 15:47 ` Pierre-Louis Bossart
2018-04-11 3:41 ` [alsa-devel] " Vinod Koul
2018-04-05 16:48 ` [PATCH v2 03/13] soundwire: Add support for port management Vinod Koul
2018-04-05 23:04 ` Pierre-Louis Bossart
2018-04-06 5:00 ` Vinod Koul
2018-04-06 15:26 ` Pierre-Louis Bossart
2018-04-05 16:48 ` [PATCH v2 04/13] soundwire: Add Master and Slave port programming Vinod Koul
2018-04-05 23:14 ` Pierre-Louis Bossart
2018-04-06 5:01 ` Vinod Koul
2018-04-05 16:48 ` [PATCH v2 05/13] soundwire: Add helpers for ports operations Vinod Koul
2018-04-05 23:27 ` Pierre-Louis Bossart
2018-04-06 5:05 ` Vinod Koul
2018-04-05 16:48 ` [PATCH v2 06/13] soundwire: Add bank switch routine Vinod Koul
2018-04-05 23:35 ` Pierre-Louis Bossart
2018-04-06 8:33 ` Vinod Koul
2018-04-05 16:48 ` [PATCH v2 07/13] soundwire: Add stream configuration APIs Vinod Koul
2018-04-05 23:40 ` Pierre-Louis Bossart
2018-04-06 8:48 ` Vinod Koul
2018-04-06 15:28 ` Pierre-Louis Bossart
2018-04-05 16:48 ` [PATCH v2 08/13] ASoC: Add SoundWire stream programming interface Vinod Koul
2018-04-05 23:42 ` Pierre-Louis Bossart
2018-04-06 8:49 ` Vinod Koul
2018-04-05 16:48 ` [PATCH v2 09/13] soundwire: Remove cdns_master_ops Vinod Koul
2018-04-05 16:48 ` [PATCH v2 10/13] soundwire: cdns: Add port routines Vinod Koul
2018-04-06 0:19 ` Pierre-Louis Bossart
2018-04-06 8:55 ` Vinod Koul
2018-04-06 15:29 ` Pierre-Louis Bossart
2018-04-05 16:48 ` [PATCH v2 11/13] soundwire: cdns: Add stream routines Vinod Koul
2018-04-06 0:29 ` Pierre-Louis Bossart [this message]
2018-04-06 8:57 ` Vinod Koul
2018-04-05 16:48 ` [PATCH v2 12/13] soundwire: intel: Add stream initialization Vinod Koul
2018-04-05 16:48 ` [PATCH v2 13/13] soundwire: intel: Add audio DAI ops Vinod Koul
2018-04-06 0:46 ` [PATCH v2 00/13] soundwire: Add stream support 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=03af620f-2961-32f0-99a2-dbf4e5bd0fd2@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=liam.r.girdwood@linux.intel.com \
--cc=patches.audio@intel.com \
--cc=tiwai@suse.de \
--cc=vinod.koul@intel.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