blob: 83be8e3f095ef46fb58d7567c84c5cb1b0db1b73 [file] [log] [blame]
Takashi Iwai2c484df2005-06-30 18:54:04 +02001/*
2 * linux/sound/arm/pxa2xx-pcm.c -- ALSA PCM interface for the Intel PXA2xx chip
3 *
4 * Author: Nicolas Pitre
5 * Created: Nov 30, 2004
6 * Copyright: (C) 2004 MontaVista Software, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
Paul Gortmakerda155d52011-07-15 12:38:28 -040013#include <linux/module.h>
Russell Kingc9bd5e62013-06-27 12:53:37 +010014#include <linux/dma-mapping.h>
Daniel Mackd65a1452013-08-12 10:42:39 +020015#include <linux/dmaengine.h>
16
Arnd Bergmannb4528142014-05-04 11:25:21 +080017#include <mach/dma.h>
18
Takashi Iwai2c484df2005-06-30 18:54:04 +020019#include <sound/core.h>
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040020#include <sound/pxa2xx-lib.h>
Daniel Mackd65a1452013-08-12 10:42:39 +020021#include <sound/dmaengine_pcm.h>
Takashi Iwai2c484df2005-06-30 18:54:04 +020022
23#include "pxa2xx-pcm.h"
24
Takashi Iwaid18f8372005-11-17 15:10:38 +010025static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
Takashi Iwai2c484df2005-06-30 18:54:04 +020026{
Takashi Iwaid18f8372005-11-17 15:10:38 +010027 struct pxa2xx_pcm_client *client = substream->private_data;
Takashi Iwai2c484df2005-06-30 18:54:04 +020028
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040029 __pxa2xx_pcm_prepare(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020030
31 return client->prepare(substream);
32}
33
Takashi Iwaid18f8372005-11-17 15:10:38 +010034static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
Takashi Iwai2c484df2005-06-30 18:54:04 +020035{
Takashi Iwaid18f8372005-11-17 15:10:38 +010036 struct pxa2xx_pcm_client *client = substream->private_data;
37 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai2c484df2005-06-30 18:54:04 +020038 struct pxa2xx_runtime_data *rtd;
39 int ret;
40
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040041 ret = __pxa2xx_pcm_open(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020042 if (ret)
43 goto out;
44
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040045 rtd = runtime->private_data;
Takashi Iwai2c484df2005-06-30 18:54:04 +020046
47 rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
48 client->playback_params : client->capture_params;
Daniel Mackd65a1452013-08-12 10:42:39 +020049 ret = pxa_request_dma("dma", DMA_PRIO_LOW,
Takashi Iwai2c484df2005-06-30 18:54:04 +020050 pxa2xx_pcm_dma_irq, substream);
51 if (ret < 0)
52 goto err2;
53 rtd->dma_ch = ret;
54
Takashi Iwai2c484df2005-06-30 18:54:04 +020055 ret = client->startup(substream);
56 if (!ret)
57 goto out;
58
59 pxa_free_dma(rtd->dma_ch);
60 err2:
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040061 __pxa2xx_pcm_close(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020062 out:
63 return ret;
64}
65
Takashi Iwaid18f8372005-11-17 15:10:38 +010066static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
Takashi Iwai2c484df2005-06-30 18:54:04 +020067{
Takashi Iwaid18f8372005-11-17 15:10:38 +010068 struct pxa2xx_pcm_client *client = substream->private_data;
Takashi Iwai2c484df2005-06-30 18:54:04 +020069 struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
70
71 pxa_free_dma(rtd->dma_ch);
72 client->shutdown(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020073
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040074 return __pxa2xx_pcm_close(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020075}
76
Takashi Iwaid18f8372005-11-17 15:10:38 +010077static struct snd_pcm_ops pxa2xx_pcm_ops = {
Takashi Iwai2c484df2005-06-30 18:54:04 +020078 .open = pxa2xx_pcm_open,
79 .close = pxa2xx_pcm_close,
80 .ioctl = snd_pcm_lib_ioctl,
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040081 .hw_params = __pxa2xx_pcm_hw_params,
82 .hw_free = __pxa2xx_pcm_hw_free,
Takashi Iwai2c484df2005-06-30 18:54:04 +020083 .prepare = pxa2xx_pcm_prepare,
84 .trigger = pxa2xx_pcm_trigger,
85 .pointer = pxa2xx_pcm_pointer,
86 .mmap = pxa2xx_pcm_mmap,
87};
88
Takashi Iwaid18f8372005-11-17 15:10:38 +010089int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
90 struct snd_pcm **rpcm)
Takashi Iwai2c484df2005-06-30 18:54:04 +020091{
Takashi Iwaid18f8372005-11-17 15:10:38 +010092 struct snd_pcm *pcm;
Takashi Iwai2c484df2005-06-30 18:54:04 +020093 int play = client->playback_params ? 1 : 0;
94 int capt = client->capture_params ? 1 : 0;
95 int ret;
96
97 ret = snd_pcm_new(card, "PXA2xx-PCM", 0, play, capt, &pcm);
98 if (ret)
99 goto out;
100
101 pcm->private_data = client;
102 pcm->private_free = pxa2xx_pcm_free_dma_buffers;
103
Russell Kingc9bd5e62013-06-27 12:53:37 +0100104 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
105 if (ret)
106 goto out;
Takashi Iwai2c484df2005-06-30 18:54:04 +0200107
108 if (play) {
109 int stream = SNDRV_PCM_STREAM_PLAYBACK;
110 snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
111 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
112 if (ret)
113 goto out;
114 }
115 if (capt) {
116 int stream = SNDRV_PCM_STREAM_CAPTURE;
117 snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
118 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
119 if (ret)
120 goto out;
121 }
122
123 if (rpcm)
124 *rpcm = pcm;
125 ret = 0;
126
127 out:
128 return ret;
129}
130
131EXPORT_SYMBOL(pxa2xx_pcm_new);
132
133MODULE_AUTHOR("Nicolas Pitre");
134MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
135MODULE_LICENSE("GPL");