1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/sound/soc/pxa/z2.c
5 * SoC Audio driver for Aeronix Zipit Z2
7 * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com>
8 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
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/consumer.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 <linux/platform_data/asoc-pxa.h>
26 #include "../codecs/wm8750.h"
27 #include "pxa2xx-i2s.h"
29 static struct snd_soc_card snd_soc_z2;
31 static int z2_hw_params(struct snd_pcm_substream *substream,
32 struct snd_pcm_hw_params *params)
34 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
35 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
36 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
40 switch (params_rate(params)) {
54 /* set the codec system clock for DAC and ADC */
55 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
60 /* set the I2S system clock as input (unused) */
61 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
69 static struct snd_soc_jack hs_jack;
71 /* Headset jack detection DAPM pins */
72 static struct snd_soc_jack_pin hs_jack_pins[] = {
75 .mask = SND_JACK_MICROPHONE,
78 .pin = "Headphone Jack",
79 .mask = SND_JACK_HEADPHONE,
83 .mask = SND_JACK_HEADPHONE,
88 /* Headset jack detection gpios */
89 static struct snd_soc_jack_gpio hs_jack_gpios[] = {
92 .report = SND_JACK_HEADSET,
98 /* z2 machine dapm widgets */
99 static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
100 SND_SOC_DAPM_HP("Headphone Jack", NULL),
101 SND_SOC_DAPM_MIC("Mic Jack", NULL),
102 SND_SOC_DAPM_SPK("Ext Spk", NULL),
104 /* headset is a mic and mono headphone */
105 SND_SOC_DAPM_HP("Headset Jack", NULL),
108 /* Z2 machine audio_map */
109 static const struct snd_soc_dapm_route z2_audio_map[] = {
111 /* headphone connected to LOUT1, ROUT1 */
112 {"Headphone Jack", NULL, "LOUT1"},
113 {"Headphone Jack", NULL, "ROUT1"},
115 /* ext speaker connected to LOUT2, ROUT2 */
116 {"Ext Spk", NULL, "ROUT2"},
117 {"Ext Spk", NULL, "LOUT2"},
119 /* mic is connected to R input 2 - with bias */
120 {"RINPUT2", NULL, "Mic Bias"},
121 {"Mic Bias", NULL, "Mic Jack"},
125 * Logic for a wm8750 as connected on a Z2 Device
127 static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
131 /* Jack detection API stuff */
132 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
133 SND_JACK_HEADSET, &hs_jack,
135 ARRAY_SIZE(hs_jack_pins));
139 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
150 static const struct snd_soc_ops z2_ops = {
151 .hw_params = z2_hw_params,
154 /* z2 digital audio interface glue - connects codec <--> CPU */
155 SND_SOC_DAILINK_DEFS(wm8750,
156 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-i2s")),
157 DAILINK_COMP_ARRAY(COMP_CODEC("wm8750.0-001b", "wm8750-hifi")),
158 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
160 static struct snd_soc_dai_link z2_dai = {
162 .stream_name = "WM8750",
163 .init = z2_wm8750_init,
164 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
165 SND_SOC_DAIFMT_CBS_CFS,
167 SND_SOC_DAILINK_REG(wm8750),
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 hs_jack_gpios[0].gpiod_dev = &z2_snd_device->dev;
198 platform_set_drvdata(z2_snd_device, &snd_soc_z2);
199 ret = platform_device_add(z2_snd_device);
202 platform_device_put(z2_snd_device);
207 static void __exit z2_exit(void)
209 platform_device_unregister(z2_snd_device);
212 module_init(z2_init);
213 module_exit(z2_exit);
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");