Merge remote-tracking branch 'asoc/topic/spear' into asoc-next

This commit is contained in:
Mark Brown 2013-06-17 17:20:28 +01:00
commit 5f5eb4efe5
7 changed files with 53 additions and 194 deletions

View File

@ -51,6 +51,7 @@ source "sound/soc/pxa/Kconfig"
source "sound/soc/samsung/Kconfig"
source "sound/soc/s6000/Kconfig"
source "sound/soc/sh/Kconfig"
source "sound/soc/spear/Kconfig"
source "sound/soc/tegra/Kconfig"
source "sound/soc/txx9/Kconfig"
source "sound/soc/ux500/Kconfig"

View File

@ -29,6 +29,7 @@ obj-$(CONFIG_SND_SOC) += pxa/
obj-$(CONFIG_SND_SOC) += samsung/
obj-$(CONFIG_SND_SOC) += s6000/
obj-$(CONFIG_SND_SOC) += sh/
obj-$(CONFIG_SND_SOC) += spear/
obj-$(CONFIG_SND_SOC) += tegra/
obj-$(CONFIG_SND_SOC) += txx9/
obj-$(CONFIG_SND_SOC) += ux500/

9
sound/soc/spear/Kconfig Normal file
View File

@ -0,0 +1,9 @@
config SND_SPEAR_SOC
tristate
select SND_SOC_DMAENGINE_PCM
config SND_SPEAR_SPDIF_OUT
tristate
config SND_SPEAR_SPDIF_IN
tristate

8
sound/soc/spear/Makefile Normal file
View File

@ -0,0 +1,8 @@
# SPEAR Platform Support
snd-soc-spear-pcm-objs := spear_pcm.o
snd-soc-spear-spdif-in-objs := spdif_in.o
snd-soc-spear-spdif-out-objs := spdif_out.o
obj-$(CONFIG_SND_SPEAR_SOC) += snd-soc-spear-pcm.o
obj-$(CONFIG_SND_SPEAR_SPDIF_IN) += snd-soc-spear-spdif-in.o
obj-$(CONFIG_SND_SPEAR_SPDIF_OUT) += snd-soc-spear-spdif-out.o

View File

@ -49,15 +49,12 @@ static void spdif_in_configure(struct spdif_in_dev *host)
writel(0xF, host->io_base + SPDIF_IN_IRQ_MASK);
}
static int spdif_in_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai)
static int spdif_in_dai_probe(struct snd_soc_dai *dai)
{
struct spdif_in_dev *host = snd_soc_dai_get_drvdata(cpu_dai);
struct spdif_in_dev *host = snd_soc_dai_get_drvdata(dai);
if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
return -EINVAL;
dai->capture_dma_data = &host->dma_params;
snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)&host->dma_params);
return 0;
}
@ -70,7 +67,6 @@ static void spdif_in_shutdown(struct snd_pcm_substream *substream,
return;
writel(0x0, host->io_base + SPDIF_IN_IRQ_MASK);
snd_soc_dai_set_dma_data(dai, substream, NULL);
}
static void spdif_in_format(struct spdif_in_dev *host, u32 format)
@ -151,13 +147,13 @@ static int spdif_in_trigger(struct snd_pcm_substream *substream, int cmd,
}
static struct snd_soc_dai_ops spdif_in_dai_ops = {
.startup = spdif_in_startup,
.shutdown = spdif_in_shutdown,
.trigger = spdif_in_trigger,
.hw_params = spdif_in_hw_params,
};
struct snd_soc_dai_driver spdif_in_dai = {
static struct snd_soc_dai_driver spdif_in_dai = {
.probe = spdif_in_dai_probe,
.capture = {
.channels_min = 2,
.channels_max = 2,
@ -235,7 +231,7 @@ static int spdif_in_probe(struct platform_device *pdev)
if (host->irq < 0)
return -EINVAL;
host->clk = clk_get(&pdev->dev, NULL);
host->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(host->clk))
return PTR_ERR(host->clk);
@ -257,34 +253,21 @@ static int spdif_in_probe(struct platform_device *pdev)
ret = devm_request_irq(&pdev->dev, host->irq, spdif_in_irq, 0,
"spdif-in", host);
if (ret) {
clk_put(host->clk);
dev_warn(&pdev->dev, "request_irq failed\n");
return ret;
}
ret = snd_soc_register_component(&pdev->dev, &spdif_in_component,
return snd_soc_register_component(&pdev->dev, &spdif_in_component,
&spdif_in_dai, 1);
if (ret != 0) {
clk_put(host->clk);
return ret;
}
return 0;
}
static int spdif_in_remove(struct platform_device *pdev)
{
struct spdif_in_dev *host = dev_get_drvdata(&pdev->dev);
snd_soc_unregister_component(&pdev->dev);
dev_set_drvdata(&pdev->dev, NULL);
clk_put(host->clk);
return 0;
}
static struct platform_driver spdif_in_driver = {
.probe = spdif_in_probe,
.remove = spdif_in_remove,

View File

@ -62,8 +62,6 @@ static int spdif_out_startup(struct snd_pcm_substream *substream,
if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
return -EINVAL;
snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)&host->dma_params);
ret = clk_enable(host->clk);
if (ret)
return ret;
@ -84,7 +82,6 @@ static void spdif_out_shutdown(struct snd_pcm_substream *substream,
clk_disable(host->clk);
host->running = false;
snd_soc_dai_set_dma_data(dai, substream, NULL);
}
static void spdif_out_clock(struct spdif_out_dev *host, u32 core_freq,
@ -243,8 +240,12 @@ static const struct snd_kcontrol_new spdif_out_controls[] = {
spdif_mute_get, spdif_mute_put),
};
int spdif_soc_dai_probe(struct snd_soc_dai *dai)
static int spdif_soc_dai_probe(struct snd_soc_dai *dai)
{
struct spdif_out_dev *host = snd_soc_dai_get_drvdata(dai);
dai->playback_dma_data = &host->dma_params;
return snd_soc_add_dai_controls(dai, spdif_out_controls,
ARRAY_SIZE(spdif_out_controls));
}
@ -281,30 +282,18 @@ static int spdif_out_probe(struct platform_device *pdev)
struct resource *res;
int ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -EINVAL;
if (!devm_request_mem_region(&pdev->dev, res->start,
resource_size(res), pdev->name)) {
dev_warn(&pdev->dev, "Failed to get memory resourse\n");
return -ENOENT;
}
host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
if (!host) {
dev_warn(&pdev->dev, "kzalloc fail\n");
return -ENOMEM;
}
host->io_base = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
if (!host->io_base) {
dev_warn(&pdev->dev, "ioremap failed\n");
return -ENOMEM;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
host->io_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(host->io_base))
return PTR_ERR(host->io_base);
host->clk = clk_get(&pdev->dev, NULL);
host->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(host->clk))
return PTR_ERR(host->clk);
@ -320,22 +309,12 @@ static int spdif_out_probe(struct platform_device *pdev)
ret = snd_soc_register_component(&pdev->dev, &spdif_out_component,
&spdif_out_dai, 1);
if (ret != 0) {
clk_put(host->clk);
return ret;
}
return 0;
}
static int spdif_out_remove(struct platform_device *pdev)
{
struct spdif_out_dev *host = dev_get_drvdata(&pdev->dev);
snd_soc_unregister_component(&pdev->dev);
dev_set_drvdata(&pdev->dev, NULL);
clk_put(host->clk);
return 0;
}

View File

@ -13,19 +13,13 @@
#include <linux/module.h>
#include <linux/dmaengine.h>
#include <linux/dma-mapping.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/scatterlist.h>
#include <linux/slab.h>
#include <sound/core.h>
#include <sound/dmaengine_pcm.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/spear_dma.h>
static struct snd_pcm_hardware spear_pcm_hardware = {
static const struct snd_pcm_hardware spear_pcm_hardware = {
.info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
@ -37,149 +31,33 @@ static struct snd_pcm_hardware spear_pcm_hardware = {
.fifo_size = 0, /* fifo size in bytes */
};
static int spear_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
static struct dma_chan *spear_pcm_request_chan(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_substream *substream)
{
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
struct spear_dma_data *dma_data;
return 0;
dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
return snd_dmaengine_pcm_request_channel(dma_data->filter, dma_data);
}
static int spear_pcm_hw_free(struct snd_pcm_substream *substream)
{
snd_pcm_set_runtime_buffer(substream, NULL);
return 0;
}
static int spear_pcm_open(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct spear_dma_data *dma_data = (struct spear_dma_data *)
snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
int ret;
ret = snd_soc_set_runtime_hwparams(substream, &spear_pcm_hardware);
if (ret)
return ret;
return snd_dmaengine_pcm_open_request_chan(substream, dma_data->filter,
dma_data);
}
static int spear_pcm_mmap(struct snd_pcm_substream *substream,
struct vm_area_struct *vma)
{
struct snd_pcm_runtime *runtime = substream->runtime;
return dma_mmap_writecombine(substream->pcm->card->dev, vma,
runtime->dma_area, runtime->dma_addr,
runtime->dma_bytes);
}
static struct snd_pcm_ops spear_pcm_ops = {
.open = spear_pcm_open,
.close = snd_dmaengine_pcm_close_release_chan,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = spear_pcm_hw_params,
.hw_free = spear_pcm_hw_free,
.trigger = snd_dmaengine_pcm_trigger,
.pointer = snd_dmaengine_pcm_pointer,
.mmap = spear_pcm_mmap,
};
static int
spear_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream,
size_t size)
{
struct snd_pcm_substream *substream = pcm->streams[stream].substream;
struct snd_dma_buffer *buf = &substream->dma_buffer;
buf->dev.type = SNDRV_DMA_TYPE_DEV;
buf->dev.dev = pcm->card->dev;
buf->private_data = NULL;
buf->area = dma_alloc_writecombine(pcm->card->dev, size,
&buf->addr, GFP_KERNEL);
if (!buf->area)
return -ENOMEM;
dev_info(buf->dev.dev,
" preallocate_dma_buffer: area=%p, addr=%p, size=%d\n",
(void *)buf->area, (void *)buf->addr, size);
buf->bytes = size;
return 0;
}
static void spear_pcm_free(struct snd_pcm *pcm)
{
struct snd_pcm_substream *substream;
struct snd_dma_buffer *buf;
int stream;
for (stream = 0; stream < 2; stream++) {
substream = pcm->streams[stream].substream;
if (!substream)
continue;
buf = &substream->dma_buffer;
if (!buf || !buf->area)
continue;
dma_free_writecombine(pcm->card->dev, buf->bytes,
buf->area, buf->addr);
buf->area = NULL;
}
}
static u64 spear_pcm_dmamask = DMA_BIT_MASK(32);
static int spear_pcm_new(struct snd_soc_pcm_runtime *rtd)
{
struct snd_card *card = rtd->card->snd_card;
int ret;
if (!card->dev->dma_mask)
card->dev->dma_mask = &spear_pcm_dmamask;
if (!card->dev->coherent_dma_mask)
card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
if (rtd->cpu_dai->driver->playback.channels_min) {
ret = spear_pcm_preallocate_dma_buffer(rtd->pcm,
SNDRV_PCM_STREAM_PLAYBACK,
spear_pcm_hardware.buffer_bytes_max);
if (ret)
return ret;
}
if (rtd->cpu_dai->driver->capture.channels_min) {
ret = spear_pcm_preallocate_dma_buffer(rtd->pcm,
SNDRV_PCM_STREAM_CAPTURE,
spear_pcm_hardware.buffer_bytes_max);
if (ret)
return ret;
}
return 0;
}
static struct snd_soc_platform_driver spear_soc_platform = {
.ops = &spear_pcm_ops,
.pcm_new = spear_pcm_new,
.pcm_free = spear_pcm_free,
static const struct snd_dmaengine_pcm_config spear_dmaengine_pcm_config = {
.pcm_hardware = &spear_pcm_hardware,
.compat_request_channel = spear_pcm_request_chan,
.prealloc_buffer_size = 16 * 1024,
};
static int spear_soc_platform_probe(struct platform_device *pdev)
{
return snd_soc_register_platform(&pdev->dev, &spear_soc_platform);
return snd_dmaengine_pcm_register(&pdev->dev,
&spear_dmaengine_pcm_config,
SND_DMAENGINE_PCM_FLAG_NO_DT |
SND_DMAENGINE_PCM_FLAG_COMPAT);
}
static int spear_soc_platform_remove(struct platform_device *pdev)
{
snd_soc_unregister_platform(&pdev->dev);
snd_dmaengine_pcm_unregister(&pdev->dev);
return 0;
}