.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * bytcht-da7213.c - ASoc Machine driver for Intel Baytrail and |
---|
3 | 4 | * Cherrytrail-based platforms, with Dialog DA7213 codec |
---|
.. | .. |
---|
7 | 8 | * |
---|
8 | 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
9 | 10 | * |
---|
10 | | - * This program is free software; you can redistribute it and/or modify |
---|
11 | | - * it under the terms of the GNU General Public License as published by |
---|
12 | | - * the Free Software Foundation; version 2 of the License. |
---|
13 | | - * |
---|
14 | | - * This program is distributed in the hope that it will be useful, but |
---|
15 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | | - * General Public License for more details. |
---|
18 | | - * |
---|
19 | 11 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
20 | 12 | */ |
---|
21 | 13 | |
---|
.. | .. |
---|
23 | 15 | #include <linux/acpi.h> |
---|
24 | 16 | #include <linux/platform_device.h> |
---|
25 | 17 | #include <linux/slab.h> |
---|
26 | | -#include <asm/platform_sst_audio.h> |
---|
27 | 18 | #include <sound/pcm.h> |
---|
28 | 19 | #include <sound/pcm_params.h> |
---|
29 | 20 | #include <sound/soc.h> |
---|
.. | .. |
---|
87 | 78 | * with explicit setting to I2S 2ch 24-bit. The word length is set with |
---|
88 | 79 | * dai_set_tdm_slot() since there is no other API exposed |
---|
89 | 80 | */ |
---|
90 | | - ret = snd_soc_dai_set_fmt(rtd->cpu_dai, |
---|
| 81 | + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0), |
---|
91 | 82 | SND_SOC_DAIFMT_I2S | |
---|
92 | 83 | SND_SOC_DAIFMT_NB_NF | |
---|
93 | 84 | SND_SOC_DAIFMT_CBS_CFS); |
---|
.. | .. |
---|
96 | 87 | return ret; |
---|
97 | 88 | } |
---|
98 | 89 | |
---|
99 | | - ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24); |
---|
| 90 | + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, 24); |
---|
100 | 91 | if (ret < 0) { |
---|
101 | 92 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); |
---|
102 | 93 | return ret; |
---|
.. | .. |
---|
114 | 105 | static int aif1_hw_params(struct snd_pcm_substream *substream, |
---|
115 | 106 | struct snd_pcm_hw_params *params) |
---|
116 | 107 | { |
---|
117 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
118 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
---|
| 108 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
| 109 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
119 | 110 | int ret; |
---|
120 | 111 | |
---|
121 | 112 | ret = snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK, |
---|
.. | .. |
---|
135 | 126 | |
---|
136 | 127 | static int aif1_hw_free(struct snd_pcm_substream *substream) |
---|
137 | 128 | { |
---|
138 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
139 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
---|
| 129 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
| 130 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
140 | 131 | int ret; |
---|
141 | 132 | |
---|
142 | 133 | ret = snd_soc_dai_set_pll(codec_dai, 0, |
---|
.. | .. |
---|
159 | 150 | |
---|
160 | 151 | }; |
---|
161 | 152 | |
---|
| 153 | +SND_SOC_DAILINK_DEF(dummy, |
---|
| 154 | + DAILINK_COMP_ARRAY(COMP_DUMMY())); |
---|
| 155 | + |
---|
| 156 | +SND_SOC_DAILINK_DEF(media, |
---|
| 157 | + DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai"))); |
---|
| 158 | + |
---|
| 159 | +SND_SOC_DAILINK_DEF(deepbuffer, |
---|
| 160 | + DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai"))); |
---|
| 161 | + |
---|
| 162 | +SND_SOC_DAILINK_DEF(ssp2_port, |
---|
| 163 | + DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port"))); |
---|
| 164 | +SND_SOC_DAILINK_DEF(ssp2_codec, |
---|
| 165 | + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7213:00", |
---|
| 166 | + "da7213-hifi"))); |
---|
| 167 | + |
---|
| 168 | +SND_SOC_DAILINK_DEF(platform, |
---|
| 169 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform"))); |
---|
| 170 | + |
---|
162 | 171 | static struct snd_soc_dai_link dailink[] = { |
---|
163 | 172 | [MERR_DPCM_AUDIO] = { |
---|
164 | 173 | .name = "Audio Port", |
---|
165 | 174 | .stream_name = "Audio", |
---|
166 | | - .cpu_dai_name = "media-cpu-dai", |
---|
167 | | - .codec_dai_name = "snd-soc-dummy-dai", |
---|
168 | | - .codec_name = "snd-soc-dummy", |
---|
169 | | - .platform_name = "sst-mfld-platform", |
---|
170 | 175 | .nonatomic = true, |
---|
171 | 176 | .dynamic = 1, |
---|
172 | 177 | .dpcm_playback = 1, |
---|
173 | 178 | .dpcm_capture = 1, |
---|
174 | 179 | .ops = &aif1_ops, |
---|
| 180 | + SND_SOC_DAILINK_REG(media, dummy, platform), |
---|
175 | 181 | }, |
---|
176 | 182 | [MERR_DPCM_DEEP_BUFFER] = { |
---|
177 | 183 | .name = "Deep-Buffer Audio Port", |
---|
178 | 184 | .stream_name = "Deep-Buffer Audio", |
---|
179 | | - .cpu_dai_name = "deepbuffer-cpu-dai", |
---|
180 | | - .codec_dai_name = "snd-soc-dummy-dai", |
---|
181 | | - .codec_name = "snd-soc-dummy", |
---|
182 | | - .platform_name = "sst-mfld-platform", |
---|
183 | 185 | .nonatomic = true, |
---|
184 | 186 | .dynamic = 1, |
---|
185 | 187 | .dpcm_playback = 1, |
---|
186 | 188 | .ops = &aif1_ops, |
---|
| 189 | + SND_SOC_DAILINK_REG(deepbuffer, dummy, platform), |
---|
187 | 190 | }, |
---|
188 | 191 | /* CODEC<->CODEC link */ |
---|
189 | 192 | /* back ends */ |
---|
190 | 193 | { |
---|
191 | 194 | .name = "SSP2-Codec", |
---|
192 | 195 | .id = 0, |
---|
193 | | - .cpu_dai_name = "ssp2-port", |
---|
194 | | - .platform_name = "sst-mfld-platform", |
---|
195 | 196 | .no_pcm = 1, |
---|
196 | | - .codec_dai_name = "da7213-hifi", |
---|
197 | | - .codec_name = "i2c-DLGS7213:00", |
---|
198 | 197 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
---|
199 | 198 | | SND_SOC_DAIFMT_CBS_CFS, |
---|
200 | 199 | .be_hw_params_fixup = codec_fixup, |
---|
.. | .. |
---|
202 | 201 | .dpcm_playback = 1, |
---|
203 | 202 | .dpcm_capture = 1, |
---|
204 | 203 | .ops = &ssp2_ops, |
---|
| 204 | + SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform), |
---|
205 | 205 | }, |
---|
206 | 206 | }; |
---|
207 | 207 | |
---|
| 208 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
---|
| 209 | +/* use space before codec name to simplify card ID, and simplify driver name */ |
---|
| 210 | +#define CARD_NAME "bytcht da7213" /* card name will be 'sof-bytcht da7213' */ |
---|
| 211 | +#define DRIVER_NAME "SOF" |
---|
| 212 | +#else |
---|
| 213 | +#define CARD_NAME "bytcht-da7213" |
---|
| 214 | +#define DRIVER_NAME NULL /* card name will be used for driver name */ |
---|
| 215 | +#endif |
---|
| 216 | + |
---|
208 | 217 | /* SoC card */ |
---|
209 | 218 | static struct snd_soc_card bytcht_da7213_card = { |
---|
210 | | - .name = "bytcht-da7213", |
---|
| 219 | + .name = CARD_NAME, |
---|
| 220 | + .driver_name = DRIVER_NAME, |
---|
211 | 221 | .owner = THIS_MODULE, |
---|
212 | 222 | .dai_link = dailink, |
---|
213 | 223 | .num_links = ARRAY_SIZE(dailink), |
---|
.. | .. |
---|
225 | 235 | { |
---|
226 | 236 | struct snd_soc_card *card; |
---|
227 | 237 | struct snd_soc_acpi_mach *mach; |
---|
228 | | - const char *i2c_name = NULL; |
---|
| 238 | + const char *platform_name; |
---|
| 239 | + struct acpi_device *adev; |
---|
229 | 240 | int dai_index = 0; |
---|
230 | 241 | int ret_val = 0; |
---|
231 | 242 | int i; |
---|
232 | 243 | |
---|
233 | | - mach = (&pdev->dev)->platform_data; |
---|
| 244 | + mach = pdev->dev.platform_data; |
---|
234 | 245 | card = &bytcht_da7213_card; |
---|
235 | 246 | card->dev = &pdev->dev; |
---|
236 | 247 | |
---|
237 | 248 | /* fix index of codec dai */ |
---|
238 | 249 | for (i = 0; i < ARRAY_SIZE(dailink); i++) { |
---|
239 | | - if (!strcmp(dailink[i].codec_name, "i2c-DLGS7213:00")) { |
---|
| 250 | + if (!strcmp(dailink[i].codecs->name, "i2c-DLGS7213:00")) { |
---|
240 | 251 | dai_index = i; |
---|
241 | 252 | break; |
---|
242 | 253 | } |
---|
243 | 254 | } |
---|
244 | 255 | |
---|
245 | 256 | /* fixup codec name based on HID */ |
---|
246 | | - i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1); |
---|
247 | | - if (i2c_name) { |
---|
| 257 | + adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); |
---|
| 258 | + if (adev) { |
---|
248 | 259 | snprintf(codec_name, sizeof(codec_name), |
---|
249 | | - "%s%s", "i2c-", i2c_name); |
---|
250 | | - dailink[dai_index].codec_name = codec_name; |
---|
| 260 | + "i2c-%s", acpi_dev_name(adev)); |
---|
| 261 | + put_device(&adev->dev); |
---|
| 262 | + dailink[dai_index].codecs->name = codec_name; |
---|
251 | 263 | } |
---|
| 264 | + |
---|
| 265 | + /* override plaform name, if required */ |
---|
| 266 | + platform_name = mach->mach_params.platform; |
---|
| 267 | + |
---|
| 268 | + ret_val = snd_soc_fixup_dai_links_platform_name(card, platform_name); |
---|
| 269 | + if (ret_val) |
---|
| 270 | + return ret_val; |
---|
252 | 271 | |
---|
253 | 272 | ret_val = devm_snd_soc_register_card(&pdev->dev, card); |
---|
254 | 273 | if (ret_val) { |
---|
.. | .. |
---|
263 | 282 | static struct platform_driver bytcht_da7213_driver = { |
---|
264 | 283 | .driver = { |
---|
265 | 284 | .name = "bytcht_da7213", |
---|
| 285 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
---|
| 286 | + .pm = &snd_soc_pm_ops, |
---|
| 287 | +#endif |
---|
266 | 288 | }, |
---|
267 | 289 | .probe = bytcht_da7213_probe, |
---|
268 | 290 | }; |
---|