2 * Copyright (c) 2016 Intel Corporation
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.
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
23 #include <drm/drm_modeset_helper.h>
24 #include <drm/drm_plane_helper.h>
27 * DOC: aux kms helpers
29 * This helper library contains various one-off functions which don't really fit
30 * anywhere else in the DRM modeset helper library.
34 * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
36 * @dev: drm device to operate on
38 * Some userspace presumes that the first connected connector is the main
39 * display, where it's supposed to display e.g. the login screen. For
40 * laptops, this should be the main panel. Use this function to sort all
41 * (eDP/LVDS/DSI) panels to the front of the connector list, instead of
42 * painstakingly trying to initialize them in the right order.
44 void drm_helper_move_panel_connectors_to_head(struct drm_device
*dev
)
46 struct drm_connector
*connector
, *tmp
;
47 struct list_head panel_list
;
49 INIT_LIST_HEAD(&panel_list
);
51 spin_lock_irq(&dev
->mode_config
.connector_list_lock
);
52 list_for_each_entry_safe(connector
, tmp
,
53 &dev
->mode_config
.connector_list
, head
) {
54 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
||
55 connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
||
56 connector
->connector_type
== DRM_MODE_CONNECTOR_DSI
)
57 list_move_tail(&connector
->head
, &panel_list
);
60 list_splice(&panel_list
, &dev
->mode_config
.connector_list
);
61 spin_unlock_irq(&dev
->mode_config
.connector_list_lock
);
63 EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head
);
66 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
68 * @fb: drm_framebuffer object to fill out
69 * @mode_cmd: metadata from the userspace fb creation request
71 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
74 void drm_helper_mode_fill_fb_struct(struct drm_device
*dev
,
75 struct drm_framebuffer
*fb
,
76 const struct drm_mode_fb_cmd2
*mode_cmd
)
81 fb
->format
= drm_get_format_info(dev
, mode_cmd
);
82 fb
->width
= mode_cmd
->width
;
83 fb
->height
= mode_cmd
->height
;
84 for (i
= 0; i
< 4; i
++) {
85 fb
->pitches
[i
] = mode_cmd
->pitches
[i
];
86 fb
->offsets
[i
] = mode_cmd
->offsets
[i
];
88 fb
->modifier
= mode_cmd
->modifier
[0];
89 fb
->flags
= mode_cmd
->flags
;
91 EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct
);
94 * This is the minimal list of formats that seem to be safe for modeset use
95 * with all current DRM drivers. Most hardware can actually support more
96 * formats than this and drivers may specify a more accurate list when
97 * creating the primary plane. However drivers that still call
98 * drm_plane_init() will use this minimal format list as the default.
100 static const uint32_t safe_modeset_formats
[] = {
105 static struct drm_plane
*create_primary_plane(struct drm_device
*dev
)
107 struct drm_plane
*primary
;
110 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
111 if (primary
== NULL
) {
112 DRM_DEBUG_KMS("Failed to allocate primary plane\n");
117 * Remove the format_default field from drm_plane when dropping
120 primary
->format_default
= true;
122 /* possible_crtc's will be filled in later by crtc_init */
123 ret
= drm_universal_plane_init(dev
, primary
, 0,
124 &drm_primary_helper_funcs
,
125 safe_modeset_formats
,
126 ARRAY_SIZE(safe_modeset_formats
),
128 DRM_PLANE_TYPE_PRIMARY
, NULL
);
138 * drm_crtc_init - Legacy CRTC initialization function
140 * @crtc: CRTC object to init
141 * @funcs: callbacks for the new CRTC
143 * Initialize a CRTC object with a default helper-provided primary plane and no
147 * Zero on success, error code on failure.
149 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
150 const struct drm_crtc_funcs
*funcs
)
152 struct drm_plane
*primary
;
154 primary
= create_primary_plane(dev
);
155 return drm_crtc_init_with_planes(dev
, crtc
, primary
, NULL
, funcs
,
158 EXPORT_SYMBOL(drm_crtc_init
);