blob: f632ca05960e788961e57a4077fb9364a327fccb [file] [log] [blame]
Daniel Vetter52217192016-08-12 22:48:50 +02001/*
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
Daniel Vetter52217192016-08-12 22:48:50 +020023#include <drm/drm_connector.h>
24#include <drm/drm_edid.h>
Laurent Pinchart93382032016-11-28 20:51:09 +020025#include <drm/drm_encoder.h>
Hans de Goede8d70f392017-11-25 20:35:49 +010026#include <drm/drm_utils.h>
Daniel Vetter99f45e32018-09-05 15:57:06 +020027#include <drm/drm_print.h>
28#include <drm/drm_drv.h>
29#include <drm/drm_file.h>
30
31#include <linux/uaccess.h>
Daniel Vetter52217192016-08-12 22:48:50 +020032
33#include "drm_crtc_internal.h"
34#include "drm_internal.h"
35
Daniel Vetterae2a6da2016-08-12 22:48:53 +020036/**
37 * DOC: overview
38 *
39 * In DRM connectors are the general abstraction for display sinks, and include
40 * als fixed panels or anything else that can display pixels in some form. As
41 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
42 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
Thierry Redingad093602017-02-28 15:46:39 +010043 * Hence they are reference-counted using drm_connector_get() and
44 * drm_connector_put().
Daniel Vetterae2a6da2016-08-12 22:48:53 +020045 *
Daniel Vetterd5745282017-01-25 07:26:45 +010046 * KMS driver must create, initialize, register and attach at a &struct
47 * drm_connector for each such sink. The instance is created as other KMS
Daniel Vetteraec97462017-01-25 07:26:48 +010048 * objects and initialized by setting the following fields. The connector is
49 * initialized with a call to drm_connector_init() with a pointer to the
50 * &struct drm_connector_funcs and a connector type, and then exposed to
51 * userspace with a call to drm_connector_register().
Daniel Vetterae2a6da2016-08-12 22:48:53 +020052 *
53 * Connectors must be attached to an encoder to be used. For devices that map
54 * connectors to encoders 1:1, the connector should be attached at
Daniel Vettercde4c442018-07-09 10:40:07 +020055 * initialization time with a call to drm_connector_attach_encoder(). The
Daniel Vetterd5745282017-01-25 07:26:45 +010056 * driver must also set the &drm_connector.encoder field to point to the
Daniel Vetterae2a6da2016-08-12 22:48:53 +020057 * attached encoder.
58 *
59 * For connectors which are not fixed (like built-in panels) the driver needs to
60 * support hotplug notifications. The simplest way to do that is by using the
61 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
62 * hardware support for hotplug interrupts. Connectors with hardware hotplug
63 * support can instead use e.g. drm_helper_hpd_irq_event().
64 */
65
Daniel Vetter52217192016-08-12 22:48:50 +020066struct drm_conn_prop_enum_list {
67 int type;
68 const char *name;
69 struct ida ida;
70};
71
72/*
73 * Connector and encoder types.
74 */
75static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
76 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
77 { DRM_MODE_CONNECTOR_VGA, "VGA" },
78 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
79 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
80 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
81 { DRM_MODE_CONNECTOR_Composite, "Composite" },
82 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
83 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
84 { DRM_MODE_CONNECTOR_Component, "Component" },
85 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
86 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
87 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
88 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
89 { DRM_MODE_CONNECTOR_TV, "TV" },
90 { DRM_MODE_CONNECTOR_eDP, "eDP" },
91 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
92 { DRM_MODE_CONNECTOR_DSI, "DSI" },
93 { DRM_MODE_CONNECTOR_DPI, "DPI" },
Brian Starkey935774c2017-03-29 17:42:32 +010094 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
Noralf Trønnesfc06bf12019-07-19 17:59:06 +020095 { DRM_MODE_CONNECTOR_SPI, "SPI" },
Daniel Vetter52217192016-08-12 22:48:50 +020096};
97
98void drm_connector_ida_init(void)
99{
100 int i;
101
102 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
103 ida_init(&drm_connector_enum_list[i].ida);
104}
105
106void drm_connector_ida_destroy(void)
107{
108 int i;
109
110 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
111 ida_destroy(&drm_connector_enum_list[i].ida);
112}
113
114/**
115 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
116 * @connector: connector to quwery
117 *
Daniel Vetterae2a6da2016-08-12 22:48:53 +0200118 * The kernel supports per-connector configuration of its consoles through
Daniel Vetter52217192016-08-12 22:48:50 +0200119 * use of the video= parameter. This function parses that option and
120 * extracts the user's specified mode (or enable/disable status) for a
121 * particular connector. This is typically only used during the early fbdev
122 * setup.
123 */
124static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
125{
126 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
127 char *option = NULL;
128
129 if (fb_get_options(connector->name, &option))
130 return;
131
132 if (!drm_mode_parse_command_line_for_connector(option,
133 connector,
134 mode))
135 return;
136
137 if (mode->force) {
Jani Nikula6140cf22017-02-20 10:51:48 +0200138 DRM_INFO("forcing %s connector %s\n", connector->name,
139 drm_get_connector_force_name(mode->force));
Daniel Vetter52217192016-08-12 22:48:50 +0200140 connector->force = mode->force;
141 }
142
Hans de Goede09809392020-01-05 16:51:20 +0100143 if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
144 DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
145 connector->name, mode->panel_orientation);
146 drm_connector_set_panel_orientation(connector,
147 mode->panel_orientation);
148 }
149
Maxime Ripard3aeeb132019-06-19 12:17:50 +0200150 DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
Maxime Ripard50b09462019-06-24 10:40:16 +0200151 connector->name, mode->name,
Daniel Vetter52217192016-08-12 22:48:50 +0200152 mode->xres, mode->yres,
153 mode->refresh_specified ? mode->refresh : 60,
154 mode->rb ? " reduced blanking" : "",
155 mode->margins ? " with margins" : "",
156 mode->interlace ? " interlaced" : "");
157}
158
159static void drm_connector_free(struct kref *kref)
160{
161 struct drm_connector *connector =
162 container_of(kref, struct drm_connector, base.refcount);
163 struct drm_device *dev = connector->dev;
164
165 drm_mode_object_unregister(dev, &connector->base);
166 connector->funcs->destroy(connector);
167}
168
Daniel Vetterea497bb2017-12-13 13:49:36 +0100169void drm_connector_free_work_fn(struct work_struct *work)
Daniel Vettera703c552017-12-04 21:48:18 +0100170{
Daniel Vetterea497bb2017-12-13 13:49:36 +0100171 struct drm_connector *connector, *n;
172 struct drm_device *dev =
173 container_of(work, struct drm_device, mode_config.connector_free_work);
174 struct drm_mode_config *config = &dev->mode_config;
175 unsigned long flags;
176 struct llist_node *freed;
Daniel Vettera703c552017-12-04 21:48:18 +0100177
Daniel Vetterea497bb2017-12-13 13:49:36 +0100178 spin_lock_irqsave(&config->connector_list_lock, flags);
179 freed = llist_del_all(&config->connector_free_list);
180 spin_unlock_irqrestore(&config->connector_list_lock, flags);
181
182 llist_for_each_entry_safe(connector, n, freed, free_node) {
183 drm_mode_object_unregister(dev, &connector->base);
184 connector->funcs->destroy(connector);
185 }
Daniel Vettera703c552017-12-04 21:48:18 +0100186}
187
Daniel Vetter52217192016-08-12 22:48:50 +0200188/**
189 * drm_connector_init - Init a preallocated connector
190 * @dev: DRM device
191 * @connector: the connector to init
192 * @funcs: callbacks for this connector
193 * @connector_type: user visible type of the connector
194 *
195 * Initialises a preallocated connector. Connectors should be
196 * subclassed as part of driver connector objects.
197 *
198 * Returns:
199 * Zero on success, error code on failure.
200 */
201int drm_connector_init(struct drm_device *dev,
202 struct drm_connector *connector,
203 const struct drm_connector_funcs *funcs,
204 int connector_type)
205{
206 struct drm_mode_config *config = &dev->mode_config;
207 int ret;
208 struct ida *connector_ida =
209 &drm_connector_enum_list[connector_type].ida;
210
Haneen Mohammedba1f6652018-05-25 04:25:55 +0300211 WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
212 (!funcs->atomic_destroy_state ||
213 !funcs->atomic_duplicate_state));
214
Thierry Reding2135ea72017-02-28 15:46:37 +0100215 ret = __drm_mode_object_add(dev, &connector->base,
216 DRM_MODE_OBJECT_CONNECTOR,
217 false, drm_connector_free);
Daniel Vetter52217192016-08-12 22:48:50 +0200218 if (ret)
Daniel Vetter613051d2016-12-14 00:08:06 +0100219 return ret;
Daniel Vetter52217192016-08-12 22:48:50 +0200220
221 connector->base.properties = &connector->properties;
222 connector->dev = dev;
223 connector->funcs = funcs;
224
Ville Syrjälä2a8d3ea2018-01-25 15:30:20 +0200225 /* connector index is used with 32bit bitmasks */
226 ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
227 if (ret < 0) {
228 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
229 drm_connector_enum_list[connector_type].name,
230 ret);
Daniel Vetter52217192016-08-12 22:48:50 +0200231 goto out_put;
Ville Syrjälä2a8d3ea2018-01-25 15:30:20 +0200232 }
Daniel Vetter52217192016-08-12 22:48:50 +0200233 connector->index = ret;
234 ret = 0;
235
236 connector->connector_type = connector_type;
237 connector->connector_type_id =
238 ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
239 if (connector->connector_type_id < 0) {
240 ret = connector->connector_type_id;
241 goto out_put_id;
242 }
243 connector->name =
244 kasprintf(GFP_KERNEL, "%s-%d",
245 drm_connector_enum_list[connector_type].name,
246 connector->connector_type_id);
247 if (!connector->name) {
248 ret = -ENOMEM;
249 goto out_put_type_id;
250 }
251
252 INIT_LIST_HEAD(&connector->probed_modes);
253 INIT_LIST_HEAD(&connector->modes);
Daniel Vettere73ab002016-12-18 14:35:45 +0100254 mutex_init(&connector->mutex);
Daniel Vetter52217192016-08-12 22:48:50 +0200255 connector->edid_blob_ptr = NULL;
Manasi Navare2de3a072019-03-12 19:17:22 -0700256 connector->tile_blob_ptr = NULL;
Daniel Vetter52217192016-08-12 22:48:50 +0200257 connector->status = connector_status_unknown;
Hans de Goede8d70f392017-11-25 20:35:49 +0100258 connector->display_info.panel_orientation =
259 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
Daniel Vetter52217192016-08-12 22:48:50 +0200260
261 drm_connector_get_cmdline_mode(connector);
262
263 /* We should add connectors at the end to avoid upsetting the connector
264 * index too much. */
Daniel Vetter613051d2016-12-14 00:08:06 +0100265 spin_lock_irq(&config->connector_list_lock);
Daniel Vetter52217192016-08-12 22:48:50 +0200266 list_add_tail(&connector->head, &config->connector_list);
267 config->num_connector++;
Daniel Vetter613051d2016-12-14 00:08:06 +0100268 spin_unlock_irq(&config->connector_list_lock);
Daniel Vetter52217192016-08-12 22:48:50 +0200269
Brian Starkey935774c2017-03-29 17:42:32 +0100270 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
271 connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
Gerd Hoffmann6b7e2d52018-10-02 13:10:40 +0200272 drm_connector_attach_edid_property(connector);
Daniel Vetter52217192016-08-12 22:48:50 +0200273
274 drm_object_attach_property(&connector->base,
275 config->dpms_property, 0);
276
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200277 drm_object_attach_property(&connector->base,
278 config->link_status_property,
279 0);
280
Dave Airlie66660d42017-10-16 05:08:09 +0100281 drm_object_attach_property(&connector->base,
282 config->non_desktop_property,
283 0);
Manasi Navare2de3a072019-03-12 19:17:22 -0700284 drm_object_attach_property(&connector->base,
285 config->tile_property,
286 0);
Dave Airlie66660d42017-10-16 05:08:09 +0100287
Daniel Vetter52217192016-08-12 22:48:50 +0200288 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
289 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
290 }
291
292 connector->debugfs_entry = NULL;
293out_put_type_id:
294 if (ret)
Christophe JAILLET587680c2016-10-02 08:01:22 +0200295 ida_simple_remove(connector_ida, connector->connector_type_id);
Daniel Vetter52217192016-08-12 22:48:50 +0200296out_put_id:
297 if (ret)
Christophe JAILLET587680c2016-10-02 08:01:22 +0200298 ida_simple_remove(&config->connector_ida, connector->index);
Daniel Vetter52217192016-08-12 22:48:50 +0200299out_put:
300 if (ret)
301 drm_mode_object_unregister(dev, &connector->base);
302
Daniel Vetter52217192016-08-12 22:48:50 +0200303 return ret;
304}
305EXPORT_SYMBOL(drm_connector_init);
306
307/**
Andrzej Pietrasiewicz100163d2019-07-26 19:22:56 +0200308 * drm_connector_init_with_ddc - Init a preallocated connector
309 * @dev: DRM device
310 * @connector: the connector to init
311 * @funcs: callbacks for this connector
312 * @connector_type: user visible type of the connector
313 * @ddc: pointer to the associated ddc adapter
314 *
315 * Initialises a preallocated connector. Connectors should be
316 * subclassed as part of driver connector objects.
317 *
318 * Ensures that the ddc field of the connector is correctly set.
319 *
320 * Returns:
321 * Zero on success, error code on failure.
322 */
323int drm_connector_init_with_ddc(struct drm_device *dev,
324 struct drm_connector *connector,
325 const struct drm_connector_funcs *funcs,
326 int connector_type,
327 struct i2c_adapter *ddc)
328{
329 int ret;
330
331 ret = drm_connector_init(dev, connector, funcs, connector_type);
332 if (ret)
333 return ret;
334
335 /* provide ddc symlink in sysfs */
336 connector->ddc = ddc;
337
338 return ret;
339}
340EXPORT_SYMBOL(drm_connector_init_with_ddc);
341
342/**
Gerd Hoffmann6b7e2d52018-10-02 13:10:40 +0200343 * drm_connector_attach_edid_property - attach edid property.
Gerd Hoffmann6b7e2d52018-10-02 13:10:40 +0200344 * @connector: the connector
345 *
346 * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
347 * edid property attached by default. This function can be used to
348 * explicitly enable the edid property in these cases.
349 */
350void drm_connector_attach_edid_property(struct drm_connector *connector)
351{
352 struct drm_mode_config *config = &connector->dev->mode_config;
353
354 drm_object_attach_property(&connector->base,
355 config->edid_property,
356 0);
357}
358EXPORT_SYMBOL(drm_connector_attach_edid_property);
359
360/**
Daniel Vettercde4c442018-07-09 10:40:07 +0200361 * drm_connector_attach_encoder - attach a connector to an encoder
Daniel Vetter52217192016-08-12 22:48:50 +0200362 * @connector: connector to attach
363 * @encoder: encoder to attach @connector to
364 *
365 * This function links up a connector to an encoder. Note that the routing
366 * restrictions between encoders and crtcs are exposed to userspace through the
367 * possible_clones and possible_crtcs bitmasks.
368 *
369 * Returns:
370 * Zero on success, negative errno on failure.
371 */
Daniel Vettercde4c442018-07-09 10:40:07 +0200372int drm_connector_attach_encoder(struct drm_connector *connector,
373 struct drm_encoder *encoder)
Daniel Vetter52217192016-08-12 22:48:50 +0200374{
Daniel Vetter52217192016-08-12 22:48:50 +0200375 /*
376 * In the past, drivers have attempted to model the static association
377 * of connector to encoder in simple connector/encoder devices using a
378 * direct assignment of connector->encoder = encoder. This connection
379 * is a logical one and the responsibility of the core, so drivers are
380 * expected not to mess with this.
381 *
382 * Note that the error return should've been enough here, but a large
383 * majority of drivers ignores the return value, so add in a big WARN
384 * to get people's attention.
385 */
386 if (WARN_ON(connector->encoder))
387 return -EINVAL;
388
José Roberto de Souza62afb4a2019-09-13 16:28:57 -0700389 connector->possible_encoders |= drm_encoder_mask(encoder);
390
391 return 0;
Daniel Vetter52217192016-08-12 22:48:50 +0200392}
Daniel Vettercde4c442018-07-09 10:40:07 +0200393EXPORT_SYMBOL(drm_connector_attach_encoder);
Daniel Vetter52217192016-08-12 22:48:50 +0200394
Ville Syrjälä38cb8d92018-06-28 16:13:13 +0300395/**
José Roberto de Souza62afb4a2019-09-13 16:28:57 -0700396 * drm_connector_has_possible_encoder - check if the connector and encoder are
397 * associated with each other
Ville Syrjälä38cb8d92018-06-28 16:13:13 +0300398 * @connector: the connector
399 * @encoder: the encoder
400 *
401 * Returns:
402 * True if @encoder is one of the possible encoders for @connector.
403 */
404bool drm_connector_has_possible_encoder(struct drm_connector *connector,
405 struct drm_encoder *encoder)
406{
José Roberto de Souza62afb4a2019-09-13 16:28:57 -0700407 return connector->possible_encoders & drm_encoder_mask(encoder);
Ville Syrjälä38cb8d92018-06-28 16:13:13 +0300408}
409EXPORT_SYMBOL(drm_connector_has_possible_encoder);
410
Daniel Vetter52217192016-08-12 22:48:50 +0200411static void drm_mode_remove(struct drm_connector *connector,
412 struct drm_display_mode *mode)
413{
414 list_del(&mode->head);
415 drm_mode_destroy(connector->dev, mode);
416}
417
418/**
419 * drm_connector_cleanup - cleans up an initialised connector
420 * @connector: connector to cleanup
421 *
422 * Cleans up the connector but doesn't free the object.
423 */
424void drm_connector_cleanup(struct drm_connector *connector)
425{
426 struct drm_device *dev = connector->dev;
427 struct drm_display_mode *mode, *t;
428
429 /* The connector should have been removed from userspace long before
430 * it is finally destroyed.
431 */
Lyude Paul39b50c62018-10-16 16:39:46 -0400432 if (WARN_ON(connector->registration_state ==
433 DRM_CONNECTOR_REGISTERED))
Daniel Vetter52217192016-08-12 22:48:50 +0200434 drm_connector_unregister(connector);
435
436 if (connector->tile_group) {
437 drm_mode_put_tile_group(dev, connector->tile_group);
438 connector->tile_group = NULL;
439 }
440
441 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
442 drm_mode_remove(connector, mode);
443
444 list_for_each_entry_safe(mode, t, &connector->modes, head)
445 drm_mode_remove(connector, mode);
446
Christophe JAILLET9a47dba2016-10-07 09:27:41 +0200447 ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
448 connector->connector_type_id);
Daniel Vetter52217192016-08-12 22:48:50 +0200449
Christophe JAILLET9a47dba2016-10-07 09:27:41 +0200450 ida_simple_remove(&dev->mode_config.connector_ida,
451 connector->index);
Daniel Vetter52217192016-08-12 22:48:50 +0200452
453 kfree(connector->display_info.bus_formats);
454 drm_mode_object_unregister(dev, &connector->base);
455 kfree(connector->name);
456 connector->name = NULL;
Daniel Vetter613051d2016-12-14 00:08:06 +0100457 spin_lock_irq(&dev->mode_config.connector_list_lock);
Daniel Vetter52217192016-08-12 22:48:50 +0200458 list_del(&connector->head);
459 dev->mode_config.num_connector--;
Daniel Vetter613051d2016-12-14 00:08:06 +0100460 spin_unlock_irq(&dev->mode_config.connector_list_lock);
Daniel Vetter52217192016-08-12 22:48:50 +0200461
462 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
463 if (connector->state && connector->funcs->atomic_destroy_state)
464 connector->funcs->atomic_destroy_state(connector,
465 connector->state);
466
Daniel Vettere73ab002016-12-18 14:35:45 +0100467 mutex_destroy(&connector->mutex);
468
Daniel Vetter52217192016-08-12 22:48:50 +0200469 memset(connector, 0, sizeof(*connector));
470}
471EXPORT_SYMBOL(drm_connector_cleanup);
472
473/**
474 * drm_connector_register - register a connector
475 * @connector: the connector to register
476 *
Daniel Vetter69b22f512019-09-17 14:09:36 +0200477 * Register userspace interfaces for a connector. Only call this for connectors
478 * which can be hotplugged after drm_dev_register() has been called already,
479 * e.g. DP MST connectors. All other connectors will be registered automatically
480 * when calling drm_dev_register().
Daniel Vetter52217192016-08-12 22:48:50 +0200481 *
482 * Returns:
483 * Zero on success, error code on failure.
484 */
485int drm_connector_register(struct drm_connector *connector)
486{
Daniel Vettere73ab002016-12-18 14:35:45 +0100487 int ret = 0;
Daniel Vetter52217192016-08-12 22:48:50 +0200488
Daniel Vettere6e7b482017-01-12 17:15:56 +0100489 if (!connector->dev->registered)
490 return 0;
491
Daniel Vettere73ab002016-12-18 14:35:45 +0100492 mutex_lock(&connector->mutex);
Lyude Paul39b50c62018-10-16 16:39:46 -0400493 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
Daniel Vettere73ab002016-12-18 14:35:45 +0100494 goto unlock;
Daniel Vetter52217192016-08-12 22:48:50 +0200495
496 ret = drm_sysfs_connector_add(connector);
497 if (ret)
Daniel Vettere73ab002016-12-18 14:35:45 +0100498 goto unlock;
Daniel Vetter52217192016-08-12 22:48:50 +0200499
Greg Kroah-Hartmanb792e642019-06-13 15:34:39 +0200500 drm_debugfs_connector_add(connector);
Daniel Vetter52217192016-08-12 22:48:50 +0200501
502 if (connector->funcs->late_register) {
503 ret = connector->funcs->late_register(connector);
504 if (ret)
505 goto err_debugfs;
506 }
507
508 drm_mode_object_register(connector->dev, &connector->base);
509
Lyude Paul39b50c62018-10-16 16:39:46 -0400510 connector->registration_state = DRM_CONNECTOR_REGISTERED;
Daniel Vettere73ab002016-12-18 14:35:45 +0100511 goto unlock;
Daniel Vetter52217192016-08-12 22:48:50 +0200512
513err_debugfs:
514 drm_debugfs_connector_remove(connector);
Daniel Vetter52217192016-08-12 22:48:50 +0200515 drm_sysfs_connector_remove(connector);
Daniel Vettere73ab002016-12-18 14:35:45 +0100516unlock:
517 mutex_unlock(&connector->mutex);
Daniel Vetter52217192016-08-12 22:48:50 +0200518 return ret;
519}
520EXPORT_SYMBOL(drm_connector_register);
521
522/**
523 * drm_connector_unregister - unregister a connector
524 * @connector: the connector to unregister
525 *
Daniel Vetter69b22f512019-09-17 14:09:36 +0200526 * Unregister userspace interfaces for a connector. Only call this for
527 * connectors which have registered explicitly by calling drm_dev_register(),
528 * since connectors are unregistered automatically when drm_dev_unregister() is
529 * called.
Daniel Vetter52217192016-08-12 22:48:50 +0200530 */
531void drm_connector_unregister(struct drm_connector *connector)
532{
Daniel Vettere73ab002016-12-18 14:35:45 +0100533 mutex_lock(&connector->mutex);
Lyude Paul39b50c62018-10-16 16:39:46 -0400534 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
Daniel Vettere73ab002016-12-18 14:35:45 +0100535 mutex_unlock(&connector->mutex);
Daniel Vetter52217192016-08-12 22:48:50 +0200536 return;
Daniel Vettere73ab002016-12-18 14:35:45 +0100537 }
Daniel Vetter52217192016-08-12 22:48:50 +0200538
539 if (connector->funcs->early_unregister)
540 connector->funcs->early_unregister(connector);
541
542 drm_sysfs_connector_remove(connector);
543 drm_debugfs_connector_remove(connector);
544
Lyude Paul39b50c62018-10-16 16:39:46 -0400545 connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
Daniel Vettere73ab002016-12-18 14:35:45 +0100546 mutex_unlock(&connector->mutex);
Daniel Vetter52217192016-08-12 22:48:50 +0200547}
548EXPORT_SYMBOL(drm_connector_unregister);
549
550void drm_connector_unregister_all(struct drm_device *dev)
551{
552 struct drm_connector *connector;
Daniel Vetter613051d2016-12-14 00:08:06 +0100553 struct drm_connector_list_iter conn_iter;
Daniel Vetter52217192016-08-12 22:48:50 +0200554
Thierry Redingb982dab2017-02-28 15:46:43 +0100555 drm_connector_list_iter_begin(dev, &conn_iter);
Daniel Vetter613051d2016-12-14 00:08:06 +0100556 drm_for_each_connector_iter(connector, &conn_iter)
Daniel Vetter52217192016-08-12 22:48:50 +0200557 drm_connector_unregister(connector);
Thierry Redingb982dab2017-02-28 15:46:43 +0100558 drm_connector_list_iter_end(&conn_iter);
Daniel Vetter52217192016-08-12 22:48:50 +0200559}
560
561int drm_connector_register_all(struct drm_device *dev)
562{
563 struct drm_connector *connector;
Daniel Vetter613051d2016-12-14 00:08:06 +0100564 struct drm_connector_list_iter conn_iter;
565 int ret = 0;
Daniel Vetter52217192016-08-12 22:48:50 +0200566
Thierry Redingb982dab2017-02-28 15:46:43 +0100567 drm_connector_list_iter_begin(dev, &conn_iter);
Daniel Vetter613051d2016-12-14 00:08:06 +0100568 drm_for_each_connector_iter(connector, &conn_iter) {
Daniel Vetter52217192016-08-12 22:48:50 +0200569 ret = drm_connector_register(connector);
570 if (ret)
Daniel Vetter613051d2016-12-14 00:08:06 +0100571 break;
Daniel Vetter52217192016-08-12 22:48:50 +0200572 }
Thierry Redingb982dab2017-02-28 15:46:43 +0100573 drm_connector_list_iter_end(&conn_iter);
Daniel Vetter52217192016-08-12 22:48:50 +0200574
Daniel Vetter613051d2016-12-14 00:08:06 +0100575 if (ret)
576 drm_connector_unregister_all(dev);
Daniel Vetter52217192016-08-12 22:48:50 +0200577 return ret;
578}
579
580/**
581 * drm_get_connector_status_name - return a string for connector status
582 * @status: connector status to compute name of
583 *
584 * In contrast to the other drm_get_*_name functions this one here returns a
585 * const pointer and hence is threadsafe.
586 */
587const char *drm_get_connector_status_name(enum drm_connector_status status)
588{
589 if (status == connector_status_connected)
590 return "connected";
591 else if (status == connector_status_disconnected)
592 return "disconnected";
593 else
594 return "unknown";
595}
596EXPORT_SYMBOL(drm_get_connector_status_name);
597
Jani Nikula6140cf22017-02-20 10:51:48 +0200598/**
599 * drm_get_connector_force_name - return a string for connector force
600 * @force: connector force to get name of
601 *
602 * Returns: const pointer to name.
603 */
604const char *drm_get_connector_force_name(enum drm_connector_force force)
605{
606 switch (force) {
607 case DRM_FORCE_UNSPECIFIED:
608 return "unspecified";
609 case DRM_FORCE_OFF:
610 return "off";
611 case DRM_FORCE_ON:
612 return "on";
613 case DRM_FORCE_ON_DIGITAL:
614 return "digital";
615 default:
616 return "unknown";
617 }
618}
619
Daniel Vetter613051d2016-12-14 00:08:06 +0100620#ifdef CONFIG_LOCKDEP
621static struct lockdep_map connector_list_iter_dep_map = {
622 .name = "drm_connector_list_iter"
623};
624#endif
625
626/**
Thierry Redingb982dab2017-02-28 15:46:43 +0100627 * drm_connector_list_iter_begin - initialize a connector_list iterator
Daniel Vetter613051d2016-12-14 00:08:06 +0100628 * @dev: DRM device
629 * @iter: connector_list iterator
630 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100631 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
Thierry Redingb982dab2017-02-28 15:46:43 +0100632 * must always be cleaned up again by calling drm_connector_list_iter_end().
Daniel Vetter613051d2016-12-14 00:08:06 +0100633 * Iteration itself happens using drm_connector_list_iter_next() or
634 * drm_for_each_connector_iter().
635 */
Thierry Redingb982dab2017-02-28 15:46:43 +0100636void drm_connector_list_iter_begin(struct drm_device *dev,
637 struct drm_connector_list_iter *iter)
Daniel Vetter613051d2016-12-14 00:08:06 +0100638{
639 iter->dev = dev;
640 iter->conn = NULL;
641 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
642}
Thierry Redingb982dab2017-02-28 15:46:43 +0100643EXPORT_SYMBOL(drm_connector_list_iter_begin);
Daniel Vetter613051d2016-12-14 00:08:06 +0100644
Daniel Vettera703c552017-12-04 21:48:18 +0100645/*
646 * Extra-safe connector put function that works in any context. Should only be
647 * used from the connector_iter functions, where we never really expect to
648 * actually release the connector when dropping our final reference.
649 */
650static void
Daniel Vetterea497bb2017-12-13 13:49:36 +0100651__drm_connector_put_safe(struct drm_connector *conn)
Daniel Vettera703c552017-12-04 21:48:18 +0100652{
Daniel Vetterea497bb2017-12-13 13:49:36 +0100653 struct drm_mode_config *config = &conn->dev->mode_config;
654
655 lockdep_assert_held(&config->connector_list_lock);
656
657 if (!refcount_dec_and_test(&conn->base.refcount.refcount))
658 return;
659
660 llist_add(&conn->free_node, &config->connector_free_list);
661 schedule_work(&config->connector_free_work);
Daniel Vettera703c552017-12-04 21:48:18 +0100662}
663
Daniel Vetter613051d2016-12-14 00:08:06 +0100664/**
665 * drm_connector_list_iter_next - return next connector
Lyude Paul4f45c772018-07-16 13:17:11 -0400666 * @iter: connector_list iterator
Daniel Vetter613051d2016-12-14 00:08:06 +0100667 *
668 * Returns the next connector for @iter, or NULL when the list walk has
669 * completed.
670 */
671struct drm_connector *
672drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
673{
674 struct drm_connector *old_conn = iter->conn;
675 struct drm_mode_config *config = &iter->dev->mode_config;
676 struct list_head *lhead;
677 unsigned long flags;
678
679 spin_lock_irqsave(&config->connector_list_lock, flags);
680 lhead = old_conn ? &old_conn->head : &config->connector_list;
681
682 do {
683 if (lhead->next == &config->connector_list) {
684 iter->conn = NULL;
685 break;
686 }
687
688 lhead = lhead->next;
689 iter->conn = list_entry(lhead, struct drm_connector, head);
690
691 /* loop until it's not a zombie connector */
692 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
Daniel Vetter613051d2016-12-14 00:08:06 +0100693
694 if (old_conn)
Daniel Vetterea497bb2017-12-13 13:49:36 +0100695 __drm_connector_put_safe(old_conn);
696 spin_unlock_irqrestore(&config->connector_list_lock, flags);
Daniel Vetter613051d2016-12-14 00:08:06 +0100697
698 return iter->conn;
699}
700EXPORT_SYMBOL(drm_connector_list_iter_next);
701
702/**
Thierry Redingb982dab2017-02-28 15:46:43 +0100703 * drm_connector_list_iter_end - tear down a connector_list iterator
Daniel Vetter613051d2016-12-14 00:08:06 +0100704 * @iter: connector_list iterator
705 *
706 * Tears down @iter and releases any resources (like &drm_connector references)
707 * acquired while walking the list. This must always be called, both when the
708 * iteration completes fully or when it was aborted without walking the entire
709 * list.
710 */
Thierry Redingb982dab2017-02-28 15:46:43 +0100711void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
Daniel Vetter613051d2016-12-14 00:08:06 +0100712{
Daniel Vetterea497bb2017-12-13 13:49:36 +0100713 struct drm_mode_config *config = &iter->dev->mode_config;
714 unsigned long flags;
715
Daniel Vetter613051d2016-12-14 00:08:06 +0100716 iter->dev = NULL;
Daniel Vetterea497bb2017-12-13 13:49:36 +0100717 if (iter->conn) {
718 spin_lock_irqsave(&config->connector_list_lock, flags);
719 __drm_connector_put_safe(iter->conn);
720 spin_unlock_irqrestore(&config->connector_list_lock, flags);
721 }
Qian Cai5facae42019-09-19 12:09:40 -0400722 lock_release(&connector_list_iter_dep_map, _RET_IP_);
Daniel Vetter613051d2016-12-14 00:08:06 +0100723}
Thierry Redingb982dab2017-02-28 15:46:43 +0100724EXPORT_SYMBOL(drm_connector_list_iter_end);
Daniel Vetter613051d2016-12-14 00:08:06 +0100725
Daniel Vetter52217192016-08-12 22:48:50 +0200726static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
727 { SubPixelUnknown, "Unknown" },
728 { SubPixelHorizontalRGB, "Horizontal RGB" },
729 { SubPixelHorizontalBGR, "Horizontal BGR" },
730 { SubPixelVerticalRGB, "Vertical RGB" },
731 { SubPixelVerticalBGR, "Vertical BGR" },
732 { SubPixelNone, "None" },
733};
734
735/**
736 * drm_get_subpixel_order_name - return a string for a given subpixel enum
737 * @order: enum of subpixel_order
738 *
739 * Note you could abuse this and return something out of bounds, but that
740 * would be a caller error. No unscrubbed user data should make it here.
741 */
742const char *drm_get_subpixel_order_name(enum subpixel_order order)
743{
744 return drm_subpixel_enum_list[order].name;
745}
746EXPORT_SYMBOL(drm_get_subpixel_order_name);
747
748static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
749 { DRM_MODE_DPMS_ON, "On" },
750 { DRM_MODE_DPMS_STANDBY, "Standby" },
751 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
752 { DRM_MODE_DPMS_OFF, "Off" }
753};
754DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
755
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200756static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
757 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
758 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
759};
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200760
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200761/**
762 * drm_display_info_set_bus_formats - set the supported bus formats
763 * @info: display info to store bus formats in
764 * @formats: array containing the supported bus formats
765 * @num_formats: the number of entries in the fmts array
766 *
767 * Store the supported bus formats in display info structure.
768 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
769 * a full list of available formats.
770 */
771int drm_display_info_set_bus_formats(struct drm_display_info *info,
772 const u32 *formats,
773 unsigned int num_formats)
774{
775 u32 *fmts = NULL;
776
777 if (!formats && num_formats)
778 return -EINVAL;
779
780 if (formats && num_formats) {
781 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
782 GFP_KERNEL);
783 if (!fmts)
784 return -ENOMEM;
785 }
786
787 kfree(info->bus_formats);
788 info->bus_formats = fmts;
789 info->num_bus_formats = num_formats;
790
791 return 0;
792}
793EXPORT_SYMBOL(drm_display_info_set_bus_formats);
794
Daniel Vetter52217192016-08-12 22:48:50 +0200795/* Optional connector properties. */
796static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
797 { DRM_MODE_SCALE_NONE, "None" },
798 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
799 { DRM_MODE_SCALE_CENTER, "Center" },
800 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
801};
802
803static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
804 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
805 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
806 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
807};
808
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +0300809static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
810 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
811 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
812 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
813 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
814 { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
815};
816
Hans de Goede8d70f392017-11-25 20:35:49 +0100817static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
818 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
819 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
820 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
821 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
822};
823
Daniel Vetter52217192016-08-12 22:48:50 +0200824static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
825 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
826 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
827 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
828};
829DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
830
831static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
832 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
833 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
834 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
835};
836DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
837 drm_dvi_i_subconnector_enum_list)
838
839static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
840 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
841 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
842 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
843 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
844 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
845};
846DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
847
848static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
849 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
850 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
851 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
852 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
853 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
854};
855DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
856 drm_tv_subconnector_enum_list)
857
Uma Shankard2c6a402019-02-19 22:42:59 +0530858static const struct drm_prop_enum_list hdmi_colorspaces[] = {
859 /* For Default case, driver will set the colorspace */
860 { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
861 /* Standard Definition Colorimetry based on CEA 861 */
862 { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
863 { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
864 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
865 { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
866 /* High Definition Colorimetry based on IEC 61966-2-4 */
867 { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
868 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
869 { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
870 /* Colorimetry based on IEC 61966-2-5 [33] */
871 { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
872 /* Colorimetry based on IEC 61966-2-5 */
873 { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
874 /* Colorimetry based on ITU-R BT.2020 */
875 { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
876 /* Colorimetry based on ITU-R BT.2020 */
877 { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
878 /* Colorimetry based on ITU-R BT.2020 */
879 { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
880 /* Added as part of Additional Colorimetry Extension in 861.G */
881 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
882 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
883};
884
Gwan-gyeong Mun45cf0e92019-09-19 22:53:07 +0300885/*
886 * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
887 * Format Table 2-120
888 */
889static const struct drm_prop_enum_list dp_colorspaces[] = {
890 /* For Default case, driver will set the colorspace */
891 { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
892 { DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
893 /* Colorimetry based on scRGB (IEC 61966-2-2) */
894 { DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
895 /* Colorimetry based on IEC 61966-2-5 */
896 { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
897 /* Colorimetry based on SMPTE RP 431-2 */
898 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
899 /* Colorimetry based on ITU-R BT.2020 */
900 { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
901 { DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
902 { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
903 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
904 { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
905 /* High Definition Colorimetry based on IEC 61966-2-4 */
906 { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
907 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
908 { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
909 /* Colorimetry based on IEC 61966-2-5 [33] */
910 { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
911 /* Colorimetry based on ITU-R BT.2020 */
912 { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
913 /* Colorimetry based on ITU-R BT.2020 */
914 { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
915};
916
Daniel Vetter4ada6f22016-11-17 09:56:48 +0100917/**
918 * DOC: standard connector properties
919 *
920 * DRM connectors have a few standardized properties:
921 *
922 * EDID:
923 * Blob property which contains the current EDID read from the sink. This
924 * is useful to parse sink identification information like vendor, model
925 * and serial. Drivers should update this property by calling
Daniel Vetterc555f022018-07-09 10:40:06 +0200926 * drm_connector_update_edid_property(), usually after having parsed
Daniel Vetter4ada6f22016-11-17 09:56:48 +0100927 * the EDID using drm_add_edid_modes(). Userspace cannot change this
928 * property.
929 * DPMS:
930 * Legacy property for setting the power state of the connector. For atomic
931 * drivers this is only provided for backwards compatibility with existing
932 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
933 * connector is linked to. Drivers should never set this property directly,
Daniel Vetterd5745282017-01-25 07:26:45 +0100934 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
Daniel Vetter144a7992017-07-25 14:02:04 +0200935 * callback. For atomic drivers the remapping to the "ACTIVE" property is
936 * implemented in the DRM core. This is the only standard connector
937 * property that userspace can change.
Daniel Vetterd0d1aee52017-09-21 00:59:57 +0200938 *
939 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
940 * userspace must use "ACTIVE" on the CRTC instead.
941 *
942 * WARNING:
943 *
944 * For userspace also running on legacy drivers the "DPMS" semantics are a
945 * lot more complicated. First, userspace cannot rely on the "DPMS" value
946 * returned by the GETCONNECTOR actually reflecting reality, because many
947 * drivers fail to update it. For atomic drivers this is taken care of in
948 * drm_atomic_helper_update_legacy_modeset_state().
949 *
950 * The second issue is that the DPMS state is only well-defined when the
951 * connector is connected to a CRTC. In atomic the DRM core enforces that
952 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
953 *
954 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
955 * "DPMS" is forced to ON. But see above, that might not be reflected in
956 * the software value on legacy drivers.
957 *
958 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
959 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
960 * never read back the value of "DPMS" because it can be incorrect.
Daniel Vetter4ada6f22016-11-17 09:56:48 +0100961 * PATH:
962 * Connector path property to identify how this sink is physically
963 * connected. Used by DP MST. This should be set by calling
Daniel Vetter97e14fb2018-07-09 10:40:08 +0200964 * drm_connector_set_path_property(), in the case of DP MST with the
Daniel Vetter4ada6f22016-11-17 09:56:48 +0100965 * path property the MST manager created. Userspace cannot change this
966 * property.
967 * TILE:
968 * Connector tile group property to indicate how a set of DRM connector
969 * compose together into one logical screen. This is used by both high-res
970 * external screens (often only using a single cable, but exposing multiple
971 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
972 * are not gen-locked. Note that for tiled panels which are genlocked, like
973 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
974 * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
Daniel Vetter97e14fb2018-07-09 10:40:08 +0200975 * should update this value using drm_connector_set_tile_property().
Daniel Vetter4ada6f22016-11-17 09:56:48 +0100976 * Userspace cannot change this property.
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200977 * link-status:
Sean Paul716719a2018-01-08 14:55:35 -0500978 * Connector link-status property to indicate the status of link. The
979 * default value of link-status is "GOOD". If something fails during or
980 * after modeset, the kernel driver may set this to "BAD" and issue a
981 * hotplug uevent. Drivers should update this value using
Daniel Vetter97e14fb2018-07-09 10:40:08 +0200982 * drm_connector_set_link_status_property().
Dave Airlie66660d42017-10-16 05:08:09 +0100983 * non_desktop:
984 * Indicates the output should be ignored for purposes of displaying a
985 * standard desktop environment or console. This is most likely because
986 * the output device is not rectilinear.
Sean Paul24557862018-01-08 14:55:37 -0500987 * Content Protection:
988 * This property is used by userspace to request the kernel protect future
989 * content communicated over the link. When requested, kernel will apply
990 * the appropriate means of protection (most often HDCP), and use the
991 * property to tell userspace the protection is active.
992 *
993 * Drivers can set this up by calling
994 * drm_connector_attach_content_protection_property() on initialization.
995 *
996 * The value of this property can be one of the following:
997 *
Daniel Vetterbbeba092018-02-19 23:53:54 +0100998 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
Sean Paul24557862018-01-08 14:55:37 -0500999 * The link is not protected, content is transmitted in the clear.
Daniel Vetterbbeba092018-02-19 23:53:54 +01001000 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
Sean Paul24557862018-01-08 14:55:37 -05001001 * Userspace has requested content protection, but the link is not
1002 * currently protected. When in this state, kernel should enable
1003 * Content Protection as soon as possible.
Daniel Vetterbbeba092018-02-19 23:53:54 +01001004 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
Sean Paul24557862018-01-08 14:55:37 -05001005 * Userspace has requested content protection, and the link is
1006 * protected. Only the driver can set the property to this value.
1007 * If userspace attempts to set to ENABLED, kernel will return
1008 * -EINVAL.
1009 *
1010 * A few guidelines:
1011 *
1012 * - DESIRED state should be preserved until userspace de-asserts it by
1013 * setting the property to UNDESIRED. This means ENABLED should only
1014 * transition to UNDESIRED when the user explicitly requests it.
1015 * - If the state is DESIRED, kernel should attempt to re-authenticate the
1016 * link whenever possible. This includes across disable/enable, dpms,
1017 * hotplug, downstream device changes, link status failures, etc..
Ramalingam Cbb5a45d2019-08-01 17:11:17 +05301018 * - Kernel sends uevent with the connector id and property id through
1019 * @drm_hdcp_update_content_protection, upon below kernel triggered
1020 * scenarios:
Sean Paul12db36b2019-08-12 10:01:03 -04001021 *
1022 * - DESIRED -> ENABLED (authentication success)
1023 * - ENABLED -> DESIRED (termination of authentication)
Ramalingam Cbb5a45d2019-08-01 17:11:17 +05301024 * - Please note no uevents for userspace triggered property state changes,
1025 * which can't fail such as
Sean Paul12db36b2019-08-12 10:01:03 -04001026 *
1027 * - DESIRED/ENABLED -> UNDESIRED
1028 * - UNDESIRED -> DESIRED
Ramalingam Cbb5a45d2019-08-01 17:11:17 +05301029 * - Userspace is responsible for polling the property or listen to uevents
1030 * to determine when the value transitions from ENABLED to DESIRED.
1031 * This signifies the link is no longer protected and userspace should
1032 * take appropriate action (whatever that might be).
Daniel Vetter4ada6f22016-11-17 09:56:48 +01001033 *
Ramalingam C7672dbb2019-08-01 17:11:14 +05301034 * HDCP Content Type:
1035 * This Enum property is used by the userspace to declare the content type
1036 * of the display stream, to kernel. Here display stream stands for any
1037 * display content that userspace intended to display through HDCP
1038 * encryption.
1039 *
1040 * Content Type of a stream is decided by the owner of the stream, as
1041 * "HDCP Type0" or "HDCP Type1".
1042 *
1043 * The value of the property can be one of the below:
1044 * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
1045 * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
1046 *
1047 * When kernel starts the HDCP authentication (see "Content Protection"
1048 * for details), it uses the content type in "HDCP Content Type"
1049 * for performing the HDCP authentication with the display sink.
1050 *
1051 * Please note in HDCP spec versions, a link can be authenticated with
1052 * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
1053 * authenticated with HDCP1.4 only for Content Type 0(though it is implicit
1054 * in nature. As there is no reference for Content Type in HDCP1.4).
1055 *
1056 * HDCP2.2 authentication protocol itself takes the "Content Type" as a
1057 * parameter, which is a input for the DP HDCP2.2 encryption algo.
1058 *
1059 * In case of Type 0 content protection request, kernel driver can choose
1060 * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
1061 * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
1062 * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
1063 * But if the content is classified as "HDCP Type 1", above mentioned
1064 * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
1065 * authenticate the HDCP1.4 capable sink for "HDCP Type 1".
1066 *
1067 * Please note userspace can be ignorant of the HDCP versions used by the
1068 * kernel driver to achieve the "HDCP Content Type".
1069 *
1070 * At current scenario, classifying a content as Type 1 ensures that the
1071 * content will be displayed only through the HDCP2.2 encrypted link.
1072 *
1073 * Note that the HDCP Content Type property is introduced at HDCP 2.2, and
1074 * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
1075 * (hence supporting Type 0 and Type 1). Based on how next versions of
1076 * HDCP specs are defined content Type could be used for higher versions
1077 * too.
1078 *
1079 * If content type is changed when "Content Protection" is not UNDESIRED,
1080 * then kernel will disable the HDCP and re-enable with new type in the
1081 * same atomic commit. And when "Content Protection" is ENABLED, it means
1082 * that link is HDCP authenticated and encrypted, for the transmission of
1083 * the Type of stream mentioned at "HDCP Content Type".
1084 *
Uma Shankara09db882019-06-04 16:47:02 +05301085 * HDR_OUTPUT_METADATA:
1086 * Connector property to enable userspace to send HDR Metadata to
1087 * driver. This metadata is based on the composition and blending
1088 * policies decided by user, taking into account the hardware and
1089 * sink capabilities. The driver gets this metadata and creates a
1090 * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1091 * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1092 * sent to sink. This notifies the sink of the upcoming frame's Color
1093 * Encoding and Luminance parameters.
1094 *
1095 * Userspace first need to detect the HDR capabilities of sink by
1096 * reading and parsing the EDID. Details of HDR metadata for HDMI
1097 * are added in CTA 861.G spec. For DP , its defined in VESA DP
1098 * Standard v1.4. It needs to then get the metadata information
1099 * of the video/game/app content which are encoded in HDR (basically
1100 * using HDR transfer functions). With this information it needs to
1101 * decide on a blending policy and compose the relevant
1102 * layers/overlays into a common format. Once this blending is done,
1103 * userspace will be aware of the metadata of the composed frame to
1104 * be send to sink. It then uses this property to communicate this
1105 * metadata to driver which then make a Infoframe packet and sends
1106 * to sink based on the type of encoder connected.
1107 *
1108 * Userspace will be responsible to do Tone mapping operation in case:
1109 * - Some layers are HDR and others are SDR
1110 * - HDR layers luminance is not same as sink
Sean Paul9f9b2552019-06-13 11:17:23 -04001111 *
Uma Shankara09db882019-06-04 16:47:02 +05301112 * It will even need to do colorspace conversion and get all layers
1113 * to one common colorspace for blending. It can use either GL, Media
1114 * or display engine to get this done based on the capabilties of the
1115 * associated hardware.
1116 *
1117 * Driver expects metadata to be put in &struct hdr_output_metadata
1118 * structure from userspace. This is received as blob and stored in
1119 * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1120 * sink metadata in &struct hdr_sink_metadata, as
1121 * &drm_connector.hdr_sink_metadata. Driver uses
1122 * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1123 * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1124 * HDMI encoder.
1125 *
Radhakrishna Sripada47e22ff2018-10-12 11:42:32 -07001126 * max bpc:
1127 * This range property is used by userspace to limit the bit depth. When
1128 * used the driver would limit the bpc in accordance with the valid range
1129 * supported by the hardware and sink. Drivers to use the function
1130 * drm_connector_attach_max_bpc_property() to create and attach the
1131 * property to the connector during initialization.
1132 *
Daniel Vetter4ada6f22016-11-17 09:56:48 +01001133 * Connectors also have one standardized atomic property:
1134 *
1135 * CRTC_ID:
1136 * Mode object ID of the &drm_crtc this connector should be connected to.
Hans de Goede8d70f392017-11-25 20:35:49 +01001137 *
1138 * Connectors for LCD panels may also have one standardized property:
1139 *
1140 * panel orientation:
1141 * On some devices the LCD panel is mounted in the casing in such a way
1142 * that the up/top side of the panel does not match with the top side of
1143 * the device. Userspace can use this property to check for this.
1144 * Note that input coordinates from touchscreens (input devices with
1145 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
1146 * coordinates, so if userspace rotates the picture to adjust for
1147 * the orientation it must also apply the same transformation to the
Daniel Vetterbbeba092018-02-19 23:53:54 +01001148 * touchscreen input coordinates. This property is initialized by calling
Derek Basehore69654c62020-01-05 16:51:19 +01001149 * drm_connector_set_panel_orientation() or
1150 * drm_connector_set_panel_orientation_with_quirk()
Daniel Vetterbbeba092018-02-19 23:53:54 +01001151 *
1152 * scaling mode:
1153 * This property defines how a non-native mode is upscaled to the native
1154 * mode of an LCD panel:
1155 *
1156 * None:
1157 * No upscaling happens, scaling is left to the panel. Not all
1158 * drivers expose this mode.
1159 * Full:
1160 * The output is upscaled to the full resolution of the panel,
1161 * ignoring the aspect ratio.
1162 * Center:
1163 * No upscaling happens, the output is centered within the native
1164 * resolution the panel.
1165 * Full aspect:
1166 * The output is upscaled to maximize either the width or height
1167 * while retaining the aspect ratio.
1168 *
1169 * This property should be set up by calling
1170 * drm_connector_attach_scaling_mode_property(). Note that drivers
1171 * can also expose this property to external outputs, in which case they
1172 * must support "None", which should be the default (since external screens
1173 * have a built-in scaler).
Daniel Vetter4ada6f22016-11-17 09:56:48 +01001174 */
1175
Daniel Vetter52217192016-08-12 22:48:50 +02001176int drm_connector_create_standard_properties(struct drm_device *dev)
1177{
1178 struct drm_property *prop;
1179
1180 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
1181 DRM_MODE_PROP_IMMUTABLE,
1182 "EDID", 0);
1183 if (!prop)
1184 return -ENOMEM;
1185 dev->mode_config.edid_property = prop;
1186
1187 prop = drm_property_create_enum(dev, 0,
1188 "DPMS", drm_dpms_enum_list,
1189 ARRAY_SIZE(drm_dpms_enum_list));
1190 if (!prop)
1191 return -ENOMEM;
1192 dev->mode_config.dpms_property = prop;
1193
1194 prop = drm_property_create(dev,
1195 DRM_MODE_PROP_BLOB |
1196 DRM_MODE_PROP_IMMUTABLE,
1197 "PATH", 0);
1198 if (!prop)
1199 return -ENOMEM;
1200 dev->mode_config.path_property = prop;
1201
1202 prop = drm_property_create(dev,
1203 DRM_MODE_PROP_BLOB |
1204 DRM_MODE_PROP_IMMUTABLE,
1205 "TILE", 0);
1206 if (!prop)
1207 return -ENOMEM;
1208 dev->mode_config.tile_property = prop;
1209
Manasi Navare40ee6fb2016-12-16 12:29:06 +02001210 prop = drm_property_create_enum(dev, 0, "link-status",
1211 drm_link_status_enum_list,
1212 ARRAY_SIZE(drm_link_status_enum_list));
1213 if (!prop)
1214 return -ENOMEM;
1215 dev->mode_config.link_status_property = prop;
1216
Dave Airlie66660d42017-10-16 05:08:09 +01001217 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
1218 if (!prop)
1219 return -ENOMEM;
1220 dev->mode_config.non_desktop_property = prop;
1221
Uma Shankarfbb5d032019-05-16 19:40:06 +05301222 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1223 "HDR_OUTPUT_METADATA", 0);
1224 if (!prop)
1225 return -ENOMEM;
1226 dev->mode_config.hdr_output_metadata_property = prop;
1227
Daniel Vetter52217192016-08-12 22:48:50 +02001228 return 0;
1229}
1230
1231/**
1232 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1233 * @dev: DRM device
1234 *
1235 * Called by a driver the first time a DVI-I connector is made.
1236 */
1237int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1238{
1239 struct drm_property *dvi_i_selector;
1240 struct drm_property *dvi_i_subconnector;
1241
1242 if (dev->mode_config.dvi_i_select_subconnector_property)
1243 return 0;
1244
1245 dvi_i_selector =
1246 drm_property_create_enum(dev, 0,
1247 "select subconnector",
1248 drm_dvi_i_select_enum_list,
1249 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1250 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1251
1252 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1253 "subconnector",
1254 drm_dvi_i_subconnector_enum_list,
1255 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1256 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1257
1258 return 0;
1259}
1260EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1261
1262/**
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03001263 * DOC: HDMI connector properties
1264 *
1265 * content type (HDMI specific):
1266 * Indicates content type setting to be used in HDMI infoframes to indicate
Matt Roper1e55a532019-02-01 17:23:26 -08001267 * content type for the external device, so that it adjusts its display
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03001268 * settings accordingly.
1269 *
1270 * The value of this property can be one of the following:
1271 *
1272 * No Data:
1273 * Content type is unknown
1274 * Graphics:
1275 * Content type is graphics
1276 * Photo:
1277 * Content type is photo
1278 * Cinema:
1279 * Content type is cinema
1280 * Game:
1281 * Content type is game
1282 *
1283 * Drivers can set up this property by calling
1284 * drm_connector_attach_content_type_property(). Decoding to
Daniel Vetterba609632018-07-02 11:10:23 +02001285 * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03001286 */
1287
1288/**
1289 * drm_connector_attach_content_type_property - attach content-type property
1290 * @connector: connector to attach content type property on.
1291 *
1292 * Called by a driver the first time a HDMI connector is made.
1293 */
1294int drm_connector_attach_content_type_property(struct drm_connector *connector)
1295{
1296 if (!drm_mode_create_content_type_property(connector->dev))
1297 drm_object_attach_property(&connector->base,
1298 connector->dev->mode_config.content_type_property,
1299 DRM_MODE_CONTENT_TYPE_NO_DATA);
1300 return 0;
1301}
1302EXPORT_SYMBOL(drm_connector_attach_content_type_property);
1303
1304
1305/**
1306 * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
1307 * content type information, based
1308 * on correspondent DRM property.
1309 * @frame: HDMI AVI infoframe
1310 * @conn_state: DRM display connector state
1311 *
1312 */
1313void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
1314 const struct drm_connector_state *conn_state)
1315{
1316 switch (conn_state->content_type) {
1317 case DRM_MODE_CONTENT_TYPE_GRAPHICS:
1318 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1319 break;
1320 case DRM_MODE_CONTENT_TYPE_CINEMA:
1321 frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
1322 break;
1323 case DRM_MODE_CONTENT_TYPE_GAME:
1324 frame->content_type = HDMI_CONTENT_TYPE_GAME;
1325 break;
1326 case DRM_MODE_CONTENT_TYPE_PHOTO:
1327 frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
1328 break;
1329 default:
1330 /* Graphics is the default(0) */
1331 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1332 }
1333
1334 frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
1335}
1336EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
1337
1338/**
Boris Brezillon6c4f52d2018-12-06 15:24:37 +01001339 * drm_mode_attach_tv_margin_properties - attach TV connector margin properties
1340 * @connector: DRM connector
1341 *
1342 * Called by a driver when it needs to attach TV margin props to a connector.
1343 * Typically used on SDTV and HDMI connectors.
1344 */
1345void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
1346{
1347 struct drm_device *dev = connector->dev;
1348
1349 drm_object_attach_property(&connector->base,
1350 dev->mode_config.tv_left_margin_property,
1351 0);
1352 drm_object_attach_property(&connector->base,
1353 dev->mode_config.tv_right_margin_property,
1354 0);
1355 drm_object_attach_property(&connector->base,
1356 dev->mode_config.tv_top_margin_property,
1357 0);
1358 drm_object_attach_property(&connector->base,
1359 dev->mode_config.tv_bottom_margin_property,
1360 0);
1361}
1362EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
1363
1364/**
1365 * drm_mode_create_tv_margin_properties - create TV connector margin properties
1366 * @dev: DRM device
1367 *
1368 * Called by a driver's HDMI connector initialization routine, this function
1369 * creates the TV margin properties for a given device. No need to call this
1370 * function for an SDTV connector, it's already called from
1371 * drm_mode_create_tv_properties().
1372 */
1373int drm_mode_create_tv_margin_properties(struct drm_device *dev)
1374{
1375 if (dev->mode_config.tv_left_margin_property)
1376 return 0;
1377
1378 dev->mode_config.tv_left_margin_property =
1379 drm_property_create_range(dev, 0, "left margin", 0, 100);
1380 if (!dev->mode_config.tv_left_margin_property)
1381 return -ENOMEM;
1382
1383 dev->mode_config.tv_right_margin_property =
1384 drm_property_create_range(dev, 0, "right margin", 0, 100);
1385 if (!dev->mode_config.tv_right_margin_property)
1386 return -ENOMEM;
1387
1388 dev->mode_config.tv_top_margin_property =
1389 drm_property_create_range(dev, 0, "top margin", 0, 100);
1390 if (!dev->mode_config.tv_top_margin_property)
1391 return -ENOMEM;
1392
1393 dev->mode_config.tv_bottom_margin_property =
1394 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1395 if (!dev->mode_config.tv_bottom_margin_property)
1396 return -ENOMEM;
1397
1398 return 0;
1399}
1400EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
1401
1402/**
Boris Brezilloneda68872018-12-06 15:24:35 +01001403 * drm_mode_create_tv_properties - create TV specific connector properties
Daniel Vetter52217192016-08-12 22:48:50 +02001404 * @dev: DRM device
1405 * @num_modes: number of different TV formats (modes) supported
1406 * @modes: array of pointers to strings containing name of each format
1407 *
1408 * Called by a driver's TV initialization routine, this function creates
1409 * the TV specific connector properties for a given device. Caller is
1410 * responsible for allocating a list of format names and passing them to
1411 * this routine.
1412 */
1413int drm_mode_create_tv_properties(struct drm_device *dev,
1414 unsigned int num_modes,
1415 const char * const modes[])
1416{
1417 struct drm_property *tv_selector;
1418 struct drm_property *tv_subconnector;
1419 unsigned int i;
1420
1421 if (dev->mode_config.tv_select_subconnector_property)
1422 return 0;
1423
1424 /*
1425 * Basic connector properties
1426 */
1427 tv_selector = drm_property_create_enum(dev, 0,
1428 "select subconnector",
1429 drm_tv_select_enum_list,
1430 ARRAY_SIZE(drm_tv_select_enum_list));
1431 if (!tv_selector)
1432 goto nomem;
1433
1434 dev->mode_config.tv_select_subconnector_property = tv_selector;
1435
1436 tv_subconnector =
1437 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1438 "subconnector",
1439 drm_tv_subconnector_enum_list,
1440 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1441 if (!tv_subconnector)
1442 goto nomem;
1443 dev->mode_config.tv_subconnector_property = tv_subconnector;
1444
1445 /*
1446 * Other, TV specific properties: margins & TV modes.
1447 */
Boris Brezillon6c4f52d2018-12-06 15:24:37 +01001448 if (drm_mode_create_tv_margin_properties(dev))
Daniel Vetter52217192016-08-12 22:48:50 +02001449 goto nomem;
1450
1451 dev->mode_config.tv_mode_property =
1452 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1453 "mode", num_modes);
1454 if (!dev->mode_config.tv_mode_property)
1455 goto nomem;
1456
1457 for (i = 0; i < num_modes; i++)
Ville Syrjälä30e9db6d2018-03-16 21:04:20 +02001458 drm_property_add_enum(dev->mode_config.tv_mode_property,
Daniel Vetter52217192016-08-12 22:48:50 +02001459 i, modes[i]);
1460
1461 dev->mode_config.tv_brightness_property =
1462 drm_property_create_range(dev, 0, "brightness", 0, 100);
1463 if (!dev->mode_config.tv_brightness_property)
1464 goto nomem;
1465
1466 dev->mode_config.tv_contrast_property =
1467 drm_property_create_range(dev, 0, "contrast", 0, 100);
1468 if (!dev->mode_config.tv_contrast_property)
1469 goto nomem;
1470
1471 dev->mode_config.tv_flicker_reduction_property =
1472 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1473 if (!dev->mode_config.tv_flicker_reduction_property)
1474 goto nomem;
1475
1476 dev->mode_config.tv_overscan_property =
1477 drm_property_create_range(dev, 0, "overscan", 0, 100);
1478 if (!dev->mode_config.tv_overscan_property)
1479 goto nomem;
1480
1481 dev->mode_config.tv_saturation_property =
1482 drm_property_create_range(dev, 0, "saturation", 0, 100);
1483 if (!dev->mode_config.tv_saturation_property)
1484 goto nomem;
1485
1486 dev->mode_config.tv_hue_property =
1487 drm_property_create_range(dev, 0, "hue", 0, 100);
1488 if (!dev->mode_config.tv_hue_property)
1489 goto nomem;
1490
1491 return 0;
1492nomem:
1493 return -ENOMEM;
1494}
1495EXPORT_SYMBOL(drm_mode_create_tv_properties);
1496
1497/**
1498 * drm_mode_create_scaling_mode_property - create scaling mode property
1499 * @dev: DRM device
1500 *
1501 * Called by a driver the first time it's needed, must be attached to desired
1502 * connectors.
Maarten Lankhorst8f6e1e22017-05-01 15:37:54 +02001503 *
1504 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1505 * instead to correctly assign &drm_connector_state.picture_aspect_ratio
1506 * in the atomic state.
Daniel Vetter52217192016-08-12 22:48:50 +02001507 */
1508int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1509{
1510 struct drm_property *scaling_mode;
1511
1512 if (dev->mode_config.scaling_mode_property)
1513 return 0;
1514
1515 scaling_mode =
1516 drm_property_create_enum(dev, 0, "scaling mode",
1517 drm_scaling_mode_enum_list,
1518 ARRAY_SIZE(drm_scaling_mode_enum_list));
1519
1520 dev->mode_config.scaling_mode_property = scaling_mode;
1521
1522 return 0;
1523}
1524EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1525
1526/**
Nicholas Kazlauskasab7a6642018-10-04 14:38:42 -04001527 * DOC: Variable refresh properties
1528 *
1529 * Variable refresh rate capable displays can dynamically adjust their
1530 * refresh rate by extending the duration of their vertical front porch
1531 * until page flip or timeout occurs. This can reduce or remove stuttering
1532 * and latency in scenarios where the page flip does not align with the
1533 * vblank interval.
1534 *
1535 * An example scenario would be an application flipping at a constant rate
1536 * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1537 * interval and the same contents will be displayed twice. This can be
1538 * observed as stuttering for content with motion.
1539 *
1540 * If variable refresh rate was active on a display that supported a
1541 * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1542 * for the example scenario. The minimum supported variable refresh rate of
1543 * 35Hz is below the page flip frequency and the vertical front porch can
1544 * be extended until the page flip occurs. The vblank interval will be
1545 * directly aligned to the page flip rate.
1546 *
1547 * Not all userspace content is suitable for use with variable refresh rate.
1548 * Large and frequent changes in vertical front porch duration may worsen
1549 * perceived stuttering for input sensitive applications.
1550 *
1551 * Panel brightness will also vary with vertical front porch duration. Some
1552 * panels may have noticeable differences in brightness between the minimum
1553 * vertical front porch duration and the maximum vertical front porch duration.
1554 * Large and frequent changes in vertical front porch duration may produce
1555 * observable flickering for such panels.
1556 *
1557 * Userspace control for variable refresh rate is supported via properties
1558 * on the &drm_connector and &drm_crtc objects.
1559 *
1560 * "vrr_capable":
1561 * Optional &drm_connector boolean property that drivers should attach
1562 * with drm_connector_attach_vrr_capable_property() on connectors that
1563 * could support variable refresh rates. Drivers should update the
1564 * property value by calling drm_connector_set_vrr_capable_property().
1565 *
1566 * Absence of the property should indicate absence of support.
1567 *
Daniel Vetter77086012019-01-30 17:30:06 +01001568 * "VRR_ENABLED":
Nicholas Kazlauskasab7a6642018-10-04 14:38:42 -04001569 * Default &drm_crtc boolean property that notifies the driver that the
1570 * content on the CRTC is suitable for variable refresh rate presentation.
1571 * The driver will take this property as a hint to enable variable
1572 * refresh rate support if the receiver supports it, ie. if the
1573 * "vrr_capable" property is true on the &drm_connector object. The
1574 * vertical front porch duration will be extended until page-flip or
1575 * timeout when enabled.
1576 *
1577 * The minimum vertical front porch duration is defined as the vertical
1578 * front porch duration for the current mode.
1579 *
1580 * The maximum vertical front porch duration is greater than or equal to
1581 * the minimum vertical front porch duration. The duration is derived
1582 * from the minimum supported variable refresh rate for the connector.
1583 *
1584 * The driver may place further restrictions within these minimum
1585 * and maximum bounds.
Nicholas Kazlauskasab7a6642018-10-04 14:38:42 -04001586 */
1587
1588/**
Nicholas Kazlauskasba1b0f62018-09-18 09:55:20 -04001589 * drm_connector_attach_vrr_capable_property - creates the
1590 * vrr_capable property
1591 * @connector: connector to create the vrr_capable property on.
1592 *
1593 * This is used by atomic drivers to add support for querying
1594 * variable refresh rate capability for a connector.
1595 *
1596 * Returns:
1597 * Zero on success, negative errono on failure.
1598 */
1599int drm_connector_attach_vrr_capable_property(
1600 struct drm_connector *connector)
1601{
1602 struct drm_device *dev = connector->dev;
1603 struct drm_property *prop;
1604
1605 if (!connector->vrr_capable_property) {
1606 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1607 "vrr_capable");
1608 if (!prop)
1609 return -ENOMEM;
1610
1611 connector->vrr_capable_property = prop;
1612 drm_object_attach_property(&connector->base, prop, 0);
1613 }
1614
1615 return 0;
1616}
1617EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
1618
1619/**
Maarten Lankhorst8f6e1e22017-05-01 15:37:54 +02001620 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1621 * @connector: connector to attach scaling mode property on.
1622 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1623 *
1624 * This is used to add support for scaling mode to atomic drivers.
1625 * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
1626 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1627 *
1628 * This is the atomic version of drm_mode_create_scaling_mode_property().
1629 *
1630 * Returns:
1631 * Zero on success, negative errno on failure.
1632 */
1633int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1634 u32 scaling_mode_mask)
1635{
1636 struct drm_device *dev = connector->dev;
1637 struct drm_property *scaling_mode_property;
Ville Syrjälä30e9db6d2018-03-16 21:04:20 +02001638 int i;
Maarten Lankhorst8f6e1e22017-05-01 15:37:54 +02001639 const unsigned valid_scaling_mode_mask =
1640 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
1641
1642 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
1643 scaling_mode_mask & ~valid_scaling_mode_mask))
1644 return -EINVAL;
1645
1646 scaling_mode_property =
1647 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
1648 hweight32(scaling_mode_mask));
1649
1650 if (!scaling_mode_property)
1651 return -ENOMEM;
1652
1653 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
1654 int ret;
1655
1656 if (!(BIT(i) & scaling_mode_mask))
1657 continue;
1658
Ville Syrjälä30e9db6d2018-03-16 21:04:20 +02001659 ret = drm_property_add_enum(scaling_mode_property,
Maarten Lankhorst8f6e1e22017-05-01 15:37:54 +02001660 drm_scaling_mode_enum_list[i].type,
1661 drm_scaling_mode_enum_list[i].name);
1662
1663 if (ret) {
1664 drm_property_destroy(dev, scaling_mode_property);
1665
1666 return ret;
1667 }
1668 }
1669
1670 drm_object_attach_property(&connector->base,
1671 scaling_mode_property, 0);
1672
1673 connector->scaling_mode_property = scaling_mode_property;
1674
1675 return 0;
1676}
1677EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
1678
1679/**
Daniel Vetter52217192016-08-12 22:48:50 +02001680 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1681 * @dev: DRM device
1682 *
1683 * Called by a driver the first time it's needed, must be attached to desired
1684 * connectors.
1685 *
1686 * Returns:
1687 * Zero on success, negative errno on failure.
1688 */
1689int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1690{
1691 if (dev->mode_config.aspect_ratio_property)
1692 return 0;
1693
1694 dev->mode_config.aspect_ratio_property =
1695 drm_property_create_enum(dev, 0, "aspect ratio",
1696 drm_aspect_ratio_enum_list,
1697 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1698
1699 if (dev->mode_config.aspect_ratio_property == NULL)
1700 return -ENOMEM;
1701
1702 return 0;
1703}
1704EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1705
1706/**
Uma Shankard2c6a402019-02-19 22:42:59 +05301707 * DOC: standard connector properties
1708 *
1709 * Colorspace:
Uma Shankard2c6a402019-02-19 22:42:59 +05301710 * This property helps select a suitable colorspace based on the sink
1711 * capability. Modern sink devices support wider gamut like BT2020.
1712 * This helps switch to BT2020 mode if the BT2020 encoded video stream
1713 * is being played by the user, same for any other colorspace. Thereby
1714 * giving a good visual experience to users.
1715 *
1716 * The expectation from userspace is that it should parse the EDID
1717 * and get supported colorspaces. Use this property and switch to the
1718 * one supported. Sink supported colorspaces should be retrieved by
1719 * userspace from EDID and driver will not explicitly expose them.
1720 *
1721 * Basically the expectation from userspace is:
1722 * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
1723 * colorspace
1724 * - Set this new property to let the sink know what it
1725 * converted the CRTC output to.
1726 * - This property is just to inform sink what colorspace
1727 * source is trying to drive.
1728 *
Gwan-gyeong Mun8806cd32019-09-19 22:53:06 +03001729 * Because between HDMI and DP have different colorspaces,
Gwan-gyeong Mun45cf0e92019-09-19 22:53:07 +03001730 * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
1731 * drm_mode_create_dp_colorspace_property() is used for DP connector.
Uma Shankard2c6a402019-02-19 22:42:59 +05301732 */
Gwan-gyeong Mun8806cd32019-09-19 22:53:06 +03001733
1734/**
1735 * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
1736 * @connector: connector to create the Colorspace property on.
1737 *
1738 * Called by a driver the first time it's needed, must be attached to desired
1739 * HDMI connectors.
1740 *
1741 * Returns:
1742 * Zero on success, negative errono on failure.
1743 */
1744int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
Uma Shankard2c6a402019-02-19 22:42:59 +05301745{
1746 struct drm_device *dev = connector->dev;
Uma Shankard2c6a402019-02-19 22:42:59 +05301747
Gwan-gyeong Mun8806cd32019-09-19 22:53:06 +03001748 if (connector->colorspace_property)
Uma Shankard2c6a402019-02-19 22:42:59 +05301749 return 0;
Uma Shankard2c6a402019-02-19 22:42:59 +05301750
Gwan-gyeong Mun8806cd32019-09-19 22:53:06 +03001751 connector->colorspace_property =
1752 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
1753 hdmi_colorspaces,
1754 ARRAY_SIZE(hdmi_colorspaces));
1755
1756 if (!connector->colorspace_property)
1757 return -ENOMEM;
Uma Shankard2c6a402019-02-19 22:42:59 +05301758
1759 return 0;
1760}
Gwan-gyeong Mun8806cd32019-09-19 22:53:06 +03001761EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
Uma Shankard2c6a402019-02-19 22:42:59 +05301762
1763/**
Gwan-gyeong Mun45cf0e92019-09-19 22:53:07 +03001764 * drm_mode_create_dp_colorspace_property - create dp colorspace property
1765 * @connector: connector to create the Colorspace property on.
1766 *
1767 * Called by a driver the first time it's needed, must be attached to desired
1768 * DP connectors.
1769 *
1770 * Returns:
1771 * Zero on success, negative errono on failure.
1772 */
1773int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
1774{
1775 struct drm_device *dev = connector->dev;
1776
1777 if (connector->colorspace_property)
1778 return 0;
1779
1780 connector->colorspace_property =
1781 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
1782 dp_colorspaces,
1783 ARRAY_SIZE(dp_colorspaces));
1784
1785 if (!connector->colorspace_property)
1786 return -ENOMEM;
1787
1788 return 0;
1789}
1790EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
Daniel Vetter52217192016-08-12 22:48:50 +02001791
Daniel Vetter97e14fb2018-07-09 10:40:08 +02001792/**
Daniel Vetter52217192016-08-12 22:48:50 +02001793 * drm_mode_create_content_type_property - create content type property
1794 * @dev: DRM device
Daniel Vetter97e14fb2018-07-09 10:40:08 +02001795 *
Daniel Vetter52217192016-08-12 22:48:50 +02001796 * Called by a driver the first time it's needed, must be attached to desired
1797 * connectors.
1798 *
1799 * Returns:
1800 * Zero on success, negative errno on failure.
1801 */
1802int drm_mode_create_content_type_property(struct drm_device *dev)
1803{
1804 if (dev->mode_config.content_type_property)
Daniel Vetter97e14fb2018-07-09 10:40:08 +02001805 return 0;
Daniel Vetter52217192016-08-12 22:48:50 +02001806
1807 dev->mode_config.content_type_property =
1808 drm_property_create_enum(dev, 0, "content type",
1809 drm_content_type_enum_list,
1810 ARRAY_SIZE(drm_content_type_enum_list));
1811
1812 if (dev->mode_config.content_type_property == NULL)
1813 return -ENOMEM;
1814
1815 return 0;
1816}
1817EXPORT_SYMBOL(drm_mode_create_content_type_property);
1818
1819/**
1820 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1821 * @dev: DRM device
1822 *
1823 * Create the the suggested x/y offset property for connectors.
1824 */
1825int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
1826{
1827 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
1828 return 0;
1829
1830 dev->mode_config.suggested_x_property =
1831 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
1832
1833 dev->mode_config.suggested_y_property =
1834 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
Daniel Vetter97e14fb2018-07-09 10:40:08 +02001835
Daniel Vetter52217192016-08-12 22:48:50 +02001836 if (dev->mode_config.suggested_x_property == NULL ||
1837 dev->mode_config.suggested_y_property == NULL)
Daniel Vetterc555f022018-07-09 10:40:06 +02001838 return -ENOMEM;
Daniel Vetter52217192016-08-12 22:48:50 +02001839 return 0;
1840}
1841EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
1842
1843/**
1844 * drm_connector_set_path_property - set tile property on connector
1845 * @connector: connector to set property on.
1846 * @path: path to use for property; must not be NULL.
1847 *
Daniel Vetterc555f022018-07-09 10:40:06 +02001848 * This creates a property to expose to userspace to specify a
Daniel Vetter97e14fb2018-07-09 10:40:08 +02001849 * connector path. This is mainly used for DisplayPort MST where
Daniel Vetter52217192016-08-12 22:48:50 +02001850 * connectors have a topology and we want to allow userspace to give
1851 * them more meaningful names.
1852 *
1853 * Returns:
1854 * Zero on success, negative errno on failure.
1855 */
1856int drm_connector_set_path_property(struct drm_connector *connector,
1857 const char *path)
1858{
1859 struct drm_device *dev = connector->dev;
1860 int ret;
1861
Keith Packard170178f2017-12-13 00:44:26 -08001862 ret = drm_property_replace_global_blob(dev,
1863 &connector->path_blob_ptr,
1864 strlen(path) + 1,
1865 path,
1866 &connector->base,
1867 dev->mode_config.path_property);
1868 return ret;
1869}
1870EXPORT_SYMBOL(drm_connector_set_path_property);
1871
1872/**
1873 * drm_connector_set_tile_property - set tile property on connector
1874 * @connector: connector to set property on.
Dave Airlie66660d42017-10-16 05:08:09 +01001875 *
1876 * This looks up the tile information for a connector, and creates a
1877 * property for userspace to parse if it exists. The property is of
1878 * the form of 8 integers using ':' as a separator.
Manasi Navare2de3a072019-03-12 19:17:22 -07001879 * This is used for dual port tiled displays with DisplayPort SST
1880 * or DisplayPort MST connectors.
Daniel Vetter52217192016-08-12 22:48:50 +02001881 *
1882 * Returns:
1883 * Zero on success, errno on failure.
1884 */
1885int drm_connector_set_tile_property(struct drm_connector *connector)
1886{
1887 struct drm_device *dev = connector->dev;
1888 char tile[256];
1889 int ret;
1890
1891 if (!connector->has_tile) {
1892 ret = drm_property_replace_global_blob(dev,
1893 &connector->tile_blob_ptr,
1894 0,
1895 NULL,
1896 &connector->base,
1897 dev->mode_config.tile_property);
1898 return ret;
1899 }
1900
1901 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
1902 connector->tile_group->id, connector->tile_is_single_monitor,
1903 connector->num_h_tile, connector->num_v_tile,
1904 connector->tile_h_loc, connector->tile_v_loc,
1905 connector->tile_h_size, connector->tile_v_size);
1906
1907 ret = drm_property_replace_global_blob(dev,
1908 &connector->tile_blob_ptr,
1909 strlen(tile) + 1,
1910 tile,
1911 &connector->base,
1912 dev->mode_config.tile_property);
1913 return ret;
1914}
1915EXPORT_SYMBOL(drm_connector_set_tile_property);
1916
1917/**
1918 * drm_connector_update_edid_property - update the edid property of a connector
1919 * @connector: drm connector
1920 * @edid: new value of the edid property
1921 *
1922 * This function creates a new blob modeset object and assigns its id to the
1923 * connector's edid property.
Manasi Navare2de3a072019-03-12 19:17:22 -07001924 * Since we also parse tile information from EDID's displayID block, we also
1925 * set the connector's tile property here. See drm_connector_set_tile_property()
1926 * for more details.
Daniel Vetter52217192016-08-12 22:48:50 +02001927 *
1928 * Returns:
1929 * Zero on success, negative errno on failure.
1930 */
1931int drm_connector_update_edid_property(struct drm_connector *connector,
1932 const struct edid *edid)
1933{
1934 struct drm_device *dev = connector->dev;
1935 size_t size = 0;
1936 int ret;
1937
1938 /* ignore requests to set edid when overridden */
1939 if (connector->override_edid)
1940 return 0;
1941
Manasi Navare40ee6fb2016-12-16 12:29:06 +02001942 if (edid)
1943 size = EDID_LENGTH * (1 + edid->extensions);
1944
1945 /* Set the display info, using edid if available, otherwise
1946 * reseting the values to defaults. This duplicates the work
1947 * done in drm_add_edid_modes, but that function is not
1948 * consistently called before this one in all drivers and the
1949 * computation is cheap enough that it seems better to
1950 * duplicate it rather than attempt to ensure some arbitrary
1951 * ordering of calls.
1952 */
1953 if (edid)
1954 drm_add_display_info(connector, edid);
1955 else
1956 drm_reset_display_info(connector);
1957
1958 drm_object_property_set_value(&connector->base,
1959 dev->mode_config.non_desktop_property,
1960 connector->display_info.non_desktop);
1961
1962 ret = drm_property_replace_global_blob(dev,
1963 &connector->edid_blob_ptr,
1964 size,
1965 edid,
1966 &connector->base,
1967 dev->mode_config.edid_property);
Manasi Navare2de3a072019-03-12 19:17:22 -07001968 if (ret)
1969 return ret;
1970 return drm_connector_set_tile_property(connector);
Daniel Vetter52217192016-08-12 22:48:50 +02001971}
Daniel Vetterc555f022018-07-09 10:40:06 +02001972EXPORT_SYMBOL(drm_connector_update_edid_property);
Daniel Vetter52217192016-08-12 22:48:50 +02001973
Manasi Navare40ee6fb2016-12-16 12:29:06 +02001974/**
Daniel Vetter97e14fb2018-07-09 10:40:08 +02001975 * drm_connector_set_link_status_property - Set link status property of a connector
Manasi Navare40ee6fb2016-12-16 12:29:06 +02001976 * @connector: drm connector
1977 * @link_status: new value of link status property (0: Good, 1: Bad)
1978 *
1979 * In usual working scenario, this link status property will always be set to
1980 * "GOOD". If something fails during or after a mode set, the kernel driver
1981 * may set this link status property to "BAD". The caller then needs to send a
1982 * hotplug uevent for userspace to re-check the valid modes through
1983 * GET_CONNECTOR_IOCTL and retry modeset.
1984 *
1985 * Note: Drivers cannot rely on userspace to support this property and
1986 * issue a modeset. As such, they may choose to handle issues (like
1987 * re-training a link) without userspace's intervention.
1988 *
1989 * The reason for adding this property is to handle link training failures, but
1990 * it is not limited to DP or link training. For example, if we implement
1991 * asynchronous setcrtc, this property can be used to report any failures in that.
1992 */
Daniel Vetter97e14fb2018-07-09 10:40:08 +02001993void drm_connector_set_link_status_property(struct drm_connector *connector,
1994 uint64_t link_status)
Manasi Navare40ee6fb2016-12-16 12:29:06 +02001995{
1996 struct drm_device *dev = connector->dev;
1997
1998 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1999 connector->state->link_status = link_status;
2000 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2001}
Daniel Vetter97e14fb2018-07-09 10:40:08 +02002002EXPORT_SYMBOL(drm_connector_set_link_status_property);
Manasi Navare40ee6fb2016-12-16 12:29:06 +02002003
Hans de Goede8d70f392017-11-25 20:35:49 +01002004/**
Radhakrishna Sripada47e22ff2018-10-12 11:42:32 -07002005 * drm_connector_attach_max_bpc_property - attach "max bpc" property
2006 * @connector: connector to attach max bpc property on.
2007 * @min: The minimum bit depth supported by the connector.
2008 * @max: The maximum bit depth supported by the connector.
2009 *
2010 * This is used to add support for limiting the bit depth on a connector.
2011 *
2012 * Returns:
2013 * Zero on success, negative errno on failure.
2014 */
2015int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
2016 int min, int max)
2017{
2018 struct drm_device *dev = connector->dev;
2019 struct drm_property *prop;
2020
2021 prop = connector->max_bpc_property;
2022 if (!prop) {
2023 prop = drm_property_create_range(dev, 0, "max bpc", min, max);
2024 if (!prop)
2025 return -ENOMEM;
2026
2027 connector->max_bpc_property = prop;
2028 }
2029
2030 drm_object_attach_property(&connector->base, prop, max);
2031 connector->state->max_requested_bpc = max;
2032 connector->state->max_bpc = max;
2033
2034 return 0;
2035}
2036EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
2037
2038/**
Nicholas Kazlauskasba1b0f62018-09-18 09:55:20 -04002039 * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2040 * capable property for a connector
2041 * @connector: drm connector
2042 * @capable: True if the connector is variable refresh rate capable
2043 *
2044 * Should be used by atomic drivers to update the indicated support for
2045 * variable refresh rate over a connector.
2046 */
2047void drm_connector_set_vrr_capable_property(
2048 struct drm_connector *connector, bool capable)
2049{
2050 drm_object_property_set_value(&connector->base,
2051 connector->vrr_capable_property,
2052 capable);
2053}
2054EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2055
2056/**
Derek Basehore69654c62020-01-05 16:51:19 +01002057 * drm_connector_set_panel_orientation - sets the connecter's panel_orientation
2058 * @connector: connector for which to set the panel-orientation property.
2059 * @panel_orientation: drm_panel_orientation value to set
Hans de Goede8d70f392017-11-25 20:35:49 +01002060 *
Derek Basehore69654c62020-01-05 16:51:19 +01002061 * This function sets the connector's panel_orientation and attaches
2062 * a "panel orientation" property to the connector.
Hans de Goede8d70f392017-11-25 20:35:49 +01002063 *
Derek Basehore69654c62020-01-05 16:51:19 +01002064 * Calling this function on a connector where the panel_orientation has
2065 * already been set is a no-op (e.g. the orientation has been overridden with
2066 * a kernel commandline option).
2067 *
2068 * It is allowed to call this function with a panel_orientation of
2069 * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
Hans de Goede8d70f392017-11-25 20:35:49 +01002070 *
2071 * Returns:
2072 * Zero on success, negative errno on failure.
2073 */
Derek Basehore69654c62020-01-05 16:51:19 +01002074int drm_connector_set_panel_orientation(
2075 struct drm_connector *connector,
2076 enum drm_panel_orientation panel_orientation)
Hans de Goede8d70f392017-11-25 20:35:49 +01002077{
2078 struct drm_device *dev = connector->dev;
2079 struct drm_display_info *info = &connector->display_info;
2080 struct drm_property *prop;
Hans de Goede8d70f392017-11-25 20:35:49 +01002081
Derek Basehore69654c62020-01-05 16:51:19 +01002082 /* Already set? */
2083 if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
Hans de Goede8d70f392017-11-25 20:35:49 +01002084 return 0;
2085
Derek Basehore69654c62020-01-05 16:51:19 +01002086 /* Don't attach the property if the orientation is unknown */
2087 if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2088 return 0;
2089
2090 info->panel_orientation = panel_orientation;
2091
Hans de Goede8d70f392017-11-25 20:35:49 +01002092 prop = dev->mode_config.panel_orientation_property;
2093 if (!prop) {
2094 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
2095 "panel orientation",
2096 drm_panel_orientation_enum_list,
2097 ARRAY_SIZE(drm_panel_orientation_enum_list));
2098 if (!prop)
2099 return -ENOMEM;
2100
2101 dev->mode_config.panel_orientation_property = prop;
2102 }
2103
2104 drm_object_attach_property(&connector->base, prop,
2105 info->panel_orientation);
2106 return 0;
2107}
Derek Basehore69654c62020-01-05 16:51:19 +01002108EXPORT_SYMBOL(drm_connector_set_panel_orientation);
2109
2110/**
2111 * drm_connector_set_panel_orientation_with_quirk -
2112 * set the connecter's panel_orientation after checking for quirks
2113 * @connector: connector for which to init the panel-orientation property.
2114 * @panel_orientation: drm_panel_orientation value to set
2115 * @width: width in pixels of the panel, used for panel quirk detection
2116 * @height: height in pixels of the panel, used for panel quirk detection
2117 *
2118 * Like drm_connector_set_panel_orientation(), but with a check for platform
2119 * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
2120 *
2121 * Returns:
2122 * Zero on success, negative errno on failure.
2123 */
2124int drm_connector_set_panel_orientation_with_quirk(
2125 struct drm_connector *connector,
2126 enum drm_panel_orientation panel_orientation,
2127 int width, int height)
2128{
2129 int orientation_quirk;
2130
2131 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
2132 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2133 panel_orientation = orientation_quirk;
2134
2135 return drm_connector_set_panel_orientation(connector,
2136 panel_orientation);
2137}
2138EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
Hans de Goede8d70f392017-11-25 20:35:49 +01002139
Daniel Vetter97e14fb2018-07-09 10:40:08 +02002140int drm_connector_set_obj_prop(struct drm_mode_object *obj,
Daniel Vetter52217192016-08-12 22:48:50 +02002141 struct drm_property *property,
2142 uint64_t value)
2143{
2144 int ret = -EINVAL;
2145 struct drm_connector *connector = obj_to_connector(obj);
2146
2147 /* Do DPMS ourselves */
2148 if (property == connector->dev->mode_config.dpms_property) {
2149 ret = (*connector->funcs->dpms)(connector, (int)value);
2150 } else if (connector->funcs->set_property)
2151 ret = connector->funcs->set_property(connector, property, value);
2152
Daniel Vetter144a7992017-07-25 14:02:04 +02002153 if (!ret)
Daniel Vetter52217192016-08-12 22:48:50 +02002154 drm_object_property_set_value(&connector->base, property, value);
2155 return ret;
2156}
2157
Daniel Vetter97e14fb2018-07-09 10:40:08 +02002158int drm_connector_property_set_ioctl(struct drm_device *dev,
2159 void *data, struct drm_file *file_priv)
Daniel Vetter52217192016-08-12 22:48:50 +02002160{
2161 struct drm_mode_connector_set_property *conn_set_prop = data;
2162 struct drm_mode_obj_set_property obj_set_prop = {
2163 .value = conn_set_prop->value,
2164 .prop_id = conn_set_prop->prop_id,
2165 .obj_id = conn_set_prop->connector_id,
2166 .obj_type = DRM_MODE_OBJECT_CONNECTOR
2167 };
2168
2169 /* It does all the locking and checking we need */
2170 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
2171}
2172
2173static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
2174{
2175 /* For atomic drivers only state objects are synchronously updated and
2176 * protected by modeset locks, so check those first. */
2177 if (connector->state)
2178 return connector->state->best_encoder;
2179 return connector->encoder;
2180}
2181
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302182static bool
2183drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
2184 const struct list_head *export_list,
2185 const struct drm_file *file_priv)
Daniel Vetter52217192016-08-12 22:48:50 +02002186{
2187 /*
2188 * If user-space hasn't configured the driver to expose the stereo 3D
2189 * modes, don't expose them.
2190 */
2191 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
2192 return false;
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302193 /*
2194 * If user-space hasn't configured the driver to expose the modes
2195 * with aspect-ratio, don't expose them. However if such a mode
2196 * is unique, let it be exposed, but reset the aspect-ratio flags
2197 * while preparing the list of user-modes.
2198 */
2199 if (!file_priv->aspect_ratio_allowed) {
2200 struct drm_display_mode *mode_itr;
2201
2202 list_for_each_entry(mode_itr, export_list, export_head)
2203 if (drm_mode_match(mode_itr, mode,
2204 DRM_MODE_MATCH_TIMINGS |
2205 DRM_MODE_MATCH_CLOCK |
2206 DRM_MODE_MATCH_FLAGS |
2207 DRM_MODE_MATCH_3D_FLAGS))
2208 return false;
2209 }
Daniel Vetter52217192016-08-12 22:48:50 +02002210
2211 return true;
2212}
2213
2214int drm_mode_getconnector(struct drm_device *dev, void *data,
2215 struct drm_file *file_priv)
2216{
2217 struct drm_mode_get_connector *out_resp = data;
2218 struct drm_connector *connector;
2219 struct drm_encoder *encoder;
2220 struct drm_display_mode *mode;
2221 int mode_count = 0;
2222 int encoders_count = 0;
2223 int ret = 0;
2224 int copied = 0;
Daniel Vetter52217192016-08-12 22:48:50 +02002225 struct drm_mode_modeinfo u_mode;
2226 struct drm_mode_modeinfo __user *mode_ptr;
2227 uint32_t __user *encoder_ptr;
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302228 LIST_HEAD(export_list);
Daniel Vetter52217192016-08-12 22:48:50 +02002229
2230 if (!drm_core_check_feature(dev, DRIVER_MODESET))
Chris Wilson69fdf422018-09-13 20:20:50 +01002231 return -EOPNOTSUPP;
Daniel Vetter52217192016-08-12 22:48:50 +02002232
2233 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
2234
Keith Packard418da172017-03-14 23:25:07 -07002235 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
Daniel Vetter91eefc02016-12-14 00:08:10 +01002236 if (!connector)
2237 return -ENOENT;
Daniel Vetter52217192016-08-12 22:48:50 +02002238
José Roberto de Souza62afb4a2019-09-13 16:28:57 -07002239 encoders_count = hweight32(connector->possible_encoders);
Daniel Vetter91eefc02016-12-14 00:08:10 +01002240
2241 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
2242 copied = 0;
2243 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
Ville Syrjälä83aefbb2018-06-28 16:13:09 +03002244
José Roberto de Souza62afb4a2019-09-13 16:28:57 -07002245 drm_connector_for_each_possible_encoder(connector, encoder) {
Ville Syrjälä83aefbb2018-06-28 16:13:09 +03002246 if (put_user(encoder->base.id, encoder_ptr + copied)) {
2247 ret = -EFAULT;
2248 goto out;
Daniel Vetter91eefc02016-12-14 00:08:10 +01002249 }
Ville Syrjälä83aefbb2018-06-28 16:13:09 +03002250 copied++;
Daniel Vetter91eefc02016-12-14 00:08:10 +01002251 }
2252 }
2253 out_resp->count_encoders = encoders_count;
2254
2255 out_resp->connector_id = connector->base.id;
2256 out_resp->connector_type = connector->connector_type;
2257 out_resp->connector_type_id = connector->connector_type_id;
2258
2259 mutex_lock(&dev->mode_config.mutex);
2260 if (out_resp->count_modes == 0) {
2261 connector->funcs->fill_modes(connector,
2262 dev->mode_config.max_width,
2263 dev->mode_config.max_height);
2264 }
2265
2266 out_resp->mm_width = connector->display_info.width_mm;
2267 out_resp->mm_height = connector->display_info.height_mm;
2268 out_resp->subpixel = connector->display_info.subpixel_order;
2269 out_resp->connection = connector->status;
2270
2271 /* delayed so we get modes regardless of pre-fill_modes state */
2272 list_for_each_entry(mode, &connector->modes, head)
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302273 if (drm_mode_expose_to_userspace(mode, &export_list,
2274 file_priv)) {
2275 list_add_tail(&mode->export_head, &export_list);
Daniel Vetter91eefc02016-12-14 00:08:10 +01002276 mode_count++;
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302277 }
Daniel Vetter91eefc02016-12-14 00:08:10 +01002278
Daniel Vetter52217192016-08-12 22:48:50 +02002279 /*
2280 * This ioctl is called twice, once to determine how much space is
2281 * needed, and the 2nd time to fill it.
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302282 * The modes that need to be exposed to the user are maintained in the
2283 * 'export_list'. When the ioctl is called first time to determine the,
2284 * space, the export_list gets filled, to find the no.of modes. In the
2285 * 2nd time, the user modes are filled, one by one from the export_list.
Daniel Vetter52217192016-08-12 22:48:50 +02002286 */
2287 if ((out_resp->count_modes >= mode_count) && mode_count) {
2288 copied = 0;
2289 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302290 list_for_each_entry(mode, &export_list, export_head) {
Daniel Vetter52217192016-08-12 22:48:50 +02002291 drm_mode_convert_to_umode(&u_mode, mode);
Ankit Nautiyalc3ff0cd2018-05-08 16:39:43 +05302292 /*
2293 * Reset aspect ratio flags of user-mode, if modes with
2294 * aspect-ratio are not supported.
2295 */
2296 if (!file_priv->aspect_ratio_allowed)
2297 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
Daniel Vetter52217192016-08-12 22:48:50 +02002298 if (copy_to_user(mode_ptr + copied,
2299 &u_mode, sizeof(u_mode))) {
2300 ret = -EFAULT;
Daniel Vettere94ac352017-06-20 22:28:37 +02002301 mutex_unlock(&dev->mode_config.mutex);
2302
Daniel Vetter52217192016-08-12 22:48:50 +02002303 goto out;
2304 }
2305 copied++;
2306 }
2307 }
2308 out_resp->count_modes = mode_count;
Daniel Vetter52217192016-08-12 22:48:50 +02002309 mutex_unlock(&dev->mode_config.mutex);
Daniel Vettere94ac352017-06-20 22:28:37 +02002310
2311 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2312 encoder = drm_connector_get_encoder(connector);
2313 if (encoder)
2314 out_resp->encoder_id = encoder->base.id;
2315 else
2316 out_resp->encoder_id = 0;
2317
2318 /* Only grab properties after probing, to make sure EDID and other
2319 * properties reflect the latest status. */
2320 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2321 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2322 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2323 &out_resp->count_props);
2324 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2325
2326out:
Thierry Redingad093602017-02-28 15:46:39 +01002327 drm_connector_put(connector);
Daniel Vetter52217192016-08-12 22:48:50 +02002328
2329 return ret;
2330}
2331
Daniel Vetter9498c192016-11-14 12:58:24 +01002332
2333/**
2334 * DOC: Tile group
2335 *
2336 * Tile groups are used to represent tiled monitors with a unique integer
2337 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
2338 * we store this in a tile group, so we have a common identifier for all tiles
2339 * in a monitor group. The property is called "TILE". Drivers can manage tile
2340 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
2341 * drm_mode_get_tile_group(). But this is only needed for internal panels where
2342 * the tile group information is exposed through a non-standard way.
2343 */
2344
2345static void drm_tile_group_free(struct kref *kref)
2346{
2347 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
2348 struct drm_device *dev = tg->dev;
2349 mutex_lock(&dev->mode_config.idr_mutex);
2350 idr_remove(&dev->mode_config.tile_idr, tg->id);
2351 mutex_unlock(&dev->mode_config.idr_mutex);
2352 kfree(tg);
2353}
2354
2355/**
2356 * drm_mode_put_tile_group - drop a reference to a tile group.
2357 * @dev: DRM device
2358 * @tg: tile group to drop reference to.
2359 *
2360 * drop reference to tile group and free if 0.
2361 */
2362void drm_mode_put_tile_group(struct drm_device *dev,
2363 struct drm_tile_group *tg)
2364{
2365 kref_put(&tg->refcount, drm_tile_group_free);
2366}
2367EXPORT_SYMBOL(drm_mode_put_tile_group);
2368
2369/**
2370 * drm_mode_get_tile_group - get a reference to an existing tile group
2371 * @dev: DRM device
2372 * @topology: 8-bytes unique per monitor.
2373 *
2374 * Use the unique bytes to get a reference to an existing tile group.
2375 *
2376 * RETURNS:
2377 * tile group or NULL if not found.
2378 */
2379struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2380 char topology[8])
2381{
2382 struct drm_tile_group *tg;
2383 int id;
2384 mutex_lock(&dev->mode_config.idr_mutex);
2385 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
2386 if (!memcmp(tg->group_data, topology, 8)) {
2387 if (!kref_get_unless_zero(&tg->refcount))
2388 tg = NULL;
2389 mutex_unlock(&dev->mode_config.idr_mutex);
2390 return tg;
2391 }
2392 }
2393 mutex_unlock(&dev->mode_config.idr_mutex);
2394 return NULL;
2395}
2396EXPORT_SYMBOL(drm_mode_get_tile_group);
2397
2398/**
2399 * drm_mode_create_tile_group - create a tile group from a displayid description
2400 * @dev: DRM device
2401 * @topology: 8-bytes unique per monitor.
2402 *
2403 * Create a tile group for the unique monitor, and get a unique
2404 * identifier for the tile group.
2405 *
2406 * RETURNS:
Dan Carpenter705c8162018-12-17 10:00:38 +03002407 * new tile group or NULL.
Daniel Vetter9498c192016-11-14 12:58:24 +01002408 */
2409struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2410 char topology[8])
2411{
2412 struct drm_tile_group *tg;
2413 int ret;
2414
2415 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
2416 if (!tg)
Dan Carpenter705c8162018-12-17 10:00:38 +03002417 return NULL;
Daniel Vetter9498c192016-11-14 12:58:24 +01002418
2419 kref_init(&tg->refcount);
2420 memcpy(tg->group_data, topology, 8);
2421 tg->dev = dev;
2422
2423 mutex_lock(&dev->mode_config.idr_mutex);
2424 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
2425 if (ret >= 0) {
2426 tg->id = ret;
2427 } else {
2428 kfree(tg);
Dan Carpenter705c8162018-12-17 10:00:38 +03002429 tg = NULL;
Daniel Vetter9498c192016-11-14 12:58:24 +01002430 }
2431
2432 mutex_unlock(&dev->mode_config.idr_mutex);
2433 return tg;
2434}
2435EXPORT_SYMBOL(drm_mode_create_tile_group);