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 | |
Jie Yang | e56c72d | 2015-04-02 15:37:02 +0800 | [diff] [blame] | 25 | #include "../common/sst-dsp.h" |
| 26 | #include "../haswell/sst-haswell-ipc.h" |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 27 | |
Jie Yang | e56c72d | 2015-04-02 15:37:02 +0800 | [diff] [blame] | 28 | #include "../../codecs/rt286.h" |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 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 | { |
Kuninori Morimoto | 4510112 | 2018-01-29 04:36:54 +0000 | [diff] [blame] | 81 | struct snd_soc_component *component = rtd->codec_dai->component; |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 82 | int ret = 0; |
Lars-Peter Clausen | 85c85e5 | 2015-03-04 10:33:21 +0100 | [diff] [blame] | 83 | 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 Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 86 | if (ret) |
| 87 | return ret; |
| 88 | |
Kuninori Morimoto | 4510112 | 2018-01-29 04:36:54 +0000 | [diff] [blame] | 89 | rt286_mic_detect(component, &broadwell_headset); |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 94 | static 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 */ |
Fang, Yang A | 369a9f5 | 2015-02-09 00:18:12 -0800 | [diff] [blame] | 107 | params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream, |
| 112 | struct snd_pcm_hw_params *params) |
| 113 | { |
| 114 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 115 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 116 | int ret; |
| 117 | |
| 118 | ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, |
| 119 | SND_SOC_CLOCK_IN); |
| 120 | |
| 121 | if (ret < 0) { |
| 122 | dev_err(rtd->dev, "can't set codec sysclk configuration\n"); |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | return ret; |
| 127 | } |
| 128 | |
Julia Lawall | d5bc18c | 2016-10-15 16:55:45 +0200 | [diff] [blame] | 129 | static const struct snd_soc_ops broadwell_rt286_ops = { |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 130 | .hw_params = broadwell_rt286_hw_params, |
| 131 | }; |
| 132 | |
| 133 | static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd) |
| 134 | { |
Kuninori Morimoto | 2ee178d | 2018-01-29 02:42:21 +0000 | [diff] [blame] | 135 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 136 | struct sst_pdata *pdata = dev_get_platdata(component->dev); |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 137 | struct sst_hsw *broadwell = pdata->dsp; |
| 138 | int ret; |
| 139 | |
| 140 | /* Set ADSP SSP port settings */ |
| 141 | ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0, |
| 142 | SST_HSW_DEVICE_MCLK_FREQ_24_MHZ, |
| 143 | SST_HSW_DEVICE_CLOCK_MASTER, 9); |
| 144 | if (ret < 0) { |
| 145 | dev_err(rtd->dev, "error: failed to set device config\n"); |
| 146 | return ret; |
| 147 | } |
| 148 | |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | /* broadwell digital audio interface glue - connects codec <--> CPU */ |
| 153 | static struct snd_soc_dai_link broadwell_rt286_dais[] = { |
| 154 | /* Front End DAI links */ |
| 155 | { |
| 156 | .name = "System PCM", |
Jie Yang | 7bb73cb | 2014-11-28 21:52:11 +0800 | [diff] [blame] | 157 | .stream_name = "System Playback/Capture", |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 158 | .cpu_dai_name = "System 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 | .init = broadwell_rtd_init, |
| 164 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 165 | .dpcm_playback = 1, |
Jie Yang | 7bb73cb | 2014-11-28 21:52:11 +0800 | [diff] [blame] | 166 | .dpcm_capture = 1, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 167 | }, |
| 168 | { |
| 169 | .name = "Offload0", |
| 170 | .stream_name = "Offload0 Playback", |
| 171 | .cpu_dai_name = "Offload0 Pin", |
| 172 | .platform_name = "haswell-pcm-audio", |
| 173 | .dynamic = 1, |
| 174 | .codec_name = "snd-soc-dummy", |
| 175 | .codec_dai_name = "snd-soc-dummy-dai", |
| 176 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 177 | .dpcm_playback = 1, |
| 178 | }, |
| 179 | { |
| 180 | .name = "Offload1", |
| 181 | .stream_name = "Offload1 Playback", |
| 182 | .cpu_dai_name = "Offload1 Pin", |
| 183 | .platform_name = "haswell-pcm-audio", |
| 184 | .dynamic = 1, |
| 185 | .codec_name = "snd-soc-dummy", |
| 186 | .codec_dai_name = "snd-soc-dummy-dai", |
| 187 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 188 | .dpcm_playback = 1, |
| 189 | }, |
| 190 | { |
| 191 | .name = "Loopback PCM", |
| 192 | .stream_name = "Loopback", |
| 193 | .cpu_dai_name = "Loopback Pin", |
| 194 | .platform_name = "haswell-pcm-audio", |
Rander Wang | 906a9ab | 2018-12-18 16:24:54 +0800 | [diff] [blame^] | 195 | .dynamic = 1, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 196 | .codec_name = "snd-soc-dummy", |
| 197 | .codec_dai_name = "snd-soc-dummy-dai", |
| 198 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
| 199 | .dpcm_capture = 1, |
| 200 | }, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 201 | /* Back End DAI links */ |
| 202 | { |
| 203 | /* SSP0 - Codec */ |
| 204 | .name = "Codec", |
Mengdong Lin | 2f0ad49 | 2016-04-19 13:12:35 +0800 | [diff] [blame] | 205 | .id = 0, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 206 | .cpu_dai_name = "snd-soc-dummy-dai", |
| 207 | .platform_name = "snd-soc-dummy", |
| 208 | .no_pcm = 1, |
| 209 | .codec_name = "i2c-INT343A:00", |
| 210 | .codec_dai_name = "rt286-aif1", |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 211 | .init = broadwell_rt286_codec_init, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 212 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 213 | SND_SOC_DAIFMT_CBS_CFS, |
| 214 | .ignore_suspend = 1, |
| 215 | .ignore_pmdown_time = 1, |
| 216 | .be_hw_params_fixup = broadwell_ssp0_fixup, |
| 217 | .ops = &broadwell_rt286_ops, |
| 218 | .dpcm_playback = 1, |
| 219 | .dpcm_capture = 1, |
| 220 | }, |
| 221 | }; |
| 222 | |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame] | 223 | static int broadwell_suspend(struct snd_soc_card *card){ |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 224 | struct snd_soc_component *component; |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame] | 225 | |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 226 | for_each_card_components(card, component) { |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 227 | if (!strcmp(component->name, "i2c-INT343A:00")) { |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 228 | |
Kuninori Morimoto | 4510112 | 2018-01-29 04:36:54 +0000 | [diff] [blame] | 229 | dev_dbg(component->dev, "disabling jack detect before going to suspend.\n"); |
| 230 | rt286_mic_detect(component, NULL); |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int broadwell_resume(struct snd_soc_card *card){ |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 238 | struct snd_soc_component *component; |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame] | 239 | |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 240 | for_each_card_components(card, component) { |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 241 | if (!strcmp(component->name, "i2c-INT343A:00")) { |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 242 | |
Kuninori Morimoto | 4510112 | 2018-01-29 04:36:54 +0000 | [diff] [blame] | 243 | dev_dbg(component->dev, "enabling jack detect for resume.\n"); |
| 244 | rt286_mic_detect(component, &broadwell_headset); |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame] | 245 | break; |
| 246 | } |
| 247 | } |
| 248 | return 0; |
| 249 | } |
| 250 | |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 251 | /* broadwell audio machine driver for WPT + RT286S */ |
| 252 | static struct snd_soc_card broadwell_rt286 = { |
| 253 | .name = "broadwell-rt286", |
| 254 | .owner = THIS_MODULE, |
| 255 | .dai_link = broadwell_rt286_dais, |
| 256 | .num_links = ARRAY_SIZE(broadwell_rt286_dais), |
Jie Yang | c1e99c9 | 2014-10-30 21:16:23 +0800 | [diff] [blame] | 257 | .controls = broadwell_controls, |
| 258 | .num_controls = ARRAY_SIZE(broadwell_controls), |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 259 | .dapm_widgets = broadwell_widgets, |
| 260 | .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets), |
| 261 | .dapm_routes = broadwell_rt286_map, |
| 262 | .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map), |
| 263 | .fully_routed = true, |
Jie Yang | 1a5ab21c | 2015-02-27 12:54:29 +0800 | [diff] [blame] | 264 | .suspend_pre = broadwell_suspend, |
| 265 | .resume_post = broadwell_resume, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | static int broadwell_audio_probe(struct platform_device *pdev) |
| 269 | { |
| 270 | broadwell_rt286.dev = &pdev->dev; |
Axel Lin | 9ed7476 | 2015-09-02 12:01:27 +0800 | [diff] [blame] | 271 | return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286); |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static struct platform_driver broadwell_audio = { |
| 275 | .probe = broadwell_audio_probe, |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 276 | .driver = { |
| 277 | .name = "broadwell-audio", |
Liam Girdwood | afdb74f | 2014-07-14 10:35:40 +0800 | [diff] [blame] | 278 | }, |
| 279 | }; |
| 280 | |
| 281 | module_platform_driver(broadwell_audio) |
| 282 | |
| 283 | /* Module information */ |
| 284 | MODULE_AUTHOR("Liam Girdwood, Xingchao Wang"); |
| 285 | MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell"); |
| 286 | MODULE_LICENSE("GPL v2"); |
| 287 | MODULE_ALIAS("platform:broadwell-audio"); |