Commit | Line | Data |
---|---|---|
a10e763b | 1 | // SPDX-License-Identifier: GPL-2.0-only |
28796eaf IM |
2 | /* |
3 | * e740-wm9705.c -- SoC audio for e740 | |
4 | * | |
5 | * Copyright 2007 (c) Ian Molton <spyro@f2s.com> | |
28796eaf IM |
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> | |
28796eaf | 15 | |
28796eaf IM |
16 | #include <mach/audio.h> |
17 | #include <mach/eseries-gpio.h> | |
18 | ||
19 | #include <asm/mach-types.h> | |
20 | ||
28796eaf IM |
21 | #define E740_AUDIO_OUT 1 |
22 | #define E740_AUDIO_IN 2 | |
23 | ||
24 | static int e740_audio_power; | |
25 | ||
26 | static void e740_sync_audio_power(int status) | |
27 | { | |
28 | gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status); | |
29 | gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0); | |
30 | gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0); | |
31 | } | |
32 | ||
33 | static int e740_mic_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 | e740_audio_power |= E740_AUDIO_IN; | |
38 | else if (event & SND_SOC_DAPM_POST_PMD) | |
39 | e740_audio_power &= ~E740_AUDIO_IN; | |
40 | ||
41 | e740_sync_audio_power(e740_audio_power); | |
42 | ||
43 | return 0; | |
44 | } | |
45 | ||
46 | static int e740_output_amp_event(struct snd_soc_dapm_widget *w, | |
47 | struct snd_kcontrol *kcontrol, int event) | |
48 | { | |
49 | if (event & SND_SOC_DAPM_PRE_PMU) | |
50 | e740_audio_power |= E740_AUDIO_OUT; | |
51 | else if (event & SND_SOC_DAPM_POST_PMD) | |
52 | e740_audio_power &= ~E740_AUDIO_OUT; | |
53 | ||
54 | e740_sync_audio_power(e740_audio_power); | |
55 | ||
56 | return 0; | |
57 | } | |
58 | ||
59 | static const struct snd_soc_dapm_widget e740_dapm_widgets[] = { | |
60 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
61 | SND_SOC_DAPM_SPK("Speaker", NULL), | |
62 | SND_SOC_DAPM_MIC("Mic (Internal)", NULL), | |
63 | SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0, | |
64 | e740_output_amp_event, SND_SOC_DAPM_PRE_PMU | | |
65 | SND_SOC_DAPM_POST_PMD), | |
66 | SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0, | |
67 | e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU | | |
68 | SND_SOC_DAPM_POST_PMD), | |
69 | }; | |
70 | ||
71 | static const struct snd_soc_dapm_route audio_map[] = { | |
72 | {"Output Amp", NULL, "LOUT"}, | |
73 | {"Output Amp", NULL, "ROUT"}, | |
74 | {"Output Amp", NULL, "MONOOUT"}, | |
75 | ||
76 | {"Speaker", NULL, "Output Amp"}, | |
77 | {"Headphone Jack", NULL, "Output Amp"}, | |
78 | ||
79 | {"MIC1", NULL, "Mic Amp"}, | |
80 | {"Mic Amp", NULL, "Mic (Internal)"}, | |
81 | }; | |
82 | ||
28796eaf IM |
83 | static struct snd_soc_dai_link e740_dai[] = { |
84 | { | |
85 | .name = "AC97", | |
86 | .stream_name = "AC97 HiFi", | |
4bfc4e25 | 87 | .cpu_dai_name = "pxa2xx-ac97", |
f0fba2ad LG |
88 | .codec_dai_name = "wm9705-hifi", |
89 | .platform_name = "pxa-pcm-audio", | |
90 | .codec_name = "wm9705-codec", | |
28796eaf IM |
91 | }, |
92 | { | |
93 | .name = "AC97 Aux", | |
94 | .stream_name = "AC97 Aux", | |
4bfc4e25 | 95 | .cpu_dai_name = "pxa2xx-ac97-aux", |
f0fba2ad LG |
96 | .codec_dai_name = "wm9705-aux", |
97 | .platform_name = "pxa-pcm-audio", | |
98 | .codec_name = "wm9705-codec", | |
28796eaf IM |
99 | }, |
100 | }; | |
101 | ||
102 | static struct snd_soc_card e740 = { | |
103 | .name = "Toshiba e740", | |
561c6a17 | 104 | .owner = THIS_MODULE, |
28796eaf IM |
105 | .dai_link = e740_dai, |
106 | .num_links = ARRAY_SIZE(e740_dai), | |
23d8f225 LPC |
107 | |
108 | .dapm_widgets = e740_dapm_widgets, | |
109 | .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets), | |
110 | .dapm_routes = audio_map, | |
111 | .num_dapm_routes = ARRAY_SIZE(audio_map), | |
dff6c964 | 112 | .fully_routed = true, |
28796eaf IM |
113 | }; |
114 | ||
62133829 AL |
115 | static struct gpio e740_audio_gpios[] = { |
116 | { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" }, | |
117 | { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" }, | |
118 | { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" }, | |
119 | }; | |
28796eaf | 120 | |
570f6fe1 | 121 | static int e740_probe(struct platform_device *pdev) |
28796eaf | 122 | { |
62133829 | 123 | struct snd_soc_card *card = &e740; |
28796eaf IM |
124 | int ret; |
125 | ||
62133829 AL |
126 | ret = gpio_request_array(e740_audio_gpios, |
127 | ARRAY_SIZE(e740_audio_gpios)); | |
28796eaf IM |
128 | if (ret) |
129 | return ret; | |
130 | ||
62133829 | 131 | card->dev = &pdev->dev; |
28796eaf | 132 | |
2fd7076a | 133 | ret = devm_snd_soc_register_card(&pdev->dev, card); |
62133829 AL |
134 | if (ret) { |
135 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", | |
136 | ret); | |
137 | gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); | |
28796eaf | 138 | } |
28796eaf IM |
139 | return ret; |
140 | } | |
141 | ||
570f6fe1 | 142 | static int e740_remove(struct platform_device *pdev) |
28796eaf | 143 | { |
62133829 | 144 | gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); |
62133829 | 145 | return 0; |
28796eaf IM |
146 | } |
147 | ||
62133829 AL |
148 | static struct platform_driver e740_driver = { |
149 | .driver = { | |
150 | .name = "e740-audio", | |
7db1698f | 151 | .pm = &snd_soc_pm_ops, |
62133829 AL |
152 | }, |
153 | .probe = e740_probe, | |
570f6fe1 | 154 | .remove = e740_remove, |
62133829 AL |
155 | }; |
156 | ||
157 | module_platform_driver(e740_driver); | |
28796eaf IM |
158 | |
159 | /* Module information */ | |
160 | MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); | |
161 | MODULE_DESCRIPTION("ALSA SoC driver for e740"); | |
162 | MODULE_LICENSE("GPL v2"); | |
62133829 | 163 | MODULE_ALIAS("platform:e740-audio"); |