diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-08-23 12:40:01 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-11-09 11:51:01 -0500 |
commit | abda5dfdd56e548a7c569a40c404d8679c4f35f1 (patch) | |
tree | 76ffbdd5b07758eb0f157cee96e8d29825ce0b08 /sound/soc/samsung/lowland.c | |
parent | 588ac5e0b63da9cdef8b1b1d71dbcd95a8a94131 (diff) |
ASoC: Add Lowland machine driver
The Lowland platform is based on the Cragganmore system like Speyside but
uses the WM5100 audio CODEC.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/samsung/lowland.c')
-rw-r--r-- | sound/soc/samsung/lowland.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/sound/soc/samsung/lowland.c b/sound/soc/samsung/lowland.c new file mode 100644 index 000000000000..eff1b4b65df4 --- /dev/null +++ b/sound/soc/samsung/lowland.c | |||
@@ -0,0 +1,246 @@ | |||
1 | /* | ||
2 | * Lowland audio support | ||
3 | * | ||
4 | * Copyright 2011 Wolfson Microelectronics | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <sound/soc.h> | ||
13 | #include <sound/soc-dapm.h> | ||
14 | #include <sound/jack.h> | ||
15 | #include <linux/gpio.h> | ||
16 | #include <linux/module.h> | ||
17 | |||
18 | #include "../codecs/wm5100.h" | ||
19 | #include "../codecs/wm9081.h" | ||
20 | |||
21 | #define MCLK1_RATE (44100 * 512) | ||
22 | #define CLKOUT_RATE (44100 * 256) | ||
23 | |||
24 | static int lowland_hw_params(struct snd_pcm_substream *substream, | ||
25 | struct snd_pcm_hw_params *params) | ||
26 | { | ||
27 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
28 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
29 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
30 | int ret; | ||
31 | |||
32 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | ||
33 | | SND_SOC_DAIFMT_NB_NF | ||
34 | | SND_SOC_DAIFMT_CBM_CFM); | ||
35 | if (ret < 0) | ||
36 | return ret; | ||
37 | |||
38 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | ||
39 | | SND_SOC_DAIFMT_NB_NF | ||
40 | | SND_SOC_DAIFMT_CBM_CFM); | ||
41 | if (ret < 0) | ||
42 | return ret; | ||
43 | |||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | static struct snd_soc_ops lowland_ops = { | ||
48 | .hw_params = lowland_hw_params, | ||
49 | }; | ||
50 | |||
51 | static struct snd_soc_jack lowland_headset; | ||
52 | |||
53 | /* Headset jack detection DAPM pins */ | ||
54 | static struct snd_soc_jack_pin lowland_headset_pins[] = { | ||
55 | { | ||
56 | .pin = "Headphone", | ||
57 | .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT, | ||
58 | }, | ||
59 | { | ||
60 | .pin = "Headset Mic", | ||
61 | .mask = SND_JACK_MICROPHONE, | ||
62 | }, | ||
63 | }; | ||
64 | |||
65 | static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd) | ||
66 | { | ||
67 | struct snd_soc_codec *codec = rtd->codec; | ||
68 | int ret; | ||
69 | |||
70 | ret = snd_soc_codec_set_sysclk(codec, WM5100_CLK_SYSCLK, | ||
71 | WM5100_CLKSRC_MCLK1, MCLK1_RATE, | ||
72 | SND_SOC_CLOCK_IN); | ||
73 | if (ret < 0) { | ||
74 | pr_err("Failed to set SYSCLK clock source: %d\n", ret); | ||
75 | return ret; | ||
76 | } | ||
77 | |||
78 | /* Clock OPCLK, used by the other audio components. */ | ||
79 | ret = snd_soc_codec_set_sysclk(codec, WM5100_CLK_OPCLK, 0, | ||
80 | CLKOUT_RATE, 0); | ||
81 | if (ret < 0) { | ||
82 | pr_err("Failed to set OPCLK rate: %d\n", ret); | ||
83 | return ret; | ||
84 | } | ||
85 | |||
86 | ret = snd_soc_jack_new(codec, "Headset", | ||
87 | SND_JACK_LINEOUT | SND_JACK_HEADSET | | ||
88 | SND_JACK_BTN_0, | ||
89 | &lowland_headset); | ||
90 | if (ret) | ||
91 | return ret; | ||
92 | |||
93 | ret = snd_soc_jack_add_pins(&lowland_headset, | ||
94 | ARRAY_SIZE(lowland_headset_pins), | ||
95 | lowland_headset_pins); | ||
96 | if (ret) | ||
97 | return ret; | ||
98 | |||
99 | wm5100_detect(codec, &lowland_headset); | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static struct snd_soc_dai_link lowland_dai[] = { | ||
105 | { | ||
106 | .name = "CPU", | ||
107 | .stream_name = "CPU", | ||
108 | .cpu_dai_name = "samsung-i2s.0", | ||
109 | .codec_dai_name = "wm5100-aif1", | ||
110 | .platform_name = "samsung-audio", | ||
111 | .codec_name = "wm5100.1-001a", | ||
112 | .ops = &lowland_ops, | ||
113 | .init = lowland_wm5100_init, | ||
114 | }, | ||
115 | { | ||
116 | .name = "Baseband", | ||
117 | .stream_name = "Baseband", | ||
118 | .cpu_dai_name = "wm5100-aif2", | ||
119 | .codec_dai_name = "wm1250-ev1", | ||
120 | .codec_name = "wm1250-ev1.1-0027", | ||
121 | .ops = &lowland_ops, | ||
122 | .ignore_suspend = 1, | ||
123 | }, | ||
124 | }; | ||
125 | |||
126 | static int lowland_wm9081_init(struct snd_soc_dapm_context *dapm) | ||
127 | { | ||
128 | snd_soc_dapm_nc_pin(dapm, "LINEOUT"); | ||
129 | |||
130 | /* At any time the WM9081 is active it will have this clock */ | ||
131 | return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0, | ||
132 | CLKOUT_RATE, 0); | ||
133 | } | ||
134 | |||
135 | static struct snd_soc_aux_dev lowland_aux_dev[] = { | ||
136 | { | ||
137 | .name = "wm9081", | ||
138 | .codec_name = "wm9081.1-006c", | ||
139 | .init = lowland_wm9081_init, | ||
140 | }, | ||
141 | }; | ||
142 | |||
143 | static struct snd_soc_codec_conf lowland_codec_conf[] = { | ||
144 | { | ||
145 | .dev_name = "wm9081.1-006c", | ||
146 | .name_prefix = "Sub", | ||
147 | }, | ||
148 | }; | ||
149 | |||
150 | static const struct snd_kcontrol_new controls[] = { | ||
151 | SOC_DAPM_PIN_SWITCH("Main Speaker"), | ||
152 | SOC_DAPM_PIN_SWITCH("Main DMIC"), | ||
153 | SOC_DAPM_PIN_SWITCH("Main AMIC"), | ||
154 | SOC_DAPM_PIN_SWITCH("WM1250 Input"), | ||
155 | SOC_DAPM_PIN_SWITCH("WM1250 Output"), | ||
156 | SOC_DAPM_PIN_SWITCH("Headphone"), | ||
157 | }; | ||
158 | |||
159 | static struct snd_soc_dapm_widget widgets[] = { | ||
160 | SND_SOC_DAPM_HP("Headphone", NULL), | ||
161 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | ||
162 | |||
163 | SND_SOC_DAPM_SPK("Main Speaker", NULL), | ||
164 | |||
165 | SND_SOC_DAPM_MIC("Main AMIC", NULL), | ||
166 | SND_SOC_DAPM_MIC("Main DMIC", NULL), | ||
167 | }; | ||
168 | |||
169 | static struct snd_soc_dapm_route audio_paths[] = { | ||
170 | { "Sub IN1", NULL, "HPOUT2L" }, | ||
171 | { "Sub IN2", NULL, "HPOUT2R" }, | ||
172 | |||
173 | { "Main Speaker", NULL, "Sub SPKN" }, | ||
174 | { "Main Speaker", NULL, "Sub SPKP" }, | ||
175 | { "Main Speaker", NULL, "SPKDAT1" }, | ||
176 | }; | ||
177 | |||
178 | static struct snd_soc_card lowland = { | ||
179 | .name = "Lowland", | ||
180 | .dai_link = lowland_dai, | ||
181 | .num_links = ARRAY_SIZE(lowland_dai), | ||
182 | .aux_dev = lowland_aux_dev, | ||
183 | .num_aux_devs = ARRAY_SIZE(lowland_aux_dev), | ||
184 | .codec_conf = lowland_codec_conf, | ||
185 | .num_configs = ARRAY_SIZE(lowland_codec_conf), | ||
186 | |||
187 | .controls = controls, | ||
188 | .num_controls = ARRAY_SIZE(controls), | ||
189 | .dapm_widgets = widgets, | ||
190 | .num_dapm_widgets = ARRAY_SIZE(widgets), | ||
191 | .dapm_routes = audio_paths, | ||
192 | .num_dapm_routes = ARRAY_SIZE(audio_paths), | ||
193 | }; | ||
194 | |||
195 | static __devinit int lowland_probe(struct platform_device *pdev) | ||
196 | { | ||
197 | struct snd_soc_card *card = &lowland; | ||
198 | int ret; | ||
199 | |||
200 | card->dev = &pdev->dev; | ||
201 | |||
202 | ret = snd_soc_register_card(card); | ||
203 | if (ret) { | ||
204 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", | ||
205 | ret); | ||
206 | return ret; | ||
207 | } | ||
208 | |||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static int __devexit lowland_remove(struct platform_device *pdev) | ||
213 | { | ||
214 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
215 | |||
216 | snd_soc_unregister_card(card); | ||
217 | |||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static struct platform_driver lowland_driver = { | ||
222 | .driver = { | ||
223 | .name = "lowland", | ||
224 | .owner = THIS_MODULE, | ||
225 | .pm = &snd_soc_pm_ops, | ||
226 | }, | ||
227 | .probe = lowland_probe, | ||
228 | .remove = __devexit_p(lowland_remove), | ||
229 | }; | ||
230 | |||
231 | static int __init lowland_audio_init(void) | ||
232 | { | ||
233 | return platform_driver_register(&lowland_driver); | ||
234 | } | ||
235 | module_init(lowland_audio_init); | ||
236 | |||
237 | static void __exit lowland_audio_exit(void) | ||
238 | { | ||
239 | platform_driver_unregister(&lowland_driver); | ||
240 | } | ||
241 | module_exit(lowland_audio_exit); | ||
242 | |||
243 | MODULE_DESCRIPTION("Lowland audio support"); | ||
244 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
245 | MODULE_LICENSE("GPL"); | ||
246 | MODULE_ALIAS("platform:lowland"); | ||