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 <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dapm.h>
29 #include <asm/mach-types.h>
30 #include <plat/hardware.h>
34 #include "omap-mcpdm.h"
36 #include "../codecs/twl6040.h"
38 static int twl6040_power_mode
;
40 static int sdp4430_hw_params(struct snd_pcm_substream
*substream
,
41 struct snd_pcm_hw_params
*params
)
43 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
44 struct snd_soc_dai
*codec_dai
= rtd
->dai
->codec_dai
;
48 if (twl6040_power_mode
) {
49 clk_id
= TWL6040_SYSCLK_SEL_HPPLL
;
52 clk_id
= TWL6040_SYSCLK_SEL_LPPLL
;
56 /* set the codec mclk */
57 ret
= snd_soc_dai_set_sysclk(codec_dai
, clk_id
, freq
,
60 printk(KERN_ERR
"can't set codec system clock\n");
65 static struct snd_soc_ops sdp4430_ops
= {
66 .hw_params
= sdp4430_hw_params
,
69 static int sdp4430_get_power_mode(struct snd_kcontrol
*kcontrol
,
70 struct snd_ctl_elem_value
*ucontrol
)
72 ucontrol
->value
.integer
.value
[0] = twl6040_power_mode
;
76 static int sdp4430_set_power_mode(struct snd_kcontrol
*kcontrol
,
77 struct snd_ctl_elem_value
*ucontrol
)
79 if (twl6040_power_mode
== ucontrol
->value
.integer
.value
[0])
82 twl6040_power_mode
= ucontrol
->value
.integer
.value
[0];
87 static const char *power_texts
[] = {"Low-Power", "High-Performance"};
89 static const struct soc_enum sdp4430_enum
[] = {
90 SOC_ENUM_SINGLE_EXT(2, power_texts
),
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
),
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 SND_SOC_DAPM_SPK("Earphone Spk", NULL
),
107 static const struct snd_soc_dapm_route audio_map
[] = {
108 /* External Mics: MAINMIC, SUBMIC with bias*/
109 {"MAINMIC", NULL
, "Main Mic Bias"},
110 {"SUBMIC", NULL
, "Main Mic Bias"},
111 {"Main Mic Bias", NULL
, "Ext Mic"},
113 /* External Speakers: HFL, HFR */
114 {"Ext Spk", NULL
, "HFL"},
115 {"Ext Spk", NULL
, "HFR"},
117 /* Headset Mic: HSMIC with bias */
118 {"HSMIC", NULL
, "Headset Mic Bias"},
119 {"Headset Mic Bias", NULL
, "Headset Mic"},
121 /* Headset Stereophone (Headphone): HSOL, HSOR */
122 {"Headset Stereophone", NULL
, "HSOL"},
123 {"Headset Stereophone", NULL
, "HSOR"},
125 /* Earphone speaker */
126 {"Earphone Spk", NULL
, "EP"},
129 static int sdp4430_twl6040_init(struct snd_soc_codec
*codec
)
133 /* Add SDP4430 specific controls */
134 ret
= snd_soc_add_controls(codec
, sdp4430_controls
,
135 ARRAY_SIZE(sdp4430_controls
));
139 /* Add SDP4430 specific widgets */
140 ret
= snd_soc_dapm_new_controls(codec
, sdp4430_twl6040_dapm_widgets
,
141 ARRAY_SIZE(sdp4430_twl6040_dapm_widgets
));
145 /* Set up SDP4430 specific audio path audio_map */
146 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
148 /* SDP4430 connected pins */
149 snd_soc_dapm_enable_pin(codec
, "Ext Mic");
150 snd_soc_dapm_enable_pin(codec
, "Ext Spk");
151 snd_soc_dapm_enable_pin(codec
, "Headset Mic");
152 snd_soc_dapm_enable_pin(codec
, "Headset Stereophone");
154 /* TWL6040 not connected pins */
155 snd_soc_dapm_nc_pin(codec
, "AFML");
156 snd_soc_dapm_nc_pin(codec
, "AFMR");
158 ret
= snd_soc_dapm_sync(codec
);
163 /* Digital audio interface glue - connects codec <--> CPU */
164 static struct snd_soc_dai_link sdp4430_dai
= {
166 .stream_name
= "TWL6040",
167 .cpu_dai
= &omap_mcpdm_dai
,
168 .codec_dai
= &twl6040_dai
,
169 .init
= sdp4430_twl6040_init
,
173 /* Audio machine driver */
174 static struct snd_soc_card snd_soc_sdp4430
= {
176 .platform
= &omap_soc_platform
,
177 .dai_link
= &sdp4430_dai
,
181 /* Audio subsystem */
182 static struct snd_soc_device sdp4430_snd_devdata
= {
183 .card
= &snd_soc_sdp4430
,
184 .codec_dev
= &soc_codec_dev_twl6040
,
187 static struct platform_device
*sdp4430_snd_device
;
189 static int __init
sdp4430_soc_init(void)
193 if (!machine_is_omap_4430sdp()) {
194 pr_debug("Not SDP4430!\n");
197 printk(KERN_INFO
"SDP4430 SoC init\n");
199 sdp4430_snd_device
= platform_device_alloc("soc-audio", -1);
200 if (!sdp4430_snd_device
) {
201 printk(KERN_ERR
"Platform device allocation failed\n");
205 platform_set_drvdata(sdp4430_snd_device
, &sdp4430_snd_devdata
);
206 sdp4430_snd_devdata
.dev
= &sdp4430_snd_device
->dev
;
208 ret
= platform_device_add(sdp4430_snd_device
);
212 /* Codec starts in HP mode */
213 twl6040_power_mode
= 1;
218 printk(KERN_ERR
"Unable to add platform device\n");
219 platform_device_put(sdp4430_snd_device
);
222 module_init(sdp4430_soc_init
);
224 static void __exit
sdp4430_soc_exit(void)
226 platform_device_unregister(sdp4430_snd_device
);
228 module_exit(sdp4430_soc_exit
);
230 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
231 MODULE_DESCRIPTION("ALSA SoC SDP4430");
232 MODULE_LICENSE("GPL");