blob: e6c727b317fbd8fa5a1d33fef7133aa601eeddd7 [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
Takashi Iwai2c484df2005-06-30 18:54:04 +020017#include <sound/core.h>
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040018#include <sound/pxa2xx-lib.h>
Daniel Mackd65a1452013-08-12 10:42:39 +020019#include <sound/dmaengine_pcm.h>
Takashi Iwai2c484df2005-06-30 18:54:04 +020020
21#include "pxa2xx-pcm.h"
22
Takashi Iwaid18f8372005-11-17 15:10:38 +010023static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
Takashi Iwai2c484df2005-06-30 18:54:04 +020024{
Takashi Iwaid18f8372005-11-17 15:10:38 +010025 struct pxa2xx_pcm_client *client = substream->private_data;
Takashi Iwai2c484df2005-06-30 18:54:04 +020026
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040027 __pxa2xx_pcm_prepare(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020028
29 return client->prepare(substream);
30}
31
Takashi Iwaid18f8372005-11-17 15:10:38 +010032static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
Takashi Iwai2c484df2005-06-30 18:54:04 +020033{
Takashi Iwaid18f8372005-11-17 15:10:38 +010034 struct pxa2xx_pcm_client *client = substream->private_data;
35 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai2c484df2005-06-30 18:54:04 +020036 struct pxa2xx_runtime_data *rtd;
37 int ret;
38
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040039 ret = __pxa2xx_pcm_open(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020040 if (ret)
41 goto out;
42
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040043 rtd = runtime->private_data;
Takashi Iwai2c484df2005-06-30 18:54:04 +020044
45 rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
46 client->playback_params : client->capture_params;
Daniel Mackd65a1452013-08-12 10:42:39 +020047 ret = pxa_request_dma("dma", DMA_PRIO_LOW,
Takashi Iwai2c484df2005-06-30 18:54:04 +020048 pxa2xx_pcm_dma_irq, substream);
49 if (ret < 0)
50 goto err2;
51 rtd->dma_ch = ret;
52
Takashi Iwai2c484df2005-06-30 18:54:04 +020053 ret = client->startup(substream);
54 if (!ret)
55 goto out;
56
57 pxa_free_dma(rtd->dma_ch);
58 err2:
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040059 __pxa2xx_pcm_close(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020060 out:
61 return ret;
62}
63
Takashi Iwaid18f8372005-11-17 15:10:38 +010064static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
Takashi Iwai2c484df2005-06-30 18:54:04 +020065{
Takashi Iwaid18f8372005-11-17 15:10:38 +010066 struct pxa2xx_pcm_client *client = substream->private_data;
Takashi Iwai2c484df2005-06-30 18:54:04 +020067 struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
68
69 pxa_free_dma(rtd->dma_ch);
70 client->shutdown(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020071
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040072 return __pxa2xx_pcm_close(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020073}
74
Takashi Iwaid18f8372005-11-17 15:10:38 +010075static struct snd_pcm_ops pxa2xx_pcm_ops = {
Takashi Iwai2c484df2005-06-30 18:54:04 +020076 .open = pxa2xx_pcm_open,
77 .close = pxa2xx_pcm_close,
78 .ioctl = snd_pcm_lib_ioctl,
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040079 .hw_params = __pxa2xx_pcm_hw_params,
80 .hw_free = __pxa2xx_pcm_hw_free,
Takashi Iwai2c484df2005-06-30 18:54:04 +020081 .prepare = pxa2xx_pcm_prepare,
82 .trigger = pxa2xx_pcm_trigger,
83 .pointer = pxa2xx_pcm_pointer,
84 .mmap = pxa2xx_pcm_mmap,
85};
86
Takashi Iwaid18f8372005-11-17 15:10:38 +010087int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
88 struct snd_pcm **rpcm)
Takashi Iwai2c484df2005-06-30 18:54:04 +020089{
Takashi Iwaid18f8372005-11-17 15:10:38 +010090 struct snd_pcm *pcm;
Takashi Iwai2c484df2005-06-30 18:54:04 +020091 int play = client->playback_params ? 1 : 0;
92 int capt = client->capture_params ? 1 : 0;
93 int ret;
94
95 ret = snd_pcm_new(card, "PXA2xx-PCM", 0, play, capt, &pcm);
96 if (ret)
97 goto out;
98
99 pcm->private_data = client;
100 pcm->private_free = pxa2xx_pcm_free_dma_buffers;
101
Russell Kingc9bd5e62013-06-27 12:53:37 +0100102 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
103 if (ret)
104 goto out;
Takashi Iwai2c484df2005-06-30 18:54:04 +0200105
106 if (play) {
107 int stream = SNDRV_PCM_STREAM_PLAYBACK;
108 snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
109 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
110 if (ret)
111 goto out;
112 }
113 if (capt) {
114 int stream = SNDRV_PCM_STREAM_CAPTURE;
115 snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
116 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
117 if (ret)
118 goto out;
119 }
120
121 if (rpcm)
122 *rpcm = pcm;
123 ret = 0;
124
125 out:
126 return ret;
127}
128
129EXPORT_SYMBOL(pxa2xx_pcm_new);
130
131MODULE_AUTHOR("Nicolas Pitre");
132MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
133MODULE_LICENSE("GPL");