hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/sound/pci/hda/hda_bind.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * HD-audio codec driver binding
34 * Copyright (c) Takashi Iwai <tiwai@suse.de>
....@@ -11,7 +12,7 @@
1112 #include <linux/pm.h>
1213 #include <linux/pm_runtime.h>
1314 #include <sound/core.h>
14
-#include "hda_codec.h"
15
+#include <sound/hda_codec.h>
1516 #include "hda_local.h"
1617
1718 /*
....@@ -89,6 +90,12 @@
8990 hda_codec_patch_t patch;
9091 int err;
9192
93
+ if (codec->bus->core.ext_ops) {
94
+ if (WARN_ON(!codec->bus->core.ext_ops->hdev_attach))
95
+ return -EINVAL;
96
+ return codec->bus->core.ext_ops->hdev_attach(&codec->core);
97
+ }
98
+
9299 if (WARN_ON(!codec->preset))
93100 return -EINVAL;
94101
....@@ -136,6 +143,7 @@
136143
137144 error:
138145 snd_hda_codec_cleanup_for_unbind(codec);
146
+ codec->preset = NULL;
139147 return err;
140148 }
141149
....@@ -143,9 +151,16 @@
143151 {
144152 struct hda_codec *codec = dev_to_hda_codec(dev);
145153
154
+ if (codec->bus->core.ext_ops) {
155
+ if (WARN_ON(!codec->bus->core.ext_ops->hdev_detach))
156
+ return -EINVAL;
157
+ return codec->bus->core.ext_ops->hdev_detach(&codec->core);
158
+ }
159
+
146160 if (codec->patch_ops.free)
147161 codec->patch_ops.free(codec);
148162 snd_hda_codec_cleanup_for_unbind(codec);
163
+ codec->preset = NULL;
149164 module_put(dev->driver->owner);
150165 return 0;
151166 }
....@@ -288,29 +303,31 @@
288303 {
289304 int err;
290305
306
+ if (codec->configured)
307
+ return 0;
308
+
291309 if (is_generic_config(codec))
292310 codec->probe_id = HDA_CODEC_ID_GENERIC;
293311 else
294312 codec->probe_id = 0;
295313
296
- err = snd_hdac_device_register(&codec->core);
297
- if (err < 0)
298
- return err;
314
+ if (!device_is_registered(&codec->core.dev)) {
315
+ err = snd_hdac_device_register(&codec->core);
316
+ if (err < 0)
317
+ return err;
318
+ }
299319
300320 if (!codec->preset)
301321 codec_bind_module(codec);
302322 if (!codec->preset) {
303323 err = codec_bind_generic(codec);
304324 if (err < 0) {
305
- codec_err(codec, "Unable to bind the codec\n");
306
- goto error;
325
+ codec_dbg(codec, "Unable to bind the codec\n");
326
+ return err;
307327 }
308328 }
309329
330
+ codec->configured = 1;
310331 return 0;
311
-
312
- error:
313
- snd_hdac_device_unregister(&codec->core);
314
- return err;
315332 }
316333 EXPORT_SYMBOL_GPL(snd_hda_codec_configure);