diff options
Diffstat (limited to 'sound/soc')
-rw-r--r-- | sound/soc/omap/Kconfig | 8 | ||||
-rw-r--r-- | sound/soc/omap/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/omap/osk5912.c | 232 |
3 files changed, 242 insertions, 0 deletions
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig index aea27e70043c..8b7766b998d7 100644 --- a/sound/soc/omap/Kconfig +++ b/sound/soc/omap/Kconfig | |||
@@ -13,3 +13,11 @@ config SND_OMAP_SOC_N810 | |||
13 | select SND_SOC_TLV320AIC3X | 13 | select SND_SOC_TLV320AIC3X |
14 | help | 14 | help |
15 | Say Y if you want to add support for SoC audio on Nokia N810. | 15 | Say Y if you want to add support for SoC audio on Nokia N810. |
16 | |||
17 | config SND_OMAP_SOC_OSK5912 | ||
18 | tristate "SoC Audio support for omap osk5912" | ||
19 | depends on SND_OMAP_SOC && MACH_OMAP_OSK | ||
20 | select SND_OMAP_SOC_MCBSP | ||
21 | select SND_SOC_TLV320AIC23 | ||
22 | help | ||
23 | Say Y if you want to add support for SoC audio on osk5912. | ||
diff --git a/sound/soc/omap/Makefile b/sound/soc/omap/Makefile index d8d8d58075e3..e09d1f297f64 100644 --- a/sound/soc/omap/Makefile +++ b/sound/soc/omap/Makefile | |||
@@ -7,5 +7,7 @@ obj-$(CONFIG_SND_OMAP_SOC_MCBSP) += snd-soc-omap-mcbsp.o | |||
7 | 7 | ||
8 | # OMAP Machine Support | 8 | # OMAP Machine Support |
9 | snd-soc-n810-objs := n810.o | 9 | snd-soc-n810-objs := n810.o |
10 | snd-soc-osk5912-objs := osk5912.o | ||
10 | 11 | ||
11 | obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o | 12 | obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o |
13 | obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o | ||
diff --git a/sound/soc/omap/osk5912.c b/sound/soc/omap/osk5912.c new file mode 100644 index 000000000000..0fe733796898 --- /dev/null +++ b/sound/soc/omap/osk5912.c | |||
@@ -0,0 +1,232 @@ | |||
1 | /* | ||
2 | * osk5912.c -- SoC audio for OSK 5912 | ||
3 | * | ||
4 | * Copyright (C) 2008 Mistral Solutions | ||
5 | * | ||
6 | * Contact: Arun KS <arunks@mistralsolutions.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * version 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
20 | * 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/clk.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <sound/core.h> | ||
27 | #include <sound/pcm.h> | ||
28 | #include <sound/soc.h> | ||
29 | #include <sound/soc-dapm.h> | ||
30 | |||
31 | #include <asm/mach-types.h> | ||
32 | #include <mach/hardware.h> | ||
33 | #include <linux/gpio.h> | ||
34 | #include <mach/mcbsp.h> | ||
35 | |||
36 | #include "omap-mcbsp.h" | ||
37 | #include "omap-pcm.h" | ||
38 | #include "../codecs/tlv320aic23.h" | ||
39 | |||
40 | #define CODEC_CLOCK 12000000 | ||
41 | |||
42 | static struct clk *tlv320aic23_mclk; | ||
43 | |||
44 | static int osk_startup(struct snd_pcm_substream *substream) | ||
45 | { | ||
46 | return clk_enable(tlv320aic23_mclk); | ||
47 | } | ||
48 | |||
49 | static void osk_shutdown(struct snd_pcm_substream *substream) | ||
50 | { | ||
51 | clk_disable(tlv320aic23_mclk); | ||
52 | } | ||
53 | |||
54 | static int osk_hw_params(struct snd_pcm_substream *substream, | ||
55 | struct snd_pcm_hw_params *params) | ||
56 | { | ||
57 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
58 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | ||
59 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | ||
60 | int err; | ||
61 | |||
62 | /* Set codec DAI configuration */ | ||
63 | err = snd_soc_dai_set_fmt(codec_dai, | ||
64 | SND_SOC_DAIFMT_DSP_A | | ||
65 | SND_SOC_DAIFMT_NB_IF | | ||
66 | SND_SOC_DAIFMT_CBM_CFM); | ||
67 | if (err < 0) { | ||
68 | printk(KERN_ERR "can't set codec DAI configuration\n"); | ||
69 | return err; | ||
70 | } | ||
71 | |||
72 | /* Set cpu DAI configuration */ | ||
73 | err = snd_soc_dai_set_fmt(cpu_dai, | ||
74 | SND_SOC_DAIFMT_DSP_A | | ||
75 | SND_SOC_DAIFMT_NB_IF | | ||
76 | SND_SOC_DAIFMT_CBM_CFM); | ||
77 | if (err < 0) { | ||
78 | printk(KERN_ERR "can't set cpu DAI configuration\n"); | ||
79 | return err; | ||
80 | } | ||
81 | |||
82 | /* Set the codec system clock for DAC and ADC */ | ||
83 | err = | ||
84 | snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN); | ||
85 | |||
86 | if (err < 0) { | ||
87 | printk(KERN_ERR "can't set codec system clock\n"); | ||
88 | return err; | ||
89 | } | ||
90 | |||
91 | return err; | ||
92 | } | ||
93 | |||
94 | static struct snd_soc_ops osk_ops = { | ||
95 | .startup = osk_startup, | ||
96 | .hw_params = osk_hw_params, | ||
97 | .shutdown = osk_shutdown, | ||
98 | }; | ||
99 | |||
100 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { | ||
101 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
102 | SND_SOC_DAPM_LINE("Line In", NULL), | ||
103 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | ||
104 | }; | ||
105 | |||
106 | static const struct snd_soc_dapm_route audio_map[] = { | ||
107 | {"Headphone Jack", NULL, "LHPOUT"}, | ||
108 | {"Headphone Jack", NULL, "RHPOUT"}, | ||
109 | |||
110 | {"LLINEIN", NULL, "Line In"}, | ||
111 | {"RLINEIN", NULL, "Line In"}, | ||
112 | |||
113 | {"MICIN", NULL, "Mic Jack"}, | ||
114 | }; | ||
115 | |||
116 | static int osk_tlv320aic23_init(struct snd_soc_codec *codec) | ||
117 | { | ||
118 | |||
119 | /* Add osk5912 specific widgets */ | ||
120 | snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, | ||
121 | ARRAY_SIZE(tlv320aic23_dapm_widgets)); | ||
122 | |||
123 | /* Set up osk5912 specific audio path audio_map */ | ||
124 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
125 | |||
126 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); | ||
127 | snd_soc_dapm_enable_pin(codec, "Line In"); | ||
128 | snd_soc_dapm_enable_pin(codec, "Mic Jack"); | ||
129 | |||
130 | snd_soc_dapm_sync(codec); | ||
131 | |||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | /* Digital audio interface glue - connects codec <--> CPU */ | ||
136 | static struct snd_soc_dai_link osk_dai = { | ||
137 | .name = "TLV320AIC23", | ||
138 | .stream_name = "AIC23", | ||
139 | .cpu_dai = &omap_mcbsp_dai[0], | ||
140 | .codec_dai = &tlv320aic23_dai, | ||
141 | .init = osk_tlv320aic23_init, | ||
142 | .ops = &osk_ops, | ||
143 | }; | ||
144 | |||
145 | /* Audio machine driver */ | ||
146 | static struct snd_soc_machine snd_soc_machine_osk = { | ||
147 | .name = "OSK5912", | ||
148 | .dai_link = &osk_dai, | ||
149 | .num_links = 1, | ||
150 | }; | ||
151 | |||
152 | /* Audio subsystem */ | ||
153 | static struct snd_soc_device osk_snd_devdata = { | ||
154 | .machine = &snd_soc_machine_osk, | ||
155 | .platform = &omap_soc_platform, | ||
156 | .codec_dev = &soc_codec_dev_tlv320aic23, | ||
157 | }; | ||
158 | |||
159 | static struct platform_device *osk_snd_device; | ||
160 | |||
161 | static int __init osk_soc_init(void) | ||
162 | { | ||
163 | int err; | ||
164 | u32 curRate; | ||
165 | struct device *dev; | ||
166 | |||
167 | if (!(machine_is_omap_osk())) | ||
168 | return -ENODEV; | ||
169 | |||
170 | osk_snd_device = platform_device_alloc("soc-audio", -1); | ||
171 | if (!osk_snd_device) | ||
172 | return -ENOMEM; | ||
173 | |||
174 | platform_set_drvdata(osk_snd_device, &osk_snd_devdata); | ||
175 | osk_snd_devdata.dev = &osk_snd_device->dev; | ||
176 | *(unsigned int *)osk_dai.cpu_dai->private_data = 0; /* McBSP1 */ | ||
177 | err = platform_device_add(osk_snd_device); | ||
178 | if (err) | ||
179 | goto err1; | ||
180 | |||
181 | dev = &osk_snd_device->dev; | ||
182 | |||
183 | tlv320aic23_mclk = clk_get(dev, "mclk"); | ||
184 | if (IS_ERR(tlv320aic23_mclk)) { | ||
185 | printk(KERN_ERR "Could not get mclk clock\n"); | ||
186 | return -ENODEV; | ||
187 | } | ||
188 | |||
189 | if (clk_get_usecount(tlv320aic23_mclk) > 0) { | ||
190 | /* MCLK is already in use */ | ||
191 | printk(KERN_WARNING | ||
192 | "MCLK in use at %d Hz. We change it to %d Hz\n", | ||
193 | (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK); | ||
194 | } | ||
195 | |||
196 | /* | ||
197 | * Configure 12 MHz output on MCLK. | ||
198 | */ | ||
199 | curRate = (uint) clk_get_rate(tlv320aic23_mclk); | ||
200 | if (curRate != CODEC_CLOCK) { | ||
201 | if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) { | ||
202 | printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n"); | ||
203 | err = -ECANCELED; | ||
204 | goto err1; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | printk(KERN_INFO "MCLK = %d [%d], usecount = %d\n", | ||
209 | (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK, | ||
210 | clk_get_usecount(tlv320aic23_mclk)); | ||
211 | |||
212 | return 0; | ||
213 | err1: | ||
214 | clk_put(tlv320aic23_mclk); | ||
215 | platform_device_del(osk_snd_device); | ||
216 | platform_device_put(osk_snd_device); | ||
217 | |||
218 | return err; | ||
219 | |||
220 | } | ||
221 | |||
222 | static void __exit osk_soc_exit(void) | ||
223 | { | ||
224 | platform_device_unregister(osk_snd_device); | ||
225 | } | ||
226 | |||
227 | module_init(osk_soc_init); | ||
228 | module_exit(osk_soc_exit); | ||
229 | |||
230 | MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); | ||
231 | MODULE_DESCRIPTION("ALSA SoC OSK 5912"); | ||
232 | MODULE_LICENSE("GPL"); | ||