blob: 0e550f14028f11ce04fa5bfd4b560f9c283b4ade [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>
22#include <sound/pcm_params.h>
23
24#include "sst-dsp.h"
25#include "sst-haswell-ipc.h"
26
27#include "../codecs/rt286.h"
28
29static const struct snd_soc_dapm_widget broadwell_widgets[] = {
30 SND_SOC_DAPM_HP("Headphones", NULL),
31 SND_SOC_DAPM_SPK("Speaker", NULL),
32 SND_SOC_DAPM_MIC("Mic Jack", NULL),
33 SND_SOC_DAPM_MIC("DMIC1", NULL),
34 SND_SOC_DAPM_MIC("DMIC2", NULL),
35 SND_SOC_DAPM_LINE("Line Jack", NULL),
36};
37
38static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
39
40 /* speaker */
41 {"Speaker", NULL, "SPOR"},
42 {"Speaker", NULL, "SPOL"},
43
44 /* HP jack connectors - unknown if we have jack deteck */
45 {"Headphones", NULL, "HPO Pin"},
46
47 /* other jacks */
48 {"MIC1", NULL, "Mic Jack"},
49 {"LINE1", NULL, "Line Jack"},
50
51 /* digital mics */
52 {"DMIC1 Pin", NULL, "DMIC1"},
53 {"DMIC2 Pin", NULL, "DMIC2"},
54
55 /* CODEC BE connections */
56 {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
57 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
58};
59
60static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
61 struct snd_pcm_hw_params *params)
62{
63 struct snd_interval *rate = hw_param_interval(params,
64 SNDRV_PCM_HW_PARAM_RATE);
65 struct snd_interval *channels = hw_param_interval(params,
66 SNDRV_PCM_HW_PARAM_CHANNELS);
67
68 /* The ADSP will covert the FE rate to 48k, stereo */
69 rate->min = rate->max = 48000;
70 channels->min = channels->max = 2;
71
72 /* set SSP0 to 16 bit */
73 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
74 SNDRV_PCM_HW_PARAM_FIRST_MASK],
75 SNDRV_PCM_FORMAT_S16_LE);
76 return 0;
77}
78
79static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
80 struct snd_pcm_hw_params *params)
81{
82 struct snd_soc_pcm_runtime *rtd = substream->private_data;
83 struct snd_soc_dai *codec_dai = rtd->codec_dai;
84 int ret;
85
86 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
87 SND_SOC_CLOCK_IN);
88
89 if (ret < 0) {
90 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
91 return ret;
92 }
93
94 return ret;
95}
96
97static struct snd_soc_ops broadwell_rt286_ops = {
98 .hw_params = broadwell_rt286_hw_params,
99};
100
101static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
102{
103 struct snd_soc_codec *codec = rtd->codec;
104 struct snd_soc_dapm_context *dapm = &codec->dapm;
105 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
106 struct sst_hsw *broadwell = pdata->dsp;
107 int ret;
108
109 /* Set ADSP SSP port settings */
110 ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
111 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
112 SST_HSW_DEVICE_CLOCK_MASTER, 9);
113 if (ret < 0) {
114 dev_err(rtd->dev, "error: failed to set device config\n");
115 return ret;
116 }
117
118 /* always connected - check HP for jack detect */
119 snd_soc_dapm_enable_pin(dapm, "Headphones");
120 snd_soc_dapm_enable_pin(dapm, "Speaker");
121 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
122 snd_soc_dapm_enable_pin(dapm, "Line Jack");
123 snd_soc_dapm_enable_pin(dapm, "DMIC1");
124 snd_soc_dapm_enable_pin(dapm, "DMIC2");
125
126 return 0;
127}
128
129/* broadwell digital audio interface glue - connects codec <--> CPU */
130static struct snd_soc_dai_link broadwell_rt286_dais[] = {
131 /* Front End DAI links */
132 {
133 .name = "System PCM",
134 .stream_name = "System Playback",
135 .cpu_dai_name = "System Pin",
136 .platform_name = "haswell-pcm-audio",
137 .dynamic = 1,
138 .codec_name = "snd-soc-dummy",
139 .codec_dai_name = "snd-soc-dummy-dai",
140 .init = broadwell_rtd_init,
141 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
142 .dpcm_playback = 1,
143 },
144 {
145 .name = "Offload0",
146 .stream_name = "Offload0 Playback",
147 .cpu_dai_name = "Offload0 Pin",
148 .platform_name = "haswell-pcm-audio",
149 .dynamic = 1,
150 .codec_name = "snd-soc-dummy",
151 .codec_dai_name = "snd-soc-dummy-dai",
152 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
153 .dpcm_playback = 1,
154 },
155 {
156 .name = "Offload1",
157 .stream_name = "Offload1 Playback",
158 .cpu_dai_name = "Offload1 Pin",
159 .platform_name = "haswell-pcm-audio",
160 .dynamic = 1,
161 .codec_name = "snd-soc-dummy",
162 .codec_dai_name = "snd-soc-dummy-dai",
163 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
164 .dpcm_playback = 1,
165 },
166 {
167 .name = "Loopback PCM",
168 .stream_name = "Loopback",
169 .cpu_dai_name = "Loopback Pin",
170 .platform_name = "haswell-pcm-audio",
171 .dynamic = 0,
172 .codec_name = "snd-soc-dummy",
173 .codec_dai_name = "snd-soc-dummy-dai",
174 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
175 .dpcm_capture = 1,
176 },
177 {
178 .name = "Capture PCM",
179 .stream_name = "Capture",
180 .cpu_dai_name = "Capture Pin",
181 .platform_name = "haswell-pcm-audio",
182 .dynamic = 1,
183 .codec_name = "snd-soc-dummy",
184 .codec_dai_name = "snd-soc-dummy-dai",
185 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
186 .dpcm_capture = 1,
187 },
188
189 /* Back End DAI links */
190 {
191 /* SSP0 - Codec */
192 .name = "Codec",
193 .be_id = 0,
194 .cpu_dai_name = "snd-soc-dummy-dai",
195 .platform_name = "snd-soc-dummy",
196 .no_pcm = 1,
197 .codec_name = "i2c-INT343A:00",
198 .codec_dai_name = "rt286-aif1",
199 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
200 SND_SOC_DAIFMT_CBS_CFS,
201 .ignore_suspend = 1,
202 .ignore_pmdown_time = 1,
203 .be_hw_params_fixup = broadwell_ssp0_fixup,
204 .ops = &broadwell_rt286_ops,
205 .dpcm_playback = 1,
206 .dpcm_capture = 1,
207 },
208};
209
210/* broadwell audio machine driver for WPT + RT286S */
211static struct snd_soc_card broadwell_rt286 = {
212 .name = "broadwell-rt286",
213 .owner = THIS_MODULE,
214 .dai_link = broadwell_rt286_dais,
215 .num_links = ARRAY_SIZE(broadwell_rt286_dais),
216 .dapm_widgets = broadwell_widgets,
217 .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
218 .dapm_routes = broadwell_rt286_map,
219 .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
220 .fully_routed = true,
221};
222
223static int broadwell_audio_probe(struct platform_device *pdev)
224{
225 broadwell_rt286.dev = &pdev->dev;
226
227 return snd_soc_register_card(&broadwell_rt286);
228}
229
230static int broadwell_audio_remove(struct platform_device *pdev)
231{
232 snd_soc_unregister_card(&broadwell_rt286);
233 return 0;
234}
235
236static struct platform_driver broadwell_audio = {
237 .probe = broadwell_audio_probe,
238 .remove = broadwell_audio_remove,
239 .driver = {
240 .name = "broadwell-audio",
241 .owner = THIS_MODULE,
242 },
243};
244
245module_platform_driver(broadwell_audio)
246
247/* Module information */
248MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
249MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
250MODULE_LICENSE("GPL v2");
251MODULE_ALIAS("platform:broadwell-audio");