]> asedeno.scripts.mit.edu Git - linux.git/blob - sound/soc/pxa/e750_wm9705.c
Merge branch 'next' into for-linus
[linux.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.h>
11
12 #include <sound/core.h>
13 #include <sound/pcm.h>
14 #include <sound/soc.h>
15
16 #include <mach/audio.h>
17 #include <mach/eseries-gpio.h>
18
19 #include <asm/mach-types.h>
20
21 static int e750_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                 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
26         else if (event & SND_SOC_DAPM_POST_PMD)
27                 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
28
29         return 0;
30 }
31
32 static int e750_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                 gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
37         else if (event & SND_SOC_DAPM_POST_PMD)
38                 gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
39
40         return 0;
41 }
42
43 static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
44         SND_SOC_DAPM_HP("Headphone Jack", NULL),
45         SND_SOC_DAPM_SPK("Speaker", NULL),
46         SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
47         SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
48                         e750_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                         e750_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 Amp", NULL, "HPOUTL"},
57         {"Headphone Amp", NULL, "HPOUTR"},
58         {"Headphone Jack", NULL, "Headphone Amp"},
59
60         {"Speaker Amp", NULL, "MONOOUT"},
61         {"Speaker", NULL, "Speaker Amp"},
62
63         {"MIC1", NULL, "Mic (Internal)"},
64 };
65
66 static struct snd_soc_dai_link e750_dai[] = {
67         {
68                 .name = "AC97",
69                 .stream_name = "AC97 HiFi",
70                 .cpu_dai_name = "pxa2xx-ac97",
71                 .codec_dai_name = "wm9705-hifi",
72                 .platform_name = "pxa-pcm-audio",
73                 .codec_name = "wm9705-codec",
74                 /* use ops to check startup state */
75         },
76         {
77                 .name = "AC97 Aux",
78                 .stream_name = "AC97 Aux",
79                 .cpu_dai_name = "pxa2xx-ac97-aux",
80                 .codec_dai_name = "wm9705-aux",
81                 .platform_name = "pxa-pcm-audio",
82                 .codec_name = "wm9705-codec",
83         },
84 };
85
86 static struct snd_soc_card e750 = {
87         .name = "Toshiba e750",
88         .owner = THIS_MODULE,
89         .dai_link = e750_dai,
90         .num_links = ARRAY_SIZE(e750_dai),
91
92         .dapm_widgets = e750_dapm_widgets,
93         .num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets),
94         .dapm_routes = audio_map,
95         .num_dapm_routes = ARRAY_SIZE(audio_map),
96         .fully_routed = true,
97 };
98
99 static struct gpio e750_audio_gpios[] = {
100         { GPIO_E750_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
101         { GPIO_E750_SPK_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
102 };
103
104 static int e750_probe(struct platform_device *pdev)
105 {
106         struct snd_soc_card *card = &e750;
107         int ret;
108
109         ret = gpio_request_array(e750_audio_gpios,
110                                  ARRAY_SIZE(e750_audio_gpios));
111         if (ret)
112                 return ret;
113
114         card->dev = &pdev->dev;
115
116         ret = devm_snd_soc_register_card(&pdev->dev, card);
117         if (ret) {
118                 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
119                         ret);
120                 gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
121         }
122         return ret;
123 }
124
125 static int e750_remove(struct platform_device *pdev)
126 {
127         gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
128         return 0;
129 }
130
131 static struct platform_driver e750_driver = {
132         .driver         = {
133                 .name   = "e750-audio",
134                 .pm     = &snd_soc_pm_ops,
135         },
136         .probe          = e750_probe,
137         .remove         = e750_remove,
138 };
139
140 module_platform_driver(e750_driver);
141
142 /* Module information */
143 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
144 MODULE_DESCRIPTION("ALSA SoC driver for e750");
145 MODULE_LICENSE("GPL v2");
146 MODULE_ALIAS("platform:e750-audio");