ASoC: Fix Zylonite voice interface stereo configurations
[deliverable/linux.git] / sound / soc / pxa / zylonite.c
CommitLineData
2dac9217
MB
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>
2c782f59 17#include <linux/clk.h>
2dac9217
MB
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>
24
25#include "../codecs/wm9713.h"
26#include "pxa2xx-pcm.h"
27#include "pxa2xx-ac97.h"
28#include "pxa-ssp.h"
29
2c782f59
MB
30/*
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.
34 */
35static int clk_pout;
36module_param(clk_pout, int, 0);
37MODULE_PARM_DESC(clk_pout, "Use CLK_POUT as WM9713 MCLK (SW15 on board).");
38
39static struct clk *pout;
40
2dac9217
MB
41static struct snd_soc_card zylonite;
42
43static 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),
49};
50
51/* Currently supported audio map */
52static const struct snd_soc_dapm_route audio_map[] = {
53
54 /* Headphone output connected to HPL/HPR */
55 { "Headphone", NULL, "HPL" },
56 { "Headphone", NULL, "HPR" },
57
58 /* On-board earpiece */
59 { "Headset Earpiece", NULL, "OUT3" },
60
61 /* Headphone mic */
62 { "MIC2A", NULL, "Mic Bias" },
63 { "Mic Bias", NULL, "Headset Microphone" },
64
65 /* On-board mic */
66 { "MIC1", NULL, "Mic Bias" },
67 { "Mic Bias", NULL, "Handset Microphone" },
68
69 /* Multiactor differentially connected over SPKL/SPKR */
70 { "Multiactor", NULL, "SPKL" },
71 { "Multiactor", NULL, "SPKR" },
72};
73
74static int zylonite_wm9713_init(struct snd_soc_codec *codec)
75{
2c782f59
MB
76 if (clk_pout)
77 snd_soc_dai_set_pll(&codec->dai[0], 0, clk_get_rate(pout), 0);
2dac9217
MB
78
79 snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets,
80 ARRAY_SIZE(zylonite_dapm_widgets));
81
82 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
83
84 /* Static setup for now */
85 snd_soc_dapm_enable_pin(codec, "Headphone");
86 snd_soc_dapm_enable_pin(codec, "Headset Earpiece");
87
88 snd_soc_dapm_sync(codec);
89 return 0;
90}
91
92static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
93 struct snd_pcm_hw_params *params)
94{
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;
a435869c 98 unsigned int pll_out = 0;
2dac9217
MB
99 unsigned int acds = 0;
100 unsigned int wm9713_div = 0;
101 int ret = 0;
102
103 switch (params_rate(params)) {
104 case 8000:
105 wm9713_div = 12;
a435869c 106 pll_out = 2048000;
2dac9217
MB
107 break;
108 case 16000:
109 wm9713_div = 6;
a435869c 110 pll_out = 4096000;
2dac9217
MB
111 break;
112 case 48000:
113 default:
114 wm9713_div = 2;
a435869c 115 pll_out = 12288000;
2dac9217
MB
116 acds = 1;
117 break;
118 }
119
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;
124
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;
129
d3b89421
MB
130 /* We're not really in network mode but the emulation wants this. */
131 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 1, 1);
2dac9217
MB
132 if (ret < 0)
133 return ret;
134
a435869c
MB
135 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, pll_out);
136 if (ret < 0)
137 return ret;
138
2dac9217
MB
139 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_AUDIO_DIV_ACDS, acds);
140 if (ret < 0)
141 return ret;
142
143 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1);
144 if (ret < 0)
145 return ret;
146
2c782f59
MB
147 if (clk_pout)
148 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_PLL_DIV,
149 WM9713_PCMDIV(wm9713_div));
150 else
151 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
152 WM9713_PCMDIV(wm9713_div));
2dac9217
MB
153 if (ret < 0)
154 return ret;
155
156 return 0;
157}
158
159static struct snd_soc_ops zylonite_voice_ops = {
160 .hw_params = zylonite_voice_hw_params,
161};
162
163static struct snd_soc_dai_link zylonite_dai[] = {
164{
165 .name = "AC97",
166 .stream_name = "AC97 HiFi",
167 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
168 .codec_dai = &wm9713_dai[WM9713_DAI_AC97_HIFI],
169 .init = zylonite_wm9713_init,
170},
171{
172 .name = "AC97 Aux",
173 .stream_name = "AC97 Aux",
174 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
175 .codec_dai = &wm9713_dai[WM9713_DAI_AC97_AUX],
176},
177{
178 .name = "WM9713 Voice",
179 .stream_name = "WM9713 Voice",
180 .cpu_dai = &pxa_ssp_dai[PXA_DAI_SSP3],
181 .codec_dai = &wm9713_dai[WM9713_DAI_PCM_VOICE],
182 .ops = &zylonite_voice_ops,
183},
184};
185
2c782f59
MB
186static int zylonite_probe(struct platform_device *pdev)
187{
188 int ret;
189
190 if (clk_pout) {
191 pout = clk_get(NULL, "CLK_POUT");
192 if (IS_ERR(pout)) {
193 dev_err(&pdev->dev, "Unable to obtain CLK_POUT: %ld\n",
194 PTR_ERR(pout));
195 return PTR_ERR(pout);
196 }
197
198 ret = clk_enable(pout);
199 if (ret != 0) {
200 dev_err(&pdev->dev, "Unable to enable CLK_POUT: %d\n",
201 ret);
202 clk_put(pout);
203 return ret;
204 }
205
206 dev_dbg(&pdev->dev, "MCLK enabled at %luHz\n",
207 clk_get_rate(pout));
208 }
209
210 return 0;
211}
212
213static int zylonite_remove(struct platform_device *pdev)
214{
215 if (clk_pout) {
216 clk_disable(pout);
217 clk_put(pout);
218 }
219
220 return 0;
221}
222
223static int zylonite_suspend_post(struct platform_device *pdev,
224 pm_message_t state)
225{
226 if (clk_pout)
227 clk_disable(pout);
228
229 return 0;
230}
231
232static int zylonite_resume_pre(struct platform_device *pdev)
233{
234 int ret = 0;
235
236 if (clk_pout) {
237 ret = clk_enable(pout);
238 if (ret != 0)
239 dev_err(&pdev->dev, "Unable to enable CLK_POUT: %d\n",
240 ret);
241 }
242
243 return ret;
244}
245
2dac9217
MB
246static struct snd_soc_card zylonite = {
247 .name = "Zylonite",
2c782f59
MB
248 .probe = &zylonite_probe,
249 .remove = &zylonite_remove,
250 .suspend_post = &zylonite_suspend_post,
251 .resume_pre = &zylonite_resume_pre,
87689d56 252 .platform = &pxa2xx_soc_platform,
2dac9217
MB
253 .dai_link = zylonite_dai,
254 .num_links = ARRAY_SIZE(zylonite_dai),
255};
256
257static struct snd_soc_device zylonite_snd_ac97_devdata = {
258 .card = &zylonite,
2dac9217
MB
259 .codec_dev = &soc_codec_dev_wm9713,
260};
261
262static struct platform_device *zylonite_snd_ac97_device;
263
264static int __init zylonite_init(void)
265{
266 int ret;
267
268 zylonite_snd_ac97_device = platform_device_alloc("soc-audio", -1);
269 if (!zylonite_snd_ac97_device)
270 return -ENOMEM;
271
272 platform_set_drvdata(zylonite_snd_ac97_device,
273 &zylonite_snd_ac97_devdata);
274 zylonite_snd_ac97_devdata.dev = &zylonite_snd_ac97_device->dev;
275
276 ret = platform_device_add(zylonite_snd_ac97_device);
277 if (ret != 0)
278 platform_device_put(zylonite_snd_ac97_device);
279
280 return ret;
281}
282
283static void __exit zylonite_exit(void)
284{
285 platform_device_unregister(zylonite_snd_ac97_device);
286}
287
288module_init(zylonite_init);
289module_exit(zylonite_exit);
290
291MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
292MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite");
293MODULE_LICENSE("GPL");
This page took 0.067281 seconds and 5 git commands to generate.