2 * Copyright (c) 2006-2009 Red Hat Inc.
3 * Copyright (c) 2006-2008 Intel Corporation
4 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
6 * DRM framebuffer helper functions
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/kernel.h>
33 #include <linux/sysrq.h>
34 #include <linux/slab.h>
36 #include <linux/module.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_fb_helper.h>
40 #include <drm/drm_crtc_helper.h>
42 static LIST_HEAD(kernel_fb_helper_list);
47 * The fb helper functions are useful to provide an fbdev on top of a drm kernel
48 * mode setting driver. They can be used mostly independently from the crtc
49 * helper functions used by many drivers to implement the kernel mode setting
52 * Initialization is done as a four-step process with drm_fb_helper_prepare(),
53 * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and
54 * drm_fb_helper_initial_config(). Drivers with fancier requirements than the
55 * default behaviour can override the third step with their own code.
56 * Teardown is done with drm_fb_helper_fini().
58 * At runtime drivers should restore the fbdev console by calling
59 * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
60 * should also notify the fb helper code from updates to the output
61 * configuration by calling drm_fb_helper_hotplug_event(). For easier
62 * integration with the output polling code in drm_crtc_helper.c the modeset
63 * code provides a ->output_poll_changed callback.
65 * All other functions exported by the fb helper library can be used to
66 * implement the fbdev driver interface by the driver.
68 * It is possible, though perhaps somewhat tricky, to implement race-free
69 * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare()
70 * helper must be called first to initialize the minimum required to make
71 * hotplug detection work. Drivers also need to make sure to properly set up
72 * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init()
73 * it is safe to enable interrupts and start processing hotplug events. At the
74 * same time, drivers should initialize all modeset objects such as CRTCs,
75 * encoders and connectors. To finish up the fbdev helper initialization, the
76 * drm_fb_helper_init() function is called. To probe for all attached displays
77 * and set up an initial configuration using the detected hardware, drivers
78 * should call drm_fb_helper_single_add_all_connectors() followed by
79 * drm_fb_helper_initial_config().
83 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
85 * @fb_helper: fbdev initialized with drm_fb_helper_init
87 * This functions adds all the available connectors for use with the given
88 * fb_helper. This is a separate step to allow drivers to freely assign
89 * connectors to the fbdev, e.g. if some are reserved for special purposes or
90 * not adequate to be used for the fbcon.
92 * Since this is part of the initial setup before the fbdev is published, no
93 * locking is required.
95 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
97 struct drm_device *dev = fb_helper->dev;
98 struct drm_connector *connector;
101 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
102 struct drm_fb_helper_connector *fb_helper_connector;
104 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
105 if (!fb_helper_connector)
108 fb_helper_connector->connector = connector;
109 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
113 for (i = 0; i < fb_helper->connector_count; i++) {
114 kfree(fb_helper->connector_info[i]);
115 fb_helper->connector_info[i] = NULL;
117 fb_helper->connector_count = 0;
120 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
122 static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
124 struct drm_fb_helper_connector *fb_helper_conn;
127 for (i = 0; i < fb_helper->connector_count; i++) {
128 struct drm_cmdline_mode *mode;
129 struct drm_connector *connector;
132 fb_helper_conn = fb_helper->connector_info[i];
133 connector = fb_helper_conn->connector;
134 mode = &fb_helper_conn->cmdline_mode;
136 /* do something on return - turn off connector maybe */
137 if (fb_get_options(connector->name, &option))
140 if (drm_mode_parse_command_line_for_connector(option,
145 switch (mode->force) {
149 case DRM_FORCE_ON_DIGITAL:
158 DRM_INFO("forcing %s connector %s\n",
160 connector->force = mode->force;
163 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
165 mode->xres, mode->yres,
166 mode->refresh_specified ? mode->refresh : 60,
167 mode->rb ? " reduced blanking" : "",
168 mode->margins ? " with margins" : "",
169 mode->interlace ? " interlaced" : "");
176 static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper)
178 uint16_t *r_base, *g_base, *b_base;
181 if (helper->funcs->gamma_get == NULL)
184 r_base = crtc->gamma_store;
185 g_base = r_base + crtc->gamma_size;
186 b_base = g_base + crtc->gamma_size;
188 for (i = 0; i < crtc->gamma_size; i++)
189 helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i);
192 static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
194 uint16_t *r_base, *g_base, *b_base;
196 if (crtc->funcs->gamma_set == NULL)
199 r_base = crtc->gamma_store;
200 g_base = r_base + crtc->gamma_size;
201 b_base = g_base + crtc->gamma_size;
203 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
207 * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter
208 * @info: fbdev registered by the helper
210 int drm_fb_helper_debug_enter(struct fb_info *info)
212 struct drm_fb_helper *helper = info->par;
213 struct drm_crtc_helper_funcs *funcs;
216 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
217 for (i = 0; i < helper->crtc_count; i++) {
218 struct drm_mode_set *mode_set =
219 &helper->crtc_info[i].mode_set;
221 if (!mode_set->crtc->enabled)
224 funcs = mode_set->crtc->helper_private;
225 drm_fb_helper_save_lut_atomic(mode_set->crtc, helper);
226 funcs->mode_set_base_atomic(mode_set->crtc,
230 ENTER_ATOMIC_MODE_SET);
236 EXPORT_SYMBOL(drm_fb_helper_debug_enter);
238 /* Find the real fb for a given fb helper CRTC */
239 static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
241 struct drm_device *dev = crtc->dev;
244 list_for_each_entry(c, &dev->mode_config.crtc_list, head) {
245 if (crtc->base.id == c->base.id)
246 return c->primary->fb;
253 * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
254 * @info: fbdev registered by the helper
256 int drm_fb_helper_debug_leave(struct fb_info *info)
258 struct drm_fb_helper *helper = info->par;
259 struct drm_crtc *crtc;
260 struct drm_crtc_helper_funcs *funcs;
261 struct drm_framebuffer *fb;
264 for (i = 0; i < helper->crtc_count; i++) {
265 struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
266 crtc = mode_set->crtc;
267 funcs = crtc->helper_private;
268 fb = drm_mode_config_fb(crtc);
274 DRM_ERROR("no fb to restore??\n");
278 drm_fb_helper_restore_lut_atomic(mode_set->crtc);
279 funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x,
280 crtc->y, LEAVE_ATOMIC_MODE_SET);
285 EXPORT_SYMBOL(drm_fb_helper_debug_leave);
287 static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper)
289 struct drm_device *dev = fb_helper->dev;
290 struct drm_plane *plane;
294 drm_warn_on_modeset_not_all_locked(dev);
296 list_for_each_entry(plane, &dev->mode_config.plane_list, head)
297 if (plane->type != DRM_PLANE_TYPE_PRIMARY)
298 drm_plane_force_disable(plane);
300 for (i = 0; i < fb_helper->crtc_count; i++) {
301 struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
302 struct drm_crtc *crtc = mode_set->crtc;
305 if (crtc->funcs->cursor_set) {
306 ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0);
311 ret = drm_mode_set_config_internal(mode_set);
318 * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
319 * @fb_helper: fbcon to restore
321 * This should be called from driver's drm ->lastclose callback
322 * when implementing an fbcon on top of kms using this helper. This ensures that
323 * the user isn't greeted with a black screen when e.g. X dies.
325 * Use this variant if you need to bypass locking (panic), or already
326 * hold all modeset locks. Otherwise use drm_fb_helper_restore_fbdev_mode_unlocked()
328 static bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
330 return restore_fbdev_mode(fb_helper);
334 * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
335 * @fb_helper: fbcon to restore
337 * This should be called from driver's drm ->lastclose callback
338 * when implementing an fbcon on top of kms using this helper. This ensures that
339 * the user isn't greeted with a black screen when e.g. X dies.
341 bool drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
343 struct drm_device *dev = fb_helper->dev;
345 drm_modeset_lock_all(dev);
346 ret = restore_fbdev_mode(fb_helper);
347 drm_modeset_unlock_all(dev);
350 EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked);
353 * restore fbcon display for all kms driver's using this helper, used for sysrq
354 * and panic handling.
356 static bool drm_fb_helper_force_kernel_mode(void)
358 bool ret, error = false;
359 struct drm_fb_helper *helper;
361 if (list_empty(&kernel_fb_helper_list))
364 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
365 struct drm_device *dev = helper->dev;
367 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
370 /* NOTE: we use lockless flag below to avoid grabbing other
371 * modeset locks. So just trylock the underlying mutex
374 if (!mutex_trylock(&dev->mode_config.mutex)) {
379 ret = drm_fb_helper_restore_fbdev_mode(helper);
383 mutex_unlock(&dev->mode_config.mutex);
388 static int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
392 * It's a waste of time and effort to switch back to text console
393 * if the kernel should reboot before panic messages can be seen.
395 if (panic_timeout < 0)
398 pr_err("panic occurred, switching back to text console\n");
399 return drm_fb_helper_force_kernel_mode();
402 static struct notifier_block paniced = {
403 .notifier_call = drm_fb_helper_panic,
406 static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
408 struct drm_device *dev = fb_helper->dev;
409 struct drm_crtc *crtc;
410 int bound = 0, crtcs_bound = 0;
412 /* Sometimes user space wants everything disabled, so don't steal the
413 * display if there's a master. */
414 if (dev->primary->master)
417 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
418 if (crtc->primary->fb)
420 if (crtc->primary->fb == fb_helper->fb)
424 if (bound < crtcs_bound)
430 #ifdef CONFIG_MAGIC_SYSRQ
431 static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
434 ret = drm_fb_helper_force_kernel_mode();
436 DRM_ERROR("Failed to restore crtc configuration\n");
438 static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
440 static void drm_fb_helper_sysrq(int dummy1)
442 schedule_work(&drm_fb_helper_restore_work);
445 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
446 .handler = drm_fb_helper_sysrq,
447 .help_msg = "force-fb(V)",
448 .action_msg = "Restore framebuffer console",
451 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
454 static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
456 struct drm_fb_helper *fb_helper = info->par;
457 struct drm_device *dev = fb_helper->dev;
458 struct drm_crtc *crtc;
459 struct drm_connector *connector;
463 * fbdev->blank can be called from irq context in case of a panic.
464 * Since we already have our own special panic handler which will
465 * restore the fbdev console mode completely, just bail out early.
467 if (oops_in_progress)
471 * For each CRTC in this fb, turn the connectors on/off.
473 drm_modeset_lock_all(dev);
474 if (!drm_fb_helper_is_bound(fb_helper)) {
475 drm_modeset_unlock_all(dev);
479 for (i = 0; i < fb_helper->crtc_count; i++) {
480 crtc = fb_helper->crtc_info[i].mode_set.crtc;
485 /* Walk the connectors & encoders on this fb turning them on/off */
486 for (j = 0; j < fb_helper->connector_count; j++) {
487 connector = fb_helper->connector_info[j]->connector;
488 connector->funcs->dpms(connector, dpms_mode);
489 drm_object_property_set_value(&connector->base,
490 dev->mode_config.dpms_property, dpms_mode);
493 drm_modeset_unlock_all(dev);
497 * drm_fb_helper_blank - implementation for ->fb_blank
498 * @blank: desired blanking state
499 * @info: fbdev registered by the helper
501 int drm_fb_helper_blank(int blank, struct fb_info *info)
504 /* Display: On; HSync: On, VSync: On */
505 case FB_BLANK_UNBLANK:
506 drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON);
508 /* Display: Off; HSync: On, VSync: On */
509 case FB_BLANK_NORMAL:
510 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
512 /* Display: Off; HSync: Off, VSync: On */
513 case FB_BLANK_HSYNC_SUSPEND:
514 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
516 /* Display: Off; HSync: On, VSync: Off */
517 case FB_BLANK_VSYNC_SUSPEND:
518 drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND);
520 /* Display: Off; HSync: Off, VSync: Off */
521 case FB_BLANK_POWERDOWN:
522 drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF);
527 EXPORT_SYMBOL(drm_fb_helper_blank);
529 static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
533 for (i = 0; i < helper->connector_count; i++)
534 kfree(helper->connector_info[i]);
535 kfree(helper->connector_info);
536 for (i = 0; i < helper->crtc_count; i++) {
537 kfree(helper->crtc_info[i].mode_set.connectors);
538 if (helper->crtc_info[i].mode_set.mode)
539 drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode);
541 kfree(helper->crtc_info);
545 * drm_fb_helper_prepare - setup a drm_fb_helper structure
547 * @helper: driver-allocated fbdev helper structure to set up
548 * @funcs: pointer to structure of functions associate with this helper
550 * Sets up the bare minimum to make the framebuffer helper usable. This is
551 * useful to implement race-free initialization of the polling helpers.
553 void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
554 const struct drm_fb_helper_funcs *funcs)
556 INIT_LIST_HEAD(&helper->kernel_fb_list);
557 helper->funcs = funcs;
560 EXPORT_SYMBOL(drm_fb_helper_prepare);
563 * drm_fb_helper_init - initialize a drm_fb_helper structure
565 * @fb_helper: driver-allocated fbdev helper structure to initialize
566 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
567 * @max_conn_count: max connector count
569 * This allocates the structures for the fbdev helper with the given limits.
570 * Note that this won't yet touch the hardware (through the driver interfaces)
571 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
572 * to allow driver writes more control over the exact init sequence.
574 * Drivers must call drm_fb_helper_prepare() before calling this function.
577 * Zero if everything went ok, nonzero otherwise.
579 int drm_fb_helper_init(struct drm_device *dev,
580 struct drm_fb_helper *fb_helper,
581 int crtc_count, int max_conn_count)
583 struct drm_crtc *crtc;
589 fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
590 if (!fb_helper->crtc_info)
593 fb_helper->crtc_count = crtc_count;
594 fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
595 if (!fb_helper->connector_info) {
596 kfree(fb_helper->crtc_info);
599 fb_helper->connector_count = 0;
601 for (i = 0; i < crtc_count; i++) {
602 fb_helper->crtc_info[i].mode_set.connectors =
603 kcalloc(max_conn_count,
604 sizeof(struct drm_connector *),
607 if (!fb_helper->crtc_info[i].mode_set.connectors)
609 fb_helper->crtc_info[i].mode_set.num_connectors = 0;
613 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
614 fb_helper->crtc_info[i].mode_set.crtc = crtc;
620 drm_fb_helper_crtc_free(fb_helper);
623 EXPORT_SYMBOL(drm_fb_helper_init);
625 void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
627 if (!list_empty(&fb_helper->kernel_fb_list)) {
628 list_del(&fb_helper->kernel_fb_list);
629 if (list_empty(&kernel_fb_helper_list)) {
630 pr_info("drm: unregistered panic notifier\n");
631 atomic_notifier_chain_unregister(&panic_notifier_list,
633 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
637 drm_fb_helper_crtc_free(fb_helper);
640 EXPORT_SYMBOL(drm_fb_helper_fini);
642 static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
643 u16 blue, u16 regno, struct fb_info *info)
645 struct drm_fb_helper *fb_helper = info->par;
646 struct drm_framebuffer *fb = fb_helper->fb;
649 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
652 /* place color in psuedopalette */
655 palette = (u32 *)info->pseudo_palette;
656 red >>= (16 - info->var.red.length);
657 green >>= (16 - info->var.green.length);
658 blue >>= (16 - info->var.blue.length);
659 value = (red << info->var.red.offset) |
660 (green << info->var.green.offset) |
661 (blue << info->var.blue.offset);
662 if (info->var.transp.length > 0) {
663 u32 mask = (1 << info->var.transp.length) - 1;
664 mask <<= info->var.transp.offset;
667 palette[regno] = value;
672 * The driver really shouldn't advertise pseudo/directcolor
673 * visuals if it can't deal with the palette.
675 if (WARN_ON(!fb_helper->funcs->gamma_set ||
676 !fb_helper->funcs->gamma_get))
681 if (fb->bits_per_pixel == 16) {
684 if (fb->depth == 16 && regno > 63)
686 if (fb->depth == 15 && regno > 31)
689 if (fb->depth == 16) {
693 for (i = 0; i < 8; i++)
694 fb_helper->funcs->gamma_set(crtc, red,
695 green, blue, pindex + i);
698 fb_helper->funcs->gamma_get(crtc, &r,
702 for (i = 0; i < 4; i++)
703 fb_helper->funcs->gamma_set(crtc, r,
710 fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
715 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
717 * @info: fbdev registered by the helper
719 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
721 struct drm_fb_helper *fb_helper = info->par;
722 struct drm_device *dev = fb_helper->dev;
723 struct drm_crtc_helper_funcs *crtc_funcs;
724 u16 *red, *green, *blue, *transp;
725 struct drm_crtc *crtc;
729 drm_modeset_lock_all(dev);
730 if (!drm_fb_helper_is_bound(fb_helper)) {
731 drm_modeset_unlock_all(dev);
735 for (i = 0; i < fb_helper->crtc_count; i++) {
736 crtc = fb_helper->crtc_info[i].mode_set.crtc;
737 crtc_funcs = crtc->helper_private;
742 transp = cmap->transp;
745 for (j = 0; j < cmap->len; j++) {
746 u16 hred, hgreen, hblue, htransp = 0xffff;
755 rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
759 if (crtc_funcs->load_lut)
760 crtc_funcs->load_lut(crtc);
763 drm_modeset_unlock_all(dev);
766 EXPORT_SYMBOL(drm_fb_helper_setcmap);
769 * drm_fb_helper_check_var - implementation for ->fb_check_var
770 * @var: screeninfo to check
771 * @info: fbdev registered by the helper
773 int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
774 struct fb_info *info)
776 struct drm_fb_helper *fb_helper = info->par;
777 struct drm_framebuffer *fb = fb_helper->fb;
780 if (var->pixclock != 0 || in_dbg_master())
783 /* Need to resize the fb object !!! */
784 if (var->bits_per_pixel > fb->bits_per_pixel ||
785 var->xres > fb->width || var->yres > fb->height ||
786 var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
787 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
788 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
789 var->xres, var->yres, var->bits_per_pixel,
790 var->xres_virtual, var->yres_virtual,
791 fb->width, fb->height, fb->bits_per_pixel);
795 switch (var->bits_per_pixel) {
797 depth = (var->green.length == 6) ? 16 : 15;
800 depth = (var->transp.length > 0) ? 32 : 24;
803 depth = var->bits_per_pixel;
810 var->green.offset = 0;
811 var->blue.offset = 0;
813 var->green.length = 8;
814 var->blue.length = 8;
815 var->transp.length = 0;
816 var->transp.offset = 0;
819 var->red.offset = 10;
820 var->green.offset = 5;
821 var->blue.offset = 0;
823 var->green.length = 5;
824 var->blue.length = 5;
825 var->transp.length = 1;
826 var->transp.offset = 15;
829 var->red.offset = 11;
830 var->green.offset = 5;
831 var->blue.offset = 0;
833 var->green.length = 6;
834 var->blue.length = 5;
835 var->transp.length = 0;
836 var->transp.offset = 0;
839 var->red.offset = 16;
840 var->green.offset = 8;
841 var->blue.offset = 0;
843 var->green.length = 8;
844 var->blue.length = 8;
845 var->transp.length = 0;
846 var->transp.offset = 0;
849 var->red.offset = 16;
850 var->green.offset = 8;
851 var->blue.offset = 0;
853 var->green.length = 8;
854 var->blue.length = 8;
855 var->transp.length = 8;
856 var->transp.offset = 24;
863 EXPORT_SYMBOL(drm_fb_helper_check_var);
866 * drm_fb_helper_set_par - implementation for ->fb_set_par
867 * @info: fbdev registered by the helper
869 * This will let fbcon do the mode init and is called at initialization time by
870 * the fbdev core when registering the driver, and later on through the hotplug
873 int drm_fb_helper_set_par(struct fb_info *info)
875 struct drm_fb_helper *fb_helper = info->par;
876 struct fb_var_screeninfo *var = &info->var;
878 if (var->pixclock != 0) {
879 DRM_ERROR("PIXEL CLOCK SET\n");
883 drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
885 if (fb_helper->delayed_hotplug) {
886 fb_helper->delayed_hotplug = false;
887 drm_fb_helper_hotplug_event(fb_helper);
891 EXPORT_SYMBOL(drm_fb_helper_set_par);
894 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
895 * @var: updated screen information
896 * @info: fbdev registered by the helper
898 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
899 struct fb_info *info)
901 struct drm_fb_helper *fb_helper = info->par;
902 struct drm_device *dev = fb_helper->dev;
903 struct drm_mode_set *modeset;
907 drm_modeset_lock_all(dev);
908 if (!drm_fb_helper_is_bound(fb_helper)) {
909 drm_modeset_unlock_all(dev);
913 for (i = 0; i < fb_helper->crtc_count; i++) {
914 modeset = &fb_helper->crtc_info[i].mode_set;
916 modeset->x = var->xoffset;
917 modeset->y = var->yoffset;
919 if (modeset->num_connectors) {
920 ret = drm_mode_set_config_internal(modeset);
922 info->var.xoffset = var->xoffset;
923 info->var.yoffset = var->yoffset;
927 drm_modeset_unlock_all(dev);
930 EXPORT_SYMBOL(drm_fb_helper_pan_display);
933 * Allocates the backing storage and sets up the fbdev info structure through
934 * the ->fb_probe callback and then registers the fbdev and sets up the panic
937 static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
943 struct fb_info *info;
944 struct drm_fb_helper_surface_size sizes;
947 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
948 sizes.surface_depth = 24;
949 sizes.surface_bpp = 32;
950 sizes.fb_width = (unsigned)-1;
951 sizes.fb_height = (unsigned)-1;
953 /* if driver picks 8 or 16 by default use that
954 for both depth/bpp */
955 if (preferred_bpp != sizes.surface_bpp)
956 sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
958 /* first up get a count of crtcs now in use and new min/maxes width/heights */
959 for (i = 0; i < fb_helper->connector_count; i++) {
960 struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
961 struct drm_cmdline_mode *cmdline_mode;
963 cmdline_mode = &fb_helper_conn->cmdline_mode;
965 if (cmdline_mode->bpp_specified) {
966 switch (cmdline_mode->bpp) {
968 sizes.surface_depth = sizes.surface_bpp = 8;
971 sizes.surface_depth = 15;
972 sizes.surface_bpp = 16;
975 sizes.surface_depth = sizes.surface_bpp = 16;
978 sizes.surface_depth = sizes.surface_bpp = 24;
981 sizes.surface_depth = 24;
982 sizes.surface_bpp = 32;
990 for (i = 0; i < fb_helper->crtc_count; i++) {
991 struct drm_display_mode *desired_mode;
992 desired_mode = fb_helper->crtc_info[i].desired_mode;
996 gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
997 if (desired_mode->hdisplay < sizes.fb_width)
998 sizes.fb_width = desired_mode->hdisplay;
999 if (desired_mode->vdisplay < sizes.fb_height)
1000 sizes.fb_height = desired_mode->vdisplay;
1001 if (desired_mode->hdisplay > sizes.surface_width)
1002 sizes.surface_width = desired_mode->hdisplay;
1003 if (desired_mode->vdisplay > sizes.surface_height)
1004 sizes.surface_height = desired_mode->vdisplay;
1009 if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
1010 /* hmm everyone went away - assume VGA cable just fell out
1011 and will come back later. */
1012 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
1013 sizes.fb_width = sizes.surface_width = 1024;
1014 sizes.fb_height = sizes.surface_height = 768;
1017 /* push down into drivers */
1018 ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
1022 info = fb_helper->fbdev;
1025 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
1026 * events, but at init time drm_setup_crtcs needs to be called before
1027 * the fb is allocated (since we need to figure out the desired size of
1028 * the fb before we can allocate it ...). Hence we need to fix things up
1031 for (i = 0; i < fb_helper->crtc_count; i++)
1032 if (fb_helper->crtc_info[i].mode_set.num_connectors)
1033 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
1036 info->var.pixclock = 0;
1037 if (register_framebuffer(info) < 0)
1040 dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n",
1041 info->node, info->fix.id);
1043 /* Switch back to kernel console on panic */
1044 /* multi card linked list maybe */
1045 if (list_empty(&kernel_fb_helper_list)) {
1046 dev_info(fb_helper->dev->dev, "registered panic notifier\n");
1047 atomic_notifier_chain_register(&panic_notifier_list,
1049 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
1052 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
1058 * drm_fb_helper_fill_fix - initializes fixed fbdev information
1059 * @info: fbdev registered by the helper
1060 * @pitch: desired pitch
1061 * @depth: desired depth
1063 * Helper to fill in the fixed fbdev information useful for a non-accelerated
1064 * fbdev emulations. Drivers which support acceleration methods which impose
1065 * additional constraints need to set up their own limits.
1067 * Drivers should call this (or their equivalent setup code) from their
1068 * ->fb_probe callback.
1070 void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
1073 info->fix.type = FB_TYPE_PACKED_PIXELS;
1074 info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
1075 FB_VISUAL_TRUECOLOR;
1076 info->fix.mmio_start = 0;
1077 info->fix.mmio_len = 0;
1078 info->fix.type_aux = 0;
1079 info->fix.xpanstep = 1; /* doing it in hw */
1080 info->fix.ypanstep = 1; /* doing it in hw */
1081 info->fix.ywrapstep = 0;
1082 info->fix.accel = FB_ACCEL_NONE;
1084 info->fix.line_length = pitch;
1087 EXPORT_SYMBOL(drm_fb_helper_fill_fix);
1090 * drm_fb_helper_fill_var - initalizes variable fbdev information
1091 * @info: fbdev instance to set up
1092 * @fb_helper: fb helper instance to use as template
1093 * @fb_width: desired fb width
1094 * @fb_height: desired fb height
1096 * Sets up the variable fbdev metainformation from the given fb helper instance
1097 * and the drm framebuffer allocated in fb_helper->fb.
1099 * Drivers should call this (or their equivalent setup code) from their
1100 * ->fb_probe callback after having allocated the fbdev backing
1101 * storage framebuffer.
1103 void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
1104 uint32_t fb_width, uint32_t fb_height)
1106 struct drm_framebuffer *fb = fb_helper->fb;
1107 info->pseudo_palette = fb_helper->pseudo_palette;
1108 info->var.xres_virtual = fb->width;
1109 info->var.yres_virtual = fb->height;
1110 info->var.bits_per_pixel = fb->bits_per_pixel;
1111 info->var.accel_flags = FB_ACCELF_TEXT;
1112 info->var.xoffset = 0;
1113 info->var.yoffset = 0;
1114 info->var.activate = FB_ACTIVATE_NOW;
1115 info->var.height = -1;
1116 info->var.width = -1;
1118 switch (fb->depth) {
1120 info->var.red.offset = 0;
1121 info->var.green.offset = 0;
1122 info->var.blue.offset = 0;
1123 info->var.red.length = 8; /* 8bit DAC */
1124 info->var.green.length = 8;
1125 info->var.blue.length = 8;
1126 info->var.transp.offset = 0;
1127 info->var.transp.length = 0;
1130 info->var.red.offset = 10;
1131 info->var.green.offset = 5;
1132 info->var.blue.offset = 0;
1133 info->var.red.length = 5;
1134 info->var.green.length = 5;
1135 info->var.blue.length = 5;
1136 info->var.transp.offset = 15;
1137 info->var.transp.length = 1;
1140 info->var.red.offset = 11;
1141 info->var.green.offset = 5;
1142 info->var.blue.offset = 0;
1143 info->var.red.length = 5;
1144 info->var.green.length = 6;
1145 info->var.blue.length = 5;
1146 info->var.transp.offset = 0;
1149 info->var.red.offset = 16;
1150 info->var.green.offset = 8;
1151 info->var.blue.offset = 0;
1152 info->var.red.length = 8;
1153 info->var.green.length = 8;
1154 info->var.blue.length = 8;
1155 info->var.transp.offset = 0;
1156 info->var.transp.length = 0;
1159 info->var.red.offset = 16;
1160 info->var.green.offset = 8;
1161 info->var.blue.offset = 0;
1162 info->var.red.length = 8;
1163 info->var.green.length = 8;
1164 info->var.blue.length = 8;
1165 info->var.transp.offset = 24;
1166 info->var.transp.length = 8;
1172 info->var.xres = fb_width;
1173 info->var.yres = fb_height;
1175 EXPORT_SYMBOL(drm_fb_helper_fill_var);
1177 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
1181 struct drm_connector *connector;
1185 for (i = 0; i < fb_helper->connector_count; i++) {
1186 connector = fb_helper->connector_info[i]->connector;
1187 count += connector->funcs->fill_modes(connector, maxX, maxY);
1193 struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
1195 struct drm_display_mode *mode;
1197 list_for_each_entry(mode, &fb_connector->connector->modes, head) {
1198 if (mode->hdisplay > width ||
1199 mode->vdisplay > height)
1201 if (mode->type & DRM_MODE_TYPE_PREFERRED)
1206 EXPORT_SYMBOL(drm_has_preferred_mode);
1208 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
1210 struct drm_cmdline_mode *cmdline_mode;
1211 cmdline_mode = &fb_connector->cmdline_mode;
1212 return cmdline_mode->specified;
1215 struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
1216 int width, int height)
1218 struct drm_cmdline_mode *cmdline_mode;
1219 struct drm_display_mode *mode = NULL;
1220 bool prefer_non_interlace;
1222 cmdline_mode = &fb_helper_conn->cmdline_mode;
1223 if (cmdline_mode->specified == false)
1226 /* attempt to find a matching mode in the list of modes
1227 * we have gotten so far, if not add a CVT mode that conforms
1229 if (cmdline_mode->rb || cmdline_mode->margins)
1232 prefer_non_interlace = !cmdline_mode->interlace;
1234 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1235 /* check width/height */
1236 if (mode->hdisplay != cmdline_mode->xres ||
1237 mode->vdisplay != cmdline_mode->yres)
1240 if (cmdline_mode->refresh_specified) {
1241 if (mode->vrefresh != cmdline_mode->refresh)
1245 if (cmdline_mode->interlace) {
1246 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
1248 } else if (prefer_non_interlace) {
1249 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1255 if (prefer_non_interlace) {
1256 prefer_non_interlace = false;
1261 mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
1263 list_add(&mode->head, &fb_helper_conn->connector->modes);
1266 EXPORT_SYMBOL(drm_pick_cmdline_mode);
1268 static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
1273 enable = connector->status == connector_status_connected;
1275 enable = connector->status != connector_status_disconnected;
1280 static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
1283 bool any_enabled = false;
1284 struct drm_connector *connector;
1287 for (i = 0; i < fb_helper->connector_count; i++) {
1288 connector = fb_helper->connector_info[i]->connector;
1289 enabled[i] = drm_connector_enabled(connector, true);
1290 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
1291 enabled[i] ? "yes" : "no");
1292 any_enabled |= enabled[i];
1298 for (i = 0; i < fb_helper->connector_count; i++) {
1299 connector = fb_helper->connector_info[i]->connector;
1300 enabled[i] = drm_connector_enabled(connector, false);
1304 static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
1305 struct drm_display_mode **modes,
1306 bool *enabled, int width, int height)
1309 bool can_clone = false;
1310 struct drm_fb_helper_connector *fb_helper_conn;
1311 struct drm_display_mode *dmt_mode, *mode;
1313 /* only contemplate cloning in the single crtc case */
1314 if (fb_helper->crtc_count > 1)
1318 for (i = 0; i < fb_helper->connector_count; i++) {
1323 /* only contemplate cloning if more than one connector is enabled */
1327 /* check the command line or if nothing common pick 1024x768 */
1329 for (i = 0; i < fb_helper->connector_count; i++) {
1332 fb_helper_conn = fb_helper->connector_info[i];
1333 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1338 for (j = 0; j < i; j++) {
1341 if (!drm_mode_equal(modes[j], modes[i]))
1347 DRM_DEBUG_KMS("can clone using command line\n");
1351 /* try and find a 1024x768 mode on each connector */
1353 dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false);
1355 for (i = 0; i < fb_helper->connector_count; i++) {
1360 fb_helper_conn = fb_helper->connector_info[i];
1361 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1362 if (drm_mode_equal(mode, dmt_mode))
1370 DRM_DEBUG_KMS("can clone using 1024x768\n");
1373 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1377 static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
1378 struct drm_display_mode **modes,
1379 bool *enabled, int width, int height)
1381 struct drm_fb_helper_connector *fb_helper_conn;
1384 for (i = 0; i < fb_helper->connector_count; i++) {
1385 fb_helper_conn = fb_helper->connector_info[i];
1387 if (enabled[i] == false)
1390 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1391 fb_helper_conn->connector->base.id);
1393 /* got for command line mode first */
1394 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1396 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
1397 fb_helper_conn->connector->base.id);
1398 modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
1400 /* No preferred modes, pick one off the list */
1401 if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
1402 list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
1405 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
1411 static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
1412 struct drm_fb_helper_crtc **best_crtcs,
1413 struct drm_display_mode **modes,
1414 int n, int width, int height)
1417 struct drm_device *dev = fb_helper->dev;
1418 struct drm_connector *connector;
1419 struct drm_connector_helper_funcs *connector_funcs;
1420 struct drm_encoder *encoder;
1421 int my_score, best_score, score;
1422 struct drm_fb_helper_crtc **crtcs, *crtc;
1423 struct drm_fb_helper_connector *fb_helper_conn;
1425 if (n == fb_helper->connector_count)
1428 fb_helper_conn = fb_helper->connector_info[n];
1429 connector = fb_helper_conn->connector;
1431 best_crtcs[n] = NULL;
1432 best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
1433 if (modes[n] == NULL)
1436 crtcs = kzalloc(dev->mode_config.num_connector *
1437 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1442 if (connector->status == connector_status_connected)
1444 if (drm_has_cmdline_mode(fb_helper_conn))
1446 if (drm_has_preferred_mode(fb_helper_conn, width, height))
1449 connector_funcs = connector->helper_private;
1450 encoder = connector_funcs->best_encoder(connector);
1454 /* select a crtc for this connector and then attempt to configure
1455 remaining connectors */
1456 for (c = 0; c < fb_helper->crtc_count; c++) {
1457 crtc = &fb_helper->crtc_info[c];
1459 if ((encoder->possible_crtcs & (1 << c)) == 0)
1462 for (o = 0; o < n; o++)
1463 if (best_crtcs[o] == crtc)
1467 /* ignore cloning unless only a single crtc */
1468 if (fb_helper->crtc_count > 1)
1471 if (!drm_mode_equal(modes[o], modes[n]))
1476 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1477 score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
1479 if (score > best_score) {
1481 memcpy(best_crtcs, crtcs,
1482 dev->mode_config.num_connector *
1483 sizeof(struct drm_fb_helper_crtc *));
1491 static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
1493 struct drm_device *dev = fb_helper->dev;
1494 struct drm_fb_helper_crtc **crtcs;
1495 struct drm_display_mode **modes;
1496 struct drm_mode_set *modeset;
1501 DRM_DEBUG_KMS("\n");
1503 width = dev->mode_config.max_width;
1504 height = dev->mode_config.max_height;
1506 crtcs = kcalloc(dev->mode_config.num_connector,
1507 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1508 modes = kcalloc(dev->mode_config.num_connector,
1509 sizeof(struct drm_display_mode *), GFP_KERNEL);
1510 enabled = kcalloc(dev->mode_config.num_connector,
1511 sizeof(bool), GFP_KERNEL);
1512 if (!crtcs || !modes || !enabled) {
1513 DRM_ERROR("Memory allocation failed\n");
1518 drm_enable_connectors(fb_helper, enabled);
1520 if (!(fb_helper->funcs->initial_config &&
1521 fb_helper->funcs->initial_config(fb_helper, crtcs, modes,
1522 enabled, width, height))) {
1523 memset(modes, 0, dev->mode_config.num_connector*sizeof(modes[0]));
1524 memset(crtcs, 0, dev->mode_config.num_connector*sizeof(crtcs[0]));
1526 if (!drm_target_cloned(fb_helper,
1527 modes, enabled, width, height) &&
1528 !drm_target_preferred(fb_helper,
1529 modes, enabled, width, height))
1530 DRM_ERROR("Unable to find initial modes\n");
1532 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
1535 drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1538 /* need to set the modesets up here for use later */
1539 /* fill out the connector<->crtc mappings into the modesets */
1540 for (i = 0; i < fb_helper->crtc_count; i++) {
1541 modeset = &fb_helper->crtc_info[i].mode_set;
1542 modeset->num_connectors = 0;
1546 for (i = 0; i < fb_helper->connector_count; i++) {
1547 struct drm_display_mode *mode = modes[i];
1548 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1549 modeset = &fb_crtc->mode_set;
1551 if (mode && fb_crtc) {
1552 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
1553 mode->name, fb_crtc->mode_set.crtc->base.id);
1554 fb_crtc->desired_mode = mode;
1556 drm_mode_destroy(dev, modeset->mode);
1557 modeset->mode = drm_mode_duplicate(dev,
1558 fb_crtc->desired_mode);
1559 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
1560 modeset->fb = fb_helper->fb;
1564 /* Clear out any old modes if there are no more connected outputs. */
1565 for (i = 0; i < fb_helper->crtc_count; i++) {
1566 modeset = &fb_helper->crtc_info[i].mode_set;
1567 if (modeset->num_connectors == 0) {
1568 BUG_ON(modeset->fb);
1569 BUG_ON(modeset->num_connectors);
1571 drm_mode_destroy(dev, modeset->mode);
1572 modeset->mode = NULL;
1582 * drm_fb_helper_initial_config - setup a sane initial connector configuration
1583 * @fb_helper: fb_helper device struct
1584 * @bpp_sel: bpp value to use for the framebuffer configuration
1586 * Scans the CRTCs and connectors and tries to put together an initial setup.
1587 * At the moment, this is a cloned configuration across all heads with
1588 * a new framebuffer object as the backing store.
1590 * Note that this also registers the fbdev and so allows userspace to call into
1591 * the driver through the fbdev interfaces.
1593 * This function will call down into the ->fb_probe callback to let
1594 * the driver allocate and initialize the fbdev info structure and the drm
1595 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
1596 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
1597 * values for the fbdev info structure.
1600 * Zero if everything went ok, nonzero otherwise.
1602 bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
1604 struct drm_device *dev = fb_helper->dev;
1607 drm_fb_helper_parse_command_line(fb_helper);
1609 mutex_lock(&dev->mode_config.mutex);
1610 count = drm_fb_helper_probe_connector_modes(fb_helper,
1611 dev->mode_config.max_width,
1612 dev->mode_config.max_height);
1613 mutex_unlock(&dev->mode_config.mutex);
1615 * we shouldn't end up with no modes here.
1618 dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
1620 drm_setup_crtcs(fb_helper);
1622 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
1624 EXPORT_SYMBOL(drm_fb_helper_initial_config);
1627 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
1628 * probing all the outputs attached to the fb
1629 * @fb_helper: the drm_fb_helper
1631 * Scan the connectors attached to the fb_helper and try to put together a
1632 * setup after *notification of a change in output configuration.
1634 * Called at runtime, takes the mode config locks to be able to check/change the
1635 * modeset configuration. Must be run from process context (which usually means
1636 * either the output polling work or a work item launched from the driver's
1637 * hotplug interrupt).
1639 * Note that drivers may call this even before calling
1640 * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows
1641 * for a race-free fbcon setup and will make sure that the fbdev emulation will
1642 * not miss any hotplug events.
1645 * 0 on success and a non-zero error code otherwise.
1647 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
1649 struct drm_device *dev = fb_helper->dev;
1650 u32 max_width, max_height;
1652 mutex_lock(&fb_helper->dev->mode_config.mutex);
1653 if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) {
1654 fb_helper->delayed_hotplug = true;
1655 mutex_unlock(&fb_helper->dev->mode_config.mutex);
1658 DRM_DEBUG_KMS("\n");
1660 max_width = fb_helper->fb->width;
1661 max_height = fb_helper->fb->height;
1663 drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height);
1664 mutex_unlock(&fb_helper->dev->mode_config.mutex);
1666 drm_modeset_lock_all(dev);
1667 drm_setup_crtcs(fb_helper);
1668 drm_modeset_unlock_all(dev);
1669 drm_fb_helper_set_par(fb_helper->fbdev);
1673 EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
1675 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
1676 * but the module doesn't depend on any fb console symbols. At least
1677 * attempt to load fbcon to avoid leaving the system without a usable console.
1679 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
1680 static int __init drm_fb_helper_modinit(void)
1682 const char *name = "fbcon";
1683 struct module *fbcon;
1685 mutex_lock(&module_mutex);
1686 fbcon = find_module(name);
1687 mutex_unlock(&module_mutex);
1690 request_module_nowait(name);
1694 module_init(drm_fb_helper_modinit);