Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / sound / soc / pxa / e800_wm9712.c
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.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 <mach/audio.h>
18 #include <mach/eseries-gpio.h>
19
20 static int e800_spk_amp_event(struct snd_soc_dapm_widget *w,
21                                 struct snd_kcontrol *kcontrol, int event)
22 {
23         if (event & SND_SOC_DAPM_PRE_PMU)
24                 gpio_set_value(GPIO_E800_SPK_AMP_ON, 1);
25         else if (event & SND_SOC_DAPM_POST_PMD)
26                 gpio_set_value(GPIO_E800_SPK_AMP_ON, 0);
27
28         return 0;
29 }
30
31 static int e800_hp_amp_event(struct snd_soc_dapm_widget *w,
32                                 struct snd_kcontrol *kcontrol, int event)
33 {
34         if (event & SND_SOC_DAPM_PRE_PMU)
35                 gpio_set_value(GPIO_E800_HP_AMP_OFF, 0);
36         else if (event & SND_SOC_DAPM_POST_PMD)
37                 gpio_set_value(GPIO_E800_HP_AMP_OFF, 1);
38
39         return 0;
40 }
41
42 static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
43         SND_SOC_DAPM_HP("Headphone Jack", NULL),
44         SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
45         SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
46         SND_SOC_DAPM_SPK("Speaker", NULL),
47         SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
48                         e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
49                         SND_SOC_DAPM_POST_PMD),
50         SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
51                         e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
52                         SND_SOC_DAPM_POST_PMD),
53 };
54
55 static const struct snd_soc_dapm_route audio_map[] = {
56         {"Headphone Jack", NULL, "HPOUTL"},
57         {"Headphone Jack", NULL, "HPOUTR"},
58         {"Headphone Jack", NULL, "Headphone Amp"},
59
60         {"Speaker Amp", NULL, "MONOOUT"},
61         {"Speaker", NULL, "Speaker Amp"},
62
63         {"MIC1", NULL, "Mic (Internal1)"},
64         {"MIC2", NULL, "Mic (Internal2)"},
65 };
66
67
68 SND_SOC_DAILINK_DEFS(ac97,
69         DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
70         DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
71         DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
72
73 SND_SOC_DAILINK_DEFS(ac97_aux,
74         DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
75         DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")),
76         DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
77
78 static struct snd_soc_dai_link e800_dai[] = {
79         {
80                 .name = "AC97",
81                 .stream_name = "AC97 HiFi",
82                 SND_SOC_DAILINK_REG(ac97),
83         },
84         {
85                 .name = "AC97 Aux",
86                 .stream_name = "AC97 Aux",
87                 SND_SOC_DAILINK_REG(ac97_aux),
88         },
89 };
90
91 static struct snd_soc_card e800 = {
92         .name = "Toshiba e800",
93         .owner = THIS_MODULE,
94         .dai_link = e800_dai,
95         .num_links = ARRAY_SIZE(e800_dai),
96
97         .dapm_widgets = e800_dapm_widgets,
98         .num_dapm_widgets = ARRAY_SIZE(e800_dapm_widgets),
99         .dapm_routes = audio_map,
100         .num_dapm_routes = ARRAY_SIZE(audio_map),
101 };
102
103 static struct gpio e800_audio_gpios[] = {
104         { GPIO_E800_SPK_AMP_ON, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
105         { GPIO_E800_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
106 };
107
108 static int e800_probe(struct platform_device *pdev)
109 {
110         struct snd_soc_card *card = &e800;
111         int ret;
112
113         ret = gpio_request_array(e800_audio_gpios,
114                                  ARRAY_SIZE(e800_audio_gpios));
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                 gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
125         }
126         return ret;
127 }
128
129 static int e800_remove(struct platform_device *pdev)
130 {
131         gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
132         return 0;
133 }
134
135 static struct platform_driver e800_driver = {
136         .driver         = {
137                 .name   = "e800-audio",
138                 .pm     = &snd_soc_pm_ops,
139         },
140         .probe          = e800_probe,
141         .remove         = e800_remove,
142 };
143
144 module_platform_driver(e800_driver);
145
146 /* Module information */
147 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
148 MODULE_DESCRIPTION("ALSA SoC driver for e800");
149 MODULE_LICENSE("GPL v2");
150 MODULE_ALIAS("platform:e800-audio");