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