blob: 6cac1e90d2687bf1d586b0832e9116d567bfe5ba [file] [log] [blame]
Mark Brownabda5df2011-08-23 17:40:01 +01001/*
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
Mark Brownabda5df2011-08-23 17:40:01 +010024static struct snd_soc_jack lowland_headset;
25
26/* Headset jack detection DAPM pins */
27static struct snd_soc_jack_pin lowland_headset_pins[] = {
28 {
29 .pin = "Headphone",
30 .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
31 },
32 {
33 .pin = "Headset Mic",
34 .mask = SND_JACK_MICROPHONE,
35 },
36};
37
38static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
39{
40 struct snd_soc_codec *codec = rtd->codec;
41 int ret;
42
43 ret = snd_soc_codec_set_sysclk(codec, WM5100_CLK_SYSCLK,
44 WM5100_CLKSRC_MCLK1, MCLK1_RATE,
45 SND_SOC_CLOCK_IN);
46 if (ret < 0) {
47 pr_err("Failed to set SYSCLK clock source: %d\n", ret);
48 return ret;
49 }
50
51 /* Clock OPCLK, used by the other audio components. */
52 ret = snd_soc_codec_set_sysclk(codec, WM5100_CLK_OPCLK, 0,
53 CLKOUT_RATE, 0);
54 if (ret < 0) {
55 pr_err("Failed to set OPCLK rate: %d\n", ret);
56 return ret;
57 }
58
59 ret = snd_soc_jack_new(codec, "Headset",
60 SND_JACK_LINEOUT | SND_JACK_HEADSET |
61 SND_JACK_BTN_0,
62 &lowland_headset);
63 if (ret)
64 return ret;
65
66 ret = snd_soc_jack_add_pins(&lowland_headset,
67 ARRAY_SIZE(lowland_headset_pins),
68 lowland_headset_pins);
69 if (ret)
70 return ret;
71
72 wm5100_detect(codec, &lowland_headset);
73
74 return 0;
75}
76
77static struct snd_soc_dai_link lowland_dai[] = {
78 {
79 .name = "CPU",
80 .stream_name = "CPU",
81 .cpu_dai_name = "samsung-i2s.0",
82 .codec_dai_name = "wm5100-aif1",
83 .platform_name = "samsung-audio",
84 .codec_name = "wm5100.1-001a",
Mark Brown277b6fd2012-05-08 09:49:45 +010085 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
86 SND_SOC_DAIFMT_CBM_CFM,
Mark Brownabda5df2011-08-23 17:40:01 +010087 .init = lowland_wm5100_init,
88 },
89 {
90 .name = "Baseband",
91 .stream_name = "Baseband",
92 .cpu_dai_name = "wm5100-aif2",
93 .codec_dai_name = "wm1250-ev1",
94 .codec_name = "wm1250-ev1.1-0027",
Mark Brown277b6fd2012-05-08 09:49:45 +010095 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
96 SND_SOC_DAIFMT_CBM_CFM,
Mark Brownabda5df2011-08-23 17:40:01 +010097 .ignore_suspend = 1,
98 },
99};
100
101static int lowland_wm9081_init(struct snd_soc_dapm_context *dapm)
102{
103 snd_soc_dapm_nc_pin(dapm, "LINEOUT");
104
105 /* At any time the WM9081 is active it will have this clock */
106 return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0,
107 CLKOUT_RATE, 0);
108}
109
110static struct snd_soc_aux_dev lowland_aux_dev[] = {
111 {
112 .name = "wm9081",
113 .codec_name = "wm9081.1-006c",
114 .init = lowland_wm9081_init,
115 },
116};
117
118static struct snd_soc_codec_conf lowland_codec_conf[] = {
119 {
120 .dev_name = "wm9081.1-006c",
121 .name_prefix = "Sub",
122 },
123};
124
125static const struct snd_kcontrol_new controls[] = {
126 SOC_DAPM_PIN_SWITCH("Main Speaker"),
127 SOC_DAPM_PIN_SWITCH("Main DMIC"),
128 SOC_DAPM_PIN_SWITCH("Main AMIC"),
129 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
130 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
131 SOC_DAPM_PIN_SWITCH("Headphone"),
132};
133
134static struct snd_soc_dapm_widget widgets[] = {
135 SND_SOC_DAPM_HP("Headphone", NULL),
136 SND_SOC_DAPM_MIC("Headset Mic", NULL),
137
138 SND_SOC_DAPM_SPK("Main Speaker", NULL),
139
140 SND_SOC_DAPM_MIC("Main AMIC", NULL),
141 SND_SOC_DAPM_MIC("Main DMIC", NULL),
142};
143
144static struct snd_soc_dapm_route audio_paths[] = {
145 { "Sub IN1", NULL, "HPOUT2L" },
146 { "Sub IN2", NULL, "HPOUT2R" },
147
148 { "Main Speaker", NULL, "Sub SPKN" },
149 { "Main Speaker", NULL, "Sub SPKP" },
150 { "Main Speaker", NULL, "SPKDAT1" },
151};
152
153static struct snd_soc_card lowland = {
154 .name = "Lowland",
Axel Lin095d79d2011-12-22 10:53:15 +0800155 .owner = THIS_MODULE,
Mark Brownabda5df2011-08-23 17:40:01 +0100156 .dai_link = lowland_dai,
157 .num_links = ARRAY_SIZE(lowland_dai),
158 .aux_dev = lowland_aux_dev,
159 .num_aux_devs = ARRAY_SIZE(lowland_aux_dev),
160 .codec_conf = lowland_codec_conf,
161 .num_configs = ARRAY_SIZE(lowland_codec_conf),
162
163 .controls = controls,
164 .num_controls = ARRAY_SIZE(controls),
165 .dapm_widgets = widgets,
166 .num_dapm_widgets = ARRAY_SIZE(widgets),
167 .dapm_routes = audio_paths,
168 .num_dapm_routes = ARRAY_SIZE(audio_paths),
169};
170
171static __devinit int lowland_probe(struct platform_device *pdev)
172{
173 struct snd_soc_card *card = &lowland;
174 int ret;
175
176 card->dev = &pdev->dev;
177
178 ret = snd_soc_register_card(card);
179 if (ret) {
180 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
181 ret);
182 return ret;
183 }
184
185 return 0;
186}
187
188static int __devexit lowland_remove(struct platform_device *pdev)
189{
190 struct snd_soc_card *card = platform_get_drvdata(pdev);
191
192 snd_soc_unregister_card(card);
193
194 return 0;
195}
196
197static struct platform_driver lowland_driver = {
198 .driver = {
199 .name = "lowland",
200 .owner = THIS_MODULE,
201 .pm = &snd_soc_pm_ops,
202 },
203 .probe = lowland_probe,
204 .remove = __devexit_p(lowland_remove),
205};
206
Mark Browne00c3f52011-11-23 15:20:13 +0000207module_platform_driver(lowland_driver);
Mark Brownabda5df2011-08-23 17:40:01 +0100208
209MODULE_DESCRIPTION("Lowland audio support");
210MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
211MODULE_LICENSE("GPL");
212MODULE_ALIAS("platform:lowland");