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