Merge branch 'userns-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm...
[linux-2.6-block.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>
2dac9217
MB
23
24#include "../codecs/wm9713.h"
2dac9217
MB
25#include "pxa-ssp.h"
26
2c782f59
MB
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 */
32static int clk_pout;
33module_param(clk_pout, int, 0);
34MODULE_PARM_DESC(clk_pout, "Use CLK_POUT as WM9713 MCLK (SW15 on board).");
35
36static struct clk *pout;
37
2dac9217
MB
38static struct snd_soc_card zylonite;
39
40static 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 */
49static 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
f0fba2ad 71static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd)
2dac9217 72{
2c782f59 73 if (clk_pout)
f0fba2ad 74 snd_soc_dai_set_pll(rtd->codec_dai, 0, 0,
85488037 75 clk_get_rate(pout), 0);
2dac9217 76
2dac9217
MB
77 return 0;
78}
79
80static 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;
f0fba2ad
LG
84 struct snd_soc_dai *codec_dai = rtd->codec_dai;
85 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2dac9217
MB
86 unsigned int wm9713_div = 0;
87 int ret = 0;
85fab780 88 int rate = params_rate(params);
85fab780
MB
89
90 /* Only support ratios that we can generate neatly from the AC97
91 * based master clock - in particular, this excludes 44.1kHz.
92 * In most applications the voice DAC will be used for telephony
93 * data so multiples of 8kHz will be the common case.
94 */
95 switch (rate) {
2dac9217
MB
96 case 8000:
97 wm9713_div = 12;
2dac9217
MB
98 break;
99 case 16000:
100 wm9713_div = 6;
2dac9217
MB
101 break;
102 case 48000:
2dac9217 103 wm9713_div = 2;
2dac9217 104 break;
85fab780
MB
105 default:
106 /* Don't support OSS emulation */
107 return -EINVAL;
2dac9217
MB
108 }
109
85fab780 110 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1);
2dac9217
MB
111 if (ret < 0)
112 return ret;
113
2c782f59
MB
114 if (clk_pout)
115 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_PLL_DIV,
116 WM9713_PCMDIV(wm9713_div));
117 else
118 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
119 WM9713_PCMDIV(wm9713_div));
2dac9217
MB
120 if (ret < 0)
121 return ret;
122
123 return 0;
124}
125
943b7311 126static const struct snd_soc_ops zylonite_voice_ops = {
2dac9217
MB
127 .hw_params = zylonite_voice_hw_params,
128};
129
130static struct snd_soc_dai_link zylonite_dai[] = {
131{
132 .name = "AC97",
133 .stream_name = "AC97 HiFi",
f0fba2ad
LG
134 .codec_name = "wm9713-codec",
135 .platform_name = "pxa-pcm-audio",
4bfc4e25 136 .cpu_dai_name = "pxa2xx-ac97",
efd69479 137 .codec_dai_name = "wm9713-hifi",
2dac9217
MB
138 .init = zylonite_wm9713_init,
139},
140{
141 .name = "AC97 Aux",
142 .stream_name = "AC97 Aux",
f0fba2ad
LG
143 .codec_name = "wm9713-codec",
144 .platform_name = "pxa-pcm-audio",
4bfc4e25 145 .cpu_dai_name = "pxa2xx-ac97-aux",
efd69479 146 .codec_dai_name = "wm9713-aux",
2dac9217
MB
147},
148{
149 .name = "WM9713 Voice",
150 .stream_name = "WM9713 Voice",
f0fba2ad
LG
151 .codec_name = "wm9713-codec",
152 .platform_name = "pxa-pcm-audio",
153 .cpu_dai_name = "pxa-ssp-dai.2",
efd69479 154 .codec_dai_name = "wm9713-voice",
132c3096
LPC
155 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
156 SND_SOC_DAIFMT_CBS_CFS,
2dac9217
MB
157 .ops = &zylonite_voice_ops,
158},
159};
160
e7361ec4 161static int zylonite_probe(struct snd_soc_card *card)
2c782f59
MB
162{
163 int ret;
164
165 if (clk_pout) {
166 pout = clk_get(NULL, "CLK_POUT");
167 if (IS_ERR(pout)) {
eff919ac 168 dev_err(card->dev, "Unable to obtain CLK_POUT: %ld\n",
2c782f59
MB
169 PTR_ERR(pout));
170 return PTR_ERR(pout);
171 }
172
173 ret = clk_enable(pout);
174 if (ret != 0) {
eff919ac 175 dev_err(card->dev, "Unable to enable CLK_POUT: %d\n",
2c782f59
MB
176 ret);
177 clk_put(pout);
178 return ret;
179 }
180
eff919ac 181 dev_dbg(card->dev, "MCLK enabled at %luHz\n",
2c782f59
MB
182 clk_get_rate(pout));
183 }
184
185 return 0;
186}
187
e7361ec4 188static int zylonite_remove(struct snd_soc_card *card)
2c782f59
MB
189{
190 if (clk_pout) {
191 clk_disable(pout);
192 clk_put(pout);
193 }
194
195 return 0;
196}
197
70b2ac12 198static int zylonite_suspend_post(struct snd_soc_card *card)
2c782f59
MB
199{
200 if (clk_pout)
201 clk_disable(pout);
202
203 return 0;
204}
205
70b2ac12 206static int zylonite_resume_pre(struct snd_soc_card *card)
2c782f59
MB
207{
208 int ret = 0;
209
210 if (clk_pout) {
211 ret = clk_enable(pout);
212 if (ret != 0)
eff919ac 213 dev_err(card->dev, "Unable to enable CLK_POUT: %d\n",
2c782f59
MB
214 ret);
215 }
216
217 return ret;
218}
219
2dac9217
MB
220static struct snd_soc_card zylonite = {
221 .name = "Zylonite",
561c6a17 222 .owner = THIS_MODULE,
2c782f59
MB
223 .probe = &zylonite_probe,
224 .remove = &zylonite_remove,
225 .suspend_post = &zylonite_suspend_post,
226 .resume_pre = &zylonite_resume_pre,
2dac9217
MB
227 .dai_link = zylonite_dai,
228 .num_links = ARRAY_SIZE(zylonite_dai),
a9576cbb
LPC
229
230 .dapm_widgets = zylonite_dapm_widgets,
231 .num_dapm_widgets = ARRAY_SIZE(zylonite_dapm_widgets),
232 .dapm_routes = audio_map,
233 .num_dapm_routes = ARRAY_SIZE(audio_map),
2dac9217
MB
234};
235
236static struct platform_device *zylonite_snd_ac97_device;
237
238static int __init zylonite_init(void)
239{
240 int ret;
241
242 zylonite_snd_ac97_device = platform_device_alloc("soc-audio", -1);
243 if (!zylonite_snd_ac97_device)
244 return -ENOMEM;
245
f0fba2ad 246 platform_set_drvdata(zylonite_snd_ac97_device, &zylonite);
2dac9217
MB
247
248 ret = platform_device_add(zylonite_snd_ac97_device);
249 if (ret != 0)
250 platform_device_put(zylonite_snd_ac97_device);
251
252 return ret;
253}
254
255static void __exit zylonite_exit(void)
256{
257 platform_device_unregister(zylonite_snd_ac97_device);
258}
259
260module_init(zylonite_init);
261module_exit(zylonite_exit);
262
263MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
264MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite");
265MODULE_LICENSE("GPL");