2019-06-04 01:11:33 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-05-24 06:26:32 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) ST-Ericsson SA 2012
|
|
|
|
*
|
|
|
|
* Author: Ola Lilja <ola.o.lilja@stericsson.com>,
|
|
|
|
* Roger Nilsson <roger.xr.nilsson@stericsson.com>
|
|
|
|
* for ST-Ericsson.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/page.h>
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/dmaengine_pcm.h>
|
|
|
|
|
|
|
|
#include "ux500_msp_i2s.h"
|
|
|
|
#include "ux500_pcm.h"
|
|
|
|
|
2013-04-03 02:02:55 -07:00
|
|
|
#define UX500_PLATFORM_PERIODS_BYTES_MIN 128
|
|
|
|
#define UX500_PLATFORM_PERIODS_BYTES_MAX (64 * PAGE_SIZE)
|
|
|
|
#define UX500_PLATFORM_PERIODS_MIN 2
|
|
|
|
#define UX500_PLATFORM_PERIODS_MAX 48
|
|
|
|
#define UX500_PLATFORM_BUFFER_BYTES_MAX (2048 * PAGE_SIZE)
|
2012-05-24 06:26:32 -07:00
|
|
|
|
2013-06-12 00:57:59 -07:00
|
|
|
static int ux500_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct dma_slave_config *slave_config)
|
|
|
|
{
|
2023-09-11 16:49:24 -07:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2013-12-19 08:55:03 -07:00
|
|
|
struct snd_dmaengine_dai_dma_data *snd_dma_params;
|
|
|
|
dma_addr_t dma_addr;
|
2013-06-12 00:57:59 -07:00
|
|
|
int ret;
|
|
|
|
|
2023-09-11 16:49:24 -07:00
|
|
|
snd_dma_params = snd_soc_dai_get_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream);
|
2023-01-18 09:10:47 -07:00
|
|
|
dma_addr = snd_dma_params->addr;
|
2013-06-12 00:57:59 -07:00
|
|
|
|
|
|
|
ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
slave_config->dst_maxburst = 4;
|
|
|
|
slave_config->src_maxburst = 4;
|
2013-12-19 08:55:02 -07:00
|
|
|
|
|
|
|
slave_config->src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
|
|
|
|
slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
|
2013-06-12 00:57:59 -07:00
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
2013-12-19 08:55:03 -07:00
|
|
|
slave_config->dst_addr = dma_addr;
|
2013-06-12 00:57:59 -07:00
|
|
|
else
|
2013-12-19 08:55:03 -07:00
|
|
|
slave_config->src_addr = dma_addr;
|
2013-06-12 00:57:59 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-19 08:55:07 -07:00
|
|
|
static const struct snd_dmaengine_pcm_config ux500_dmaengine_of_pcm_config = {
|
|
|
|
.prepare_slave_config = ux500_pcm_prepare_slave_config,
|
|
|
|
};
|
|
|
|
|
2012-12-07 07:26:35 -07:00
|
|
|
int ux500_pcm_register_platform(struct platform_device *pdev)
|
2012-05-24 06:26:32 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2023-01-18 09:10:47 -07:00
|
|
|
ret = snd_dmaengine_pcm_register(&pdev->dev,
|
2023-01-18 09:10:48 -07:00
|
|
|
&ux500_dmaengine_of_pcm_config, 0);
|
2012-05-24 06:26:32 -07:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"%s: ERROR: Failed to register platform '%s' (%d)!\n",
|
|
|
|
__func__, pdev->name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-23 06:05:41 -07:00
|
|
|
EXPORT_SYMBOL_GPL(ux500_pcm_register_platform);
|
2012-05-24 06:26:32 -07:00
|
|
|
|
2012-12-07 07:26:35 -07:00
|
|
|
int ux500_pcm_unregister_platform(struct platform_device *pdev)
|
2012-05-24 06:26:32 -07:00
|
|
|
{
|
2013-04-15 10:20:04 -07:00
|
|
|
snd_dmaengine_pcm_unregister(&pdev->dev);
|
2012-05-24 06:26:32 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-23 06:05:41 -07:00
|
|
|
EXPORT_SYMBOL_GPL(ux500_pcm_unregister_platform);
|
2018-01-10 09:34:45 -07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Ola Lilja");
|
|
|
|
MODULE_AUTHOR("Roger Nilsson");
|
|
|
|
MODULE_DESCRIPTION("ASoC UX500 driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|