Subversion Repositories Kolibri OS

Rev

Rev 3298 | Rev 3746 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1179 serge 1
/*
2
 * Copyright (c) 2006-2009 Red Hat Inc.
3
 * Copyright (c) 2006-2008 Intel Corporation
4
 * Copyright (c) 2007 Dave Airlie 
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 
28
 *      Jesse Barnes 
29
 */
3192 Serge 30
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
 
1430 serge 32
#include 
1963 serge 33
#include 
34
#include 
1179 serge 35
#include 
3031 serge 36
#include 
37
#include 
38
#include 
39
#include 
40
#include 
1179 serge 41
 
1430 serge 42
MODULE_AUTHOR("David Airlie, Jesse Barnes");
43
MODULE_DESCRIPTION("DRM KMS helper");
44
MODULE_LICENSE("GPL and additional rights");
1179 serge 45
 
46
static LIST_HEAD(kernel_fb_helper_list);
47
 
3192 Serge 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.
3480 Serge 55
 *
56
 * Initialization is done as a three-step process with drm_fb_helper_init(),
57
 * drm_fb_helper_single_add_all_connectors() and drm_fb_helper_initial_config().
58
 * Drivers with fancier requirements than the default beheviour can override the
59
 * second step with their own code.  Teardown is done with drm_fb_helper_fini().
60
 *
61
 * At runtime drivers should restore the fbdev console by calling
62
 * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
63
 * should also notify the fb helper code from updates to the output
64
 * configuration by calling drm_fb_helper_hotplug_event(). For easier
65
 * integration with the output polling code in drm_crtc_helper.c the modeset
66
 * code proves a ->output_poll_changed callback.
67
 *
68
 * All other functions exported by the fb helper library can be used to
69
 * implement the fbdev driver interface by the driver.
3192 Serge 70
 */
71
 
3480 Serge 72
/**
73
 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
74
 * 					       emulation helper
75
 * @fb_helper: fbdev initialized with drm_fb_helper_init
76
 *
77
 * This functions adds all the available connectors for use with the given
78
 * fb_helper. This is a separate step to allow drivers to freely assign
79
 * connectors to the fbdev, e.g. if some are reserved for special purposes or
80
 * not adequate to be used for the fbcon.
81
 *
82
 * Since this is part of the initial setup before the fbdev is published, no
83
 * locking is required.
84
 */
1963 serge 85
int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
1221 serge 86
{
1963 serge 87
	struct drm_device *dev = fb_helper->dev;
88
	struct drm_connector *connector;
89
	int i;
1221 serge 90
 
1963 serge 91
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
92
		struct drm_fb_helper_connector *fb_helper_connector;
93
 
94
		fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
95
		if (!fb_helper_connector)
96
			goto fail;
97
 
98
		fb_helper_connector->connector = connector;
99
		fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
100
	}
1221 serge 101
	return 0;
1963 serge 102
fail:
103
	for (i = 0; i < fb_helper->connector_count; i++) {
104
		kfree(fb_helper->connector_info[i]);
105
		fb_helper->connector_info[i] = NULL;
106
	}
107
	fb_helper->connector_count = 0;
108
    return -ENOMEM;
1221 serge 109
}
1963 serge 110
EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
1221 serge 111
 
1963 serge 112
static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper)
1179 serge 113
{
1963 serge 114
	uint16_t *r_base, *g_base, *b_base;
115
	int i;
1179 serge 116
 
1963 serge 117
	r_base = crtc->gamma_store;
118
	g_base = r_base + crtc->gamma_size;
119
	b_base = g_base + crtc->gamma_size;
1179 serge 120
 
1963 serge 121
	for (i = 0; i < crtc->gamma_size; i++)
122
		helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i);
1179 serge 123
}
124
 
1963 serge 125
static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
1179 serge 126
{
1963 serge 127
	uint16_t *r_base, *g_base, *b_base;
128
 
3031 serge 129
	if (crtc->funcs->gamma_set == NULL)
130
		return;
131
 
1963 serge 132
	r_base = crtc->gamma_store;
133
	g_base = r_base + crtc->gamma_size;
134
	b_base = g_base + crtc->gamma_size;
135
 
136
	crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
1179 serge 137
}
138
 
139
 
3480 Serge 140
static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
141
{
142
	struct drm_device *dev = fb_helper->dev;
143
	struct drm_crtc *crtc;
144
	int bound = 0, crtcs_bound = 0;
1179 serge 145
 
3480 Serge 146
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
147
		if (crtc->fb)
148
			crtcs_bound++;
149
		if (crtc->fb == fb_helper->fb)
150
			bound++;
151
	}
152
 
153
	if (bound < crtcs_bound)
154
		return false;
155
	return true;
156
}
157
 
3031 serge 158
static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
1179 serge 159
{
160
	struct drm_fb_helper *fb_helper = info->par;
161
	struct drm_device *dev = fb_helper->dev;
162
	struct drm_crtc *crtc;
1963 serge 163
	struct drm_connector *connector;
164
	int i, j;
1179 serge 165
 
166
	/*
3480 Serge 167
	 * fbdev->blank can be called from irq context in case of a panic.
168
	 * Since we already have our own special panic handler which will
169
	 * restore the fbdev console mode completely, just bail out early.
170
	 */
171
 
172
	/*
3031 serge 173
	 * For each CRTC in this fb, turn the connectors on/off.
1179 serge 174
	 */
3480 Serge 175
	drm_modeset_lock_all(dev);
176
	if (!drm_fb_helper_is_bound(fb_helper)) {
177
		drm_modeset_unlock_all(dev);
178
		return;
179
	}
180
 
1179 serge 181
	for (i = 0; i < fb_helper->crtc_count; i++) {
1963 serge 182
		crtc = fb_helper->crtc_info[i].mode_set.crtc;
1179 serge 183
 
1963 serge 184
		if (!crtc->enabled)
1179 serge 185
				continue;
186
 
3031 serge 187
		/* Walk the connectors & encoders on this fb turning them on/off */
1963 serge 188
		for (j = 0; j < fb_helper->connector_count; j++) {
189
			connector = fb_helper->connector_info[j]->connector;
3031 serge 190
			connector->funcs->dpms(connector, dpms_mode);
3192 Serge 191
			drm_object_property_set_value(&connector->base,
3031 serge 192
				dev->mode_config.dpms_property, dpms_mode);
1963 serge 193
		}
194
	}
3480 Serge 195
	drm_modeset_unlock_all(dev);
1179 serge 196
}
197
 
3480 Serge 198
/**
199
 * drm_fb_helper_blank - implementation for ->fb_blank
200
 * @blank: desired blanking state
201
 * @info: fbdev registered by the helper
202
 */
1179 serge 203
int drm_fb_helper_blank(int blank, struct fb_info *info)
204
{
205
	switch (blank) {
1321 serge 206
	/* Display: On; HSync: On, VSync: On */
1179 serge 207
	case FB_BLANK_UNBLANK:
3031 serge 208
		drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON);
1179 serge 209
		break;
1321 serge 210
	/* Display: Off; HSync: On, VSync: On */
1179 serge 211
	case FB_BLANK_NORMAL:
3031 serge 212
		drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
1179 serge 213
		break;
1321 serge 214
	/* Display: Off; HSync: Off, VSync: On */
1179 serge 215
	case FB_BLANK_HSYNC_SUSPEND:
3031 serge 216
		drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
1179 serge 217
		break;
1321 serge 218
	/* Display: Off; HSync: On, VSync: Off */
1179 serge 219
	case FB_BLANK_VSYNC_SUSPEND:
3031 serge 220
		drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND);
1179 serge 221
		break;
1321 serge 222
	/* Display: Off; HSync: Off, VSync: Off */
1179 serge 223
	case FB_BLANK_POWERDOWN:
3031 serge 224
		drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF);
1179 serge 225
		break;
226
	}
227
	return 0;
228
}
229
EXPORT_SYMBOL(drm_fb_helper_blank);
230
 
231
static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
232
{
233
	int i;
234
 
1963 serge 235
	for (i = 0; i < helper->connector_count; i++)
236
		kfree(helper->connector_info[i]);
237
	kfree(helper->connector_info);
3031 serge 238
	for (i = 0; i < helper->crtc_count; i++) {
1179 serge 239
		kfree(helper->crtc_info[i].mode_set.connectors);
3031 serge 240
		if (helper->crtc_info[i].mode_set.mode)
241
			drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode);
242
	}
1179 serge 243
	kfree(helper->crtc_info);
244
}
245
 
3480 Serge 246
/**
247
 * drm_fb_helper_init - initialize a drm_fb_helper structure
248
 * @dev: drm device
249
 * @fb_helper: driver-allocated fbdev helper structure to initialize
250
 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
251
 * @max_conn_count: max connector count
252
 *
253
 * This allocates the structures for the fbdev helper with the given limits.
254
 * Note that this won't yet touch the hardware (through the driver interfaces)
255
 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
256
 * to allow driver writes more control over the exact init sequence.
257
 *
258
 * Drivers must set fb_helper->funcs before calling
259
 * drm_fb_helper_initial_config().
260
 *
261
 * RETURNS:
262
 * Zero if everything went ok, nonzero otherwise.
263
 */
1963 serge 264
int drm_fb_helper_init(struct drm_device *dev,
265
		       struct drm_fb_helper *fb_helper,
266
		       int crtc_count, int max_conn_count)
1179 serge 267
{
268
	struct drm_crtc *crtc;
269
	int i;
270
 
1963 serge 271
	fb_helper->dev = dev;
272
 
273
	INIT_LIST_HEAD(&fb_helper->kernel_fb_list);
274
 
275
	fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
276
	if (!fb_helper->crtc_info)
1179 serge 277
		return -ENOMEM;
278
 
1963 serge 279
	fb_helper->crtc_count = crtc_count;
280
	fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
281
	if (!fb_helper->connector_info) {
282
		kfree(fb_helper->crtc_info);
283
		return -ENOMEM;
284
	}
285
	fb_helper->connector_count = 0;
1179 serge 286
 
287
	for (i = 0; i < crtc_count; i++) {
1963 serge 288
		fb_helper->crtc_info[i].mode_set.connectors =
1179 serge 289
			kcalloc(max_conn_count,
290
				sizeof(struct drm_connector *),
291
				GFP_KERNEL);
292
 
3031 serge 293
		if (!fb_helper->crtc_info[i].mode_set.connectors)
1179 serge 294
			goto out_free;
1963 serge 295
		fb_helper->crtc_info[i].mode_set.num_connectors = 0;
1179 serge 296
	}
297
 
298
	i = 0;
299
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
1963 serge 300
		fb_helper->crtc_info[i].mode_set.crtc = crtc;
1179 serge 301
		i++;
302
	}
3031 serge 303
 
1179 serge 304
	return 0;
305
out_free:
1963 serge 306
	drm_fb_helper_crtc_free(fb_helper);
1179 serge 307
	return -ENOMEM;
308
}
1963 serge 309
EXPORT_SYMBOL(drm_fb_helper_init);
1179 serge 310
 
1246 serge 311
static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
1221 serge 312
		     u16 blue, u16 regno, struct fb_info *info)
313
{
314
	struct drm_fb_helper *fb_helper = info->par;
315
	struct drm_framebuffer *fb = fb_helper->fb;
316
	int pindex;
317
 
1246 serge 318
	if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
319
		u32 *palette;
320
		u32 value;
321
		/* place color in psuedopalette */
322
		if (regno > 16)
323
			return -EINVAL;
324
		palette = (u32 *)info->pseudo_palette;
325
		red >>= (16 - info->var.red.length);
326
		green >>= (16 - info->var.green.length);
327
		blue >>= (16 - info->var.blue.length);
328
		value = (red << info->var.red.offset) |
329
			(green << info->var.green.offset) |
330
			(blue << info->var.blue.offset);
1963 serge 331
		if (info->var.transp.length > 0) {
332
			u32 mask = (1 << info->var.transp.length) - 1;
333
			mask <<= info->var.transp.offset;
334
			value |= mask;
335
		}
1246 serge 336
		palette[regno] = value;
337
		return 0;
338
	}
339
 
1221 serge 340
	pindex = regno;
341
 
342
	if (fb->bits_per_pixel == 16) {
343
		pindex = regno << 3;
344
 
345
		if (fb->depth == 16 && regno > 63)
1246 serge 346
			return -EINVAL;
1221 serge 347
		if (fb->depth == 15 && regno > 31)
1246 serge 348
			return -EINVAL;
1221 serge 349
 
350
		if (fb->depth == 16) {
351
			u16 r, g, b;
352
			int i;
353
			if (regno < 32) {
354
				for (i = 0; i < 8; i++)
355
					fb_helper->funcs->gamma_set(crtc, red,
356
						green, blue, pindex + i);
357
			}
358
 
359
			fb_helper->funcs->gamma_get(crtc, &r,
360
						    &g, &b,
361
						    pindex >> 1);
362
 
363
			for (i = 0; i < 4; i++)
364
				fb_helper->funcs->gamma_set(crtc, r,
365
							    green, b,
366
							    (pindex >> 1) + i);
367
		}
368
	}
369
 
370
	if (fb->depth != 16)
371
		fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
1246 serge 372
	return 0;
1221 serge 373
}
374
 
3480 Serge 375
/**
376
 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
377
 * @cmap: cmap to set
378
 * @info: fbdev registered by the helper
379
 */
1221 serge 380
int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
381
{
382
	struct drm_fb_helper *fb_helper = info->par;
1963 serge 383
	struct drm_crtc_helper_funcs *crtc_funcs;
1221 serge 384
	u16 *red, *green, *blue, *transp;
385
	struct drm_crtc *crtc;
1963 serge 386
	int i, j, rc = 0;
1221 serge 387
	int start;
388
 
389
		for (i = 0; i < fb_helper->crtc_count; i++) {
1963 serge 390
		crtc = fb_helper->crtc_info[i].mode_set.crtc;
391
		crtc_funcs = crtc->helper_private;
1221 serge 392
 
393
		red = cmap->red;
394
		green = cmap->green;
395
		blue = cmap->blue;
396
		transp = cmap->transp;
397
		start = cmap->start;
398
 
1963 serge 399
		for (j = 0; j < cmap->len; j++) {
1221 serge 400
			u16 hred, hgreen, hblue, htransp = 0xffff;
401
 
402
			hred = *red++;
403
			hgreen = *green++;
404
			hblue = *blue++;
405
 
406
			if (transp)
407
				htransp = *transp++;
408
 
1246 serge 409
			rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
410
			if (rc)
411
				return rc;
1221 serge 412
		}
413
		crtc_funcs->load_lut(crtc);
414
	}
415
	return rc;
416
}
417
EXPORT_SYMBOL(drm_fb_helper_setcmap);
418
 
3480 Serge 419
/**
420
 * drm_fb_helper_check_var - implementation for ->fb_check_var
421
 * @var: screeninfo to check
422
 * @info: fbdev registered by the helper
423
 */
1179 serge 424
int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
425
			    struct fb_info *info)
426
{
427
	struct drm_fb_helper *fb_helper = info->par;
428
	struct drm_framebuffer *fb = fb_helper->fb;
429
	int depth;
430
 
1963 serge 431
	if (var->pixclock != 0 || in_dbg_master())
1179 serge 432
		return -EINVAL;
433
 
434
	/* Need to resize the fb object !!! */
3031 serge 435
	if (var->bits_per_pixel > fb->bits_per_pixel ||
436
	    var->xres > fb->width || var->yres > fb->height ||
437
	    var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
1404 serge 438
		DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
3031 serge 439
			  "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
440
			  var->xres, var->yres, var->bits_per_pixel,
441
			  var->xres_virtual, var->yres_virtual,
1404 serge 442
			  fb->width, fb->height, fb->bits_per_pixel);
1179 serge 443
		return -EINVAL;
444
	}
445
 
446
	switch (var->bits_per_pixel) {
447
	case 16:
448
		depth = (var->green.length == 6) ? 16 : 15;
449
		break;
450
	case 32:
451
		depth = (var->transp.length > 0) ? 32 : 24;
452
		break;
453
	default:
454
		depth = var->bits_per_pixel;
455
		break;
456
	}
457
 
458
	switch (depth) {
459
	case 8:
460
		var->red.offset = 0;
461
		var->green.offset = 0;
462
		var->blue.offset = 0;
463
		var->red.length = 8;
464
		var->green.length = 8;
465
		var->blue.length = 8;
466
		var->transp.length = 0;
467
		var->transp.offset = 0;
468
		break;
469
	case 15:
470
		var->red.offset = 10;
471
		var->green.offset = 5;
472
		var->blue.offset = 0;
473
		var->red.length = 5;
474
		var->green.length = 5;
475
		var->blue.length = 5;
476
		var->transp.length = 1;
477
		var->transp.offset = 15;
478
		break;
479
	case 16:
480
		var->red.offset = 11;
481
		var->green.offset = 5;
482
		var->blue.offset = 0;
483
		var->red.length = 5;
484
		var->green.length = 6;
485
		var->blue.length = 5;
486
		var->transp.length = 0;
487
		var->transp.offset = 0;
488
		break;
489
	case 24:
490
		var->red.offset = 16;
491
		var->green.offset = 8;
492
		var->blue.offset = 0;
493
		var->red.length = 8;
494
		var->green.length = 8;
495
		var->blue.length = 8;
496
		var->transp.length = 0;
497
		var->transp.offset = 0;
498
		break;
499
	case 32:
500
		var->red.offset = 16;
501
		var->green.offset = 8;
502
		var->blue.offset = 0;
503
		var->red.length = 8;
504
		var->green.length = 8;
505
		var->blue.length = 8;
506
		var->transp.length = 8;
507
		var->transp.offset = 24;
508
		break;
509
	default:
510
		return -EINVAL;
511
	}
512
	return 0;
513
}
514
EXPORT_SYMBOL(drm_fb_helper_check_var);
515
 
3480 Serge 516
/**
517
 * drm_fb_helper_set_par - implementation for ->fb_set_par
518
 * @info: fbdev registered by the helper
519
 *
520
 * This will let fbcon do the mode init and is called at initialization time by
521
 * the fbdev core when registering the driver, and later on through the hotplug
522
 * callback.
523
 */
1179 serge 524
int drm_fb_helper_set_par(struct fb_info *info)
525
{
526
	struct drm_fb_helper *fb_helper = info->par;
527
	struct drm_device *dev = fb_helper->dev;
528
	struct fb_var_screeninfo *var = &info->var;
529
	int ret;
530
	int i;
531
 
1313 serge 532
	if (var->pixclock != 0) {
1430 serge 533
		DRM_ERROR("PIXEL CLOCK SET\n");
1179 serge 534
		return -EINVAL;
535
	}
536
 
3480 Serge 537
	drm_modeset_lock_all(dev);
1179 serge 538
		for (i = 0; i < fb_helper->crtc_count; i++) {
3480 Serge 539
		ret = drm_mode_set_config_internal(&fb_helper->crtc_info[i].mode_set);
1963 serge 540
		if (ret) {
3480 Serge 541
			drm_modeset_unlock_all(dev);
1179 serge 542
				return ret;
543
		}
544
	}
3480 Serge 545
	drm_modeset_unlock_all(dev);
1963 serge 546
 
547
	if (fb_helper->delayed_hotplug) {
548
		fb_helper->delayed_hotplug = false;
3480 Serge 549
		drm_fb_helper_hotplug_event(fb_helper);
1963 serge 550
	}
1179 serge 551
	return 0;
552
}
553
EXPORT_SYMBOL(drm_fb_helper_set_par);
554
 
3480 Serge 555
/**
556
 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
557
 * @var: updated screen information
558
 * @info: fbdev registered by the helper
559
 */
1179 serge 560
int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
561
			      struct fb_info *info)
562
{
563
	struct drm_fb_helper *fb_helper = info->par;
564
	struct drm_device *dev = fb_helper->dev;
565
	struct drm_mode_set *modeset;
566
	struct drm_crtc *crtc;
567
	int ret = 0;
568
	int i;
569
 
3480 Serge 570
	drm_modeset_lock_all(dev);
571
	if (!drm_fb_helper_is_bound(fb_helper)) {
572
		drm_modeset_unlock_all(dev);
573
		return -EBUSY;
574
	}
575
 
1179 serge 576
		for (i = 0; i < fb_helper->crtc_count; i++) {
1963 serge 577
		crtc = fb_helper->crtc_info[i].mode_set.crtc;
1179 serge 578
 
579
		modeset = &fb_helper->crtc_info[i].mode_set;
580
 
581
		modeset->x = var->xoffset;
582
		modeset->y = var->yoffset;
583
 
584
		if (modeset->num_connectors) {
3480 Serge 585
			ret = drm_mode_set_config_internal(modeset);
1179 serge 586
			if (!ret) {
587
				info->var.xoffset = var->xoffset;
588
				info->var.yoffset = var->yoffset;
589
			}
590
		}
591
	}
3480 Serge 592
	drm_modeset_unlock_all(dev);
1179 serge 593
	return ret;
594
}
595
EXPORT_SYMBOL(drm_fb_helper_pan_display);
596
 
3480 Serge 597
/*
598
 * Allocates the backing storage and sets up the fbdev info structure through
599
 * the ->fb_probe callback and then registers the fbdev and sets up the panic
600
 * notifier.
601
 */
602
static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
1963 serge 603
				  int preferred_bpp)
1179 serge 604
{
3480 Serge 605
	int ret = 0;
1179 serge 606
	int crtc_count = 0;
1963 serge 607
	int i;
1179 serge 608
	struct fb_info *info;
1963 serge 609
	struct drm_fb_helper_surface_size sizes;
610
	int gamma_size = 0;
1179 serge 611
 
1963 serge 612
	memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
613
	sizes.surface_depth = 24;
614
	sizes.surface_bpp = 32;
615
	sizes.fb_width = (unsigned)-1;
616
	sizes.fb_height = (unsigned)-1;
1221 serge 617
 
3031 serge 618
	/* if driver picks 8 or 16 by default use that
619
	   for both depth/bpp */
3192 Serge 620
	if (preferred_bpp != sizes.surface_bpp)
3031 serge 621
		sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
3192 Serge 622
 
3031 serge 623
	/* first up get a count of crtcs now in use and new min/maxes width/heights */
624
	for (i = 0; i < fb_helper->connector_count; i++) {
625
		struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
626
		struct drm_cmdline_mode *cmdline_mode;
627
 
628
		cmdline_mode = &fb_helper_conn->cmdline_mode;
629
 
630
		if (cmdline_mode->bpp_specified) {
631
			switch (cmdline_mode->bpp) {
632
			case 8:
633
				sizes.surface_depth = sizes.surface_bpp = 8;
634
				break;
635
			case 15:
636
				sizes.surface_depth = 15;
637
				sizes.surface_bpp = 16;
638
				break;
639
			case 16:
640
				sizes.surface_depth = sizes.surface_bpp = 16;
641
				break;
642
			case 24:
643
				sizes.surface_depth = sizes.surface_bpp = 24;
644
				break;
645
			case 32:
1963 serge 646
    sizes.surface_depth = 24;
647
    sizes.surface_bpp = 32;
3031 serge 648
				break;
649
			}
650
			break;
651
		}
652
	}
1221 serge 653
 
1963 serge 654
	crtc_count = 0;
655
	for (i = 0; i < fb_helper->crtc_count; i++) {
656
		struct drm_display_mode *desired_mode;
657
		desired_mode = fb_helper->crtc_info[i].desired_mode;
1221 serge 658
 
1963 serge 659
		if (desired_mode) {
660
			if (gamma_size == 0)
661
				gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
662
			if (desired_mode->hdisplay < sizes.fb_width)
663
				sizes.fb_width = desired_mode->hdisplay;
664
			if (desired_mode->vdisplay < sizes.fb_height)
665
				sizes.fb_height = desired_mode->vdisplay;
666
			if (desired_mode->hdisplay > sizes.surface_width)
667
				sizes.surface_width = desired_mode->hdisplay;
668
			if (desired_mode->vdisplay > sizes.surface_height)
669
				sizes.surface_height = desired_mode->vdisplay;
1179 serge 670
			crtc_count++;
671
		}
672
	}
673
 
1963 serge 674
	if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
1179 serge 675
		/* hmm everyone went away - assume VGA cable just fell out
676
		   and will come back later. */
1963 serge 677
		DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
678
		sizes.fb_width = sizes.surface_width = 1024;
679
		sizes.fb_height = sizes.surface_height = 768;
1179 serge 680
	}
681
 
1963 serge 682
	/* push down into drivers */
3480 Serge 683
	ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
684
	if (ret < 0)
685
		return ret;
1179 serge 686
 
1963 serge 687
	info = fb_helper->fbdev;
1179 serge 688
 
3480 Serge 689
	/*
690
	 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
691
	 * events, but at init time drm_setup_crtcs needs to be called before
692
	 * the fb is allocated (since we need to figure out the desired size of
693
	 * the fb before we can allocate it ...). Hence we need to fix things up
694
	 * here again.
695
	 */
3192 Serge 696
	for (i = 0; i < fb_helper->crtc_count; i++)
3480 Serge 697
		if (fb_helper->crtc_info[i].mode_set.num_connectors)
1963 serge 698
		fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
1179 serge 699
 
3480 Serge 700
 
1313 serge 701
		info->var.pixclock = 0;
1963 serge 702
 
703
        list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
704
 
1179 serge 705
	return 0;
706
}
707
 
3480 Serge 708
/**
709
 * drm_fb_helper_fill_fix - initializes fixed fbdev information
710
 * @info: fbdev registered by the helper
711
 * @pitch: desired pitch
712
 * @depth: desired depth
713
 *
714
 * Helper to fill in the fixed fbdev information useful for a non-accelerated
715
 * fbdev emulations. Drivers which support acceleration methods which impose
716
 * additional constraints need to set up their own limits.
717
 *
718
 * Drivers should call this (or their equivalent setup code) from their
719
 * ->fb_probe callback.
720
 */
1221 serge 721
void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
722
			    uint32_t depth)
1179 serge 723
{
724
	info->fix.type = FB_TYPE_PACKED_PIXELS;
1221 serge 725
	info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
1246 serge 726
		FB_VISUAL_TRUECOLOR;
1963 serge 727
	info->fix.mmio_start = 0;
728
	info->fix.mmio_len = 0;
1179 serge 729
	info->fix.type_aux = 0;
730
	info->fix.xpanstep = 1; /* doing it in hw */
731
	info->fix.ypanstep = 1; /* doing it in hw */
732
	info->fix.ywrapstep = 0;
733
	info->fix.accel = FB_ACCEL_NONE;
734
	info->fix.type_aux = 0;
735
 
736
	info->fix.line_length = pitch;
737
	return;
738
}
739
EXPORT_SYMBOL(drm_fb_helper_fill_fix);
740
 
3480 Serge 741
/**
742
 * drm_fb_helper_fill_var - initalizes variable fbdev information
743
 * @info: fbdev instance to set up
744
 * @fb_helper: fb helper instance to use as template
745
 * @fb_width: desired fb width
746
 * @fb_height: desired fb height
747
 *
748
 * Sets up the variable fbdev metainformation from the given fb helper instance
749
 * and the drm framebuffer allocated in fb_helper->fb.
750
 *
751
 * Drivers should call this (or their equivalent setup code) from their
752
 * ->fb_probe callback after having allocated the fbdev backing
753
 * storage framebuffer.
754
 */
1963 serge 755
void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
1179 serge 756
			    uint32_t fb_width, uint32_t fb_height)
757
{
1963 serge 758
	struct drm_framebuffer *fb = fb_helper->fb;
759
	info->pseudo_palette = fb_helper->pseudo_palette;
1179 serge 760
	info->var.xres_virtual = fb->width;
761
	info->var.yres_virtual = fb->height;
762
	info->var.bits_per_pixel = fb->bits_per_pixel;
1963 serge 763
	info->var.accel_flags = FB_ACCELF_TEXT;
1179 serge 764
	info->var.xoffset = 0;
765
	info->var.yoffset = 0;
766
	info->var.activate = FB_ACTIVATE_NOW;
767
	info->var.height = -1;
768
	info->var.width = -1;
769
 
770
	switch (fb->depth) {
771
	case 8:
772
		info->var.red.offset = 0;
773
		info->var.green.offset = 0;
774
		info->var.blue.offset = 0;
775
		info->var.red.length = 8; /* 8bit DAC */
776
		info->var.green.length = 8;
777
		info->var.blue.length = 8;
778
		info->var.transp.offset = 0;
779
		info->var.transp.length = 0;
780
		break;
781
	case 15:
782
		info->var.red.offset = 10;
783
		info->var.green.offset = 5;
784
		info->var.blue.offset = 0;
785
		info->var.red.length = 5;
786
		info->var.green.length = 5;
787
		info->var.blue.length = 5;
788
		info->var.transp.offset = 15;
789
		info->var.transp.length = 1;
790
		break;
791
	case 16:
792
		info->var.red.offset = 11;
793
		info->var.green.offset = 5;
794
		info->var.blue.offset = 0;
795
		info->var.red.length = 5;
796
		info->var.green.length = 6;
797
		info->var.blue.length = 5;
798
		info->var.transp.offset = 0;
799
		break;
800
	case 24:
801
		info->var.red.offset = 16;
802
		info->var.green.offset = 8;
803
		info->var.blue.offset = 0;
804
		info->var.red.length = 8;
805
		info->var.green.length = 8;
806
		info->var.blue.length = 8;
807
		info->var.transp.offset = 0;
808
		info->var.transp.length = 0;
809
		break;
810
	case 32:
811
		info->var.red.offset = 16;
812
		info->var.green.offset = 8;
813
		info->var.blue.offset = 0;
814
		info->var.red.length = 8;
815
		info->var.green.length = 8;
816
		info->var.blue.length = 8;
817
		info->var.transp.offset = 24;
818
		info->var.transp.length = 8;
819
		break;
820
	default:
821
		break;
822
	}
823
 
824
	info->var.xres = fb_width;
825
	info->var.yres = fb_height;
826
}
827
EXPORT_SYMBOL(drm_fb_helper_fill_var);
1963 serge 828
 
829
static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
830
					       uint32_t maxX,
831
					       uint32_t maxY)
832
{
833
	struct drm_connector *connector;
834
	int count = 0;
835
	int i;
836
 
837
	for (i = 0; i < fb_helper->connector_count; i++) {
838
		connector = fb_helper->connector_info[i]->connector;
839
		count += connector->funcs->fill_modes(connector, maxX, maxY);
840
	}
841
 
842
	return count;
843
}
844
 
845
static struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
846
{
847
	struct drm_display_mode *mode;
848
 
849
	list_for_each_entry(mode, &fb_connector->connector->modes, head) {
850
		if (drm_mode_width(mode) > width ||
851
		    drm_mode_height(mode) > height)
852
			continue;
853
		if (mode->type & DRM_MODE_TYPE_PREFERRED)
854
			return mode;
855
	}
856
	return NULL;
857
}
858
 
859
static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
860
{
861
	struct drm_cmdline_mode *cmdline_mode;
862
	cmdline_mode = &fb_connector->cmdline_mode;
863
	return cmdline_mode->specified;
864
}
865
 
866
 
867
static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
868
{
869
	bool enable;
870
 
3192 Serge 871
	if (strict)
1963 serge 872
		enable = connector->status == connector_status_connected;
3192 Serge 873
	else
1963 serge 874
		enable = connector->status != connector_status_disconnected;
3192 Serge 875
 
1963 serge 876
	return enable;
877
}
878
 
879
static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
880
				  bool *enabled)
881
{
882
	bool any_enabled = false;
883
	struct drm_connector *connector;
884
	int i = 0;
885
 
886
	for (i = 0; i < fb_helper->connector_count; i++) {
887
		connector = fb_helper->connector_info[i]->connector;
888
		enabled[i] = drm_connector_enabled(connector, true);
889
		DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
890
			  enabled[i] ? "yes" : "no");
891
		any_enabled |= enabled[i];
892
	}
893
 
894
	if (any_enabled)
895
		return;
896
 
897
	for (i = 0; i < fb_helper->connector_count; i++) {
898
		connector = fb_helper->connector_info[i]->connector;
899
		enabled[i] = drm_connector_enabled(connector, false);
900
	}
901
}
902
 
903
 
904
static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
905
				 struct drm_display_mode **modes,
906
				 bool *enabled, int width, int height)
907
{
908
	struct drm_fb_helper_connector *fb_helper_conn;
909
	int i;
910
 
911
	for (i = 0; i < fb_helper->connector_count; i++) {
912
		fb_helper_conn = fb_helper->connector_info[i];
913
 
914
		if (enabled[i] == false)
915
			continue;
916
 
917
		DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
918
			      fb_helper_conn->connector->base.id);
919
 
920
		/* got for command line mode first */
921
//       modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
922
 
923
        modes[i] = NULL;
924
 
925
		if (!modes[i]) {
926
			DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
927
				      fb_helper_conn->connector->base.id);
928
			modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
929
		}
930
		/* No preferred modes, pick one off the list */
931
		if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
932
			list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
933
				break;
934
		}
935
		DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
936
			  "none");
937
	}
938
	return true;
939
}
940
 
941
static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
942
			  struct drm_fb_helper_crtc **best_crtcs,
943
			  struct drm_display_mode **modes,
944
			  int n, int width, int height)
945
{
946
	int c, o;
947
	struct drm_device *dev = fb_helper->dev;
948
	struct drm_connector *connector;
949
	struct drm_connector_helper_funcs *connector_funcs;
950
	struct drm_encoder *encoder;
951
	struct drm_fb_helper_crtc *best_crtc;
952
	int my_score, best_score, score;
953
	struct drm_fb_helper_crtc **crtcs, *crtc;
954
	struct drm_fb_helper_connector *fb_helper_conn;
955
 
956
	if (n == fb_helper->connector_count)
957
		return 0;
958
 
959
	fb_helper_conn = fb_helper->connector_info[n];
960
	connector = fb_helper_conn->connector;
961
 
962
	best_crtcs[n] = NULL;
963
	best_crtc = NULL;
964
	best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
965
	if (modes[n] == NULL)
966
		return best_score;
967
 
968
	crtcs = kzalloc(dev->mode_config.num_connector *
969
			sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
970
	if (!crtcs)
971
		return best_score;
972
 
973
	my_score = 1;
974
	if (connector->status == connector_status_connected)
975
		my_score++;
976
	if (drm_has_cmdline_mode(fb_helper_conn))
977
		my_score++;
978
	if (drm_has_preferred_mode(fb_helper_conn, width, height))
979
		my_score++;
980
 
981
	connector_funcs = connector->helper_private;
982
	encoder = connector_funcs->best_encoder(connector);
983
	if (!encoder)
984
		goto out;
985
 
986
	/* select a crtc for this connector and then attempt to configure
987
	   remaining connectors */
988
	for (c = 0; c < fb_helper->crtc_count; c++) {
989
		crtc = &fb_helper->crtc_info[c];
990
 
3192 Serge 991
		if ((encoder->possible_crtcs & (1 << c)) == 0)
1963 serge 992
			continue;
993
 
994
		for (o = 0; o < n; o++)
995
			if (best_crtcs[o] == crtc)
996
				break;
997
 
998
		if (o < n) {
999
			/* ignore cloning unless only a single crtc */
1000
			if (fb_helper->crtc_count > 1)
1001
				continue;
1002
 
1003
			if (!drm_mode_equal(modes[o], modes[n]))
1004
				continue;
1005
		}
1006
 
1007
		crtcs[n] = crtc;
1008
		memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1009
		score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
1010
						  width, height);
1011
		if (score > best_score) {
1012
			best_crtc = crtc;
1013
			best_score = score;
1014
			memcpy(best_crtcs, crtcs,
1015
			       dev->mode_config.num_connector *
1016
			       sizeof(struct drm_fb_helper_crtc *));
1017
		}
1018
	}
1019
out:
1020
	kfree(crtcs);
1021
	return best_score;
1022
}
1023
 
1024
static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
1025
{
1026
	struct drm_device *dev = fb_helper->dev;
1027
	struct drm_fb_helper_crtc **crtcs;
1028
	struct drm_display_mode **modes;
1029
	struct drm_mode_set *modeset;
1030
	bool *enabled;
1031
	int width, height;
1032
	int i, ret;
1033
 
1034
	DRM_DEBUG_KMS("\n");
1035
 
1036
	width = dev->mode_config.max_width;
1037
	height = dev->mode_config.max_height;
1038
 
1039
	crtcs = kcalloc(dev->mode_config.num_connector,
1040
			sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1041
	modes = kcalloc(dev->mode_config.num_connector,
1042
			sizeof(struct drm_display_mode *), GFP_KERNEL);
1043
	enabled = kcalloc(dev->mode_config.num_connector,
1044
			  sizeof(bool), GFP_KERNEL);
3192 Serge 1045
	if (!crtcs || !modes || !enabled) {
1046
		DRM_ERROR("Memory allocation failed\n");
1047
		goto out;
1048
	}
1963 serge 1049
 
3192 Serge 1050
 
1963 serge 1051
	drm_enable_connectors(fb_helper, enabled);
1052
 
1053
    //ret = drm_target_cloned(fb_helper, modes, enabled, width, height);
1054
 
1055
    ret = 0;
1056
 
1057
	if (!ret) {
1058
		ret = drm_target_preferred(fb_helper, modes, enabled, width, height);
1059
		if (!ret)
1060
			DRM_ERROR("Unable to find initial modes\n");
1061
	}
1062
 
1063
	DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height);
1064
 
1065
	drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1066
 
1067
	/* need to set the modesets up here for use later */
1068
	/* fill out the connector<->crtc mappings into the modesets */
1069
	for (i = 0; i < fb_helper->crtc_count; i++) {
1070
		modeset = &fb_helper->crtc_info[i].mode_set;
1071
		modeset->num_connectors = 0;
3480 Serge 1072
		modeset->fb = NULL;
1963 serge 1073
	}
1074
 
1075
	for (i = 0; i < fb_helper->connector_count; i++) {
1076
		struct drm_display_mode *mode = modes[i];
1077
		struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1078
		modeset = &fb_crtc->mode_set;
1079
 
1080
		if (mode && fb_crtc) {
1081
			DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
1082
				      mode->name, fb_crtc->mode_set.crtc->base.id);
1083
			fb_crtc->desired_mode = mode;
1084
			if (modeset->mode)
1085
				drm_mode_destroy(dev, modeset->mode);
1086
			modeset->mode = drm_mode_duplicate(dev,
1087
							   fb_crtc->desired_mode);
1088
			modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
3480 Serge 1089
			modeset->fb = fb_helper->fb;
1963 serge 1090
		}
1091
	}
1092
 
3480 Serge 1093
	/* Clear out any old modes if there are no more connected outputs. */
1094
	for (i = 0; i < fb_helper->crtc_count; i++) {
1095
		modeset = &fb_helper->crtc_info[i].mode_set;
1096
		if (modeset->num_connectors == 0) {
1097
			BUG_ON(modeset->fb);
1098
			BUG_ON(modeset->num_connectors);
1099
			if (modeset->mode)
1100
				drm_mode_destroy(dev, modeset->mode);
1101
			modeset->mode = NULL;
1102
		}
1103
	}
3192 Serge 1104
out:
1963 serge 1105
	kfree(crtcs);
1106
	kfree(modes);
1107
	kfree(enabled);
1108
}
1109
 
1110
/**
3480 Serge 1111
 * drm_fb_helper_initial_config - setup a sane initial connector configuration
3192 Serge 1112
 * @fb_helper: fb_helper device struct
1113
 * @bpp_sel: bpp value to use for the framebuffer configuration
1963 serge 1114
 *
3192 Serge 1115
 * Scans the CRTCs and connectors and tries to put together an initial setup.
1963 serge 1116
 * At the moment, this is a cloned configuration across all heads with
1117
 * a new framebuffer object as the backing store.
1118
 *
3480 Serge 1119
 * Note that this also registers the fbdev and so allows userspace to call into
1120
 * the driver through the fbdev interfaces.
1121
 *
1122
 * This function will call down into the ->fb_probe callback to let
1123
 * the driver allocate and initialize the fbdev info structure and the drm
1124
 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
1125
 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
1126
 * values for the fbdev info structure.
1127
 *
1963 serge 1128
 * RETURNS:
1129
 * Zero if everything went ok, nonzero otherwise.
1130
 */
1131
bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
1132
{
1133
	struct drm_device *dev = fb_helper->dev;
1134
	int count = 0;
1135
 
1136
//   drm_fb_helper_parse_command_line(fb_helper);
1137
 
1138
	count = drm_fb_helper_probe_connector_modes(fb_helper,
1139
						    dev->mode_config.max_width,
1140
						    dev->mode_config.max_height);
1141
	/*
1142
	 * we shouldn't end up with no modes here.
1143
	 */
3192 Serge 1144
	if (count == 0)
1145
		dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
1146
 
1147
	drm_setup_crtcs(fb_helper);
1148
 
3243 Serge 1149
	return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
3192 Serge 1150
}
1151
EXPORT_SYMBOL(drm_fb_helper_initial_config);
1152
 
1153
/**
1154
 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
1155
 *                               probing all the outputs attached to the fb
1156
 * @fb_helper: the drm_fb_helper
1157
 *
1158
 * Scan the connectors attached to the fb_helper and try to put together a
1159
 * setup after *notification of a change in output configuration.
1160
 *
3480 Serge 1161
 * Called at runtime, takes the mode config locks to be able to check/change the
1162
 * modeset configuration. Must be run from process context (which usually means
1163
 * either the output polling work or a work item launched from the driver's
1164
 * hotplug interrupt).
1165
 *
1166
 * Note that the driver must ensure that this is only called _after_ the fb has
1167
 * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
1168
 *
3192 Serge 1169
 * RETURNS:
1170
 * 0 on success and a non-zero error code otherwise.
1171
 */
1172
int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
1173
{
1174
	struct drm_device *dev = fb_helper->dev;
1175
	int count = 0;
1176
	u32 max_width, max_height, bpp_sel;
1177
 
1178
	if (!fb_helper->fb)
1179
		return 0;
1180
 
3480 Serge 1181
	mutex_lock(&fb_helper->dev->mode_config.mutex);
1182
	if (!drm_fb_helper_is_bound(fb_helper)) {
3192 Serge 1183
		fb_helper->delayed_hotplug = true;
3480 Serge 1184
		mutex_unlock(&fb_helper->dev->mode_config.mutex);
3192 Serge 1185
		return 0;
1186
	}
1187
	DRM_DEBUG_KMS("\n");
1188
 
1189
	max_width = fb_helper->fb->width;
1190
	max_height = fb_helper->fb->height;
1191
	bpp_sel = fb_helper->fb->bits_per_pixel;
1192
 
1193
	count = drm_fb_helper_probe_connector_modes(fb_helper, max_width,
1194
						    max_height);
3480 Serge 1195
	mutex_unlock(&fb_helper->dev->mode_config.mutex);
1196
 
1197
	drm_modeset_lock_all(dev);
1963 serge 1198
	drm_setup_crtcs(fb_helper);
3480 Serge 1199
	drm_modeset_unlock_all(dev);
1200
	drm_fb_helper_set_par(fb_helper->fbdev);
1963 serge 1201
 
3480 Serge 1202
	return 0;
1963 serge 1203
}
3192 Serge 1204
EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
1205