blob: 249d84b705fc321fe287053f039438aead13090e [file] [log] [blame]
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -05001/*
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>
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -050024#include <linux/mfd/twl6040.h>
25
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050026#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/soc.h>
Jorge Eduardo Candelaria96dc2272010-12-10 20:45:19 -060029#include <sound/jack.h>
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050030
31#include <asm/mach-types.h>
32#include <plat/hardware.h>
33#include <plat/mux.h>
34
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030035#include "omap-mcpdm.h"
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050036#include "omap-pcm.h"
37#include "../codecs/twl6040.h"
38
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050039static int sdp4430_hw_params(struct snd_pcm_substream *substream,
40 struct snd_pcm_hw_params *params)
41{
42 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000043 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050044 int clk_id, freq;
45 int ret;
46
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030047 clk_id = twl6040_get_clk_id(rtd->codec);
48 if (clk_id == TWL6040_SYSCLK_SEL_HPPLL)
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050049 freq = 38400000;
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030050 else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL)
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050051 freq = 32768;
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030052 else
53 return -EINVAL;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050054
55 /* set the codec mclk */
56 ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
57 SND_SOC_CLOCK_IN);
58 if (ret) {
59 printk(KERN_ERR "can't set codec system clock\n");
60 return ret;
61 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000062 return ret;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050063}
64
65static struct snd_soc_ops sdp4430_ops = {
66 .hw_params = sdp4430_hw_params,
67};
68
Jorge Eduardo Candelaria96dc2272010-12-10 20:45:19 -060069/* Headset jack */
70static struct snd_soc_jack hs_jack;
71
72/*Headset jack detection DAPM pins */
73static struct snd_soc_jack_pin hs_jack_pins[] = {
74 {
75 .pin = "Headset Mic",
76 .mask = SND_JACK_MICROPHONE,
77 },
78 {
79 .pin = "Headset Stereophone",
80 .mask = SND_JACK_HEADPHONE,
81 },
82};
83
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050084/* SDP4430 machine DAPM */
85static 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),
Jorge Eduardo Candelaria7254e2b2010-05-18 12:44:17 -050090 SND_SOC_DAPM_SPK("Earphone Spk", NULL),
Jorge Eduardo Candelaria23ac3b62010-12-08 10:55:05 -060091 SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -050092};
93
94static 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"},
99
100 /* External Speakers: HFL, HFR */
101 {"Ext Spk", NULL, "HFL"},
102 {"Ext Spk", NULL, "HFR"},
103
104 /* Headset Mic: HSMIC with bias */
105 {"HSMIC", NULL, "Headset Mic Bias"},
106 {"Headset Mic Bias", NULL, "Headset Mic"},
107
108 /* Headset Stereophone (Headphone): HSOL, HSOR */
109 {"Headset Stereophone", NULL, "HSOL"},
110 {"Headset Stereophone", NULL, "HSOR"},
Jorge Eduardo Candelaria7254e2b2010-05-18 12:44:17 -0500111
112 /* Earphone speaker */
113 {"Earphone Spk", NULL, "EP"},
Jorge Eduardo Candelaria23ac3b62010-12-08 10:55:05 -0600114
115 /* Aux/FM Stereo In: AFML, AFMR */
116 {"AFML", NULL, "Aux/FM Stereo In"},
117 {"AFMR", NULL, "Aux/FM Stereo In"},
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500118};
119
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000120static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500121{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000122 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200123 struct snd_soc_dapm_context *dapm = &codec->dapm;
Peter Ujfalusi7bf3d922011-09-26 16:05:59 +0300124 int ret, hs_trim;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500125
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500126 /* Add SDP4430 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200127 ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500128 ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
129 if (ret)
130 return ret;
131
132 /* Set up SDP4430 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200133 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500134
135 /* SDP4430 connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200136 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
137 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
Jorge Eduardo Candelaria23ac3b62010-12-08 10:55:05 -0600138 snd_soc_dapm_enable_pin(dapm, "AFML");
139 snd_soc_dapm_enable_pin(dapm, "AFMR");
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200140 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
141 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500142
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200143 ret = snd_soc_dapm_sync(dapm);
Jorge Eduardo Candelaria96dc2272010-12-10 20:45:19 -0600144 if (ret)
145 return ret;
146
Peter Ujfalusi7bf3d922011-09-26 16:05:59 +0300147 /*
148 * Configure McPDM offset cancellation based on the HSOTRIM value from
149 * twl6040.
150 */
151 hs_trim = twl6040_get_trim_value(codec, TWL6040_TRIM_HSOTRIM);
152 omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim),
153 TWL6040_HSF_TRIM_RIGHT(hs_trim));
154
Jorge Eduardo Candelaria96dc2272010-12-10 20:45:19 -0600155 /* Headset jack detection */
156 ret = snd_soc_jack_new(codec, "Headset Jack",
157 SND_JACK_HEADSET, &hs_jack);
158 if (ret)
159 return ret;
160
161 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
162 hs_jack_pins);
163
164 if (machine_is_omap_4430sdp())
165 twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
166 else
167 snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET);
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500168
169 return ret;
170}
171
172/* Digital audio interface glue - connects codec <--> CPU */
173static struct snd_soc_dai_link sdp4430_dai = {
174 .name = "TWL6040",
175 .stream_name = "TWL6040",
Peter Ujfalusi3a98cd62011-08-02 14:04:26 +0300176 .cpu_dai_name = "omap-mcpdm",
Peter Ujfalusid13f1fe2011-09-22 11:05:53 +0300177 .codec_dai_name = "twl6040-legacy",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000178 .platform_name = "omap-pcm-audio",
179 .codec_name = "twl6040-codec",
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500180 .init = sdp4430_twl6040_init,
Liam Girdwoodd8b55d22010-05-19 14:14:51 +0100181 .ops = &sdp4430_ops,
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500182};
183
184/* Audio machine driver */
185static struct snd_soc_card snd_soc_sdp4430 = {
186 .name = "SDP4430",
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500187 .dai_link = &sdp4430_dai,
188 .num_links = 1,
189};
190
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500191static struct platform_device *sdp4430_snd_device;
192
193static int __init sdp4430_soc_init(void)
194{
195 int ret;
196
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300197 if (!machine_is_omap_4430sdp())
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500198 return -ENODEV;
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500199 printk(KERN_INFO "SDP4430 SoC init\n");
200
201 sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
202 if (!sdp4430_snd_device) {
203 printk(KERN_ERR "Platform device allocation failed\n");
204 return -ENOMEM;
205 }
206
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000207 platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500208
209 ret = platform_device_add(sdp4430_snd_device);
210 if (ret)
211 goto err;
212
Misael Lopez Cruz5e64d6a2010-05-17 19:53:10 -0500213 return 0;
214
215err:
216 printk(KERN_ERR "Unable to add platform device\n");
217 platform_device_put(sdp4430_snd_device);
218 return ret;
219}
220module_init(sdp4430_soc_init);
221
222static void __exit sdp4430_soc_exit(void)
223{
224 platform_device_unregister(sdp4430_snd_device);
225}
226module_exit(sdp4430_soc_exit);
227
228MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
229MODULE_DESCRIPTION("ALSA SoC SDP4430");
230MODULE_LICENSE("GPL");
231