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