blob: 78a1770b986c466602592a05c18e00a0bd98228a [file] [log] [blame]
Ian Moltonab40d4f2008-01-10 14:50:34 +01001/*
2 * e800-wm9712.c -- SoC audio for e800
3 *
Ian Moltonab40d4f2008-01-10 14:50:34 +01004 * 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>
Ian Molton0465c7a2009-01-08 21:16:05 +000014#include <linux/gpio.h>
Ian Moltonab40d4f2008-01-10 14:50:34 +010015
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/pxa-regs.h>
22#include <mach/hardware.h>
23#include <mach/audio.h>
Ian Molton0465c7a2009-01-08 21:16:05 +000024#include <mach/eseries-gpio.h>
25
26#include <asm/mach-types.h>
Ian Moltonab40d4f2008-01-10 14:50:34 +010027
28#include "../codecs/wm9712.h"
29#include "pxa2xx-pcm.h"
30#include "pxa2xx-ac97.h"
31
Ian Molton0465c7a2009-01-08 21:16:05 +000032static int e800_spk_amp_event(struct snd_soc_dapm_widget *w,
33 struct snd_kcontrol *kcontrol, int event)
34{
35 if (event & SND_SOC_DAPM_PRE_PMU)
36 gpio_set_value(GPIO_E800_SPK_AMP_ON, 1);
37 else if (event & SND_SOC_DAPM_POST_PMD)
38 gpio_set_value(GPIO_E800_SPK_AMP_ON, 0);
39
40 return 0;
41}
42
43static int e800_hp_amp_event(struct snd_soc_dapm_widget *w,
44 struct snd_kcontrol *kcontrol, int event)
45{
46 if (event & SND_SOC_DAPM_PRE_PMU)
47 gpio_set_value(GPIO_E800_HP_AMP_OFF, 0);
48 else if (event & SND_SOC_DAPM_POST_PMD)
49 gpio_set_value(GPIO_E800_HP_AMP_OFF, 1);
50
51 return 0;
52}
53
54static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
55 SND_SOC_DAPM_HP("Headphone Jack", NULL),
56 SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
57 SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
58 SND_SOC_DAPM_SPK("Speaker", NULL),
59 SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
60 e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
61 SND_SOC_DAPM_POST_PMD),
62 SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
63 e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
64 SND_SOC_DAPM_POST_PMD),
65};
66
67static const struct snd_soc_dapm_route audio_map[] = {
68 {"Headphone Jack", NULL, "HPOUTL"},
69 {"Headphone Jack", NULL, "HPOUTR"},
70 {"Headphone Jack", NULL, "Headphone Amp"},
71
72 {"Speaker Amp", NULL, "MONOOUT"},
73 {"Speaker", NULL, "Speaker Amp"},
74
75 {"MIC1", NULL, "Mic (Internal1)"},
76 {"MIC2", NULL, "Mic (Internal2)"},
77};
78
79static int e800_ac97_init(struct snd_soc_codec *codec)
80{
81 snd_soc_dapm_new_controls(codec, e800_dapm_widgets,
82 ARRAY_SIZE(e800_dapm_widgets));
83
84 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
85 snd_soc_dapm_sync(codec);
86
87 return 0;
88}
Ian Moltonab40d4f2008-01-10 14:50:34 +010089
90static struct snd_soc_dai_link e800_dai[] = {
Ian Molton0465c7a2009-01-08 21:16:05 +000091 {
92 .name = "AC97",
93 .stream_name = "AC97 HiFi",
94 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
95 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI],
96 .init = e800_ac97_init,
97 },
98 {
99 .name = "AC97 Aux",
100 .stream_name = "AC97 Aux",
101 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
102 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX],
103 },
Ian Moltonab40d4f2008-01-10 14:50:34 +0100104};
105
Mark Brown87506542008-11-18 20:50:34 +0000106static struct snd_soc_card e800 = {
Ian Moltonab40d4f2008-01-10 14:50:34 +0100107 .name = "Toshiba e800",
Mark Brown87689d52008-12-02 16:01:14 +0000108 .platform = &pxa2xx_soc_platform,
Ian Moltonab40d4f2008-01-10 14:50:34 +0100109 .dai_link = e800_dai,
110 .num_links = ARRAY_SIZE(e800_dai),
111};
112
113static struct snd_soc_device e800_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000114 .card = &e800,
Ian Moltonab40d4f2008-01-10 14:50:34 +0100115 .codec_dev = &soc_codec_dev_wm9712,
116};
117
118static struct platform_device *e800_snd_device;
119
120static int __init e800_init(void)
121{
122 int ret;
123
124 if (!machine_is_e800())
125 return -ENODEV;
126
Ian Molton0465c7a2009-01-08 21:16:05 +0000127 ret = gpio_request(GPIO_E800_HP_AMP_OFF, "Headphone amp");
128 if (ret)
129 return ret;
130
131 ret = gpio_request(GPIO_E800_SPK_AMP_ON, "Speaker amp");
132 if (ret)
133 goto free_hp_amp_gpio;
134
135 ret = gpio_direction_output(GPIO_E800_HP_AMP_OFF, 1);
136 if (ret)
137 goto free_spk_amp_gpio;
138
139 ret = gpio_direction_output(GPIO_E800_SPK_AMP_ON, 1);
140 if (ret)
141 goto free_spk_amp_gpio;
142
Ian Moltonab40d4f2008-01-10 14:50:34 +0100143 e800_snd_device = platform_device_alloc("soc-audio", -1);
144 if (!e800_snd_device)
145 return -ENOMEM;
146
147 platform_set_drvdata(e800_snd_device, &e800_snd_devdata);
148 e800_snd_devdata.dev = &e800_snd_device->dev;
149 ret = platform_device_add(e800_snd_device);
150
Ian Molton0465c7a2009-01-08 21:16:05 +0000151 if (!ret)
152 return 0;
153
154/* Fail gracefully */
155 platform_device_put(e800_snd_device);
156free_spk_amp_gpio:
157 gpio_free(GPIO_E800_SPK_AMP_ON);
158free_hp_amp_gpio:
159 gpio_free(GPIO_E800_HP_AMP_OFF);
Ian Moltonab40d4f2008-01-10 14:50:34 +0100160
161 return ret;
162}
163
164static void __exit e800_exit(void)
165{
166 platform_device_unregister(e800_snd_device);
Ian Molton0465c7a2009-01-08 21:16:05 +0000167 gpio_free(GPIO_E800_SPK_AMP_ON);
168 gpio_free(GPIO_E800_HP_AMP_OFF);
Ian Moltonab40d4f2008-01-10 14:50:34 +0100169}
170
171module_init(e800_init);
172module_exit(e800_exit);
173
174/* Module information */
175MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
176MODULE_DESCRIPTION("ALSA SoC driver for e800");
Ian Molton0465c7a2009-01-08 21:16:05 +0000177MODULE_LICENSE("GPL v2");