Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / sound / soc / pxa / e740_wm9705.c
CommitLineData
28796eaf
IM
1/*
2 * e740-wm9705.c -- SoC audio for e740
3 *
4 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
5 *
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; version 2 ONLY.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/gpio.h>
15
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/soc.h>
28796eaf 19
28796eaf
IM
20#include <mach/audio.h>
21#include <mach/eseries-gpio.h>
22
23#include <asm/mach-types.h>
24
28796eaf
IM
25#define E740_AUDIO_OUT 1
26#define E740_AUDIO_IN 2
27
28static int e740_audio_power;
29
30static void e740_sync_audio_power(int status)
31{
32 gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
33 gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
34 gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
35}
36
37static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
38 struct snd_kcontrol *kcontrol, int event)
39{
40 if (event & SND_SOC_DAPM_PRE_PMU)
41 e740_audio_power |= E740_AUDIO_IN;
42 else if (event & SND_SOC_DAPM_POST_PMD)
43 e740_audio_power &= ~E740_AUDIO_IN;
44
45 e740_sync_audio_power(e740_audio_power);
46
47 return 0;
48}
49
50static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
51 struct snd_kcontrol *kcontrol, int event)
52{
53 if (event & SND_SOC_DAPM_PRE_PMU)
54 e740_audio_power |= E740_AUDIO_OUT;
55 else if (event & SND_SOC_DAPM_POST_PMD)
56 e740_audio_power &= ~E740_AUDIO_OUT;
57
58 e740_sync_audio_power(e740_audio_power);
59
60 return 0;
61}
62
63static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
64 SND_SOC_DAPM_HP("Headphone Jack", NULL),
65 SND_SOC_DAPM_SPK("Speaker", NULL),
66 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
67 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
68 e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
69 SND_SOC_DAPM_POST_PMD),
70 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
71 e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
72 SND_SOC_DAPM_POST_PMD),
73};
74
75static const struct snd_soc_dapm_route audio_map[] = {
76 {"Output Amp", NULL, "LOUT"},
77 {"Output Amp", NULL, "ROUT"},
78 {"Output Amp", NULL, "MONOOUT"},
79
80 {"Speaker", NULL, "Output Amp"},
81 {"Headphone Jack", NULL, "Output Amp"},
82
83 {"MIC1", NULL, "Mic Amp"},
84 {"Mic Amp", NULL, "Mic (Internal)"},
85};
86
28796eaf
IM
87static struct snd_soc_dai_link e740_dai[] = {
88 {
89 .name = "AC97",
90 .stream_name = "AC97 HiFi",
4bfc4e25 91 .cpu_dai_name = "pxa2xx-ac97",
f0fba2ad
LG
92 .codec_dai_name = "wm9705-hifi",
93 .platform_name = "pxa-pcm-audio",
94 .codec_name = "wm9705-codec",
28796eaf
IM
95 },
96 {
97 .name = "AC97 Aux",
98 .stream_name = "AC97 Aux",
4bfc4e25 99 .cpu_dai_name = "pxa2xx-ac97-aux",
f0fba2ad
LG
100 .codec_dai_name = "wm9705-aux",
101 .platform_name = "pxa-pcm-audio",
102 .codec_name = "wm9705-codec",
28796eaf
IM
103 },
104};
105
106static struct snd_soc_card e740 = {
107 .name = "Toshiba e740",
561c6a17 108 .owner = THIS_MODULE,
28796eaf
IM
109 .dai_link = e740_dai,
110 .num_links = ARRAY_SIZE(e740_dai),
23d8f225
LPC
111
112 .dapm_widgets = e740_dapm_widgets,
113 .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
114 .dapm_routes = audio_map,
115 .num_dapm_routes = ARRAY_SIZE(audio_map),
dff6c964 116 .fully_routed = true,
28796eaf
IM
117};
118
62133829
AL
119static struct gpio e740_audio_gpios[] = {
120 { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" },
121 { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" },
122 { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" },
123};
28796eaf 124
570f6fe1 125static int e740_probe(struct platform_device *pdev)
28796eaf 126{
62133829 127 struct snd_soc_card *card = &e740;
28796eaf
IM
128 int ret;
129
62133829
AL
130 ret = gpio_request_array(e740_audio_gpios,
131 ARRAY_SIZE(e740_audio_gpios));
28796eaf
IM
132 if (ret)
133 return ret;
134
62133829 135 card->dev = &pdev->dev;
28796eaf 136
2fd7076a 137 ret = devm_snd_soc_register_card(&pdev->dev, card);
62133829
AL
138 if (ret) {
139 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
140 ret);
141 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
28796eaf 142 }
28796eaf
IM
143 return ret;
144}
145
570f6fe1 146static int e740_remove(struct platform_device *pdev)
28796eaf 147{
62133829 148 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
62133829 149 return 0;
28796eaf
IM
150}
151
62133829
AL
152static struct platform_driver e740_driver = {
153 .driver = {
154 .name = "e740-audio",
7db1698f 155 .pm = &snd_soc_pm_ops,
62133829
AL
156 },
157 .probe = e740_probe,
570f6fe1 158 .remove = e740_remove,
62133829
AL
159};
160
161module_platform_driver(e740_driver);
28796eaf
IM
162
163/* Module information */
164MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
165MODULE_DESCRIPTION("ALSA SoC driver for e740");
166MODULE_LICENSE("GPL v2");
62133829 167MODULE_ALIAS("platform:e740-audio");