Linux 6.7-rc7
[linux-modified.git] / sound / soc / codecs / hdac_hda.c
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright(c) 2015-18 Intel Corporation.
3
4 /*
5  * hdac_hda.c - ASoC extensions to reuse the legacy HDA codec drivers
6  * with ASoC platform drivers. These APIs are called by the legacy HDA
7  * codec drivers using hdac_ext_bus_ops ops.
8  */
9
10 #include <linux/firmware.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/module.h>
14 #include <linux/pm_runtime.h>
15 #include <sound/pcm_params.h>
16 #include <sound/soc.h>
17 #include <sound/hdaudio_ext.h>
18 #include <sound/hda_i915.h>
19 #include <sound/hda_codec.h>
20 #include <sound/hda_register.h>
21
22 #include "hdac_hda.h"
23
24 #define STUB_FORMATS    (SNDRV_PCM_FMTBIT_S8 | \
25                         SNDRV_PCM_FMTBIT_U8 | \
26                         SNDRV_PCM_FMTBIT_S16_LE | \
27                         SNDRV_PCM_FMTBIT_U16_LE | \
28                         SNDRV_PCM_FMTBIT_S24_LE | \
29                         SNDRV_PCM_FMTBIT_U24_LE | \
30                         SNDRV_PCM_FMTBIT_S32_LE | \
31                         SNDRV_PCM_FMTBIT_U32_LE | \
32                         SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
33
34 #define STUB_HDMI_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
35                                  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
36                                  SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
37                                  SNDRV_PCM_RATE_192000)
38
39 #ifdef CONFIG_SND_HDA_PATCH_LOADER
40 static char *loadable_patch[HDA_MAX_CODECS];
41
42 module_param_array_named(patch, loadable_patch, charp, NULL, 0444);
43 MODULE_PARM_DESC(patch, "Patch file array for Intel HD audio interface. The array index is the codec address.");
44 #endif
45
46 static int hdac_hda_dai_open(struct snd_pcm_substream *substream,
47                              struct snd_soc_dai *dai);
48 static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
49                                struct snd_soc_dai *dai);
50 static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
51                                 struct snd_soc_dai *dai);
52 static int hdac_hda_dai_hw_params(struct snd_pcm_substream *substream,
53                                   struct snd_pcm_hw_params *params,
54                                   struct snd_soc_dai *dai);
55 static int hdac_hda_dai_hw_free(struct snd_pcm_substream *substream,
56                                 struct snd_soc_dai *dai);
57 static int hdac_hda_dai_set_stream(struct snd_soc_dai *dai, void *stream,
58                                    int direction);
59 static struct hda_pcm *snd_soc_find_pcm_from_dai(struct hdac_hda_priv *hda_pvt,
60                                                  struct snd_soc_dai *dai);
61
62 static const struct snd_soc_dai_ops hdac_hda_dai_ops = {
63         .startup = hdac_hda_dai_open,
64         .shutdown = hdac_hda_dai_close,
65         .prepare = hdac_hda_dai_prepare,
66         .hw_params = hdac_hda_dai_hw_params,
67         .hw_free = hdac_hda_dai_hw_free,
68         .set_stream = hdac_hda_dai_set_stream,
69 };
70
71 static struct snd_soc_dai_driver hdac_hda_dais[] = {
72 {
73         .id = HDAC_ANALOG_DAI_ID,
74         .name = "Analog Codec DAI",
75         .ops = &hdac_hda_dai_ops,
76         .playback = {
77                 .stream_name    = "Analog Codec Playback",
78                 .channels_min   = 1,
79                 .channels_max   = 16,
80                 .rates          = SNDRV_PCM_RATE_8000_192000,
81                 .formats        = STUB_FORMATS,
82                 .sig_bits       = 24,
83         },
84         .capture = {
85                 .stream_name    = "Analog Codec Capture",
86                 .channels_min   = 1,
87                 .channels_max   = 16,
88                 .rates = SNDRV_PCM_RATE_8000_192000,
89                 .formats = STUB_FORMATS,
90                 .sig_bits = 24,
91         },
92 },
93 {
94         .id = HDAC_DIGITAL_DAI_ID,
95         .name = "Digital Codec DAI",
96         .ops = &hdac_hda_dai_ops,
97         .playback = {
98                 .stream_name    = "Digital Codec Playback",
99                 .channels_min   = 1,
100                 .channels_max   = 16,
101                 .rates          = SNDRV_PCM_RATE_8000_192000,
102                 .formats        = STUB_FORMATS,
103                 .sig_bits = 24,
104         },
105         .capture = {
106                 .stream_name    = "Digital Codec Capture",
107                 .channels_min   = 1,
108                 .channels_max   = 16,
109                 .rates = SNDRV_PCM_RATE_8000_192000,
110                 .formats = STUB_FORMATS,
111                 .sig_bits = 24,
112         },
113 },
114 {
115         .id = HDAC_ALT_ANALOG_DAI_ID,
116         .name = "Alt Analog Codec DAI",
117         .ops = &hdac_hda_dai_ops,
118         .playback = {
119                 .stream_name    = "Alt Analog Codec Playback",
120                 .channels_min   = 1,
121                 .channels_max   = 16,
122                 .rates          = SNDRV_PCM_RATE_8000_192000,
123                 .formats        = STUB_FORMATS,
124                 .sig_bits       = 24,
125         },
126         .capture = {
127                 .stream_name    = "Alt Analog Codec Capture",
128                 .channels_min   = 1,
129                 .channels_max   = 16,
130                 .rates = SNDRV_PCM_RATE_8000_192000,
131                 .formats = STUB_FORMATS,
132                 .sig_bits = 24,
133         },
134 },
135 };
136
137 static struct snd_soc_dai_driver hdac_hda_hdmi_dais[] = {
138 {
139         .id = HDAC_HDMI_0_DAI_ID,
140         .name = "intel-hdmi-hifi1",
141         .ops = &hdac_hda_dai_ops,
142         .playback = {
143                 .stream_name    = "hifi1",
144                 .channels_min   = 1,
145                 .channels_max   = 32,
146                 .rates          = STUB_HDMI_RATES,
147                 .formats        = STUB_FORMATS,
148                 .sig_bits = 24,
149         },
150 },
151 {
152         .id = HDAC_HDMI_1_DAI_ID,
153         .name = "intel-hdmi-hifi2",
154         .ops = &hdac_hda_dai_ops,
155         .playback = {
156                 .stream_name    = "hifi2",
157                 .channels_min   = 1,
158                 .channels_max   = 32,
159                 .rates          = STUB_HDMI_RATES,
160                 .formats        = STUB_FORMATS,
161                 .sig_bits = 24,
162         },
163 },
164 {
165         .id = HDAC_HDMI_2_DAI_ID,
166         .name = "intel-hdmi-hifi3",
167         .ops = &hdac_hda_dai_ops,
168         .playback = {
169                 .stream_name    = "hifi3",
170                 .channels_min   = 1,
171                 .channels_max   = 32,
172                 .rates          = STUB_HDMI_RATES,
173                 .formats        = STUB_FORMATS,
174                 .sig_bits = 24,
175         },
176 },
177 {
178         .id = HDAC_HDMI_3_DAI_ID,
179         .name = "intel-hdmi-hifi4",
180         .ops = &hdac_hda_dai_ops,
181         .playback = {
182                 .stream_name    = "hifi4",
183                 .channels_min   = 1,
184                 .channels_max   = 32,
185                 .rates          = STUB_HDMI_RATES,
186                 .formats        = STUB_FORMATS,
187                 .sig_bits = 24,
188         },
189 },
190
191 };
192
193 static int hdac_hda_dai_set_stream(struct snd_soc_dai *dai,
194                                    void *stream, int direction)
195 {
196         struct snd_soc_component *component = dai->component;
197         struct hdac_hda_priv *hda_pvt;
198         struct hdac_hda_pcm *pcm;
199         struct hdac_stream *hstream;
200
201         if (!stream)
202                 return -EINVAL;
203
204         hda_pvt = snd_soc_component_get_drvdata(component);
205         pcm = &hda_pvt->pcm[dai->id];
206         hstream = (struct hdac_stream *)stream;
207
208         pcm->stream_tag[direction] = hstream->stream_tag;
209
210         return 0;
211 }
212
213 static int hdac_hda_dai_hw_params(struct snd_pcm_substream *substream,
214                                   struct snd_pcm_hw_params *params,
215                                   struct snd_soc_dai *dai)
216 {
217         struct snd_soc_component *component = dai->component;
218         struct hdac_hda_priv *hda_pvt;
219         unsigned int format_val;
220         unsigned int maxbps;
221
222         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
223                 maxbps = dai->driver->playback.sig_bits;
224         else
225                 maxbps = dai->driver->capture.sig_bits;
226
227         hda_pvt = snd_soc_component_get_drvdata(component);
228         format_val = snd_hdac_calc_stream_format(params_rate(params),
229                                                  params_channels(params),
230                                                  params_format(params),
231                                                  maxbps,
232                                                  0);
233         if (!format_val) {
234                 dev_err(dai->dev,
235                         "invalid format_val, rate=%d, ch=%d, format=%d, maxbps=%d\n",
236                         params_rate(params), params_channels(params),
237                         params_format(params), maxbps);
238
239                 return -EINVAL;
240         }
241
242         hda_pvt->pcm[dai->id].format_val[substream->stream] = format_val;
243         return 0;
244 }
245
246 static int hdac_hda_dai_hw_free(struct snd_pcm_substream *substream,
247                                 struct snd_soc_dai *dai)
248 {
249         struct snd_soc_component *component = dai->component;
250         struct hdac_hda_priv *hda_pvt;
251         struct hda_pcm_stream *hda_stream;
252         struct hda_pcm *pcm;
253
254         hda_pvt = snd_soc_component_get_drvdata(component);
255         pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
256         if (!pcm)
257                 return -EINVAL;
258
259         hda_stream = &pcm->stream[substream->stream];
260         snd_hda_codec_cleanup(hda_pvt->codec, hda_stream, substream);
261
262         return 0;
263 }
264
265 static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
266                                 struct snd_soc_dai *dai)
267 {
268         struct snd_soc_component *component = dai->component;
269         struct hda_pcm_stream *hda_stream;
270         struct hdac_hda_priv *hda_pvt;
271         struct hdac_device *hdev;
272         unsigned int format_val;
273         struct hda_pcm *pcm;
274         unsigned int stream;
275         int ret = 0;
276
277         hda_pvt = snd_soc_component_get_drvdata(component);
278         hdev = &hda_pvt->codec->core;
279         pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
280         if (!pcm)
281                 return -EINVAL;
282
283         hda_stream = &pcm->stream[substream->stream];
284
285         stream = hda_pvt->pcm[dai->id].stream_tag[substream->stream];
286         format_val = hda_pvt->pcm[dai->id].format_val[substream->stream];
287
288         ret = snd_hda_codec_prepare(hda_pvt->codec, hda_stream,
289                                     stream, format_val, substream);
290         if (ret < 0)
291                 dev_err(&hdev->dev, "codec prepare failed %d\n", ret);
292
293         return ret;
294 }
295
296 static int hdac_hda_dai_open(struct snd_pcm_substream *substream,
297                              struct snd_soc_dai *dai)
298 {
299         struct snd_soc_component *component = dai->component;
300         struct hdac_hda_priv *hda_pvt;
301         struct hda_pcm_stream *hda_stream;
302         struct hda_pcm *pcm;
303
304         hda_pvt = snd_soc_component_get_drvdata(component);
305         pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
306         if (!pcm)
307                 return -EINVAL;
308
309         snd_hda_codec_pcm_get(pcm);
310
311         hda_stream = &pcm->stream[substream->stream];
312
313         return hda_stream->ops.open(hda_stream, hda_pvt->codec, substream);
314 }
315
316 static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
317                                struct snd_soc_dai *dai)
318 {
319         struct snd_soc_component *component = dai->component;
320         struct hdac_hda_priv *hda_pvt;
321         struct hda_pcm_stream *hda_stream;
322         struct hda_pcm *pcm;
323
324         hda_pvt = snd_soc_component_get_drvdata(component);
325         pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
326         if (!pcm)
327                 return;
328
329         hda_stream = &pcm->stream[substream->stream];
330
331         hda_stream->ops.close(hda_stream, hda_pvt->codec, substream);
332
333         snd_hda_codec_pcm_put(pcm);
334 }
335
336 static struct hda_pcm *snd_soc_find_pcm_from_dai(struct hdac_hda_priv *hda_pvt,
337                                                  struct snd_soc_dai *dai)
338 {
339         struct hda_codec *hcodec = hda_pvt->codec;
340         struct hda_pcm *cpcm;
341         const char *pcm_name;
342
343         /*
344          * map DAI ID to the closest matching PCM name, using the naming
345          * scheme used by hda-codec snd_hda_gen_build_pcms() and for
346          * HDMI in hda_codec patch_hdmi.c)
347          */
348
349         switch (dai->id) {
350         case HDAC_ANALOG_DAI_ID:
351                 pcm_name = "Analog";
352                 break;
353         case HDAC_DIGITAL_DAI_ID:
354                 pcm_name = "Digital";
355                 break;
356         case HDAC_ALT_ANALOG_DAI_ID:
357                 pcm_name = "Alt Analog";
358                 break;
359         case HDAC_HDMI_0_DAI_ID:
360                 pcm_name = "HDMI 0";
361                 break;
362         case HDAC_HDMI_1_DAI_ID:
363                 pcm_name = "HDMI 1";
364                 break;
365         case HDAC_HDMI_2_DAI_ID:
366                 pcm_name = "HDMI 2";
367                 break;
368         case HDAC_HDMI_3_DAI_ID:
369                 pcm_name = "HDMI 3";
370                 break;
371         default:
372                 dev_err(&hcodec->core.dev, "invalid dai id %d\n", dai->id);
373                 return NULL;
374         }
375
376         list_for_each_entry(cpcm, &hcodec->pcm_list_head, list) {
377                 if (strstr(cpcm->name, pcm_name)) {
378                         if (strcmp(pcm_name, "Analog") == 0) {
379                                 if (strstr(cpcm->name, "Alt Analog"))
380                                         continue;
381                         }
382                         return cpcm;
383                 }
384         }
385
386         dev_err(&hcodec->core.dev, "didn't find PCM for DAI %s\n", dai->name);
387         return NULL;
388 }
389
390 static bool is_hdmi_codec(struct hda_codec *hcodec)
391 {
392         struct hda_pcm *cpcm;
393
394         list_for_each_entry(cpcm, &hcodec->pcm_list_head, list) {
395                 if (cpcm->pcm_type == HDA_PCM_TYPE_HDMI)
396                         return true;
397         }
398
399         return false;
400 }
401
402 static int hdac_hda_codec_probe(struct snd_soc_component *component)
403 {
404         struct hdac_hda_priv *hda_pvt =
405                         snd_soc_component_get_drvdata(component);
406         struct snd_soc_dapm_context *dapm =
407                         snd_soc_component_get_dapm(component);
408         struct hdac_device *hdev = &hda_pvt->codec->core;
409         struct hda_codec *hcodec = hda_pvt->codec;
410         struct hdac_ext_link *hlink;
411         hda_codec_patch_t patch;
412         int ret;
413
414         hlink = snd_hdac_ext_bus_get_hlink_by_name(hdev->bus, dev_name(&hdev->dev));
415         if (!hlink) {
416                 dev_err(&hdev->dev, "hdac link not found\n");
417                 return -EIO;
418         }
419
420         snd_hdac_ext_bus_link_get(hdev->bus, hlink);
421
422         /*
423          * Ensure any HDA display is powered at codec probe.
424          * After snd_hda_codec_device_new(), display power is
425          * managed by runtime PM.
426          */
427         if (hda_pvt->need_display_power)
428                 snd_hdac_display_power(hdev->bus,
429                                        HDA_CODEC_IDX_CONTROLLER, true);
430
431         ret = snd_hda_codec_device_new(hcodec->bus, component->card->snd_card,
432                                        hdev->addr, hcodec, true);
433         if (ret < 0) {
434                 dev_err(&hdev->dev, "failed to create hda codec %d\n", ret);
435                 goto error_no_pm;
436         }
437
438 #ifdef CONFIG_SND_HDA_PATCH_LOADER
439         if (loadable_patch[hda_pvt->dev_index] && *loadable_patch[hda_pvt->dev_index]) {
440                 const struct firmware *fw;
441
442                 dev_info(&hdev->dev, "Applying patch firmware '%s'\n",
443                          loadable_patch[hda_pvt->dev_index]);
444                 ret = request_firmware(&fw, loadable_patch[hda_pvt->dev_index],
445                                        &hdev->dev);
446                 if (ret < 0)
447                         goto error_no_pm;
448                 if (fw) {
449                         ret = snd_hda_load_patch(hcodec->bus, fw->size, fw->data);
450                         if (ret < 0) {
451                                 dev_err(&hdev->dev, "failed to load hda patch %d\n", ret);
452                                 goto error_no_pm;
453                         }
454                         release_firmware(fw);
455                 }
456         }
457 #endif
458         /*
459          * Overwrite type to HDA_DEV_ASOC since it is a ASoC driver
460          * hda_codec.c will check this flag to determine if unregister
461          * device is needed.
462          */
463         hdev->type = HDA_DEV_ASOC;
464
465         /*
466          * snd_hda_codec_device_new decrements the usage count so call get pm
467          * else the device will be powered off
468          */
469         pm_runtime_get_noresume(&hdev->dev);
470
471         hcodec->bus->card = dapm->card->snd_card;
472
473         ret = snd_hda_codec_set_name(hcodec, hcodec->preset->name);
474         if (ret < 0) {
475                 dev_err(&hdev->dev, "name failed %s\n", hcodec->preset->name);
476                 goto error_pm;
477         }
478
479         ret = snd_hdac_regmap_init(&hcodec->core);
480         if (ret < 0) {
481                 dev_err(&hdev->dev, "regmap init failed\n");
482                 goto error_pm;
483         }
484
485         patch = (hda_codec_patch_t)hcodec->preset->driver_data;
486         if (patch) {
487                 ret = patch(hcodec);
488                 if (ret < 0) {
489                         dev_err(&hdev->dev, "patch failed %d\n", ret);
490                         goto error_regmap;
491                 }
492         } else {
493                 dev_dbg(&hdev->dev, "no patch file found\n");
494         }
495
496         ret = snd_hda_codec_parse_pcms(hcodec);
497         if (ret < 0) {
498                 dev_err(&hdev->dev, "unable to map pcms to dai %d\n", ret);
499                 goto error_patch;
500         }
501
502         /* HDMI controls need to be created in machine drivers */
503         if (!is_hdmi_codec(hcodec)) {
504                 ret = snd_hda_codec_build_controls(hcodec);
505                 if (ret < 0) {
506                         dev_err(&hdev->dev, "unable to create controls %d\n",
507                                 ret);
508                         goto error_patch;
509                 }
510         }
511
512         hcodec->core.lazy_cache = true;
513
514         if (hda_pvt->need_display_power)
515                 snd_hdac_display_power(hdev->bus,
516                                        HDA_CODEC_IDX_CONTROLLER, false);
517
518         /* match for forbid call in snd_hda_codec_device_new() */
519         pm_runtime_allow(&hdev->dev);
520
521         /*
522          * hdac_device core already sets the state to active and calls
523          * get_noresume. So enable runtime and set the device to suspend.
524          * pm_runtime_enable is also called during codec registeration
525          */
526         pm_runtime_put(&hdev->dev);
527         pm_runtime_suspend(&hdev->dev);
528
529         return 0;
530
531 error_patch:
532         if (hcodec->patch_ops.free)
533                 hcodec->patch_ops.free(hcodec);
534 error_regmap:
535         snd_hdac_regmap_exit(hdev);
536 error_pm:
537         pm_runtime_put(&hdev->dev);
538 error_no_pm:
539         snd_hdac_ext_bus_link_put(hdev->bus, hlink);
540         return ret;
541 }
542
543 static void hdac_hda_codec_remove(struct snd_soc_component *component)
544 {
545         struct hdac_hda_priv *hda_pvt =
546                       snd_soc_component_get_drvdata(component);
547         struct hdac_device *hdev = &hda_pvt->codec->core;
548         struct hda_codec *codec = hda_pvt->codec;
549         struct hdac_ext_link *hlink = NULL;
550
551         hlink = snd_hdac_ext_bus_get_hlink_by_name(hdev->bus, dev_name(&hdev->dev));
552         if (!hlink) {
553                 dev_err(&hdev->dev, "hdac link not found\n");
554                 return;
555         }
556
557         pm_runtime_disable(&hdev->dev);
558         snd_hdac_ext_bus_link_put(hdev->bus, hlink);
559
560         if (codec->patch_ops.free)
561                 codec->patch_ops.free(codec);
562
563         snd_hda_codec_cleanup_for_unbind(codec);
564 }
565
566 static const struct snd_soc_dapm_route hdac_hda_dapm_routes[] = {
567         {"AIF1TX", NULL, "Codec Input Pin1"},
568         {"AIF2TX", NULL, "Codec Input Pin2"},
569         {"AIF3TX", NULL, "Codec Input Pin3"},
570
571         {"Codec Output Pin1", NULL, "AIF1RX"},
572         {"Codec Output Pin2", NULL, "AIF2RX"},
573         {"Codec Output Pin3", NULL, "AIF3RX"},
574 };
575
576 static const struct snd_soc_dapm_widget hdac_hda_dapm_widgets[] = {
577         /* Audio Interface */
578         SND_SOC_DAPM_AIF_IN("AIF1RX", "Analog Codec Playback", 0,
579                             SND_SOC_NOPM, 0, 0),
580         SND_SOC_DAPM_AIF_IN("AIF2RX", "Digital Codec Playback", 0,
581                             SND_SOC_NOPM, 0, 0),
582         SND_SOC_DAPM_AIF_IN("AIF3RX", "Alt Analog Codec Playback", 0,
583                             SND_SOC_NOPM, 0, 0),
584         SND_SOC_DAPM_AIF_OUT("AIF1TX", "Analog Codec Capture", 0,
585                              SND_SOC_NOPM, 0, 0),
586         SND_SOC_DAPM_AIF_OUT("AIF2TX", "Digital Codec Capture", 0,
587                              SND_SOC_NOPM, 0, 0),
588         SND_SOC_DAPM_AIF_OUT("AIF3TX", "Alt Analog Codec Capture", 0,
589                              SND_SOC_NOPM, 0, 0),
590
591         /* Input Pins */
592         SND_SOC_DAPM_INPUT("Codec Input Pin1"),
593         SND_SOC_DAPM_INPUT("Codec Input Pin2"),
594         SND_SOC_DAPM_INPUT("Codec Input Pin3"),
595
596         /* Output Pins */
597         SND_SOC_DAPM_OUTPUT("Codec Output Pin1"),
598         SND_SOC_DAPM_OUTPUT("Codec Output Pin2"),
599         SND_SOC_DAPM_OUTPUT("Codec Output Pin3"),
600 };
601
602 static const struct snd_soc_component_driver hdac_hda_codec = {
603         .probe                  = hdac_hda_codec_probe,
604         .remove                 = hdac_hda_codec_remove,
605         .dapm_widgets           = hdac_hda_dapm_widgets,
606         .num_dapm_widgets       = ARRAY_SIZE(hdac_hda_dapm_widgets),
607         .dapm_routes            = hdac_hda_dapm_routes,
608         .num_dapm_routes        = ARRAY_SIZE(hdac_hda_dapm_routes),
609         .idle_bias_on           = false,
610         .endianness             = 1,
611 };
612
613 static const struct snd_soc_component_driver hdac_hda_hdmi_codec = {
614         .probe                  = hdac_hda_codec_probe,
615         .remove                 = hdac_hda_codec_remove,
616         .idle_bias_on           = false,
617         .endianness             = 1,
618 };
619
620 static int hdac_hda_dev_probe(struct hdac_device *hdev)
621 {
622         struct hdac_hda_priv *hda_pvt = dev_get_drvdata(&hdev->dev);
623         struct hdac_ext_link *hlink;
624         int ret;
625
626         /* hold the ref while we probe */
627         hlink = snd_hdac_ext_bus_get_hlink_by_name(hdev->bus, dev_name(&hdev->dev));
628         if (!hlink) {
629                 dev_err(&hdev->dev, "hdac link not found\n");
630                 return -EIO;
631         }
632         snd_hdac_ext_bus_link_get(hdev->bus, hlink);
633
634         /* ASoC specific initialization */
635         if (hda_pvt->need_display_power)
636                 ret = devm_snd_soc_register_component(&hdev->dev,
637                                                 &hdac_hda_hdmi_codec, hdac_hda_hdmi_dais,
638                                                 ARRAY_SIZE(hdac_hda_hdmi_dais));
639         else
640                 ret = devm_snd_soc_register_component(&hdev->dev,
641                                                 &hdac_hda_codec, hdac_hda_dais,
642                                                 ARRAY_SIZE(hdac_hda_dais));
643
644         if (ret < 0) {
645                 dev_err(&hdev->dev, "failed to register HDA codec %d\n", ret);
646                 return ret;
647         }
648
649         snd_hdac_ext_bus_link_put(hdev->bus, hlink);
650
651         return ret;
652 }
653
654 static int hdac_hda_dev_remove(struct hdac_device *hdev)
655 {
656         /*
657          * Resources are freed in hdac_hda_codec_remove(). This
658          * function is kept to keep hda_codec_driver_remove() happy.
659          */
660         return 0;
661 }
662
663 static struct hdac_ext_bus_ops hdac_ops = {
664         .hdev_attach = hdac_hda_dev_probe,
665         .hdev_detach = hdac_hda_dev_remove,
666 };
667
668 struct hdac_ext_bus_ops *snd_soc_hdac_hda_get_ops(void)
669 {
670         return &hdac_ops;
671 }
672 EXPORT_SYMBOL_GPL(snd_soc_hdac_hda_get_ops);
673
674 MODULE_LICENSE("GPL v2");
675 MODULE_DESCRIPTION("ASoC Extensions for legacy HDA Drivers");
676 MODULE_AUTHOR("Rakesh Ughreja<rakesh.a.ughreja@intel.com>");