diff options
author | Vladimir Barinov <vbarinov@ru.mvista.com> | 2008-02-18 05:40:22 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2008-04-24 06:00:11 -0400 |
commit | 310355c111dbae005269fe3fc39afdd60779bf5d (patch) | |
tree | fc792358843354483f86ef6695c5fe83db91a9da /sound | |
parent | b40b04ad380ad641e5740486e4b9a56fd32b64cc (diff) |
[ALSA] Davinci ASoC support
Add ASoC support for the TI Davinci SoC and the Davicni-EVM reference board.
It includes:
- ASoC Davinci DMA driver
- ASoC Davinci I2S (Davinci McBSP module based) driver
- ASoC Davinci-EVM reference board
Signed-off-by: Vladimir Barinov <vbarinov@ru.mvista.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/Kconfig | 1 | ||||
-rw-r--r-- | sound/soc/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/davinci/Kconfig | 19 | ||||
-rw-r--r-- | sound/soc/davinci/Makefile | 11 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-evm.c | 208 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-i2s.c | 407 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-i2s.h | 17 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-pcm.c | 389 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-pcm.h | 29 |
9 files changed, 1082 insertions, 1 deletions
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig index 276585215160..a3b51df2bea1 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig | |||
@@ -29,6 +29,7 @@ source "sound/soc/pxa/Kconfig" | |||
29 | source "sound/soc/s3c24xx/Kconfig" | 29 | source "sound/soc/s3c24xx/Kconfig" |
30 | source "sound/soc/sh/Kconfig" | 30 | source "sound/soc/sh/Kconfig" |
31 | source "sound/soc/fsl/Kconfig" | 31 | source "sound/soc/fsl/Kconfig" |
32 | source "sound/soc/davinci/Kconfig" | ||
32 | 33 | ||
33 | # Supported codecs | 34 | # Supported codecs |
34 | source "sound/soc/codecs/Kconfig" | 35 | source "sound/soc/codecs/Kconfig" |
diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 4869c9ae7a03..e489dbdde458 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | snd-soc-core-objs := soc-core.o soc-dapm.o | 1 | snd-soc-core-objs := soc-core.o soc-dapm.o |
2 | 2 | ||
3 | obj-$(CONFIG_SND_SOC) += snd-soc-core.o | 3 | obj-$(CONFIG_SND_SOC) += snd-soc-core.o |
4 | obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ | 4 | obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ davinci/ |
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig new file mode 100644 index 000000000000..20680c551aab --- /dev/null +++ b/sound/soc/davinci/Kconfig | |||
@@ -0,0 +1,19 @@ | |||
1 | config SND_DAVINCI_SOC | ||
2 | tristate "SoC Audio for the TI DAVINCI chip" | ||
3 | depends on ARCH_DAVINCI && SND_SOC | ||
4 | help | ||
5 | Say Y or M if you want to add support for codecs attached to | ||
6 | the DAVINCI AC97 or I2S interface. You will also need | ||
7 | to select the audio interfaces to support below. | ||
8 | |||
9 | config SND_DAVINCI_SOC_I2S | ||
10 | tristate | ||
11 | |||
12 | config SND_DAVINCI_SOC_EVM | ||
13 | tristate "SoC Audio support for DaVinci EVM" | ||
14 | depends on SND_DAVINCI_SOC && MACH_DAVINCI_EVM | ||
15 | select SND_DAVINCI_SOC_I2S | ||
16 | select SND_SOC_TLV320AIC3X | ||
17 | help | ||
18 | Say Y if you want to add support for SoC audio on TI | ||
19 | DaVinci EVM platform. | ||
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile new file mode 100644 index 000000000000..ca772e5b4637 --- /dev/null +++ b/sound/soc/davinci/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # DAVINCI Platform Support | ||
2 | snd-soc-davinci-objs := davinci-pcm.o | ||
3 | snd-soc-davinci-i2s-objs := davinci-i2s.o | ||
4 | |||
5 | obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o | ||
6 | obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o | ||
7 | |||
8 | # DAVINCI Machine Support | ||
9 | snd-soc-evm-objs := davinci-evm.o | ||
10 | |||
11 | obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o | ||
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c new file mode 100644 index 000000000000..fcd165240333 --- /dev/null +++ b/sound/soc/davinci/davinci-evm.c | |||
@@ -0,0 +1,208 @@ | |||
1 | /* | ||
2 | * ASoC driver for TI DAVINCI EVM platform | ||
3 | * | ||
4 | * Author: Vladimir Barinov, <vbarinov@ru.mvista.com> | ||
5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/moduleparam.h> | ||
14 | #include <linux/timer.h> | ||
15 | #include <linux/interrupt.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | #include <sound/core.h> | ||
18 | #include <sound/pcm.h> | ||
19 | #include <sound/soc.h> | ||
20 | #include <sound/soc-dapm.h> | ||
21 | |||
22 | #include <asm/mach-types.h> | ||
23 | #include <asm/dma.h> | ||
24 | #include <asm/arch/hardware.h> | ||
25 | |||
26 | #include "../codecs/tlv320aic3x.h" | ||
27 | #include "davinci-pcm.h" | ||
28 | #include "davinci-i2s.h" | ||
29 | |||
30 | #define EVM_CODEC_CLOCK 22579200 | ||
31 | |||
32 | static int evm_hw_params(struct snd_pcm_substream *substream, | ||
33 | struct snd_pcm_hw_params *params) | ||
34 | { | ||
35 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
36 | struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai; | ||
37 | struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai; | ||
38 | int ret = 0; | ||
39 | |||
40 | /* set codec DAI configuration */ | ||
41 | ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | ||
42 | SND_SOC_DAIFMT_CBM_CFM); | ||
43 | if (ret < 0) | ||
44 | return ret; | ||
45 | |||
46 | /* set cpu DAI configuration */ | ||
47 | ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM | | ||
48 | SND_SOC_DAIFMT_IB_NF); | ||
49 | if (ret < 0) | ||
50 | return ret; | ||
51 | |||
52 | /* set the codec system clock */ | ||
53 | ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK, | ||
54 | SND_SOC_CLOCK_OUT); | ||
55 | if (ret < 0) | ||
56 | return ret; | ||
57 | |||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static struct snd_soc_ops evm_ops = { | ||
62 | .hw_params = evm_hw_params, | ||
63 | }; | ||
64 | |||
65 | /* davinci-evm machine dapm widgets */ | ||
66 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { | ||
67 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
68 | SND_SOC_DAPM_LINE("Line Out", NULL), | ||
69 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | ||
70 | SND_SOC_DAPM_LINE("Line In", NULL), | ||
71 | }; | ||
72 | |||
73 | /* davinci-evm machine audio_mapnections to the codec pins */ | ||
74 | static const char *audio_map[][3] = { | ||
75 | /* Headphone connected to HPLOUT, HPROUT */ | ||
76 | {"Headphone Jack", NULL, "HPLOUT"}, | ||
77 | {"Headphone Jack", NULL, "HPROUT"}, | ||
78 | |||
79 | /* Line Out connected to LLOUT, RLOUT */ | ||
80 | {"Line Out", NULL, "LLOUT"}, | ||
81 | {"Line Out", NULL, "RLOUT"}, | ||
82 | |||
83 | /* Mic connected to (MIC3L | MIC3R) */ | ||
84 | {"MIC3L", NULL, "Mic Bias 2V"}, | ||
85 | {"MIC3R", NULL, "Mic Bias 2V"}, | ||
86 | {"Mic Bias 2V", NULL, "Mic Jack"}, | ||
87 | |||
88 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ | ||
89 | {"LINE1L", NULL, "Line In"}, | ||
90 | {"LINE2L", NULL, "Line In"}, | ||
91 | {"LINE1R", NULL, "Line In"}, | ||
92 | {"LINE2R", NULL, "Line In"}, | ||
93 | |||
94 | {NULL, NULL, NULL}, | ||
95 | }; | ||
96 | |||
97 | /* Logic for a aic3x as connected on a davinci-evm */ | ||
98 | static int evm_aic3x_init(struct snd_soc_codec *codec) | ||
99 | { | ||
100 | int i; | ||
101 | |||
102 | /* Add davinci-evm specific widgets */ | ||
103 | for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++) | ||
104 | snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]); | ||
105 | |||
106 | /* Set up davinci-evm specific audio path audio_map */ | ||
107 | for (i = 0; audio_map[i][0] != NULL; i++) | ||
108 | snd_soc_dapm_connect_input(codec, audio_map[i][0], | ||
109 | audio_map[i][1], audio_map[i][2]); | ||
110 | |||
111 | /* not connected */ | ||
112 | snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0); | ||
113 | snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0); | ||
114 | snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0); | ||
115 | |||
116 | /* always connected */ | ||
117 | snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1); | ||
118 | snd_soc_dapm_set_endpoint(codec, "Line Out", 1); | ||
119 | snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1); | ||
120 | snd_soc_dapm_set_endpoint(codec, "Line In", 1); | ||
121 | |||
122 | snd_soc_dapm_sync_endpoints(codec); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ | ||
128 | static struct snd_soc_dai_link evm_dai = { | ||
129 | .name = "TLV320AIC3X", | ||
130 | .stream_name = "AIC3X", | ||
131 | .cpu_dai = &davinci_i2s_dai, | ||
132 | .codec_dai = &aic3x_dai, | ||
133 | .init = evm_aic3x_init, | ||
134 | .ops = &evm_ops, | ||
135 | }; | ||
136 | |||
137 | /* davinci-evm audio machine driver */ | ||
138 | static struct snd_soc_machine snd_soc_machine_evm = { | ||
139 | .name = "DaVinci EVM", | ||
140 | .dai_link = &evm_dai, | ||
141 | .num_links = 1, | ||
142 | }; | ||
143 | |||
144 | /* evm audio private data */ | ||
145 | static struct aic3x_setup_data evm_aic3x_setup = { | ||
146 | .i2c_address = 0x1b, | ||
147 | }; | ||
148 | |||
149 | /* evm audio subsystem */ | ||
150 | static struct snd_soc_device evm_snd_devdata = { | ||
151 | .machine = &snd_soc_machine_evm, | ||
152 | .platform = &davinci_soc_platform, | ||
153 | .codec_dev = &soc_codec_dev_aic3x, | ||
154 | .codec_data = &evm_aic3x_setup, | ||
155 | }; | ||
156 | |||
157 | static struct resource evm_snd_resources[] = { | ||
158 | { | ||
159 | .start = DAVINCI_MCBSP_BASE, | ||
160 | .end = DAVINCI_MCBSP_BASE + SZ_8K - 1, | ||
161 | .flags = IORESOURCE_MEM, | ||
162 | }, | ||
163 | }; | ||
164 | |||
165 | static struct evm_snd_platform_data evm_snd_data = { | ||
166 | .tx_dma_ch = DM644X_DMACH_MCBSP_TX, | ||
167 | .rx_dma_ch = DM644X_DMACH_MCBSP_RX, | ||
168 | }; | ||
169 | |||
170 | static struct platform_device *evm_snd_device; | ||
171 | |||
172 | static int __init evm_init(void) | ||
173 | { | ||
174 | int ret; | ||
175 | |||
176 | evm_snd_device = platform_device_alloc("soc-audio", 0); | ||
177 | if (!evm_snd_device) | ||
178 | return -ENOMEM; | ||
179 | |||
180 | platform_set_drvdata(evm_snd_device, &evm_snd_devdata); | ||
181 | evm_snd_devdata.dev = &evm_snd_device->dev; | ||
182 | evm_snd_device->dev.platform_data = &evm_snd_data; | ||
183 | |||
184 | ret = platform_device_add_resources(evm_snd_device, evm_snd_resources, | ||
185 | ARRAY_SIZE(evm_snd_resources)); | ||
186 | if (ret) { | ||
187 | platform_device_put(evm_snd_device); | ||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | ret = platform_device_add(evm_snd_device); | ||
192 | if (ret) | ||
193 | platform_device_put(evm_snd_device); | ||
194 | |||
195 | return ret; | ||
196 | } | ||
197 | |||
198 | static void __exit evm_exit(void) | ||
199 | { | ||
200 | platform_device_unregister(evm_snd_device); | ||
201 | } | ||
202 | |||
203 | module_init(evm_init); | ||
204 | module_exit(evm_exit); | ||
205 | |||
206 | MODULE_AUTHOR("Vladimir Barinov"); | ||
207 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); | ||
208 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c new file mode 100644 index 000000000000..c421774b33ee --- /dev/null +++ b/sound/soc/davinci/davinci-i2s.c | |||
@@ -0,0 +1,407 @@ | |||
1 | /* | ||
2 | * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor | ||
3 | * | ||
4 | * Author: Vladimir Barinov, <vbarinov@ru.mvista.com> | ||
5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/init.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/device.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/clk.h> | ||
18 | |||
19 | #include <sound/core.h> | ||
20 | #include <sound/pcm.h> | ||
21 | #include <sound/pcm_params.h> | ||
22 | #include <sound/initval.h> | ||
23 | #include <sound/soc.h> | ||
24 | |||
25 | #include "davinci-pcm.h" | ||
26 | |||
27 | #define DAVINCI_MCBSP_DRR_REG 0x00 | ||
28 | #define DAVINCI_MCBSP_DXR_REG 0x04 | ||
29 | #define DAVINCI_MCBSP_SPCR_REG 0x08 | ||
30 | #define DAVINCI_MCBSP_RCR_REG 0x0c | ||
31 | #define DAVINCI_MCBSP_XCR_REG 0x10 | ||
32 | #define DAVINCI_MCBSP_SRGR_REG 0x14 | ||
33 | #define DAVINCI_MCBSP_PCR_REG 0x24 | ||
34 | |||
35 | #define DAVINCI_MCBSP_SPCR_RRST (1 << 0) | ||
36 | #define DAVINCI_MCBSP_SPCR_RINTM(v) ((v) << 4) | ||
37 | #define DAVINCI_MCBSP_SPCR_XRST (1 << 16) | ||
38 | #define DAVINCI_MCBSP_SPCR_XINTM(v) ((v) << 20) | ||
39 | #define DAVINCI_MCBSP_SPCR_GRST (1 << 22) | ||
40 | #define DAVINCI_MCBSP_SPCR_FRST (1 << 23) | ||
41 | #define DAVINCI_MCBSP_SPCR_FREE (1 << 25) | ||
42 | |||
43 | #define DAVINCI_MCBSP_RCR_RWDLEN1(v) ((v) << 5) | ||
44 | #define DAVINCI_MCBSP_RCR_RFRLEN1(v) ((v) << 8) | ||
45 | #define DAVINCI_MCBSP_RCR_RDATDLY(v) ((v) << 16) | ||
46 | #define DAVINCI_MCBSP_RCR_RWDLEN2(v) ((v) << 21) | ||
47 | |||
48 | #define DAVINCI_MCBSP_XCR_XWDLEN1(v) ((v) << 5) | ||
49 | #define DAVINCI_MCBSP_XCR_XFRLEN1(v) ((v) << 8) | ||
50 | #define DAVINCI_MCBSP_XCR_XDATDLY(v) ((v) << 16) | ||
51 | #define DAVINCI_MCBSP_XCR_XFIG (1 << 18) | ||
52 | #define DAVINCI_MCBSP_XCR_XWDLEN2(v) ((v) << 21) | ||
53 | |||
54 | #define DAVINCI_MCBSP_SRGR_FWID(v) ((v) << 8) | ||
55 | #define DAVINCI_MCBSP_SRGR_FPER(v) ((v) << 16) | ||
56 | #define DAVINCI_MCBSP_SRGR_FSGM (1 << 28) | ||
57 | |||
58 | #define DAVINCI_MCBSP_PCR_CLKRP (1 << 0) | ||
59 | #define DAVINCI_MCBSP_PCR_CLKXP (1 << 1) | ||
60 | #define DAVINCI_MCBSP_PCR_FSRP (1 << 2) | ||
61 | #define DAVINCI_MCBSP_PCR_FSXP (1 << 3) | ||
62 | #define DAVINCI_MCBSP_PCR_CLKRM (1 << 8) | ||
63 | #define DAVINCI_MCBSP_PCR_CLKXM (1 << 9) | ||
64 | #define DAVINCI_MCBSP_PCR_FSRM (1 << 10) | ||
65 | #define DAVINCI_MCBSP_PCR_FSXM (1 << 11) | ||
66 | |||
67 | #define MOD_REG_BIT(val, mask, set) do { \ | ||
68 | if (set) { \ | ||
69 | val |= mask; \ | ||
70 | } else { \ | ||
71 | val &= ~mask; \ | ||
72 | } \ | ||
73 | } while (0) | ||
74 | |||
75 | enum { | ||
76 | DAVINCI_MCBSP_WORD_8 = 0, | ||
77 | DAVINCI_MCBSP_WORD_12, | ||
78 | DAVINCI_MCBSP_WORD_16, | ||
79 | DAVINCI_MCBSP_WORD_20, | ||
80 | DAVINCI_MCBSP_WORD_24, | ||
81 | DAVINCI_MCBSP_WORD_32, | ||
82 | }; | ||
83 | |||
84 | static struct davinci_pcm_dma_params davinci_i2s_pcm_out = { | ||
85 | .name = "I2S PCM Stereo out", | ||
86 | }; | ||
87 | |||
88 | static struct davinci_pcm_dma_params davinci_i2s_pcm_in = { | ||
89 | .name = "I2S PCM Stereo in", | ||
90 | }; | ||
91 | |||
92 | struct davinci_mcbsp_dev { | ||
93 | void __iomem *base; | ||
94 | struct clk *clk; | ||
95 | struct davinci_pcm_dma_params *dma_params[2]; | ||
96 | }; | ||
97 | |||
98 | static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev, | ||
99 | int reg, u32 val) | ||
100 | { | ||
101 | __raw_writel(val, dev->base + reg); | ||
102 | } | ||
103 | |||
104 | static inline u32 davinci_mcbsp_read_reg(struct davinci_mcbsp_dev *dev, int reg) | ||
105 | { | ||
106 | return __raw_readl(dev->base + reg); | ||
107 | } | ||
108 | |||
109 | static void davinci_mcbsp_start(struct snd_pcm_substream *substream) | ||
110 | { | ||
111 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
112 | struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data; | ||
113 | u32 w; | ||
114 | |||
115 | /* Start the sample generator and enable transmitter/receiver */ | ||
116 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | ||
117 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST, 1); | ||
118 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
119 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 1); | ||
120 | else | ||
121 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 1); | ||
122 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); | ||
123 | |||
124 | /* Start frame sync */ | ||
125 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | ||
126 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_FRST, 1); | ||
127 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); | ||
128 | } | ||
129 | |||
130 | static void davinci_mcbsp_stop(struct snd_pcm_substream *substream) | ||
131 | { | ||
132 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
133 | struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data; | ||
134 | u32 w; | ||
135 | |||
136 | /* Reset transmitter/receiver and sample rate/frame sync generators */ | ||
137 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | ||
138 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST | | ||
139 | DAVINCI_MCBSP_SPCR_FRST, 0); | ||
140 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
141 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 0); | ||
142 | else | ||
143 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 0); | ||
144 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); | ||
145 | } | ||
146 | |||
147 | static int davinci_i2s_startup(struct snd_pcm_substream *substream) | ||
148 | { | ||
149 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
150 | struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai; | ||
151 | struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data; | ||
152 | |||
153 | cpu_dai->dma_data = dev->dma_params[substream->stream]; | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | static int davinci_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai, | ||
159 | unsigned int fmt) | ||
160 | { | ||
161 | struct davinci_mcbsp_dev *dev = cpu_dai->private_data; | ||
162 | u32 w; | ||
163 | |||
164 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
165 | case SND_SOC_DAIFMT_CBS_CFS: | ||
166 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, | ||
167 | DAVINCI_MCBSP_PCR_FSXM | | ||
168 | DAVINCI_MCBSP_PCR_FSRM | | ||
169 | DAVINCI_MCBSP_PCR_CLKXM | | ||
170 | DAVINCI_MCBSP_PCR_CLKRM); | ||
171 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, | ||
172 | DAVINCI_MCBSP_SRGR_FSGM); | ||
173 | break; | ||
174 | case SND_SOC_DAIFMT_CBM_CFM: | ||
175 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, 0); | ||
176 | break; | ||
177 | default: | ||
178 | return -EINVAL; | ||
179 | } | ||
180 | |||
181 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
182 | case SND_SOC_DAIFMT_IB_NF: | ||
183 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG); | ||
184 | MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP | | ||
185 | DAVINCI_MCBSP_PCR_CLKRP, 1); | ||
186 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w); | ||
187 | break; | ||
188 | case SND_SOC_DAIFMT_NB_IF: | ||
189 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG); | ||
190 | MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_FSXP | | ||
191 | DAVINCI_MCBSP_PCR_FSRP, 1); | ||
192 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w); | ||
193 | break; | ||
194 | case SND_SOC_DAIFMT_IB_IF: | ||
195 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG); | ||
196 | MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP | | ||
197 | DAVINCI_MCBSP_PCR_CLKRP | | ||
198 | DAVINCI_MCBSP_PCR_FSXP | | ||
199 | DAVINCI_MCBSP_PCR_FSRP, 1); | ||
200 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w); | ||
201 | break; | ||
202 | case SND_SOC_DAIFMT_NB_NF: | ||
203 | break; | ||
204 | default: | ||
205 | return -EINVAL; | ||
206 | } | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, | ||
212 | struct snd_pcm_hw_params *params) | ||
213 | { | ||
214 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
215 | struct davinci_pcm_dma_params *dma_params = rtd->dai->cpu_dai->dma_data; | ||
216 | struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data; | ||
217 | struct snd_interval *i = NULL; | ||
218 | int mcbsp_word_length; | ||
219 | u32 w; | ||
220 | |||
221 | /* general line settings */ | ||
222 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, | ||
223 | DAVINCI_MCBSP_SPCR_RINTM(3) | | ||
224 | DAVINCI_MCBSP_SPCR_XINTM(3) | | ||
225 | DAVINCI_MCBSP_SPCR_FREE); | ||
226 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, | ||
227 | DAVINCI_MCBSP_RCR_RFRLEN1(1) | | ||
228 | DAVINCI_MCBSP_RCR_RDATDLY(1)); | ||
229 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, | ||
230 | DAVINCI_MCBSP_XCR_XFRLEN1(1) | | ||
231 | DAVINCI_MCBSP_XCR_XDATDLY(1) | | ||
232 | DAVINCI_MCBSP_XCR_XFIG); | ||
233 | |||
234 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); | ||
235 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG); | ||
236 | MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FWID(snd_interval_value(i) - 1), 1); | ||
237 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w); | ||
238 | |||
239 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_FRAME_BITS); | ||
240 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG); | ||
241 | MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FPER(snd_interval_value(i) - 1), 1); | ||
242 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w); | ||
243 | |||
244 | /* Determine xfer data type */ | ||
245 | switch (params_format(params)) { | ||
246 | case SNDRV_PCM_FORMAT_S8: | ||
247 | dma_params->data_type = 1; | ||
248 | mcbsp_word_length = DAVINCI_MCBSP_WORD_8; | ||
249 | break; | ||
250 | case SNDRV_PCM_FORMAT_S16_LE: | ||
251 | dma_params->data_type = 2; | ||
252 | mcbsp_word_length = DAVINCI_MCBSP_WORD_16; | ||
253 | break; | ||
254 | case SNDRV_PCM_FORMAT_S32_LE: | ||
255 | dma_params->data_type = 4; | ||
256 | mcbsp_word_length = DAVINCI_MCBSP_WORD_32; | ||
257 | break; | ||
258 | default: | ||
259 | printk(KERN_WARNING "davinci-i2s: unsupported PCM format"); | ||
260 | return -EINVAL; | ||
261 | } | ||
262 | |||
263 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_RCR_REG); | ||
264 | MOD_REG_BIT(w, DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) | | ||
265 | DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length), 1); | ||
266 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, w); | ||
267 | |||
268 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_XCR_REG); | ||
269 | MOD_REG_BIT(w, DAVINCI_MCBSP_XCR_XWDLEN1(mcbsp_word_length) | | ||
270 | DAVINCI_MCBSP_XCR_XWDLEN2(mcbsp_word_length), 1); | ||
271 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, w); | ||
272 | |||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd) | ||
277 | { | ||
278 | int ret = 0; | ||
279 | |||
280 | switch (cmd) { | ||
281 | case SNDRV_PCM_TRIGGER_START: | ||
282 | case SNDRV_PCM_TRIGGER_RESUME: | ||
283 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
284 | davinci_mcbsp_start(substream); | ||
285 | break; | ||
286 | case SNDRV_PCM_TRIGGER_STOP: | ||
287 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
288 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
289 | davinci_mcbsp_stop(substream); | ||
290 | break; | ||
291 | default: | ||
292 | ret = -EINVAL; | ||
293 | } | ||
294 | |||
295 | return ret; | ||
296 | } | ||
297 | |||
298 | static int davinci_i2s_probe(struct platform_device *pdev) | ||
299 | { | ||
300 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
301 | struct snd_soc_machine *machine = socdev->machine; | ||
302 | struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai; | ||
303 | struct davinci_mcbsp_dev *dev; | ||
304 | struct resource *mem, *ioarea; | ||
305 | struct evm_snd_platform_data *pdata; | ||
306 | int ret; | ||
307 | |||
308 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
309 | if (!mem) { | ||
310 | dev_err(&pdev->dev, "no mem resource?\n"); | ||
311 | return -ENODEV; | ||
312 | } | ||
313 | |||
314 | ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1, | ||
315 | pdev->name); | ||
316 | if (!ioarea) { | ||
317 | dev_err(&pdev->dev, "McBSP region already claimed\n"); | ||
318 | return -EBUSY; | ||
319 | } | ||
320 | |||
321 | dev = kzalloc(sizeof(struct davinci_mcbsp_dev), GFP_KERNEL); | ||
322 | if (!dev) { | ||
323 | ret = -ENOMEM; | ||
324 | goto err_release_region; | ||
325 | } | ||
326 | |||
327 | cpu_dai->private_data = dev; | ||
328 | |||
329 | dev->clk = clk_get(&pdev->dev, "McBSPCLK"); | ||
330 | if (IS_ERR(dev->clk)) { | ||
331 | ret = -ENODEV; | ||
332 | goto err_free_mem; | ||
333 | } | ||
334 | clk_enable(dev->clk); | ||
335 | |||
336 | dev->base = (void __iomem *)IO_ADDRESS(mem->start); | ||
337 | pdata = pdev->dev.platform_data; | ||
338 | |||
339 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK] = &davinci_i2s_pcm_out; | ||
340 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->channel = pdata->tx_dma_ch; | ||
341 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->dma_addr = | ||
342 | (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DXR_REG); | ||
343 | |||
344 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE] = &davinci_i2s_pcm_in; | ||
345 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->channel = pdata->rx_dma_ch; | ||
346 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->dma_addr = | ||
347 | (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DRR_REG); | ||
348 | |||
349 | return 0; | ||
350 | |||
351 | err_free_mem: | ||
352 | kfree(dev); | ||
353 | err_release_region: | ||
354 | release_mem_region(mem->start, (mem->end - mem->start) + 1); | ||
355 | |||
356 | return ret; | ||
357 | } | ||
358 | |||
359 | static void davinci_i2s_remove(struct platform_device *pdev) | ||
360 | { | ||
361 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
362 | struct snd_soc_machine *machine = socdev->machine; | ||
363 | struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai; | ||
364 | struct davinci_mcbsp_dev *dev = cpu_dai->private_data; | ||
365 | struct resource *mem; | ||
366 | |||
367 | clk_disable(dev->clk); | ||
368 | clk_put(dev->clk); | ||
369 | dev->clk = NULL; | ||
370 | |||
371 | kfree(dev); | ||
372 | |||
373 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
374 | release_mem_region(mem->start, (mem->end - mem->start) + 1); | ||
375 | } | ||
376 | |||
377 | #define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000 | ||
378 | |||
379 | struct snd_soc_cpu_dai davinci_i2s_dai = { | ||
380 | .name = "davinci-i2s", | ||
381 | .id = 0, | ||
382 | .type = SND_SOC_DAI_I2S, | ||
383 | .probe = davinci_i2s_probe, | ||
384 | .remove = davinci_i2s_remove, | ||
385 | .playback = { | ||
386 | .channels_min = 2, | ||
387 | .channels_max = 2, | ||
388 | .rates = DAVINCI_I2S_RATES, | ||
389 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | ||
390 | .capture = { | ||
391 | .channels_min = 2, | ||
392 | .channels_max = 2, | ||
393 | .rates = DAVINCI_I2S_RATES, | ||
394 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | ||
395 | .ops = { | ||
396 | .startup = davinci_i2s_startup, | ||
397 | .trigger = davinci_i2s_trigger, | ||
398 | .hw_params = davinci_i2s_hw_params,}, | ||
399 | .dai_ops = { | ||
400 | .set_fmt = davinci_i2s_set_dai_fmt, | ||
401 | }, | ||
402 | }; | ||
403 | EXPORT_SYMBOL_GPL(davinci_i2s_dai); | ||
404 | |||
405 | MODULE_AUTHOR("Vladimir Barinov"); | ||
406 | MODULE_DESCRIPTION("TI DAVINCI I2S (McBSP) SoC Interface"); | ||
407 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/davinci/davinci-i2s.h b/sound/soc/davinci/davinci-i2s.h new file mode 100644 index 000000000000..9592d17db320 --- /dev/null +++ b/sound/soc/davinci/davinci-i2s.h | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor | ||
3 | * | ||
4 | * Author: Vladimir Barinov, <vbarinov@ru.mvista.com> | ||
5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #ifndef _DAVINCI_I2S_H | ||
13 | #define _DAVINCI_I2S_H | ||
14 | |||
15 | extern struct snd_soc_cpu_dai davinci_i2s_dai; | ||
16 | |||
17 | #endif | ||
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c new file mode 100644 index 000000000000..6a76927c9971 --- /dev/null +++ b/sound/soc/davinci/davinci-pcm.c | |||
@@ -0,0 +1,389 @@ | |||
1 | /* | ||
2 | * ALSA PCM interface for the TI DAVINCI processor | ||
3 | * | ||
4 | * Author: Vladimir Barinov, <vbarinov@ru.mvista.com> | ||
5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/dma-mapping.h> | ||
17 | |||
18 | #include <sound/core.h> | ||
19 | #include <sound/pcm.h> | ||
20 | #include <sound/pcm_params.h> | ||
21 | #include <sound/soc.h> | ||
22 | |||
23 | #include <asm/dma.h> | ||
24 | |||
25 | #include "davinci-pcm.h" | ||
26 | |||
27 | #define DAVINCI_PCM_DEBUG 0 | ||
28 | #if DAVINCI_PCM_DEBUG | ||
29 | #define DPRINTK(x...) printk(KERN_DEBUG x) | ||
30 | #else | ||
31 | #define DPRINTK(x...) | ||
32 | #endif | ||
33 | |||
34 | static struct snd_pcm_hardware davinci_pcm_hardware = { | ||
35 | .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | | ||
36 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | | ||
37 | SNDRV_PCM_INFO_PAUSE), | ||
38 | .formats = (SNDRV_PCM_FMTBIT_S16_LE), | ||
39 | .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | | ||
40 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | | ||
41 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | | ||
42 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | | ||
43 | SNDRV_PCM_RATE_KNOT), | ||
44 | .rate_min = 8000, | ||
45 | .rate_max = 96000, | ||
46 | .channels_min = 2, | ||
47 | .channels_max = 2, | ||
48 | .buffer_bytes_max = 128 * 1024, | ||
49 | .period_bytes_min = 32, | ||
50 | .period_bytes_max = 8 * 1024, | ||
51 | .periods_min = 16, | ||
52 | .periods_max = 255, | ||
53 | .fifo_size = 0, | ||
54 | }; | ||
55 | |||
56 | struct davinci_runtime_data { | ||
57 | spinlock_t lock; | ||
58 | int period; /* current DMA period */ | ||
59 | int master_lch; /* Master DMA channel */ | ||
60 | int slave_lch; /* Slave DMA channel */ | ||
61 | struct davinci_pcm_dma_params *params; /* DMA params */ | ||
62 | }; | ||
63 | |||
64 | static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream) | ||
65 | { | ||
66 | struct davinci_runtime_data *prtd = substream->runtime->private_data; | ||
67 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
68 | int lch = prtd->slave_lch; | ||
69 | unsigned int period_size; | ||
70 | unsigned int dma_offset; | ||
71 | dma_addr_t dma_pos; | ||
72 | dma_addr_t src, dst; | ||
73 | unsigned short src_bidx, dst_bidx; | ||
74 | unsigned int data_type; | ||
75 | unsigned int count; | ||
76 | |||
77 | period_size = snd_pcm_lib_period_bytes(substream); | ||
78 | dma_offset = prtd->period * period_size; | ||
79 | dma_pos = runtime->dma_addr + dma_offset; | ||
80 | |||
81 | DPRINTK("audio_set_dma_params_play channel = %d dma_ptr = %x " | ||
82 | "period_size=%x\n", lch, dma_pos, period_size); | ||
83 | |||
84 | data_type = prtd->params->data_type; | ||
85 | count = period_size / data_type; | ||
86 | |||
87 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
88 | src = dma_pos; | ||
89 | dst = prtd->params->dma_addr; | ||
90 | src_bidx = data_type; | ||
91 | dst_bidx = 0; | ||
92 | } else { | ||
93 | src = prtd->params->dma_addr; | ||
94 | dst = dma_pos; | ||
95 | src_bidx = 0; | ||
96 | dst_bidx = data_type; | ||
97 | } | ||
98 | |||
99 | davinci_set_dma_src_params(lch, src, INCR, W8BIT); | ||
100 | davinci_set_dma_dest_params(lch, dst, INCR, W8BIT); | ||
101 | davinci_set_dma_src_index(lch, src_bidx, 0); | ||
102 | davinci_set_dma_dest_index(lch, dst_bidx, 0); | ||
103 | davinci_set_dma_transfer_params(lch, data_type, count, 1, 0, ASYNC); | ||
104 | |||
105 | prtd->period++; | ||
106 | if (unlikely(prtd->period >= runtime->periods)) | ||
107 | prtd->period = 0; | ||
108 | } | ||
109 | |||
110 | static void davinci_pcm_dma_irq(int lch, u16 ch_status, void *data) | ||
111 | { | ||
112 | struct snd_pcm_substream *substream = data; | ||
113 | struct davinci_runtime_data *prtd = substream->runtime->private_data; | ||
114 | |||
115 | DPRINTK("lch=%d, status=0x%x\n", lch, ch_status); | ||
116 | |||
117 | if (unlikely(ch_status != DMA_COMPLETE)) | ||
118 | return; | ||
119 | |||
120 | if (snd_pcm_running(substream)) { | ||
121 | snd_pcm_period_elapsed(substream); | ||
122 | |||
123 | spin_lock(&prtd->lock); | ||
124 | davinci_pcm_enqueue_dma(substream); | ||
125 | spin_unlock(&prtd->lock); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | static int davinci_pcm_dma_request(struct snd_pcm_substream *substream) | ||
130 | { | ||
131 | struct davinci_runtime_data *prtd = substream->runtime->private_data; | ||
132 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
133 | struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data; | ||
134 | int tcc = TCC_ANY; | ||
135 | int ret; | ||
136 | |||
137 | if (!dma_data) | ||
138 | return -ENODEV; | ||
139 | |||
140 | prtd->params = dma_data; | ||
141 | |||
142 | /* Request master DMA channel */ | ||
143 | ret = davinci_request_dma(prtd->params->channel, prtd->params->name, | ||
144 | davinci_pcm_dma_irq, substream, | ||
145 | &prtd->master_lch, &tcc, EVENTQ_0); | ||
146 | if (ret) | ||
147 | return ret; | ||
148 | |||
149 | /* Request slave DMA channel */ | ||
150 | ret = davinci_request_dma(PARAM_ANY, "Link", | ||
151 | NULL, NULL, &prtd->slave_lch, &tcc, EVENTQ_0); | ||
152 | if (ret) { | ||
153 | davinci_free_dma(prtd->master_lch); | ||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | /* Link slave DMA channel in loopback */ | ||
158 | davinci_dma_link_lch(prtd->slave_lch, prtd->slave_lch); | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | ||
164 | { | ||
165 | struct davinci_runtime_data *prtd = substream->runtime->private_data; | ||
166 | int ret = 0; | ||
167 | |||
168 | spin_lock(&prtd->lock); | ||
169 | |||
170 | switch (cmd) { | ||
171 | case SNDRV_PCM_TRIGGER_START: | ||
172 | case SNDRV_PCM_TRIGGER_RESUME: | ||
173 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
174 | davinci_start_dma(prtd->master_lch); | ||
175 | break; | ||
176 | case SNDRV_PCM_TRIGGER_STOP: | ||
177 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
178 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
179 | davinci_stop_dma(prtd->master_lch); | ||
180 | break; | ||
181 | default: | ||
182 | ret = -EINVAL; | ||
183 | break; | ||
184 | } | ||
185 | |||
186 | spin_unlock(&prtd->lock); | ||
187 | |||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | static int davinci_pcm_prepare(struct snd_pcm_substream *substream) | ||
192 | { | ||
193 | struct davinci_runtime_data *prtd = substream->runtime->private_data; | ||
194 | struct paramentry_descriptor temp; | ||
195 | |||
196 | prtd->period = 0; | ||
197 | davinci_pcm_enqueue_dma(substream); | ||
198 | |||
199 | /* Get slave channel dma params for master channel startup */ | ||
200 | davinci_get_dma_params(prtd->slave_lch, &temp); | ||
201 | davinci_set_dma_params(prtd->master_lch, &temp); | ||
202 | |||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | static snd_pcm_uframes_t | ||
207 | davinci_pcm_pointer(struct snd_pcm_substream *substream) | ||
208 | { | ||
209 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
210 | struct davinci_runtime_data *prtd = runtime->private_data; | ||
211 | unsigned int offset; | ||
212 | dma_addr_t count; | ||
213 | dma_addr_t src, dst; | ||
214 | |||
215 | spin_lock(&prtd->lock); | ||
216 | |||
217 | davinci_dma_getposition(prtd->master_lch, &src, &dst); | ||
218 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
219 | count = src - runtime->dma_addr; | ||
220 | else | ||
221 | count = dst - runtime->dma_addr;; | ||
222 | |||
223 | spin_unlock(&prtd->lock); | ||
224 | |||
225 | offset = bytes_to_frames(runtime, count); | ||
226 | if (offset >= runtime->buffer_size) | ||
227 | offset = 0; | ||
228 | |||
229 | return offset; | ||
230 | } | ||
231 | |||
232 | static int davinci_pcm_open(struct snd_pcm_substream *substream) | ||
233 | { | ||
234 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
235 | struct davinci_runtime_data *prtd; | ||
236 | int ret = 0; | ||
237 | |||
238 | snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware); | ||
239 | |||
240 | prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL); | ||
241 | if (prtd == NULL) | ||
242 | return -ENOMEM; | ||
243 | |||
244 | spin_lock_init(&prtd->lock); | ||
245 | |||
246 | runtime->private_data = prtd; | ||
247 | |||
248 | ret = davinci_pcm_dma_request(substream); | ||
249 | if (ret) { | ||
250 | printk(KERN_ERR "davinci_pcm: Failed to get dma channels\n"); | ||
251 | kfree(prtd); | ||
252 | } | ||
253 | |||
254 | return ret; | ||
255 | } | ||
256 | |||
257 | static int davinci_pcm_close(struct snd_pcm_substream *substream) | ||
258 | { | ||
259 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
260 | struct davinci_runtime_data *prtd = runtime->private_data; | ||
261 | |||
262 | davinci_dma_unlink_lch(prtd->slave_lch, prtd->slave_lch); | ||
263 | |||
264 | davinci_free_dma(prtd->slave_lch); | ||
265 | davinci_free_dma(prtd->master_lch); | ||
266 | |||
267 | kfree(prtd); | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static int davinci_pcm_hw_params(struct snd_pcm_substream *substream, | ||
273 | struct snd_pcm_hw_params *hw_params) | ||
274 | { | ||
275 | return snd_pcm_lib_malloc_pages(substream, | ||
276 | params_buffer_bytes(hw_params)); | ||
277 | } | ||
278 | |||
279 | static int davinci_pcm_hw_free(struct snd_pcm_substream *substream) | ||
280 | { | ||
281 | return snd_pcm_lib_free_pages(substream); | ||
282 | } | ||
283 | |||
284 | static int davinci_pcm_mmap(struct snd_pcm_substream *substream, | ||
285 | struct vm_area_struct *vma) | ||
286 | { | ||
287 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
288 | |||
289 | return dma_mmap_writecombine(substream->pcm->card->dev, vma, | ||
290 | runtime->dma_area, | ||
291 | runtime->dma_addr, | ||
292 | runtime->dma_bytes); | ||
293 | } | ||
294 | |||
295 | struct snd_pcm_ops davinci_pcm_ops = { | ||
296 | .open = davinci_pcm_open, | ||
297 | .close = davinci_pcm_close, | ||
298 | .ioctl = snd_pcm_lib_ioctl, | ||
299 | .hw_params = davinci_pcm_hw_params, | ||
300 | .hw_free = davinci_pcm_hw_free, | ||
301 | .prepare = davinci_pcm_prepare, | ||
302 | .trigger = davinci_pcm_trigger, | ||
303 | .pointer = davinci_pcm_pointer, | ||
304 | .mmap = davinci_pcm_mmap, | ||
305 | }; | ||
306 | |||
307 | static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) | ||
308 | { | ||
309 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; | ||
310 | struct snd_dma_buffer *buf = &substream->dma_buffer; | ||
311 | size_t size = davinci_pcm_hardware.buffer_bytes_max; | ||
312 | |||
313 | buf->dev.type = SNDRV_DMA_TYPE_DEV; | ||
314 | buf->dev.dev = pcm->card->dev; | ||
315 | buf->private_data = NULL; | ||
316 | buf->area = dma_alloc_writecombine(pcm->card->dev, size, | ||
317 | &buf->addr, GFP_KERNEL); | ||
318 | |||
319 | DPRINTK("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n", | ||
320 | (void *) buf->area, (void *) buf->addr, size); | ||
321 | |||
322 | if (!buf->area) | ||
323 | return -ENOMEM; | ||
324 | |||
325 | buf->bytes = size; | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | static void davinci_pcm_free(struct snd_pcm *pcm) | ||
330 | { | ||
331 | struct snd_pcm_substream *substream; | ||
332 | struct snd_dma_buffer *buf; | ||
333 | int stream; | ||
334 | |||
335 | for (stream = 0; stream < 2; stream++) { | ||
336 | substream = pcm->streams[stream].substream; | ||
337 | if (!substream) | ||
338 | continue; | ||
339 | |||
340 | buf = &substream->dma_buffer; | ||
341 | if (!buf->area) | ||
342 | continue; | ||
343 | |||
344 | dma_free_writecombine(pcm->card->dev, buf->bytes, | ||
345 | buf->area, buf->addr); | ||
346 | buf->area = NULL; | ||
347 | } | ||
348 | } | ||
349 | |||
350 | static u64 davinci_pcm_dmamask = 0xffffffff; | ||
351 | |||
352 | static int davinci_pcm_new(struct snd_card *card, | ||
353 | struct snd_soc_codec_dai *dai, struct snd_pcm *pcm) | ||
354 | { | ||
355 | int ret; | ||
356 | |||
357 | if (!card->dev->dma_mask) | ||
358 | card->dev->dma_mask = &davinci_pcm_dmamask; | ||
359 | if (!card->dev->coherent_dma_mask) | ||
360 | card->dev->coherent_dma_mask = 0xffffffff; | ||
361 | |||
362 | if (dai->playback.channels_min) { | ||
363 | ret = davinci_pcm_preallocate_dma_buffer(pcm, | ||
364 | SNDRV_PCM_STREAM_PLAYBACK); | ||
365 | if (ret) | ||
366 | return ret; | ||
367 | } | ||
368 | |||
369 | if (dai->capture.channels_min) { | ||
370 | ret = davinci_pcm_preallocate_dma_buffer(pcm, | ||
371 | SNDRV_PCM_STREAM_CAPTURE); | ||
372 | if (ret) | ||
373 | return ret; | ||
374 | } | ||
375 | |||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | struct snd_soc_platform davinci_soc_platform = { | ||
380 | .name = "davinci-audio", | ||
381 | .pcm_ops = &davinci_pcm_ops, | ||
382 | .pcm_new = davinci_pcm_new, | ||
383 | .pcm_free = davinci_pcm_free, | ||
384 | }; | ||
385 | EXPORT_SYMBOL_GPL(davinci_soc_platform); | ||
386 | |||
387 | MODULE_AUTHOR("Vladimir Barinov"); | ||
388 | MODULE_DESCRIPTION("TI DAVINCI PCM DMA module"); | ||
389 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h new file mode 100644 index 000000000000..8d6a45e75a6e --- /dev/null +++ b/sound/soc/davinci/davinci-pcm.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * ALSA PCM interface for the TI DAVINCI processor | ||
3 | * | ||
4 | * Author: Vladimir Barinov, <vbarinov@ru.mvista.com> | ||
5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #ifndef _DAVINCI_PCM_H | ||
13 | #define _DAVINCI_PCM_H | ||
14 | |||
15 | struct davinci_pcm_dma_params { | ||
16 | char *name; /* stream identifier */ | ||
17 | int channel; /* sync dma channel ID */ | ||
18 | dma_addr_t dma_addr; /* device physical address for DMA */ | ||
19 | unsigned int data_type; /* xfer data type */ | ||
20 | }; | ||
21 | |||
22 | struct evm_snd_platform_data { | ||
23 | int tx_dma_ch; | ||
24 | int rx_dma_ch; | ||
25 | }; | ||
26 | |||
27 | extern struct snd_soc_platform davinci_soc_platform; | ||
28 | |||
29 | #endif | ||