Commit | Line | Data |
---|---|---|
d21e0f4c MV |
1 | /* |
2 | * linux/sound/soc/pxa/z2.c | |
3 | * | |
4 | * SoC Audio driver for Aeronix Zipit Z2 | |
5 | * | |
6 | * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com> | |
7 | * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
14 | #include <linux/module.h> | |
15 | #include <linux/moduleparam.h> | |
16 | #include <linux/timer.h> | |
17 | #include <linux/interrupt.h> | |
18 | #include <linux/platform_device.h> | |
19 | #include <linux/gpio.h> | |
20 | ||
21 | #include <sound/core.h> | |
22 | #include <sound/pcm.h> | |
23 | #include <sound/soc.h> | |
d21e0f4c MV |
24 | #include <sound/jack.h> |
25 | ||
26 | #include <asm/mach-types.h> | |
27 | #include <mach/hardware.h> | |
28 | #include <mach/audio.h> | |
29 | #include <mach/z2.h> | |
30 | ||
31 | #include "../codecs/wm8750.h" | |
d21e0f4c MV |
32 | #include "pxa2xx-i2s.h" |
33 | ||
34 | static struct snd_soc_card snd_soc_z2; | |
35 | ||
36 | static int z2_hw_params(struct snd_pcm_substream *substream, | |
37 | struct snd_pcm_hw_params *params) | |
38 | { | |
39 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad LG |
40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
41 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
d21e0f4c MV |
42 | unsigned int clk = 0; |
43 | int ret = 0; | |
44 | ||
45 | switch (params_rate(params)) { | |
46 | case 8000: | |
47 | case 16000: | |
48 | case 48000: | |
49 | case 96000: | |
50 | clk = 12288000; | |
51 | break; | |
52 | case 11025: | |
53 | case 22050: | |
54 | case 44100: | |
55 | clk = 11289600; | |
56 | break; | |
57 | } | |
58 | ||
59 | /* set codec DAI configuration */ | |
60 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | |
61 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); | |
62 | if (ret < 0) | |
63 | return ret; | |
64 | ||
65 | /* set cpu DAI configuration */ | |
66 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | | |
67 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); | |
68 | if (ret < 0) | |
69 | return ret; | |
70 | ||
71 | /* set the codec system clock for DAC and ADC */ | |
72 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, | |
73 | SND_SOC_CLOCK_IN); | |
74 | if (ret < 0) | |
75 | return ret; | |
76 | ||
77 | /* set the I2S system clock as input (unused) */ | |
78 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0, | |
79 | SND_SOC_CLOCK_IN); | |
80 | if (ret < 0) | |
81 | return ret; | |
82 | ||
83 | return 0; | |
84 | } | |
85 | ||
86 | static struct snd_soc_jack hs_jack; | |
87 | ||
88 | /* Headset jack detection DAPM pins */ | |
89 | static struct snd_soc_jack_pin hs_jack_pins[] = { | |
90 | { | |
91 | .pin = "Mic Jack", | |
92 | .mask = SND_JACK_MICROPHONE, | |
93 | }, | |
94 | { | |
95 | .pin = "Headphone Jack", | |
96 | .mask = SND_JACK_HEADPHONE, | |
97 | }, | |
98 | }; | |
99 | ||
100 | /* Headset jack detection gpios */ | |
101 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { | |
102 | { | |
103 | .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT, | |
104 | .name = "hsdet-gpio", | |
105 | .report = SND_JACK_HEADSET, | |
106 | .debounce_time = 200, | |
107 | }, | |
108 | }; | |
109 | ||
110 | /* z2 machine dapm widgets */ | |
111 | static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = { | |
112 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
113 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | |
114 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | |
115 | ||
116 | /* headset is a mic and mono headphone */ | |
117 | SND_SOC_DAPM_HP("Headset Jack", NULL), | |
118 | }; | |
119 | ||
120 | /* Z2 machine audio_map */ | |
121 | static const struct snd_soc_dapm_route audio_map[] = { | |
122 | ||
123 | /* headphone connected to LOUT1, ROUT1 */ | |
124 | {"Headphone Jack", NULL, "LOUT1"}, | |
125 | {"Headphone Jack", NULL, "ROUT1"}, | |
126 | ||
127 | /* ext speaker connected to LOUT2, ROUT2 */ | |
128 | {"Ext Spk", NULL , "ROUT2"}, | |
129 | {"Ext Spk", NULL , "LOUT2"}, | |
130 | ||
131 | /* mic is connected to R input 2 - with bias */ | |
132 | {"RINPUT2", NULL, "Mic Bias"}, | |
133 | {"Mic Bias", NULL, "Mic Jack"}, | |
134 | }; | |
135 | ||
136 | /* | |
137 | * Logic for a wm8750 as connected on a Z2 Device | |
138 | */ | |
f0fba2ad | 139 | static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd) |
d21e0f4c | 140 | { |
f0fba2ad | 141 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 142 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
d21e0f4c MV |
143 | int ret; |
144 | ||
145 | /* NC codec pins */ | |
ce6120cc LG |
146 | snd_soc_dapm_disable_pin(dapm, "LINPUT3"); |
147 | snd_soc_dapm_disable_pin(dapm, "RINPUT3"); | |
148 | snd_soc_dapm_disable_pin(dapm, "OUT3"); | |
149 | snd_soc_dapm_disable_pin(dapm, "MONO"); | |
d21e0f4c MV |
150 | |
151 | /* Add z2 specific widgets */ | |
ce6120cc | 152 | snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets, |
d21e0f4c MV |
153 | ARRAY_SIZE(wm8750_dapm_widgets)); |
154 | ||
155 | /* Set up z2 specific audio paths */ | |
ce6120cc | 156 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
d21e0f4c | 157 | |
ce6120cc | 158 | ret = snd_soc_dapm_sync(dapm); |
d21e0f4c MV |
159 | if (ret) |
160 | goto err; | |
161 | ||
162 | /* Jack detection API stuff */ | |
f0fba2ad | 163 | ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, |
d21e0f4c MV |
164 | &hs_jack); |
165 | if (ret) | |
166 | goto err; | |
167 | ||
168 | ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins), | |
169 | hs_jack_pins); | |
170 | if (ret) | |
171 | goto err; | |
172 | ||
173 | ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios), | |
174 | hs_jack_gpios); | |
175 | if (ret) | |
176 | goto err; | |
177 | ||
178 | return 0; | |
179 | ||
180 | err: | |
181 | return ret; | |
182 | } | |
183 | ||
184 | static struct snd_soc_ops z2_ops = { | |
185 | .hw_params = z2_hw_params, | |
186 | }; | |
187 | ||
188 | /* z2 digital audio interface glue - connects codec <--> CPU */ | |
189 | static struct snd_soc_dai_link z2_dai = { | |
190 | .name = "wm8750", | |
191 | .stream_name = "WM8750", | |
a2a0086d | 192 | .cpu_dai_name = "pxa2xx-i2s", |
f0fba2ad LG |
193 | .codec_dai_name = "wm8750-hifi", |
194 | .platform_name = "pxa-pcm-audio", | |
195 | .codec_name = "wm8750-codec.0-001a", | |
d21e0f4c MV |
196 | .init = z2_wm8750_init, |
197 | .ops = &z2_ops, | |
198 | }; | |
199 | ||
200 | /* z2 audio machine driver */ | |
201 | static struct snd_soc_card snd_soc_z2 = { | |
202 | .name = "Z2", | |
d21e0f4c MV |
203 | .dai_link = &z2_dai, |
204 | .num_links = 1, | |
205 | }; | |
206 | ||
d21e0f4c MV |
207 | static struct platform_device *z2_snd_device; |
208 | ||
209 | static int __init z2_init(void) | |
210 | { | |
211 | int ret; | |
212 | ||
213 | if (!machine_is_zipit2()) | |
214 | return -ENODEV; | |
215 | ||
216 | z2_snd_device = platform_device_alloc("soc-audio", -1); | |
217 | if (!z2_snd_device) | |
218 | return -ENOMEM; | |
219 | ||
f0fba2ad | 220 | platform_set_drvdata(z2_snd_device, &snd_soc_z2); |
d21e0f4c MV |
221 | ret = platform_device_add(z2_snd_device); |
222 | ||
223 | if (ret) | |
224 | platform_device_put(z2_snd_device); | |
225 | ||
226 | return ret; | |
227 | } | |
228 | ||
229 | static void __exit z2_exit(void) | |
230 | { | |
231 | platform_device_unregister(z2_snd_device); | |
232 | } | |
233 | ||
234 | module_init(z2_init); | |
235 | module_exit(z2_exit); | |
236 | ||
237 | MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, " | |
238 | "Marek Vasut <marek.vasut@gmail.com>"); | |
239 | MODULE_DESCRIPTION("ALSA SoC ZipitZ2"); | |
240 | MODULE_LICENSE("GPL"); |