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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (c) 2016 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Permission to use, copy, modify, distribute, and sell this software and its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * documentation for any purpose is hereby granted without fee, provided that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * the above copyright notice appear in all copies and that both that copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * notice and this permission notice appear in supporting documentation, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * that the name of the copyright holders not be used in advertising or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * publicity pertaining to distribution of the software without specific,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * written prior permission.  The copyright holders make no representations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * about the suitability of this software for any purpose.  It is provided "as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * is" without express or implied warranty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * OF THIS SOFTWARE.
^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) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <drm/drm_bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <drm/drm_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <drm/drm_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <drm/drm_encoder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "drm_crtc_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * DOC: overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * Encoders represent the connecting element between the CRTC (as the overall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * pixel pipeline, represented by &struct drm_crtc) and the connectors (as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * generic sink entity, represented by &struct drm_connector). An encoder takes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * pixel data from a CRTC and converts it to a format suitable for any attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * connector. Encoders are objects exposed to userspace, originally to allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * userspace to infer cloning and connector/CRTC restrictions. Unfortunately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * almost all drivers get this wrong, making the uabi pretty much useless. On
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * top of that the exposed restrictions are too simple for today's hardware, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * the recommended way to infer restrictions is by using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * DRM_MODE_ATOMIC_TEST_ONLY flag for the atomic IOCTL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * Otherwise encoders aren't used in the uapi at all (any modeset request from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * userspace directly connects a connector with a CRTC), drivers are therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * free to use them however they wish. Modeset helper libraries make strong use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * of encoders to facilitate code sharing. But for more complex settings it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * usually better to move shared code into a separate &drm_bridge. Compared to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * encoders, bridges also have the benefit of being purely an internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * abstraction since they are not exposed to userspace at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * Encoders are initialized with drm_encoder_init() and cleaned up using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * drm_encoder_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	{ DRM_MODE_ENCODER_NONE, "None" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	{ DRM_MODE_ENCODER_DAC, "DAC" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	{ DRM_MODE_ENCODER_TVDAC, "TV" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	{ DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	{ DRM_MODE_ENCODER_DSI, "DSI" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	{ DRM_MODE_ENCODER_DPMST, "DP MST" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{ DRM_MODE_ENCODER_DPI, "DPI" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) int drm_encoder_register_all(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct drm_encoder *encoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	drm_for_each_encoder(encoder, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		if (encoder->funcs->late_register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			ret = encoder->funcs->late_register(encoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) void drm_encoder_unregister_all(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct drm_encoder *encoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	drm_for_each_encoder(encoder, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (encoder->funcs->early_unregister)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			encoder->funcs->early_unregister(encoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * drm_encoder_init - Init a preallocated encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * @encoder: the encoder to init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @funcs: callbacks for this encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * @encoder_type: user visible type of the encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * @name: printf style format string for the encoder name, or NULL for default name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * Initialises a preallocated encoder. Encoder should be subclassed as part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * driver encoder objects. At driver unload time drm_encoder_cleanup() should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * called from the driver's &drm_encoder_funcs.destroy hook.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * Zero on success, error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int drm_encoder_init(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		     struct drm_encoder *encoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		     const struct drm_encoder_funcs *funcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		     int encoder_type, const char *name, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* encoder index is used with 32bit bitmasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (WARN_ON(dev->mode_config.num_encoder >= 32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	encoder->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	encoder->encoder_type = encoder_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	encoder->funcs = funcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		va_start(ap, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		encoder->name = kvasprintf(GFP_KERNEL, name, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 					  drm_encoder_enum_list[encoder_type].name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 					  encoder->base.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (!encoder->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	INIT_LIST_HEAD(&encoder->bridge_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	encoder->index = dev->mode_config.num_encoder++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		drm_mode_object_unregister(dev, &encoder->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) EXPORT_SYMBOL(drm_encoder_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * drm_encoder_cleanup - cleans up an initialised encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * @encoder: encoder to cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * Cleans up the encoder but doesn't free the object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) void drm_encoder_cleanup(struct drm_encoder *encoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct drm_device *dev = encoder->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct drm_bridge *bridge, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* Note that the encoder_list is considered to be static; should we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 * remove the drm_encoder at runtime we would have to decrement all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 * the indices on the drm_encoder after us in the encoder_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	list_for_each_entry_safe(bridge, next, &encoder->bridge_chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				 chain_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		drm_bridge_detach(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	drm_mode_object_unregister(dev, &encoder->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	kfree(encoder->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	list_del(&encoder->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	dev->mode_config.num_encoder--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	memset(encoder, 0, sizeof(*encoder));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) EXPORT_SYMBOL(drm_encoder_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct drm_connector *connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct drm_device *dev = encoder->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	bool uses_atomic = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct drm_connector_list_iter conn_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/* For atomic drivers only state objects are synchronously updated and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 * protected by modeset locks, so check those first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	drm_connector_list_iter_begin(dev, &conn_iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	drm_for_each_connector_iter(connector, &conn_iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (!connector->state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		uses_atomic = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (connector->state->best_encoder != encoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		drm_connector_list_iter_end(&conn_iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return connector->state->crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	drm_connector_list_iter_end(&conn_iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	/* Don't return stale data (e.g. pending async disable). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (uses_atomic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return encoder->crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) int drm_mode_getencoder(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct drm_mode_get_encoder *enc_resp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct drm_encoder *encoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct drm_crtc *crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	encoder = drm_encoder_find(dev, file_priv, enc_resp->encoder_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (!encoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	crtc = drm_encoder_get_crtc(encoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (crtc && drm_lease_held(file_priv, crtc->base.id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		enc_resp->crtc_id = crtc->base.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		enc_resp->crtc_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	enc_resp->encoder_type = encoder->encoder_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	enc_resp->encoder_id = encoder->base.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	enc_resp->possible_crtcs = drm_lease_filter_crtcs(file_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 							  encoder->possible_crtcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	enc_resp->possible_clones = encoder->possible_clones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }