Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // hdac_component.c - routines for sync between HD-A core and DRM driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/component.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <sound/hdaudio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <sound/hda_component.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <sound/hda_register.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static void hdac_acomp_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static struct drm_audio_component *hdac_get_acomp(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	return devres_find(dev, hdac_acomp_release, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * snd_hdac_set_codec_wakeup - Enable / disable HDMI/DP codec wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @bus: HDA core bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @enable: enable or disable the wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * This function is supposed to be used only by a HD-audio controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * driver that needs the interaction with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * This function should be called during the chip reset, also called at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * resume for updating STATESTS register read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * Returns zero for success or a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct drm_audio_component *acomp = bus->audio_component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (!acomp || !acomp->ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (!acomp->ops->codec_wake_override)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	dev_dbg(bus->dev, "%s codec wakeup\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		enable ? "enable" : "disable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	acomp->ops->codec_wake_override(acomp->dev, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) EXPORT_SYMBOL_GPL(snd_hdac_set_codec_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * snd_hdac_display_power - Power up / down the power refcount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * @bus: HDA core bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * @idx: HDA codec address, pass HDA_CODEC_IDX_CONTROLLER for controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * @enable: power up or down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * This function is used by either HD-audio controller or codec driver that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * needs the interaction with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * This function updates the power status, and calls the get_power() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * put_power() ops accordingly, toggling the codec wakeup, too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) void snd_hdac_display_power(struct hdac_bus *bus, unsigned int idx, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct drm_audio_component *acomp = bus->audio_component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	dev_dbg(bus->dev, "display power %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		enable ? "enable" : "disable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	mutex_lock(&bus->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		set_bit(idx, &bus->display_power_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		clear_bit(idx, &bus->display_power_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (!acomp || !acomp->ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (bus->display_power_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (!bus->display_power_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			unsigned long cookie = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			if (acomp->ops->get_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				cookie = acomp->ops->get_power(acomp->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			snd_hdac_set_codec_wakeup(bus, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			snd_hdac_set_codec_wakeup(bus, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			bus->display_power_active = cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (bus->display_power_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			unsigned long cookie = bus->display_power_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			if (acomp->ops->put_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				acomp->ops->put_power(acomp->dev, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			bus->display_power_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	mutex_unlock(&bus->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) EXPORT_SYMBOL_GPL(snd_hdac_display_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * snd_hdac_sync_audio_rate - Set N/CTS based on the sample rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * @codec: HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * @nid: the pin widget NID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * @dev_id: device identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * @rate: the sample rate to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * This function is supposed to be used only by a HD-audio controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * driver that needs the interaction with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * This function sets N/CTS value based on the given sample rate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * Returns zero for success, or a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int snd_hdac_sync_audio_rate(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			     int dev_id, int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct hdac_bus *bus = codec->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct drm_audio_component *acomp = bus->audio_component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	int port, pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (!acomp || !acomp->ops || !acomp->ops->sync_audio_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	port = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (acomp->audio_ops && acomp->audio_ops->pin2port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		port = acomp->audio_ops->pin2port(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (port < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	pipe = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return acomp->ops->sync_audio_rate(acomp->dev, port, pipe, rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) EXPORT_SYMBOL_GPL(snd_hdac_sync_audio_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * snd_hdac_acomp_get_eld - Get the audio state and ELD via component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * @codec: HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * @nid: the pin widget NID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * @dev_id: device identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @audio_enabled: the pointer to store the current audio state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * @buffer: the buffer pointer to store ELD bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * @max_bytes: the max bytes to be stored on @buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * This function is supposed to be used only by a HD-audio controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * driver that needs the interaction with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * This function queries the current state of the audio on the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * digital port and fetches the ELD bytes onto the given buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * It returns the number of bytes for the total ELD data, zero for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * invalid ELD, or a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * The return size is the total bytes required for the whole ELD bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * thus it may be over @max_bytes.  If it's over @max_bytes, it implies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * that only a part of ELD bytes have been fetched.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, int dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			   bool *audio_enabled, char *buffer, int max_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct hdac_bus *bus = codec->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct drm_audio_component *acomp = bus->audio_component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int port, pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (!acomp || !acomp->ops || !acomp->ops->get_eld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	port = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (acomp->audio_ops && acomp->audio_ops->pin2port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		port = acomp->audio_ops->pin2port(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		if (port < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	pipe = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return acomp->ops->get_eld(acomp->dev, port, pipe, audio_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				   buffer, max_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) EXPORT_SYMBOL_GPL(snd_hdac_acomp_get_eld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int hdac_component_master_bind(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct drm_audio_component *acomp = hdac_get_acomp(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (WARN_ON(!acomp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	ret = component_bind_all(dev, acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (WARN_ON(!(acomp->dev && acomp->ops))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		goto out_unbind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* pin the module to avoid dynamic unbinding, but only if given */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (!try_module_get(acomp->ops->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		goto out_unbind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (acomp->audio_ops && acomp->audio_ops->master_bind) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		ret = acomp->audio_ops->master_bind(dev, acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			goto module_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	complete_all(&acomp->master_bind_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  module_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	module_put(acomp->ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) out_unbind:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	component_unbind_all(dev, acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	complete_all(&acomp->master_bind_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static void hdac_component_master_unbind(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct drm_audio_component *acomp = hdac_get_acomp(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (acomp->audio_ops && acomp->audio_ops->master_unbind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		acomp->audio_ops->master_unbind(dev, acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	module_put(acomp->ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	component_unbind_all(dev, acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	WARN_ON(acomp->ops || acomp->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static const struct component_master_ops hdac_component_master_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	.bind = hdac_component_master_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	.unbind = hdac_component_master_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * snd_hdac_acomp_register_notifier - Register audio component ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  * @bus: HDA core bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * @aops: audio component ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * This function is supposed to be used only by a HD-audio controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * driver that needs the interaction with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * This function sets the given ops to be called by the graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * Returns zero for success or a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int snd_hdac_acomp_register_notifier(struct hdac_bus *bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				    const struct drm_audio_component_audio_ops *aops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (!bus->audio_component)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	bus->audio_component->audio_ops = aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) EXPORT_SYMBOL_GPL(snd_hdac_acomp_register_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * snd_hdac_acomp_init - Initialize audio component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * @bus: HDA core bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * @aops: audio component ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * @match_master: match function for finding components
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * @extra_size: Extra bytes to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * This function is supposed to be used only by a HD-audio controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * driver that needs the interaction with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * This function initializes and sets up the audio component to communicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * Unlike snd_hdac_i915_init(), this function doesn't synchronize with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * binding with the DRM component.  Each caller needs to sync via master_bind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * audio_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * Returns zero for success or a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int snd_hdac_acomp_init(struct hdac_bus *bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			const struct drm_audio_component_audio_ops *aops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			int (*match_master)(struct device *, int, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			size_t extra_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct component_match *match = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct device *dev = bus->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct drm_audio_component *acomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (WARN_ON(hdac_get_acomp(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	acomp = devres_alloc(hdac_acomp_release, sizeof(*acomp) + extra_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (!acomp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	acomp->audio_ops = aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	init_completion(&acomp->master_bind_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	bus->audio_component = acomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	devres_add(dev, acomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	component_match_add_typed(dev, &match, match_master, bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	ret = component_master_add_with_match(dev, &hdac_component_master_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 					      match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	bus->audio_component = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	devres_destroy(dev, hdac_acomp_release, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	dev_info(dev, "failed to add audio component master (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) EXPORT_SYMBOL_GPL(snd_hdac_acomp_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * snd_hdac_acomp_exit - Finalize audio component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * @bus: HDA core bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * This function is supposed to be used only by a HD-audio controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * driver that needs the interaction with graphics driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * This function releases the audio component that has been used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * Returns zero for success or a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int snd_hdac_acomp_exit(struct hdac_bus *bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct device *dev = bus->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct drm_audio_component *acomp = bus->audio_component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (!acomp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (WARN_ON(bus->display_power_active) && acomp->ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		acomp->ops->put_power(acomp->dev, bus->display_power_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	bus->display_power_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	bus->display_power_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	component_master_del(dev, &hdac_component_master_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	bus->audio_component = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	devres_destroy(dev, hdac_acomp_release, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) EXPORT_SYMBOL_GPL(snd_hdac_acomp_exit);