blob: 9effa3da982f46621e94dd8623186038a3ac8933 [file] [log] [blame]
Liam Girdwoodafdb74f2014-07-14 10:35:40 +08001/*
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>
Jie Yangc1e99c92014-10-30 21:16:23 +080022#include <sound/jack.h>
Liam Girdwoodafdb74f2014-07-14 10:35:40 +080023#include <sound/pcm_params.h>
24
25#include "sst-dsp.h"
26#include "sst-haswell-ipc.h"
27
28#include "../codecs/rt286.h"
29
Jie Yangc1e99c92014-10-30 21:16:23 +080030static struct snd_soc_jack broadwell_headset;
31/* Headset jack detection DAPM pins */
32static 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
43static const struct snd_kcontrol_new broadwell_controls[] = {
44 SOC_DAPM_PIN_SWITCH("Speaker"),
45 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
46};
47
Liam Girdwoodafdb74f2014-07-14 10:35:40 +080048static const struct snd_soc_dapm_widget broadwell_widgets[] = {
Jie Yangc1e99c92014-10-30 21:16:23 +080049 SND_SOC_DAPM_HP("Headphone Jack", NULL),
Liam Girdwoodafdb74f2014-07-14 10:35:40 +080050 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
57static 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 */
Jie Yangc1e99c92014-10-30 21:16:23 +080064 {"Headphone Jack", NULL, "HPO Pin"},
Liam Girdwoodafdb74f2014-07-14 10:35:40 +080065
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
Jie Yangc1e99c92014-10-30 21:16:23 +080079static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
80{
81 struct snd_soc_codec *codec = rtd->codec;
82 int ret = 0;
Lars-Peter Clausen85c85e52015-03-04 10:33:21 +010083 ret = snd_soc_card_jack_new(rtd->card, "Headset",
84 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset,
85 broadwell_headset_pins, ARRAY_SIZE(broadwell_headset_pins));
Jie Yangc1e99c92014-10-30 21:16:23 +080086 if (ret)
87 return ret;
88
89 rt286_mic_detect(codec, &broadwell_headset);
90 return 0;
91}
92
93
Liam Girdwoodafdb74f2014-07-14 10:35:40 +080094static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
95 struct snd_pcm_hw_params *params)
96{
97 struct snd_interval *rate = hw_param_interval(params,
98 SNDRV_PCM_HW_PARAM_RATE);
99 struct snd_interval *channels = hw_param_interval(params,
100 SNDRV_PCM_HW_PARAM_CHANNELS);
101
102 /* The ADSP will covert the FE rate to 48k, stereo */
103 rate->min = rate->max = 48000;
104 channels->min = channels->max = 2;
105
106 /* set SSP0 to 16 bit */
107 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
108 SNDRV_PCM_HW_PARAM_FIRST_MASK],
109 SNDRV_PCM_FORMAT_S16_LE);
110 return 0;
111}
112
113static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
114 struct snd_pcm_hw_params *params)
115{
116 struct snd_soc_pcm_runtime *rtd = substream->private_data;
117 struct snd_soc_dai *codec_dai = rtd->codec_dai;
118 int ret;
119
120 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
121 SND_SOC_CLOCK_IN);
122
123 if (ret < 0) {
124 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
125 return ret;
126 }
127
128 return ret;
129}
130
131static struct snd_soc_ops broadwell_rt286_ops = {
132 .hw_params = broadwell_rt286_hw_params,
133};
134
135static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
136{
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800137 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
138 struct sst_hsw *broadwell = pdata->dsp;
139 int ret;
140
141 /* Set ADSP SSP port settings */
142 ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
143 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
144 SST_HSW_DEVICE_CLOCK_MASTER, 9);
145 if (ret < 0) {
146 dev_err(rtd->dev, "error: failed to set device config\n");
147 return ret;
148 }
149
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800150 return 0;
151}
152
153/* broadwell digital audio interface glue - connects codec <--> CPU */
154static struct snd_soc_dai_link broadwell_rt286_dais[] = {
155 /* Front End DAI links */
156 {
157 .name = "System PCM",
Jie Yang7bb73cb2014-11-28 21:52:11 +0800158 .stream_name = "System Playback/Capture",
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800159 .cpu_dai_name = "System Pin",
160 .platform_name = "haswell-pcm-audio",
161 .dynamic = 1,
162 .codec_name = "snd-soc-dummy",
163 .codec_dai_name = "snd-soc-dummy-dai",
164 .init = broadwell_rtd_init,
165 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
166 .dpcm_playback = 1,
Jie Yang7bb73cb2014-11-28 21:52:11 +0800167 .dpcm_capture = 1,
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800168 },
169 {
170 .name = "Offload0",
171 .stream_name = "Offload0 Playback",
172 .cpu_dai_name = "Offload0 Pin",
173 .platform_name = "haswell-pcm-audio",
174 .dynamic = 1,
175 .codec_name = "snd-soc-dummy",
176 .codec_dai_name = "snd-soc-dummy-dai",
177 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
178 .dpcm_playback = 1,
179 },
180 {
181 .name = "Offload1",
182 .stream_name = "Offload1 Playback",
183 .cpu_dai_name = "Offload1 Pin",
184 .platform_name = "haswell-pcm-audio",
185 .dynamic = 1,
186 .codec_name = "snd-soc-dummy",
187 .codec_dai_name = "snd-soc-dummy-dai",
188 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
189 .dpcm_playback = 1,
190 },
191 {
192 .name = "Loopback PCM",
193 .stream_name = "Loopback",
194 .cpu_dai_name = "Loopback Pin",
195 .platform_name = "haswell-pcm-audio",
196 .dynamic = 0,
197 .codec_name = "snd-soc-dummy",
198 .codec_dai_name = "snd-soc-dummy-dai",
199 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
200 .dpcm_capture = 1,
201 },
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800202 /* Back End DAI links */
203 {
204 /* SSP0 - Codec */
205 .name = "Codec",
206 .be_id = 0,
207 .cpu_dai_name = "snd-soc-dummy-dai",
208 .platform_name = "snd-soc-dummy",
209 .no_pcm = 1,
210 .codec_name = "i2c-INT343A:00",
211 .codec_dai_name = "rt286-aif1",
Jie Yangc1e99c92014-10-30 21:16:23 +0800212 .init = broadwell_rt286_codec_init,
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800213 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
214 SND_SOC_DAIFMT_CBS_CFS,
215 .ignore_suspend = 1,
216 .ignore_pmdown_time = 1,
217 .be_hw_params_fixup = broadwell_ssp0_fixup,
218 .ops = &broadwell_rt286_ops,
219 .dpcm_playback = 1,
220 .dpcm_capture = 1,
221 },
222};
223
224/* broadwell audio machine driver for WPT + RT286S */
225static struct snd_soc_card broadwell_rt286 = {
226 .name = "broadwell-rt286",
227 .owner = THIS_MODULE,
228 .dai_link = broadwell_rt286_dais,
229 .num_links = ARRAY_SIZE(broadwell_rt286_dais),
Jie Yangc1e99c92014-10-30 21:16:23 +0800230 .controls = broadwell_controls,
231 .num_controls = ARRAY_SIZE(broadwell_controls),
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800232 .dapm_widgets = broadwell_widgets,
233 .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
234 .dapm_routes = broadwell_rt286_map,
235 .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
236 .fully_routed = true,
237};
238
239static int broadwell_audio_probe(struct platform_device *pdev)
240{
241 broadwell_rt286.dev = &pdev->dev;
242
243 return snd_soc_register_card(&broadwell_rt286);
244}
245
246static int broadwell_audio_remove(struct platform_device *pdev)
247{
248 snd_soc_unregister_card(&broadwell_rt286);
249 return 0;
250}
251
252static struct platform_driver broadwell_audio = {
253 .probe = broadwell_audio_probe,
254 .remove = broadwell_audio_remove,
255 .driver = {
256 .name = "broadwell-audio",
Liam Girdwoodafdb74f2014-07-14 10:35:40 +0800257 },
258};
259
260module_platform_driver(broadwell_audio)
261
262/* Module information */
263MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
264MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
265MODULE_LICENSE("GPL v2");
266MODULE_ALIAS("platform:broadwell-audio");