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>
24 #include "../codecs/wm9713.h"
25 #include "pxa2xx-ac97.h"
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.
34 module_param(clk_pout
, int, 0);
35 MODULE_PARM_DESC(clk_pout
, "Use CLK_POUT as WM9713 MCLK (SW15 on board).");
37 static struct clk
*pout
;
39 static struct snd_soc_card zylonite
;
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
),
49 /* Currently supported audio map */
50 static const struct snd_soc_dapm_route audio_map
[] = {
52 /* Headphone output connected to HPL/HPR */
53 { "Headphone", NULL
, "HPL" },
54 { "Headphone", NULL
, "HPR" },
56 /* On-board earpiece */
57 { "Headset Earpiece", NULL
, "OUT3" },
60 { "MIC2A", NULL
, "Mic Bias" },
61 { "Mic Bias", NULL
, "Headset Microphone" },
64 { "MIC1", NULL
, "Mic Bias" },
65 { "Mic Bias", NULL
, "Handset Microphone" },
67 /* Multiactor differentially connected over SPKL/SPKR */
68 { "Multiactor", NULL
, "SPKL" },
69 { "Multiactor", NULL
, "SPKR" },
72 static int zylonite_wm9713_init(struct snd_soc_pcm_runtime
*rtd
)
74 struct snd_soc_codec
*codec
= rtd
->codec
;
75 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
78 snd_soc_dai_set_pll(rtd
->codec_dai
, 0, 0,
79 clk_get_rate(pout
), 0);
81 snd_soc_dapm_new_controls(dapm
, zylonite_dapm_widgets
,
82 ARRAY_SIZE(zylonite_dapm_widgets
));
84 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
86 /* Static setup for now */
87 snd_soc_dapm_enable_pin(dapm
, "Headphone");
88 snd_soc_dapm_enable_pin(dapm
, "Headset Earpiece");
90 snd_soc_dapm_sync(dapm
);
94 static int zylonite_voice_hw_params(struct snd_pcm_substream
*substream
,
95 struct snd_pcm_hw_params
*params
)
97 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
98 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
99 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
100 unsigned int pll_out
= 0;
101 unsigned int wm9713_div
= 0;
103 int rate
= params_rate(params
);
104 int width
= snd_pcm_format_physical_width(params_format(params
));
106 /* Only support ratios that we can generate neatly from the AC97
107 * based master clock - in particular, this excludes 44.1kHz.
108 * In most applications the voice DAC will be used for telephony
109 * data so multiples of 8kHz will be the common case.
122 /* Don't support OSS emulation */
126 /* Add 1 to the width for the leading clock cycle */
127 pll_out
= rate
* (width
+ 1) * 8;
129 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA_SSP_CLK_AUDIO
, 0, 1);
133 ret
= snd_soc_dai_set_pll(cpu_dai
, 0, 0, 0, pll_out
);
138 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM9713_PCMCLK_PLL_DIV
,
139 WM9713_PCMDIV(wm9713_div
));
141 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM9713_PCMCLK_DIV
,
142 WM9713_PCMDIV(wm9713_div
));
146 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
147 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
151 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
152 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
159 static struct snd_soc_ops zylonite_voice_ops
= {
160 .hw_params
= zylonite_voice_hw_params
,
163 static struct snd_soc_dai_link zylonite_dai
[] = {
166 .stream_name
= "AC97 HiFi",
167 .codec_name
= "wm9713-codec",
168 .platform_name
= "pxa-pcm-audio",
169 .cpu_dai_name
= "pxa-ac97.0",
170 .codec_name
= "wm9713-hifi",
171 .init
= zylonite_wm9713_init
,
175 .stream_name
= "AC97 Aux",
176 .codec_name
= "wm9713-codec",
177 .platform_name
= "pxa-pcm-audio",
178 .cpu_dai_name
= "pxa-ac97.1",
179 .codec_name
= "wm9713-aux",
182 .name
= "WM9713 Voice",
183 .stream_name
= "WM9713 Voice",
184 .codec_name
= "wm9713-codec",
185 .platform_name
= "pxa-pcm-audio",
186 .cpu_dai_name
= "pxa-ssp-dai.2",
187 .codec_name
= "wm9713-voice",
188 .ops
= &zylonite_voice_ops
,
192 static int zylonite_probe(struct platform_device
*pdev
)
197 pout
= clk_get(NULL
, "CLK_POUT");
199 dev_err(&pdev
->dev
, "Unable to obtain CLK_POUT: %ld\n",
201 return PTR_ERR(pout
);
204 ret
= clk_enable(pout
);
206 dev_err(&pdev
->dev
, "Unable to enable CLK_POUT: %d\n",
212 dev_dbg(&pdev
->dev
, "MCLK enabled at %luHz\n",
219 static int zylonite_remove(struct platform_device
*pdev
)
229 static int zylonite_suspend_post(struct platform_device
*pdev
,
238 static int zylonite_resume_pre(struct platform_device
*pdev
)
243 ret
= clk_enable(pout
);
245 dev_err(&pdev
->dev
, "Unable to enable CLK_POUT: %d\n",
252 static struct snd_soc_card zylonite
= {
254 .probe
= &zylonite_probe
,
255 .remove
= &zylonite_remove
,
256 .suspend_post
= &zylonite_suspend_post
,
257 .resume_pre
= &zylonite_resume_pre
,
258 .dai_link
= zylonite_dai
,
259 .num_links
= ARRAY_SIZE(zylonite_dai
),
260 .owner
= THIS_MODULE
,
263 static struct platform_device
*zylonite_snd_ac97_device
;
265 static int __init
zylonite_init(void)
269 zylonite_snd_ac97_device
= platform_device_alloc("soc-audio", -1);
270 if (!zylonite_snd_ac97_device
)
273 platform_set_drvdata(zylonite_snd_ac97_device
, &zylonite
);
275 ret
= platform_device_add(zylonite_snd_ac97_device
);
277 platform_device_put(zylonite_snd_ac97_device
);
282 static void __exit
zylonite_exit(void)
284 platform_device_unregister(zylonite_snd_ac97_device
);
287 module_init(zylonite_init
);
288 module_exit(zylonite_exit
);
290 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
291 MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite");
292 MODULE_LICENSE("GPL");