| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * HD-audio codec driver binding |
|---|
| 3 | 4 | * Copyright (c) Takashi Iwai <tiwai@suse.de> |
|---|
| .. | .. |
|---|
| 11 | 12 | #include <linux/pm.h> |
|---|
| 12 | 13 | #include <linux/pm_runtime.h> |
|---|
| 13 | 14 | #include <sound/core.h> |
|---|
| 14 | | -#include "hda_codec.h" |
|---|
| 15 | +#include <sound/hda_codec.h> |
|---|
| 15 | 16 | #include "hda_local.h" |
|---|
| 16 | 17 | |
|---|
| 17 | 18 | /* |
|---|
| .. | .. |
|---|
| 89 | 90 | hda_codec_patch_t patch; |
|---|
| 90 | 91 | int err; |
|---|
| 91 | 92 | |
|---|
| 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 | + |
|---|
| 92 | 99 | if (WARN_ON(!codec->preset)) |
|---|
| 93 | 100 | return -EINVAL; |
|---|
| 94 | 101 | |
|---|
| .. | .. |
|---|
| 142 | 149 | static int hda_codec_driver_remove(struct device *dev) |
|---|
| 143 | 150 | { |
|---|
| 144 | 151 | struct hda_codec *codec = dev_to_hda_codec(dev); |
|---|
| 152 | + |
|---|
| 153 | + if (codec->bus->core.ext_ops) { |
|---|
| 154 | + if (WARN_ON(!codec->bus->core.ext_ops->hdev_detach)) |
|---|
| 155 | + return -EINVAL; |
|---|
| 156 | + return codec->bus->core.ext_ops->hdev_detach(&codec->core); |
|---|
| 157 | + } |
|---|
| 145 | 158 | |
|---|
| 146 | 159 | if (codec->patch_ops.free) |
|---|
| 147 | 160 | codec->patch_ops.free(codec); |
|---|
| .. | .. |
|---|
| 288 | 301 | { |
|---|
| 289 | 302 | int err; |
|---|
| 290 | 303 | |
|---|
| 304 | + if (codec->configured) |
|---|
| 305 | + return 0; |
|---|
| 306 | + |
|---|
| 291 | 307 | if (is_generic_config(codec)) |
|---|
| 292 | 308 | codec->probe_id = HDA_CODEC_ID_GENERIC; |
|---|
| 293 | 309 | else |
|---|
| 294 | 310 | codec->probe_id = 0; |
|---|
| 295 | 311 | |
|---|
| 296 | | - err = snd_hdac_device_register(&codec->core); |
|---|
| 297 | | - if (err < 0) |
|---|
| 298 | | - return err; |
|---|
| 312 | + if (!device_is_registered(&codec->core.dev)) { |
|---|
| 313 | + err = snd_hdac_device_register(&codec->core); |
|---|
| 314 | + if (err < 0) |
|---|
| 315 | + return err; |
|---|
| 316 | + } |
|---|
| 299 | 317 | |
|---|
| 300 | 318 | if (!codec->preset) |
|---|
| 301 | 319 | codec_bind_module(codec); |
|---|
| 302 | 320 | if (!codec->preset) { |
|---|
| 303 | 321 | err = codec_bind_generic(codec); |
|---|
| 304 | 322 | if (err < 0) { |
|---|
| 305 | | - codec_err(codec, "Unable to bind the codec\n"); |
|---|
| 306 | | - goto error; |
|---|
| 323 | + codec_dbg(codec, "Unable to bind the codec\n"); |
|---|
| 324 | + return err; |
|---|
| 307 | 325 | } |
|---|
| 308 | 326 | } |
|---|
| 309 | 327 | |
|---|
| 328 | + codec->configured = 1; |
|---|
| 310 | 329 | return 0; |
|---|
| 311 | | - |
|---|
| 312 | | - error: |
|---|
| 313 | | - snd_hdac_device_unregister(&codec->core); |
|---|
| 314 | | - return err; |
|---|
| 315 | 330 | } |
|---|
| 316 | 331 | EXPORT_SYMBOL_GPL(snd_hda_codec_configure); |
|---|