sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / soc / pxa / e740_wm9705.c
blob086c37a856308748b734ad8c4ac5ab8b53ac8b04
1 /*
2 * e740-wm9705.c -- SoC audio for e740
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>
20 #include <mach/audio.h>
21 #include <mach/eseries-gpio.h>
23 #include <asm/mach-types.h>
25 #include "pxa2xx-ac97.h"
28 #define E740_AUDIO_OUT 1
29 #define E740_AUDIO_IN 2
31 static int e740_audio_power;
33 static void e740_sync_audio_power(int status)
35 gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
36 gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
37 gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
40 static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
41 struct snd_kcontrol *kcontrol, int event)
43 if (event & SND_SOC_DAPM_PRE_PMU)
44 e740_audio_power |= E740_AUDIO_IN;
45 else if (event & SND_SOC_DAPM_POST_PMD)
46 e740_audio_power &= ~E740_AUDIO_IN;
48 e740_sync_audio_power(e740_audio_power);
50 return 0;
53 static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
54 struct snd_kcontrol *kcontrol, int event)
56 if (event & SND_SOC_DAPM_PRE_PMU)
57 e740_audio_power |= E740_AUDIO_OUT;
58 else if (event & SND_SOC_DAPM_POST_PMD)
59 e740_audio_power &= ~E740_AUDIO_OUT;
61 e740_sync_audio_power(e740_audio_power);
63 return 0;
66 static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
67 SND_SOC_DAPM_HP("Headphone Jack", NULL),
68 SND_SOC_DAPM_SPK("Speaker", NULL),
69 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
70 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
71 e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
72 SND_SOC_DAPM_POST_PMD),
73 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
74 e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
75 SND_SOC_DAPM_POST_PMD),
78 static const struct snd_soc_dapm_route audio_map[] = {
79 {"Output Amp", NULL, "LOUT"},
80 {"Output Amp", NULL, "ROUT"},
81 {"Output Amp", NULL, "MONOOUT"},
83 {"Speaker", NULL, "Output Amp"},
84 {"Headphone Jack", NULL, "Output Amp"},
86 {"MIC1", NULL, "Mic Amp"},
87 {"Mic Amp", NULL, "Mic (Internal)"},
90 static struct snd_soc_dai_link e740_dai[] = {
92 .name = "AC97",
93 .stream_name = "AC97 HiFi",
94 .cpu_dai_name = "pxa2xx-ac97",
95 .codec_dai_name = "wm9705-hifi",
96 .platform_name = "pxa-pcm-audio",
97 .codec_name = "wm9705-codec",
100 .name = "AC97 Aux",
101 .stream_name = "AC97 Aux",
102 .cpu_dai_name = "pxa2xx-ac97-aux",
103 .codec_dai_name = "wm9705-aux",
104 .platform_name = "pxa-pcm-audio",
105 .codec_name = "wm9705-codec",
109 static struct snd_soc_card e740 = {
110 .name = "Toshiba e740",
111 .owner = THIS_MODULE,
112 .dai_link = e740_dai,
113 .num_links = ARRAY_SIZE(e740_dai),
115 .dapm_widgets = e740_dapm_widgets,
116 .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
117 .dapm_routes = audio_map,
118 .num_dapm_routes = ARRAY_SIZE(audio_map),
119 .fully_routed = true,
122 static struct gpio e740_audio_gpios[] = {
123 { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" },
124 { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" },
125 { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" },
128 static int e740_probe(struct platform_device *pdev)
130 struct snd_soc_card *card = &e740;
131 int ret;
133 ret = gpio_request_array(e740_audio_gpios,
134 ARRAY_SIZE(e740_audio_gpios));
135 if (ret)
136 return ret;
138 card->dev = &pdev->dev;
140 ret = devm_snd_soc_register_card(&pdev->dev, card);
141 if (ret) {
142 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
143 ret);
144 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
146 return ret;
149 static int e740_remove(struct platform_device *pdev)
151 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
152 return 0;
155 static struct platform_driver e740_driver = {
156 .driver = {
157 .name = "e740-audio",
158 .pm = &snd_soc_pm_ops,
160 .probe = e740_probe,
161 .remove = e740_remove,
164 module_platform_driver(e740_driver);
166 /* Module information */
167 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
168 MODULE_DESCRIPTION("ALSA SoC driver for e740");
169 MODULE_LICENSE("GPL v2");
170 MODULE_ALIAS("platform:e740-audio");