2 * SoC audio for HP iPAQ hx4700
4 * Copyright (c) 2009 Philipp Zabel
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
13 #include <linux/module.h>
14 #include <linux/timer.h>
15 #include <linux/interrupt.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/gpio.h>
20 #include <sound/core.h>
21 #include <sound/jack.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
26 #include <mach/hx4700.h>
27 #include <asm/mach-types.h>
28 #include "pxa2xx-i2s.h"
30 #include "../codecs/ak4641.h"
32 static struct snd_soc_jack hs_jack
;
34 /* Headphones jack detection DAPM pin */
35 static struct snd_soc_jack_pin hs_jack_pin
[] = {
37 .pin
= "Headphone Jack",
38 .mask
= SND_JACK_HEADPHONE
,
42 /* disable speaker when hp jack is inserted */
43 .mask
= SND_JACK_HEADPHONE
,
48 /* Headphones jack detection GPIO */
49 static struct snd_soc_jack_gpio hs_jack_gpio
= {
50 .gpio
= GPIO75_HX4700_EARPHONE_nDET
,
53 .report
= SND_JACK_HEADPHONE
,
58 * iPAQ hx4700 uses I2S for capture and playback.
60 static int hx4700_hw_params(struct snd_pcm_substream
*substream
,
61 struct snd_pcm_hw_params
*params
)
63 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
64 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
65 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
68 /* set the I2S system clock as output */
69 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA2XX_I2S_SYSCLK
, 0,
74 /* inform codec driver about clock freq *
75 * (PXA I2S always uses divider 256) */
76 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, 256 * params_rate(params
),
84 static struct snd_soc_ops hx4700_ops
= {
85 .hw_params
= hx4700_hw_params
,
88 static int hx4700_spk_power(struct snd_soc_dapm_widget
*w
,
89 struct snd_kcontrol
*k
, int event
)
91 gpio_set_value(GPIO107_HX4700_SPK_nSD
, !!SND_SOC_DAPM_EVENT_ON(event
));
95 static int hx4700_hp_power(struct snd_soc_dapm_widget
*w
,
96 struct snd_kcontrol
*k
, int event
)
98 gpio_set_value(GPIO92_HX4700_HP_DRIVER
, !!SND_SOC_DAPM_EVENT_ON(event
));
102 /* hx4700 machine dapm widgets */
103 static const struct snd_soc_dapm_widget hx4700_dapm_widgets
[] = {
104 SND_SOC_DAPM_HP("Headphone Jack", hx4700_hp_power
),
105 SND_SOC_DAPM_SPK("Speaker", hx4700_spk_power
),
106 SND_SOC_DAPM_MIC("Built-in Microphone", NULL
),
109 /* hx4700 machine audio_map */
110 static const struct snd_soc_dapm_route hx4700_audio_map
[] = {
112 /* Headphone connected to LOUT, ROUT */
113 {"Headphone Jack", NULL
, "LOUT"},
114 {"Headphone Jack", NULL
, "ROUT"},
116 /* Speaker connected to MOUT2 */
117 {"Speaker", NULL
, "MOUT2"},
119 /* Microphone connected to MICIN */
120 {"MICIN", NULL
, "Built-in Microphone"},
121 {"AIN", NULL
, "MICOUT"},
125 * Logic for a ak4641 as connected on a HP iPAQ hx4700
127 static int hx4700_ak4641_init(struct snd_soc_pcm_runtime
*rtd
)
131 /* Jack detection API stuff */
132 err
= snd_soc_card_jack_new(rtd
->card
, "Headphone Jack",
133 SND_JACK_HEADPHONE
, &hs_jack
, hs_jack_pin
,
134 ARRAY_SIZE(hs_jack_pin
));
138 err
= snd_soc_jack_add_gpios(&hs_jack
, 1, &hs_jack_gpio
);
143 static int hx4700_card_remove(struct snd_soc_card
*card
)
145 snd_soc_jack_free_gpios(&hs_jack
, 1, &hs_jack_gpio
);
150 /* hx4700 digital audio interface glue - connects codec <--> CPU */
151 static struct snd_soc_dai_link hx4700_dai
= {
153 .stream_name
= "AK4641",
154 .cpu_dai_name
= "pxa2xx-i2s",
155 .codec_dai_name
= "ak4641-hifi",
156 .platform_name
= "pxa-pcm-audio",
157 .codec_name
= "ak4641.0-0012",
158 .init
= hx4700_ak4641_init
,
159 .dai_fmt
= SND_SOC_DAIFMT_MSB
| SND_SOC_DAIFMT_NB_NF
|
160 SND_SOC_DAIFMT_CBS_CFS
,
164 /* hx4700 audio machine driver */
165 static struct snd_soc_card snd_soc_card_hx4700
= {
166 .name
= "iPAQ hx4700",
167 .owner
= THIS_MODULE
,
168 .remove
= hx4700_card_remove
,
169 .dai_link
= &hx4700_dai
,
171 .dapm_widgets
= hx4700_dapm_widgets
,
172 .num_dapm_widgets
= ARRAY_SIZE(hx4700_dapm_widgets
),
173 .dapm_routes
= hx4700_audio_map
,
174 .num_dapm_routes
= ARRAY_SIZE(hx4700_audio_map
),
175 .fully_routed
= true,
178 static struct gpio hx4700_audio_gpios
[] = {
179 { GPIO107_HX4700_SPK_nSD
, GPIOF_OUT_INIT_HIGH
, "SPK_POWER" },
180 { GPIO92_HX4700_HP_DRIVER
, GPIOF_OUT_INIT_LOW
, "EP_POWER" },
183 static int hx4700_audio_probe(struct platform_device
*pdev
)
187 if (!machine_is_h4700())
190 ret
= gpio_request_array(hx4700_audio_gpios
,
191 ARRAY_SIZE(hx4700_audio_gpios
));
195 snd_soc_card_hx4700
.dev
= &pdev
->dev
;
196 ret
= devm_snd_soc_register_card(&pdev
->dev
, &snd_soc_card_hx4700
);
198 gpio_free_array(hx4700_audio_gpios
,
199 ARRAY_SIZE(hx4700_audio_gpios
));
204 static int hx4700_audio_remove(struct platform_device
*pdev
)
206 gpio_set_value(GPIO92_HX4700_HP_DRIVER
, 0);
207 gpio_set_value(GPIO107_HX4700_SPK_nSD
, 0);
209 gpio_free_array(hx4700_audio_gpios
, ARRAY_SIZE(hx4700_audio_gpios
));
213 static struct platform_driver hx4700_audio_driver
= {
215 .name
= "hx4700-audio",
216 .pm
= &snd_soc_pm_ops
,
218 .probe
= hx4700_audio_probe
,
219 .remove
= hx4700_audio_remove
,
222 module_platform_driver(hx4700_audio_driver
);
224 MODULE_AUTHOR("Philipp Zabel");
225 MODULE_DESCRIPTION("ALSA SoC iPAQ hx4700");
226 MODULE_LICENSE("GPL");
227 MODULE_ALIAS("platform:hx4700-audio");