blob: cef8d8da5952b294827bb7dc9e6b36abecbb2e3b [file] [log] [blame]
Dave Airlie785b93e2009-08-28 15:46:53 +10001/*
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 Shevchenko3b40a442010-02-02 14:40:32 -080030#include <linux/kernel.h>
Dave Airlie785b93e2009-08-28 15:46:53 +100031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Dave Airlie785b93e2009-08-28 15:46:53 +100033#include <linux/fb.h>
34#include "drmP.h"
35#include "drm_crtc.h"
36#include "drm_fb_helper.h"
37#include "drm_crtc_helper.h"
38
Dave Airlie6fcefd52009-09-08 11:08:32 +100039MODULE_AUTHOR("David Airlie, Jesse Barnes");
40MODULE_DESCRIPTION("DRM KMS helper");
41MODULE_LICENSE("GPL and additional rights");
42
Dave Airlie785b93e2009-08-28 15:46:53 +100043static LIST_HEAD(kernel_fb_helper_list);
44
Dave Airlie0b4c0f32010-03-30 05:34:15 +000045/* simple single crtc case helper function */
46int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
Dave Airlied50ba252009-09-23 14:44:08 +100047{
Dave Airlie0b4c0f32010-03-30 05:34:15 +000048 struct drm_device *dev = fb_helper->dev;
49 struct drm_connector *connector;
50 int i;
Dave Airlied50ba252009-09-23 14:44:08 +100051
Dave Airlie0b4c0f32010-03-30 05:34:15 +000052 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
53 struct drm_fb_helper_connector *fb_helper_connector;
54
55 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
56 if (!fb_helper_connector)
57 goto fail;
58
59 fb_helper_connector->connector = connector;
60 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
61 }
Dave Airlied50ba252009-09-23 14:44:08 +100062 return 0;
Dave Airlie0b4c0f32010-03-30 05:34:15 +000063fail:
64 for (i = 0; i < fb_helper->connector_count; i++) {
65 kfree(fb_helper->connector_info[i]);
66 fb_helper->connector_info[i] = NULL;
67 }
68 fb_helper->connector_count = 0;
69 return -ENOMEM;
Dave Airlied50ba252009-09-23 14:44:08 +100070}
Dave Airlie0b4c0f32010-03-30 05:34:15 +000071EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
Dave Airlied50ba252009-09-23 14:44:08 +100072
Dave Airlied50ba252009-09-23 14:44:08 +100073/**
74 * drm_fb_helper_connector_parse_command_line - parse command line for connector
75 * @connector - connector to parse line for
76 * @mode_option - per connector mode option
77 *
78 * This parses the connector specific then generic command lines for
79 * modes and options to configure the connector.
80 *
81 * This uses the same parameters as the fb modedb.c, except for extra
82 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
83 *
84 * enable/enable Digital/disable bit at the end
85 */
Dave Airlie0b4c0f32010-03-30 05:34:15 +000086static bool drm_fb_helper_connector_parse_command_line(struct drm_fb_helper_connector *fb_helper_conn,
Dave Airlied50ba252009-09-23 14:44:08 +100087 const char *mode_option)
88{
89 const char *name;
90 unsigned int namelen;
91 int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
92 unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0;
93 int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
94 int i;
95 enum drm_connector_force force = DRM_FORCE_UNSPECIFIED;
Dave Airlie8ef86782009-09-26 06:39:00 +100096 struct drm_fb_helper_cmdline_mode *cmdline_mode;
Dan Carpenter09f0c482010-08-19 11:46:29 +020097 struct drm_connector *connector;
Dave Airlied50ba252009-09-23 14:44:08 +100098
Dave Airlie0b4c0f32010-03-30 05:34:15 +000099 if (!fb_helper_conn)
Dave Airlie8ef86782009-09-26 06:39:00 +1000100 return false;
Dan Carpenter09f0c482010-08-19 11:46:29 +0200101 connector = fb_helper_conn->connector;
Dave Airlie8ef86782009-09-26 06:39:00 +1000102
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000103 cmdline_mode = &fb_helper_conn->cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +1000104 if (!mode_option)
105 mode_option = fb_mode_option;
106
107 if (!mode_option) {
108 cmdline_mode->specified = false;
109 return false;
110 }
111
112 name = mode_option;
113 namelen = strlen(name);
114 for (i = namelen-1; i >= 0; i--) {
115 switch (name[i]) {
116 case '@':
117 namelen = i;
118 if (!refresh_specified && !bpp_specified &&
119 !yres_specified) {
Andy Shevchenko3b40a442010-02-02 14:40:32 -0800120 refresh = simple_strtol(&name[i+1], NULL, 10);
Dave Airlied50ba252009-09-23 14:44:08 +1000121 refresh_specified = 1;
122 if (cvt || rb)
123 cvt = 0;
124 } else
125 goto done;
126 break;
127 case '-':
128 namelen = i;
129 if (!bpp_specified && !yres_specified) {
Andy Shevchenko3b40a442010-02-02 14:40:32 -0800130 bpp = simple_strtol(&name[i+1], NULL, 10);
Dave Airlied50ba252009-09-23 14:44:08 +1000131 bpp_specified = 1;
132 if (cvt || rb)
133 cvt = 0;
134 } else
135 goto done;
136 break;
137 case 'x':
138 if (!yres_specified) {
Andy Shevchenko3b40a442010-02-02 14:40:32 -0800139 yres = simple_strtol(&name[i+1], NULL, 10);
Dave Airlied50ba252009-09-23 14:44:08 +1000140 yres_specified = 1;
141 } else
142 goto done;
143 case '0' ... '9':
144 break;
145 case 'M':
146 if (!yres_specified)
147 cvt = 1;
148 break;
149 case 'R':
Adam Jacksonb829e012010-06-10 13:33:26 -0400150 if (cvt)
Dave Airlied50ba252009-09-23 14:44:08 +1000151 rb = 1;
152 break;
153 case 'm':
154 if (!cvt)
155 margins = 1;
156 break;
157 case 'i':
158 if (!cvt)
159 interlace = 1;
160 break;
161 case 'e':
162 force = DRM_FORCE_ON;
163 break;
164 case 'D':
Roel Kluine89a8c92009-12-31 13:06:29 +0100165 if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) &&
Dave Airlied50ba252009-09-23 14:44:08 +1000166 (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB))
167 force = DRM_FORCE_ON;
168 else
169 force = DRM_FORCE_ON_DIGITAL;
170 break;
171 case 'd':
172 force = DRM_FORCE_OFF;
173 break;
174 default:
175 goto done;
176 }
177 }
178 if (i < 0 && yres_specified) {
Andy Shevchenko3b40a442010-02-02 14:40:32 -0800179 xres = simple_strtol(name, NULL, 10);
Dave Airlied50ba252009-09-23 14:44:08 +1000180 res_specified = 1;
181 }
182done:
183
184 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
185 drm_get_connector_name(connector), xres, yres,
186 (refresh) ? refresh : 60, (rb) ? " reduced blanking" :
187 "", (margins) ? " with margins" : "", (interlace) ?
188 " interlaced" : "");
189
190 if (force) {
191 const char *s;
192 switch (force) {
193 case DRM_FORCE_OFF: s = "OFF"; break;
194 case DRM_FORCE_ON_DIGITAL: s = "ON - dig"; break;
195 default:
196 case DRM_FORCE_ON: s = "ON"; break;
197 }
198
199 DRM_INFO("forcing %s connector %s\n",
200 drm_get_connector_name(connector), s);
201 connector->force = force;
202 }
203
204 if (res_specified) {
205 cmdline_mode->specified = true;
206 cmdline_mode->xres = xres;
207 cmdline_mode->yres = yres;
208 }
209
210 if (refresh_specified) {
211 cmdline_mode->refresh_specified = true;
212 cmdline_mode->refresh = refresh;
213 }
214
215 if (bpp_specified) {
216 cmdline_mode->bpp_specified = true;
217 cmdline_mode->bpp = bpp;
218 }
219 cmdline_mode->rb = rb ? true : false;
220 cmdline_mode->cvt = cvt ? true : false;
221 cmdline_mode->interlace = interlace ? true : false;
222
223 return true;
224}
225
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000226static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
Dave Airlied50ba252009-09-23 14:44:08 +1000227{
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000228 struct drm_fb_helper_connector *fb_helper_conn;
229 int i;
Dave Airlied50ba252009-09-23 14:44:08 +1000230
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000231 for (i = 0; i < fb_helper->connector_count; i++) {
Dave Airlied50ba252009-09-23 14:44:08 +1000232 char *option = NULL;
233
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000234 fb_helper_conn = fb_helper->connector_info[i];
235
Dave Airlied50ba252009-09-23 14:44:08 +1000236 /* do something on return - turn off connector maybe */
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000237 if (fb_get_options(drm_get_connector_name(fb_helper_conn->connector), &option))
Dave Airlied50ba252009-09-23 14:44:08 +1000238 continue;
239
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000240 drm_fb_helper_connector_parse_command_line(fb_helper_conn, option);
Dave Airlied50ba252009-09-23 14:44:08 +1000241 }
242 return 0;
243}
244
Dave Airlie785b93e2009-08-28 15:46:53 +1000245bool drm_fb_helper_force_kernel_mode(void)
246{
247 int i = 0;
248 bool ret, error = false;
249 struct drm_fb_helper *helper;
250
251 if (list_empty(&kernel_fb_helper_list))
252 return false;
253
254 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
255 for (i = 0; i < helper->crtc_count; i++) {
256 struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
257 ret = drm_crtc_helper_set_config(mode_set);
258 if (ret)
259 error = true;
260 }
261 }
262 return error;
263}
264
265int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
266 void *panic_str)
267{
Dave Airliefc2362a2010-06-07 12:14:54 +1000268 printk(KERN_ERR "panic occurred, switching back to text console\n");
Dave Airlie785b93e2009-08-28 15:46:53 +1000269 return drm_fb_helper_force_kernel_mode();
270 return 0;
271}
272EXPORT_SYMBOL(drm_fb_helper_panic);
273
274static struct notifier_block paniced = {
275 .notifier_call = drm_fb_helper_panic,
276};
277
278/**
279 * drm_fb_helper_restore - restore the framebuffer console (kernel) config
280 *
281 * Restore's the kernel's fbcon mode, used for lastclose & panic paths.
282 */
283void drm_fb_helper_restore(void)
284{
285 bool ret;
286 ret = drm_fb_helper_force_kernel_mode();
287 if (ret == true)
288 DRM_ERROR("Failed to restore crtc configuration\n");
289}
290EXPORT_SYMBOL(drm_fb_helper_restore);
291
Mikael Petterssonbea1d352009-09-28 18:26:25 +0200292#ifdef CONFIG_MAGIC_SYSRQ
Dave Airlie785b93e2009-08-28 15:46:53 +1000293static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
294{
295 drm_fb_helper_restore();
296}
297static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
298
299static void drm_fb_helper_sysrq(int dummy1, struct tty_struct *dummy3)
300{
301 schedule_work(&drm_fb_helper_restore_work);
302}
303
304static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
305 .handler = drm_fb_helper_sysrq,
306 .help_msg = "force-fb(V)",
307 .action_msg = "Restore framebuffer console",
308};
Randy Dunlapb8c40d62010-03-25 18:29:05 +0000309#else
310static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
Mikael Petterssonbea1d352009-09-28 18:26:25 +0200311#endif
Dave Airlie785b93e2009-08-28 15:46:53 +1000312
313static void drm_fb_helper_on(struct fb_info *info)
314{
315 struct drm_fb_helper *fb_helper = info->par;
316 struct drm_device *dev = fb_helper->dev;
317 struct drm_crtc *crtc;
Dave Airlie8be48d92010-03-30 05:34:14 +0000318 struct drm_crtc_helper_funcs *crtc_funcs;
Jesse Barnes023eb572010-07-02 10:48:08 -0700319 struct drm_connector *connector;
Dave Airlie785b93e2009-08-28 15:46:53 +1000320 struct drm_encoder *encoder;
Jesse Barnes023eb572010-07-02 10:48:08 -0700321 int i, j;
Dave Airlie785b93e2009-08-28 15:46:53 +1000322
323 /*
324 * For each CRTC in this fb, turn the crtc on then,
325 * find all associated encoders and turn them on.
326 */
Dave Airlie8be48d92010-03-30 05:34:14 +0000327 mutex_lock(&dev->mode_config.mutex);
Jesse Barnese87b2c42009-09-17 18:14:41 -0700328 for (i = 0; i < fb_helper->crtc_count; i++) {
Dave Airlie8be48d92010-03-30 05:34:14 +0000329 crtc = fb_helper->crtc_info[i].mode_set.crtc;
330 crtc_funcs = crtc->helper_private;
Dave Airlie785b93e2009-08-28 15:46:53 +1000331
Dave Airlie8be48d92010-03-30 05:34:14 +0000332 if (!crtc->enabled)
333 continue;
Dave Airlie785b93e2009-08-28 15:46:53 +1000334
Dave Airlie8be48d92010-03-30 05:34:14 +0000335 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
Dave Airlie785b93e2009-08-28 15:46:53 +1000336
Jesse Barnes023eb572010-07-02 10:48:08 -0700337 /* Walk the connectors & encoders on this fb turning them on */
338 for (j = 0; j < fb_helper->connector_count; j++) {
339 connector = fb_helper->connector_info[j]->connector;
340 connector->dpms = DRM_MODE_DPMS_ON;
341 drm_connector_property_set_value(connector,
342 dev->mode_config.dpms_property,
343 DRM_MODE_DPMS_ON);
344 }
Dave Airlie8be48d92010-03-30 05:34:14 +0000345 /* Found a CRTC on this fb, now find encoders */
346 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
347 if (encoder->crtc == crtc) {
348 struct drm_encoder_helper_funcs *encoder_funcs;
349
350 encoder_funcs = encoder->helper_private;
351 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
Dave Airlie785b93e2009-08-28 15:46:53 +1000352 }
353 }
354 }
Dave Airlie8be48d92010-03-30 05:34:14 +0000355 mutex_unlock(&dev->mode_config.mutex);
Dave Airlie785b93e2009-08-28 15:46:53 +1000356}
357
358static void drm_fb_helper_off(struct fb_info *info, int dpms_mode)
359{
360 struct drm_fb_helper *fb_helper = info->par;
361 struct drm_device *dev = fb_helper->dev;
362 struct drm_crtc *crtc;
Dave Airlie8be48d92010-03-30 05:34:14 +0000363 struct drm_crtc_helper_funcs *crtc_funcs;
Jesse Barnes023eb572010-07-02 10:48:08 -0700364 struct drm_connector *connector;
Dave Airlie785b93e2009-08-28 15:46:53 +1000365 struct drm_encoder *encoder;
Jesse Barnes023eb572010-07-02 10:48:08 -0700366 int i, j;
Dave Airlie785b93e2009-08-28 15:46:53 +1000367
368 /*
369 * For each CRTC in this fb, find all associated encoders
370 * and turn them off, then turn off the CRTC.
371 */
Dave Airlie8be48d92010-03-30 05:34:14 +0000372 mutex_lock(&dev->mode_config.mutex);
Jesse Barnese87b2c42009-09-17 18:14:41 -0700373 for (i = 0; i < fb_helper->crtc_count; i++) {
Dave Airlie8be48d92010-03-30 05:34:14 +0000374 crtc = fb_helper->crtc_info[i].mode_set.crtc;
375 crtc_funcs = crtc->helper_private;
Dave Airlie785b93e2009-08-28 15:46:53 +1000376
Dave Airlie8be48d92010-03-30 05:34:14 +0000377 if (!crtc->enabled)
378 continue;
Dave Airlie785b93e2009-08-28 15:46:53 +1000379
Jesse Barnes023eb572010-07-02 10:48:08 -0700380 /* Walk the connectors on this fb and mark them off */
381 for (j = 0; j < fb_helper->connector_count; j++) {
382 connector = fb_helper->connector_info[j]->connector;
383 connector->dpms = dpms_mode;
384 drm_connector_property_set_value(connector,
385 dev->mode_config.dpms_property,
386 dpms_mode);
387 }
Dave Airlie8be48d92010-03-30 05:34:14 +0000388 /* Found a CRTC on this fb, now find encoders */
389 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
390 if (encoder->crtc == crtc) {
391 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie785b93e2009-08-28 15:46:53 +1000392
Dave Airlie8be48d92010-03-30 05:34:14 +0000393 encoder_funcs = encoder->helper_private;
394 encoder_funcs->dpms(encoder, dpms_mode);
Jesse Barnese87b2c42009-09-17 18:14:41 -0700395 }
Dave Airlie785b93e2009-08-28 15:46:53 +1000396 }
Dave Airlie8be48d92010-03-30 05:34:14 +0000397 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
Dave Airlie785b93e2009-08-28 15:46:53 +1000398 }
Dave Airlie8be48d92010-03-30 05:34:14 +0000399 mutex_unlock(&dev->mode_config.mutex);
Dave Airlie785b93e2009-08-28 15:46:53 +1000400}
401
402int drm_fb_helper_blank(int blank, struct fb_info *info)
403{
404 switch (blank) {
James Simmons731b5a12009-10-29 20:39:07 +0000405 /* Display: On; HSync: On, VSync: On */
Dave Airlie785b93e2009-08-28 15:46:53 +1000406 case FB_BLANK_UNBLANK:
407 drm_fb_helper_on(info);
408 break;
James Simmons731b5a12009-10-29 20:39:07 +0000409 /* Display: Off; HSync: On, VSync: On */
Dave Airlie785b93e2009-08-28 15:46:53 +1000410 case FB_BLANK_NORMAL:
Zhenyu Wang5fd4df42010-01-18 16:47:04 +0800411 drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY);
Dave Airlie785b93e2009-08-28 15:46:53 +1000412 break;
James Simmons731b5a12009-10-29 20:39:07 +0000413 /* Display: Off; HSync: Off, VSync: On */
Dave Airlie785b93e2009-08-28 15:46:53 +1000414 case FB_BLANK_HSYNC_SUSPEND:
415 drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY);
416 break;
James Simmons731b5a12009-10-29 20:39:07 +0000417 /* Display: Off; HSync: On, VSync: Off */
Dave Airlie785b93e2009-08-28 15:46:53 +1000418 case FB_BLANK_VSYNC_SUSPEND:
419 drm_fb_helper_off(info, DRM_MODE_DPMS_SUSPEND);
420 break;
James Simmons731b5a12009-10-29 20:39:07 +0000421 /* Display: Off; HSync: Off, VSync: Off */
Dave Airlie785b93e2009-08-28 15:46:53 +1000422 case FB_BLANK_POWERDOWN:
423 drm_fb_helper_off(info, DRM_MODE_DPMS_OFF);
424 break;
425 }
426 return 0;
427}
428EXPORT_SYMBOL(drm_fb_helper_blank);
429
430static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
431{
432 int i;
433
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000434 for (i = 0; i < helper->connector_count; i++)
435 kfree(helper->connector_info[i]);
436 kfree(helper->connector_info);
Dave Airlie785b93e2009-08-28 15:46:53 +1000437 for (i = 0; i < helper->crtc_count; i++)
438 kfree(helper->crtc_info[i].mode_set.connectors);
439 kfree(helper->crtc_info);
440}
441
Dave Airlie4abe3522010-03-30 05:34:18 +0000442int drm_fb_helper_init(struct drm_device *dev,
443 struct drm_fb_helper *fb_helper,
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000444 int crtc_count, int max_conn_count)
Dave Airlie785b93e2009-08-28 15:46:53 +1000445{
Dave Airlie785b93e2009-08-28 15:46:53 +1000446 struct drm_crtc *crtc;
447 int ret = 0;
448 int i;
449
Dave Airlie4abe3522010-03-30 05:34:18 +0000450 fb_helper->dev = dev;
Dave Airlie4abe3522010-03-30 05:34:18 +0000451
452 INIT_LIST_HEAD(&fb_helper->kernel_fb_list);
453
454 fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
455 if (!fb_helper->crtc_info)
Dave Airlie785b93e2009-08-28 15:46:53 +1000456 return -ENOMEM;
457
Dave Airlie4abe3522010-03-30 05:34:18 +0000458 fb_helper->crtc_count = crtc_count;
459 fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
460 if (!fb_helper->connector_info) {
461 kfree(fb_helper->crtc_info);
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000462 return -ENOMEM;
463 }
Dave Airlie4abe3522010-03-30 05:34:18 +0000464 fb_helper->connector_count = 0;
Dave Airlie785b93e2009-08-28 15:46:53 +1000465
466 for (i = 0; i < crtc_count; i++) {
Dave Airlie4abe3522010-03-30 05:34:18 +0000467 fb_helper->crtc_info[i].mode_set.connectors =
Dave Airlie785b93e2009-08-28 15:46:53 +1000468 kcalloc(max_conn_count,
469 sizeof(struct drm_connector *),
470 GFP_KERNEL);
471
Dave Airlie4abe3522010-03-30 05:34:18 +0000472 if (!fb_helper->crtc_info[i].mode_set.connectors) {
Dave Airlie785b93e2009-08-28 15:46:53 +1000473 ret = -ENOMEM;
474 goto out_free;
475 }
Dave Airlie4abe3522010-03-30 05:34:18 +0000476 fb_helper->crtc_info[i].mode_set.num_connectors = 0;
Dave Airlie785b93e2009-08-28 15:46:53 +1000477 }
478
479 i = 0;
480 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Dave Airlie4abe3522010-03-30 05:34:18 +0000481 fb_helper->crtc_info[i].crtc_id = crtc->base.id;
482 fb_helper->crtc_info[i].mode_set.crtc = crtc;
Dave Airlie785b93e2009-08-28 15:46:53 +1000483 i++;
484 }
Dave Airlie4abe3522010-03-30 05:34:18 +0000485 fb_helper->conn_limit = max_conn_count;
Dave Airlie785b93e2009-08-28 15:46:53 +1000486 return 0;
487out_free:
Dave Airlie4abe3522010-03-30 05:34:18 +0000488 drm_fb_helper_crtc_free(fb_helper);
Dave Airlie785b93e2009-08-28 15:46:53 +1000489 return -ENOMEM;
490}
Dave Airlie4abe3522010-03-30 05:34:18 +0000491EXPORT_SYMBOL(drm_fb_helper_init);
492
493void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
494{
495 if (!list_empty(&fb_helper->kernel_fb_list)) {
496 list_del(&fb_helper->kernel_fb_list);
497 if (list_empty(&kernel_fb_helper_list)) {
Kirill Smelkov3da1f332010-05-14 19:45:16 +0400498 printk(KERN_INFO "drm: unregistered panic notifier\n");
Dave Airlie4abe3522010-03-30 05:34:18 +0000499 atomic_notifier_chain_unregister(&panic_notifier_list,
500 &paniced);
501 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
502 }
503 }
504
505 drm_fb_helper_crtc_free(fb_helper);
506
Dave Airlie4abe3522010-03-30 05:34:18 +0000507}
508EXPORT_SYMBOL(drm_fb_helper_fini);
Dave Airlie785b93e2009-08-28 15:46:53 +1000509
Dave Airliec850cb72009-10-23 18:49:03 +1000510static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
Dave Airlieb8c00ac2009-10-06 13:54:01 +1000511 u16 blue, u16 regno, struct fb_info *info)
512{
513 struct drm_fb_helper *fb_helper = info->par;
514 struct drm_framebuffer *fb = fb_helper->fb;
515 int pindex;
516
Dave Airliec850cb72009-10-23 18:49:03 +1000517 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
518 u32 *palette;
519 u32 value;
520 /* place color in psuedopalette */
521 if (regno > 16)
522 return -EINVAL;
523 palette = (u32 *)info->pseudo_palette;
524 red >>= (16 - info->var.red.length);
525 green >>= (16 - info->var.green.length);
526 blue >>= (16 - info->var.blue.length);
527 value = (red << info->var.red.offset) |
528 (green << info->var.green.offset) |
529 (blue << info->var.blue.offset);
530 palette[regno] = value;
531 return 0;
532 }
533
Dave Airlieb8c00ac2009-10-06 13:54:01 +1000534 pindex = regno;
535
536 if (fb->bits_per_pixel == 16) {
537 pindex = regno << 3;
538
539 if (fb->depth == 16 && regno > 63)
Dave Airliec850cb72009-10-23 18:49:03 +1000540 return -EINVAL;
Dave Airlieb8c00ac2009-10-06 13:54:01 +1000541 if (fb->depth == 15 && regno > 31)
Dave Airliec850cb72009-10-23 18:49:03 +1000542 return -EINVAL;
Dave Airlieb8c00ac2009-10-06 13:54:01 +1000543
544 if (fb->depth == 16) {
545 u16 r, g, b;
546 int i;
547 if (regno < 32) {
548 for (i = 0; i < 8; i++)
549 fb_helper->funcs->gamma_set(crtc, red,
550 green, blue, pindex + i);
551 }
552
553 fb_helper->funcs->gamma_get(crtc, &r,
554 &g, &b,
555 pindex >> 1);
556
557 for (i = 0; i < 4; i++)
558 fb_helper->funcs->gamma_set(crtc, r,
559 green, b,
560 (pindex >> 1) + i);
561 }
562 }
563
564 if (fb->depth != 16)
565 fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
Dave Airliec850cb72009-10-23 18:49:03 +1000566 return 0;
Dave Airlieb8c00ac2009-10-06 13:54:01 +1000567}
568
Dave Airlie068143d2009-10-05 09:58:02 +1000569int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
570{
571 struct drm_fb_helper *fb_helper = info->par;
Dave Airlie8be48d92010-03-30 05:34:14 +0000572 struct drm_crtc_helper_funcs *crtc_funcs;
Dave Airlie068143d2009-10-05 09:58:02 +1000573 u16 *red, *green, *blue, *transp;
574 struct drm_crtc *crtc;
575 int i, rc = 0;
576 int start;
577
Dave Airlie8be48d92010-03-30 05:34:14 +0000578 for (i = 0; i < fb_helper->crtc_count; i++) {
579 crtc = fb_helper->crtc_info[i].mode_set.crtc;
580 crtc_funcs = crtc->helper_private;
Dave Airlie068143d2009-10-05 09:58:02 +1000581
582 red = cmap->red;
583 green = cmap->green;
584 blue = cmap->blue;
585 transp = cmap->transp;
586 start = cmap->start;
587
588 for (i = 0; i < cmap->len; i++) {
589 u16 hred, hgreen, hblue, htransp = 0xffff;
590
591 hred = *red++;
592 hgreen = *green++;
593 hblue = *blue++;
594
595 if (transp)
596 htransp = *transp++;
597
Dave Airliec850cb72009-10-23 18:49:03 +1000598 rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
599 if (rc)
600 return rc;
Dave Airlie068143d2009-10-05 09:58:02 +1000601 }
602 crtc_funcs->load_lut(crtc);
603 }
604 return rc;
605}
606EXPORT_SYMBOL(drm_fb_helper_setcmap);
607
Dave Airlie785b93e2009-08-28 15:46:53 +1000608int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
609 struct fb_info *info)
610{
611 struct drm_fb_helper *fb_helper = info->par;
612 struct drm_framebuffer *fb = fb_helper->fb;
613 int depth;
614
Clemens Ladisch5349ef32009-11-04 09:42:52 +0100615 if (var->pixclock != 0)
Dave Airlie785b93e2009-08-28 15:46:53 +1000616 return -EINVAL;
617
618 /* Need to resize the fb object !!! */
Dave Airlie509c7d82010-01-08 09:27:08 +1000619 if (var->bits_per_pixel > fb->bits_per_pixel || var->xres > fb->width || var->yres > fb->height) {
620 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
621 "object %dx%d-%d > %dx%d-%d\n", var->xres, var->yres, var->bits_per_pixel,
622 fb->width, fb->height, fb->bits_per_pixel);
Dave Airlie785b93e2009-08-28 15:46:53 +1000623 return -EINVAL;
624 }
625
626 switch (var->bits_per_pixel) {
627 case 16:
628 depth = (var->green.length == 6) ? 16 : 15;
629 break;
630 case 32:
631 depth = (var->transp.length > 0) ? 32 : 24;
632 break;
633 default:
634 depth = var->bits_per_pixel;
635 break;
636 }
637
638 switch (depth) {
639 case 8:
640 var->red.offset = 0;
641 var->green.offset = 0;
642 var->blue.offset = 0;
643 var->red.length = 8;
644 var->green.length = 8;
645 var->blue.length = 8;
646 var->transp.length = 0;
647 var->transp.offset = 0;
648 break;
649 case 15:
650 var->red.offset = 10;
651 var->green.offset = 5;
652 var->blue.offset = 0;
653 var->red.length = 5;
654 var->green.length = 5;
655 var->blue.length = 5;
656 var->transp.length = 1;
657 var->transp.offset = 15;
658 break;
659 case 16:
660 var->red.offset = 11;
661 var->green.offset = 5;
662 var->blue.offset = 0;
663 var->red.length = 5;
664 var->green.length = 6;
665 var->blue.length = 5;
666 var->transp.length = 0;
667 var->transp.offset = 0;
668 break;
669 case 24:
670 var->red.offset = 16;
671 var->green.offset = 8;
672 var->blue.offset = 0;
673 var->red.length = 8;
674 var->green.length = 8;
675 var->blue.length = 8;
676 var->transp.length = 0;
677 var->transp.offset = 0;
678 break;
679 case 32:
680 var->red.offset = 16;
681 var->green.offset = 8;
682 var->blue.offset = 0;
683 var->red.length = 8;
684 var->green.length = 8;
685 var->blue.length = 8;
686 var->transp.length = 8;
687 var->transp.offset = 24;
688 break;
689 default:
690 return -EINVAL;
691 }
692 return 0;
693}
694EXPORT_SYMBOL(drm_fb_helper_check_var);
695
696/* this will let fbcon do the mode init */
697int drm_fb_helper_set_par(struct fb_info *info)
698{
699 struct drm_fb_helper *fb_helper = info->par;
700 struct drm_device *dev = fb_helper->dev;
701 struct fb_var_screeninfo *var = &info->var;
702 struct drm_crtc *crtc;
703 int ret;
704 int i;
705
Clemens Ladisch5349ef32009-11-04 09:42:52 +0100706 if (var->pixclock != 0) {
Pavel Roskin172e91f2010-02-11 14:31:32 +1000707 DRM_ERROR("PIXEL CLOCK SET\n");
Dave Airlie785b93e2009-08-28 15:46:53 +1000708 return -EINVAL;
709 }
710
Dave Airlie8be48d92010-03-30 05:34:14 +0000711 mutex_lock(&dev->mode_config.mutex);
712 for (i = 0; i < fb_helper->crtc_count; i++) {
713 crtc = fb_helper->crtc_info[i].mode_set.crtc;
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000714 ret = crtc->funcs->set_config(&fb_helper->crtc_info[i].mode_set);
715 if (ret) {
Dave Airlie785b93e2009-08-28 15:46:53 +1000716 mutex_unlock(&dev->mode_config.mutex);
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000717 return ret;
Dave Airlie785b93e2009-08-28 15:46:53 +1000718 }
719 }
Dave Airlie8be48d92010-03-30 05:34:14 +0000720 mutex_unlock(&dev->mode_config.mutex);
Dave Airlie4abe3522010-03-30 05:34:18 +0000721
722 if (fb_helper->delayed_hotplug) {
723 fb_helper->delayed_hotplug = false;
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000724 drm_fb_helper_hotplug_event(fb_helper);
Dave Airlie4abe3522010-03-30 05:34:18 +0000725 }
Dave Airlie785b93e2009-08-28 15:46:53 +1000726 return 0;
727}
728EXPORT_SYMBOL(drm_fb_helper_set_par);
729
730int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
731 struct fb_info *info)
732{
733 struct drm_fb_helper *fb_helper = info->par;
734 struct drm_device *dev = fb_helper->dev;
735 struct drm_mode_set *modeset;
736 struct drm_crtc *crtc;
737 int ret = 0;
738 int i;
739
Dave Airlie8be48d92010-03-30 05:34:14 +0000740 mutex_lock(&dev->mode_config.mutex);
741 for (i = 0; i < fb_helper->crtc_count; i++) {
742 crtc = fb_helper->crtc_info[i].mode_set.crtc;
Dave Airlie785b93e2009-08-28 15:46:53 +1000743
744 modeset = &fb_helper->crtc_info[i].mode_set;
745
746 modeset->x = var->xoffset;
747 modeset->y = var->yoffset;
748
749 if (modeset->num_connectors) {
Dave Airlie785b93e2009-08-28 15:46:53 +1000750 ret = crtc->funcs->set_config(modeset);
Dave Airlie785b93e2009-08-28 15:46:53 +1000751 if (!ret) {
752 info->var.xoffset = var->xoffset;
753 info->var.yoffset = var->yoffset;
754 }
755 }
756 }
Dave Airlie8be48d92010-03-30 05:34:14 +0000757 mutex_unlock(&dev->mode_config.mutex);
Dave Airlie785b93e2009-08-28 15:46:53 +1000758 return ret;
759}
760EXPORT_SYMBOL(drm_fb_helper_pan_display);
761
Dave Airlie8be48d92010-03-30 05:34:14 +0000762int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
763 int preferred_bpp)
Dave Airlie785b93e2009-08-28 15:46:53 +1000764{
Dave Airlie785b93e2009-08-28 15:46:53 +1000765 int new_fb = 0;
766 int crtc_count = 0;
Dave Airlie4abe3522010-03-30 05:34:18 +0000767 int i;
Dave Airlie785b93e2009-08-28 15:46:53 +1000768 struct fb_info *info;
Dave Airlie38651672010-03-30 05:34:13 +0000769 struct drm_fb_helper_surface_size sizes;
Dave Airlie8be48d92010-03-30 05:34:14 +0000770 int gamma_size = 0;
Dave Airlie38651672010-03-30 05:34:13 +0000771
772 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
773 sizes.surface_depth = 24;
774 sizes.surface_bpp = 32;
775 sizes.fb_width = (unsigned)-1;
776 sizes.fb_height = (unsigned)-1;
Dave Airlie785b93e2009-08-28 15:46:53 +1000777
Dave Airlieb8c00ac2009-10-06 13:54:01 +1000778 /* if driver picks 8 or 16 by default use that
779 for both depth/bpp */
Dave Airlie38651672010-03-30 05:34:13 +0000780 if (preferred_bpp != sizes.surface_bpp) {
781 sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
Dave Airlieb8c00ac2009-10-06 13:54:01 +1000782 }
Dave Airlie785b93e2009-08-28 15:46:53 +1000783 /* first up get a count of crtcs now in use and new min/maxes width/heights */
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000784 for (i = 0; i < fb_helper->connector_count; i++) {
785 struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
Dave Airlie8ef86782009-09-26 06:39:00 +1000786 struct drm_fb_helper_cmdline_mode *cmdline_mode;
787
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000788 cmdline_mode = &fb_helper_conn->cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +1000789
790 if (cmdline_mode->bpp_specified) {
791 switch (cmdline_mode->bpp) {
792 case 8:
Dave Airlie38651672010-03-30 05:34:13 +0000793 sizes.surface_depth = sizes.surface_bpp = 8;
Dave Airlied50ba252009-09-23 14:44:08 +1000794 break;
795 case 15:
Dave Airlie38651672010-03-30 05:34:13 +0000796 sizes.surface_depth = 15;
797 sizes.surface_bpp = 16;
Dave Airlied50ba252009-09-23 14:44:08 +1000798 break;
799 case 16:
Dave Airlie38651672010-03-30 05:34:13 +0000800 sizes.surface_depth = sizes.surface_bpp = 16;
Dave Airlied50ba252009-09-23 14:44:08 +1000801 break;
802 case 24:
Dave Airlie38651672010-03-30 05:34:13 +0000803 sizes.surface_depth = sizes.surface_bpp = 24;
Dave Airlied50ba252009-09-23 14:44:08 +1000804 break;
805 case 32:
Dave Airlie38651672010-03-30 05:34:13 +0000806 sizes.surface_depth = 24;
807 sizes.surface_bpp = 32;
Dave Airlied50ba252009-09-23 14:44:08 +1000808 break;
809 }
810 break;
811 }
812 }
813
Dave Airlie8be48d92010-03-30 05:34:14 +0000814 crtc_count = 0;
815 for (i = 0; i < fb_helper->crtc_count; i++) {
816 struct drm_display_mode *desired_mode;
817 desired_mode = fb_helper->crtc_info[i].desired_mode;
Dave Airlie785b93e2009-08-28 15:46:53 +1000818
Dave Airlie8be48d92010-03-30 05:34:14 +0000819 if (desired_mode) {
820 if (gamma_size == 0)
821 gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
822 if (desired_mode->hdisplay < sizes.fb_width)
823 sizes.fb_width = desired_mode->hdisplay;
824 if (desired_mode->vdisplay < sizes.fb_height)
825 sizes.fb_height = desired_mode->vdisplay;
826 if (desired_mode->hdisplay > sizes.surface_width)
827 sizes.surface_width = desired_mode->hdisplay;
828 if (desired_mode->vdisplay > sizes.surface_height)
829 sizes.surface_height = desired_mode->vdisplay;
Dave Airlie785b93e2009-08-28 15:46:53 +1000830 crtc_count++;
831 }
832 }
833
Dave Airlie38651672010-03-30 05:34:13 +0000834 if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
Dave Airlie785b93e2009-08-28 15:46:53 +1000835 /* hmm everyone went away - assume VGA cable just fell out
836 and will come back later. */
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000837 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
Dave Airlie19b4b442010-03-30 05:34:16 +0000838 sizes.fb_width = sizes.surface_width = 1024;
839 sizes.fb_height = sizes.surface_height = 768;
Dave Airlie785b93e2009-08-28 15:46:53 +1000840 }
841
Dave Airlie38651672010-03-30 05:34:13 +0000842 /* push down into drivers */
Dave Airlie4abe3522010-03-30 05:34:18 +0000843 new_fb = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
Dave Airlie38651672010-03-30 05:34:13 +0000844 if (new_fb < 0)
845 return new_fb;
Dave Airlie785b93e2009-08-28 15:46:53 +1000846
Dave Airlie38651672010-03-30 05:34:13 +0000847 info = fb_helper->fbdev;
Dave Airlie785b93e2009-08-28 15:46:53 +1000848
Dave Airlie8be48d92010-03-30 05:34:14 +0000849 /* set the fb pointer */
850 for (i = 0; i < fb_helper->crtc_count; i++) {
851 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
Dave Airlie785b93e2009-08-28 15:46:53 +1000852 }
853
Dave Airlie785b93e2009-08-28 15:46:53 +1000854 if (new_fb) {
Clemens Ladisch5349ef32009-11-04 09:42:52 +0100855 info->var.pixclock = 0;
Clemens Ladisch3bea21b2009-11-04 09:43:00 +0100856 if (register_framebuffer(info) < 0) {
Dave Airlie785b93e2009-08-28 15:46:53 +1000857 return -EINVAL;
Clemens Ladisch3bea21b2009-11-04 09:43:00 +0100858 }
Dave Airlie38651672010-03-30 05:34:13 +0000859
860 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
861 info->fix.id);
862
Dave Airlie785b93e2009-08-28 15:46:53 +1000863 } else {
864 drm_fb_helper_set_par(info);
865 }
Dave Airlie785b93e2009-08-28 15:46:53 +1000866
867 /* Switch back to kernel console on panic */
868 /* multi card linked list maybe */
869 if (list_empty(&kernel_fb_helper_list)) {
Kirill Smelkov3da1f332010-05-14 19:45:16 +0400870 printk(KERN_INFO "drm: registered panic notifier\n");
Dave Airlie785b93e2009-08-28 15:46:53 +1000871 atomic_notifier_chain_register(&panic_notifier_list,
872 &paniced);
873 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
874 }
Dave Airlie38651672010-03-30 05:34:13 +0000875 if (new_fb)
876 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
877
Dave Airlie785b93e2009-08-28 15:46:53 +1000878 return 0;
879}
880EXPORT_SYMBOL(drm_fb_helper_single_fb_probe);
881
Dave Airlie068143d2009-10-05 09:58:02 +1000882void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
883 uint32_t depth)
Dave Airlie785b93e2009-08-28 15:46:53 +1000884{
885 info->fix.type = FB_TYPE_PACKED_PIXELS;
Dave Airlie068143d2009-10-05 09:58:02 +1000886 info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
Dave Airliec850cb72009-10-23 18:49:03 +1000887 FB_VISUAL_TRUECOLOR;
Dave Airlie785b93e2009-08-28 15:46:53 +1000888 info->fix.type_aux = 0;
889 info->fix.xpanstep = 1; /* doing it in hw */
890 info->fix.ypanstep = 1; /* doing it in hw */
891 info->fix.ywrapstep = 0;
Dave Airlie3420e742009-08-31 10:33:29 +1000892 info->fix.accel = FB_ACCEL_NONE;
Dave Airlie785b93e2009-08-28 15:46:53 +1000893 info->fix.type_aux = 0;
894
895 info->fix.line_length = pitch;
896 return;
897}
898EXPORT_SYMBOL(drm_fb_helper_fill_fix);
899
Dave Airlie38651672010-03-30 05:34:13 +0000900void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
Dave Airlie785b93e2009-08-28 15:46:53 +1000901 uint32_t fb_width, uint32_t fb_height)
902{
Dave Airlie38651672010-03-30 05:34:13 +0000903 struct drm_framebuffer *fb = fb_helper->fb;
904 info->pseudo_palette = fb_helper->pseudo_palette;
Dave Airlie785b93e2009-08-28 15:46:53 +1000905 info->var.xres_virtual = fb->width;
906 info->var.yres_virtual = fb->height;
907 info->var.bits_per_pixel = fb->bits_per_pixel;
908 info->var.xoffset = 0;
909 info->var.yoffset = 0;
910 info->var.activate = FB_ACTIVATE_NOW;
911 info->var.height = -1;
912 info->var.width = -1;
913
914 switch (fb->depth) {
915 case 8:
916 info->var.red.offset = 0;
917 info->var.green.offset = 0;
918 info->var.blue.offset = 0;
919 info->var.red.length = 8; /* 8bit DAC */
920 info->var.green.length = 8;
921 info->var.blue.length = 8;
922 info->var.transp.offset = 0;
923 info->var.transp.length = 0;
924 break;
925 case 15:
926 info->var.red.offset = 10;
927 info->var.green.offset = 5;
928 info->var.blue.offset = 0;
929 info->var.red.length = 5;
930 info->var.green.length = 5;
931 info->var.blue.length = 5;
932 info->var.transp.offset = 15;
933 info->var.transp.length = 1;
934 break;
935 case 16:
936 info->var.red.offset = 11;
937 info->var.green.offset = 5;
938 info->var.blue.offset = 0;
939 info->var.red.length = 5;
940 info->var.green.length = 6;
941 info->var.blue.length = 5;
942 info->var.transp.offset = 0;
943 break;
944 case 24:
945 info->var.red.offset = 16;
946 info->var.green.offset = 8;
947 info->var.blue.offset = 0;
948 info->var.red.length = 8;
949 info->var.green.length = 8;
950 info->var.blue.length = 8;
951 info->var.transp.offset = 0;
952 info->var.transp.length = 0;
953 break;
954 case 32:
955 info->var.red.offset = 16;
956 info->var.green.offset = 8;
957 info->var.blue.offset = 0;
958 info->var.red.length = 8;
959 info->var.green.length = 8;
960 info->var.blue.length = 8;
961 info->var.transp.offset = 24;
962 info->var.transp.length = 8;
963 break;
964 default:
965 break;
966 }
967
968 info->var.xres = fb_width;
969 info->var.yres = fb_height;
970}
971EXPORT_SYMBOL(drm_fb_helper_fill_var);
Dave Airlie38651672010-03-30 05:34:13 +0000972
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000973static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
974 uint32_t maxX,
975 uint32_t maxY)
Dave Airlie38651672010-03-30 05:34:13 +0000976{
977 struct drm_connector *connector;
978 int count = 0;
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000979 int i;
Dave Airlie38651672010-03-30 05:34:13 +0000980
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000981 for (i = 0; i < fb_helper->connector_count; i++) {
982 connector = fb_helper->connector_info[i]->connector;
Dave Airlie38651672010-03-30 05:34:13 +0000983 count += connector->funcs->fill_modes(connector, maxX, maxY);
984 }
985
986 return count;
987}
988
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000989static struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
Dave Airlie38651672010-03-30 05:34:13 +0000990{
991 struct drm_display_mode *mode;
992
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000993 list_for_each_entry(mode, &fb_connector->connector->modes, head) {
Dave Airlie38651672010-03-30 05:34:13 +0000994 if (drm_mode_width(mode) > width ||
995 drm_mode_height(mode) > height)
996 continue;
997 if (mode->type & DRM_MODE_TYPE_PREFERRED)
998 return mode;
999 }
1000 return NULL;
1001}
1002
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001003static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
Dave Airlie38651672010-03-30 05:34:13 +00001004{
Dave Airlie38651672010-03-30 05:34:13 +00001005 struct drm_fb_helper_cmdline_mode *cmdline_mode;
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001006 cmdline_mode = &fb_connector->cmdline_mode;
Dave Airlie38651672010-03-30 05:34:13 +00001007 return cmdline_mode->specified;
1008}
1009
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001010static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
1011 int width, int height)
Dave Airlie38651672010-03-30 05:34:13 +00001012{
Dave Airlie38651672010-03-30 05:34:13 +00001013 struct drm_fb_helper_cmdline_mode *cmdline_mode;
1014 struct drm_display_mode *mode = NULL;
1015
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001016 cmdline_mode = &fb_helper_conn->cmdline_mode;
Dave Airlie38651672010-03-30 05:34:13 +00001017 if (cmdline_mode->specified == false)
1018 return mode;
1019
1020 /* attempt to find a matching mode in the list of modes
1021 * we have gotten so far, if not add a CVT mode that conforms
1022 */
1023 if (cmdline_mode->rb || cmdline_mode->margins)
1024 goto create_mode;
1025
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001026 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
Dave Airlie38651672010-03-30 05:34:13 +00001027 /* check width/height */
1028 if (mode->hdisplay != cmdline_mode->xres ||
1029 mode->vdisplay != cmdline_mode->yres)
1030 continue;
1031
1032 if (cmdline_mode->refresh_specified) {
1033 if (mode->vrefresh != cmdline_mode->refresh)
1034 continue;
1035 }
1036
1037 if (cmdline_mode->interlace) {
1038 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
1039 continue;
1040 }
1041 return mode;
1042 }
1043
1044create_mode:
Adam Jacksonb829e012010-06-10 13:33:26 -04001045 if (cmdline_mode->cvt)
1046 mode = drm_cvt_mode(fb_helper_conn->connector->dev,
1047 cmdline_mode->xres, cmdline_mode->yres,
1048 cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60,
1049 cmdline_mode->rb, cmdline_mode->interlace,
1050 cmdline_mode->margins);
1051 else
1052 mode = drm_gtf_mode(fb_helper_conn->connector->dev,
1053 cmdline_mode->xres, cmdline_mode->yres,
1054 cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60,
1055 cmdline_mode->interlace,
1056 cmdline_mode->margins);
Dave Airlie38651672010-03-30 05:34:13 +00001057 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001058 list_add(&mode->head, &fb_helper_conn->connector->modes);
Dave Airlie38651672010-03-30 05:34:13 +00001059 return mode;
1060}
1061
1062static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
1063{
1064 bool enable;
1065
1066 if (strict) {
1067 enable = connector->status == connector_status_connected;
1068 } else {
1069 enable = connector->status != connector_status_disconnected;
1070 }
1071 return enable;
1072}
1073
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001074static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
1075 bool *enabled)
Dave Airlie38651672010-03-30 05:34:13 +00001076{
1077 bool any_enabled = false;
1078 struct drm_connector *connector;
1079 int i = 0;
1080
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001081 for (i = 0; i < fb_helper->connector_count; i++) {
1082 connector = fb_helper->connector_info[i]->connector;
Dave Airlie38651672010-03-30 05:34:13 +00001083 enabled[i] = drm_connector_enabled(connector, true);
1084 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
1085 enabled[i] ? "yes" : "no");
1086 any_enabled |= enabled[i];
Dave Airlie38651672010-03-30 05:34:13 +00001087 }
1088
1089 if (any_enabled)
1090 return;
1091
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001092 for (i = 0; i < fb_helper->connector_count; i++) {
1093 connector = fb_helper->connector_info[i]->connector;
Dave Airlie38651672010-03-30 05:34:13 +00001094 enabled[i] = drm_connector_enabled(connector, false);
Dave Airlie38651672010-03-30 05:34:13 +00001095 }
1096}
1097
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001098static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
1099 struct drm_display_mode **modes,
1100 bool *enabled, int width, int height)
1101{
1102 int count, i, j;
1103 bool can_clone = false;
1104 struct drm_fb_helper_connector *fb_helper_conn;
1105 struct drm_display_mode *dmt_mode, *mode;
1106
1107 /* only contemplate cloning in the single crtc case */
1108 if (fb_helper->crtc_count > 1)
1109 return false;
1110
1111 count = 0;
1112 for (i = 0; i < fb_helper->connector_count; i++) {
1113 if (enabled[i])
1114 count++;
1115 }
1116
1117 /* only contemplate cloning if more than one connector is enabled */
1118 if (count <= 1)
1119 return false;
1120
1121 /* check the command line or if nothing common pick 1024x768 */
1122 can_clone = true;
1123 for (i = 0; i < fb_helper->connector_count; i++) {
1124 if (!enabled[i])
1125 continue;
1126 fb_helper_conn = fb_helper->connector_info[i];
1127 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1128 if (!modes[i]) {
1129 can_clone = false;
1130 break;
1131 }
1132 for (j = 0; j < i; j++) {
1133 if (!enabled[j])
1134 continue;
1135 if (!drm_mode_equal(modes[j], modes[i]))
1136 can_clone = false;
1137 }
1138 }
1139
1140 if (can_clone) {
1141 DRM_DEBUG_KMS("can clone using command line\n");
1142 return true;
1143 }
1144
1145 /* try and find a 1024x768 mode on each connector */
1146 can_clone = true;
1147 dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60);
1148
1149 for (i = 0; i < fb_helper->connector_count; i++) {
1150
1151 if (!enabled[i])
1152 continue;
1153
1154 fb_helper_conn = fb_helper->connector_info[i];
1155 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1156 if (drm_mode_equal(mode, dmt_mode))
1157 modes[i] = mode;
1158 }
1159 if (!modes[i])
1160 can_clone = false;
1161 }
1162
1163 if (can_clone) {
1164 DRM_DEBUG_KMS("can clone using 1024x768\n");
1165 return true;
1166 }
1167 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1168 return false;
1169}
1170
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001171static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
Dave Airlie38651672010-03-30 05:34:13 +00001172 struct drm_display_mode **modes,
1173 bool *enabled, int width, int height)
1174{
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001175 struct drm_fb_helper_connector *fb_helper_conn;
1176 int i;
Dave Airlie38651672010-03-30 05:34:13 +00001177
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001178 for (i = 0; i < fb_helper->connector_count; i++) {
1179 fb_helper_conn = fb_helper->connector_info[i];
Dave Airlie38651672010-03-30 05:34:13 +00001180
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001181 if (enabled[i] == false)
Dave Airlie38651672010-03-30 05:34:13 +00001182 continue;
Dave Airlie38651672010-03-30 05:34:13 +00001183
1184 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001185 fb_helper_conn->connector->base.id);
Dave Airlie38651672010-03-30 05:34:13 +00001186
1187 /* got for command line mode first */
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001188 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
Dave Airlie38651672010-03-30 05:34:13 +00001189 if (!modes[i]) {
1190 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001191 fb_helper_conn->connector->base.id);
1192 modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
Dave Airlie38651672010-03-30 05:34:13 +00001193 }
1194 /* No preferred modes, pick one off the list */
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001195 if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
1196 list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
Dave Airlie38651672010-03-30 05:34:13 +00001197 break;
1198 }
1199 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
1200 "none");
Dave Airlie38651672010-03-30 05:34:13 +00001201 }
1202 return true;
1203}
1204
Dave Airlie8be48d92010-03-30 05:34:14 +00001205static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
1206 struct drm_fb_helper_crtc **best_crtcs,
Dave Airlie38651672010-03-30 05:34:13 +00001207 struct drm_display_mode **modes,
1208 int n, int width, int height)
1209{
1210 int c, o;
Dave Airlie8be48d92010-03-30 05:34:14 +00001211 struct drm_device *dev = fb_helper->dev;
Dave Airlie38651672010-03-30 05:34:13 +00001212 struct drm_connector *connector;
1213 struct drm_connector_helper_funcs *connector_funcs;
1214 struct drm_encoder *encoder;
Dave Airlie8be48d92010-03-30 05:34:14 +00001215 struct drm_fb_helper_crtc *best_crtc;
Dave Airlie38651672010-03-30 05:34:13 +00001216 int my_score, best_score, score;
Dave Airlie8be48d92010-03-30 05:34:14 +00001217 struct drm_fb_helper_crtc **crtcs, *crtc;
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001218 struct drm_fb_helper_connector *fb_helper_conn;
Dave Airlie38651672010-03-30 05:34:13 +00001219
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001220 if (n == fb_helper->connector_count)
Dave Airlie38651672010-03-30 05:34:13 +00001221 return 0;
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001222
1223 fb_helper_conn = fb_helper->connector_info[n];
1224 connector = fb_helper_conn->connector;
Dave Airlie38651672010-03-30 05:34:13 +00001225
1226 best_crtcs[n] = NULL;
1227 best_crtc = NULL;
Dave Airlie8be48d92010-03-30 05:34:14 +00001228 best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
Dave Airlie38651672010-03-30 05:34:13 +00001229 if (modes[n] == NULL)
1230 return best_score;
1231
Dave Airlie8be48d92010-03-30 05:34:14 +00001232 crtcs = kzalloc(dev->mode_config.num_connector *
1233 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
Dave Airlie38651672010-03-30 05:34:13 +00001234 if (!crtcs)
1235 return best_score;
1236
1237 my_score = 1;
1238 if (connector->status == connector_status_connected)
1239 my_score++;
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001240 if (drm_has_cmdline_mode(fb_helper_conn))
Dave Airlie38651672010-03-30 05:34:13 +00001241 my_score++;
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001242 if (drm_has_preferred_mode(fb_helper_conn, width, height))
Dave Airlie38651672010-03-30 05:34:13 +00001243 my_score++;
1244
1245 connector_funcs = connector->helper_private;
1246 encoder = connector_funcs->best_encoder(connector);
1247 if (!encoder)
1248 goto out;
1249
Dave Airlie38651672010-03-30 05:34:13 +00001250 /* select a crtc for this connector and then attempt to configure
1251 remaining connectors */
Dave Airlie8be48d92010-03-30 05:34:14 +00001252 for (c = 0; c < fb_helper->crtc_count; c++) {
1253 crtc = &fb_helper->crtc_info[c];
Dave Airlie38651672010-03-30 05:34:13 +00001254
1255 if ((encoder->possible_crtcs & (1 << c)) == 0) {
Dave Airlie38651672010-03-30 05:34:13 +00001256 continue;
1257 }
1258
1259 for (o = 0; o < n; o++)
1260 if (best_crtcs[o] == crtc)
1261 break;
1262
1263 if (o < n) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001264 /* ignore cloning unless only a single crtc */
1265 if (fb_helper->crtc_count > 1)
1266 continue;
1267
1268 if (!drm_mode_equal(modes[o], modes[n]))
1269 continue;
Dave Airlie38651672010-03-30 05:34:13 +00001270 }
1271
1272 crtcs[n] = crtc;
Dave Airlie8be48d92010-03-30 05:34:14 +00001273 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1274 score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
Dave Airlie38651672010-03-30 05:34:13 +00001275 width, height);
1276 if (score > best_score) {
1277 best_crtc = crtc;
1278 best_score = score;
1279 memcpy(best_crtcs, crtcs,
1280 dev->mode_config.num_connector *
Dave Airlie8be48d92010-03-30 05:34:14 +00001281 sizeof(struct drm_fb_helper_crtc *));
Dave Airlie38651672010-03-30 05:34:13 +00001282 }
Dave Airlie38651672010-03-30 05:34:13 +00001283 }
1284out:
1285 kfree(crtcs);
1286 return best_score;
1287}
1288
Dave Airlie8be48d92010-03-30 05:34:14 +00001289static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
Dave Airlie38651672010-03-30 05:34:13 +00001290{
Dave Airlie8be48d92010-03-30 05:34:14 +00001291 struct drm_device *dev = fb_helper->dev;
1292 struct drm_fb_helper_crtc **crtcs;
Dave Airlie38651672010-03-30 05:34:13 +00001293 struct drm_display_mode **modes;
1294 struct drm_encoder *encoder;
Dave Airlie8be48d92010-03-30 05:34:14 +00001295 struct drm_mode_set *modeset;
Dave Airlie38651672010-03-30 05:34:13 +00001296 bool *enabled;
1297 int width, height;
1298 int i, ret;
1299
1300 DRM_DEBUG_KMS("\n");
1301
1302 width = dev->mode_config.max_width;
1303 height = dev->mode_config.max_height;
1304
1305 /* clean out all the encoder/crtc combos */
1306 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1307 encoder->crtc = NULL;
1308 }
1309
1310 crtcs = kcalloc(dev->mode_config.num_connector,
Dave Airlie8be48d92010-03-30 05:34:14 +00001311 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
Dave Airlie38651672010-03-30 05:34:13 +00001312 modes = kcalloc(dev->mode_config.num_connector,
1313 sizeof(struct drm_display_mode *), GFP_KERNEL);
1314 enabled = kcalloc(dev->mode_config.num_connector,
1315 sizeof(bool), GFP_KERNEL);
1316
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001317 drm_enable_connectors(fb_helper, enabled);
Dave Airlie38651672010-03-30 05:34:13 +00001318
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001319 ret = drm_target_cloned(fb_helper, modes, enabled, width, height);
1320 if (!ret) {
1321 ret = drm_target_preferred(fb_helper, modes, enabled, width, height);
1322 if (!ret)
1323 DRM_ERROR("Unable to find initial modes\n");
1324 }
Dave Airlie38651672010-03-30 05:34:13 +00001325
1326 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height);
1327
Dave Airlie8be48d92010-03-30 05:34:14 +00001328 drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1329
1330 /* need to set the modesets up here for use later */
1331 /* fill out the connector<->crtc mappings into the modesets */
1332 for (i = 0; i < fb_helper->crtc_count; i++) {
1333 modeset = &fb_helper->crtc_info[i].mode_set;
1334 modeset->num_connectors = 0;
1335 }
Dave Airlie38651672010-03-30 05:34:13 +00001336
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001337 for (i = 0; i < fb_helper->connector_count; i++) {
Dave Airlie38651672010-03-30 05:34:13 +00001338 struct drm_display_mode *mode = modes[i];
Dave Airlie8be48d92010-03-30 05:34:14 +00001339 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1340 modeset = &fb_crtc->mode_set;
Dave Airlie38651672010-03-30 05:34:13 +00001341
Dave Airlie8be48d92010-03-30 05:34:14 +00001342 if (mode && fb_crtc) {
Dave Airlie38651672010-03-30 05:34:13 +00001343 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
Dave Airlie8be48d92010-03-30 05:34:14 +00001344 mode->name, fb_crtc->mode_set.crtc->base.id);
1345 fb_crtc->desired_mode = mode;
1346 if (modeset->mode)
1347 drm_mode_destroy(dev, modeset->mode);
1348 modeset->mode = drm_mode_duplicate(dev,
1349 fb_crtc->desired_mode);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001350 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
Dave Airlie38651672010-03-30 05:34:13 +00001351 }
Dave Airlie38651672010-03-30 05:34:13 +00001352 }
1353
1354 kfree(crtcs);
1355 kfree(modes);
1356 kfree(enabled);
1357}
1358
1359/**
1360 * drm_helper_initial_config - setup a sane initial connector configuration
1361 * @dev: DRM device
1362 *
1363 * LOCKING:
1364 * Called at init time, must take mode config lock.
1365 *
1366 * Scan the CRTCs and connectors and try to put together an initial setup.
1367 * At the moment, this is a cloned configuration across all heads with
1368 * a new framebuffer object as the backing store.
1369 *
1370 * RETURNS:
1371 * Zero if everything went ok, nonzero otherwise.
1372 */
Dave Airlie4abe3522010-03-30 05:34:18 +00001373bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
Dave Airlie38651672010-03-30 05:34:13 +00001374{
Dave Airlie8be48d92010-03-30 05:34:14 +00001375 struct drm_device *dev = fb_helper->dev;
Dave Airlie38651672010-03-30 05:34:13 +00001376 int count = 0;
1377
1378 /* disable all the possible outputs/crtcs before entering KMS mode */
Dave Airlie8be48d92010-03-30 05:34:14 +00001379 drm_helper_disable_unused_functions(fb_helper->dev);
Dave Airlie38651672010-03-30 05:34:13 +00001380
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001381 drm_fb_helper_parse_command_line(fb_helper);
Dave Airlie38651672010-03-30 05:34:13 +00001382
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001383 count = drm_fb_helper_probe_connector_modes(fb_helper,
1384 dev->mode_config.max_width,
1385 dev->mode_config.max_height);
Dave Airlie38651672010-03-30 05:34:13 +00001386 /*
1387 * we shouldn't end up with no modes here.
1388 */
Dave Airlie5c4426a2010-03-30 05:34:17 +00001389 if (count == 0) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001390 printk(KERN_INFO "No connectors reported connected with modes\n");
Dave Airlie5c4426a2010-03-30 05:34:17 +00001391 }
Dave Airlie8be48d92010-03-30 05:34:14 +00001392 drm_setup_crtcs(fb_helper);
Dave Airlie38651672010-03-30 05:34:13 +00001393
Dave Airlie4abe3522010-03-30 05:34:18 +00001394 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
Dave Airlie38651672010-03-30 05:34:13 +00001395}
Dave Airlie8be48d92010-03-30 05:34:14 +00001396EXPORT_SYMBOL(drm_fb_helper_initial_config);
Dave Airlie38651672010-03-30 05:34:13 +00001397
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001398bool drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
Dave Airlie38651672010-03-30 05:34:13 +00001399{
Dave Airlie5c4426a2010-03-30 05:34:17 +00001400 int count = 0;
Dave Airlie4abe3522010-03-30 05:34:18 +00001401 u32 max_width, max_height, bpp_sel;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001402 bool bound = false, crtcs_bound = false;
1403 struct drm_crtc *crtc;
Dave Airlie4abe3522010-03-30 05:34:18 +00001404
1405 if (!fb_helper->fb)
1406 return false;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001407
1408 list_for_each_entry(crtc, &fb_helper->dev->mode_config.crtc_list, head) {
1409 if (crtc->fb)
1410 crtcs_bound = true;
1411 if (crtc->fb == fb_helper->fb)
1412 bound = true;
1413 }
1414
1415 if (!bound && crtcs_bound) {
1416 fb_helper->delayed_hotplug = true;
1417 return false;
1418 }
Dave Airlie38651672010-03-30 05:34:13 +00001419 DRM_DEBUG_KMS("\n");
1420
Dave Airlie4abe3522010-03-30 05:34:18 +00001421 max_width = fb_helper->fb->width;
1422 max_height = fb_helper->fb->height;
1423 bpp_sel = fb_helper->fb->bits_per_pixel;
1424
Dave Airlie5c4426a2010-03-30 05:34:17 +00001425 count = drm_fb_helper_probe_connector_modes(fb_helper, max_width,
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001426 max_height);
Dave Airlie8be48d92010-03-30 05:34:14 +00001427 drm_setup_crtcs(fb_helper);
Dave Airlie38651672010-03-30 05:34:13 +00001428
Dave Airlie4abe3522010-03-30 05:34:18 +00001429 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
Dave Airlie38651672010-03-30 05:34:13 +00001430}
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001431EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
Dave Airlie5c4426a2010-03-30 05:34:17 +00001432