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