1
2
3
4
5
6
7
8
9
10
11
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>
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"
32#include "pxa2xx-i2s.h"
33
34static struct snd_soc_card snd_soc_z2;
35
36static 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;
40 struct snd_soc_dai *codec_dai = rtd->codec_dai;
41 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
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
60 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
61 SND_SOC_CLOCK_IN);
62 if (ret < 0)
63 return ret;
64
65
66 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
67 SND_SOC_CLOCK_IN);
68 if (ret < 0)
69 return ret;
70
71 return 0;
72}
73
74static struct snd_soc_jack hs_jack;
75
76
77static struct snd_soc_jack_pin hs_jack_pins[] = {
78 {
79 .pin = "Mic Jack",
80 .mask = SND_JACK_MICROPHONE,
81 },
82 {
83 .pin = "Headphone Jack",
84 .mask = SND_JACK_HEADPHONE,
85 },
86 {
87 .pin = "Ext Spk",
88 .mask = SND_JACK_HEADPHONE,
89 .invert = 1
90 },
91};
92
93
94static struct snd_soc_jack_gpio hs_jack_gpios[] = {
95 {
96 .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
97 .name = "hsdet-gpio",
98 .report = SND_JACK_HEADSET,
99 .debounce_time = 200,
100 .invert = 1,
101 },
102};
103
104
105static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
106 SND_SOC_DAPM_HP("Headphone Jack", NULL),
107 SND_SOC_DAPM_MIC("Mic Jack", NULL),
108 SND_SOC_DAPM_SPK("Ext Spk", NULL),
109
110
111 SND_SOC_DAPM_HP("Headset Jack", NULL),
112};
113
114
115static const struct snd_soc_dapm_route z2_audio_map[] = {
116
117
118 {"Headphone Jack", NULL, "LOUT1"},
119 {"Headphone Jack", NULL, "ROUT1"},
120
121
122 {"Ext Spk", NULL , "ROUT2"},
123 {"Ext Spk", NULL , "LOUT2"},
124
125
126 {"RINPUT2", NULL, "Mic Bias"},
127 {"Mic Bias", NULL, "Mic Jack"},
128};
129
130
131
132
133static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
134{
135 int ret;
136
137
138 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET,
139 &hs_jack, hs_jack_pins,
140 ARRAY_SIZE(hs_jack_pins));
141 if (ret)
142 goto err;
143
144 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
145 hs_jack_gpios);
146 if (ret)
147 goto err;
148
149 return 0;
150
151err:
152 return ret;
153}
154
155static struct snd_soc_ops z2_ops = {
156 .hw_params = z2_hw_params,
157};
158
159
160static struct snd_soc_dai_link z2_dai = {
161 .name = "wm8750",
162 .stream_name = "WM8750",
163 .cpu_dai_name = "pxa2xx-i2s",
164 .codec_dai_name = "wm8750-hifi",
165 .platform_name = "pxa-pcm-audio",
166 .codec_name = "wm8750.0-001b",
167 .init = z2_wm8750_init,
168 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
169 SND_SOC_DAIFMT_CBS_CFS,
170 .ops = &z2_ops,
171};
172
173
174static struct snd_soc_card snd_soc_z2 = {
175 .name = "Z2",
176 .owner = THIS_MODULE,
177 .dai_link = &z2_dai,
178 .num_links = 1,
179
180 .dapm_widgets = wm8750_dapm_widgets,
181 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
182 .dapm_routes = z2_audio_map,
183 .num_dapm_routes = ARRAY_SIZE(z2_audio_map),
184 .fully_routed = true,
185};
186
187static struct platform_device *z2_snd_device;
188
189static int __init z2_init(void)
190{
191 int ret;
192
193 if (!machine_is_zipit2())
194 return -ENODEV;
195
196 z2_snd_device = platform_device_alloc("soc-audio", -1);
197 if (!z2_snd_device)
198 return -ENOMEM;
199
200 platform_set_drvdata(z2_snd_device, &snd_soc_z2);
201 ret = platform_device_add(z2_snd_device);
202
203 if (ret)
204 platform_device_put(z2_snd_device);
205
206 return ret;
207}
208
209static void __exit z2_exit(void)
210{
211 platform_device_unregister(z2_snd_device);
212}
213
214module_init(z2_init);
215module_exit(z2_exit);
216
217MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
218 "Marek Vasut <marek.vasut@gmail.com>");
219MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
220MODULE_LICENSE("GPL");
221