Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 1 | /* |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 2 | * neo1973_wm8753.c -- SoC audio for Openmoko Neo1973 and Freerunner devices |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 3 | * |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 4 | * Copyright 2007 Openmoko Inc |
| 5 | * Author: Graeme Gregory <graeme@openmoko.org> |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 6 | * Copyright 2007 Wolfson Microelectronics PLC. |
| 7 | * Author: Graeme Gregory |
| 8 | * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 9 | * Copyright 2009 Wolfson Microelectronics |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 19 | #include <linux/gpio.h> |
| 20 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 21 | #include <sound/soc.h> |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 22 | |
Mark Brown | fb2aa07 | 2008-10-08 13:02:20 +0100 | [diff] [blame] | 23 | #include <asm/mach-types.h> |
Arnd Bergmann | 5d229ce5 | 2013-04-11 19:08:42 +0200 | [diff] [blame] | 24 | #include "regs-iis.h" |
Harald Welte | aa9673c | 2007-12-19 15:37:49 +0100 | [diff] [blame] | 25 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 26 | #include "../codecs/wm8753.h" |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 27 | #include "s3c24xx-i2s.h" |
| 28 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 29 | static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream, |
| 30 | struct snd_pcm_hw_params *params) |
| 31 | { |
| 32 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 33 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 34 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 35 | unsigned int pll_out = 0, bclk = 0; |
| 36 | int ret = 0; |
| 37 | unsigned long iis_clkrate; |
| 38 | |
| 39 | iis_clkrate = s3c24xx_i2s_get_clockrate(); |
| 40 | |
| 41 | switch (params_rate(params)) { |
| 42 | case 8000: |
| 43 | case 16000: |
| 44 | pll_out = 12288000; |
| 45 | break; |
| 46 | case 48000: |
| 47 | bclk = WM8753_BCLK_DIV_4; |
| 48 | pll_out = 12288000; |
| 49 | break; |
| 50 | case 96000: |
| 51 | bclk = WM8753_BCLK_DIV_2; |
| 52 | pll_out = 12288000; |
| 53 | break; |
| 54 | case 11025: |
| 55 | bclk = WM8753_BCLK_DIV_16; |
| 56 | pll_out = 11289600; |
| 57 | break; |
| 58 | case 22050: |
| 59 | bclk = WM8753_BCLK_DIV_8; |
| 60 | pll_out = 11289600; |
| 61 | break; |
| 62 | case 44100: |
| 63 | bclk = WM8753_BCLK_DIV_4; |
| 64 | pll_out = 11289600; |
| 65 | break; |
| 66 | case 88200: |
| 67 | bclk = WM8753_BCLK_DIV_2; |
| 68 | pll_out = 11289600; |
| 69 | break; |
| 70 | } |
| 71 | |
| 72 | /* set codec DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 73 | ret = snd_soc_dai_set_fmt(codec_dai, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 74 | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 75 | SND_SOC_DAIFMT_CBM_CFM); |
| 76 | if (ret < 0) |
| 77 | return ret; |
| 78 | |
| 79 | /* set cpu DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 80 | ret = snd_soc_dai_set_fmt(cpu_dai, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 81 | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 82 | SND_SOC_DAIFMT_CBM_CFM); |
| 83 | if (ret < 0) |
| 84 | return ret; |
| 85 | |
| 86 | /* set the codec system clock for DAC and ADC */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 87 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 88 | SND_SOC_CLOCK_IN); |
| 89 | if (ret < 0) |
| 90 | return ret; |
| 91 | |
| 92 | /* set MCLK division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 93 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK, |
Graeme Gregory | 8ba02ac | 2008-04-30 20:24:54 +0200 | [diff] [blame] | 94 | S3C2410_IISMOD_32FS); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 95 | if (ret < 0) |
| 96 | return ret; |
| 97 | |
| 98 | /* set codec BCLK division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 99 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 100 | if (ret < 0) |
| 101 | return ret; |
| 102 | |
| 103 | /* set prescaler division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 104 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER, |
Graeme Gregory | 8ba02ac | 2008-04-30 20:24:54 +0200 | [diff] [blame] | 105 | S3C24XX_PRESCALE(4, 4)); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 106 | if (ret < 0) |
| 107 | return ret; |
| 108 | |
| 109 | /* codec PLL input is PCLK/4 */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 110 | ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 111 | iis_clkrate / 4, pll_out); |
| 112 | if (ret < 0) |
| 113 | return ret; |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream) |
| 119 | { |
| 120 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 121 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 122 | |
| 123 | /* disable the PLL */ |
Takashi Iwai | 140318a | 2009-10-01 08:40:32 +0200 | [diff] [blame] | 124 | return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Neo1973 WM8753 HiFi DAI opserations. |
| 129 | */ |
| 130 | static struct snd_soc_ops neo1973_hifi_ops = { |
| 131 | .hw_params = neo1973_hifi_hw_params, |
| 132 | .hw_free = neo1973_hifi_hw_free, |
| 133 | }; |
| 134 | |
| 135 | static int neo1973_voice_hw_params(struct snd_pcm_substream *substream, |
| 136 | struct snd_pcm_hw_params *params) |
| 137 | { |
| 138 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 139 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 140 | unsigned int pcmdiv = 0; |
| 141 | int ret = 0; |
| 142 | unsigned long iis_clkrate; |
| 143 | |
| 144 | iis_clkrate = s3c24xx_i2s_get_clockrate(); |
| 145 | |
| 146 | if (params_rate(params) != 8000) |
| 147 | return -EINVAL; |
| 148 | if (params_channels(params) != 1) |
| 149 | return -EINVAL; |
| 150 | |
| 151 | pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */ |
| 152 | |
| 153 | /* todo: gg check mode (DSP_B) against CSR datasheet */ |
| 154 | /* set codec DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 155 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 156 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); |
| 157 | if (ret < 0) |
| 158 | return ret; |
| 159 | |
| 160 | /* set the codec system clock for DAC and ADC */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 161 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 162 | SND_SOC_CLOCK_IN); |
| 163 | if (ret < 0) |
| 164 | return ret; |
| 165 | |
| 166 | /* set codec PCM division for sample rate */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 167 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 168 | if (ret < 0) |
| 169 | return ret; |
| 170 | |
Andrea Gelmini | fa2eb00 | 2010-10-16 15:19:20 +0200 | [diff] [blame] | 171 | /* configure and enable PLL for 12.288MHz output */ |
Takashi Iwai | 140318a | 2009-10-01 08:40:32 +0200 | [diff] [blame] | 172 | ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 173 | iis_clkrate / 4, 12288000); |
| 174 | if (ret < 0) |
| 175 | return ret; |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int neo1973_voice_hw_free(struct snd_pcm_substream *substream) |
| 181 | { |
| 182 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 183 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 184 | |
| 185 | /* disable the PLL */ |
Takashi Iwai | 140318a | 2009-10-01 08:40:32 +0200 | [diff] [blame] | 186 | return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static struct snd_soc_ops neo1973_voice_ops = { |
| 190 | .hw_params = neo1973_voice_hw_params, |
| 191 | .hw_free = neo1973_voice_hw_free, |
| 192 | }; |
| 193 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 194 | /* Shared routes and controls */ |
| 195 | |
| 196 | static const struct snd_soc_dapm_widget neo1973_wm8753_dapm_widgets[] = { |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 197 | SND_SOC_DAPM_LINE("GSM Line Out", NULL), |
| 198 | SND_SOC_DAPM_LINE("GSM Line In", NULL), |
| 199 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 200 | SND_SOC_DAPM_MIC("Handset Mic", NULL), |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 201 | }; |
| 202 | |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 203 | static const struct snd_soc_dapm_route neo1973_wm8753_routes[] = { |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 204 | /* Connections to the GSM Module */ |
| 205 | {"GSM Line Out", NULL, "MONO1"}, |
| 206 | {"GSM Line Out", NULL, "MONO2"}, |
| 207 | {"RXP", NULL, "GSM Line In"}, |
| 208 | {"RXN", NULL, "GSM Line In"}, |
| 209 | |
| 210 | /* Connections to Headset */ |
| 211 | {"MIC1", NULL, "Mic Bias"}, |
| 212 | {"Mic Bias", NULL, "Headset Mic"}, |
| 213 | |
| 214 | /* Call Mic */ |
| 215 | {"MIC2", NULL, "Mic Bias"}, |
| 216 | {"MIC2N", NULL, "Mic Bias"}, |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 217 | {"Mic Bias", NULL, "Handset Mic"}, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 218 | |
| 219 | /* Connect the ALC pins */ |
| 220 | {"ACIN", NULL, "ACOP"}, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 223 | static const struct snd_kcontrol_new neo1973_wm8753_controls[] = { |
Lars-Peter Clausen | 004c52e | 2011-03-07 08:04:54 +0100 | [diff] [blame] | 224 | SOC_DAPM_PIN_SWITCH("GSM Line Out"), |
| 225 | SOC_DAPM_PIN_SWITCH("GSM Line In"), |
| 226 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 227 | SOC_DAPM_PIN_SWITCH("Handset Mic"), |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 230 | /* GTA02 specific routes and controls */ |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 231 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 232 | static int gta02_speaker_enabled; |
| 233 | |
| 234 | static int lm4853_set_spk(struct snd_kcontrol *kcontrol, |
| 235 | struct snd_ctl_elem_value *ucontrol) |
| 236 | { |
| 237 | gta02_speaker_enabled = ucontrol->value.integer.value[0]; |
| 238 | |
Kukjin Kim | b2ca787 | 2013-01-02 09:57:59 -0800 | [diff] [blame] | 239 | gpio_set_value(S3C2410_GPJ(2), !gta02_speaker_enabled); |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | static int lm4853_get_spk(struct snd_kcontrol *kcontrol, |
| 245 | struct snd_ctl_elem_value *ucontrol) |
| 246 | { |
| 247 | ucontrol->value.integer.value[0] = gta02_speaker_enabled; |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static int lm4853_event(struct snd_soc_dapm_widget *w, |
| 252 | struct snd_kcontrol *k, int event) |
| 253 | { |
Kukjin Kim | b2ca787 | 2013-01-02 09:57:59 -0800 | [diff] [blame] | 254 | gpio_set_value(S3C2410_GPJ(1), SND_SOC_DAPM_EVENT_OFF(event)); |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | static const struct snd_soc_dapm_route neo1973_gta02_routes[] = { |
| 260 | /* Connections to the amp */ |
| 261 | {"Stereo Out", NULL, "LOUT1"}, |
| 262 | {"Stereo Out", NULL, "ROUT1"}, |
| 263 | |
| 264 | /* Call Speaker */ |
| 265 | {"Handset Spk", NULL, "LOUT2"}, |
| 266 | {"Handset Spk", NULL, "ROUT2"}, |
| 267 | }; |
| 268 | |
| 269 | static const struct snd_kcontrol_new neo1973_gta02_wm8753_controls[] = { |
| 270 | SOC_DAPM_PIN_SWITCH("Handset Spk"), |
| 271 | SOC_DAPM_PIN_SWITCH("Stereo Out"), |
| 272 | |
| 273 | SOC_SINGLE_BOOL_EXT("Amp Spk Switch", 0, |
| 274 | lm4853_get_spk, |
| 275 | lm4853_set_spk), |
| 276 | }; |
| 277 | |
| 278 | static const struct snd_soc_dapm_widget neo1973_gta02_wm8753_dapm_widgets[] = { |
| 279 | SND_SOC_DAPM_SPK("Handset Spk", NULL), |
| 280 | SND_SOC_DAPM_SPK("Stereo Out", lm4853_event), |
| 281 | }; |
| 282 | |
| 283 | static int neo1973_gta02_wm8753_init(struct snd_soc_codec *codec) |
| 284 | { |
| 285 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 286 | int ret; |
| 287 | |
| 288 | ret = snd_soc_dapm_new_controls(dapm, neo1973_gta02_wm8753_dapm_widgets, |
| 289 | ARRAY_SIZE(neo1973_gta02_wm8753_dapm_widgets)); |
| 290 | if (ret) |
| 291 | return ret; |
| 292 | |
| 293 | ret = snd_soc_dapm_add_routes(dapm, neo1973_gta02_routes, |
| 294 | ARRAY_SIZE(neo1973_gta02_routes)); |
| 295 | if (ret) |
| 296 | return ret; |
| 297 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 298 | ret = snd_soc_add_card_controls(codec->card, neo1973_gta02_wm8753_controls, |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 299 | ARRAY_SIZE(neo1973_gta02_wm8753_controls)); |
| 300 | if (ret) |
| 301 | return ret; |
| 302 | |
| 303 | snd_soc_dapm_disable_pin(dapm, "Stereo Out"); |
| 304 | snd_soc_dapm_disable_pin(dapm, "Handset Spk"); |
| 305 | snd_soc_dapm_ignore_suspend(dapm, "Stereo Out"); |
| 306 | snd_soc_dapm_ignore_suspend(dapm, "Handset Spk"); |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 311 | static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd) |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 312 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 313 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 314 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 315 | int ret; |
Tim Niemeyer | 1894c59 | 2008-05-05 14:16:12 +0200 | [diff] [blame] | 316 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 317 | /* set up NC codec pins */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 318 | snd_soc_dapm_nc_pin(dapm, "OUT3"); |
| 319 | snd_soc_dapm_nc_pin(dapm, "OUT4"); |
| 320 | snd_soc_dapm_nc_pin(dapm, "LINE1"); |
| 321 | snd_soc_dapm_nc_pin(dapm, "LINE2"); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 322 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 323 | /* Add neo1973 specific widgets */ |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 324 | ret = snd_soc_dapm_new_controls(dapm, neo1973_wm8753_dapm_widgets, |
| 325 | ARRAY_SIZE(neo1973_wm8753_dapm_widgets)); |
| 326 | if (ret) |
| 327 | return ret; |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 328 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 329 | /* add neo1973 specific controls */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 330 | ret = snd_soc_add_card_controls(rtd->card, neo1973_wm8753_controls, |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 331 | ARRAY_SIZE(neo1973_wm8753_controls)); |
| 332 | if (ret) |
| 333 | return ret; |
| 334 | |
| 335 | /* set up neo1973 specific audio routes */ |
| 336 | ret = snd_soc_dapm_add_routes(dapm, neo1973_wm8753_routes, |
| 337 | ARRAY_SIZE(neo1973_wm8753_routes)); |
| 338 | if (ret) |
| 339 | return ret; |
| 340 | |
| 341 | /* set endpoints to default off mode */ |
Lars-Peter Clausen | 004c52e | 2011-03-07 08:04:54 +0100 | [diff] [blame] | 342 | snd_soc_dapm_disable_pin(dapm, "GSM Line Out"); |
| 343 | snd_soc_dapm_disable_pin(dapm, "GSM Line In"); |
| 344 | snd_soc_dapm_disable_pin(dapm, "Headset Mic"); |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 345 | snd_soc_dapm_disable_pin(dapm, "Handset Mic"); |
Jonas Bonn | e808994 | 2008-10-01 18:17:12 +0100 | [diff] [blame] | 346 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 347 | /* allow audio paths from the GSM modem to run during suspend */ |
| 348 | snd_soc_dapm_ignore_suspend(dapm, "GSM Line Out"); |
| 349 | snd_soc_dapm_ignore_suspend(dapm, "GSM Line In"); |
| 350 | snd_soc_dapm_ignore_suspend(dapm, "Headset Mic"); |
| 351 | snd_soc_dapm_ignore_suspend(dapm, "Handset Mic"); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 352 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 353 | if (machine_is_neo1973_gta02()) { |
| 354 | ret = neo1973_gta02_wm8753_init(codec); |
| 355 | if (ret) |
| 356 | return ret; |
| 357 | } |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 358 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 359 | return 0; |
| 360 | } |
| 361 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 362 | static struct snd_soc_dai_link neo1973_dai[] = { |
| 363 | { /* Hifi Playback - for similatious use with voice below */ |
| 364 | .name = "WM8753", |
| 365 | .stream_name = "WM8753 HiFi", |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 366 | .platform_name = "s3c24xx-iis", |
Lars-Peter Clausen | 518aa59 | 2011-01-24 22:12:42 +0100 | [diff] [blame] | 367 | .cpu_dai_name = "s3c24xx-iis", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 368 | .codec_dai_name = "wm8753-hifi", |
Denis 'GNUtoo' Carikli | b2ccf06 | 2012-02-26 19:21:54 +0100 | [diff] [blame] | 369 | .codec_name = "wm8753.0-001a", |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 370 | .init = neo1973_wm8753_init, |
| 371 | .ops = &neo1973_hifi_ops, |
| 372 | }, |
| 373 | { /* Voice via BT */ |
| 374 | .name = "Bluetooth", |
| 375 | .stream_name = "Voice", |
Barry Song | 200ceb9 | 2013-05-18 20:25:00 +0800 | [diff] [blame] | 376 | .cpu_dai_name = "bt-sco-pcm", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 377 | .codec_dai_name = "wm8753-voice", |
Denis 'GNUtoo' Carikli | b2ccf06 | 2012-02-26 19:21:54 +0100 | [diff] [blame] | 378 | .codec_name = "wm8753.0-001a", |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 379 | .ops = &neo1973_voice_ops, |
| 380 | }, |
| 381 | }; |
| 382 | |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 383 | static struct snd_soc_aux_dev neo1973_aux_devs[] = { |
| 384 | { |
Lars-Peter Clausen | a077ff9 | 2011-03-07 08:04:59 +0100 | [diff] [blame] | 385 | .name = "dfbmcs320", |
| 386 | .codec_name = "dfbmcs320.0", |
| 387 | }, |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | static struct snd_soc_codec_conf neo1973_codec_conf[] = { |
| 391 | { |
| 392 | .dev_name = "lm4857.0-007c", |
| 393 | .name_prefix = "Amp", |
| 394 | }, |
| 395 | }; |
| 396 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 397 | static const struct gpio neo1973_gta02_gpios[] = { |
Kukjin Kim | b2ca787 | 2013-01-02 09:57:59 -0800 | [diff] [blame] | 398 | { S3C2410_GPJ(2), GPIOF_OUT_INIT_HIGH, "GTA02_HP_IN" }, |
| 399 | { S3C2410_GPJ(1), GPIOF_OUT_INIT_HIGH, "GTA02_AMP_SHUT" }, |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 400 | }; |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 401 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 402 | static struct snd_soc_card neo1973 = { |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 403 | .name = "neo1973", |
Axel Lin | 095d79d | 2011-12-22 10:53:15 +0800 | [diff] [blame] | 404 | .owner = THIS_MODULE, |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 405 | .dai_link = neo1973_dai, |
| 406 | .num_links = ARRAY_SIZE(neo1973_dai), |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 407 | .aux_dev = neo1973_aux_devs, |
| 408 | .num_aux_devs = ARRAY_SIZE(neo1973_aux_devs), |
| 409 | .codec_conf = neo1973_codec_conf, |
| 410 | .num_configs = ARRAY_SIZE(neo1973_codec_conf), |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 411 | }; |
| 412 | |
| 413 | static struct platform_device *neo1973_snd_device; |
| 414 | |
| 415 | static int __init neo1973_init(void) |
| 416 | { |
| 417 | int ret; |
| 418 | |
Denis 'GNUtoo' Carikli | 1ae5cbc | 2012-01-30 00:31:47 +0100 | [diff] [blame] | 419 | if (!machine_is_neo1973_gta02()) |
Mark Brown | fb2aa07 | 2008-10-08 13:02:20 +0100 | [diff] [blame] | 420 | return -ENODEV; |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 421 | |
| 422 | if (machine_is_neo1973_gta02()) { |
| 423 | neo1973.name = "neo1973gta02"; |
Lars-Peter Clausen | a077ff9 | 2011-03-07 08:04:59 +0100 | [diff] [blame] | 424 | neo1973.num_aux_devs = 1; |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 425 | |
| 426 | ret = gpio_request_array(neo1973_gta02_gpios, |
| 427 | ARRAY_SIZE(neo1973_gta02_gpios)); |
| 428 | if (ret) |
| 429 | return ret; |
Mark Brown | fb2aa07 | 2008-10-08 13:02:20 +0100 | [diff] [blame] | 430 | } |
| 431 | |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 432 | neo1973_snd_device = platform_device_alloc("soc-audio", -1); |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 433 | if (!neo1973_snd_device) { |
| 434 | ret = -ENOMEM; |
| 435 | goto err_gpio_free; |
| 436 | } |
| 437 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 438 | platform_set_drvdata(neo1973_snd_device, &neo1973); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 439 | ret = platform_device_add(neo1973_snd_device); |
| 440 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 441 | if (ret) |
Lars-Peter Clausen | a077ff9 | 2011-03-07 08:04:59 +0100 | [diff] [blame] | 442 | goto err_put_device; |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 443 | |
| 444 | return 0; |
| 445 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 446 | err_put_device: |
| 447 | platform_device_put(neo1973_snd_device); |
| 448 | err_gpio_free: |
| 449 | if (machine_is_neo1973_gta02()) { |
| 450 | gpio_free_array(neo1973_gta02_gpios, |
| 451 | ARRAY_SIZE(neo1973_gta02_gpios)); |
Jean Delvare | d280289 | 2008-09-01 17:44:05 +0200 | [diff] [blame] | 452 | } |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 453 | return ret; |
| 454 | } |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 455 | module_init(neo1973_init); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 456 | |
| 457 | static void __exit neo1973_exit(void) |
| 458 | { |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 459 | platform_device_unregister(neo1973_snd_device); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 460 | |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 461 | if (machine_is_neo1973_gta02()) { |
| 462 | gpio_free_array(neo1973_gta02_gpios, |
| 463 | ARRAY_SIZE(neo1973_gta02_gpios)); |
| 464 | } |
| 465 | } |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 466 | module_exit(neo1973_exit); |
| 467 | |
| 468 | /* Module information */ |
Graeme Gregory | 443590e | 2008-04-30 20:25:23 +0200 | [diff] [blame] | 469 | MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org"); |
Lars-Peter Clausen | f5c4ffb | 2011-03-07 08:04:58 +0100 | [diff] [blame] | 470 | MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973 and Frerunner"); |
Graeme Gregory | 74930bb | 2007-05-14 11:03:52 +0200 | [diff] [blame] | 471 | MODULE_LICENSE("GPL"); |