blob: 1c6f4b436de31868af917a1767397c7daf1c7a84 [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;
Takashi Iwai2c484df2005-06-30 18:54:04 +020049
Takashi Iwai2c484df2005-06-30 18:54:04 +020050 ret = client->startup(substream);
51 if (!ret)
Daniel Mack58ceb572015-09-30 22:51:52 +020052 goto err2;
Takashi Iwai2c484df2005-06-30 18:54:04 +020053
Daniel Mack58ceb572015-09-30 22:51:52 +020054 return 0;
55
Takashi Iwai2c484df2005-06-30 18:54:04 +020056 err2:
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040057 __pxa2xx_pcm_close(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020058 out:
59 return ret;
60}
61
Takashi Iwaid18f8372005-11-17 15:10:38 +010062static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
Takashi Iwai2c484df2005-06-30 18:54:04 +020063{
Takashi Iwaid18f8372005-11-17 15:10:38 +010064 struct pxa2xx_pcm_client *client = substream->private_data;
Takashi Iwai2c484df2005-06-30 18:54:04 +020065
Takashi Iwai2c484df2005-06-30 18:54:04 +020066 client->shutdown(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020067
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040068 return __pxa2xx_pcm_close(substream);
Takashi Iwai2c484df2005-06-30 18:54:04 +020069}
70
Arvind Yadav28f05482017-08-18 13:15:10 +053071static const struct snd_pcm_ops pxa2xx_pcm_ops = {
Takashi Iwai2c484df2005-06-30 18:54:04 +020072 .open = pxa2xx_pcm_open,
73 .close = pxa2xx_pcm_close,
74 .ioctl = snd_pcm_lib_ioctl,
Dmitry Baryshkova6d77312008-09-10 05:01:20 +040075 .hw_params = __pxa2xx_pcm_hw_params,
76 .hw_free = __pxa2xx_pcm_hw_free,
Takashi Iwai2c484df2005-06-30 18:54:04 +020077 .prepare = pxa2xx_pcm_prepare,
78 .trigger = pxa2xx_pcm_trigger,
79 .pointer = pxa2xx_pcm_pointer,
80 .mmap = pxa2xx_pcm_mmap,
81};
82
Takashi Iwaid18f8372005-11-17 15:10:38 +010083int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
84 struct snd_pcm **rpcm)
Takashi Iwai2c484df2005-06-30 18:54:04 +020085{
Takashi Iwaid18f8372005-11-17 15:10:38 +010086 struct snd_pcm *pcm;
Takashi Iwai2c484df2005-06-30 18:54:04 +020087 int play = client->playback_params ? 1 : 0;
88 int capt = client->capture_params ? 1 : 0;
89 int ret;
90
91 ret = snd_pcm_new(card, "PXA2xx-PCM", 0, play, capt, &pcm);
92 if (ret)
93 goto out;
94
95 pcm->private_data = client;
96 pcm->private_free = pxa2xx_pcm_free_dma_buffers;
97
Russell Kingc9bd5e62013-06-27 12:53:37 +010098 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
99 if (ret)
100 goto out;
Takashi Iwai2c484df2005-06-30 18:54:04 +0200101
102 if (play) {
103 int stream = SNDRV_PCM_STREAM_PLAYBACK;
104 snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
105 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
106 if (ret)
107 goto out;
108 }
109 if (capt) {
110 int stream = SNDRV_PCM_STREAM_CAPTURE;
111 snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
112 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
113 if (ret)
114 goto out;
115 }
116
117 if (rpcm)
118 *rpcm = pcm;
119 ret = 0;
120
121 out:
122 return ret;
123}
124
125EXPORT_SYMBOL(pxa2xx_pcm_new);
126
127MODULE_AUTHOR("Nicolas Pitre");
128MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
129MODULE_LICENSE("GPL");