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