Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006-2009 Red Hat Inc. |
| 3 | * Copyright (c) 2006-2008 Intel Corporation |
| 4 | * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> |
| 5 | * |
| 6 | * DRM framebuffer helper functions |
| 7 | * |
| 8 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 9 | * documentation for any purpose is hereby granted without fee, provided that |
| 10 | * the above copyright notice appear in all copies and that both that copyright |
| 11 | * notice and this permission notice appear in supporting documentation, and |
| 12 | * that the name of the copyright holders not be used in advertising or |
| 13 | * publicity pertaining to distribution of the software without specific, |
| 14 | * written prior permission. The copyright holders make no representations |
| 15 | * about the suitability of this software for any purpose. It is provided "as |
| 16 | * is" without express or implied warranty. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 19 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 20 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 21 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 22 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 23 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 24 | * OF THIS SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Dave Airlie <airlied@linux.ie> |
| 28 | * Jesse Barnes <jesse.barnes@intel.com> |
| 29 | */ |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 30 | #include <linux/kernel.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 31 | #include <linux/sysrq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 33 | #include <linux/fb.h> |
| 34 | #include "drmP.h" |
| 35 | #include "drm_crtc.h" |
| 36 | #include "drm_fb_helper.h" |
| 37 | #include "drm_crtc_helper.h" |
| 38 | |
Dave Airlie | 6fcefd5 | 2009-09-08 11:08:32 +1000 | [diff] [blame] | 39 | MODULE_AUTHOR("David Airlie, Jesse Barnes"); |
| 40 | MODULE_DESCRIPTION("DRM KMS helper"); |
| 41 | MODULE_LICENSE("GPL and additional rights"); |
| 42 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 43 | static LIST_HEAD(kernel_fb_helper_list); |
| 44 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 45 | /* simple single crtc case helper function */ |
| 46 | int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper) |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 47 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 48 | struct drm_device *dev = fb_helper->dev; |
| 49 | struct drm_connector *connector; |
| 50 | int i; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 51 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 52 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 53 | struct drm_fb_helper_connector *fb_helper_connector; |
| 54 | |
| 55 | fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL); |
| 56 | if (!fb_helper_connector) |
| 57 | goto fail; |
| 58 | |
| 59 | fb_helper_connector->connector = connector; |
| 60 | fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector; |
| 61 | } |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 62 | return 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 63 | fail: |
| 64 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 65 | kfree(fb_helper->connector_info[i]); |
| 66 | fb_helper->connector_info[i] = NULL; |
| 67 | } |
| 68 | fb_helper->connector_count = 0; |
| 69 | return -ENOMEM; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 70 | } |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 71 | EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 72 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 73 | /** |
| 74 | * drm_fb_helper_connector_parse_command_line - parse command line for connector |
| 75 | * @connector - connector to parse line for |
| 76 | * @mode_option - per connector mode option |
| 77 | * |
| 78 | * This parses the connector specific then generic command lines for |
| 79 | * modes and options to configure the connector. |
| 80 | * |
| 81 | * This uses the same parameters as the fb modedb.c, except for extra |
| 82 | * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd] |
| 83 | * |
| 84 | * enable/enable Digital/disable bit at the end |
| 85 | */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 86 | static bool drm_fb_helper_connector_parse_command_line(struct drm_fb_helper_connector *fb_helper_conn, |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 87 | const char *mode_option) |
| 88 | { |
| 89 | const char *name; |
| 90 | unsigned int namelen; |
| 91 | int res_specified = 0, bpp_specified = 0, refresh_specified = 0; |
| 92 | unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0; |
| 93 | int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0; |
| 94 | int i; |
| 95 | enum drm_connector_force force = DRM_FORCE_UNSPECIFIED; |
Dave Airlie | 8ef8678 | 2009-09-26 06:39:00 +1000 | [diff] [blame] | 96 | struct drm_fb_helper_cmdline_mode *cmdline_mode; |
Dan Carpenter | 09f0c48 | 2010-08-19 11:46:29 +0200 | [diff] [blame] | 97 | struct drm_connector *connector; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 98 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 99 | if (!fb_helper_conn) |
Dave Airlie | 8ef8678 | 2009-09-26 06:39:00 +1000 | [diff] [blame] | 100 | return false; |
Dan Carpenter | 09f0c48 | 2010-08-19 11:46:29 +0200 | [diff] [blame] | 101 | connector = fb_helper_conn->connector; |
Dave Airlie | 8ef8678 | 2009-09-26 06:39:00 +1000 | [diff] [blame] | 102 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 103 | cmdline_mode = &fb_helper_conn->cmdline_mode; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 104 | if (!mode_option) |
| 105 | mode_option = fb_mode_option; |
| 106 | |
| 107 | if (!mode_option) { |
| 108 | cmdline_mode->specified = false; |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | name = mode_option; |
| 113 | namelen = strlen(name); |
| 114 | for (i = namelen-1; i >= 0; i--) { |
| 115 | switch (name[i]) { |
| 116 | case '@': |
| 117 | namelen = i; |
| 118 | if (!refresh_specified && !bpp_specified && |
| 119 | !yres_specified) { |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 120 | refresh = simple_strtol(&name[i+1], NULL, 10); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 121 | refresh_specified = 1; |
| 122 | if (cvt || rb) |
| 123 | cvt = 0; |
| 124 | } else |
| 125 | goto done; |
| 126 | break; |
| 127 | case '-': |
| 128 | namelen = i; |
| 129 | if (!bpp_specified && !yres_specified) { |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 130 | bpp = simple_strtol(&name[i+1], NULL, 10); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 131 | bpp_specified = 1; |
| 132 | if (cvt || rb) |
| 133 | cvt = 0; |
| 134 | } else |
| 135 | goto done; |
| 136 | break; |
| 137 | case 'x': |
| 138 | if (!yres_specified) { |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 139 | yres = simple_strtol(&name[i+1], NULL, 10); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 140 | yres_specified = 1; |
| 141 | } else |
| 142 | goto done; |
| 143 | case '0' ... '9': |
| 144 | break; |
| 145 | case 'M': |
| 146 | if (!yres_specified) |
| 147 | cvt = 1; |
| 148 | break; |
| 149 | case 'R': |
Adam Jackson | b829e01 | 2010-06-10 13:33:26 -0400 | [diff] [blame] | 150 | if (cvt) |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 151 | rb = 1; |
| 152 | break; |
| 153 | case 'm': |
| 154 | if (!cvt) |
| 155 | margins = 1; |
| 156 | break; |
| 157 | case 'i': |
| 158 | if (!cvt) |
| 159 | interlace = 1; |
| 160 | break; |
| 161 | case 'e': |
| 162 | force = DRM_FORCE_ON; |
| 163 | break; |
| 164 | case 'D': |
Roel Kluin | e89a8c9 | 2009-12-31 13:06:29 +0100 | [diff] [blame] | 165 | if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) && |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 166 | (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)) |
| 167 | force = DRM_FORCE_ON; |
| 168 | else |
| 169 | force = DRM_FORCE_ON_DIGITAL; |
| 170 | break; |
| 171 | case 'd': |
| 172 | force = DRM_FORCE_OFF; |
| 173 | break; |
| 174 | default: |
| 175 | goto done; |
| 176 | } |
| 177 | } |
| 178 | if (i < 0 && yres_specified) { |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 179 | xres = simple_strtol(name, NULL, 10); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 180 | res_specified = 1; |
| 181 | } |
| 182 | done: |
| 183 | |
| 184 | DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", |
| 185 | drm_get_connector_name(connector), xres, yres, |
| 186 | (refresh) ? refresh : 60, (rb) ? " reduced blanking" : |
| 187 | "", (margins) ? " with margins" : "", (interlace) ? |
| 188 | " interlaced" : ""); |
| 189 | |
| 190 | if (force) { |
| 191 | const char *s; |
| 192 | switch (force) { |
| 193 | case DRM_FORCE_OFF: s = "OFF"; break; |
| 194 | case DRM_FORCE_ON_DIGITAL: s = "ON - dig"; break; |
| 195 | default: |
| 196 | case DRM_FORCE_ON: s = "ON"; break; |
| 197 | } |
| 198 | |
| 199 | DRM_INFO("forcing %s connector %s\n", |
| 200 | drm_get_connector_name(connector), s); |
| 201 | connector->force = force; |
| 202 | } |
| 203 | |
| 204 | if (res_specified) { |
| 205 | cmdline_mode->specified = true; |
| 206 | cmdline_mode->xres = xres; |
| 207 | cmdline_mode->yres = yres; |
| 208 | } |
| 209 | |
| 210 | if (refresh_specified) { |
| 211 | cmdline_mode->refresh_specified = true; |
| 212 | cmdline_mode->refresh = refresh; |
| 213 | } |
| 214 | |
| 215 | if (bpp_specified) { |
| 216 | cmdline_mode->bpp_specified = true; |
| 217 | cmdline_mode->bpp = bpp; |
| 218 | } |
| 219 | cmdline_mode->rb = rb ? true : false; |
| 220 | cmdline_mode->cvt = cvt ? true : false; |
| 221 | cmdline_mode->interlace = interlace ? true : false; |
| 222 | |
| 223 | return true; |
| 224 | } |
| 225 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 226 | static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper) |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 227 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 228 | struct drm_fb_helper_connector *fb_helper_conn; |
| 229 | int i; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 230 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 231 | for (i = 0; i < fb_helper->connector_count; i++) { |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 232 | char *option = NULL; |
| 233 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 234 | fb_helper_conn = fb_helper->connector_info[i]; |
| 235 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 236 | /* do something on return - turn off connector maybe */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 237 | if (fb_get_options(drm_get_connector_name(fb_helper_conn->connector), &option)) |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 238 | continue; |
| 239 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 240 | drm_fb_helper_connector_parse_command_line(fb_helper_conn, option); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 241 | } |
| 242 | return 0; |
| 243 | } |
| 244 | |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 245 | int drm_fb_helper_debug_enter(struct fb_info *info) |
| 246 | { |
| 247 | struct drm_fb_helper *helper = info->par; |
| 248 | struct drm_crtc_helper_funcs *funcs; |
| 249 | int i; |
| 250 | |
| 251 | if (list_empty(&kernel_fb_helper_list)) |
| 252 | return false; |
| 253 | |
| 254 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
| 255 | for (i = 0; i < helper->crtc_count; i++) { |
| 256 | struct drm_mode_set *mode_set = |
| 257 | &helper->crtc_info[i].mode_set; |
| 258 | |
| 259 | if (!mode_set->crtc->enabled) |
| 260 | continue; |
| 261 | |
| 262 | funcs = mode_set->crtc->helper_private; |
| 263 | funcs->mode_set_base_atomic(mode_set->crtc, |
| 264 | mode_set->fb, |
| 265 | mode_set->x, |
Jason Wessel | 413d45d | 2010-09-26 06:47:25 -0500 | [diff] [blame^] | 266 | mode_set->y, |
| 267 | 1); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 268 | |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | EXPORT_SYMBOL(drm_fb_helper_debug_enter); |
| 275 | |
| 276 | /* Find the real fb for a given fb helper CRTC */ |
| 277 | static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc) |
| 278 | { |
| 279 | struct drm_device *dev = crtc->dev; |
| 280 | struct drm_crtc *c; |
| 281 | |
| 282 | list_for_each_entry(c, &dev->mode_config.crtc_list, head) { |
| 283 | if (crtc->base.id == c->base.id) |
| 284 | return c->fb; |
| 285 | } |
| 286 | |
| 287 | return NULL; |
| 288 | } |
| 289 | |
| 290 | int drm_fb_helper_debug_leave(struct fb_info *info) |
| 291 | { |
| 292 | struct drm_fb_helper *helper = info->par; |
| 293 | struct drm_crtc *crtc; |
| 294 | struct drm_crtc_helper_funcs *funcs; |
| 295 | struct drm_framebuffer *fb; |
| 296 | int i; |
| 297 | |
| 298 | for (i = 0; i < helper->crtc_count; i++) { |
| 299 | struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set; |
| 300 | crtc = mode_set->crtc; |
| 301 | funcs = crtc->helper_private; |
| 302 | fb = drm_mode_config_fb(crtc); |
| 303 | |
| 304 | if (!crtc->enabled) |
| 305 | continue; |
| 306 | |
| 307 | if (!fb) { |
| 308 | DRM_ERROR("no fb to restore??\n"); |
| 309 | continue; |
| 310 | } |
| 311 | |
| 312 | funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x, |
Jason Wessel | 413d45d | 2010-09-26 06:47:25 -0500 | [diff] [blame^] | 313 | crtc->y, 0); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | EXPORT_SYMBOL(drm_fb_helper_debug_leave); |
| 319 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 320 | bool drm_fb_helper_force_kernel_mode(void) |
| 321 | { |
| 322 | int i = 0; |
| 323 | bool ret, error = false; |
| 324 | struct drm_fb_helper *helper; |
| 325 | |
| 326 | if (list_empty(&kernel_fb_helper_list)) |
| 327 | return false; |
| 328 | |
| 329 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
| 330 | for (i = 0; i < helper->crtc_count; i++) { |
| 331 | struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set; |
| 332 | ret = drm_crtc_helper_set_config(mode_set); |
| 333 | if (ret) |
| 334 | error = true; |
| 335 | } |
| 336 | } |
| 337 | return error; |
| 338 | } |
| 339 | |
| 340 | int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed, |
| 341 | void *panic_str) |
| 342 | { |
Dave Airlie | fc2362a | 2010-06-07 12:14:54 +1000 | [diff] [blame] | 343 | printk(KERN_ERR "panic occurred, switching back to text console\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 344 | return drm_fb_helper_force_kernel_mode(); |
| 345 | return 0; |
| 346 | } |
| 347 | EXPORT_SYMBOL(drm_fb_helper_panic); |
| 348 | |
| 349 | static struct notifier_block paniced = { |
| 350 | .notifier_call = drm_fb_helper_panic, |
| 351 | }; |
| 352 | |
| 353 | /** |
| 354 | * drm_fb_helper_restore - restore the framebuffer console (kernel) config |
| 355 | * |
| 356 | * Restore's the kernel's fbcon mode, used for lastclose & panic paths. |
| 357 | */ |
| 358 | void drm_fb_helper_restore(void) |
| 359 | { |
| 360 | bool ret; |
| 361 | ret = drm_fb_helper_force_kernel_mode(); |
| 362 | if (ret == true) |
| 363 | DRM_ERROR("Failed to restore crtc configuration\n"); |
| 364 | } |
| 365 | EXPORT_SYMBOL(drm_fb_helper_restore); |
| 366 | |
Mikael Pettersson | bea1d35 | 2009-09-28 18:26:25 +0200 | [diff] [blame] | 367 | #ifdef CONFIG_MAGIC_SYSRQ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 368 | static void drm_fb_helper_restore_work_fn(struct work_struct *ignored) |
| 369 | { |
| 370 | drm_fb_helper_restore(); |
| 371 | } |
| 372 | static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn); |
| 373 | |
Dmitry Torokhov | 1495cc9 | 2010-08-17 21:15:46 -0700 | [diff] [blame] | 374 | static void drm_fb_helper_sysrq(int dummy1) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 375 | { |
| 376 | schedule_work(&drm_fb_helper_restore_work); |
| 377 | } |
| 378 | |
| 379 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { |
| 380 | .handler = drm_fb_helper_sysrq, |
| 381 | .help_msg = "force-fb(V)", |
| 382 | .action_msg = "Restore framebuffer console", |
| 383 | }; |
Randy Dunlap | b8c40d6 | 2010-03-25 18:29:05 +0000 | [diff] [blame] | 384 | #else |
| 385 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { }; |
Mikael Pettersson | bea1d35 | 2009-09-28 18:26:25 +0200 | [diff] [blame] | 386 | #endif |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 387 | |
| 388 | static void drm_fb_helper_on(struct fb_info *info) |
| 389 | { |
| 390 | struct drm_fb_helper *fb_helper = info->par; |
| 391 | struct drm_device *dev = fb_helper->dev; |
| 392 | struct drm_crtc *crtc; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 393 | struct drm_crtc_helper_funcs *crtc_funcs; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 394 | struct drm_connector *connector; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 395 | struct drm_encoder *encoder; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 396 | int i, j; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * For each CRTC in this fb, turn the crtc on then, |
| 400 | * find all associated encoders and turn them on. |
| 401 | */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 402 | mutex_lock(&dev->mode_config.mutex); |
Jesse Barnes | e87b2c4 | 2009-09-17 18:14:41 -0700 | [diff] [blame] | 403 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 404 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
| 405 | crtc_funcs = crtc->helper_private; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 406 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 407 | if (!crtc->enabled) |
| 408 | continue; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 409 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 410 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 411 | |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 412 | /* Walk the connectors & encoders on this fb turning them on */ |
| 413 | for (j = 0; j < fb_helper->connector_count; j++) { |
| 414 | connector = fb_helper->connector_info[j]->connector; |
| 415 | connector->dpms = DRM_MODE_DPMS_ON; |
| 416 | drm_connector_property_set_value(connector, |
| 417 | dev->mode_config.dpms_property, |
| 418 | DRM_MODE_DPMS_ON); |
| 419 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 420 | /* Found a CRTC on this fb, now find encoders */ |
| 421 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 422 | if (encoder->crtc == crtc) { |
| 423 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 424 | |
| 425 | encoder_funcs = encoder->helper_private; |
| 426 | encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 430 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static void drm_fb_helper_off(struct fb_info *info, int dpms_mode) |
| 434 | { |
| 435 | struct drm_fb_helper *fb_helper = info->par; |
| 436 | struct drm_device *dev = fb_helper->dev; |
| 437 | struct drm_crtc *crtc; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 438 | struct drm_crtc_helper_funcs *crtc_funcs; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 439 | struct drm_connector *connector; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 440 | struct drm_encoder *encoder; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 441 | int i, j; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 442 | |
| 443 | /* |
| 444 | * For each CRTC in this fb, find all associated encoders |
| 445 | * and turn them off, then turn off the CRTC. |
| 446 | */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 447 | mutex_lock(&dev->mode_config.mutex); |
Jesse Barnes | e87b2c4 | 2009-09-17 18:14:41 -0700 | [diff] [blame] | 448 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 449 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
| 450 | crtc_funcs = crtc->helper_private; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 451 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 452 | if (!crtc->enabled) |
| 453 | continue; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 454 | |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 455 | /* Walk the connectors on this fb and mark them off */ |
| 456 | for (j = 0; j < fb_helper->connector_count; j++) { |
| 457 | connector = fb_helper->connector_info[j]->connector; |
| 458 | connector->dpms = dpms_mode; |
| 459 | drm_connector_property_set_value(connector, |
| 460 | dev->mode_config.dpms_property, |
| 461 | dpms_mode); |
| 462 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 463 | /* Found a CRTC on this fb, now find encoders */ |
| 464 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 465 | if (encoder->crtc == crtc) { |
| 466 | struct drm_encoder_helper_funcs *encoder_funcs; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 467 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 468 | encoder_funcs = encoder->helper_private; |
| 469 | encoder_funcs->dpms(encoder, dpms_mode); |
Jesse Barnes | e87b2c4 | 2009-09-17 18:14:41 -0700 | [diff] [blame] | 470 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 471 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 472 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 473 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 474 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | int drm_fb_helper_blank(int blank, struct fb_info *info) |
| 478 | { |
| 479 | switch (blank) { |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 480 | /* Display: On; HSync: On, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 481 | case FB_BLANK_UNBLANK: |
| 482 | drm_fb_helper_on(info); |
| 483 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 484 | /* Display: Off; HSync: On, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 485 | case FB_BLANK_NORMAL: |
Zhenyu Wang | 5fd4df4 | 2010-01-18 16:47:04 +0800 | [diff] [blame] | 486 | drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 487 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 488 | /* Display: Off; HSync: Off, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 489 | case FB_BLANK_HSYNC_SUSPEND: |
| 490 | drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY); |
| 491 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 492 | /* Display: Off; HSync: On, VSync: Off */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 493 | case FB_BLANK_VSYNC_SUSPEND: |
| 494 | drm_fb_helper_off(info, DRM_MODE_DPMS_SUSPEND); |
| 495 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 496 | /* Display: Off; HSync: Off, VSync: Off */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 497 | case FB_BLANK_POWERDOWN: |
| 498 | drm_fb_helper_off(info, DRM_MODE_DPMS_OFF); |
| 499 | break; |
| 500 | } |
| 501 | return 0; |
| 502 | } |
| 503 | EXPORT_SYMBOL(drm_fb_helper_blank); |
| 504 | |
| 505 | static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper) |
| 506 | { |
| 507 | int i; |
| 508 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 509 | for (i = 0; i < helper->connector_count; i++) |
| 510 | kfree(helper->connector_info[i]); |
| 511 | kfree(helper->connector_info); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 512 | for (i = 0; i < helper->crtc_count; i++) |
| 513 | kfree(helper->crtc_info[i].mode_set.connectors); |
| 514 | kfree(helper->crtc_info); |
| 515 | } |
| 516 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 517 | int drm_fb_helper_init(struct drm_device *dev, |
| 518 | struct drm_fb_helper *fb_helper, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 519 | int crtc_count, int max_conn_count) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 520 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 521 | struct drm_crtc *crtc; |
| 522 | int ret = 0; |
| 523 | int i; |
| 524 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 525 | fb_helper->dev = dev; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 526 | |
| 527 | INIT_LIST_HEAD(&fb_helper->kernel_fb_list); |
| 528 | |
| 529 | fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL); |
| 530 | if (!fb_helper->crtc_info) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 531 | return -ENOMEM; |
| 532 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 533 | fb_helper->crtc_count = crtc_count; |
| 534 | fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL); |
| 535 | if (!fb_helper->connector_info) { |
| 536 | kfree(fb_helper->crtc_info); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 537 | return -ENOMEM; |
| 538 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 539 | fb_helper->connector_count = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 540 | |
| 541 | for (i = 0; i < crtc_count; i++) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 542 | fb_helper->crtc_info[i].mode_set.connectors = |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 543 | kcalloc(max_conn_count, |
| 544 | sizeof(struct drm_connector *), |
| 545 | GFP_KERNEL); |
| 546 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 547 | if (!fb_helper->crtc_info[i].mode_set.connectors) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 548 | ret = -ENOMEM; |
| 549 | goto out_free; |
| 550 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 551 | fb_helper->crtc_info[i].mode_set.num_connectors = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | i = 0; |
| 555 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 556 | fb_helper->crtc_info[i].crtc_id = crtc->base.id; |
| 557 | fb_helper->crtc_info[i].mode_set.crtc = crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 558 | i++; |
| 559 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 560 | fb_helper->conn_limit = max_conn_count; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 561 | return 0; |
| 562 | out_free: |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 563 | drm_fb_helper_crtc_free(fb_helper); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 564 | return -ENOMEM; |
| 565 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 566 | EXPORT_SYMBOL(drm_fb_helper_init); |
| 567 | |
| 568 | void drm_fb_helper_fini(struct drm_fb_helper *fb_helper) |
| 569 | { |
| 570 | if (!list_empty(&fb_helper->kernel_fb_list)) { |
| 571 | list_del(&fb_helper->kernel_fb_list); |
| 572 | if (list_empty(&kernel_fb_helper_list)) { |
Kirill Smelkov | 3da1f33 | 2010-05-14 19:45:16 +0400 | [diff] [blame] | 573 | printk(KERN_INFO "drm: unregistered panic notifier\n"); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 574 | atomic_notifier_chain_unregister(&panic_notifier_list, |
| 575 | &paniced); |
| 576 | unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | drm_fb_helper_crtc_free(fb_helper); |
| 581 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 582 | } |
| 583 | EXPORT_SYMBOL(drm_fb_helper_fini); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 584 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 585 | static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green, |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 586 | u16 blue, u16 regno, struct fb_info *info) |
| 587 | { |
| 588 | struct drm_fb_helper *fb_helper = info->par; |
| 589 | struct drm_framebuffer *fb = fb_helper->fb; |
| 590 | int pindex; |
| 591 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 592 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 593 | u32 *palette; |
| 594 | u32 value; |
| 595 | /* place color in psuedopalette */ |
| 596 | if (regno > 16) |
| 597 | return -EINVAL; |
| 598 | palette = (u32 *)info->pseudo_palette; |
| 599 | red >>= (16 - info->var.red.length); |
| 600 | green >>= (16 - info->var.green.length); |
| 601 | blue >>= (16 - info->var.blue.length); |
| 602 | value = (red << info->var.red.offset) | |
| 603 | (green << info->var.green.offset) | |
| 604 | (blue << info->var.blue.offset); |
| 605 | palette[regno] = value; |
| 606 | return 0; |
| 607 | } |
| 608 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 609 | pindex = regno; |
| 610 | |
| 611 | if (fb->bits_per_pixel == 16) { |
| 612 | pindex = regno << 3; |
| 613 | |
| 614 | if (fb->depth == 16 && regno > 63) |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 615 | return -EINVAL; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 616 | if (fb->depth == 15 && regno > 31) |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 617 | return -EINVAL; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 618 | |
| 619 | if (fb->depth == 16) { |
| 620 | u16 r, g, b; |
| 621 | int i; |
| 622 | if (regno < 32) { |
| 623 | for (i = 0; i < 8; i++) |
| 624 | fb_helper->funcs->gamma_set(crtc, red, |
| 625 | green, blue, pindex + i); |
| 626 | } |
| 627 | |
| 628 | fb_helper->funcs->gamma_get(crtc, &r, |
| 629 | &g, &b, |
| 630 | pindex >> 1); |
| 631 | |
| 632 | for (i = 0; i < 4; i++) |
| 633 | fb_helper->funcs->gamma_set(crtc, r, |
| 634 | green, b, |
| 635 | (pindex >> 1) + i); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | if (fb->depth != 16) |
| 640 | fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex); |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 641 | return 0; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 642 | } |
| 643 | |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 644 | int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 645 | { |
| 646 | struct drm_fb_helper *fb_helper = info->par; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 647 | struct drm_crtc_helper_funcs *crtc_funcs; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 648 | u16 *red, *green, *blue, *transp; |
| 649 | struct drm_crtc *crtc; |
| 650 | int i, rc = 0; |
| 651 | int start; |
| 652 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 653 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 654 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
| 655 | crtc_funcs = crtc->helper_private; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 656 | |
| 657 | red = cmap->red; |
| 658 | green = cmap->green; |
| 659 | blue = cmap->blue; |
| 660 | transp = cmap->transp; |
| 661 | start = cmap->start; |
| 662 | |
| 663 | for (i = 0; i < cmap->len; i++) { |
| 664 | u16 hred, hgreen, hblue, htransp = 0xffff; |
| 665 | |
| 666 | hred = *red++; |
| 667 | hgreen = *green++; |
| 668 | hblue = *blue++; |
| 669 | |
| 670 | if (transp) |
| 671 | htransp = *transp++; |
| 672 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 673 | rc = setcolreg(crtc, hred, hgreen, hblue, start++, info); |
| 674 | if (rc) |
| 675 | return rc; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 676 | } |
| 677 | crtc_funcs->load_lut(crtc); |
| 678 | } |
| 679 | return rc; |
| 680 | } |
| 681 | EXPORT_SYMBOL(drm_fb_helper_setcmap); |
| 682 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 683 | int drm_fb_helper_check_var(struct fb_var_screeninfo *var, |
| 684 | struct fb_info *info) |
| 685 | { |
| 686 | struct drm_fb_helper *fb_helper = info->par; |
| 687 | struct drm_framebuffer *fb = fb_helper->fb; |
| 688 | int depth; |
| 689 | |
Jason Wessel | f90ebd9 | 2010-08-05 09:22:32 -0500 | [diff] [blame] | 690 | if (var->pixclock != 0 || in_dbg_master()) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 691 | return -EINVAL; |
| 692 | |
| 693 | /* Need to resize the fb object !!! */ |
Dave Airlie | 509c7d8 | 2010-01-08 09:27:08 +1000 | [diff] [blame] | 694 | if (var->bits_per_pixel > fb->bits_per_pixel || var->xres > fb->width || var->yres > fb->height) { |
| 695 | DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb " |
| 696 | "object %dx%d-%d > %dx%d-%d\n", var->xres, var->yres, var->bits_per_pixel, |
| 697 | fb->width, fb->height, fb->bits_per_pixel); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 698 | return -EINVAL; |
| 699 | } |
| 700 | |
| 701 | switch (var->bits_per_pixel) { |
| 702 | case 16: |
| 703 | depth = (var->green.length == 6) ? 16 : 15; |
| 704 | break; |
| 705 | case 32: |
| 706 | depth = (var->transp.length > 0) ? 32 : 24; |
| 707 | break; |
| 708 | default: |
| 709 | depth = var->bits_per_pixel; |
| 710 | break; |
| 711 | } |
| 712 | |
| 713 | switch (depth) { |
| 714 | case 8: |
| 715 | var->red.offset = 0; |
| 716 | var->green.offset = 0; |
| 717 | var->blue.offset = 0; |
| 718 | var->red.length = 8; |
| 719 | var->green.length = 8; |
| 720 | var->blue.length = 8; |
| 721 | var->transp.length = 0; |
| 722 | var->transp.offset = 0; |
| 723 | break; |
| 724 | case 15: |
| 725 | var->red.offset = 10; |
| 726 | var->green.offset = 5; |
| 727 | var->blue.offset = 0; |
| 728 | var->red.length = 5; |
| 729 | var->green.length = 5; |
| 730 | var->blue.length = 5; |
| 731 | var->transp.length = 1; |
| 732 | var->transp.offset = 15; |
| 733 | break; |
| 734 | case 16: |
| 735 | var->red.offset = 11; |
| 736 | var->green.offset = 5; |
| 737 | var->blue.offset = 0; |
| 738 | var->red.length = 5; |
| 739 | var->green.length = 6; |
| 740 | var->blue.length = 5; |
| 741 | var->transp.length = 0; |
| 742 | var->transp.offset = 0; |
| 743 | break; |
| 744 | case 24: |
| 745 | var->red.offset = 16; |
| 746 | var->green.offset = 8; |
| 747 | var->blue.offset = 0; |
| 748 | var->red.length = 8; |
| 749 | var->green.length = 8; |
| 750 | var->blue.length = 8; |
| 751 | var->transp.length = 0; |
| 752 | var->transp.offset = 0; |
| 753 | break; |
| 754 | case 32: |
| 755 | var->red.offset = 16; |
| 756 | var->green.offset = 8; |
| 757 | var->blue.offset = 0; |
| 758 | var->red.length = 8; |
| 759 | var->green.length = 8; |
| 760 | var->blue.length = 8; |
| 761 | var->transp.length = 8; |
| 762 | var->transp.offset = 24; |
| 763 | break; |
| 764 | default: |
| 765 | return -EINVAL; |
| 766 | } |
| 767 | return 0; |
| 768 | } |
| 769 | EXPORT_SYMBOL(drm_fb_helper_check_var); |
| 770 | |
| 771 | /* this will let fbcon do the mode init */ |
| 772 | int drm_fb_helper_set_par(struct fb_info *info) |
| 773 | { |
| 774 | struct drm_fb_helper *fb_helper = info->par; |
| 775 | struct drm_device *dev = fb_helper->dev; |
| 776 | struct fb_var_screeninfo *var = &info->var; |
| 777 | struct drm_crtc *crtc; |
| 778 | int ret; |
| 779 | int i; |
| 780 | |
Clemens Ladisch | 5349ef3 | 2009-11-04 09:42:52 +0100 | [diff] [blame] | 781 | if (var->pixclock != 0) { |
Pavel Roskin | 172e91f | 2010-02-11 14:31:32 +1000 | [diff] [blame] | 782 | DRM_ERROR("PIXEL CLOCK SET\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 783 | return -EINVAL; |
| 784 | } |
| 785 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 786 | mutex_lock(&dev->mode_config.mutex); |
| 787 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 788 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 789 | ret = crtc->funcs->set_config(&fb_helper->crtc_info[i].mode_set); |
| 790 | if (ret) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 791 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 792 | return ret; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 793 | } |
| 794 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 795 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 796 | |
| 797 | if (fb_helper->delayed_hotplug) { |
| 798 | fb_helper->delayed_hotplug = false; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 799 | drm_fb_helper_hotplug_event(fb_helper); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 800 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 801 | return 0; |
| 802 | } |
| 803 | EXPORT_SYMBOL(drm_fb_helper_set_par); |
| 804 | |
| 805 | int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, |
| 806 | struct fb_info *info) |
| 807 | { |
| 808 | struct drm_fb_helper *fb_helper = info->par; |
| 809 | struct drm_device *dev = fb_helper->dev; |
| 810 | struct drm_mode_set *modeset; |
| 811 | struct drm_crtc *crtc; |
| 812 | int ret = 0; |
| 813 | int i; |
| 814 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 815 | mutex_lock(&dev->mode_config.mutex); |
| 816 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 817 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 818 | |
| 819 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 820 | |
| 821 | modeset->x = var->xoffset; |
| 822 | modeset->y = var->yoffset; |
| 823 | |
| 824 | if (modeset->num_connectors) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 825 | ret = crtc->funcs->set_config(modeset); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 826 | if (!ret) { |
| 827 | info->var.xoffset = var->xoffset; |
| 828 | info->var.yoffset = var->yoffset; |
| 829 | } |
| 830 | } |
| 831 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 832 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 833 | return ret; |
| 834 | } |
| 835 | EXPORT_SYMBOL(drm_fb_helper_pan_display); |
| 836 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 837 | int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, |
| 838 | int preferred_bpp) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 839 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 840 | int new_fb = 0; |
| 841 | int crtc_count = 0; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 842 | int i; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 843 | struct fb_info *info; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 844 | struct drm_fb_helper_surface_size sizes; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 845 | int gamma_size = 0; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 846 | |
| 847 | memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); |
| 848 | sizes.surface_depth = 24; |
| 849 | sizes.surface_bpp = 32; |
| 850 | sizes.fb_width = (unsigned)-1; |
| 851 | sizes.fb_height = (unsigned)-1; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 852 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 853 | /* if driver picks 8 or 16 by default use that |
| 854 | for both depth/bpp */ |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 855 | if (preferred_bpp != sizes.surface_bpp) { |
| 856 | sizes.surface_depth = sizes.surface_bpp = preferred_bpp; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 857 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 858 | /* first up get a count of crtcs now in use and new min/maxes width/heights */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 859 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 860 | struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i]; |
Dave Airlie | 8ef8678 | 2009-09-26 06:39:00 +1000 | [diff] [blame] | 861 | struct drm_fb_helper_cmdline_mode *cmdline_mode; |
| 862 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 863 | cmdline_mode = &fb_helper_conn->cmdline_mode; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 864 | |
| 865 | if (cmdline_mode->bpp_specified) { |
| 866 | switch (cmdline_mode->bpp) { |
| 867 | case 8: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 868 | sizes.surface_depth = sizes.surface_bpp = 8; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 869 | break; |
| 870 | case 15: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 871 | sizes.surface_depth = 15; |
| 872 | sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 873 | break; |
| 874 | case 16: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 875 | sizes.surface_depth = sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 876 | break; |
| 877 | case 24: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 878 | sizes.surface_depth = sizes.surface_bpp = 24; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 879 | break; |
| 880 | case 32: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 881 | sizes.surface_depth = 24; |
| 882 | sizes.surface_bpp = 32; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 883 | break; |
| 884 | } |
| 885 | break; |
| 886 | } |
| 887 | } |
| 888 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 889 | crtc_count = 0; |
| 890 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 891 | struct drm_display_mode *desired_mode; |
| 892 | desired_mode = fb_helper->crtc_info[i].desired_mode; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 893 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 894 | if (desired_mode) { |
| 895 | if (gamma_size == 0) |
| 896 | gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size; |
| 897 | if (desired_mode->hdisplay < sizes.fb_width) |
| 898 | sizes.fb_width = desired_mode->hdisplay; |
| 899 | if (desired_mode->vdisplay < sizes.fb_height) |
| 900 | sizes.fb_height = desired_mode->vdisplay; |
| 901 | if (desired_mode->hdisplay > sizes.surface_width) |
| 902 | sizes.surface_width = desired_mode->hdisplay; |
| 903 | if (desired_mode->vdisplay > sizes.surface_height) |
| 904 | sizes.surface_height = desired_mode->vdisplay; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 905 | crtc_count++; |
| 906 | } |
| 907 | } |
| 908 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 909 | if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 910 | /* hmm everyone went away - assume VGA cable just fell out |
| 911 | and will come back later. */ |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 912 | DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n"); |
Dave Airlie | 19b4b44 | 2010-03-30 05:34:16 +0000 | [diff] [blame] | 913 | sizes.fb_width = sizes.surface_width = 1024; |
| 914 | sizes.fb_height = sizes.surface_height = 768; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 915 | } |
| 916 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 917 | /* push down into drivers */ |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 918 | new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 919 | if (new_fb < 0) |
| 920 | return new_fb; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 921 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 922 | info = fb_helper->fbdev; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 923 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 924 | /* set the fb pointer */ |
| 925 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 926 | fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 927 | } |
| 928 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 929 | if (new_fb) { |
Clemens Ladisch | 5349ef3 | 2009-11-04 09:42:52 +0100 | [diff] [blame] | 930 | info->var.pixclock = 0; |
Clemens Ladisch | 3bea21b | 2009-11-04 09:43:00 +0100 | [diff] [blame] | 931 | if (register_framebuffer(info) < 0) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 932 | return -EINVAL; |
Clemens Ladisch | 3bea21b | 2009-11-04 09:43:00 +0100 | [diff] [blame] | 933 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 934 | |
| 935 | printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, |
| 936 | info->fix.id); |
| 937 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 938 | } else { |
| 939 | drm_fb_helper_set_par(info); |
| 940 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 941 | |
| 942 | /* Switch back to kernel console on panic */ |
| 943 | /* multi card linked list maybe */ |
| 944 | if (list_empty(&kernel_fb_helper_list)) { |
Kirill Smelkov | 3da1f33 | 2010-05-14 19:45:16 +0400 | [diff] [blame] | 945 | printk(KERN_INFO "drm: registered panic notifier\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 946 | atomic_notifier_chain_register(&panic_notifier_list, |
| 947 | &paniced); |
| 948 | register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 949 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 950 | if (new_fb) |
| 951 | list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list); |
| 952 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 953 | return 0; |
| 954 | } |
| 955 | EXPORT_SYMBOL(drm_fb_helper_single_fb_probe); |
| 956 | |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 957 | void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, |
| 958 | uint32_t depth) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 959 | { |
| 960 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 961 | info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR : |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 962 | FB_VISUAL_TRUECOLOR; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 963 | info->fix.type_aux = 0; |
| 964 | info->fix.xpanstep = 1; /* doing it in hw */ |
| 965 | info->fix.ypanstep = 1; /* doing it in hw */ |
| 966 | info->fix.ywrapstep = 0; |
Dave Airlie | 3420e74 | 2009-08-31 10:33:29 +1000 | [diff] [blame] | 967 | info->fix.accel = FB_ACCEL_NONE; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 968 | info->fix.type_aux = 0; |
| 969 | |
| 970 | info->fix.line_length = pitch; |
| 971 | return; |
| 972 | } |
| 973 | EXPORT_SYMBOL(drm_fb_helper_fill_fix); |
| 974 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 975 | void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper, |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 976 | uint32_t fb_width, uint32_t fb_height) |
| 977 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 978 | struct drm_framebuffer *fb = fb_helper->fb; |
| 979 | info->pseudo_palette = fb_helper->pseudo_palette; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 980 | info->var.xres_virtual = fb->width; |
| 981 | info->var.yres_virtual = fb->height; |
| 982 | info->var.bits_per_pixel = fb->bits_per_pixel; |
| 983 | info->var.xoffset = 0; |
| 984 | info->var.yoffset = 0; |
| 985 | info->var.activate = FB_ACTIVATE_NOW; |
| 986 | info->var.height = -1; |
| 987 | info->var.width = -1; |
| 988 | |
| 989 | switch (fb->depth) { |
| 990 | case 8: |
| 991 | info->var.red.offset = 0; |
| 992 | info->var.green.offset = 0; |
| 993 | info->var.blue.offset = 0; |
| 994 | info->var.red.length = 8; /* 8bit DAC */ |
| 995 | info->var.green.length = 8; |
| 996 | info->var.blue.length = 8; |
| 997 | info->var.transp.offset = 0; |
| 998 | info->var.transp.length = 0; |
| 999 | break; |
| 1000 | case 15: |
| 1001 | info->var.red.offset = 10; |
| 1002 | info->var.green.offset = 5; |
| 1003 | info->var.blue.offset = 0; |
| 1004 | info->var.red.length = 5; |
| 1005 | info->var.green.length = 5; |
| 1006 | info->var.blue.length = 5; |
| 1007 | info->var.transp.offset = 15; |
| 1008 | info->var.transp.length = 1; |
| 1009 | break; |
| 1010 | case 16: |
| 1011 | info->var.red.offset = 11; |
| 1012 | info->var.green.offset = 5; |
| 1013 | info->var.blue.offset = 0; |
| 1014 | info->var.red.length = 5; |
| 1015 | info->var.green.length = 6; |
| 1016 | info->var.blue.length = 5; |
| 1017 | info->var.transp.offset = 0; |
| 1018 | break; |
| 1019 | case 24: |
| 1020 | info->var.red.offset = 16; |
| 1021 | info->var.green.offset = 8; |
| 1022 | info->var.blue.offset = 0; |
| 1023 | info->var.red.length = 8; |
| 1024 | info->var.green.length = 8; |
| 1025 | info->var.blue.length = 8; |
| 1026 | info->var.transp.offset = 0; |
| 1027 | info->var.transp.length = 0; |
| 1028 | break; |
| 1029 | case 32: |
| 1030 | info->var.red.offset = 16; |
| 1031 | info->var.green.offset = 8; |
| 1032 | info->var.blue.offset = 0; |
| 1033 | info->var.red.length = 8; |
| 1034 | info->var.green.length = 8; |
| 1035 | info->var.blue.length = 8; |
| 1036 | info->var.transp.offset = 24; |
| 1037 | info->var.transp.length = 8; |
| 1038 | break; |
| 1039 | default: |
| 1040 | break; |
| 1041 | } |
| 1042 | |
| 1043 | info->var.xres = fb_width; |
| 1044 | info->var.yres = fb_height; |
| 1045 | } |
| 1046 | EXPORT_SYMBOL(drm_fb_helper_fill_var); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1047 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1048 | static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper, |
| 1049 | uint32_t maxX, |
| 1050 | uint32_t maxY) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1051 | { |
| 1052 | struct drm_connector *connector; |
| 1053 | int count = 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1054 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1055 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1056 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1057 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1058 | count += connector->funcs->fill_modes(connector, maxX, maxY); |
| 1059 | } |
| 1060 | |
| 1061 | return count; |
| 1062 | } |
| 1063 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1064 | static struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1065 | { |
| 1066 | struct drm_display_mode *mode; |
| 1067 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1068 | list_for_each_entry(mode, &fb_connector->connector->modes, head) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1069 | if (drm_mode_width(mode) > width || |
| 1070 | drm_mode_height(mode) > height) |
| 1071 | continue; |
| 1072 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 1073 | return mode; |
| 1074 | } |
| 1075 | return NULL; |
| 1076 | } |
| 1077 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1078 | static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1079 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1080 | struct drm_fb_helper_cmdline_mode *cmdline_mode; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1081 | cmdline_mode = &fb_connector->cmdline_mode; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1082 | return cmdline_mode->specified; |
| 1083 | } |
| 1084 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1085 | static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn, |
| 1086 | int width, int height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1087 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1088 | struct drm_fb_helper_cmdline_mode *cmdline_mode; |
| 1089 | struct drm_display_mode *mode = NULL; |
| 1090 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1091 | cmdline_mode = &fb_helper_conn->cmdline_mode; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1092 | if (cmdline_mode->specified == false) |
| 1093 | return mode; |
| 1094 | |
| 1095 | /* attempt to find a matching mode in the list of modes |
| 1096 | * we have gotten so far, if not add a CVT mode that conforms |
| 1097 | */ |
| 1098 | if (cmdline_mode->rb || cmdline_mode->margins) |
| 1099 | goto create_mode; |
| 1100 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1101 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1102 | /* check width/height */ |
| 1103 | if (mode->hdisplay != cmdline_mode->xres || |
| 1104 | mode->vdisplay != cmdline_mode->yres) |
| 1105 | continue; |
| 1106 | |
| 1107 | if (cmdline_mode->refresh_specified) { |
| 1108 | if (mode->vrefresh != cmdline_mode->refresh) |
| 1109 | continue; |
| 1110 | } |
| 1111 | |
| 1112 | if (cmdline_mode->interlace) { |
| 1113 | if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) |
| 1114 | continue; |
| 1115 | } |
| 1116 | return mode; |
| 1117 | } |
| 1118 | |
| 1119 | create_mode: |
Adam Jackson | b829e01 | 2010-06-10 13:33:26 -0400 | [diff] [blame] | 1120 | if (cmdline_mode->cvt) |
| 1121 | mode = drm_cvt_mode(fb_helper_conn->connector->dev, |
| 1122 | cmdline_mode->xres, cmdline_mode->yres, |
| 1123 | cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60, |
| 1124 | cmdline_mode->rb, cmdline_mode->interlace, |
| 1125 | cmdline_mode->margins); |
| 1126 | else |
| 1127 | mode = drm_gtf_mode(fb_helper_conn->connector->dev, |
| 1128 | cmdline_mode->xres, cmdline_mode->yres, |
| 1129 | cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60, |
| 1130 | cmdline_mode->interlace, |
| 1131 | cmdline_mode->margins); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1132 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1133 | list_add(&mode->head, &fb_helper_conn->connector->modes); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1134 | return mode; |
| 1135 | } |
| 1136 | |
| 1137 | static bool drm_connector_enabled(struct drm_connector *connector, bool strict) |
| 1138 | { |
| 1139 | bool enable; |
| 1140 | |
| 1141 | if (strict) { |
| 1142 | enable = connector->status == connector_status_connected; |
| 1143 | } else { |
| 1144 | enable = connector->status != connector_status_disconnected; |
| 1145 | } |
| 1146 | return enable; |
| 1147 | } |
| 1148 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1149 | static void drm_enable_connectors(struct drm_fb_helper *fb_helper, |
| 1150 | bool *enabled) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1151 | { |
| 1152 | bool any_enabled = false; |
| 1153 | struct drm_connector *connector; |
| 1154 | int i = 0; |
| 1155 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1156 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1157 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1158 | enabled[i] = drm_connector_enabled(connector, true); |
| 1159 | DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id, |
| 1160 | enabled[i] ? "yes" : "no"); |
| 1161 | any_enabled |= enabled[i]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | if (any_enabled) |
| 1165 | return; |
| 1166 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1167 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1168 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1169 | enabled[i] = drm_connector_enabled(connector, false); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1173 | static bool drm_target_cloned(struct drm_fb_helper *fb_helper, |
| 1174 | struct drm_display_mode **modes, |
| 1175 | bool *enabled, int width, int height) |
| 1176 | { |
| 1177 | int count, i, j; |
| 1178 | bool can_clone = false; |
| 1179 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1180 | struct drm_display_mode *dmt_mode, *mode; |
| 1181 | |
| 1182 | /* only contemplate cloning in the single crtc case */ |
| 1183 | if (fb_helper->crtc_count > 1) |
| 1184 | return false; |
| 1185 | |
| 1186 | count = 0; |
| 1187 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1188 | if (enabled[i]) |
| 1189 | count++; |
| 1190 | } |
| 1191 | |
| 1192 | /* only contemplate cloning if more than one connector is enabled */ |
| 1193 | if (count <= 1) |
| 1194 | return false; |
| 1195 | |
| 1196 | /* check the command line or if nothing common pick 1024x768 */ |
| 1197 | can_clone = true; |
| 1198 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1199 | if (!enabled[i]) |
| 1200 | continue; |
| 1201 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1202 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); |
| 1203 | if (!modes[i]) { |
| 1204 | can_clone = false; |
| 1205 | break; |
| 1206 | } |
| 1207 | for (j = 0; j < i; j++) { |
| 1208 | if (!enabled[j]) |
| 1209 | continue; |
| 1210 | if (!drm_mode_equal(modes[j], modes[i])) |
| 1211 | can_clone = false; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | if (can_clone) { |
| 1216 | DRM_DEBUG_KMS("can clone using command line\n"); |
| 1217 | return true; |
| 1218 | } |
| 1219 | |
| 1220 | /* try and find a 1024x768 mode on each connector */ |
| 1221 | can_clone = true; |
| 1222 | dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60); |
| 1223 | |
| 1224 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1225 | |
| 1226 | if (!enabled[i]) |
| 1227 | continue; |
| 1228 | |
| 1229 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1230 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
| 1231 | if (drm_mode_equal(mode, dmt_mode)) |
| 1232 | modes[i] = mode; |
| 1233 | } |
| 1234 | if (!modes[i]) |
| 1235 | can_clone = false; |
| 1236 | } |
| 1237 | |
| 1238 | if (can_clone) { |
| 1239 | DRM_DEBUG_KMS("can clone using 1024x768\n"); |
| 1240 | return true; |
| 1241 | } |
| 1242 | DRM_INFO("kms: can't enable cloning when we probably wanted to.\n"); |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1246 | static bool drm_target_preferred(struct drm_fb_helper *fb_helper, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1247 | struct drm_display_mode **modes, |
| 1248 | bool *enabled, int width, int height) |
| 1249 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1250 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1251 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1252 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1253 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1254 | fb_helper_conn = fb_helper->connector_info[i]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1255 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1256 | if (enabled[i] == false) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1257 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1258 | |
| 1259 | DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n", |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1260 | fb_helper_conn->connector->base.id); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1261 | |
| 1262 | /* got for command line mode first */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1263 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1264 | if (!modes[i]) { |
| 1265 | DRM_DEBUG_KMS("looking for preferred mode on connector %d\n", |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1266 | fb_helper_conn->connector->base.id); |
| 1267 | modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1268 | } |
| 1269 | /* No preferred modes, pick one off the list */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1270 | if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) { |
| 1271 | list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1272 | break; |
| 1273 | } |
| 1274 | DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name : |
| 1275 | "none"); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1276 | } |
| 1277 | return true; |
| 1278 | } |
| 1279 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1280 | static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, |
| 1281 | struct drm_fb_helper_crtc **best_crtcs, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1282 | struct drm_display_mode **modes, |
| 1283 | int n, int width, int height) |
| 1284 | { |
| 1285 | int c, o; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1286 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1287 | struct drm_connector *connector; |
| 1288 | struct drm_connector_helper_funcs *connector_funcs; |
| 1289 | struct drm_encoder *encoder; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1290 | struct drm_fb_helper_crtc *best_crtc; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1291 | int my_score, best_score, score; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1292 | struct drm_fb_helper_crtc **crtcs, *crtc; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1293 | struct drm_fb_helper_connector *fb_helper_conn; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1294 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1295 | if (n == fb_helper->connector_count) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1296 | return 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1297 | |
| 1298 | fb_helper_conn = fb_helper->connector_info[n]; |
| 1299 | connector = fb_helper_conn->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1300 | |
| 1301 | best_crtcs[n] = NULL; |
| 1302 | best_crtc = NULL; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1303 | best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1304 | if (modes[n] == NULL) |
| 1305 | return best_score; |
| 1306 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1307 | crtcs = kzalloc(dev->mode_config.num_connector * |
| 1308 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1309 | if (!crtcs) |
| 1310 | return best_score; |
| 1311 | |
| 1312 | my_score = 1; |
| 1313 | if (connector->status == connector_status_connected) |
| 1314 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1315 | if (drm_has_cmdline_mode(fb_helper_conn)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1316 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1317 | if (drm_has_preferred_mode(fb_helper_conn, width, height)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1318 | my_score++; |
| 1319 | |
| 1320 | connector_funcs = connector->helper_private; |
| 1321 | encoder = connector_funcs->best_encoder(connector); |
| 1322 | if (!encoder) |
| 1323 | goto out; |
| 1324 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1325 | /* select a crtc for this connector and then attempt to configure |
| 1326 | remaining connectors */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1327 | for (c = 0; c < fb_helper->crtc_count; c++) { |
| 1328 | crtc = &fb_helper->crtc_info[c]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1329 | |
| 1330 | if ((encoder->possible_crtcs & (1 << c)) == 0) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1331 | continue; |
| 1332 | } |
| 1333 | |
| 1334 | for (o = 0; o < n; o++) |
| 1335 | if (best_crtcs[o] == crtc) |
| 1336 | break; |
| 1337 | |
| 1338 | if (o < n) { |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1339 | /* ignore cloning unless only a single crtc */ |
| 1340 | if (fb_helper->crtc_count > 1) |
| 1341 | continue; |
| 1342 | |
| 1343 | if (!drm_mode_equal(modes[o], modes[n])) |
| 1344 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | crtcs[n] = crtc; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1348 | memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *)); |
| 1349 | score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1350 | width, height); |
| 1351 | if (score > best_score) { |
| 1352 | best_crtc = crtc; |
| 1353 | best_score = score; |
| 1354 | memcpy(best_crtcs, crtcs, |
| 1355 | dev->mode_config.num_connector * |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1356 | sizeof(struct drm_fb_helper_crtc *)); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1357 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1358 | } |
| 1359 | out: |
| 1360 | kfree(crtcs); |
| 1361 | return best_score; |
| 1362 | } |
| 1363 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1364 | static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1365 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1366 | struct drm_device *dev = fb_helper->dev; |
| 1367 | struct drm_fb_helper_crtc **crtcs; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1368 | struct drm_display_mode **modes; |
| 1369 | struct drm_encoder *encoder; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1370 | struct drm_mode_set *modeset; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1371 | bool *enabled; |
| 1372 | int width, height; |
| 1373 | int i, ret; |
| 1374 | |
| 1375 | DRM_DEBUG_KMS("\n"); |
| 1376 | |
| 1377 | width = dev->mode_config.max_width; |
| 1378 | height = dev->mode_config.max_height; |
| 1379 | |
| 1380 | /* clean out all the encoder/crtc combos */ |
| 1381 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 1382 | encoder->crtc = NULL; |
| 1383 | } |
| 1384 | |
| 1385 | crtcs = kcalloc(dev->mode_config.num_connector, |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1386 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1387 | modes = kcalloc(dev->mode_config.num_connector, |
| 1388 | sizeof(struct drm_display_mode *), GFP_KERNEL); |
| 1389 | enabled = kcalloc(dev->mode_config.num_connector, |
| 1390 | sizeof(bool), GFP_KERNEL); |
| 1391 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1392 | drm_enable_connectors(fb_helper, enabled); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1393 | |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1394 | ret = drm_target_cloned(fb_helper, modes, enabled, width, height); |
| 1395 | if (!ret) { |
| 1396 | ret = drm_target_preferred(fb_helper, modes, enabled, width, height); |
| 1397 | if (!ret) |
| 1398 | DRM_ERROR("Unable to find initial modes\n"); |
| 1399 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1400 | |
| 1401 | DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height); |
| 1402 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1403 | drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height); |
| 1404 | |
| 1405 | /* need to set the modesets up here for use later */ |
| 1406 | /* fill out the connector<->crtc mappings into the modesets */ |
| 1407 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 1408 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 1409 | modeset->num_connectors = 0; |
| 1410 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1411 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1412 | for (i = 0; i < fb_helper->connector_count; i++) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1413 | struct drm_display_mode *mode = modes[i]; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1414 | struct drm_fb_helper_crtc *fb_crtc = crtcs[i]; |
| 1415 | modeset = &fb_crtc->mode_set; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1416 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1417 | if (mode && fb_crtc) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1418 | DRM_DEBUG_KMS("desired mode %s set on crtc %d\n", |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1419 | mode->name, fb_crtc->mode_set.crtc->base.id); |
| 1420 | fb_crtc->desired_mode = mode; |
| 1421 | if (modeset->mode) |
| 1422 | drm_mode_destroy(dev, modeset->mode); |
| 1423 | modeset->mode = drm_mode_duplicate(dev, |
| 1424 | fb_crtc->desired_mode); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1425 | modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1426 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | kfree(crtcs); |
| 1430 | kfree(modes); |
| 1431 | kfree(enabled); |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * drm_helper_initial_config - setup a sane initial connector configuration |
| 1436 | * @dev: DRM device |
| 1437 | * |
| 1438 | * LOCKING: |
| 1439 | * Called at init time, must take mode config lock. |
| 1440 | * |
| 1441 | * Scan the CRTCs and connectors and try to put together an initial setup. |
| 1442 | * At the moment, this is a cloned configuration across all heads with |
| 1443 | * a new framebuffer object as the backing store. |
| 1444 | * |
| 1445 | * RETURNS: |
| 1446 | * Zero if everything went ok, nonzero otherwise. |
| 1447 | */ |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1448 | bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1449 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1450 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1451 | int count = 0; |
| 1452 | |
| 1453 | /* disable all the possible outputs/crtcs before entering KMS mode */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1454 | drm_helper_disable_unused_functions(fb_helper->dev); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1455 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1456 | drm_fb_helper_parse_command_line(fb_helper); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1457 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1458 | count = drm_fb_helper_probe_connector_modes(fb_helper, |
| 1459 | dev->mode_config.max_width, |
| 1460 | dev->mode_config.max_height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1461 | /* |
| 1462 | * we shouldn't end up with no modes here. |
| 1463 | */ |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1464 | if (count == 0) { |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1465 | printk(KERN_INFO "No connectors reported connected with modes\n"); |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1466 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1467 | drm_setup_crtcs(fb_helper); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1468 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1469 | return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1470 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1471 | EXPORT_SYMBOL(drm_fb_helper_initial_config); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1472 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1473 | bool drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1474 | { |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1475 | int count = 0; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1476 | u32 max_width, max_height, bpp_sel; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1477 | bool bound = false, crtcs_bound = false; |
| 1478 | struct drm_crtc *crtc; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1479 | |
| 1480 | if (!fb_helper->fb) |
| 1481 | return false; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1482 | |
| 1483 | list_for_each_entry(crtc, &fb_helper->dev->mode_config.crtc_list, head) { |
| 1484 | if (crtc->fb) |
| 1485 | crtcs_bound = true; |
| 1486 | if (crtc->fb == fb_helper->fb) |
| 1487 | bound = true; |
| 1488 | } |
| 1489 | |
| 1490 | if (!bound && crtcs_bound) { |
| 1491 | fb_helper->delayed_hotplug = true; |
| 1492 | return false; |
| 1493 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1494 | DRM_DEBUG_KMS("\n"); |
| 1495 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1496 | max_width = fb_helper->fb->width; |
| 1497 | max_height = fb_helper->fb->height; |
| 1498 | bpp_sel = fb_helper->fb->bits_per_pixel; |
| 1499 | |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1500 | count = drm_fb_helper_probe_connector_modes(fb_helper, max_width, |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1501 | max_height); |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1502 | drm_setup_crtcs(fb_helper); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1503 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1504 | return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1505 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1506 | EXPORT_SYMBOL(drm_fb_helper_hotplug_event); |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1507 | |