2 * linux/sound/soc/pxa/z2.c
4 * SoC Audio driver for Aeronix Zipit Z2
6 * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com>
7 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
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.
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>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/soc.h>
24 #include <sound/soc-dapm.h>
25 #include <sound/jack.h>
27 #include <asm/mach-types.h>
28 #include <mach/hardware.h>
29 #include <mach/audio.h>
32 #include "../codecs/wm8750.h"
33 #include "pxa2xx-pcm.h"
34 #include "pxa2xx-i2s.h"
36 static struct snd_soc_card snd_soc_z2
;
38 static int z2_hw_params(struct snd_pcm_substream
*substream
,
39 struct snd_pcm_hw_params
*params
)
41 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
42 struct snd_soc_dai
*codec_dai
= rtd
->dai
->codec_dai
;
43 struct snd_soc_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
47 switch (params_rate(params
)) {
61 /* set codec DAI configuration */
62 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
63 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
67 /* set cpu DAI configuration */
68 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
69 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
73 /* set the codec system clock for DAC and ADC */
74 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8750_SYSCLK
, clk
,
79 /* set the I2S system clock as input (unused) */
80 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA2XX_I2S_SYSCLK
, 0,
88 static struct snd_soc_jack hs_jack
;
90 /* Headset jack detection DAPM pins */
91 static struct snd_soc_jack_pin hs_jack_pins
[] = {
94 .mask
= SND_JACK_MICROPHONE
,
97 .pin
= "Headphone Jack",
98 .mask
= SND_JACK_HEADPHONE
,
102 /* Headset jack detection gpios */
103 static struct snd_soc_jack_gpio hs_jack_gpios
[] = {
105 .gpio
= GPIO37_ZIPITZ2_HEADSET_DETECT
,
106 .name
= "hsdet-gpio",
107 .report
= SND_JACK_HEADSET
,
108 .debounce_time
= 200,
112 /* z2 machine dapm widgets */
113 static const struct snd_soc_dapm_widget wm8750_dapm_widgets
[] = {
114 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
115 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
116 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
118 /* headset is a mic and mono headphone */
119 SND_SOC_DAPM_HP("Headset Jack", NULL
),
122 /* Z2 machine audio_map */
123 static const struct snd_soc_dapm_route audio_map
[] = {
125 /* headphone connected to LOUT1, ROUT1 */
126 {"Headphone Jack", NULL
, "LOUT1"},
127 {"Headphone Jack", NULL
, "ROUT1"},
129 /* ext speaker connected to LOUT2, ROUT2 */
130 {"Ext Spk", NULL
, "ROUT2"},
131 {"Ext Spk", NULL
, "LOUT2"},
133 /* mic is connected to R input 2 - with bias */
134 {"RINPUT2", NULL
, "Mic Bias"},
135 {"Mic Bias", NULL
, "Mic Jack"},
139 * Logic for a wm8750 as connected on a Z2 Device
141 static int z2_wm8750_init(struct snd_soc_codec
*codec
)
146 snd_soc_dapm_disable_pin(codec
, "LINPUT3");
147 snd_soc_dapm_disable_pin(codec
, "RINPUT3");
148 snd_soc_dapm_disable_pin(codec
, "OUT3");
149 snd_soc_dapm_disable_pin(codec
, "MONO");
151 /* Add z2 specific widgets */
152 snd_soc_dapm_new_controls(codec
, wm8750_dapm_widgets
,
153 ARRAY_SIZE(wm8750_dapm_widgets
));
155 /* Set up z2 specific audio paths */
156 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
158 ret
= snd_soc_dapm_sync(codec
);
162 /* Jack detection API stuff */
163 ret
= snd_soc_jack_new(&snd_soc_z2
, "Headset Jack", SND_JACK_HEADSET
,
168 ret
= snd_soc_jack_add_pins(&hs_jack
, ARRAY_SIZE(hs_jack_pins
),
173 ret
= snd_soc_jack_add_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
184 static struct snd_soc_ops z2_ops
= {
185 .hw_params
= z2_hw_params
,
188 /* z2 digital audio interface glue - connects codec <--> CPU */
189 static struct snd_soc_dai_link z2_dai
= {
191 .stream_name
= "WM8750",
192 .cpu_dai
= &pxa_i2s_dai
,
193 .codec_dai
= &wm8750_dai
,
194 .init
= z2_wm8750_init
,
198 /* z2 audio machine driver */
199 static struct snd_soc_card snd_soc_z2
= {
201 .platform
= &pxa2xx_soc_platform
,
206 /* z2 audio subsystem */
207 static struct snd_soc_device z2_snd_devdata
= {
209 .codec_dev
= &soc_codec_dev_wm8750
,
212 static struct platform_device
*z2_snd_device
;
214 static int __init
z2_init(void)
218 if (!machine_is_zipit2())
221 z2_snd_device
= platform_device_alloc("soc-audio", -1);
225 platform_set_drvdata(z2_snd_device
, &z2_snd_devdata
);
226 z2_snd_devdata
.dev
= &z2_snd_device
->dev
;
227 ret
= platform_device_add(z2_snd_device
);
230 platform_device_put(z2_snd_device
);
235 static void __exit
z2_exit(void)
237 platform_device_unregister(z2_snd_device
);
240 module_init(z2_init
);
241 module_exit(z2_exit
);
243 MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
244 "Marek Vasut <marek.vasut@gmail.com>");
245 MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
246 MODULE_LICENSE("GPL");