ASoC: Use network mode with 2 slots for 16-bit stereo in pxa-ssp/Zylonite
[linux-2.6/btrfs-unstable.git] / sound / soc / pxa / zylonite.c
blob9f6116edbb84854683695c92adca51fb33067b33
1 /*
2 * zylonite.c -- SoC audio for Zylonite
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/device.h>
17 #include <linux/clk.h>
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>
23 #include <sound/soc-dapm.h>
25 #include "../codecs/wm9713.h"
26 #include "pxa2xx-pcm.h"
27 #include "pxa2xx-ac97.h"
28 #include "pxa-ssp.h"
31 * There is a physical switch SW15 on the board which changes the MCLK
32 * for the WM9713 between the standard AC97 master clock and the
33 * output of the CLK_POUT signal from the PXA.
35 static int clk_pout;
36 module_param(clk_pout, int, 0);
37 MODULE_PARM_DESC(clk_pout, "Use CLK_POUT as WM9713 MCLK (SW15 on board).");
39 static struct clk *pout;
41 static struct snd_soc_card zylonite;
43 static const struct snd_soc_dapm_widget zylonite_dapm_widgets[] = {
44 SND_SOC_DAPM_HP("Headphone", NULL),
45 SND_SOC_DAPM_MIC("Headset Microphone", NULL),
46 SND_SOC_DAPM_MIC("Handset Microphone", NULL),
47 SND_SOC_DAPM_SPK("Multiactor", NULL),
48 SND_SOC_DAPM_SPK("Headset Earpiece", NULL),
51 /* Currently supported audio map */
52 static const struct snd_soc_dapm_route audio_map[] = {
54 /* Headphone output connected to HPL/HPR */
55 { "Headphone", NULL, "HPL" },
56 { "Headphone", NULL, "HPR" },
58 /* On-board earpiece */
59 { "Headset Earpiece", NULL, "OUT3" },
61 /* Headphone mic */
62 { "MIC2A", NULL, "Mic Bias" },
63 { "Mic Bias", NULL, "Headset Microphone" },
65 /* On-board mic */
66 { "MIC1", NULL, "Mic Bias" },
67 { "Mic Bias", NULL, "Handset Microphone" },
69 /* Multiactor differentially connected over SPKL/SPKR */
70 { "Multiactor", NULL, "SPKL" },
71 { "Multiactor", NULL, "SPKR" },
74 static int zylonite_wm9713_init(struct snd_soc_codec *codec)
76 if (clk_pout)
77 snd_soc_dai_set_pll(&codec->dai[0], 0, clk_get_rate(pout), 0);
79 snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets,
80 ARRAY_SIZE(zylonite_dapm_widgets));
82 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
84 /* Static setup for now */
85 snd_soc_dapm_enable_pin(codec, "Headphone");
86 snd_soc_dapm_enable_pin(codec, "Headset Earpiece");
88 snd_soc_dapm_sync(codec);
89 return 0;
92 static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
93 struct snd_pcm_hw_params *params)
95 struct snd_soc_pcm_runtime *rtd = substream->private_data;
96 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
97 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
98 unsigned int pll_out = 0;
99 unsigned int acds = 0;
100 unsigned int wm9713_div = 0;
101 int ret = 0;
103 switch (params_rate(params)) {
104 case 8000:
105 wm9713_div = 12;
106 pll_out = 2048000;
107 break;
108 case 16000:
109 wm9713_div = 6;
110 pll_out = 4096000;
111 break;
112 case 48000:
113 default:
114 wm9713_div = 2;
115 pll_out = 12288000;
116 acds = 1;
117 break;
120 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
121 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
122 if (ret < 0)
123 return ret;
125 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
126 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
127 if (ret < 0)
128 return ret;
130 /* Use network mode for stereo, one slot per channel. */
131 if (params_channels(params) > 1)
132 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 2);
133 else
134 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 1, 1);
135 if (ret < 0)
136 return ret;
138 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, pll_out);
139 if (ret < 0)
140 return ret;
142 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_AUDIO_DIV_ACDS, acds);
143 if (ret < 0)
144 return ret;
146 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1);
147 if (ret < 0)
148 return ret;
150 if (clk_pout)
151 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_PLL_DIV,
152 WM9713_PCMDIV(wm9713_div));
153 else
154 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
155 WM9713_PCMDIV(wm9713_div));
156 if (ret < 0)
157 return ret;
159 return 0;
162 static struct snd_soc_ops zylonite_voice_ops = {
163 .hw_params = zylonite_voice_hw_params,
166 static struct snd_soc_dai_link zylonite_dai[] = {
168 .name = "AC97",
169 .stream_name = "AC97 HiFi",
170 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
171 .codec_dai = &wm9713_dai[WM9713_DAI_AC97_HIFI],
172 .init = zylonite_wm9713_init,
175 .name = "AC97 Aux",
176 .stream_name = "AC97 Aux",
177 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
178 .codec_dai = &wm9713_dai[WM9713_DAI_AC97_AUX],
181 .name = "WM9713 Voice",
182 .stream_name = "WM9713 Voice",
183 .cpu_dai = &pxa_ssp_dai[PXA_DAI_SSP3],
184 .codec_dai = &wm9713_dai[WM9713_DAI_PCM_VOICE],
185 .ops = &zylonite_voice_ops,
189 static int zylonite_probe(struct platform_device *pdev)
191 int ret;
193 if (clk_pout) {
194 pout = clk_get(NULL, "CLK_POUT");
195 if (IS_ERR(pout)) {
196 dev_err(&pdev->dev, "Unable to obtain CLK_POUT: %ld\n",
197 PTR_ERR(pout));
198 return PTR_ERR(pout);
201 ret = clk_enable(pout);
202 if (ret != 0) {
203 dev_err(&pdev->dev, "Unable to enable CLK_POUT: %d\n",
204 ret);
205 clk_put(pout);
206 return ret;
209 dev_dbg(&pdev->dev, "MCLK enabled at %luHz\n",
210 clk_get_rate(pout));
213 return 0;
216 static int zylonite_remove(struct platform_device *pdev)
218 if (clk_pout) {
219 clk_disable(pout);
220 clk_put(pout);
223 return 0;
226 static int zylonite_suspend_post(struct platform_device *pdev,
227 pm_message_t state)
229 if (clk_pout)
230 clk_disable(pout);
232 return 0;
235 static int zylonite_resume_pre(struct platform_device *pdev)
237 int ret = 0;
239 if (clk_pout) {
240 ret = clk_enable(pout);
241 if (ret != 0)
242 dev_err(&pdev->dev, "Unable to enable CLK_POUT: %d\n",
243 ret);
246 return ret;
249 static struct snd_soc_card zylonite = {
250 .name = "Zylonite",
251 .probe = &zylonite_probe,
252 .remove = &zylonite_remove,
253 .suspend_post = &zylonite_suspend_post,
254 .resume_pre = &zylonite_resume_pre,
255 .platform = &pxa2xx_soc_platform,
256 .dai_link = zylonite_dai,
257 .num_links = ARRAY_SIZE(zylonite_dai),
260 static struct snd_soc_device zylonite_snd_ac97_devdata = {
261 .card = &zylonite,
262 .codec_dev = &soc_codec_dev_wm9713,
265 static struct platform_device *zylonite_snd_ac97_device;
267 static int __init zylonite_init(void)
269 int ret;
271 zylonite_snd_ac97_device = platform_device_alloc("soc-audio", -1);
272 if (!zylonite_snd_ac97_device)
273 return -ENOMEM;
275 platform_set_drvdata(zylonite_snd_ac97_device,
276 &zylonite_snd_ac97_devdata);
277 zylonite_snd_ac97_devdata.dev = &zylonite_snd_ac97_device->dev;
279 ret = platform_device_add(zylonite_snd_ac97_device);
280 if (ret != 0)
281 platform_device_put(zylonite_snd_ac97_device);
283 return ret;
286 static void __exit zylonite_exit(void)
288 platform_device_unregister(zylonite_snd_ac97_device);
291 module_init(zylonite_init);
292 module_exit(zylonite_exit);
294 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
295 MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite");
296 MODULE_LICENSE("GPL");