1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/sound/soc/pxa/z2.c
5 * SoC Audio driver for Aeronix Zipit Z2
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>
18 #include <sound/core.h>
19 #include <sound/pcm.h>
20 #include <sound/soc.h>
21 #include <sound/jack.h>
23 #include <asm/mach-types.h>
24 #include <mach/hardware.h>
25 #include <mach/audio.h>
28 #include "../codecs/wm8750.h"
29 #include "pxa2xx-i2s.h"
31 static struct snd_soc_card snd_soc_z2;
33 static int z2_hw_params(struct snd_pcm_substream *substream,
34 struct snd_pcm_hw_params *params)
36 struct snd_soc_pcm_runtime *rtd = substream->private_data;
37 struct snd_soc_dai *codec_dai = rtd->codec_dai;
38 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
42 switch (params_rate(params)) {
56 /* set the codec system clock for DAC and ADC */
57 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
62 /* set the I2S system clock as input (unused) */
63 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
71 static struct snd_soc_jack hs_jack;
73 /* Headset jack detection DAPM pins */
74 static struct snd_soc_jack_pin hs_jack_pins[] = {
77 .mask = SND_JACK_MICROPHONE,
80 .pin = "Headphone Jack",
81 .mask = SND_JACK_HEADPHONE,
85 .mask = SND_JACK_HEADPHONE,
90 /* Headset jack detection gpios */
91 static struct snd_soc_jack_gpio hs_jack_gpios[] = {
93 .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
95 .report = SND_JACK_HEADSET,
101 /* z2 machine dapm widgets */
102 static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
103 SND_SOC_DAPM_HP("Headphone Jack", NULL),
104 SND_SOC_DAPM_MIC("Mic Jack", NULL),
105 SND_SOC_DAPM_SPK("Ext Spk", NULL),
107 /* headset is a mic and mono headphone */
108 SND_SOC_DAPM_HP("Headset Jack", NULL),
111 /* Z2 machine audio_map */
112 static const struct snd_soc_dapm_route z2_audio_map[] = {
114 /* headphone connected to LOUT1, ROUT1 */
115 {"Headphone Jack", NULL, "LOUT1"},
116 {"Headphone Jack", NULL, "ROUT1"},
118 /* ext speaker connected to LOUT2, ROUT2 */
119 {"Ext Spk", NULL, "ROUT2"},
120 {"Ext Spk", NULL, "LOUT2"},
122 /* mic is connected to R input 2 - with bias */
123 {"RINPUT2", NULL, "Mic Bias"},
124 {"Mic Bias", NULL, "Mic Jack"},
128 * Logic for a wm8750 as connected on a Z2 Device
130 static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
134 /* Jack detection API stuff */
135 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET,
136 &hs_jack, hs_jack_pins,
137 ARRAY_SIZE(hs_jack_pins));
141 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
152 static const struct snd_soc_ops z2_ops = {
153 .hw_params = z2_hw_params,
156 /* z2 digital audio interface glue - connects codec <--> CPU */
157 static struct snd_soc_dai_link z2_dai = {
159 .stream_name = "WM8750",
160 .cpu_dai_name = "pxa2xx-i2s",
161 .codec_dai_name = "wm8750-hifi",
162 .platform_name = "pxa-pcm-audio",
163 .codec_name = "wm8750.0-001b",
164 .init = z2_wm8750_init,
165 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
166 SND_SOC_DAIFMT_CBS_CFS,
170 /* z2 audio machine driver */
171 static struct snd_soc_card snd_soc_z2 = {
173 .owner = THIS_MODULE,
177 .dapm_widgets = wm8750_dapm_widgets,
178 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
179 .dapm_routes = z2_audio_map,
180 .num_dapm_routes = ARRAY_SIZE(z2_audio_map),
181 .fully_routed = true,
184 static struct platform_device *z2_snd_device;
186 static int __init z2_init(void)
190 if (!machine_is_zipit2())
193 z2_snd_device = platform_device_alloc("soc-audio", -1);
197 platform_set_drvdata(z2_snd_device, &snd_soc_z2);
198 ret = platform_device_add(z2_snd_device);
201 platform_device_put(z2_snd_device);
206 static void __exit z2_exit(void)
208 platform_device_unregister(z2_snd_device);
211 module_init(z2_init);
212 module_exit(z2_exit);
216 MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
217 MODULE_LICENSE("GPL");