drm/nouveau: remove (most) hardcoded object handle usage
[deliverable/linux.git] / drivers / gpu / drm / drm_fb_helper.c
CommitLineData
785b93ef
DA
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 */
d56b1b9d
SK
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
3b40a443 32#include <linux/kernel.h>
785b93ef 33#include <linux/sysrq.h>
5a0e3ad6 34#include <linux/slab.h>
785b93ef 35#include <linux/fb.h>
e0cd3608 36#include <linux/module.h>
760285e7
DH
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>
785b93ef
DA
41
42static LIST_HEAD(kernel_fb_helper_list);
43
d0ddc033
DV
44/**
45 * DOC: fbdev helpers
46 *
47 * The fb helper functions are useful to provide an fbdev on top of a drm kernel
83c617c5 48 * mode setting driver. They can be used mostly independently from the crtc
d0ddc033
DV
49 * helper functions used by many drivers to implement the kernel mode setting
50 * interfaces.
207fd329 51 *
10a23102
TR
52 * Initialization is done as a four-step process with drm_fb_helper_prepare(),
53 * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and
54 * drm_fb_helper_initial_config(). Drivers with fancier requirements than the
55 * default behaviour can override the third step with their own code.
56 * Teardown is done with drm_fb_helper_fini().
207fd329
DV
57 *
58 * At runtime drivers should restore the fbdev console by calling
59 * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
60 * should also notify the fb helper code from updates to the output
61 * configuration by calling drm_fb_helper_hotplug_event(). For easier
62 * integration with the output polling code in drm_crtc_helper.c the modeset
83c617c5 63 * code provides a ->output_poll_changed callback.
207fd329
DV
64 *
65 * All other functions exported by the fb helper library can be used to
66 * implement the fbdev driver interface by the driver.
10a23102
TR
67 *
68 * It is possible, though perhaps somewhat tricky, to implement race-free
69 * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare()
70 * helper must be called first to initialize the minimum required to make
71 * hotplug detection work. Drivers also need to make sure to properly set up
72 * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init()
73 * it is safe to enable interrupts and start processing hotplug events. At the
74 * same time, drivers should initialize all modeset objects such as CRTCs,
75 * encoders and connectors. To finish up the fbdev helper initialization, the
76 * drm_fb_helper_init() function is called. To probe for all attached displays
77 * and set up an initial configuration using the detected hardware, drivers
78 * should call drm_fb_helper_single_add_all_connectors() followed by
79 * drm_fb_helper_initial_config().
d0ddc033
DV
80 */
81
207fd329
DV
82/**
83 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
84 * emulation helper
85 * @fb_helper: fbdev initialized with drm_fb_helper_init
86 *
87 * This functions adds all the available connectors for use with the given
88 * fb_helper. This is a separate step to allow drivers to freely assign
89 * connectors to the fbdev, e.g. if some are reserved for special purposes or
90 * not adequate to be used for the fbcon.
91 *
92 * Since this is part of the initial setup before the fbdev is published, no
93 * locking is required.
94 */
0b4c0f3f 95int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
d50ba256 96{
0b4c0f3f
DA
97 struct drm_device *dev = fb_helper->dev;
98 struct drm_connector *connector;
99 int i;
d50ba256 100
0b4c0f3f
DA
101 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
102 struct drm_fb_helper_connector *fb_helper_connector;
103
104 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
105 if (!fb_helper_connector)
106 goto fail;
d50ba256 107
0b4c0f3f
DA
108 fb_helper_connector->connector = connector;
109 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
110 }
d50ba256 111 return 0;
0b4c0f3f
DA
112fail:
113 for (i = 0; i < fb_helper->connector_count; i++) {
114 kfree(fb_helper->connector_info[i]);
115 fb_helper->connector_info[i] = NULL;
116 }
117 fb_helper->connector_count = 0;
118 return -ENOMEM;
d50ba256 119}
0b4c0f3f 120EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
d50ba256 121
65c2a89c
DA
122int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector)
123{
124 struct drm_fb_helper_connector **temp;
125 struct drm_fb_helper_connector *fb_helper_connector;
126
127 WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
128 if (fb_helper->connector_count + 1 > fb_helper->connector_info_alloc_count) {
129 temp = krealloc(fb_helper->connector_info, sizeof(struct drm_fb_helper_connector) * (fb_helper->connector_count + 1), GFP_KERNEL);
130 if (!temp)
131 return -ENOMEM;
132
133 fb_helper->connector_info_alloc_count = fb_helper->connector_count + 1;
134 fb_helper->connector_info = temp;
135 }
136
137
138 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
139 if (!fb_helper_connector)
140 return -ENOMEM;
141
142 fb_helper_connector->connector = connector;
143 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
144 return 0;
145}
146EXPORT_SYMBOL(drm_fb_helper_add_one_connector);
147
148int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
149 struct drm_connector *connector)
150{
151 struct drm_fb_helper_connector *fb_helper_connector;
152 int i, j;
153
154 WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
155
156 for (i = 0; i < fb_helper->connector_count; i++) {
157 if (fb_helper->connector_info[i]->connector == connector)
158 break;
159 }
160
161 if (i == fb_helper->connector_count)
162 return -EINVAL;
163 fb_helper_connector = fb_helper->connector_info[i];
164
165 for (j = i + 1; j < fb_helper->connector_count; j++) {
166 fb_helper->connector_info[j - 1] = fb_helper->connector_info[j];
167 }
168 fb_helper->connector_count--;
169 kfree(fb_helper_connector);
170 return 0;
171}
172EXPORT_SYMBOL(drm_fb_helper_remove_one_connector);
173
0b4c0f3f 174static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
d50ba256 175{
0b4c0f3f
DA
176 struct drm_fb_helper_connector *fb_helper_conn;
177 int i;
d50ba256 178
0b4c0f3f 179 for (i = 0; i < fb_helper->connector_count; i++) {
1794d257
CW
180 struct drm_cmdline_mode *mode;
181 struct drm_connector *connector;
d50ba256
DA
182 char *option = NULL;
183
0b4c0f3f 184 fb_helper_conn = fb_helper->connector_info[i];
1794d257
CW
185 connector = fb_helper_conn->connector;
186 mode = &fb_helper_conn->cmdline_mode;
0b4c0f3f 187
d50ba256 188 /* do something on return - turn off connector maybe */
25933820 189 if (fb_get_options(connector->name, &option))
d50ba256
DA
190 continue;
191
1794d257
CW
192 if (drm_mode_parse_command_line_for_connector(option,
193 connector,
194 mode)) {
195 if (mode->force) {
196 const char *s;
197 switch (mode->force) {
6c91083f
SK
198 case DRM_FORCE_OFF:
199 s = "OFF";
200 break;
201 case DRM_FORCE_ON_DIGITAL:
202 s = "ON - dig";
203 break;
1794d257 204 default:
6c91083f
SK
205 case DRM_FORCE_ON:
206 s = "ON";
207 break;
1794d257
CW
208 }
209
210 DRM_INFO("forcing %s connector %s\n",
25933820 211 connector->name, s);
1794d257
CW
212 connector->force = mode->force;
213 }
214
215 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
25933820 216 connector->name,
1794d257
CW
217 mode->xres, mode->yres,
218 mode->refresh_specified ? mode->refresh : 60,
219 mode->rb ? " reduced blanking" : "",
220 mode->margins ? " with margins" : "",
221 mode->interlace ? " interlaced" : "");
222 }
223
d50ba256
DA
224 }
225 return 0;
226}
227
99231028
JW
228static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper)
229{
230 uint16_t *r_base, *g_base, *b_base;
231 int i;
232
04c0c569
VS
233 if (helper->funcs->gamma_get == NULL)
234 return;
235
99231028
JW
236 r_base = crtc->gamma_store;
237 g_base = r_base + crtc->gamma_size;
238 b_base = g_base + crtc->gamma_size;
239
240 for (i = 0; i < crtc->gamma_size; i++)
241 helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i);
242}
243
244static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
245{
246 uint16_t *r_base, *g_base, *b_base;
247
ebe0f244
LP
248 if (crtc->funcs->gamma_set == NULL)
249 return;
250
99231028
JW
251 r_base = crtc->gamma_store;
252 g_base = r_base + crtc->gamma_size;
253 b_base = g_base + crtc->gamma_size;
254
255 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
256}
257
207fd329
DV
258/**
259 * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter
260 * @info: fbdev registered by the helper
261 */
1a7aba7f
JB
262int drm_fb_helper_debug_enter(struct fb_info *info)
263{
264 struct drm_fb_helper *helper = info->par;
265 struct drm_crtc_helper_funcs *funcs;
266 int i;
267
1a7aba7f
JB
268 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
269 for (i = 0; i < helper->crtc_count; i++) {
270 struct drm_mode_set *mode_set =
271 &helper->crtc_info[i].mode_set;
272
273 if (!mode_set->crtc->enabled)
274 continue;
275
276 funcs = mode_set->crtc->helper_private;
99231028 277 drm_fb_helper_save_lut_atomic(mode_set->crtc, helper);
1a7aba7f
JB
278 funcs->mode_set_base_atomic(mode_set->crtc,
279 mode_set->fb,
280 mode_set->x,
413d45d3 281 mode_set->y,
21c74a8e 282 ENTER_ATOMIC_MODE_SET);
1a7aba7f
JB
283 }
284 }
285
286 return 0;
287}
288EXPORT_SYMBOL(drm_fb_helper_debug_enter);
289
290/* Find the real fb for a given fb helper CRTC */
291static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
292{
293 struct drm_device *dev = crtc->dev;
294 struct drm_crtc *c;
295
296 list_for_each_entry(c, &dev->mode_config.crtc_list, head) {
297 if (crtc->base.id == c->base.id)
f4510a27 298 return c->primary->fb;
1a7aba7f
JB
299 }
300
301 return NULL;
302}
303
207fd329
DV
304/**
305 * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
306 * @info: fbdev registered by the helper
307 */
1a7aba7f
JB
308int drm_fb_helper_debug_leave(struct fb_info *info)
309{
310 struct drm_fb_helper *helper = info->par;
311 struct drm_crtc *crtc;
312 struct drm_crtc_helper_funcs *funcs;
313 struct drm_framebuffer *fb;
314 int i;
315
316 for (i = 0; i < helper->crtc_count; i++) {
317 struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
318 crtc = mode_set->crtc;
319 funcs = crtc->helper_private;
320 fb = drm_mode_config_fb(crtc);
321
322 if (!crtc->enabled)
323 continue;
324
325 if (!fb) {
326 DRM_ERROR("no fb to restore??\n");
327 continue;
328 }
329
99231028 330 drm_fb_helper_restore_lut_atomic(mode_set->crtc);
1a7aba7f 331 funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x,
21c74a8e 332 crtc->y, LEAVE_ATOMIC_MODE_SET);
1a7aba7f
JB
333 }
334
335 return 0;
336}
337EXPORT_SYMBOL(drm_fb_helper_debug_leave);
338
5ea1f752 339static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper)
e8e7a2b8 340{
3858bc5d
VS
341 struct drm_device *dev = fb_helper->dev;
342 struct drm_plane *plane;
e8e7a2b8 343 bool error = false;
3858bc5d
VS
344 int i;
345
346 drm_warn_on_modeset_not_all_locked(dev);
6aed8ec3 347
3858bc5d 348 list_for_each_entry(plane, &dev->mode_config.plane_list, head)
e27dde3e
MR
349 if (plane->type != DRM_PLANE_TYPE_PRIMARY)
350 drm_plane_force_disable(plane);
6aed8ec3 351
e8e7a2b8
DA
352 for (i = 0; i < fb_helper->crtc_count; i++) {
353 struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
3858bc5d
VS
354 struct drm_crtc *crtc = mode_set->crtc;
355 int ret;
356
357 if (crtc->funcs->cursor_set) {
358 ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0);
359 if (ret)
360 error = true;
361 }
362
2d13b679 363 ret = drm_mode_set_config_internal(mode_set);
e8e7a2b8
DA
364 if (ret)
365 error = true;
366 }
367 return error;
368}
5ea1f752
RC
369/**
370 * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
371 * @fb_helper: fbcon to restore
372 *
373 * This should be called from driver's drm ->lastclose callback
374 * when implementing an fbcon on top of kms using this helper. This ensures that
375 * the user isn't greeted with a black screen when e.g. X dies.
376 *
377 * Use this variant if you need to bypass locking (panic), or already
378 * hold all modeset locks. Otherwise use drm_fb_helper_restore_fbdev_mode_unlocked()
379 */
380static bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
381{
382 return restore_fbdev_mode(fb_helper);
383}
384
385/**
386 * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
387 * @fb_helper: fbcon to restore
388 *
389 * This should be called from driver's drm ->lastclose callback
390 * when implementing an fbcon on top of kms using this helper. This ensures that
391 * the user isn't greeted with a black screen when e.g. X dies.
392 */
393bool drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
394{
395 struct drm_device *dev = fb_helper->dev;
396 bool ret;
397 drm_modeset_lock_all(dev);
398 ret = restore_fbdev_mode(fb_helper);
399 drm_modeset_unlock_all(dev);
400 return ret;
401}
402EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked);
e8e7a2b8 403
d21bf469
DV
404/*
405 * restore fbcon display for all kms driver's using this helper, used for sysrq
406 * and panic handling.
407 */
78b9c353 408static bool drm_fb_helper_force_kernel_mode(void)
785b93ef 409{
785b93ef
DA
410 bool ret, error = false;
411 struct drm_fb_helper *helper;
412
413 if (list_empty(&kernel_fb_helper_list))
414 return false;
415
416 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
b77f0765
TR
417 struct drm_device *dev = helper->dev;
418
419 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
420 continue;
421
51fd371b
RC
422 /* NOTE: we use lockless flag below to avoid grabbing other
423 * modeset locks. So just trylock the underlying mutex
424 * directly:
425 */
b77f0765
TR
426 if (!mutex_trylock(&dev->mode_config.mutex)) {
427 error = true;
e8e7a2b8 428 continue;
b77f0765 429 }
e8e7a2b8
DA
430
431 ret = drm_fb_helper_restore_fbdev_mode(helper);
432 if (ret)
433 error = true;
b77f0765
TR
434
435 mutex_unlock(&dev->mode_config.mutex);
785b93ef
DA
436 }
437 return error;
438}
439
43c8a849 440static int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
785b93ef
DA
441 void *panic_str)
442{
d68752cf
HD
443 /*
444 * It's a waste of time and effort to switch back to text console
445 * if the kernel should reboot before panic messages can be seen.
446 */
447 if (panic_timeout < 0)
448 return 0;
449
d56b1b9d 450 pr_err("panic occurred, switching back to text console\n");
785b93ef 451 return drm_fb_helper_force_kernel_mode();
785b93ef 452}
785b93ef
DA
453
454static struct notifier_block paniced = {
455 .notifier_call = drm_fb_helper_panic,
456};
457
20c60c35
DV
458static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
459{
460 struct drm_device *dev = fb_helper->dev;
461 struct drm_crtc *crtc;
462 int bound = 0, crtcs_bound = 0;
463
520edd13
PZ
464 /* Sometimes user space wants everything disabled, so don't steal the
465 * display if there's a master. */
466 if (dev->primary->master)
467 return false;
468
20c60c35 469 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
f4510a27 470 if (crtc->primary->fb)
20c60c35 471 crtcs_bound++;
f4510a27 472 if (crtc->primary->fb == fb_helper->fb)
20c60c35
DV
473 bound++;
474 }
475
476 if (bound < crtcs_bound)
477 return false;
520edd13 478
20c60c35
DV
479 return true;
480}
481
bea1d35b 482#ifdef CONFIG_MAGIC_SYSRQ
785b93ef
DA
483static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
484{
d21bf469
DV
485 bool ret;
486 ret = drm_fb_helper_force_kernel_mode();
487 if (ret == true)
488 DRM_ERROR("Failed to restore crtc configuration\n");
785b93ef
DA
489}
490static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
491
1495cc9d 492static void drm_fb_helper_sysrq(int dummy1)
785b93ef
DA
493{
494 schedule_work(&drm_fb_helper_restore_work);
495}
496
497static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
498 .handler = drm_fb_helper_sysrq,
499 .help_msg = "force-fb(V)",
500 .action_msg = "Restore framebuffer console",
501};
b8c40d62
RD
502#else
503static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
bea1d35b 504#endif
785b93ef 505
3a8148c5 506static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
785b93ef
DA
507{
508 struct drm_fb_helper *fb_helper = info->par;
509 struct drm_device *dev = fb_helper->dev;
510 struct drm_crtc *crtc;
023eb571 511 struct drm_connector *connector;
023eb571 512 int i, j;
785b93ef 513
928c2f0c
DV
514 /*
515 * fbdev->blank can be called from irq context in case of a panic.
1b1d5397
DV
516 * Since we already have our own special panic handler which will
517 * restore the fbdev console mode completely, just bail out early.
518 */
519 if (oops_in_progress)
520 return;
521
785b93ef 522 /*
3a8148c5 523 * For each CRTC in this fb, turn the connectors on/off.
785b93ef 524 */
84849903 525 drm_modeset_lock_all(dev);
20c60c35
DV
526 if (!drm_fb_helper_is_bound(fb_helper)) {
527 drm_modeset_unlock_all(dev);
528 return;
529 }
530
e87b2c42 531 for (i = 0; i < fb_helper->crtc_count; i++) {
8be48d92 532 crtc = fb_helper->crtc_info[i].mode_set.crtc;
785b93ef 533
8be48d92
DA
534 if (!crtc->enabled)
535 continue;
536
3a8148c5 537 /* Walk the connectors & encoders on this fb turning them on/off */
023eb571
JB
538 for (j = 0; j < fb_helper->connector_count; j++) {
539 connector = fb_helper->connector_info[j]->connector;
e04190e0 540 connector->funcs->dpms(connector, dpms_mode);
58495563 541 drm_object_property_set_value(&connector->base,
3a8148c5 542 dev->mode_config.dpms_property, dpms_mode);
785b93ef 543 }
785b93ef 544 }
84849903 545 drm_modeset_unlock_all(dev);
785b93ef
DA
546}
547
207fd329
DV
548/**
549 * drm_fb_helper_blank - implementation for ->fb_blank
550 * @blank: desired blanking state
551 * @info: fbdev registered by the helper
552 */
785b93ef
DA
553int drm_fb_helper_blank(int blank, struct fb_info *info)
554{
555 switch (blank) {
731b5a15 556 /* Display: On; HSync: On, VSync: On */
785b93ef 557 case FB_BLANK_UNBLANK:
3a8148c5 558 drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON);
785b93ef 559 break;
731b5a15 560 /* Display: Off; HSync: On, VSync: On */
785b93ef 561 case FB_BLANK_NORMAL:
3a8148c5 562 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
785b93ef 563 break;
731b5a15 564 /* Display: Off; HSync: Off, VSync: On */
785b93ef 565 case FB_BLANK_HSYNC_SUSPEND:
3a8148c5 566 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
785b93ef 567 break;
731b5a15 568 /* Display: Off; HSync: On, VSync: Off */
785b93ef 569 case FB_BLANK_VSYNC_SUSPEND:
3a8148c5 570 drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND);
785b93ef 571 break;
731b5a15 572 /* Display: Off; HSync: Off, VSync: Off */
785b93ef 573 case FB_BLANK_POWERDOWN:
3a8148c5 574 drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF);
785b93ef
DA
575 break;
576 }
577 return 0;
578}
579EXPORT_SYMBOL(drm_fb_helper_blank);
580
581static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
582{
583 int i;
584
0b4c0f3f
DA
585 for (i = 0; i < helper->connector_count; i++)
586 kfree(helper->connector_info[i]);
587 kfree(helper->connector_info);
a1b7736d 588 for (i = 0; i < helper->crtc_count; i++) {
785b93ef 589 kfree(helper->crtc_info[i].mode_set.connectors);
a1b7736d
SH
590 if (helper->crtc_info[i].mode_set.mode)
591 drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode);
592 }
785b93ef
DA
593 kfree(helper->crtc_info);
594}
595
10a23102
TR
596/**
597 * drm_fb_helper_prepare - setup a drm_fb_helper structure
598 * @dev: DRM device
599 * @helper: driver-allocated fbdev helper structure to set up
600 * @funcs: pointer to structure of functions associate with this helper
601 *
602 * Sets up the bare minimum to make the framebuffer helper usable. This is
603 * useful to implement race-free initialization of the polling helpers.
604 */
605void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
606 const struct drm_fb_helper_funcs *funcs)
607{
608 INIT_LIST_HEAD(&helper->kernel_fb_list);
609 helper->funcs = funcs;
610 helper->dev = dev;
611}
612EXPORT_SYMBOL(drm_fb_helper_prepare);
613
207fd329
DV
614/**
615 * drm_fb_helper_init - initialize a drm_fb_helper structure
616 * @dev: drm device
617 * @fb_helper: driver-allocated fbdev helper structure to initialize
618 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
619 * @max_conn_count: max connector count
620 *
621 * This allocates the structures for the fbdev helper with the given limits.
622 * Note that this won't yet touch the hardware (through the driver interfaces)
623 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
624 * to allow driver writes more control over the exact init sequence.
625 *
10a23102 626 * Drivers must call drm_fb_helper_prepare() before calling this function.
207fd329
DV
627 *
628 * RETURNS:
629 * Zero if everything went ok, nonzero otherwise.
630 */
4abe3520
DA
631int drm_fb_helper_init(struct drm_device *dev,
632 struct drm_fb_helper *fb_helper,
eb1f8e4f 633 int crtc_count, int max_conn_count)
785b93ef 634{
785b93ef 635 struct drm_crtc *crtc;
785b93ef
DA
636 int i;
637
04cfe97e
XL
638 if (!max_conn_count)
639 return -EINVAL;
640
4abe3520
DA
641 fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
642 if (!fb_helper->crtc_info)
785b93ef
DA
643 return -ENOMEM;
644
4abe3520
DA
645 fb_helper->crtc_count = crtc_count;
646 fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
647 if (!fb_helper->connector_info) {
648 kfree(fb_helper->crtc_info);
0b4c0f3f
DA
649 return -ENOMEM;
650 }
65c2a89c 651 fb_helper->connector_info_alloc_count = dev->mode_config.num_connector;
4abe3520 652 fb_helper->connector_count = 0;
785b93ef
DA
653
654 for (i = 0; i < crtc_count; i++) {
4abe3520 655 fb_helper->crtc_info[i].mode_set.connectors =
785b93ef
DA
656 kcalloc(max_conn_count,
657 sizeof(struct drm_connector *),
658 GFP_KERNEL);
659
4a1b0714 660 if (!fb_helper->crtc_info[i].mode_set.connectors)
785b93ef 661 goto out_free;
4abe3520 662 fb_helper->crtc_info[i].mode_set.num_connectors = 0;
785b93ef
DA
663 }
664
665 i = 0;
666 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
4abe3520 667 fb_helper->crtc_info[i].mode_set.crtc = crtc;
785b93ef
DA
668 i++;
669 }
e9ad3181 670
785b93ef
DA
671 return 0;
672out_free:
4abe3520 673 drm_fb_helper_crtc_free(fb_helper);
785b93ef
DA
674 return -ENOMEM;
675}
4abe3520
DA
676EXPORT_SYMBOL(drm_fb_helper_init);
677
678void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
679{
680 if (!list_empty(&fb_helper->kernel_fb_list)) {
681 list_del(&fb_helper->kernel_fb_list);
682 if (list_empty(&kernel_fb_helper_list)) {
d56b1b9d 683 pr_info("drm: unregistered panic notifier\n");
4abe3520
DA
684 atomic_notifier_chain_unregister(&panic_notifier_list,
685 &paniced);
686 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
687 }
688 }
689
690 drm_fb_helper_crtc_free(fb_helper);
691
4abe3520
DA
692}
693EXPORT_SYMBOL(drm_fb_helper_fini);
785b93ef 694
c850cb78 695static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
b8c00ac5
DA
696 u16 blue, u16 regno, struct fb_info *info)
697{
698 struct drm_fb_helper *fb_helper = info->par;
699 struct drm_framebuffer *fb = fb_helper->fb;
700 int pindex;
701
c850cb78
DA
702 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
703 u32 *palette;
704 u32 value;
705 /* place color in psuedopalette */
706 if (regno > 16)
707 return -EINVAL;
708 palette = (u32 *)info->pseudo_palette;
709 red >>= (16 - info->var.red.length);
710 green >>= (16 - info->var.green.length);
711 blue >>= (16 - info->var.blue.length);
712 value = (red << info->var.red.offset) |
713 (green << info->var.green.offset) |
714 (blue << info->var.blue.offset);
9da12b6a
RC
715 if (info->var.transp.length > 0) {
716 u32 mask = (1 << info->var.transp.length) - 1;
717 mask <<= info->var.transp.offset;
718 value |= mask;
719 }
c850cb78
DA
720 palette[regno] = value;
721 return 0;
722 }
723
04c0c569
VS
724 /*
725 * The driver really shouldn't advertise pseudo/directcolor
726 * visuals if it can't deal with the palette.
727 */
728 if (WARN_ON(!fb_helper->funcs->gamma_set ||
729 !fb_helper->funcs->gamma_get))
730 return -EINVAL;
731
b8c00ac5
DA
732 pindex = regno;
733
734 if (fb->bits_per_pixel == 16) {
735 pindex = regno << 3;
736
737 if (fb->depth == 16 && regno > 63)
c850cb78 738 return -EINVAL;
b8c00ac5 739 if (fb->depth == 15 && regno > 31)
c850cb78 740 return -EINVAL;
b8c00ac5
DA
741
742 if (fb->depth == 16) {
743 u16 r, g, b;
744 int i;
745 if (regno < 32) {
746 for (i = 0; i < 8; i++)
747 fb_helper->funcs->gamma_set(crtc, red,
748 green, blue, pindex + i);
749 }
750
751 fb_helper->funcs->gamma_get(crtc, &r,
752 &g, &b,
753 pindex >> 1);
754
755 for (i = 0; i < 4; i++)
756 fb_helper->funcs->gamma_set(crtc, r,
757 green, b,
758 (pindex >> 1) + i);
759 }
760 }
761
762 if (fb->depth != 16)
763 fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
c850cb78 764 return 0;
b8c00ac5
DA
765}
766
207fd329
DV
767/**
768 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
769 * @cmap: cmap to set
770 * @info: fbdev registered by the helper
771 */
068143d3
DA
772int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
773{
774 struct drm_fb_helper *fb_helper = info->par;
8391a3d5 775 struct drm_device *dev = fb_helper->dev;
8be48d92 776 struct drm_crtc_helper_funcs *crtc_funcs;
068143d3
DA
777 u16 *red, *green, *blue, *transp;
778 struct drm_crtc *crtc;
062ac622 779 int i, j, rc = 0;
068143d3
DA
780 int start;
781
8391a3d5
VS
782 drm_modeset_lock_all(dev);
783 if (!drm_fb_helper_is_bound(fb_helper)) {
784 drm_modeset_unlock_all(dev);
785 return -EBUSY;
786 }
787
8be48d92
DA
788 for (i = 0; i < fb_helper->crtc_count; i++) {
789 crtc = fb_helper->crtc_info[i].mode_set.crtc;
790 crtc_funcs = crtc->helper_private;
068143d3
DA
791
792 red = cmap->red;
793 green = cmap->green;
794 blue = cmap->blue;
795 transp = cmap->transp;
796 start = cmap->start;
797
062ac622 798 for (j = 0; j < cmap->len; j++) {
068143d3
DA
799 u16 hred, hgreen, hblue, htransp = 0xffff;
800
801 hred = *red++;
802 hgreen = *green++;
803 hblue = *blue++;
804
805 if (transp)
806 htransp = *transp++;
807
c850cb78
DA
808 rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
809 if (rc)
8391a3d5 810 goto out;
068143d3 811 }
04c0c569
VS
812 if (crtc_funcs->load_lut)
813 crtc_funcs->load_lut(crtc);
068143d3 814 }
8391a3d5
VS
815 out:
816 drm_modeset_unlock_all(dev);
068143d3
DA
817 return rc;
818}
819EXPORT_SYMBOL(drm_fb_helper_setcmap);
820
207fd329
DV
821/**
822 * drm_fb_helper_check_var - implementation for ->fb_check_var
823 * @var: screeninfo to check
824 * @info: fbdev registered by the helper
825 */
785b93ef
DA
826int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
827 struct fb_info *info)
828{
829 struct drm_fb_helper *fb_helper = info->par;
830 struct drm_framebuffer *fb = fb_helper->fb;
831 int depth;
832
f90ebd9e 833 if (var->pixclock != 0 || in_dbg_master())
785b93ef
DA
834 return -EINVAL;
835
836 /* Need to resize the fb object !!! */
62fb376e
CW
837 if (var->bits_per_pixel > fb->bits_per_pixel ||
838 var->xres > fb->width || var->yres > fb->height ||
839 var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
509c7d83 840 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
62fb376e
CW
841 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
842 var->xres, var->yres, var->bits_per_pixel,
843 var->xres_virtual, var->yres_virtual,
509c7d83 844 fb->width, fb->height, fb->bits_per_pixel);
785b93ef
DA
845 return -EINVAL;
846 }
847
848 switch (var->bits_per_pixel) {
849 case 16:
850 depth = (var->green.length == 6) ? 16 : 15;
851 break;
852 case 32:
853 depth = (var->transp.length > 0) ? 32 : 24;
854 break;
855 default:
856 depth = var->bits_per_pixel;
857 break;
858 }
859
860 switch (depth) {
861 case 8:
862 var->red.offset = 0;
863 var->green.offset = 0;
864 var->blue.offset = 0;
865 var->red.length = 8;
866 var->green.length = 8;
867 var->blue.length = 8;
868 var->transp.length = 0;
869 var->transp.offset = 0;
870 break;
871 case 15:
872 var->red.offset = 10;
873 var->green.offset = 5;
874 var->blue.offset = 0;
875 var->red.length = 5;
876 var->green.length = 5;
877 var->blue.length = 5;
878 var->transp.length = 1;
879 var->transp.offset = 15;
880 break;
881 case 16:
882 var->red.offset = 11;
883 var->green.offset = 5;
884 var->blue.offset = 0;
885 var->red.length = 5;
886 var->green.length = 6;
887 var->blue.length = 5;
888 var->transp.length = 0;
889 var->transp.offset = 0;
890 break;
891 case 24:
892 var->red.offset = 16;
893 var->green.offset = 8;
894 var->blue.offset = 0;
895 var->red.length = 8;
896 var->green.length = 8;
897 var->blue.length = 8;
898 var->transp.length = 0;
899 var->transp.offset = 0;
900 break;
901 case 32:
902 var->red.offset = 16;
903 var->green.offset = 8;
904 var->blue.offset = 0;
905 var->red.length = 8;
906 var->green.length = 8;
907 var->blue.length = 8;
908 var->transp.length = 8;
909 var->transp.offset = 24;
910 break;
911 default:
912 return -EINVAL;
913 }
914 return 0;
915}
916EXPORT_SYMBOL(drm_fb_helper_check_var);
917
207fd329
DV
918/**
919 * drm_fb_helper_set_par - implementation for ->fb_set_par
920 * @info: fbdev registered by the helper
921 *
922 * This will let fbcon do the mode init and is called at initialization time by
923 * the fbdev core when registering the driver, and later on through the hotplug
924 * callback.
925 */
785b93ef
DA
926int drm_fb_helper_set_par(struct fb_info *info)
927{
928 struct drm_fb_helper *fb_helper = info->par;
785b93ef 929 struct fb_var_screeninfo *var = &info->var;
785b93ef 930
5349ef31 931 if (var->pixclock != 0) {
172e91f5 932 DRM_ERROR("PIXEL CLOCK SET\n");
785b93ef
DA
933 return -EINVAL;
934 }
935
5ea1f752 936 drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
4abe3520
DA
937
938 if (fb_helper->delayed_hotplug) {
939 fb_helper->delayed_hotplug = false;
eb1f8e4f 940 drm_fb_helper_hotplug_event(fb_helper);
4abe3520 941 }
785b93ef
DA
942 return 0;
943}
944EXPORT_SYMBOL(drm_fb_helper_set_par);
945
207fd329
DV
946/**
947 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
948 * @var: updated screen information
949 * @info: fbdev registered by the helper
950 */
785b93ef
DA
951int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
952 struct fb_info *info)
953{
954 struct drm_fb_helper *fb_helper = info->par;
955 struct drm_device *dev = fb_helper->dev;
956 struct drm_mode_set *modeset;
785b93ef
DA
957 int ret = 0;
958 int i;
959
84849903 960 drm_modeset_lock_all(dev);
20c60c35
DV
961 if (!drm_fb_helper_is_bound(fb_helper)) {
962 drm_modeset_unlock_all(dev);
963 return -EBUSY;
964 }
965
8be48d92 966 for (i = 0; i < fb_helper->crtc_count; i++) {
785b93ef
DA
967 modeset = &fb_helper->crtc_info[i].mode_set;
968
969 modeset->x = var->xoffset;
970 modeset->y = var->yoffset;
971
972 if (modeset->num_connectors) {
2d13b679 973 ret = drm_mode_set_config_internal(modeset);
785b93ef
DA
974 if (!ret) {
975 info->var.xoffset = var->xoffset;
976 info->var.yoffset = var->yoffset;
977 }
978 }
979 }
84849903 980 drm_modeset_unlock_all(dev);
785b93ef
DA
981 return ret;
982}
983EXPORT_SYMBOL(drm_fb_helper_pan_display);
984
8acf658a 985/*
207fd329
DV
986 * Allocates the backing storage and sets up the fbdev info structure through
987 * the ->fb_probe callback and then registers the fbdev and sets up the panic
988 * notifier.
8acf658a 989 */
de1ace5b
DV
990static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
991 int preferred_bpp)
785b93ef 992{
8acf658a 993 int ret = 0;
785b93ef 994 int crtc_count = 0;
4abe3520 995 int i;
785b93ef 996 struct fb_info *info;
38651674 997 struct drm_fb_helper_surface_size sizes;
8be48d92 998 int gamma_size = 0;
38651674
DA
999
1000 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
1001 sizes.surface_depth = 24;
1002 sizes.surface_bpp = 32;
1003 sizes.fb_width = (unsigned)-1;
1004 sizes.fb_height = (unsigned)-1;
785b93ef 1005
b8c00ac5
DA
1006 /* if driver picks 8 or 16 by default use that
1007 for both depth/bpp */
96081cdf 1008 if (preferred_bpp != sizes.surface_bpp)
38651674 1009 sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
96081cdf 1010
785b93ef 1011 /* first up get a count of crtcs now in use and new min/maxes width/heights */
0b4c0f3f
DA
1012 for (i = 0; i < fb_helper->connector_count; i++) {
1013 struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
1794d257 1014 struct drm_cmdline_mode *cmdline_mode;
8ef8678c 1015
0b4c0f3f 1016 cmdline_mode = &fb_helper_conn->cmdline_mode;
d50ba256
DA
1017
1018 if (cmdline_mode->bpp_specified) {
1019 switch (cmdline_mode->bpp) {
1020 case 8:
38651674 1021 sizes.surface_depth = sizes.surface_bpp = 8;
d50ba256
DA
1022 break;
1023 case 15:
38651674
DA
1024 sizes.surface_depth = 15;
1025 sizes.surface_bpp = 16;
d50ba256
DA
1026 break;
1027 case 16:
38651674 1028 sizes.surface_depth = sizes.surface_bpp = 16;
d50ba256
DA
1029 break;
1030 case 24:
38651674 1031 sizes.surface_depth = sizes.surface_bpp = 24;
d50ba256
DA
1032 break;
1033 case 32:
38651674
DA
1034 sizes.surface_depth = 24;
1035 sizes.surface_bpp = 32;
d50ba256
DA
1036 break;
1037 }
1038 break;
1039 }
1040 }
1041
8be48d92
DA
1042 crtc_count = 0;
1043 for (i = 0; i < fb_helper->crtc_count; i++) {
1044 struct drm_display_mode *desired_mode;
1045 desired_mode = fb_helper->crtc_info[i].desired_mode;
1046
1047 if (desired_mode) {
1048 if (gamma_size == 0)
1049 gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
1050 if (desired_mode->hdisplay < sizes.fb_width)
1051 sizes.fb_width = desired_mode->hdisplay;
1052 if (desired_mode->vdisplay < sizes.fb_height)
1053 sizes.fb_height = desired_mode->vdisplay;
1054 if (desired_mode->hdisplay > sizes.surface_width)
1055 sizes.surface_width = desired_mode->hdisplay;
1056 if (desired_mode->vdisplay > sizes.surface_height)
1057 sizes.surface_height = desired_mode->vdisplay;
785b93ef
DA
1058 crtc_count++;
1059 }
1060 }
1061
38651674 1062 if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
785b93ef
DA
1063 /* hmm everyone went away - assume VGA cable just fell out
1064 and will come back later. */
eb1f8e4f 1065 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
19b4b445
DA
1066 sizes.fb_width = sizes.surface_width = 1024;
1067 sizes.fb_height = sizes.surface_height = 768;
785b93ef
DA
1068 }
1069
38651674 1070 /* push down into drivers */
8acf658a
DV
1071 ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
1072 if (ret < 0)
1073 return ret;
785b93ef 1074
38651674 1075 info = fb_helper->fbdev;
785b93ef 1076
7e53f3a4
DV
1077 /*
1078 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
1079 * events, but at init time drm_setup_crtcs needs to be called before
1080 * the fb is allocated (since we need to figure out the desired size of
1081 * the fb before we can allocate it ...). Hence we need to fix things up
1082 * here again.
1083 */
96081cdf 1084 for (i = 0; i < fb_helper->crtc_count; i++)
7e53f3a4
DV
1085 if (fb_helper->crtc_info[i].mode_set.num_connectors)
1086 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
1087
785b93ef 1088
8acf658a
DV
1089 info->var.pixclock = 0;
1090 if (register_framebuffer(info) < 0)
1091 return -EINVAL;
38651674 1092
8acf658a
DV
1093 dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n",
1094 info->node, info->fix.id);
785b93ef
DA
1095
1096 /* Switch back to kernel console on panic */
1097 /* multi card linked list maybe */
1098 if (list_empty(&kernel_fb_helper_list)) {
d56b1b9d 1099 dev_info(fb_helper->dev->dev, "registered panic notifier\n");
785b93ef
DA
1100 atomic_notifier_chain_register(&panic_notifier_list,
1101 &paniced);
1102 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
1103 }
8acf658a
DV
1104
1105 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
38651674 1106
785b93ef
DA
1107 return 0;
1108}
785b93ef 1109
207fd329
DV
1110/**
1111 * drm_fb_helper_fill_fix - initializes fixed fbdev information
1112 * @info: fbdev registered by the helper
1113 * @pitch: desired pitch
1114 * @depth: desired depth
1115 *
1116 * Helper to fill in the fixed fbdev information useful for a non-accelerated
1117 * fbdev emulations. Drivers which support acceleration methods which impose
1118 * additional constraints need to set up their own limits.
1119 *
1120 * Drivers should call this (or their equivalent setup code) from their
1121 * ->fb_probe callback.
1122 */
3632ef89
DA
1123void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
1124 uint32_t depth)
1125{
1126 info->fix.type = FB_TYPE_PACKED_PIXELS;
1127 info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
1128 FB_VISUAL_TRUECOLOR;
1129 info->fix.mmio_start = 0;
1130 info->fix.mmio_len = 0;
1131 info->fix.type_aux = 0;
1132 info->fix.xpanstep = 1; /* doing it in hw */
1133 info->fix.ypanstep = 1; /* doing it in hw */
1134 info->fix.ywrapstep = 0;
1135 info->fix.accel = FB_ACCEL_NONE;
3632ef89
DA
1136
1137 info->fix.line_length = pitch;
1138 return;
1139}
1140EXPORT_SYMBOL(drm_fb_helper_fill_fix);
1141
207fd329
DV
1142/**
1143 * drm_fb_helper_fill_var - initalizes variable fbdev information
1144 * @info: fbdev instance to set up
1145 * @fb_helper: fb helper instance to use as template
1146 * @fb_width: desired fb width
1147 * @fb_height: desired fb height
1148 *
1149 * Sets up the variable fbdev metainformation from the given fb helper instance
1150 * and the drm framebuffer allocated in fb_helper->fb.
1151 *
1152 * Drivers should call this (or their equivalent setup code) from their
1153 * ->fb_probe callback after having allocated the fbdev backing
1154 * storage framebuffer.
1155 */
38651674 1156void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
785b93ef
DA
1157 uint32_t fb_width, uint32_t fb_height)
1158{
38651674
DA
1159 struct drm_framebuffer *fb = fb_helper->fb;
1160 info->pseudo_palette = fb_helper->pseudo_palette;
785b93ef
DA
1161 info->var.xres_virtual = fb->width;
1162 info->var.yres_virtual = fb->height;
1163 info->var.bits_per_pixel = fb->bits_per_pixel;
57084d05 1164 info->var.accel_flags = FB_ACCELF_TEXT;
785b93ef
DA
1165 info->var.xoffset = 0;
1166 info->var.yoffset = 0;
1167 info->var.activate = FB_ACTIVATE_NOW;
1168 info->var.height = -1;
1169 info->var.width = -1;
1170
1171 switch (fb->depth) {
1172 case 8:
1173 info->var.red.offset = 0;
1174 info->var.green.offset = 0;
1175 info->var.blue.offset = 0;
1176 info->var.red.length = 8; /* 8bit DAC */
1177 info->var.green.length = 8;
1178 info->var.blue.length = 8;
1179 info->var.transp.offset = 0;
1180 info->var.transp.length = 0;
1181 break;
1182 case 15:
1183 info->var.red.offset = 10;
1184 info->var.green.offset = 5;
1185 info->var.blue.offset = 0;
1186 info->var.red.length = 5;
1187 info->var.green.length = 5;
1188 info->var.blue.length = 5;
1189 info->var.transp.offset = 15;
1190 info->var.transp.length = 1;
1191 break;
1192 case 16:
1193 info->var.red.offset = 11;
1194 info->var.green.offset = 5;
1195 info->var.blue.offset = 0;
1196 info->var.red.length = 5;
1197 info->var.green.length = 6;
1198 info->var.blue.length = 5;
1199 info->var.transp.offset = 0;
1200 break;
1201 case 24:
1202 info->var.red.offset = 16;
1203 info->var.green.offset = 8;
1204 info->var.blue.offset = 0;
1205 info->var.red.length = 8;
1206 info->var.green.length = 8;
1207 info->var.blue.length = 8;
1208 info->var.transp.offset = 0;
1209 info->var.transp.length = 0;
1210 break;
1211 case 32:
1212 info->var.red.offset = 16;
1213 info->var.green.offset = 8;
1214 info->var.blue.offset = 0;
1215 info->var.red.length = 8;
1216 info->var.green.length = 8;
1217 info->var.blue.length = 8;
1218 info->var.transp.offset = 24;
1219 info->var.transp.length = 8;
1220 break;
1221 default:
1222 break;
1223 }
1224
1225 info->var.xres = fb_width;
1226 info->var.yres = fb_height;
1227}
1228EXPORT_SYMBOL(drm_fb_helper_fill_var);
38651674 1229
0b4c0f3f
DA
1230static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
1231 uint32_t maxX,
1232 uint32_t maxY)
38651674
DA
1233{
1234 struct drm_connector *connector;
1235 int count = 0;
0b4c0f3f 1236 int i;
38651674 1237
0b4c0f3f
DA
1238 for (i = 0; i < fb_helper->connector_count; i++) {
1239 connector = fb_helper->connector_info[i]->connector;
38651674
DA
1240 count += connector->funcs->fill_modes(connector, maxX, maxY);
1241 }
1242
1243 return count;
1244}
1245
2f1046f3 1246struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
38651674
DA
1247{
1248 struct drm_display_mode *mode;
1249
0b4c0f3f 1250 list_for_each_entry(mode, &fb_connector->connector->modes, head) {
9d3de138
DV
1251 if (mode->hdisplay > width ||
1252 mode->vdisplay > height)
38651674
DA
1253 continue;
1254 if (mode->type & DRM_MODE_TYPE_PREFERRED)
1255 return mode;
1256 }
1257 return NULL;
1258}
2f1046f3 1259EXPORT_SYMBOL(drm_has_preferred_mode);
38651674 1260
0b4c0f3f 1261static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
38651674 1262{
1794d257 1263 struct drm_cmdline_mode *cmdline_mode;
0b4c0f3f 1264 cmdline_mode = &fb_connector->cmdline_mode;
38651674
DA
1265 return cmdline_mode->specified;
1266}
1267
2f1046f3 1268struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
0b4c0f3f 1269 int width, int height)
38651674 1270{
1794d257 1271 struct drm_cmdline_mode *cmdline_mode;
38651674 1272 struct drm_display_mode *mode = NULL;
c683f427 1273 bool prefer_non_interlace;
38651674 1274
0b4c0f3f 1275 cmdline_mode = &fb_helper_conn->cmdline_mode;
38651674
DA
1276 if (cmdline_mode->specified == false)
1277 return mode;
1278
1279 /* attempt to find a matching mode in the list of modes
1280 * we have gotten so far, if not add a CVT mode that conforms
1281 */
1282 if (cmdline_mode->rb || cmdline_mode->margins)
1283 goto create_mode;
1284
c683f427
TI
1285 prefer_non_interlace = !cmdline_mode->interlace;
1286 again:
0b4c0f3f 1287 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
38651674
DA
1288 /* check width/height */
1289 if (mode->hdisplay != cmdline_mode->xres ||
1290 mode->vdisplay != cmdline_mode->yres)
1291 continue;
1292
1293 if (cmdline_mode->refresh_specified) {
1294 if (mode->vrefresh != cmdline_mode->refresh)
1295 continue;
1296 }
1297
1298 if (cmdline_mode->interlace) {
1299 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
1300 continue;
c683f427
TI
1301 } else if (prefer_non_interlace) {
1302 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1303 continue;
38651674
DA
1304 }
1305 return mode;
1306 }
1307
c683f427
TI
1308 if (prefer_non_interlace) {
1309 prefer_non_interlace = false;
1310 goto again;
1311 }
1312
38651674 1313create_mode:
1794d257
CW
1314 mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
1315 cmdline_mode);
0b4c0f3f 1316 list_add(&mode->head, &fb_helper_conn->connector->modes);
38651674
DA
1317 return mode;
1318}
2f1046f3 1319EXPORT_SYMBOL(drm_pick_cmdline_mode);
38651674
DA
1320
1321static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
1322{
1323 bool enable;
1324
96081cdf 1325 if (strict)
38651674 1326 enable = connector->status == connector_status_connected;
96081cdf 1327 else
38651674 1328 enable = connector->status != connector_status_disconnected;
96081cdf 1329
38651674
DA
1330 return enable;
1331}
1332
0b4c0f3f
DA
1333static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
1334 bool *enabled)
38651674
DA
1335{
1336 bool any_enabled = false;
1337 struct drm_connector *connector;
1338 int i = 0;
1339
0b4c0f3f
DA
1340 for (i = 0; i < fb_helper->connector_count; i++) {
1341 connector = fb_helper->connector_info[i]->connector;
38651674
DA
1342 enabled[i] = drm_connector_enabled(connector, true);
1343 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
1344 enabled[i] ? "yes" : "no");
1345 any_enabled |= enabled[i];
38651674
DA
1346 }
1347
1348 if (any_enabled)
1349 return;
1350
0b4c0f3f
DA
1351 for (i = 0; i < fb_helper->connector_count; i++) {
1352 connector = fb_helper->connector_info[i]->connector;
38651674 1353 enabled[i] = drm_connector_enabled(connector, false);
38651674
DA
1354 }
1355}
1356
1d42bbc8
DA
1357static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
1358 struct drm_display_mode **modes,
1359 bool *enabled, int width, int height)
1360{
1361 int count, i, j;
1362 bool can_clone = false;
1363 struct drm_fb_helper_connector *fb_helper_conn;
1364 struct drm_display_mode *dmt_mode, *mode;
1365
1366 /* only contemplate cloning in the single crtc case */
1367 if (fb_helper->crtc_count > 1)
1368 return false;
1369
1370 count = 0;
1371 for (i = 0; i < fb_helper->connector_count; i++) {
1372 if (enabled[i])
1373 count++;
1374 }
1375
1376 /* only contemplate cloning if more than one connector is enabled */
1377 if (count <= 1)
1378 return false;
1379
1380 /* check the command line or if nothing common pick 1024x768 */
1381 can_clone = true;
1382 for (i = 0; i < fb_helper->connector_count; i++) {
1383 if (!enabled[i])
1384 continue;
1385 fb_helper_conn = fb_helper->connector_info[i];
1386 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1387 if (!modes[i]) {
1388 can_clone = false;
1389 break;
1390 }
1391 for (j = 0; j < i; j++) {
1392 if (!enabled[j])
1393 continue;
1394 if (!drm_mode_equal(modes[j], modes[i]))
1395 can_clone = false;
1396 }
1397 }
1398
1399 if (can_clone) {
1400 DRM_DEBUG_KMS("can clone using command line\n");
1401 return true;
1402 }
1403
1404 /* try and find a 1024x768 mode on each connector */
1405 can_clone = true;
f6e252ba 1406 dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false);
1d42bbc8
DA
1407
1408 for (i = 0; i < fb_helper->connector_count; i++) {
1409
1410 if (!enabled[i])
1411 continue;
1412
1413 fb_helper_conn = fb_helper->connector_info[i];
1414 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1415 if (drm_mode_equal(mode, dmt_mode))
1416 modes[i] = mode;
1417 }
1418 if (!modes[i])
1419 can_clone = false;
1420 }
1421
1422 if (can_clone) {
1423 DRM_DEBUG_KMS("can clone using 1024x768\n");
1424 return true;
1425 }
1426 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1427 return false;
1428}
1429
0b4c0f3f 1430static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
38651674
DA
1431 struct drm_display_mode **modes,
1432 bool *enabled, int width, int height)
1433{
0b4c0f3f
DA
1434 struct drm_fb_helper_connector *fb_helper_conn;
1435 int i;
38651674 1436
0b4c0f3f
DA
1437 for (i = 0; i < fb_helper->connector_count; i++) {
1438 fb_helper_conn = fb_helper->connector_info[i];
38651674 1439
0b4c0f3f 1440 if (enabled[i] == false)
38651674 1441 continue;
38651674
DA
1442
1443 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
0b4c0f3f 1444 fb_helper_conn->connector->base.id);
38651674
DA
1445
1446 /* got for command line mode first */
0b4c0f3f 1447 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
38651674
DA
1448 if (!modes[i]) {
1449 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
0b4c0f3f
DA
1450 fb_helper_conn->connector->base.id);
1451 modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
38651674
DA
1452 }
1453 /* No preferred modes, pick one off the list */
0b4c0f3f
DA
1454 if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
1455 list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
38651674
DA
1456 break;
1457 }
1458 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
1459 "none");
38651674
DA
1460 }
1461 return true;
1462}
1463
8be48d92
DA
1464static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
1465 struct drm_fb_helper_crtc **best_crtcs,
38651674
DA
1466 struct drm_display_mode **modes,
1467 int n, int width, int height)
1468{
1469 int c, o;
8be48d92 1470 struct drm_device *dev = fb_helper->dev;
38651674
DA
1471 struct drm_connector *connector;
1472 struct drm_connector_helper_funcs *connector_funcs;
1473 struct drm_encoder *encoder;
38651674 1474 int my_score, best_score, score;
8be48d92 1475 struct drm_fb_helper_crtc **crtcs, *crtc;
0b4c0f3f 1476 struct drm_fb_helper_connector *fb_helper_conn;
38651674 1477
0b4c0f3f 1478 if (n == fb_helper->connector_count)
38651674 1479 return 0;
0b4c0f3f
DA
1480
1481 fb_helper_conn = fb_helper->connector_info[n];
1482 connector = fb_helper_conn->connector;
38651674
DA
1483
1484 best_crtcs[n] = NULL;
8be48d92 1485 best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
38651674
DA
1486 if (modes[n] == NULL)
1487 return best_score;
1488
8be48d92
DA
1489 crtcs = kzalloc(dev->mode_config.num_connector *
1490 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
38651674
DA
1491 if (!crtcs)
1492 return best_score;
1493
1494 my_score = 1;
1495 if (connector->status == connector_status_connected)
1496 my_score++;
0b4c0f3f 1497 if (drm_has_cmdline_mode(fb_helper_conn))
38651674 1498 my_score++;
0b4c0f3f 1499 if (drm_has_preferred_mode(fb_helper_conn, width, height))
38651674
DA
1500 my_score++;
1501
1502 connector_funcs = connector->helper_private;
1503 encoder = connector_funcs->best_encoder(connector);
1504 if (!encoder)
1505 goto out;
1506
38651674
DA
1507 /* select a crtc for this connector and then attempt to configure
1508 remaining connectors */
8be48d92
DA
1509 for (c = 0; c < fb_helper->crtc_count; c++) {
1510 crtc = &fb_helper->crtc_info[c];
38651674 1511
96081cdf 1512 if ((encoder->possible_crtcs & (1 << c)) == 0)
38651674 1513 continue;
38651674
DA
1514
1515 for (o = 0; o < n; o++)
1516 if (best_crtcs[o] == crtc)
1517 break;
1518
1519 if (o < n) {
1d42bbc8
DA
1520 /* ignore cloning unless only a single crtc */
1521 if (fb_helper->crtc_count > 1)
1522 continue;
1523
1524 if (!drm_mode_equal(modes[o], modes[n]))
1525 continue;
38651674
DA
1526 }
1527
1528 crtcs[n] = crtc;
8be48d92
DA
1529 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1530 score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
38651674
DA
1531 width, height);
1532 if (score > best_score) {
38651674
DA
1533 best_score = score;
1534 memcpy(best_crtcs, crtcs,
1535 dev->mode_config.num_connector *
8be48d92 1536 sizeof(struct drm_fb_helper_crtc *));
38651674 1537 }
38651674
DA
1538 }
1539out:
1540 kfree(crtcs);
1541 return best_score;
1542}
1543
8be48d92 1544static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
38651674 1545{
8be48d92
DA
1546 struct drm_device *dev = fb_helper->dev;
1547 struct drm_fb_helper_crtc **crtcs;
38651674 1548 struct drm_display_mode **modes;
8be48d92 1549 struct drm_mode_set *modeset;
38651674
DA
1550 bool *enabled;
1551 int width, height;
11e17a08 1552 int i;
38651674
DA
1553
1554 DRM_DEBUG_KMS("\n");
1555
1556 width = dev->mode_config.max_width;
1557 height = dev->mode_config.max_height;
1558
38651674 1559 crtcs = kcalloc(dev->mode_config.num_connector,
8be48d92 1560 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
38651674
DA
1561 modes = kcalloc(dev->mode_config.num_connector,
1562 sizeof(struct drm_display_mode *), GFP_KERNEL);
1563 enabled = kcalloc(dev->mode_config.num_connector,
1564 sizeof(bool), GFP_KERNEL);
8c5eaca0
SK
1565 if (!crtcs || !modes || !enabled) {
1566 DRM_ERROR("Memory allocation failed\n");
1567 goto out;
1568 }
1569
38651674 1570
0b4c0f3f 1571 drm_enable_connectors(fb_helper, enabled);
38651674 1572
11e17a08
JB
1573 if (!(fb_helper->funcs->initial_config &&
1574 fb_helper->funcs->initial_config(fb_helper, crtcs, modes,
1575 enabled, width, height))) {
1576 memset(modes, 0, dev->mode_config.num_connector*sizeof(modes[0]));
1577 memset(crtcs, 0, dev->mode_config.num_connector*sizeof(crtcs[0]));
1578
1579 if (!drm_target_cloned(fb_helper,
1580 modes, enabled, width, height) &&
1581 !drm_target_preferred(fb_helper,
1582 modes, enabled, width, height))
1d42bbc8 1583 DRM_ERROR("Unable to find initial modes\n");
38651674 1584
11e17a08
JB
1585 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
1586 width, height);
38651674 1587
11e17a08
JB
1588 drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1589 }
8be48d92
DA
1590
1591 /* need to set the modesets up here for use later */
1592 /* fill out the connector<->crtc mappings into the modesets */
1593 for (i = 0; i < fb_helper->crtc_count; i++) {
1594 modeset = &fb_helper->crtc_info[i].mode_set;
1595 modeset->num_connectors = 0;
7e53f3a4 1596 modeset->fb = NULL;
8be48d92 1597 }
38651674 1598
0b4c0f3f 1599 for (i = 0; i < fb_helper->connector_count; i++) {
38651674 1600 struct drm_display_mode *mode = modes[i];
8be48d92
DA
1601 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1602 modeset = &fb_crtc->mode_set;
38651674 1603
8be48d92 1604 if (mode && fb_crtc) {
38651674 1605 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
8be48d92
DA
1606 mode->name, fb_crtc->mode_set.crtc->base.id);
1607 fb_crtc->desired_mode = mode;
1608 if (modeset->mode)
1609 drm_mode_destroy(dev, modeset->mode);
1610 modeset->mode = drm_mode_duplicate(dev,
1611 fb_crtc->desired_mode);
0b4c0f3f 1612 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
7e53f3a4 1613 modeset->fb = fb_helper->fb;
38651674 1614 }
38651674
DA
1615 }
1616
7e53f3a4
DV
1617 /* Clear out any old modes if there are no more connected outputs. */
1618 for (i = 0; i < fb_helper->crtc_count; i++) {
1619 modeset = &fb_helper->crtc_info[i].mode_set;
1620 if (modeset->num_connectors == 0) {
1621 BUG_ON(modeset->fb);
1622 BUG_ON(modeset->num_connectors);
1623 if (modeset->mode)
1624 drm_mode_destroy(dev, modeset->mode);
1625 modeset->mode = NULL;
1626 }
1627 }
8c5eaca0 1628out:
38651674
DA
1629 kfree(crtcs);
1630 kfree(modes);
1631 kfree(enabled);
1632}
1633
1634/**
207fd329 1635 * drm_fb_helper_initial_config - setup a sane initial connector configuration
d0ddc033
DV
1636 * @fb_helper: fb_helper device struct
1637 * @bpp_sel: bpp value to use for the framebuffer configuration
38651674 1638 *
d0ddc033 1639 * Scans the CRTCs and connectors and tries to put together an initial setup.
38651674
DA
1640 * At the moment, this is a cloned configuration across all heads with
1641 * a new framebuffer object as the backing store.
1642 *
207fd329
DV
1643 * Note that this also registers the fbdev and so allows userspace to call into
1644 * the driver through the fbdev interfaces.
1645 *
1646 * This function will call down into the ->fb_probe callback to let
1647 * the driver allocate and initialize the fbdev info structure and the drm
1648 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
1649 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
1650 * values for the fbdev info structure.
1651 *
38651674
DA
1652 * RETURNS:
1653 * Zero if everything went ok, nonzero otherwise.
1654 */
4abe3520 1655bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
38651674 1656{
8be48d92 1657 struct drm_device *dev = fb_helper->dev;
38651674
DA
1658 int count = 0;
1659
0b4c0f3f 1660 drm_fb_helper_parse_command_line(fb_helper);
38651674 1661
53f1904b 1662 mutex_lock(&dev->mode_config.mutex);
0b4c0f3f
DA
1663 count = drm_fb_helper_probe_connector_modes(fb_helper,
1664 dev->mode_config.max_width,
1665 dev->mode_config.max_height);
53f1904b 1666 mutex_unlock(&dev->mode_config.mutex);
38651674
DA
1667 /*
1668 * we shouldn't end up with no modes here.
1669 */
96081cdf 1670 if (count == 0)
d56b1b9d 1671 dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
96081cdf 1672
8be48d92 1673 drm_setup_crtcs(fb_helper);
38651674 1674
4abe3520 1675 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
38651674 1676}
8be48d92 1677EXPORT_SYMBOL(drm_fb_helper_initial_config);
38651674 1678
7394371d
CW
1679/**
1680 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
d0ddc033 1681 * probing all the outputs attached to the fb
7394371d
CW
1682 * @fb_helper: the drm_fb_helper
1683 *
7394371d
CW
1684 * Scan the connectors attached to the fb_helper and try to put together a
1685 * setup after *notification of a change in output configuration.
1686 *
207fd329
DV
1687 * Called at runtime, takes the mode config locks to be able to check/change the
1688 * modeset configuration. Must be run from process context (which usually means
1689 * either the output polling work or a work item launched from the driver's
1690 * hotplug interrupt).
1691 *
50c3dc97
DV
1692 * Note that drivers may call this even before calling
1693 * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows
1694 * for a race-free fbcon setup and will make sure that the fbdev emulation will
1695 * not miss any hotplug events.
207fd329 1696 *
7394371d
CW
1697 * RETURNS:
1698 * 0 on success and a non-zero error code otherwise.
1699 */
1700int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
38651674 1701{
7394371d 1702 struct drm_device *dev = fb_helper->dev;
51bbd276 1703 u32 max_width, max_height;
5c4426a7 1704
89ced125 1705 mutex_lock(&fb_helper->dev->mode_config.mutex);
50c3dc97 1706 if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) {
4abe3520 1707 fb_helper->delayed_hotplug = true;
89ced125 1708 mutex_unlock(&fb_helper->dev->mode_config.mutex);
7394371d 1709 return 0;
4abe3520 1710 }
eb1f8e4f 1711 DRM_DEBUG_KMS("\n");
4abe3520 1712
eb1f8e4f
DA
1713 max_width = fb_helper->fb->width;
1714 max_height = fb_helper->fb->height;
5c4426a7 1715
51bbd276 1716 drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height);
89ced125
DV
1717 mutex_unlock(&fb_helper->dev->mode_config.mutex);
1718
1719 drm_modeset_lock_all(dev);
eb1f8e4f 1720 drm_setup_crtcs(fb_helper);
84849903 1721 drm_modeset_unlock_all(dev);
2180c3c7
DV
1722 drm_fb_helper_set_par(fb_helper->fbdev);
1723
1724 return 0;
5c4426a7 1725}
eb1f8e4f 1726EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
5c4426a7 1727
6a108a14 1728/* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
3ce05168
DF
1729 * but the module doesn't depend on any fb console symbols. At least
1730 * attempt to load fbcon to avoid leaving the system without a usable console.
1731 */
6a108a14 1732#if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
3ce05168
DF
1733static int __init drm_fb_helper_modinit(void)
1734{
1735 const char *name = "fbcon";
1736 struct module *fbcon;
1737
1738 mutex_lock(&module_mutex);
1739 fbcon = find_module(name);
1740 mutex_unlock(&module_mutex);
1741
1742 if (!fbcon)
1743 request_module_nowait(name);
1744 return 0;
1745}
1746
1747module_init(drm_fb_helper_modinit);
1748#endif
This page took 0.49297 seconds and 5 git commands to generate.