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 #include <linux/sysrq.h>
34 #include "drm_fb_helper.h"
35 #include "drm_crtc_helper.h"
37 MODULE_AUTHOR("David Airlie, Jesse Barnes");
38 MODULE_DESCRIPTION("DRM KMS helper");
39 MODULE_LICENSE("GPL and additional rights");
41 static LIST_HEAD(kernel_fb_helper_list
);
43 int drm_fb_helper_add_connector(struct drm_connector
*connector
)
45 connector
->fb_helper_private
= kzalloc(sizeof(struct drm_fb_helper_connector
), GFP_KERNEL
);
46 if (!connector
->fb_helper_private
)
51 EXPORT_SYMBOL(drm_fb_helper_add_connector
);
53 static int my_atoi(const char *name
)
60 val
= 10*val
+(*name
-'0');
69 * drm_fb_helper_connector_parse_command_line - parse command line for connector
70 * @connector - connector to parse line for
71 * @mode_option - per connector mode option
73 * This parses the connector specific then generic command lines for
74 * modes and options to configure the connector.
76 * This uses the same parameters as the fb modedb.c, except for extra
77 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
79 * enable/enable Digital/disable bit at the end
81 static bool drm_fb_helper_connector_parse_command_line(struct drm_connector
*connector
,
82 const char *mode_option
)
86 int res_specified
= 0, bpp_specified
= 0, refresh_specified
= 0;
87 unsigned int xres
= 0, yres
= 0, bpp
= 32, refresh
= 0;
88 int yres_specified
= 0, cvt
= 0, rb
= 0, interlace
= 0, margins
= 0;
90 enum drm_connector_force force
= DRM_FORCE_UNSPECIFIED
;
91 struct drm_fb_helper_connector
*fb_help_conn
= connector
->fb_helper_private
;
92 struct drm_fb_helper_cmdline_mode
*cmdline_mode
;
97 cmdline_mode
= &fb_help_conn
->cmdline_mode
;
99 mode_option
= fb_mode_option
;
102 cmdline_mode
->specified
= false;
107 namelen
= strlen(name
);
108 for (i
= namelen
-1; i
>= 0; i
--) {
112 if (!refresh_specified
&& !bpp_specified
&&
114 refresh
= my_atoi(&name
[i
+1]);
115 refresh_specified
= 1;
123 if (!bpp_specified
&& !yres_specified
) {
124 bpp
= my_atoi(&name
[i
+1]);
132 if (!yres_specified
) {
133 yres
= my_atoi(&name
[i
+1]);
156 force
= DRM_FORCE_ON
;
159 if ((connector
->connector_type
!= DRM_MODE_CONNECTOR_DVII
) ||
160 (connector
->connector_type
!= DRM_MODE_CONNECTOR_HDMIB
))
161 force
= DRM_FORCE_ON
;
163 force
= DRM_FORCE_ON_DIGITAL
;
166 force
= DRM_FORCE_OFF
;
172 if (i
< 0 && yres_specified
) {
173 xres
= my_atoi(name
);
178 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
179 drm_get_connector_name(connector
), xres
, yres
,
180 (refresh
) ? refresh
: 60, (rb
) ? " reduced blanking" :
181 "", (margins
) ? " with margins" : "", (interlace
) ?
187 case DRM_FORCE_OFF
: s
= "OFF"; break;
188 case DRM_FORCE_ON_DIGITAL
: s
= "ON - dig"; break;
190 case DRM_FORCE_ON
: s
= "ON"; break;
193 DRM_INFO("forcing %s connector %s\n",
194 drm_get_connector_name(connector
), s
);
195 connector
->force
= force
;
199 cmdline_mode
->specified
= true;
200 cmdline_mode
->xres
= xres
;
201 cmdline_mode
->yres
= yres
;
204 if (refresh_specified
) {
205 cmdline_mode
->refresh_specified
= true;
206 cmdline_mode
->refresh
= refresh
;
210 cmdline_mode
->bpp_specified
= true;
211 cmdline_mode
->bpp
= bpp
;
213 cmdline_mode
->rb
= rb
? true : false;
214 cmdline_mode
->cvt
= cvt
? true : false;
215 cmdline_mode
->interlace
= interlace
? true : false;
220 int drm_fb_helper_parse_command_line(struct drm_device
*dev
)
222 struct drm_connector
*connector
;
224 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
227 /* do something on return - turn off connector maybe */
228 if (fb_get_options(drm_get_connector_name(connector
), &option
))
231 drm_fb_helper_connector_parse_command_line(connector
, option
);
236 bool drm_fb_helper_force_kernel_mode(void)
239 bool ret
, error
= false;
240 struct drm_fb_helper
*helper
;
242 if (list_empty(&kernel_fb_helper_list
))
245 list_for_each_entry(helper
, &kernel_fb_helper_list
, kernel_fb_list
) {
246 for (i
= 0; i
< helper
->crtc_count
; i
++) {
247 struct drm_mode_set
*mode_set
= &helper
->crtc_info
[i
].mode_set
;
248 ret
= drm_crtc_helper_set_config(mode_set
);
256 int drm_fb_helper_panic(struct notifier_block
*n
, unsigned long ununsed
,
259 DRM_ERROR("panic occurred, switching back to text console\n");
260 return drm_fb_helper_force_kernel_mode();
263 EXPORT_SYMBOL(drm_fb_helper_panic
);
265 static struct notifier_block paniced
= {
266 .notifier_call
= drm_fb_helper_panic
,
270 * drm_fb_helper_restore - restore the framebuffer console (kernel) config
272 * Restore's the kernel's fbcon mode, used for lastclose & panic paths.
274 void drm_fb_helper_restore(void)
277 ret
= drm_fb_helper_force_kernel_mode();
279 DRM_ERROR("Failed to restore crtc configuration\n");
281 EXPORT_SYMBOL(drm_fb_helper_restore
);
283 #ifdef CONFIG_MAGIC_SYSRQ
284 static void drm_fb_helper_restore_work_fn(struct work_struct
*ignored
)
286 drm_fb_helper_restore();
288 static DECLARE_WORK(drm_fb_helper_restore_work
, drm_fb_helper_restore_work_fn
);
290 static void drm_fb_helper_sysrq(int dummy1
, struct tty_struct
*dummy3
)
292 schedule_work(&drm_fb_helper_restore_work
);
295 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op
= {
296 .handler
= drm_fb_helper_sysrq
,
297 .help_msg
= "force-fb(V)",
298 .action_msg
= "Restore framebuffer console",
302 static void drm_fb_helper_on(struct fb_info
*info
)
304 struct drm_fb_helper
*fb_helper
= info
->par
;
305 struct drm_device
*dev
= fb_helper
->dev
;
306 struct drm_crtc
*crtc
;
307 struct drm_encoder
*encoder
;
311 * For each CRTC in this fb, turn the crtc on then,
312 * find all associated encoders and turn them on.
314 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
315 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
316 struct drm_crtc_helper_funcs
*crtc_funcs
=
317 crtc
->helper_private
;
319 /* Only mess with CRTCs in this fb */
320 if (crtc
->base
.id
!= fb_helper
->crtc_info
[i
].crtc_id
||
324 mutex_lock(&dev
->mode_config
.mutex
);
325 crtc_funcs
->dpms(crtc
, DRM_MODE_DPMS_ON
);
326 mutex_unlock(&dev
->mode_config
.mutex
);
328 /* Found a CRTC on this fb, now find encoders */
329 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
330 if (encoder
->crtc
== crtc
) {
331 struct drm_encoder_helper_funcs
*encoder_funcs
;
333 encoder_funcs
= encoder
->helper_private
;
334 mutex_lock(&dev
->mode_config
.mutex
);
335 encoder_funcs
->dpms(encoder
, DRM_MODE_DPMS_ON
);
336 mutex_unlock(&dev
->mode_config
.mutex
);
343 static void drm_fb_helper_off(struct fb_info
*info
, int dpms_mode
)
345 struct drm_fb_helper
*fb_helper
= info
->par
;
346 struct drm_device
*dev
= fb_helper
->dev
;
347 struct drm_crtc
*crtc
;
348 struct drm_encoder
*encoder
;
352 * For each CRTC in this fb, find all associated encoders
353 * and turn them off, then turn off the CRTC.
355 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
356 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
357 struct drm_crtc_helper_funcs
*crtc_funcs
=
358 crtc
->helper_private
;
360 /* Only mess with CRTCs in this fb */
361 if (crtc
->base
.id
!= fb_helper
->crtc_info
[i
].crtc_id
||
365 /* Found a CRTC on this fb, now find encoders */
366 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
367 if (encoder
->crtc
== crtc
) {
368 struct drm_encoder_helper_funcs
*encoder_funcs
;
370 encoder_funcs
= encoder
->helper_private
;
371 mutex_lock(&dev
->mode_config
.mutex
);
372 encoder_funcs
->dpms(encoder
, dpms_mode
);
373 mutex_unlock(&dev
->mode_config
.mutex
);
376 if (dpms_mode
== DRM_MODE_DPMS_OFF
) {
377 mutex_lock(&dev
->mode_config
.mutex
);
378 crtc_funcs
->dpms(crtc
, dpms_mode
);
379 mutex_unlock(&dev
->mode_config
.mutex
);
385 int drm_fb_helper_blank(int blank
, struct fb_info
*info
)
388 case FB_BLANK_UNBLANK
:
389 drm_fb_helper_on(info
);
391 case FB_BLANK_NORMAL
:
392 drm_fb_helper_off(info
, DRM_MODE_DPMS_STANDBY
);
394 case FB_BLANK_HSYNC_SUSPEND
:
395 drm_fb_helper_off(info
, DRM_MODE_DPMS_STANDBY
);
397 case FB_BLANK_VSYNC_SUSPEND
:
398 drm_fb_helper_off(info
, DRM_MODE_DPMS_SUSPEND
);
400 case FB_BLANK_POWERDOWN
:
401 drm_fb_helper_off(info
, DRM_MODE_DPMS_OFF
);
406 EXPORT_SYMBOL(drm_fb_helper_blank
);
408 static void drm_fb_helper_crtc_free(struct drm_fb_helper
*helper
)
412 for (i
= 0; i
< helper
->crtc_count
; i
++)
413 kfree(helper
->crtc_info
[i
].mode_set
.connectors
);
414 kfree(helper
->crtc_info
);
417 int drm_fb_helper_init_crtc_count(struct drm_fb_helper
*helper
, int crtc_count
, int max_conn_count
)
419 struct drm_device
*dev
= helper
->dev
;
420 struct drm_crtc
*crtc
;
424 helper
->crtc_info
= kcalloc(crtc_count
, sizeof(struct drm_fb_helper_crtc
), GFP_KERNEL
);
425 if (!helper
->crtc_info
)
428 helper
->crtc_count
= crtc_count
;
430 for (i
= 0; i
< crtc_count
; i
++) {
431 helper
->crtc_info
[i
].mode_set
.connectors
=
432 kcalloc(max_conn_count
,
433 sizeof(struct drm_connector
*),
436 if (!helper
->crtc_info
[i
].mode_set
.connectors
) {
440 helper
->crtc_info
[i
].mode_set
.num_connectors
= 0;
444 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
445 helper
->crtc_info
[i
].crtc_id
= crtc
->base
.id
;
446 helper
->crtc_info
[i
].mode_set
.crtc
= crtc
;
449 helper
->conn_limit
= max_conn_count
;
452 drm_fb_helper_crtc_free(helper
);
455 EXPORT_SYMBOL(drm_fb_helper_init_crtc_count
);
457 static int setcolreg(struct drm_crtc
*crtc
, u16 red
, u16 green
,
458 u16 blue
, u16 regno
, struct fb_info
*info
)
460 struct drm_fb_helper
*fb_helper
= info
->par
;
461 struct drm_framebuffer
*fb
= fb_helper
->fb
;
464 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
467 /* place color in psuedopalette */
470 palette
= (u32
*)info
->pseudo_palette
;
471 red
>>= (16 - info
->var
.red
.length
);
472 green
>>= (16 - info
->var
.green
.length
);
473 blue
>>= (16 - info
->var
.blue
.length
);
474 value
= (red
<< info
->var
.red
.offset
) |
475 (green
<< info
->var
.green
.offset
) |
476 (blue
<< info
->var
.blue
.offset
);
477 palette
[regno
] = value
;
483 if (fb
->bits_per_pixel
== 16) {
486 if (fb
->depth
== 16 && regno
> 63)
488 if (fb
->depth
== 15 && regno
> 31)
491 if (fb
->depth
== 16) {
495 for (i
= 0; i
< 8; i
++)
496 fb_helper
->funcs
->gamma_set(crtc
, red
,
497 green
, blue
, pindex
+ i
);
500 fb_helper
->funcs
->gamma_get(crtc
, &r
,
504 for (i
= 0; i
< 4; i
++)
505 fb_helper
->funcs
->gamma_set(crtc
, r
,
512 fb_helper
->funcs
->gamma_set(crtc
, red
, green
, blue
, pindex
);
516 int drm_fb_helper_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
518 struct drm_fb_helper
*fb_helper
= info
->par
;
519 struct drm_device
*dev
= fb_helper
->dev
;
520 u16
*red
, *green
, *blue
, *transp
;
521 struct drm_crtc
*crtc
;
525 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
526 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
527 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
528 if (crtc
->base
.id
== fb_helper
->crtc_info
[i
].crtc_id
)
531 if (i
== fb_helper
->crtc_count
)
537 transp
= cmap
->transp
;
540 for (i
= 0; i
< cmap
->len
; i
++) {
541 u16 hred
, hgreen
, hblue
, htransp
= 0xffff;
550 rc
= setcolreg(crtc
, hred
, hgreen
, hblue
, start
++, info
);
554 crtc_funcs
->load_lut(crtc
);
558 EXPORT_SYMBOL(drm_fb_helper_setcmap
);
560 int drm_fb_helper_setcolreg(unsigned regno
,
565 struct fb_info
*info
)
567 struct drm_fb_helper
*fb_helper
= info
->par
;
568 struct drm_device
*dev
= fb_helper
->dev
;
569 struct drm_crtc
*crtc
;
576 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
577 struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
578 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
579 if (crtc
->base
.id
== fb_helper
->crtc_info
[i
].crtc_id
)
582 if (i
== fb_helper
->crtc_count
)
585 ret
= setcolreg(crtc
, red
, green
, blue
, regno
, info
);
589 crtc_funcs
->load_lut(crtc
);
593 EXPORT_SYMBOL(drm_fb_helper_setcolreg
);
595 int drm_fb_helper_check_var(struct fb_var_screeninfo
*var
,
596 struct fb_info
*info
)
598 struct drm_fb_helper
*fb_helper
= info
->par
;
599 struct drm_framebuffer
*fb
= fb_helper
->fb
;
602 if (var
->pixclock
== -1 || !var
->pixclock
)
605 /* Need to resize the fb object !!! */
606 if (var
->xres
> fb
->width
|| var
->yres
> fb
->height
) {
607 DRM_ERROR("Requested width/height is greater than current fb "
608 "object %dx%d > %dx%d\n", var
->xres
, var
->yres
,
609 fb
->width
, fb
->height
);
610 DRM_ERROR("Need resizing code.\n");
614 switch (var
->bits_per_pixel
) {
616 depth
= (var
->green
.length
== 6) ? 16 : 15;
619 depth
= (var
->transp
.length
> 0) ? 32 : 24;
622 depth
= var
->bits_per_pixel
;
629 var
->green
.offset
= 0;
630 var
->blue
.offset
= 0;
632 var
->green
.length
= 8;
633 var
->blue
.length
= 8;
634 var
->transp
.length
= 0;
635 var
->transp
.offset
= 0;
638 var
->red
.offset
= 10;
639 var
->green
.offset
= 5;
640 var
->blue
.offset
= 0;
642 var
->green
.length
= 5;
643 var
->blue
.length
= 5;
644 var
->transp
.length
= 1;
645 var
->transp
.offset
= 15;
648 var
->red
.offset
= 11;
649 var
->green
.offset
= 5;
650 var
->blue
.offset
= 0;
652 var
->green
.length
= 6;
653 var
->blue
.length
= 5;
654 var
->transp
.length
= 0;
655 var
->transp
.offset
= 0;
658 var
->red
.offset
= 16;
659 var
->green
.offset
= 8;
660 var
->blue
.offset
= 0;
662 var
->green
.length
= 8;
663 var
->blue
.length
= 8;
664 var
->transp
.length
= 0;
665 var
->transp
.offset
= 0;
668 var
->red
.offset
= 16;
669 var
->green
.offset
= 8;
670 var
->blue
.offset
= 0;
672 var
->green
.length
= 8;
673 var
->blue
.length
= 8;
674 var
->transp
.length
= 8;
675 var
->transp
.offset
= 24;
682 EXPORT_SYMBOL(drm_fb_helper_check_var
);
684 /* this will let fbcon do the mode init */
685 int drm_fb_helper_set_par(struct fb_info
*info
)
687 struct drm_fb_helper
*fb_helper
= info
->par
;
688 struct drm_device
*dev
= fb_helper
->dev
;
689 struct fb_var_screeninfo
*var
= &info
->var
;
690 struct drm_crtc
*crtc
;
694 if (var
->pixclock
!= -1) {
695 DRM_ERROR("PIXEL CLCOK SET\n");
699 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
701 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
702 if (crtc
->base
.id
== fb_helper
->crtc_info
[i
].crtc_id
)
705 if (i
== fb_helper
->crtc_count
)
708 if (crtc
->fb
== fb_helper
->crtc_info
[i
].mode_set
.fb
) {
709 mutex_lock(&dev
->mode_config
.mutex
);
710 ret
= crtc
->funcs
->set_config(&fb_helper
->crtc_info
[i
].mode_set
);
711 mutex_unlock(&dev
->mode_config
.mutex
);
718 EXPORT_SYMBOL(drm_fb_helper_set_par
);
720 int drm_fb_helper_pan_display(struct fb_var_screeninfo
*var
,
721 struct fb_info
*info
)
723 struct drm_fb_helper
*fb_helper
= info
->par
;
724 struct drm_device
*dev
= fb_helper
->dev
;
725 struct drm_mode_set
*modeset
;
726 struct drm_crtc
*crtc
;
730 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
731 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
732 if (crtc
->base
.id
== fb_helper
->crtc_info
[i
].crtc_id
)
736 if (i
== fb_helper
->crtc_count
)
739 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
741 modeset
->x
= var
->xoffset
;
742 modeset
->y
= var
->yoffset
;
744 if (modeset
->num_connectors
) {
745 mutex_lock(&dev
->mode_config
.mutex
);
746 ret
= crtc
->funcs
->set_config(modeset
);
747 mutex_unlock(&dev
->mode_config
.mutex
);
749 info
->var
.xoffset
= var
->xoffset
;
750 info
->var
.yoffset
= var
->yoffset
;
756 EXPORT_SYMBOL(drm_fb_helper_pan_display
);
758 int drm_fb_helper_single_fb_probe(struct drm_device
*dev
,
760 int (*fb_create
)(struct drm_device
*dev
,
763 uint32_t surface_width
,
764 uint32_t surface_height
,
765 uint32_t surface_depth
,
766 uint32_t surface_bpp
,
767 struct drm_framebuffer
**fb_ptr
))
769 struct drm_crtc
*crtc
;
770 struct drm_connector
*connector
;
771 unsigned int fb_width
= (unsigned)-1, fb_height
= (unsigned)-1;
772 unsigned int surface_width
= 0, surface_height
= 0;
775 int ret
, i
, conn_count
= 0;
776 struct fb_info
*info
;
777 struct drm_framebuffer
*fb
;
778 struct drm_mode_set
*modeset
= NULL
;
779 struct drm_fb_helper
*fb_helper
;
780 uint32_t surface_depth
= 24, surface_bpp
= 32;
782 /* if driver picks 8 or 16 by default use that
783 for both depth/bpp */
784 if (preferred_bpp
!= surface_bpp
) {
785 surface_depth
= surface_bpp
= preferred_bpp
;
787 /* first up get a count of crtcs now in use and new min/maxes width/heights */
788 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
789 struct drm_fb_helper_connector
*fb_help_conn
= connector
->fb_helper_private
;
791 struct drm_fb_helper_cmdline_mode
*cmdline_mode
;
796 cmdline_mode
= &fb_help_conn
->cmdline_mode
;
798 if (cmdline_mode
->bpp_specified
) {
799 switch (cmdline_mode
->bpp
) {
801 surface_depth
= surface_bpp
= 8;
808 surface_depth
= surface_bpp
= 16;
811 surface_depth
= surface_bpp
= 24;
822 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
823 if (drm_helper_crtc_in_use(crtc
)) {
824 if (crtc
->desired_mode
) {
825 if (crtc
->desired_mode
->hdisplay
< fb_width
)
826 fb_width
= crtc
->desired_mode
->hdisplay
;
828 if (crtc
->desired_mode
->vdisplay
< fb_height
)
829 fb_height
= crtc
->desired_mode
->vdisplay
;
831 if (crtc
->desired_mode
->hdisplay
> surface_width
)
832 surface_width
= crtc
->desired_mode
->hdisplay
;
834 if (crtc
->desired_mode
->vdisplay
> surface_height
)
835 surface_height
= crtc
->desired_mode
->vdisplay
;
841 if (crtc_count
== 0 || fb_width
== -1 || fb_height
== -1) {
842 /* hmm everyone went away - assume VGA cable just fell out
843 and will come back later. */
847 /* do we have an fb already? */
848 if (list_empty(&dev
->mode_config
.fb_kernel_list
)) {
849 ret
= (*fb_create
)(dev
, fb_width
, fb_height
, surface_width
,
850 surface_height
, surface_depth
, surface_bpp
,
856 fb
= list_first_entry(&dev
->mode_config
.fb_kernel_list
,
857 struct drm_framebuffer
, filp_head
);
859 /* if someone hotplugs something bigger than we have already allocated, we are pwned.
860 As really we can't resize an fbdev that is in the wild currently due to fbdev
861 not really being designed for the lower layers moving stuff around under it.
862 - so in the grand style of things - punt. */
863 if ((fb
->width
< surface_width
) ||
864 (fb
->height
< surface_height
)) {
865 DRM_ERROR("Framebuffer not large enough to scale console onto.\n");
871 fb_helper
= info
->par
;
874 /* okay we need to setup new connector sets in the crtcs */
875 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
876 modeset
= &fb_helper
->crtc_info
[crtc_count
].mode_set
;
879 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
880 if (connector
->encoder
)
881 if (connector
->encoder
->crtc
== modeset
->crtc
) {
882 modeset
->connectors
[conn_count
] = connector
;
884 if (conn_count
> fb_helper
->conn_limit
)
889 for (i
= conn_count
; i
< fb_helper
->conn_limit
; i
++)
890 modeset
->connectors
[i
] = NULL
;
892 modeset
->crtc
= crtc
;
895 modeset
->num_connectors
= conn_count
;
896 if (modeset
->crtc
->desired_mode
) {
898 drm_mode_destroy(dev
, modeset
->mode
);
899 modeset
->mode
= drm_mode_duplicate(dev
,
900 modeset
->crtc
->desired_mode
);
903 fb_helper
->crtc_count
= crtc_count
;
907 info
->var
.pixclock
= -1;
908 if (register_framebuffer(info
) < 0)
911 drm_fb_helper_set_par(info
);
913 printk(KERN_INFO
"fb%d: %s frame buffer device\n", info
->node
,
916 /* Switch back to kernel console on panic */
917 /* multi card linked list maybe */
918 if (list_empty(&kernel_fb_helper_list
)) {
919 printk(KERN_INFO
"registered panic notifier\n");
920 atomic_notifier_chain_register(&panic_notifier_list
,
922 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
924 list_add(&fb_helper
->kernel_fb_list
, &kernel_fb_helper_list
);
927 EXPORT_SYMBOL(drm_fb_helper_single_fb_probe
);
929 void drm_fb_helper_free(struct drm_fb_helper
*helper
)
931 list_del(&helper
->kernel_fb_list
);
932 if (list_empty(&kernel_fb_helper_list
)) {
933 printk(KERN_INFO
"unregistered panic notifier\n");
934 atomic_notifier_chain_unregister(&panic_notifier_list
,
936 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
938 drm_fb_helper_crtc_free(helper
);
940 EXPORT_SYMBOL(drm_fb_helper_free
);
942 void drm_fb_helper_fill_fix(struct fb_info
*info
, uint32_t pitch
,
945 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
946 info
->fix
.visual
= depth
== 8 ? FB_VISUAL_PSEUDOCOLOR
:
948 info
->fix
.type_aux
= 0;
949 info
->fix
.xpanstep
= 1; /* doing it in hw */
950 info
->fix
.ypanstep
= 1; /* doing it in hw */
951 info
->fix
.ywrapstep
= 0;
952 info
->fix
.accel
= FB_ACCEL_NONE
;
953 info
->fix
.type_aux
= 0;
955 info
->fix
.line_length
= pitch
;
958 EXPORT_SYMBOL(drm_fb_helper_fill_fix
);
960 void drm_fb_helper_fill_var(struct fb_info
*info
, struct drm_framebuffer
*fb
,
961 uint32_t fb_width
, uint32_t fb_height
)
963 info
->pseudo_palette
= fb
->pseudo_palette
;
964 info
->var
.xres_virtual
= fb
->width
;
965 info
->var
.yres_virtual
= fb
->height
;
966 info
->var
.bits_per_pixel
= fb
->bits_per_pixel
;
967 info
->var
.xoffset
= 0;
968 info
->var
.yoffset
= 0;
969 info
->var
.activate
= FB_ACTIVATE_NOW
;
970 info
->var
.height
= -1;
971 info
->var
.width
= -1;
975 info
->var
.red
.offset
= 0;
976 info
->var
.green
.offset
= 0;
977 info
->var
.blue
.offset
= 0;
978 info
->var
.red
.length
= 8; /* 8bit DAC */
979 info
->var
.green
.length
= 8;
980 info
->var
.blue
.length
= 8;
981 info
->var
.transp
.offset
= 0;
982 info
->var
.transp
.length
= 0;
985 info
->var
.red
.offset
= 10;
986 info
->var
.green
.offset
= 5;
987 info
->var
.blue
.offset
= 0;
988 info
->var
.red
.length
= 5;
989 info
->var
.green
.length
= 5;
990 info
->var
.blue
.length
= 5;
991 info
->var
.transp
.offset
= 15;
992 info
->var
.transp
.length
= 1;
995 info
->var
.red
.offset
= 11;
996 info
->var
.green
.offset
= 5;
997 info
->var
.blue
.offset
= 0;
998 info
->var
.red
.length
= 5;
999 info
->var
.green
.length
= 6;
1000 info
->var
.blue
.length
= 5;
1001 info
->var
.transp
.offset
= 0;
1004 info
->var
.red
.offset
= 16;
1005 info
->var
.green
.offset
= 8;
1006 info
->var
.blue
.offset
= 0;
1007 info
->var
.red
.length
= 8;
1008 info
->var
.green
.length
= 8;
1009 info
->var
.blue
.length
= 8;
1010 info
->var
.transp
.offset
= 0;
1011 info
->var
.transp
.length
= 0;
1014 info
->var
.red
.offset
= 16;
1015 info
->var
.green
.offset
= 8;
1016 info
->var
.blue
.offset
= 0;
1017 info
->var
.red
.length
= 8;
1018 info
->var
.green
.length
= 8;
1019 info
->var
.blue
.length
= 8;
1020 info
->var
.transp
.offset
= 24;
1021 info
->var
.transp
.length
= 8;
1027 info
->var
.xres
= fb_width
;
1028 info
->var
.yres
= fb_height
;
1030 EXPORT_SYMBOL(drm_fb_helper_fill_var
);