Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 1 | /* |
| 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 Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 13 | #include <linux/module.h> |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 14 | #include <linux/dmaengine.h> |
| 15 | |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 16 | #include <sound/core.h> |
Dmitry Baryshkov | a6d7731 | 2008-09-10 05:01:20 +0400 | [diff] [blame] | 17 | #include <sound/pxa2xx-lib.h> |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 18 | #include <sound/dmaengine_pcm.h> |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 19 | |
| 20 | #include "pxa2xx-pcm.h" |
| 21 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 22 | static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 23 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 24 | struct pxa2xx_pcm_client *client = substream->private_data; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 25 | |
Dmitry Baryshkov | a6d7731 | 2008-09-10 05:01:20 +0400 | [diff] [blame] | 26 | __pxa2xx_pcm_prepare(substream); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 27 | |
| 28 | return client->prepare(substream); |
| 29 | } |
| 30 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 31 | static int pxa2xx_pcm_open(struct snd_pcm_substream *substream) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 32 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 33 | struct pxa2xx_pcm_client *client = substream->private_data; |
| 34 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 35 | struct pxa2xx_runtime_data *rtd; |
| 36 | int ret; |
| 37 | |
Dmitry Baryshkov | a6d7731 | 2008-09-10 05:01:20 +0400 | [diff] [blame] | 38 | ret = __pxa2xx_pcm_open(substream); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 39 | if (ret) |
| 40 | goto out; |
| 41 | |
Dmitry Baryshkov | a6d7731 | 2008-09-10 05:01:20 +0400 | [diff] [blame] | 42 | rtd = runtime->private_data; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 43 | |
| 44 | rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
| 45 | client->playback_params : client->capture_params; |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 46 | ret = pxa_request_dma("dma", DMA_PRIO_LOW, |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 47 | pxa2xx_pcm_dma_irq, substream); |
| 48 | if (ret < 0) |
| 49 | goto err2; |
| 50 | rtd->dma_ch = ret; |
| 51 | |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 52 | ret = client->startup(substream); |
| 53 | if (!ret) |
| 54 | goto out; |
| 55 | |
| 56 | pxa_free_dma(rtd->dma_ch); |
| 57 | err2: |
Dmitry Baryshkov | a6d7731 | 2008-09-10 05:01:20 +0400 | [diff] [blame] | 58 | __pxa2xx_pcm_close(substream); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 59 | out: |
| 60 | return ret; |
| 61 | } |
| 62 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 63 | static int pxa2xx_pcm_close(struct snd_pcm_substream *substream) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 64 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 65 | struct pxa2xx_pcm_client *client = substream->private_data; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 66 | struct pxa2xx_runtime_data *rtd = substream->runtime->private_data; |
| 67 | |
| 68 | pxa_free_dma(rtd->dma_ch); |
| 69 | client->shutdown(substream); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 70 | |
Dmitry Baryshkov | a6d7731 | 2008-09-10 05:01:20 +0400 | [diff] [blame] | 71 | return __pxa2xx_pcm_close(substream); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 74 | static struct snd_pcm_ops pxa2xx_pcm_ops = { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 75 | .open = pxa2xx_pcm_open, |
| 76 | .close = pxa2xx_pcm_close, |
| 77 | .ioctl = snd_pcm_lib_ioctl, |
Dmitry Baryshkov | a6d7731 | 2008-09-10 05:01:20 +0400 | [diff] [blame] | 78 | .hw_params = __pxa2xx_pcm_hw_params, |
| 79 | .hw_free = __pxa2xx_pcm_hw_free, |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 80 | .prepare = pxa2xx_pcm_prepare, |
| 81 | .trigger = pxa2xx_pcm_trigger, |
| 82 | .pointer = pxa2xx_pcm_pointer, |
| 83 | .mmap = pxa2xx_pcm_mmap, |
| 84 | }; |
| 85 | |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 86 | static u64 pxa2xx_pcm_dmamask = 0xffffffff; |
| 87 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 88 | int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client, |
| 89 | struct snd_pcm **rpcm) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 90 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 91 | struct snd_pcm *pcm; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 92 | int play = client->playback_params ? 1 : 0; |
| 93 | int capt = client->capture_params ? 1 : 0; |
| 94 | int ret; |
| 95 | |
| 96 | ret = snd_pcm_new(card, "PXA2xx-PCM", 0, play, capt, &pcm); |
| 97 | if (ret) |
| 98 | goto out; |
| 99 | |
| 100 | pcm->private_data = client; |
| 101 | pcm->private_free = pxa2xx_pcm_free_dma_buffers; |
| 102 | |
| 103 | if (!card->dev->dma_mask) |
| 104 | card->dev->dma_mask = &pxa2xx_pcm_dmamask; |
| 105 | if (!card->dev->coherent_dma_mask) |
| 106 | card->dev->coherent_dma_mask = 0xffffffff; |
| 107 | |
| 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 | |
| 131 | EXPORT_SYMBOL(pxa2xx_pcm_new); |
| 132 | |
| 133 | MODULE_AUTHOR("Nicolas Pitre"); |
| 134 | MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module"); |
| 135 | MODULE_LICENSE("GPL"); |