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