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