]> git.ipfire.org Git - people/ms/linux.git/blob - sound/soc/pxa/z2.c
dc6c48e4738b3fbbeb339bcfa28359128ec50cd2
[people/ms/linux.git] / sound / soc / pxa / z2.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/sound/soc/pxa/z2.c
4 *
5 * SoC Audio driver for Aeronix Zipit Z2
6 *
7 * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com>
8 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
9 */
10
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/timer.h>
14 #include <linux/interrupt.h>
15 #include <linux/platform_device.h>
16 #include <linux/gpio.h>
17
18 #include <sound/core.h>
19 #include <sound/pcm.h>
20 #include <sound/soc.h>
21 #include <sound/jack.h>
22
23 #include <asm/mach-types.h>
24 #include <linux/platform_data/asoc-pxa.h>
25 #include <mach/z2.h>
26
27 #include "../codecs/wm8750.h"
28 #include "pxa2xx-i2s.h"
29
30 static struct snd_soc_card snd_soc_z2;
31
32 static int z2_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34 {
35 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
36 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
37 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
38 unsigned int clk = 0;
39 int ret = 0;
40
41 switch (params_rate(params)) {
42 case 8000:
43 case 16000:
44 case 48000:
45 case 96000:
46 clk = 12288000;
47 break;
48 case 11025:
49 case 22050:
50 case 44100:
51 clk = 11289600;
52 break;
53 }
54
55 /* set the codec system clock for DAC and ADC */
56 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
57 SND_SOC_CLOCK_IN);
58 if (ret < 0)
59 return ret;
60
61 /* set the I2S system clock as input (unused) */
62 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
63 SND_SOC_CLOCK_IN);
64 if (ret < 0)
65 return ret;
66
67 return 0;
68 }
69
70 static struct snd_soc_jack hs_jack;
71
72 /* Headset jack detection DAPM pins */
73 static struct snd_soc_jack_pin hs_jack_pins[] = {
74 {
75 .pin = "Mic Jack",
76 .mask = SND_JACK_MICROPHONE,
77 },
78 {
79 .pin = "Headphone Jack",
80 .mask = SND_JACK_HEADPHONE,
81 },
82 {
83 .pin = "Ext Spk",
84 .mask = SND_JACK_HEADPHONE,
85 .invert = 1
86 },
87 };
88
89 /* Headset jack detection gpios */
90 static struct snd_soc_jack_gpio hs_jack_gpios[] = {
91 {
92 .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
93 .name = "hsdet-gpio",
94 .report = SND_JACK_HEADSET,
95 .debounce_time = 200,
96 .invert = 1,
97 },
98 };
99
100 /* z2 machine dapm widgets */
101 static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
102 SND_SOC_DAPM_HP("Headphone Jack", NULL),
103 SND_SOC_DAPM_MIC("Mic Jack", NULL),
104 SND_SOC_DAPM_SPK("Ext Spk", NULL),
105
106 /* headset is a mic and mono headphone */
107 SND_SOC_DAPM_HP("Headset Jack", NULL),
108 };
109
110 /* Z2 machine audio_map */
111 static const struct snd_soc_dapm_route z2_audio_map[] = {
112
113 /* headphone connected to LOUT1, ROUT1 */
114 {"Headphone Jack", NULL, "LOUT1"},
115 {"Headphone Jack", NULL, "ROUT1"},
116
117 /* ext speaker connected to LOUT2, ROUT2 */
118 {"Ext Spk", NULL, "ROUT2"},
119 {"Ext Spk", NULL, "LOUT2"},
120
121 /* mic is connected to R input 2 - with bias */
122 {"RINPUT2", NULL, "Mic Bias"},
123 {"Mic Bias", NULL, "Mic Jack"},
124 };
125
126 /*
127 * Logic for a wm8750 as connected on a Z2 Device
128 */
129 static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
130 {
131 int ret;
132
133 /* Jack detection API stuff */
134 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET,
135 &hs_jack, hs_jack_pins,
136 ARRAY_SIZE(hs_jack_pins));
137 if (ret)
138 goto err;
139
140 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
141 hs_jack_gpios);
142 if (ret)
143 goto err;
144
145 return 0;
146
147 err:
148 return ret;
149 }
150
151 static const struct snd_soc_ops z2_ops = {
152 .hw_params = z2_hw_params,
153 };
154
155 /* z2 digital audio interface glue - connects codec <--> CPU */
156 SND_SOC_DAILINK_DEFS(wm8750,
157 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-i2s")),
158 DAILINK_COMP_ARRAY(COMP_CODEC("wm8750.0-001b", "wm8750-hifi")),
159 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
160
161 static struct snd_soc_dai_link z2_dai = {
162 .name = "wm8750",
163 .stream_name = "WM8750",
164 .init = z2_wm8750_init,
165 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
166 SND_SOC_DAIFMT_CBS_CFS,
167 .ops = &z2_ops,
168 SND_SOC_DAILINK_REG(wm8750),
169 };
170
171 /* z2 audio machine driver */
172 static struct snd_soc_card snd_soc_z2 = {
173 .name = "Z2",
174 .owner = THIS_MODULE,
175 .dai_link = &z2_dai,
176 .num_links = 1,
177
178 .dapm_widgets = wm8750_dapm_widgets,
179 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
180 .dapm_routes = z2_audio_map,
181 .num_dapm_routes = ARRAY_SIZE(z2_audio_map),
182 .fully_routed = true,
183 };
184
185 static struct platform_device *z2_snd_device;
186
187 static int __init z2_init(void)
188 {
189 int ret;
190
191 if (!machine_is_zipit2())
192 return -ENODEV;
193
194 z2_snd_device = platform_device_alloc("soc-audio", -1);
195 if (!z2_snd_device)
196 return -ENOMEM;
197
198 platform_set_drvdata(z2_snd_device, &snd_soc_z2);
199 ret = platform_device_add(z2_snd_device);
200
201 if (ret)
202 platform_device_put(z2_snd_device);
203
204 return ret;
205 }
206
207 static void __exit z2_exit(void)
208 {
209 platform_device_unregister(z2_snd_device);
210 }
211
212 module_init(z2_init);
213 module_exit(z2_exit);
214
215 MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
216 "Marek Vasut <marek.vasut@gmail.com>");
217 MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
218 MODULE_LICENSE("GPL");