pcmcia: remove unused pxa/sa1100 drivers
[sfrench/cifs-2.6.git] / sound / soc / pxa / e750_wm9705.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * e750-wm9705.c  --  SoC audio for e750
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 <linux/platform_data/asoc-pxa.h>
17
18 #include <asm/mach-types.h>
19
20 static struct gpio_desc *gpiod_spk_amp, *gpiod_hp_amp;
21
22 static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
23                                 struct snd_kcontrol *kcontrol, int event)
24 {
25         if (event & SND_SOC_DAPM_PRE_PMU)
26                 gpiod_set_value(gpiod_spk_amp, 1);
27         else if (event & SND_SOC_DAPM_POST_PMD)
28                 gpiod_set_value(gpiod_spk_amp, 0);
29
30         return 0;
31 }
32
33 static int e750_hp_amp_event(struct snd_soc_dapm_widget *w,
34                                 struct snd_kcontrol *kcontrol, int event)
35 {
36         if (event & SND_SOC_DAPM_PRE_PMU)
37                 gpiod_set_value(gpiod_hp_amp, 1);
38         else if (event & SND_SOC_DAPM_POST_PMD)
39                 gpiod_set_value(gpiod_hp_amp, 0);
40
41         return 0;
42 }
43
44 static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
45         SND_SOC_DAPM_HP("Headphone Jack", NULL),
46         SND_SOC_DAPM_SPK("Speaker", NULL),
47         SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
48         SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
49                         e750_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                         e750_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 Amp", NULL, "HPOUTL"},
58         {"Headphone Amp", NULL, "HPOUTR"},
59         {"Headphone Jack", NULL, "Headphone Amp"},
60
61         {"Speaker Amp", NULL, "MONOOUT"},
62         {"Speaker", NULL, "Speaker Amp"},
63
64         {"MIC1", NULL, "Mic (Internal)"},
65 };
66
67 SND_SOC_DAILINK_DEFS(ac97,
68         DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
69         DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-hifi")),
70         DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
71
72 SND_SOC_DAILINK_DEFS(ac97_aux,
73         DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
74         DAILINK_COMP_ARRAY(COMP_CODEC("wm9705-codec", "wm9705-aux")),
75         DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
76
77 static struct snd_soc_dai_link e750_dai[] = {
78         {
79                 .name = "AC97",
80                 .stream_name = "AC97 HiFi",
81                 SND_SOC_DAILINK_REG(ac97),
82                 /* use ops to check startup state */
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 e750 = {
92         .name = "Toshiba e750",
93         .owner = THIS_MODULE,
94         .dai_link = e750_dai,
95         .num_links = ARRAY_SIZE(e750_dai),
96
97         .dapm_widgets = e750_dapm_widgets,
98         .num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets),
99         .dapm_routes = audio_map,
100         .num_dapm_routes = ARRAY_SIZE(audio_map),
101         .fully_routed = true,
102 };
103
104 static int e750_probe(struct platform_device *pdev)
105 {
106         struct snd_soc_card *card = &e750;
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
127 static int e750_remove(struct platform_device *pdev)
128 {
129         return 0;
130 }
131
132 static struct platform_driver e750_driver = {
133         .driver         = {
134                 .name   = "e750-audio",
135                 .pm     = &snd_soc_pm_ops,
136         },
137         .probe          = e750_probe,
138         .remove         = e750_remove,
139 };
140
141 module_platform_driver(e750_driver);
142
143 /* Module information */
144 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
145 MODULE_DESCRIPTION("ALSA SoC driver for e750");
146 MODULE_LICENSE("GPL v2");
147 MODULE_ALIAS("platform:e750-audio");