Commit | Line | Data |
---|---|---|
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> | |
17 | #include <linux/i2c.h> | |
18 | #include <sound/core.h> | |
19 | #include <sound/pcm.h> | |
20 | #include <sound/pcm_params.h> | |
21 | #include <sound/soc.h> | |
22 | #include <sound/soc-dapm.h> | |
23 | ||
24 | #include "../codecs/wm9713.h" | |
25 | #include "pxa2xx-pcm.h" | |
26 | #include "pxa2xx-ac97.h" | |
27 | #include "pxa-ssp.h" | |
28 | ||
29 | static struct snd_soc_card zylonite; | |
30 | ||
31 | static const struct snd_soc_dapm_widget zylonite_dapm_widgets[] = { | |
32 | SND_SOC_DAPM_HP("Headphone", NULL), | |
33 | SND_SOC_DAPM_MIC("Headset Microphone", NULL), | |
34 | SND_SOC_DAPM_MIC("Handset Microphone", NULL), | |
35 | SND_SOC_DAPM_SPK("Multiactor", NULL), | |
36 | SND_SOC_DAPM_SPK("Headset Earpiece", NULL), | |
37 | }; | |
38 | ||
39 | /* Currently supported audio map */ | |
40 | static const struct snd_soc_dapm_route audio_map[] = { | |
41 | ||
42 | /* Headphone output connected to HPL/HPR */ | |
43 | { "Headphone", NULL, "HPL" }, | |
44 | { "Headphone", NULL, "HPR" }, | |
45 | ||
46 | /* On-board earpiece */ | |
47 | { "Headset Earpiece", NULL, "OUT3" }, | |
48 | ||
49 | /* Headphone mic */ | |
50 | { "MIC2A", NULL, "Mic Bias" }, | |
51 | { "Mic Bias", NULL, "Headset Microphone" }, | |
52 | ||
53 | /* On-board mic */ | |
54 | { "MIC1", NULL, "Mic Bias" }, | |
55 | { "Mic Bias", NULL, "Handset Microphone" }, | |
56 | ||
57 | /* Multiactor differentially connected over SPKL/SPKR */ | |
58 | { "Multiactor", NULL, "SPKL" }, | |
59 | { "Multiactor", NULL, "SPKR" }, | |
60 | }; | |
61 | ||
62 | static int zylonite_wm9713_init(struct snd_soc_codec *codec) | |
63 | { | |
64 | /* Currently we only support use of the AC97 clock here. If | |
65 | * CLK_POUT is selected by SW15 then the clock API will need | |
66 | * to be used to request and enable it here. | |
67 | */ | |
68 | ||
69 | snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets, | |
70 | ARRAY_SIZE(zylonite_dapm_widgets)); | |
71 | ||
72 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | |
73 | ||
74 | /* Static setup for now */ | |
75 | snd_soc_dapm_enable_pin(codec, "Headphone"); | |
76 | snd_soc_dapm_enable_pin(codec, "Headset Earpiece"); | |
77 | ||
78 | snd_soc_dapm_sync(codec); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | static int zylonite_voice_hw_params(struct snd_pcm_substream *substream, | |
83 | struct snd_pcm_hw_params *params) | |
84 | { | |
85 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
86 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | |
87 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | |
88 | unsigned int pll_out = 0; | |
89 | unsigned int acds = 0; | |
90 | unsigned int wm9713_div = 0; | |
91 | int ret = 0; | |
92 | ||
93 | switch (params_rate(params)) { | |
94 | case 8000: | |
95 | wm9713_div = 12; | |
96 | pll_out = 2048000; | |
97 | break; | |
98 | case 16000: | |
99 | wm9713_div = 6; | |
100 | pll_out = 4096000; | |
101 | break; | |
102 | case 48000: | |
103 | default: | |
104 | wm9713_div = 2; | |
105 | pll_out = 12288000; | |
106 | acds = 1; | |
107 | break; | |
108 | } | |
109 | ||
110 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | |
111 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); | |
112 | if (ret < 0) | |
113 | return ret; | |
114 | ||
115 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | | |
116 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); | |
117 | if (ret < 0) | |
118 | return ret; | |
119 | ||
120 | ret = snd_soc_dai_set_tdm_slot(cpu_dai, | |
121 | params_channels(params), | |
122 | params_channels(params)); | |
123 | if (ret < 0) | |
124 | return ret; | |
125 | ||
126 | ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, pll_out); | |
127 | if (ret < 0) | |
128 | return ret; | |
129 | ||
130 | ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_AUDIO_DIV_ACDS, acds); | |
131 | if (ret < 0) | |
132 | return ret; | |
133 | ||
134 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1); | |
135 | if (ret < 0) | |
136 | return ret; | |
137 | ||
138 | /* Note that if the PLL is in use the WM9713_PCMCLK_PLL_DIV needs | |
139 | * to be set instead. | |
140 | */ | |
141 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV, | |
142 | WM9713_PCMDIV(wm9713_div)); | |
143 | if (ret < 0) | |
144 | return ret; | |
145 | ||
146 | return 0; | |
147 | } | |
148 | ||
149 | static struct snd_soc_ops zylonite_voice_ops = { | |
150 | .hw_params = zylonite_voice_hw_params, | |
151 | }; | |
152 | ||
153 | static struct snd_soc_dai_link zylonite_dai[] = { | |
154 | { | |
155 | .name = "AC97", | |
156 | .stream_name = "AC97 HiFi", | |
157 | .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI], | |
158 | .codec_dai = &wm9713_dai[WM9713_DAI_AC97_HIFI], | |
159 | .init = zylonite_wm9713_init, | |
160 | }, | |
161 | { | |
162 | .name = "AC97 Aux", | |
163 | .stream_name = "AC97 Aux", | |
164 | .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX], | |
165 | .codec_dai = &wm9713_dai[WM9713_DAI_AC97_AUX], | |
166 | }, | |
167 | { | |
168 | .name = "WM9713 Voice", | |
169 | .stream_name = "WM9713 Voice", | |
170 | .cpu_dai = &pxa_ssp_dai[PXA_DAI_SSP3], | |
171 | .codec_dai = &wm9713_dai[WM9713_DAI_PCM_VOICE], | |
172 | .ops = &zylonite_voice_ops, | |
173 | }, | |
174 | }; | |
175 | ||
176 | static struct snd_soc_card zylonite = { | |
177 | .name = "Zylonite", | |
87689d56 | 178 | .platform = &pxa2xx_soc_platform, |
2dac9217 MB |
179 | .dai_link = zylonite_dai, |
180 | .num_links = ARRAY_SIZE(zylonite_dai), | |
181 | }; | |
182 | ||
183 | static struct snd_soc_device zylonite_snd_ac97_devdata = { | |
184 | .card = &zylonite, | |
2dac9217 MB |
185 | .codec_dev = &soc_codec_dev_wm9713, |
186 | }; | |
187 | ||
188 | static struct platform_device *zylonite_snd_ac97_device; | |
189 | ||
190 | static int __init zylonite_init(void) | |
191 | { | |
192 | int ret; | |
193 | ||
194 | zylonite_snd_ac97_device = platform_device_alloc("soc-audio", -1); | |
195 | if (!zylonite_snd_ac97_device) | |
196 | return -ENOMEM; | |
197 | ||
198 | platform_set_drvdata(zylonite_snd_ac97_device, | |
199 | &zylonite_snd_ac97_devdata); | |
200 | zylonite_snd_ac97_devdata.dev = &zylonite_snd_ac97_device->dev; | |
201 | ||
202 | ret = platform_device_add(zylonite_snd_ac97_device); | |
203 | if (ret != 0) | |
204 | platform_device_put(zylonite_snd_ac97_device); | |
205 | ||
206 | return ret; | |
207 | } | |
208 | ||
209 | static void __exit zylonite_exit(void) | |
210 | { | |
211 | platform_device_unregister(zylonite_snd_ac97_device); | |
212 | } | |
213 | ||
214 | module_init(zylonite_init); | |
215 | module_exit(zylonite_exit); | |
216 | ||
217 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | |
218 | MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite"); | |
219 | MODULE_LICENSE("GPL"); |