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/jack.h>
26 #include <asm/mach-types.h>
27 #include <mach/hardware.h>
28 #include <mach/audio.h>
31 #include "../codecs/wm8750.h"
32 #include "pxa2xx-i2s.h"
34 static struct snd_soc_card snd_soc_z2
;
36 static int z2_hw_params(struct snd_pcm_substream
*substream
,
37 struct snd_pcm_hw_params
*params
)
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
;
45 switch (params_rate(params
)) {
59 /* set the codec system clock for DAC and ADC */
60 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8750_SYSCLK
, clk
,
65 /* set the I2S system clock as input (unused) */
66 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA2XX_I2S_SYSCLK
, 0,
74 static struct snd_soc_jack hs_jack
;
76 /* Headset jack detection DAPM pins */
77 static struct snd_soc_jack_pin hs_jack_pins
[] = {
80 .mask
= SND_JACK_MICROPHONE
,
83 .pin
= "Headphone Jack",
84 .mask
= SND_JACK_HEADPHONE
,
88 .mask
= SND_JACK_HEADPHONE
,
93 /* Headset jack detection gpios */
94 static struct snd_soc_jack_gpio hs_jack_gpios
[] = {
96 .gpio
= GPIO37_ZIPITZ2_HEADSET_DETECT
,
98 .report
= SND_JACK_HEADSET
,
104 /* z2 machine dapm widgets */
105 static 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
),
110 /* headset is a mic and mono headphone */
111 SND_SOC_DAPM_HP("Headset Jack", NULL
),
114 /* Z2 machine audio_map */
115 static const struct snd_soc_dapm_route z2_audio_map
[] = {
117 /* headphone connected to LOUT1, ROUT1 */
118 {"Headphone Jack", NULL
, "LOUT1"},
119 {"Headphone Jack", NULL
, "ROUT1"},
121 /* ext speaker connected to LOUT2, ROUT2 */
122 {"Ext Spk", NULL
, "ROUT2"},
123 {"Ext Spk", NULL
, "LOUT2"},
125 /* mic is connected to R input 2 - with bias */
126 {"RINPUT2", NULL
, "Mic Bias"},
127 {"Mic Bias", NULL
, "Mic Jack"},
131 * Logic for a wm8750 as connected on a Z2 Device
133 static int z2_wm8750_init(struct snd_soc_pcm_runtime
*rtd
)
137 /* Jack detection API stuff */
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
));
144 ret
= snd_soc_jack_add_gpios(&hs_jack
, ARRAY_SIZE(hs_jack_gpios
),
155 static struct snd_soc_ops z2_ops
= {
156 .hw_params
= z2_hw_params
,
159 /* z2 digital audio interface glue - connects codec <--> CPU */
160 static struct snd_soc_dai_link z2_dai
= {
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
,
173 /* z2 audio machine driver */
174 static struct snd_soc_card snd_soc_z2
= {
176 .owner
= THIS_MODULE
,
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,
187 static struct platform_device
*z2_snd_device
;
189 static int __init
z2_init(void)
193 if (!machine_is_zipit2())
196 z2_snd_device
= platform_device_alloc("soc-audio", -1);
200 platform_set_drvdata(z2_snd_device
, &snd_soc_z2
);
201 ret
= platform_device_add(z2_snd_device
);
204 platform_device_put(z2_snd_device
);
209 static void __exit
z2_exit(void)
211 platform_device_unregister(z2_snd_device
);
214 module_init(z2_init
);
215 module_exit(z2_exit
);
217 MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
218 "Marek Vasut <marek.vasut@gmail.com>");
219 MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
220 MODULE_LICENSE("GPL");