Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 1 | /* |
| 2 | * sdp3430.c -- SoC audio for TI OMAP3430 SDP |
| 3 | * |
| 4 | * Author: Misael Lopez Cruz <x0052729@ti.com> |
| 5 | * |
| 6 | * Based on: |
| 7 | * Author: Steve Sakoman <steve@sakoman.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * version 2 as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/clk.h> |
| 26 | #include <linux/platform_device.h> |
Candelaria Villareal, Jorge | c5910a7 | 2009-07-14 20:04:08 -0500 | [diff] [blame^] | 27 | #include <linux/i2c/twl4030.h> |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 28 | #include <sound/core.h> |
| 29 | #include <sound/pcm.h> |
| 30 | #include <sound/soc.h> |
| 31 | #include <sound/soc-dapm.h> |
Lopez Cruz, Misael | de0b988 | 2009-03-05 11:32:31 -0600 | [diff] [blame] | 32 | #include <sound/jack.h> |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 33 | |
| 34 | #include <asm/mach-types.h> |
| 35 | #include <mach/hardware.h> |
| 36 | #include <mach/gpio.h> |
| 37 | #include <mach/mcbsp.h> |
| 38 | |
| 39 | #include "omap-mcbsp.h" |
| 40 | #include "omap-pcm.h" |
| 41 | #include "../codecs/twl4030.h" |
| 42 | |
Candelaria Villareal, Jorge | c5910a7 | 2009-07-14 20:04:08 -0500 | [diff] [blame^] | 43 | #define TWL4030_INTBR_PMBR1 0x0D |
| 44 | #define EXTMUTE(value) (value << 2) |
| 45 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 46 | static struct snd_soc_card snd_soc_sdp3430; |
| 47 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 48 | static int sdp3430_hw_params(struct snd_pcm_substream *substream, |
| 49 | struct snd_pcm_hw_params *params) |
| 50 | { |
| 51 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 52 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 53 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
| 54 | int ret; |
| 55 | |
| 56 | /* Set codec DAI configuration */ |
| 57 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 58 | SND_SOC_DAIFMT_I2S | |
| 59 | SND_SOC_DAIFMT_NB_NF | |
| 60 | SND_SOC_DAIFMT_CBM_CFM); |
| 61 | if (ret < 0) { |
| 62 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | /* Set cpu DAI configuration */ |
| 67 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 68 | SND_SOC_DAIFMT_I2S | |
| 69 | SND_SOC_DAIFMT_NB_NF | |
| 70 | SND_SOC_DAIFMT_CBM_CFM); |
| 71 | if (ret < 0) { |
| 72 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | /* Set the codec system clock for DAC and ADC */ |
| 77 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 78 | SND_SOC_CLOCK_IN); |
| 79 | if (ret < 0) { |
| 80 | printk(KERN_ERR "can't set codec system clock\n"); |
| 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static struct snd_soc_ops sdp3430_ops = { |
| 88 | .hw_params = sdp3430_hw_params, |
| 89 | }; |
| 90 | |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 91 | static int sdp3430_hw_voice_params(struct snd_pcm_substream *substream, |
| 92 | struct snd_pcm_hw_params *params) |
| 93 | { |
| 94 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 95 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 96 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
| 97 | int ret; |
| 98 | |
| 99 | /* Set codec DAI configuration */ |
| 100 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 101 | SND_SOC_DAIFMT_DSP_A | |
| 102 | SND_SOC_DAIFMT_IB_NF | |
Lopez Cruz, Misael | c264301 | 2009-06-19 03:23:42 -0500 | [diff] [blame] | 103 | SND_SOC_DAIFMT_CBM_CFM); |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 104 | if (ret) { |
| 105 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | /* Set cpu DAI configuration */ |
| 110 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 111 | SND_SOC_DAIFMT_DSP_A | |
| 112 | SND_SOC_DAIFMT_IB_NF | |
| 113 | SND_SOC_DAIFMT_CBM_CFM); |
| 114 | if (ret < 0) { |
| 115 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | /* Set the codec system clock for DAC and ADC */ |
| 120 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 121 | SND_SOC_CLOCK_IN); |
| 122 | if (ret < 0) { |
| 123 | printk(KERN_ERR "can't set codec system clock\n"); |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static struct snd_soc_ops sdp3430_voice_ops = { |
| 131 | .hw_params = sdp3430_hw_voice_params, |
| 132 | }; |
| 133 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 134 | /* Headset jack */ |
| 135 | static struct snd_soc_jack hs_jack; |
| 136 | |
| 137 | /* Headset jack detection DAPM pins */ |
| 138 | static struct snd_soc_jack_pin hs_jack_pins[] = { |
| 139 | { |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 140 | .pin = "Headset Mic", |
| 141 | .mask = SND_JACK_MICROPHONE, |
| 142 | }, |
| 143 | { |
| 144 | .pin = "Headset Stereophone", |
| 145 | .mask = SND_JACK_HEADPHONE, |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 146 | }, |
| 147 | }; |
| 148 | |
| 149 | /* Headset jack detection gpios */ |
| 150 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { |
| 151 | { |
| 152 | .gpio = (OMAP_MAX_GPIO_LINES + 2), |
| 153 | .name = "hsdet-gpio", |
| 154 | .report = SND_JACK_HEADSET, |
| 155 | .debounce_time = 200, |
| 156 | }, |
| 157 | }; |
| 158 | |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 159 | /* SDP3430 machine DAPM */ |
| 160 | static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = { |
| 161 | SND_SOC_DAPM_MIC("Ext Mic", NULL), |
| 162 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 163 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 164 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | static const struct snd_soc_dapm_route audio_map[] = { |
| 168 | /* External Mics: MAINMIC, SUBMIC with bias*/ |
| 169 | {"MAINMIC", NULL, "Mic Bias 1"}, |
| 170 | {"SUBMIC", NULL, "Mic Bias 2"}, |
| 171 | {"Mic Bias 1", NULL, "Ext Mic"}, |
| 172 | {"Mic Bias 2", NULL, "Ext Mic"}, |
| 173 | |
| 174 | /* External Speakers: HFL, HFR */ |
| 175 | {"Ext Spk", NULL, "HFL"}, |
| 176 | {"Ext Spk", NULL, "HFR"}, |
| 177 | |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 178 | /* Headset Mic: HSMIC with bias */ |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 179 | {"HSMIC", NULL, "Headset Mic Bias"}, |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 180 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
| 181 | |
| 182 | /* Headset Stereophone (Headphone): HSOL, HSOR */ |
| 183 | {"Headset Stereophone", NULL, "HSOL"}, |
| 184 | {"Headset Stereophone", NULL, "HSOR"}, |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static int sdp3430_twl4030_init(struct snd_soc_codec *codec) |
| 188 | { |
| 189 | int ret; |
| 190 | |
| 191 | /* Add SDP3430 specific widgets */ |
| 192 | ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets, |
| 193 | ARRAY_SIZE(sdp3430_twl4030_dapm_widgets)); |
| 194 | if (ret) |
| 195 | return ret; |
| 196 | |
| 197 | /* Set up SDP3430 specific audio path audio_map */ |
| 198 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
| 199 | |
| 200 | /* SDP3430 connected pins */ |
| 201 | snd_soc_dapm_enable_pin(codec, "Ext Mic"); |
| 202 | snd_soc_dapm_enable_pin(codec, "Ext Spk"); |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 203 | snd_soc_dapm_disable_pin(codec, "Headset Mic"); |
| 204 | snd_soc_dapm_disable_pin(codec, "Headset Stereophone"); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 205 | |
| 206 | /* TWL4030 not connected pins */ |
| 207 | snd_soc_dapm_nc_pin(codec, "AUXL"); |
| 208 | snd_soc_dapm_nc_pin(codec, "AUXR"); |
| 209 | snd_soc_dapm_nc_pin(codec, "CARKITMIC"); |
| 210 | snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); |
| 211 | snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); |
| 212 | |
| 213 | snd_soc_dapm_nc_pin(codec, "OUTL"); |
| 214 | snd_soc_dapm_nc_pin(codec, "OUTR"); |
| 215 | snd_soc_dapm_nc_pin(codec, "EARPIECE"); |
| 216 | snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); |
| 217 | snd_soc_dapm_nc_pin(codec, "PREDRIVER"); |
| 218 | snd_soc_dapm_nc_pin(codec, "CARKITL"); |
| 219 | snd_soc_dapm_nc_pin(codec, "CARKITR"); |
| 220 | |
| 221 | ret = snd_soc_dapm_sync(codec); |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 222 | if (ret) |
| 223 | return ret; |
| 224 | |
| 225 | /* Headset jack detection */ |
| 226 | ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack", |
| 227 | SND_JACK_HEADSET, &hs_jack); |
| 228 | if (ret) |
| 229 | return ret; |
| 230 | |
| 231 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), |
| 232 | hs_jack_pins); |
| 233 | if (ret) |
| 234 | return ret; |
| 235 | |
| 236 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
| 237 | hs_jack_gpios); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 238 | |
| 239 | return ret; |
| 240 | } |
| 241 | |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 242 | static int sdp3430_twl4030_voice_init(struct snd_soc_codec *codec) |
| 243 | { |
| 244 | unsigned short reg; |
| 245 | |
| 246 | /* Enable voice interface */ |
| 247 | reg = codec->read(codec, TWL4030_REG_VOICE_IF); |
| 248 | reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN; |
| 249 | codec->write(codec, TWL4030_REG_VOICE_IF, reg); |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 255 | /* Digital audio interface glue - connects codec <--> CPU */ |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 256 | static struct snd_soc_dai_link sdp3430_dai[] = { |
| 257 | { |
| 258 | .name = "TWL4030 I2S", |
| 259 | .stream_name = "TWL4030 Audio", |
| 260 | .cpu_dai = &omap_mcbsp_dai[0], |
| 261 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], |
| 262 | .init = sdp3430_twl4030_init, |
| 263 | .ops = &sdp3430_ops, |
| 264 | }, |
| 265 | { |
| 266 | .name = "TWL4030 PCM", |
| 267 | .stream_name = "TWL4030 Voice", |
| 268 | .cpu_dai = &omap_mcbsp_dai[1], |
| 269 | .codec_dai = &twl4030_dai[TWL4030_DAI_VOICE], |
| 270 | .init = sdp3430_twl4030_voice_init, |
| 271 | .ops = &sdp3430_voice_ops, |
| 272 | }, |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | /* Audio machine driver */ |
Lopez Cruz, Misael | 272edb0 | 2009-02-10 02:05:07 -0600 | [diff] [blame] | 276 | static struct snd_soc_card snd_soc_sdp3430 = { |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 277 | .name = "SDP3430", |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 278 | .platform = &omap_soc_platform, |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 279 | .dai_link = sdp3430_dai, |
| 280 | .num_links = ARRAY_SIZE(sdp3430_dai), |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 281 | }; |
| 282 | |
Peter Ujfalusi | 7385ba4 | 2009-05-22 10:13:16 +0300 | [diff] [blame] | 283 | /* twl4030 setup */ |
| 284 | static struct twl4030_setup_data twl4030_setup = { |
| 285 | .ramp_delay_value = 3, |
| 286 | .sysclk = 26000, |
Candelaria Villareal, Jorge | c5910a7 | 2009-07-14 20:04:08 -0500 | [diff] [blame^] | 287 | .hs_extmute = 1, |
Peter Ujfalusi | 7385ba4 | 2009-05-22 10:13:16 +0300 | [diff] [blame] | 288 | }; |
| 289 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 290 | /* Audio subsystem */ |
| 291 | static struct snd_soc_device sdp3430_snd_devdata = { |
Lopez Cruz, Misael | 272edb0 | 2009-02-10 02:05:07 -0600 | [diff] [blame] | 292 | .card = &snd_soc_sdp3430, |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 293 | .codec_dev = &soc_codec_dev_twl4030, |
Peter Ujfalusi | 7385ba4 | 2009-05-22 10:13:16 +0300 | [diff] [blame] | 294 | .codec_data = &twl4030_setup, |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 295 | }; |
| 296 | |
| 297 | static struct platform_device *sdp3430_snd_device; |
| 298 | |
| 299 | static int __init sdp3430_soc_init(void) |
| 300 | { |
| 301 | int ret; |
| 302 | |
| 303 | if (!machine_is_omap_3430sdp()) { |
| 304 | pr_debug("Not SDP3430!\n"); |
| 305 | return -ENODEV; |
| 306 | } |
| 307 | printk(KERN_INFO "SDP3430 SoC init\n"); |
| 308 | |
| 309 | sdp3430_snd_device = platform_device_alloc("soc-audio", -1); |
| 310 | if (!sdp3430_snd_device) { |
| 311 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 312 | return -ENOMEM; |
| 313 | } |
| 314 | |
| 315 | platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata); |
| 316 | sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev; |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 317 | *(unsigned int *)sdp3430_dai[0].cpu_dai->private_data = 1; /* McBSP2 */ |
| 318 | *(unsigned int *)sdp3430_dai[1].cpu_dai->private_data = 2; /* McBSP3 */ |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 319 | |
Candelaria Villareal, Jorge | c5910a7 | 2009-07-14 20:04:08 -0500 | [diff] [blame^] | 320 | /* Set TWL4030 GPIO6 as EXTMUTE signal */ |
| 321 | twl4030_i2c_write_u8(TWL4030_MODULE_INTBR, EXTMUTE(0x02), |
| 322 | TWL4030_MODULE_INTBR); |
| 323 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 324 | ret = platform_device_add(sdp3430_snd_device); |
| 325 | if (ret) |
| 326 | goto err1; |
| 327 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 328 | return 0; |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 329 | |
| 330 | err1: |
| 331 | printk(KERN_ERR "Unable to add platform device\n"); |
| 332 | platform_device_put(sdp3430_snd_device); |
| 333 | |
| 334 | return ret; |
| 335 | } |
| 336 | module_init(sdp3430_soc_init); |
| 337 | |
| 338 | static void __exit sdp3430_soc_exit(void) |
| 339 | { |
Lopez Cruz, Misael | de0b988 | 2009-03-05 11:32:31 -0600 | [diff] [blame] | 340 | snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
| 341 | hs_jack_gpios); |
| 342 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 343 | platform_device_unregister(sdp3430_snd_device); |
| 344 | } |
| 345 | module_exit(sdp3430_soc_exit); |
| 346 | |
| 347 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); |
| 348 | MODULE_DESCRIPTION("ALSA SoC SDP3430"); |
| 349 | MODULE_LICENSE("GPL"); |
| 350 | |