1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * e800-wm9712.c -- SoC audio for e800
4 *
5 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
6 */
7
8 #include <linux/module.h>
9 #include <linux/moduleparam.h>
10 #include <linux/gpio/consumer.h>
11
12 #include <sound/core.h>
13 #include <sound/pcm.h>
14 #include <sound/soc.h>
15
16 #include <asm/mach-types.h>
17 #include <linux/platform_data/asoc-pxa.h>
18
19 static struct gpio_desc *gpiod_spk_amp, *gpiod_hp_amp;
20
e800_spk_amp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)21 static int e800_spk_amp_event(struct snd_soc_dapm_widget *w,
22 struct snd_kcontrol *kcontrol, int event)
23 {
24 if (event & SND_SOC_DAPM_PRE_PMU)
25 gpiod_set_value(gpiod_spk_amp, 1);
26 else if (event & SND_SOC_DAPM_POST_PMD)
27 gpiod_set_value(gpiod_spk_amp, 0);
28
29 return 0;
30 }
31
e800_hp_amp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)32 static int e800_hp_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 gpiod_set_value(gpiod_hp_amp, 1);
37 else if (event & SND_SOC_DAPM_POST_PMD)
38 gpiod_set_value(gpiod_hp_amp, 0);
39
40 return 0;
41 }
42
43 static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
44 SND_SOC_DAPM_HP("Headphone Jack", NULL),
45 SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
46 SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
47 SND_SOC_DAPM_SPK("Speaker", NULL),
48 SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
49 e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
50 SND_SOC_DAPM_POST_PMD),
51 SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
52 e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
53 SND_SOC_DAPM_POST_PMD),
54 };
55
56 static const struct snd_soc_dapm_route audio_map[] = {
57 {"Headphone Jack", NULL, "HPOUTL"},
58 {"Headphone Jack", NULL, "HPOUTR"},
59 {"Headphone Jack", NULL, "Headphone Amp"},
60
61 {"Speaker Amp", NULL, "MONOOUT"},
62 {"Speaker", NULL, "Speaker Amp"},
63
64 {"MIC1", NULL, "Mic (Internal1)"},
65 {"MIC2", NULL, "Mic (Internal2)"},
66 };
67
68
69 SND_SOC_DAILINK_DEFS(ac97,
70 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
71 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
72 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
73
74 SND_SOC_DAILINK_DEFS(ac97_aux,
75 DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
76 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")),
77 DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
78
79 static struct snd_soc_dai_link e800_dai[] = {
80 {
81 .name = "AC97",
82 .stream_name = "AC97 HiFi",
83 SND_SOC_DAILINK_REG(ac97),
84 },
85 {
86 .name = "AC97 Aux",
87 .stream_name = "AC97 Aux",
88 SND_SOC_DAILINK_REG(ac97_aux),
89 },
90 };
91
92 static struct snd_soc_card e800 = {
93 .name = "Toshiba e800",
94 .owner = THIS_MODULE,
95 .dai_link = e800_dai,
96 .num_links = ARRAY_SIZE(e800_dai),
97
98 .dapm_widgets = e800_dapm_widgets,
99 .num_dapm_widgets = ARRAY_SIZE(e800_dapm_widgets),
100 .dapm_routes = audio_map,
101 .num_dapm_routes = ARRAY_SIZE(audio_map),
102 };
103
e800_probe(struct platform_device * pdev)104 static int e800_probe(struct platform_device *pdev)
105 {
106 struct snd_soc_card *card = &e800;
107 int ret;
108
109 gpiod_hp_amp = devm_gpiod_get(&pdev->dev, "Headphone amp", GPIOD_OUT_LOW);
110 ret = PTR_ERR_OR_ZERO(gpiod_hp_amp);
111 if (ret)
112 return ret;
113 gpiod_spk_amp = devm_gpiod_get(&pdev->dev, "Speaker amp", GPIOD_OUT_LOW);
114 ret = PTR_ERR_OR_ZERO(gpiod_spk_amp);
115 if (ret)
116 return ret;
117
118 card->dev = &pdev->dev;
119
120 ret = devm_snd_soc_register_card(&pdev->dev, card);
121 if (ret)
122 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
123 ret);
124 return ret;
125 }
126
e800_remove(struct platform_device * pdev)127 static int e800_remove(struct platform_device *pdev)
128 {
129 return 0;
130 }
131
132 static struct platform_driver e800_driver = {
133 .driver = {
134 .name = "e800-audio",
135 .pm = &snd_soc_pm_ops,
136 },
137 .probe = e800_probe,
138 .remove = e800_remove,
139 };
140
141 module_platform_driver(e800_driver);
142
143 /* Module information */
144 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
145 MODULE_DESCRIPTION("ALSA SoC driver for e800");
146 MODULE_LICENSE("GPL v2");
147 MODULE_ALIAS("platform:e800-audio");
148