Merge branch 'topic/rt5670' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[deliverable/linux.git] / sound / soc / intel / broadwell.c
1 /*
2 * Intel Broadwell Wildcatpoint SST Audio
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/soc.h>
22 #include <sound/jack.h>
23 #include <sound/pcm_params.h>
24
25 #include "sst-dsp.h"
26 #include "sst-haswell-ipc.h"
27
28 #include "../codecs/rt286.h"
29
30 static struct snd_soc_jack broadwell_headset;
31 /* Headset jack detection DAPM pins */
32 static struct snd_soc_jack_pin broadwell_headset_pins[] = {
33 {
34 .pin = "Mic Jack",
35 .mask = SND_JACK_MICROPHONE,
36 },
37 {
38 .pin = "Headphone Jack",
39 .mask = SND_JACK_HEADPHONE,
40 },
41 };
42
43 static const struct snd_kcontrol_new broadwell_controls[] = {
44 SOC_DAPM_PIN_SWITCH("Speaker"),
45 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
46 };
47
48 static const struct snd_soc_dapm_widget broadwell_widgets[] = {
49 SND_SOC_DAPM_HP("Headphone Jack", NULL),
50 SND_SOC_DAPM_SPK("Speaker", NULL),
51 SND_SOC_DAPM_MIC("Mic Jack", NULL),
52 SND_SOC_DAPM_MIC("DMIC1", NULL),
53 SND_SOC_DAPM_MIC("DMIC2", NULL),
54 SND_SOC_DAPM_LINE("Line Jack", NULL),
55 };
56
57 static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
58
59 /* speaker */
60 {"Speaker", NULL, "SPOR"},
61 {"Speaker", NULL, "SPOL"},
62
63 /* HP jack connectors - unknown if we have jack deteck */
64 {"Headphone Jack", NULL, "HPO Pin"},
65
66 /* other jacks */
67 {"MIC1", NULL, "Mic Jack"},
68 {"LINE1", NULL, "Line Jack"},
69
70 /* digital mics */
71 {"DMIC1 Pin", NULL, "DMIC1"},
72 {"DMIC2 Pin", NULL, "DMIC2"},
73
74 /* CODEC BE connections */
75 {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
76 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
77 };
78
79 static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
80 {
81 struct snd_soc_codec *codec = rtd->codec;
82 int ret = 0;
83 ret = snd_soc_jack_new(codec, "Headset",
84 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset);
85
86 if (ret)
87 return ret;
88
89 ret = snd_soc_jack_add_pins(&broadwell_headset,
90 ARRAY_SIZE(broadwell_headset_pins),
91 broadwell_headset_pins);
92 if (ret)
93 return ret;
94
95 rt286_mic_detect(codec, &broadwell_headset);
96 return 0;
97 }
98
99
100 static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
101 struct snd_pcm_hw_params *params)
102 {
103 struct snd_interval *rate = hw_param_interval(params,
104 SNDRV_PCM_HW_PARAM_RATE);
105 struct snd_interval *channels = hw_param_interval(params,
106 SNDRV_PCM_HW_PARAM_CHANNELS);
107
108 /* The ADSP will covert the FE rate to 48k, stereo */
109 rate->min = rate->max = 48000;
110 channels->min = channels->max = 2;
111
112 /* set SSP0 to 16 bit */
113 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
114 SNDRV_PCM_HW_PARAM_FIRST_MASK],
115 SNDRV_PCM_FORMAT_S16_LE);
116 return 0;
117 }
118
119 static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
120 struct snd_pcm_hw_params *params)
121 {
122 struct snd_soc_pcm_runtime *rtd = substream->private_data;
123 struct snd_soc_dai *codec_dai = rtd->codec_dai;
124 int ret;
125
126 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
127 SND_SOC_CLOCK_IN);
128
129 if (ret < 0) {
130 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
131 return ret;
132 }
133
134 return ret;
135 }
136
137 static struct snd_soc_ops broadwell_rt286_ops = {
138 .hw_params = broadwell_rt286_hw_params,
139 };
140
141 static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
142 {
143 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
144 struct sst_hsw *broadwell = pdata->dsp;
145 int ret;
146
147 /* Set ADSP SSP port settings */
148 ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
149 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
150 SST_HSW_DEVICE_CLOCK_MASTER, 9);
151 if (ret < 0) {
152 dev_err(rtd->dev, "error: failed to set device config\n");
153 return ret;
154 }
155
156 return 0;
157 }
158
159 /* broadwell digital audio interface glue - connects codec <--> CPU */
160 static struct snd_soc_dai_link broadwell_rt286_dais[] = {
161 /* Front End DAI links */
162 {
163 .name = "System PCM",
164 .stream_name = "System Playback/Capture",
165 .cpu_dai_name = "System Pin",
166 .platform_name = "haswell-pcm-audio",
167 .dynamic = 1,
168 .codec_name = "snd-soc-dummy",
169 .codec_dai_name = "snd-soc-dummy-dai",
170 .init = broadwell_rtd_init,
171 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
172 .dpcm_playback = 1,
173 .dpcm_capture = 1,
174 },
175 {
176 .name = "Offload0",
177 .stream_name = "Offload0 Playback",
178 .cpu_dai_name = "Offload0 Pin",
179 .platform_name = "haswell-pcm-audio",
180 .dynamic = 1,
181 .codec_name = "snd-soc-dummy",
182 .codec_dai_name = "snd-soc-dummy-dai",
183 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
184 .dpcm_playback = 1,
185 },
186 {
187 .name = "Offload1",
188 .stream_name = "Offload1 Playback",
189 .cpu_dai_name = "Offload1 Pin",
190 .platform_name = "haswell-pcm-audio",
191 .dynamic = 1,
192 .codec_name = "snd-soc-dummy",
193 .codec_dai_name = "snd-soc-dummy-dai",
194 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
195 .dpcm_playback = 1,
196 },
197 {
198 .name = "Loopback PCM",
199 .stream_name = "Loopback",
200 .cpu_dai_name = "Loopback Pin",
201 .platform_name = "haswell-pcm-audio",
202 .dynamic = 0,
203 .codec_name = "snd-soc-dummy",
204 .codec_dai_name = "snd-soc-dummy-dai",
205 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
206 .dpcm_capture = 1,
207 },
208 /* Back End DAI links */
209 {
210 /* SSP0 - Codec */
211 .name = "Codec",
212 .be_id = 0,
213 .cpu_dai_name = "snd-soc-dummy-dai",
214 .platform_name = "snd-soc-dummy",
215 .no_pcm = 1,
216 .codec_name = "i2c-INT343A:00",
217 .codec_dai_name = "rt286-aif1",
218 .init = broadwell_rt286_codec_init,
219 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
220 SND_SOC_DAIFMT_CBS_CFS,
221 .ignore_suspend = 1,
222 .ignore_pmdown_time = 1,
223 .be_hw_params_fixup = broadwell_ssp0_fixup,
224 .ops = &broadwell_rt286_ops,
225 .dpcm_playback = 1,
226 .dpcm_capture = 1,
227 },
228 };
229
230 /* broadwell audio machine driver for WPT + RT286S */
231 static struct snd_soc_card broadwell_rt286 = {
232 .name = "broadwell-rt286",
233 .owner = THIS_MODULE,
234 .dai_link = broadwell_rt286_dais,
235 .num_links = ARRAY_SIZE(broadwell_rt286_dais),
236 .controls = broadwell_controls,
237 .num_controls = ARRAY_SIZE(broadwell_controls),
238 .dapm_widgets = broadwell_widgets,
239 .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
240 .dapm_routes = broadwell_rt286_map,
241 .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
242 .fully_routed = true,
243 };
244
245 static int broadwell_audio_probe(struct platform_device *pdev)
246 {
247 broadwell_rt286.dev = &pdev->dev;
248
249 return snd_soc_register_card(&broadwell_rt286);
250 }
251
252 static int broadwell_audio_remove(struct platform_device *pdev)
253 {
254 snd_soc_unregister_card(&broadwell_rt286);
255 return 0;
256 }
257
258 static struct platform_driver broadwell_audio = {
259 .probe = broadwell_audio_probe,
260 .remove = broadwell_audio_remove,
261 .driver = {
262 .name = "broadwell-audio",
263 },
264 };
265
266 module_platform_driver(broadwell_audio)
267
268 /* Module information */
269 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
270 MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
271 MODULE_LICENSE("GPL v2");
272 MODULE_ALIAS("platform:broadwell-audio");
This page took 0.038408 seconds and 5 git commands to generate.