Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 1 | /* |
| 2 | * zoom2.c -- SoC audio for Zoom2 |
| 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> |
| 27 | #include <sound/soc-dapm.h> |
| 28 | |
| 29 | #include <asm/mach-types.h> |
| 30 | #include <mach/hardware.h> |
| 31 | #include <mach/gpio.h> |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 32 | #include <mach/board-zoom.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 33 | #include <plat/mcbsp.h> |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 34 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 35 | /* Register descriptions for twl4030 codec part */ |
| 36 | #include <linux/mfd/twl4030-codec.h> |
| 37 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 38 | #include "omap-mcbsp.h" |
| 39 | #include "omap-pcm.h" |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 40 | |
Candelaria Villareal, Jorge | 1b6ebdd | 2009-07-02 19:04:07 -0500 | [diff] [blame] | 41 | #define ZOOM2_HEADSET_MUX_GPIO (OMAP_MAX_GPIO_LINES + 15) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 42 | |
| 43 | static int zoom2_hw_params(struct snd_pcm_substream *substream, |
| 44 | struct snd_pcm_hw_params *params) |
| 45 | { |
| 46 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 47 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 48 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 49 | int ret; |
| 50 | |
| 51 | /* Set codec DAI configuration */ |
| 52 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 53 | SND_SOC_DAIFMT_I2S | |
| 54 | SND_SOC_DAIFMT_NB_NF | |
| 55 | SND_SOC_DAIFMT_CBM_CFM); |
| 56 | if (ret < 0) { |
| 57 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | /* Set cpu DAI configuration */ |
| 62 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 63 | SND_SOC_DAIFMT_I2S | |
| 64 | SND_SOC_DAIFMT_NB_NF | |
| 65 | SND_SOC_DAIFMT_CBM_CFM); |
| 66 | if (ret < 0) { |
| 67 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | /* Set the codec system clock for DAC and ADC */ |
| 72 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 73 | SND_SOC_CLOCK_IN); |
| 74 | if (ret < 0) { |
| 75 | printk(KERN_ERR "can't set codec system clock\n"); |
| 76 | return ret; |
| 77 | } |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static struct snd_soc_ops zoom2_ops = { |
| 83 | .hw_params = zoom2_hw_params, |
| 84 | }; |
| 85 | |
| 86 | static int zoom2_hw_voice_params(struct snd_pcm_substream *substream, |
| 87 | struct snd_pcm_hw_params *params) |
| 88 | { |
| 89 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 90 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 91 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 92 | int ret; |
| 93 | |
| 94 | /* Set codec DAI configuration */ |
| 95 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 96 | SND_SOC_DAIFMT_DSP_A | |
| 97 | SND_SOC_DAIFMT_IB_NF | |
Lopez Cruz, Misael | c264301 | 2009-06-19 03:23:42 -0500 | [diff] [blame] | 98 | SND_SOC_DAIFMT_CBM_CFM); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 99 | if (ret) { |
| 100 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | /* Set cpu DAI configuration */ |
| 105 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 106 | SND_SOC_DAIFMT_DSP_A | |
| 107 | SND_SOC_DAIFMT_IB_NF | |
| 108 | SND_SOC_DAIFMT_CBM_CFM); |
| 109 | if (ret < 0) { |
| 110 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | /* Set the codec system clock for DAC and ADC */ |
| 115 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, |
| 116 | SND_SOC_CLOCK_IN); |
| 117 | if (ret < 0) { |
| 118 | printk(KERN_ERR "can't set codec system clock\n"); |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static struct snd_soc_ops zoom2_voice_ops = { |
| 126 | .hw_params = zoom2_hw_voice_params, |
| 127 | }; |
| 128 | |
| 129 | /* Zoom2 machine DAPM */ |
| 130 | static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = { |
| 131 | SND_SOC_DAPM_MIC("Ext Mic", NULL), |
| 132 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 133 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 134 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), |
| 135 | SND_SOC_DAPM_LINE("Aux In", NULL), |
| 136 | }; |
| 137 | |
| 138 | static const struct snd_soc_dapm_route audio_map[] = { |
| 139 | /* External Mics: MAINMIC, SUBMIC with bias*/ |
| 140 | {"MAINMIC", NULL, "Mic Bias 1"}, |
| 141 | {"SUBMIC", NULL, "Mic Bias 2"}, |
| 142 | {"Mic Bias 1", NULL, "Ext Mic"}, |
| 143 | {"Mic Bias 2", NULL, "Ext Mic"}, |
| 144 | |
| 145 | /* External Speakers: HFL, HFR */ |
| 146 | {"Ext Spk", NULL, "HFL"}, |
| 147 | {"Ext Spk", NULL, "HFR"}, |
| 148 | |
| 149 | /* Headset Stereophone: HSOL, HSOR */ |
| 150 | {"Headset Stereophone", NULL, "HSOL"}, |
| 151 | {"Headset Stereophone", NULL, "HSOR"}, |
| 152 | |
| 153 | /* Headset Mic: HSMIC with bias */ |
| 154 | {"HSMIC", NULL, "Headset Mic Bias"}, |
| 155 | {"Headset Mic Bias", NULL, "Headset Mic"}, |
| 156 | |
| 157 | /* Aux In: AUXL, AUXR */ |
| 158 | {"Aux In", NULL, "AUXL"}, |
| 159 | {"Aux In", NULL, "AUXR"}, |
| 160 | }; |
| 161 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 162 | static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 163 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 164 | struct snd_soc_codec *codec = rtd->codec; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 165 | int ret; |
| 166 | |
| 167 | /* Add Zoom2 specific widgets */ |
| 168 | ret = snd_soc_dapm_new_controls(codec, zoom2_twl4030_dapm_widgets, |
| 169 | ARRAY_SIZE(zoom2_twl4030_dapm_widgets)); |
| 170 | if (ret) |
| 171 | return ret; |
| 172 | |
| 173 | /* Set up Zoom2 specific audio path audio_map */ |
| 174 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
| 175 | |
| 176 | /* Zoom2 connected pins */ |
| 177 | snd_soc_dapm_enable_pin(codec, "Ext Mic"); |
| 178 | snd_soc_dapm_enable_pin(codec, "Ext Spk"); |
| 179 | snd_soc_dapm_enable_pin(codec, "Headset Mic"); |
| 180 | snd_soc_dapm_enable_pin(codec, "Headset Stereophone"); |
| 181 | snd_soc_dapm_enable_pin(codec, "Aux In"); |
| 182 | |
| 183 | /* TWL4030 not connected pins */ |
| 184 | snd_soc_dapm_nc_pin(codec, "CARKITMIC"); |
| 185 | snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); |
| 186 | snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 187 | snd_soc_dapm_nc_pin(codec, "EARPIECE"); |
| 188 | snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); |
| 189 | snd_soc_dapm_nc_pin(codec, "PREDRIVER"); |
| 190 | snd_soc_dapm_nc_pin(codec, "CARKITL"); |
| 191 | snd_soc_dapm_nc_pin(codec, "CARKITR"); |
| 192 | |
| 193 | ret = snd_soc_dapm_sync(codec); |
| 194 | |
| 195 | return ret; |
| 196 | } |
| 197 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 198 | static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 199 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 200 | struct snd_soc_codec *codec = rtd->codec; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 201 | unsigned short reg; |
| 202 | |
| 203 | /* Enable voice interface */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 204 | reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 205 | reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 206 | codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 212 | static struct snd_soc_dai_link zoom2_dai[] = { |
| 213 | { |
| 214 | .name = "TWL4030 I2S", |
| 215 | .stream_name = "TWL4030 Audio", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 216 | .cpu_dai_name = "omap-mcbsp-dai.1", |
| 217 | .codec_dai_name = "twl4030-hifi", |
| 218 | .platform_name = "omap-pcm-audio", |
| 219 | .codec_name = "twl4030-codec", |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 220 | .init = zoom2_twl4030_init, |
| 221 | .ops = &zoom2_ops, |
| 222 | }, |
| 223 | { |
| 224 | .name = "TWL4030 PCM", |
| 225 | .stream_name = "TWL4030 Voice", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 226 | .cpu_dai_name = "omap-mcbsp-dai.2", |
| 227 | .codec_dai_name = "twl4030-voice", |
| 228 | .platform_name = "omap-pcm-audio", |
| 229 | .codec_name = "twl4030-codec", |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 230 | .init = zoom2_twl4030_voice_init, |
| 231 | .ops = &zoom2_voice_ops, |
| 232 | }, |
| 233 | }; |
| 234 | |
| 235 | /* Audio machine driver */ |
| 236 | static struct snd_soc_card snd_soc_zoom2 = { |
| 237 | .name = "Zoom2", |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 238 | .dai_link = zoom2_dai, |
| 239 | .num_links = ARRAY_SIZE(zoom2_dai), |
| 240 | }; |
| 241 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 242 | static struct platform_device *zoom2_snd_device; |
| 243 | |
| 244 | static int __init zoom2_soc_init(void) |
| 245 | { |
| 246 | int ret; |
| 247 | |
Jarkko Nikula | ec588ae | 2010-10-06 16:47:26 +0300 | [diff] [blame^] | 248 | if (!machine_is_omap_zoom2()) |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 249 | return -ENODEV; |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 250 | printk(KERN_INFO "Zoom2 SoC init\n"); |
| 251 | |
| 252 | zoom2_snd_device = platform_device_alloc("soc-audio", -1); |
| 253 | if (!zoom2_snd_device) { |
| 254 | printk(KERN_ERR "Platform device allocation failed\n"); |
| 255 | return -ENOMEM; |
| 256 | } |
| 257 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 258 | platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 259 | ret = platform_device_add(zoom2_snd_device); |
| 260 | if (ret) |
| 261 | goto err1; |
| 262 | |
| 263 | BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0); |
| 264 | gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0); |
| 265 | |
Candelaria Villareal, Jorge | 1b6ebdd | 2009-07-02 19:04:07 -0500 | [diff] [blame] | 266 | BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0); |
| 267 | gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0); |
| 268 | |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 269 | return 0; |
| 270 | |
| 271 | err1: |
| 272 | printk(KERN_ERR "Unable to add platform device\n"); |
| 273 | platform_device_put(zoom2_snd_device); |
| 274 | |
| 275 | return ret; |
| 276 | } |
| 277 | module_init(zoom2_soc_init); |
| 278 | |
| 279 | static void __exit zoom2_soc_exit(void) |
| 280 | { |
| 281 | gpio_free(ZOOM2_HEADSET_MUX_GPIO); |
Candelaria Villareal, Jorge | 1b6ebdd | 2009-07-02 19:04:07 -0500 | [diff] [blame] | 282 | gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO); |
Lopez Cruz, Misael | df20593 | 2009-06-11 17:35:27 -0500 | [diff] [blame] | 283 | |
| 284 | platform_device_unregister(zoom2_snd_device); |
| 285 | } |
| 286 | module_exit(zoom2_soc_exit); |
| 287 | |
| 288 | MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>"); |
| 289 | MODULE_DESCRIPTION("ALSA SoC Zoom2"); |
| 290 | MODULE_LICENSE("GPL"); |
| 291 | |