Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 5 | * documentation for any purpose is hereby granted without fee, provided that |
| 6 | * the above copyright notice appear in all copies and that both that copyright |
| 7 | * notice and this permission notice appear in supporting documentation, and |
| 8 | * that the name of the copyright holders not be used in advertising or |
| 9 | * publicity pertaining to distribution of the software without specific, |
| 10 | * written prior permission. The copyright holders make no representations |
| 11 | * about the suitability of this software for any purpose. It is provided "as |
| 12 | * is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 | * OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __DRM_ENCODER_H__ |
| 24 | #define __DRM_ENCODER_H__ |
| 25 | |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/ctype.h> |
Laurent Pinchart | 2407d1d | 2016-11-28 21:03:49 +0200 | [diff] [blame] | 28 | #include <drm/drm_crtc.h> |
Laurent Pinchart | 9338203 | 2016-11-28 20:51:09 +0200 | [diff] [blame] | 29 | #include <drm/drm_mode.h> |
Daniel Vetter | 949619f | 2016-08-29 10:27:51 +0200 | [diff] [blame] | 30 | #include <drm/drm_mode_object.h> |
Daniel Vetter | d78aa65 | 2018-09-05 15:57:05 +0200 | [diff] [blame] | 31 | #include <drm/drm_util.h> |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 32 | |
Laurent Pinchart | 9338203 | 2016-11-28 20:51:09 +0200 | [diff] [blame] | 33 | struct drm_encoder; |
| 34 | |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 35 | /** |
| 36 | * struct drm_encoder_funcs - encoder controls |
| 37 | * |
| 38 | * Encoders sit between CRTCs and connectors. |
| 39 | */ |
| 40 | struct drm_encoder_funcs { |
| 41 | /** |
| 42 | * @reset: |
| 43 | * |
| 44 | * Reset encoder hardware and software state to off. This function isn't |
| 45 | * called by the core directly, only through drm_mode_config_reset(). |
| 46 | * It's not a helper hook only for historical reasons. |
| 47 | */ |
| 48 | void (*reset)(struct drm_encoder *encoder); |
| 49 | |
| 50 | /** |
| 51 | * @destroy: |
| 52 | * |
| 53 | * Clean up encoder resources. This is only called at driver unload time |
| 54 | * through drm_mode_config_cleanup() since an encoder cannot be |
| 55 | * hotplugged in DRM. |
| 56 | */ |
| 57 | void (*destroy)(struct drm_encoder *encoder); |
| 58 | |
| 59 | /** |
| 60 | * @late_register: |
| 61 | * |
| 62 | * This optional hook can be used to register additional userspace |
| 63 | * interfaces attached to the encoder like debugfs interfaces. |
| 64 | * It is called late in the driver load sequence from drm_dev_register(). |
| 65 | * Everything added from this callback should be unregistered in |
| 66 | * the early_unregister callback. |
| 67 | * |
| 68 | * Returns: |
| 69 | * |
| 70 | * 0 on success, or a negative error code on failure. |
| 71 | */ |
| 72 | int (*late_register)(struct drm_encoder *encoder); |
| 73 | |
| 74 | /** |
| 75 | * @early_unregister: |
| 76 | * |
| 77 | * This optional hook should be used to unregister the additional |
| 78 | * userspace interfaces attached to the encoder from |
Daniel Vetter | 559bdaf | 2017-01-25 07:26:55 +0100 | [diff] [blame] | 79 | * @late_register. It is called from drm_dev_unregister(), |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 80 | * early in the driver unload sequence to disable userspace access |
| 81 | * before data structures are torndown. |
| 82 | */ |
| 83 | void (*early_unregister)(struct drm_encoder *encoder); |
| 84 | }; |
| 85 | |
| 86 | /** |
| 87 | * struct drm_encoder - central DRM encoder structure |
| 88 | * @dev: parent DRM device |
| 89 | * @head: list management |
| 90 | * @base: base KMS object |
| 91 | * @name: human readable name, can be overwritten by the driver |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 92 | * @bridge: bridge associated to the encoder |
| 93 | * @funcs: control functions |
| 94 | * @helper_private: mid-layer private data |
| 95 | * |
| 96 | * CRTCs drive pixels to encoders, which convert them into signals |
| 97 | * appropriate for a given connector or set of connectors. |
| 98 | */ |
| 99 | struct drm_encoder { |
| 100 | struct drm_device *dev; |
| 101 | struct list_head head; |
| 102 | |
| 103 | struct drm_mode_object base; |
| 104 | char *name; |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 105 | /** |
| 106 | * @encoder_type: |
| 107 | * |
| 108 | * One of the DRM_MODE_ENCODER_<foo> types in drm_mode.h. The following |
| 109 | * encoder types are defined thus far: |
| 110 | * |
| 111 | * - DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A. |
| 112 | * |
| 113 | * - DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort. |
| 114 | * |
| 115 | * - DRM_MODE_ENCODER_LVDS for display panels, or in general any panel |
| 116 | * with a proprietary parallel connector. |
| 117 | * |
| 118 | * - DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video, |
| 119 | * Component, SCART). |
| 120 | * |
| 121 | * - DRM_MODE_ENCODER_VIRTUAL for virtual machine displays |
| 122 | * |
| 123 | * - DRM_MODE_ENCODER_DSI for panels connected using the DSI serial bus. |
| 124 | * |
| 125 | * - DRM_MODE_ENCODER_DPI for panels connected using the DPI parallel |
| 126 | * bus. |
| 127 | * |
| 128 | * - DRM_MODE_ENCODER_DPMST for special fake encoders used to allow |
| 129 | * mutliple DP MST streams to share one physical encoder. |
| 130 | */ |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 131 | int encoder_type; |
| 132 | |
| 133 | /** |
| 134 | * @index: Position inside the mode_config.list, can be used as an array |
| 135 | * index. It is invariant over the lifetime of the encoder. |
| 136 | */ |
| 137 | unsigned index; |
| 138 | |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 139 | /** |
| 140 | * @possible_crtcs: Bitmask of potential CRTC bindings, using |
| 141 | * drm_crtc_index() as the index into the bitfield. The driver must set |
| 142 | * the bits for all &drm_crtc objects this encoder can be connected to |
Lyude Paul | c873724 | 2019-09-13 18:27:02 -0400 | [diff] [blame] | 143 | * before calling drm_dev_register(). |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 144 | * |
Ville Syrjälä | 0df1082 | 2020-02-11 18:22:07 +0200 | [diff] [blame] | 145 | * You will get a WARN if you get this wrong in the driver. |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 146 | * |
| 147 | * Note that since CRTC objects can't be hotplugged the assigned indices |
| 148 | * are stable and hence known before registering all objects. |
| 149 | */ |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 150 | uint32_t possible_crtcs; |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * @possible_clones: Bitmask of potential sibling encoders for cloning, |
| 154 | * using drm_encoder_index() as the index into the bitfield. The driver |
| 155 | * must set the bits for all &drm_encoder objects which can clone a |
| 156 | * &drm_crtc together with this encoder before calling |
Lyude Paul | 8c8ae2f | 2019-09-13 18:27:01 -0400 | [diff] [blame] | 157 | * drm_dev_register(). Drivers should set the bit representing the |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 158 | * encoder itself, too. Cloning bits should be set such that when two |
| 159 | * encoders can be used in a cloned configuration, they both should have |
| 160 | * each another bits set. |
| 161 | * |
Ville Syrjälä | 71427795 | 2020-02-11 18:22:02 +0200 | [diff] [blame] | 162 | * As an exception to the above rule if the driver doesn't implement |
| 163 | * any cloning it can leave @possible_clones set to 0. The core will |
| 164 | * automagically fix this up by setting the bit for the encoder itself. |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 165 | * |
Ville Syrjälä | 74d2aac | 2020-02-11 18:22:06 +0200 | [diff] [blame] | 166 | * You will get a WARN if you get this wrong in the driver. |
| 167 | * |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 168 | * Note that since encoder objects can't be hotplugged the assigned indices |
| 169 | * are stable and hence known before registering all objects. |
| 170 | */ |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 171 | uint32_t possible_clones; |
| 172 | |
Daniel Vetter | 2e2b96e | 2017-11-08 21:30:07 +0100 | [diff] [blame] | 173 | /** |
| 174 | * @crtc: Currently bound CRTC, only really meaningful for non-atomic |
| 175 | * drivers. Atomic drivers should instead check |
| 176 | * &drm_connector_state.crtc. |
| 177 | */ |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 178 | struct drm_crtc *crtc; |
Boris Brezillon | 05193dc | 2019-12-03 15:15:08 +0100 | [diff] [blame] | 179 | |
| 180 | /** |
Laurent Pinchart | be39f3d | 2020-02-26 13:24:24 +0200 | [diff] [blame] | 181 | * @bridge_chain: Bridges attached to this encoder. Drivers shall not |
| 182 | * access this field directly. |
Boris Brezillon | 05193dc | 2019-12-03 15:15:08 +0100 | [diff] [blame] | 183 | */ |
| 184 | struct list_head bridge_chain; |
| 185 | |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 186 | const struct drm_encoder_funcs *funcs; |
| 187 | const struct drm_encoder_helper_funcs *helper_private; |
| 188 | }; |
| 189 | |
| 190 | #define obj_to_encoder(x) container_of(x, struct drm_encoder, base) |
| 191 | |
| 192 | __printf(5, 6) |
| 193 | int drm_encoder_init(struct drm_device *dev, |
| 194 | struct drm_encoder *encoder, |
| 195 | const struct drm_encoder_funcs *funcs, |
| 196 | int encoder_type, const char *name, ...); |
| 197 | |
| 198 | /** |
| 199 | * drm_encoder_index - find the index of a registered encoder |
| 200 | * @encoder: encoder to find index for |
| 201 | * |
| 202 | * Given a registered encoder, return the index of that encoder within a DRM |
| 203 | * device's list of encoders. |
| 204 | */ |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 205 | static inline unsigned int drm_encoder_index(const struct drm_encoder *encoder) |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 206 | { |
| 207 | return encoder->index; |
| 208 | } |
| 209 | |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 210 | /** |
Lyude Paul | a859f12 | 2019-09-13 18:27:03 -0400 | [diff] [blame] | 211 | * drm_encoder_mask - find the mask of a registered encoder |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 212 | * @encoder: encoder to find mask for |
| 213 | * |
| 214 | * Given a registered encoder, return the mask bit of that encoder for an |
| 215 | * encoder's possible_clones field. |
| 216 | */ |
| 217 | static inline u32 drm_encoder_mask(const struct drm_encoder *encoder) |
| 218 | { |
| 219 | return 1 << drm_encoder_index(encoder); |
| 220 | } |
| 221 | |
| 222 | /** |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 223 | * drm_encoder_crtc_ok - can a given crtc drive a given encoder? |
| 224 | * @encoder: encoder to test |
| 225 | * @crtc: crtc to test |
| 226 | * |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 227 | * Returns false if @encoder can't be driven by @crtc, true otherwise. |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 228 | */ |
| 229 | static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder, |
| 230 | struct drm_crtc *crtc) |
| 231 | { |
| 232 | return !!(encoder->possible_crtcs & drm_crtc_mask(crtc)); |
| 233 | } |
| 234 | |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 235 | /** |
| 236 | * drm_encoder_find - find a &drm_encoder |
| 237 | * @dev: DRM device |
Dave Airlie | e7e62c7 | 2017-11-09 09:35:04 +1000 | [diff] [blame] | 238 | * @file_priv: drm file to check for lease against. |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 239 | * @id: encoder id |
| 240 | * |
| 241 | * Returns the encoder with @id, NULL if it doesn't exist. Simple wrapper around |
| 242 | * drm_mode_object_find(). |
| 243 | */ |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 244 | static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 245 | struct drm_file *file_priv, |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 246 | uint32_t id) |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 247 | { |
| 248 | struct drm_mode_object *mo; |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 249 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 250 | mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_ENCODER); |
Daniel Vetter | e03e6de | 2016-08-29 10:27:50 +0200 | [diff] [blame] | 251 | |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 252 | return mo ? obj_to_encoder(mo) : NULL; |
| 253 | } |
| 254 | |
| 255 | void drm_encoder_cleanup(struct drm_encoder *encoder); |
| 256 | |
Daniel Vetter | afb21ea6 | 2016-08-31 18:09:04 +0200 | [diff] [blame] | 257 | /** |
| 258 | * drm_for_each_encoder_mask - iterate over encoders specified by bitmask |
| 259 | * @encoder: the loop cursor |
| 260 | * @dev: the DRM device |
| 261 | * @encoder_mask: bitmask of encoder indices |
| 262 | * |
| 263 | * Iterate over all encoders specified by bitmask. |
| 264 | */ |
| 265 | #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \ |
| 266 | list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \ |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 267 | for_each_if ((encoder_mask) & drm_encoder_mask(encoder)) |
Daniel Vetter | afb21ea6 | 2016-08-31 18:09:04 +0200 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * drm_for_each_encoder - iterate over all encoders |
| 271 | * @encoder: the loop cursor |
| 272 | * @dev: the DRM device |
| 273 | * |
| 274 | * Iterate over all encoders of @dev. |
| 275 | */ |
| 276 | #define drm_for_each_encoder(encoder, dev) \ |
| 277 | list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head) |
| 278 | |
Daniel Vetter | 321a95a | 2016-08-29 10:27:49 +0200 | [diff] [blame] | 279 | #endif |