Subversion Repositories Kolibri OS

Rev

Rev 5060 | Rev 6084 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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