Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 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> |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 22 | #include <sound/jack.h> |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 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 | |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 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 | |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 48 | static const struct snd_soc_dapm_widget broadwell_widgets[] = { |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 49 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 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 */ |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 64 | {"Headphone Jack", NULL, "HPO Pin"}, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 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 | |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 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 | |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 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 */ |
Fang, Yang A | 369a9f5 | 2015-02-09 00:18:12 -0800 | [diff] [blame] | 113 | params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream, |
| 118 | struct snd_pcm_hw_params *params) |
| 119 | { |
| 120 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 121 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 122 | int ret; |
| 123 | |
| 124 | ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, |
| 125 | SND_SOC_CLOCK_IN); |
| 126 | |
| 127 | if (ret < 0) { |
| 128 | dev_err(rtd->dev, "can't set codec sysclk configuration\n"); |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | static struct snd_soc_ops broadwell_rt286_ops = { |
| 136 | .hw_params = broadwell_rt286_hw_params, |
| 137 | }; |
| 138 | |
| 139 | static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd) |
| 140 | { |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 141 | struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev); |
| 142 | struct sst_hsw *broadwell = pdata->dsp; |
| 143 | int ret; |
| 144 | |
| 145 | /* Set ADSP SSP port settings */ |
| 146 | ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0, |
| 147 | SST_HSW_DEVICE_MCLK_FREQ_24_MHZ, |
| 148 | SST_HSW_DEVICE_CLOCK_MASTER, 9); |
| 149 | if (ret < 0) { |
| 150 | dev_err(rtd->dev, "error: failed to set device config\n"); |
| 151 | return ret; |
| 152 | } |
| 153 | |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | /* broadwell digital audio interface glue - connects codec <--> CPU */ |
| 158 | static struct snd_soc_dai_link broadwell_rt286_dais[] = { |
| 159 | /* Front End DAI links */ |
| 160 | { |
| 161 | .name = "System PCM", |
Jie Yang | 7bb73cb | 2014-11-28 21:52:11 +0800 | [diff] [blame] | 162 | .stream_name = "System Playback/Capture", |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 163 | .cpu_dai_name = "System Pin", |
| 164 | .platform_name = "haswell-pcm-audio", |
| 165 | .dynamic = 1, |
| 166 | .codec_name = "snd-soc-dummy", |
| 167 | .codec_dai_name = "snd-soc-dummy-dai", |
| 168 | .init = broadwell_rtd_init, |
| 169 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 170 | .dpcm_playback = 1, |
Jie Yang | 7bb73cb | 2014-11-28 21:52:11 +0800 | [diff] [blame] | 171 | .dpcm_capture = 1, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 172 | }, |
| 173 | { |
| 174 | .name = "Offload0", |
| 175 | .stream_name = "Offload0 Playback", |
| 176 | .cpu_dai_name = "Offload0 Pin", |
| 177 | .platform_name = "haswell-pcm-audio", |
| 178 | .dynamic = 1, |
| 179 | .codec_name = "snd-soc-dummy", |
| 180 | .codec_dai_name = "snd-soc-dummy-dai", |
| 181 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 182 | .dpcm_playback = 1, |
| 183 | }, |
| 184 | { |
| 185 | .name = "Offload1", |
| 186 | .stream_name = "Offload1 Playback", |
| 187 | .cpu_dai_name = "Offload1 Pin", |
| 188 | .platform_name = "haswell-pcm-audio", |
| 189 | .dynamic = 1, |
| 190 | .codec_name = "snd-soc-dummy", |
| 191 | .codec_dai_name = "snd-soc-dummy-dai", |
| 192 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 193 | .dpcm_playback = 1, |
| 194 | }, |
| 195 | { |
| 196 | .name = "Loopback PCM", |
| 197 | .stream_name = "Loopback", |
| 198 | .cpu_dai_name = "Loopback Pin", |
| 199 | .platform_name = "haswell-pcm-audio", |
| 200 | .dynamic = 0, |
| 201 | .codec_name = "snd-soc-dummy", |
| 202 | .codec_dai_name = "snd-soc-dummy-dai", |
| 203 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 204 | .dpcm_capture = 1, |
| 205 | }, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 206 | /* Back End DAI links */ |
| 207 | { |
| 208 | /* SSP0 - Codec */ |
| 209 | .name = "Codec", |
| 210 | .be_id = 0, |
| 211 | .cpu_dai_name = "snd-soc-dummy-dai", |
| 212 | .platform_name = "snd-soc-dummy", |
| 213 | .no_pcm = 1, |
| 214 | .codec_name = "i2c-INT343A:00", |
| 215 | .codec_dai_name = "rt286-aif1", |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 216 | .init = broadwell_rt286_codec_init, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 217 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 218 | SND_SOC_DAIFMT_CBS_CFS, |
| 219 | .ignore_suspend = 1, |
| 220 | .ignore_pmdown_time = 1, |
| 221 | .be_hw_params_fixup = broadwell_ssp0_fixup, |
| 222 | .ops = &broadwell_rt286_ops, |
| 223 | .dpcm_playback = 1, |
| 224 | .dpcm_capture = 1, |
| 225 | }, |
| 226 | }; |
| 227 | |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame^] | 228 | static int broadwell_suspend(struct snd_soc_card *card){ |
| 229 | struct snd_soc_codec *codec; |
| 230 | |
| 231 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
| 232 | if (!strcmp(codec->component.name, "i2c-INT343A:00")) { |
| 233 | dev_dbg(codec->dev, "disabling jack detect before going to suspend.\n"); |
| 234 | rt286_mic_detect(codec, NULL); |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int broadwell_resume(struct snd_soc_card *card){ |
| 242 | struct snd_soc_codec *codec; |
| 243 | |
| 244 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
| 245 | if (!strcmp(codec->component.name, "i2c-INT343A:00")) { |
| 246 | dev_dbg(codec->dev, "enabling jack detect for resume.\n"); |
| 247 | rt286_mic_detect(codec, &broadwell_headset); |
| 248 | break; |
| 249 | } |
| 250 | } |
| 251 | return 0; |
| 252 | } |
| 253 | |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 254 | /* broadwell audio machine driver for WPT + RT286S */ |
| 255 | static struct snd_soc_card broadwell_rt286 = { |
| 256 | .name = "broadwell-rt286", |
| 257 | .owner = THIS_MODULE, |
| 258 | .dai_link = broadwell_rt286_dais, |
| 259 | .num_links = ARRAY_SIZE(broadwell_rt286_dais), |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 260 | .controls = broadwell_controls, |
| 261 | .num_controls = ARRAY_SIZE(broadwell_controls), |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 262 | .dapm_widgets = broadwell_widgets, |
| 263 | .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets), |
| 264 | .dapm_routes = broadwell_rt286_map, |
| 265 | .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map), |
| 266 | .fully_routed = true, |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame^] | 267 | .suspend_pre = broadwell_suspend, |
| 268 | .resume_post = broadwell_resume, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | static int broadwell_audio_probe(struct platform_device *pdev) |
| 272 | { |
| 273 | broadwell_rt286.dev = &pdev->dev; |
| 274 | |
| 275 | return snd_soc_register_card(&broadwell_rt286); |
| 276 | } |
| 277 | |
| 278 | static int broadwell_audio_remove(struct platform_device *pdev) |
| 279 | { |
| 280 | snd_soc_unregister_card(&broadwell_rt286); |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static struct platform_driver broadwell_audio = { |
| 285 | .probe = broadwell_audio_probe, |
| 286 | .remove = broadwell_audio_remove, |
| 287 | .driver = { |
| 288 | .name = "broadwell-audio", |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 289 | }, |
| 290 | }; |
| 291 | |
| 292 | module_platform_driver(broadwell_audio) |
| 293 | |
| 294 | /* Module information */ |
| 295 | MODULE_AUTHOR("Liam Girdwood, Xingchao Wang"); |
| 296 | MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell"); |
| 297 | MODULE_LICENSE("GPL v2"); |
| 298 | MODULE_ALIAS("platform:broadwell-audio"); |