Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +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_CONNECTOR_H__ |
| 24 | #define __DRM_CONNECTOR_H__ |
| 25 | |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/ctype.h> |
Daniel Vetter | 949619f | 2016-08-29 10:27:51 +0200 | [diff] [blame] | 28 | #include <drm/drm_mode_object.h> |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 29 | |
Daniel Vetter | 199e4e9 | 2016-08-31 18:09:05 +0200 | [diff] [blame] | 30 | #include <uapi/drm/drm_mode.h> |
| 31 | |
| 32 | struct drm_device; |
| 33 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 34 | struct drm_connector_helper_funcs; |
| 35 | struct drm_device; |
| 36 | struct drm_crtc; |
| 37 | struct drm_encoder; |
| 38 | struct drm_property; |
| 39 | struct drm_property_blob; |
| 40 | struct edid; |
| 41 | |
| 42 | enum drm_connector_force { |
| 43 | DRM_FORCE_UNSPECIFIED, |
| 44 | DRM_FORCE_OFF, |
| 45 | DRM_FORCE_ON, /* force on analog part normally */ |
| 46 | DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */ |
| 47 | }; |
| 48 | |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 49 | /** |
| 50 | * enum drm_connector_status - status for a &drm_connector |
| 51 | * |
| 52 | * This enum is used to track the connector status. There are no separate |
| 53 | * #defines for the uapi! |
| 54 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 55 | enum drm_connector_status { |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 56 | /** |
| 57 | * @connector_status_connected: The connector is definitely connected to |
| 58 | * a sink device, and can be enabled. |
| 59 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 60 | connector_status_connected = 1, |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 61 | /** |
| 62 | * @connector_status_disconnected: The connector isn't connected to a |
| 63 | * sink device which can be autodetect. For digital outputs like DP or |
| 64 | * HDMI (which can be realiable probed) this means there's really |
| 65 | * nothing there. It is driver-dependent whether a connector with this |
| 66 | * status can be lit up or not. |
| 67 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 68 | connector_status_disconnected = 2, |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 69 | /** |
| 70 | * @connector_status_unknown: The connector's status could not be |
| 71 | * reliably detected. This happens when probing would either cause |
| 72 | * flicker (like load-detection when the connector is in use), or when a |
| 73 | * hardware resource isn't available (like when load-detection needs a |
| 74 | * free CRTC). It should be possible to light up the connector with one |
| 75 | * of the listed fallback modes. For default configuration userspace |
| 76 | * should only try to light up connectors with unknown status when |
| 77 | * there's not connector with @connector_status_connected. |
| 78 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 79 | connector_status_unknown = 3, |
| 80 | }; |
| 81 | |
| 82 | enum subpixel_order { |
| 83 | SubPixelUnknown = 0, |
| 84 | SubPixelHorizontalRGB, |
| 85 | SubPixelHorizontalBGR, |
| 86 | SubPixelVerticalRGB, |
| 87 | SubPixelVerticalBGR, |
| 88 | SubPixelNone, |
| 89 | }; |
| 90 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 91 | /** |
| 92 | * struct drm_display_info - runtime data about the connected sink |
| 93 | * |
| 94 | * Describes a given display (e.g. CRT or flat panel) and its limitations. For |
| 95 | * fixed display sinks like built-in panels there's not much difference between |
| 96 | * this and struct &drm_connector. But for sinks with a real cable this |
| 97 | * structure is meant to describe all the things at the other end of the cable. |
| 98 | * |
| 99 | * For sinks which provide an EDID this can be filled out by calling |
| 100 | * drm_add_edid_modes(). |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 101 | */ |
| 102 | struct drm_display_info { |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 103 | /** |
| 104 | * @name: Name of the display. |
| 105 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 106 | char name[DRM_DISPLAY_INFO_LEN]; |
| 107 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 108 | /** |
| 109 | * @width_mm: Physical width in mm. |
| 110 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 111 | unsigned int width_mm; |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 112 | /** |
| 113 | * @height_mm: Physical height in mm. |
| 114 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 115 | unsigned int height_mm; |
| 116 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 117 | /** |
| 118 | * @pixel_clock: Maximum pixel clock supported by the sink, in units of |
| 119 | * 100Hz. This mismatches the clok in &drm_display_mode (which is in |
| 120 | * kHZ), because that's what the EDID uses as base unit. |
| 121 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 122 | unsigned int pixel_clock; |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 123 | /** |
| 124 | * @bpc: Maximum bits per color channel. Used by HDMI and DP outputs. |
| 125 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 126 | unsigned int bpc; |
| 127 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 128 | /** |
| 129 | * @subpixel_order: Subpixel order of LCD panels. |
| 130 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 131 | enum subpixel_order subpixel_order; |
| 132 | |
| 133 | #define DRM_COLOR_FORMAT_RGB444 (1<<0) |
| 134 | #define DRM_COLOR_FORMAT_YCRCB444 (1<<1) |
| 135 | #define DRM_COLOR_FORMAT_YCRCB422 (1<<2) |
| 136 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 137 | /** |
| 138 | * @color_formats: HDMI Color formats, selects between RGB and YCrCb |
| 139 | * modes. Used DRM_COLOR_FORMAT\_ defines, which are _not_ the same ones |
| 140 | * as used to describe the pixel format in framebuffers, and also don't |
| 141 | * match the formats in @bus_formats which are shared with v4l. |
| 142 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 143 | u32 color_formats; |
| 144 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 145 | /** |
| 146 | * @bus_formats: Pixel data format on the wire, somewhat redundant with |
| 147 | * @color_formats. Array of size @num_bus_formats encoded using |
| 148 | * MEDIA_BUS_FMT\_ defines shared with v4l and media drivers. |
| 149 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 150 | const u32 *bus_formats; |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 151 | /** |
| 152 | * @num_bus_formats: Size of @bus_formats array. |
| 153 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 154 | unsigned int num_bus_formats; |
| 155 | |
| 156 | #define DRM_BUS_FLAG_DE_LOW (1<<0) |
| 157 | #define DRM_BUS_FLAG_DE_HIGH (1<<1) |
| 158 | /* drive data on pos. edge */ |
| 159 | #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2) |
| 160 | /* drive data on neg. edge */ |
| 161 | #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3) |
| 162 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 163 | /** |
| 164 | * @bus_flags: Additional information (like pixel signal polarity) for |
| 165 | * the pixel data on the bus, using DRM_BUS_FLAGS\_ defines. |
| 166 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 167 | u32 bus_flags; |
| 168 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 169 | /** |
Ville Syrjälä | 2a272ca | 2016-09-28 16:51:37 +0300 | [diff] [blame] | 170 | * @max_tmds_clock: Maximum TMDS clock rate supported by the |
| 171 | * sink in kHz. 0 means undefined. |
| 172 | */ |
| 173 | int max_tmds_clock; |
| 174 | |
| 175 | /** |
| 176 | * @dvi_dual: Dual-link DVI sink? |
| 177 | */ |
| 178 | bool dvi_dual; |
| 179 | |
| 180 | /** |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 181 | * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even |
| 182 | * more stuff redundant with @bus_formats. |
| 183 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 184 | u8 edid_hdmi_dc_modes; |
| 185 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 186 | /** |
| 187 | * @cea_rev: CEA revision of the HDMI sink. |
| 188 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 189 | u8 cea_rev; |
| 190 | }; |
| 191 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 192 | int drm_display_info_set_bus_formats(struct drm_display_info *info, |
| 193 | const u32 *formats, |
| 194 | unsigned int num_formats); |
| 195 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 196 | /** |
| 197 | * struct drm_connector_state - mutable connector state |
| 198 | * @connector: backpointer to the connector |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 199 | * @best_encoder: can be used by helpers and drivers to select the encoder |
| 200 | * @state: backpointer to global drm_atomic_state |
| 201 | */ |
| 202 | struct drm_connector_state { |
| 203 | struct drm_connector *connector; |
| 204 | |
Daniel Vetter | afb21ea6 | 2016-08-31 18:09:04 +0200 | [diff] [blame] | 205 | /** |
| 206 | * @crtc: CRTC to connect connector to, NULL if disabled. |
| 207 | * |
| 208 | * Do not change this directly, use drm_atomic_set_crtc_for_connector() |
| 209 | * instead. |
| 210 | */ |
| 211 | struct drm_crtc *crtc; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 212 | |
| 213 | struct drm_encoder *best_encoder; |
| 214 | |
| 215 | struct drm_atomic_state *state; |
| 216 | }; |
| 217 | |
| 218 | /** |
| 219 | * struct drm_connector_funcs - control connectors on a given device |
| 220 | * |
| 221 | * Each CRTC may have one or more connectors attached to it. The functions |
| 222 | * below allow the core DRM code to control connectors, enumerate available modes, |
| 223 | * etc. |
| 224 | */ |
| 225 | struct drm_connector_funcs { |
| 226 | /** |
| 227 | * @dpms: |
| 228 | * |
| 229 | * Legacy entry point to set the per-connector DPMS state. Legacy DPMS |
| 230 | * is exposed as a standard property on the connector, but diverted to |
| 231 | * this callback in the drm core. Note that atomic drivers don't |
| 232 | * implement the 4 level DPMS support on the connector any more, but |
| 233 | * instead only have an on/off "ACTIVE" property on the CRTC object. |
| 234 | * |
| 235 | * Drivers implementing atomic modeset should use |
| 236 | * drm_atomic_helper_connector_dpms() to implement this hook. |
| 237 | * |
| 238 | * RETURNS: |
| 239 | * |
| 240 | * 0 on success or a negative error code on failure. |
| 241 | */ |
| 242 | int (*dpms)(struct drm_connector *connector, int mode); |
| 243 | |
| 244 | /** |
| 245 | * @reset: |
| 246 | * |
| 247 | * Reset connector hardware and software state to off. This function isn't |
| 248 | * called by the core directly, only through drm_mode_config_reset(). |
| 249 | * It's not a helper hook only for historical reasons. |
| 250 | * |
| 251 | * Atomic drivers can use drm_atomic_helper_connector_reset() to reset |
| 252 | * atomic state using this hook. |
| 253 | */ |
| 254 | void (*reset)(struct drm_connector *connector); |
| 255 | |
| 256 | /** |
| 257 | * @detect: |
| 258 | * |
| 259 | * Check to see if anything is attached to the connector. The parameter |
| 260 | * force is set to false whilst polling, true when checking the |
| 261 | * connector due to a user request. force can be used by the driver to |
| 262 | * avoid expensive, destructive operations during automated probing. |
| 263 | * |
| 264 | * FIXME: |
| 265 | * |
| 266 | * Note that this hook is only called by the probe helper. It's not in |
| 267 | * the helper library vtable purely for historical reasons. The only DRM |
| 268 | * core entry point to probe connector state is @fill_modes. |
| 269 | * |
| 270 | * RETURNS: |
| 271 | * |
| 272 | * drm_connector_status indicating the connector's status. |
| 273 | */ |
| 274 | enum drm_connector_status (*detect)(struct drm_connector *connector, |
| 275 | bool force); |
| 276 | |
| 277 | /** |
| 278 | * @force: |
| 279 | * |
| 280 | * This function is called to update internal encoder state when the |
| 281 | * connector is forced to a certain state by userspace, either through |
| 282 | * the sysfs interfaces or on the kernel cmdline. In that case the |
| 283 | * @detect callback isn't called. |
| 284 | * |
| 285 | * FIXME: |
| 286 | * |
| 287 | * Note that this hook is only called by the probe helper. It's not in |
| 288 | * the helper library vtable purely for historical reasons. The only DRM |
| 289 | * core entry point to probe connector state is @fill_modes. |
| 290 | */ |
| 291 | void (*force)(struct drm_connector *connector); |
| 292 | |
| 293 | /** |
| 294 | * @fill_modes: |
| 295 | * |
| 296 | * Entry point for output detection and basic mode validation. The |
| 297 | * driver should reprobe the output if needed (e.g. when hotplug |
| 298 | * handling is unreliable), add all detected modes to connector->modes |
| 299 | * and filter out any the device can't support in any configuration. It |
| 300 | * also needs to filter out any modes wider or higher than the |
| 301 | * parameters max_width and max_height indicate. |
| 302 | * |
| 303 | * The drivers must also prune any modes no longer valid from |
| 304 | * connector->modes. Furthermore it must update connector->status and |
| 305 | * connector->edid. If no EDID has been received for this output |
| 306 | * connector->edid must be NULL. |
| 307 | * |
| 308 | * Drivers using the probe helpers should use |
| 309 | * drm_helper_probe_single_connector_modes() or |
| 310 | * drm_helper_probe_single_connector_modes_nomerge() to implement this |
| 311 | * function. |
| 312 | * |
| 313 | * RETURNS: |
| 314 | * |
| 315 | * The number of modes detected and filled into connector->modes. |
| 316 | */ |
| 317 | int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height); |
| 318 | |
| 319 | /** |
| 320 | * @set_property: |
| 321 | * |
| 322 | * This is the legacy entry point to update a property attached to the |
| 323 | * connector. |
| 324 | * |
| 325 | * Drivers implementing atomic modeset should use |
| 326 | * drm_atomic_helper_connector_set_property() to implement this hook. |
| 327 | * |
| 328 | * This callback is optional if the driver does not support any legacy |
| 329 | * driver-private properties. |
| 330 | * |
| 331 | * RETURNS: |
| 332 | * |
| 333 | * 0 on success or a negative error code on failure. |
| 334 | */ |
| 335 | int (*set_property)(struct drm_connector *connector, struct drm_property *property, |
| 336 | uint64_t val); |
| 337 | |
| 338 | /** |
| 339 | * @late_register: |
| 340 | * |
| 341 | * This optional hook can be used to register additional userspace |
| 342 | * interfaces attached to the connector, light backlight control, i2c, |
| 343 | * DP aux or similar interfaces. It is called late in the driver load |
| 344 | * sequence from drm_connector_register() when registering all the |
| 345 | * core drm connector interfaces. Everything added from this callback |
| 346 | * should be unregistered in the early_unregister callback. |
| 347 | * |
Daniel Vetter | 82b6693 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 348 | * This is called while holding drm_connector->mutex. |
| 349 | * |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 350 | * Returns: |
| 351 | * |
| 352 | * 0 on success, or a negative error code on failure. |
| 353 | */ |
| 354 | int (*late_register)(struct drm_connector *connector); |
| 355 | |
| 356 | /** |
| 357 | * @early_unregister: |
| 358 | * |
| 359 | * This optional hook should be used to unregister the additional |
| 360 | * userspace interfaces attached to the connector from |
Grazvydas Ignotas | 621a999 | 2016-10-09 20:07:00 +0300 | [diff] [blame] | 361 | * late_register(). It is called from drm_connector_unregister(), |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 362 | * early in the driver unload sequence to disable userspace access |
| 363 | * before data structures are torndown. |
Daniel Vetter | 82b6693 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 364 | * |
| 365 | * This is called while holding drm_connector->mutex. |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 366 | */ |
| 367 | void (*early_unregister)(struct drm_connector *connector); |
| 368 | |
| 369 | /** |
| 370 | * @destroy: |
| 371 | * |
| 372 | * Clean up connector resources. This is called at driver unload time |
| 373 | * through drm_mode_config_cleanup(). It can also be called at runtime |
| 374 | * when a connector is being hot-unplugged for drivers that support |
| 375 | * connector hotplugging (e.g. DisplayPort MST). |
| 376 | */ |
| 377 | void (*destroy)(struct drm_connector *connector); |
| 378 | |
| 379 | /** |
| 380 | * @atomic_duplicate_state: |
| 381 | * |
| 382 | * Duplicate the current atomic state for this connector and return it. |
Grazvydas Ignotas | 621a999 | 2016-10-09 20:07:00 +0300 | [diff] [blame] | 383 | * The core and helpers guarantee that any atomic state duplicated with |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 384 | * this hook and still owned by the caller (i.e. not transferred to the |
| 385 | * driver by calling ->atomic_commit() from struct |
| 386 | * &drm_mode_config_funcs) will be cleaned up by calling the |
| 387 | * @atomic_destroy_state hook in this structure. |
| 388 | * |
| 389 | * Atomic drivers which don't subclass struct &drm_connector_state should use |
| 390 | * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the |
| 391 | * state structure to extend it with driver-private state should use |
| 392 | * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is |
| 393 | * duplicated in a consistent fashion across drivers. |
| 394 | * |
| 395 | * It is an error to call this hook before connector->state has been |
| 396 | * initialized correctly. |
| 397 | * |
| 398 | * NOTE: |
| 399 | * |
| 400 | * If the duplicate state references refcounted resources this hook must |
| 401 | * acquire a reference for each of them. The driver must release these |
| 402 | * references again in @atomic_destroy_state. |
| 403 | * |
| 404 | * RETURNS: |
| 405 | * |
| 406 | * Duplicated atomic state or NULL when the allocation failed. |
| 407 | */ |
| 408 | struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector); |
| 409 | |
| 410 | /** |
| 411 | * @atomic_destroy_state: |
| 412 | * |
| 413 | * Destroy a state duplicated with @atomic_duplicate_state and release |
| 414 | * or unreference all resources it references |
| 415 | */ |
| 416 | void (*atomic_destroy_state)(struct drm_connector *connector, |
| 417 | struct drm_connector_state *state); |
| 418 | |
| 419 | /** |
| 420 | * @atomic_set_property: |
| 421 | * |
| 422 | * Decode a driver-private property value and store the decoded value |
| 423 | * into the passed-in state structure. Since the atomic core decodes all |
| 424 | * standardized properties (even for extensions beyond the core set of |
| 425 | * properties which might not be implemented by all drivers) this |
| 426 | * requires drivers to subclass the state structure. |
| 427 | * |
| 428 | * Such driver-private properties should really only be implemented for |
| 429 | * truly hardware/vendor specific state. Instead it is preferred to |
| 430 | * standardize atomic extension and decode the properties used to expose |
| 431 | * such an extension in the core. |
| 432 | * |
| 433 | * Do not call this function directly, use |
| 434 | * drm_atomic_connector_set_property() instead. |
| 435 | * |
| 436 | * This callback is optional if the driver does not support any |
| 437 | * driver-private atomic properties. |
| 438 | * |
| 439 | * NOTE: |
| 440 | * |
| 441 | * This function is called in the state assembly phase of atomic |
| 442 | * modesets, which can be aborted for any reason (including on |
| 443 | * userspace's request to just check whether a configuration would be |
| 444 | * possible). Drivers MUST NOT touch any persistent state (hardware or |
| 445 | * software) or data structures except the passed in @state parameter. |
| 446 | * |
| 447 | * Also since userspace controls in which order properties are set this |
| 448 | * function must not do any input validation (since the state update is |
| 449 | * incomplete and hence likely inconsistent). Instead any such input |
| 450 | * validation must be done in the various atomic_check callbacks. |
| 451 | * |
| 452 | * RETURNS: |
| 453 | * |
| 454 | * 0 if the property has been found, -EINVAL if the property isn't |
| 455 | * implemented by the driver (which shouldn't ever happen, the core only |
| 456 | * asks for properties attached to this connector). No other validation |
| 457 | * is allowed by the driver. The core already checks that the property |
| 458 | * value is within the range (integer, valid enum value, ...) the driver |
| 459 | * set when registering the property. |
| 460 | */ |
| 461 | int (*atomic_set_property)(struct drm_connector *connector, |
| 462 | struct drm_connector_state *state, |
| 463 | struct drm_property *property, |
| 464 | uint64_t val); |
| 465 | |
| 466 | /** |
| 467 | * @atomic_get_property: |
| 468 | * |
| 469 | * Reads out the decoded driver-private property. This is used to |
| 470 | * implement the GETCONNECTOR IOCTL. |
| 471 | * |
| 472 | * Do not call this function directly, use |
| 473 | * drm_atomic_connector_get_property() instead. |
| 474 | * |
| 475 | * This callback is optional if the driver does not support any |
| 476 | * driver-private atomic properties. |
| 477 | * |
| 478 | * RETURNS: |
| 479 | * |
| 480 | * 0 on success, -EINVAL if the property isn't implemented by the |
| 481 | * driver (which shouldn't ever happen, the core only asks for |
| 482 | * properties attached to this connector). |
| 483 | */ |
| 484 | int (*atomic_get_property)(struct drm_connector *connector, |
| 485 | const struct drm_connector_state *state, |
| 486 | struct drm_property *property, |
| 487 | uint64_t *val); |
| 488 | }; |
| 489 | |
| 490 | /* mode specified on the command line */ |
| 491 | struct drm_cmdline_mode { |
| 492 | bool specified; |
| 493 | bool refresh_specified; |
| 494 | bool bpp_specified; |
| 495 | int xres, yres; |
| 496 | int bpp; |
| 497 | int refresh; |
| 498 | bool rb; |
| 499 | bool interlace; |
| 500 | bool cvt; |
| 501 | bool margins; |
| 502 | enum drm_connector_force force; |
| 503 | }; |
| 504 | |
| 505 | /** |
| 506 | * struct drm_connector - central DRM connector control structure |
| 507 | * @dev: parent DRM device |
| 508 | * @kdev: kernel device for sysfs attributes |
| 509 | * @attr: sysfs attributes |
| 510 | * @head: list management |
| 511 | * @base: base KMS object |
| 512 | * @name: human readable name, can be overwritten by the driver |
| 513 | * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h |
| 514 | * @connector_type_id: index into connector type enum |
| 515 | * @interlace_allowed: can this connector handle interlaced modes? |
| 516 | * @doublescan_allowed: can this connector handle doublescan? |
| 517 | * @stereo_allowed: can this connector handle stereo modes? |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 518 | * @modes: modes available on this connector (from fill_modes() + user) |
| 519 | * @status: one of the drm_connector_status enums (connected, not, or unknown) |
| 520 | * @probed_modes: list of modes derived directly from the display |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 521 | * @funcs: connector control functions |
| 522 | * @edid_blob_ptr: DRM property containing EDID if present |
| 523 | * @properties: property tracking for this connector |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 524 | * @dpms: current dpms state |
| 525 | * @helper_private: mid-layer private data |
| 526 | * @cmdline_mode: mode line parsed from the kernel cmdline for this connector |
| 527 | * @force: a DRM_FORCE_<foo> state for forced mode sets |
| 528 | * @override_edid: has the EDID been overwritten through debugfs for testing? |
| 529 | * @encoder_ids: valid encoders for this connector |
| 530 | * @encoder: encoder driving this connector, if any |
| 531 | * @eld: EDID-like data, if present |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 532 | * @latency_present: AV delay info from ELD, if found |
| 533 | * @video_latency: video latency info from ELD, if found |
| 534 | * @audio_latency: audio latency info from ELD, if found |
| 535 | * @null_edid_counter: track sinks that give us all zeros for the EDID |
| 536 | * @bad_edid_counter: track sinks that give us an EDID with invalid checksum |
| 537 | * @edid_corrupt: indicates whether the last read EDID was corrupt |
| 538 | * @debugfs_entry: debugfs directory for this connector |
| 539 | * @state: current atomic state for this connector |
| 540 | * @has_tile: is this connector connected to a tiled monitor |
| 541 | * @tile_group: tile group for the connected monitor |
| 542 | * @tile_is_single_monitor: whether the tile is one monitor housing |
| 543 | * @num_h_tile: number of horizontal tiles in the tile group |
| 544 | * @num_v_tile: number of vertical tiles in the tile group |
| 545 | * @tile_h_loc: horizontal location of this tile |
| 546 | * @tile_v_loc: vertical location of this tile |
| 547 | * @tile_h_size: horizontal size of this tile. |
| 548 | * @tile_v_size: vertical size of this tile. |
| 549 | * |
| 550 | * Each connector may be connected to one or more CRTCs, or may be clonable by |
| 551 | * another connector if they can share a CRTC. Each connector also has a specific |
| 552 | * position in the broader display (referred to as a 'screen' though it could |
| 553 | * span multiple monitors). |
| 554 | */ |
| 555 | struct drm_connector { |
| 556 | struct drm_device *dev; |
| 557 | struct device *kdev; |
| 558 | struct device_attribute *attr; |
| 559 | struct list_head head; |
| 560 | |
| 561 | struct drm_mode_object base; |
| 562 | |
| 563 | char *name; |
| 564 | |
| 565 | /** |
Daniel Vetter | 82b6693 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 566 | * @mutex: Lock for general connector state, but currently only protects |
| 567 | * @registered. Most of the connector state is still protected by the |
| 568 | * mutex in &drm_mode_config. |
| 569 | */ |
| 570 | struct mutex mutex; |
| 571 | |
| 572 | /** |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 573 | * @index: Compacted connector index, which matches the position inside |
| 574 | * the mode_config.list for drivers not supporting hot-add/removing. Can |
| 575 | * be used as an array index. It is invariant over the lifetime of the |
| 576 | * connector. |
| 577 | */ |
| 578 | unsigned index; |
| 579 | |
| 580 | int connector_type; |
| 581 | int connector_type_id; |
| 582 | bool interlace_allowed; |
| 583 | bool doublescan_allowed; |
| 584 | bool stereo_allowed; |
Daniel Vetter | 82b6693 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 585 | /** |
| 586 | * @registered: Is this connector exposed (registered) with userspace? |
| 587 | * Protected by @mutex. |
| 588 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 589 | bool registered; |
| 590 | struct list_head modes; /* list of modes on this connector */ |
| 591 | |
| 592 | enum drm_connector_status status; |
| 593 | |
| 594 | /* these are modes added by probing with DDC or the BIOS */ |
| 595 | struct list_head probed_modes; |
| 596 | |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 597 | /** |
| 598 | * @display_info: Display information is filled from EDID information |
| 599 | * when a display is detected. For non hot-pluggable displays such as |
| 600 | * flat panels in embedded systems, the driver should initialize the |
| 601 | * display_info.width_mm and display_info.height_mm fields with the |
| 602 | * physical size of the display. |
| 603 | */ |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 604 | struct drm_display_info display_info; |
| 605 | const struct drm_connector_funcs *funcs; |
| 606 | |
| 607 | struct drm_property_blob *edid_blob_ptr; |
| 608 | struct drm_object_properties properties; |
| 609 | |
| 610 | /** |
| 611 | * @path_blob_ptr: |
| 612 | * |
| 613 | * DRM blob property data for the DP MST path property. |
| 614 | */ |
| 615 | struct drm_property_blob *path_blob_ptr; |
| 616 | |
| 617 | /** |
| 618 | * @tile_blob_ptr: |
| 619 | * |
| 620 | * DRM blob property data for the tile property (used mostly by DP MST). |
| 621 | * This is meant for screens which are driven through separate display |
| 622 | * pipelines represented by &drm_crtc, which might not be running with |
| 623 | * genlocked clocks. For tiled panels which are genlocked, like |
| 624 | * dual-link LVDS or dual-link DSI, the driver should try to not expose |
| 625 | * the tiling and virtualize both &drm_crtc and &drm_plane if needed. |
| 626 | */ |
| 627 | struct drm_property_blob *tile_blob_ptr; |
| 628 | |
| 629 | /* should we poll this connector for connects and disconnects */ |
| 630 | /* hot plug detectable */ |
| 631 | #define DRM_CONNECTOR_POLL_HPD (1 << 0) |
| 632 | /* poll for connections */ |
| 633 | #define DRM_CONNECTOR_POLL_CONNECT (1 << 1) |
| 634 | /* can cleanly poll for disconnections without flickering the screen */ |
| 635 | /* DACs should rarely do this without a lot of testing */ |
| 636 | #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2) |
| 637 | |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 638 | /** |
| 639 | * @polled: |
| 640 | * |
| 641 | * Connector polling mode, a combination of |
| 642 | * |
| 643 | * DRM_CONNECTOR_POLL_HPD |
| 644 | * The connector generates hotplug events and doesn't need to be |
| 645 | * periodically polled. The CONNECT and DISCONNECT flags must not |
| 646 | * be set together with the HPD flag. |
| 647 | * |
| 648 | * DRM_CONNECTOR_POLL_CONNECT |
| 649 | * Periodically poll the connector for connection. |
| 650 | * |
| 651 | * DRM_CONNECTOR_POLL_DISCONNECT |
| 652 | * Periodically poll the connector for disconnection. |
| 653 | * |
| 654 | * Set to 0 for connectors that don't support connection status |
| 655 | * discovery. |
| 656 | */ |
| 657 | uint8_t polled; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 658 | |
| 659 | /* requested DPMS state */ |
| 660 | int dpms; |
| 661 | |
| 662 | const struct drm_connector_helper_funcs *helper_private; |
| 663 | |
| 664 | /* forced on connector */ |
| 665 | struct drm_cmdline_mode cmdline_mode; |
| 666 | enum drm_connector_force force; |
| 667 | bool override_edid; |
| 668 | |
| 669 | #define DRM_CONNECTOR_MAX_ENCODER 3 |
| 670 | uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER]; |
| 671 | struct drm_encoder *encoder; /* currently active encoder */ |
| 672 | |
| 673 | #define MAX_ELD_BYTES 128 |
| 674 | /* EDID bits */ |
| 675 | uint8_t eld[MAX_ELD_BYTES]; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 676 | bool latency_present[2]; |
| 677 | int video_latency[2]; /* [0]: progressive, [1]: interlaced */ |
| 678 | int audio_latency[2]; |
| 679 | int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */ |
| 680 | unsigned bad_edid_counter; |
| 681 | |
| 682 | /* Flag for raw EDID header corruption - used in Displayport |
| 683 | * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6 |
| 684 | */ |
| 685 | bool edid_corrupt; |
| 686 | |
| 687 | struct dentry *debugfs_entry; |
| 688 | |
| 689 | struct drm_connector_state *state; |
| 690 | |
| 691 | /* DisplayID bits */ |
| 692 | bool has_tile; |
| 693 | struct drm_tile_group *tile_group; |
| 694 | bool tile_is_single_monitor; |
| 695 | |
| 696 | uint8_t num_h_tile, num_v_tile; |
| 697 | uint8_t tile_h_loc, tile_v_loc; |
| 698 | uint16_t tile_h_size, tile_v_size; |
| 699 | }; |
| 700 | |
| 701 | #define obj_to_connector(x) container_of(x, struct drm_connector, base) |
| 702 | |
| 703 | int drm_connector_init(struct drm_device *dev, |
| 704 | struct drm_connector *connector, |
| 705 | const struct drm_connector_funcs *funcs, |
| 706 | int connector_type); |
| 707 | int drm_connector_register(struct drm_connector *connector); |
| 708 | void drm_connector_unregister(struct drm_connector *connector); |
| 709 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
| 710 | struct drm_encoder *encoder); |
| 711 | |
| 712 | void drm_connector_cleanup(struct drm_connector *connector); |
| 713 | static inline unsigned drm_connector_index(struct drm_connector *connector) |
| 714 | { |
| 715 | return connector->index; |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * drm_connector_lookup - lookup connector object |
| 720 | * @dev: DRM device |
| 721 | * @id: connector object id |
| 722 | * |
| 723 | * This function looks up the connector object specified by id |
| 724 | * add takes a reference to it. |
| 725 | */ |
| 726 | static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev, |
| 727 | uint32_t id) |
| 728 | { |
| 729 | struct drm_mode_object *mo; |
| 730 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR); |
| 731 | return mo ? obj_to_connector(mo) : NULL; |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * drm_connector_reference - incr the connector refcnt |
| 736 | * @connector: connector |
| 737 | * |
| 738 | * This function increments the connector's refcount. |
| 739 | */ |
| 740 | static inline void drm_connector_reference(struct drm_connector *connector) |
| 741 | { |
| 742 | drm_mode_object_reference(&connector->base); |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * drm_connector_unreference - unref a connector |
| 747 | * @connector: connector to unref |
| 748 | * |
| 749 | * This function decrements the connector's refcount and frees it if it drops to zero. |
| 750 | */ |
| 751 | static inline void drm_connector_unreference(struct drm_connector *connector) |
| 752 | { |
| 753 | drm_mode_object_unreference(&connector->base); |
| 754 | } |
| 755 | |
| 756 | const char *drm_get_connector_status_name(enum drm_connector_status status); |
| 757 | const char *drm_get_subpixel_order_name(enum subpixel_order order); |
| 758 | const char *drm_get_dpms_name(int val); |
| 759 | const char *drm_get_dvi_i_subconnector_name(int val); |
| 760 | const char *drm_get_dvi_i_select_name(int val); |
| 761 | const char *drm_get_tv_subconnector_name(int val); |
| 762 | const char *drm_get_tv_select_name(int val); |
| 763 | |
| 764 | int drm_mode_create_dvi_i_properties(struct drm_device *dev); |
| 765 | int drm_mode_create_tv_properties(struct drm_device *dev, |
| 766 | unsigned int num_modes, |
| 767 | const char * const modes[]); |
| 768 | int drm_mode_create_scaling_mode_property(struct drm_device *dev); |
| 769 | int drm_mode_create_aspect_ratio_property(struct drm_device *dev); |
| 770 | int drm_mode_create_suggested_offset_properties(struct drm_device *dev); |
| 771 | |
| 772 | int drm_mode_connector_set_path_property(struct drm_connector *connector, |
| 773 | const char *path); |
| 774 | int drm_mode_connector_set_tile_property(struct drm_connector *connector); |
| 775 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
| 776 | const struct edid *edid); |
Daniel Vetter | afb21ea6 | 2016-08-31 18:09:04 +0200 | [diff] [blame] | 777 | |
| 778 | /** |
| 779 | * drm_for_each_connector - iterate over all connectors |
| 780 | * @connector: the loop cursor |
| 781 | * @dev: the DRM device |
| 782 | * |
| 783 | * Iterate over all connectors of @dev. |
| 784 | */ |
| 785 | #define drm_for_each_connector(connector, dev) \ |
| 786 | for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \ |
| 787 | connector = list_first_entry(&(dev)->mode_config.connector_list, \ |
| 788 | struct drm_connector, head); \ |
| 789 | &connector->head != (&(dev)->mode_config.connector_list); \ |
| 790 | connector = list_next_entry(connector, head)) |
| 791 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 792 | #endif |