This patch series enables DMA mode on Intel Keem Bay platform
Subsystems (5)
cover This patch series enables DMA mode on Intel Keem Bay platform
v1: Initial patch version, which contains fix for S24_LE format and also enable
DMA mode on Intel Keembay platform
Michael Sit Wei Hong (5):
ASoC: Intel: KMB: Fix S24_LE configuration
dt-bindings: sound: intel, keembay-i2s: Add info for device to use DMA
ASoC: soc-generic-dmaengine-pcm: Add custom prepare and submit
function
ASoC: dmaengine_pcm: expose functions to header file for custom
functions
ASoC: Intel: KMB: Enable DMA transfer mode
.../bindings/sound/intel,keembay-i2s.yaml | 14 ++ include/sound/dmaengine_pcm.h | 21 ++ sound/core/pcm_dmaengine.c | 46 ++-- sound/soc/intel/Kconfig | 2 + sound/soc/intel/keembay/kmb_platform.c | 208 ++++++++++++++++-- sound/soc/intel/keembay/kmb_platform.h | 9 + sound/soc/soc-generic-dmaengine-pcm.c | 8 +- 7 files changed, 270 insertions(+), 38 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/5 ASoC: Intel: KMB: Fix S24_LE configuration
S24_LE is 24 bit audio in 32 bit container configuration Fixing the configuration to match the data arrangement of this audio format.
--- sound/soc/intel/keembay/kmb_platform.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/intel/keembay/kmb_platform.c +3 -3
@@ -487,9 +487,9 @@ static int kmb_dai_hw_params(struct snd_pcm_substream *substream, kmb_i2s->xfer_resolution =0x02 ;break ;case SNDRV_PCM_FORMAT_S24_LE : - config->data_width =24 ; - kmb_i2s->ccr =0x08 ; - kmb_i2s->xfer_resolution =0x04 ; + config->data_width =32 ; + kmb_i2s->ccr =0x14 ; + kmb_i2s->xfer_resolution =0x05 ;break ;case SNDRV_PCM_FORMAT_S32_LE : config->data_width =32 ;
Signature · 1 line
2.17.1
PATCH 2/5 dt-bindings: sound: intel, keembay-i2s: Add info for device to use DMA
In reply to Michael Sit Wei HongAdd descriptions for entries needed for audio device to use DMA channels for audio playback and capture.
--- .../bindings/sound/intel,keembay-i2s.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/sound/intel,keembay-i2s.yaml +14 -0
@@ -45,6 +45,18 @@ properties: - const: osc - const: apb_clk + dmas: + items: + - description: DMA controller phandle and DMA channel + for TX and RX + + dma-names: + items: + - description: "tx" for the transmit channel + "rx" for the receive channel + - const: tx + - const: rx + required: - compatible - "#sound-dai-cells"
@@ -70,4 +82,6 @@ examples: interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>; clock-names = "osc", "apb_clk"; clocks = <&scmi_clk KEEM_BAY_PSS_AUX_I2S3>, <&scmi_clk KEEM_BAY_PSS_I2S3>; + dmas = <&axi_dma0 29 &axi_dma0 33>; + dma-names = "tx", "rx"; };
Signature · 1 line
2.17.1
PATCH 3/5 ASoC: soc-generic-dmaengine-pcm: Add custom prepare and submit function
In reply to Michael Sit Wei HongEnabling custom prepare and submit function to overcome DMA limitation.
In the Intel KeemBay solution, the DW AXI-based DMA has a limitation on the number of DMA blocks per transfer. In the case of 16 bit audio ASoC would allocate blocks exceeding the DMA block limitation.
The ASoC layers are not aware of such DMA limitation, and the DMA engine does not provide an API to set the maximum number of blocks per linked link.
This patch suggests an additional callback to let the caller check and modify the number of blocks per transfer to work-around the limitations.
--- include/sound/dmaengine_pcm.h | 6 ++++++ sound/core/pcm_dmaengine.c | 30 ++++++++++++++++++++++----- sound/soc/soc-generic-dmaengine-pcm.c | 8 ++++++- 3 files changed, 38 insertions(+), 6 deletions(-)
include/sound/dmaengine_pcm.h +6 -0
@@ -28,6 +28,9 @@ snd_pcm_substream_to_dma_direction(const struct snd_pcm_substream *substream)int snd_hwparams_to_dma_slave_config (const struct snd_pcm_substream *substream,const struct snd_pcm_hw_params *params,struct dma_slave_config *slave_config);int snd_dmaengine_pcm_trigger (struct snd_pcm_substream *substream,int cmd); +int snd_dmaengine_pcm_custom_trigger (struct snd_pcm_substream *substream,int cmd, +int (*custom_pcm_prepare_and_submit)(struct snd_pcm_substream *substream)); +snd_pcm_uframes_t snd_dmaengine_pcm_pointer (struct snd_pcm_substream *substream);snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue (struct snd_pcm_substream *substream);
@@ -113,6 +116,8 @@ int snd_dmaengine_pcm_refine_runtime_hwparams(* which do not use devicetree. * @process: Callback used to apply processing on samples transferred from/to * user space. +* @custom_pcm_prepare_and_submit: Callback used to work-around DMA limitations +* related to link lists. * @compat_filter_fn: Will be used as the filter function when requesting a * channel for platforms which do not use devicetree. The filter parameter * will be the DAI's DMA data.
@@ -138,6 +143,7 @@ struct snd_dmaengine_pcm_config {int (*process)(struct snd_pcm_substream *substream,int channel,unsigned long hwoff,void *buf,unsigned long bytes); +int (*custom_pcm_prepare_and_submit)(struct snd_pcm_substream *substream);dma_filter_fn compat_filter_fn;struct device *dma_dev;const char *chan_names[SNDRV_PCM_STREAM_LAST +1 ];
sound/core/pcm_dmaengine.c +25 -5
@@ -170,16 +170,20 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) }/** -* snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation +* snd_dmaengine_pcm_custom_trigger - customized PCM trigger implementation to +* work-around DMA limitations related to link lists. * @substream: PCM substream * @cmd: Trigger command +* @custom_pcm_prepare_and_submit: custom function to deal with DMA limitations * * Returns 0 on success, a negative error code otherwise. * -* This function can be used as the PCM trigger callback for dmaengine based PCM -* driver implementations. +* This function can be used as the PCM trigger callback for customized dmaengine +* based PCM driver implementations. */ -int snd_dmaengine_pcm_trigger (struct snd_pcm_substream *substream,int cmd) + +int snd_dmaengine_pcm_custom_trigger (struct snd_pcm_substream *substream,int cmd, +int (*custom_pcm_prepare_and_submit)(struct snd_pcm_substream *substream)) {struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream);struct snd_pcm_runtime *runtime = substream->runtime;
@@ -187,7 +191,7 @@ int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd)switch (cmd) {case SNDRV_PCM_TRIGGER_START : - ret =dmaengine_pcm_prepare_and_submit (substream); + ret =custom_pcm_prepare_and_submit (substream);if (ret)return ret;dma_async_issue_pending (prtd->dma_chan);
@@ -214,6 +218,22 @@ int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd)return 0 ; } +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_custom_trigger); + +/** +* snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation +* @substream: PCM substream +* @cmd: Trigger command +* +* Returns 0 on success, a negative error code otherwise. +* +* This function can be used as the PCM trigger callback for dmaengine based PCM +* driver implementations. +*/ +int snd_dmaengine_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +return snd_dmaengine_pcm_custom_trigger (substream, cmd, dmaengine_pcm_prepare_and_submit); +}EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_trigger);/**
sound/soc/soc-generic-dmaengine-pcm.c +7 -1
@@ -173,7 +173,13 @@ static int dmaengine_pcm_close(struct snd_soc_component *component,static int dmaengine_pcm_trigger (struct snd_soc_component *component,struct snd_pcm_substream *substream,int cmd) { -return snd_dmaengine_pcm_trigger (substream, cmd); +struct dmaengine_pcm *pcm =soc_component_to_pcm (component); + +if (pcm->config && pcm->config->custom_pcm_prepare_and_submit) +return snd_dmaengine_pcm_custom_trigger (substream, cmd, + pcm->config->custom_pcm_prepare_and_submit); +else +return snd_dmaengine_pcm_trigger (substream, cmd); } static struct dma_chan *dmaengine_pcm_compat_request_channel(
Signature · 1 line
2.17.1
PATCH 4/5 ASoC: dmaengine_pcm: expose functions to header file for custom functions
In reply to Michael Sit Wei HongMoving some functions to the header file to be used by custom prepare and submit function.
In the Intel KeemBay solution, there is a DMA limitation which requires a custom prepare and submit function to modify the number of blocks per linked link.
This patch exposes some of the functions used in the pcm_dmaengine.c to be used by the custom function.
--- include/sound/dmaengine_pcm.h | 15 +++++++++++++++ sound/core/pcm_dmaengine.c | 16 ++-------------- 2 files changed, 17 insertions(+), 14 deletions(-)
include/sound/dmaengine_pcm.h +15 -0
@@ -174,8 +174,23 @@ struct dmaengine_pcm {unsigned int flags; }; +struct dmaengine_pcm_runtime_data { +struct dma_chan *dma_chan; +dma_cookie_t cookie; + +unsigned int pos; +}; + +static inline struct dmaengine_pcm_runtime_data *substream_to_prtd ( +const struct snd_pcm_substream *substream) +{ +return substream->runtime->private_data; +} +static inline struct dmaengine_pcm *soc_component_to_pcm (struct snd_soc_component *p) { return container_of(p, struct dmaengine_pcm, component); } + +void dmaengine_pcm_dma_complete (void *arg);#endif
sound/core/pcm_dmaengine.c +2 -14
@@ -19,19 +19,6 @@#include <sound/dmaengine_pcm.h> -struct dmaengine_pcm_runtime_data { -struct dma_chan *dma_chan; -dma_cookie_t cookie; - -unsigned int pos; -}; - -static inline struct dmaengine_pcm_runtime_data *substream_to_prtd ( -const struct snd_pcm_substream *substream) -{ -return substream->runtime->private_data; -} -struct dma_chan *snd_dmaengine_pcm_get_chan (struct snd_pcm_substream *substream) {struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream);
@@ -128,7 +115,7 @@ void snd_dmaengine_pcm_set_config_from_dai_data( }EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_set_config_from_dai_data); -static void dmaengine_pcm_dma_complete (void *arg) +void dmaengine_pcm_dma_complete (void *arg) {struct snd_pcm_substream *substream = arg;struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream);
@@ -139,6 +126,7 @@ static void dmaengine_pcm_dma_complete(void *arg)snd_pcm_period_elapsed (substream); } +EXPORT_SYMBOL_GPL (dmaengine_pcm_dma_complete);static int dmaengine_pcm_prepare_and_submit (struct snd_pcm_substream *substream) {
Signature · 1 line
2.17.1
PATCH 5/5 ASoC: Intel: KMB: Enable DMA transfer mode
In reply to Michael Sit Wei HongEnable DMA transfer mode for Intel Keem Bay ASoC platform driver.
The driver will search the device tree for DMA resources at boot time to enable DMA transfer mode, and will proceed to use DMA transfer if the resource is available, otherwise the default PIO mode will be used.
Due to DMA Block transfer limitation, a customized function is introduced to check and handle the limitation. Instead of limiting the maximum period bytes to the minimum supported, which forces the period size to less than 10.6ms in the worst case, adjusting the DMA to use a longer linked list will allow more flexible period sizes which does not force applications to use ridiculously small period sizes.
--- sound/soc/intel/Kconfig | 2 + sound/soc/intel/keembay/kmb_platform.c | 202 +++++++++++++++++++++++-- sound/soc/intel/keembay/kmb_platform.h | 9 ++ 3 files changed, 198 insertions(+), 15 deletions(-)
sound/soc/intel/Kconfig +2 -0
@@ -200,6 +200,8 @@ config SND_SOC_INTEL_KEEMBAY tristate "Keembay Platforms" depends on ARM64 || COMPILE_TEST depends on COMMON_CLK + select SND_DMAENGINE_PCM + select SND_SOC_GENERIC_DMAENGINE_PCM help If you have a Intel Keembay platform then enable this option by saying Y or m.
sound/soc/intel/keembay/kmb_platform.c +187 -15
307 lines not on this page · raw message
sound/soc/intel/keembay/kmb_platform.h +9 -0
@@ -12,6 +12,7 @@#include <linux/bits.h> #include <linux/bitfield.h> #include <linux/types.h> +#include <sound/dmaengine_pcm.h> /* Register values with reference to KMB databook v1.1 */ /* common register for all channel */
@@ -103,7 +104,12 @@#define DW_I2S_MASTER BIT(3)#define I2S_RXDMA 0x01C0 +#define I2S_RRXDMA 0x01C4#define I2S_TXDMA 0x01C8 +#define I2S_RTXDMA 0x01CC +#define I2S_DMACR 0x0200 +#define I2S_DMAEN_RXBLOCK (1 << 16) +#define I2S_DMAEN_TXBLOCK (1 << 17)/* * struct i2s_clk_config_data - represent i2s clk configuration data
@@ -131,6 +137,9 @@ struct kmb_i2s_info {u32 xfer_resolution;u32 fifo_th;bool master; +/* data related to DMA transfers b/w i2s and DMAC */ +struct snd_dmaengine_dai_dma_data play_dma_data; +struct snd_dmaengine_dai_dma_data capture_dma_data;struct i2s_clk_config_data config;int (*i2s_clk_cfg)(struct i2s_clk_config_data *config);
Signature · 1 line
2.17.1