Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Speyside 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> |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 14 | #include <sound/jack.h> |
| 15 | #include <linux/gpio.h> |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 16 | |
| 17 | #include "../codecs/wm8915.h" |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame] | 18 | #include "../codecs/wm9081.h" |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 19 | |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 20 | #define WM8915_HPSEL_GPIO 214 |
| 21 | |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 22 | static int speyside_set_bias_level(struct snd_soc_card *card, |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame^] | 23 | struct snd_soc_dapm_context *dapm, |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 24 | enum snd_soc_bias_level level) |
| 25 | { |
| 26 | struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; |
| 27 | int ret; |
| 28 | |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame^] | 29 | if (dapm->dev != codec_dai->dev) |
| 30 | return 0; |
| 31 | |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 32 | switch (level) { |
| 33 | case SND_SOC_BIAS_STANDBY: |
Mark Brown | 1e025a3 | 2011-06-01 19:32:22 +0100 | [diff] [blame] | 34 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK2, |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 35 | 32768, SND_SOC_CLOCK_IN); |
| 36 | if (ret < 0) |
| 37 | return ret; |
| 38 | |
Mark Brown | 1e025a3 | 2011-06-01 19:32:22 +0100 | [diff] [blame] | 39 | ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK2, |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 40 | 0, 0, 0); |
| 41 | if (ret < 0) { |
| 42 | pr_err("Failed to stop FLL\n"); |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | default: |
| 47 | break; |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 53 | static int speyside_hw_params(struct snd_pcm_substream *substream, |
| 54 | struct snd_pcm_hw_params *params) |
| 55 | { |
| 56 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 57 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 58 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 59 | int ret; |
| 60 | |
| 61 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
| 62 | | SND_SOC_DAIFMT_NB_NF |
| 63 | | SND_SOC_DAIFMT_CBM_CFM); |
| 64 | if (ret < 0) |
| 65 | return ret; |
| 66 | |
| 67 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
| 68 | | SND_SOC_DAIFMT_NB_NF |
| 69 | | SND_SOC_DAIFMT_CBM_CFM); |
| 70 | if (ret < 0) |
| 71 | return ret; |
| 72 | |
Mark Brown | 1e025a3 | 2011-06-01 19:32:22 +0100 | [diff] [blame] | 73 | ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK2, |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 74 | 32768, 256 * 48000); |
| 75 | if (ret < 0) |
| 76 | return ret; |
| 77 | |
| 78 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL, |
| 79 | 256 * 48000, SND_SOC_CLOCK_IN); |
| 80 | if (ret < 0) |
| 81 | return ret; |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static struct snd_soc_ops speyside_ops = { |
| 87 | .hw_params = speyside_hw_params, |
| 88 | }; |
| 89 | |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 90 | static struct snd_soc_jack speyside_headset; |
| 91 | |
| 92 | /* Headset jack detection DAPM pins */ |
| 93 | static struct snd_soc_jack_pin speyside_headset_pins[] = { |
| 94 | { |
| 95 | .pin = "Headset Mic", |
| 96 | .mask = SND_JACK_MICROPHONE, |
| 97 | }, |
| 98 | { |
| 99 | .pin = "Headphone", |
| 100 | .mask = SND_JACK_HEADPHONE, |
| 101 | }, |
| 102 | }; |
| 103 | |
| 104 | /* Default the headphone selection to active high */ |
| 105 | static int speyside_jack_polarity; |
| 106 | |
| 107 | static int speyside_get_micbias(struct snd_soc_dapm_widget *source, |
| 108 | struct snd_soc_dapm_widget *sink) |
| 109 | { |
| 110 | if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0)) |
| 111 | return 1; |
| 112 | if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0)) |
| 113 | return 1; |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static void speyside_set_polarity(struct snd_soc_codec *codec, |
| 119 | int polarity) |
| 120 | { |
| 121 | speyside_jack_polarity = !polarity; |
| 122 | gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity); |
| 123 | |
| 124 | /* Re-run DAPM to make sure we're using the correct mic bias */ |
| 125 | snd_soc_dapm_sync(&codec->dapm); |
| 126 | } |
| 127 | |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 128 | static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd) |
| 129 | { |
| 130 | struct snd_soc_dai *dai = rtd->codec_dai; |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 131 | struct snd_soc_codec *codec = rtd->codec; |
| 132 | int ret; |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 133 | |
Mark Brown | 1e025a3 | 2011-06-01 19:32:22 +0100 | [diff] [blame] | 134 | ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK2, 32768, 0); |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 135 | if (ret < 0) |
| 136 | return ret; |
| 137 | |
| 138 | ret = gpio_request(WM8915_HPSEL_GPIO, "HP_SEL"); |
| 139 | if (ret != 0) |
| 140 | pr_err("Failed to request HP_SEL GPIO: %d\n", ret); |
| 141 | gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity); |
| 142 | |
| 143 | ret = snd_soc_jack_new(codec, "Headset", |
| 144 | SND_JACK_HEADSET | SND_JACK_BTN_0, |
| 145 | &speyside_headset); |
| 146 | if (ret) |
| 147 | return ret; |
| 148 | |
| 149 | ret = snd_soc_jack_add_pins(&speyside_headset, |
| 150 | ARRAY_SIZE(speyside_headset_pins), |
| 151 | speyside_headset_pins); |
| 152 | if (ret) |
| 153 | return ret; |
| 154 | |
| 155 | wm8915_detect(codec, &speyside_headset, speyside_set_polarity); |
| 156 | |
| 157 | return 0; |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Mark Brown | b7a5d14 | 2011-04-12 17:37:52 -0700 | [diff] [blame] | 160 | static int speyside_late_probe(struct snd_soc_card *card) |
| 161 | { |
| 162 | snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone"); |
| 163 | snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic"); |
| 164 | snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC"); |
| 165 | snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC"); |
| 166 | snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker"); |
| 167 | snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output"); |
| 168 | snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input"); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 173 | static struct snd_soc_dai_link speyside_dai[] = { |
| 174 | { |
| 175 | .name = "CPU", |
| 176 | .stream_name = "CPU", |
| 177 | .cpu_dai_name = "samsung-i2s.0", |
| 178 | .codec_dai_name = "wm8915-aif1", |
| 179 | .platform_name = "samsung-audio", |
| 180 | .codec_name = "wm8915.1-001a", |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 181 | .init = speyside_wm8915_init, |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 182 | .ops = &speyside_ops, |
| 183 | }, |
Mark Brown | 556e4fb | 2011-04-12 14:15:10 -0700 | [diff] [blame] | 184 | { |
| 185 | .name = "Baseband", |
| 186 | .stream_name = "Baseband", |
| 187 | .cpu_dai_name = "wm8915-aif2", |
| 188 | .codec_dai_name = "wm1250-ev1", |
| 189 | .codec_name = "wm1250-ev1.1-0027", |
Mark Brown | 556e4fb | 2011-04-12 14:15:10 -0700 | [diff] [blame] | 190 | .ops = &speyside_ops, |
Mark Brown | b7a5d14 | 2011-04-12 17:37:52 -0700 | [diff] [blame] | 191 | .ignore_suspend = 1, |
Mark Brown | 556e4fb | 2011-04-12 14:15:10 -0700 | [diff] [blame] | 192 | }, |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame] | 195 | static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm) |
| 196 | { |
| 197 | snd_soc_dapm_nc_pin(dapm, "LINEOUT"); |
| 198 | |
| 199 | /* At any time the WM9081 is active it will have this clock */ |
| 200 | return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, |
| 201 | 48000 * 256, 0); |
| 202 | } |
| 203 | |
| 204 | static struct snd_soc_aux_dev speyside_aux_dev[] = { |
| 205 | { |
| 206 | .name = "wm9081", |
| 207 | .codec_name = "wm9081.1-006c", |
| 208 | .init = speyside_wm9081_init, |
| 209 | }, |
| 210 | }; |
| 211 | |
| 212 | static struct snd_soc_codec_conf speyside_codec_conf[] = { |
| 213 | { |
| 214 | .dev_name = "wm9081.1-006c", |
| 215 | .name_prefix = "Sub", |
| 216 | }, |
| 217 | }; |
| 218 | |
Mark Brown | ea0e60d | 2011-04-12 00:09:53 -0700 | [diff] [blame] | 219 | static const struct snd_kcontrol_new controls[] = { |
| 220 | SOC_DAPM_PIN_SWITCH("Main Speaker"), |
| 221 | SOC_DAPM_PIN_SWITCH("Main DMIC"), |
| 222 | SOC_DAPM_PIN_SWITCH("Main AMIC"), |
Mark Brown | 556e4fb | 2011-04-12 14:15:10 -0700 | [diff] [blame] | 223 | SOC_DAPM_PIN_SWITCH("WM1250 Input"), |
| 224 | SOC_DAPM_PIN_SWITCH("WM1250 Output"), |
Mark Brown | ea0e60d | 2011-04-12 00:09:53 -0700 | [diff] [blame] | 225 | }; |
| 226 | |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 227 | static struct snd_soc_dapm_widget widgets[] = { |
| 228 | SND_SOC_DAPM_HP("Headphone", NULL), |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 229 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 230 | |
| 231 | SND_SOC_DAPM_SPK("Main Speaker", NULL), |
| 232 | |
| 233 | SND_SOC_DAPM_MIC("Main AMIC", NULL), |
| 234 | SND_SOC_DAPM_MIC("Main DMIC", NULL), |
| 235 | }; |
| 236 | |
| 237 | static struct snd_soc_dapm_route audio_paths[] = { |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 238 | { "IN1RN", NULL, "MICB1" }, |
| 239 | { "IN1RP", NULL, "MICB1" }, |
| 240 | { "IN1RN", NULL, "MICB2" }, |
| 241 | { "IN1RP", NULL, "MICB2" }, |
| 242 | { "MICB1", NULL, "Headset Mic", speyside_get_micbias }, |
| 243 | { "MICB2", NULL, "Headset Mic", speyside_get_micbias }, |
| 244 | |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 245 | { "IN1LP", NULL, "MICB2" }, |
Mark Brown | 68688e7 | 2011-04-12 00:00:36 -0700 | [diff] [blame] | 246 | { "IN1RN", NULL, "MICB1" }, |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 247 | { "MICB2", NULL, "Main AMIC" }, |
| 248 | |
| 249 | { "DMIC1DAT", NULL, "MICB1" }, |
| 250 | { "DMIC2DAT", NULL, "MICB1" }, |
| 251 | { "MICB1", NULL, "Main DMIC" }, |
| 252 | |
| 253 | { "Headphone", NULL, "HPOUT1L" }, |
| 254 | { "Headphone", NULL, "HPOUT1R" }, |
| 255 | |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame] | 256 | { "Sub IN1", NULL, "HPOUT2L" }, |
| 257 | { "Sub IN2", NULL, "HPOUT2R" }, |
| 258 | |
| 259 | { "Main Speaker", NULL, "Sub SPKN" }, |
| 260 | { "Main Speaker", NULL, "Sub SPKP" }, |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 261 | { "Main Speaker", NULL, "SPKDAT" }, |
| 262 | }; |
| 263 | |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 264 | static struct snd_soc_card speyside = { |
| 265 | .name = "Speyside", |
| 266 | .dai_link = speyside_dai, |
| 267 | .num_links = ARRAY_SIZE(speyside_dai), |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame] | 268 | .aux_dev = speyside_aux_dev, |
| 269 | .num_aux_devs = ARRAY_SIZE(speyside_aux_dev), |
| 270 | .codec_conf = speyside_codec_conf, |
| 271 | .num_configs = ARRAY_SIZE(speyside_codec_conf), |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 272 | |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 273 | .set_bias_level = speyside_set_bias_level, |
| 274 | |
Mark Brown | ea0e60d | 2011-04-12 00:09:53 -0700 | [diff] [blame] | 275 | .controls = controls, |
| 276 | .num_controls = ARRAY_SIZE(controls), |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 277 | .dapm_widgets = widgets, |
| 278 | .num_dapm_widgets = ARRAY_SIZE(widgets), |
| 279 | .dapm_routes = audio_paths, |
| 280 | .num_dapm_routes = ARRAY_SIZE(audio_paths), |
Mark Brown | b7a5d14 | 2011-04-12 17:37:52 -0700 | [diff] [blame] | 281 | |
| 282 | .late_probe = speyside_late_probe, |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | static __devinit int speyside_probe(struct platform_device *pdev) |
| 286 | { |
| 287 | struct snd_soc_card *card = &speyside; |
| 288 | int ret; |
| 289 | |
| 290 | card->dev = &pdev->dev; |
| 291 | |
| 292 | ret = snd_soc_register_card(card); |
| 293 | if (ret) { |
| 294 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 295 | ret); |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int __devexit speyside_remove(struct platform_device *pdev) |
| 303 | { |
| 304 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 305 | |
| 306 | snd_soc_unregister_card(card); |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static struct platform_driver speyside_driver = { |
| 312 | .driver = { |
| 313 | .name = "speyside", |
| 314 | .owner = THIS_MODULE, |
| 315 | .pm = &snd_soc_pm_ops, |
| 316 | }, |
| 317 | .probe = speyside_probe, |
| 318 | .remove = __devexit_p(speyside_remove), |
| 319 | }; |
| 320 | |
| 321 | static int __init speyside_audio_init(void) |
| 322 | { |
| 323 | return platform_driver_register(&speyside_driver); |
| 324 | } |
| 325 | module_init(speyside_audio_init); |
| 326 | |
| 327 | static void __exit speyside_audio_exit(void) |
| 328 | { |
| 329 | platform_driver_unregister(&speyside_driver); |
| 330 | } |
| 331 | module_exit(speyside_audio_exit); |
| 332 | |
| 333 | MODULE_DESCRIPTION("Speyside audio support"); |
| 334 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 335 | MODULE_LICENSE("GPL"); |
| 336 | MODULE_ALIAS("platform:speyside"); |