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