| .. | .. |
|---|
| 54 | 54 | /** |
|---|
| 55 | 55 | * snd_hdac_display_power - Power up / down the power refcount |
|---|
| 56 | 56 | * @bus: HDA core bus |
|---|
| 57 | + * @idx: HDA codec address, pass HDA_CODEC_IDX_CONTROLLER for controller |
|---|
| 57 | 58 | * @enable: power up or down |
|---|
| 58 | 59 | * |
|---|
| 59 | | - * This function is supposed to be used only by a HD-audio controller |
|---|
| 60 | | - * driver that needs the interaction with graphics driver. |
|---|
| 60 | + * This function is used by either HD-audio controller or codec driver that |
|---|
| 61 | + * needs the interaction with graphics driver. |
|---|
| 61 | 62 | * |
|---|
| 62 | | - * This function manages a refcount and calls the get_power() and |
|---|
| 63 | + * This function updates the power status, and calls the get_power() and |
|---|
| 63 | 64 | * put_power() ops accordingly, toggling the codec wakeup, too. |
|---|
| 64 | | - * |
|---|
| 65 | | - * Returns zero for success or a negative error code. |
|---|
| 66 | 65 | */ |
|---|
| 67 | | -int snd_hdac_display_power(struct hdac_bus *bus, bool enable) |
|---|
| 66 | +void snd_hdac_display_power(struct hdac_bus *bus, unsigned int idx, bool enable) |
|---|
| 68 | 67 | { |
|---|
| 69 | 68 | struct drm_audio_component *acomp = bus->audio_component; |
|---|
| 70 | | - |
|---|
| 71 | | - if (!acomp || !acomp->ops) |
|---|
| 72 | | - return -ENODEV; |
|---|
| 73 | 69 | |
|---|
| 74 | 70 | dev_dbg(bus->dev, "display power %s\n", |
|---|
| 75 | 71 | enable ? "enable" : "disable"); |
|---|
| 76 | 72 | |
|---|
| 77 | | - if (enable) { |
|---|
| 78 | | - if (!bus->drm_power_refcount++) { |
|---|
| 73 | + mutex_lock(&bus->lock); |
|---|
| 74 | + if (enable) |
|---|
| 75 | + set_bit(idx, &bus->display_power_status); |
|---|
| 76 | + else |
|---|
| 77 | + clear_bit(idx, &bus->display_power_status); |
|---|
| 78 | + |
|---|
| 79 | + if (!acomp || !acomp->ops) |
|---|
| 80 | + goto unlock; |
|---|
| 81 | + |
|---|
| 82 | + if (bus->display_power_status) { |
|---|
| 83 | + if (!bus->display_power_active) { |
|---|
| 84 | + unsigned long cookie = -1; |
|---|
| 85 | + |
|---|
| 79 | 86 | if (acomp->ops->get_power) |
|---|
| 80 | | - acomp->ops->get_power(acomp->dev); |
|---|
| 87 | + cookie = acomp->ops->get_power(acomp->dev); |
|---|
| 88 | + |
|---|
| 81 | 89 | snd_hdac_set_codec_wakeup(bus, true); |
|---|
| 82 | 90 | snd_hdac_set_codec_wakeup(bus, false); |
|---|
| 91 | + bus->display_power_active = cookie; |
|---|
| 83 | 92 | } |
|---|
| 84 | 93 | } else { |
|---|
| 85 | | - WARN_ON(!bus->drm_power_refcount); |
|---|
| 86 | | - if (!--bus->drm_power_refcount) |
|---|
| 87 | | - if (acomp->ops->put_power) |
|---|
| 88 | | - acomp->ops->put_power(acomp->dev); |
|---|
| 89 | | - } |
|---|
| 94 | + if (bus->display_power_active) { |
|---|
| 95 | + unsigned long cookie = bus->display_power_active; |
|---|
| 90 | 96 | |
|---|
| 91 | | - return 0; |
|---|
| 97 | + if (acomp->ops->put_power) |
|---|
| 98 | + acomp->ops->put_power(acomp->dev, cookie); |
|---|
| 99 | + |
|---|
| 100 | + bus->display_power_active = 0; |
|---|
| 101 | + } |
|---|
| 102 | + } |
|---|
| 103 | + unlock: |
|---|
| 104 | + mutex_unlock(&bus->lock); |
|---|
| 92 | 105 | } |
|---|
| 93 | 106 | EXPORT_SYMBOL_GPL(snd_hdac_display_power); |
|---|
| 94 | 107 | |
|---|
| .. | .. |
|---|
| 197 | 210 | goto module_put; |
|---|
| 198 | 211 | } |
|---|
| 199 | 212 | |
|---|
| 213 | + complete_all(&acomp->master_bind_complete); |
|---|
| 200 | 214 | return 0; |
|---|
| 201 | 215 | |
|---|
| 202 | 216 | module_put: |
|---|
| 203 | 217 | module_put(acomp->ops->owner); |
|---|
| 204 | 218 | out_unbind: |
|---|
| 205 | 219 | component_unbind_all(dev, acomp); |
|---|
| 220 | + complete_all(&acomp->master_bind_complete); |
|---|
| 206 | 221 | |
|---|
| 207 | 222 | return ret; |
|---|
| 208 | 223 | } |
|---|
| .. | .. |
|---|
| 249 | 264 | /** |
|---|
| 250 | 265 | * snd_hdac_acomp_init - Initialize audio component |
|---|
| 251 | 266 | * @bus: HDA core bus |
|---|
| 267 | + * @aops: audio component ops |
|---|
| 252 | 268 | * @match_master: match function for finding components |
|---|
| 253 | 269 | * @extra_size: Extra bytes to allocate |
|---|
| 254 | 270 | * |
|---|
| .. | .. |
|---|
| 266 | 282 | */ |
|---|
| 267 | 283 | int snd_hdac_acomp_init(struct hdac_bus *bus, |
|---|
| 268 | 284 | const struct drm_audio_component_audio_ops *aops, |
|---|
| 269 | | - int (*match_master)(struct device *, void *), |
|---|
| 285 | + int (*match_master)(struct device *, int, void *), |
|---|
| 270 | 286 | size_t extra_size) |
|---|
| 271 | 287 | { |
|---|
| 272 | 288 | struct component_match *match = NULL; |
|---|
| .. | .. |
|---|
| 282 | 298 | if (!acomp) |
|---|
| 283 | 299 | return -ENOMEM; |
|---|
| 284 | 300 | acomp->audio_ops = aops; |
|---|
| 301 | + init_completion(&acomp->master_bind_complete); |
|---|
| 285 | 302 | bus->audio_component = acomp; |
|---|
| 286 | 303 | devres_add(dev, acomp); |
|---|
| 287 | 304 | |
|---|
| 288 | | - component_match_add(dev, &match, match_master, bus); |
|---|
| 305 | + component_match_add_typed(dev, &match, match_master, bus); |
|---|
| 289 | 306 | ret = component_master_add_with_match(dev, &hdac_component_master_ops, |
|---|
| 290 | 307 | match); |
|---|
| 291 | 308 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 321 | 338 | if (!acomp) |
|---|
| 322 | 339 | return 0; |
|---|
| 323 | 340 | |
|---|
| 324 | | - WARN_ON(bus->drm_power_refcount); |
|---|
| 325 | | - if (bus->drm_power_refcount > 0 && acomp->ops) |
|---|
| 326 | | - acomp->ops->put_power(acomp->dev); |
|---|
| 341 | + if (WARN_ON(bus->display_power_active) && acomp->ops) |
|---|
| 342 | + acomp->ops->put_power(acomp->dev, bus->display_power_active); |
|---|
| 343 | + |
|---|
| 344 | + bus->display_power_active = 0; |
|---|
| 345 | + bus->display_power_status = 0; |
|---|
| 327 | 346 | |
|---|
| 328 | 347 | component_master_del(dev, &hdac_component_master_ops); |
|---|
| 329 | 348 | |
|---|