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> |
| 14 | |
| 15 | #include "../codecs/wm8915.h" |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame^] | 16 | #include "../codecs/wm9081.h" |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 17 | |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 18 | static int speyside_set_bias_level(struct snd_soc_card *card, |
| 19 | enum snd_soc_bias_level level) |
| 20 | { |
| 21 | struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; |
| 22 | int ret; |
| 23 | |
| 24 | switch (level) { |
| 25 | case SND_SOC_BIAS_STANDBY: |
| 26 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1, |
| 27 | 32768, SND_SOC_CLOCK_IN); |
| 28 | if (ret < 0) |
| 29 | return ret; |
| 30 | |
| 31 | ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1, |
| 32 | 0, 0, 0); |
| 33 | if (ret < 0) { |
| 34 | pr_err("Failed to stop FLL\n"); |
| 35 | return ret; |
| 36 | } |
| 37 | |
| 38 | default: |
| 39 | break; |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 45 | static int speyside_hw_params(struct snd_pcm_substream *substream, |
| 46 | struct snd_pcm_hw_params *params) |
| 47 | { |
| 48 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 49 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 50 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 51 | int ret; |
| 52 | |
| 53 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
| 54 | | SND_SOC_DAIFMT_NB_NF |
| 55 | | SND_SOC_DAIFMT_CBM_CFM); |
| 56 | if (ret < 0) |
| 57 | return ret; |
| 58 | |
| 59 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
| 60 | | SND_SOC_DAIFMT_NB_NF |
| 61 | | SND_SOC_DAIFMT_CBM_CFM); |
| 62 | if (ret < 0) |
| 63 | return ret; |
| 64 | |
| 65 | ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK1, |
| 66 | 32768, 256 * 48000); |
| 67 | if (ret < 0) |
| 68 | return ret; |
| 69 | |
| 70 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL, |
| 71 | 256 * 48000, SND_SOC_CLOCK_IN); |
| 72 | if (ret < 0) |
| 73 | return ret; |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static struct snd_soc_ops speyside_ops = { |
| 79 | .hw_params = speyside_hw_params, |
| 80 | }; |
| 81 | |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 82 | static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd) |
| 83 | { |
| 84 | struct snd_soc_dai *dai = rtd->codec_dai; |
| 85 | |
| 86 | return snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0); |
| 87 | } |
| 88 | |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 89 | static struct snd_soc_dai_link speyside_dai[] = { |
| 90 | { |
| 91 | .name = "CPU", |
| 92 | .stream_name = "CPU", |
| 93 | .cpu_dai_name = "samsung-i2s.0", |
| 94 | .codec_dai_name = "wm8915-aif1", |
| 95 | .platform_name = "samsung-audio", |
| 96 | .codec_name = "wm8915.1-001a", |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 97 | .init = speyside_wm8915_init, |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 98 | .ops = &speyside_ops, |
| 99 | }, |
| 100 | }; |
| 101 | |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame^] | 102 | static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm) |
| 103 | { |
| 104 | snd_soc_dapm_nc_pin(dapm, "LINEOUT"); |
| 105 | |
| 106 | /* At any time the WM9081 is active it will have this clock */ |
| 107 | return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, |
| 108 | 48000 * 256, 0); |
| 109 | } |
| 110 | |
| 111 | static struct snd_soc_aux_dev speyside_aux_dev[] = { |
| 112 | { |
| 113 | .name = "wm9081", |
| 114 | .codec_name = "wm9081.1-006c", |
| 115 | .init = speyside_wm9081_init, |
| 116 | }, |
| 117 | }; |
| 118 | |
| 119 | static struct snd_soc_codec_conf speyside_codec_conf[] = { |
| 120 | { |
| 121 | .dev_name = "wm9081.1-006c", |
| 122 | .name_prefix = "Sub", |
| 123 | }, |
| 124 | }; |
| 125 | |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 126 | static struct snd_soc_dapm_widget widgets[] = { |
| 127 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 128 | |
| 129 | SND_SOC_DAPM_SPK("Main Speaker", NULL), |
| 130 | |
| 131 | SND_SOC_DAPM_MIC("Main AMIC", NULL), |
| 132 | SND_SOC_DAPM_MIC("Main DMIC", NULL), |
| 133 | }; |
| 134 | |
| 135 | static struct snd_soc_dapm_route audio_paths[] = { |
| 136 | { "IN1LP", NULL, "MICB2" }, |
| 137 | { "MICB2", NULL, "Main AMIC" }, |
| 138 | |
| 139 | { "DMIC1DAT", NULL, "MICB1" }, |
| 140 | { "DMIC2DAT", NULL, "MICB1" }, |
| 141 | { "MICB1", NULL, "Main DMIC" }, |
| 142 | |
| 143 | { "Headphone", NULL, "HPOUT1L" }, |
| 144 | { "Headphone", NULL, "HPOUT1R" }, |
| 145 | |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame^] | 146 | { "Sub IN1", NULL, "HPOUT2L" }, |
| 147 | { "Sub IN2", NULL, "HPOUT2R" }, |
| 148 | |
| 149 | { "Main Speaker", NULL, "Sub SPKN" }, |
| 150 | { "Main Speaker", NULL, "Sub SPKP" }, |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 151 | { "Main Speaker", NULL, "SPKDAT" }, |
| 152 | }; |
| 153 | |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 154 | static struct snd_soc_card speyside = { |
| 155 | .name = "Speyside", |
| 156 | .dai_link = speyside_dai, |
| 157 | .num_links = ARRAY_SIZE(speyside_dai), |
Mark Brown | ea3e98e | 2011-04-11 23:42:25 -0700 | [diff] [blame^] | 158 | .aux_dev = speyside_aux_dev, |
| 159 | .num_aux_devs = ARRAY_SIZE(speyside_aux_dev), |
| 160 | .codec_conf = speyside_codec_conf, |
| 161 | .num_configs = ARRAY_SIZE(speyside_codec_conf), |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 162 | |
Mark Brown | ea0a591 | 2011-04-11 23:32:03 -0700 | [diff] [blame] | 163 | .set_bias_level = speyside_set_bias_level, |
| 164 | |
Mark Brown | ecfb1ad | 2011-04-11 23:09:15 -0700 | [diff] [blame] | 165 | .dapm_widgets = widgets, |
| 166 | .num_dapm_widgets = ARRAY_SIZE(widgets), |
| 167 | .dapm_routes = audio_paths, |
| 168 | .num_dapm_routes = ARRAY_SIZE(audio_paths), |
Mark Brown | 9b8dc66 | 2011-04-12 17:24:39 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | static __devinit int speyside_probe(struct platform_device *pdev) |
| 172 | { |
| 173 | struct snd_soc_card *card = &speyside; |
| 174 | int ret; |
| 175 | |
| 176 | card->dev = &pdev->dev; |
| 177 | |
| 178 | ret = snd_soc_register_card(card); |
| 179 | if (ret) { |
| 180 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 181 | ret); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | static int __devexit speyside_remove(struct platform_device *pdev) |
| 189 | { |
| 190 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 191 | |
| 192 | snd_soc_unregister_card(card); |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static struct platform_driver speyside_driver = { |
| 198 | .driver = { |
| 199 | .name = "speyside", |
| 200 | .owner = THIS_MODULE, |
| 201 | .pm = &snd_soc_pm_ops, |
| 202 | }, |
| 203 | .probe = speyside_probe, |
| 204 | .remove = __devexit_p(speyside_remove), |
| 205 | }; |
| 206 | |
| 207 | static int __init speyside_audio_init(void) |
| 208 | { |
| 209 | return platform_driver_register(&speyside_driver); |
| 210 | } |
| 211 | module_init(speyside_audio_init); |
| 212 | |
| 213 | static void __exit speyside_audio_exit(void) |
| 214 | { |
| 215 | platform_driver_unregister(&speyside_driver); |
| 216 | } |
| 217 | module_exit(speyside_audio_exit); |
| 218 | |
| 219 | MODULE_DESCRIPTION("Speyside audio support"); |
| 220 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 221 | MODULE_LICENSE("GPL"); |
| 222 | MODULE_ALIAS("platform:speyside"); |