Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v3.15
  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
 13#include <linux/module.h>
 14#include <linux/dma-mapping.h>
 15#include <linux/dmaengine.h>
 16
 
 
 17#include <sound/core.h>
 18#include <sound/pxa2xx-lib.h>
 19#include <sound/dmaengine_pcm.h>
 20
 21#include "pxa2xx-pcm.h"
 22
 23static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
 24{
 25	struct pxa2xx_pcm_client *client = substream->private_data;
 26
 27	__pxa2xx_pcm_prepare(substream);
 28
 29	return client->prepare(substream);
 30}
 31
 32static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
 33{
 34	struct pxa2xx_pcm_client *client = substream->private_data;
 35	struct snd_pcm_runtime *runtime = substream->runtime;
 36	struct pxa2xx_runtime_data *rtd;
 37	int ret;
 38
 39	ret = __pxa2xx_pcm_open(substream);
 40	if (ret)
 41		goto out;
 42
 43	rtd = runtime->private_data;
 44
 45	rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
 46		      client->playback_params : client->capture_params;
 47	ret = pxa_request_dma("dma", DMA_PRIO_LOW,
 48			      pxa2xx_pcm_dma_irq, substream);
 49	if (ret < 0)
 50		goto err2;
 51	rtd->dma_ch = ret;
 52
 53	ret = client->startup(substream);
 54	if (!ret)
 55		goto out;
 
 
 56
 57	pxa_free_dma(rtd->dma_ch);
 58 err2:
 59	__pxa2xx_pcm_close(substream);
 60 out:
 61	return ret;
 62}
 63
 64static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
 65{
 66	struct pxa2xx_pcm_client *client = substream->private_data;
 67	struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
 68
 69	pxa_free_dma(rtd->dma_ch);
 70	client->shutdown(substream);
 71
 72	return __pxa2xx_pcm_close(substream);
 73}
 74
 75static struct snd_pcm_ops pxa2xx_pcm_ops = {
 76	.open		= pxa2xx_pcm_open,
 77	.close		= pxa2xx_pcm_close,
 78	.ioctl		= snd_pcm_lib_ioctl,
 79	.hw_params	= __pxa2xx_pcm_hw_params,
 80	.hw_free	= __pxa2xx_pcm_hw_free,
 81	.prepare	= pxa2xx_pcm_prepare,
 82	.trigger	= pxa2xx_pcm_trigger,
 83	.pointer	= pxa2xx_pcm_pointer,
 84	.mmap		= pxa2xx_pcm_mmap,
 85};
 86
 87int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
 88		   struct snd_pcm **rpcm)
 89{
 90	struct snd_pcm *pcm;
 91	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
102	ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
103	if (ret)
104		goto out;
105
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");
v4.6
  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
 13#include <linux/module.h>
 14#include <linux/dma-mapping.h>
 15#include <linux/dmaengine.h>
 16
 17#include <mach/dma.h>
 18
 19#include <sound/core.h>
 20#include <sound/pxa2xx-lib.h>
 21#include <sound/dmaengine_pcm.h>
 22
 23#include "pxa2xx-pcm.h"
 24
 25static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
 26{
 27	struct pxa2xx_pcm_client *client = substream->private_data;
 28
 29	__pxa2xx_pcm_prepare(substream);
 30
 31	return client->prepare(substream);
 32}
 33
 34static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
 35{
 36	struct pxa2xx_pcm_client *client = substream->private_data;
 37	struct snd_pcm_runtime *runtime = substream->runtime;
 38	struct pxa2xx_runtime_data *rtd;
 39	int ret;
 40
 41	ret = __pxa2xx_pcm_open(substream);
 42	if (ret)
 43		goto out;
 44
 45	rtd = runtime->private_data;
 46
 47	rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
 48		      client->playback_params : client->capture_params;
 
 
 
 
 
 49
 50	ret = client->startup(substream);
 51	if (!ret)
 52		goto err2;
 53
 54	return 0;
 55
 
 56 err2:
 57	__pxa2xx_pcm_close(substream);
 58 out:
 59	return ret;
 60}
 61
 62static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
 63{
 64	struct pxa2xx_pcm_client *client = substream->private_data;
 
 65
 
 66	client->shutdown(substream);
 67
 68	return __pxa2xx_pcm_close(substream);
 69}
 70
 71static struct snd_pcm_ops pxa2xx_pcm_ops = {
 72	.open		= pxa2xx_pcm_open,
 73	.close		= pxa2xx_pcm_close,
 74	.ioctl		= snd_pcm_lib_ioctl,
 75	.hw_params	= __pxa2xx_pcm_hw_params,
 76	.hw_free	= __pxa2xx_pcm_hw_free,
 77	.prepare	= pxa2xx_pcm_prepare,
 78	.trigger	= pxa2xx_pcm_trigger,
 79	.pointer	= pxa2xx_pcm_pointer,
 80	.mmap		= pxa2xx_pcm_mmap,
 81};
 82
 83int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
 84		   struct snd_pcm **rpcm)
 85{
 86	struct snd_pcm *pcm;
 87	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
 98	ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
 99	if (ret)
100		goto out;
101
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");