Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Littlemill audio support |
| 3 | * |
| 4 | * Copyright 2011 Wolfson Microelectronics |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <sound/soc.h> |
| 13 | #include <sound/soc-dapm.h> |
| 14 | #include <sound/jack.h> |
| 15 | #include <linux/gpio.h> |
| 16 | #include <linux/module.h> |
| 17 | |
| 18 | #include "../codecs/wm8994.h" |
| 19 | |
| 20 | static int sample_rate = 44100; |
| 21 | |
| 22 | static int littlemill_set_bias_level(struct snd_soc_card *card, |
| 23 | struct snd_soc_dapm_context *dapm, |
| 24 | enum snd_soc_bias_level level) |
| 25 | { |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 26 | struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 27 | int ret; |
| 28 | |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 29 | if (dapm->dev != aif1_dai->dev) |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 30 | return 0; |
| 31 | |
| 32 | switch (level) { |
| 33 | case SND_SOC_BIAS_PREPARE: |
| 34 | /* |
| 35 | * If we've not already clocked things via hw_params() |
| 36 | * then do so now, otherwise these are noops. |
| 37 | */ |
| 38 | if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 39 | ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 40 | WM8994_FLL_SRC_MCLK2, 32768, |
| 41 | sample_rate * 512); |
| 42 | if (ret < 0) { |
| 43 | pr_err("Failed to start FLL: %d\n", ret); |
| 44 | return ret; |
| 45 | } |
| 46 | |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 47 | ret = snd_soc_dai_set_sysclk(aif1_dai, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 48 | WM8994_SYSCLK_FLL1, |
| 49 | sample_rate * 512, |
| 50 | SND_SOC_CLOCK_IN); |
| 51 | if (ret < 0) { |
| 52 | pr_err("Failed to set SYSCLK: %d\n", ret); |
| 53 | return ret; |
| 54 | } |
| 55 | } |
| 56 | break; |
| 57 | |
| 58 | default: |
| 59 | break; |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int littlemill_set_bias_level_post(struct snd_soc_card *card, |
| 66 | struct snd_soc_dapm_context *dapm, |
| 67 | enum snd_soc_bias_level level) |
| 68 | { |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 69 | struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; |
| 70 | struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai; |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 71 | int ret; |
| 72 | |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 73 | if (dapm->dev != aif1_dai->dev) |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 74 | return 0; |
| 75 | |
| 76 | switch (level) { |
| 77 | case SND_SOC_BIAS_STANDBY: |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 78 | ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 79 | 32768, SND_SOC_CLOCK_IN); |
| 80 | if (ret < 0) { |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 81 | pr_err("Failed to switch away from FLL2: %d\n", ret); |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 82 | return ret; |
| 83 | } |
| 84 | |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 85 | ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 86 | 0, 0, 0); |
| 87 | if (ret < 0) { |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 88 | pr_err("Failed to stop FLL2: %d\n", ret); |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2, |
| 93 | 32768, SND_SOC_CLOCK_IN); |
| 94 | if (ret < 0) { |
| 95 | pr_err("Failed to switch away from FLL1: %d\n", ret); |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, |
| 100 | 0, 0, 0); |
| 101 | if (ret < 0) { |
| 102 | pr_err("Failed to stop FLL1: %d\n", ret); |
| 103 | return ret; |
| 104 | } |
| 105 | break; |
| 106 | |
| 107 | case SND_SOC_BIAS_PREPARE: |
| 108 | ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, |
| 109 | WM8994_FLL_SRC_BCLK, 64 * 8000, |
| 110 | 8000 * 256); |
| 111 | if (ret < 0) { |
| 112 | pr_err("Failed to start FLL: %d\n", ret); |
| 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_FLL2, |
| 117 | 8000 * 256, |
| 118 | SND_SOC_CLOCK_IN); |
| 119 | if (ret < 0) { |
| 120 | pr_err("Failed to set SYSCLK: %d\n", ret); |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 121 | return ret; |
| 122 | } |
| 123 | break; |
| 124 | |
| 125 | default: |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | dapm->bias_level = level; |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static int littlemill_hw_params(struct snd_pcm_substream *substream, |
| 135 | struct snd_pcm_hw_params *params) |
| 136 | { |
| 137 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 138 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 139 | int ret; |
| 140 | |
| 141 | sample_rate = params_rate(params); |
| 142 | |
| 143 | ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, |
| 144 | WM8994_FLL_SRC_MCLK2, 32768, |
| 145 | sample_rate * 512); |
| 146 | if (ret < 0) { |
| 147 | pr_err("Failed to start FLL: %d\n", ret); |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | ret = snd_soc_dai_set_sysclk(codec_dai, |
| 152 | WM8994_SYSCLK_FLL1, |
| 153 | sample_rate * 512, |
| 154 | SND_SOC_CLOCK_IN); |
| 155 | if (ret < 0) { |
| 156 | pr_err("Failed to set SYSCLK: %d\n", ret); |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static struct snd_soc_ops littlemill_ops = { |
| 164 | .hw_params = littlemill_hw_params, |
| 165 | }; |
| 166 | |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 167 | static const struct snd_soc_pcm_stream baseband_params = { |
| 168 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 169 | .rate_min = 8000, |
| 170 | .rate_max = 8000, |
| 171 | .channels_min = 2, |
| 172 | .channels_max = 2, |
| 173 | }; |
| 174 | |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 175 | static struct snd_soc_dai_link littlemill_dai[] = { |
| 176 | { |
| 177 | .name = "CPU", |
| 178 | .stream_name = "CPU", |
| 179 | .cpu_dai_name = "samsung-i2s.0", |
| 180 | .codec_dai_name = "wm8994-aif1", |
| 181 | .platform_name = "samsung-audio", |
| 182 | .codec_name = "wm8994-codec", |
| 183 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 184 | | SND_SOC_DAIFMT_CBM_CFM, |
| 185 | .ops = &littlemill_ops, |
| 186 | }, |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 187 | { |
| 188 | .name = "Baseband", |
| 189 | .stream_name = "Baseband", |
| 190 | .cpu_dai_name = "wm8994-aif2", |
| 191 | .codec_dai_name = "wm1250-ev1", |
| 192 | .codec_name = "wm1250-ev1.1-0027", |
| 193 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 194 | | SND_SOC_DAIFMT_CBM_CFM, |
| 195 | .ignore_suspend = 1, |
| 196 | .params = &baseband_params, |
| 197 | }, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static struct snd_soc_dapm_widget widgets[] = { |
| 201 | SND_SOC_DAPM_HP("Headphone", NULL), |
Mark Brown | 8f10316 | 2011-12-02 17:36:06 +0000 | [diff] [blame] | 202 | |
| 203 | SND_SOC_DAPM_MIC("AMIC", NULL), |
| 204 | SND_SOC_DAPM_MIC("DMIC", NULL), |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | static struct snd_soc_dapm_route audio_paths[] = { |
| 208 | { "Headphone", NULL, "HPOUT1L" }, |
| 209 | { "Headphone", NULL, "HPOUT1R" }, |
Mark Brown | 8f10316 | 2011-12-02 17:36:06 +0000 | [diff] [blame] | 210 | |
| 211 | { "AMIC", NULL, "MICBIAS1" }, /* Default for AMICBIAS jumper */ |
| 212 | { "IN1LN", NULL, "AMIC" }, |
| 213 | |
| 214 | { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */ |
| 215 | { "DMIC1DAT", NULL, "DMIC" }, |
| 216 | { "DMIC2DAT", NULL, "DMIC" }, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
Mark Brown | f2e2026 | 2011-12-02 15:55:52 +0000 | [diff] [blame] | 219 | static struct snd_soc_jack littlemill_headset; |
| 220 | |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 221 | static int littlemill_late_probe(struct snd_soc_card *card) |
| 222 | { |
Mark Brown | f2e2026 | 2011-12-02 15:55:52 +0000 | [diff] [blame] | 223 | struct snd_soc_codec *codec = card->rtd[0].codec; |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 224 | struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; |
| 225 | struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai; |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 226 | int ret; |
| 227 | |
Mark Brown | 0cbe4b3 | 2012-04-18 18:20:05 +0100 | [diff] [blame^] | 228 | ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2, |
| 229 | 32768, SND_SOC_CLOCK_IN); |
| 230 | if (ret < 0) |
| 231 | return ret; |
| 232 | |
| 233 | ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 234 | 32768, SND_SOC_CLOCK_IN); |
| 235 | if (ret < 0) |
| 236 | return ret; |
| 237 | |
Mark Brown | f2e2026 | 2011-12-02 15:55:52 +0000 | [diff] [blame] | 238 | ret = snd_soc_jack_new(codec, "Headset", |
| 239 | SND_JACK_HEADSET | SND_JACK_MECHANICAL | |
| 240 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 241 | SND_JACK_BTN_2 | SND_JACK_BTN_3 | |
| 242 | SND_JACK_BTN_4 | SND_JACK_BTN_5, |
| 243 | &littlemill_headset); |
| 244 | if (ret) |
| 245 | return ret; |
| 246 | |
| 247 | /* This will check device compatibility itself */ |
| 248 | wm8958_mic_detect(codec, &littlemill_headset, NULL, NULL); |
| 249 | |
Mark Brown | 654a28c | 2012-02-03 13:15:18 +0000 | [diff] [blame] | 250 | /* As will this */ |
| 251 | wm8994_mic_detect(codec, &littlemill_headset, 1); |
| 252 | |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static struct snd_soc_card littlemill = { |
| 257 | .name = "Littlemill", |
Axel Lin | 095d79d | 2011-12-22 10:53:15 +0800 | [diff] [blame] | 258 | .owner = THIS_MODULE, |
Mark Brown | 0a590b1 | 2011-11-28 22:05:41 +0000 | [diff] [blame] | 259 | .dai_link = littlemill_dai, |
| 260 | .num_links = ARRAY_SIZE(littlemill_dai), |
| 261 | |
| 262 | .set_bias_level = littlemill_set_bias_level, |
| 263 | .set_bias_level_post = littlemill_set_bias_level_post, |
| 264 | |
| 265 | .dapm_widgets = widgets, |
| 266 | .num_dapm_widgets = ARRAY_SIZE(widgets), |
| 267 | .dapm_routes = audio_paths, |
| 268 | .num_dapm_routes = ARRAY_SIZE(audio_paths), |
| 269 | |
| 270 | .late_probe = littlemill_late_probe, |
| 271 | }; |
| 272 | |
| 273 | static __devinit int littlemill_probe(struct platform_device *pdev) |
| 274 | { |
| 275 | struct snd_soc_card *card = &littlemill; |
| 276 | int ret; |
| 277 | |
| 278 | card->dev = &pdev->dev; |
| 279 | |
| 280 | ret = snd_soc_register_card(card); |
| 281 | if (ret) { |
| 282 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 283 | ret); |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static int __devexit littlemill_remove(struct platform_device *pdev) |
| 291 | { |
| 292 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 293 | |
| 294 | snd_soc_unregister_card(card); |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | static struct platform_driver littlemill_driver = { |
| 300 | .driver = { |
| 301 | .name = "littlemill", |
| 302 | .owner = THIS_MODULE, |
| 303 | .pm = &snd_soc_pm_ops, |
| 304 | }, |
| 305 | .probe = littlemill_probe, |
| 306 | .remove = __devexit_p(littlemill_remove), |
| 307 | }; |
| 308 | |
| 309 | module_platform_driver(littlemill_driver); |
| 310 | |
| 311 | MODULE_DESCRIPTION("Littlemill audio support"); |
| 312 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 313 | MODULE_LICENSE("GPL"); |
| 314 | MODULE_ALIAS("platform:littlemill"); |