Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / sound / soc / samsung / lowland.c
blob4adff934f771e8ef18741e8b009c4b7eb25628b5
1 /*
2 * Lowland audio support
4 * Copyright 2011 Wolfson Microelectronics
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.
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>
18 #include "../codecs/wm5100.h"
19 #include "../codecs/wm9081.h"
21 #define MCLK1_RATE (44100 * 512)
22 #define CLKOUT_RATE (44100 * 256)
24 static int lowland_hw_params(struct snd_pcm_substream *substream,
25 struct snd_pcm_hw_params *params)
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;
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;
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;
44 return 0;
47 static struct snd_soc_ops lowland_ops = {
48 .hw_params = lowland_hw_params,
51 static struct snd_soc_jack lowland_headset;
53 /* Headset jack detection DAPM pins */
54 static struct snd_soc_jack_pin lowland_headset_pins[] = {
56 .pin = "Headphone",
57 .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
60 .pin = "Headset Mic",
61 .mask = SND_JACK_MICROPHONE,
65 static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
67 struct snd_soc_codec *codec = rtd->codec;
68 int ret;
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;
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;
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;
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;
99 wm5100_detect(codec, &lowland_headset);
101 return 0;
104 static struct snd_soc_dai_link lowland_dai[] = {
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,
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,
126 static int lowland_wm9081_init(struct snd_soc_dapm_context *dapm)
128 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
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);
135 static struct snd_soc_aux_dev lowland_aux_dev[] = {
137 .name = "wm9081",
138 .codec_name = "wm9081.1-006c",
139 .init = lowland_wm9081_init,
143 static struct snd_soc_codec_conf lowland_codec_conf[] = {
145 .dev_name = "wm9081.1-006c",
146 .name_prefix = "Sub",
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"),
159 static struct snd_soc_dapm_widget widgets[] = {
160 SND_SOC_DAPM_HP("Headphone", NULL),
161 SND_SOC_DAPM_MIC("Headset Mic", NULL),
163 SND_SOC_DAPM_SPK("Main Speaker", NULL),
165 SND_SOC_DAPM_MIC("Main AMIC", NULL),
166 SND_SOC_DAPM_MIC("Main DMIC", NULL),
169 static struct snd_soc_dapm_route audio_paths[] = {
170 { "Sub IN1", NULL, "HPOUT2L" },
171 { "Sub IN2", NULL, "HPOUT2R" },
173 { "Main Speaker", NULL, "Sub SPKN" },
174 { "Main Speaker", NULL, "Sub SPKP" },
175 { "Main Speaker", NULL, "SPKDAT1" },
178 static struct snd_soc_card lowland = {
179 .name = "Lowland",
180 .owner = THIS_MODULE,
181 .dai_link = lowland_dai,
182 .num_links = ARRAY_SIZE(lowland_dai),
183 .aux_dev = lowland_aux_dev,
184 .num_aux_devs = ARRAY_SIZE(lowland_aux_dev),
185 .codec_conf = lowland_codec_conf,
186 .num_configs = ARRAY_SIZE(lowland_codec_conf),
188 .controls = controls,
189 .num_controls = ARRAY_SIZE(controls),
190 .dapm_widgets = widgets,
191 .num_dapm_widgets = ARRAY_SIZE(widgets),
192 .dapm_routes = audio_paths,
193 .num_dapm_routes = ARRAY_SIZE(audio_paths),
196 static __devinit int lowland_probe(struct platform_device *pdev)
198 struct snd_soc_card *card = &lowland;
199 int ret;
201 card->dev = &pdev->dev;
203 ret = snd_soc_register_card(card);
204 if (ret) {
205 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
206 ret);
207 return ret;
210 return 0;
213 static int __devexit lowland_remove(struct platform_device *pdev)
215 struct snd_soc_card *card = platform_get_drvdata(pdev);
217 snd_soc_unregister_card(card);
219 return 0;
222 static struct platform_driver lowland_driver = {
223 .driver = {
224 .name = "lowland",
225 .owner = THIS_MODULE,
226 .pm = &snd_soc_pm_ops,
228 .probe = lowland_probe,
229 .remove = __devexit_p(lowland_remove),
232 module_platform_driver(lowland_driver);
234 MODULE_DESCRIPTION("Lowland audio support");
235 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
236 MODULE_LICENSE("GPL");
237 MODULE_ALIAS("platform:lowland");