drm_modes.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  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 <drm/drmP.h>
  36. #include <drm/drm_crtc.h>
  37. #include <video/of_videomode.h>
  38. #include <video/videomode.h>
  39. #include <drm/drm_modes.h>
  40. #include "drm_crtc_internal.h"
  41. /**
  42. * drm_mode_debug_printmodeline - print a mode to dmesg
  43. * @mode: mode to print
  44. *
  45. * Describe @mode using DRM_DEBUG.
  46. */
  47. void drm_mode_debug_printmodeline(const struct drm_display_mode *mode)
  48. {
  49. DRM_DEBUG_KMS("Modeline " DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
  50. }
  51. EXPORT_SYMBOL(drm_mode_debug_printmodeline);
  52. /**
  53. * drm_mode_create - create a new display mode
  54. * @dev: DRM device
  55. *
  56. * Create a new, cleared drm_display_mode with kzalloc, allocate an ID for it
  57. * and return it.
  58. *
  59. * Returns:
  60. * Pointer to new mode on success, NULL on error.
  61. */
  62. struct drm_display_mode *drm_mode_create(struct drm_device *dev)
  63. {
  64. struct drm_display_mode *nmode;
  65. nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL);
  66. if (!nmode)
  67. return NULL;
  68. if (drm_mode_object_get(dev, &nmode->base, DRM_MODE_OBJECT_MODE)) {
  69. kfree(nmode);
  70. return NULL;
  71. }
  72. return nmode;
  73. }
  74. EXPORT_SYMBOL(drm_mode_create);
  75. /**
  76. * drm_mode_destroy - remove a mode
  77. * @dev: DRM device
  78. * @mode: mode to remove
  79. *
  80. * Release @mode's unique ID, then free it @mode structure itself using kfree.
  81. */
  82. void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
  83. {
  84. if (!mode)
  85. return;
  86. drm_mode_object_unregister(dev, &mode->base);
  87. kfree(mode);
  88. }
  89. EXPORT_SYMBOL(drm_mode_destroy);
  90. /**
  91. * drm_mode_probed_add - add a mode to a connector's probed_mode list
  92. * @connector: connector the new mode
  93. * @mode: mode data
  94. *
  95. * Add @mode to @connector's probed_mode list for later use. This list should
  96. * then in a second step get filtered and all the modes actually supported by
  97. * the hardware moved to the @connector's modes list.
  98. */
  99. void drm_mode_probed_add(struct drm_connector *connector,
  100. struct drm_display_mode *mode)
  101. {
  102. WARN_ON(!mutex_is_locked(&connector->dev->mode_config.mutex));
  103. list_add_tail(&mode->head, &connector->probed_modes);
  104. }
  105. EXPORT_SYMBOL(drm_mode_probed_add);
  106. /**
  107. * drm_cvt_mode -create a modeline based on the CVT algorithm
  108. * @dev: drm device
  109. * @hdisplay: hdisplay size
  110. * @vdisplay: vdisplay size
  111. * @vrefresh: vrefresh rate
  112. * @reduced: whether to use reduced blanking
  113. * @interlaced: whether to compute an interlaced mode
  114. * @margins: whether to add margins (borders)
  115. *
  116. * This function is called to generate the modeline based on CVT algorithm
  117. * according to the hdisplay, vdisplay, vrefresh.
  118. * It is based from the VESA(TM) Coordinated Video Timing Generator by
  119. * Graham Loveridge April 9, 2003 available at
  120. * http://www.elo.utfsm.cl/~elo212/docs/CVTd6r1.xls
  121. *
  122. * And it is copied from xf86CVTmode in xserver/hw/xfree86/modes/xf86cvt.c.
  123. * What I have done is to translate it by using integer calculation.
  124. *
  125. * Returns:
  126. * The modeline based on the CVT algorithm stored in a drm_display_mode object.
  127. * The display mode object is allocated with drm_mode_create(). Returns NULL
  128. * when no mode could be allocated.
  129. */
  130. struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, int hdisplay,
  131. int vdisplay, int vrefresh,
  132. bool reduced, bool interlaced, bool margins)
  133. {
  134. #define HV_FACTOR 1000
  135. /* 1) top/bottom margin size (% of height) - default: 1.8, */
  136. #define CVT_MARGIN_PERCENTAGE 18
  137. /* 2) character cell horizontal granularity (pixels) - default 8 */
  138. #define CVT_H_GRANULARITY 8
  139. /* 3) Minimum vertical porch (lines) - default 3 */
  140. #define CVT_MIN_V_PORCH 3
  141. /* 4) Minimum number of vertical back porch lines - default 6 */
  142. #define CVT_MIN_V_BPORCH 6
  143. /* Pixel Clock step (kHz) */
  144. #define CVT_CLOCK_STEP 250
  145. struct drm_display_mode *drm_mode;
  146. unsigned int vfieldrate, hperiod;
  147. int hdisplay_rnd, hmargin, vdisplay_rnd, vmargin, vsync;
  148. int interlace;
  149. u64 tmp;
  150. /* allocate the drm_display_mode structure. If failure, we will
  151. * return directly
  152. */
  153. drm_mode = drm_mode_create(dev);
  154. if (!drm_mode)
  155. return NULL;
  156. /* the CVT default refresh rate is 60Hz */
  157. if (!vrefresh)
  158. vrefresh = 60;
  159. /* the required field fresh rate */
  160. if (interlaced)
  161. vfieldrate = vrefresh * 2;
  162. else
  163. vfieldrate = vrefresh;
  164. /* horizontal pixels */
  165. hdisplay_rnd = hdisplay - (hdisplay % CVT_H_GRANULARITY);
  166. /* determine the left&right borders */
  167. hmargin = 0;
  168. if (margins) {
  169. hmargin = hdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000;
  170. hmargin -= hmargin % CVT_H_GRANULARITY;
  171. }
  172. /* find the total active pixels */
  173. drm_mode->hdisplay = hdisplay_rnd + 2 * hmargin;
  174. /* find the number of lines per field */
  175. if (interlaced)
  176. vdisplay_rnd = vdisplay / 2;
  177. else
  178. vdisplay_rnd = vdisplay;
  179. /* find the top & bottom borders */
  180. vmargin = 0;
  181. if (margins)
  182. vmargin = vdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000;
  183. drm_mode->vdisplay = vdisplay + 2 * vmargin;
  184. /* Interlaced */
  185. if (interlaced)
  186. interlace = 1;
  187. else
  188. interlace = 0;
  189. /* Determine VSync Width from aspect ratio */
  190. if (!(vdisplay % 3) && ((vdisplay * 4 / 3) == hdisplay))
  191. vsync = 4;
  192. else if (!(vdisplay % 9) && ((vdisplay * 16 / 9) == hdisplay))
  193. vsync = 5;
  194. else if (!(vdisplay % 10) && ((vdisplay * 16 / 10) == hdisplay))
  195. vsync = 6;
  196. else if (!(vdisplay % 4) && ((vdisplay * 5 / 4) == hdisplay))
  197. vsync = 7;
  198. else if (!(vdisplay % 9) && ((vdisplay * 15 / 9) == hdisplay))
  199. vsync = 7;
  200. else /* custom */
  201. vsync = 10;
  202. if (!reduced) {
  203. /* simplify the GTF calculation */
  204. /* 4) Minimum time of vertical sync + back porch interval (µs)
  205. * default 550.0
  206. */
  207. int tmp1, tmp2;
  208. #define CVT_MIN_VSYNC_BP 550
  209. /* 3) Nominal HSync width (% of line period) - default 8 */
  210. #define CVT_HSYNC_PERCENTAGE 8
  211. unsigned int hblank_percentage;
  212. int vsyncandback_porch, vback_porch, hblank;
  213. /* estimated the horizontal period */
  214. tmp1 = HV_FACTOR * 1000000 -
  215. CVT_MIN_VSYNC_BP * HV_FACTOR * vfieldrate;
  216. tmp2 = (vdisplay_rnd + 2 * vmargin + CVT_MIN_V_PORCH) * 2 +
  217. interlace;
  218. hperiod = tmp1 * 2 / (tmp2 * vfieldrate);
  219. tmp1 = CVT_MIN_VSYNC_BP * HV_FACTOR / hperiod + 1;
  220. /* 9. Find number of lines in sync + backporch */
  221. if (tmp1 < (vsync + CVT_MIN_V_PORCH))
  222. vsyncandback_porch = vsync + CVT_MIN_V_PORCH;
  223. else
  224. vsyncandback_porch = tmp1;
  225. /* 10. Find number of lines in back porch */
  226. vback_porch = vsyncandback_porch - vsync;
  227. drm_mode->vtotal = vdisplay_rnd + 2 * vmargin +
  228. vsyncandback_porch + CVT_MIN_V_PORCH;
  229. /* 5) Definition of Horizontal blanking time limitation */
  230. /* Gradient (%/kHz) - default 600 */
  231. #define CVT_M_FACTOR 600
  232. /* Offset (%) - default 40 */
  233. #define CVT_C_FACTOR 40
  234. /* Blanking time scaling factor - default 128 */
  235. #define CVT_K_FACTOR 128
  236. /* Scaling factor weighting - default 20 */
  237. #define CVT_J_FACTOR 20
  238. #define CVT_M_PRIME (CVT_M_FACTOR * CVT_K_FACTOR / 256)
  239. #define CVT_C_PRIME ((CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \
  240. CVT_J_FACTOR)
  241. /* 12. Find ideal blanking duty cycle from formula */
  242. hblank_percentage = CVT_C_PRIME * HV_FACTOR - CVT_M_PRIME *
  243. hperiod / 1000;
  244. /* 13. Blanking time */
  245. if (hblank_percentage < 20 * HV_FACTOR)
  246. hblank_percentage = 20 * HV_FACTOR;
  247. hblank = drm_mode->hdisplay * hblank_percentage /
  248. (100 * HV_FACTOR - hblank_percentage);
  249. hblank -= hblank % (2 * CVT_H_GRANULARITY);
  250. /* 14. find the total pixels per line */
  251. drm_mode->htotal = drm_mode->hdisplay + hblank;
  252. drm_mode->hsync_end = drm_mode->hdisplay + hblank / 2;
  253. drm_mode->hsync_start = drm_mode->hsync_end -
  254. (drm_mode->htotal * CVT_HSYNC_PERCENTAGE) / 100;
  255. drm_mode->hsync_start += CVT_H_GRANULARITY -
  256. drm_mode->hsync_start % CVT_H_GRANULARITY;
  257. /* fill the Vsync values */
  258. drm_mode->vsync_start = drm_mode->vdisplay + CVT_MIN_V_PORCH;
  259. drm_mode->vsync_end = drm_mode->vsync_start + vsync;
  260. } else {
  261. /* Reduced blanking */
  262. /* Minimum vertical blanking interval time (µs)- default 460 */
  263. #define CVT_RB_MIN_VBLANK 460
  264. /* Fixed number of clocks for horizontal sync */
  265. #define CVT_RB_H_SYNC 32
  266. /* Fixed number of clocks for horizontal blanking */
  267. #define CVT_RB_H_BLANK 160
  268. /* Fixed number of lines for vertical front porch - default 3*/
  269. #define CVT_RB_VFPORCH 3
  270. int vbilines;
  271. int tmp1, tmp2;
  272. /* 8. Estimate Horizontal period. */
  273. tmp1 = HV_FACTOR * 1000000 -
  274. CVT_RB_MIN_VBLANK * HV_FACTOR * vfieldrate;
  275. tmp2 = vdisplay_rnd + 2 * vmargin;
  276. hperiod = tmp1 / (tmp2 * vfieldrate);
  277. /* 9. Find number of lines in vertical blanking */
  278. vbilines = CVT_RB_MIN_VBLANK * HV_FACTOR / hperiod + 1;
  279. /* 10. Check if vertical blanking is sufficient */
  280. if (vbilines < (CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH))
  281. vbilines = CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH;
  282. /* 11. Find total number of lines in vertical field */
  283. drm_mode->vtotal = vdisplay_rnd + 2 * vmargin + vbilines;
  284. /* 12. Find total number of pixels in a line */
  285. drm_mode->htotal = drm_mode->hdisplay + CVT_RB_H_BLANK;
  286. /* Fill in HSync values */
  287. drm_mode->hsync_end = drm_mode->hdisplay + CVT_RB_H_BLANK / 2;
  288. drm_mode->hsync_start = drm_mode->hsync_end - CVT_RB_H_SYNC;
  289. /* Fill in VSync values */
  290. drm_mode->vsync_start = drm_mode->vdisplay + CVT_RB_VFPORCH;
  291. drm_mode->vsync_end = drm_mode->vsync_start + vsync;
  292. }
  293. /* 15/13. Find pixel clock frequency (kHz for xf86) */
  294. tmp = drm_mode->htotal; /* perform intermediate calcs in u64 */
  295. tmp *= HV_FACTOR * 1000;
  296. do_div(tmp, hperiod);
  297. tmp -= drm_mode->clock % CVT_CLOCK_STEP;
  298. drm_mode->clock = tmp;
  299. /* 18/16. Find actual vertical frame frequency */
  300. /* ignore - just set the mode flag for interlaced */
  301. if (interlaced) {
  302. drm_mode->vtotal *= 2;
  303. drm_mode->flags |= DRM_MODE_FLAG_INTERLACE;
  304. }
  305. /* Fill the mode line name */
  306. drm_mode_set_name(drm_mode);
  307. if (reduced)
  308. drm_mode->flags |= (DRM_MODE_FLAG_PHSYNC |
  309. DRM_MODE_FLAG_NVSYNC);
  310. else
  311. drm_mode->flags |= (DRM_MODE_FLAG_PVSYNC |
  312. DRM_MODE_FLAG_NHSYNC);
  313. return drm_mode;
  314. }
  315. EXPORT_SYMBOL(drm_cvt_mode);
  316. /**
  317. * drm_gtf_mode_complex - create the modeline based on the full GTF algorithm
  318. * @dev: drm device
  319. * @hdisplay: hdisplay size
  320. * @vdisplay: vdisplay size
  321. * @vrefresh: vrefresh rate.
  322. * @interlaced: whether to compute an interlaced mode
  323. * @margins: desired margin (borders) size
  324. * @GTF_M: extended GTF formula parameters
  325. * @GTF_2C: extended GTF formula parameters
  326. * @GTF_K: extended GTF formula parameters
  327. * @GTF_2J: extended GTF formula parameters
  328. *
  329. * GTF feature blocks specify C and J in multiples of 0.5, so we pass them
  330. * in here multiplied by two. For a C of 40, pass in 80.
  331. *
  332. * Returns:
  333. * The modeline based on the full GTF algorithm stored in a drm_display_mode object.
  334. * The display mode object is allocated with drm_mode_create(). Returns NULL
  335. * when no mode could be allocated.
  336. */
  337. struct drm_display_mode *
  338. drm_gtf_mode_complex(struct drm_device *dev, int hdisplay, int vdisplay,
  339. int vrefresh, bool interlaced, int margins,
  340. int GTF_M, int GTF_2C, int GTF_K, int GTF_2J)
  341. { /* 1) top/bottom margin size (% of height) - default: 1.8, */
  342. #define GTF_MARGIN_PERCENTAGE 18
  343. /* 2) character cell horizontal granularity (pixels) - default 8 */
  344. #define GTF_CELL_GRAN 8
  345. /* 3) Minimum vertical porch (lines) - default 3 */
  346. #define GTF_MIN_V_PORCH 1
  347. /* width of vsync in lines */
  348. #define V_SYNC_RQD 3
  349. /* width of hsync as % of total line */
  350. #define H_SYNC_PERCENT 8
  351. /* min time of vsync + back porch (microsec) */
  352. #define MIN_VSYNC_PLUS_BP 550
  353. /* C' and M' are part of the Blanking Duty Cycle computation */
  354. #define GTF_C_PRIME ((((GTF_2C - GTF_2J) * GTF_K / 256) + GTF_2J) / 2)
  355. #define GTF_M_PRIME (GTF_K * GTF_M / 256)
  356. struct drm_display_mode *drm_mode;
  357. unsigned int hdisplay_rnd, vdisplay_rnd, vfieldrate_rqd;
  358. int top_margin, bottom_margin;
  359. int interlace;
  360. unsigned int hfreq_est;
  361. int vsync_plus_bp, vback_porch;
  362. unsigned int vtotal_lines, vfieldrate_est, hperiod;
  363. unsigned int vfield_rate, vframe_rate;
  364. int left_margin, right_margin;
  365. unsigned int total_active_pixels, ideal_duty_cycle;
  366. unsigned int hblank, total_pixels, pixel_freq;
  367. int hsync, hfront_porch, vodd_front_porch_lines;
  368. unsigned int tmp1, tmp2;
  369. drm_mode = drm_mode_create(dev);
  370. if (!drm_mode)
  371. return NULL;
  372. /* 1. In order to give correct results, the number of horizontal
  373. * pixels requested is first processed to ensure that it is divisible
  374. * by the character size, by rounding it to the nearest character
  375. * cell boundary:
  376. */
  377. hdisplay_rnd = (hdisplay + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN;
  378. hdisplay_rnd = hdisplay_rnd * GTF_CELL_GRAN;
  379. /* 2. If interlace is requested, the number of vertical lines assumed
  380. * by the calculation must be halved, as the computation calculates
  381. * the number of vertical lines per field.
  382. */
  383. if (interlaced)
  384. vdisplay_rnd = vdisplay / 2;
  385. else
  386. vdisplay_rnd = vdisplay;
  387. /* 3. Find the frame rate required: */
  388. if (interlaced)
  389. vfieldrate_rqd = vrefresh * 2;
  390. else
  391. vfieldrate_rqd = vrefresh;
  392. /* 4. Find number of lines in Top margin: */
  393. top_margin = 0;
  394. if (margins)
  395. top_margin = (vdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) /
  396. 1000;
  397. /* 5. Find number of lines in bottom margin: */
  398. bottom_margin = top_margin;
  399. /* 6. If interlace is required, then set variable interlace: */
  400. if (interlaced)
  401. interlace = 1;
  402. else
  403. interlace = 0;
  404. /* 7. Estimate the Horizontal frequency */
  405. {
  406. tmp1 = (1000000 - MIN_VSYNC_PLUS_BP * vfieldrate_rqd) / 500;
  407. tmp2 = (vdisplay_rnd + 2 * top_margin + GTF_MIN_V_PORCH) *
  408. 2 + interlace;
  409. hfreq_est = (tmp2 * 1000 * vfieldrate_rqd) / tmp1;
  410. }
  411. /* 8. Find the number of lines in V sync + back porch */
  412. /* [V SYNC+BP] = RINT(([MIN VSYNC+BP] * hfreq_est / 1000000)) */
  413. vsync_plus_bp = MIN_VSYNC_PLUS_BP * hfreq_est / 1000;
  414. vsync_plus_bp = (vsync_plus_bp + 500) / 1000;
  415. /* 9. Find the number of lines in V back porch alone: */
  416. vback_porch = vsync_plus_bp - V_SYNC_RQD;
  417. /* 10. Find the total number of lines in Vertical field period: */
  418. vtotal_lines = vdisplay_rnd + top_margin + bottom_margin +
  419. vsync_plus_bp + GTF_MIN_V_PORCH;
  420. /* 11. Estimate the Vertical field frequency: */
  421. vfieldrate_est = hfreq_est / vtotal_lines;
  422. /* 12. Find the actual horizontal period: */
  423. hperiod = 1000000 / (vfieldrate_rqd * vtotal_lines);
  424. /* 13. Find the actual Vertical field frequency: */
  425. vfield_rate = hfreq_est / vtotal_lines;
  426. /* 14. Find the Vertical frame frequency: */
  427. if (interlaced)
  428. vframe_rate = vfield_rate / 2;
  429. else
  430. vframe_rate = vfield_rate;
  431. /* 15. Find number of pixels in left margin: */
  432. if (margins)
  433. left_margin = (hdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) /
  434. 1000;
  435. else
  436. left_margin = 0;
  437. /* 16.Find number of pixels in right margin: */
  438. right_margin = left_margin;
  439. /* 17.Find total number of active pixels in image and left and right */
  440. total_active_pixels = hdisplay_rnd + left_margin + right_margin;
  441. /* 18.Find the ideal blanking duty cycle from blanking duty cycle */
  442. ideal_duty_cycle = GTF_C_PRIME * 1000 -
  443. (GTF_M_PRIME * 1000000 / hfreq_est);
  444. /* 19.Find the number of pixels in the blanking time to the nearest
  445. * double character cell: */
  446. hblank = total_active_pixels * ideal_duty_cycle /
  447. (100000 - ideal_duty_cycle);
  448. hblank = (hblank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN);
  449. hblank = hblank * 2 * GTF_CELL_GRAN;
  450. /* 20.Find total number of pixels: */
  451. total_pixels = total_active_pixels + hblank;
  452. /* 21.Find pixel clock frequency: */
  453. pixel_freq = total_pixels * hfreq_est / 1000;
  454. /* Stage 1 computations are now complete; I should really pass
  455. * the results to another function and do the Stage 2 computations,
  456. * but I only need a few more values so I'll just append the
  457. * computations here for now */
  458. /* 17. Find the number of pixels in the horizontal sync period: */
  459. hsync = H_SYNC_PERCENT * total_pixels / 100;
  460. hsync = (hsync + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN;
  461. hsync = hsync * GTF_CELL_GRAN;
  462. /* 18. Find the number of pixels in horizontal front porch period */
  463. hfront_porch = hblank / 2 - hsync;
  464. /* 36. Find the number of lines in the odd front porch period: */
  465. vodd_front_porch_lines = GTF_MIN_V_PORCH ;
  466. /* finally, pack the results in the mode struct */
  467. drm_mode->hdisplay = hdisplay_rnd;
  468. drm_mode->hsync_start = hdisplay_rnd + hfront_porch;
  469. drm_mode->hsync_end = drm_mode->hsync_start + hsync;
  470. drm_mode->htotal = total_pixels;
  471. drm_mode->vdisplay = vdisplay_rnd;
  472. drm_mode->vsync_start = vdisplay_rnd + vodd_front_porch_lines;
  473. drm_mode->vsync_end = drm_mode->vsync_start + V_SYNC_RQD;
  474. drm_mode->vtotal = vtotal_lines;
  475. drm_mode->clock = pixel_freq;
  476. if (interlaced) {
  477. drm_mode->vtotal *= 2;
  478. drm_mode->flags |= DRM_MODE_FLAG_INTERLACE;
  479. }
  480. drm_mode_set_name(drm_mode);
  481. if (GTF_M == 600 && GTF_2C == 80 && GTF_K == 128 && GTF_2J == 40)
  482. drm_mode->flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC;
  483. else
  484. drm_mode->flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC;
  485. return drm_mode;
  486. }
  487. EXPORT_SYMBOL(drm_gtf_mode_complex);
  488. /**
  489. * drm_gtf_mode - create the modeline based on the GTF algorithm
  490. * @dev: drm device
  491. * @hdisplay: hdisplay size
  492. * @vdisplay: vdisplay size
  493. * @vrefresh: vrefresh rate.
  494. * @interlaced: whether to compute an interlaced mode
  495. * @margins: desired margin (borders) size
  496. *
  497. * return the modeline based on GTF algorithm
  498. *
  499. * This function is to create the modeline based on the GTF algorithm.
  500. * Generalized Timing Formula is derived from:
  501. *
  502. * GTF Spreadsheet by Andy Morrish (1/5/97)
  503. * available at http://www.vesa.org
  504. *
  505. * And it is copied from the file of xserver/hw/xfree86/modes/xf86gtf.c.
  506. * What I have done is to translate it by using integer calculation.
  507. * I also refer to the function of fb_get_mode in the file of
  508. * drivers/video/fbmon.c
  509. *
  510. * Standard GTF parameters::
  511. *
  512. * M = 600
  513. * C = 40
  514. * K = 128
  515. * J = 20
  516. *
  517. * Returns:
  518. * The modeline based on the GTF algorithm stored in a drm_display_mode object.
  519. * The display mode object is allocated with drm_mode_create(). Returns NULL
  520. * when no mode could be allocated.
  521. */
  522. struct drm_display_mode *
  523. drm_gtf_mode(struct drm_device *dev, int hdisplay, int vdisplay, int vrefresh,
  524. bool interlaced, int margins)
  525. {
  526. return drm_gtf_mode_complex(dev, hdisplay, vdisplay, vrefresh,
  527. interlaced, margins,
  528. 600, 40 * 2, 128, 20 * 2);
  529. }
  530. EXPORT_SYMBOL(drm_gtf_mode);
  531. #ifdef CONFIG_VIDEOMODE_HELPERS
  532. /**
  533. * drm_display_mode_from_videomode - fill in @dmode using @vm,
  534. * @vm: videomode structure to use as source
  535. * @dmode: drm_display_mode structure to use as destination
  536. *
  537. * Fills out @dmode using the display mode specified in @vm.
  538. */
  539. void drm_display_mode_from_videomode(const struct videomode *vm,
  540. struct drm_display_mode *dmode)
  541. {
  542. dmode->hdisplay = vm->hactive;
  543. dmode->hsync_start = dmode->hdisplay + vm->hfront_porch;
  544. dmode->hsync_end = dmode->hsync_start + vm->hsync_len;
  545. dmode->htotal = dmode->hsync_end + vm->hback_porch;
  546. dmode->vdisplay = vm->vactive;
  547. dmode->vsync_start = dmode->vdisplay + vm->vfront_porch;
  548. dmode->vsync_end = dmode->vsync_start + vm->vsync_len;
  549. dmode->vtotal = dmode->vsync_end + vm->vback_porch;
  550. dmode->clock = vm->pixelclock / 1000;
  551. dmode->flags = 0;
  552. if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
  553. dmode->flags |= DRM_MODE_FLAG_PHSYNC;
  554. else if (vm->flags & DISPLAY_FLAGS_HSYNC_LOW)
  555. dmode->flags |= DRM_MODE_FLAG_NHSYNC;
  556. if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
  557. dmode->flags |= DRM_MODE_FLAG_PVSYNC;
  558. else if (vm->flags & DISPLAY_FLAGS_VSYNC_LOW)
  559. dmode->flags |= DRM_MODE_FLAG_NVSYNC;
  560. if (vm->flags & DISPLAY_FLAGS_INTERLACED)
  561. dmode->flags |= DRM_MODE_FLAG_INTERLACE;
  562. if (vm->flags & DISPLAY_FLAGS_DOUBLESCAN)
  563. dmode->flags |= DRM_MODE_FLAG_DBLSCAN;
  564. if (vm->flags & DISPLAY_FLAGS_DOUBLECLK)
  565. dmode->flags |= DRM_MODE_FLAG_DBLCLK;
  566. drm_mode_set_name(dmode);
  567. }
  568. EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
  569. /**
  570. * drm_display_mode_to_videomode - fill in @vm using @dmode,
  571. * @dmode: drm_display_mode structure to use as source
  572. * @vm: videomode structure to use as destination
  573. *
  574. * Fills out @vm using the display mode specified in @dmode.
  575. */
  576. void drm_display_mode_to_videomode(const struct drm_display_mode *dmode,
  577. struct videomode *vm)
  578. {
  579. vm->hactive = dmode->hdisplay;
  580. vm->hfront_porch = dmode->hsync_start - dmode->hdisplay;
  581. vm->hsync_len = dmode->hsync_end - dmode->hsync_start;
  582. vm->hback_porch = dmode->htotal - dmode->hsync_end;
  583. vm->vactive = dmode->vdisplay;
  584. vm->vfront_porch = dmode->vsync_start - dmode->vdisplay;
  585. vm->vsync_len = dmode->vsync_end - dmode->vsync_start;
  586. vm->vback_porch = dmode->vtotal - dmode->vsync_end;
  587. vm->pixelclock = dmode->clock * 1000;
  588. vm->flags = 0;
  589. if (dmode->flags & DRM_MODE_FLAG_PHSYNC)
  590. vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
  591. else if (dmode->flags & DRM_MODE_FLAG_NHSYNC)
  592. vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
  593. if (dmode->flags & DRM_MODE_FLAG_PVSYNC)
  594. vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
  595. else if (dmode->flags & DRM_MODE_FLAG_NVSYNC)
  596. vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
  597. if (dmode->flags & DRM_MODE_FLAG_INTERLACE)
  598. vm->flags |= DISPLAY_FLAGS_INTERLACED;
  599. if (dmode->flags & DRM_MODE_FLAG_DBLSCAN)
  600. vm->flags |= DISPLAY_FLAGS_DOUBLESCAN;
  601. if (dmode->flags & DRM_MODE_FLAG_DBLCLK)
  602. vm->flags |= DISPLAY_FLAGS_DOUBLECLK;
  603. }
  604. EXPORT_SYMBOL_GPL(drm_display_mode_to_videomode);
  605. /**
  606. * drm_bus_flags_from_videomode - extract information about pixelclk and
  607. * DE polarity from videomode and store it in a separate variable
  608. * @vm: videomode structure to use
  609. * @bus_flags: information about pixelclk and DE polarity will be stored here
  610. *
  611. * Sets DRM_BUS_FLAG_DE_(LOW|HIGH) and DRM_BUS_FLAG_PIXDATA_(POS|NEG)EDGE
  612. * in @bus_flags according to DISPLAY_FLAGS found in @vm
  613. */
  614. void drm_bus_flags_from_videomode(const struct videomode *vm, u32 *bus_flags)
  615. {
  616. *bus_flags = 0;
  617. if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
  618. *bus_flags |= DRM_BUS_FLAG_PIXDATA_POSEDGE;
  619. if (vm->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
  620. *bus_flags |= DRM_BUS_FLAG_PIXDATA_NEGEDGE;
  621. if (vm->flags & DISPLAY_FLAGS_DE_LOW)
  622. *bus_flags |= DRM_BUS_FLAG_DE_LOW;
  623. if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
  624. *bus_flags |= DRM_BUS_FLAG_DE_HIGH;
  625. }
  626. EXPORT_SYMBOL_GPL(drm_bus_flags_from_videomode);
  627. #ifdef CONFIG_OF
  628. /**
  629. * of_get_drm_display_mode - get a drm_display_mode from devicetree
  630. * @np: device_node with the timing specification
  631. * @dmode: will be set to the return value
  632. * @bus_flags: information about pixelclk and DE polarity
  633. * @index: index into the list of display timings in devicetree
  634. *
  635. * This function is expensive and should only be used, if only one mode is to be
  636. * read from DT. To get multiple modes start with of_get_display_timings and
  637. * work with that instead.
  638. *
  639. * Returns:
  640. * 0 on success, a negative errno code when no of videomode node was found.
  641. */
  642. int of_get_drm_display_mode(struct device_node *np,
  643. struct drm_display_mode *dmode, u32 *bus_flags,
  644. int index)
  645. {
  646. struct videomode vm;
  647. int ret;
  648. ret = of_get_videomode(np, &vm, index);
  649. if (ret)
  650. return ret;
  651. drm_display_mode_from_videomode(&vm, dmode);
  652. if (bus_flags)
  653. drm_bus_flags_from_videomode(&vm, bus_flags);
  654. pr_debug("%s: got %dx%d display mode from %s\n",
  655. of_node_full_name(np), vm.hactive, vm.vactive, np->name);
  656. drm_mode_debug_printmodeline(dmode);
  657. return 0;
  658. }
  659. EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
  660. #endif /* CONFIG_OF */
  661. #endif /* CONFIG_VIDEOMODE_HELPERS */
  662. /**
  663. * drm_mode_set_name - set the name on a mode
  664. * @mode: name will be set in this mode
  665. *
  666. * Set the name of @mode to a standard format which is <hdisplay>x<vdisplay>
  667. * with an optional 'i' suffix for interlaced modes.
  668. */
  669. void drm_mode_set_name(struct drm_display_mode *mode)
  670. {
  671. bool interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
  672. snprintf(mode->name, DRM_DISPLAY_MODE_LEN, "%dx%d%s",
  673. mode->hdisplay, mode->vdisplay,
  674. interlaced ? "i" : "");
  675. }
  676. EXPORT_SYMBOL(drm_mode_set_name);
  677. /**
  678. * drm_mode_hsync - get the hsync of a mode
  679. * @mode: mode
  680. *
  681. * Returns:
  682. * @modes's hsync rate in kHz, rounded to the nearest integer. Calculates the
  683. * value first if it is not yet set.
  684. */
  685. int drm_mode_hsync(const struct drm_display_mode *mode)
  686. {
  687. unsigned int calc_val;
  688. if (mode->hsync)
  689. return mode->hsync;
  690. if (mode->htotal < 0)
  691. return 0;
  692. calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */
  693. calc_val += 500; /* round to 1000Hz */
  694. calc_val /= 1000; /* truncate to kHz */
  695. return calc_val;
  696. }
  697. EXPORT_SYMBOL(drm_mode_hsync);
  698. /**
  699. * drm_mode_vrefresh - get the vrefresh of a mode
  700. * @mode: mode
  701. *
  702. * Returns:
  703. * @modes's vrefresh rate in Hz, rounded to the nearest integer. Calculates the
  704. * value first if it is not yet set.
  705. */
  706. int drm_mode_vrefresh(const struct drm_display_mode *mode)
  707. {
  708. int refresh = 0;
  709. unsigned int calc_val;
  710. if (mode->vrefresh > 0)
  711. refresh = mode->vrefresh;
  712. else if (mode->htotal > 0 && mode->vtotal > 0) {
  713. int vtotal;
  714. vtotal = mode->vtotal;
  715. /* work out vrefresh the value will be x1000 */
  716. calc_val = (mode->clock * 1000);
  717. calc_val /= mode->htotal;
  718. refresh = (calc_val + vtotal / 2) / vtotal;
  719. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  720. refresh *= 2;
  721. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  722. refresh /= 2;
  723. if (mode->vscan > 1)
  724. refresh /= mode->vscan;
  725. }
  726. return refresh;
  727. }
  728. EXPORT_SYMBOL(drm_mode_vrefresh);
  729. /**
  730. * drm_mode_set_crtcinfo - set CRTC modesetting timing parameters
  731. * @p: mode
  732. * @adjust_flags: a combination of adjustment flags
  733. *
  734. * Setup the CRTC modesetting timing parameters for @p, adjusting if necessary.
  735. *
  736. * - The CRTC_INTERLACE_HALVE_V flag can be used to halve vertical timings of
  737. * interlaced modes.
  738. * - The CRTC_STEREO_DOUBLE flag can be used to compute the timings for
  739. * buffers containing two eyes (only adjust the timings when needed, eg. for
  740. * "frame packing" or "side by side full").
  741. * - The CRTC_NO_DBLSCAN and CRTC_NO_VSCAN flags request that adjustment *not*
  742. * be performed for doublescan and vscan > 1 modes respectively.
  743. */
  744. void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags)
  745. {
  746. if ((p == NULL) || ((p->type & DRM_MODE_TYPE_CRTC_C) == DRM_MODE_TYPE_BUILTIN))
  747. return;
  748. p->crtc_clock = p->clock;
  749. p->crtc_hdisplay = p->hdisplay;
  750. p->crtc_hsync_start = p->hsync_start;
  751. p->crtc_hsync_end = p->hsync_end;
  752. p->crtc_htotal = p->htotal;
  753. p->crtc_hskew = p->hskew;
  754. p->crtc_vdisplay = p->vdisplay;
  755. p->crtc_vsync_start = p->vsync_start;
  756. p->crtc_vsync_end = p->vsync_end;
  757. p->crtc_vtotal = p->vtotal;
  758. if (p->flags & DRM_MODE_FLAG_INTERLACE) {
  759. if (adjust_flags & CRTC_INTERLACE_HALVE_V) {
  760. p->crtc_vdisplay /= 2;
  761. p->crtc_vsync_start /= 2;
  762. p->crtc_vsync_end /= 2;
  763. p->crtc_vtotal /= 2;
  764. }
  765. }
  766. if (!(adjust_flags & CRTC_NO_DBLSCAN)) {
  767. if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
  768. p->crtc_vdisplay *= 2;
  769. p->crtc_vsync_start *= 2;
  770. p->crtc_vsync_end *= 2;
  771. p->crtc_vtotal *= 2;
  772. }
  773. }
  774. if (!(adjust_flags & CRTC_NO_VSCAN)) {
  775. if (p->vscan > 1) {
  776. p->crtc_vdisplay *= p->vscan;
  777. p->crtc_vsync_start *= p->vscan;
  778. p->crtc_vsync_end *= p->vscan;
  779. p->crtc_vtotal *= p->vscan;
  780. }
  781. }
  782. if (adjust_flags & CRTC_STEREO_DOUBLE) {
  783. unsigned int layout = p->flags & DRM_MODE_FLAG_3D_MASK;
  784. switch (layout) {
  785. case DRM_MODE_FLAG_3D_FRAME_PACKING:
  786. p->crtc_clock *= 2;
  787. p->crtc_vdisplay += p->crtc_vtotal;
  788. p->crtc_vsync_start += p->crtc_vtotal;
  789. p->crtc_vsync_end += p->crtc_vtotal;
  790. p->crtc_vtotal += p->crtc_vtotal;
  791. break;
  792. }
  793. }
  794. p->crtc_vblank_start = min(p->crtc_vsync_start, p->crtc_vdisplay);
  795. p->crtc_vblank_end = max(p->crtc_vsync_end, p->crtc_vtotal);
  796. p->crtc_hblank_start = min(p->crtc_hsync_start, p->crtc_hdisplay);
  797. p->crtc_hblank_end = max(p->crtc_hsync_end, p->crtc_htotal);
  798. }
  799. EXPORT_SYMBOL(drm_mode_set_crtcinfo);
  800. /**
  801. * drm_mode_copy - copy the mode
  802. * @dst: mode to overwrite
  803. * @src: mode to copy
  804. *
  805. * Copy an existing mode into another mode, preserving the object id and
  806. * list head of the destination mode.
  807. */
  808. void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src)
  809. {
  810. int id = dst->base.id;
  811. struct list_head head = dst->head;
  812. *dst = *src;
  813. dst->base.id = id;
  814. dst->head = head;
  815. }
  816. EXPORT_SYMBOL(drm_mode_copy);
  817. /**
  818. * drm_mode_duplicate - allocate and duplicate an existing mode
  819. * @dev: drm_device to allocate the duplicated mode for
  820. * @mode: mode to duplicate
  821. *
  822. * Just allocate a new mode, copy the existing mode into it, and return
  823. * a pointer to it. Used to create new instances of established modes.
  824. *
  825. * Returns:
  826. * Pointer to duplicated mode on success, NULL on error.
  827. */
  828. struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  829. const struct drm_display_mode *mode)
  830. {
  831. struct drm_display_mode *nmode;
  832. nmode = drm_mode_create(dev);
  833. if (!nmode)
  834. return NULL;
  835. drm_mode_copy(nmode, mode);
  836. return nmode;
  837. }
  838. EXPORT_SYMBOL(drm_mode_duplicate);
  839. /**
  840. * drm_mode_equal - test modes for equality
  841. * @mode1: first mode
  842. * @mode2: second mode
  843. *
  844. * Check to see if @mode1 and @mode2 are equivalent.
  845. *
  846. * Returns:
  847. * True if the modes are equal, false otherwise.
  848. */
  849. bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
  850. {
  851. if (!mode1 && !mode2)
  852. return true;
  853. if (!mode1 || !mode2)
  854. return false;
  855. /* do clock check convert to PICOS so fb modes get matched
  856. * the same */
  857. if (mode1->clock && mode2->clock) {
  858. if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
  859. return false;
  860. } else if (mode1->clock != mode2->clock)
  861. return false;
  862. return drm_mode_equal_no_clocks(mode1, mode2);
  863. }
  864. EXPORT_SYMBOL(drm_mode_equal);
  865. /**
  866. * drm_mode_equal_no_clocks - test modes for equality
  867. * @mode1: first mode
  868. * @mode2: second mode
  869. *
  870. * Check to see if @mode1 and @mode2 are equivalent, but
  871. * don't check the pixel clocks.
  872. *
  873. * Returns:
  874. * True if the modes are equal, false otherwise.
  875. */
  876. bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
  877. {
  878. if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) !=
  879. (mode2->flags & DRM_MODE_FLAG_3D_MASK))
  880. return false;
  881. return drm_mode_equal_no_clocks_no_stereo(mode1, mode2);
  882. }
  883. EXPORT_SYMBOL(drm_mode_equal_no_clocks);
  884. /**
  885. * drm_mode_equal_no_clocks_no_stereo - test modes for equality
  886. * @mode1: first mode
  887. * @mode2: second mode
  888. *
  889. * Check to see if @mode1 and @mode2 are equivalent, but
  890. * don't check the pixel clocks nor the stereo layout.
  891. *
  892. * Returns:
  893. * True if the modes are equal, false otherwise.
  894. */
  895. bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
  896. const struct drm_display_mode *mode2)
  897. {
  898. if (mode1->hdisplay == mode2->hdisplay &&
  899. mode1->hsync_start == mode2->hsync_start &&
  900. mode1->hsync_end == mode2->hsync_end &&
  901. mode1->htotal == mode2->htotal &&
  902. mode1->hskew == mode2->hskew &&
  903. mode1->vdisplay == mode2->vdisplay &&
  904. mode1->vsync_start == mode2->vsync_start &&
  905. mode1->vsync_end == mode2->vsync_end &&
  906. mode1->vtotal == mode2->vtotal &&
  907. mode1->vscan == mode2->vscan &&
  908. mode1->picture_aspect_ratio == mode2->picture_aspect_ratio &&
  909. (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
  910. (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
  911. return true;
  912. return false;
  913. }
  914. EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
  915. /**
  916. * drm_mode_validate_basic - make sure the mode is somewhat sane
  917. * @mode: mode to check
  918. *
  919. * Check that the mode timings are at least somewhat reasonable.
  920. * Any hardware specific limits are left up for each driver to check.
  921. *
  922. * Returns:
  923. * The mode status
  924. */
  925. enum drm_mode_status
  926. drm_mode_validate_basic(const struct drm_display_mode *mode)
  927. {
  928. if (mode->clock == 0)
  929. return MODE_CLOCK_LOW;
  930. if (mode->hdisplay == 0 ||
  931. mode->hsync_start < mode->hdisplay ||
  932. mode->hsync_end < mode->hsync_start ||
  933. mode->htotal < mode->hsync_end)
  934. return MODE_H_ILLEGAL;
  935. if (mode->vdisplay == 0 ||
  936. mode->vsync_start < mode->vdisplay ||
  937. mode->vsync_end < mode->vsync_start ||
  938. mode->vtotal < mode->vsync_end)
  939. return MODE_V_ILLEGAL;
  940. return MODE_OK;
  941. }
  942. EXPORT_SYMBOL(drm_mode_validate_basic);
  943. /**
  944. * drm_mode_validate_size - make sure modes adhere to size constraints
  945. * @mode: mode to check
  946. * @maxX: maximum width
  947. * @maxY: maximum height
  948. *
  949. * This function is a helper which can be used to validate modes against size
  950. * limitations of the DRM device/connector. If a mode is too big its status
  951. * member is updated with the appropriate validation failure code. The list
  952. * itself is not changed.
  953. *
  954. * Returns:
  955. * The mode status
  956. */
  957. enum drm_mode_status
  958. drm_mode_validate_size(const struct drm_display_mode *mode,
  959. int maxX, int maxY)
  960. {
  961. if (maxX > 0 && mode->hdisplay > maxX)
  962. return MODE_VIRTUAL_X;
  963. if (maxY > 0 && mode->vdisplay > maxY)
  964. return MODE_VIRTUAL_Y;
  965. return MODE_OK;
  966. }
  967. EXPORT_SYMBOL(drm_mode_validate_size);
  968. #define MODE_STATUS(status) [MODE_ ## status + 3] = #status
  969. static const char * const drm_mode_status_names[] = {
  970. MODE_STATUS(OK),
  971. MODE_STATUS(HSYNC),
  972. MODE_STATUS(VSYNC),
  973. MODE_STATUS(H_ILLEGAL),
  974. MODE_STATUS(V_ILLEGAL),
  975. MODE_STATUS(BAD_WIDTH),
  976. MODE_STATUS(NOMODE),
  977. MODE_STATUS(NO_INTERLACE),
  978. MODE_STATUS(NO_DBLESCAN),
  979. MODE_STATUS(NO_VSCAN),
  980. MODE_STATUS(MEM),
  981. MODE_STATUS(VIRTUAL_X),
  982. MODE_STATUS(VIRTUAL_Y),
  983. MODE_STATUS(MEM_VIRT),
  984. MODE_STATUS(NOCLOCK),
  985. MODE_STATUS(CLOCK_HIGH),
  986. MODE_STATUS(CLOCK_LOW),
  987. MODE_STATUS(CLOCK_RANGE),
  988. MODE_STATUS(BAD_HVALUE),
  989. MODE_STATUS(BAD_VVALUE),
  990. MODE_STATUS(BAD_VSCAN),
  991. MODE_STATUS(HSYNC_NARROW),
  992. MODE_STATUS(HSYNC_WIDE),
  993. MODE_STATUS(HBLANK_NARROW),
  994. MODE_STATUS(HBLANK_WIDE),
  995. MODE_STATUS(VSYNC_NARROW),
  996. MODE_STATUS(VSYNC_WIDE),
  997. MODE_STATUS(VBLANK_NARROW),
  998. MODE_STATUS(VBLANK_WIDE),
  999. MODE_STATUS(PANEL),
  1000. MODE_STATUS(INTERLACE_WIDTH),
  1001. MODE_STATUS(ONE_WIDTH),
  1002. MODE_STATUS(ONE_HEIGHT),
  1003. MODE_STATUS(ONE_SIZE),
  1004. MODE_STATUS(NO_REDUCED),
  1005. MODE_STATUS(NO_STEREO),
  1006. MODE_STATUS(STALE),
  1007. MODE_STATUS(BAD),
  1008. MODE_STATUS(ERROR),
  1009. };
  1010. #undef MODE_STATUS
  1011. static const char *drm_get_mode_status_name(enum drm_mode_status status)
  1012. {
  1013. int index = status + 3;
  1014. if (WARN_ON(index < 0 || index >= ARRAY_SIZE(drm_mode_status_names)))
  1015. return "";
  1016. return drm_mode_status_names[index];
  1017. }
  1018. /**
  1019. * drm_mode_prune_invalid - remove invalid modes from mode list
  1020. * @dev: DRM device
  1021. * @mode_list: list of modes to check
  1022. * @verbose: be verbose about it
  1023. *
  1024. * This helper function can be used to prune a display mode list after
  1025. * validation has been completed. All modes who's status is not MODE_OK will be
  1026. * removed from the list, and if @verbose the status code and mode name is also
  1027. * printed to dmesg.
  1028. */
  1029. void drm_mode_prune_invalid(struct drm_device *dev,
  1030. struct list_head *mode_list, bool verbose)
  1031. {
  1032. struct drm_display_mode *mode, *t;
  1033. list_for_each_entry_safe(mode, t, mode_list, head) {
  1034. if (mode->status != MODE_OK) {
  1035. list_del(&mode->head);
  1036. if (verbose) {
  1037. drm_mode_debug_printmodeline(mode);
  1038. DRM_DEBUG_KMS("Not using %s mode: %s\n",
  1039. mode->name,
  1040. drm_get_mode_status_name(mode->status));
  1041. }
  1042. drm_mode_destroy(dev, mode);
  1043. }
  1044. }
  1045. }
  1046. EXPORT_SYMBOL(drm_mode_prune_invalid);
  1047. /**
  1048. * drm_mode_compare - compare modes for favorability
  1049. * @priv: unused
  1050. * @lh_a: list_head for first mode
  1051. * @lh_b: list_head for second mode
  1052. *
  1053. * Compare two modes, given by @lh_a and @lh_b, returning a value indicating
  1054. * which is better.
  1055. *
  1056. * Returns:
  1057. * Negative if @lh_a is better than @lh_b, zero if they're equivalent, or
  1058. * positive if @lh_b is better than @lh_a.
  1059. */
  1060. static int drm_mode_compare(void *priv, struct list_head *lh_a, struct list_head *lh_b)
  1061. {
  1062. struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head);
  1063. struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head);
  1064. int diff;
  1065. diff = ((b->type & DRM_MODE_TYPE_PREFERRED) != 0) -
  1066. ((a->type & DRM_MODE_TYPE_PREFERRED) != 0);
  1067. if (diff)
  1068. return diff;
  1069. diff = b->hdisplay * b->vdisplay - a->hdisplay * a->vdisplay;
  1070. if (diff)
  1071. return diff;
  1072. diff = b->vrefresh - a->vrefresh;
  1073. if (diff)
  1074. return diff;
  1075. diff = b->clock - a->clock;
  1076. return diff;
  1077. }
  1078. /**
  1079. * drm_mode_sort - sort mode list
  1080. * @mode_list: list of drm_display_mode structures to sort
  1081. *
  1082. * Sort @mode_list by favorability, moving good modes to the head of the list.
  1083. */
  1084. void drm_mode_sort(struct list_head *mode_list)
  1085. {
  1086. list_sort(NULL, mode_list, drm_mode_compare);
  1087. }
  1088. EXPORT_SYMBOL(drm_mode_sort);
  1089. /**
  1090. * drm_mode_connector_list_update - update the mode list for the connector
  1091. * @connector: the connector to update
  1092. *
  1093. * This moves the modes from the @connector probed_modes list
  1094. * to the actual mode list. It compares the probed mode against the current
  1095. * list and only adds different/new modes.
  1096. *
  1097. * This is just a helper functions doesn't validate any modes itself and also
  1098. * doesn't prune any invalid modes. Callers need to do that themselves.
  1099. */
  1100. void drm_mode_connector_list_update(struct drm_connector *connector)
  1101. {
  1102. struct drm_display_mode *pmode, *pt;
  1103. WARN_ON(!mutex_is_locked(&connector->dev->mode_config.mutex));
  1104. list_for_each_entry_safe(pmode, pt, &connector->probed_modes, head) {
  1105. struct drm_display_mode *mode;
  1106. bool found_it = false;
  1107. /* go through current modes checking for the new probed mode */
  1108. list_for_each_entry(mode, &connector->modes, head) {
  1109. if (!drm_mode_equal(pmode, mode))
  1110. continue;
  1111. found_it = true;
  1112. /*
  1113. * If the old matching mode is stale (ie. left over
  1114. * from a previous probe) just replace it outright.
  1115. * Otherwise just merge the type bits between all
  1116. * equal probed modes.
  1117. *
  1118. * If two probed modes are considered equal, pick the
  1119. * actual timings from the one that's marked as
  1120. * preferred (in case the match isn't 100%). If
  1121. * multiple or zero preferred modes are present, favor
  1122. * the mode added to the probed_modes list first.
  1123. */
  1124. if (mode->status == MODE_STALE) {
  1125. drm_mode_copy(mode, pmode);
  1126. } else if ((mode->type & DRM_MODE_TYPE_PREFERRED) == 0 &&
  1127. (pmode->type & DRM_MODE_TYPE_PREFERRED) != 0) {
  1128. pmode->type |= mode->type;
  1129. drm_mode_copy(mode, pmode);
  1130. } else {
  1131. mode->type |= pmode->type;
  1132. }
  1133. list_del(&pmode->head);
  1134. drm_mode_destroy(connector->dev, pmode);
  1135. break;
  1136. }
  1137. if (!found_it) {
  1138. list_move_tail(&pmode->head, &connector->modes);
  1139. }
  1140. }
  1141. }
  1142. EXPORT_SYMBOL(drm_mode_connector_list_update);
  1143. /**
  1144. * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
  1145. * @mode_option: optional per connector mode option
  1146. * @connector: connector to parse modeline for
  1147. * @mode: preallocated drm_cmdline_mode structure to fill out
  1148. *
  1149. * This parses @mode_option command line modeline for modes and options to
  1150. * configure the connector. If @mode_option is NULL the default command line
  1151. * modeline in fb_mode_option will be parsed instead.
  1152. *
  1153. * This uses the same parameters as the fb modedb.c, except for an extra
  1154. * force-enable, force-enable-digital and force-disable bit at the end:
  1155. *
  1156. * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
  1157. *
  1158. * The intermediate drm_cmdline_mode structure is required to store additional
  1159. * options from the command line modline like the force-enable/disable flag.
  1160. *
  1161. * Returns:
  1162. * True if a valid modeline has been parsed, false otherwise.
  1163. */
  1164. bool drm_mode_parse_command_line_for_connector(const char *mode_option,
  1165. struct drm_connector *connector,
  1166. struct drm_cmdline_mode *mode)
  1167. {
  1168. const char *name;
  1169. unsigned int namelen;
  1170. bool res_specified = false, bpp_specified = false, refresh_specified = false;
  1171. unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0;
  1172. bool yres_specified = false, cvt = false, rb = false;
  1173. bool interlace = false, margins = false, was_digit = false;
  1174. int i;
  1175. enum drm_connector_force force = DRM_FORCE_UNSPECIFIED;
  1176. #ifdef CONFIG_FB
  1177. if (!mode_option)
  1178. mode_option = fb_mode_option;
  1179. #endif
  1180. if (!mode_option) {
  1181. mode->specified = false;
  1182. return false;
  1183. }
  1184. name = mode_option;
  1185. namelen = strlen(name);
  1186. for (i = namelen-1; i >= 0; i--) {
  1187. switch (name[i]) {
  1188. case '@':
  1189. if (!refresh_specified && !bpp_specified &&
  1190. !yres_specified && !cvt && !rb && was_digit) {
  1191. refresh = simple_strtol(&name[i+1], NULL, 10);
  1192. refresh_specified = true;
  1193. was_digit = false;
  1194. } else
  1195. goto done;
  1196. break;
  1197. case '-':
  1198. if (!bpp_specified && !yres_specified && !cvt &&
  1199. !rb && was_digit) {
  1200. bpp = simple_strtol(&name[i+1], NULL, 10);
  1201. bpp_specified = true;
  1202. was_digit = false;
  1203. } else
  1204. goto done;
  1205. break;
  1206. case 'x':
  1207. if (!yres_specified && was_digit) {
  1208. yres = simple_strtol(&name[i+1], NULL, 10);
  1209. yres_specified = true;
  1210. was_digit = false;
  1211. } else
  1212. goto done;
  1213. break;
  1214. case '0' ... '9':
  1215. was_digit = true;
  1216. break;
  1217. case 'M':
  1218. if (yres_specified || cvt || was_digit)
  1219. goto done;
  1220. cvt = true;
  1221. break;
  1222. case 'R':
  1223. if (yres_specified || cvt || rb || was_digit)
  1224. goto done;
  1225. rb = true;
  1226. break;
  1227. case 'm':
  1228. if (cvt || yres_specified || was_digit)
  1229. goto done;
  1230. margins = true;
  1231. break;
  1232. case 'i':
  1233. if (cvt || yres_specified || was_digit)
  1234. goto done;
  1235. interlace = true;
  1236. break;
  1237. case 'e':
  1238. if (yres_specified || bpp_specified || refresh_specified ||
  1239. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  1240. goto done;
  1241. force = DRM_FORCE_ON;
  1242. break;
  1243. case 'D':
  1244. if (yres_specified || bpp_specified || refresh_specified ||
  1245. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  1246. goto done;
  1247. if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) &&
  1248. (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB))
  1249. force = DRM_FORCE_ON;
  1250. else
  1251. force = DRM_FORCE_ON_DIGITAL;
  1252. break;
  1253. case 'd':
  1254. if (yres_specified || bpp_specified || refresh_specified ||
  1255. was_digit || (force != DRM_FORCE_UNSPECIFIED))
  1256. goto done;
  1257. force = DRM_FORCE_OFF;
  1258. break;
  1259. default:
  1260. goto done;
  1261. }
  1262. }
  1263. if (i < 0 && yres_specified) {
  1264. char *ch;
  1265. xres = simple_strtol(name, &ch, 10);
  1266. if ((ch != NULL) && (*ch == 'x'))
  1267. res_specified = true;
  1268. else
  1269. i = ch - name;
  1270. } else if (!yres_specified && was_digit) {
  1271. /* catch mode that begins with digits but has no 'x' */
  1272. i = 0;
  1273. }
  1274. done:
  1275. if (i >= 0) {
  1276. pr_warn("[drm] parse error at position %i in video mode '%s'\n",
  1277. i, name);
  1278. mode->specified = false;
  1279. return false;
  1280. }
  1281. if (res_specified) {
  1282. mode->specified = true;
  1283. mode->xres = xres;
  1284. mode->yres = yres;
  1285. }
  1286. if (refresh_specified) {
  1287. mode->refresh_specified = true;
  1288. mode->refresh = refresh;
  1289. }
  1290. if (bpp_specified) {
  1291. mode->bpp_specified = true;
  1292. mode->bpp = bpp;
  1293. }
  1294. mode->rb = rb;
  1295. mode->cvt = cvt;
  1296. mode->interlace = interlace;
  1297. mode->margins = margins;
  1298. mode->force = force;
  1299. return true;
  1300. }
  1301. EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector);
  1302. /**
  1303. * drm_mode_create_from_cmdline_mode - convert a command line modeline into a DRM display mode
  1304. * @dev: DRM device to create the new mode for
  1305. * @cmd: input command line modeline
  1306. *
  1307. * Returns:
  1308. * Pointer to converted mode on success, NULL on error.
  1309. */
  1310. struct drm_display_mode *
  1311. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  1312. struct drm_cmdline_mode *cmd)
  1313. {
  1314. struct drm_display_mode *mode;
  1315. if (cmd->cvt)
  1316. mode = drm_cvt_mode(dev,
  1317. cmd->xres, cmd->yres,
  1318. cmd->refresh_specified ? cmd->refresh : 60,
  1319. cmd->rb, cmd->interlace,
  1320. cmd->margins);
  1321. else
  1322. mode = drm_gtf_mode(dev,
  1323. cmd->xres, cmd->yres,
  1324. cmd->refresh_specified ? cmd->refresh : 60,
  1325. cmd->interlace,
  1326. cmd->margins);
  1327. if (!mode)
  1328. return NULL;
  1329. mode->type |= DRM_MODE_TYPE_USERDEF;
  1330. drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
  1331. return mode;
  1332. }
  1333. EXPORT_SYMBOL(drm_mode_create_from_cmdline_mode);
  1334. /**
  1335. * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
  1336. * @out: drm_mode_modeinfo struct to return to the user
  1337. * @in: drm_display_mode to use
  1338. *
  1339. * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
  1340. * the user.
  1341. */
  1342. void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
  1343. const struct drm_display_mode *in)
  1344. {
  1345. WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX ||
  1346. in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX ||
  1347. in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX ||
  1348. in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX ||
  1349. in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX,
  1350. "timing values too large for mode info\n");
  1351. out->clock = in->clock;
  1352. out->hdisplay = in->hdisplay;
  1353. out->hsync_start = in->hsync_start;
  1354. out->hsync_end = in->hsync_end;
  1355. out->htotal = in->htotal;
  1356. out->hskew = in->hskew;
  1357. out->vdisplay = in->vdisplay;
  1358. out->vsync_start = in->vsync_start;
  1359. out->vsync_end = in->vsync_end;
  1360. out->vtotal = in->vtotal;
  1361. out->vscan = in->vscan;
  1362. out->vrefresh = in->vrefresh;
  1363. out->flags = in->flags;
  1364. out->type = in->type;
  1365. out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
  1366. switch (in->picture_aspect_ratio) {
  1367. case HDMI_PICTURE_ASPECT_4_3:
  1368. out->flags |= DRM_MODE_FLAG_PIC_AR_4_3;
  1369. break;
  1370. case HDMI_PICTURE_ASPECT_16_9:
  1371. out->flags |= DRM_MODE_FLAG_PIC_AR_16_9;
  1372. break;
  1373. case HDMI_PICTURE_ASPECT_64_27:
  1374. out->flags |= DRM_MODE_FLAG_PIC_AR_64_27;
  1375. break;
  1376. case DRM_MODE_PICTURE_ASPECT_256_135:
  1377. out->flags |= DRM_MODE_FLAG_PIC_AR_256_135;
  1378. break;
  1379. case HDMI_PICTURE_ASPECT_RESERVED:
  1380. default:
  1381. out->flags |= DRM_MODE_FLAG_PIC_AR_NONE;
  1382. break;
  1383. }
  1384. strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
  1385. out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
  1386. }
  1387. /**
  1388. * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode
  1389. * @out: drm_display_mode to return to the user
  1390. * @in: drm_mode_modeinfo to use
  1391. *
  1392. * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
  1393. * the caller.
  1394. *
  1395. * Returns:
  1396. * Zero on success, negative errno on failure.
  1397. */
  1398. int drm_mode_convert_umode(struct drm_display_mode *out,
  1399. const struct drm_mode_modeinfo *in)
  1400. {
  1401. int ret = -EINVAL;
  1402. if (in->clock > INT_MAX || in->vrefresh > INT_MAX) {
  1403. ret = -ERANGE;
  1404. goto out;
  1405. }
  1406. if ((in->flags & DRM_MODE_FLAG_3D_MASK) > DRM_MODE_FLAG_3D_MAX)
  1407. goto out;
  1408. out->clock = in->clock;
  1409. out->hdisplay = in->hdisplay;
  1410. out->hsync_start = in->hsync_start;
  1411. out->hsync_end = in->hsync_end;
  1412. out->htotal = in->htotal;
  1413. out->hskew = in->hskew;
  1414. out->vdisplay = in->vdisplay;
  1415. out->vsync_start = in->vsync_start;
  1416. out->vsync_end = in->vsync_end;
  1417. out->vtotal = in->vtotal;
  1418. out->vscan = in->vscan;
  1419. out->vrefresh = in->vrefresh;
  1420. out->flags = in->flags;
  1421. out->type = in->type;
  1422. strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
  1423. out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
  1424. /* Clearing picture aspect ratio bits from out flags */
  1425. out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
  1426. switch (in->flags & DRM_MODE_FLAG_PIC_AR_MASK) {
  1427. case DRM_MODE_FLAG_PIC_AR_4_3:
  1428. out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_4_3;
  1429. break;
  1430. case DRM_MODE_FLAG_PIC_AR_16_9:
  1431. out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_16_9;
  1432. break;
  1433. case DRM_MODE_FLAG_PIC_AR_64_27:
  1434. out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_64_27;
  1435. break;
  1436. case DRM_MODE_FLAG_PIC_AR_256_135:
  1437. out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_256_135;
  1438. break;
  1439. default:
  1440. out->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
  1441. break;
  1442. }
  1443. out->status = drm_mode_validate_basic(out);
  1444. if (out->status != MODE_OK)
  1445. goto out;
  1446. drm_mode_set_crtcinfo(out, CRTC_INTERLACE_HALVE_V);
  1447. ret = 0;
  1448. out:
  1449. return ret;
  1450. }