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