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> |
Balaji T K | ebeb53e | 2009-12-15 20:09:02 +0530 | [diff] [blame] | 27 | #include <linux/i2c/twl.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> |
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> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 36 | #include <plat/mcbsp.h> |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 37 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 38 | /* Register descriptions for twl4030 codec part */ |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 39 | #include <linux/mfd/twl4030-audio.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 40 | #include <linux/module.h> |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 41 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 42 | #include "omap-mcbsp.h" |
| 43 | #include "omap-pcm.h" |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 44 | |
Candelaria Villareal, Jorge | 30cd0c4a | 2009-08-25 10:13:25 -0500 | [diff] [blame] | 45 | /* TWL4030 PMBR1 Register */ |
| 46 | #define TWL4030_INTBR_PMBR1 0x0D |
| 47 | /* TWL4030 PMBR1 Register GPIO6 mux bit */ |
| 48 | #define TWL4030_GPIO6_PWM0_MUTE(value) (value << 2) |
Candelaria Villareal, Jorge | c5910a7 | 2009-07-14 20:04:08 -0500 | [diff] [blame] | 49 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 50 | static struct snd_soc_card snd_soc_sdp3430; |
| 51 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 52 | static int sdp3430_hw_params(struct snd_pcm_substream *substream, |
| 53 | struct snd_pcm_hw_params *params) |
| 54 | { |
| 55 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 56 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 57 | int ret; |
| 58 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 59 | /* Set the codec system clock for DAC and ADC */ |
| 60 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 61 | SND_SOC_CLOCK_IN); |
| 62 | if (ret < 0) { |
| 63 | printk(KERN_ERR "can't set codec system clock\n"); |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static struct snd_soc_ops sdp3430_ops = { |
| 71 | .hw_params = sdp3430_hw_params, |
| 72 | }; |
| 73 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 74 | /* Headset jack */ |
| 75 | static struct snd_soc_jack hs_jack; |
| 76 | |
| 77 | /* Headset jack detection DAPM pins */ |
| 78 | static struct snd_soc_jack_pin hs_jack_pins[] = { |
| 79 | { |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 80 | .pin = "Headset Mic", |
| 81 | .mask = SND_JACK_MICROPHONE, |
| 82 | }, |
| 83 | { |
| 84 | .pin = "Headset Stereophone", |
| 85 | .mask = SND_JACK_HEADPHONE, |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 86 | }, |
| 87 | }; |
| 88 | |
| 89 | /* Headset jack detection gpios */ |
| 90 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { |
| 91 | { |
| 92 | .gpio = (OMAP_MAX_GPIO_LINES + 2), |
| 93 | .name = "hsdet-gpio", |
| 94 | .report = SND_JACK_HEADSET, |
| 95 | .debounce_time = 200, |
| 96 | }, |
| 97 | }; |
| 98 | |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 99 | /* SDP3430 machine DAPM */ |
| 100 | static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = { |
| 101 | SND_SOC_DAPM_MIC("Ext Mic", NULL), |
| 102 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 103 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 104 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | static const struct snd_soc_dapm_route audio_map[] = { |
| 108 | /* External Mics: MAINMIC, SUBMIC with bias*/ |
| 109 | {"MAINMIC", NULL, "Mic Bias 1"}, |
| 110 | {"SUBMIC", NULL, "Mic Bias 2"}, |
| 111 | {"Mic Bias 1", NULL, "Ext Mic"}, |
| 112 | {"Mic Bias 2", NULL, "Ext Mic"}, |
| 113 | |
| 114 | /* External Speakers: HFL, HFR */ |
| 115 | {"Ext Spk", NULL, "HFL"}, |
| 116 | {"Ext Spk", NULL, "HFR"}, |
| 117 | |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 118 | /* Headset Mic: HSMIC with bias */ |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 119 | {"HSMIC", NULL, "Headset Mic Bias"}, |
Lopez Cruz, Misael | 6320877 | 2009-03-19 01:07:34 -0500 | [diff] [blame] | 120 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
| 121 | |
| 122 | /* Headset Stereophone (Headphone): HSOL, HSOR */ |
| 123 | {"Headset Stereophone", NULL, "HSOL"}, |
| 124 | {"Headset Stereophone", NULL, "HSOR"}, |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 125 | }; |
| 126 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 127 | static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd) |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 128 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 129 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 130 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 131 | int ret; |
| 132 | |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 133 | /* SDP3430 connected pins */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 134 | snd_soc_dapm_enable_pin(dapm, "Ext Mic"); |
| 135 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); |
| 136 | snd_soc_dapm_disable_pin(dapm, "Headset Mic"); |
| 137 | snd_soc_dapm_disable_pin(dapm, "Headset Stereophone"); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 138 | |
| 139 | /* TWL4030 not connected pins */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 140 | snd_soc_dapm_nc_pin(dapm, "AUXL"); |
| 141 | snd_soc_dapm_nc_pin(dapm, "AUXR"); |
| 142 | snd_soc_dapm_nc_pin(dapm, "CARKITMIC"); |
| 143 | snd_soc_dapm_nc_pin(dapm, "DIGIMIC0"); |
| 144 | snd_soc_dapm_nc_pin(dapm, "DIGIMIC1"); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 145 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 146 | snd_soc_dapm_nc_pin(dapm, "OUTL"); |
| 147 | snd_soc_dapm_nc_pin(dapm, "OUTR"); |
| 148 | snd_soc_dapm_nc_pin(dapm, "EARPIECE"); |
| 149 | snd_soc_dapm_nc_pin(dapm, "PREDRIVEL"); |
| 150 | snd_soc_dapm_nc_pin(dapm, "PREDRIVER"); |
| 151 | snd_soc_dapm_nc_pin(dapm, "CARKITL"); |
| 152 | snd_soc_dapm_nc_pin(dapm, "CARKITR"); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 153 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 154 | /* Headset jack detection */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 155 | ret = snd_soc_jack_new(codec, "Headset Jack", |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 156 | SND_JACK_HEADSET, &hs_jack); |
| 157 | if (ret) |
| 158 | return ret; |
| 159 | |
| 160 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), |
| 161 | hs_jack_pins); |
| 162 | if (ret) |
| 163 | return ret; |
| 164 | |
| 165 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
| 166 | hs_jack_gpios); |
Lopez Cruz, Misael | 979c036 | 2009-03-04 11:39:07 -0600 | [diff] [blame] | 167 | |
| 168 | return ret; |
| 169 | } |
| 170 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 171 | static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd) |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 172 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 173 | struct snd_soc_codec *codec = rtd->codec; |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 174 | unsigned short reg; |
| 175 | |
| 176 | /* Enable voice interface */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 177 | reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF); |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 178 | reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 179 | codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg); |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 185 | /* Digital audio interface glue - connects codec <--> CPU */ |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 186 | static struct snd_soc_dai_link sdp3430_dai[] = { |
| 187 | { |
| 188 | .name = "TWL4030 I2S", |
| 189 | .stream_name = "TWL4030 Audio", |
Peter Ujfalusi | 45656b4 | 2012-02-14 18:20:58 +0200 | [diff] [blame] | 190 | .cpu_dai_name = "omap-mcbsp.2", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 191 | .codec_dai_name = "twl4030-hifi", |
| 192 | .platform_name = "omap-pcm-audio", |
| 193 | .codec_name = "twl4030-codec", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 194 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 195 | SND_SOC_DAIFMT_CBM_CFM, |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 196 | .init = sdp3430_twl4030_init, |
| 197 | .ops = &sdp3430_ops, |
| 198 | }, |
| 199 | { |
| 200 | .name = "TWL4030 PCM", |
| 201 | .stream_name = "TWL4030 Voice", |
Peter Ujfalusi | 45656b4 | 2012-02-14 18:20:58 +0200 | [diff] [blame] | 202 | .cpu_dai_name = "omap-mcbsp.3", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 203 | .codec_dai_name = "twl4030-voice", |
| 204 | .platform_name = "omap-pcm-audio", |
| 205 | .codec_name = "twl4030-codec", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 206 | .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF | |
| 207 | SND_SOC_DAIFMT_CBM_CFM, |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 208 | .init = sdp3430_twl4030_voice_init, |
Jarkko Nikula | a3c6dac | 2011-09-30 16:07:46 +0300 | [diff] [blame] | 209 | .ops = &sdp3430_ops, |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 210 | }, |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | /* Audio machine driver */ |
Lopez Cruz, Misael | 272edb0 | 2009-02-10 02:05:07 -0600 | [diff] [blame] | 214 | static struct snd_soc_card snd_soc_sdp3430 = { |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 215 | .name = "SDP3430", |
Axel Lin | b425b88 | 2011-12-22 11:08:59 +0800 | [diff] [blame] | 216 | .owner = THIS_MODULE, |
Lopez Cruz, Misael | 11a7281 | 2009-05-18 11:53:04 -0500 | [diff] [blame] | 217 | .dai_link = sdp3430_dai, |
| 218 | .num_links = ARRAY_SIZE(sdp3430_dai), |
Peter Ujfalusi | f8cf149 | 2011-10-10 15:34:12 +0300 | [diff] [blame] | 219 | |
| 220 | .dapm_widgets = sdp3430_twl4030_dapm_widgets, |
| 221 | .num_dapm_widgets = ARRAY_SIZE(sdp3430_twl4030_dapm_widgets), |
| 222 | .dapm_routes = audio_map, |
| 223 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 224 | }; |
| 225 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 226 | static struct platform_device *sdp3430_snd_device; |
| 227 | |
| 228 | static int __init sdp3430_soc_init(void) |
| 229 | { |
| 230 | int ret; |
Candelaria Villareal, Jorge | 30cd0c4a | 2009-08-25 10:13:25 -0500 | [diff] [blame] | 231 | u8 pin_mux; |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 232 | |
Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame] | 233 | if (!machine_is_omap_3430sdp()) |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 234 | return -ENODEV; |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 235 | printk(KERN_INFO "SDP3430 SoC init\n"); |
| 236 | |
| 237 | sdp3430_snd_device = platform_device_alloc("soc-audio", -1); |
| 238 | if (!sdp3430_snd_device) { |
| 239 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 240 | return -ENOMEM; |
| 241 | } |
| 242 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 243 | platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430); |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 244 | |
Candelaria Villareal, Jorge | c5910a7 | 2009-07-14 20:04:08 -0500 | [diff] [blame] | 245 | /* Set TWL4030 GPIO6 as EXTMUTE signal */ |
Balaji T K | ebeb53e | 2009-12-15 20:09:02 +0530 | [diff] [blame] | 246 | twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux, |
Candelaria Villareal, Jorge | 30cd0c4a | 2009-08-25 10:13:25 -0500 | [diff] [blame] | 247 | TWL4030_INTBR_PMBR1); |
| 248 | pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03); |
| 249 | pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02); |
Balaji T K | ebeb53e | 2009-12-15 20:09:02 +0530 | [diff] [blame] | 250 | twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux, |
Candelaria Villareal, Jorge | 30cd0c4a | 2009-08-25 10:13:25 -0500 | [diff] [blame] | 251 | TWL4030_INTBR_PMBR1); |
Candelaria Villareal, Jorge | c5910a7 | 2009-07-14 20:04:08 -0500 | [diff] [blame] | 252 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 253 | ret = platform_device_add(sdp3430_snd_device); |
| 254 | if (ret) |
| 255 | goto err1; |
| 256 | |
Lopez Cruz, Misael | 77dd7e1 | 2009-03-12 21:45:27 -0500 | [diff] [blame] | 257 | return 0; |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 258 | |
| 259 | err1: |
| 260 | printk(KERN_ERR "Unable to add platform device\n"); |
| 261 | platform_device_put(sdp3430_snd_device); |
| 262 | |
| 263 | return ret; |
| 264 | } |
| 265 | module_init(sdp3430_soc_init); |
| 266 | |
| 267 | static void __exit sdp3430_soc_exit(void) |
| 268 | { |
Lopez Cruz, Misael | de0b988 | 2009-03-05 11:32:31 -0600 | [diff] [blame] | 269 | snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), |
| 270 | hs_jack_gpios); |
| 271 | |
Misael Lopez Cruz | 4451582 | 2008-11-24 22:21:23 -0600 | [diff] [blame] | 272 | platform_device_unregister(sdp3430_snd_device); |
| 273 | } |
| 274 | module_exit(sdp3430_soc_exit); |
| 275 | |
| 276 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); |
| 277 | MODULE_DESCRIPTION("ALSA SoC SDP3430"); |
| 278 | MODULE_LICENSE("GPL"); |
| 279 | |