Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * zylonite.c -- SoC audio for Zylonite |
| 3 | * |
| 4 | * Copyright 2008 Wolfson Microelectronics PLC. |
| 5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of the |
| 10 | * License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/device.h> |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 17 | #include <linux/clk.h> |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 18 | #include <linux/i2c.h> |
| 19 | #include <sound/core.h> |
| 20 | #include <sound/pcm.h> |
| 21 | #include <sound/pcm_params.h> |
| 22 | #include <sound/soc.h> |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 23 | |
| 24 | #include "../codecs/wm9713.h" |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 25 | #include "pxa2xx-ac97.h" |
| 26 | #include "pxa-ssp.h" |
| 27 | |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 28 | /* |
| 29 | * There is a physical switch SW15 on the board which changes the MCLK |
| 30 | * for the WM9713 between the standard AC97 master clock and the |
| 31 | * output of the CLK_POUT signal from the PXA. |
| 32 | */ |
| 33 | static int clk_pout; |
| 34 | module_param(clk_pout, int, 0); |
| 35 | MODULE_PARM_DESC(clk_pout, "Use CLK_POUT as WM9713 MCLK (SW15 on board)."); |
| 36 | |
| 37 | static struct clk *pout; |
| 38 | |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 39 | static struct snd_soc_card zylonite; |
| 40 | |
| 41 | static const struct snd_soc_dapm_widget zylonite_dapm_widgets[] = { |
| 42 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 43 | SND_SOC_DAPM_MIC("Headset Microphone", NULL), |
| 44 | SND_SOC_DAPM_MIC("Handset Microphone", NULL), |
| 45 | SND_SOC_DAPM_SPK("Multiactor", NULL), |
| 46 | SND_SOC_DAPM_SPK("Headset Earpiece", NULL), |
| 47 | }; |
| 48 | |
| 49 | /* Currently supported audio map */ |
| 50 | static const struct snd_soc_dapm_route audio_map[] = { |
| 51 | |
| 52 | /* Headphone output connected to HPL/HPR */ |
| 53 | { "Headphone", NULL, "HPL" }, |
| 54 | { "Headphone", NULL, "HPR" }, |
| 55 | |
| 56 | /* On-board earpiece */ |
| 57 | { "Headset Earpiece", NULL, "OUT3" }, |
| 58 | |
| 59 | /* Headphone mic */ |
| 60 | { "MIC2A", NULL, "Mic Bias" }, |
| 61 | { "Mic Bias", NULL, "Headset Microphone" }, |
| 62 | |
| 63 | /* On-board mic */ |
| 64 | { "MIC1", NULL, "Mic Bias" }, |
| 65 | { "Mic Bias", NULL, "Handset Microphone" }, |
| 66 | |
| 67 | /* Multiactor differentially connected over SPKL/SPKR */ |
| 68 | { "Multiactor", NULL, "SPKL" }, |
| 69 | { "Multiactor", NULL, "SPKR" }, |
| 70 | }; |
| 71 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 72 | static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd) |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 73 | { |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 74 | if (clk_pout) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 75 | snd_soc_dai_set_pll(rtd->codec_dai, 0, 0, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 76 | clk_get_rate(pout), 0); |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 77 | |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int zylonite_voice_hw_params(struct snd_pcm_substream *substream, |
| 82 | struct snd_pcm_hw_params *params) |
| 83 | { |
| 84 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 85 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 86 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Mark Brown | a435869 | 2009-01-23 11:49:45 +0000 | [diff] [blame] | 87 | unsigned int pll_out = 0; |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 88 | unsigned int wm9713_div = 0; |
| 89 | int ret = 0; |
Mark Brown | 85fab78 | 2009-03-13 14:27:08 +0000 | [diff] [blame] | 90 | int rate = params_rate(params); |
| 91 | int width = snd_pcm_format_physical_width(params_format(params)); |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 92 | |
Mark Brown | 85fab78 | 2009-03-13 14:27:08 +0000 | [diff] [blame] | 93 | /* Only support ratios that we can generate neatly from the AC97 |
| 94 | * based master clock - in particular, this excludes 44.1kHz. |
| 95 | * In most applications the voice DAC will be used for telephony |
| 96 | * data so multiples of 8kHz will be the common case. |
| 97 | */ |
| 98 | switch (rate) { |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 99 | case 8000: |
| 100 | wm9713_div = 12; |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 101 | break; |
| 102 | case 16000: |
| 103 | wm9713_div = 6; |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 104 | break; |
| 105 | case 48000: |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 106 | wm9713_div = 2; |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 107 | break; |
Mark Brown | 85fab78 | 2009-03-13 14:27:08 +0000 | [diff] [blame] | 108 | default: |
| 109 | /* Don't support OSS emulation */ |
| 110 | return -EINVAL; |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Mark Brown | 85fab78 | 2009-03-13 14:27:08 +0000 | [diff] [blame] | 113 | /* Add 1 to the width for the leading clock cycle */ |
| 114 | pll_out = rate * (width + 1) * 8; |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 115 | |
Mark Brown | 85fab78 | 2009-03-13 14:27:08 +0000 | [diff] [blame] | 116 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1); |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 117 | if (ret < 0) |
| 118 | return ret; |
| 119 | |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 120 | ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, pll_out); |
Mark Brown | a435869 | 2009-01-23 11:49:45 +0000 | [diff] [blame] | 121 | if (ret < 0) |
| 122 | return ret; |
| 123 | |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 124 | if (clk_pout) |
| 125 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_PLL_DIV, |
| 126 | WM9713_PCMDIV(wm9713_div)); |
| 127 | else |
| 128 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV, |
| 129 | WM9713_PCMDIV(wm9713_div)); |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 130 | if (ret < 0) |
| 131 | return ret; |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static struct snd_soc_ops zylonite_voice_ops = { |
| 137 | .hw_params = zylonite_voice_hw_params, |
| 138 | }; |
| 139 | |
| 140 | static struct snd_soc_dai_link zylonite_dai[] = { |
| 141 | { |
| 142 | .name = "AC97", |
| 143 | .stream_name = "AC97 HiFi", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 144 | .codec_name = "wm9713-codec", |
| 145 | .platform_name = "pxa-pcm-audio", |
Dmitry Eremin-Solenikov | 4bfc4e2 | 2011-02-23 02:29:11 +0300 | [diff] [blame] | 146 | .cpu_dai_name = "pxa2xx-ac97", |
Antonio Ospite | efd6947 | 2011-03-18 12:47:33 +0100 | [diff] [blame] | 147 | .codec_dai_name = "wm9713-hifi", |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 148 | .init = zylonite_wm9713_init, |
| 149 | }, |
| 150 | { |
| 151 | .name = "AC97 Aux", |
| 152 | .stream_name = "AC97 Aux", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 153 | .codec_name = "wm9713-codec", |
| 154 | .platform_name = "pxa-pcm-audio", |
Dmitry Eremin-Solenikov | 4bfc4e2 | 2011-02-23 02:29:11 +0300 | [diff] [blame] | 155 | .cpu_dai_name = "pxa2xx-ac97-aux", |
Antonio Ospite | efd6947 | 2011-03-18 12:47:33 +0100 | [diff] [blame] | 156 | .codec_dai_name = "wm9713-aux", |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 157 | }, |
| 158 | { |
| 159 | .name = "WM9713 Voice", |
| 160 | .stream_name = "WM9713 Voice", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 161 | .codec_name = "wm9713-codec", |
| 162 | .platform_name = "pxa-pcm-audio", |
| 163 | .cpu_dai_name = "pxa-ssp-dai.2", |
Antonio Ospite | efd6947 | 2011-03-18 12:47:33 +0100 | [diff] [blame] | 164 | .codec_dai_name = "wm9713-voice", |
Lars-Peter Clausen | 132c309 | 2015-01-01 17:16:18 +0100 | [diff] [blame^] | 165 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 166 | SND_SOC_DAIFMT_CBS_CFS, |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 167 | .ops = &zylonite_voice_ops, |
| 168 | }, |
| 169 | }; |
| 170 | |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 171 | static int zylonite_probe(struct snd_soc_card *card) |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 172 | { |
| 173 | int ret; |
| 174 | |
| 175 | if (clk_pout) { |
| 176 | pout = clk_get(NULL, "CLK_POUT"); |
| 177 | if (IS_ERR(pout)) { |
Arnd Bergmann | eff919a | 2011-10-01 22:03:34 +0200 | [diff] [blame] | 178 | dev_err(card->dev, "Unable to obtain CLK_POUT: %ld\n", |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 179 | PTR_ERR(pout)); |
| 180 | return PTR_ERR(pout); |
| 181 | } |
| 182 | |
| 183 | ret = clk_enable(pout); |
| 184 | if (ret != 0) { |
Arnd Bergmann | eff919a | 2011-10-01 22:03:34 +0200 | [diff] [blame] | 185 | dev_err(card->dev, "Unable to enable CLK_POUT: %d\n", |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 186 | ret); |
| 187 | clk_put(pout); |
| 188 | return ret; |
| 189 | } |
| 190 | |
Arnd Bergmann | eff919a | 2011-10-01 22:03:34 +0200 | [diff] [blame] | 191 | dev_dbg(card->dev, "MCLK enabled at %luHz\n", |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 192 | clk_get_rate(pout)); |
| 193 | } |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 198 | static int zylonite_remove(struct snd_soc_card *card) |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 199 | { |
| 200 | if (clk_pout) { |
| 201 | clk_disable(pout); |
| 202 | clk_put(pout); |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 208 | static int zylonite_suspend_post(struct snd_soc_card *card) |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 209 | { |
| 210 | if (clk_pout) |
| 211 | clk_disable(pout); |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 216 | static int zylonite_resume_pre(struct snd_soc_card *card) |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 217 | { |
| 218 | int ret = 0; |
| 219 | |
| 220 | if (clk_pout) { |
| 221 | ret = clk_enable(pout); |
| 222 | if (ret != 0) |
Arnd Bergmann | eff919a | 2011-10-01 22:03:34 +0200 | [diff] [blame] | 223 | dev_err(card->dev, "Unable to enable CLK_POUT: %d\n", |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 224 | ret); |
| 225 | } |
| 226 | |
| 227 | return ret; |
| 228 | } |
| 229 | |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 230 | static struct snd_soc_card zylonite = { |
| 231 | .name = "Zylonite", |
Axel Lin | 561c6a1 | 2011-12-22 09:44:43 +0800 | [diff] [blame] | 232 | .owner = THIS_MODULE, |
Mark Brown | 2c782f5 | 2009-01-16 16:35:52 +0000 | [diff] [blame] | 233 | .probe = &zylonite_probe, |
| 234 | .remove = &zylonite_remove, |
| 235 | .suspend_post = &zylonite_suspend_post, |
| 236 | .resume_pre = &zylonite_resume_pre, |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 237 | .dai_link = zylonite_dai, |
| 238 | .num_links = ARRAY_SIZE(zylonite_dai), |
Lars-Peter Clausen | a9576cb | 2014-03-01 15:48:20 +0100 | [diff] [blame] | 239 | |
| 240 | .dapm_widgets = zylonite_dapm_widgets, |
| 241 | .num_dapm_widgets = ARRAY_SIZE(zylonite_dapm_widgets), |
| 242 | .dapm_routes = audio_map, |
| 243 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | static struct platform_device *zylonite_snd_ac97_device; |
| 247 | |
| 248 | static int __init zylonite_init(void) |
| 249 | { |
| 250 | int ret; |
| 251 | |
| 252 | zylonite_snd_ac97_device = platform_device_alloc("soc-audio", -1); |
| 253 | if (!zylonite_snd_ac97_device) |
| 254 | return -ENOMEM; |
| 255 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 256 | platform_set_drvdata(zylonite_snd_ac97_device, &zylonite); |
Mark Brown | 2dac921 | 2008-11-21 14:01:41 +0000 | [diff] [blame] | 257 | |
| 258 | ret = platform_device_add(zylonite_snd_ac97_device); |
| 259 | if (ret != 0) |
| 260 | platform_device_put(zylonite_snd_ac97_device); |
| 261 | |
| 262 | return ret; |
| 263 | } |
| 264 | |
| 265 | static void __exit zylonite_exit(void) |
| 266 | { |
| 267 | platform_device_unregister(zylonite_snd_ac97_device); |
| 268 | } |
| 269 | |
| 270 | module_init(zylonite_init); |
| 271 | module_exit(zylonite_exit); |
| 272 | |
| 273 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 274 | MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite"); |
| 275 | MODULE_LICENSE("GPL"); |