| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 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> | 
| Jorge Eduardo Candelaria | 96dc227 | 2010-12-10 20:45:19 -0600 | [diff] [blame] | 27 | #include <sound/jack.h> | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 28 |  | 
|  | 29 | #include <asm/mach-types.h> | 
|  | 30 | #include <plat/hardware.h> | 
|  | 31 | #include <plat/mux.h> | 
|  | 32 |  | 
|  | 33 | #include "mcpdm.h" | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 34 | #include "omap-pcm.h" | 
|  | 35 | #include "../codecs/twl6040.h" | 
|  | 36 |  | 
|  | 37 | static int twl6040_power_mode; | 
|  | 38 |  | 
|  | 39 | static 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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 43 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 44 | int clk_id, freq; | 
|  | 45 | int ret; | 
|  | 46 |  | 
|  | 47 | if (twl6040_power_mode) { | 
|  | 48 | clk_id = TWL6040_SYSCLK_SEL_HPPLL; | 
|  | 49 | freq = 38400000; | 
|  | 50 | } else { | 
|  | 51 | clk_id = TWL6040_SYSCLK_SEL_LPPLL; | 
|  | 52 | freq = 32768; | 
|  | 53 | } | 
|  | 54 |  | 
|  | 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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 62 | return ret; | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
|  | 65 | static struct snd_soc_ops sdp4430_ops = { | 
|  | 66 | .hw_params = sdp4430_hw_params, | 
|  | 67 | }; | 
|  | 68 |  | 
| Jorge Eduardo Candelaria | 96dc227 | 2010-12-10 20:45:19 -0600 | [diff] [blame] | 69 | /* Headset jack */ | 
|  | 70 | static struct snd_soc_jack hs_jack; | 
|  | 71 |  | 
|  | 72 | /*Headset jack detection DAPM pins */ | 
|  | 73 | static 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 Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 84 | static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol, | 
|  | 85 | struct snd_ctl_elem_value *ucontrol) | 
|  | 86 | { | 
|  | 87 | ucontrol->value.integer.value[0] = twl6040_power_mode; | 
|  | 88 | return 0; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | static int sdp4430_set_power_mode(struct snd_kcontrol *kcontrol, | 
|  | 92 | struct snd_ctl_elem_value *ucontrol) | 
|  | 93 | { | 
|  | 94 | if (twl6040_power_mode == ucontrol->value.integer.value[0]) | 
|  | 95 | return 0; | 
|  | 96 |  | 
|  | 97 | twl6040_power_mode = ucontrol->value.integer.value[0]; | 
|  | 98 |  | 
|  | 99 | return 1; | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | static const char *power_texts[] = {"Low-Power", "High-Performance"}; | 
|  | 103 |  | 
|  | 104 | static const struct soc_enum sdp4430_enum[] = { | 
|  | 105 | SOC_ENUM_SINGLE_EXT(2, power_texts), | 
|  | 106 | }; | 
|  | 107 |  | 
|  | 108 | static const struct snd_kcontrol_new sdp4430_controls[] = { | 
|  | 109 | SOC_ENUM_EXT("TWL6040 Power Mode", sdp4430_enum[0], | 
|  | 110 | sdp4430_get_power_mode, sdp4430_set_power_mode), | 
|  | 111 | }; | 
|  | 112 |  | 
|  | 113 | /* SDP4430 machine DAPM */ | 
|  | 114 | static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = { | 
|  | 115 | SND_SOC_DAPM_MIC("Ext Mic", NULL), | 
|  | 116 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | 
|  | 117 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | 
|  | 118 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | 
| Jorge Eduardo Candelaria | 7254e2b | 2010-05-18 12:44:17 -0500 | [diff] [blame] | 119 | SND_SOC_DAPM_SPK("Earphone Spk", NULL), | 
| Jorge Eduardo Candelaria | 23ac3b6 | 2010-12-08 10:55:05 -0600 | [diff] [blame] | 120 | SND_SOC_DAPM_INPUT("Aux/FM Stereo In"), | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 121 | }; | 
|  | 122 |  | 
|  | 123 | static const struct snd_soc_dapm_route audio_map[] = { | 
|  | 124 | /* External Mics: MAINMIC, SUBMIC with bias*/ | 
|  | 125 | {"MAINMIC", NULL, "Main Mic Bias"}, | 
|  | 126 | {"SUBMIC", NULL, "Main Mic Bias"}, | 
|  | 127 | {"Main Mic Bias", NULL, "Ext Mic"}, | 
|  | 128 |  | 
|  | 129 | /* External Speakers: HFL, HFR */ | 
|  | 130 | {"Ext Spk", NULL, "HFL"}, | 
|  | 131 | {"Ext Spk", NULL, "HFR"}, | 
|  | 132 |  | 
|  | 133 | /* Headset Mic: HSMIC with bias */ | 
|  | 134 | {"HSMIC", NULL, "Headset Mic Bias"}, | 
|  | 135 | {"Headset Mic Bias", NULL, "Headset Mic"}, | 
|  | 136 |  | 
|  | 137 | /* Headset Stereophone (Headphone): HSOL, HSOR */ | 
|  | 138 | {"Headset Stereophone", NULL, "HSOL"}, | 
|  | 139 | {"Headset Stereophone", NULL, "HSOR"}, | 
| Jorge Eduardo Candelaria | 7254e2b | 2010-05-18 12:44:17 -0500 | [diff] [blame] | 140 |  | 
|  | 141 | /* Earphone speaker */ | 
|  | 142 | {"Earphone Spk", NULL, "EP"}, | 
| Jorge Eduardo Candelaria | 23ac3b6 | 2010-12-08 10:55:05 -0600 | [diff] [blame] | 143 |  | 
|  | 144 | /* Aux/FM Stereo In: AFML, AFMR */ | 
|  | 145 | {"AFML", NULL, "Aux/FM Stereo In"}, | 
|  | 146 | {"AFMR", NULL, "Aux/FM Stereo In"}, | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 147 | }; | 
|  | 148 |  | 
| Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 149 | static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd) | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 150 | { | 
| Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 151 | struct snd_soc_codec *codec = rtd->codec; | 
| Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 152 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 153 | int ret; | 
|  | 154 |  | 
|  | 155 | /* Add SDP4430 specific controls */ | 
|  | 156 | ret = snd_soc_add_controls(codec, sdp4430_controls, | 
|  | 157 | ARRAY_SIZE(sdp4430_controls)); | 
|  | 158 | if (ret) | 
|  | 159 | return ret; | 
|  | 160 |  | 
|  | 161 | /* Add SDP4430 specific widgets */ | 
| Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 162 | ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets, | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 163 | ARRAY_SIZE(sdp4430_twl6040_dapm_widgets)); | 
|  | 164 | if (ret) | 
|  | 165 | return ret; | 
|  | 166 |  | 
|  | 167 | /* Set up SDP4430 specific audio path audio_map */ | 
| Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 168 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 169 |  | 
|  | 170 | /* SDP4430 connected pins */ | 
| Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 171 | snd_soc_dapm_enable_pin(dapm, "Ext Mic"); | 
|  | 172 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); | 
| Jorge Eduardo Candelaria | 23ac3b6 | 2010-12-08 10:55:05 -0600 | [diff] [blame] | 173 | snd_soc_dapm_enable_pin(dapm, "AFML"); | 
|  | 174 | snd_soc_dapm_enable_pin(dapm, "AFMR"); | 
| Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 175 | snd_soc_dapm_enable_pin(dapm, "Headset Mic"); | 
|  | 176 | snd_soc_dapm_enable_pin(dapm, "Headset Stereophone"); | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 177 |  | 
| Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 178 | ret = snd_soc_dapm_sync(dapm); | 
| Jorge Eduardo Candelaria | 96dc227 | 2010-12-10 20:45:19 -0600 | [diff] [blame] | 179 | if (ret) | 
|  | 180 | return ret; | 
|  | 181 |  | 
|  | 182 | /* Headset jack detection */ | 
|  | 183 | ret = snd_soc_jack_new(codec, "Headset Jack", | 
|  | 184 | SND_JACK_HEADSET, &hs_jack); | 
|  | 185 | if (ret) | 
|  | 186 | return ret; | 
|  | 187 |  | 
|  | 188 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), | 
|  | 189 | hs_jack_pins); | 
|  | 190 |  | 
|  | 191 | if (machine_is_omap_4430sdp()) | 
|  | 192 | twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET); | 
|  | 193 | else | 
|  | 194 | snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET); | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 195 |  | 
|  | 196 | return ret; | 
|  | 197 | } | 
|  | 198 |  | 
|  | 199 | /* Digital audio interface glue - connects codec <--> CPU */ | 
|  | 200 | static struct snd_soc_dai_link sdp4430_dai = { | 
|  | 201 | .name = "TWL6040", | 
|  | 202 | .stream_name = "TWL6040", | 
| Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 203 | .cpu_dai_name ="omap-mcpdm-dai", | 
|  | 204 | .codec_dai_name = "twl6040-hifi", | 
|  | 205 | .platform_name = "omap-pcm-audio", | 
|  | 206 | .codec_name = "twl6040-codec", | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 207 | .init = sdp4430_twl6040_init, | 
| Liam Girdwood | d8b55d2 | 2010-05-19 14:14:51 +0100 | [diff] [blame] | 208 | .ops = &sdp4430_ops, | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 209 | }; | 
|  | 210 |  | 
|  | 211 | /* Audio machine driver */ | 
|  | 212 | static struct snd_soc_card snd_soc_sdp4430 = { | 
|  | 213 | .name = "SDP4430", | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 214 | .dai_link = &sdp4430_dai, | 
|  | 215 | .num_links = 1, | 
|  | 216 | }; | 
|  | 217 |  | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 218 | static struct platform_device *sdp4430_snd_device; | 
|  | 219 |  | 
|  | 220 | static int __init sdp4430_soc_init(void) | 
|  | 221 | { | 
|  | 222 | int ret; | 
|  | 223 |  | 
| Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 224 | if (!machine_is_omap_4430sdp()) | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 225 | return -ENODEV; | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 226 | printk(KERN_INFO "SDP4430 SoC init\n"); | 
|  | 227 |  | 
|  | 228 | sdp4430_snd_device = platform_device_alloc("soc-audio", -1); | 
|  | 229 | if (!sdp4430_snd_device) { | 
|  | 230 | printk(KERN_ERR "Platform device allocation failed\n"); | 
|  | 231 | return -ENOMEM; | 
|  | 232 | } | 
|  | 233 |  | 
| Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 234 | platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430); | 
| Misael Lopez Cruz | 5e64d6a | 2010-05-17 19:53:10 -0500 | [diff] [blame] | 235 |  | 
|  | 236 | ret = platform_device_add(sdp4430_snd_device); | 
|  | 237 | if (ret) | 
|  | 238 | goto err; | 
|  | 239 |  | 
|  | 240 | /* Codec starts in HP mode */ | 
|  | 241 | twl6040_power_mode = 1; | 
|  | 242 |  | 
|  | 243 | return 0; | 
|  | 244 |  | 
|  | 245 | err: | 
|  | 246 | printk(KERN_ERR "Unable to add platform device\n"); | 
|  | 247 | platform_device_put(sdp4430_snd_device); | 
|  | 248 | return ret; | 
|  | 249 | } | 
|  | 250 | module_init(sdp4430_soc_init); | 
|  | 251 |  | 
|  | 252 | static void __exit sdp4430_soc_exit(void) | 
|  | 253 | { | 
|  | 254 | platform_device_unregister(sdp4430_snd_device); | 
|  | 255 | } | 
|  | 256 | module_exit(sdp4430_soc_exit); | 
|  | 257 |  | 
|  | 258 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); | 
|  | 259 | MODULE_DESCRIPTION("ALSA SoC SDP4430"); | 
|  | 260 | MODULE_LICENSE("GPL"); | 
|  | 261 |  |