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> |
| 27 | #include <sound/core.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include <sound/soc.h> |
| 30 | #include <sound/soc-dapm.h> |
Lopez Cruz, Misael | de0b988 | 2009-03-05 11:32:31 -0600 | [diff] [blame] | 31 | #include <sound/jack.h> |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 32 | |
| 33 | #include <asm/mach-types.h> |
| 34 | #include <mach/hardware.h> |
| 35 | #include <mach/gpio.h> |
| 36 | #include <mach/mcbsp.h> |
| 37 | |
| 38 | #include "omap-mcbsp.h" |
| 39 | #include "omap-pcm.h" |
| 40 | #include "../codecs/twl4030.h" |
| 41 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 42 | static struct snd_soc_card snd_soc_sdp3430; |
| 43 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 44 | static int sdp3430_hw_params(struct snd_pcm_substream *substream, |
| 45 | struct snd_pcm_hw_params *params) |
| 46 | { |
| 47 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 48 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 49 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
| 50 | int ret; |
| 51 | |
| 52 | /* Set codec DAI configuration */ |
| 53 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 54 | SND_SOC_DAIFMT_I2S | |
| 55 | SND_SOC_DAIFMT_NB_NF | |
| 56 | SND_SOC_DAIFMT_CBM_CFM); |
| 57 | if (ret < 0) { |
| 58 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | /* Set cpu DAI configuration */ |
| 63 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 64 | SND_SOC_DAIFMT_I2S | |
| 65 | SND_SOC_DAIFMT_NB_NF | |
| 66 | SND_SOC_DAIFMT_CBM_CFM); |
| 67 | if (ret < 0) { |
| 68 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | /* Set the codec system clock for DAC and ADC */ |
| 73 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 74 | SND_SOC_CLOCK_IN); |
| 75 | if (ret < 0) { |
| 76 | printk(KERN_ERR "can't set codec system clock\n"); |
| 77 | return ret; |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static struct snd_soc_ops sdp3430_ops = { |
| 84 | .hw_params = sdp3430_hw_params, |
| 85 | }; |
| 86 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 87 | /* Headset jack */ |
| 88 | static struct snd_soc_jack hs_jack; |
| 89 | |
| 90 | /* Headset jack detection DAPM pins */ |
| 91 | static struct snd_soc_jack_pin hs_jack_pins[] = { |
| 92 | { |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 93 | .pin = "Headset Mic", |
| 94 | .mask = SND_JACK_MICROPHONE, |
| 95 | }, |
| 96 | { |
| 97 | .pin = "Headset Stereophone", |
| 98 | .mask = SND_JACK_HEADPHONE, |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 99 | }, |
| 100 | }; |
| 101 | |
| 102 | /* Headset jack detection gpios */ |
| 103 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { |
| 104 | { |
| 105 | .gpio = (OMAP_MAX_GPIO_LINES + 2), |
| 106 | .name = "hsdet-gpio", |
| 107 | .report = SND_JACK_HEADSET, |
| 108 | .debounce_time = 200, |
| 109 | }, |
| 110 | }; |
| 111 | |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 112 | /* SDP3430 machine DAPM */ |
| 113 | static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = { |
| 114 | SND_SOC_DAPM_MIC("Ext Mic", NULL), |
| 115 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 116 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 117 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | static const struct snd_soc_dapm_route audio_map[] = { |
| 121 | /* External Mics: MAINMIC, SUBMIC with bias*/ |
| 122 | {"MAINMIC", NULL, "Mic Bias 1"}, |
| 123 | {"SUBMIC", NULL, "Mic Bias 2"}, |
| 124 | {"Mic Bias 1", NULL, "Ext Mic"}, |
| 125 | {"Mic Bias 2", NULL, "Ext Mic"}, |
| 126 | |
| 127 | /* External Speakers: HFL, HFR */ |
| 128 | {"Ext Spk", NULL, "HFL"}, |
| 129 | {"Ext Spk", NULL, "HFR"}, |
| 130 | |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 131 | /* Headset Mic: HSMIC with bias */ |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 132 | {"HSMIC", NULL, "Headset Mic Bias"}, |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 133 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
| 134 | |
| 135 | /* Headset Stereophone (Headphone): HSOL, HSOR */ |
| 136 | {"Headset Stereophone", NULL, "HSOL"}, |
| 137 | {"Headset Stereophone", NULL, "HSOR"}, |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static int sdp3430_twl4030_init(struct snd_soc_codec *codec) |
| 141 | { |
| 142 | int ret; |
| 143 | |
| 144 | /* Add SDP3430 specific widgets */ |
| 145 | ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets, |
| 146 | ARRAY_SIZE(sdp3430_twl4030_dapm_widgets)); |
| 147 | if (ret) |
| 148 | return ret; |
| 149 | |
| 150 | /* Set up SDP3430 specific audio path audio_map */ |
| 151 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
| 152 | |
| 153 | /* SDP3430 connected pins */ |
| 154 | snd_soc_dapm_enable_pin(codec, "Ext Mic"); |
| 155 | snd_soc_dapm_enable_pin(codec, "Ext Spk"); |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 156 | snd_soc_dapm_disable_pin(codec, "Headset Mic"); |
| 157 | snd_soc_dapm_disable_pin(codec, "Headset Stereophone"); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 158 | |
| 159 | /* TWL4030 not connected pins */ |
| 160 | snd_soc_dapm_nc_pin(codec, "AUXL"); |
| 161 | snd_soc_dapm_nc_pin(codec, "AUXR"); |
| 162 | snd_soc_dapm_nc_pin(codec, "CARKITMIC"); |
| 163 | snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); |
| 164 | snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); |
| 165 | |
| 166 | snd_soc_dapm_nc_pin(codec, "OUTL"); |
| 167 | snd_soc_dapm_nc_pin(codec, "OUTR"); |
| 168 | snd_soc_dapm_nc_pin(codec, "EARPIECE"); |
| 169 | snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); |
| 170 | snd_soc_dapm_nc_pin(codec, "PREDRIVER"); |
| 171 | snd_soc_dapm_nc_pin(codec, "CARKITL"); |
| 172 | snd_soc_dapm_nc_pin(codec, "CARKITR"); |
| 173 | |
| 174 | ret = snd_soc_dapm_sync(codec); |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 175 | if (ret) |
| 176 | return ret; |
| 177 | |
| 178 | /* Headset jack detection */ |
| 179 | ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack", |
| 180 | SND_JACK_HEADSET, &hs_jack); |
| 181 | if (ret) |
| 182 | return ret; |
| 183 | |
| 184 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), |
| 185 | hs_jack_pins); |
| 186 | if (ret) |
| 187 | return ret; |
| 188 | |
| 189 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
| 190 | hs_jack_gpios); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 191 | |
| 192 | return ret; |
| 193 | } |
| 194 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 195 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 196 | static struct snd_soc_dai_link sdp3430_dai = { |
| 197 | .name = "TWL4030", |
| 198 | .stream_name = "TWL4030", |
| 199 | .cpu_dai = &omap_mcbsp_dai[0], |
| 200 | .codec_dai = &twl4030_dai, |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 201 | .init = sdp3430_twl4030_init, |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 202 | .ops = &sdp3430_ops, |
| 203 | }; |
| 204 | |
| 205 | /* Audio machine driver */ |
Lopez Cruz, Misael | 272edb0 | 2009-02-10 02:05:07 -0600 | [diff] [blame] | 206 | static struct snd_soc_card snd_soc_sdp3430 = { |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 207 | .name = "SDP3430", |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 208 | .platform = &omap_soc_platform, |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 209 | .dai_link = &sdp3430_dai, |
| 210 | .num_links = 1, |
| 211 | }; |
| 212 | |
| 213 | /* Audio subsystem */ |
| 214 | static struct snd_soc_device sdp3430_snd_devdata = { |
Lopez Cruz, Misael | 272edb0 | 2009-02-10 02:05:07 -0600 | [diff] [blame] | 215 | .card = &snd_soc_sdp3430, |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 216 | .codec_dev = &soc_codec_dev_twl4030, |
| 217 | }; |
| 218 | |
| 219 | static struct platform_device *sdp3430_snd_device; |
| 220 | |
| 221 | static int __init sdp3430_soc_init(void) |
| 222 | { |
| 223 | int ret; |
| 224 | |
| 225 | if (!machine_is_omap_3430sdp()) { |
| 226 | pr_debug("Not SDP3430!\n"); |
| 227 | return -ENODEV; |
| 228 | } |
| 229 | printk(KERN_INFO "SDP3430 SoC init\n"); |
| 230 | |
| 231 | sdp3430_snd_device = platform_device_alloc("soc-audio", -1); |
| 232 | if (!sdp3430_snd_device) { |
| 233 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 234 | return -ENOMEM; |
| 235 | } |
| 236 | |
| 237 | platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata); |
| 238 | sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev; |
| 239 | *(unsigned int *)sdp3430_dai.cpu_dai->private_data = 1; /* McBSP2 */ |
| 240 | |
| 241 | ret = platform_device_add(sdp3430_snd_device); |
| 242 | if (ret) |
| 243 | goto err1; |
| 244 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 245 | return 0; |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 246 | |
| 247 | err1: |
| 248 | printk(KERN_ERR "Unable to add platform device\n"); |
| 249 | platform_device_put(sdp3430_snd_device); |
| 250 | |
| 251 | return ret; |
| 252 | } |
| 253 | module_init(sdp3430_soc_init); |
| 254 | |
| 255 | static void __exit sdp3430_soc_exit(void) |
| 256 | { |
Lopez Cruz, Misael | de0b988 | 2009-03-05 11:32:31 -0600 | [diff] [blame] | 257 | snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
| 258 | hs_jack_gpios); |
| 259 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 260 | platform_device_unregister(sdp3430_snd_device); |
| 261 | } |
| 262 | module_exit(sdp3430_soc_exit); |
| 263 | |
| 264 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); |
| 265 | MODULE_DESCRIPTION("ALSA SoC SDP3430"); |
| 266 | MODULE_LICENSE("GPL"); |
| 267 | |