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