percpu, x86: don't use PMD_SIZE as embedded atom_size on 32bit
[zen-stable.git] / drivers / gpu / drm / drm_fb_helper.c
blob7432e724ecbb9e0dd379ed03ff52b3ab75de9a4d
1 /*
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
24 * OF THIS SOFTWARE.
26 * Authors:
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
30 #include <linux/kernel.h>
31 #include <linux/sysrq.h>
32 #include <linux/slab.h>
33 #include <linux/fb.h>
34 #include <linux/module.h>
35 #include "drmP.h"
36 #include "drm_crtc.h"
37 #include "drm_fb_helper.h"
38 #include "drm_crtc_helper.h"
40 MODULE_AUTHOR("David Airlie, Jesse Barnes");
41 MODULE_DESCRIPTION("DRM KMS helper");
42 MODULE_LICENSE("GPL and additional rights");
44 static LIST_HEAD(kernel_fb_helper_list);
46 /* simple single crtc case helper function */
47 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
49 struct drm_device *dev = fb_helper->dev;
50 struct drm_connector *connector;
51 int i;
53 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
54 struct drm_fb_helper_connector *fb_helper_connector;
56 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
57 if (!fb_helper_connector)
58 goto fail;
60 fb_helper_connector->connector = connector;
61 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
63 return 0;
64 fail:
65 for (i = 0; i < fb_helper->connector_count; i++) {
66 kfree(fb_helper->connector_info[i]);
67 fb_helper->connector_info[i] = NULL;
69 fb_helper->connector_count = 0;
70 return -ENOMEM;
72 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
74 static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
76 struct drm_fb_helper_connector *fb_helper_conn;
77 int i;
79 for (i = 0; i < fb_helper->connector_count; i++) {
80 struct drm_cmdline_mode *mode;
81 struct drm_connector *connector;
82 char *option = NULL;
84 fb_helper_conn = fb_helper->connector_info[i];
85 connector = fb_helper_conn->connector;
86 mode = &fb_helper_conn->cmdline_mode;
88 /* do something on return - turn off connector maybe */
89 if (fb_get_options(drm_get_connector_name(connector), &option))
90 continue;
92 if (drm_mode_parse_command_line_for_connector(option,
93 connector,
94 mode)) {
95 if (mode->force) {
96 const char *s;
97 switch (mode->force) {
98 case DRM_FORCE_OFF: s = "OFF"; break;
99 case DRM_FORCE_ON_DIGITAL: s = "ON - dig"; break;
100 default:
101 case DRM_FORCE_ON: s = "ON"; break;
104 DRM_INFO("forcing %s connector %s\n",
105 drm_get_connector_name(connector), s);
106 connector->force = mode->force;
109 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
110 drm_get_connector_name(connector),
111 mode->xres, mode->yres,
112 mode->refresh_specified ? mode->refresh : 60,
113 mode->rb ? " reduced blanking" : "",
114 mode->margins ? " with margins" : "",
115 mode->interlace ? " interlaced" : "");
119 return 0;
122 static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper)
124 uint16_t *r_base, *g_base, *b_base;
125 int i;
127 r_base = crtc->gamma_store;
128 g_base = r_base + crtc->gamma_size;
129 b_base = g_base + crtc->gamma_size;
131 for (i = 0; i < crtc->gamma_size; i++)
132 helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i);
135 static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
137 uint16_t *r_base, *g_base, *b_base;
139 r_base = crtc->gamma_store;
140 g_base = r_base + crtc->gamma_size;
141 b_base = g_base + crtc->gamma_size;
143 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
146 int drm_fb_helper_debug_enter(struct fb_info *info)
148 struct drm_fb_helper *helper = info->par;
149 struct drm_crtc_helper_funcs *funcs;
150 int i;
152 if (list_empty(&kernel_fb_helper_list))
153 return false;
155 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
156 for (i = 0; i < helper->crtc_count; i++) {
157 struct drm_mode_set *mode_set =
158 &helper->crtc_info[i].mode_set;
160 if (!mode_set->crtc->enabled)
161 continue;
163 funcs = mode_set->crtc->helper_private;
164 drm_fb_helper_save_lut_atomic(mode_set->crtc, helper);
165 funcs->mode_set_base_atomic(mode_set->crtc,
166 mode_set->fb,
167 mode_set->x,
168 mode_set->y,
169 ENTER_ATOMIC_MODE_SET);
173 return 0;
175 EXPORT_SYMBOL(drm_fb_helper_debug_enter);
177 /* Find the real fb for a given fb helper CRTC */
178 static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
180 struct drm_device *dev = crtc->dev;
181 struct drm_crtc *c;
183 list_for_each_entry(c, &dev->mode_config.crtc_list, head) {
184 if (crtc->base.id == c->base.id)
185 return c->fb;
188 return NULL;
191 int drm_fb_helper_debug_leave(struct fb_info *info)
193 struct drm_fb_helper *helper = info->par;
194 struct drm_crtc *crtc;
195 struct drm_crtc_helper_funcs *funcs;
196 struct drm_framebuffer *fb;
197 int i;
199 for (i = 0; i < helper->crtc_count; i++) {
200 struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
201 crtc = mode_set->crtc;
202 funcs = crtc->helper_private;
203 fb = drm_mode_config_fb(crtc);
205 if (!crtc->enabled)
206 continue;
208 if (!fb) {
209 DRM_ERROR("no fb to restore??\n");
210 continue;
213 drm_fb_helper_restore_lut_atomic(mode_set->crtc);
214 funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x,
215 crtc->y, LEAVE_ATOMIC_MODE_SET);
218 return 0;
220 EXPORT_SYMBOL(drm_fb_helper_debug_leave);
222 bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
224 bool error = false;
225 int i, ret;
226 for (i = 0; i < fb_helper->crtc_count; i++) {
227 struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
228 ret = drm_crtc_helper_set_config(mode_set);
229 if (ret)
230 error = true;
232 return error;
234 EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode);
236 bool drm_fb_helper_force_kernel_mode(void)
238 bool ret, error = false;
239 struct drm_fb_helper *helper;
241 if (list_empty(&kernel_fb_helper_list))
242 return false;
244 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
245 if (helper->dev->switch_power_state == DRM_SWITCH_POWER_OFF)
246 continue;
248 ret = drm_fb_helper_restore_fbdev_mode(helper);
249 if (ret)
250 error = true;
252 return error;
255 int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
256 void *panic_str)
259 * It's a waste of time and effort to switch back to text console
260 * if the kernel should reboot before panic messages can be seen.
262 if (panic_timeout < 0)
263 return 0;
265 printk(KERN_ERR "panic occurred, switching back to text console\n");
266 return drm_fb_helper_force_kernel_mode();
268 EXPORT_SYMBOL(drm_fb_helper_panic);
270 static struct notifier_block paniced = {
271 .notifier_call = drm_fb_helper_panic,
275 * drm_fb_helper_restore - restore the framebuffer console (kernel) config
277 * Restore's the kernel's fbcon mode, used for lastclose & panic paths.
279 void drm_fb_helper_restore(void)
281 bool ret;
282 ret = drm_fb_helper_force_kernel_mode();
283 if (ret == true)
284 DRM_ERROR("Failed to restore crtc configuration\n");
286 EXPORT_SYMBOL(drm_fb_helper_restore);
288 #ifdef CONFIG_MAGIC_SYSRQ
289 static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
291 drm_fb_helper_restore();
293 static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
295 static void drm_fb_helper_sysrq(int dummy1)
297 schedule_work(&drm_fb_helper_restore_work);
300 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
301 .handler = drm_fb_helper_sysrq,
302 .help_msg = "force-fb(V)",
303 .action_msg = "Restore framebuffer console",
305 #else
306 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
307 #endif
309 static void drm_fb_helper_on(struct fb_info *info)
311 struct drm_fb_helper *fb_helper = info->par;
312 struct drm_device *dev = fb_helper->dev;
313 struct drm_crtc *crtc;
314 struct drm_crtc_helper_funcs *crtc_funcs;
315 struct drm_connector *connector;
316 struct drm_encoder *encoder;
317 int i, j;
320 * For each CRTC in this fb, turn the crtc on then,
321 * find all associated encoders and turn them on.
323 mutex_lock(&dev->mode_config.mutex);
324 for (i = 0; i < fb_helper->crtc_count; i++) {
325 crtc = fb_helper->crtc_info[i].mode_set.crtc;
326 crtc_funcs = crtc->helper_private;
328 if (!crtc->enabled)
329 continue;
331 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
333 /* Walk the connectors & encoders on this fb turning them on */
334 for (j = 0; j < fb_helper->connector_count; j++) {
335 connector = fb_helper->connector_info[j]->connector;
336 connector->dpms = DRM_MODE_DPMS_ON;
337 drm_connector_property_set_value(connector,
338 dev->mode_config.dpms_property,
339 DRM_MODE_DPMS_ON);
341 /* Found a CRTC on this fb, now find encoders */
342 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
343 if (encoder->crtc == crtc) {
344 struct drm_encoder_helper_funcs *encoder_funcs;
346 encoder_funcs = encoder->helper_private;
347 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
351 mutex_unlock(&dev->mode_config.mutex);
354 static void drm_fb_helper_off(struct fb_info *info, int dpms_mode)
356 struct drm_fb_helper *fb_helper = info->par;
357 struct drm_device *dev = fb_helper->dev;
358 struct drm_crtc *crtc;
359 struct drm_crtc_helper_funcs *crtc_funcs;
360 struct drm_connector *connector;
361 struct drm_encoder *encoder;
362 int i, j;
365 * For each CRTC in this fb, find all associated encoders
366 * and turn them off, then turn off the CRTC.
368 mutex_lock(&dev->mode_config.mutex);
369 for (i = 0; i < fb_helper->crtc_count; i++) {
370 crtc = fb_helper->crtc_info[i].mode_set.crtc;
371 crtc_funcs = crtc->helper_private;
373 if (!crtc->enabled)
374 continue;
376 /* Walk the connectors on this fb and mark them off */
377 for (j = 0; j < fb_helper->connector_count; j++) {
378 connector = fb_helper->connector_info[j]->connector;
379 connector->dpms = dpms_mode;
380 drm_connector_property_set_value(connector,
381 dev->mode_config.dpms_property,
382 dpms_mode);
384 /* Found a CRTC on this fb, now find encoders */
385 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
386 if (encoder->crtc == crtc) {
387 struct drm_encoder_helper_funcs *encoder_funcs;
389 encoder_funcs = encoder->helper_private;
390 encoder_funcs->dpms(encoder, dpms_mode);
393 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
395 mutex_unlock(&dev->mode_config.mutex);
398 int drm_fb_helper_blank(int blank, struct fb_info *info)
400 switch (blank) {
401 /* Display: On; HSync: On, VSync: On */
402 case FB_BLANK_UNBLANK:
403 drm_fb_helper_on(info);
404 break;
405 /* Display: Off; HSync: On, VSync: On */
406 case FB_BLANK_NORMAL:
407 drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY);
408 break;
409 /* Display: Off; HSync: Off, VSync: On */
410 case FB_BLANK_HSYNC_SUSPEND:
411 drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY);
412 break;
413 /* Display: Off; HSync: On, VSync: Off */
414 case FB_BLANK_VSYNC_SUSPEND:
415 drm_fb_helper_off(info, DRM_MODE_DPMS_SUSPEND);
416 break;
417 /* Display: Off; HSync: Off, VSync: Off */
418 case FB_BLANK_POWERDOWN:
419 drm_fb_helper_off(info, DRM_MODE_DPMS_OFF);
420 break;
422 return 0;
424 EXPORT_SYMBOL(drm_fb_helper_blank);
426 static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
428 int i;
430 for (i = 0; i < helper->connector_count; i++)
431 kfree(helper->connector_info[i]);
432 kfree(helper->connector_info);
433 for (i = 0; i < helper->crtc_count; i++)
434 kfree(helper->crtc_info[i].mode_set.connectors);
435 kfree(helper->crtc_info);
438 int drm_fb_helper_init(struct drm_device *dev,
439 struct drm_fb_helper *fb_helper,
440 int crtc_count, int max_conn_count)
442 struct drm_crtc *crtc;
443 int ret = 0;
444 int i;
446 fb_helper->dev = dev;
448 INIT_LIST_HEAD(&fb_helper->kernel_fb_list);
450 fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
451 if (!fb_helper->crtc_info)
452 return -ENOMEM;
454 fb_helper->crtc_count = crtc_count;
455 fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
456 if (!fb_helper->connector_info) {
457 kfree(fb_helper->crtc_info);
458 return -ENOMEM;
460 fb_helper->connector_count = 0;
462 for (i = 0; i < crtc_count; i++) {
463 fb_helper->crtc_info[i].mode_set.connectors =
464 kcalloc(max_conn_count,
465 sizeof(struct drm_connector *),
466 GFP_KERNEL);
468 if (!fb_helper->crtc_info[i].mode_set.connectors) {
469 ret = -ENOMEM;
470 goto out_free;
472 fb_helper->crtc_info[i].mode_set.num_connectors = 0;
475 i = 0;
476 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
477 fb_helper->crtc_info[i].crtc_id = crtc->base.id;
478 fb_helper->crtc_info[i].mode_set.crtc = crtc;
479 i++;
481 fb_helper->conn_limit = max_conn_count;
482 return 0;
483 out_free:
484 drm_fb_helper_crtc_free(fb_helper);
485 return -ENOMEM;
487 EXPORT_SYMBOL(drm_fb_helper_init);
489 void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
491 if (!list_empty(&fb_helper->kernel_fb_list)) {
492 list_del(&fb_helper->kernel_fb_list);
493 if (list_empty(&kernel_fb_helper_list)) {
494 printk(KERN_INFO "drm: unregistered panic notifier\n");
495 atomic_notifier_chain_unregister(&panic_notifier_list,
496 &paniced);
497 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
501 drm_fb_helper_crtc_free(fb_helper);
504 EXPORT_SYMBOL(drm_fb_helper_fini);
506 static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
507 u16 blue, u16 regno, struct fb_info *info)
509 struct drm_fb_helper *fb_helper = info->par;
510 struct drm_framebuffer *fb = fb_helper->fb;
511 int pindex;
513 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
514 u32 *palette;
515 u32 value;
516 /* place color in psuedopalette */
517 if (regno > 16)
518 return -EINVAL;
519 palette = (u32 *)info->pseudo_palette;
520 red >>= (16 - info->var.red.length);
521 green >>= (16 - info->var.green.length);
522 blue >>= (16 - info->var.blue.length);
523 value = (red << info->var.red.offset) |
524 (green << info->var.green.offset) |
525 (blue << info->var.blue.offset);
526 if (info->var.transp.length > 0) {
527 u32 mask = (1 << info->var.transp.length) - 1;
528 mask <<= info->var.transp.offset;
529 value |= mask;
531 palette[regno] = value;
532 return 0;
535 pindex = regno;
537 if (fb->bits_per_pixel == 16) {
538 pindex = regno << 3;
540 if (fb->depth == 16 && regno > 63)
541 return -EINVAL;
542 if (fb->depth == 15 && regno > 31)
543 return -EINVAL;
545 if (fb->depth == 16) {
546 u16 r, g, b;
547 int i;
548 if (regno < 32) {
549 for (i = 0; i < 8; i++)
550 fb_helper->funcs->gamma_set(crtc, red,
551 green, blue, pindex + i);
554 fb_helper->funcs->gamma_get(crtc, &r,
555 &g, &b,
556 pindex >> 1);
558 for (i = 0; i < 4; i++)
559 fb_helper->funcs->gamma_set(crtc, r,
560 green, b,
561 (pindex >> 1) + i);
565 if (fb->depth != 16)
566 fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
567 return 0;
570 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
572 struct drm_fb_helper *fb_helper = info->par;
573 struct drm_crtc_helper_funcs *crtc_funcs;
574 u16 *red, *green, *blue, *transp;
575 struct drm_crtc *crtc;
576 int i, j, rc = 0;
577 int start;
579 for (i = 0; i < fb_helper->crtc_count; i++) {
580 crtc = fb_helper->crtc_info[i].mode_set.crtc;
581 crtc_funcs = crtc->helper_private;
583 red = cmap->red;
584 green = cmap->green;
585 blue = cmap->blue;
586 transp = cmap->transp;
587 start = cmap->start;
589 for (j = 0; j < cmap->len; j++) {
590 u16 hred, hgreen, hblue, htransp = 0xffff;
592 hred = *red++;
593 hgreen = *green++;
594 hblue = *blue++;
596 if (transp)
597 htransp = *transp++;
599 rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
600 if (rc)
601 return rc;
603 crtc_funcs->load_lut(crtc);
605 return rc;
607 EXPORT_SYMBOL(drm_fb_helper_setcmap);
609 int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
610 struct fb_info *info)
612 struct drm_fb_helper *fb_helper = info->par;
613 struct drm_framebuffer *fb = fb_helper->fb;
614 int depth;
616 if (var->pixclock != 0 || in_dbg_master())
617 return -EINVAL;
619 /* Need to resize the fb object !!! */
620 if (var->bits_per_pixel > fb->bits_per_pixel ||
621 var->xres > fb->width || var->yres > fb->height ||
622 var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
623 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
624 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
625 var->xres, var->yres, var->bits_per_pixel,
626 var->xres_virtual, var->yres_virtual,
627 fb->width, fb->height, fb->bits_per_pixel);
628 return -EINVAL;
631 switch (var->bits_per_pixel) {
632 case 16:
633 depth = (var->green.length == 6) ? 16 : 15;
634 break;
635 case 32:
636 depth = (var->transp.length > 0) ? 32 : 24;
637 break;
638 default:
639 depth = var->bits_per_pixel;
640 break;
643 switch (depth) {
644 case 8:
645 var->red.offset = 0;
646 var->green.offset = 0;
647 var->blue.offset = 0;
648 var->red.length = 8;
649 var->green.length = 8;
650 var->blue.length = 8;
651 var->transp.length = 0;
652 var->transp.offset = 0;
653 break;
654 case 15:
655 var->red.offset = 10;
656 var->green.offset = 5;
657 var->blue.offset = 0;
658 var->red.length = 5;
659 var->green.length = 5;
660 var->blue.length = 5;
661 var->transp.length = 1;
662 var->transp.offset = 15;
663 break;
664 case 16:
665 var->red.offset = 11;
666 var->green.offset = 5;
667 var->blue.offset = 0;
668 var->red.length = 5;
669 var->green.length = 6;
670 var->blue.length = 5;
671 var->transp.length = 0;
672 var->transp.offset = 0;
673 break;
674 case 24:
675 var->red.offset = 16;
676 var->green.offset = 8;
677 var->blue.offset = 0;
678 var->red.length = 8;
679 var->green.length = 8;
680 var->blue.length = 8;
681 var->transp.length = 0;
682 var->transp.offset = 0;
683 break;
684 case 32:
685 var->red.offset = 16;
686 var->green.offset = 8;
687 var->blue.offset = 0;
688 var->red.length = 8;
689 var->green.length = 8;
690 var->blue.length = 8;
691 var->transp.length = 8;
692 var->transp.offset = 24;
693 break;
694 default:
695 return -EINVAL;
697 return 0;
699 EXPORT_SYMBOL(drm_fb_helper_check_var);
701 /* this will let fbcon do the mode init */
702 int drm_fb_helper_set_par(struct fb_info *info)
704 struct drm_fb_helper *fb_helper = info->par;
705 struct drm_device *dev = fb_helper->dev;
706 struct fb_var_screeninfo *var = &info->var;
707 struct drm_crtc *crtc;
708 int ret;
709 int i;
711 if (var->pixclock != 0) {
712 DRM_ERROR("PIXEL CLOCK SET\n");
713 return -EINVAL;
716 mutex_lock(&dev->mode_config.mutex);
717 for (i = 0; i < fb_helper->crtc_count; i++) {
718 crtc = fb_helper->crtc_info[i].mode_set.crtc;
719 ret = crtc->funcs->set_config(&fb_helper->crtc_info[i].mode_set);
720 if (ret) {
721 mutex_unlock(&dev->mode_config.mutex);
722 return ret;
725 mutex_unlock(&dev->mode_config.mutex);
727 if (fb_helper->delayed_hotplug) {
728 fb_helper->delayed_hotplug = false;
729 drm_fb_helper_hotplug_event(fb_helper);
731 return 0;
733 EXPORT_SYMBOL(drm_fb_helper_set_par);
735 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
736 struct fb_info *info)
738 struct drm_fb_helper *fb_helper = info->par;
739 struct drm_device *dev = fb_helper->dev;
740 struct drm_mode_set *modeset;
741 struct drm_crtc *crtc;
742 int ret = 0;
743 int i;
745 mutex_lock(&dev->mode_config.mutex);
746 for (i = 0; i < fb_helper->crtc_count; i++) {
747 crtc = fb_helper->crtc_info[i].mode_set.crtc;
749 modeset = &fb_helper->crtc_info[i].mode_set;
751 modeset->x = var->xoffset;
752 modeset->y = var->yoffset;
754 if (modeset->num_connectors) {
755 ret = crtc->funcs->set_config(modeset);
756 if (!ret) {
757 info->var.xoffset = var->xoffset;
758 info->var.yoffset = var->yoffset;
762 mutex_unlock(&dev->mode_config.mutex);
763 return ret;
765 EXPORT_SYMBOL(drm_fb_helper_pan_display);
767 int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
768 int preferred_bpp)
770 int new_fb = 0;
771 int crtc_count = 0;
772 int i;
773 struct fb_info *info;
774 struct drm_fb_helper_surface_size sizes;
775 int gamma_size = 0;
777 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
778 sizes.surface_depth = 24;
779 sizes.surface_bpp = 32;
780 sizes.fb_width = (unsigned)-1;
781 sizes.fb_height = (unsigned)-1;
783 /* if driver picks 8 or 16 by default use that
784 for both depth/bpp */
785 if (preferred_bpp != sizes.surface_bpp) {
786 sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
788 /* first up get a count of crtcs now in use and new min/maxes width/heights */
789 for (i = 0; i < fb_helper->connector_count; i++) {
790 struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
791 struct drm_cmdline_mode *cmdline_mode;
793 cmdline_mode = &fb_helper_conn->cmdline_mode;
795 if (cmdline_mode->bpp_specified) {
796 switch (cmdline_mode->bpp) {
797 case 8:
798 sizes.surface_depth = sizes.surface_bpp = 8;
799 break;
800 case 15:
801 sizes.surface_depth = 15;
802 sizes.surface_bpp = 16;
803 break;
804 case 16:
805 sizes.surface_depth = sizes.surface_bpp = 16;
806 break;
807 case 24:
808 sizes.surface_depth = sizes.surface_bpp = 24;
809 break;
810 case 32:
811 sizes.surface_depth = 24;
812 sizes.surface_bpp = 32;
813 break;
815 break;
819 crtc_count = 0;
820 for (i = 0; i < fb_helper->crtc_count; i++) {
821 struct drm_display_mode *desired_mode;
822 desired_mode = fb_helper->crtc_info[i].desired_mode;
824 if (desired_mode) {
825 if (gamma_size == 0)
826 gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
827 if (desired_mode->hdisplay < sizes.fb_width)
828 sizes.fb_width = desired_mode->hdisplay;
829 if (desired_mode->vdisplay < sizes.fb_height)
830 sizes.fb_height = desired_mode->vdisplay;
831 if (desired_mode->hdisplay > sizes.surface_width)
832 sizes.surface_width = desired_mode->hdisplay;
833 if (desired_mode->vdisplay > sizes.surface_height)
834 sizes.surface_height = desired_mode->vdisplay;
835 crtc_count++;
839 if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
840 /* hmm everyone went away - assume VGA cable just fell out
841 and will come back later. */
842 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
843 sizes.fb_width = sizes.surface_width = 1024;
844 sizes.fb_height = sizes.surface_height = 768;
847 /* push down into drivers */
848 new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
849 if (new_fb < 0)
850 return new_fb;
852 info = fb_helper->fbdev;
854 /* set the fb pointer */
855 for (i = 0; i < fb_helper->crtc_count; i++) {
856 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
859 if (new_fb) {
860 info->var.pixclock = 0;
861 if (register_framebuffer(info) < 0) {
862 return -EINVAL;
865 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
866 info->fix.id);
868 } else {
869 drm_fb_helper_set_par(info);
872 /* Switch back to kernel console on panic */
873 /* multi card linked list maybe */
874 if (list_empty(&kernel_fb_helper_list)) {
875 printk(KERN_INFO "drm: registered panic notifier\n");
876 atomic_notifier_chain_register(&panic_notifier_list,
877 &paniced);
878 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
880 if (new_fb)
881 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
883 return 0;
885 EXPORT_SYMBOL(drm_fb_helper_single_fb_probe);
887 void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
888 uint32_t depth)
890 info->fix.type = FB_TYPE_PACKED_PIXELS;
891 info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
892 FB_VISUAL_TRUECOLOR;
893 info->fix.mmio_start = 0;
894 info->fix.mmio_len = 0;
895 info->fix.type_aux = 0;
896 info->fix.xpanstep = 1; /* doing it in hw */
897 info->fix.ypanstep = 1; /* doing it in hw */
898 info->fix.ywrapstep = 0;
899 info->fix.accel = FB_ACCEL_NONE;
900 info->fix.type_aux = 0;
902 info->fix.line_length = pitch;
903 return;
905 EXPORT_SYMBOL(drm_fb_helper_fill_fix);
907 void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
908 uint32_t fb_width, uint32_t fb_height)
910 struct drm_framebuffer *fb = fb_helper->fb;
911 info->pseudo_palette = fb_helper->pseudo_palette;
912 info->var.xres_virtual = fb->width;
913 info->var.yres_virtual = fb->height;
914 info->var.bits_per_pixel = fb->bits_per_pixel;
915 info->var.accel_flags = FB_ACCELF_TEXT;
916 info->var.xoffset = 0;
917 info->var.yoffset = 0;
918 info->var.activate = FB_ACTIVATE_NOW;
919 info->var.height = -1;
920 info->var.width = -1;
922 switch (fb->depth) {
923 case 8:
924 info->var.red.offset = 0;
925 info->var.green.offset = 0;
926 info->var.blue.offset = 0;
927 info->var.red.length = 8; /* 8bit DAC */
928 info->var.green.length = 8;
929 info->var.blue.length = 8;
930 info->var.transp.offset = 0;
931 info->var.transp.length = 0;
932 break;
933 case 15:
934 info->var.red.offset = 10;
935 info->var.green.offset = 5;
936 info->var.blue.offset = 0;
937 info->var.red.length = 5;
938 info->var.green.length = 5;
939 info->var.blue.length = 5;
940 info->var.transp.offset = 15;
941 info->var.transp.length = 1;
942 break;
943 case 16:
944 info->var.red.offset = 11;
945 info->var.green.offset = 5;
946 info->var.blue.offset = 0;
947 info->var.red.length = 5;
948 info->var.green.length = 6;
949 info->var.blue.length = 5;
950 info->var.transp.offset = 0;
951 break;
952 case 24:
953 info->var.red.offset = 16;
954 info->var.green.offset = 8;
955 info->var.blue.offset = 0;
956 info->var.red.length = 8;
957 info->var.green.length = 8;
958 info->var.blue.length = 8;
959 info->var.transp.offset = 0;
960 info->var.transp.length = 0;
961 break;
962 case 32:
963 info->var.red.offset = 16;
964 info->var.green.offset = 8;
965 info->var.blue.offset = 0;
966 info->var.red.length = 8;
967 info->var.green.length = 8;
968 info->var.blue.length = 8;
969 info->var.transp.offset = 24;
970 info->var.transp.length = 8;
971 break;
972 default:
973 break;
976 info->var.xres = fb_width;
977 info->var.yres = fb_height;
979 EXPORT_SYMBOL(drm_fb_helper_fill_var);
981 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
982 uint32_t maxX,
983 uint32_t maxY)
985 struct drm_connector *connector;
986 int count = 0;
987 int i;
989 for (i = 0; i < fb_helper->connector_count; i++) {
990 connector = fb_helper->connector_info[i]->connector;
991 count += connector->funcs->fill_modes(connector, maxX, maxY);
994 return count;
997 static struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
999 struct drm_display_mode *mode;
1001 list_for_each_entry(mode, &fb_connector->connector->modes, head) {
1002 if (drm_mode_width(mode) > width ||
1003 drm_mode_height(mode) > height)
1004 continue;
1005 if (mode->type & DRM_MODE_TYPE_PREFERRED)
1006 return mode;
1008 return NULL;
1011 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
1013 struct drm_cmdline_mode *cmdline_mode;
1014 cmdline_mode = &fb_connector->cmdline_mode;
1015 return cmdline_mode->specified;
1018 static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
1019 int width, int height)
1021 struct drm_cmdline_mode *cmdline_mode;
1022 struct drm_display_mode *mode = NULL;
1024 cmdline_mode = &fb_helper_conn->cmdline_mode;
1025 if (cmdline_mode->specified == false)
1026 return mode;
1028 /* attempt to find a matching mode in the list of modes
1029 * we have gotten so far, if not add a CVT mode that conforms
1031 if (cmdline_mode->rb || cmdline_mode->margins)
1032 goto create_mode;
1034 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1035 /* check width/height */
1036 if (mode->hdisplay != cmdline_mode->xres ||
1037 mode->vdisplay != cmdline_mode->yres)
1038 continue;
1040 if (cmdline_mode->refresh_specified) {
1041 if (mode->vrefresh != cmdline_mode->refresh)
1042 continue;
1045 if (cmdline_mode->interlace) {
1046 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
1047 continue;
1049 return mode;
1052 create_mode:
1053 mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
1054 cmdline_mode);
1055 list_add(&mode->head, &fb_helper_conn->connector->modes);
1056 return mode;
1059 static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
1061 bool enable;
1063 if (strict) {
1064 enable = connector->status == connector_status_connected;
1065 } else {
1066 enable = connector->status != connector_status_disconnected;
1068 return enable;
1071 static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
1072 bool *enabled)
1074 bool any_enabled = false;
1075 struct drm_connector *connector;
1076 int i = 0;
1078 for (i = 0; i < fb_helper->connector_count; i++) {
1079 connector = fb_helper->connector_info[i]->connector;
1080 enabled[i] = drm_connector_enabled(connector, true);
1081 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
1082 enabled[i] ? "yes" : "no");
1083 any_enabled |= enabled[i];
1086 if (any_enabled)
1087 return;
1089 for (i = 0; i < fb_helper->connector_count; i++) {
1090 connector = fb_helper->connector_info[i]->connector;
1091 enabled[i] = drm_connector_enabled(connector, false);
1095 static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
1096 struct drm_display_mode **modes,
1097 bool *enabled, int width, int height)
1099 int count, i, j;
1100 bool can_clone = false;
1101 struct drm_fb_helper_connector *fb_helper_conn;
1102 struct drm_display_mode *dmt_mode, *mode;
1104 /* only contemplate cloning in the single crtc case */
1105 if (fb_helper->crtc_count > 1)
1106 return false;
1108 count = 0;
1109 for (i = 0; i < fb_helper->connector_count; i++) {
1110 if (enabled[i])
1111 count++;
1114 /* only contemplate cloning if more than one connector is enabled */
1115 if (count <= 1)
1116 return false;
1118 /* check the command line or if nothing common pick 1024x768 */
1119 can_clone = true;
1120 for (i = 0; i < fb_helper->connector_count; i++) {
1121 if (!enabled[i])
1122 continue;
1123 fb_helper_conn = fb_helper->connector_info[i];
1124 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1125 if (!modes[i]) {
1126 can_clone = false;
1127 break;
1129 for (j = 0; j < i; j++) {
1130 if (!enabled[j])
1131 continue;
1132 if (!drm_mode_equal(modes[j], modes[i]))
1133 can_clone = false;
1137 if (can_clone) {
1138 DRM_DEBUG_KMS("can clone using command line\n");
1139 return true;
1142 /* try and find a 1024x768 mode on each connector */
1143 can_clone = true;
1144 dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60);
1146 for (i = 0; i < fb_helper->connector_count; i++) {
1148 if (!enabled[i])
1149 continue;
1151 fb_helper_conn = fb_helper->connector_info[i];
1152 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1153 if (drm_mode_equal(mode, dmt_mode))
1154 modes[i] = mode;
1156 if (!modes[i])
1157 can_clone = false;
1160 if (can_clone) {
1161 DRM_DEBUG_KMS("can clone using 1024x768\n");
1162 return true;
1164 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1165 return false;
1168 static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
1169 struct drm_display_mode **modes,
1170 bool *enabled, int width, int height)
1172 struct drm_fb_helper_connector *fb_helper_conn;
1173 int i;
1175 for (i = 0; i < fb_helper->connector_count; i++) {
1176 fb_helper_conn = fb_helper->connector_info[i];
1178 if (enabled[i] == false)
1179 continue;
1181 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1182 fb_helper_conn->connector->base.id);
1184 /* got for command line mode first */
1185 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1186 if (!modes[i]) {
1187 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
1188 fb_helper_conn->connector->base.id);
1189 modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
1191 /* No preferred modes, pick one off the list */
1192 if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
1193 list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
1194 break;
1196 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
1197 "none");
1199 return true;
1202 static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
1203 struct drm_fb_helper_crtc **best_crtcs,
1204 struct drm_display_mode **modes,
1205 int n, int width, int height)
1207 int c, o;
1208 struct drm_device *dev = fb_helper->dev;
1209 struct drm_connector *connector;
1210 struct drm_connector_helper_funcs *connector_funcs;
1211 struct drm_encoder *encoder;
1212 struct drm_fb_helper_crtc *best_crtc;
1213 int my_score, best_score, score;
1214 struct drm_fb_helper_crtc **crtcs, *crtc;
1215 struct drm_fb_helper_connector *fb_helper_conn;
1217 if (n == fb_helper->connector_count)
1218 return 0;
1220 fb_helper_conn = fb_helper->connector_info[n];
1221 connector = fb_helper_conn->connector;
1223 best_crtcs[n] = NULL;
1224 best_crtc = NULL;
1225 best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
1226 if (modes[n] == NULL)
1227 return best_score;
1229 crtcs = kzalloc(dev->mode_config.num_connector *
1230 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1231 if (!crtcs)
1232 return best_score;
1234 my_score = 1;
1235 if (connector->status == connector_status_connected)
1236 my_score++;
1237 if (drm_has_cmdline_mode(fb_helper_conn))
1238 my_score++;
1239 if (drm_has_preferred_mode(fb_helper_conn, width, height))
1240 my_score++;
1242 connector_funcs = connector->helper_private;
1243 encoder = connector_funcs->best_encoder(connector);
1244 if (!encoder)
1245 goto out;
1247 /* select a crtc for this connector and then attempt to configure
1248 remaining connectors */
1249 for (c = 0; c < fb_helper->crtc_count; c++) {
1250 crtc = &fb_helper->crtc_info[c];
1252 if ((encoder->possible_crtcs & (1 << c)) == 0) {
1253 continue;
1256 for (o = 0; o < n; o++)
1257 if (best_crtcs[o] == crtc)
1258 break;
1260 if (o < n) {
1261 /* ignore cloning unless only a single crtc */
1262 if (fb_helper->crtc_count > 1)
1263 continue;
1265 if (!drm_mode_equal(modes[o], modes[n]))
1266 continue;
1269 crtcs[n] = crtc;
1270 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1271 score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
1272 width, height);
1273 if (score > best_score) {
1274 best_crtc = crtc;
1275 best_score = score;
1276 memcpy(best_crtcs, crtcs,
1277 dev->mode_config.num_connector *
1278 sizeof(struct drm_fb_helper_crtc *));
1281 out:
1282 kfree(crtcs);
1283 return best_score;
1286 static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
1288 struct drm_device *dev = fb_helper->dev;
1289 struct drm_fb_helper_crtc **crtcs;
1290 struct drm_display_mode **modes;
1291 struct drm_encoder *encoder;
1292 struct drm_mode_set *modeset;
1293 bool *enabled;
1294 int width, height;
1295 int i, ret;
1297 DRM_DEBUG_KMS("\n");
1299 width = dev->mode_config.max_width;
1300 height = dev->mode_config.max_height;
1302 /* clean out all the encoder/crtc combos */
1303 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1304 encoder->crtc = NULL;
1307 crtcs = kcalloc(dev->mode_config.num_connector,
1308 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1309 modes = kcalloc(dev->mode_config.num_connector,
1310 sizeof(struct drm_display_mode *), GFP_KERNEL);
1311 enabled = kcalloc(dev->mode_config.num_connector,
1312 sizeof(bool), GFP_KERNEL);
1314 drm_enable_connectors(fb_helper, enabled);
1316 ret = drm_target_cloned(fb_helper, modes, enabled, width, height);
1317 if (!ret) {
1318 ret = drm_target_preferred(fb_helper, modes, enabled, width, height);
1319 if (!ret)
1320 DRM_ERROR("Unable to find initial modes\n");
1323 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height);
1325 drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1327 /* need to set the modesets up here for use later */
1328 /* fill out the connector<->crtc mappings into the modesets */
1329 for (i = 0; i < fb_helper->crtc_count; i++) {
1330 modeset = &fb_helper->crtc_info[i].mode_set;
1331 modeset->num_connectors = 0;
1334 for (i = 0; i < fb_helper->connector_count; i++) {
1335 struct drm_display_mode *mode = modes[i];
1336 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1337 modeset = &fb_crtc->mode_set;
1339 if (mode && fb_crtc) {
1340 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
1341 mode->name, fb_crtc->mode_set.crtc->base.id);
1342 fb_crtc->desired_mode = mode;
1343 if (modeset->mode)
1344 drm_mode_destroy(dev, modeset->mode);
1345 modeset->mode = drm_mode_duplicate(dev,
1346 fb_crtc->desired_mode);
1347 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
1351 kfree(crtcs);
1352 kfree(modes);
1353 kfree(enabled);
1357 * drm_helper_initial_config - setup a sane initial connector configuration
1358 * @dev: DRM device
1360 * LOCKING:
1361 * Called at init time, must take mode config lock.
1363 * Scan the CRTCs and connectors and try to put together an initial setup.
1364 * At the moment, this is a cloned configuration across all heads with
1365 * a new framebuffer object as the backing store.
1367 * RETURNS:
1368 * Zero if everything went ok, nonzero otherwise.
1370 bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
1372 struct drm_device *dev = fb_helper->dev;
1373 int count = 0;
1375 /* disable all the possible outputs/crtcs before entering KMS mode */
1376 drm_helper_disable_unused_functions(fb_helper->dev);
1378 drm_fb_helper_parse_command_line(fb_helper);
1380 count = drm_fb_helper_probe_connector_modes(fb_helper,
1381 dev->mode_config.max_width,
1382 dev->mode_config.max_height);
1384 * we shouldn't end up with no modes here.
1386 if (count == 0) {
1387 printk(KERN_INFO "No connectors reported connected with modes\n");
1389 drm_setup_crtcs(fb_helper);
1391 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
1393 EXPORT_SYMBOL(drm_fb_helper_initial_config);
1396 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
1397 * probing all the outputs attached to the fb.
1398 * @fb_helper: the drm_fb_helper
1400 * LOCKING:
1401 * Called at runtime, must take mode config lock.
1403 * Scan the connectors attached to the fb_helper and try to put together a
1404 * setup after *notification of a change in output configuration.
1406 * RETURNS:
1407 * 0 on success and a non-zero error code otherwise.
1409 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
1411 struct drm_device *dev = fb_helper->dev;
1412 int count = 0;
1413 u32 max_width, max_height, bpp_sel;
1414 bool bound = false, crtcs_bound = false;
1415 struct drm_crtc *crtc;
1417 if (!fb_helper->fb)
1418 return 0;
1420 mutex_lock(&dev->mode_config.mutex);
1421 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
1422 if (crtc->fb)
1423 crtcs_bound = true;
1424 if (crtc->fb == fb_helper->fb)
1425 bound = true;
1428 if (!bound && crtcs_bound) {
1429 fb_helper->delayed_hotplug = true;
1430 mutex_unlock(&dev->mode_config.mutex);
1431 return 0;
1433 DRM_DEBUG_KMS("\n");
1435 max_width = fb_helper->fb->width;
1436 max_height = fb_helper->fb->height;
1437 bpp_sel = fb_helper->fb->bits_per_pixel;
1439 count = drm_fb_helper_probe_connector_modes(fb_helper, max_width,
1440 max_height);
1441 drm_setup_crtcs(fb_helper);
1442 mutex_unlock(&dev->mode_config.mutex);
1444 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
1446 EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
1448 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
1449 * but the module doesn't depend on any fb console symbols. At least
1450 * attempt to load fbcon to avoid leaving the system without a usable console.
1452 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
1453 static int __init drm_fb_helper_modinit(void)
1455 const char *name = "fbcon";
1456 struct module *fbcon;
1458 mutex_lock(&module_mutex);
1459 fbcon = find_module(name);
1460 mutex_unlock(&module_mutex);
1462 if (!fbcon)
1463 request_module_nowait(name);
1464 return 0;
1467 module_init(drm_fb_helper_modinit);
1468 #endif