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