2 * e750-wm9705.c -- SoC audio for e750
4 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
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.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/gpio.h>
16 #include <sound/core.h>
17 #include <sound/pcm.h>
18 #include <sound/soc.h>
19 #include <sound/soc-dapm.h>
21 #include <mach/pxa-regs.h>
22 #include <mach/hardware.h>
23 #include <mach/audio.h>
24 #include <mach/eseries-gpio.h>
26 #include <asm/mach-types.h>
28 #include "../codecs/wm9705.h"
29 #include "pxa2xx-pcm.h"
30 #include "pxa2xx-ac97.h"
32 static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
33 struct snd_kcontrol *kcontrol, int event)
35 if (event & SND_SOC_DAPM_PRE_PMU)
36 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
37 else if (event & SND_SOC_DAPM_POST_PMD)
38 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
43 static int e750_hp_amp_event(struct snd_soc_dapm_widget *w,
44 struct snd_kcontrol *kcontrol, int event)
46 if (event & SND_SOC_DAPM_PRE_PMU)
47 gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
48 else if (event & SND_SOC_DAPM_POST_PMD)
49 gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
54 static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
55 SND_SOC_DAPM_HP("Headphone Jack", NULL),
56 SND_SOC_DAPM_SPK("Speaker", NULL),
57 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
58 SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
59 e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
60 SND_SOC_DAPM_POST_PMD),
61 SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
62 e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
63 SND_SOC_DAPM_POST_PMD),
66 static const struct snd_soc_dapm_route audio_map[] = {
67 {"Headphone Amp", NULL, "HPOUTL"},
68 {"Headphone Amp", NULL, "HPOUTR"},
69 {"Headphone Jack", NULL, "Headphone Amp"},
71 {"Speaker Amp", NULL, "MONOOUT"},
72 {"Speaker", NULL, "Speaker Amp"},
74 {"MIC1", NULL, "Mic (Internal)"},
77 static int e750_ac97_init(struct snd_soc_codec *codec)
79 snd_soc_dapm_nc_pin(codec, "LOUT");
80 snd_soc_dapm_nc_pin(codec, "ROUT");
81 snd_soc_dapm_nc_pin(codec, "PHONE");
82 snd_soc_dapm_nc_pin(codec, "LINEINL");
83 snd_soc_dapm_nc_pin(codec, "LINEINR");
84 snd_soc_dapm_nc_pin(codec, "CDINL");
85 snd_soc_dapm_nc_pin(codec, "CDINR");
86 snd_soc_dapm_nc_pin(codec, "PCBEEP");
87 snd_soc_dapm_nc_pin(codec, "MIC2");
89 snd_soc_dapm_new_controls(codec, e750_dapm_widgets,
90 ARRAY_SIZE(e750_dapm_widgets));
92 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
94 snd_soc_dapm_sync(codec);
99 static struct snd_soc_dai_link e750_dai[] = {
102 .stream_name = "AC97 HiFi",
103 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
104 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_HIFI],
105 .init = e750_ac97_init,
106 /* use ops to check startup state */
110 .stream_name = "AC97 Aux",
111 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
112 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_AUX],
116 static struct snd_soc_card e750 = {
117 .name = "Toshiba e750",
118 .platform = &pxa2xx_soc_platform,
119 .dai_link = e750_dai,
120 .num_links = ARRAY_SIZE(e750_dai),
123 static struct snd_soc_device e750_snd_devdata = {
125 .codec_dev = &soc_codec_dev_wm9705,
128 static struct platform_device *e750_snd_device;
130 static int __init e750_init(void)
134 if (!machine_is_e750())
137 ret = gpio_request(GPIO_E750_HP_AMP_OFF, "Headphone amp");
141 ret = gpio_request(GPIO_E750_SPK_AMP_OFF, "Speaker amp");
143 goto free_hp_amp_gpio;
145 ret = gpio_direction_output(GPIO_E750_HP_AMP_OFF, 1);
147 goto free_spk_amp_gpio;
149 ret = gpio_direction_output(GPIO_E750_SPK_AMP_OFF, 1);
151 goto free_spk_amp_gpio;
153 e750_snd_device = platform_device_alloc("soc-audio", -1);
154 if (!e750_snd_device) {
156 goto free_spk_amp_gpio;
159 platform_set_drvdata(e750_snd_device, &e750_snd_devdata);
160 e750_snd_devdata.dev = &e750_snd_device->dev;
161 ret = platform_device_add(e750_snd_device);
166 /* Fail gracefully */
167 platform_device_put(e750_snd_device);
169 gpio_free(GPIO_E750_SPK_AMP_OFF);
171 gpio_free(GPIO_E750_HP_AMP_OFF);
176 static void __exit e750_exit(void)
178 platform_device_unregister(e750_snd_device);
179 gpio_free(GPIO_E750_SPK_AMP_OFF);
180 gpio_free(GPIO_E750_HP_AMP_OFF);
183 module_init(e750_init);
184 module_exit(e750_exit);
186 /* Module information */
187 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
188 MODULE_DESCRIPTION("ALSA SoC driver for e750");
189 MODULE_LICENSE("GPL v2");