535c2cadf4d1c3329e91b45b4cd2d7a5fa9bc182
[deliverable/linux.git] / drivers / gpu / drm / drm_fb_helper.c
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>
5 *
6 * DRM framebuffer helper functions
7 *
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.
17 *
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.
25 *
26 * Authors:
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
29 */
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
32 #include <linux/kernel.h>
33 #include <linux/sysrq.h>
34 #include <linux/slab.h>
35 #include <linux/fb.h>
36 #include <linux/module.h>
37 #include <drm/drmP.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_fb_helper.h>
40 #include <drm/drm_crtc_helper.h>
41
42 MODULE_AUTHOR("David Airlie, Jesse Barnes");
43 MODULE_DESCRIPTION("DRM KMS helper");
44 MODULE_LICENSE("GPL and additional rights");
45
46 static LIST_HEAD(kernel_fb_helper_list);
47
48 /**
49 * DOC: fbdev helpers
50 *
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
54 * interfaces.
55 */
56
57 /* simple single crtc case helper function */
58 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
59 {
60 struct drm_device *dev = fb_helper->dev;
61 struct drm_connector *connector;
62 int i;
63
64 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
65 struct drm_fb_helper_connector *fb_helper_connector;
66
67 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
68 if (!fb_helper_connector)
69 goto fail;
70
71 fb_helper_connector->connector = connector;
72 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
73 }
74 return 0;
75 fail:
76 for (i = 0; i < fb_helper->connector_count; i++) {
77 kfree(fb_helper->connector_info[i]);
78 fb_helper->connector_info[i] = NULL;
79 }
80 fb_helper->connector_count = 0;
81 return -ENOMEM;
82 }
83 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
84
85 static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
86 {
87 struct drm_fb_helper_connector *fb_helper_conn;
88 int i;
89
90 for (i = 0; i < fb_helper->connector_count; i++) {
91 struct drm_cmdline_mode *mode;
92 struct drm_connector *connector;
93 char *option = NULL;
94
95 fb_helper_conn = fb_helper->connector_info[i];
96 connector = fb_helper_conn->connector;
97 mode = &fb_helper_conn->cmdline_mode;
98
99 /* do something on return - turn off connector maybe */
100 if (fb_get_options(drm_get_connector_name(connector), &option))
101 continue;
102
103 if (drm_mode_parse_command_line_for_connector(option,
104 connector,
105 mode)) {
106 if (mode->force) {
107 const char *s;
108 switch (mode->force) {
109 case DRM_FORCE_OFF:
110 s = "OFF";
111 break;
112 case DRM_FORCE_ON_DIGITAL:
113 s = "ON - dig";
114 break;
115 default:
116 case DRM_FORCE_ON:
117 s = "ON";
118 break;
119 }
120
121 DRM_INFO("forcing %s connector %s\n",
122 drm_get_connector_name(connector), s);
123 connector->force = mode->force;
124 }
125
126 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
127 drm_get_connector_name(connector),
128 mode->xres, mode->yres,
129 mode->refresh_specified ? mode->refresh : 60,
130 mode->rb ? " reduced blanking" : "",
131 mode->margins ? " with margins" : "",
132 mode->interlace ? " interlaced" : "");
133 }
134
135 }
136 return 0;
137 }
138
139 static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper)
140 {
141 uint16_t *r_base, *g_base, *b_base;
142 int i;
143
144 r_base = crtc->gamma_store;
145 g_base = r_base + crtc->gamma_size;
146 b_base = g_base + crtc->gamma_size;
147
148 for (i = 0; i < crtc->gamma_size; i++)
149 helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i);
150 }
151
152 static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
153 {
154 uint16_t *r_base, *g_base, *b_base;
155
156 if (crtc->funcs->gamma_set == NULL)
157 return;
158
159 r_base = crtc->gamma_store;
160 g_base = r_base + crtc->gamma_size;
161 b_base = g_base + crtc->gamma_size;
162
163 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
164 }
165
166 int drm_fb_helper_debug_enter(struct fb_info *info)
167 {
168 struct drm_fb_helper *helper = info->par;
169 struct drm_crtc_helper_funcs *funcs;
170 int i;
171
172 if (list_empty(&kernel_fb_helper_list))
173 return false;
174
175 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
176 for (i = 0; i < helper->crtc_count; i++) {
177 struct drm_mode_set *mode_set =
178 &helper->crtc_info[i].mode_set;
179
180 if (!mode_set->crtc->enabled)
181 continue;
182
183 funcs = mode_set->crtc->helper_private;
184 drm_fb_helper_save_lut_atomic(mode_set->crtc, helper);
185 funcs->mode_set_base_atomic(mode_set->crtc,
186 mode_set->fb,
187 mode_set->x,
188 mode_set->y,
189 ENTER_ATOMIC_MODE_SET);
190 }
191 }
192
193 return 0;
194 }
195 EXPORT_SYMBOL(drm_fb_helper_debug_enter);
196
197 /* Find the real fb for a given fb helper CRTC */
198 static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
199 {
200 struct drm_device *dev = crtc->dev;
201 struct drm_crtc *c;
202
203 list_for_each_entry(c, &dev->mode_config.crtc_list, head) {
204 if (crtc->base.id == c->base.id)
205 return c->fb;
206 }
207
208 return NULL;
209 }
210
211 int drm_fb_helper_debug_leave(struct fb_info *info)
212 {
213 struct drm_fb_helper *helper = info->par;
214 struct drm_crtc *crtc;
215 struct drm_crtc_helper_funcs *funcs;
216 struct drm_framebuffer *fb;
217 int i;
218
219 for (i = 0; i < helper->crtc_count; i++) {
220 struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
221 crtc = mode_set->crtc;
222 funcs = crtc->helper_private;
223 fb = drm_mode_config_fb(crtc);
224
225 if (!crtc->enabled)
226 continue;
227
228 if (!fb) {
229 DRM_ERROR("no fb to restore??\n");
230 continue;
231 }
232
233 drm_fb_helper_restore_lut_atomic(mode_set->crtc);
234 funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x,
235 crtc->y, LEAVE_ATOMIC_MODE_SET);
236 }
237
238 return 0;
239 }
240 EXPORT_SYMBOL(drm_fb_helper_debug_leave);
241
242 /**
243 * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
244 * @fb_helper: fbcon to restore
245 *
246 * This should be called from driver's drm->lastclose callback when implementing
247 * an fbcon on top of kms using this helper. This ensures that the user isn't
248 * greeted with a black screen when e.g. X dies.
249 */
250 bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
251 {
252 bool error = false;
253 int i, ret;
254
255 drm_warn_on_modeset_not_all_locked(fb_helper->dev);
256
257 for (i = 0; i < fb_helper->crtc_count; i++) {
258 struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
259 ret = drm_mode_set_config_internal(mode_set);
260 if (ret)
261 error = true;
262 }
263 return error;
264 }
265 EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode);
266
267 /*
268 * restore fbcon display for all kms driver's using this helper, used for sysrq
269 * and panic handling.
270 */
271 static bool drm_fb_helper_force_kernel_mode(void)
272 {
273 bool ret, error = false;
274 struct drm_fb_helper *helper;
275
276 if (list_empty(&kernel_fb_helper_list))
277 return false;
278
279 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
280 if (helper->dev->switch_power_state == DRM_SWITCH_POWER_OFF)
281 continue;
282
283 ret = drm_fb_helper_restore_fbdev_mode(helper);
284 if (ret)
285 error = true;
286 }
287 return error;
288 }
289
290 static int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
291 void *panic_str)
292 {
293 /*
294 * It's a waste of time and effort to switch back to text console
295 * if the kernel should reboot before panic messages can be seen.
296 */
297 if (panic_timeout < 0)
298 return 0;
299
300 pr_err("panic occurred, switching back to text console\n");
301 return drm_fb_helper_force_kernel_mode();
302 }
303
304 static struct notifier_block paniced = {
305 .notifier_call = drm_fb_helper_panic,
306 };
307
308 static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
309 {
310 struct drm_device *dev = fb_helper->dev;
311 struct drm_crtc *crtc;
312 int bound = 0, crtcs_bound = 0;
313
314 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
315 if (crtc->fb)
316 crtcs_bound++;
317 if (crtc->fb == fb_helper->fb)
318 bound++;
319 }
320
321 if (bound < crtcs_bound)
322 return false;
323 return true;
324 }
325
326 #ifdef CONFIG_MAGIC_SYSRQ
327 static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
328 {
329 bool ret;
330 ret = drm_fb_helper_force_kernel_mode();
331 if (ret == true)
332 DRM_ERROR("Failed to restore crtc configuration\n");
333 }
334 static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
335
336 static void drm_fb_helper_sysrq(int dummy1)
337 {
338 schedule_work(&drm_fb_helper_restore_work);
339 }
340
341 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
342 .handler = drm_fb_helper_sysrq,
343 .help_msg = "force-fb(V)",
344 .action_msg = "Restore framebuffer console",
345 };
346 #else
347 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
348 #endif
349
350 static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
351 {
352 struct drm_fb_helper *fb_helper = info->par;
353 struct drm_device *dev = fb_helper->dev;
354 struct drm_crtc *crtc;
355 struct drm_connector *connector;
356 int i, j;
357
358 /*
359 * For each CRTC in this fb, turn the connectors on/off.
360 */
361 drm_modeset_lock_all(dev);
362 if (!drm_fb_helper_is_bound(fb_helper)) {
363 drm_modeset_unlock_all(dev);
364 return;
365 }
366
367 for (i = 0; i < fb_helper->crtc_count; i++) {
368 crtc = fb_helper->crtc_info[i].mode_set.crtc;
369
370 if (!crtc->enabled)
371 continue;
372
373 /* Walk the connectors & encoders on this fb turning them on/off */
374 for (j = 0; j < fb_helper->connector_count; j++) {
375 connector = fb_helper->connector_info[j]->connector;
376 connector->funcs->dpms(connector, dpms_mode);
377 drm_object_property_set_value(&connector->base,
378 dev->mode_config.dpms_property, dpms_mode);
379 }
380 }
381 drm_modeset_unlock_all(dev);
382 }
383
384 int drm_fb_helper_blank(int blank, struct fb_info *info)
385 {
386 switch (blank) {
387 /* Display: On; HSync: On, VSync: On */
388 case FB_BLANK_UNBLANK:
389 drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON);
390 break;
391 /* Display: Off; HSync: On, VSync: On */
392 case FB_BLANK_NORMAL:
393 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
394 break;
395 /* Display: Off; HSync: Off, VSync: On */
396 case FB_BLANK_HSYNC_SUSPEND:
397 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
398 break;
399 /* Display: Off; HSync: On, VSync: Off */
400 case FB_BLANK_VSYNC_SUSPEND:
401 drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND);
402 break;
403 /* Display: Off; HSync: Off, VSync: Off */
404 case FB_BLANK_POWERDOWN:
405 drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF);
406 break;
407 }
408 return 0;
409 }
410 EXPORT_SYMBOL(drm_fb_helper_blank);
411
412 static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
413 {
414 int i;
415
416 for (i = 0; i < helper->connector_count; i++)
417 kfree(helper->connector_info[i]);
418 kfree(helper->connector_info);
419 for (i = 0; i < helper->crtc_count; i++) {
420 kfree(helper->crtc_info[i].mode_set.connectors);
421 if (helper->crtc_info[i].mode_set.mode)
422 drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode);
423 }
424 kfree(helper->crtc_info);
425 }
426
427 int drm_fb_helper_init(struct drm_device *dev,
428 struct drm_fb_helper *fb_helper,
429 int crtc_count, int max_conn_count)
430 {
431 struct drm_crtc *crtc;
432 int i;
433
434 fb_helper->dev = dev;
435
436 INIT_LIST_HEAD(&fb_helper->kernel_fb_list);
437
438 fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
439 if (!fb_helper->crtc_info)
440 return -ENOMEM;
441
442 fb_helper->crtc_count = crtc_count;
443 fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
444 if (!fb_helper->connector_info) {
445 kfree(fb_helper->crtc_info);
446 return -ENOMEM;
447 }
448 fb_helper->connector_count = 0;
449
450 for (i = 0; i < crtc_count; i++) {
451 fb_helper->crtc_info[i].mode_set.connectors =
452 kcalloc(max_conn_count,
453 sizeof(struct drm_connector *),
454 GFP_KERNEL);
455
456 if (!fb_helper->crtc_info[i].mode_set.connectors)
457 goto out_free;
458 fb_helper->crtc_info[i].mode_set.num_connectors = 0;
459 }
460
461 i = 0;
462 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
463 fb_helper->crtc_info[i].mode_set.crtc = crtc;
464 i++;
465 }
466
467 return 0;
468 out_free:
469 drm_fb_helper_crtc_free(fb_helper);
470 return -ENOMEM;
471 }
472 EXPORT_SYMBOL(drm_fb_helper_init);
473
474 void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
475 {
476 if (!list_empty(&fb_helper->kernel_fb_list)) {
477 list_del(&fb_helper->kernel_fb_list);
478 if (list_empty(&kernel_fb_helper_list)) {
479 pr_info("drm: unregistered panic notifier\n");
480 atomic_notifier_chain_unregister(&panic_notifier_list,
481 &paniced);
482 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
483 }
484 }
485
486 drm_fb_helper_crtc_free(fb_helper);
487
488 }
489 EXPORT_SYMBOL(drm_fb_helper_fini);
490
491 static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
492 u16 blue, u16 regno, struct fb_info *info)
493 {
494 struct drm_fb_helper *fb_helper = info->par;
495 struct drm_framebuffer *fb = fb_helper->fb;
496 int pindex;
497
498 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
499 u32 *palette;
500 u32 value;
501 /* place color in psuedopalette */
502 if (regno > 16)
503 return -EINVAL;
504 palette = (u32 *)info->pseudo_palette;
505 red >>= (16 - info->var.red.length);
506 green >>= (16 - info->var.green.length);
507 blue >>= (16 - info->var.blue.length);
508 value = (red << info->var.red.offset) |
509 (green << info->var.green.offset) |
510 (blue << info->var.blue.offset);
511 if (info->var.transp.length > 0) {
512 u32 mask = (1 << info->var.transp.length) - 1;
513 mask <<= info->var.transp.offset;
514 value |= mask;
515 }
516 palette[regno] = value;
517 return 0;
518 }
519
520 pindex = regno;
521
522 if (fb->bits_per_pixel == 16) {
523 pindex = regno << 3;
524
525 if (fb->depth == 16 && regno > 63)
526 return -EINVAL;
527 if (fb->depth == 15 && regno > 31)
528 return -EINVAL;
529
530 if (fb->depth == 16) {
531 u16 r, g, b;
532 int i;
533 if (regno < 32) {
534 for (i = 0; i < 8; i++)
535 fb_helper->funcs->gamma_set(crtc, red,
536 green, blue, pindex + i);
537 }
538
539 fb_helper->funcs->gamma_get(crtc, &r,
540 &g, &b,
541 pindex >> 1);
542
543 for (i = 0; i < 4; i++)
544 fb_helper->funcs->gamma_set(crtc, r,
545 green, b,
546 (pindex >> 1) + i);
547 }
548 }
549
550 if (fb->depth != 16)
551 fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
552 return 0;
553 }
554
555 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
556 {
557 struct drm_fb_helper *fb_helper = info->par;
558 struct drm_crtc_helper_funcs *crtc_funcs;
559 u16 *red, *green, *blue, *transp;
560 struct drm_crtc *crtc;
561 int i, j, rc = 0;
562 int start;
563
564 for (i = 0; i < fb_helper->crtc_count; i++) {
565 crtc = fb_helper->crtc_info[i].mode_set.crtc;
566 crtc_funcs = crtc->helper_private;
567
568 red = cmap->red;
569 green = cmap->green;
570 blue = cmap->blue;
571 transp = cmap->transp;
572 start = cmap->start;
573
574 for (j = 0; j < cmap->len; j++) {
575 u16 hred, hgreen, hblue, htransp = 0xffff;
576
577 hred = *red++;
578 hgreen = *green++;
579 hblue = *blue++;
580
581 if (transp)
582 htransp = *transp++;
583
584 rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
585 if (rc)
586 return rc;
587 }
588 crtc_funcs->load_lut(crtc);
589 }
590 return rc;
591 }
592 EXPORT_SYMBOL(drm_fb_helper_setcmap);
593
594 int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
595 struct fb_info *info)
596 {
597 struct drm_fb_helper *fb_helper = info->par;
598 struct drm_framebuffer *fb = fb_helper->fb;
599 int depth;
600
601 if (var->pixclock != 0 || in_dbg_master())
602 return -EINVAL;
603
604 /* Need to resize the fb object !!! */
605 if (var->bits_per_pixel > fb->bits_per_pixel ||
606 var->xres > fb->width || var->yres > fb->height ||
607 var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
608 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
609 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
610 var->xres, var->yres, var->bits_per_pixel,
611 var->xres_virtual, var->yres_virtual,
612 fb->width, fb->height, fb->bits_per_pixel);
613 return -EINVAL;
614 }
615
616 switch (var->bits_per_pixel) {
617 case 16:
618 depth = (var->green.length == 6) ? 16 : 15;
619 break;
620 case 32:
621 depth = (var->transp.length > 0) ? 32 : 24;
622 break;
623 default:
624 depth = var->bits_per_pixel;
625 break;
626 }
627
628 switch (depth) {
629 case 8:
630 var->red.offset = 0;
631 var->green.offset = 0;
632 var->blue.offset = 0;
633 var->red.length = 8;
634 var->green.length = 8;
635 var->blue.length = 8;
636 var->transp.length = 0;
637 var->transp.offset = 0;
638 break;
639 case 15:
640 var->red.offset = 10;
641 var->green.offset = 5;
642 var->blue.offset = 0;
643 var->red.length = 5;
644 var->green.length = 5;
645 var->blue.length = 5;
646 var->transp.length = 1;
647 var->transp.offset = 15;
648 break;
649 case 16:
650 var->red.offset = 11;
651 var->green.offset = 5;
652 var->blue.offset = 0;
653 var->red.length = 5;
654 var->green.length = 6;
655 var->blue.length = 5;
656 var->transp.length = 0;
657 var->transp.offset = 0;
658 break;
659 case 24:
660 var->red.offset = 16;
661 var->green.offset = 8;
662 var->blue.offset = 0;
663 var->red.length = 8;
664 var->green.length = 8;
665 var->blue.length = 8;
666 var->transp.length = 0;
667 var->transp.offset = 0;
668 break;
669 case 32:
670 var->red.offset = 16;
671 var->green.offset = 8;
672 var->blue.offset = 0;
673 var->red.length = 8;
674 var->green.length = 8;
675 var->blue.length = 8;
676 var->transp.length = 8;
677 var->transp.offset = 24;
678 break;
679 default:
680 return -EINVAL;
681 }
682 return 0;
683 }
684 EXPORT_SYMBOL(drm_fb_helper_check_var);
685
686 /* this will let fbcon do the mode init */
687 int drm_fb_helper_set_par(struct fb_info *info)
688 {
689 struct drm_fb_helper *fb_helper = info->par;
690 struct drm_device *dev = fb_helper->dev;
691 struct fb_var_screeninfo *var = &info->var;
692 int ret;
693 int i;
694
695 if (var->pixclock != 0) {
696 DRM_ERROR("PIXEL CLOCK SET\n");
697 return -EINVAL;
698 }
699
700 drm_modeset_lock_all(dev);
701 for (i = 0; i < fb_helper->crtc_count; i++) {
702 ret = drm_mode_set_config_internal(&fb_helper->crtc_info[i].mode_set);
703 if (ret) {
704 drm_modeset_unlock_all(dev);
705 return ret;
706 }
707 }
708 drm_modeset_unlock_all(dev);
709
710 if (fb_helper->delayed_hotplug) {
711 fb_helper->delayed_hotplug = false;
712 drm_fb_helper_hotplug_event(fb_helper);
713 }
714 return 0;
715 }
716 EXPORT_SYMBOL(drm_fb_helper_set_par);
717
718 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
719 struct fb_info *info)
720 {
721 struct drm_fb_helper *fb_helper = info->par;
722 struct drm_device *dev = fb_helper->dev;
723 struct drm_mode_set *modeset;
724 struct drm_crtc *crtc;
725 int ret = 0;
726 int i;
727
728 drm_modeset_lock_all(dev);
729 if (!drm_fb_helper_is_bound(fb_helper)) {
730 drm_modeset_unlock_all(dev);
731 return -EBUSY;
732 }
733
734 for (i = 0; i < fb_helper->crtc_count; i++) {
735 crtc = fb_helper->crtc_info[i].mode_set.crtc;
736
737 modeset = &fb_helper->crtc_info[i].mode_set;
738
739 modeset->x = var->xoffset;
740 modeset->y = var->yoffset;
741
742 if (modeset->num_connectors) {
743 ret = drm_mode_set_config_internal(modeset);
744 if (!ret) {
745 info->var.xoffset = var->xoffset;
746 info->var.yoffset = var->yoffset;
747 }
748 }
749 }
750 drm_modeset_unlock_all(dev);
751 return ret;
752 }
753 EXPORT_SYMBOL(drm_fb_helper_pan_display);
754
755 static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
756 int preferred_bpp)
757 {
758 int new_fb = 0;
759 int crtc_count = 0;
760 int i;
761 struct fb_info *info;
762 struct drm_fb_helper_surface_size sizes;
763 int gamma_size = 0;
764
765 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
766 sizes.surface_depth = 24;
767 sizes.surface_bpp = 32;
768 sizes.fb_width = (unsigned)-1;
769 sizes.fb_height = (unsigned)-1;
770
771 /* if driver picks 8 or 16 by default use that
772 for both depth/bpp */
773 if (preferred_bpp != sizes.surface_bpp)
774 sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
775
776 /* first up get a count of crtcs now in use and new min/maxes width/heights */
777 for (i = 0; i < fb_helper->connector_count; i++) {
778 struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
779 struct drm_cmdline_mode *cmdline_mode;
780
781 cmdline_mode = &fb_helper_conn->cmdline_mode;
782
783 if (cmdline_mode->bpp_specified) {
784 switch (cmdline_mode->bpp) {
785 case 8:
786 sizes.surface_depth = sizes.surface_bpp = 8;
787 break;
788 case 15:
789 sizes.surface_depth = 15;
790 sizes.surface_bpp = 16;
791 break;
792 case 16:
793 sizes.surface_depth = sizes.surface_bpp = 16;
794 break;
795 case 24:
796 sizes.surface_depth = sizes.surface_bpp = 24;
797 break;
798 case 32:
799 sizes.surface_depth = 24;
800 sizes.surface_bpp = 32;
801 break;
802 }
803 break;
804 }
805 }
806
807 crtc_count = 0;
808 for (i = 0; i < fb_helper->crtc_count; i++) {
809 struct drm_display_mode *desired_mode;
810 desired_mode = fb_helper->crtc_info[i].desired_mode;
811
812 if (desired_mode) {
813 if (gamma_size == 0)
814 gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
815 if (desired_mode->hdisplay < sizes.fb_width)
816 sizes.fb_width = desired_mode->hdisplay;
817 if (desired_mode->vdisplay < sizes.fb_height)
818 sizes.fb_height = desired_mode->vdisplay;
819 if (desired_mode->hdisplay > sizes.surface_width)
820 sizes.surface_width = desired_mode->hdisplay;
821 if (desired_mode->vdisplay > sizes.surface_height)
822 sizes.surface_height = desired_mode->vdisplay;
823 crtc_count++;
824 }
825 }
826
827 if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
828 /* hmm everyone went away - assume VGA cable just fell out
829 and will come back later. */
830 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
831 sizes.fb_width = sizes.surface_width = 1024;
832 sizes.fb_height = sizes.surface_height = 768;
833 }
834
835 /* push down into drivers */
836 new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
837 if (new_fb < 0)
838 return new_fb;
839
840 info = fb_helper->fbdev;
841
842 /*
843 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
844 * events, but at init time drm_setup_crtcs needs to be called before
845 * the fb is allocated (since we need to figure out the desired size of
846 * the fb before we can allocate it ...). Hence we need to fix things up
847 * here again.
848 */
849 for (i = 0; i < fb_helper->crtc_count; i++)
850 if (fb_helper->crtc_info[i].mode_set.num_connectors)
851 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
852
853
854 if (new_fb) {
855 info->var.pixclock = 0;
856 if (register_framebuffer(info) < 0)
857 return -EINVAL;
858
859 dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n",
860 info->node, info->fix.id);
861
862 }
863
864 /* Switch back to kernel console on panic */
865 /* multi card linked list maybe */
866 if (list_empty(&kernel_fb_helper_list)) {
867 dev_info(fb_helper->dev->dev, "registered panic notifier\n");
868 atomic_notifier_chain_register(&panic_notifier_list,
869 &paniced);
870 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
871 }
872 if (new_fb)
873 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
874
875 return 0;
876 }
877
878 void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
879 uint32_t depth)
880 {
881 info->fix.type = FB_TYPE_PACKED_PIXELS;
882 info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
883 FB_VISUAL_TRUECOLOR;
884 info->fix.mmio_start = 0;
885 info->fix.mmio_len = 0;
886 info->fix.type_aux = 0;
887 info->fix.xpanstep = 1; /* doing it in hw */
888 info->fix.ypanstep = 1; /* doing it in hw */
889 info->fix.ywrapstep = 0;
890 info->fix.accel = FB_ACCEL_NONE;
891 info->fix.type_aux = 0;
892
893 info->fix.line_length = pitch;
894 return;
895 }
896 EXPORT_SYMBOL(drm_fb_helper_fill_fix);
897
898 void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
899 uint32_t fb_width, uint32_t fb_height)
900 {
901 struct drm_framebuffer *fb = fb_helper->fb;
902 info->pseudo_palette = fb_helper->pseudo_palette;
903 info->var.xres_virtual = fb->width;
904 info->var.yres_virtual = fb->height;
905 info->var.bits_per_pixel = fb->bits_per_pixel;
906 info->var.accel_flags = FB_ACCELF_TEXT;
907 info->var.xoffset = 0;
908 info->var.yoffset = 0;
909 info->var.activate = FB_ACTIVATE_NOW;
910 info->var.height = -1;
911 info->var.width = -1;
912
913 switch (fb->depth) {
914 case 8:
915 info->var.red.offset = 0;
916 info->var.green.offset = 0;
917 info->var.blue.offset = 0;
918 info->var.red.length = 8; /* 8bit DAC */
919 info->var.green.length = 8;
920 info->var.blue.length = 8;
921 info->var.transp.offset = 0;
922 info->var.transp.length = 0;
923 break;
924 case 15:
925 info->var.red.offset = 10;
926 info->var.green.offset = 5;
927 info->var.blue.offset = 0;
928 info->var.red.length = 5;
929 info->var.green.length = 5;
930 info->var.blue.length = 5;
931 info->var.transp.offset = 15;
932 info->var.transp.length = 1;
933 break;
934 case 16:
935 info->var.red.offset = 11;
936 info->var.green.offset = 5;
937 info->var.blue.offset = 0;
938 info->var.red.length = 5;
939 info->var.green.length = 6;
940 info->var.blue.length = 5;
941 info->var.transp.offset = 0;
942 break;
943 case 24:
944 info->var.red.offset = 16;
945 info->var.green.offset = 8;
946 info->var.blue.offset = 0;
947 info->var.red.length = 8;
948 info->var.green.length = 8;
949 info->var.blue.length = 8;
950 info->var.transp.offset = 0;
951 info->var.transp.length = 0;
952 break;
953 case 32:
954 info->var.red.offset = 16;
955 info->var.green.offset = 8;
956 info->var.blue.offset = 0;
957 info->var.red.length = 8;
958 info->var.green.length = 8;
959 info->var.blue.length = 8;
960 info->var.transp.offset = 24;
961 info->var.transp.length = 8;
962 break;
963 default:
964 break;
965 }
966
967 info->var.xres = fb_width;
968 info->var.yres = fb_height;
969 }
970 EXPORT_SYMBOL(drm_fb_helper_fill_var);
971
972 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
973 uint32_t maxX,
974 uint32_t maxY)
975 {
976 struct drm_connector *connector;
977 int count = 0;
978 int i;
979
980 for (i = 0; i < fb_helper->connector_count; i++) {
981 connector = fb_helper->connector_info[i]->connector;
982 count += connector->funcs->fill_modes(connector, maxX, maxY);
983 }
984
985 return count;
986 }
987
988 static struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
989 {
990 struct drm_display_mode *mode;
991
992 list_for_each_entry(mode, &fb_connector->connector->modes, head) {
993 if (drm_mode_width(mode) > width ||
994 drm_mode_height(mode) > height)
995 continue;
996 if (mode->type & DRM_MODE_TYPE_PREFERRED)
997 return mode;
998 }
999 return NULL;
1000 }
1001
1002 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
1003 {
1004 struct drm_cmdline_mode *cmdline_mode;
1005 cmdline_mode = &fb_connector->cmdline_mode;
1006 return cmdline_mode->specified;
1007 }
1008
1009 static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
1010 int width, int height)
1011 {
1012 struct drm_cmdline_mode *cmdline_mode;
1013 struct drm_display_mode *mode = NULL;
1014
1015 cmdline_mode = &fb_helper_conn->cmdline_mode;
1016 if (cmdline_mode->specified == false)
1017 return mode;
1018
1019 /* attempt to find a matching mode in the list of modes
1020 * we have gotten so far, if not add a CVT mode that conforms
1021 */
1022 if (cmdline_mode->rb || cmdline_mode->margins)
1023 goto create_mode;
1024
1025 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1026 /* check width/height */
1027 if (mode->hdisplay != cmdline_mode->xres ||
1028 mode->vdisplay != cmdline_mode->yres)
1029 continue;
1030
1031 if (cmdline_mode->refresh_specified) {
1032 if (mode->vrefresh != cmdline_mode->refresh)
1033 continue;
1034 }
1035
1036 if (cmdline_mode->interlace) {
1037 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
1038 continue;
1039 }
1040 return mode;
1041 }
1042
1043 create_mode:
1044 mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
1045 cmdline_mode);
1046 list_add(&mode->head, &fb_helper_conn->connector->modes);
1047 return mode;
1048 }
1049
1050 static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
1051 {
1052 bool enable;
1053
1054 if (strict)
1055 enable = connector->status == connector_status_connected;
1056 else
1057 enable = connector->status != connector_status_disconnected;
1058
1059 return enable;
1060 }
1061
1062 static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
1063 bool *enabled)
1064 {
1065 bool any_enabled = false;
1066 struct drm_connector *connector;
1067 int i = 0;
1068
1069 for (i = 0; i < fb_helper->connector_count; i++) {
1070 connector = fb_helper->connector_info[i]->connector;
1071 enabled[i] = drm_connector_enabled(connector, true);
1072 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
1073 enabled[i] ? "yes" : "no");
1074 any_enabled |= enabled[i];
1075 }
1076
1077 if (any_enabled)
1078 return;
1079
1080 for (i = 0; i < fb_helper->connector_count; i++) {
1081 connector = fb_helper->connector_info[i]->connector;
1082 enabled[i] = drm_connector_enabled(connector, false);
1083 }
1084 }
1085
1086 static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
1087 struct drm_display_mode **modes,
1088 bool *enabled, int width, int height)
1089 {
1090 int count, i, j;
1091 bool can_clone = false;
1092 struct drm_fb_helper_connector *fb_helper_conn;
1093 struct drm_display_mode *dmt_mode, *mode;
1094
1095 /* only contemplate cloning in the single crtc case */
1096 if (fb_helper->crtc_count > 1)
1097 return false;
1098
1099 count = 0;
1100 for (i = 0; i < fb_helper->connector_count; i++) {
1101 if (enabled[i])
1102 count++;
1103 }
1104
1105 /* only contemplate cloning if more than one connector is enabled */
1106 if (count <= 1)
1107 return false;
1108
1109 /* check the command line or if nothing common pick 1024x768 */
1110 can_clone = true;
1111 for (i = 0; i < fb_helper->connector_count; i++) {
1112 if (!enabled[i])
1113 continue;
1114 fb_helper_conn = fb_helper->connector_info[i];
1115 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1116 if (!modes[i]) {
1117 can_clone = false;
1118 break;
1119 }
1120 for (j = 0; j < i; j++) {
1121 if (!enabled[j])
1122 continue;
1123 if (!drm_mode_equal(modes[j], modes[i]))
1124 can_clone = false;
1125 }
1126 }
1127
1128 if (can_clone) {
1129 DRM_DEBUG_KMS("can clone using command line\n");
1130 return true;
1131 }
1132
1133 /* try and find a 1024x768 mode on each connector */
1134 can_clone = true;
1135 dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false);
1136
1137 for (i = 0; i < fb_helper->connector_count; i++) {
1138
1139 if (!enabled[i])
1140 continue;
1141
1142 fb_helper_conn = fb_helper->connector_info[i];
1143 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1144 if (drm_mode_equal(mode, dmt_mode))
1145 modes[i] = mode;
1146 }
1147 if (!modes[i])
1148 can_clone = false;
1149 }
1150
1151 if (can_clone) {
1152 DRM_DEBUG_KMS("can clone using 1024x768\n");
1153 return true;
1154 }
1155 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1156 return false;
1157 }
1158
1159 static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
1160 struct drm_display_mode **modes,
1161 bool *enabled, int width, int height)
1162 {
1163 struct drm_fb_helper_connector *fb_helper_conn;
1164 int i;
1165
1166 for (i = 0; i < fb_helper->connector_count; i++) {
1167 fb_helper_conn = fb_helper->connector_info[i];
1168
1169 if (enabled[i] == false)
1170 continue;
1171
1172 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1173 fb_helper_conn->connector->base.id);
1174
1175 /* got for command line mode first */
1176 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1177 if (!modes[i]) {
1178 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
1179 fb_helper_conn->connector->base.id);
1180 modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
1181 }
1182 /* No preferred modes, pick one off the list */
1183 if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
1184 list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
1185 break;
1186 }
1187 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
1188 "none");
1189 }
1190 return true;
1191 }
1192
1193 static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
1194 struct drm_fb_helper_crtc **best_crtcs,
1195 struct drm_display_mode **modes,
1196 int n, int width, int height)
1197 {
1198 int c, o;
1199 struct drm_device *dev = fb_helper->dev;
1200 struct drm_connector *connector;
1201 struct drm_connector_helper_funcs *connector_funcs;
1202 struct drm_encoder *encoder;
1203 struct drm_fb_helper_crtc *best_crtc;
1204 int my_score, best_score, score;
1205 struct drm_fb_helper_crtc **crtcs, *crtc;
1206 struct drm_fb_helper_connector *fb_helper_conn;
1207
1208 if (n == fb_helper->connector_count)
1209 return 0;
1210
1211 fb_helper_conn = fb_helper->connector_info[n];
1212 connector = fb_helper_conn->connector;
1213
1214 best_crtcs[n] = NULL;
1215 best_crtc = NULL;
1216 best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
1217 if (modes[n] == NULL)
1218 return best_score;
1219
1220 crtcs = kzalloc(dev->mode_config.num_connector *
1221 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1222 if (!crtcs)
1223 return best_score;
1224
1225 my_score = 1;
1226 if (connector->status == connector_status_connected)
1227 my_score++;
1228 if (drm_has_cmdline_mode(fb_helper_conn))
1229 my_score++;
1230 if (drm_has_preferred_mode(fb_helper_conn, width, height))
1231 my_score++;
1232
1233 connector_funcs = connector->helper_private;
1234 encoder = connector_funcs->best_encoder(connector);
1235 if (!encoder)
1236 goto out;
1237
1238 /* select a crtc for this connector and then attempt to configure
1239 remaining connectors */
1240 for (c = 0; c < fb_helper->crtc_count; c++) {
1241 crtc = &fb_helper->crtc_info[c];
1242
1243 if ((encoder->possible_crtcs & (1 << c)) == 0)
1244 continue;
1245
1246 for (o = 0; o < n; o++)
1247 if (best_crtcs[o] == crtc)
1248 break;
1249
1250 if (o < n) {
1251 /* ignore cloning unless only a single crtc */
1252 if (fb_helper->crtc_count > 1)
1253 continue;
1254
1255 if (!drm_mode_equal(modes[o], modes[n]))
1256 continue;
1257 }
1258
1259 crtcs[n] = crtc;
1260 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1261 score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
1262 width, height);
1263 if (score > best_score) {
1264 best_crtc = crtc;
1265 best_score = score;
1266 memcpy(best_crtcs, crtcs,
1267 dev->mode_config.num_connector *
1268 sizeof(struct drm_fb_helper_crtc *));
1269 }
1270 }
1271 out:
1272 kfree(crtcs);
1273 return best_score;
1274 }
1275
1276 static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
1277 {
1278 struct drm_device *dev = fb_helper->dev;
1279 struct drm_fb_helper_crtc **crtcs;
1280 struct drm_display_mode **modes;
1281 struct drm_mode_set *modeset;
1282 bool *enabled;
1283 int width, height;
1284 int i, ret;
1285
1286 DRM_DEBUG_KMS("\n");
1287
1288 width = dev->mode_config.max_width;
1289 height = dev->mode_config.max_height;
1290
1291 crtcs = kcalloc(dev->mode_config.num_connector,
1292 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1293 modes = kcalloc(dev->mode_config.num_connector,
1294 sizeof(struct drm_display_mode *), GFP_KERNEL);
1295 enabled = kcalloc(dev->mode_config.num_connector,
1296 sizeof(bool), GFP_KERNEL);
1297 if (!crtcs || !modes || !enabled) {
1298 DRM_ERROR("Memory allocation failed\n");
1299 goto out;
1300 }
1301
1302
1303 drm_enable_connectors(fb_helper, enabled);
1304
1305 ret = drm_target_cloned(fb_helper, modes, enabled, width, height);
1306 if (!ret) {
1307 ret = drm_target_preferred(fb_helper, modes, enabled, width, height);
1308 if (!ret)
1309 DRM_ERROR("Unable to find initial modes\n");
1310 }
1311
1312 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height);
1313
1314 drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1315
1316 /* need to set the modesets up here for use later */
1317 /* fill out the connector<->crtc mappings into the modesets */
1318 for (i = 0; i < fb_helper->crtc_count; i++) {
1319 modeset = &fb_helper->crtc_info[i].mode_set;
1320 modeset->num_connectors = 0;
1321 modeset->fb = NULL;
1322 }
1323
1324 for (i = 0; i < fb_helper->connector_count; i++) {
1325 struct drm_display_mode *mode = modes[i];
1326 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1327 modeset = &fb_crtc->mode_set;
1328
1329 if (mode && fb_crtc) {
1330 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
1331 mode->name, fb_crtc->mode_set.crtc->base.id);
1332 fb_crtc->desired_mode = mode;
1333 if (modeset->mode)
1334 drm_mode_destroy(dev, modeset->mode);
1335 modeset->mode = drm_mode_duplicate(dev,
1336 fb_crtc->desired_mode);
1337 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
1338 modeset->fb = fb_helper->fb;
1339 }
1340 }
1341
1342 /* Clear out any old modes if there are no more connected outputs. */
1343 for (i = 0; i < fb_helper->crtc_count; i++) {
1344 modeset = &fb_helper->crtc_info[i].mode_set;
1345 if (modeset->num_connectors == 0) {
1346 BUG_ON(modeset->fb);
1347 BUG_ON(modeset->num_connectors);
1348 if (modeset->mode)
1349 drm_mode_destroy(dev, modeset->mode);
1350 modeset->mode = NULL;
1351 }
1352 }
1353 out:
1354 kfree(crtcs);
1355 kfree(modes);
1356 kfree(enabled);
1357 }
1358
1359 /**
1360 * drm_helper_initial_config - setup a sane initial connector configuration
1361 * @fb_helper: fb_helper device struct
1362 * @bpp_sel: bpp value to use for the framebuffer configuration
1363 *
1364 * LOCKING:
1365 * Called at init time by the driver to set up the @fb_helper initial
1366 * configuration, must take the mode config lock.
1367 *
1368 * Scans the CRTCs and connectors and tries to put together an initial setup.
1369 * At the moment, this is a cloned configuration across all heads with
1370 * a new framebuffer object as the backing store.
1371 *
1372 * RETURNS:
1373 * Zero if everything went ok, nonzero otherwise.
1374 */
1375 bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
1376 {
1377 struct drm_device *dev = fb_helper->dev;
1378 int count = 0;
1379
1380 drm_fb_helper_parse_command_line(fb_helper);
1381
1382 count = drm_fb_helper_probe_connector_modes(fb_helper,
1383 dev->mode_config.max_width,
1384 dev->mode_config.max_height);
1385 /*
1386 * we shouldn't end up with no modes here.
1387 */
1388 if (count == 0)
1389 dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
1390
1391 drm_setup_crtcs(fb_helper);
1392
1393 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
1394 }
1395 EXPORT_SYMBOL(drm_fb_helper_initial_config);
1396
1397 /**
1398 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
1399 * probing all the outputs attached to the fb
1400 * @fb_helper: the drm_fb_helper
1401 *
1402 * LOCKING:
1403 * Called at runtime, must take mode config lock.
1404 *
1405 * Scan the connectors attached to the fb_helper and try to put together a
1406 * setup after *notification of a change in output configuration.
1407 *
1408 * RETURNS:
1409 * 0 on success and a non-zero error code otherwise.
1410 */
1411 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
1412 {
1413 struct drm_device *dev = fb_helper->dev;
1414 int count = 0;
1415 u32 max_width, max_height, bpp_sel;
1416
1417 if (!fb_helper->fb)
1418 return 0;
1419
1420 drm_modeset_lock_all(dev);
1421 if (!drm_fb_helper_is_bound(fb_helper)) {
1422 fb_helper->delayed_hotplug = true;
1423 drm_modeset_unlock_all(dev);
1424 return 0;
1425 }
1426 DRM_DEBUG_KMS("\n");
1427
1428 max_width = fb_helper->fb->width;
1429 max_height = fb_helper->fb->height;
1430 bpp_sel = fb_helper->fb->bits_per_pixel;
1431
1432 count = drm_fb_helper_probe_connector_modes(fb_helper, max_width,
1433 max_height);
1434 drm_setup_crtcs(fb_helper);
1435 drm_modeset_unlock_all(dev);
1436
1437 drm_fb_helper_set_par(fb_helper->fbdev);
1438
1439 return 0;
1440 }
1441 EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
1442
1443 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
1444 * but the module doesn't depend on any fb console symbols. At least
1445 * attempt to load fbcon to avoid leaving the system without a usable console.
1446 */
1447 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
1448 static int __init drm_fb_helper_modinit(void)
1449 {
1450 const char *name = "fbcon";
1451 struct module *fbcon;
1452
1453 mutex_lock(&module_mutex);
1454 fbcon = find_module(name);
1455 mutex_unlock(&module_mutex);
1456
1457 if (!fbcon)
1458 request_module_nowait(name);
1459 return 0;
1460 }
1461
1462 module_init(drm_fb_helper_modinit);
1463 #endif
This page took 0.084676 seconds and 4 git commands to generate.