2 * Intel Broadwell Wildcatpoint SST Audio
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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.
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.
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>
26 #include "sst-haswell-ipc.h"
28 #include "../codecs/rt286.h"
30 static struct snd_soc_jack broadwell_headset
;
31 /* Headset jack detection DAPM pins */
32 static struct snd_soc_jack_pin broadwell_headset_pins
[] = {
35 .mask
= SND_JACK_MICROPHONE
,
38 .pin
= "Headphone Jack",
39 .mask
= SND_JACK_HEADPHONE
,
43 static const struct snd_kcontrol_new broadwell_controls
[] = {
44 SOC_DAPM_PIN_SWITCH("Speaker"),
45 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
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
),
57 static const struct snd_soc_dapm_route broadwell_rt286_map
[] = {
60 {"Speaker", NULL
, "SPOR"},
61 {"Speaker", NULL
, "SPOL"},
63 /* HP jack connectors - unknown if we have jack deteck */
64 {"Headphone Jack", NULL
, "HPO Pin"},
67 {"MIC1", NULL
, "Mic Jack"},
68 {"LINE1", NULL
, "Line Jack"},
71 {"DMIC1 Pin", NULL
, "DMIC1"},
72 {"DMIC2 Pin", NULL
, "DMIC2"},
74 /* CODEC BE connections */
75 {"SSP0 CODEC IN", NULL
, "AIF1 Capture"},
76 {"AIF1 Playback", NULL
, "SSP0 CODEC OUT"},
79 static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime
*rtd
)
81 struct snd_soc_codec
*codec
= rtd
->codec
;
83 ret
= snd_soc_jack_new(codec
, "Headset",
84 SND_JACK_HEADSET
| SND_JACK_BTN_0
, &broadwell_headset
);
89 ret
= snd_soc_jack_add_pins(&broadwell_headset
,
90 ARRAY_SIZE(broadwell_headset_pins
),
91 broadwell_headset_pins
);
95 rt286_mic_detect(codec
, &broadwell_headset
);
100 static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime
*rtd
,
101 struct snd_pcm_hw_params
*params
)
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
);
108 /* The ADSP will covert the FE rate to 48k, stereo */
109 rate
->min
= rate
->max
= 48000;
110 channels
->min
= channels
->max
= 2;
112 /* set SSP0 to 16 bit */
113 snd_mask_set(¶ms
->masks
[SNDRV_PCM_HW_PARAM_FORMAT
-
114 SNDRV_PCM_HW_PARAM_FIRST_MASK
],
115 SNDRV_PCM_FORMAT_S16_LE
);
119 static int broadwell_rt286_hw_params(struct snd_pcm_substream
*substream
,
120 struct snd_pcm_hw_params
*params
)
122 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
123 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
126 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT286_SCLK_S_PLL
, 24000000,
130 dev_err(rtd
->dev
, "can't set codec sysclk configuration\n");
137 static struct snd_soc_ops broadwell_rt286_ops
= {
138 .hw_params
= broadwell_rt286_hw_params
,
141 static int broadwell_rtd_init(struct snd_soc_pcm_runtime
*rtd
)
143 struct snd_soc_codec
*codec
= rtd
->codec
;
144 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
145 struct sst_pdata
*pdata
= dev_get_platdata(rtd
->platform
->dev
);
146 struct sst_hsw
*broadwell
= pdata
->dsp
;
149 /* Set ADSP SSP port settings */
150 ret
= sst_hsw_device_set_config(broadwell
, SST_HSW_DEVICE_SSP_0
,
151 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ
,
152 SST_HSW_DEVICE_CLOCK_MASTER
, 9);
154 dev_err(rtd
->dev
, "error: failed to set device config\n");
158 /* always connected - check HP for jack detect */
159 snd_soc_dapm_enable_pin(dapm
, "Headphone Jack");
160 snd_soc_dapm_enable_pin(dapm
, "Speaker");
161 snd_soc_dapm_enable_pin(dapm
, "Mic Jack");
162 snd_soc_dapm_enable_pin(dapm
, "Line Jack");
163 snd_soc_dapm_enable_pin(dapm
, "DMIC1");
164 snd_soc_dapm_enable_pin(dapm
, "DMIC2");
169 /* broadwell digital audio interface glue - connects codec <--> CPU */
170 static struct snd_soc_dai_link broadwell_rt286_dais
[] = {
171 /* Front End DAI links */
173 .name
= "System PCM",
174 .stream_name
= "System Playback/Capture",
175 .cpu_dai_name
= "System Pin",
176 .platform_name
= "haswell-pcm-audio",
178 .codec_name
= "snd-soc-dummy",
179 .codec_dai_name
= "snd-soc-dummy-dai",
180 .init
= broadwell_rtd_init
,
181 .trigger
= {SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
187 .stream_name
= "Offload0 Playback",
188 .cpu_dai_name
= "Offload0 Pin",
189 .platform_name
= "haswell-pcm-audio",
191 .codec_name
= "snd-soc-dummy",
192 .codec_dai_name
= "snd-soc-dummy-dai",
193 .trigger
= {SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
198 .stream_name
= "Offload1 Playback",
199 .cpu_dai_name
= "Offload1 Pin",
200 .platform_name
= "haswell-pcm-audio",
202 .codec_name
= "snd-soc-dummy",
203 .codec_dai_name
= "snd-soc-dummy-dai",
204 .trigger
= {SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
208 .name
= "Loopback PCM",
209 .stream_name
= "Loopback",
210 .cpu_dai_name
= "Loopback Pin",
211 .platform_name
= "haswell-pcm-audio",
213 .codec_name
= "snd-soc-dummy",
214 .codec_dai_name
= "snd-soc-dummy-dai",
215 .trigger
= {SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
218 /* Back End DAI links */
223 .cpu_dai_name
= "snd-soc-dummy-dai",
224 .platform_name
= "snd-soc-dummy",
226 .codec_name
= "i2c-INT343A:00",
227 .codec_dai_name
= "rt286-aif1",
228 .init
= broadwell_rt286_codec_init
,
229 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
230 SND_SOC_DAIFMT_CBS_CFS
,
232 .ignore_pmdown_time
= 1,
233 .be_hw_params_fixup
= broadwell_ssp0_fixup
,
234 .ops
= &broadwell_rt286_ops
,
240 /* broadwell audio machine driver for WPT + RT286S */
241 static struct snd_soc_card broadwell_rt286
= {
242 .name
= "broadwell-rt286",
243 .owner
= THIS_MODULE
,
244 .dai_link
= broadwell_rt286_dais
,
245 .num_links
= ARRAY_SIZE(broadwell_rt286_dais
),
246 .controls
= broadwell_controls
,
247 .num_controls
= ARRAY_SIZE(broadwell_controls
),
248 .dapm_widgets
= broadwell_widgets
,
249 .num_dapm_widgets
= ARRAY_SIZE(broadwell_widgets
),
250 .dapm_routes
= broadwell_rt286_map
,
251 .num_dapm_routes
= ARRAY_SIZE(broadwell_rt286_map
),
252 .fully_routed
= true,
255 static int broadwell_audio_probe(struct platform_device
*pdev
)
257 broadwell_rt286
.dev
= &pdev
->dev
;
259 return snd_soc_register_card(&broadwell_rt286
);
262 static int broadwell_audio_remove(struct platform_device
*pdev
)
264 snd_soc_unregister_card(&broadwell_rt286
);
268 static struct platform_driver broadwell_audio
= {
269 .probe
= broadwell_audio_probe
,
270 .remove
= broadwell_audio_remove
,
272 .name
= "broadwell-audio",
276 module_platform_driver(broadwell_audio
)
278 /* Module information */
279 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
280 MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
281 MODULE_LICENSE("GPL v2");
282 MODULE_ALIAS("platform:broadwell-audio");