drm_modes.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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. p->crtc_vtotal |= 1;
  637. }
  638. if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
  639. p->crtc_vdisplay *= 2;
  640. p->crtc_vsync_start *= 2;
  641. p->crtc_vsync_end *= 2;
  642. p->crtc_vtotal *= 2;
  643. }
  644. if (p->vscan > 1) {
  645. p->crtc_vdisplay *= p->vscan;
  646. p->crtc_vsync_start *= p->vscan;
  647. p->crtc_vsync_end *= p->vscan;
  648. p->crtc_vtotal *= p->vscan;
  649. }
  650. p->crtc_vblank_start = min(p->crtc_vsync_start, p->crtc_vdisplay);
  651. p->crtc_vblank_end = max(p->crtc_vsync_end, p->crtc_vtotal);
  652. p->crtc_hblank_start = min(p->crtc_hsync_start, p->crtc_hdisplay);
  653. p->crtc_hblank_end = max(p->crtc_hsync_end, p->crtc_htotal);
  654. p->crtc_hadjusted = false;
  655. p->crtc_vadjusted = false;
  656. }
  657. EXPORT_SYMBOL(drm_mode_set_crtcinfo);
  658. /**
  659. * drm_mode_duplicate - allocate and duplicate an existing mode
  660. * @m: mode to duplicate
  661. *
  662. * LOCKING:
  663. * None.
  664. *
  665. * Just allocate a new mode, copy the existing mode into it, and return
  666. * a pointer to it. Used to create new instances of established modes.
  667. */
  668. struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  669. const struct drm_display_mode *mode)
  670. {
  671. struct drm_display_mode *nmode;
  672. int new_id;
  673. nmode = drm_mode_create(dev);
  674. if (!nmode)
  675. return NULL;
  676. new_id = nmode->base.id;
  677. *nmode = *mode;
  678. nmode->base.id = new_id;
  679. INIT_LIST_HEAD(&nmode->head);
  680. return nmode;
  681. }
  682. EXPORT_SYMBOL(drm_mode_duplicate);
  683. /**
  684. * drm_mode_equal - test modes for equality
  685. * @mode1: first mode
  686. * @mode2: second mode
  687. *
  688. * LOCKING:
  689. * None.
  690. *
  691. * Check to see if @mode1 and @mode2 are equivalent.
  692. *
  693. * RETURNS:
  694. * True if the modes are equal, false otherwise.
  695. */
  696. bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2)
  697. {
  698. /* do clock check convert to PICOS so fb modes get matched
  699. * the same */
  700. if (mode1->clock && mode2->clock) {
  701. if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
  702. return false;
  703. } else if (mode1->clock != mode2->clock)
  704. return false;
  705. if (mode1->hdisplay == mode2->hdisplay &&
  706. mode1->hsync_start == mode2->hsync_start &&
  707. mode1->hsync_end == mode2->hsync_end &&
  708. mode1->htotal == mode2->htotal &&
  709. mode1->hskew == mode2->hskew &&
  710. mode1->vdisplay == mode2->vdisplay &&
  711. mode1->vsync_start == mode2->vsync_start &&
  712. mode1->vsync_end == mode2->vsync_end &&
  713. mode1->vtotal == mode2->vtotal &&
  714. mode1->vscan == mode2->vscan &&
  715. mode1->flags == mode2->flags)
  716. return true;
  717. return false;
  718. }
  719. EXPORT_SYMBOL(drm_mode_equal);
  720. /**
  721. * drm_mode_validate_size - make sure modes adhere to size constraints
  722. * @dev: DRM device
  723. * @mode_list: list of modes to check
  724. * @maxX: maximum width
  725. * @maxY: maximum height
  726. * @maxPitch: max pitch
  727. *
  728. * LOCKING:
  729. * Caller must hold a lock protecting @mode_list.
  730. *
  731. * The DRM device (@dev) has size and pitch limits. Here we validate the
  732. * modes we probed for @dev against those limits and set their status as
  733. * necessary.
  734. */
  735. void drm_mode_validate_size(struct drm_device *dev,
  736. struct list_head *mode_list,
  737. int maxX, int maxY, int maxPitch)
  738. {
  739. struct drm_display_mode *mode;
  740. list_for_each_entry(mode, mode_list, head) {
  741. if (maxPitch > 0 && mode->hdisplay > maxPitch)
  742. mode->status = MODE_BAD_WIDTH;
  743. if (maxX > 0 && mode->hdisplay > maxX)
  744. mode->status = MODE_VIRTUAL_X;
  745. if (maxY > 0 && mode->vdisplay > maxY)
  746. mode->status = MODE_VIRTUAL_Y;
  747. }
  748. }
  749. EXPORT_SYMBOL(drm_mode_validate_size);
  750. /**
  751. * drm_mode_validate_clocks - validate modes against clock limits
  752. * @dev: DRM device
  753. * @mode_list: list of modes to check
  754. * @min: minimum clock rate array
  755. * @max: maximum clock rate array
  756. * @n_ranges: number of clock ranges (size of arrays)
  757. *
  758. * LOCKING:
  759. * Caller must hold a lock protecting @mode_list.
  760. *
  761. * Some code may need to check a mode list against the clock limits of the
  762. * device in question. This function walks the mode list, testing to make
  763. * sure each mode falls within a given range (defined by @min and @max
  764. * arrays) and sets @mode->status as needed.
  765. */
  766. void drm_mode_validate_clocks(struct drm_device *dev,
  767. struct list_head *mode_list,
  768. int *min, int *max, int n_ranges)
  769. {
  770. struct drm_display_mode *mode;
  771. int i;
  772. list_for_each_entry(mode, mode_list, head) {
  773. bool good = false;
  774. for (i = 0; i < n_ranges; i++) {
  775. if (mode->clock >= min[i] && mode->clock <= max[i]) {
  776. good = true;
  777. break;
  778. }
  779. }
  780. if (!good)
  781. mode->status = MODE_CLOCK_RANGE;
  782. }
  783. }
  784. EXPORT_SYMBOL(drm_mode_validate_clocks);
  785. /**
  786. * drm_mode_prune_invalid - remove invalid modes from mode list
  787. * @dev: DRM device
  788. * @mode_list: list of modes to check
  789. * @verbose: be verbose about it
  790. *
  791. * LOCKING:
  792. * Caller must hold a lock protecting @mode_list.
  793. *
  794. * Once mode list generation is complete, a caller can use this routine to
  795. * remove invalid modes from a mode list. If any of the modes have a
  796. * status other than %MODE_OK, they are removed from @mode_list and freed.
  797. */
  798. void drm_mode_prune_invalid(struct drm_device *dev,
  799. struct list_head *mode_list, bool verbose)
  800. {
  801. struct drm_display_mode *mode, *t;
  802. list_for_each_entry_safe(mode, t, mode_list, head) {
  803. if (mode->status != MODE_OK) {
  804. list_del(&mode->head);
  805. if (verbose) {
  806. drm_mode_debug_printmodeline(mode);
  807. DRM_DEBUG_KMS("Not using %s mode %d\n",
  808. mode->name, mode->status);
  809. }
  810. drm_mode_destroy(dev, mode);
  811. }
  812. }
  813. }
  814. EXPORT_SYMBOL(drm_mode_prune_invalid);
  815. /**
  816. * drm_mode_compare - compare modes for favorability
  817. * @priv: unused
  818. * @lh_a: list_head for first mode
  819. * @lh_b: list_head for second mode
  820. *
  821. * LOCKING:
  822. * None.
  823. *
  824. * Compare two modes, given by @lh_a and @lh_b, returning a value indicating
  825. * which is better.
  826. *
  827. * RETURNS:
  828. * Negative if @lh_a is better than @lh_b, zero if they're equivalent, or
  829. * positive if @lh_b is better than @lh_a.
  830. */
  831. static int drm_mode_compare(void *priv, struct list_head *lh_a, struct list_head *lh_b)
  832. {
  833. struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head);
  834. struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head);
  835. int diff;
  836. diff = ((b->type & DRM_MODE_TYPE_PREFERRED) != 0) -
  837. ((a->type & DRM_MODE_TYPE_PREFERRED) != 0);
  838. if (diff)
  839. return diff;
  840. diff = b->hdisplay * b->vdisplay - a->hdisplay * a->vdisplay;
  841. if (diff)
  842. return diff;
  843. diff = b->clock - a->clock;
  844. return diff;
  845. }
  846. /**
  847. * drm_mode_sort - sort mode list
  848. * @mode_list: list to sort
  849. *
  850. * LOCKING:
  851. * Caller must hold a lock protecting @mode_list.
  852. *
  853. * Sort @mode_list by favorability, putting good modes first.
  854. */
  855. void drm_mode_sort(struct list_head *mode_list)
  856. {
  857. list_sort(NULL, mode_list, drm_mode_compare);
  858. }
  859. EXPORT_SYMBOL(drm_mode_sort);
  860. /**
  861. * drm_mode_connector_list_update - update the mode list for the connector
  862. * @connector: the connector to update
  863. *
  864. * LOCKING:
  865. * Caller must hold a lock protecting @mode_list.
  866. *
  867. * This moves the modes from the @connector probed_modes list
  868. * to the actual mode list. It compares the probed mode against the current
  869. * list and only adds different modes. All modes unverified after this point
  870. * will be removed by the prune invalid modes.
  871. */
  872. void drm_mode_connector_list_update(struct drm_connector *connector)
  873. {
  874. struct drm_display_mode *mode;
  875. struct drm_display_mode *pmode, *pt;
  876. int found_it;
  877. list_for_each_entry_safe(pmode, pt, &connector->probed_modes,
  878. head) {
  879. found_it = 0;
  880. /* go through current modes checking for the new probed mode */
  881. list_for_each_entry(mode, &connector->modes, head) {
  882. if (drm_mode_equal(pmode, mode)) {
  883. found_it = 1;
  884. /* if equal delete the probed mode */
  885. mode->status = pmode->status;
  886. /* Merge type bits together */
  887. mode->type |= pmode->type;
  888. list_del(&pmode->head);
  889. drm_mode_destroy(connector->dev, pmode);
  890. break;
  891. }
  892. }
  893. if (!found_it) {
  894. list_move_tail(&pmode->head, &connector->modes);
  895. }
  896. }
  897. }
  898. EXPORT_SYMBOL(drm_mode_connector_list_update);
  899. /**
  900. * drm_mode_parse_command_line_for_connector - parse command line for connector
  901. * @mode_option - per connector mode option
  902. * @connector - connector to parse line for
  903. *
  904. * This parses the connector specific then generic command lines for
  905. * modes and options to configure the connector.
  906. *
  907. * This uses the same parameters as the fb modedb.c, except for extra
  908. * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
  909. *
  910. * enable/enable Digital/disable bit at the end
  911. */
  912. bool drm_mode_parse_command_line_for_connector(const char *mode_option,
  913. struct drm_connector *connector,
  914. struct drm_cmdline_mode *mode)
  915. {
  916. const char *name;
  917. unsigned int namelen;
  918. bool res_specified = false, bpp_specified = false, refresh_specified = false;
  919. unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0;
  920. bool yres_specified = false, cvt = false, rb = false;
  921. bool interlace = false, margins = false, was_digit = false;
  922. int i;
  923. enum drm_connector_force force = DRM_FORCE_UNSPECIFIED;
  924. #ifdef CONFIG_FB
  925. if (!mode_option)
  926. mode_option = fb_mode_option;
  927. #endif
  928. if (!mode_option) {
  929. mode->specified = false;
  930. return false;
  931. }
  932. name = mode_option;
  933. namelen = strlen(name);
  934. for (i = namelen-1; i >= 0; i--) {
  935. switch (name[i]) {
  936. case '@':
  937. if (!refresh_specified && !bpp_specified &&
  938. !yres_specified && !cvt && !rb && was_digit) {
  939. refresh = simple_strtol(&name[i+1], NULL, 10);
  940. refresh_specified = true;
  941. was_digit = false;
  942. } else
  943. goto done;
  944. break;
  945. case '-':
  946. if (!bpp_specified && !yres_specified && !cvt &&
  947. !rb && was_digit) {
  948. bpp = simple_strtol(&name[i+1], NULL, 10);
  949. bpp_specified = true;
  950. was_digit = false;
  951. } else
  952. goto done;
  953. break;
  954. case 'x':
  955. if (!yres_specified && was_digit) {
  956. yres = simple_strtol(&name[i+1], NULL, 10);
  957. yres_specified = true;
  958. was_digit = false;
  959. } else
  960. goto done;
  961. case '0' ... '9':
  962. was_digit = true;
  963. break;
  964. case 'M':
  965. if (yres_specified || cvt || was_digit)
  966. goto done;
  967. cvt = true;
  968. break;
  969. case 'R':
  970. if (yres_specified || cvt || rb || was_digit)
  971. goto done;
  972. rb = true;
  973. break;
  974. case 'm':
  975. if (cvt || yres_specified || was_digit)
  976. goto done;
  977. margins = true;
  978. break;
  979. case 'i':
  980. if (cvt || yres_specified || was_digit)
  981. goto done;
  982. interlace = true;
  983. break;
  984. case 'e':
  985. if (yres_specified || bpp_specified || refresh_specified ||
  986. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  987. goto done;
  988. force = DRM_FORCE_ON;
  989. break;
  990. case 'D':
  991. if (yres_specified || bpp_specified || refresh_specified ||
  992. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  993. goto done;
  994. if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) &&
  995. (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB))
  996. force = DRM_FORCE_ON;
  997. else
  998. force = DRM_FORCE_ON_DIGITAL;
  999. break;
  1000. case 'd':
  1001. if (yres_specified || bpp_specified || refresh_specified ||
  1002. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  1003. goto done;
  1004. force = DRM_FORCE_OFF;
  1005. break;
  1006. default:
  1007. goto done;
  1008. }
  1009. }
  1010. if (i < 0 && yres_specified) {
  1011. char *ch;
  1012. xres = simple_strtol(name, &ch, 10);
  1013. if ((ch != NULL) && (*ch == 'x'))
  1014. res_specified = true;
  1015. else
  1016. i = ch - name;
  1017. } else if (!yres_specified && was_digit) {
  1018. /* catch mode that begins with digits but has no 'x' */
  1019. i = 0;
  1020. }
  1021. done:
  1022. if (i >= 0) {
  1023. printk(KERN_WARNING
  1024. "parse error at position %i in video mode '%s'\n",
  1025. i, name);
  1026. mode->specified = false;
  1027. return false;
  1028. }
  1029. if (res_specified) {
  1030. mode->specified = true;
  1031. mode->xres = xres;
  1032. mode->yres = yres;
  1033. }
  1034. if (refresh_specified) {
  1035. mode->refresh_specified = true;
  1036. mode->refresh = refresh;
  1037. }
  1038. if (bpp_specified) {
  1039. mode->bpp_specified = true;
  1040. mode->bpp = bpp;
  1041. }
  1042. mode->rb = rb;
  1043. mode->cvt = cvt;
  1044. mode->interlace = interlace;
  1045. mode->margins = margins;
  1046. mode->force = force;
  1047. return true;
  1048. }
  1049. EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector);
  1050. struct drm_display_mode *
  1051. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  1052. struct drm_cmdline_mode *cmd)
  1053. {
  1054. struct drm_display_mode *mode;
  1055. if (cmd->cvt)
  1056. mode = drm_cvt_mode(dev,
  1057. cmd->xres, cmd->yres,
  1058. cmd->refresh_specified ? cmd->refresh : 60,
  1059. cmd->rb, cmd->interlace,
  1060. cmd->margins);
  1061. else
  1062. mode = drm_gtf_mode(dev,
  1063. cmd->xres, cmd->yres,
  1064. cmd->refresh_specified ? cmd->refresh : 60,
  1065. cmd->interlace,
  1066. cmd->margins);
  1067. if (!mode)
  1068. return NULL;
  1069. drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
  1070. return mode;
  1071. }
  1072. EXPORT_SYMBOL(drm_mode_create_from_cmdline_mode);