diff options
Diffstat (limited to 'sound/soc/omap/sdp4430.c')
-rw-r--r-- | sound/soc/omap/sdp4430.c | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/sound/soc/omap/sdp4430.c b/sound/soc/omap/sdp4430.c new file mode 100644 index 000000000000..83831ee35d07 --- /dev/null +++ b/sound/soc/omap/sdp4430.c | |||
@@ -0,0 +1,228 @@ | |||
1 | /* | ||
2 | * sdp4430.c -- SoC audio for TI OMAP4430 SDP | ||
3 | * | ||
4 | * Author: Misael Lopez Cruz <x0052729@ti.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * version 2 as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * 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., 51 Franklin St, Fifth Floor, Boston, MA | ||
18 | * 02110-1301 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/clk.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <sound/core.h> | ||
25 | #include <sound/pcm.h> | ||
26 | #include <sound/soc.h> | ||
27 | #include <sound/soc-dapm.h> | ||
28 | |||
29 | #include <asm/mach-types.h> | ||
30 | #include <plat/hardware.h> | ||
31 | #include <plat/mux.h> | ||
32 | |||
33 | #include "mcpdm.h" | ||
34 | #include "omap-mcpdm.h" | ||
35 | #include "omap-pcm.h" | ||
36 | #include "../codecs/twl6040.h" | ||
37 | |||
38 | static int twl6040_power_mode; | ||
39 | |||
40 | static int sdp4430_hw_params(struct snd_pcm_substream *substream, | ||
41 | struct snd_pcm_hw_params *params) | ||
42 | { | ||
43 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
44 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | ||
45 | int clk_id, freq; | ||
46 | int ret; | ||
47 | |||
48 | if (twl6040_power_mode) { | ||
49 | clk_id = TWL6040_SYSCLK_SEL_HPPLL; | ||
50 | freq = 38400000; | ||
51 | } else { | ||
52 | clk_id = TWL6040_SYSCLK_SEL_LPPLL; | ||
53 | freq = 32768; | ||
54 | } | ||
55 | |||
56 | /* set the codec mclk */ | ||
57 | ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq, | ||
58 | SND_SOC_CLOCK_IN); | ||
59 | if (ret) { | ||
60 | printk(KERN_ERR "can't set codec system clock\n"); | ||
61 | return ret; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | static struct snd_soc_ops sdp4430_ops = { | ||
66 | .hw_params = sdp4430_hw_params, | ||
67 | }; | ||
68 | |||
69 | static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol, | ||
70 | struct snd_ctl_elem_value *ucontrol) | ||
71 | { | ||
72 | ucontrol->value.integer.value[0] = twl6040_power_mode; | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | static int sdp4430_set_power_mode(struct snd_kcontrol *kcontrol, | ||
77 | struct snd_ctl_elem_value *ucontrol) | ||
78 | { | ||
79 | if (twl6040_power_mode == ucontrol->value.integer.value[0]) | ||
80 | return 0; | ||
81 | |||
82 | twl6040_power_mode = ucontrol->value.integer.value[0]; | ||
83 | |||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | static const char *power_texts[] = {"Low-Power", "High-Performance"}; | ||
88 | |||
89 | static const struct soc_enum sdp4430_enum[] = { | ||
90 | SOC_ENUM_SINGLE_EXT(2, power_texts), | ||
91 | }; | ||
92 | |||
93 | static const struct snd_kcontrol_new sdp4430_controls[] = { | ||
94 | SOC_ENUM_EXT("TWL6040 Power Mode", sdp4430_enum[0], | ||
95 | sdp4430_get_power_mode, sdp4430_set_power_mode), | ||
96 | }; | ||
97 | |||
98 | /* SDP4430 machine DAPM */ | ||
99 | static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = { | ||
100 | SND_SOC_DAPM_MIC("Ext Mic", NULL), | ||
101 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | ||
102 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | ||
103 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | ||
104 | }; | ||
105 | |||
106 | static const struct snd_soc_dapm_route audio_map[] = { | ||
107 | /* External Mics: MAINMIC, SUBMIC with bias*/ | ||
108 | {"MAINMIC", NULL, "Main Mic Bias"}, | ||
109 | {"SUBMIC", NULL, "Main Mic Bias"}, | ||
110 | {"Main Mic Bias", NULL, "Ext Mic"}, | ||
111 | |||
112 | /* External Speakers: HFL, HFR */ | ||
113 | {"Ext Spk", NULL, "HFL"}, | ||
114 | {"Ext Spk", NULL, "HFR"}, | ||
115 | |||
116 | /* Headset Mic: HSMIC with bias */ | ||
117 | {"HSMIC", NULL, "Headset Mic Bias"}, | ||
118 | {"Headset Mic Bias", NULL, "Headset Mic"}, | ||
119 | |||
120 | /* Headset Stereophone (Headphone): HSOL, HSOR */ | ||
121 | {"Headset Stereophone", NULL, "HSOL"}, | ||
122 | {"Headset Stereophone", NULL, "HSOR"}, | ||
123 | }; | ||
124 | |||
125 | static int sdp4430_twl6040_init(struct snd_soc_codec *codec) | ||
126 | { | ||
127 | int ret; | ||
128 | |||
129 | /* Add SDP4430 specific controls */ | ||
130 | ret = snd_soc_add_controls(codec, sdp4430_controls, | ||
131 | ARRAY_SIZE(sdp4430_controls)); | ||
132 | if (ret) | ||
133 | return ret; | ||
134 | |||
135 | /* Add SDP4430 specific widgets */ | ||
136 | ret = snd_soc_dapm_new_controls(codec, sdp4430_twl6040_dapm_widgets, | ||
137 | ARRAY_SIZE(sdp4430_twl6040_dapm_widgets)); | ||
138 | if (ret) | ||
139 | return ret; | ||
140 | |||
141 | /* Set up SDP4430 specific audio path audio_map */ | ||
142 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
143 | |||
144 | /* SDP4430 connected pins */ | ||
145 | snd_soc_dapm_enable_pin(codec, "Ext Mic"); | ||
146 | snd_soc_dapm_enable_pin(codec, "Ext Spk"); | ||
147 | snd_soc_dapm_enable_pin(codec, "Headset Mic"); | ||
148 | snd_soc_dapm_enable_pin(codec, "Headset Stereophone"); | ||
149 | |||
150 | /* TWL6040 not connected pins */ | ||
151 | snd_soc_dapm_nc_pin(codec, "AFML"); | ||
152 | snd_soc_dapm_nc_pin(codec, "AFMR"); | ||
153 | |||
154 | ret = snd_soc_dapm_sync(codec); | ||
155 | |||
156 | return ret; | ||
157 | } | ||
158 | |||
159 | /* Digital audio interface glue - connects codec <--> CPU */ | ||
160 | static struct snd_soc_dai_link sdp4430_dai = { | ||
161 | .name = "TWL6040", | ||
162 | .stream_name = "TWL6040", | ||
163 | .cpu_dai = &omap_mcpdm_dai, | ||
164 | .codec_dai = &twl6040_dai, | ||
165 | .init = sdp4430_twl6040_init, | ||
166 | }; | ||
167 | |||
168 | /* Audio machine driver */ | ||
169 | static struct snd_soc_card snd_soc_sdp4430 = { | ||
170 | .name = "SDP4430", | ||
171 | .platform = &omap_soc_platform, | ||
172 | .dai_link = &sdp4430_dai, | ||
173 | .num_links = 1, | ||
174 | }; | ||
175 | |||
176 | /* Audio subsystem */ | ||
177 | static struct snd_soc_device sdp4430_snd_devdata = { | ||
178 | .card = &snd_soc_sdp4430, | ||
179 | .codec_dev = &soc_codec_dev_twl6040, | ||
180 | }; | ||
181 | |||
182 | static struct platform_device *sdp4430_snd_device; | ||
183 | |||
184 | static int __init sdp4430_soc_init(void) | ||
185 | { | ||
186 | int ret; | ||
187 | |||
188 | if (!machine_is_omap_4430sdp()) { | ||
189 | pr_debug("Not SDP4430!\n"); | ||
190 | return -ENODEV; | ||
191 | } | ||
192 | printk(KERN_INFO "SDP4430 SoC init\n"); | ||
193 | |||
194 | sdp4430_snd_device = platform_device_alloc("soc-audio", -1); | ||
195 | if (!sdp4430_snd_device) { | ||
196 | printk(KERN_ERR "Platform device allocation failed\n"); | ||
197 | return -ENOMEM; | ||
198 | } | ||
199 | |||
200 | platform_set_drvdata(sdp4430_snd_device, &sdp4430_snd_devdata); | ||
201 | sdp4430_snd_devdata.dev = &sdp4430_snd_device->dev; | ||
202 | |||
203 | ret = platform_device_add(sdp4430_snd_device); | ||
204 | if (ret) | ||
205 | goto err; | ||
206 | |||
207 | /* Codec starts in HP mode */ | ||
208 | twl6040_power_mode = 1; | ||
209 | |||
210 | return 0; | ||
211 | |||
212 | err: | ||
213 | printk(KERN_ERR "Unable to add platform device\n"); | ||
214 | platform_device_put(sdp4430_snd_device); | ||
215 | return ret; | ||
216 | } | ||
217 | module_init(sdp4430_soc_init); | ||
218 | |||
219 | static void __exit sdp4430_soc_exit(void) | ||
220 | { | ||
221 | platform_device_unregister(sdp4430_snd_device); | ||
222 | } | ||
223 | module_exit(sdp4430_soc_exit); | ||
224 | |||
225 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); | ||
226 | MODULE_DESCRIPTION("ALSA SoC SDP4430"); | ||
227 | MODULE_LICENSE("GPL"); | ||
228 | |||