2 * sdp4430.c -- SoC audio for TI OMAP4430 SDP
4 * Author: Misael Lopez Cruz <x0052729@ti.com>
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.
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.
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
22 #include <linux/clk.h>
23 #include <linux/platform_device.h>
24 #include <linux/mfd/twl6040.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/soc.h>
29 #include <sound/jack.h>
31 #include <asm/mach-types.h>
32 #include <plat/hardware.h>
35 #include "omap-mcpdm.h"
37 #include "../codecs/twl6040.h"
39 static int sdp4430_hw_params(struct snd_pcm_substream *substream,
40 struct snd_pcm_hw_params *params)
42 struct snd_soc_pcm_runtime *rtd = substream->private_data;
43 struct snd_soc_dai *codec_dai = rtd->codec_dai;
47 clk_id = twl6040_get_clk_id(rtd->codec);
48 if (clk_id == TWL6040_SYSCLK_SEL_HPPLL)
50 else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL)
55 /* set the codec mclk */
56 ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
59 printk(KERN_ERR "can't set codec system clock\n");
65 static struct snd_soc_ops sdp4430_ops = {
66 .hw_params = sdp4430_hw_params,
70 static struct snd_soc_jack hs_jack;
72 /*Headset jack detection DAPM pins */
73 static struct snd_soc_jack_pin hs_jack_pins[] = {
76 .mask = SND_JACK_MICROPHONE,
79 .pin = "Headset Stereophone",
80 .mask = SND_JACK_HEADPHONE,
84 /* SDP4430 machine DAPM */
85 static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
86 SND_SOC_DAPM_MIC("Ext Mic", NULL),
87 SND_SOC_DAPM_SPK("Ext Spk", NULL),
88 SND_SOC_DAPM_MIC("Headset Mic", NULL),
89 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
90 SND_SOC_DAPM_SPK("Earphone Spk", NULL),
91 SND_SOC_DAPM_INPUT("FM Stereo In"),
94 static const struct snd_soc_dapm_route audio_map[] = {
95 /* External Mics: MAINMIC, SUBMIC with bias*/
96 {"MAINMIC", NULL, "Main Mic Bias"},
97 {"SUBMIC", NULL, "Main Mic Bias"},
98 {"Main Mic Bias", NULL, "Ext Mic"},
100 /* External Speakers: HFL, HFR */
101 {"Ext Spk", NULL, "HFL"},
102 {"Ext Spk", NULL, "HFR"},
104 /* Headset Mic: HSMIC with bias */
105 {"HSMIC", NULL, "Headset Mic Bias"},
106 {"Headset Mic Bias", NULL, "Headset Mic"},
108 /* Headset Stereophone (Headphone): HSOL, HSOR */
109 {"Headset Stereophone", NULL, "HSOL"},
110 {"Headset Stereophone", NULL, "HSOR"},
112 /* Earphone speaker */
113 {"Earphone Spk", NULL, "EP"},
115 /* Aux/FM Stereo In: AFML, AFMR */
116 {"AFML", NULL, "FM Stereo In"},
117 {"AFMR", NULL, "FM Stereo In"},
120 static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
122 struct snd_soc_codec *codec = rtd->codec;
126 * Configure McPDM offset cancellation based on the HSOTRIM value from
129 hs_trim = twl6040_get_trim_value(codec, TWL6040_TRIM_HSOTRIM);
130 omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim),
131 TWL6040_HSF_TRIM_RIGHT(hs_trim));
133 /* Headset jack detection */
134 ret = snd_soc_jack_new(codec, "Headset Jack",
135 SND_JACK_HEADSET, &hs_jack);
139 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
142 if (machine_is_omap_4430sdp())
143 twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
145 snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET);
150 /* Digital audio interface glue - connects codec <--> CPU */
151 static struct snd_soc_dai_link sdp4430_dai = {
153 .stream_name = "TWL6040",
154 .cpu_dai_name = "omap-mcpdm",
155 .codec_dai_name = "twl6040-legacy",
156 .platform_name = "omap-pcm-audio",
157 .codec_name = "twl6040-codec",
158 .init = sdp4430_twl6040_init,
162 /* Audio machine driver */
163 static struct snd_soc_card snd_soc_sdp4430 = {
165 .dai_link = &sdp4430_dai,
168 .dapm_widgets = sdp4430_twl6040_dapm_widgets,
169 .num_dapm_widgets = ARRAY_SIZE(sdp4430_twl6040_dapm_widgets),
170 .dapm_routes = audio_map,
171 .num_dapm_routes = ARRAY_SIZE(audio_map),
174 static struct platform_device *sdp4430_snd_device;
176 static int __init sdp4430_soc_init(void)
180 if (!machine_is_omap_4430sdp())
182 printk(KERN_INFO "SDP4430 SoC init\n");
184 sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
185 if (!sdp4430_snd_device) {
186 printk(KERN_ERR "Platform device allocation failed\n");
190 platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
192 ret = platform_device_add(sdp4430_snd_device);
199 printk(KERN_ERR "Unable to add platform device\n");
200 platform_device_put(sdp4430_snd_device);
203 module_init(sdp4430_soc_init);
205 static void __exit sdp4430_soc_exit(void)
207 platform_device_unregister(sdp4430_snd_device);
209 module_exit(sdp4430_soc_exit);
211 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
212 MODULE_DESCRIPTION("ALSA SoC SDP4430");
213 MODULE_LICENSE("GPL");