diff options
author | Xiubo Li <Li.Xiubo@freescale.com> | 2013-12-16 22:24:38 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-12-18 13:27:59 -0500 |
commit | 4355082149429d1f87b6fbfc3ebc6305a5372ce2 (patch) | |
tree | c195c0d54e6a427dc7f21600d8d1853583652725 | |
parent | 6ce4eac1f600b34f2f7f58f9cd8f0503d79e42ae (diff) |
ASoC: Add SAI SoC Digital Audio Interface driver.
This adds Freescale SAI ASoC Audio support.
This implementation is only compatible with device tree definition.
Features:
o Supports playback/capture
o Supports 16/20/24 bit PCM
o Supports 8k - 96k sample rates
o Supports master and slave mode.
Signed-off-by: Alison Wang <b18965@freescale.com>
Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | sound/soc/fsl/Kconfig | 4 | ||||
-rw-r--r-- | sound/soc/fsl/Makefile | 4 | ||||
-rw-r--r-- | sound/soc/fsl/fsl_sai.c | 492 | ||||
-rw-r--r-- | sound/soc/fsl/fsl_sai.h | 114 |
4 files changed, 613 insertions, 1 deletions
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index b7ab71f2ccc1..ac4fe4ea15a9 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig | |||
@@ -1,3 +1,7 @@ | |||
1 | config SND_SOC_FSL_SAI | ||
2 | tristate | ||
3 | select SND_SOC_GENERIC_DMAENGINE_PCM | ||
4 | |||
1 | config SND_SOC_FSL_SSI | 5 | config SND_SOC_FSL_SSI |
2 | tristate | 6 | tristate |
3 | 7 | ||
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile index 8db705b0fdf9..aaccbee17006 100644 --- a/sound/soc/fsl/Makefile +++ b/sound/soc/fsl/Makefile | |||
@@ -10,11 +10,13 @@ obj-$(CONFIG_SND_SOC_P1022_DS) += snd-soc-p1022-ds.o | |||
10 | snd-soc-p1022-rdk-objs := p1022_rdk.o | 10 | snd-soc-p1022-rdk-objs := p1022_rdk.o |
11 | obj-$(CONFIG_SND_SOC_P1022_RDK) += snd-soc-p1022-rdk.o | 11 | obj-$(CONFIG_SND_SOC_P1022_RDK) += snd-soc-p1022-rdk.o |
12 | 12 | ||
13 | # Freescale PowerPC SSI/DMA Platform Support | 13 | # Freescale SSI/DMA/SAI/SPDIF Support |
14 | snd-soc-fsl-sai-objs := fsl_sai.o | ||
14 | snd-soc-fsl-ssi-objs := fsl_ssi.o | 15 | snd-soc-fsl-ssi-objs := fsl_ssi.o |
15 | snd-soc-fsl-spdif-objs := fsl_spdif.o | 16 | snd-soc-fsl-spdif-objs := fsl_spdif.o |
16 | snd-soc-fsl-utils-objs := fsl_utils.o | 17 | snd-soc-fsl-utils-objs := fsl_utils.o |
17 | snd-soc-fsl-dma-objs := fsl_dma.o | 18 | snd-soc-fsl-dma-objs := fsl_dma.o |
19 | obj-$(CONFIG_SND_SOC_FSL_SAI) += snd-soc-fsl-sai.o | ||
18 | obj-$(CONFIG_SND_SOC_FSL_SSI) += snd-soc-fsl-ssi.o | 20 | obj-$(CONFIG_SND_SOC_FSL_SSI) += snd-soc-fsl-ssi.o |
19 | obj-$(CONFIG_SND_SOC_FSL_SPDIF) += snd-soc-fsl-spdif.o | 21 | obj-$(CONFIG_SND_SOC_FSL_SPDIF) += snd-soc-fsl-spdif.o |
20 | obj-$(CONFIG_SND_SOC_FSL_UTILS) += snd-soc-fsl-utils.o | 22 | obj-$(CONFIG_SND_SOC_FSL_UTILS) += snd-soc-fsl-utils.o |
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c new file mode 100644 index 000000000000..50a797e65781 --- /dev/null +++ b/sound/soc/fsl/fsl_sai.c | |||
@@ -0,0 +1,492 @@ | |||
1 | /* | ||
2 | * Freescale ALSA SoC Digital Audio Interface (SAI) driver. | ||
3 | * | ||
4 | * Copyright 2012-2013 Freescale Semiconductor, Inc. | ||
5 | * | ||
6 | * This program is free software, you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation, either version 2 of the License, or(at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/clk.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/dmaengine.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/of_address.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <sound/core.h> | ||
20 | #include <sound/dmaengine_pcm.h> | ||
21 | #include <sound/pcm_params.h> | ||
22 | |||
23 | #include "fsl_sai.h" | ||
24 | |||
25 | static inline u32 sai_readl(struct fsl_sai *sai, | ||
26 | const void __iomem *addr) | ||
27 | { | ||
28 | u32 val; | ||
29 | |||
30 | val = __raw_readl(addr); | ||
31 | |||
32 | if (likely(sai->big_endian_regs)) | ||
33 | val = be32_to_cpu(val); | ||
34 | else | ||
35 | val = le32_to_cpu(val); | ||
36 | rmb(); | ||
37 | |||
38 | return val; | ||
39 | } | ||
40 | |||
41 | static inline void sai_writel(struct fsl_sai *sai, | ||
42 | u32 val, void __iomem *addr) | ||
43 | { | ||
44 | wmb(); | ||
45 | if (likely(sai->big_endian_regs)) | ||
46 | val = cpu_to_be32(val); | ||
47 | else | ||
48 | val = cpu_to_le32(val); | ||
49 | |||
50 | __raw_writel(val, addr); | ||
51 | } | ||
52 | |||
53 | static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai, | ||
54 | int clk_id, unsigned int freq, int fsl_dir) | ||
55 | { | ||
56 | u32 val_cr2, reg_cr2; | ||
57 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
58 | |||
59 | if (fsl_dir == FSL_FMT_TRANSMITTER) | ||
60 | reg_cr2 = FSL_SAI_TCR2; | ||
61 | else | ||
62 | reg_cr2 = FSL_SAI_RCR2; | ||
63 | |||
64 | val_cr2 = sai_readl(sai, sai->base + reg_cr2); | ||
65 | switch (clk_id) { | ||
66 | case FSL_SAI_CLK_BUS: | ||
67 | val_cr2 &= ~FSL_SAI_CR2_MSEL_MASK; | ||
68 | val_cr2 |= FSL_SAI_CR2_MSEL_BUS; | ||
69 | break; | ||
70 | case FSL_SAI_CLK_MAST1: | ||
71 | val_cr2 &= ~FSL_SAI_CR2_MSEL_MASK; | ||
72 | val_cr2 |= FSL_SAI_CR2_MSEL_MCLK1; | ||
73 | break; | ||
74 | case FSL_SAI_CLK_MAST2: | ||
75 | val_cr2 &= ~FSL_SAI_CR2_MSEL_MASK; | ||
76 | val_cr2 |= FSL_SAI_CR2_MSEL_MCLK2; | ||
77 | break; | ||
78 | case FSL_SAI_CLK_MAST3: | ||
79 | val_cr2 &= ~FSL_SAI_CR2_MSEL_MASK; | ||
80 | val_cr2 |= FSL_SAI_CR2_MSEL_MCLK3; | ||
81 | break; | ||
82 | default: | ||
83 | return -EINVAL; | ||
84 | } | ||
85 | sai_writel(sai, val_cr2, sai->base + reg_cr2); | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | static int fsl_sai_set_dai_sysclk(struct snd_soc_dai *cpu_dai, | ||
91 | int clk_id, unsigned int freq, int dir) | ||
92 | { | ||
93 | int ret; | ||
94 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
95 | |||
96 | if (dir == SND_SOC_CLOCK_IN) | ||
97 | return 0; | ||
98 | |||
99 | ret = clk_prepare_enable(sai->clk); | ||
100 | if (ret) | ||
101 | return ret; | ||
102 | |||
103 | sai_writel(sai, 0x0, sai->base + FSL_SAI_RCSR); | ||
104 | sai_writel(sai, 0x0, sai->base + FSL_SAI_TCSR); | ||
105 | sai_writel(sai, FSL_SAI_MAXBURST_TX * 2, sai->base + FSL_SAI_TCR1); | ||
106 | sai_writel(sai, FSL_SAI_MAXBURST_RX - 1, sai->base + FSL_SAI_RCR1); | ||
107 | |||
108 | ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq, | ||
109 | FSL_FMT_TRANSMITTER); | ||
110 | if (ret) { | ||
111 | dev_err(cpu_dai->dev, | ||
112 | "Cannot set SAI's transmitter sysclk: %d\n", | ||
113 | ret); | ||
114 | return ret; | ||
115 | } | ||
116 | |||
117 | ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq, | ||
118 | FSL_FMT_RECEIVER); | ||
119 | if (ret) { | ||
120 | dev_err(cpu_dai->dev, | ||
121 | "Cannot set SAI's receiver sysclk: %d\n", | ||
122 | ret); | ||
123 | return ret; | ||
124 | } | ||
125 | |||
126 | clk_disable_unprepare(sai->clk); | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | static int fsl_sai_set_dai_fmt_tr(struct snd_soc_dai *cpu_dai, | ||
132 | unsigned int fmt, int fsl_dir) | ||
133 | { | ||
134 | u32 val_cr2, val_cr3, val_cr4, reg_cr2, reg_cr3, reg_cr4; | ||
135 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
136 | |||
137 | if (fsl_dir == FSL_FMT_TRANSMITTER) { | ||
138 | reg_cr2 = FSL_SAI_TCR2; | ||
139 | reg_cr3 = FSL_SAI_TCR3; | ||
140 | reg_cr4 = FSL_SAI_TCR4; | ||
141 | } else { | ||
142 | reg_cr2 = FSL_SAI_RCR2; | ||
143 | reg_cr3 = FSL_SAI_RCR3; | ||
144 | reg_cr4 = FSL_SAI_RCR4; | ||
145 | } | ||
146 | |||
147 | val_cr2 = sai_readl(sai, sai->base + reg_cr2); | ||
148 | val_cr3 = sai_readl(sai, sai->base + reg_cr3); | ||
149 | val_cr4 = sai_readl(sai, sai->base + reg_cr4); | ||
150 | |||
151 | if (sai->big_endian_data) | ||
152 | val_cr4 |= FSL_SAI_CR4_MF; | ||
153 | else | ||
154 | val_cr4 &= ~FSL_SAI_CR4_MF; | ||
155 | |||
156 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
157 | case SND_SOC_DAIFMT_I2S: | ||
158 | val_cr4 |= FSL_SAI_CR4_FSE; | ||
159 | val_cr4 |= FSL_SAI_CR4_FSP; | ||
160 | break; | ||
161 | default: | ||
162 | return -EINVAL; | ||
163 | } | ||
164 | |||
165 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
166 | case SND_SOC_DAIFMT_IB_IF: | ||
167 | val_cr4 |= FSL_SAI_CR4_FSP; | ||
168 | val_cr2 &= ~FSL_SAI_CR2_BCP; | ||
169 | break; | ||
170 | case SND_SOC_DAIFMT_IB_NF: | ||
171 | val_cr4 &= ~FSL_SAI_CR4_FSP; | ||
172 | val_cr2 &= ~FSL_SAI_CR2_BCP; | ||
173 | break; | ||
174 | case SND_SOC_DAIFMT_NB_IF: | ||
175 | val_cr4 |= FSL_SAI_CR4_FSP; | ||
176 | val_cr2 |= FSL_SAI_CR2_BCP; | ||
177 | break; | ||
178 | case SND_SOC_DAIFMT_NB_NF: | ||
179 | val_cr4 &= ~FSL_SAI_CR4_FSP; | ||
180 | val_cr2 |= FSL_SAI_CR2_BCP; | ||
181 | break; | ||
182 | default: | ||
183 | return -EINVAL; | ||
184 | } | ||
185 | |||
186 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
187 | case SND_SOC_DAIFMT_CBS_CFS: | ||
188 | val_cr2 |= FSL_SAI_CR2_BCD_MSTR; | ||
189 | val_cr4 |= FSL_SAI_CR4_FSD_MSTR; | ||
190 | break; | ||
191 | case SND_SOC_DAIFMT_CBM_CFM: | ||
192 | val_cr2 &= ~FSL_SAI_CR2_BCD_MSTR; | ||
193 | val_cr4 &= ~FSL_SAI_CR4_FSD_MSTR; | ||
194 | break; | ||
195 | default: | ||
196 | return -EINVAL; | ||
197 | } | ||
198 | |||
199 | val_cr3 |= FSL_SAI_CR3_TRCE; | ||
200 | |||
201 | if (fsl_dir == FSL_FMT_RECEIVER) | ||
202 | val_cr2 |= FSL_SAI_CR2_SYNC; | ||
203 | |||
204 | sai_writel(sai, val_cr2, sai->base + reg_cr2); | ||
205 | sai_writel(sai, val_cr3, sai->base + reg_cr3); | ||
206 | sai_writel(sai, val_cr4, sai->base + reg_cr4); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static int fsl_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | ||
212 | { | ||
213 | int ret; | ||
214 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
215 | |||
216 | ret = clk_prepare_enable(sai->clk); | ||
217 | if (ret) | ||
218 | return ret; | ||
219 | |||
220 | ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_TRANSMITTER); | ||
221 | if (ret) { | ||
222 | dev_err(cpu_dai->dev, | ||
223 | "Cannot set SAI's transmitter format: %d\n", | ||
224 | ret); | ||
225 | return ret; | ||
226 | } | ||
227 | |||
228 | ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_RECEIVER); | ||
229 | if (ret) { | ||
230 | dev_err(cpu_dai->dev, | ||
231 | "Cannot set SAI's receiver format: %d\n", | ||
232 | ret); | ||
233 | return ret; | ||
234 | } | ||
235 | |||
236 | clk_disable_unprepare(sai->clk); | ||
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static int fsl_sai_hw_params(struct snd_pcm_substream *substream, | ||
242 | struct snd_pcm_hw_params *params, | ||
243 | struct snd_soc_dai *cpu_dai) | ||
244 | { | ||
245 | u32 val_cr4, val_cr5, val_mr, reg_cr4, reg_cr5, reg_mr, word_width; | ||
246 | unsigned int channels = params_channels(params); | ||
247 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
248 | |||
249 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
250 | reg_cr4 = FSL_SAI_TCR4; | ||
251 | reg_cr5 = FSL_SAI_TCR5; | ||
252 | reg_mr = FSL_SAI_TMR; | ||
253 | } else { | ||
254 | reg_cr4 = FSL_SAI_RCR4; | ||
255 | reg_cr5 = FSL_SAI_RCR5; | ||
256 | reg_mr = FSL_SAI_RMR; | ||
257 | } | ||
258 | |||
259 | val_cr4 = sai_readl(sai, sai->base + reg_cr4); | ||
260 | val_cr4 &= ~FSL_SAI_CR4_SYWD_MASK; | ||
261 | val_cr4 &= ~FSL_SAI_CR4_FRSZ_MASK; | ||
262 | |||
263 | val_cr5 = sai_readl(sai, sai->base + reg_cr5); | ||
264 | val_cr5 &= ~FSL_SAI_CR5_WNW_MASK; | ||
265 | val_cr5 &= ~FSL_SAI_CR5_W0W_MASK; | ||
266 | val_cr5 &= ~FSL_SAI_CR5_FBT_MASK; | ||
267 | |||
268 | switch (params_format(params)) { | ||
269 | case SNDRV_PCM_FORMAT_S16_LE: | ||
270 | word_width = 16; | ||
271 | break; | ||
272 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
273 | word_width = 20; | ||
274 | break; | ||
275 | case SNDRV_PCM_FORMAT_S24_LE: | ||
276 | word_width = 24; | ||
277 | break; | ||
278 | default: | ||
279 | return -EINVAL; | ||
280 | } | ||
281 | |||
282 | val_cr4 |= FSL_SAI_CR4_SYWD(word_width); | ||
283 | val_cr5 |= FSL_SAI_CR5_WNW(word_width); | ||
284 | val_cr5 |= FSL_SAI_CR5_W0W(word_width); | ||
285 | |||
286 | if (sai->big_endian_data) | ||
287 | val_cr5 |= FSL_SAI_CR5_FBT(word_width - 1); | ||
288 | else | ||
289 | val_cr5 |= FSL_SAI_CR5_FBT(0); | ||
290 | |||
291 | val_cr4 |= FSL_SAI_CR4_FRSZ(channels); | ||
292 | if (channels == 2 || channels == 1) | ||
293 | val_mr = ~0UL - ((1 << channels) - 1); | ||
294 | else | ||
295 | return -EINVAL; | ||
296 | |||
297 | sai_writel(sai, val_cr4, sai->base + reg_cr4); | ||
298 | sai_writel(sai, val_cr5, sai->base + reg_cr5); | ||
299 | sai_writel(sai, val_mr, sai->base + reg_mr); | ||
300 | |||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd, | ||
305 | struct snd_soc_dai *cpu_dai) | ||
306 | { | ||
307 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
308 | unsigned int tcsr, rcsr; | ||
309 | |||
310 | tcsr = sai_readl(sai, sai->base + FSL_SAI_TCSR); | ||
311 | rcsr = sai_readl(sai, sai->base + FSL_SAI_RCSR); | ||
312 | |||
313 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
314 | tcsr |= FSL_SAI_CSR_FRDE; | ||
315 | rcsr &= ~FSL_SAI_CSR_FRDE; | ||
316 | } else { | ||
317 | rcsr |= FSL_SAI_CSR_FRDE; | ||
318 | tcsr &= ~FSL_SAI_CSR_FRDE; | ||
319 | } | ||
320 | |||
321 | switch (cmd) { | ||
322 | case SNDRV_PCM_TRIGGER_START: | ||
323 | case SNDRV_PCM_TRIGGER_RESUME: | ||
324 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
325 | tcsr |= FSL_SAI_CSR_TERE; | ||
326 | rcsr |= FSL_SAI_CSR_TERE; | ||
327 | sai_writel(sai, rcsr, sai->base + FSL_SAI_RCSR); | ||
328 | sai_writel(sai, tcsr, sai->base + FSL_SAI_TCSR); | ||
329 | break; | ||
330 | |||
331 | case SNDRV_PCM_TRIGGER_STOP: | ||
332 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
333 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
334 | if (!(cpu_dai->playback_active || cpu_dai->capture_active)) { | ||
335 | tcsr &= ~FSL_SAI_CSR_TERE; | ||
336 | rcsr &= ~FSL_SAI_CSR_TERE; | ||
337 | } | ||
338 | sai_writel(sai, tcsr, sai->base + FSL_SAI_TCSR); | ||
339 | sai_writel(sai, rcsr, sai->base + FSL_SAI_RCSR); | ||
340 | break; | ||
341 | default: | ||
342 | return -EINVAL; | ||
343 | } | ||
344 | |||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | static int fsl_sai_startup(struct snd_pcm_substream *substream, | ||
349 | struct snd_soc_dai *cpu_dai) | ||
350 | { | ||
351 | int ret; | ||
352 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
353 | |||
354 | ret = clk_prepare_enable(sai->clk); | ||
355 | |||
356 | return ret; | ||
357 | } | ||
358 | |||
359 | static void fsl_sai_shutdown(struct snd_pcm_substream *substream, | ||
360 | struct snd_soc_dai *cpu_dai) | ||
361 | { | ||
362 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); | ||
363 | |||
364 | clk_disable_unprepare(sai->clk); | ||
365 | } | ||
366 | |||
367 | static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = { | ||
368 | .set_sysclk = fsl_sai_set_dai_sysclk, | ||
369 | .set_fmt = fsl_sai_set_dai_fmt, | ||
370 | .hw_params = fsl_sai_hw_params, | ||
371 | .trigger = fsl_sai_trigger, | ||
372 | .startup = fsl_sai_startup, | ||
373 | .shutdown = fsl_sai_shutdown, | ||
374 | }; | ||
375 | |||
376 | static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai) | ||
377 | { | ||
378 | struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev); | ||
379 | |||
380 | cpu_dai->playback_dma_data = &sai->dma_params_tx; | ||
381 | cpu_dai->capture_dma_data = &sai->dma_params_rx; | ||
382 | |||
383 | snd_soc_dai_set_drvdata(cpu_dai, sai); | ||
384 | |||
385 | return 0; | ||
386 | } | ||
387 | |||
388 | static int fsl_sai_dai_remove(struct snd_soc_dai *cpu_dai) | ||
389 | { | ||
390 | cpu_dai->playback_dma_data = NULL; | ||
391 | cpu_dai->capture_dma_data = NULL; | ||
392 | |||
393 | snd_soc_dai_set_drvdata(cpu_dai, NULL); | ||
394 | |||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | static struct snd_soc_dai_driver fsl_sai_dai = { | ||
399 | .probe = fsl_sai_dai_probe, | ||
400 | .remove = fsl_sai_dai_remove, | ||
401 | .playback = { | ||
402 | .channels_min = 1, | ||
403 | .channels_max = 2, | ||
404 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
405 | .formats = FSL_SAI_FORMATS, | ||
406 | }, | ||
407 | .capture = { | ||
408 | .channels_min = 1, | ||
409 | .channels_max = 2, | ||
410 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
411 | .formats = FSL_SAI_FORMATS, | ||
412 | }, | ||
413 | .ops = &fsl_sai_pcm_dai_ops, | ||
414 | }; | ||
415 | |||
416 | static const struct snd_soc_component_driver fsl_component = { | ||
417 | .name = "fsl-sai", | ||
418 | }; | ||
419 | |||
420 | static int fsl_sai_probe(struct platform_device *pdev) | ||
421 | { | ||
422 | int ret; | ||
423 | struct fsl_sai *sai; | ||
424 | struct resource *res; | ||
425 | struct device_node *np = pdev->dev.of_node; | ||
426 | |||
427 | sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); | ||
428 | if (!sai) | ||
429 | return -ENOMEM; | ||
430 | |||
431 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
432 | sai->base = devm_ioremap_resource(&pdev->dev, res); | ||
433 | if (IS_ERR(sai->base)) | ||
434 | return PTR_ERR(sai->base); | ||
435 | |||
436 | sai->clk = devm_clk_get(&pdev->dev, "sai"); | ||
437 | if (IS_ERR(sai->clk)) { | ||
438 | dev_err(&pdev->dev, "Cannot get SAI's clock\n"); | ||
439 | return PTR_ERR(sai->clk); | ||
440 | } | ||
441 | |||
442 | sai->dma_params_rx.addr = res->start + FSL_SAI_RDR; | ||
443 | sai->dma_params_tx.addr = res->start + FSL_SAI_TDR; | ||
444 | sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; | ||
445 | sai->dma_params_tx.maxburst = FSL_SAI_MAXBURST_TX; | ||
446 | |||
447 | sai->big_endian_regs = of_property_read_bool(np, "big-endian-regs"); | ||
448 | sai->big_endian_data = of_property_read_bool(np, "big-endian-data"); | ||
449 | |||
450 | platform_set_drvdata(pdev, sai); | ||
451 | |||
452 | ret = devm_snd_soc_register_component(&pdev->dev, &fsl_component, | ||
453 | &fsl_sai_dai, 1); | ||
454 | if (ret) | ||
455 | return ret; | ||
456 | |||
457 | ret = snd_dmaengine_pcm_register(&pdev->dev, NULL, | ||
458 | SND_DMAENGINE_PCM_FLAG_NO_RESIDUE); | ||
459 | if (ret) | ||
460 | return ret; | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static int fsl_sai_remove(struct platform_device *pdev) | ||
466 | { | ||
467 | snd_dmaengine_pcm_unregister(&pdev->dev); | ||
468 | |||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | static const struct of_device_id fsl_sai_ids[] = { | ||
473 | { .compatible = "fsl,vf610-sai", }, | ||
474 | { /* sentinel */ } | ||
475 | }; | ||
476 | |||
477 | static struct platform_driver fsl_sai_driver = { | ||
478 | .probe = fsl_sai_probe, | ||
479 | .remove = fsl_sai_remove, | ||
480 | |||
481 | .driver = { | ||
482 | .name = "fsl-sai", | ||
483 | .owner = THIS_MODULE, | ||
484 | .of_match_table = fsl_sai_ids, | ||
485 | }, | ||
486 | }; | ||
487 | module_platform_driver(fsl_sai_driver); | ||
488 | |||
489 | MODULE_DESCRIPTION("Freescale Soc SAI Interface"); | ||
490 | MODULE_AUTHOR("Xiubo Li, <Li.Xiubo@freescale.com>"); | ||
491 | MODULE_ALIAS("platform:fsl-sai"); | ||
492 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h new file mode 100644 index 000000000000..41bb62e69361 --- /dev/null +++ b/sound/soc/fsl/fsl_sai.h | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | * Copyright 2012-2013 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #ifndef __FSL_SAI_H | ||
10 | #define __FSL_SAI_H | ||
11 | |||
12 | #include <sound/dmaengine_pcm.h> | ||
13 | |||
14 | #define FSL_SAI_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ | ||
15 | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
16 | SNDRV_PCM_FMTBIT_S24_LE) | ||
17 | |||
18 | /* SAI Transmit/Recieve Control Register */ | ||
19 | #define FSL_SAI_TCSR 0x00 | ||
20 | #define FSL_SAI_RCSR 0x80 | ||
21 | #define FSL_SAI_CSR_TERE BIT(31) | ||
22 | #define FSL_SAI_CSR_FWF BIT(17) | ||
23 | #define FSL_SAI_CSR_FRIE BIT(8) | ||
24 | #define FSL_SAI_CSR_FRDE BIT(0) | ||
25 | |||
26 | /* SAI Transmit Data/FIFO/MASK Register */ | ||
27 | #define FSL_SAI_TDR 0x20 | ||
28 | #define FSL_SAI_TFR 0x40 | ||
29 | #define FSL_SAI_TMR 0x60 | ||
30 | |||
31 | /* SAI Recieve Data/FIFO/MASK Register */ | ||
32 | #define FSL_SAI_RDR 0xa0 | ||
33 | #define FSL_SAI_RFR 0xc0 | ||
34 | #define FSL_SAI_RMR 0xe0 | ||
35 | |||
36 | /* SAI Transmit and Recieve Configuration 1 Register */ | ||
37 | #define FSL_SAI_TCR1 0x04 | ||
38 | #define FSL_SAI_RCR1 0x84 | ||
39 | |||
40 | /* SAI Transmit and Recieve Configuration 2 Register */ | ||
41 | #define FSL_SAI_TCR2 0x08 | ||
42 | #define FSL_SAI_RCR2 0x88 | ||
43 | #define FSL_SAI_CR2_SYNC BIT(30) | ||
44 | #define FSL_SAI_CR2_MSEL_MASK (0xff << 26) | ||
45 | #define FSL_SAI_CR2_MSEL_BUS 0 | ||
46 | #define FSL_SAI_CR2_MSEL_MCLK1 BIT(26) | ||
47 | #define FSL_SAI_CR2_MSEL_MCLK2 BIT(27) | ||
48 | #define FSL_SAI_CR2_MSEL_MCLK3 (BIT(26) | BIT(27)) | ||
49 | #define FSL_SAI_CR2_BCP BIT(25) | ||
50 | #define FSL_SAI_CR2_BCD_MSTR BIT(24) | ||
51 | |||
52 | /* SAI Transmit and Recieve Configuration 3 Register */ | ||
53 | #define FSL_SAI_TCR3 0x0c | ||
54 | #define FSL_SAI_RCR3 0x8c | ||
55 | #define FSL_SAI_CR3_TRCE BIT(16) | ||
56 | #define FSL_SAI_CR3_WDFL(x) (x) | ||
57 | #define FSL_SAI_CR3_WDFL_MASK 0x1f | ||
58 | |||
59 | /* SAI Transmit and Recieve Configuration 4 Register */ | ||
60 | #define FSL_SAI_TCR4 0x10 | ||
61 | #define FSL_SAI_RCR4 0x90 | ||
62 | #define FSL_SAI_CR4_FRSZ(x) (((x) - 1) << 16) | ||
63 | #define FSL_SAI_CR4_FRSZ_MASK (0x1f << 16) | ||
64 | #define FSL_SAI_CR4_SYWD(x) (((x) - 1) << 8) | ||
65 | #define FSL_SAI_CR4_SYWD_MASK (0x1f << 8) | ||
66 | #define FSL_SAI_CR4_MF BIT(4) | ||
67 | #define FSL_SAI_CR4_FSE BIT(3) | ||
68 | #define FSL_SAI_CR4_FSP BIT(1) | ||
69 | #define FSL_SAI_CR4_FSD_MSTR BIT(0) | ||
70 | |||
71 | /* SAI Transmit and Recieve Configuration 5 Register */ | ||
72 | #define FSL_SAI_TCR5 0x14 | ||
73 | #define FSL_SAI_RCR5 0x94 | ||
74 | #define FSL_SAI_CR5_WNW(x) (((x) - 1) << 24) | ||
75 | #define FSL_SAI_CR5_WNW_MASK (0x1f << 24) | ||
76 | #define FSL_SAI_CR5_W0W(x) (((x) - 1) << 16) | ||
77 | #define FSL_SAI_CR5_W0W_MASK (0x1f << 16) | ||
78 | #define FSL_SAI_CR5_FBT(x) ((x) << 8) | ||
79 | #define FSL_SAI_CR5_FBT_MASK (0x1f << 8) | ||
80 | |||
81 | /* SAI type */ | ||
82 | #define FSL_SAI_DMA BIT(0) | ||
83 | #define FSL_SAI_USE_AC97 BIT(1) | ||
84 | #define FSL_SAI_NET BIT(2) | ||
85 | #define FSL_SAI_TRA_SYN BIT(3) | ||
86 | #define FSL_SAI_REC_SYN BIT(4) | ||
87 | #define FSL_SAI_USE_I2S_SLAVE BIT(5) | ||
88 | |||
89 | #define FSL_FMT_TRANSMITTER 0 | ||
90 | #define FSL_FMT_RECEIVER 1 | ||
91 | |||
92 | /* SAI clock sources */ | ||
93 | #define FSL_SAI_CLK_BUS 0 | ||
94 | #define FSL_SAI_CLK_MAST1 1 | ||
95 | #define FSL_SAI_CLK_MAST2 2 | ||
96 | #define FSL_SAI_CLK_MAST3 3 | ||
97 | |||
98 | /* SAI data transfer numbers per DMA request */ | ||
99 | #define FSL_SAI_MAXBURST_TX 6 | ||
100 | #define FSL_SAI_MAXBURST_RX 6 | ||
101 | |||
102 | struct fsl_sai { | ||
103 | struct clk *clk; | ||
104 | |||
105 | void __iomem *base; | ||
106 | |||
107 | bool big_endian_regs; | ||
108 | bool big_endian_data; | ||
109 | |||
110 | struct snd_dmaengine_dai_dma_data dma_params_rx; | ||
111 | struct snd_dmaengine_dai_dma_data dma_params_tx; | ||
112 | }; | ||
113 | |||
114 | #endif /* __FSL_SAI_H */ | ||