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