blob: 2bc97e92446bdc0affab447bc0ee7d0d35a75f27 [file] [log] [blame]
Ian Moltona7e2e732009-01-08 21:03:55 +00001/*
2 * e750-wm9705.c -- SoC audio for e750
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>
19#include <sound/soc-dapm.h>
20
Ian Moltona7e2e732009-01-08 21:03:55 +000021#include <mach/audio.h>
22#include <mach/eseries-gpio.h>
23
24#include <asm/mach-types.h>
25
26#include "../codecs/wm9705.h"
Ian Moltona7e2e732009-01-08 21:03:55 +000027#include "pxa2xx-ac97.h"
28
29static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
30 struct snd_kcontrol *kcontrol, int event)
31{
32 if (event & SND_SOC_DAPM_PRE_PMU)
33 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
34 else if (event & SND_SOC_DAPM_POST_PMD)
35 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
36
37 return 0;
38}
39
40static int e750_hp_amp_event(struct snd_soc_dapm_widget *w,
41 struct snd_kcontrol *kcontrol, int event)
42{
43 if (event & SND_SOC_DAPM_PRE_PMU)
44 gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
45 else if (event & SND_SOC_DAPM_POST_PMD)
46 gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
47
48 return 0;
49}
50
51static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
52 SND_SOC_DAPM_HP("Headphone Jack", NULL),
53 SND_SOC_DAPM_SPK("Speaker", NULL),
54 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
55 SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
56 e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
57 SND_SOC_DAPM_POST_PMD),
58 SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
59 e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
60 SND_SOC_DAPM_POST_PMD),
61};
62
63static const struct snd_soc_dapm_route audio_map[] = {
64 {"Headphone Amp", NULL, "HPOUTL"},
65 {"Headphone Amp", NULL, "HPOUTR"},
66 {"Headphone Jack", NULL, "Headphone Amp"},
67
68 {"Speaker Amp", NULL, "MONOOUT"},
69 {"Speaker", NULL, "Speaker Amp"},
70
71 {"MIC1", NULL, "Mic (Internal)"},
72};
73
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000074static int e750_ac97_init(struct snd_soc_pcm_runtime *rtd)
Ian Moltona7e2e732009-01-08 21:03:55 +000075{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000076 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020077 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000078
Liam Girdwoodce6120c2010-11-05 15:53:46 +020079 snd_soc_dapm_nc_pin(dapm, "LOUT");
80 snd_soc_dapm_nc_pin(dapm, "ROUT");
81 snd_soc_dapm_nc_pin(dapm, "PHONE");
82 snd_soc_dapm_nc_pin(dapm, "LINEINL");
83 snd_soc_dapm_nc_pin(dapm, "LINEINR");
84 snd_soc_dapm_nc_pin(dapm, "CDINL");
85 snd_soc_dapm_nc_pin(dapm, "CDINR");
86 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
87 snd_soc_dapm_nc_pin(dapm, "MIC2");
Ian Moltona7e2e732009-01-08 21:03:55 +000088
Liam Girdwoodce6120c2010-11-05 15:53:46 +020089 snd_soc_dapm_new_controls(dapm, e750_dapm_widgets,
Ian Moltona7e2e732009-01-08 21:03:55 +000090 ARRAY_SIZE(e750_dapm_widgets));
91
Liam Girdwoodce6120c2010-11-05 15:53:46 +020092 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Ian Moltona7e2e732009-01-08 21:03:55 +000093
Liam Girdwoodce6120c2010-11-05 15:53:46 +020094 snd_soc_dapm_sync(dapm);
Ian Moltona7e2e732009-01-08 21:03:55 +000095
96 return 0;
97}
98
99static struct snd_soc_dai_link e750_dai[] = {
100 {
101 .name = "AC97",
102 .stream_name = "AC97 HiFi",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000103 .cpu_dai_name = "pxa-ac97.0",
104 .codec_dai_name = "wm9705-hifi",
105 .platform_name = "pxa-pcm-audio",
106 .codec_name = "wm9705-codec",
Ian Moltona7e2e732009-01-08 21:03:55 +0000107 .init = e750_ac97_init,
108 /* use ops to check startup state */
109 },
110 {
111 .name = "AC97 Aux",
112 .stream_name = "AC97 Aux",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000113 .cpu_dai_name = "pxa-ac97.1",
114 .codec_dai_name ="wm9705-aux",
115 .platform_name = "pxa-pcm-audio",
116 .codec_name = "wm9705-codec",
Ian Moltona7e2e732009-01-08 21:03:55 +0000117 },
118};
119
120static struct snd_soc_card e750 = {
121 .name = "Toshiba e750",
Ian Moltona7e2e732009-01-08 21:03:55 +0000122 .dai_link = e750_dai,
123 .num_links = ARRAY_SIZE(e750_dai),
124};
125
Ian Moltona7e2e732009-01-08 21:03:55 +0000126static struct platform_device *e750_snd_device;
127
128static int __init e750_init(void)
129{
130 int ret;
131
132 if (!machine_is_e750())
133 return -ENODEV;
134
135 ret = gpio_request(GPIO_E750_HP_AMP_OFF, "Headphone amp");
136 if (ret)
137 return ret;
138
139 ret = gpio_request(GPIO_E750_SPK_AMP_OFF, "Speaker amp");
140 if (ret)
141 goto free_hp_amp_gpio;
142
143 ret = gpio_direction_output(GPIO_E750_HP_AMP_OFF, 1);
144 if (ret)
145 goto free_spk_amp_gpio;
146
147 ret = gpio_direction_output(GPIO_E750_SPK_AMP_OFF, 1);
148 if (ret)
149 goto free_spk_amp_gpio;
150
151 e750_snd_device = platform_device_alloc("soc-audio", -1);
152 if (!e750_snd_device) {
153 ret = -ENOMEM;
154 goto free_spk_amp_gpio;
155 }
156
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000157 platform_set_drvdata(e750_snd_device, &e750);
Ian Moltona7e2e732009-01-08 21:03:55 +0000158 ret = platform_device_add(e750_snd_device);
159
160 if (!ret)
161 return 0;
162
163/* Fail gracefully */
164 platform_device_put(e750_snd_device);
165free_spk_amp_gpio:
166 gpio_free(GPIO_E750_SPK_AMP_OFF);
167free_hp_amp_gpio:
168 gpio_free(GPIO_E750_HP_AMP_OFF);
169
170 return ret;
171}
172
173static void __exit e750_exit(void)
174{
175 platform_device_unregister(e750_snd_device);
176 gpio_free(GPIO_E750_SPK_AMP_OFF);
177 gpio_free(GPIO_E750_HP_AMP_OFF);
178}
179
180module_init(e750_init);
181module_exit(e750_exit);
182
183/* Module information */
184MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
185MODULE_DESCRIPTION("ALSA SoC driver for e750");
186MODULE_LICENSE("GPL v2");