drm_modes.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /*
  2. * Copyright © 1997-2003 by The XFree86 Project, Inc.
  3. * Copyright © 2007 Dave Airlie
  4. * Copyright © 2007-2008 Intel Corporation
  5. * Jesse Barnes <jesse.barnes@intel.com>
  6. * Copyright 2005-2006 Luc Verhaegen
  7. * Copyright (c) 2001, Andy Ritger aritger@nvidia.com
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. * Except as contained in this notice, the name of the copyright holder(s)
  28. * and author(s) shall not be used in advertising or otherwise to promote
  29. * the sale, use or other dealings in this Software without prior written
  30. * authorization from the copyright holder(s) and author(s).
  31. */
  32. #include <linux/list.h>
  33. #include <linux/list_sort.h>
  34. #include <linux/export.h>
  35. #include "drmP.h"
  36. #include "drm.h"
  37. #include "drm_crtc.h"
  38. /**
  39. * drm_mode_debug_printmodeline - debug print a mode
  40. * @dev: DRM device
  41. * @mode: mode to print
  42. *
  43. * LOCKING:
  44. * None.
  45. *
  46. * Describe @mode using DRM_DEBUG.
  47. */
  48. void drm_mode_debug_printmodeline(struct drm_display_mode *mode)
  49. {
  50. DRM_DEBUG_KMS("Modeline %d:\"%s\" %d %d %d %d %d %d %d %d %d %d "
  51. "0x%x 0x%x\n",
  52. mode->base.id, mode->name, mode->vrefresh, mode->clock,
  53. mode->hdisplay, mode->hsync_start,
  54. mode->hsync_end, mode->htotal,
  55. mode->vdisplay, mode->vsync_start,
  56. mode->vsync_end, mode->vtotal, mode->type, mode->flags);
  57. }
  58. EXPORT_SYMBOL(drm_mode_debug_printmodeline);
  59. /**
  60. * drm_cvt_mode -create a modeline based on CVT algorithm
  61. * @dev: DRM device
  62. * @hdisplay: hdisplay size
  63. * @vdisplay: vdisplay size
  64. * @vrefresh : vrefresh rate
  65. * @reduced : Whether the GTF calculation is simplified
  66. * @interlaced:Whether the interlace is supported
  67. *
  68. * LOCKING:
  69. * none.
  70. *
  71. * return the modeline based on CVT algorithm
  72. *
  73. * This function is called to generate the modeline based on CVT algorithm
  74. * according to the hdisplay, vdisplay, vrefresh.
  75. * It is based from the VESA(TM) Coordinated Video Timing Generator by
  76. * Graham Loveridge April 9, 2003 available at
  77. * http://www.elo.utfsm.cl/~elo212/docs/CVTd6r1.xls
  78. *
  79. * And it is copied from xf86CVTmode in xserver/hw/xfree86/modes/xf86cvt.c.
  80. * What I have done is to translate it by using integer calculation.
  81. */
  82. #define HV_FACTOR 1000
  83. struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, int hdisplay,
  84. int vdisplay, int vrefresh,
  85. bool reduced, bool interlaced, bool margins)
  86. {
  87. /* 1) top/bottom margin size (% of height) - default: 1.8, */
  88. #define CVT_MARGIN_PERCENTAGE 18
  89. /* 2) character cell horizontal granularity (pixels) - default 8 */
  90. #define CVT_H_GRANULARITY 8
  91. /* 3) Minimum vertical porch (lines) - default 3 */
  92. #define CVT_MIN_V_PORCH 3
  93. /* 4) Minimum number of vertical back porch lines - default 6 */
  94. #define CVT_MIN_V_BPORCH 6
  95. /* Pixel Clock step (kHz) */
  96. #define CVT_CLOCK_STEP 250
  97. struct drm_display_mode *drm_mode;
  98. unsigned int vfieldrate, hperiod;
  99. int hdisplay_rnd, hmargin, vdisplay_rnd, vmargin, vsync;
  100. int interlace;
  101. /* allocate the drm_display_mode structure. If failure, we will
  102. * return directly
  103. */
  104. drm_mode = drm_mode_create(dev);
  105. if (!drm_mode)
  106. return NULL;
  107. /* the CVT default refresh rate is 60Hz */
  108. if (!vrefresh)
  109. vrefresh = 60;
  110. /* the required field fresh rate */
  111. if (interlaced)
  112. vfieldrate = vrefresh * 2;
  113. else
  114. vfieldrate = vrefresh;
  115. /* horizontal pixels */
  116. hdisplay_rnd = hdisplay - (hdisplay % CVT_H_GRANULARITY);
  117. /* determine the left&right borders */
  118. hmargin = 0;
  119. if (margins) {
  120. hmargin = hdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000;
  121. hmargin -= hmargin % CVT_H_GRANULARITY;
  122. }
  123. /* find the total active pixels */
  124. drm_mode->hdisplay = hdisplay_rnd + 2 * hmargin;
  125. /* find the number of lines per field */
  126. if (interlaced)
  127. vdisplay_rnd = vdisplay / 2;
  128. else
  129. vdisplay_rnd = vdisplay;
  130. /* find the top & bottom borders */
  131. vmargin = 0;
  132. if (margins)
  133. vmargin = vdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000;
  134. drm_mode->vdisplay = vdisplay + 2 * vmargin;
  135. /* Interlaced */
  136. if (interlaced)
  137. interlace = 1;
  138. else
  139. interlace = 0;
  140. /* Determine VSync Width from aspect ratio */
  141. if (!(vdisplay % 3) && ((vdisplay * 4 / 3) == hdisplay))
  142. vsync = 4;
  143. else if (!(vdisplay % 9) && ((vdisplay * 16 / 9) == hdisplay))
  144. vsync = 5;
  145. else if (!(vdisplay % 10) && ((vdisplay * 16 / 10) == hdisplay))
  146. vsync = 6;
  147. else if (!(vdisplay % 4) && ((vdisplay * 5 / 4) == hdisplay))
  148. vsync = 7;
  149. else if (!(vdisplay % 9) && ((vdisplay * 15 / 9) == hdisplay))
  150. vsync = 7;
  151. else /* custom */
  152. vsync = 10;
  153. if (!reduced) {
  154. /* simplify the GTF calculation */
  155. /* 4) Minimum time of vertical sync + back porch interval (µs)
  156. * default 550.0
  157. */
  158. int tmp1, tmp2;
  159. #define CVT_MIN_VSYNC_BP 550
  160. /* 3) Nominal HSync width (% of line period) - default 8 */
  161. #define CVT_HSYNC_PERCENTAGE 8
  162. unsigned int hblank_percentage;
  163. int vsyncandback_porch, vback_porch, hblank;
  164. /* estimated the horizontal period */
  165. tmp1 = HV_FACTOR * 1000000 -
  166. CVT_MIN_VSYNC_BP * HV_FACTOR * vfieldrate;
  167. tmp2 = (vdisplay_rnd + 2 * vmargin + CVT_MIN_V_PORCH) * 2 +
  168. interlace;
  169. hperiod = tmp1 * 2 / (tmp2 * vfieldrate);
  170. tmp1 = CVT_MIN_VSYNC_BP * HV_FACTOR / hperiod + 1;
  171. /* 9. Find number of lines in sync + backporch */
  172. if (tmp1 < (vsync + CVT_MIN_V_PORCH))
  173. vsyncandback_porch = vsync + CVT_MIN_V_PORCH;
  174. else
  175. vsyncandback_porch = tmp1;
  176. /* 10. Find number of lines in back porch */
  177. vback_porch = vsyncandback_porch - vsync;
  178. drm_mode->vtotal = vdisplay_rnd + 2 * vmargin +
  179. vsyncandback_porch + CVT_MIN_V_PORCH;
  180. /* 5) Definition of Horizontal blanking time limitation */
  181. /* Gradient (%/kHz) - default 600 */
  182. #define CVT_M_FACTOR 600
  183. /* Offset (%) - default 40 */
  184. #define CVT_C_FACTOR 40
  185. /* Blanking time scaling factor - default 128 */
  186. #define CVT_K_FACTOR 128
  187. /* Scaling factor weighting - default 20 */
  188. #define CVT_J_FACTOR 20
  189. #define CVT_M_PRIME (CVT_M_FACTOR * CVT_K_FACTOR / 256)
  190. #define CVT_C_PRIME ((CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \
  191. CVT_J_FACTOR)
  192. /* 12. Find ideal blanking duty cycle from formula */
  193. hblank_percentage = CVT_C_PRIME * HV_FACTOR - CVT_M_PRIME *
  194. hperiod / 1000;
  195. /* 13. Blanking time */
  196. if (hblank_percentage < 20 * HV_FACTOR)
  197. hblank_percentage = 20 * HV_FACTOR;
  198. hblank = drm_mode->hdisplay * hblank_percentage /
  199. (100 * HV_FACTOR - hblank_percentage);
  200. hblank -= hblank % (2 * CVT_H_GRANULARITY);
  201. /* 14. find the total pixes per line */
  202. drm_mode->htotal = drm_mode->hdisplay + hblank;
  203. drm_mode->hsync_end = drm_mode->hdisplay + hblank / 2;
  204. drm_mode->hsync_start = drm_mode->hsync_end -
  205. (drm_mode->htotal * CVT_HSYNC_PERCENTAGE) / 100;
  206. drm_mode->hsync_start += CVT_H_GRANULARITY -
  207. drm_mode->hsync_start % CVT_H_GRANULARITY;
  208. /* fill the Vsync values */
  209. drm_mode->vsync_start = drm_mode->vdisplay + CVT_MIN_V_PORCH;
  210. drm_mode->vsync_end = drm_mode->vsync_start + vsync;
  211. } else {
  212. /* Reduced blanking */
  213. /* Minimum vertical blanking interval time (µs)- default 460 */
  214. #define CVT_RB_MIN_VBLANK 460
  215. /* Fixed number of clocks for horizontal sync */
  216. #define CVT_RB_H_SYNC 32
  217. /* Fixed number of clocks for horizontal blanking */
  218. #define CVT_RB_H_BLANK 160
  219. /* Fixed number of lines for vertical front porch - default 3*/
  220. #define CVT_RB_VFPORCH 3
  221. int vbilines;
  222. int tmp1, tmp2;
  223. /* 8. Estimate Horizontal period. */
  224. tmp1 = HV_FACTOR * 1000000 -
  225. CVT_RB_MIN_VBLANK * HV_FACTOR * vfieldrate;
  226. tmp2 = vdisplay_rnd + 2 * vmargin;
  227. hperiod = tmp1 / (tmp2 * vfieldrate);
  228. /* 9. Find number of lines in vertical blanking */
  229. vbilines = CVT_RB_MIN_VBLANK * HV_FACTOR / hperiod + 1;
  230. /* 10. Check if vertical blanking is sufficient */
  231. if (vbilines < (CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH))
  232. vbilines = CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH;
  233. /* 11. Find total number of lines in vertical field */
  234. drm_mode->vtotal = vdisplay_rnd + 2 * vmargin + vbilines;
  235. /* 12. Find total number of pixels in a line */
  236. drm_mode->htotal = drm_mode->hdisplay + CVT_RB_H_BLANK;
  237. /* Fill in HSync values */
  238. drm_mode->hsync_end = drm_mode->hdisplay + CVT_RB_H_BLANK / 2;
  239. drm_mode->hsync_start = drm_mode->hsync_end - CVT_RB_H_SYNC;
  240. /* Fill in VSync values */
  241. drm_mode->vsync_start = drm_mode->vdisplay + CVT_RB_VFPORCH;
  242. drm_mode->vsync_end = drm_mode->vsync_start + vsync;
  243. }
  244. /* 15/13. Find pixel clock frequency (kHz for xf86) */
  245. drm_mode->clock = drm_mode->htotal * HV_FACTOR * 1000 / hperiod;
  246. drm_mode->clock -= drm_mode->clock % CVT_CLOCK_STEP;
  247. /* 18/16. Find actual vertical frame frequency */
  248. /* ignore - just set the mode flag for interlaced */
  249. if (interlaced) {
  250. drm_mode->vtotal *= 2;
  251. drm_mode->flags |= DRM_MODE_FLAG_INTERLACE;
  252. }
  253. /* Fill the mode line name */
  254. drm_mode_set_name(drm_mode);
  255. if (reduced)
  256. drm_mode->flags |= (DRM_MODE_FLAG_PHSYNC |
  257. DRM_MODE_FLAG_NVSYNC);
  258. else
  259. drm_mode->flags |= (DRM_MODE_FLAG_PVSYNC |
  260. DRM_MODE_FLAG_NHSYNC);
  261. return drm_mode;
  262. }
  263. EXPORT_SYMBOL(drm_cvt_mode);
  264. /**
  265. * drm_gtf_mode_complex - create the modeline based on full GTF algorithm
  266. *
  267. * @dev :drm device
  268. * @hdisplay :hdisplay size
  269. * @vdisplay :vdisplay size
  270. * @vrefresh :vrefresh rate.
  271. * @interlaced :whether the interlace is supported
  272. * @margins :desired margin size
  273. * @GTF_[MCKJ] :extended GTF formula parameters
  274. *
  275. * LOCKING.
  276. * none.
  277. *
  278. * return the modeline based on full GTF algorithm.
  279. *
  280. * GTF feature blocks specify C and J in multiples of 0.5, so we pass them
  281. * in here multiplied by two. For a C of 40, pass in 80.
  282. */
  283. struct drm_display_mode *
  284. drm_gtf_mode_complex(struct drm_device *dev, int hdisplay, int vdisplay,
  285. int vrefresh, bool interlaced, int margins,
  286. int GTF_M, int GTF_2C, int GTF_K, int GTF_2J)
  287. { /* 1) top/bottom margin size (% of height) - default: 1.8, */
  288. #define GTF_MARGIN_PERCENTAGE 18
  289. /* 2) character cell horizontal granularity (pixels) - default 8 */
  290. #define GTF_CELL_GRAN 8
  291. /* 3) Minimum vertical porch (lines) - default 3 */
  292. #define GTF_MIN_V_PORCH 1
  293. /* width of vsync in lines */
  294. #define V_SYNC_RQD 3
  295. /* width of hsync as % of total line */
  296. #define H_SYNC_PERCENT 8
  297. /* min time of vsync + back porch (microsec) */
  298. #define MIN_VSYNC_PLUS_BP 550
  299. /* C' and M' are part of the Blanking Duty Cycle computation */
  300. #define GTF_C_PRIME ((((GTF_2C - GTF_2J) * GTF_K / 256) + GTF_2J) / 2)
  301. #define GTF_M_PRIME (GTF_K * GTF_M / 256)
  302. struct drm_display_mode *drm_mode;
  303. unsigned int hdisplay_rnd, vdisplay_rnd, vfieldrate_rqd;
  304. int top_margin, bottom_margin;
  305. int interlace;
  306. unsigned int hfreq_est;
  307. int vsync_plus_bp, vback_porch;
  308. unsigned int vtotal_lines, vfieldrate_est, hperiod;
  309. unsigned int vfield_rate, vframe_rate;
  310. int left_margin, right_margin;
  311. unsigned int total_active_pixels, ideal_duty_cycle;
  312. unsigned int hblank, total_pixels, pixel_freq;
  313. int hsync, hfront_porch, vodd_front_porch_lines;
  314. unsigned int tmp1, tmp2;
  315. drm_mode = drm_mode_create(dev);
  316. if (!drm_mode)
  317. return NULL;
  318. /* 1. In order to give correct results, the number of horizontal
  319. * pixels requested is first processed to ensure that it is divisible
  320. * by the character size, by rounding it to the nearest character
  321. * cell boundary:
  322. */
  323. hdisplay_rnd = (hdisplay + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN;
  324. hdisplay_rnd = hdisplay_rnd * GTF_CELL_GRAN;
  325. /* 2. If interlace is requested, the number of vertical lines assumed
  326. * by the calculation must be halved, as the computation calculates
  327. * the number of vertical lines per field.
  328. */
  329. if (interlaced)
  330. vdisplay_rnd = vdisplay / 2;
  331. else
  332. vdisplay_rnd = vdisplay;
  333. /* 3. Find the frame rate required: */
  334. if (interlaced)
  335. vfieldrate_rqd = vrefresh * 2;
  336. else
  337. vfieldrate_rqd = vrefresh;
  338. /* 4. Find number of lines in Top margin: */
  339. top_margin = 0;
  340. if (margins)
  341. top_margin = (vdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) /
  342. 1000;
  343. /* 5. Find number of lines in bottom margin: */
  344. bottom_margin = top_margin;
  345. /* 6. If interlace is required, then set variable interlace: */
  346. if (interlaced)
  347. interlace = 1;
  348. else
  349. interlace = 0;
  350. /* 7. Estimate the Horizontal frequency */
  351. {
  352. tmp1 = (1000000 - MIN_VSYNC_PLUS_BP * vfieldrate_rqd) / 500;
  353. tmp2 = (vdisplay_rnd + 2 * top_margin + GTF_MIN_V_PORCH) *
  354. 2 + interlace;
  355. hfreq_est = (tmp2 * 1000 * vfieldrate_rqd) / tmp1;
  356. }
  357. /* 8. Find the number of lines in V sync + back porch */
  358. /* [V SYNC+BP] = RINT(([MIN VSYNC+BP] * hfreq_est / 1000000)) */
  359. vsync_plus_bp = MIN_VSYNC_PLUS_BP * hfreq_est / 1000;
  360. vsync_plus_bp = (vsync_plus_bp + 500) / 1000;
  361. /* 9. Find the number of lines in V back porch alone: */
  362. vback_porch = vsync_plus_bp - V_SYNC_RQD;
  363. /* 10. Find the total number of lines in Vertical field period: */
  364. vtotal_lines = vdisplay_rnd + top_margin + bottom_margin +
  365. vsync_plus_bp + GTF_MIN_V_PORCH;
  366. /* 11. Estimate the Vertical field frequency: */
  367. vfieldrate_est = hfreq_est / vtotal_lines;
  368. /* 12. Find the actual horizontal period: */
  369. hperiod = 1000000 / (vfieldrate_rqd * vtotal_lines);
  370. /* 13. Find the actual Vertical field frequency: */
  371. vfield_rate = hfreq_est / vtotal_lines;
  372. /* 14. Find the Vertical frame frequency: */
  373. if (interlaced)
  374. vframe_rate = vfield_rate / 2;
  375. else
  376. vframe_rate = vfield_rate;
  377. /* 15. Find number of pixels in left margin: */
  378. if (margins)
  379. left_margin = (hdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) /
  380. 1000;
  381. else
  382. left_margin = 0;
  383. /* 16.Find number of pixels in right margin: */
  384. right_margin = left_margin;
  385. /* 17.Find total number of active pixels in image and left and right */
  386. total_active_pixels = hdisplay_rnd + left_margin + right_margin;
  387. /* 18.Find the ideal blanking duty cycle from blanking duty cycle */
  388. ideal_duty_cycle = GTF_C_PRIME * 1000 -
  389. (GTF_M_PRIME * 1000000 / hfreq_est);
  390. /* 19.Find the number of pixels in the blanking time to the nearest
  391. * double character cell: */
  392. hblank = total_active_pixels * ideal_duty_cycle /
  393. (100000 - ideal_duty_cycle);
  394. hblank = (hblank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN);
  395. hblank = hblank * 2 * GTF_CELL_GRAN;
  396. /* 20.Find total number of pixels: */
  397. total_pixels = total_active_pixels + hblank;
  398. /* 21.Find pixel clock frequency: */
  399. pixel_freq = total_pixels * hfreq_est / 1000;
  400. /* Stage 1 computations are now complete; I should really pass
  401. * the results to another function and do the Stage 2 computations,
  402. * but I only need a few more values so I'll just append the
  403. * computations here for now */
  404. /* 17. Find the number of pixels in the horizontal sync period: */
  405. hsync = H_SYNC_PERCENT * total_pixels / 100;
  406. hsync = (hsync + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN;
  407. hsync = hsync * GTF_CELL_GRAN;
  408. /* 18. Find the number of pixels in horizontal front porch period */
  409. hfront_porch = hblank / 2 - hsync;
  410. /* 36. Find the number of lines in the odd front porch period: */
  411. vodd_front_porch_lines = GTF_MIN_V_PORCH ;
  412. /* finally, pack the results in the mode struct */
  413. drm_mode->hdisplay = hdisplay_rnd;
  414. drm_mode->hsync_start = hdisplay_rnd + hfront_porch;
  415. drm_mode->hsync_end = drm_mode->hsync_start + hsync;
  416. drm_mode->htotal = total_pixels;
  417. drm_mode->vdisplay = vdisplay_rnd;
  418. drm_mode->vsync_start = vdisplay_rnd + vodd_front_porch_lines;
  419. drm_mode->vsync_end = drm_mode->vsync_start + V_SYNC_RQD;
  420. drm_mode->vtotal = vtotal_lines;
  421. drm_mode->clock = pixel_freq;
  422. if (interlaced) {
  423. drm_mode->vtotal *= 2;
  424. drm_mode->flags |= DRM_MODE_FLAG_INTERLACE;
  425. }
  426. drm_mode_set_name(drm_mode);
  427. if (GTF_M == 600 && GTF_2C == 80 && GTF_K == 128 && GTF_2J == 40)
  428. drm_mode->flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC;
  429. else
  430. drm_mode->flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC;
  431. return drm_mode;
  432. }
  433. EXPORT_SYMBOL(drm_gtf_mode_complex);
  434. /**
  435. * drm_gtf_mode - create the modeline based on GTF algorithm
  436. *
  437. * @dev :drm device
  438. * @hdisplay :hdisplay size
  439. * @vdisplay :vdisplay size
  440. * @vrefresh :vrefresh rate.
  441. * @interlaced :whether the interlace is supported
  442. * @margins :whether the margin is supported
  443. *
  444. * LOCKING.
  445. * none.
  446. *
  447. * return the modeline based on GTF algorithm
  448. *
  449. * This function is to create the modeline based on the GTF algorithm.
  450. * Generalized Timing Formula is derived from:
  451. * GTF Spreadsheet by Andy Morrish (1/5/97)
  452. * available at http://www.vesa.org
  453. *
  454. * And it is copied from the file of xserver/hw/xfree86/modes/xf86gtf.c.
  455. * What I have done is to translate it by using integer calculation.
  456. * I also refer to the function of fb_get_mode in the file of
  457. * drivers/video/fbmon.c
  458. *
  459. * Standard GTF parameters:
  460. * M = 600
  461. * C = 40
  462. * K = 128
  463. * J = 20
  464. */
  465. struct drm_display_mode *
  466. drm_gtf_mode(struct drm_device *dev, int hdisplay, int vdisplay, int vrefresh,
  467. bool lace, int margins)
  468. {
  469. return drm_gtf_mode_complex(dev, hdisplay, vdisplay, vrefresh, lace,
  470. margins, 600, 40 * 2, 128, 20 * 2);
  471. }
  472. EXPORT_SYMBOL(drm_gtf_mode);
  473. /**
  474. * drm_mode_set_name - set the name on a mode
  475. * @mode: name will be set in this mode
  476. *
  477. * LOCKING:
  478. * None.
  479. *
  480. * Set the name of @mode to a standard format.
  481. */
  482. void drm_mode_set_name(struct drm_display_mode *mode)
  483. {
  484. bool interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
  485. snprintf(mode->name, DRM_DISPLAY_MODE_LEN, "%dx%d%s",
  486. mode->hdisplay, mode->vdisplay,
  487. interlaced ? "i" : "");
  488. }
  489. EXPORT_SYMBOL(drm_mode_set_name);
  490. /**
  491. * drm_mode_list_concat - move modes from one list to another
  492. * @head: source list
  493. * @new: dst list
  494. *
  495. * LOCKING:
  496. * Caller must ensure both lists are locked.
  497. *
  498. * Move all the modes from @head to @new.
  499. */
  500. void drm_mode_list_concat(struct list_head *head, struct list_head *new)
  501. {
  502. struct list_head *entry, *tmp;
  503. list_for_each_safe(entry, tmp, head) {
  504. list_move_tail(entry, new);
  505. }
  506. }
  507. EXPORT_SYMBOL(drm_mode_list_concat);
  508. /**
  509. * drm_mode_width - get the width of a mode
  510. * @mode: mode
  511. *
  512. * LOCKING:
  513. * None.
  514. *
  515. * Return @mode's width (hdisplay) value.
  516. *
  517. * FIXME: is this needed?
  518. *
  519. * RETURNS:
  520. * @mode->hdisplay
  521. */
  522. int drm_mode_width(struct drm_display_mode *mode)
  523. {
  524. return mode->hdisplay;
  525. }
  526. EXPORT_SYMBOL(drm_mode_width);
  527. /**
  528. * drm_mode_height - get the height of a mode
  529. * @mode: mode
  530. *
  531. * LOCKING:
  532. * None.
  533. *
  534. * Return @mode's height (vdisplay) value.
  535. *
  536. * FIXME: is this needed?
  537. *
  538. * RETURNS:
  539. * @mode->vdisplay
  540. */
  541. int drm_mode_height(struct drm_display_mode *mode)
  542. {
  543. return mode->vdisplay;
  544. }
  545. EXPORT_SYMBOL(drm_mode_height);
  546. /** drm_mode_hsync - get the hsync of a mode
  547. * @mode: mode
  548. *
  549. * LOCKING:
  550. * None.
  551. *
  552. * Return @modes's hsync rate in kHz, rounded to the nearest int.
  553. */
  554. int drm_mode_hsync(const struct drm_display_mode *mode)
  555. {
  556. unsigned int calc_val;
  557. if (mode->hsync)
  558. return mode->hsync;
  559. if (mode->htotal < 0)
  560. return 0;
  561. calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */
  562. calc_val += 500; /* round to 1000Hz */
  563. calc_val /= 1000; /* truncate to kHz */
  564. return calc_val;
  565. }
  566. EXPORT_SYMBOL(drm_mode_hsync);
  567. /**
  568. * drm_mode_vrefresh - get the vrefresh of a mode
  569. * @mode: mode
  570. *
  571. * LOCKING:
  572. * None.
  573. *
  574. * Return @mode's vrefresh rate in Hz or calculate it if necessary.
  575. *
  576. * FIXME: why is this needed? shouldn't vrefresh be set already?
  577. *
  578. * RETURNS:
  579. * Vertical refresh rate. It will be the result of actual value plus 0.5.
  580. * If it is 70.288, it will return 70Hz.
  581. * If it is 59.6, it will return 60Hz.
  582. */
  583. int drm_mode_vrefresh(const struct drm_display_mode *mode)
  584. {
  585. int refresh = 0;
  586. unsigned int calc_val;
  587. if (mode->vrefresh > 0)
  588. refresh = mode->vrefresh;
  589. else if (mode->htotal > 0 && mode->vtotal > 0) {
  590. int vtotal;
  591. vtotal = mode->vtotal;
  592. /* work out vrefresh the value will be x1000 */
  593. calc_val = (mode->clock * 1000);
  594. calc_val /= mode->htotal;
  595. refresh = (calc_val + vtotal / 2) / vtotal;
  596. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  597. refresh *= 2;
  598. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  599. refresh /= 2;
  600. if (mode->vscan > 1)
  601. refresh /= mode->vscan;
  602. }
  603. return refresh;
  604. }
  605. EXPORT_SYMBOL(drm_mode_vrefresh);
  606. /**
  607. * drm_mode_set_crtcinfo - set CRTC modesetting parameters
  608. * @p: mode
  609. * @adjust_flags: unused? (FIXME)
  610. *
  611. * LOCKING:
  612. * None.
  613. *
  614. * Setup the CRTC modesetting parameters for @p, adjusting if necessary.
  615. */
  616. void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags)
  617. {
  618. if ((p == NULL) || ((p->type & DRM_MODE_TYPE_CRTC_C) == DRM_MODE_TYPE_BUILTIN))
  619. return;
  620. p->crtc_hdisplay = p->hdisplay;
  621. p->crtc_hsync_start = p->hsync_start;
  622. p->crtc_hsync_end = p->hsync_end;
  623. p->crtc_htotal = p->htotal;
  624. p->crtc_hskew = p->hskew;
  625. p->crtc_vdisplay = p->vdisplay;
  626. p->crtc_vsync_start = p->vsync_start;
  627. p->crtc_vsync_end = p->vsync_end;
  628. p->crtc_vtotal = p->vtotal;
  629. if (p->flags & DRM_MODE_FLAG_INTERLACE) {
  630. if (adjust_flags & CRTC_INTERLACE_HALVE_V) {
  631. p->crtc_vdisplay /= 2;
  632. p->crtc_vsync_start /= 2;
  633. p->crtc_vsync_end /= 2;
  634. p->crtc_vtotal /= 2;
  635. }
  636. }
  637. if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
  638. p->crtc_vdisplay *= 2;
  639. p->crtc_vsync_start *= 2;
  640. p->crtc_vsync_end *= 2;
  641. p->crtc_vtotal *= 2;
  642. }
  643. if (p->vscan > 1) {
  644. p->crtc_vdisplay *= p->vscan;
  645. p->crtc_vsync_start *= p->vscan;
  646. p->crtc_vsync_end *= p->vscan;
  647. p->crtc_vtotal *= p->vscan;
  648. }
  649. p->crtc_vblank_start = min(p->crtc_vsync_start, p->crtc_vdisplay);
  650. p->crtc_vblank_end = max(p->crtc_vsync_end, p->crtc_vtotal);
  651. p->crtc_hblank_start = min(p->crtc_hsync_start, p->crtc_hdisplay);
  652. p->crtc_hblank_end = max(p->crtc_hsync_end, p->crtc_htotal);
  653. }
  654. EXPORT_SYMBOL(drm_mode_set_crtcinfo);
  655. /**
  656. * drm_mode_copy - copy the mode
  657. * @dst: mode to overwrite
  658. * @src: mode to copy
  659. *
  660. * LOCKING:
  661. * None.
  662. *
  663. * Copy an existing mode into another mode, preserving the object id
  664. * of the destination mode.
  665. */
  666. void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src)
  667. {
  668. int id = dst->base.id;
  669. *dst = *src;
  670. dst->base.id = id;
  671. INIT_LIST_HEAD(&dst->head);
  672. }
  673. EXPORT_SYMBOL(drm_mode_copy);
  674. /**
  675. * drm_mode_duplicate - allocate and duplicate an existing mode
  676. * @m: mode to duplicate
  677. *
  678. * LOCKING:
  679. * None.
  680. *
  681. * Just allocate a new mode, copy the existing mode into it, and return
  682. * a pointer to it. Used to create new instances of established modes.
  683. */
  684. struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  685. const struct drm_display_mode *mode)
  686. {
  687. struct drm_display_mode *nmode;
  688. nmode = drm_mode_create(dev);
  689. if (!nmode)
  690. return NULL;
  691. drm_mode_copy(nmode, mode);
  692. return nmode;
  693. }
  694. EXPORT_SYMBOL(drm_mode_duplicate);
  695. /**
  696. * drm_mode_equal - test modes for equality
  697. * @mode1: first mode
  698. * @mode2: second mode
  699. *
  700. * LOCKING:
  701. * None.
  702. *
  703. * Check to see if @mode1 and @mode2 are equivalent.
  704. *
  705. * RETURNS:
  706. * True if the modes are equal, false otherwise.
  707. */
  708. bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2)
  709. {
  710. /* do clock check convert to PICOS so fb modes get matched
  711. * the same */
  712. if (mode1->clock && mode2->clock) {
  713. if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
  714. return false;
  715. } else if (mode1->clock != mode2->clock)
  716. return false;
  717. if (mode1->hdisplay == mode2->hdisplay &&
  718. mode1->hsync_start == mode2->hsync_start &&
  719. mode1->hsync_end == mode2->hsync_end &&
  720. mode1->htotal == mode2->htotal &&
  721. mode1->hskew == mode2->hskew &&
  722. mode1->vdisplay == mode2->vdisplay &&
  723. mode1->vsync_start == mode2->vsync_start &&
  724. mode1->vsync_end == mode2->vsync_end &&
  725. mode1->vtotal == mode2->vtotal &&
  726. mode1->vscan == mode2->vscan &&
  727. mode1->flags == mode2->flags)
  728. return true;
  729. return false;
  730. }
  731. EXPORT_SYMBOL(drm_mode_equal);
  732. /**
  733. * drm_mode_validate_size - make sure modes adhere to size constraints
  734. * @dev: DRM device
  735. * @mode_list: list of modes to check
  736. * @maxX: maximum width
  737. * @maxY: maximum height
  738. * @maxPitch: max pitch
  739. *
  740. * LOCKING:
  741. * Caller must hold a lock protecting @mode_list.
  742. *
  743. * The DRM device (@dev) has size and pitch limits. Here we validate the
  744. * modes we probed for @dev against those limits and set their status as
  745. * necessary.
  746. */
  747. void drm_mode_validate_size(struct drm_device *dev,
  748. struct list_head *mode_list,
  749. int maxX, int maxY, int maxPitch)
  750. {
  751. struct drm_display_mode *mode;
  752. list_for_each_entry(mode, mode_list, head) {
  753. if (maxPitch > 0 && mode->hdisplay > maxPitch)
  754. mode->status = MODE_BAD_WIDTH;
  755. if (maxX > 0 && mode->hdisplay > maxX)
  756. mode->status = MODE_VIRTUAL_X;
  757. if (maxY > 0 && mode->vdisplay > maxY)
  758. mode->status = MODE_VIRTUAL_Y;
  759. }
  760. }
  761. EXPORT_SYMBOL(drm_mode_validate_size);
  762. /**
  763. * drm_mode_validate_clocks - validate modes against clock limits
  764. * @dev: DRM device
  765. * @mode_list: list of modes to check
  766. * @min: minimum clock rate array
  767. * @max: maximum clock rate array
  768. * @n_ranges: number of clock ranges (size of arrays)
  769. *
  770. * LOCKING:
  771. * Caller must hold a lock protecting @mode_list.
  772. *
  773. * Some code may need to check a mode list against the clock limits of the
  774. * device in question. This function walks the mode list, testing to make
  775. * sure each mode falls within a given range (defined by @min and @max
  776. * arrays) and sets @mode->status as needed.
  777. */
  778. void drm_mode_validate_clocks(struct drm_device *dev,
  779. struct list_head *mode_list,
  780. int *min, int *max, int n_ranges)
  781. {
  782. struct drm_display_mode *mode;
  783. int i;
  784. list_for_each_entry(mode, mode_list, head) {
  785. bool good = false;
  786. for (i = 0; i < n_ranges; i++) {
  787. if (mode->clock >= min[i] && mode->clock <= max[i]) {
  788. good = true;
  789. break;
  790. }
  791. }
  792. if (!good)
  793. mode->status = MODE_CLOCK_RANGE;
  794. }
  795. }
  796. EXPORT_SYMBOL(drm_mode_validate_clocks);
  797. /**
  798. * drm_mode_prune_invalid - remove invalid modes from mode list
  799. * @dev: DRM device
  800. * @mode_list: list of modes to check
  801. * @verbose: be verbose about it
  802. *
  803. * LOCKING:
  804. * Caller must hold a lock protecting @mode_list.
  805. *
  806. * Once mode list generation is complete, a caller can use this routine to
  807. * remove invalid modes from a mode list. If any of the modes have a
  808. * status other than %MODE_OK, they are removed from @mode_list and freed.
  809. */
  810. void drm_mode_prune_invalid(struct drm_device *dev,
  811. struct list_head *mode_list, bool verbose)
  812. {
  813. struct drm_display_mode *mode, *t;
  814. list_for_each_entry_safe(mode, t, mode_list, head) {
  815. if (mode->status != MODE_OK) {
  816. list_del(&mode->head);
  817. if (verbose) {
  818. drm_mode_debug_printmodeline(mode);
  819. DRM_DEBUG_KMS("Not using %s mode %d\n",
  820. mode->name, mode->status);
  821. }
  822. drm_mode_destroy(dev, mode);
  823. }
  824. }
  825. }
  826. EXPORT_SYMBOL(drm_mode_prune_invalid);
  827. /**
  828. * drm_mode_compare - compare modes for favorability
  829. * @priv: unused
  830. * @lh_a: list_head for first mode
  831. * @lh_b: list_head for second mode
  832. *
  833. * LOCKING:
  834. * None.
  835. *
  836. * Compare two modes, given by @lh_a and @lh_b, returning a value indicating
  837. * which is better.
  838. *
  839. * RETURNS:
  840. * Negative if @lh_a is better than @lh_b, zero if they're equivalent, or
  841. * positive if @lh_b is better than @lh_a.
  842. */
  843. static int drm_mode_compare(void *priv, struct list_head *lh_a, struct list_head *lh_b)
  844. {
  845. struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head);
  846. struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head);
  847. int diff;
  848. diff = ((b->type & DRM_MODE_TYPE_PREFERRED) != 0) -
  849. ((a->type & DRM_MODE_TYPE_PREFERRED) != 0);
  850. if (diff)
  851. return diff;
  852. diff = b->hdisplay * b->vdisplay - a->hdisplay * a->vdisplay;
  853. if (diff)
  854. return diff;
  855. diff = b->clock - a->clock;
  856. return diff;
  857. }
  858. /**
  859. * drm_mode_sort - sort mode list
  860. * @mode_list: list to sort
  861. *
  862. * LOCKING:
  863. * Caller must hold a lock protecting @mode_list.
  864. *
  865. * Sort @mode_list by favorability, putting good modes first.
  866. */
  867. void drm_mode_sort(struct list_head *mode_list)
  868. {
  869. list_sort(NULL, mode_list, drm_mode_compare);
  870. }
  871. EXPORT_SYMBOL(drm_mode_sort);
  872. /**
  873. * drm_mode_connector_list_update - update the mode list for the connector
  874. * @connector: the connector to update
  875. *
  876. * LOCKING:
  877. * Caller must hold a lock protecting @mode_list.
  878. *
  879. * This moves the modes from the @connector probed_modes list
  880. * to the actual mode list. It compares the probed mode against the current
  881. * list and only adds different modes. All modes unverified after this point
  882. * will be removed by the prune invalid modes.
  883. */
  884. void drm_mode_connector_list_update(struct drm_connector *connector)
  885. {
  886. struct drm_display_mode *mode;
  887. struct drm_display_mode *pmode, *pt;
  888. int found_it;
  889. list_for_each_entry_safe(pmode, pt, &connector->probed_modes,
  890. head) {
  891. found_it = 0;
  892. /* go through current modes checking for the new probed mode */
  893. list_for_each_entry(mode, &connector->modes, head) {
  894. if (drm_mode_equal(pmode, mode)) {
  895. found_it = 1;
  896. /* if equal delete the probed mode */
  897. mode->status = pmode->status;
  898. /* Merge type bits together */
  899. mode->type |= pmode->type;
  900. list_del(&pmode->head);
  901. drm_mode_destroy(connector->dev, pmode);
  902. break;
  903. }
  904. }
  905. if (!found_it) {
  906. list_move_tail(&pmode->head, &connector->modes);
  907. }
  908. }
  909. }
  910. EXPORT_SYMBOL(drm_mode_connector_list_update);
  911. /**
  912. * drm_mode_parse_command_line_for_connector - parse command line for connector
  913. * @mode_option - per connector mode option
  914. * @connector - connector to parse line for
  915. *
  916. * This parses the connector specific then generic command lines for
  917. * modes and options to configure the connector.
  918. *
  919. * This uses the same parameters as the fb modedb.c, except for extra
  920. * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
  921. *
  922. * enable/enable Digital/disable bit at the end
  923. */
  924. bool drm_mode_parse_command_line_for_connector(const char *mode_option,
  925. struct drm_connector *connector,
  926. struct drm_cmdline_mode *mode)
  927. {
  928. const char *name;
  929. unsigned int namelen;
  930. bool res_specified = false, bpp_specified = false, refresh_specified = false;
  931. unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0;
  932. bool yres_specified = false, cvt = false, rb = false;
  933. bool interlace = false, margins = false, was_digit = false;
  934. int i;
  935. enum drm_connector_force force = DRM_FORCE_UNSPECIFIED;
  936. #ifdef CONFIG_FB
  937. if (!mode_option)
  938. mode_option = fb_mode_option;
  939. #endif
  940. if (!mode_option) {
  941. mode->specified = false;
  942. return false;
  943. }
  944. name = mode_option;
  945. namelen = strlen(name);
  946. for (i = namelen-1; i >= 0; i--) {
  947. switch (name[i]) {
  948. case '@':
  949. if (!refresh_specified && !bpp_specified &&
  950. !yres_specified && !cvt && !rb && was_digit) {
  951. refresh = simple_strtol(&name[i+1], NULL, 10);
  952. refresh_specified = true;
  953. was_digit = false;
  954. } else
  955. goto done;
  956. break;
  957. case '-':
  958. if (!bpp_specified && !yres_specified && !cvt &&
  959. !rb && was_digit) {
  960. bpp = simple_strtol(&name[i+1], NULL, 10);
  961. bpp_specified = true;
  962. was_digit = false;
  963. } else
  964. goto done;
  965. break;
  966. case 'x':
  967. if (!yres_specified && was_digit) {
  968. yres = simple_strtol(&name[i+1], NULL, 10);
  969. yres_specified = true;
  970. was_digit = false;
  971. } else
  972. goto done;
  973. case '0' ... '9':
  974. was_digit = true;
  975. break;
  976. case 'M':
  977. if (yres_specified || cvt || was_digit)
  978. goto done;
  979. cvt = true;
  980. break;
  981. case 'R':
  982. if (yres_specified || cvt || rb || was_digit)
  983. goto done;
  984. rb = true;
  985. break;
  986. case 'm':
  987. if (cvt || yres_specified || was_digit)
  988. goto done;
  989. margins = true;
  990. break;
  991. case 'i':
  992. if (cvt || yres_specified || was_digit)
  993. goto done;
  994. interlace = true;
  995. break;
  996. case 'e':
  997. if (yres_specified || bpp_specified || refresh_specified ||
  998. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  999. goto done;
  1000. force = DRM_FORCE_ON;
  1001. break;
  1002. case 'D':
  1003. if (yres_specified || bpp_specified || refresh_specified ||
  1004. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  1005. goto done;
  1006. if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) &&
  1007. (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB))
  1008. force = DRM_FORCE_ON;
  1009. else
  1010. force = DRM_FORCE_ON_DIGITAL;
  1011. break;
  1012. case 'd':
  1013. if (yres_specified || bpp_specified || refresh_specified ||
  1014. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  1015. goto done;
  1016. force = DRM_FORCE_OFF;
  1017. break;
  1018. default:
  1019. goto done;
  1020. }
  1021. }
  1022. if (i < 0 && yres_specified) {
  1023. char *ch;
  1024. xres = simple_strtol(name, &ch, 10);
  1025. if ((ch != NULL) && (*ch == 'x'))
  1026. res_specified = true;
  1027. else
  1028. i = ch - name;
  1029. } else if (!yres_specified && was_digit) {
  1030. /* catch mode that begins with digits but has no 'x' */
  1031. i = 0;
  1032. }
  1033. done:
  1034. if (i >= 0) {
  1035. printk(KERN_WARNING
  1036. "parse error at position %i in video mode '%s'\n",
  1037. i, name);
  1038. mode->specified = false;
  1039. return false;
  1040. }
  1041. if (res_specified) {
  1042. mode->specified = true;
  1043. mode->xres = xres;
  1044. mode->yres = yres;
  1045. }
  1046. if (refresh_specified) {
  1047. mode->refresh_specified = true;
  1048. mode->refresh = refresh;
  1049. }
  1050. if (bpp_specified) {
  1051. mode->bpp_specified = true;
  1052. mode->bpp = bpp;
  1053. }
  1054. mode->rb = rb;
  1055. mode->cvt = cvt;
  1056. mode->interlace = interlace;
  1057. mode->margins = margins;
  1058. mode->force = force;
  1059. return true;
  1060. }
  1061. EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector);
  1062. struct drm_display_mode *
  1063. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  1064. struct drm_cmdline_mode *cmd)
  1065. {
  1066. struct drm_display_mode *mode;
  1067. if (cmd->cvt)
  1068. mode = drm_cvt_mode(dev,
  1069. cmd->xres, cmd->yres,
  1070. cmd->refresh_specified ? cmd->refresh : 60,
  1071. cmd->rb, cmd->interlace,
  1072. cmd->margins);
  1073. else
  1074. mode = drm_gtf_mode(dev,
  1075. cmd->xres, cmd->yres,
  1076. cmd->refresh_specified ? cmd->refresh : 60,
  1077. cmd->interlace,
  1078. cmd->margins);
  1079. if (!mode)
  1080. return NULL;
  1081. drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
  1082. return mode;
  1083. }
  1084. EXPORT_SYMBOL(drm_mode_create_from_cmdline_mode);