| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * cht-bsw-nau8824.c - ASoc Machine driver for Intel Cherryview-based |
|---|
| 3 | 4 | * platforms Cherrytrail and Braswell, with nau8824 codec. |
|---|
| .. | .. |
|---|
| 8 | 9 | * Author: Wang, Joseph C <joequant@gmail.com> |
|---|
| 9 | 10 | * Co-author: John Hsu <KCHSU0@nuvoton.com> |
|---|
| 10 | 11 | * This file is based on cht_bsw_rt5672.c and cht-bsw-max98090.c |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 13 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 14 | | - * the Free Software Foundation; version 2 of the License. |
|---|
| 15 | | - * |
|---|
| 16 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 17 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 19 | | - * General Public License for more details. |
|---|
| 20 | 12 | */ |
|---|
| 21 | 13 | |
|---|
| 22 | 14 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 25 | 17 | #include <sound/pcm.h> |
|---|
| 26 | 18 | #include <sound/pcm_params.h> |
|---|
| 27 | 19 | #include <sound/soc.h> |
|---|
| 20 | +#include <sound/soc-acpi.h> |
|---|
| 28 | 21 | #include <sound/jack.h> |
|---|
| 29 | 22 | #include <linux/input.h> |
|---|
| 30 | 23 | #include "../atom/sst-atom-controls.h" |
|---|
| .. | .. |
|---|
| 79 | 72 | static int cht_aif1_hw_params(struct snd_pcm_substream *substream, |
|---|
| 80 | 73 | struct snd_pcm_hw_params *params) |
|---|
| 81 | 74 | { |
|---|
| 82 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
|---|
| 83 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
|---|
| 75 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 76 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
|---|
| 84 | 77 | int ret; |
|---|
| 85 | 78 | |
|---|
| 86 | 79 | ret = snd_soc_dai_set_sysclk(codec_dai, NAU8824_CLK_FLL_FS, 0, |
|---|
| .. | .. |
|---|
| 103 | 96 | { |
|---|
| 104 | 97 | struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card); |
|---|
| 105 | 98 | struct snd_soc_jack *jack = &ctx->jack; |
|---|
| 106 | | - struct snd_soc_dai *codec_dai = runtime->codec_dai; |
|---|
| 99 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0); |
|---|
| 107 | 100 | struct snd_soc_component *component = codec_dai->component; |
|---|
| 108 | 101 | int ret, jack_type; |
|---|
| 109 | 102 | |
|---|
| .. | .. |
|---|
| 115 | 108 | } |
|---|
| 116 | 109 | |
|---|
| 117 | 110 | /* NAU88L24 supports 4 butons headset detection |
|---|
| 118 | | - * KEY_MEDIA |
|---|
| 111 | + * KEY_PLAYPAUSE |
|---|
| 119 | 112 | * KEY_VOICECOMMAND |
|---|
| 120 | 113 | * KEY_VOLUMEUP |
|---|
| 121 | 114 | * KEY_VOLUMEDOWN |
|---|
| .. | .. |
|---|
| 129 | 122 | "Headset Jack creation failed %d\n", ret); |
|---|
| 130 | 123 | return ret; |
|---|
| 131 | 124 | } |
|---|
| 132 | | - snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA); |
|---|
| 125 | + snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
|---|
| 133 | 126 | snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); |
|---|
| 134 | 127 | snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); |
|---|
| 135 | 128 | snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); |
|---|
| .. | .. |
|---|
| 174 | 167 | .hw_params = cht_aif1_hw_params, |
|---|
| 175 | 168 | }; |
|---|
| 176 | 169 | |
|---|
| 170 | +SND_SOC_DAILINK_DEF(dummy, |
|---|
| 171 | + DAILINK_COMP_ARRAY(COMP_DUMMY())); |
|---|
| 172 | + |
|---|
| 173 | +SND_SOC_DAILINK_DEF(media, |
|---|
| 174 | + DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai"))); |
|---|
| 175 | + |
|---|
| 176 | +SND_SOC_DAILINK_DEF(deepbuffer, |
|---|
| 177 | + DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai"))); |
|---|
| 178 | + |
|---|
| 179 | +SND_SOC_DAILINK_DEF(compress, |
|---|
| 180 | + DAILINK_COMP_ARRAY(COMP_CPU("compress-cpu-dai"))); |
|---|
| 181 | + |
|---|
| 182 | +SND_SOC_DAILINK_DEF(ssp2_port, |
|---|
| 183 | + DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port"))); |
|---|
| 184 | +SND_SOC_DAILINK_DEF(ssp2_codec, |
|---|
| 185 | + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10508824:00", |
|---|
| 186 | + NAU8824_CODEC_DAI))); |
|---|
| 187 | + |
|---|
| 188 | +SND_SOC_DAILINK_DEF(platform, |
|---|
| 189 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform"))); |
|---|
| 190 | + |
|---|
| 177 | 191 | static struct snd_soc_dai_link cht_dailink[] = { |
|---|
| 178 | 192 | /* Front End DAI links */ |
|---|
| 179 | 193 | [MERR_DPCM_AUDIO] = { |
|---|
| 180 | 194 | .name = "Audio Port", |
|---|
| 181 | 195 | .stream_name = "Audio", |
|---|
| 182 | | - .cpu_dai_name = "media-cpu-dai", |
|---|
| 183 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 184 | | - .codec_name = "snd-soc-dummy", |
|---|
| 185 | | - .platform_name = "sst-mfld-platform", |
|---|
| 186 | 196 | .nonatomic = true, |
|---|
| 187 | 197 | .dynamic = 1, |
|---|
| 188 | 198 | .dpcm_playback = 1, |
|---|
| 189 | 199 | .dpcm_capture = 1, |
|---|
| 190 | 200 | .ops = &cht_aif1_ops, |
|---|
| 201 | + SND_SOC_DAILINK_REG(media, dummy, platform), |
|---|
| 191 | 202 | }, |
|---|
| 192 | 203 | [MERR_DPCM_DEEP_BUFFER] = { |
|---|
| 193 | 204 | .name = "Deep-Buffer Audio Port", |
|---|
| 194 | 205 | .stream_name = "Deep-Buffer Audio", |
|---|
| 195 | | - .cpu_dai_name = "deepbuffer-cpu-dai", |
|---|
| 196 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 197 | | - .codec_name = "snd-soc-dummy", |
|---|
| 198 | | - .platform_name = "sst-mfld-platform", |
|---|
| 199 | 206 | .nonatomic = true, |
|---|
| 200 | 207 | .dynamic = 1, |
|---|
| 201 | 208 | .dpcm_playback = 1, |
|---|
| 202 | 209 | .ops = &cht_aif1_ops, |
|---|
| 210 | + SND_SOC_DAILINK_REG(deepbuffer, dummy, platform), |
|---|
| 203 | 211 | }, |
|---|
| 204 | 212 | [MERR_DPCM_COMPR] = { |
|---|
| 205 | 213 | .name = "Compressed Port", |
|---|
| 206 | 214 | .stream_name = "Compress", |
|---|
| 207 | | - .cpu_dai_name = "compress-cpu-dai", |
|---|
| 208 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 209 | | - .codec_name = "snd-soc-dummy", |
|---|
| 210 | | - .platform_name = "sst-mfld-platform", |
|---|
| 215 | + SND_SOC_DAILINK_REG(compress, dummy, platform), |
|---|
| 211 | 216 | }, |
|---|
| 212 | 217 | /* Back End DAI links */ |
|---|
| 213 | 218 | { |
|---|
| 214 | 219 | /* SSP2 - Codec */ |
|---|
| 215 | 220 | .name = "SSP2-Codec", |
|---|
| 216 | 221 | .id = 1, |
|---|
| 217 | | - .cpu_dai_name = "ssp2-port", |
|---|
| 218 | | - .platform_name = "sst-mfld-platform", |
|---|
| 219 | 222 | .no_pcm = 1, |
|---|
| 220 | | - .codec_dai_name = NAU8824_CODEC_DAI, |
|---|
| 221 | | - .codec_name = "i2c-10508824:00", |
|---|
| 222 | 223 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF |
|---|
| 223 | 224 | | SND_SOC_DAIFMT_CBS_CFS, |
|---|
| 224 | 225 | .init = cht_codec_init, |
|---|
| .. | .. |
|---|
| 226 | 227 | .dpcm_playback = 1, |
|---|
| 227 | 228 | .dpcm_capture = 1, |
|---|
| 228 | 229 | .ops = &cht_be_ssp2_ops, |
|---|
| 230 | + SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform), |
|---|
| 229 | 231 | }, |
|---|
| 230 | 232 | }; |
|---|
| 231 | 233 | |
|---|
| 234 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
|---|
| 235 | +/* use space before codec name to simplify card ID, and simplify driver name */ |
|---|
| 236 | +#define CARD_NAME "bytcht nau8824" /* card name will be 'sof-bytcht nau8824 */ |
|---|
| 237 | +#define DRIVER_NAME "SOF" |
|---|
| 238 | +#else |
|---|
| 239 | +#define CARD_NAME "chtnau8824" |
|---|
| 240 | +#define DRIVER_NAME NULL /* card name will be used for driver name */ |
|---|
| 241 | +#endif |
|---|
| 242 | + |
|---|
| 232 | 243 | /* SoC card */ |
|---|
| 233 | 244 | static struct snd_soc_card snd_soc_card_cht = { |
|---|
| 234 | | - .name = "chtnau8824", |
|---|
| 245 | + .name = CARD_NAME, |
|---|
| 246 | + .driver_name = DRIVER_NAME, |
|---|
| 235 | 247 | .owner = THIS_MODULE, |
|---|
| 236 | 248 | .dai_link = cht_dailink, |
|---|
| 237 | 249 | .num_links = ARRAY_SIZE(cht_dailink), |
|---|
| .. | .. |
|---|
| 246 | 258 | static int snd_cht_mc_probe(struct platform_device *pdev) |
|---|
| 247 | 259 | { |
|---|
| 248 | 260 | struct cht_mc_private *drv; |
|---|
| 261 | + struct snd_soc_acpi_mach *mach; |
|---|
| 262 | + const char *platform_name; |
|---|
| 249 | 263 | int ret_val; |
|---|
| 250 | 264 | |
|---|
| 251 | 265 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 253 | 267 | return -ENOMEM; |
|---|
| 254 | 268 | snd_soc_card_set_drvdata(&snd_soc_card_cht, drv); |
|---|
| 255 | 269 | |
|---|
| 256 | | - /* register the soc card */ |
|---|
| 270 | + /* override plaform name, if required */ |
|---|
| 257 | 271 | snd_soc_card_cht.dev = &pdev->dev; |
|---|
| 272 | + mach = pdev->dev.platform_data; |
|---|
| 273 | + platform_name = mach->mach_params.platform; |
|---|
| 274 | + |
|---|
| 275 | + ret_val = snd_soc_fixup_dai_links_platform_name(&snd_soc_card_cht, |
|---|
| 276 | + platform_name); |
|---|
| 277 | + if (ret_val) |
|---|
| 278 | + return ret_val; |
|---|
| 279 | + |
|---|
| 280 | + /* register the soc card */ |
|---|
| 258 | 281 | ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cht); |
|---|
| 259 | 282 | if (ret_val) { |
|---|
| 260 | 283 | dev_err(&pdev->dev, |
|---|
| .. | .. |
|---|
| 269 | 292 | static struct platform_driver snd_cht_mc_driver = { |
|---|
| 270 | 293 | .driver = { |
|---|
| 271 | 294 | .name = "cht-bsw-nau8824", |
|---|
| 295 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
|---|
| 296 | + .pm = &snd_soc_pm_ops, |
|---|
| 297 | +#endif |
|---|
| 272 | 298 | }, |
|---|
| 273 | 299 | .probe = snd_cht_mc_probe, |
|---|
| 274 | 300 | }; |
|---|