diff options
author | Scott Jiang <scott.jiang.linux@gmail.com> | 2012-06-20 17:00:31 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-06-20 06:26:54 -0400 |
commit | f62ae7bda434ac5d2bcd6feb4f5bdb5885633177 (patch) | |
tree | 602c996b1ca275cc5144447d2c14dfd8bd4e1aff /sound/soc/blackfin | |
parent | d2aae47f804830da904d2454d73959eda4ebb0fd (diff) |
ASoC: add i2s dai driver for bf6xx soc
This driver enables i2s mode support on blackfin bf6xx platform.
We reuse bf5xx-i2s-pcm.c as its i2s pcm driver because it's the same
for both bf5xx and bf6xx soc.
Signed-off-by: Scott Jiang <scott.jiang.linux@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/blackfin')
-rw-r--r-- | sound/soc/blackfin/Kconfig | 11 | ||||
-rw-r--r-- | sound/soc/blackfin/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/blackfin/bf6xx-i2s.c | 234 |
3 files changed, 244 insertions, 3 deletions
diff --git a/sound/soc/blackfin/Kconfig b/sound/soc/blackfin/Kconfig index 0374a3965095..16b88f5c26e2 100644 --- a/sound/soc/blackfin/Kconfig +++ b/sound/soc/blackfin/Kconfig | |||
@@ -10,12 +10,14 @@ config SND_BF5XX_I2S | |||
10 | You will also need to select the audio interfaces to support below. | 10 | You will also need to select the audio interfaces to support below. |
11 | 11 | ||
12 | config SND_BF5XX_SOC_SSM2602 | 12 | config SND_BF5XX_SOC_SSM2602 |
13 | tristate "SoC SSM2602 Audio support for BF52x ezkit" | 13 | tristate "SoC SSM2602 Audio Codec Add-On Card support" |
14 | depends on SND_BF5XX_I2S && (SPI_MASTER || I2C) | 14 | depends on SND_BF5XX_I2S && (SPI_MASTER || I2C) |
15 | select SND_BF5XX_SOC_I2S | 15 | select SND_BF5XX_SOC_I2S if !BF60x |
16 | select SND_BF6XX_SOC_I2S if BF60x | ||
16 | select SND_SOC_SSM2602 | 17 | select SND_SOC_SSM2602 |
17 | help | 18 | help |
18 | Say Y if you want to add support for SoC audio on BF527-EZKIT. | 19 | Say Y if you want to add support for the Analog Devices |
20 | SSM2602 Audio Codec Add-On Card. | ||
19 | 21 | ||
20 | config SND_SOC_BFIN_EVAL_ADAU1701 | 22 | config SND_SOC_BFIN_EVAL_ADAU1701 |
21 | tristate "Support for the EVAL-ADAU1701MINIZ board on Blackfin eval boards" | 23 | tristate "Support for the EVAL-ADAU1701MINIZ board on Blackfin eval boards" |
@@ -169,6 +171,9 @@ config SND_BF6XX_SOC_SPORT | |||
169 | config SND_BF5XX_SOC_I2S | 171 | config SND_BF5XX_SOC_I2S |
170 | tristate | 172 | tristate |
171 | 173 | ||
174 | config SND_BF6XX_SOC_I2S | ||
175 | tristate | ||
176 | |||
172 | config SND_BF5XX_SOC_TDM | 177 | config SND_BF5XX_SOC_TDM |
173 | tristate | 178 | tristate |
174 | 179 | ||
diff --git a/sound/soc/blackfin/Makefile b/sound/soc/blackfin/Makefile index 13b092239a82..6fea1f4cbee2 100644 --- a/sound/soc/blackfin/Makefile +++ b/sound/soc/blackfin/Makefile | |||
@@ -6,6 +6,7 @@ snd-soc-bf5xx-sport-objs := bf5xx-sport.o | |||
6 | snd-soc-bf6xx-sport-objs := bf6xx-sport.o | 6 | snd-soc-bf6xx-sport-objs := bf6xx-sport.o |
7 | snd-soc-bf5xx-ac97-objs := bf5xx-ac97.o | 7 | snd-soc-bf5xx-ac97-objs := bf5xx-ac97.o |
8 | snd-soc-bf5xx-i2s-objs := bf5xx-i2s.o | 8 | snd-soc-bf5xx-i2s-objs := bf5xx-i2s.o |
9 | snd-soc-bf6xx-i2s-objs := bf6xx-i2s.o | ||
9 | snd-soc-bf5xx-tdm-objs := bf5xx-tdm.o | 10 | snd-soc-bf5xx-tdm-objs := bf5xx-tdm.o |
10 | 11 | ||
11 | obj-$(CONFIG_SND_BF5XX_AC97) += snd-bf5xx-ac97.o | 12 | obj-$(CONFIG_SND_BF5XX_AC97) += snd-bf5xx-ac97.o |
@@ -15,6 +16,7 @@ obj-$(CONFIG_SND_BF5XX_SOC_SPORT) += snd-soc-bf5xx-sport.o | |||
15 | obj-$(CONFIG_SND_BF6XX_SOC_SPORT) += snd-soc-bf6xx-sport.o | 16 | obj-$(CONFIG_SND_BF6XX_SOC_SPORT) += snd-soc-bf6xx-sport.o |
16 | obj-$(CONFIG_SND_BF5XX_SOC_AC97) += snd-soc-bf5xx-ac97.o | 17 | obj-$(CONFIG_SND_BF5XX_SOC_AC97) += snd-soc-bf5xx-ac97.o |
17 | obj-$(CONFIG_SND_BF5XX_SOC_I2S) += snd-soc-bf5xx-i2s.o | 18 | obj-$(CONFIG_SND_BF5XX_SOC_I2S) += snd-soc-bf5xx-i2s.o |
19 | obj-$(CONFIG_SND_BF6XX_SOC_I2S) += snd-soc-bf6xx-i2s.o | ||
18 | obj-$(CONFIG_SND_BF5XX_SOC_TDM) += snd-soc-bf5xx-tdm.o | 20 | obj-$(CONFIG_SND_BF5XX_SOC_TDM) += snd-soc-bf5xx-tdm.o |
19 | 21 | ||
20 | # Blackfin Machine Support | 22 | # Blackfin Machine Support |
diff --git a/sound/soc/blackfin/bf6xx-i2s.c b/sound/soc/blackfin/bf6xx-i2s.c new file mode 100644 index 000000000000..c3c2466d3a42 --- /dev/null +++ b/sound/soc/blackfin/bf6xx-i2s.c | |||
@@ -0,0 +1,234 @@ | |||
1 | /* | ||
2 | * bf6xx-i2s.c - Analog Devices BF6XX i2s interface driver | ||
3 | * | ||
4 | * Copyright (c) 2012 Analog Devices Inc. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | */ | ||
19 | |||
20 | #include <linux/device.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <sound/pcm.h> | ||
25 | #include <sound/pcm_params.h> | ||
26 | #include <sound/soc.h> | ||
27 | #include <sound/soc-dai.h> | ||
28 | |||
29 | #include "bf6xx-sport.h" | ||
30 | |||
31 | struct sport_params param; | ||
32 | |||
33 | static int bfin_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, | ||
34 | unsigned int fmt) | ||
35 | { | ||
36 | struct sport_device *sport = snd_soc_dai_get_drvdata(cpu_dai); | ||
37 | struct device *dev = &sport->pdev->dev; | ||
38 | int ret = 0; | ||
39 | |||
40 | param.spctl &= ~(SPORT_CTL_OPMODE | SPORT_CTL_CKRE | SPORT_CTL_FSR | ||
41 | | SPORT_CTL_LFS | SPORT_CTL_LAFS); | ||
42 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
43 | case SND_SOC_DAIFMT_I2S: | ||
44 | param.spctl |= SPORT_CTL_OPMODE | SPORT_CTL_CKRE | ||
45 | | SPORT_CTL_LFS; | ||
46 | break; | ||
47 | case SND_SOC_DAIFMT_DSP_A: | ||
48 | param.spctl |= SPORT_CTL_FSR; | ||
49 | break; | ||
50 | case SND_SOC_DAIFMT_LEFT_J: | ||
51 | param.spctl |= SPORT_CTL_OPMODE | SPORT_CTL_LFS | ||
52 | | SPORT_CTL_LAFS; | ||
53 | break; | ||
54 | default: | ||
55 | dev_err(dev, "%s: Unknown DAI format type\n", __func__); | ||
56 | ret = -EINVAL; | ||
57 | break; | ||
58 | } | ||
59 | |||
60 | param.spctl &= ~(SPORT_CTL_ICLK | SPORT_CTL_IFS); | ||
61 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
62 | case SND_SOC_DAIFMT_CBM_CFM: | ||
63 | break; | ||
64 | case SND_SOC_DAIFMT_CBS_CFS: | ||
65 | case SND_SOC_DAIFMT_CBM_CFS: | ||
66 | case SND_SOC_DAIFMT_CBS_CFM: | ||
67 | ret = -EINVAL; | ||
68 | break; | ||
69 | default: | ||
70 | dev_err(dev, "%s: Unknown DAI master type\n", __func__); | ||
71 | ret = -EINVAL; | ||
72 | break; | ||
73 | } | ||
74 | |||
75 | return ret; | ||
76 | } | ||
77 | |||
78 | static int bfin_i2s_hw_params(struct snd_pcm_substream *substream, | ||
79 | struct snd_pcm_hw_params *params, | ||
80 | struct snd_soc_dai *dai) | ||
81 | { | ||
82 | struct sport_device *sport = snd_soc_dai_get_drvdata(dai); | ||
83 | struct device *dev = &sport->pdev->dev; | ||
84 | int ret = 0; | ||
85 | |||
86 | param.spctl &= ~SPORT_CTL_SLEN; | ||
87 | switch (params_format(params)) { | ||
88 | case SNDRV_PCM_FORMAT_S8: | ||
89 | param.spctl |= 0x70; | ||
90 | sport->wdsize = 1; | ||
91 | case SNDRV_PCM_FORMAT_S16_LE: | ||
92 | param.spctl |= 0xf0; | ||
93 | sport->wdsize = 2; | ||
94 | break; | ||
95 | case SNDRV_PCM_FORMAT_S24_LE: | ||
96 | param.spctl |= 0x170; | ||
97 | sport->wdsize = 3; | ||
98 | break; | ||
99 | case SNDRV_PCM_FORMAT_S32_LE: | ||
100 | param.spctl |= 0x1f0; | ||
101 | sport->wdsize = 4; | ||
102 | break; | ||
103 | } | ||
104 | |||
105 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
106 | ret = sport_set_tx_params(sport, ¶m); | ||
107 | if (ret) { | ||
108 | dev_err(dev, "SPORT tx is busy!\n"); | ||
109 | return ret; | ||
110 | } | ||
111 | } else { | ||
112 | ret = sport_set_rx_params(sport, ¶m); | ||
113 | if (ret) { | ||
114 | dev_err(dev, "SPORT rx is busy!\n"); | ||
115 | return ret; | ||
116 | } | ||
117 | } | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | #ifdef CONFIG_PM | ||
122 | static int bfin_i2s_suspend(struct snd_soc_dai *dai) | ||
123 | { | ||
124 | struct sport_device *sport = snd_soc_dai_get_drvdata(dai); | ||
125 | |||
126 | if (dai->capture_active) | ||
127 | sport_rx_stop(sport); | ||
128 | if (dai->playback_active) | ||
129 | sport_tx_stop(sport); | ||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | static int bfin_i2s_resume(struct snd_soc_dai *dai) | ||
134 | { | ||
135 | struct sport_device *sport = snd_soc_dai_get_drvdata(dai); | ||
136 | struct device *dev = &sport->pdev->dev; | ||
137 | int ret; | ||
138 | |||
139 | ret = sport_set_tx_params(sport, ¶m); | ||
140 | if (ret) { | ||
141 | dev_err(dev, "SPORT tx is busy!\n"); | ||
142 | return ret; | ||
143 | } | ||
144 | ret = sport_set_rx_params(sport, ¶m); | ||
145 | if (ret) { | ||
146 | dev_err(dev, "SPORT rx is busy!\n"); | ||
147 | return ret; | ||
148 | } | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | #else | ||
154 | #define bfin_i2s_suspend NULL | ||
155 | #define bfin_i2s_resume NULL | ||
156 | #endif | ||
157 | |||
158 | #define BFIN_I2S_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ | ||
159 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ | ||
160 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | \ | ||
161 | SNDRV_PCM_RATE_96000) | ||
162 | |||
163 | #define BFIN_I2S_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \ | ||
164 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | ||
165 | |||
166 | static struct snd_soc_dai_ops bfin_i2s_dai_ops = { | ||
167 | .hw_params = bfin_i2s_hw_params, | ||
168 | .set_fmt = bfin_i2s_set_dai_fmt, | ||
169 | }; | ||
170 | |||
171 | static struct snd_soc_dai_driver bfin_i2s_dai = { | ||
172 | .suspend = bfin_i2s_suspend, | ||
173 | .resume = bfin_i2s_resume, | ||
174 | .playback = { | ||
175 | .channels_min = 1, | ||
176 | .channels_max = 2, | ||
177 | .rates = BFIN_I2S_RATES, | ||
178 | .formats = BFIN_I2S_FORMATS, | ||
179 | }, | ||
180 | .capture = { | ||
181 | .channels_min = 1, | ||
182 | .channels_max = 2, | ||
183 | .rates = BFIN_I2S_RATES, | ||
184 | .formats = BFIN_I2S_FORMATS, | ||
185 | }, | ||
186 | .ops = &bfin_i2s_dai_ops, | ||
187 | }; | ||
188 | |||
189 | static int __devinit bfin_i2s_probe(struct platform_device *pdev) | ||
190 | { | ||
191 | struct sport_device *sport; | ||
192 | struct device *dev = &pdev->dev; | ||
193 | int ret; | ||
194 | |||
195 | sport = sport_create(pdev); | ||
196 | if (!sport) | ||
197 | return -ENODEV; | ||
198 | |||
199 | /* register with the ASoC layers */ | ||
200 | ret = snd_soc_register_dai(dev, &bfin_i2s_dai); | ||
201 | if (ret) { | ||
202 | dev_err(dev, "Failed to register DAI: %d\n", ret); | ||
203 | sport_delete(sport); | ||
204 | return ret; | ||
205 | } | ||
206 | platform_set_drvdata(pdev, sport); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static int __devexit bfin_i2s_remove(struct platform_device *pdev) | ||
212 | { | ||
213 | struct sport_device *sport = platform_get_drvdata(pdev); | ||
214 | |||
215 | snd_soc_unregister_dai(&pdev->dev); | ||
216 | sport_delete(sport); | ||
217 | |||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static struct platform_driver bfin_i2s_driver = { | ||
222 | .probe = bfin_i2s_probe, | ||
223 | .remove = __devexit_p(bfin_i2s_remove), | ||
224 | .driver = { | ||
225 | .name = "bfin-i2s", | ||
226 | .owner = THIS_MODULE, | ||
227 | }, | ||
228 | }; | ||
229 | |||
230 | module_platform_driver(bfin_i2s_driver); | ||
231 | |||
232 | MODULE_DESCRIPTION("Analog Devices BF6XX i2s interface driver"); | ||
233 | MODULE_AUTHOR("Scott Jiang <Scott.Jiang.Linux@gmail.com>"); | ||
234 | MODULE_LICENSE("GPL v2"); | ||