0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/module.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/gpio/consumer.h>
0015
0016 #include <sound/soc.h>
0017
0018 #include "regs-iis.h"
0019 #include "../codecs/wm8753.h"
0020 #include "s3c24xx-i2s.h"
0021
0022 static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
0023 struct snd_pcm_hw_params *params)
0024 {
0025 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0026 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0027 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0028 unsigned int pll_out = 0, bclk = 0;
0029 int ret = 0;
0030 unsigned long iis_clkrate;
0031
0032 iis_clkrate = s3c24xx_i2s_get_clockrate();
0033
0034 switch (params_rate(params)) {
0035 case 8000:
0036 case 16000:
0037 pll_out = 12288000;
0038 break;
0039 case 48000:
0040 bclk = WM8753_BCLK_DIV_4;
0041 pll_out = 12288000;
0042 break;
0043 case 96000:
0044 bclk = WM8753_BCLK_DIV_2;
0045 pll_out = 12288000;
0046 break;
0047 case 11025:
0048 bclk = WM8753_BCLK_DIV_16;
0049 pll_out = 11289600;
0050 break;
0051 case 22050:
0052 bclk = WM8753_BCLK_DIV_8;
0053 pll_out = 11289600;
0054 break;
0055 case 44100:
0056 bclk = WM8753_BCLK_DIV_4;
0057 pll_out = 11289600;
0058 break;
0059 case 88200:
0060 bclk = WM8753_BCLK_DIV_2;
0061 pll_out = 11289600;
0062 break;
0063 }
0064
0065
0066 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out,
0067 SND_SOC_CLOCK_IN);
0068 if (ret < 0)
0069 return ret;
0070
0071
0072 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
0073 S3C2410_IISMOD_32FS);
0074 if (ret < 0)
0075 return ret;
0076
0077
0078 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
0079 if (ret < 0)
0080 return ret;
0081
0082
0083 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
0084 S3C24XX_PRESCALE(4, 4));
0085 if (ret < 0)
0086 return ret;
0087
0088
0089 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0,
0090 iis_clkrate / 4, pll_out);
0091 if (ret < 0)
0092 return ret;
0093
0094 return 0;
0095 }
0096
0097 static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
0098 {
0099 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0100 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0101
0102
0103 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0, 0);
0104 }
0105
0106
0107
0108
0109 static const struct snd_soc_ops neo1973_hifi_ops = {
0110 .hw_params = neo1973_hifi_hw_params,
0111 .hw_free = neo1973_hifi_hw_free,
0112 };
0113
0114 static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
0115 struct snd_pcm_hw_params *params)
0116 {
0117 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0118 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0119 unsigned int pcmdiv = 0;
0120 int ret = 0;
0121 unsigned long iis_clkrate;
0122
0123 iis_clkrate = s3c24xx_i2s_get_clockrate();
0124
0125 if (params_rate(params) != 8000)
0126 return -EINVAL;
0127 if (params_channels(params) != 1)
0128 return -EINVAL;
0129
0130 pcmdiv = WM8753_PCM_DIV_6;
0131
0132
0133 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
0134 SND_SOC_CLOCK_IN);
0135 if (ret < 0)
0136 return ret;
0137
0138
0139 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv);
0140 if (ret < 0)
0141 return ret;
0142
0143
0144 ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0,
0145 iis_clkrate / 4, 12288000);
0146 if (ret < 0)
0147 return ret;
0148
0149 return 0;
0150 }
0151
0152 static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
0153 {
0154 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0155 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0156
0157
0158 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
0159 }
0160
0161 static const struct snd_soc_ops neo1973_voice_ops = {
0162 .hw_params = neo1973_voice_hw_params,
0163 .hw_free = neo1973_voice_hw_free,
0164 };
0165
0166 static struct gpio_desc *gpiod_hp_in, *gpiod_amp_shut;
0167 static int gta02_speaker_enabled;
0168
0169 static int lm4853_set_spk(struct snd_kcontrol *kcontrol,
0170 struct snd_ctl_elem_value *ucontrol)
0171 {
0172 gta02_speaker_enabled = ucontrol->value.integer.value[0];
0173
0174 gpiod_set_value(gpiod_hp_in, !gta02_speaker_enabled);
0175
0176 return 0;
0177 }
0178
0179 static int lm4853_get_spk(struct snd_kcontrol *kcontrol,
0180 struct snd_ctl_elem_value *ucontrol)
0181 {
0182 ucontrol->value.integer.value[0] = gta02_speaker_enabled;
0183 return 0;
0184 }
0185
0186 static int lm4853_event(struct snd_soc_dapm_widget *w,
0187 struct snd_kcontrol *k, int event)
0188 {
0189 gpiod_set_value(gpiod_amp_shut, SND_SOC_DAPM_EVENT_OFF(event));
0190
0191 return 0;
0192 }
0193
0194 static const struct snd_soc_dapm_widget neo1973_wm8753_dapm_widgets[] = {
0195 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
0196 SND_SOC_DAPM_LINE("GSM Line In", NULL),
0197 SND_SOC_DAPM_MIC("Headset Mic", NULL),
0198 SND_SOC_DAPM_MIC("Handset Mic", NULL),
0199 SND_SOC_DAPM_SPK("Handset Spk", NULL),
0200 SND_SOC_DAPM_SPK("Stereo Out", lm4853_event),
0201 };
0202
0203 static const struct snd_soc_dapm_route neo1973_wm8753_routes[] = {
0204
0205 {"GSM Line Out", NULL, "MONO1"},
0206 {"GSM Line Out", NULL, "MONO2"},
0207 {"RXP", NULL, "GSM Line In"},
0208 {"RXN", NULL, "GSM Line In"},
0209
0210
0211 {"MIC1", NULL, "Mic Bias"},
0212 {"Mic Bias", NULL, "Headset Mic"},
0213
0214
0215 {"MIC2", NULL, "Mic Bias"},
0216 {"MIC2N", NULL, "Mic Bias"},
0217 {"Mic Bias", NULL, "Handset Mic"},
0218
0219
0220 {"ACIN", NULL, "ACOP"},
0221
0222
0223 {"Stereo Out", NULL, "LOUT1"},
0224 {"Stereo Out", NULL, "ROUT1"},
0225
0226
0227 {"Handset Spk", NULL, "LOUT2"},
0228 {"Handset Spk", NULL, "ROUT2"},
0229 };
0230
0231 static const struct snd_kcontrol_new neo1973_wm8753_controls[] = {
0232 SOC_DAPM_PIN_SWITCH("GSM Line Out"),
0233 SOC_DAPM_PIN_SWITCH("GSM Line In"),
0234 SOC_DAPM_PIN_SWITCH("Headset Mic"),
0235 SOC_DAPM_PIN_SWITCH("Handset Mic"),
0236 SOC_DAPM_PIN_SWITCH("Handset Spk"),
0237 SOC_DAPM_PIN_SWITCH("Stereo Out"),
0238
0239 SOC_SINGLE_BOOL_EXT("Amp Spk Switch", 0,
0240 lm4853_get_spk,
0241 lm4853_set_spk),
0242 };
0243
0244 static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd)
0245 {
0246 struct snd_soc_card *card = rtd->card;
0247
0248
0249 snd_soc_dapm_disable_pin(&card->dapm, "GSM Line Out");
0250 snd_soc_dapm_disable_pin(&card->dapm, "GSM Line In");
0251 snd_soc_dapm_disable_pin(&card->dapm, "Headset Mic");
0252 snd_soc_dapm_disable_pin(&card->dapm, "Handset Mic");
0253 snd_soc_dapm_disable_pin(&card->dapm, "Stereo Out");
0254 snd_soc_dapm_disable_pin(&card->dapm, "Handset Spk");
0255
0256
0257 snd_soc_dapm_ignore_suspend(&card->dapm, "GSM Line Out");
0258 snd_soc_dapm_ignore_suspend(&card->dapm, "GSM Line In");
0259 snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
0260 snd_soc_dapm_ignore_suspend(&card->dapm, "Handset Mic");
0261 snd_soc_dapm_ignore_suspend(&card->dapm, "Stereo Out");
0262 snd_soc_dapm_ignore_suspend(&card->dapm, "Handset Spk");
0263
0264 return 0;
0265 }
0266
0267 SND_SOC_DAILINK_DEFS(wm8753,
0268 DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")),
0269 DAILINK_COMP_ARRAY(COMP_CODEC("wm8753.0-001a", "wm8753-hifi")),
0270 DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis")));
0271
0272 SND_SOC_DAILINK_DEFS(bluetooth,
0273 DAILINK_COMP_ARRAY(COMP_CPU("bt-sco-pcm")),
0274 DAILINK_COMP_ARRAY(COMP_CODEC("wm8753.0-001a", "wm8753-voice")));
0275
0276 static struct snd_soc_dai_link neo1973_dai[] = {
0277 {
0278 .name = "WM8753",
0279 .stream_name = "WM8753 HiFi",
0280 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0281 SND_SOC_DAIFMT_CBM_CFM,
0282 .init = neo1973_wm8753_init,
0283 .ops = &neo1973_hifi_ops,
0284 SND_SOC_DAILINK_REG(wm8753),
0285 },
0286 {
0287 .name = "Bluetooth",
0288 .stream_name = "Voice",
0289 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
0290 SND_SOC_DAIFMT_CBS_CFS,
0291 .ops = &neo1973_voice_ops,
0292 SND_SOC_DAILINK_REG(bluetooth),
0293 },
0294 };
0295
0296 static struct snd_soc_aux_dev neo1973_aux_devs[] = {
0297 {
0298 .dlc = COMP_AUX("dfbmcs320.0"),
0299 },
0300 };
0301
0302 static struct snd_soc_codec_conf neo1973_codec_conf[] = {
0303 {
0304 .dlc = COMP_CODEC_CONF("lm4857.0-007c"),
0305 .name_prefix = "Amp",
0306 },
0307 };
0308
0309 static struct snd_soc_card neo1973 = {
0310 .name = "neo1973gta02",
0311 .owner = THIS_MODULE,
0312 .dai_link = neo1973_dai,
0313 .num_links = ARRAY_SIZE(neo1973_dai),
0314 .aux_dev = neo1973_aux_devs,
0315 .num_aux_devs = ARRAY_SIZE(neo1973_aux_devs),
0316 .codec_conf = neo1973_codec_conf,
0317 .num_configs = ARRAY_SIZE(neo1973_codec_conf),
0318
0319 .controls = neo1973_wm8753_controls,
0320 .num_controls = ARRAY_SIZE(neo1973_wm8753_controls),
0321 .dapm_widgets = neo1973_wm8753_dapm_widgets,
0322 .num_dapm_widgets = ARRAY_SIZE(neo1973_wm8753_dapm_widgets),
0323 .dapm_routes = neo1973_wm8753_routes,
0324 .num_dapm_routes = ARRAY_SIZE(neo1973_wm8753_routes),
0325 .fully_routed = true,
0326 };
0327
0328 static int neo1973_probe(struct platform_device *pdev)
0329 {
0330 struct device *dev = &pdev->dev;
0331
0332 gpiod_hp_in = devm_gpiod_get(dev, "hp", GPIOD_OUT_HIGH);
0333 if (IS_ERR(gpiod_hp_in)) {
0334 dev_err(dev, "missing gpio %s\n", "hp");
0335 return PTR_ERR(gpiod_hp_in);
0336 }
0337 gpiod_amp_shut = devm_gpiod_get(dev, "amp-shut", GPIOD_OUT_HIGH);
0338 if (IS_ERR(gpiod_amp_shut)) {
0339 dev_err(dev, "missing gpio %s\n", "amp-shut");
0340 return PTR_ERR(gpiod_amp_shut);
0341 }
0342
0343 neo1973.dev = dev;
0344 return devm_snd_soc_register_card(dev, &neo1973);
0345 }
0346
0347 static struct platform_driver neo1973_audio = {
0348 .driver = {
0349 .name = "neo1973-audio",
0350 .pm = &snd_soc_pm_ops,
0351 },
0352 .probe = neo1973_probe,
0353 };
0354 module_platform_driver(neo1973_audio);
0355
0356
0357 MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
0358 MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973 and Frerunner");
0359 MODULE_LICENSE("GPL");
0360 MODULE_ALIAS("platform:neo1973-audio");