xref: /OK3568_Linux_fs/kernel/sound/soc/fsl/imx-pcm-fiq.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0+
2*4882a593Smuzhiyun // imx-pcm-fiq.c  --  ALSA Soc Audio Layer
3*4882a593Smuzhiyun //
4*4882a593Smuzhiyun // Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
5*4882a593Smuzhiyun //
6*4882a593Smuzhiyun // This code is based on code copyrighted by Freescale,
7*4882a593Smuzhiyun // Liam Girdwood, Javier Martin and probably others.
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/clk.h>
10*4882a593Smuzhiyun #include <linux/delay.h>
11*4882a593Smuzhiyun #include <linux/device.h>
12*4882a593Smuzhiyun #include <linux/dma-mapping.h>
13*4882a593Smuzhiyun #include <linux/init.h>
14*4882a593Smuzhiyun #include <linux/interrupt.h>
15*4882a593Smuzhiyun #include <linux/module.h>
16*4882a593Smuzhiyun #include <linux/platform_device.h>
17*4882a593Smuzhiyun #include <linux/slab.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <sound/core.h>
20*4882a593Smuzhiyun #include <sound/dmaengine_pcm.h>
21*4882a593Smuzhiyun #include <sound/initval.h>
22*4882a593Smuzhiyun #include <sound/pcm.h>
23*4882a593Smuzhiyun #include <sound/pcm_params.h>
24*4882a593Smuzhiyun #include <sound/soc.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #include <asm/fiq.h>
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include <linux/platform_data/asoc-imx-ssi.h>
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include "imx-ssi.h"
31*4882a593Smuzhiyun #include "imx-pcm.h"
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun struct imx_pcm_runtime_data {
34*4882a593Smuzhiyun 	unsigned int period;
35*4882a593Smuzhiyun 	int periods;
36*4882a593Smuzhiyun 	unsigned long offset;
37*4882a593Smuzhiyun 	struct hrtimer hrt;
38*4882a593Smuzhiyun 	int poll_time_ns;
39*4882a593Smuzhiyun 	struct snd_pcm_substream *substream;
40*4882a593Smuzhiyun 	atomic_t playing;
41*4882a593Smuzhiyun 	atomic_t capturing;
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
snd_hrtimer_callback(struct hrtimer * hrt)44*4882a593Smuzhiyun static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun 	struct imx_pcm_runtime_data *iprtd =
47*4882a593Smuzhiyun 		container_of(hrt, struct imx_pcm_runtime_data, hrt);
48*4882a593Smuzhiyun 	struct snd_pcm_substream *substream = iprtd->substream;
49*4882a593Smuzhiyun 	struct pt_regs regs;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	if (!atomic_read(&iprtd->playing) && !atomic_read(&iprtd->capturing))
52*4882a593Smuzhiyun 		return HRTIMER_NORESTART;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	get_fiq_regs(&regs);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
57*4882a593Smuzhiyun 		iprtd->offset = regs.ARM_r8 & 0xffff;
58*4882a593Smuzhiyun 	else
59*4882a593Smuzhiyun 		iprtd->offset = regs.ARM_r9 & 0xffff;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	snd_pcm_period_elapsed(substream);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	hrtimer_forward_now(hrt, ns_to_ktime(iprtd->poll_time_ns));
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	return HRTIMER_RESTART;
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun static struct fiq_handler fh = {
69*4882a593Smuzhiyun 	.name		= DRV_NAME,
70*4882a593Smuzhiyun };
71*4882a593Smuzhiyun 
snd_imx_pcm_hw_params(struct snd_soc_component * component,struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)72*4882a593Smuzhiyun static int snd_imx_pcm_hw_params(struct snd_soc_component *component,
73*4882a593Smuzhiyun 				 struct snd_pcm_substream *substream,
74*4882a593Smuzhiyun 				 struct snd_pcm_hw_params *params)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
77*4882a593Smuzhiyun 	struct imx_pcm_runtime_data *iprtd = runtime->private_data;
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	iprtd->periods = params_periods(params);
80*4882a593Smuzhiyun 	iprtd->period = params_period_bytes(params);
81*4882a593Smuzhiyun 	iprtd->offset = 0;
82*4882a593Smuzhiyun 	iprtd->poll_time_ns = 1000000000 / params_rate(params) *
83*4882a593Smuzhiyun 				params_period_size(params);
84*4882a593Smuzhiyun 	snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	return 0;
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun 
snd_imx_pcm_prepare(struct snd_soc_component * component,struct snd_pcm_substream * substream)89*4882a593Smuzhiyun static int snd_imx_pcm_prepare(struct snd_soc_component *component,
90*4882a593Smuzhiyun 			       struct snd_pcm_substream *substream)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
93*4882a593Smuzhiyun 	struct imx_pcm_runtime_data *iprtd = runtime->private_data;
94*4882a593Smuzhiyun 	struct pt_regs regs;
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	get_fiq_regs(&regs);
97*4882a593Smuzhiyun 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
98*4882a593Smuzhiyun 		regs.ARM_r8 = (iprtd->period * iprtd->periods - 1) << 16;
99*4882a593Smuzhiyun 	else
100*4882a593Smuzhiyun 		regs.ARM_r9 = (iprtd->period * iprtd->periods - 1) << 16;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	set_fiq_regs(&regs);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	return 0;
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun static int imx_pcm_fiq;
108*4882a593Smuzhiyun 
snd_imx_pcm_trigger(struct snd_soc_component * component,struct snd_pcm_substream * substream,int cmd)109*4882a593Smuzhiyun static int snd_imx_pcm_trigger(struct snd_soc_component *component,
110*4882a593Smuzhiyun 			       struct snd_pcm_substream *substream, int cmd)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
113*4882a593Smuzhiyun 	struct imx_pcm_runtime_data *iprtd = runtime->private_data;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	switch (cmd) {
116*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_START:
117*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_RESUME:
118*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
119*4882a593Smuzhiyun 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
120*4882a593Smuzhiyun 			atomic_set(&iprtd->playing, 1);
121*4882a593Smuzhiyun 		else
122*4882a593Smuzhiyun 			atomic_set(&iprtd->capturing, 1);
123*4882a593Smuzhiyun 		hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns),
124*4882a593Smuzhiyun 		      HRTIMER_MODE_REL);
125*4882a593Smuzhiyun 		enable_fiq(imx_pcm_fiq);
126*4882a593Smuzhiyun 		break;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_STOP:
129*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_SUSPEND:
130*4882a593Smuzhiyun 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
131*4882a593Smuzhiyun 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
132*4882a593Smuzhiyun 			atomic_set(&iprtd->playing, 0);
133*4882a593Smuzhiyun 		else
134*4882a593Smuzhiyun 			atomic_set(&iprtd->capturing, 0);
135*4882a593Smuzhiyun 		if (!atomic_read(&iprtd->playing) &&
136*4882a593Smuzhiyun 				!atomic_read(&iprtd->capturing))
137*4882a593Smuzhiyun 			disable_fiq(imx_pcm_fiq);
138*4882a593Smuzhiyun 		break;
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	default:
141*4882a593Smuzhiyun 		return -EINVAL;
142*4882a593Smuzhiyun 	}
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	return 0;
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun static snd_pcm_uframes_t
snd_imx_pcm_pointer(struct snd_soc_component * component,struct snd_pcm_substream * substream)148*4882a593Smuzhiyun snd_imx_pcm_pointer(struct snd_soc_component *component,
149*4882a593Smuzhiyun 		    struct snd_pcm_substream *substream)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
152*4882a593Smuzhiyun 	struct imx_pcm_runtime_data *iprtd = runtime->private_data;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	return bytes_to_frames(substream->runtime, iprtd->offset);
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun static const struct snd_pcm_hardware snd_imx_hardware = {
158*4882a593Smuzhiyun 	.info = SNDRV_PCM_INFO_INTERLEAVED |
159*4882a593Smuzhiyun 		SNDRV_PCM_INFO_BLOCK_TRANSFER |
160*4882a593Smuzhiyun 		SNDRV_PCM_INFO_MMAP |
161*4882a593Smuzhiyun 		SNDRV_PCM_INFO_MMAP_VALID |
162*4882a593Smuzhiyun 		SNDRV_PCM_INFO_PAUSE |
163*4882a593Smuzhiyun 		SNDRV_PCM_INFO_RESUME,
164*4882a593Smuzhiyun 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
165*4882a593Smuzhiyun 	.buffer_bytes_max = IMX_SSI_DMABUF_SIZE,
166*4882a593Smuzhiyun 	.period_bytes_min = 128,
167*4882a593Smuzhiyun 	.period_bytes_max = 16 * 1024,
168*4882a593Smuzhiyun 	.periods_min = 4,
169*4882a593Smuzhiyun 	.periods_max = 255,
170*4882a593Smuzhiyun 	.fifo_size = 0,
171*4882a593Smuzhiyun };
172*4882a593Smuzhiyun 
snd_imx_open(struct snd_soc_component * component,struct snd_pcm_substream * substream)173*4882a593Smuzhiyun static int snd_imx_open(struct snd_soc_component *component,
174*4882a593Smuzhiyun 			struct snd_pcm_substream *substream)
175*4882a593Smuzhiyun {
176*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
177*4882a593Smuzhiyun 	struct imx_pcm_runtime_data *iprtd;
178*4882a593Smuzhiyun 	int ret;
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL);
181*4882a593Smuzhiyun 	if (iprtd == NULL)
182*4882a593Smuzhiyun 		return -ENOMEM;
183*4882a593Smuzhiyun 	runtime->private_data = iprtd;
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 	iprtd->substream = substream;
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	atomic_set(&iprtd->playing, 0);
188*4882a593Smuzhiyun 	atomic_set(&iprtd->capturing, 0);
189*4882a593Smuzhiyun 	hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
190*4882a593Smuzhiyun 	iprtd->hrt.function = snd_hrtimer_callback;
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	ret = snd_pcm_hw_constraint_integer(substream->runtime,
193*4882a593Smuzhiyun 			SNDRV_PCM_HW_PARAM_PERIODS);
194*4882a593Smuzhiyun 	if (ret < 0) {
195*4882a593Smuzhiyun 		kfree(iprtd);
196*4882a593Smuzhiyun 		return ret;
197*4882a593Smuzhiyun 	}
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
200*4882a593Smuzhiyun 	return 0;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun 
snd_imx_close(struct snd_soc_component * component,struct snd_pcm_substream * substream)203*4882a593Smuzhiyun static int snd_imx_close(struct snd_soc_component *component,
204*4882a593Smuzhiyun 			 struct snd_pcm_substream *substream)
205*4882a593Smuzhiyun {
206*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
207*4882a593Smuzhiyun 	struct imx_pcm_runtime_data *iprtd = runtime->private_data;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	hrtimer_cancel(&iprtd->hrt);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 	kfree(iprtd);
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 	return 0;
214*4882a593Smuzhiyun }
215*4882a593Smuzhiyun 
snd_imx_pcm_mmap(struct snd_soc_component * component,struct snd_pcm_substream * substream,struct vm_area_struct * vma)216*4882a593Smuzhiyun static int snd_imx_pcm_mmap(struct snd_soc_component *component,
217*4882a593Smuzhiyun 			    struct snd_pcm_substream *substream,
218*4882a593Smuzhiyun 			    struct vm_area_struct *vma)
219*4882a593Smuzhiyun {
220*4882a593Smuzhiyun 	struct snd_pcm_runtime *runtime = substream->runtime;
221*4882a593Smuzhiyun 	int ret;
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	ret = dma_mmap_wc(substream->pcm->card->dev, vma, runtime->dma_area,
224*4882a593Smuzhiyun 			  runtime->dma_addr, runtime->dma_bytes);
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	pr_debug("%s: ret: %d %p %pad 0x%08zx\n", __func__, ret,
227*4882a593Smuzhiyun 			runtime->dma_area,
228*4882a593Smuzhiyun 			&runtime->dma_addr,
229*4882a593Smuzhiyun 			runtime->dma_bytes);
230*4882a593Smuzhiyun 	return ret;
231*4882a593Smuzhiyun }
232*4882a593Smuzhiyun 
imx_pcm_preallocate_dma_buffer(struct snd_pcm * pcm,int stream)233*4882a593Smuzhiyun static int imx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
234*4882a593Smuzhiyun {
235*4882a593Smuzhiyun 	struct snd_pcm_substream *substream = pcm->streams[stream].substream;
236*4882a593Smuzhiyun 	struct snd_dma_buffer *buf = &substream->dma_buffer;
237*4882a593Smuzhiyun 	size_t size = IMX_SSI_DMABUF_SIZE;
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	buf->dev.type = SNDRV_DMA_TYPE_DEV;
240*4882a593Smuzhiyun 	buf->dev.dev = pcm->card->dev;
241*4882a593Smuzhiyun 	buf->private_data = NULL;
242*4882a593Smuzhiyun 	buf->area = dma_alloc_wc(pcm->card->dev, size, &buf->addr, GFP_KERNEL);
243*4882a593Smuzhiyun 	if (!buf->area)
244*4882a593Smuzhiyun 		return -ENOMEM;
245*4882a593Smuzhiyun 	buf->bytes = size;
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 	return 0;
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun 
imx_pcm_new(struct snd_soc_pcm_runtime * rtd)250*4882a593Smuzhiyun static int imx_pcm_new(struct snd_soc_pcm_runtime *rtd)
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun 	struct snd_card *card = rtd->card->snd_card;
253*4882a593Smuzhiyun 	struct snd_pcm *pcm = rtd->pcm;
254*4882a593Smuzhiyun 	int ret;
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun 	ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
257*4882a593Smuzhiyun 	if (ret)
258*4882a593Smuzhiyun 		return ret;
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun 	if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
261*4882a593Smuzhiyun 		ret = imx_pcm_preallocate_dma_buffer(pcm,
262*4882a593Smuzhiyun 			SNDRV_PCM_STREAM_PLAYBACK);
263*4882a593Smuzhiyun 		if (ret)
264*4882a593Smuzhiyun 			return ret;
265*4882a593Smuzhiyun 	}
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun 	if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
268*4882a593Smuzhiyun 		ret = imx_pcm_preallocate_dma_buffer(pcm,
269*4882a593Smuzhiyun 			SNDRV_PCM_STREAM_CAPTURE);
270*4882a593Smuzhiyun 		if (ret)
271*4882a593Smuzhiyun 			return ret;
272*4882a593Smuzhiyun 	}
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun 	return 0;
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun static int ssi_irq;
278*4882a593Smuzhiyun 
snd_imx_pcm_new(struct snd_soc_component * component,struct snd_soc_pcm_runtime * rtd)279*4882a593Smuzhiyun static int snd_imx_pcm_new(struct snd_soc_component *component,
280*4882a593Smuzhiyun 			   struct snd_soc_pcm_runtime *rtd)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun 	struct snd_pcm *pcm = rtd->pcm;
283*4882a593Smuzhiyun 	struct snd_pcm_substream *substream;
284*4882a593Smuzhiyun 	int ret;
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	ret = imx_pcm_new(rtd);
287*4882a593Smuzhiyun 	if (ret)
288*4882a593Smuzhiyun 		return ret;
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun 	substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
291*4882a593Smuzhiyun 	if (substream) {
292*4882a593Smuzhiyun 		struct snd_dma_buffer *buf = &substream->dma_buffer;
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun 		imx_ssi_fiq_tx_buffer = (unsigned long)buf->area;
295*4882a593Smuzhiyun 	}
296*4882a593Smuzhiyun 
297*4882a593Smuzhiyun 	substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
298*4882a593Smuzhiyun 	if (substream) {
299*4882a593Smuzhiyun 		struct snd_dma_buffer *buf = &substream->dma_buffer;
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 		imx_ssi_fiq_rx_buffer = (unsigned long)buf->area;
302*4882a593Smuzhiyun 	}
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	set_fiq_handler(&imx_ssi_fiq_start,
305*4882a593Smuzhiyun 		&imx_ssi_fiq_end - &imx_ssi_fiq_start);
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	return 0;
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun 
imx_pcm_free(struct snd_pcm * pcm)310*4882a593Smuzhiyun static void imx_pcm_free(struct snd_pcm *pcm)
311*4882a593Smuzhiyun {
312*4882a593Smuzhiyun 	struct snd_pcm_substream *substream;
313*4882a593Smuzhiyun 	struct snd_dma_buffer *buf;
314*4882a593Smuzhiyun 	int stream;
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun 	for (stream = 0; stream < 2; stream++) {
317*4882a593Smuzhiyun 		substream = pcm->streams[stream].substream;
318*4882a593Smuzhiyun 		if (!substream)
319*4882a593Smuzhiyun 			continue;
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 		buf = &substream->dma_buffer;
322*4882a593Smuzhiyun 		if (!buf->area)
323*4882a593Smuzhiyun 			continue;
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 		dma_free_wc(pcm->card->dev, buf->bytes, buf->area, buf->addr);
326*4882a593Smuzhiyun 		buf->area = NULL;
327*4882a593Smuzhiyun 	}
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun 
snd_imx_pcm_free(struct snd_soc_component * component,struct snd_pcm * pcm)330*4882a593Smuzhiyun static void snd_imx_pcm_free(struct snd_soc_component *component,
331*4882a593Smuzhiyun 			     struct snd_pcm *pcm)
332*4882a593Smuzhiyun {
333*4882a593Smuzhiyun 	mxc_set_irq_fiq(ssi_irq, 0);
334*4882a593Smuzhiyun 	release_fiq(&fh);
335*4882a593Smuzhiyun 	imx_pcm_free(pcm);
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun static const struct snd_soc_component_driver imx_soc_component_fiq = {
339*4882a593Smuzhiyun 	.open		= snd_imx_open,
340*4882a593Smuzhiyun 	.close		= snd_imx_close,
341*4882a593Smuzhiyun 	.hw_params	= snd_imx_pcm_hw_params,
342*4882a593Smuzhiyun 	.prepare	= snd_imx_pcm_prepare,
343*4882a593Smuzhiyun 	.trigger	= snd_imx_pcm_trigger,
344*4882a593Smuzhiyun 	.pointer	= snd_imx_pcm_pointer,
345*4882a593Smuzhiyun 	.mmap		= snd_imx_pcm_mmap,
346*4882a593Smuzhiyun 	.pcm_construct	= snd_imx_pcm_new,
347*4882a593Smuzhiyun 	.pcm_destruct	= snd_imx_pcm_free,
348*4882a593Smuzhiyun };
349*4882a593Smuzhiyun 
imx_pcm_fiq_init(struct platform_device * pdev,struct imx_pcm_fiq_params * params)350*4882a593Smuzhiyun int imx_pcm_fiq_init(struct platform_device *pdev,
351*4882a593Smuzhiyun 		struct imx_pcm_fiq_params *params)
352*4882a593Smuzhiyun {
353*4882a593Smuzhiyun 	int ret;
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun 	ret = claim_fiq(&fh);
356*4882a593Smuzhiyun 	if (ret) {
357*4882a593Smuzhiyun 		dev_err(&pdev->dev, "failed to claim fiq: %d", ret);
358*4882a593Smuzhiyun 		return ret;
359*4882a593Smuzhiyun 	}
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun 	mxc_set_irq_fiq(params->irq, 1);
362*4882a593Smuzhiyun 	ssi_irq = params->irq;
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun 	imx_pcm_fiq = params->irq;
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun 	imx_ssi_fiq_base = (unsigned long)params->base;
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun 	params->dma_params_tx->maxburst = 4;
369*4882a593Smuzhiyun 	params->dma_params_rx->maxburst = 6;
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 	ret = devm_snd_soc_register_component(&pdev->dev, &imx_soc_component_fiq,
372*4882a593Smuzhiyun 					      NULL, 0);
373*4882a593Smuzhiyun 	if (ret)
374*4882a593Smuzhiyun 		goto failed_register;
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	return 0;
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun failed_register:
379*4882a593Smuzhiyun 	mxc_set_irq_fiq(ssi_irq, 0);
380*4882a593Smuzhiyun 	release_fiq(&fh);
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun 	return ret;
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(imx_pcm_fiq_init);
385*4882a593Smuzhiyun 
imx_pcm_fiq_exit(struct platform_device * pdev)386*4882a593Smuzhiyun void imx_pcm_fiq_exit(struct platform_device *pdev)
387*4882a593Smuzhiyun {
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(imx_pcm_fiq_exit);
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun MODULE_LICENSE("GPL");
392