1 // SPDX-License-Identifier: GPL-2.0-only
3 * e740-wm9705.c -- SoC audio for e740
5 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
8 #include <linux/module.h>
9 #include <linux/moduleparam.h>
10 #include <linux/gpio/consumer.h>
12 #include <sound/core.h>
13 #include <sound/pcm.h>
14 #include <sound/soc.h>
16 #include <linux/platform_data/asoc-pxa.h>
18 #include <asm/mach-types.h>
20 static struct gpio_desc *gpiod_output_amp, *gpiod_input_amp;
21 static struct gpio_desc *gpiod_audio_power;
23 #define E740_AUDIO_OUT 1
24 #define E740_AUDIO_IN 2
26 static int e740_audio_power;
28 static void e740_sync_audio_power(int status)
30 gpiod_set_value(gpiod_audio_power, !status);
31 gpiod_set_value(gpiod_output_amp, (status & E740_AUDIO_OUT) ? 1 : 0);
32 gpiod_set_value(gpiod_input_amp, (status & E740_AUDIO_IN) ? 1 : 0);
35 static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
36 struct snd_kcontrol *kcontrol, int event)
38 if (event & SND_SOC_DAPM_PRE_PMU)
39 e740_audio_power |= E740_AUDIO_IN;
40 else if (event & SND_SOC_DAPM_POST_PMD)
41 e740_audio_power &= ~E740_AUDIO_IN;
43 e740_sync_audio_power(e740_audio_power);
48 static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
49 struct snd_kcontrol *kcontrol, int event)
51 if (event & SND_SOC_DAPM_PRE_PMU)
52 e740_audio_power |= E740_AUDIO_OUT;
53 else if (event & SND_SOC_DAPM_POST_PMD)
54 e740_audio_power &= ~E740_AUDIO_OUT;
56 e740_sync_audio_power(e740_audio_power);
61 static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
62 SND_SOC_DAPM_HP("Headphone Jack", NULL),
63 SND_SOC_DAPM_SPK("Speaker", NULL),
64 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
65 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
66 e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
67 SND_SOC_DAPM_POST_PMD),
68 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
69 e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
70 SND_SOC_DAPM_POST_PMD),
73 static const struct snd_soc_dapm_route audio_map[] = {
74 {"Output Amp", NULL, "LOUT"},
75 {"Output Amp", NULL, "ROUT"},
76 {"Output Amp", NULL, "MONOOUT"},
78 {"Speaker", NULL, "Output Amp"},
79 {"Headphone Jack", NULL, "Output Amp"},
81 {"MIC1", NULL, "Mic Amp"},
82 {"Mic Amp", NULL, "Mic (Internal)"},
85 SND_SOC_DAILINK_DEFS(ac97,
86 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
87 DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-hifi")),
88 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
90 SND_SOC_DAILINK_DEFS(ac97_aux,
91 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
92 DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-aux")),
93 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
95 static struct snd_soc_dai_link e740_dai[] = {
98 .stream_name = "AC97 HiFi",
99 SND_SOC_DAILINK_REG(ac97),
103 .stream_name = "AC97 Aux",
104 SND_SOC_DAILINK_REG(ac97_aux),
108 static struct snd_soc_card e740 = {
109 .name = "Toshiba e740",
110 .owner = THIS_MODULE,
111 .dai_link = e740_dai,
112 .num_links = ARRAY_SIZE(e740_dai),
114 .dapm_widgets = e740_dapm_widgets,
115 .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
116 .dapm_routes = audio_map,
117 .num_dapm_routes = ARRAY_SIZE(audio_map),
118 .fully_routed = true,
121 static int e740_probe(struct platform_device *pdev)
123 struct snd_soc_card *card = &e740;
126 gpiod_input_amp = devm_gpiod_get(&pdev->dev, "Mic amp", GPIOD_OUT_LOW);
127 ret = PTR_ERR_OR_ZERO(gpiod_input_amp);
130 gpiod_output_amp = devm_gpiod_get(&pdev->dev, "Output amp", GPIOD_OUT_LOW);
131 ret = PTR_ERR_OR_ZERO(gpiod_output_amp);
134 gpiod_audio_power = devm_gpiod_get(&pdev->dev, "Audio power", GPIOD_OUT_HIGH);
135 ret = PTR_ERR_OR_ZERO(gpiod_audio_power);
139 card->dev = &pdev->dev;
141 ret = devm_snd_soc_register_card(&pdev->dev, card);
143 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
148 static int e740_remove(struct platform_device *pdev)
153 static struct platform_driver e740_driver = {
155 .name = "e740-audio",
156 .pm = &snd_soc_pm_ops,
159 .remove = e740_remove,
162 module_platform_driver(e740_driver);
164 /* Module information */
165 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
166 MODULE_DESCRIPTION("ALSA SoC driver for e740");
167 MODULE_LICENSE("GPL v2");
168 MODULE_ALIAS("platform:e740-audio");