| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Intel Broadwell Wildcatpoint SST Audio |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 17 | 8 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 21 | 12 | #include <sound/soc.h> |
|---|
| 22 | 13 | #include <sound/jack.h> |
|---|
| 23 | 14 | #include <sound/pcm_params.h> |
|---|
| 24 | | - |
|---|
| 25 | | -#include "../common/sst-dsp.h" |
|---|
| 26 | | -#include "../haswell/sst-haswell-ipc.h" |
|---|
| 15 | +#include <sound/soc-acpi.h> |
|---|
| 27 | 16 | |
|---|
| 28 | 17 | #include "../../codecs/rt286.h" |
|---|
| 29 | 18 | |
|---|
| .. | .. |
|---|
| 78 | 67 | |
|---|
| 79 | 68 | static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd) |
|---|
| 80 | 69 | { |
|---|
| 81 | | - struct snd_soc_component *component = rtd->codec_dai->component; |
|---|
| 70 | + struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; |
|---|
| 82 | 71 | int ret = 0; |
|---|
| 83 | 72 | ret = snd_soc_card_jack_new(rtd->card, "Headset", |
|---|
| 84 | 73 | SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset, |
|---|
| .. | .. |
|---|
| 95 | 84 | struct snd_pcm_hw_params *params) |
|---|
| 96 | 85 | { |
|---|
| 97 | 86 | 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); |
|---|
| 87 | + SNDRV_PCM_HW_PARAM_RATE); |
|---|
| 88 | + struct snd_interval *chan = hw_param_interval(params, |
|---|
| 89 | + SNDRV_PCM_HW_PARAM_CHANNELS); |
|---|
| 101 | 90 | |
|---|
| 102 | 91 | /* The ADSP will covert the FE rate to 48k, stereo */ |
|---|
| 103 | 92 | rate->min = rate->max = 48000; |
|---|
| 104 | | - channels->min = channels->max = 2; |
|---|
| 93 | + chan->min = chan->max = 2; |
|---|
| 105 | 94 | |
|---|
| 106 | 95 | /* set SSP0 to 16 bit */ |
|---|
| 107 | 96 | params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); |
|---|
| .. | .. |
|---|
| 111 | 100 | static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream, |
|---|
| 112 | 101 | struct snd_pcm_hw_params *params) |
|---|
| 113 | 102 | { |
|---|
| 114 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
|---|
| 115 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
|---|
| 103 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 104 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
|---|
| 116 | 105 | int ret; |
|---|
| 117 | 106 | |
|---|
| 118 | 107 | ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, |
|---|
| .. | .. |
|---|
| 130 | 119 | .hw_params = broadwell_rt286_hw_params, |
|---|
| 131 | 120 | }; |
|---|
| 132 | 121 | |
|---|
| 133 | | -static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd) |
|---|
| 122 | +static const unsigned int channels[] = { |
|---|
| 123 | + 2, |
|---|
| 124 | +}; |
|---|
| 125 | + |
|---|
| 126 | +static const struct snd_pcm_hw_constraint_list constraints_channels = { |
|---|
| 127 | + .count = ARRAY_SIZE(channels), |
|---|
| 128 | + .list = channels, |
|---|
| 129 | + .mask = 0, |
|---|
| 130 | +}; |
|---|
| 131 | + |
|---|
| 132 | +static int broadwell_fe_startup(struct snd_pcm_substream *substream) |
|---|
| 134 | 133 | { |
|---|
| 135 | | - struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
|---|
| 136 | | - struct sst_pdata *pdata = dev_get_platdata(component->dev); |
|---|
| 137 | | - struct sst_hsw *broadwell = pdata->dsp; |
|---|
| 138 | | - int ret; |
|---|
| 134 | + struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| 139 | 135 | |
|---|
| 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 | | - |
|---|
| 149 | | - return 0; |
|---|
| 136 | + /* Board supports stereo configuration only */ |
|---|
| 137 | + runtime->hw.channels_max = 2; |
|---|
| 138 | + return snd_pcm_hw_constraint_list(runtime, 0, |
|---|
| 139 | + SNDRV_PCM_HW_PARAM_CHANNELS, |
|---|
| 140 | + &constraints_channels); |
|---|
| 150 | 141 | } |
|---|
| 142 | + |
|---|
| 143 | +static const struct snd_soc_ops broadwell_fe_ops = { |
|---|
| 144 | + .startup = broadwell_fe_startup, |
|---|
| 145 | +}; |
|---|
| 146 | + |
|---|
| 147 | +SND_SOC_DAILINK_DEF(system, |
|---|
| 148 | + DAILINK_COMP_ARRAY(COMP_CPU("System Pin"))); |
|---|
| 149 | + |
|---|
| 150 | +SND_SOC_DAILINK_DEF(offload0, |
|---|
| 151 | + DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin"))); |
|---|
| 152 | + |
|---|
| 153 | +SND_SOC_DAILINK_DEF(offload1, |
|---|
| 154 | + DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin"))); |
|---|
| 155 | + |
|---|
| 156 | +SND_SOC_DAILINK_DEF(loopback, |
|---|
| 157 | + DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin"))); |
|---|
| 158 | + |
|---|
| 159 | +SND_SOC_DAILINK_DEF(dummy, |
|---|
| 160 | + DAILINK_COMP_ARRAY(COMP_DUMMY())); |
|---|
| 161 | + |
|---|
| 162 | +SND_SOC_DAILINK_DEF(platform, |
|---|
| 163 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio"))); |
|---|
| 164 | + |
|---|
| 165 | +SND_SOC_DAILINK_DEF(codec, |
|---|
| 166 | + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00", "rt286-aif1"))); |
|---|
| 167 | + |
|---|
| 168 | +SND_SOC_DAILINK_DEF(ssp0_port, |
|---|
| 169 | + DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port"))); |
|---|
| 151 | 170 | |
|---|
| 152 | 171 | /* broadwell digital audio interface glue - connects codec <--> CPU */ |
|---|
| 153 | 172 | static struct snd_soc_dai_link broadwell_rt286_dais[] = { |
|---|
| .. | .. |
|---|
| 155 | 174 | { |
|---|
| 156 | 175 | .name = "System PCM", |
|---|
| 157 | 176 | .stream_name = "System Playback/Capture", |
|---|
| 158 | | - .cpu_dai_name = "System Pin", |
|---|
| 159 | | - .platform_name = "haswell-pcm-audio", |
|---|
| 177 | + .nonatomic = 1, |
|---|
| 160 | 178 | .dynamic = 1, |
|---|
| 161 | | - .codec_name = "snd-soc-dummy", |
|---|
| 162 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 163 | | - .init = broadwell_rtd_init, |
|---|
| 164 | 179 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
|---|
| 180 | + .ops = &broadwell_fe_ops, |
|---|
| 165 | 181 | .dpcm_playback = 1, |
|---|
| 166 | 182 | .dpcm_capture = 1, |
|---|
| 183 | + SND_SOC_DAILINK_REG(system, dummy, platform), |
|---|
| 167 | 184 | }, |
|---|
| 168 | 185 | { |
|---|
| 169 | 186 | .name = "Offload0", |
|---|
| 170 | 187 | .stream_name = "Offload0 Playback", |
|---|
| 171 | | - .cpu_dai_name = "Offload0 Pin", |
|---|
| 172 | | - .platform_name = "haswell-pcm-audio", |
|---|
| 188 | + .nonatomic = 1, |
|---|
| 173 | 189 | .dynamic = 1, |
|---|
| 174 | | - .codec_name = "snd-soc-dummy", |
|---|
| 175 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 176 | 190 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
|---|
| 177 | 191 | .dpcm_playback = 1, |
|---|
| 192 | + SND_SOC_DAILINK_REG(offload0, dummy, platform), |
|---|
| 178 | 193 | }, |
|---|
| 179 | 194 | { |
|---|
| 180 | 195 | .name = "Offload1", |
|---|
| 181 | 196 | .stream_name = "Offload1 Playback", |
|---|
| 182 | | - .cpu_dai_name = "Offload1 Pin", |
|---|
| 183 | | - .platform_name = "haswell-pcm-audio", |
|---|
| 197 | + .nonatomic = 1, |
|---|
| 184 | 198 | .dynamic = 1, |
|---|
| 185 | | - .codec_name = "snd-soc-dummy", |
|---|
| 186 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 187 | 199 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
|---|
| 188 | 200 | .dpcm_playback = 1, |
|---|
| 201 | + SND_SOC_DAILINK_REG(offload1, dummy, platform), |
|---|
| 189 | 202 | }, |
|---|
| 190 | 203 | { |
|---|
| 191 | 204 | .name = "Loopback PCM", |
|---|
| 192 | 205 | .stream_name = "Loopback", |
|---|
| 193 | | - .cpu_dai_name = "Loopback Pin", |
|---|
| 194 | | - .platform_name = "haswell-pcm-audio", |
|---|
| 206 | + .nonatomic = 1, |
|---|
| 195 | 207 | .dynamic = 1, |
|---|
| 196 | | - .codec_name = "snd-soc-dummy", |
|---|
| 197 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 198 | 208 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, |
|---|
| 199 | 209 | .dpcm_capture = 1, |
|---|
| 210 | + SND_SOC_DAILINK_REG(loopback, dummy, platform), |
|---|
| 200 | 211 | }, |
|---|
| 201 | 212 | /* Back End DAI links */ |
|---|
| 202 | 213 | { |
|---|
| 203 | 214 | /* SSP0 - Codec */ |
|---|
| 204 | 215 | .name = "Codec", |
|---|
| 205 | 216 | .id = 0, |
|---|
| 206 | | - .cpu_dai_name = "snd-soc-dummy-dai", |
|---|
| 207 | | - .platform_name = "snd-soc-dummy", |
|---|
| 208 | 217 | .no_pcm = 1, |
|---|
| 209 | | - .codec_name = "i2c-INT343A:00", |
|---|
| 210 | | - .codec_dai_name = "rt286-aif1", |
|---|
| 211 | 218 | .init = broadwell_rt286_codec_init, |
|---|
| 212 | 219 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
|---|
| 213 | 220 | SND_SOC_DAIFMT_CBS_CFS, |
|---|
| 214 | | - .ignore_suspend = 1, |
|---|
| 215 | 221 | .ignore_pmdown_time = 1, |
|---|
| 216 | 222 | .be_hw_params_fixup = broadwell_ssp0_fixup, |
|---|
| 217 | 223 | .ops = &broadwell_rt286_ops, |
|---|
| 218 | 224 | .dpcm_playback = 1, |
|---|
| 219 | 225 | .dpcm_capture = 1, |
|---|
| 226 | + SND_SOC_DAILINK_REG(ssp0_port, codec, platform), |
|---|
| 220 | 227 | }, |
|---|
| 221 | 228 | }; |
|---|
| 222 | 229 | |
|---|
| 223 | | -static int broadwell_suspend(struct snd_soc_card *card){ |
|---|
| 230 | +static int broadwell_disable_jack(struct snd_soc_card *card) |
|---|
| 231 | +{ |
|---|
| 224 | 232 | struct snd_soc_component *component; |
|---|
| 225 | 233 | |
|---|
| 226 | | - list_for_each_entry(component, &card->component_dev_list, card_list) { |
|---|
| 234 | + for_each_card_components(card, component) { |
|---|
| 227 | 235 | if (!strcmp(component->name, "i2c-INT343A:00")) { |
|---|
| 228 | 236 | |
|---|
| 229 | 237 | dev_dbg(component->dev, "disabling jack detect before going to suspend.\n"); |
|---|
| .. | .. |
|---|
| 231 | 239 | break; |
|---|
| 232 | 240 | } |
|---|
| 233 | 241 | } |
|---|
| 242 | + |
|---|
| 234 | 243 | return 0; |
|---|
| 244 | +} |
|---|
| 245 | + |
|---|
| 246 | +static int broadwell_suspend(struct snd_soc_card *card) |
|---|
| 247 | +{ |
|---|
| 248 | + return broadwell_disable_jack(card); |
|---|
| 235 | 249 | } |
|---|
| 236 | 250 | |
|---|
| 237 | 251 | static int broadwell_resume(struct snd_soc_card *card){ |
|---|
| 238 | 252 | struct snd_soc_component *component; |
|---|
| 239 | 253 | |
|---|
| 240 | | - list_for_each_entry(component, &card->component_dev_list, card_list) { |
|---|
| 254 | + for_each_card_components(card, component) { |
|---|
| 241 | 255 | if (!strcmp(component->name, "i2c-INT343A:00")) { |
|---|
| 242 | 256 | |
|---|
| 243 | 257 | dev_dbg(component->dev, "enabling jack detect for resume.\n"); |
|---|
| .. | .. |
|---|
| 248 | 262 | return 0; |
|---|
| 249 | 263 | } |
|---|
| 250 | 264 | |
|---|
| 265 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) |
|---|
| 266 | +/* use space before codec name to simplify card ID, and simplify driver name */ |
|---|
| 267 | +#define CARD_NAME "bdw rt286" /* card name will be 'sof-bdw rt286' */ |
|---|
| 268 | +#define DRIVER_NAME "SOF" |
|---|
| 269 | +#else |
|---|
| 270 | +#define CARD_NAME "broadwell-rt286" |
|---|
| 271 | +#define DRIVER_NAME NULL /* card name will be used for driver name */ |
|---|
| 272 | +#endif |
|---|
| 273 | + |
|---|
| 251 | 274 | /* broadwell audio machine driver for WPT + RT286S */ |
|---|
| 252 | 275 | static struct snd_soc_card broadwell_rt286 = { |
|---|
| 253 | | - .name = "broadwell-rt286", |
|---|
| 276 | + .name = CARD_NAME, |
|---|
| 277 | + .driver_name = DRIVER_NAME, |
|---|
| 254 | 278 | .owner = THIS_MODULE, |
|---|
| 255 | 279 | .dai_link = broadwell_rt286_dais, |
|---|
| 256 | 280 | .num_links = ARRAY_SIZE(broadwell_rt286_dais), |
|---|
| .. | .. |
|---|
| 267 | 291 | |
|---|
| 268 | 292 | static int broadwell_audio_probe(struct platform_device *pdev) |
|---|
| 269 | 293 | { |
|---|
| 294 | + struct snd_soc_acpi_mach *mach; |
|---|
| 295 | + int ret; |
|---|
| 296 | + |
|---|
| 270 | 297 | broadwell_rt286.dev = &pdev->dev; |
|---|
| 298 | + |
|---|
| 299 | + /* override plaform name, if required */ |
|---|
| 300 | + mach = pdev->dev.platform_data; |
|---|
| 301 | + ret = snd_soc_fixup_dai_links_platform_name(&broadwell_rt286, |
|---|
| 302 | + mach->mach_params.platform); |
|---|
| 303 | + if (ret) |
|---|
| 304 | + return ret; |
|---|
| 305 | + |
|---|
| 271 | 306 | return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286); |
|---|
| 307 | +} |
|---|
| 308 | + |
|---|
| 309 | +static int broadwell_audio_remove(struct platform_device *pdev) |
|---|
| 310 | +{ |
|---|
| 311 | + struct snd_soc_card *card = platform_get_drvdata(pdev); |
|---|
| 312 | + |
|---|
| 313 | + return broadwell_disable_jack(card); |
|---|
| 272 | 314 | } |
|---|
| 273 | 315 | |
|---|
| 274 | 316 | static struct platform_driver broadwell_audio = { |
|---|
| 275 | 317 | .probe = broadwell_audio_probe, |
|---|
| 318 | + .remove = broadwell_audio_remove, |
|---|
| 276 | 319 | .driver = { |
|---|
| 277 | 320 | .name = "broadwell-audio", |
|---|
| 278 | 321 | }, |
|---|