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 MODULE_AUTHOR("David Airlie, Jesse Barnes");
43 MODULE_DESCRIPTION("DRM KMS helper");
44 MODULE_LICENSE("GPL and additional rights");
46 static LIST_HEAD(kernel_fb_helper_list
);
51 * The fb helper functions are useful to provide an fbdev on top of a drm kernel
52 * mode setting driver. They can be used mostly independantely from the crtc
53 * helper functions used by many drivers to implement the kernel mode setting
56 * Initialization is done as a three-step process with drm_fb_helper_init(),
57 * drm_fb_helper_single_add_all_connectors() and drm_fb_helper_initial_config().
58 * Drivers with fancier requirements than the default beheviour can override the
59 * second step with their own code. Teardown is done with drm_fb_helper_fini().
61 * At runtime drivers should restore the fbdev console by calling
62 * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
63 * should also notify the fb helper code from updates to the output
64 * configuration by calling drm_fb_helper_hotplug_event(). For easier
65 * integration with the output polling code in drm_crtc_helper.c the modeset
66 * code proves a ->output_poll_changed callback.
68 * All other functions exported by the fb helper library can be used to
69 * implement the fbdev driver interface by the driver.
73 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
75 * @fb_helper: fbdev initialized with drm_fb_helper_init
77 * This functions adds all the available connectors for use with the given
78 * fb_helper. This is a separate step to allow drivers to freely assign
79 * connectors to the fbdev, e.g. if some are reserved for special purposes or
80 * not adequate to be used for the fbcon.
82 * Since this is part of the initial setup before the fbdev is published, no
83 * locking is required.
85 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper
*fb_helper
)
87 struct drm_device
*dev
= fb_helper
->dev
;
88 struct drm_connector
*connector
;
91 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
92 struct drm_fb_helper_connector
*fb_helper_connector
;
94 fb_helper_connector
= kzalloc(sizeof(struct drm_fb_helper_connector
), GFP_KERNEL
);
95 if (!fb_helper_connector
)
98 fb_helper_connector
->connector
= connector
;
99 fb_helper
->connector_info
[fb_helper
->connector_count
++] = fb_helper_connector
;
103 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
104 kfree(fb_helper
->connector_info
[i
]);
105 fb_helper
->connector_info
[i
] = NULL
;
107 fb_helper
->connector_count
= 0;
110 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors
);
112 static int drm_fb_helper_parse_command_line(struct drm_fb_helper
*fb_helper
)
114 struct drm_fb_helper_connector
*fb_helper_conn
;
117 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
118 struct drm_cmdline_mode
*mode
;
119 struct drm_connector
*connector
;
122 fb_helper_conn
= fb_helper
->connector_info
[i
];
123 connector
= fb_helper_conn
->connector
;
124 mode
= &fb_helper_conn
->cmdline_mode
;
126 /* do something on return - turn off connector maybe */
127 if (fb_get_options(drm_get_connector_name(connector
), &option
))
130 if (drm_mode_parse_command_line_for_connector(option
,
135 switch (mode
->force
) {
139 case DRM_FORCE_ON_DIGITAL
:
148 DRM_INFO("forcing %s connector %s\n",
149 drm_get_connector_name(connector
), s
);
150 connector
->force
= mode
->force
;
153 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
154 drm_get_connector_name(connector
),
155 mode
->xres
, mode
->yres
,
156 mode
->refresh_specified
? mode
->refresh
: 60,
157 mode
->rb
? " reduced blanking" : "",
158 mode
->margins
? " with margins" : "",
159 mode
->interlace
? " interlaced" : "");
166 static void drm_fb_helper_save_lut_atomic(struct drm_crtc
*crtc
, struct drm_fb_helper
*helper
)
168 uint16_t *r_base
, *g_base
, *b_base
;
171 r_base
= crtc
->gamma_store
;
172 g_base
= r_base
+ crtc
->gamma_size
;
173 b_base
= g_base
+ crtc
->gamma_size
;
175 for (i
= 0; i
< crtc
->gamma_size
; i
++)
176 helper
->funcs
->gamma_get(crtc
, &r_base
[i
], &g_base
[i
], &b_base
[i
], i
);
179 static void drm_fb_helper_restore_lut_atomic(struct drm_crtc
*crtc
)
181 uint16_t *r_base
, *g_base
, *b_base
;
183 if (crtc
->funcs
->gamma_set
== NULL
)
186 r_base
= crtc
->gamma_store
;
187 g_base
= r_base
+ crtc
->gamma_size
;
188 b_base
= g_base
+ crtc
->gamma_size
;
190 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
194 * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter
195 * @info: fbdev registered by the helper
197 int drm_fb_helper_debug_enter(struct fb_info
*info
)
199 struct drm_fb_helper
*helper
= info
->par
;
200 struct drm_crtc_helper_funcs
*funcs
;
203 if (list_empty(&kernel_fb_helper_list
))
206 list_for_each_entry(helper
, &kernel_fb_helper_list
, kernel_fb_list
) {
207 for (i
= 0; i
< helper
->crtc_count
; i
++) {
208 struct drm_mode_set
*mode_set
=
209 &helper
->crtc_info
[i
].mode_set
;
211 if (!mode_set
->crtc
->enabled
)
214 funcs
= mode_set
->crtc
->helper_private
;
215 drm_fb_helper_save_lut_atomic(mode_set
->crtc
, helper
);
216 funcs
->mode_set_base_atomic(mode_set
->crtc
,
220 ENTER_ATOMIC_MODE_SET
);
226 EXPORT_SYMBOL(drm_fb_helper_debug_enter
);
228 /* Find the real fb for a given fb helper CRTC */
229 static struct drm_framebuffer
*drm_mode_config_fb(struct drm_crtc
*crtc
)
231 struct drm_device
*dev
= crtc
->dev
;
234 list_for_each_entry(c
, &dev
->mode_config
.crtc_list
, head
) {
235 if (crtc
->base
.id
== c
->base
.id
)
243 * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
244 * @info: fbdev registered by the helper
246 int drm_fb_helper_debug_leave(struct fb_info
*info
)
248 struct drm_fb_helper
*helper
= info
->par
;
249 struct drm_crtc
*crtc
;
250 struct drm_crtc_helper_funcs
*funcs
;
251 struct drm_framebuffer
*fb
;
254 for (i
= 0; i
< helper
->crtc_count
; i
++) {
255 struct drm_mode_set
*mode_set
= &helper
->crtc_info
[i
].mode_set
;
256 crtc
= mode_set
->crtc
;
257 funcs
= crtc
->helper_private
;
258 fb
= drm_mode_config_fb(crtc
);
264 DRM_ERROR("no fb to restore??\n");
268 drm_fb_helper_restore_lut_atomic(mode_set
->crtc
);
269 funcs
->mode_set_base_atomic(mode_set
->crtc
, fb
, crtc
->x
,
270 crtc
->y
, LEAVE_ATOMIC_MODE_SET
);
275 EXPORT_SYMBOL(drm_fb_helper_debug_leave
);
278 * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
279 * @fb_helper: fbcon to restore
281 * This should be called from driver's drm ->lastclose callback
282 * when implementing an fbcon on top of kms using this helper. This ensures that
283 * the user isn't greeted with a black screen when e.g. X dies.
285 bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper
*fb_helper
)
290 drm_warn_on_modeset_not_all_locked(fb_helper
->dev
);
292 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
293 struct drm_mode_set
*mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
294 ret
= drm_mode_set_config_internal(mode_set
);
300 EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode
);
303 * restore fbcon display for all kms driver's using this helper, used for sysrq
304 * and panic handling.
306 static bool drm_fb_helper_force_kernel_mode(void)
308 bool ret
, error
= false;
309 struct drm_fb_helper
*helper
;
311 if (list_empty(&kernel_fb_helper_list
))
314 list_for_each_entry(helper
, &kernel_fb_helper_list
, kernel_fb_list
) {
315 if (helper
->dev
->switch_power_state
== DRM_SWITCH_POWER_OFF
)
318 ret
= drm_fb_helper_restore_fbdev_mode(helper
);
325 static int drm_fb_helper_panic(struct notifier_block
*n
, unsigned long ununsed
,
329 * It's a waste of time and effort to switch back to text console
330 * if the kernel should reboot before panic messages can be seen.
332 if (panic_timeout
< 0)
335 pr_err("panic occurred, switching back to text console\n");
336 return drm_fb_helper_force_kernel_mode();
339 static struct notifier_block paniced
= {
340 .notifier_call
= drm_fb_helper_panic
,
343 static bool drm_fb_helper_is_bound(struct drm_fb_helper
*fb_helper
)
345 struct drm_device
*dev
= fb_helper
->dev
;
346 struct drm_crtc
*crtc
;
347 int bound
= 0, crtcs_bound
= 0;
349 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
352 if (crtc
->fb
== fb_helper
->fb
)
356 if (bound
< crtcs_bound
)
361 #ifdef CONFIG_MAGIC_SYSRQ
362 static void drm_fb_helper_restore_work_fn(struct work_struct
*ignored
)
365 ret
= drm_fb_helper_force_kernel_mode();
367 DRM_ERROR("Failed to restore crtc configuration\n");
369 static DECLARE_WORK(drm_fb_helper_restore_work
, drm_fb_helper_restore_work_fn
);
371 static void drm_fb_helper_sysrq(int dummy1
)
373 schedule_work(&drm_fb_helper_restore_work
);
376 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op
= {
377 .handler
= drm_fb_helper_sysrq
,
378 .help_msg
= "force-fb(V)",
379 .action_msg
= "Restore framebuffer console",
382 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op
= { };
385 static void drm_fb_helper_dpms(struct fb_info
*info
, int dpms_mode
)
387 struct drm_fb_helper
*fb_helper
= info
->par
;
388 struct drm_device
*dev
= fb_helper
->dev
;
389 struct drm_crtc
*crtc
;
390 struct drm_connector
*connector
;
394 * For each CRTC in this fb, turn the connectors on/off.
396 drm_modeset_lock_all(dev
);
397 if (!drm_fb_helper_is_bound(fb_helper
)) {
398 drm_modeset_unlock_all(dev
);
402 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
403 crtc
= fb_helper
->crtc_info
[i
].mode_set
.crtc
;
408 /* Walk the connectors & encoders on this fb turning them on/off */
409 for (j
= 0; j
< fb_helper
->connector_count
; j
++) {
410 connector
= fb_helper
->connector_info
[j
]->connector
;
411 connector
->funcs
->dpms(connector
, dpms_mode
);
412 drm_object_property_set_value(&connector
->base
,
413 dev
->mode_config
.dpms_property
, dpms_mode
);
416 drm_modeset_unlock_all(dev
);
420 * drm_fb_helper_blank - implementation for ->fb_blank
421 * @blank: desired blanking state
422 * @info: fbdev registered by the helper
424 int drm_fb_helper_blank(int blank
, struct fb_info
*info
)
427 /* Display: On; HSync: On, VSync: On */
428 case FB_BLANK_UNBLANK
:
429 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_ON
);
431 /* Display: Off; HSync: On, VSync: On */
432 case FB_BLANK_NORMAL
:
433 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_STANDBY
);
435 /* Display: Off; HSync: Off, VSync: On */
436 case FB_BLANK_HSYNC_SUSPEND
:
437 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_STANDBY
);
439 /* Display: Off; HSync: On, VSync: Off */
440 case FB_BLANK_VSYNC_SUSPEND
:
441 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_SUSPEND
);
443 /* Display: Off; HSync: Off, VSync: Off */
444 case FB_BLANK_POWERDOWN
:
445 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_OFF
);
450 EXPORT_SYMBOL(drm_fb_helper_blank
);
452 static void drm_fb_helper_crtc_free(struct drm_fb_helper
*helper
)
456 for (i
= 0; i
< helper
->connector_count
; i
++)
457 kfree(helper
->connector_info
[i
]);
458 kfree(helper
->connector_info
);
459 for (i
= 0; i
< helper
->crtc_count
; i
++) {
460 kfree(helper
->crtc_info
[i
].mode_set
.connectors
);
461 if (helper
->crtc_info
[i
].mode_set
.mode
)
462 drm_mode_destroy(helper
->dev
, helper
->crtc_info
[i
].mode_set
.mode
);
464 kfree(helper
->crtc_info
);
468 * drm_fb_helper_init - initialize a drm_fb_helper structure
470 * @fb_helper: driver-allocated fbdev helper structure to initialize
471 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
472 * @max_conn_count: max connector count
474 * This allocates the structures for the fbdev helper with the given limits.
475 * Note that this won't yet touch the hardware (through the driver interfaces)
476 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
477 * to allow driver writes more control over the exact init sequence.
479 * Drivers must set fb_helper->funcs before calling
480 * drm_fb_helper_initial_config().
483 * Zero if everything went ok, nonzero otherwise.
485 int drm_fb_helper_init(struct drm_device
*dev
,
486 struct drm_fb_helper
*fb_helper
,
487 int crtc_count
, int max_conn_count
)
489 struct drm_crtc
*crtc
;
492 fb_helper
->dev
= dev
;
494 INIT_LIST_HEAD(&fb_helper
->kernel_fb_list
);
496 fb_helper
->crtc_info
= kcalloc(crtc_count
, sizeof(struct drm_fb_helper_crtc
), GFP_KERNEL
);
497 if (!fb_helper
->crtc_info
)
500 fb_helper
->crtc_count
= crtc_count
;
501 fb_helper
->connector_info
= kcalloc(dev
->mode_config
.num_connector
, sizeof(struct drm_fb_helper_connector
*), GFP_KERNEL
);
502 if (!fb_helper
->connector_info
) {
503 kfree(fb_helper
->crtc_info
);
506 fb_helper
->connector_count
= 0;
508 for (i
= 0; i
< crtc_count
; i
++) {
509 fb_helper
->crtc_info
[i
].mode_set
.connectors
=
510 kcalloc(max_conn_count
,
511 sizeof(struct drm_connector
*),
514 if (!fb_helper
->crtc_info
[i
].mode_set
.connectors
)
516 fb_helper
->crtc_info
[i
].mode_set
.num_connectors
= 0;
520 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
521 fb_helper
->crtc_info
[i
].mode_set
.crtc
= crtc
;
527 drm_fb_helper_crtc_free(fb_helper
);
530 EXPORT_SYMBOL(drm_fb_helper_init
);
532 void drm_fb_helper_fini(struct drm_fb_helper
*fb_helper
)
534 if (!list_empty(&fb_helper
->kernel_fb_list
)) {
535 list_del(&fb_helper
->kernel_fb_list
);
536 if (list_empty(&kernel_fb_helper_list
)) {
537 pr_info("drm: unregistered panic notifier\n");
538 atomic_notifier_chain_unregister(&panic_notifier_list
,
540 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
544 drm_fb_helper_crtc_free(fb_helper
);
547 EXPORT_SYMBOL(drm_fb_helper_fini
);
549 static int setcolreg(struct drm_crtc
*crtc
, u16 red
, u16 green
,
550 u16 blue
, u16 regno
, struct fb_info
*info
)
552 struct drm_fb_helper
*fb_helper
= info
->par
;
553 struct drm_framebuffer
*fb
= fb_helper
->fb
;
556 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
559 /* place color in psuedopalette */
562 palette
= (u32
*)info
->pseudo_palette
;
563 red
>>= (16 - info
->var
.red
.length
);
564 green
>>= (16 - info
->var
.green
.length
);
565 blue
>>= (16 - info
->var
.blue
.length
);
566 value
= (red
<< info
->var
.red
.offset
) |
567 (green
<< info
->var
.green
.offset
) |
568 (blue
<< info
->var
.blue
.offset
);
569 if (info
->var
.transp
.length
> 0) {
570 u32 mask
= (1 << info
->var
.transp
.length
) - 1;
571 mask
<<= info
->var
.transp
.offset
;
574 palette
[regno
] = value
;
580 if (fb
->bits_per_pixel
== 16) {
583 if (fb
->depth
== 16 && regno
> 63)
585 if (fb
->depth
== 15 && regno
> 31)
588 if (fb
->depth
== 16) {
592 for (i
= 0; i
< 8; i
++)
593 fb_helper
->funcs
->gamma_set(crtc
, red
,
594 green
, blue
, pindex
+ i
);
597 fb_helper
->funcs
->gamma_get(crtc
, &r
,
601 for (i
= 0; i
< 4; i
++)
602 fb_helper
->funcs
->gamma_set(crtc
, r
,
609 fb_helper
->funcs
->gamma_set(crtc
, red
, green
, blue
, pindex
);
614 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
616 * @info: fbdev registered by the helper
618 int drm_fb_helper_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
620 struct drm_fb_helper
*fb_helper
= info
->par
;
621 struct drm_crtc_helper_funcs
*crtc_funcs
;
622 u16
*red
, *green
, *blue
, *transp
;
623 struct drm_crtc
*crtc
;
627 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
628 crtc
= fb_helper
->crtc_info
[i
].mode_set
.crtc
;
629 crtc_funcs
= crtc
->helper_private
;
634 transp
= cmap
->transp
;
637 for (j
= 0; j
< cmap
->len
; j
++) {
638 u16 hred
, hgreen
, hblue
, htransp
= 0xffff;
647 rc
= setcolreg(crtc
, hred
, hgreen
, hblue
, start
++, info
);
651 crtc_funcs
->load_lut(crtc
);
655 EXPORT_SYMBOL(drm_fb_helper_setcmap
);
658 * drm_fb_helper_check_var - implementation for ->fb_check_var
659 * @var: screeninfo to check
660 * @info: fbdev registered by the helper
662 int drm_fb_helper_check_var(struct fb_var_screeninfo
*var
,
663 struct fb_info
*info
)
665 struct drm_fb_helper
*fb_helper
= info
->par
;
666 struct drm_framebuffer
*fb
= fb_helper
->fb
;
669 if (var
->pixclock
!= 0 || in_dbg_master())
672 /* Need to resize the fb object !!! */
673 if (var
->bits_per_pixel
> fb
->bits_per_pixel
||
674 var
->xres
> fb
->width
|| var
->yres
> fb
->height
||
675 var
->xres_virtual
> fb
->width
|| var
->yres_virtual
> fb
->height
) {
676 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
677 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
678 var
->xres
, var
->yres
, var
->bits_per_pixel
,
679 var
->xres_virtual
, var
->yres_virtual
,
680 fb
->width
, fb
->height
, fb
->bits_per_pixel
);
684 switch (var
->bits_per_pixel
) {
686 depth
= (var
->green
.length
== 6) ? 16 : 15;
689 depth
= (var
->transp
.length
> 0) ? 32 : 24;
692 depth
= var
->bits_per_pixel
;
699 var
->green
.offset
= 0;
700 var
->blue
.offset
= 0;
702 var
->green
.length
= 8;
703 var
->blue
.length
= 8;
704 var
->transp
.length
= 0;
705 var
->transp
.offset
= 0;
708 var
->red
.offset
= 10;
709 var
->green
.offset
= 5;
710 var
->blue
.offset
= 0;
712 var
->green
.length
= 5;
713 var
->blue
.length
= 5;
714 var
->transp
.length
= 1;
715 var
->transp
.offset
= 15;
718 var
->red
.offset
= 11;
719 var
->green
.offset
= 5;
720 var
->blue
.offset
= 0;
722 var
->green
.length
= 6;
723 var
->blue
.length
= 5;
724 var
->transp
.length
= 0;
725 var
->transp
.offset
= 0;
728 var
->red
.offset
= 16;
729 var
->green
.offset
= 8;
730 var
->blue
.offset
= 0;
732 var
->green
.length
= 8;
733 var
->blue
.length
= 8;
734 var
->transp
.length
= 0;
735 var
->transp
.offset
= 0;
738 var
->red
.offset
= 16;
739 var
->green
.offset
= 8;
740 var
->blue
.offset
= 0;
742 var
->green
.length
= 8;
743 var
->blue
.length
= 8;
744 var
->transp
.length
= 8;
745 var
->transp
.offset
= 24;
752 EXPORT_SYMBOL(drm_fb_helper_check_var
);
755 * drm_fb_helper_set_par - implementation for ->fb_set_par
756 * @info: fbdev registered by the helper
758 * This will let fbcon do the mode init and is called at initialization time by
759 * the fbdev core when registering the driver, and later on through the hotplug
762 int drm_fb_helper_set_par(struct fb_info
*info
)
764 struct drm_fb_helper
*fb_helper
= info
->par
;
765 struct drm_device
*dev
= fb_helper
->dev
;
766 struct fb_var_screeninfo
*var
= &info
->var
;
770 if (var
->pixclock
!= 0) {
771 DRM_ERROR("PIXEL CLOCK SET\n");
775 drm_modeset_lock_all(dev
);
776 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
777 ret
= drm_mode_set_config_internal(&fb_helper
->crtc_info
[i
].mode_set
);
779 drm_modeset_unlock_all(dev
);
783 drm_modeset_unlock_all(dev
);
785 if (fb_helper
->delayed_hotplug
) {
786 fb_helper
->delayed_hotplug
= false;
787 drm_fb_helper_hotplug_event(fb_helper
);
791 EXPORT_SYMBOL(drm_fb_helper_set_par
);
794 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
795 * @var: updated screen information
796 * @info: fbdev registered by the helper
798 int drm_fb_helper_pan_display(struct fb_var_screeninfo
*var
,
799 struct fb_info
*info
)
801 struct drm_fb_helper
*fb_helper
= info
->par
;
802 struct drm_device
*dev
= fb_helper
->dev
;
803 struct drm_mode_set
*modeset
;
804 struct drm_crtc
*crtc
;
808 drm_modeset_lock_all(dev
);
809 if (!drm_fb_helper_is_bound(fb_helper
)) {
810 drm_modeset_unlock_all(dev
);
814 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
815 crtc
= fb_helper
->crtc_info
[i
].mode_set
.crtc
;
817 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
819 modeset
->x
= var
->xoffset
;
820 modeset
->y
= var
->yoffset
;
822 if (modeset
->num_connectors
) {
823 ret
= drm_mode_set_config_internal(modeset
);
825 info
->var
.xoffset
= var
->xoffset
;
826 info
->var
.yoffset
= var
->yoffset
;
830 drm_modeset_unlock_all(dev
);
833 EXPORT_SYMBOL(drm_fb_helper_pan_display
);
836 * Allocates the backing storage and sets up the fbdev info structure through
837 * the ->fb_probe callback and then registers the fbdev and sets up the panic
840 static int drm_fb_helper_single_fb_probe(struct drm_fb_helper
*fb_helper
,
846 struct fb_info
*info
;
847 struct drm_fb_helper_surface_size sizes
;
850 memset(&sizes
, 0, sizeof(struct drm_fb_helper_surface_size
));
851 sizes
.surface_depth
= 24;
852 sizes
.surface_bpp
= 32;
853 sizes
.fb_width
= (unsigned)-1;
854 sizes
.fb_height
= (unsigned)-1;
856 /* if driver picks 8 or 16 by default use that
857 for both depth/bpp */
858 if (preferred_bpp
!= sizes
.surface_bpp
)
859 sizes
.surface_depth
= sizes
.surface_bpp
= preferred_bpp
;
861 /* first up get a count of crtcs now in use and new min/maxes width/heights */
862 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
863 struct drm_fb_helper_connector
*fb_helper_conn
= fb_helper
->connector_info
[i
];
864 struct drm_cmdline_mode
*cmdline_mode
;
866 cmdline_mode
= &fb_helper_conn
->cmdline_mode
;
868 if (cmdline_mode
->bpp_specified
) {
869 switch (cmdline_mode
->bpp
) {
871 sizes
.surface_depth
= sizes
.surface_bpp
= 8;
874 sizes
.surface_depth
= 15;
875 sizes
.surface_bpp
= 16;
878 sizes
.surface_depth
= sizes
.surface_bpp
= 16;
881 sizes
.surface_depth
= sizes
.surface_bpp
= 24;
884 sizes
.surface_depth
= 24;
885 sizes
.surface_bpp
= 32;
893 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
894 struct drm_display_mode
*desired_mode
;
895 desired_mode
= fb_helper
->crtc_info
[i
].desired_mode
;
899 gamma_size
= fb_helper
->crtc_info
[i
].mode_set
.crtc
->gamma_size
;
900 if (desired_mode
->hdisplay
< sizes
.fb_width
)
901 sizes
.fb_width
= desired_mode
->hdisplay
;
902 if (desired_mode
->vdisplay
< sizes
.fb_height
)
903 sizes
.fb_height
= desired_mode
->vdisplay
;
904 if (desired_mode
->hdisplay
> sizes
.surface_width
)
905 sizes
.surface_width
= desired_mode
->hdisplay
;
906 if (desired_mode
->vdisplay
> sizes
.surface_height
)
907 sizes
.surface_height
= desired_mode
->vdisplay
;
912 if (crtc_count
== 0 || sizes
.fb_width
== -1 || sizes
.fb_height
== -1) {
913 /* hmm everyone went away - assume VGA cable just fell out
914 and will come back later. */
915 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
916 sizes
.fb_width
= sizes
.surface_width
= 1024;
917 sizes
.fb_height
= sizes
.surface_height
= 768;
920 /* push down into drivers */
921 ret
= (*fb_helper
->funcs
->fb_probe
)(fb_helper
, &sizes
);
925 info
= fb_helper
->fbdev
;
928 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
929 * events, but at init time drm_setup_crtcs needs to be called before
930 * the fb is allocated (since we need to figure out the desired size of
931 * the fb before we can allocate it ...). Hence we need to fix things up
934 for (i
= 0; i
< fb_helper
->crtc_count
; i
++)
935 if (fb_helper
->crtc_info
[i
].mode_set
.num_connectors
)
936 fb_helper
->crtc_info
[i
].mode_set
.fb
= fb_helper
->fb
;
939 info
->var
.pixclock
= 0;
940 if (register_framebuffer(info
) < 0)
943 dev_info(fb_helper
->dev
->dev
, "fb%d: %s frame buffer device\n",
944 info
->node
, info
->fix
.id
);
946 /* Switch back to kernel console on panic */
947 /* multi card linked list maybe */
948 if (list_empty(&kernel_fb_helper_list
)) {
949 dev_info(fb_helper
->dev
->dev
, "registered panic notifier\n");
950 atomic_notifier_chain_register(&panic_notifier_list
,
952 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
955 list_add(&fb_helper
->kernel_fb_list
, &kernel_fb_helper_list
);
961 * drm_fb_helper_fill_fix - initializes fixed fbdev information
962 * @info: fbdev registered by the helper
963 * @pitch: desired pitch
964 * @depth: desired depth
966 * Helper to fill in the fixed fbdev information useful for a non-accelerated
967 * fbdev emulations. Drivers which support acceleration methods which impose
968 * additional constraints need to set up their own limits.
970 * Drivers should call this (or their equivalent setup code) from their
971 * ->fb_probe callback.
973 void drm_fb_helper_fill_fix(struct fb_info
*info
, uint32_t pitch
,
976 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
977 info
->fix
.visual
= depth
== 8 ? FB_VISUAL_PSEUDOCOLOR
:
979 info
->fix
.mmio_start
= 0;
980 info
->fix
.mmio_len
= 0;
981 info
->fix
.type_aux
= 0;
982 info
->fix
.xpanstep
= 1; /* doing it in hw */
983 info
->fix
.ypanstep
= 1; /* doing it in hw */
984 info
->fix
.ywrapstep
= 0;
985 info
->fix
.accel
= FB_ACCEL_NONE
;
986 info
->fix
.type_aux
= 0;
988 info
->fix
.line_length
= pitch
;
991 EXPORT_SYMBOL(drm_fb_helper_fill_fix
);
994 * drm_fb_helper_fill_var - initalizes variable fbdev information
995 * @info: fbdev instance to set up
996 * @fb_helper: fb helper instance to use as template
997 * @fb_width: desired fb width
998 * @fb_height: desired fb height
1000 * Sets up the variable fbdev metainformation from the given fb helper instance
1001 * and the drm framebuffer allocated in fb_helper->fb.
1003 * Drivers should call this (or their equivalent setup code) from their
1004 * ->fb_probe callback after having allocated the fbdev backing
1005 * storage framebuffer.
1007 void drm_fb_helper_fill_var(struct fb_info
*info
, struct drm_fb_helper
*fb_helper
,
1008 uint32_t fb_width
, uint32_t fb_height
)
1010 struct drm_framebuffer
*fb
= fb_helper
->fb
;
1011 info
->pseudo_palette
= fb_helper
->pseudo_palette
;
1012 info
->var
.xres_virtual
= fb
->width
;
1013 info
->var
.yres_virtual
= fb
->height
;
1014 info
->var
.bits_per_pixel
= fb
->bits_per_pixel
;
1015 info
->var
.accel_flags
= FB_ACCELF_TEXT
;
1016 info
->var
.xoffset
= 0;
1017 info
->var
.yoffset
= 0;
1018 info
->var
.activate
= FB_ACTIVATE_NOW
;
1019 info
->var
.height
= -1;
1020 info
->var
.width
= -1;
1022 switch (fb
->depth
) {
1024 info
->var
.red
.offset
= 0;
1025 info
->var
.green
.offset
= 0;
1026 info
->var
.blue
.offset
= 0;
1027 info
->var
.red
.length
= 8; /* 8bit DAC */
1028 info
->var
.green
.length
= 8;
1029 info
->var
.blue
.length
= 8;
1030 info
->var
.transp
.offset
= 0;
1031 info
->var
.transp
.length
= 0;
1034 info
->var
.red
.offset
= 10;
1035 info
->var
.green
.offset
= 5;
1036 info
->var
.blue
.offset
= 0;
1037 info
->var
.red
.length
= 5;
1038 info
->var
.green
.length
= 5;
1039 info
->var
.blue
.length
= 5;
1040 info
->var
.transp
.offset
= 15;
1041 info
->var
.transp
.length
= 1;
1044 info
->var
.red
.offset
= 11;
1045 info
->var
.green
.offset
= 5;
1046 info
->var
.blue
.offset
= 0;
1047 info
->var
.red
.length
= 5;
1048 info
->var
.green
.length
= 6;
1049 info
->var
.blue
.length
= 5;
1050 info
->var
.transp
.offset
= 0;
1053 info
->var
.red
.offset
= 16;
1054 info
->var
.green
.offset
= 8;
1055 info
->var
.blue
.offset
= 0;
1056 info
->var
.red
.length
= 8;
1057 info
->var
.green
.length
= 8;
1058 info
->var
.blue
.length
= 8;
1059 info
->var
.transp
.offset
= 0;
1060 info
->var
.transp
.length
= 0;
1063 info
->var
.red
.offset
= 16;
1064 info
->var
.green
.offset
= 8;
1065 info
->var
.blue
.offset
= 0;
1066 info
->var
.red
.length
= 8;
1067 info
->var
.green
.length
= 8;
1068 info
->var
.blue
.length
= 8;
1069 info
->var
.transp
.offset
= 24;
1070 info
->var
.transp
.length
= 8;
1076 info
->var
.xres
= fb_width
;
1077 info
->var
.yres
= fb_height
;
1079 EXPORT_SYMBOL(drm_fb_helper_fill_var
);
1081 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper
*fb_helper
,
1085 struct drm_connector
*connector
;
1089 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1090 connector
= fb_helper
->connector_info
[i
]->connector
;
1091 count
+= connector
->funcs
->fill_modes(connector
, maxX
, maxY
);
1097 static struct drm_display_mode
*drm_has_preferred_mode(struct drm_fb_helper_connector
*fb_connector
, int width
, int height
)
1099 struct drm_display_mode
*mode
;
1101 list_for_each_entry(mode
, &fb_connector
->connector
->modes
, head
) {
1102 if (drm_mode_width(mode
) > width
||
1103 drm_mode_height(mode
) > height
)
1105 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
)
1111 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector
*fb_connector
)
1113 struct drm_cmdline_mode
*cmdline_mode
;
1114 cmdline_mode
= &fb_connector
->cmdline_mode
;
1115 return cmdline_mode
->specified
;
1118 static struct drm_display_mode
*drm_pick_cmdline_mode(struct drm_fb_helper_connector
*fb_helper_conn
,
1119 int width
, int height
)
1121 struct drm_cmdline_mode
*cmdline_mode
;
1122 struct drm_display_mode
*mode
= NULL
;
1124 cmdline_mode
= &fb_helper_conn
->cmdline_mode
;
1125 if (cmdline_mode
->specified
== false)
1128 /* attempt to find a matching mode in the list of modes
1129 * we have gotten so far, if not add a CVT mode that conforms
1131 if (cmdline_mode
->rb
|| cmdline_mode
->margins
)
1134 list_for_each_entry(mode
, &fb_helper_conn
->connector
->modes
, head
) {
1135 /* check width/height */
1136 if (mode
->hdisplay
!= cmdline_mode
->xres
||
1137 mode
->vdisplay
!= cmdline_mode
->yres
)
1140 if (cmdline_mode
->refresh_specified
) {
1141 if (mode
->vrefresh
!= cmdline_mode
->refresh
)
1145 if (cmdline_mode
->interlace
) {
1146 if (!(mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
1153 mode
= drm_mode_create_from_cmdline_mode(fb_helper_conn
->connector
->dev
,
1155 list_add(&mode
->head
, &fb_helper_conn
->connector
->modes
);
1159 static bool drm_connector_enabled(struct drm_connector
*connector
, bool strict
)
1164 enable
= connector
->status
== connector_status_connected
;
1166 enable
= connector
->status
!= connector_status_disconnected
;
1171 static void drm_enable_connectors(struct drm_fb_helper
*fb_helper
,
1174 bool any_enabled
= false;
1175 struct drm_connector
*connector
;
1178 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1179 connector
= fb_helper
->connector_info
[i
]->connector
;
1180 enabled
[i
] = drm_connector_enabled(connector
, true);
1181 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector
->base
.id
,
1182 enabled
[i
] ? "yes" : "no");
1183 any_enabled
|= enabled
[i
];
1189 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1190 connector
= fb_helper
->connector_info
[i
]->connector
;
1191 enabled
[i
] = drm_connector_enabled(connector
, false);
1195 static bool drm_target_cloned(struct drm_fb_helper
*fb_helper
,
1196 struct drm_display_mode
**modes
,
1197 bool *enabled
, int width
, int height
)
1200 bool can_clone
= false;
1201 struct drm_fb_helper_connector
*fb_helper_conn
;
1202 struct drm_display_mode
*dmt_mode
, *mode
;
1204 /* only contemplate cloning in the single crtc case */
1205 if (fb_helper
->crtc_count
> 1)
1209 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1214 /* only contemplate cloning if more than one connector is enabled */
1218 /* check the command line or if nothing common pick 1024x768 */
1220 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1223 fb_helper_conn
= fb_helper
->connector_info
[i
];
1224 modes
[i
] = drm_pick_cmdline_mode(fb_helper_conn
, width
, height
);
1229 for (j
= 0; j
< i
; j
++) {
1232 if (!drm_mode_equal(modes
[j
], modes
[i
]))
1238 DRM_DEBUG_KMS("can clone using command line\n");
1242 /* try and find a 1024x768 mode on each connector */
1244 dmt_mode
= drm_mode_find_dmt(fb_helper
->dev
, 1024, 768, 60, false);
1246 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1251 fb_helper_conn
= fb_helper
->connector_info
[i
];
1252 list_for_each_entry(mode
, &fb_helper_conn
->connector
->modes
, head
) {
1253 if (drm_mode_equal(mode
, dmt_mode
))
1261 DRM_DEBUG_KMS("can clone using 1024x768\n");
1264 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1268 static bool drm_target_preferred(struct drm_fb_helper
*fb_helper
,
1269 struct drm_display_mode
**modes
,
1270 bool *enabled
, int width
, int height
)
1272 struct drm_fb_helper_connector
*fb_helper_conn
;
1275 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1276 fb_helper_conn
= fb_helper
->connector_info
[i
];
1278 if (enabled
[i
] == false)
1281 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1282 fb_helper_conn
->connector
->base
.id
);
1284 /* got for command line mode first */
1285 modes
[i
] = drm_pick_cmdline_mode(fb_helper_conn
, width
, height
);
1287 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
1288 fb_helper_conn
->connector
->base
.id
);
1289 modes
[i
] = drm_has_preferred_mode(fb_helper_conn
, width
, height
);
1291 /* No preferred modes, pick one off the list */
1292 if (!modes
[i
] && !list_empty(&fb_helper_conn
->connector
->modes
)) {
1293 list_for_each_entry(modes
[i
], &fb_helper_conn
->connector
->modes
, head
)
1296 DRM_DEBUG_KMS("found mode %s\n", modes
[i
] ? modes
[i
]->name
:
1302 static int drm_pick_crtcs(struct drm_fb_helper
*fb_helper
,
1303 struct drm_fb_helper_crtc
**best_crtcs
,
1304 struct drm_display_mode
**modes
,
1305 int n
, int width
, int height
)
1308 struct drm_device
*dev
= fb_helper
->dev
;
1309 struct drm_connector
*connector
;
1310 struct drm_connector_helper_funcs
*connector_funcs
;
1311 struct drm_encoder
*encoder
;
1312 struct drm_fb_helper_crtc
*best_crtc
;
1313 int my_score
, best_score
, score
;
1314 struct drm_fb_helper_crtc
**crtcs
, *crtc
;
1315 struct drm_fb_helper_connector
*fb_helper_conn
;
1317 if (n
== fb_helper
->connector_count
)
1320 fb_helper_conn
= fb_helper
->connector_info
[n
];
1321 connector
= fb_helper_conn
->connector
;
1323 best_crtcs
[n
] = NULL
;
1325 best_score
= drm_pick_crtcs(fb_helper
, best_crtcs
, modes
, n
+1, width
, height
);
1326 if (modes
[n
] == NULL
)
1329 crtcs
= kzalloc(dev
->mode_config
.num_connector
*
1330 sizeof(struct drm_fb_helper_crtc
*), GFP_KERNEL
);
1335 if (connector
->status
== connector_status_connected
)
1337 if (drm_has_cmdline_mode(fb_helper_conn
))
1339 if (drm_has_preferred_mode(fb_helper_conn
, width
, height
))
1342 connector_funcs
= connector
->helper_private
;
1343 encoder
= connector_funcs
->best_encoder(connector
);
1347 /* select a crtc for this connector and then attempt to configure
1348 remaining connectors */
1349 for (c
= 0; c
< fb_helper
->crtc_count
; c
++) {
1350 crtc
= &fb_helper
->crtc_info
[c
];
1352 if ((encoder
->possible_crtcs
& (1 << c
)) == 0)
1355 for (o
= 0; o
< n
; o
++)
1356 if (best_crtcs
[o
] == crtc
)
1360 /* ignore cloning unless only a single crtc */
1361 if (fb_helper
->crtc_count
> 1)
1364 if (!drm_mode_equal(modes
[o
], modes
[n
]))
1369 memcpy(crtcs
, best_crtcs
, n
* sizeof(struct drm_fb_helper_crtc
*));
1370 score
= my_score
+ drm_pick_crtcs(fb_helper
, crtcs
, modes
, n
+ 1,
1372 if (score
> best_score
) {
1375 memcpy(best_crtcs
, crtcs
,
1376 dev
->mode_config
.num_connector
*
1377 sizeof(struct drm_fb_helper_crtc
*));
1385 static void drm_setup_crtcs(struct drm_fb_helper
*fb_helper
)
1387 struct drm_device
*dev
= fb_helper
->dev
;
1388 struct drm_fb_helper_crtc
**crtcs
;
1389 struct drm_display_mode
**modes
;
1390 struct drm_mode_set
*modeset
;
1395 DRM_DEBUG_KMS("\n");
1397 width
= dev
->mode_config
.max_width
;
1398 height
= dev
->mode_config
.max_height
;
1400 crtcs
= kcalloc(dev
->mode_config
.num_connector
,
1401 sizeof(struct drm_fb_helper_crtc
*), GFP_KERNEL
);
1402 modes
= kcalloc(dev
->mode_config
.num_connector
,
1403 sizeof(struct drm_display_mode
*), GFP_KERNEL
);
1404 enabled
= kcalloc(dev
->mode_config
.num_connector
,
1405 sizeof(bool), GFP_KERNEL
);
1406 if (!crtcs
|| !modes
|| !enabled
) {
1407 DRM_ERROR("Memory allocation failed\n");
1412 drm_enable_connectors(fb_helper
, enabled
);
1414 ret
= drm_target_cloned(fb_helper
, modes
, enabled
, width
, height
);
1416 ret
= drm_target_preferred(fb_helper
, modes
, enabled
, width
, height
);
1418 DRM_ERROR("Unable to find initial modes\n");
1421 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width
, height
);
1423 drm_pick_crtcs(fb_helper
, crtcs
, modes
, 0, width
, height
);
1425 /* need to set the modesets up here for use later */
1426 /* fill out the connector<->crtc mappings into the modesets */
1427 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1428 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
1429 modeset
->num_connectors
= 0;
1433 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1434 struct drm_display_mode
*mode
= modes
[i
];
1435 struct drm_fb_helper_crtc
*fb_crtc
= crtcs
[i
];
1436 modeset
= &fb_crtc
->mode_set
;
1438 if (mode
&& fb_crtc
) {
1439 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
1440 mode
->name
, fb_crtc
->mode_set
.crtc
->base
.id
);
1441 fb_crtc
->desired_mode
= mode
;
1443 drm_mode_destroy(dev
, modeset
->mode
);
1444 modeset
->mode
= drm_mode_duplicate(dev
,
1445 fb_crtc
->desired_mode
);
1446 modeset
->connectors
[modeset
->num_connectors
++] = fb_helper
->connector_info
[i
]->connector
;
1447 modeset
->fb
= fb_helper
->fb
;
1451 /* Clear out any old modes if there are no more connected outputs. */
1452 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1453 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
1454 if (modeset
->num_connectors
== 0) {
1455 BUG_ON(modeset
->fb
);
1456 BUG_ON(modeset
->num_connectors
);
1458 drm_mode_destroy(dev
, modeset
->mode
);
1459 modeset
->mode
= NULL
;
1469 * drm_fb_helper_initial_config - setup a sane initial connector configuration
1470 * @fb_helper: fb_helper device struct
1471 * @bpp_sel: bpp value to use for the framebuffer configuration
1473 * Scans the CRTCs and connectors and tries to put together an initial setup.
1474 * At the moment, this is a cloned configuration across all heads with
1475 * a new framebuffer object as the backing store.
1477 * Note that this also registers the fbdev and so allows userspace to call into
1478 * the driver through the fbdev interfaces.
1480 * This function will call down into the ->fb_probe callback to let
1481 * the driver allocate and initialize the fbdev info structure and the drm
1482 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
1483 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
1484 * values for the fbdev info structure.
1487 * Zero if everything went ok, nonzero otherwise.
1489 bool drm_fb_helper_initial_config(struct drm_fb_helper
*fb_helper
, int bpp_sel
)
1491 struct drm_device
*dev
= fb_helper
->dev
;
1494 drm_fb_helper_parse_command_line(fb_helper
);
1496 count
= drm_fb_helper_probe_connector_modes(fb_helper
,
1497 dev
->mode_config
.max_width
,
1498 dev
->mode_config
.max_height
);
1500 * we shouldn't end up with no modes here.
1503 dev_info(fb_helper
->dev
->dev
, "No connectors reported connected with modes\n");
1505 drm_setup_crtcs(fb_helper
);
1507 return drm_fb_helper_single_fb_probe(fb_helper
, bpp_sel
);
1509 EXPORT_SYMBOL(drm_fb_helper_initial_config
);
1512 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
1513 * probing all the outputs attached to the fb
1514 * @fb_helper: the drm_fb_helper
1516 * Scan the connectors attached to the fb_helper and try to put together a
1517 * setup after *notification of a change in output configuration.
1519 * Called at runtime, takes the mode config locks to be able to check/change the
1520 * modeset configuration. Must be run from process context (which usually means
1521 * either the output polling work or a work item launched from the driver's
1522 * hotplug interrupt).
1524 * Note that the driver must ensure that this is only called _after_ the fb has
1525 * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
1528 * 0 on success and a non-zero error code otherwise.
1530 int drm_fb_helper_hotplug_event(struct drm_fb_helper
*fb_helper
)
1532 struct drm_device
*dev
= fb_helper
->dev
;
1534 u32 max_width
, max_height
, bpp_sel
;
1539 drm_modeset_lock_all(dev
);
1540 if (!drm_fb_helper_is_bound(fb_helper
)) {
1541 fb_helper
->delayed_hotplug
= true;
1542 drm_modeset_unlock_all(dev
);
1545 DRM_DEBUG_KMS("\n");
1547 max_width
= fb_helper
->fb
->width
;
1548 max_height
= fb_helper
->fb
->height
;
1549 bpp_sel
= fb_helper
->fb
->bits_per_pixel
;
1551 count
= drm_fb_helper_probe_connector_modes(fb_helper
, max_width
,
1553 drm_setup_crtcs(fb_helper
);
1554 drm_modeset_unlock_all(dev
);
1556 drm_fb_helper_set_par(fb_helper
->fbdev
);
1560 EXPORT_SYMBOL(drm_fb_helper_hotplug_event
);
1562 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
1563 * but the module doesn't depend on any fb console symbols. At least
1564 * attempt to load fbcon to avoid leaving the system without a usable console.
1566 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
1567 static int __init
drm_fb_helper_modinit(void)
1569 const char *name
= "fbcon";
1570 struct module
*fbcon
;
1572 mutex_lock(&module_mutex
);
1573 fbcon
= find_module(name
);
1574 mutex_unlock(&module_mutex
);
1577 request_module_nowait(name
);
1581 module_init(drm_fb_helper_modinit
);