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 | */ |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 31 | |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 32 | #include <linux/kernel.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 33 | #include <linux/sysrq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 35 | #include <linux/fb.h> |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 36 | #include <linux/module.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/drmP.h> |
| 38 | #include <drm/drm_crtc.h> |
| 39 | #include <drm/drm_fb_helper.h> |
| 40 | #include <drm/drm_crtc_helper.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 41 | |
Dave Airlie | 6fcefd5 | 2009-09-08 11:08:32 +1000 | [diff] [blame] | 42 | MODULE_AUTHOR("David Airlie, Jesse Barnes"); |
| 43 | MODULE_DESCRIPTION("DRM KMS helper"); |
| 44 | MODULE_LICENSE("GPL and additional rights"); |
| 45 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 46 | static LIST_HEAD(kernel_fb_helper_list); |
| 47 | |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 48 | /** |
| 49 | * DOC: fbdev helpers |
| 50 | * |
| 51 | * The fb helper functions are useful to provide an fbdev on top of a drm kernel |
| 52 | * mode setting driver. They can be used mostly independantely from the crtc |
| 53 | * helper functions used by many drivers to implement the kernel mode setting |
| 54 | * interfaces. |
| 55 | */ |
| 56 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 57 | /* simple single crtc case helper function */ |
| 58 | 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] | 59 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 60 | struct drm_device *dev = fb_helper->dev; |
| 61 | struct drm_connector *connector; |
| 62 | int i; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 63 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 64 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 65 | struct drm_fb_helper_connector *fb_helper_connector; |
| 66 | |
| 67 | fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL); |
| 68 | if (!fb_helper_connector) |
| 69 | goto fail; |
| 70 | |
| 71 | fb_helper_connector->connector = connector; |
| 72 | fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector; |
| 73 | } |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 74 | return 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 75 | fail: |
| 76 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 77 | kfree(fb_helper->connector_info[i]); |
| 78 | fb_helper->connector_info[i] = NULL; |
| 79 | } |
| 80 | fb_helper->connector_count = 0; |
| 81 | return -ENOMEM; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 82 | } |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 83 | EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 84 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 85 | 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] | 86 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 87 | struct drm_fb_helper_connector *fb_helper_conn; |
| 88 | int i; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 89 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 90 | for (i = 0; i < fb_helper->connector_count; i++) { |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 91 | struct drm_cmdline_mode *mode; |
| 92 | struct drm_connector *connector; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 93 | char *option = NULL; |
| 94 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 95 | fb_helper_conn = fb_helper->connector_info[i]; |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 96 | connector = fb_helper_conn->connector; |
| 97 | mode = &fb_helper_conn->cmdline_mode; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 98 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 99 | /* do something on return - turn off connector maybe */ |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 100 | if (fb_get_options(drm_get_connector_name(connector), &option)) |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 101 | continue; |
| 102 | |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 103 | if (drm_mode_parse_command_line_for_connector(option, |
| 104 | connector, |
| 105 | mode)) { |
| 106 | if (mode->force) { |
| 107 | const char *s; |
| 108 | switch (mode->force) { |
Sachin Kamat | 6c91083 | 2012-11-15 03:43:28 +0000 | [diff] [blame] | 109 | case DRM_FORCE_OFF: |
| 110 | s = "OFF"; |
| 111 | break; |
| 112 | case DRM_FORCE_ON_DIGITAL: |
| 113 | s = "ON - dig"; |
| 114 | break; |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 115 | default: |
Sachin Kamat | 6c91083 | 2012-11-15 03:43:28 +0000 | [diff] [blame] | 116 | case DRM_FORCE_ON: |
| 117 | s = "ON"; |
| 118 | break; |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | DRM_INFO("forcing %s connector %s\n", |
| 122 | drm_get_connector_name(connector), s); |
| 123 | connector->force = mode->force; |
| 124 | } |
| 125 | |
| 126 | DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", |
| 127 | drm_get_connector_name(connector), |
| 128 | mode->xres, mode->yres, |
| 129 | mode->refresh_specified ? mode->refresh : 60, |
| 130 | mode->rb ? " reduced blanking" : "", |
| 131 | mode->margins ? " with margins" : "", |
| 132 | mode->interlace ? " interlaced" : ""); |
| 133 | } |
| 134 | |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 135 | } |
| 136 | return 0; |
| 137 | } |
| 138 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 139 | static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper) |
| 140 | { |
| 141 | uint16_t *r_base, *g_base, *b_base; |
| 142 | int i; |
| 143 | |
| 144 | r_base = crtc->gamma_store; |
| 145 | g_base = r_base + crtc->gamma_size; |
| 146 | b_base = g_base + crtc->gamma_size; |
| 147 | |
| 148 | for (i = 0; i < crtc->gamma_size; i++) |
| 149 | helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i); |
| 150 | } |
| 151 | |
| 152 | static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc) |
| 153 | { |
| 154 | uint16_t *r_base, *g_base, *b_base; |
| 155 | |
Laurent Pinchart | ebe0f24 | 2012-05-17 13:27:24 +0200 | [diff] [blame] | 156 | if (crtc->funcs->gamma_set == NULL) |
| 157 | return; |
| 158 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 159 | r_base = crtc->gamma_store; |
| 160 | g_base = r_base + crtc->gamma_size; |
| 161 | b_base = g_base + crtc->gamma_size; |
| 162 | |
| 163 | crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); |
| 164 | } |
| 165 | |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 166 | int drm_fb_helper_debug_enter(struct fb_info *info) |
| 167 | { |
| 168 | struct drm_fb_helper *helper = info->par; |
| 169 | struct drm_crtc_helper_funcs *funcs; |
| 170 | int i; |
| 171 | |
| 172 | if (list_empty(&kernel_fb_helper_list)) |
| 173 | return false; |
| 174 | |
| 175 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
| 176 | for (i = 0; i < helper->crtc_count; i++) { |
| 177 | struct drm_mode_set *mode_set = |
| 178 | &helper->crtc_info[i].mode_set; |
| 179 | |
| 180 | if (!mode_set->crtc->enabled) |
| 181 | continue; |
| 182 | |
| 183 | funcs = mode_set->crtc->helper_private; |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 184 | drm_fb_helper_save_lut_atomic(mode_set->crtc, helper); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 185 | funcs->mode_set_base_atomic(mode_set->crtc, |
| 186 | mode_set->fb, |
| 187 | mode_set->x, |
Jason Wessel | 413d45d | 2010-09-26 06:47:25 -0500 | [diff] [blame] | 188 | mode_set->y, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 189 | ENTER_ATOMIC_MODE_SET); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | EXPORT_SYMBOL(drm_fb_helper_debug_enter); |
| 196 | |
| 197 | /* Find the real fb for a given fb helper CRTC */ |
| 198 | static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc) |
| 199 | { |
| 200 | struct drm_device *dev = crtc->dev; |
| 201 | struct drm_crtc *c; |
| 202 | |
| 203 | list_for_each_entry(c, &dev->mode_config.crtc_list, head) { |
| 204 | if (crtc->base.id == c->base.id) |
| 205 | return c->fb; |
| 206 | } |
| 207 | |
| 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | int drm_fb_helper_debug_leave(struct fb_info *info) |
| 212 | { |
| 213 | struct drm_fb_helper *helper = info->par; |
| 214 | struct drm_crtc *crtc; |
| 215 | struct drm_crtc_helper_funcs *funcs; |
| 216 | struct drm_framebuffer *fb; |
| 217 | int i; |
| 218 | |
| 219 | for (i = 0; i < helper->crtc_count; i++) { |
| 220 | struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set; |
| 221 | crtc = mode_set->crtc; |
| 222 | funcs = crtc->helper_private; |
| 223 | fb = drm_mode_config_fb(crtc); |
| 224 | |
| 225 | if (!crtc->enabled) |
| 226 | continue; |
| 227 | |
| 228 | if (!fb) { |
| 229 | DRM_ERROR("no fb to restore??\n"); |
| 230 | continue; |
| 231 | } |
| 232 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 233 | drm_fb_helper_restore_lut_atomic(mode_set->crtc); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 234 | funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 235 | crtc->y, LEAVE_ATOMIC_MODE_SET); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | EXPORT_SYMBOL(drm_fb_helper_debug_leave); |
| 241 | |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 242 | /** |
| 243 | * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration |
| 244 | * @fb_helper: fbcon to restore |
| 245 | * |
| 246 | * This should be called from driver's drm->lastclose callback when implementing |
| 247 | * an fbcon on top of kms using this helper. This ensures that the user isn't |
| 248 | * greeted with a black screen when e.g. X dies. |
| 249 | */ |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 250 | bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper) |
| 251 | { |
| 252 | bool error = false; |
| 253 | int i, ret; |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 254 | |
| 255 | drm_warn_on_modeset_not_all_locked(fb_helper->dev); |
| 256 | |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 257 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 258 | struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 259 | ret = drm_mode_set_config_internal(mode_set); |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 260 | if (ret) |
| 261 | error = true; |
| 262 | } |
| 263 | return error; |
| 264 | } |
| 265 | EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode); |
| 266 | |
Daniel Vetter | d21bf46 | 2013-01-20 18:09:52 +0100 | [diff] [blame] | 267 | /* |
| 268 | * restore fbcon display for all kms driver's using this helper, used for sysrq |
| 269 | * and panic handling. |
| 270 | */ |
Sachin Kamat | 78b9c35 | 2012-08-01 17:15:32 +0530 | [diff] [blame] | 271 | static bool drm_fb_helper_force_kernel_mode(void) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 272 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 273 | bool ret, error = false; |
| 274 | struct drm_fb_helper *helper; |
| 275 | |
| 276 | if (list_empty(&kernel_fb_helper_list)) |
| 277 | return false; |
| 278 | |
| 279 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 280 | if (helper->dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 281 | continue; |
| 282 | |
| 283 | ret = drm_fb_helper_restore_fbdev_mode(helper); |
| 284 | if (ret) |
| 285 | error = true; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 286 | } |
| 287 | return error; |
| 288 | } |
| 289 | |
Daniel Vetter | 43c8a84 | 2013-01-20 18:18:07 +0100 | [diff] [blame^] | 290 | static int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed, |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 291 | void *panic_str) |
| 292 | { |
Hugh Dickins | d68752c | 2011-10-17 17:06:40 -0700 | [diff] [blame] | 293 | /* |
| 294 | * It's a waste of time and effort to switch back to text console |
| 295 | * if the kernel should reboot before panic messages can be seen. |
| 296 | */ |
| 297 | if (panic_timeout < 0) |
| 298 | return 0; |
| 299 | |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 300 | pr_err("panic occurred, switching back to text console\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 301 | return drm_fb_helper_force_kernel_mode(); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 302 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 303 | |
| 304 | static struct notifier_block paniced = { |
| 305 | .notifier_call = drm_fb_helper_panic, |
| 306 | }; |
| 307 | |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 308 | static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper) |
| 309 | { |
| 310 | struct drm_device *dev = fb_helper->dev; |
| 311 | struct drm_crtc *crtc; |
| 312 | int bound = 0, crtcs_bound = 0; |
| 313 | |
| 314 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 315 | if (crtc->fb) |
| 316 | crtcs_bound++; |
| 317 | if (crtc->fb == fb_helper->fb) |
| 318 | bound++; |
| 319 | } |
| 320 | |
| 321 | if (bound < crtcs_bound) |
| 322 | return false; |
| 323 | return true; |
| 324 | } |
| 325 | |
Mikael Pettersson | bea1d35 | 2009-09-28 18:26:25 +0200 | [diff] [blame] | 326 | #ifdef CONFIG_MAGIC_SYSRQ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 327 | static void drm_fb_helper_restore_work_fn(struct work_struct *ignored) |
| 328 | { |
Daniel Vetter | d21bf46 | 2013-01-20 18:09:52 +0100 | [diff] [blame] | 329 | bool ret; |
| 330 | ret = drm_fb_helper_force_kernel_mode(); |
| 331 | if (ret == true) |
| 332 | DRM_ERROR("Failed to restore crtc configuration\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 333 | } |
| 334 | static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn); |
| 335 | |
Dmitry Torokhov | 1495cc9 | 2010-08-17 21:15:46 -0700 | [diff] [blame] | 336 | static void drm_fb_helper_sysrq(int dummy1) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 337 | { |
| 338 | schedule_work(&drm_fb_helper_restore_work); |
| 339 | } |
| 340 | |
| 341 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { |
| 342 | .handler = drm_fb_helper_sysrq, |
| 343 | .help_msg = "force-fb(V)", |
| 344 | .action_msg = "Restore framebuffer console", |
| 345 | }; |
Randy Dunlap | b8c40d6 | 2010-03-25 18:29:05 +0000 | [diff] [blame] | 346 | #else |
| 347 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { }; |
Mikael Pettersson | bea1d35 | 2009-09-28 18:26:25 +0200 | [diff] [blame] | 348 | #endif |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 349 | |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 350 | static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 351 | { |
| 352 | struct drm_fb_helper *fb_helper = info->par; |
| 353 | struct drm_device *dev = fb_helper->dev; |
| 354 | struct drm_crtc *crtc; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 355 | struct drm_connector *connector; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 356 | int i, j; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 357 | |
| 358 | /* |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 359 | * For each CRTC in this fb, turn the connectors on/off. |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 360 | */ |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 361 | drm_modeset_lock_all(dev); |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 362 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 363 | drm_modeset_unlock_all(dev); |
| 364 | return; |
| 365 | } |
| 366 | |
Jesse Barnes | e87b2c4 | 2009-09-17 18:14:41 -0700 | [diff] [blame] | 367 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 368 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
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 | if (!crtc->enabled) |
| 371 | continue; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 372 | |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 373 | /* Walk the connectors & encoders on this fb turning them on/off */ |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 374 | for (j = 0; j < fb_helper->connector_count; j++) { |
| 375 | connector = fb_helper->connector_info[j]->connector; |
Daniel Vetter | e04190e | 2012-09-07 10:14:52 +0200 | [diff] [blame] | 376 | connector->funcs->dpms(connector, dpms_mode); |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 377 | drm_object_property_set_value(&connector->base, |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 378 | dev->mode_config.dpms_property, dpms_mode); |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 379 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 380 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 381 | drm_modeset_unlock_all(dev); |
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: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 389 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 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: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 393 | drm_fb_helper_dpms(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: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 397 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 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: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 401 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 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: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 405 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 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); |
Sascha Hauer | a1b7736 | 2012-02-01 11:38:22 +0100 | [diff] [blame] | 419 | for (i = 0; i < helper->crtc_count; i++) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 420 | kfree(helper->crtc_info[i].mode_set.connectors); |
Sascha Hauer | a1b7736 | 2012-02-01 11:38:22 +0100 | [diff] [blame] | 421 | if (helper->crtc_info[i].mode_set.mode) |
| 422 | drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode); |
| 423 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 424 | kfree(helper->crtc_info); |
| 425 | } |
| 426 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 427 | int drm_fb_helper_init(struct drm_device *dev, |
| 428 | struct drm_fb_helper *fb_helper, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 429 | int crtc_count, int max_conn_count) |
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; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 432 | int i; |
| 433 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 434 | fb_helper->dev = dev; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 435 | |
| 436 | INIT_LIST_HEAD(&fb_helper->kernel_fb_list); |
| 437 | |
| 438 | fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL); |
| 439 | if (!fb_helper->crtc_info) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 440 | return -ENOMEM; |
| 441 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 442 | fb_helper->crtc_count = crtc_count; |
| 443 | fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL); |
| 444 | if (!fb_helper->connector_info) { |
| 445 | kfree(fb_helper->crtc_info); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 446 | return -ENOMEM; |
| 447 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 448 | fb_helper->connector_count = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 449 | |
| 450 | for (i = 0; i < crtc_count; i++) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 451 | fb_helper->crtc_info[i].mode_set.connectors = |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 452 | kcalloc(max_conn_count, |
| 453 | sizeof(struct drm_connector *), |
| 454 | GFP_KERNEL); |
| 455 | |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 456 | if (!fb_helper->crtc_info[i].mode_set.connectors) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 457 | goto out_free; |
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].mode_set.crtc = crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 464 | i++; |
| 465 | } |
Sascha Hauer | e9ad318 | 2012-02-01 11:38:25 +0100 | [diff] [blame] | 466 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 467 | return 0; |
| 468 | out_free: |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 469 | drm_fb_helper_crtc_free(fb_helper); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 470 | return -ENOMEM; |
| 471 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 472 | EXPORT_SYMBOL(drm_fb_helper_init); |
| 473 | |
| 474 | void drm_fb_helper_fini(struct drm_fb_helper *fb_helper) |
| 475 | { |
| 476 | if (!list_empty(&fb_helper->kernel_fb_list)) { |
| 477 | list_del(&fb_helper->kernel_fb_list); |
| 478 | if (list_empty(&kernel_fb_helper_list)) { |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 479 | pr_info("drm: unregistered panic notifier\n"); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 480 | atomic_notifier_chain_unregister(&panic_notifier_list, |
| 481 | &paniced); |
| 482 | unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | drm_fb_helper_crtc_free(fb_helper); |
| 487 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 488 | } |
| 489 | EXPORT_SYMBOL(drm_fb_helper_fini); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 490 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 491 | static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green, |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 492 | u16 blue, u16 regno, struct fb_info *info) |
| 493 | { |
| 494 | struct drm_fb_helper *fb_helper = info->par; |
| 495 | struct drm_framebuffer *fb = fb_helper->fb; |
| 496 | int pindex; |
| 497 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 498 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 499 | u32 *palette; |
| 500 | u32 value; |
| 501 | /* place color in psuedopalette */ |
| 502 | if (regno > 16) |
| 503 | return -EINVAL; |
| 504 | palette = (u32 *)info->pseudo_palette; |
| 505 | red >>= (16 - info->var.red.length); |
| 506 | green >>= (16 - info->var.green.length); |
| 507 | blue >>= (16 - info->var.blue.length); |
| 508 | value = (red << info->var.red.offset) | |
| 509 | (green << info->var.green.offset) | |
| 510 | (blue << info->var.blue.offset); |
Rob Clark | 9da12b6a | 2011-02-16 02:45:51 +0000 | [diff] [blame] | 511 | if (info->var.transp.length > 0) { |
| 512 | u32 mask = (1 << info->var.transp.length) - 1; |
| 513 | mask <<= info->var.transp.offset; |
| 514 | value |= mask; |
| 515 | } |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 516 | palette[regno] = value; |
| 517 | return 0; |
| 518 | } |
| 519 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 520 | pindex = regno; |
| 521 | |
| 522 | if (fb->bits_per_pixel == 16) { |
| 523 | pindex = regno << 3; |
| 524 | |
| 525 | if (fb->depth == 16 && regno > 63) |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 526 | return -EINVAL; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 527 | if (fb->depth == 15 && regno > 31) |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 528 | return -EINVAL; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 529 | |
| 530 | if (fb->depth == 16) { |
| 531 | u16 r, g, b; |
| 532 | int i; |
| 533 | if (regno < 32) { |
| 534 | for (i = 0; i < 8; i++) |
| 535 | fb_helper->funcs->gamma_set(crtc, red, |
| 536 | green, blue, pindex + i); |
| 537 | } |
| 538 | |
| 539 | fb_helper->funcs->gamma_get(crtc, &r, |
| 540 | &g, &b, |
| 541 | pindex >> 1); |
| 542 | |
| 543 | for (i = 0; i < 4; i++) |
| 544 | fb_helper->funcs->gamma_set(crtc, r, |
| 545 | green, b, |
| 546 | (pindex >> 1) + i); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | if (fb->depth != 16) |
| 551 | fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex); |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 552 | return 0; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 553 | } |
| 554 | |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 555 | int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 556 | { |
| 557 | struct drm_fb_helper *fb_helper = info->par; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 558 | struct drm_crtc_helper_funcs *crtc_funcs; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 559 | u16 *red, *green, *blue, *transp; |
| 560 | struct drm_crtc *crtc; |
roel | 062ac62 | 2011-03-07 18:00:34 +0100 | [diff] [blame] | 561 | int i, j, rc = 0; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 562 | int start; |
| 563 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 564 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 565 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
| 566 | crtc_funcs = crtc->helper_private; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 567 | |
| 568 | red = cmap->red; |
| 569 | green = cmap->green; |
| 570 | blue = cmap->blue; |
| 571 | transp = cmap->transp; |
| 572 | start = cmap->start; |
| 573 | |
roel | 062ac62 | 2011-03-07 18:00:34 +0100 | [diff] [blame] | 574 | for (j = 0; j < cmap->len; j++) { |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 575 | u16 hred, hgreen, hblue, htransp = 0xffff; |
| 576 | |
| 577 | hred = *red++; |
| 578 | hgreen = *green++; |
| 579 | hblue = *blue++; |
| 580 | |
| 581 | if (transp) |
| 582 | htransp = *transp++; |
| 583 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 584 | rc = setcolreg(crtc, hred, hgreen, hblue, start++, info); |
| 585 | if (rc) |
| 586 | return rc; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 587 | } |
| 588 | crtc_funcs->load_lut(crtc); |
| 589 | } |
| 590 | return rc; |
| 591 | } |
| 592 | EXPORT_SYMBOL(drm_fb_helper_setcmap); |
| 593 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 594 | int drm_fb_helper_check_var(struct fb_var_screeninfo *var, |
| 595 | struct fb_info *info) |
| 596 | { |
| 597 | struct drm_fb_helper *fb_helper = info->par; |
| 598 | struct drm_framebuffer *fb = fb_helper->fb; |
| 599 | int depth; |
| 600 | |
Jason Wessel | f90ebd9 | 2010-08-05 09:22:32 -0500 | [diff] [blame] | 601 | if (var->pixclock != 0 || in_dbg_master()) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 602 | return -EINVAL; |
| 603 | |
| 604 | /* Need to resize the fb object !!! */ |
Chris Wilson | 62fb376 | 2012-03-26 21:15:53 +0100 | [diff] [blame] | 605 | if (var->bits_per_pixel > fb->bits_per_pixel || |
| 606 | var->xres > fb->width || var->yres > fb->height || |
| 607 | var->xres_virtual > fb->width || var->yres_virtual > fb->height) { |
Dave Airlie | 509c7d8 | 2010-01-08 09:27:08 +1000 | [diff] [blame] | 608 | DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb " |
Chris Wilson | 62fb376 | 2012-03-26 21:15:53 +0100 | [diff] [blame] | 609 | "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n", |
| 610 | var->xres, var->yres, var->bits_per_pixel, |
| 611 | var->xres_virtual, var->yres_virtual, |
Dave Airlie | 509c7d8 | 2010-01-08 09:27:08 +1000 | [diff] [blame] | 612 | fb->width, fb->height, fb->bits_per_pixel); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 613 | return -EINVAL; |
| 614 | } |
| 615 | |
| 616 | switch (var->bits_per_pixel) { |
| 617 | case 16: |
| 618 | depth = (var->green.length == 6) ? 16 : 15; |
| 619 | break; |
| 620 | case 32: |
| 621 | depth = (var->transp.length > 0) ? 32 : 24; |
| 622 | break; |
| 623 | default: |
| 624 | depth = var->bits_per_pixel; |
| 625 | break; |
| 626 | } |
| 627 | |
| 628 | switch (depth) { |
| 629 | case 8: |
| 630 | var->red.offset = 0; |
| 631 | var->green.offset = 0; |
| 632 | var->blue.offset = 0; |
| 633 | var->red.length = 8; |
| 634 | var->green.length = 8; |
| 635 | var->blue.length = 8; |
| 636 | var->transp.length = 0; |
| 637 | var->transp.offset = 0; |
| 638 | break; |
| 639 | case 15: |
| 640 | var->red.offset = 10; |
| 641 | var->green.offset = 5; |
| 642 | var->blue.offset = 0; |
| 643 | var->red.length = 5; |
| 644 | var->green.length = 5; |
| 645 | var->blue.length = 5; |
| 646 | var->transp.length = 1; |
| 647 | var->transp.offset = 15; |
| 648 | break; |
| 649 | case 16: |
| 650 | var->red.offset = 11; |
| 651 | var->green.offset = 5; |
| 652 | var->blue.offset = 0; |
| 653 | var->red.length = 5; |
| 654 | var->green.length = 6; |
| 655 | var->blue.length = 5; |
| 656 | var->transp.length = 0; |
| 657 | var->transp.offset = 0; |
| 658 | break; |
| 659 | case 24: |
| 660 | var->red.offset = 16; |
| 661 | var->green.offset = 8; |
| 662 | var->blue.offset = 0; |
| 663 | var->red.length = 8; |
| 664 | var->green.length = 8; |
| 665 | var->blue.length = 8; |
| 666 | var->transp.length = 0; |
| 667 | var->transp.offset = 0; |
| 668 | break; |
| 669 | case 32: |
| 670 | var->red.offset = 16; |
| 671 | var->green.offset = 8; |
| 672 | var->blue.offset = 0; |
| 673 | var->red.length = 8; |
| 674 | var->green.length = 8; |
| 675 | var->blue.length = 8; |
| 676 | var->transp.length = 8; |
| 677 | var->transp.offset = 24; |
| 678 | break; |
| 679 | default: |
| 680 | return -EINVAL; |
| 681 | } |
| 682 | return 0; |
| 683 | } |
| 684 | EXPORT_SYMBOL(drm_fb_helper_check_var); |
| 685 | |
| 686 | /* this will let fbcon do the mode init */ |
| 687 | int drm_fb_helper_set_par(struct fb_info *info) |
| 688 | { |
| 689 | struct drm_fb_helper *fb_helper = info->par; |
| 690 | struct drm_device *dev = fb_helper->dev; |
| 691 | struct fb_var_screeninfo *var = &info->var; |
| 692 | struct drm_crtc *crtc; |
| 693 | int ret; |
| 694 | int i; |
| 695 | |
Clemens Ladisch | 5349ef3 | 2009-11-04 09:42:52 +0100 | [diff] [blame] | 696 | if (var->pixclock != 0) { |
Pavel Roskin | 172e91f | 2010-02-11 14:31:32 +1000 | [diff] [blame] | 697 | DRM_ERROR("PIXEL CLOCK SET\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 698 | return -EINVAL; |
| 699 | } |
| 700 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 701 | drm_modeset_lock_all(dev); |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 702 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 703 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 704 | ret = drm_mode_set_config_internal(&fb_helper->crtc_info[i].mode_set); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 705 | if (ret) { |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 706 | drm_modeset_unlock_all(dev); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 707 | return ret; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 708 | } |
| 709 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 710 | drm_modeset_unlock_all(dev); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 711 | |
| 712 | if (fb_helper->delayed_hotplug) { |
| 713 | fb_helper->delayed_hotplug = false; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 714 | drm_fb_helper_hotplug_event(fb_helper); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 715 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 716 | return 0; |
| 717 | } |
| 718 | EXPORT_SYMBOL(drm_fb_helper_set_par); |
| 719 | |
| 720 | int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, |
| 721 | struct fb_info *info) |
| 722 | { |
| 723 | struct drm_fb_helper *fb_helper = info->par; |
| 724 | struct drm_device *dev = fb_helper->dev; |
| 725 | struct drm_mode_set *modeset; |
| 726 | struct drm_crtc *crtc; |
| 727 | int ret = 0; |
| 728 | int i; |
| 729 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 730 | drm_modeset_lock_all(dev); |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 731 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 732 | drm_modeset_unlock_all(dev); |
| 733 | return -EBUSY; |
| 734 | } |
| 735 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 736 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 737 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 738 | |
| 739 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 740 | |
| 741 | modeset->x = var->xoffset; |
| 742 | modeset->y = var->yoffset; |
| 743 | |
| 744 | if (modeset->num_connectors) { |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 745 | ret = drm_mode_set_config_internal(modeset); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 746 | if (!ret) { |
| 747 | info->var.xoffset = var->xoffset; |
| 748 | info->var.yoffset = var->yoffset; |
| 749 | } |
| 750 | } |
| 751 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 752 | drm_modeset_unlock_all(dev); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 753 | return ret; |
| 754 | } |
| 755 | EXPORT_SYMBOL(drm_fb_helper_pan_display); |
| 756 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 757 | int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, |
| 758 | int preferred_bpp) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 759 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 760 | int new_fb = 0; |
| 761 | int crtc_count = 0; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 762 | int i; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 763 | struct fb_info *info; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 764 | struct drm_fb_helper_surface_size sizes; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 765 | int gamma_size = 0; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 766 | |
| 767 | memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); |
| 768 | sizes.surface_depth = 24; |
| 769 | sizes.surface_bpp = 32; |
| 770 | sizes.fb_width = (unsigned)-1; |
| 771 | sizes.fb_height = (unsigned)-1; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 772 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 773 | /* if driver picks 8 or 16 by default use that |
| 774 | for both depth/bpp */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 775 | if (preferred_bpp != sizes.surface_bpp) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 776 | sizes.surface_depth = sizes.surface_bpp = preferred_bpp; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 777 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 778 | /* 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] | 779 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 780 | struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i]; |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 781 | struct drm_cmdline_mode *cmdline_mode; |
Dave Airlie | 8ef8678 | 2009-09-26 06:39:00 +1000 | [diff] [blame] | 782 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 783 | cmdline_mode = &fb_helper_conn->cmdline_mode; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 784 | |
| 785 | if (cmdline_mode->bpp_specified) { |
| 786 | switch (cmdline_mode->bpp) { |
| 787 | case 8: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 788 | sizes.surface_depth = sizes.surface_bpp = 8; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 789 | break; |
| 790 | case 15: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 791 | sizes.surface_depth = 15; |
| 792 | sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 793 | break; |
| 794 | case 16: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 795 | sizes.surface_depth = sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 796 | break; |
| 797 | case 24: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 798 | sizes.surface_depth = sizes.surface_bpp = 24; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 799 | break; |
| 800 | case 32: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 801 | sizes.surface_depth = 24; |
| 802 | sizes.surface_bpp = 32; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 809 | crtc_count = 0; |
| 810 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 811 | struct drm_display_mode *desired_mode; |
| 812 | desired_mode = fb_helper->crtc_info[i].desired_mode; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 813 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 814 | if (desired_mode) { |
| 815 | if (gamma_size == 0) |
| 816 | gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size; |
| 817 | if (desired_mode->hdisplay < sizes.fb_width) |
| 818 | sizes.fb_width = desired_mode->hdisplay; |
| 819 | if (desired_mode->vdisplay < sizes.fb_height) |
| 820 | sizes.fb_height = desired_mode->vdisplay; |
| 821 | if (desired_mode->hdisplay > sizes.surface_width) |
| 822 | sizes.surface_width = desired_mode->hdisplay; |
| 823 | if (desired_mode->vdisplay > sizes.surface_height) |
| 824 | sizes.surface_height = desired_mode->vdisplay; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 825 | crtc_count++; |
| 826 | } |
| 827 | } |
| 828 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 829 | if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 830 | /* hmm everyone went away - assume VGA cable just fell out |
| 831 | and will come back later. */ |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 832 | DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n"); |
Dave Airlie | 19b4b44 | 2010-03-30 05:34:16 +0000 | [diff] [blame] | 833 | sizes.fb_width = sizes.surface_width = 1024; |
| 834 | sizes.fb_height = sizes.surface_height = 768; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 835 | } |
| 836 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 837 | /* push down into drivers */ |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 838 | new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 839 | if (new_fb < 0) |
| 840 | return new_fb; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 841 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 842 | info = fb_helper->fbdev; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 843 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 844 | /* set the fb pointer */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 845 | for (i = 0; i < fb_helper->crtc_count; i++) |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 846 | fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 847 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 848 | if (new_fb) { |
Clemens Ladisch | 5349ef3 | 2009-11-04 09:42:52 +0100 | [diff] [blame] | 849 | info->var.pixclock = 0; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 850 | if (register_framebuffer(info) < 0) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 851 | return -EINVAL; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 852 | |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 853 | dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n", |
| 854 | info->node, info->fix.id); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 855 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 856 | } else { |
| 857 | drm_fb_helper_set_par(info); |
| 858 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 859 | |
| 860 | /* Switch back to kernel console on panic */ |
| 861 | /* multi card linked list maybe */ |
| 862 | if (list_empty(&kernel_fb_helper_list)) { |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 863 | dev_info(fb_helper->dev->dev, "registered panic notifier\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 864 | atomic_notifier_chain_register(&panic_notifier_list, |
| 865 | &paniced); |
| 866 | register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 867 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 868 | if (new_fb) |
| 869 | list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list); |
| 870 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | EXPORT_SYMBOL(drm_fb_helper_single_fb_probe); |
| 874 | |
Dave Airlie | 3632ef8 | 2011-01-15 09:27:00 +1000 | [diff] [blame] | 875 | void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, |
| 876 | uint32_t depth) |
| 877 | { |
| 878 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 879 | info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR : |
| 880 | FB_VISUAL_TRUECOLOR; |
| 881 | info->fix.mmio_start = 0; |
| 882 | info->fix.mmio_len = 0; |
| 883 | info->fix.type_aux = 0; |
| 884 | info->fix.xpanstep = 1; /* doing it in hw */ |
| 885 | info->fix.ypanstep = 1; /* doing it in hw */ |
| 886 | info->fix.ywrapstep = 0; |
| 887 | info->fix.accel = FB_ACCEL_NONE; |
| 888 | info->fix.type_aux = 0; |
| 889 | |
| 890 | info->fix.line_length = pitch; |
| 891 | return; |
| 892 | } |
| 893 | EXPORT_SYMBOL(drm_fb_helper_fill_fix); |
| 894 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 895 | 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] | 896 | uint32_t fb_width, uint32_t fb_height) |
| 897 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 898 | struct drm_framebuffer *fb = fb_helper->fb; |
| 899 | info->pseudo_palette = fb_helper->pseudo_palette; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 900 | info->var.xres_virtual = fb->width; |
| 901 | info->var.yres_virtual = fb->height; |
| 902 | info->var.bits_per_pixel = fb->bits_per_pixel; |
James Simmons | 57084d0 | 2010-12-20 19:10:39 +0000 | [diff] [blame] | 903 | info->var.accel_flags = FB_ACCELF_TEXT; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 904 | info->var.xoffset = 0; |
| 905 | info->var.yoffset = 0; |
| 906 | info->var.activate = FB_ACTIVATE_NOW; |
| 907 | info->var.height = -1; |
| 908 | info->var.width = -1; |
| 909 | |
| 910 | switch (fb->depth) { |
| 911 | case 8: |
| 912 | info->var.red.offset = 0; |
| 913 | info->var.green.offset = 0; |
| 914 | info->var.blue.offset = 0; |
| 915 | info->var.red.length = 8; /* 8bit DAC */ |
| 916 | info->var.green.length = 8; |
| 917 | info->var.blue.length = 8; |
| 918 | info->var.transp.offset = 0; |
| 919 | info->var.transp.length = 0; |
| 920 | break; |
| 921 | case 15: |
| 922 | info->var.red.offset = 10; |
| 923 | info->var.green.offset = 5; |
| 924 | info->var.blue.offset = 0; |
| 925 | info->var.red.length = 5; |
| 926 | info->var.green.length = 5; |
| 927 | info->var.blue.length = 5; |
| 928 | info->var.transp.offset = 15; |
| 929 | info->var.transp.length = 1; |
| 930 | break; |
| 931 | case 16: |
| 932 | info->var.red.offset = 11; |
| 933 | info->var.green.offset = 5; |
| 934 | info->var.blue.offset = 0; |
| 935 | info->var.red.length = 5; |
| 936 | info->var.green.length = 6; |
| 937 | info->var.blue.length = 5; |
| 938 | info->var.transp.offset = 0; |
| 939 | break; |
| 940 | case 24: |
| 941 | info->var.red.offset = 16; |
| 942 | info->var.green.offset = 8; |
| 943 | info->var.blue.offset = 0; |
| 944 | info->var.red.length = 8; |
| 945 | info->var.green.length = 8; |
| 946 | info->var.blue.length = 8; |
| 947 | info->var.transp.offset = 0; |
| 948 | info->var.transp.length = 0; |
| 949 | break; |
| 950 | case 32: |
| 951 | info->var.red.offset = 16; |
| 952 | info->var.green.offset = 8; |
| 953 | info->var.blue.offset = 0; |
| 954 | info->var.red.length = 8; |
| 955 | info->var.green.length = 8; |
| 956 | info->var.blue.length = 8; |
| 957 | info->var.transp.offset = 24; |
| 958 | info->var.transp.length = 8; |
| 959 | break; |
| 960 | default: |
| 961 | break; |
| 962 | } |
| 963 | |
| 964 | info->var.xres = fb_width; |
| 965 | info->var.yres = fb_height; |
| 966 | } |
| 967 | EXPORT_SYMBOL(drm_fb_helper_fill_var); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 968 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 969 | static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper, |
| 970 | uint32_t maxX, |
| 971 | uint32_t maxY) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 972 | { |
| 973 | struct drm_connector *connector; |
| 974 | int count = 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 975 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 976 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 977 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 978 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 979 | count += connector->funcs->fill_modes(connector, maxX, maxY); |
| 980 | } |
| 981 | |
| 982 | return count; |
| 983 | } |
| 984 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 985 | 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] | 986 | { |
| 987 | struct drm_display_mode *mode; |
| 988 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 989 | list_for_each_entry(mode, &fb_connector->connector->modes, head) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 990 | if (drm_mode_width(mode) > width || |
| 991 | drm_mode_height(mode) > height) |
| 992 | continue; |
| 993 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 994 | return mode; |
| 995 | } |
| 996 | return NULL; |
| 997 | } |
| 998 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 999 | 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] | 1000 | { |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1001 | struct drm_cmdline_mode *cmdline_mode; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1002 | cmdline_mode = &fb_connector->cmdline_mode; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1003 | return cmdline_mode->specified; |
| 1004 | } |
| 1005 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1006 | static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn, |
| 1007 | int width, int height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1008 | { |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1009 | struct drm_cmdline_mode *cmdline_mode; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1010 | struct drm_display_mode *mode = NULL; |
| 1011 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1012 | cmdline_mode = &fb_helper_conn->cmdline_mode; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1013 | if (cmdline_mode->specified == false) |
| 1014 | return mode; |
| 1015 | |
| 1016 | /* attempt to find a matching mode in the list of modes |
| 1017 | * we have gotten so far, if not add a CVT mode that conforms |
| 1018 | */ |
| 1019 | if (cmdline_mode->rb || cmdline_mode->margins) |
| 1020 | goto create_mode; |
| 1021 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1022 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1023 | /* check width/height */ |
| 1024 | if (mode->hdisplay != cmdline_mode->xres || |
| 1025 | mode->vdisplay != cmdline_mode->yres) |
| 1026 | continue; |
| 1027 | |
| 1028 | if (cmdline_mode->refresh_specified) { |
| 1029 | if (mode->vrefresh != cmdline_mode->refresh) |
| 1030 | continue; |
| 1031 | } |
| 1032 | |
| 1033 | if (cmdline_mode->interlace) { |
| 1034 | if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) |
| 1035 | continue; |
| 1036 | } |
| 1037 | return mode; |
| 1038 | } |
| 1039 | |
| 1040 | create_mode: |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1041 | mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev, |
| 1042 | cmdline_mode); |
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 | |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1051 | if (strict) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1052 | enable = connector->status == connector_status_connected; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1053 | else |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1054 | enable = connector->status != connector_status_disconnected; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1055 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 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 | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1083 | static bool drm_target_cloned(struct drm_fb_helper *fb_helper, |
| 1084 | struct drm_display_mode **modes, |
| 1085 | bool *enabled, int width, int height) |
| 1086 | { |
| 1087 | int count, i, j; |
| 1088 | bool can_clone = false; |
| 1089 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1090 | struct drm_display_mode *dmt_mode, *mode; |
| 1091 | |
| 1092 | /* only contemplate cloning in the single crtc case */ |
| 1093 | if (fb_helper->crtc_count > 1) |
| 1094 | return false; |
| 1095 | |
| 1096 | count = 0; |
| 1097 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1098 | if (enabled[i]) |
| 1099 | count++; |
| 1100 | } |
| 1101 | |
| 1102 | /* only contemplate cloning if more than one connector is enabled */ |
| 1103 | if (count <= 1) |
| 1104 | return false; |
| 1105 | |
| 1106 | /* check the command line or if nothing common pick 1024x768 */ |
| 1107 | can_clone = true; |
| 1108 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1109 | if (!enabled[i]) |
| 1110 | continue; |
| 1111 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1112 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); |
| 1113 | if (!modes[i]) { |
| 1114 | can_clone = false; |
| 1115 | break; |
| 1116 | } |
| 1117 | for (j = 0; j < i; j++) { |
| 1118 | if (!enabled[j]) |
| 1119 | continue; |
| 1120 | if (!drm_mode_equal(modes[j], modes[i])) |
| 1121 | can_clone = false; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | if (can_clone) { |
| 1126 | DRM_DEBUG_KMS("can clone using command line\n"); |
| 1127 | return true; |
| 1128 | } |
| 1129 | |
| 1130 | /* try and find a 1024x768 mode on each connector */ |
| 1131 | can_clone = true; |
Adam Jackson | f6e252b | 2012-04-13 16:33:31 -0400 | [diff] [blame] | 1132 | dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false); |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1133 | |
| 1134 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1135 | |
| 1136 | if (!enabled[i]) |
| 1137 | continue; |
| 1138 | |
| 1139 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1140 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
| 1141 | if (drm_mode_equal(mode, dmt_mode)) |
| 1142 | modes[i] = mode; |
| 1143 | } |
| 1144 | if (!modes[i]) |
| 1145 | can_clone = false; |
| 1146 | } |
| 1147 | |
| 1148 | if (can_clone) { |
| 1149 | DRM_DEBUG_KMS("can clone using 1024x768\n"); |
| 1150 | return true; |
| 1151 | } |
| 1152 | DRM_INFO("kms: can't enable cloning when we probably wanted to.\n"); |
| 1153 | return false; |
| 1154 | } |
| 1155 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1156 | static bool drm_target_preferred(struct drm_fb_helper *fb_helper, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1157 | struct drm_display_mode **modes, |
| 1158 | bool *enabled, int width, int height) |
| 1159 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1160 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1161 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1162 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1163 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1164 | fb_helper_conn = fb_helper->connector_info[i]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1165 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1166 | if (enabled[i] == false) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1167 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1168 | |
| 1169 | DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n", |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1170 | fb_helper_conn->connector->base.id); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1171 | |
| 1172 | /* got for command line mode first */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1173 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1174 | if (!modes[i]) { |
| 1175 | DRM_DEBUG_KMS("looking for preferred mode on connector %d\n", |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1176 | fb_helper_conn->connector->base.id); |
| 1177 | modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1178 | } |
| 1179 | /* No preferred modes, pick one off the list */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1180 | if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) { |
| 1181 | list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1182 | break; |
| 1183 | } |
| 1184 | DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name : |
| 1185 | "none"); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1186 | } |
| 1187 | return true; |
| 1188 | } |
| 1189 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1190 | static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, |
| 1191 | struct drm_fb_helper_crtc **best_crtcs, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1192 | struct drm_display_mode **modes, |
| 1193 | int n, int width, int height) |
| 1194 | { |
| 1195 | int c, o; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1196 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1197 | struct drm_connector *connector; |
| 1198 | struct drm_connector_helper_funcs *connector_funcs; |
| 1199 | struct drm_encoder *encoder; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1200 | struct drm_fb_helper_crtc *best_crtc; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1201 | int my_score, best_score, score; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1202 | struct drm_fb_helper_crtc **crtcs, *crtc; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1203 | struct drm_fb_helper_connector *fb_helper_conn; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1204 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1205 | if (n == fb_helper->connector_count) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1206 | return 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1207 | |
| 1208 | fb_helper_conn = fb_helper->connector_info[n]; |
| 1209 | connector = fb_helper_conn->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1210 | |
| 1211 | best_crtcs[n] = NULL; |
| 1212 | best_crtc = NULL; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1213 | 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] | 1214 | if (modes[n] == NULL) |
| 1215 | return best_score; |
| 1216 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1217 | crtcs = kzalloc(dev->mode_config.num_connector * |
| 1218 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1219 | if (!crtcs) |
| 1220 | return best_score; |
| 1221 | |
| 1222 | my_score = 1; |
| 1223 | if (connector->status == connector_status_connected) |
| 1224 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1225 | if (drm_has_cmdline_mode(fb_helper_conn)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1226 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1227 | if (drm_has_preferred_mode(fb_helper_conn, width, height)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1228 | my_score++; |
| 1229 | |
| 1230 | connector_funcs = connector->helper_private; |
| 1231 | encoder = connector_funcs->best_encoder(connector); |
| 1232 | if (!encoder) |
| 1233 | goto out; |
| 1234 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1235 | /* select a crtc for this connector and then attempt to configure |
| 1236 | remaining connectors */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1237 | for (c = 0; c < fb_helper->crtc_count; c++) { |
| 1238 | crtc = &fb_helper->crtc_info[c]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1239 | |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1240 | if ((encoder->possible_crtcs & (1 << c)) == 0) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1241 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1242 | |
| 1243 | for (o = 0; o < n; o++) |
| 1244 | if (best_crtcs[o] == crtc) |
| 1245 | break; |
| 1246 | |
| 1247 | if (o < n) { |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1248 | /* ignore cloning unless only a single crtc */ |
| 1249 | if (fb_helper->crtc_count > 1) |
| 1250 | continue; |
| 1251 | |
| 1252 | if (!drm_mode_equal(modes[o], modes[n])) |
| 1253 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | crtcs[n] = crtc; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1257 | memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *)); |
| 1258 | score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1259 | width, height); |
| 1260 | if (score > best_score) { |
| 1261 | best_crtc = crtc; |
| 1262 | best_score = score; |
| 1263 | memcpy(best_crtcs, crtcs, |
| 1264 | dev->mode_config.num_connector * |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1265 | sizeof(struct drm_fb_helper_crtc *)); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1266 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1267 | } |
| 1268 | out: |
| 1269 | kfree(crtcs); |
| 1270 | return best_score; |
| 1271 | } |
| 1272 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1273 | static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1274 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1275 | struct drm_device *dev = fb_helper->dev; |
| 1276 | struct drm_fb_helper_crtc **crtcs; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1277 | struct drm_display_mode **modes; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1278 | struct drm_mode_set *modeset; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1279 | bool *enabled; |
| 1280 | int width, height; |
| 1281 | int i, ret; |
| 1282 | |
| 1283 | DRM_DEBUG_KMS("\n"); |
| 1284 | |
| 1285 | width = dev->mode_config.max_width; |
| 1286 | height = dev->mode_config.max_height; |
| 1287 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1288 | crtcs = kcalloc(dev->mode_config.num_connector, |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1289 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1290 | modes = kcalloc(dev->mode_config.num_connector, |
| 1291 | sizeof(struct drm_display_mode *), GFP_KERNEL); |
| 1292 | enabled = kcalloc(dev->mode_config.num_connector, |
| 1293 | sizeof(bool), GFP_KERNEL); |
Sachin Kamat | 8c5eaca | 2012-11-19 09:44:58 +0000 | [diff] [blame] | 1294 | if (!crtcs || !modes || !enabled) { |
| 1295 | DRM_ERROR("Memory allocation failed\n"); |
| 1296 | goto out; |
| 1297 | } |
| 1298 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1299 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1300 | drm_enable_connectors(fb_helper, enabled); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1301 | |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1302 | ret = drm_target_cloned(fb_helper, modes, enabled, width, height); |
| 1303 | if (!ret) { |
| 1304 | ret = drm_target_preferred(fb_helper, modes, enabled, width, height); |
| 1305 | if (!ret) |
| 1306 | DRM_ERROR("Unable to find initial modes\n"); |
| 1307 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1308 | |
| 1309 | DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height); |
| 1310 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1311 | drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height); |
| 1312 | |
| 1313 | /* need to set the modesets up here for use later */ |
| 1314 | /* fill out the connector<->crtc mappings into the modesets */ |
| 1315 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 1316 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 1317 | modeset->num_connectors = 0; |
| 1318 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1319 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1320 | for (i = 0; i < fb_helper->connector_count; i++) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1321 | struct drm_display_mode *mode = modes[i]; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1322 | struct drm_fb_helper_crtc *fb_crtc = crtcs[i]; |
| 1323 | modeset = &fb_crtc->mode_set; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1324 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1325 | if (mode && fb_crtc) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1326 | DRM_DEBUG_KMS("desired mode %s set on crtc %d\n", |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1327 | mode->name, fb_crtc->mode_set.crtc->base.id); |
| 1328 | fb_crtc->desired_mode = mode; |
| 1329 | if (modeset->mode) |
| 1330 | drm_mode_destroy(dev, modeset->mode); |
| 1331 | modeset->mode = drm_mode_duplicate(dev, |
| 1332 | fb_crtc->desired_mode); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1333 | modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1334 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Sachin Kamat | 8c5eaca | 2012-11-19 09:44:58 +0000 | [diff] [blame] | 1337 | out: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1338 | kfree(crtcs); |
| 1339 | kfree(modes); |
| 1340 | kfree(enabled); |
| 1341 | } |
| 1342 | |
| 1343 | /** |
| 1344 | * drm_helper_initial_config - setup a sane initial connector configuration |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 1345 | * @fb_helper: fb_helper device struct |
| 1346 | * @bpp_sel: bpp value to use for the framebuffer configuration |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1347 | * |
| 1348 | * LOCKING: |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 1349 | * Called at init time by the driver to set up the @fb_helper initial |
| 1350 | * configuration, must take the mode config lock. |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1351 | * |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 1352 | * Scans the CRTCs and connectors and tries to put together an initial setup. |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1353 | * At the moment, this is a cloned configuration across all heads with |
| 1354 | * a new framebuffer object as the backing store. |
| 1355 | * |
| 1356 | * RETURNS: |
| 1357 | * Zero if everything went ok, nonzero otherwise. |
| 1358 | */ |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1359 | 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] | 1360 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1361 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1362 | int count = 0; |
| 1363 | |
| 1364 | /* disable all the possible outputs/crtcs before entering KMS mode */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1365 | drm_helper_disable_unused_functions(fb_helper->dev); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1366 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1367 | drm_fb_helper_parse_command_line(fb_helper); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1368 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1369 | count = drm_fb_helper_probe_connector_modes(fb_helper, |
| 1370 | dev->mode_config.max_width, |
| 1371 | dev->mode_config.max_height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1372 | /* |
| 1373 | * we shouldn't end up with no modes here. |
| 1374 | */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1375 | if (count == 0) |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 1376 | dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n"); |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1377 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1378 | drm_setup_crtcs(fb_helper); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1379 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1380 | return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1381 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1382 | EXPORT_SYMBOL(drm_fb_helper_initial_config); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1383 | |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1384 | /** |
| 1385 | * drm_fb_helper_hotplug_event - respond to a hotplug notification by |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 1386 | * probing all the outputs attached to the fb |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1387 | * @fb_helper: the drm_fb_helper |
| 1388 | * |
| 1389 | * LOCKING: |
| 1390 | * Called at runtime, must take mode config lock. |
| 1391 | * |
| 1392 | * Scan the connectors attached to the fb_helper and try to put together a |
| 1393 | * setup after *notification of a change in output configuration. |
| 1394 | * |
| 1395 | * RETURNS: |
| 1396 | * 0 on success and a non-zero error code otherwise. |
| 1397 | */ |
| 1398 | int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1399 | { |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1400 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1401 | int count = 0; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1402 | u32 max_width, max_height, bpp_sel; |
| 1403 | |
| 1404 | if (!fb_helper->fb) |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1405 | return 0; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1406 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1407 | drm_modeset_lock_all(dev); |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 1408 | if (!drm_fb_helper_is_bound(fb_helper)) { |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1409 | fb_helper->delayed_hotplug = true; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1410 | drm_modeset_unlock_all(dev); |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1411 | return 0; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1412 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1413 | DRM_DEBUG_KMS("\n"); |
| 1414 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1415 | max_width = fb_helper->fb->width; |
| 1416 | max_height = fb_helper->fb->height; |
| 1417 | bpp_sel = fb_helper->fb->bits_per_pixel; |
| 1418 | |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1419 | count = drm_fb_helper_probe_connector_modes(fb_helper, max_width, |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1420 | max_height); |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1421 | drm_setup_crtcs(fb_helper); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1422 | drm_modeset_unlock_all(dev); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1423 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1424 | return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1425 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1426 | EXPORT_SYMBOL(drm_fb_helper_hotplug_event); |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 1427 | |
David Rientjes | 6a108a1 | 2011-01-20 14:44:16 -0800 | [diff] [blame] | 1428 | /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT) |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 1429 | * but the module doesn't depend on any fb console symbols. At least |
| 1430 | * attempt to load fbcon to avoid leaving the system without a usable console. |
| 1431 | */ |
David Rientjes | 6a108a1 | 2011-01-20 14:44:16 -0800 | [diff] [blame] | 1432 | #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT) |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 1433 | static int __init drm_fb_helper_modinit(void) |
| 1434 | { |
| 1435 | const char *name = "fbcon"; |
| 1436 | struct module *fbcon; |
| 1437 | |
| 1438 | mutex_lock(&module_mutex); |
| 1439 | fbcon = find_module(name); |
| 1440 | mutex_unlock(&module_mutex); |
| 1441 | |
| 1442 | if (!fbcon) |
| 1443 | request_module_nowait(name); |
| 1444 | return 0; |
| 1445 | } |
| 1446 | |
| 1447 | module_init(drm_fb_helper_modinit); |
| 1448 | #endif |