drm_fb_helper.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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. */
  30. #include <linux/kernel.h>
  31. #include <linux/sysrq.h>
  32. #include <linux/fb.h>
  33. #include "drmP.h"
  34. #include "drm_crtc.h"
  35. #include "drm_fb_helper.h"
  36. #include "drm_crtc_helper.h"
  37. MODULE_AUTHOR("David Airlie, Jesse Barnes");
  38. MODULE_DESCRIPTION("DRM KMS helper");
  39. MODULE_LICENSE("GPL and additional rights");
  40. static LIST_HEAD(kernel_fb_helper_list);
  41. int drm_fb_helper_add_connector(struct drm_connector *connector)
  42. {
  43. connector->fb_helper_private = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
  44. if (!connector->fb_helper_private)
  45. return -ENOMEM;
  46. return 0;
  47. }
  48. EXPORT_SYMBOL(drm_fb_helper_add_connector);
  49. /**
  50. * drm_fb_helper_connector_parse_command_line - parse command line for connector
  51. * @connector - connector to parse line for
  52. * @mode_option - per connector mode option
  53. *
  54. * This parses the connector specific then generic command lines for
  55. * modes and options to configure the connector.
  56. *
  57. * This uses the same parameters as the fb modedb.c, except for extra
  58. * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
  59. *
  60. * enable/enable Digital/disable bit at the end
  61. */
  62. static bool drm_fb_helper_connector_parse_command_line(struct drm_connector *connector,
  63. const char *mode_option)
  64. {
  65. const char *name;
  66. unsigned int namelen;
  67. int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
  68. unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0;
  69. int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
  70. int i;
  71. enum drm_connector_force force = DRM_FORCE_UNSPECIFIED;
  72. struct drm_fb_helper_connector *fb_help_conn = connector->fb_helper_private;
  73. struct drm_fb_helper_cmdline_mode *cmdline_mode;
  74. if (!fb_help_conn)
  75. return false;
  76. cmdline_mode = &fb_help_conn->cmdline_mode;
  77. if (!mode_option)
  78. mode_option = fb_mode_option;
  79. if (!mode_option) {
  80. cmdline_mode->specified = false;
  81. return false;
  82. }
  83. name = mode_option;
  84. namelen = strlen(name);
  85. for (i = namelen-1; i >= 0; i--) {
  86. switch (name[i]) {
  87. case '@':
  88. namelen = i;
  89. if (!refresh_specified && !bpp_specified &&
  90. !yres_specified) {
  91. refresh = simple_strtol(&name[i+1], NULL, 10);
  92. refresh_specified = 1;
  93. if (cvt || rb)
  94. cvt = 0;
  95. } else
  96. goto done;
  97. break;
  98. case '-':
  99. namelen = i;
  100. if (!bpp_specified && !yres_specified) {
  101. bpp = simple_strtol(&name[i+1], NULL, 10);
  102. bpp_specified = 1;
  103. if (cvt || rb)
  104. cvt = 0;
  105. } else
  106. goto done;
  107. break;
  108. case 'x':
  109. if (!yres_specified) {
  110. yres = simple_strtol(&name[i+1], NULL, 10);
  111. yres_specified = 1;
  112. } else
  113. goto done;
  114. case '0' ... '9':
  115. break;
  116. case 'M':
  117. if (!yres_specified)
  118. cvt = 1;
  119. break;
  120. case 'R':
  121. if (!cvt)
  122. rb = 1;
  123. break;
  124. case 'm':
  125. if (!cvt)
  126. margins = 1;
  127. break;
  128. case 'i':
  129. if (!cvt)
  130. interlace = 1;
  131. break;
  132. case 'e':
  133. force = DRM_FORCE_ON;
  134. break;
  135. case 'D':
  136. if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) &&
  137. (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB))
  138. force = DRM_FORCE_ON;
  139. else
  140. force = DRM_FORCE_ON_DIGITAL;
  141. break;
  142. case 'd':
  143. force = DRM_FORCE_OFF;
  144. break;
  145. default:
  146. goto done;
  147. }
  148. }
  149. if (i < 0 && yres_specified) {
  150. xres = simple_strtol(name, NULL, 10);
  151. res_specified = 1;
  152. }
  153. done:
  154. DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
  155. drm_get_connector_name(connector), xres, yres,
  156. (refresh) ? refresh : 60, (rb) ? " reduced blanking" :
  157. "", (margins) ? " with margins" : "", (interlace) ?
  158. " interlaced" : "");
  159. if (force) {
  160. const char *s;
  161. switch (force) {
  162. case DRM_FORCE_OFF: s = "OFF"; break;
  163. case DRM_FORCE_ON_DIGITAL: s = "ON - dig"; break;
  164. default:
  165. case DRM_FORCE_ON: s = "ON"; break;
  166. }
  167. DRM_INFO("forcing %s connector %s\n",
  168. drm_get_connector_name(connector), s);
  169. connector->force = force;
  170. }
  171. if (res_specified) {
  172. cmdline_mode->specified = true;
  173. cmdline_mode->xres = xres;
  174. cmdline_mode->yres = yres;
  175. }
  176. if (refresh_specified) {
  177. cmdline_mode->refresh_specified = true;
  178. cmdline_mode->refresh = refresh;
  179. }
  180. if (bpp_specified) {
  181. cmdline_mode->bpp_specified = true;
  182. cmdline_mode->bpp = bpp;
  183. }
  184. cmdline_mode->rb = rb ? true : false;
  185. cmdline_mode->cvt = cvt ? true : false;
  186. cmdline_mode->interlace = interlace ? true : false;
  187. return true;
  188. }
  189. int drm_fb_helper_parse_command_line(struct drm_device *dev)
  190. {
  191. struct drm_connector *connector;
  192. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  193. char *option = NULL;
  194. /* do something on return - turn off connector maybe */
  195. if (fb_get_options(drm_get_connector_name(connector), &option))
  196. continue;
  197. drm_fb_helper_connector_parse_command_line(connector, option);
  198. }
  199. return 0;
  200. }
  201. bool drm_fb_helper_force_kernel_mode(void)
  202. {
  203. int i = 0;
  204. bool ret, error = false;
  205. struct drm_fb_helper *helper;
  206. if (list_empty(&kernel_fb_helper_list))
  207. return false;
  208. list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
  209. for (i = 0; i < helper->crtc_count; i++) {
  210. struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
  211. ret = drm_crtc_helper_set_config(mode_set);
  212. if (ret)
  213. error = true;
  214. }
  215. }
  216. return error;
  217. }
  218. int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
  219. void *panic_str)
  220. {
  221. DRM_ERROR("panic occurred, switching back to text console\n");
  222. return drm_fb_helper_force_kernel_mode();
  223. return 0;
  224. }
  225. EXPORT_SYMBOL(drm_fb_helper_panic);
  226. static struct notifier_block paniced = {
  227. .notifier_call = drm_fb_helper_panic,
  228. };
  229. /**
  230. * drm_fb_helper_restore - restore the framebuffer console (kernel) config
  231. *
  232. * Restore's the kernel's fbcon mode, used for lastclose & panic paths.
  233. */
  234. void drm_fb_helper_restore(void)
  235. {
  236. bool ret;
  237. ret = drm_fb_helper_force_kernel_mode();
  238. if (ret == true)
  239. DRM_ERROR("Failed to restore crtc configuration\n");
  240. }
  241. EXPORT_SYMBOL(drm_fb_helper_restore);
  242. #ifdef CONFIG_MAGIC_SYSRQ
  243. static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
  244. {
  245. drm_fb_helper_restore();
  246. }
  247. static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
  248. static void drm_fb_helper_sysrq(int dummy1, struct tty_struct *dummy3)
  249. {
  250. schedule_work(&drm_fb_helper_restore_work);
  251. }
  252. static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
  253. .handler = drm_fb_helper_sysrq,
  254. .help_msg = "force-fb(V)",
  255. .action_msg = "Restore framebuffer console",
  256. };
  257. #else
  258. static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
  259. #endif
  260. static void drm_fb_helper_on(struct fb_info *info)
  261. {
  262. struct drm_fb_helper *fb_helper = info->par;
  263. struct drm_device *dev = fb_helper->dev;
  264. struct drm_crtc *crtc;
  265. struct drm_crtc_helper_funcs *crtc_funcs;
  266. struct drm_encoder *encoder;
  267. int i;
  268. /*
  269. * For each CRTC in this fb, turn the crtc on then,
  270. * find all associated encoders and turn them on.
  271. */
  272. mutex_lock(&dev->mode_config.mutex);
  273. for (i = 0; i < fb_helper->crtc_count; i++) {
  274. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  275. crtc_funcs = crtc->helper_private;
  276. if (!crtc->enabled)
  277. continue;
  278. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  279. /* Found a CRTC on this fb, now find encoders */
  280. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  281. if (encoder->crtc == crtc) {
  282. struct drm_encoder_helper_funcs *encoder_funcs;
  283. encoder_funcs = encoder->helper_private;
  284. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  285. }
  286. }
  287. }
  288. mutex_unlock(&dev->mode_config.mutex);
  289. }
  290. static void drm_fb_helper_off(struct fb_info *info, int dpms_mode)
  291. {
  292. struct drm_fb_helper *fb_helper = info->par;
  293. struct drm_device *dev = fb_helper->dev;
  294. struct drm_crtc *crtc;
  295. struct drm_crtc_helper_funcs *crtc_funcs;
  296. struct drm_encoder *encoder;
  297. int i;
  298. /*
  299. * For each CRTC in this fb, find all associated encoders
  300. * and turn them off, then turn off the CRTC.
  301. */
  302. mutex_lock(&dev->mode_config.mutex);
  303. for (i = 0; i < fb_helper->crtc_count; i++) {
  304. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  305. crtc_funcs = crtc->helper_private;
  306. if (!crtc->enabled)
  307. continue;
  308. /* Found a CRTC on this fb, now find encoders */
  309. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  310. if (encoder->crtc == crtc) {
  311. struct drm_encoder_helper_funcs *encoder_funcs;
  312. encoder_funcs = encoder->helper_private;
  313. encoder_funcs->dpms(encoder, dpms_mode);
  314. }
  315. }
  316. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  317. }
  318. mutex_unlock(&dev->mode_config.mutex);
  319. }
  320. int drm_fb_helper_blank(int blank, struct fb_info *info)
  321. {
  322. switch (blank) {
  323. /* Display: On; HSync: On, VSync: On */
  324. case FB_BLANK_UNBLANK:
  325. drm_fb_helper_on(info);
  326. break;
  327. /* Display: Off; HSync: On, VSync: On */
  328. case FB_BLANK_NORMAL:
  329. drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY);
  330. break;
  331. /* Display: Off; HSync: Off, VSync: On */
  332. case FB_BLANK_HSYNC_SUSPEND:
  333. drm_fb_helper_off(info, DRM_MODE_DPMS_STANDBY);
  334. break;
  335. /* Display: Off; HSync: On, VSync: Off */
  336. case FB_BLANK_VSYNC_SUSPEND:
  337. drm_fb_helper_off(info, DRM_MODE_DPMS_SUSPEND);
  338. break;
  339. /* Display: Off; HSync: Off, VSync: Off */
  340. case FB_BLANK_POWERDOWN:
  341. drm_fb_helper_off(info, DRM_MODE_DPMS_OFF);
  342. break;
  343. }
  344. return 0;
  345. }
  346. EXPORT_SYMBOL(drm_fb_helper_blank);
  347. static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
  348. {
  349. int i;
  350. for (i = 0; i < helper->crtc_count; i++)
  351. kfree(helper->crtc_info[i].mode_set.connectors);
  352. kfree(helper->crtc_info);
  353. }
  354. int drm_fb_helper_init_crtc_count(struct drm_device *dev,
  355. struct drm_fb_helper *helper,
  356. int crtc_count, int max_conn_count)
  357. {
  358. struct drm_crtc *crtc;
  359. int ret = 0;
  360. int i;
  361. INIT_LIST_HEAD(&helper->kernel_fb_list);
  362. helper->dev = dev;
  363. helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
  364. if (!helper->crtc_info)
  365. return -ENOMEM;
  366. helper->crtc_count = crtc_count;
  367. for (i = 0; i < crtc_count; i++) {
  368. helper->crtc_info[i].mode_set.connectors =
  369. kcalloc(max_conn_count,
  370. sizeof(struct drm_connector *),
  371. GFP_KERNEL);
  372. if (!helper->crtc_info[i].mode_set.connectors) {
  373. ret = -ENOMEM;
  374. goto out_free;
  375. }
  376. helper->crtc_info[i].mode_set.num_connectors = 0;
  377. }
  378. i = 0;
  379. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  380. helper->crtc_info[i].crtc_id = crtc->base.id;
  381. helper->crtc_info[i].mode_set.crtc = crtc;
  382. i++;
  383. }
  384. helper->conn_limit = max_conn_count;
  385. return 0;
  386. out_free:
  387. drm_fb_helper_crtc_free(helper);
  388. return -ENOMEM;
  389. }
  390. EXPORT_SYMBOL(drm_fb_helper_init_crtc_count);
  391. static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
  392. u16 blue, u16 regno, struct fb_info *info)
  393. {
  394. struct drm_fb_helper *fb_helper = info->par;
  395. struct drm_framebuffer *fb = fb_helper->fb;
  396. int pindex;
  397. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  398. u32 *palette;
  399. u32 value;
  400. /* place color in psuedopalette */
  401. if (regno > 16)
  402. return -EINVAL;
  403. palette = (u32 *)info->pseudo_palette;
  404. red >>= (16 - info->var.red.length);
  405. green >>= (16 - info->var.green.length);
  406. blue >>= (16 - info->var.blue.length);
  407. value = (red << info->var.red.offset) |
  408. (green << info->var.green.offset) |
  409. (blue << info->var.blue.offset);
  410. palette[regno] = value;
  411. return 0;
  412. }
  413. pindex = regno;
  414. if (fb->bits_per_pixel == 16) {
  415. pindex = regno << 3;
  416. if (fb->depth == 16 && regno > 63)
  417. return -EINVAL;
  418. if (fb->depth == 15 && regno > 31)
  419. return -EINVAL;
  420. if (fb->depth == 16) {
  421. u16 r, g, b;
  422. int i;
  423. if (regno < 32) {
  424. for (i = 0; i < 8; i++)
  425. fb_helper->funcs->gamma_set(crtc, red,
  426. green, blue, pindex + i);
  427. }
  428. fb_helper->funcs->gamma_get(crtc, &r,
  429. &g, &b,
  430. pindex >> 1);
  431. for (i = 0; i < 4; i++)
  432. fb_helper->funcs->gamma_set(crtc, r,
  433. green, b,
  434. (pindex >> 1) + i);
  435. }
  436. }
  437. if (fb->depth != 16)
  438. fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
  439. return 0;
  440. }
  441. int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
  442. {
  443. struct drm_fb_helper *fb_helper = info->par;
  444. struct drm_crtc_helper_funcs *crtc_funcs;
  445. u16 *red, *green, *blue, *transp;
  446. struct drm_crtc *crtc;
  447. int i, rc = 0;
  448. int start;
  449. for (i = 0; i < fb_helper->crtc_count; i++) {
  450. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  451. crtc_funcs = crtc->helper_private;
  452. red = cmap->red;
  453. green = cmap->green;
  454. blue = cmap->blue;
  455. transp = cmap->transp;
  456. start = cmap->start;
  457. for (i = 0; i < cmap->len; i++) {
  458. u16 hred, hgreen, hblue, htransp = 0xffff;
  459. hred = *red++;
  460. hgreen = *green++;
  461. hblue = *blue++;
  462. if (transp)
  463. htransp = *transp++;
  464. rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
  465. if (rc)
  466. return rc;
  467. }
  468. crtc_funcs->load_lut(crtc);
  469. }
  470. return rc;
  471. }
  472. EXPORT_SYMBOL(drm_fb_helper_setcmap);
  473. int drm_fb_helper_setcolreg(unsigned regno,
  474. unsigned red,
  475. unsigned green,
  476. unsigned blue,
  477. unsigned transp,
  478. struct fb_info *info)
  479. {
  480. struct drm_fb_helper *fb_helper = info->par;
  481. struct drm_crtc *crtc;
  482. struct drm_crtc_helper_funcs *crtc_funcs;
  483. int i;
  484. int ret;
  485. if (regno > 255)
  486. return 1;
  487. for (i = 0; i < fb_helper->crtc_count; i++) {
  488. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  489. crtc_funcs = crtc->helper_private;
  490. ret = setcolreg(crtc, red, green, blue, regno, info);
  491. if (ret)
  492. return ret;
  493. crtc_funcs->load_lut(crtc);
  494. }
  495. return 0;
  496. }
  497. EXPORT_SYMBOL(drm_fb_helper_setcolreg);
  498. int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
  499. struct fb_info *info)
  500. {
  501. struct drm_fb_helper *fb_helper = info->par;
  502. struct drm_framebuffer *fb = fb_helper->fb;
  503. int depth;
  504. if (var->pixclock != 0)
  505. return -EINVAL;
  506. /* Need to resize the fb object !!! */
  507. if (var->bits_per_pixel > fb->bits_per_pixel || var->xres > fb->width || var->yres > fb->height) {
  508. DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
  509. "object %dx%d-%d > %dx%d-%d\n", var->xres, var->yres, var->bits_per_pixel,
  510. fb->width, fb->height, fb->bits_per_pixel);
  511. return -EINVAL;
  512. }
  513. switch (var->bits_per_pixel) {
  514. case 16:
  515. depth = (var->green.length == 6) ? 16 : 15;
  516. break;
  517. case 32:
  518. depth = (var->transp.length > 0) ? 32 : 24;
  519. break;
  520. default:
  521. depth = var->bits_per_pixel;
  522. break;
  523. }
  524. switch (depth) {
  525. case 8:
  526. var->red.offset = 0;
  527. var->green.offset = 0;
  528. var->blue.offset = 0;
  529. var->red.length = 8;
  530. var->green.length = 8;
  531. var->blue.length = 8;
  532. var->transp.length = 0;
  533. var->transp.offset = 0;
  534. break;
  535. case 15:
  536. var->red.offset = 10;
  537. var->green.offset = 5;
  538. var->blue.offset = 0;
  539. var->red.length = 5;
  540. var->green.length = 5;
  541. var->blue.length = 5;
  542. var->transp.length = 1;
  543. var->transp.offset = 15;
  544. break;
  545. case 16:
  546. var->red.offset = 11;
  547. var->green.offset = 5;
  548. var->blue.offset = 0;
  549. var->red.length = 5;
  550. var->green.length = 6;
  551. var->blue.length = 5;
  552. var->transp.length = 0;
  553. var->transp.offset = 0;
  554. break;
  555. case 24:
  556. var->red.offset = 16;
  557. var->green.offset = 8;
  558. var->blue.offset = 0;
  559. var->red.length = 8;
  560. var->green.length = 8;
  561. var->blue.length = 8;
  562. var->transp.length = 0;
  563. var->transp.offset = 0;
  564. break;
  565. case 32:
  566. var->red.offset = 16;
  567. var->green.offset = 8;
  568. var->blue.offset = 0;
  569. var->red.length = 8;
  570. var->green.length = 8;
  571. var->blue.length = 8;
  572. var->transp.length = 8;
  573. var->transp.offset = 24;
  574. break;
  575. default:
  576. return -EINVAL;
  577. }
  578. return 0;
  579. }
  580. EXPORT_SYMBOL(drm_fb_helper_check_var);
  581. /* this will let fbcon do the mode init */
  582. int drm_fb_helper_set_par(struct fb_info *info)
  583. {
  584. struct drm_fb_helper *fb_helper = info->par;
  585. struct drm_device *dev = fb_helper->dev;
  586. struct fb_var_screeninfo *var = &info->var;
  587. struct drm_crtc *crtc;
  588. int ret;
  589. int i;
  590. if (var->pixclock != 0) {
  591. DRM_ERROR("PIXEL CLOCK SET\n");
  592. return -EINVAL;
  593. }
  594. mutex_lock(&dev->mode_config.mutex);
  595. for (i = 0; i < fb_helper->crtc_count; i++) {
  596. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  597. if (crtc->fb != fb_helper->crtc_info[i].mode_set.fb) {
  598. ret = crtc->funcs->set_config(&fb_helper->crtc_info[i].mode_set);
  599. if (ret) {
  600. mutex_unlock(&dev->mode_config.mutex);
  601. return ret;
  602. }
  603. }
  604. }
  605. mutex_unlock(&dev->mode_config.mutex);
  606. return 0;
  607. }
  608. EXPORT_SYMBOL(drm_fb_helper_set_par);
  609. int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
  610. struct fb_info *info)
  611. {
  612. struct drm_fb_helper *fb_helper = info->par;
  613. struct drm_device *dev = fb_helper->dev;
  614. struct drm_mode_set *modeset;
  615. struct drm_crtc *crtc;
  616. int ret = 0;
  617. int i;
  618. mutex_lock(&dev->mode_config.mutex);
  619. for (i = 0; i < fb_helper->crtc_count; i++) {
  620. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  621. modeset = &fb_helper->crtc_info[i].mode_set;
  622. modeset->x = var->xoffset;
  623. modeset->y = var->yoffset;
  624. if (modeset->num_connectors) {
  625. ret = crtc->funcs->set_config(modeset);
  626. if (!ret) {
  627. info->var.xoffset = var->xoffset;
  628. info->var.yoffset = var->yoffset;
  629. }
  630. }
  631. }
  632. mutex_unlock(&dev->mode_config.mutex);
  633. return ret;
  634. }
  635. EXPORT_SYMBOL(drm_fb_helper_pan_display);
  636. int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
  637. int preferred_bpp)
  638. {
  639. struct drm_device *dev = fb_helper->dev;
  640. struct drm_connector *connector;
  641. int new_fb = 0;
  642. int crtc_count = 0;
  643. int ret, i;
  644. struct fb_info *info;
  645. struct drm_fb_helper_surface_size sizes;
  646. int gamma_size = 0;
  647. memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
  648. sizes.surface_depth = 24;
  649. sizes.surface_bpp = 32;
  650. sizes.fb_width = (unsigned)-1;
  651. sizes.fb_height = (unsigned)-1;
  652. /* if driver picks 8 or 16 by default use that
  653. for both depth/bpp */
  654. if (preferred_bpp != sizes.surface_bpp) {
  655. sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
  656. }
  657. /* first up get a count of crtcs now in use and new min/maxes width/heights */
  658. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  659. struct drm_fb_helper_connector *fb_help_conn = connector->fb_helper_private;
  660. struct drm_fb_helper_cmdline_mode *cmdline_mode;
  661. if (!fb_help_conn)
  662. continue;
  663. cmdline_mode = &fb_help_conn->cmdline_mode;
  664. if (cmdline_mode->bpp_specified) {
  665. switch (cmdline_mode->bpp) {
  666. case 8:
  667. sizes.surface_depth = sizes.surface_bpp = 8;
  668. break;
  669. case 15:
  670. sizes.surface_depth = 15;
  671. sizes.surface_bpp = 16;
  672. break;
  673. case 16:
  674. sizes.surface_depth = sizes.surface_bpp = 16;
  675. break;
  676. case 24:
  677. sizes.surface_depth = sizes.surface_bpp = 24;
  678. break;
  679. case 32:
  680. sizes.surface_depth = 24;
  681. sizes.surface_bpp = 32;
  682. break;
  683. }
  684. break;
  685. }
  686. }
  687. crtc_count = 0;
  688. for (i = 0; i < fb_helper->crtc_count; i++) {
  689. struct drm_display_mode *desired_mode;
  690. desired_mode = fb_helper->crtc_info[i].desired_mode;
  691. if (desired_mode) {
  692. if (gamma_size == 0)
  693. gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
  694. if (desired_mode->hdisplay < sizes.fb_width)
  695. sizes.fb_width = desired_mode->hdisplay;
  696. if (desired_mode->vdisplay < sizes.fb_height)
  697. sizes.fb_height = desired_mode->vdisplay;
  698. if (desired_mode->hdisplay > sizes.surface_width)
  699. sizes.surface_width = desired_mode->hdisplay;
  700. if (desired_mode->vdisplay > sizes.surface_height)
  701. sizes.surface_height = desired_mode->vdisplay;
  702. crtc_count++;
  703. }
  704. }
  705. if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
  706. /* hmm everyone went away - assume VGA cable just fell out
  707. and will come back later. */
  708. return 0;
  709. }
  710. /* push down into drivers */
  711. new_fb = (*fb_helper->fb_probe)(fb_helper, &sizes);
  712. if (new_fb < 0)
  713. return new_fb;
  714. info = fb_helper->fbdev;
  715. /* set the fb pointer */
  716. for (i = 0; i < fb_helper->crtc_count; i++) {
  717. fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
  718. }
  719. if (new_fb) {
  720. info->var.pixclock = 0;
  721. ret = fb_alloc_cmap(&info->cmap, gamma_size, 0);
  722. if (ret)
  723. return ret;
  724. if (register_framebuffer(info) < 0) {
  725. fb_dealloc_cmap(&info->cmap);
  726. return -EINVAL;
  727. }
  728. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  729. info->fix.id);
  730. } else {
  731. drm_fb_helper_set_par(info);
  732. }
  733. /* Switch back to kernel console on panic */
  734. /* multi card linked list maybe */
  735. if (list_empty(&kernel_fb_helper_list)) {
  736. printk(KERN_INFO "registered panic notifier\n");
  737. atomic_notifier_chain_register(&panic_notifier_list,
  738. &paniced);
  739. register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
  740. }
  741. if (new_fb)
  742. list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
  743. return 0;
  744. }
  745. EXPORT_SYMBOL(drm_fb_helper_single_fb_probe);
  746. void drm_fb_helper_free(struct drm_fb_helper *helper)
  747. {
  748. if (!list_empty(&helper->kernel_fb_list)) {
  749. list_del(&helper->kernel_fb_list);
  750. if (list_empty(&kernel_fb_helper_list)) {
  751. printk(KERN_INFO "unregistered panic notifier\n");
  752. atomic_notifier_chain_unregister(&panic_notifier_list,
  753. &paniced);
  754. unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
  755. }
  756. }
  757. drm_fb_helper_crtc_free(helper);
  758. if (helper->fbdev->cmap.len)
  759. fb_dealloc_cmap(&helper->fbdev->cmap);
  760. }
  761. EXPORT_SYMBOL(drm_fb_helper_free);
  762. void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
  763. uint32_t depth)
  764. {
  765. info->fix.type = FB_TYPE_PACKED_PIXELS;
  766. info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
  767. FB_VISUAL_TRUECOLOR;
  768. info->fix.type_aux = 0;
  769. info->fix.xpanstep = 1; /* doing it in hw */
  770. info->fix.ypanstep = 1; /* doing it in hw */
  771. info->fix.ywrapstep = 0;
  772. info->fix.accel = FB_ACCEL_NONE;
  773. info->fix.type_aux = 0;
  774. info->fix.line_length = pitch;
  775. return;
  776. }
  777. EXPORT_SYMBOL(drm_fb_helper_fill_fix);
  778. void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
  779. uint32_t fb_width, uint32_t fb_height)
  780. {
  781. struct drm_framebuffer *fb = fb_helper->fb;
  782. info->pseudo_palette = fb_helper->pseudo_palette;
  783. info->var.xres_virtual = fb->width;
  784. info->var.yres_virtual = fb->height;
  785. info->var.bits_per_pixel = fb->bits_per_pixel;
  786. info->var.xoffset = 0;
  787. info->var.yoffset = 0;
  788. info->var.activate = FB_ACTIVATE_NOW;
  789. info->var.height = -1;
  790. info->var.width = -1;
  791. switch (fb->depth) {
  792. case 8:
  793. info->var.red.offset = 0;
  794. info->var.green.offset = 0;
  795. info->var.blue.offset = 0;
  796. info->var.red.length = 8; /* 8bit DAC */
  797. info->var.green.length = 8;
  798. info->var.blue.length = 8;
  799. info->var.transp.offset = 0;
  800. info->var.transp.length = 0;
  801. break;
  802. case 15:
  803. info->var.red.offset = 10;
  804. info->var.green.offset = 5;
  805. info->var.blue.offset = 0;
  806. info->var.red.length = 5;
  807. info->var.green.length = 5;
  808. info->var.blue.length = 5;
  809. info->var.transp.offset = 15;
  810. info->var.transp.length = 1;
  811. break;
  812. case 16:
  813. info->var.red.offset = 11;
  814. info->var.green.offset = 5;
  815. info->var.blue.offset = 0;
  816. info->var.red.length = 5;
  817. info->var.green.length = 6;
  818. info->var.blue.length = 5;
  819. info->var.transp.offset = 0;
  820. break;
  821. case 24:
  822. info->var.red.offset = 16;
  823. info->var.green.offset = 8;
  824. info->var.blue.offset = 0;
  825. info->var.red.length = 8;
  826. info->var.green.length = 8;
  827. info->var.blue.length = 8;
  828. info->var.transp.offset = 0;
  829. info->var.transp.length = 0;
  830. break;
  831. case 32:
  832. info->var.red.offset = 16;
  833. info->var.green.offset = 8;
  834. info->var.blue.offset = 0;
  835. info->var.red.length = 8;
  836. info->var.green.length = 8;
  837. info->var.blue.length = 8;
  838. info->var.transp.offset = 24;
  839. info->var.transp.length = 8;
  840. break;
  841. default:
  842. break;
  843. }
  844. info->var.xres = fb_width;
  845. info->var.yres = fb_height;
  846. }
  847. EXPORT_SYMBOL(drm_fb_helper_fill_var);
  848. static int drm_helper_probe_connector_modes(struct drm_device *dev, uint32_t maxX,
  849. uint32_t maxY)
  850. {
  851. struct drm_connector *connector;
  852. int count = 0;
  853. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  854. count += connector->funcs->fill_modes(connector, maxX, maxY);
  855. }
  856. return count;
  857. }
  858. static struct drm_display_mode *drm_has_preferred_mode(struct drm_connector *connector, int width, int height)
  859. {
  860. struct drm_display_mode *mode;
  861. list_for_each_entry(mode, &connector->modes, head) {
  862. if (drm_mode_width(mode) > width ||
  863. drm_mode_height(mode) > height)
  864. continue;
  865. if (mode->type & DRM_MODE_TYPE_PREFERRED)
  866. return mode;
  867. }
  868. return NULL;
  869. }
  870. static bool drm_has_cmdline_mode(struct drm_connector *connector)
  871. {
  872. struct drm_fb_helper_connector *fb_help_conn = connector->fb_helper_private;
  873. struct drm_fb_helper_cmdline_mode *cmdline_mode;
  874. if (!fb_help_conn)
  875. return false;
  876. cmdline_mode = &fb_help_conn->cmdline_mode;
  877. return cmdline_mode->specified;
  878. }
  879. static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_connector *connector, int width, int height)
  880. {
  881. struct drm_fb_helper_connector *fb_help_conn = connector->fb_helper_private;
  882. struct drm_fb_helper_cmdline_mode *cmdline_mode;
  883. struct drm_display_mode *mode = NULL;
  884. if (!fb_help_conn)
  885. return mode;
  886. cmdline_mode = &fb_help_conn->cmdline_mode;
  887. if (cmdline_mode->specified == false)
  888. return mode;
  889. /* attempt to find a matching mode in the list of modes
  890. * we have gotten so far, if not add a CVT mode that conforms
  891. */
  892. if (cmdline_mode->rb || cmdline_mode->margins)
  893. goto create_mode;
  894. list_for_each_entry(mode, &connector->modes, head) {
  895. /* check width/height */
  896. if (mode->hdisplay != cmdline_mode->xres ||
  897. mode->vdisplay != cmdline_mode->yres)
  898. continue;
  899. if (cmdline_mode->refresh_specified) {
  900. if (mode->vrefresh != cmdline_mode->refresh)
  901. continue;
  902. }
  903. if (cmdline_mode->interlace) {
  904. if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
  905. continue;
  906. }
  907. return mode;
  908. }
  909. create_mode:
  910. mode = drm_cvt_mode(connector->dev, cmdline_mode->xres,
  911. cmdline_mode->yres,
  912. cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60,
  913. cmdline_mode->rb, cmdline_mode->interlace,
  914. cmdline_mode->margins);
  915. drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
  916. list_add(&mode->head, &connector->modes);
  917. return mode;
  918. }
  919. static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
  920. {
  921. bool enable;
  922. if (strict) {
  923. enable = connector->status == connector_status_connected;
  924. } else {
  925. enable = connector->status != connector_status_disconnected;
  926. }
  927. return enable;
  928. }
  929. static void drm_enable_connectors(struct drm_device *dev, bool *enabled)
  930. {
  931. bool any_enabled = false;
  932. struct drm_connector *connector;
  933. int i = 0;
  934. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  935. enabled[i] = drm_connector_enabled(connector, true);
  936. DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
  937. enabled[i] ? "yes" : "no");
  938. any_enabled |= enabled[i];
  939. i++;
  940. }
  941. if (any_enabled)
  942. return;
  943. i = 0;
  944. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  945. enabled[i] = drm_connector_enabled(connector, false);
  946. i++;
  947. }
  948. }
  949. static bool drm_target_preferred(struct drm_device *dev,
  950. struct drm_display_mode **modes,
  951. bool *enabled, int width, int height)
  952. {
  953. struct drm_connector *connector;
  954. int i = 0;
  955. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  956. if (enabled[i] == false) {
  957. i++;
  958. continue;
  959. }
  960. DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
  961. connector->base.id);
  962. /* got for command line mode first */
  963. modes[i] = drm_pick_cmdline_mode(connector, width, height);
  964. if (!modes[i]) {
  965. DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
  966. connector->base.id);
  967. modes[i] = drm_has_preferred_mode(connector, width, height);
  968. }
  969. /* No preferred modes, pick one off the list */
  970. if (!modes[i] && !list_empty(&connector->modes)) {
  971. list_for_each_entry(modes[i], &connector->modes, head)
  972. break;
  973. }
  974. DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
  975. "none");
  976. i++;
  977. }
  978. return true;
  979. }
  980. static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
  981. struct drm_fb_helper_crtc **best_crtcs,
  982. struct drm_display_mode **modes,
  983. int n, int width, int height)
  984. {
  985. int c, o;
  986. struct drm_device *dev = fb_helper->dev;
  987. struct drm_connector *connector;
  988. struct drm_connector_helper_funcs *connector_funcs;
  989. struct drm_encoder *encoder;
  990. struct drm_fb_helper_crtc *best_crtc;
  991. int my_score, best_score, score;
  992. struct drm_fb_helper_crtc **crtcs, *crtc;
  993. if (n == fb_helper->dev->mode_config.num_connector)
  994. return 0;
  995. c = 0;
  996. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  997. if (c == n)
  998. break;
  999. c++;
  1000. }
  1001. best_crtcs[n] = NULL;
  1002. best_crtc = NULL;
  1003. best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
  1004. if (modes[n] == NULL)
  1005. return best_score;
  1006. crtcs = kzalloc(dev->mode_config.num_connector *
  1007. sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
  1008. if (!crtcs)
  1009. return best_score;
  1010. my_score = 1;
  1011. if (connector->status == connector_status_connected)
  1012. my_score++;
  1013. if (drm_has_cmdline_mode(connector))
  1014. my_score++;
  1015. if (drm_has_preferred_mode(connector, width, height))
  1016. my_score++;
  1017. connector_funcs = connector->helper_private;
  1018. encoder = connector_funcs->best_encoder(connector);
  1019. if (!encoder)
  1020. goto out;
  1021. /* select a crtc for this connector and then attempt to configure
  1022. remaining connectors */
  1023. for (c = 0; c < fb_helper->crtc_count; c++) {
  1024. crtc = &fb_helper->crtc_info[c];
  1025. if ((encoder->possible_crtcs & (1 << c)) == 0) {
  1026. continue;
  1027. }
  1028. for (o = 0; o < n; o++)
  1029. if (best_crtcs[o] == crtc)
  1030. break;
  1031. if (o < n) {
  1032. /* ignore cloning for now */
  1033. continue;
  1034. }
  1035. crtcs[n] = crtc;
  1036. memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
  1037. score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
  1038. width, height);
  1039. if (score > best_score) {
  1040. best_crtc = crtc;
  1041. best_score = score;
  1042. memcpy(best_crtcs, crtcs,
  1043. dev->mode_config.num_connector *
  1044. sizeof(struct drm_fb_helper_crtc *));
  1045. }
  1046. }
  1047. out:
  1048. kfree(crtcs);
  1049. return best_score;
  1050. }
  1051. static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
  1052. {
  1053. struct drm_device *dev = fb_helper->dev;
  1054. struct drm_fb_helper_crtc **crtcs;
  1055. struct drm_display_mode **modes;
  1056. struct drm_encoder *encoder;
  1057. struct drm_connector *connector;
  1058. struct drm_mode_set *modeset;
  1059. bool *enabled;
  1060. int width, height;
  1061. int i, ret;
  1062. DRM_DEBUG_KMS("\n");
  1063. width = dev->mode_config.max_width;
  1064. height = dev->mode_config.max_height;
  1065. /* clean out all the encoder/crtc combos */
  1066. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1067. encoder->crtc = NULL;
  1068. }
  1069. crtcs = kcalloc(dev->mode_config.num_connector,
  1070. sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
  1071. modes = kcalloc(dev->mode_config.num_connector,
  1072. sizeof(struct drm_display_mode *), GFP_KERNEL);
  1073. enabled = kcalloc(dev->mode_config.num_connector,
  1074. sizeof(bool), GFP_KERNEL);
  1075. drm_enable_connectors(dev, enabled);
  1076. ret = drm_target_preferred(dev, modes, enabled, width, height);
  1077. if (!ret)
  1078. DRM_ERROR("Unable to find initial modes\n");
  1079. DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height);
  1080. drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
  1081. /* need to set the modesets up here for use later */
  1082. /* fill out the connector<->crtc mappings into the modesets */
  1083. for (i = 0; i < fb_helper->crtc_count; i++) {
  1084. modeset = &fb_helper->crtc_info[i].mode_set;
  1085. modeset->num_connectors = 0;
  1086. }
  1087. i = 0;
  1088. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1089. struct drm_display_mode *mode = modes[i];
  1090. struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
  1091. modeset = &fb_crtc->mode_set;
  1092. if (mode && fb_crtc) {
  1093. DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
  1094. mode->name, fb_crtc->mode_set.crtc->base.id);
  1095. fb_crtc->desired_mode = mode;
  1096. if (modeset->mode)
  1097. drm_mode_destroy(dev, modeset->mode);
  1098. modeset->mode = drm_mode_duplicate(dev,
  1099. fb_crtc->desired_mode);
  1100. modeset->connectors[modeset->num_connectors++] = connector;
  1101. }
  1102. i++;
  1103. }
  1104. kfree(crtcs);
  1105. kfree(modes);
  1106. kfree(enabled);
  1107. }
  1108. /**
  1109. * drm_helper_initial_config - setup a sane initial connector configuration
  1110. * @dev: DRM device
  1111. *
  1112. * LOCKING:
  1113. * Called at init time, must take mode config lock.
  1114. *
  1115. * Scan the CRTCs and connectors and try to put together an initial setup.
  1116. * At the moment, this is a cloned configuration across all heads with
  1117. * a new framebuffer object as the backing store.
  1118. *
  1119. * RETURNS:
  1120. * Zero if everything went ok, nonzero otherwise.
  1121. */
  1122. bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper)
  1123. {
  1124. struct drm_device *dev = fb_helper->dev;
  1125. int count = 0;
  1126. /* disable all the possible outputs/crtcs before entering KMS mode */
  1127. drm_helper_disable_unused_functions(fb_helper->dev);
  1128. drm_fb_helper_parse_command_line(fb_helper->dev);
  1129. count = drm_helper_probe_connector_modes(dev,
  1130. dev->mode_config.max_width,
  1131. dev->mode_config.max_height);
  1132. /*
  1133. * we shouldn't end up with no modes here.
  1134. */
  1135. if (count == 0)
  1136. printk(KERN_INFO "No connectors reported connected with modes\n");
  1137. drm_setup_crtcs(fb_helper);
  1138. return 0;
  1139. }
  1140. EXPORT_SYMBOL(drm_fb_helper_initial_config);
  1141. bool drm_helper_fb_hotplug_event(struct drm_fb_helper *fb_helper,
  1142. u32 max_width, u32 max_height)
  1143. {
  1144. DRM_DEBUG_KMS("\n");
  1145. drm_helper_probe_connector_modes(fb_helper->dev, max_width,
  1146. max_height);
  1147. drm_setup_crtcs(fb_helper);
  1148. return true;
  1149. }
  1150. EXPORT_SYMBOL(drm_helper_fb_hotplug_event);